Module_CCS.c 661 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502
  1. /*
  2. * Module_CCS.c
  3. *
  4. * Created on: 2020/-3/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, *V2gtpMsgTxBuf;
  31. unsigned short Aag[64];
  32. struct MmeHeader SendMmePacket;
  33. int SendMmePacketSize;
  34. unsigned char CsuMac[6],QcaMac[6],EvMac[6],SlacRunId[8];
  35. struct sockaddr_ll DestSocketAddress;
  36. struct ifreq Req;
  37. unsigned int PwmStartTime;
  38. struct timeb SeqStartTime, SeqEndTime;
  39. unsigned char AagGroupsNum, MnbcSoundNum, AttenProfileCnt;
  40. unsigned char NewNmkKey[16], Nid[7];
  41. uint8_t get_V2G_Status_Name(uint8_t statusCode, char *statusName)
  42. {
  43. int result = PASS;
  44. switch(statusCode)
  45. {
  46. case IDLE:
  47. sprintf(statusName, "IDLE");
  48. break;
  49. case CM_SLAC_PARM_REQ:
  50. sprintf(statusName, "CM_SLAC_PARM_REQ");
  51. break;
  52. case CM_SLAC_PARM_CONF:
  53. sprintf(statusName, "CM_SLAC_PARM_CONF");
  54. break;
  55. case CM_START_ATTEN_CHAR_IND:
  56. sprintf(statusName, "CM_START_ATTEN_CHAR_IND");
  57. break;
  58. case CM_MNBC_SOUND_IND:
  59. sprintf(statusName, "CM_MNBC_SOUND_IND");
  60. break;
  61. case CM_ATTEN_CHAR_IND:
  62. sprintf(statusName, "CM_ATTEN_CHAR_IND");
  63. break;
  64. case CM_ATTEN_CHAR_RSP:
  65. sprintf(statusName, "CM_ATTEN_CHAR_RSP");
  66. break;
  67. case CM_VALIDATE_REQ:
  68. sprintf(statusName, "CM_VALIDATE_REQ");
  69. break;
  70. case CM_VALIDATE_CNF:
  71. sprintf(statusName, "CM_VALIDATE_CNF");
  72. break;
  73. case CM_SLAC_MATCH_REQ:
  74. sprintf(statusName, "CM_SLAC_MATCH_REQ");
  75. break;
  76. case CM_SLAC_MATCH_CNF:
  77. sprintf(statusName, "CM_SLAC_MATCH_CNF");
  78. break;
  79. case CM_AMP_MAP_REQ:
  80. sprintf(statusName, "CM_AMP_MAP_REQ");
  81. break;
  82. case CM_AMP_MAP_CNF:
  83. sprintf(statusName, "CM_AMP_MAP_CNF");
  84. break;
  85. case CM_SET_KEY_REQ:
  86. sprintf(statusName, "CM_SET_KEY_REQ");
  87. break;
  88. case CM_SET_KEY_CNF:
  89. sprintf(statusName, "CM_SET_KEY_CNF");
  90. break;
  91. case SLACC_SDP_UDP_Connection:
  92. sprintf(statusName, "SLACC_SDP_UDP_Connection");
  93. break;
  94. case SLACC_SDP_TCP_Connection:
  95. sprintf(statusName, "SLACC_SDP_TCP_Connection");
  96. break;
  97. case SupportedAppProtocolRequest:
  98. sprintf(statusName, "SupportedAppProtocolRequest");
  99. break;
  100. case SupportedAppProtocolResponse:
  101. sprintf(statusName, "SupportedAppProtocolResponse");
  102. break;
  103. case SessionSetupRequest:
  104. sprintf(statusName, "SessionSetupRequest");
  105. break;
  106. case SessionSetupResponse:
  107. sprintf(statusName, "UnSessionSetupResponseknown");
  108. break;
  109. case ServiceDiscoveryRequest:
  110. sprintf(statusName, "ServiceDiscoveryRequest");
  111. break;
  112. case ServiceDiscoveryResponse:
  113. sprintf(statusName, "ServiceDiscoveryResponse");
  114. break;
  115. case ServiceDetailRequest:
  116. sprintf(statusName, "ServiceDetailRequest");
  117. break;
  118. case ServiceDetailResponse:
  119. sprintf(statusName, "ServiceDetailResponse");
  120. break;
  121. case ServiceAndPaymentSelectionRequest:
  122. sprintf(statusName, "ServiceAndPaymentSelectionRequest");
  123. break;
  124. case ServiceAndPaymentSelectionResponse:
  125. sprintf(statusName, "ServiceAndPaymentSelectionResponse");
  126. break;
  127. case PaymentDetailsRequest:
  128. sprintf(statusName, "PaymentDetailsRequest");
  129. break;
  130. case PaymentDetailsResponse:
  131. sprintf(statusName, "PaymentDetailsResponse");
  132. break;
  133. case AuthorizationRequest:
  134. sprintf(statusName, "AuthorizationRequest");
  135. break;
  136. case AuthorizationResponse:
  137. sprintf(statusName, "AuthorizationResponse");
  138. break;
  139. case CertificateUpdateRequest:
  140. sprintf(statusName, "CertificateUpdateRequest");
  141. break;
  142. case CertificateUpdateResponse:
  143. sprintf(statusName, "CertificateUpdateResponse");
  144. break;
  145. case CertificateInstallationRequest:
  146. sprintf(statusName, "CertificateInstallationRequest");
  147. break;
  148. case CertificateInstallationResponse:
  149. sprintf(statusName, "CertificateInstallationResponse");
  150. break;
  151. case ChargeParameterDiscoveryRequest:
  152. sprintf(statusName, "ChargeParameterDiscoveryRequest");
  153. break;
  154. case ChargeParameterDiscoveryResponse:
  155. sprintf(statusName, "ChargeParameterDiscoveryResponse");
  156. break;
  157. case CableCheckRequest:
  158. sprintf(statusName, "CableCheckRequest");
  159. break;
  160. case CableCheckResponse:
  161. sprintf(statusName, "CableCheckResponse");
  162. break;
  163. case PreChargeRequest:
  164. sprintf(statusName, "PreChargeRequest");
  165. break;
  166. case PreChargeResponse:
  167. sprintf(statusName, "PreChargeResponse");
  168. break;
  169. case PowerDeliveryRequestStart:
  170. sprintf(statusName, "PowerDeliveryRequestStart");
  171. break;
  172. case PowerDeliveryResponsetStart:
  173. sprintf(statusName, "PowerDeliveryResponsetStart");
  174. break;
  175. case ChargingStatusRequest:
  176. sprintf(statusName, "ChargingStatusRequest");
  177. break;
  178. case ChargingStatusResponse:
  179. sprintf(statusName, "ChargingStatusResponse");
  180. break;
  181. case CurrentDemandRequest:
  182. sprintf(statusName, "CurrentDemandRequest");
  183. break;
  184. case CurrentDemandResponse:
  185. sprintf(statusName, "CurrentDemandResponse");
  186. break;
  187. case MeteringReceiptRequest:
  188. sprintf(statusName, "MeteringReceiptRequest");
  189. break;
  190. case MeteringReceiptResponse:
  191. sprintf(statusName, "MeteringReceiptResponse");
  192. break;
  193. case PowerDeliveryRequestStop:
  194. sprintf(statusName, "PowerDeliveryRequestStop");
  195. break;
  196. case PowerDeliveryResponseStop:
  197. sprintf(statusName, "PowerDeliveryResponseStop");
  198. break;
  199. case WeldingDetectionRequest:
  200. sprintf(statusName, "WeldingDetectionRequest");
  201. break;
  202. case WeldingDetectionResponse:
  203. sprintf(statusName, "WeldingDetectionResponse");
  204. break;
  205. case SessionStopRequest:
  206. sprintf(statusName, "SessionStopRequest");
  207. break;
  208. case SessionStopResponse:
  209. sprintf(statusName, "SessionStopResponse");
  210. break;
  211. case Performance_Timeout:
  212. sprintf(statusName, "Performance_Timeout");
  213. break;
  214. case Sequence_Timeout:
  215. sprintf(statusName, "Sequence_Timeout");
  216. break;
  217. case Other_Fault:
  218. sprintf(statusName, "Other_Fault");
  219. break;
  220. default:
  221. sprintf(statusName, "Unknown");
  222. result = FAIL;
  223. break;
  224. }
  225. return result;
  226. }
  227. /*===========================================================================
  228. FUNCTION: Check_V2G_Flow_Status
  229. DESCRIPTION:
  230. PRE-CONDITION:
  231. INPUT:
  232. OUTPUT:
  233. GLOBAL VARIABLES:
  234. =============================================================================*/
  235. unsigned char Check_V2G_Flow_Status()
  236. {
  237. unsigned char result = 0;
  238. switch (ShmCcsData->CommProtocol)
  239. {
  240. case V2GT_MSG_PROTOCOL_DIN70121: //0
  241. {
  242. result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
  243. break;
  244. }
  245. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  246. {
  247. result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
  248. break;
  249. }
  250. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  251. {
  252. result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
  253. break;
  254. }
  255. default:
  256. break;
  257. }
  258. return result;
  259. }
  260. /*===========================================================================
  261. FUNCTION: CAN_Tx_MSG
  262. DESCRIPTION:
  263. PRE-CONDITION:
  264. INPUT:
  265. OUTPUT:
  266. GLOBAL VARIABLES:
  267. =============================================================================*/
  268. int CAN_Tx_MSG(int Fd, unsigned int MsgId, unsigned char SlaveAddress, unsigned char DataLength, unsigned char *SendData)
  269. {
  270. #if 0
  271. struct can_frame frame;
  272. struct timeb StartTime, EndTime;
  273. unsigned int tmp = 0;
  274. int nbytes = 0;
  275. int i = 0;
  276. //Protection: To avoid unexpected length for CAN bus payload.
  277. if (DataLength > 8)
  278. {
  279. DataLength = 8;
  280. }
  281. memset(&frame, 0, sizeof(struct can_frame));
  282. frame.can_id = 0x80000000 | CAN_SEND_DIRECTION | MsgId | SlaveAddress; //0x80000000: extension ID format
  283. frame.can_dlc = DataLength;
  284. memcpy(frame.data, SendData, DataLength);
  285. nbytes = write(Fd, &frame, sizeof(struct can_frame));
  286. #if 0
  287. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][CAN_Tx_MSG] <%X> ", frame.can_id);
  288. for (i = 0; i < frame.can_dlc; i++)
  289. {
  290. DEBUG_PRINTF_EVCOMM_DETAIL("%02X ", frame.data[i]);
  291. }
  292. DEBUG_PRINTF_EVCOMM_DETAIL("(%d Bytes)\n", frame.can_dlc);
  293. #endif
  294. return nbytes;
  295. #else
  296. return -1;
  297. #endif
  298. }
  299. /*===========================================================================
  300. FUNCTION: Proc_EVStopRes
  301. DESCRIPTION:
  302. PRE-CONDITION:
  303. INPUT:
  304. OUTPUT:
  305. GLOBAL VARIABLES:
  306. =============================================================================*/
  307. int Proc_EVStopRes(int Fd)
  308. {
  309. int nbytes;
  310. unsigned char Buffer[8];
  311. memset(Buffer, 0, sizeof(Buffer));
  312. if (CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency == TRUE)
  313. {
  314. Buffer[0] = EV_EMERGENCY_STOP; //2
  315. }
  316. else
  317. {
  318. Buffer[0] = EV_NORMAL_STOP; //1
  319. }
  320. /*
  321. if(strlen(ShmStatusCodeData->PresentStatusCode[0]) > 0)
  322. {
  323. memcpy(Buffer + 2, ShmStatusCodeData->PresentStatusCode[0], 6);
  324. }
  325. */
  326. Buffer[1] = ShmStatusCodeData->PresentStatusCode[0][0];
  327. Buffer[2] = ShmStatusCodeData->PresentStatusCode[0][1];
  328. Buffer[3] = ShmStatusCodeData->PresentStatusCode[0][2];
  329. Buffer[4] = ShmStatusCodeData->PresentStatusCode[0][3];
  330. Buffer[5] = ShmStatusCodeData->PresentStatusCode[0][4];
  331. Buffer[6] = ShmStatusCodeData->PresentStatusCode[0][5];
  332. nbytes = CAN_Tx_MSG(Fd, CAN_CMD_EV_STOP_EVENT, ShmInternalComm->SlaveAddress, 7, Buffer);
  333. //system("echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle"); //for test only
  334. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  335. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_EVStopRes] Sending STOP Command to CSU");
  336. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = FALSE;
  337. return nbytes;
  338. }
  339. /*===========================================================================
  340. FUNCTION: Sniffer_Candump
  341. DESCRIPTION:
  342. 1. Only used in End_Process(), which is in fork2 of SeccComm task.
  343. PRE-CONDITION:
  344. INPUT:
  345. OUTPUT:
  346. 0: accept
  347. -1: invalid
  348. GLOBAL VARIABLES:
  349. =============================================================================*/
  350. int Sniffer_Candump(char cmd)
  351. {
  352. #if (CANDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  353. if (cmd == ENABLE)
  354. {
  355. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]init");
  356. system("cd /mnt/;rm -rf candump/");
  357. system("cd /mnt/;mkdir candump");
  358. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]on");
  359. system("cd /mnt/candump;candump -l can0 &");
  360. return 0;
  361. }
  362. else if (cmd == DISABLE)
  363. {
  364. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]off");
  365. system("killall candump");
  366. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]save");
  367. system("cd /;cp -rfv /mnt/candump /Storage/SystemLog/");
  368. return 0;
  369. }
  370. else
  371. {
  372. sprintf((char*)buf_log_evcomm_fork2, "[candump]unexpected cmd(%d)", cmd);
  373. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork2);
  374. return -1;
  375. }
  376. #endif
  377. return 0;
  378. }
  379. /*===========================================================================
  380. FUNCTION: Sniffer_Tcpdump
  381. DESCRIPTION:
  382. PRE-CONDITION:
  383. INPUT:
  384. OUTPUT:
  385. GLOBAL VARIABLES:
  386. =============================================================================*/
  387. int Sniffer_Tcpdump(char cmd)
  388. {
  389. #if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  390. if (cmd == ENABLE)
  391. {
  392. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]init...");
  393. system("cd /mnt/;rm -rf tcpdump/");
  394. system("cd /mnt/;mkdir tcpdump");
  395. unsigned char buf[256];
  396. time_t CurrentTime;
  397. struct tm *tm;
  398. struct timeval tv;
  399. memset(buf, 0, sizeof(buf));
  400. CurrentTime = time(NULL);
  401. tm = localtime(&CurrentTime);
  402. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  403. sprintf((char*)buf,
  404. "tcpdump -i eth1 -w /mnt/tcpdump/[%s][%04d%02d%02d-%02d:%02d:%02d.%06d]packets.pcap&",
  405. FIRMWARE_VERSION,
  406. tm->tm_year + 1900,
  407. tm->tm_mon + 1,
  408. tm->tm_mday,
  409. tm->tm_hour,
  410. tm->tm_min,
  411. tm->tm_sec,
  412. tv.tv_usec
  413. );
  414. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]on");
  415. system(buf);
  416. return 0;
  417. }
  418. else if (cmd == DISABLE)
  419. {
  420. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]off");
  421. system("killall tcpdump");
  422. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]wait: 2s");
  423. sleep(1);
  424. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]wait: 1s");
  425. sleep(1);
  426. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]save");
  427. system("cd /;cp -rfv /mnt/tcpdump /Storage/SystemLog/");
  428. return 0;
  429. }
  430. else
  431. {
  432. sprintf((char*)buf_log_evcomm, "[tcpdump]unexpected cmd(%d)", cmd);
  433. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  434. return -1;
  435. }
  436. #endif
  437. return 0;
  438. }
  439. /*===========================================================================
  440. FUNCTION: Check_V2G_Flow_Status_pre
  441. DESCRIPTION:
  442. PRE-CONDITION:
  443. INPUT:
  444. OUTPUT:
  445. GLOBAL VARIABLES:
  446. =============================================================================*/
  447. unsigned char Check_V2G_Flow_Status_pre()
  448. {
  449. unsigned char result = 0;
  450. switch (ShmCcsData->CommProtocol)
  451. {
  452. case V2GT_MSG_PROTOCOL_DIN70121: //0
  453. {
  454. result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus_pre;
  455. break;
  456. }
  457. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  458. {
  459. result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus_pre;
  460. break;
  461. }
  462. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  463. {
  464. result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus_pre;
  465. break;
  466. }
  467. default:
  468. break;
  469. }
  470. return result;
  471. }
  472. /*===========================================================================
  473. FUNCTION: Update_V2G_Flow_Status
  474. DESCRIPTION:
  475. PRE-CONDITION:
  476. INPUT:
  477. OUTPUT:
  478. 1. V2gFlowStatus
  479. GLOBAL VARIABLES:
  480. 1. V2gFlowStatus
  481. =============================================================================*/
  482. int Update_V2G_Flow_Status(unsigned int state_new)
  483. {
  484. unsigned char state_now;
  485. char nameNow[64], nameNew[64];
  486. state_now = Check_V2G_Flow_Status();
  487. get_V2G_Status_Name(state_now, nameNow);
  488. get_V2G_Status_Name(state_new, nameNew);
  489. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE ||
  490. CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused == TRUE)
  491. {
  492. if (state_now != Performance_Timeout && //253
  493. state_now != Sequence_Timeout && //254
  494. state_now != Other_Fault) //255
  495. {
  496. sprintf((char*)buf_log_evcomm,
  497. "[Warning]state-%s(%d) change: ignored (End_Process_inused:%d, FW_Update_Task_inused:%d)",
  498. nameNew, state_new,
  499. EVCOMM_SYS_INFO.End_Process_inused,
  500. CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused
  501. );
  502. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  503. return -1;
  504. }
  505. }
  506. if (state_now != state_new)
  507. {
  508. //Step 1: Check if Error Occours
  509. if (state_now == Performance_Timeout || //253
  510. state_now == Sequence_Timeout || //254
  511. state_now == Other_Fault) //255
  512. {
  513. if (state_new != IDLE)
  514. {
  515. if (EVCOMM_SYS_INFO.State_Change_Ignored_Notice == FALSE)
  516. {
  517. EVCOMM_SYS_INFO.State_Change_Ignored_Notice = TRUE;
  518. sprintf((char*)buf_log_evcomm,
  519. "[Warning]state-%s(%d) change: ignored(now in error state-%s(%d))",
  520. nameNow, state_new,
  521. nameNew, state_now);
  522. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  523. }
  524. return -1;
  525. }
  526. }
  527. //Updating the state formally.
  528. sprintf((char*)buf_log_evcomm,
  529. "%s(%02d) >> %s(%02d)",
  530. nameNow, state_now,
  531. nameNew, state_new
  532. );
  533. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  534. V2gFlowStatus = state_new;
  535. state_now = state_new;
  536. switch (ShmCcsData->CommProtocol)
  537. {
  538. case V2GT_MSG_PROTOCOL_DIN70121: //0
  539. {
  540. ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
  541. ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus = V2gFlowStatus;
  542. break;
  543. }
  544. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  545. {
  546. ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
  547. ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus = V2gFlowStatus;
  548. break;
  549. }
  550. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  551. {
  552. ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
  553. ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus = V2gFlowStatus;
  554. break;
  555. }
  556. default:
  557. break;
  558. }
  559. }
  560. return 0;
  561. }
  562. double DiffTimeb(struct timeb ST, struct timeb ET)
  563. {
  564. //return milli-second
  565. double StartTime, EndTime;
  566. double t_diff;
  567. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  568. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  569. t_diff = EndTime - StartTime;
  570. if (t_diff < 0)
  571. {
  572. #if 0
  573. if (t_diff < -1000) //1000ms
  574. {
  575. sprintf((char*)buf_log_evcomm,
  576. "[Warning]StartTime(%.02lf) > EndTime(%.02lf), d(%.02lf)",
  577. StartTime,
  578. EndTime,
  579. t_diff);
  580. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  581. }
  582. #endif
  583. return -1;
  584. }
  585. return t_diff;
  586. }
  587. double DiffTimeb_fork1_Error_Monitor(struct timeb ST, struct timeb ET)
  588. {
  589. //return milli-second
  590. static double StartTime, EndTime;
  591. static double t_diff;
  592. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  593. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  594. t_diff = EndTime - StartTime;
  595. if (t_diff < 0)
  596. {
  597. #if 0
  598. if (t_diff < -1000) //1000ms
  599. {
  600. sprintf((char*)buf_log_evcomm_fork2,
  601. "[fork1][Warning]S(%.02lf) > E(%.02lf), d(%.02lf)",
  602. StartTime,
  603. EndTime,
  604. t_diff);
  605. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork2);
  606. }
  607. #endif
  608. return -1;
  609. }
  610. return t_diff;
  611. }
  612. double DiffTimeb_fork2_Error_Monitor(struct timeb ST, struct timeb ET)
  613. {
  614. //return milli-second
  615. static double StartTime, EndTime;
  616. static double t_diff;
  617. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  618. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  619. t_diff = EndTime - StartTime;
  620. if (t_diff < 0)
  621. {
  622. #if 0
  623. if (t_diff < -1000) //1000ms
  624. {
  625. sprintf((char*)buf_log_evcomm_fork2,
  626. "[fork2][Warning]S(%.02lf) > E(%.02lf), d(%.02lf)",
  627. StartTime,
  628. EndTime,
  629. t_diff);
  630. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork2);
  631. }
  632. #endif
  633. return -1;
  634. }
  635. return t_diff;
  636. }
  637. int CreateShareMemory()
  638. {
  639. int MeterSMId;
  640. //create ShmSysConfigAndInfo
  641. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
  642. {
  643. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmget ShmSysConfigAndInfo NG");
  644. return 0;
  645. }
  646. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  647. {
  648. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmat ShmSysConfigAndInfo NG");
  649. return 0;
  650. }
  651. memset(ShmSysConfigAndInfo,0,sizeof(struct SysConfigAndInfo));
  652. //create ShmStatusCodeData
  653. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
  654. {
  655. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmget ShmStatusCodeData NG");
  656. return 0;
  657. }
  658. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  659. {
  660. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmat ShmStatusCodeData NG");
  661. return 0;
  662. }
  663. memset(ShmStatusCodeData,0,sizeof(struct StatusCodeData));
  664. //create ShmCcsData
  665. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
  666. {
  667. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmget ShmCcsData NG");
  668. return 0;
  669. }
  670. else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  671. {
  672. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmat ShmCcsData NG");
  673. return 0;
  674. }
  675. memset(ShmCcsData,0,sizeof(struct CcsData));
  676. return 1;
  677. }
  678. /*===========================================================================
  679. FUNCTION: ShareMemory_Init
  680. DESCRIPTION:
  681. PRE-CONDITION:
  682. INPUT:
  683. OUTPUT:
  684. GLOBAL VARIABLES:
  685. =============================================================================*/
  686. int ShareMemory_Init()
  687. {
  688. int MeterSMId;
  689. //create ShmSysConfigAndInfo
  690. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
  691. {
  692. DEBUG_ERROR("ShareMemory_Init:shmget ShmSysConfigAndInfo NG");
  693. return 0;
  694. }
  695. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  696. {
  697. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "ShareMemory_Init:shmat ShmSysConfigAndInfo NG");
  698. return 0;
  699. }
  700. //create ShmStatusCodeData
  701. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
  702. {
  703. DEBUG_ERROR("ShareMemory_Init:shmget ShmStatusCodeData NG");
  704. return 0;
  705. }
  706. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  707. {
  708. DEBUG_ERROR("ShareMemory_Init:shmat ShmStatusCodeData NG");
  709. return 0;
  710. }
  711. //create ShmCcsData
  712. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
  713. {
  714. DEBUG_ERROR("ShareMemory_Init:shmget ShmCcsData NG");
  715. return 0;
  716. }
  717. else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  718. {
  719. DEBUG_ERROR("ShareMemory_Init:shmat ShmCcsData NG");
  720. return 0;
  721. }
  722. //create ShmInternalComm
  723. if ((MeterSMId = shmget(ShmInternalCommKey, sizeof(struct InternalComm), IPC_CREAT | 0777)) < 0)
  724. {
  725. DEBUG_ERROR("ShareMemory_Init:shmget ShmInternalComm NG");
  726. return 0;
  727. }
  728. else if ((ShmInternalComm = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  729. {
  730. DEBUG_ERROR("ShareMemory_Init:shmat ShmInternalComm NG");
  731. return 0;
  732. }
  733. //Initial ShmCharger
  734. if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
  735. {
  736. DEBUG_ERROR("shmget ShmChargerKey NG\r\n");
  737. return 0;
  738. }
  739. else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  740. {
  741. DEBUG_ERROR("shmat ShmChargerKey NG\r\n");
  742. return 0;
  743. }
  744. //[To-Do] The initialization here is reduntant and should be removed partially.
  745. //SHM_Init_supportedAppProtocolRes(ShmCcsData);
  746. //SHM_Init_din_SessionSetupRes(ShmCcsData);
  747. //SHM_Init_din_ServiceDiscoveryRes(ShmCcsData);
  748. //SHM_Init_din_ServiceAndPaymentSelectionRes(ShmCcsData);
  749. //SHM_Init_din_ContractAuthenticationRes(ShmCcsData);
  750. SHM_Init_din_ChargeParameterDiscoveryRes(ShmCcsData);
  751. SHM_Init_din_CableCheckRes(ShmCcsData);
  752. SHM_Init_din_PreChargeRes(ShmCcsData);
  753. SHM_Init_din_PowerDeliveryRes(ShmCcsData);
  754. SHM_Init_din_CurrentDemandRes(ShmCcsData);
  755. SHM_Init_din_WeldingDetectionRes(ShmCcsData);
  756. SHM_Init_din_SessionStopRes(ShmCcsData);
  757. return 1;
  758. }
  759. /*===========================================================================
  760. FUNCTION: GetEthMac
  761. DESCRIPTION:
  762. 1. Accessing current CsuMac address, if Eth = eth1
  763. 2. The address of eth1(for QCA7000) is a random number, which will be modified
  764. after each time of booting up system.
  765. PRE-CONDITION:
  766. INPUT:
  767. OUTPUT:
  768. GLOBAL VARIABLES:
  769. =============================================================================*/
  770. int GetEthMac(unsigned char *Eth, unsigned char *mac)
  771. {
  772. //Parameters:MAC,IP,Mask,Gateway
  773. int fd;
  774. unsigned char addr[18], Buffer[128];
  775. memset(Buffer, 0, sizeof(Buffer));
  776. sprintf((char*)Buffer, "cat /sys/class/net/%s/address > /mnt/GetEthInfo", Eth); //CsuMac (Eth = eth1)
  777. system((char*)Buffer);
  778. fd = open("/mnt/GetEthInfo", O_RDONLY);
  779. if(fd < 0)
  780. {
  781. system("rm -f /mnt/GetEthInfo");
  782. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "GetEthMac: MAC Address open error");
  783. return 0;
  784. }
  785. memset(mac, 0, 6);
  786. memset(addr, 0, sizeof(addr));
  787. read(fd, addr, 17);
  788. close(fd);
  789. system("rm -f /mnt/GetEthInfo");
  790. 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)
  791. sprintf((char*)buf_log_evcomm,
  792. "[GetEthMac]EVSE MACAddr(CsuMac): %02x:%02x:%02x:%02x:%02x:%02x",
  793. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); //CsuMac (Eth = eth1)
  794. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  795. return 1;
  796. }
  797. /*===========================================================================
  798. FUNCTION: ReadAdcVolt
  799. DESCRIPTION:
  800. 1. fork1
  801. PRE-CONDITION:
  802. INPUT:
  803. OUTPUT:
  804. GLOBAL VARIABLES:
  805. =============================================================================*/
  806. float ReadAdcVolt(unsigned char AdcChannel)
  807. {
  808. //AIN0=CCS GUN Temp 1
  809. //AIN1=CCS GUN Temp 2
  810. //AIN2=CCS_Proximity/2
  811. //AIN3=pilot voltage
  812. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  813. return 0;
  814. #else
  815. if(AdcChannel == 3)
  816. {
  817. int fd,count,AvgTimes;
  818. unsigned char SampleBuf[4];
  819. float TmpVolt, MinSample, AvgSample = 0;
  820. fd = open("/sys/bus/iio/devices/iio\\:device0/in_voltage3_raw", O_RDONLY);
  821. if(fd > 0)
  822. {
  823. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  824. for(AvgTimes = 0; AvgTimes < 3; AvgTimes++) //period = 60~91 ms(renice -10, , CurrentDemand())
  825. {
  826. count = 0;
  827. MinSample = 2306;
  828. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  829. while(count < 30) //period = 21~42ms (renice -10, CurrentDemand())
  830. {
  831. //re-sampling period = 3~13ms (renice -10, SLAC())
  832. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  833. read(fd, SampleBuf, 4); //period = 3.2~10ms (renice -10, SLAC())
  834. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  835. TmpVolt = atoi((char*)SampleBuf);
  836. if((TmpVolt < 2306) && (TmpVolt > 0))//positive voltage
  837. {
  838. if(TmpVolt < MinSample)
  839. {
  840. MinSample = TmpVolt;
  841. }
  842. count++;
  843. }
  844. lseek(fd, 0, SEEK_SET);
  845. }
  846. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  847. AvgSample += MinSample;
  848. }
  849. AvgSample /= AvgTimes;
  850. close(fd);
  851. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  852. return ((0.954-(1.8*AvgSample/4095))/0.06);
  853. }
  854. else
  855. {
  856. return -1;
  857. }
  858. }
  859. else
  860. {
  861. FILE *fp;
  862. unsigned char str[64];
  863. unsigned char AdcValue[8];
  864. if(AdcChannel > 7)
  865. {
  866. return -1;
  867. }
  868. memset(str,0,sizeof(str));
  869. memset(AdcValue,0,sizeof(AdcValue));
  870. sprintf((char*)str, "cat /sys/bus/iio/devices/iio\\:device0/in_voltage%d_raw", AdcChannel);
  871. fp=popen((char*)str, "r");
  872. if(fgets((char*)AdcValue,sizeof(AdcValue),fp) == NULL)
  873. {
  874. pclose(fp);
  875. return -1;
  876. }
  877. pclose(fp);
  878. //Vin = Vref *D / (2^n - 1)
  879. return ((float)1.8*(float)atoi((char*)AdcValue))/4095;
  880. }
  881. #endif
  882. }
  883. /*===========================================================================
  884. FUNCTION: ReadAdcVolt
  885. DESCRIPTION:
  886. //AIN0=CCS GUN Temp 1
  887. //AIN1=CCS GUN Temp 2
  888. //AIN2=CCS_Proximity/2
  889. //AIN3=pilot voltage
  890. PRE-CONDITION:
  891. INPUT:
  892. OUTPUT:
  893. GLOBAL VARIABLES:
  894. =============================================================================*/
  895. float ReadAdcVolt_PP_fork3()
  896. {
  897. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  898. return 0;
  899. #else
  900. int fd, AvgTimes;
  901. unsigned char SampleBuf[4];
  902. float TmpVolt = 0;
  903. float AvgSample = 0;
  904. float V_pp = 0;
  905. fd = open("/sys/bus/iio/devices/iio\\:device0/in_voltage2_raw", O_RDONLY); //PP
  906. if(fd > 0)
  907. {
  908. for(AvgTimes = 0; AvgTimes < 5; AvgTimes++) //get 5 samples
  909. {
  910. read(fd, SampleBuf, 4);
  911. TmpVolt = atoi((char*)SampleBuf);
  912. lseek(fd, 0, SEEK_SET);
  913. AvgSample += TmpVolt;
  914. }
  915. close(fd);
  916. AvgSample /= AvgTimes;
  917. V_pp = (3.6*AvgSample)/4095; //PP
  918. #if 0
  919. printf("PP_adc = %.02f, PP_v = %.02f\n", AvgSample, V_pp);
  920. usleep(3000000); //300ms
  921. #endif
  922. usleep(20000); //20ms
  923. return V_pp;
  924. }
  925. else
  926. {
  927. return -1;
  928. }
  929. #endif
  930. }
  931. /*===========================================================================
  932. FUNCTION: Qca7kPowerReset
  933. DESCRIPTION:
  934. PRE-CONDITION:
  935. INPUT:
  936. OUTPUT:
  937. GLOBAL VARIABLES:
  938. =============================================================================*/
  939. void Qca7kPowerReset()
  940. {
  941. printf("\n[CCS Board]Reset QCA7000...\n");
  942. system("echo 1 > /sys/class/gpio/gpio88/value");
  943. usleep(500000);
  944. system("echo 0 > /sys/class/gpio/gpio88/value");
  945. }
  946. /*===========================================================================
  947. FUNCTION: SwitchCpStateE
  948. DESCRIPTION:
  949. PRE-CONDITION:
  950. INPUT:
  951. OUTPUT:
  952. GLOBAL VARIABLES:
  953. =============================================================================*/
  954. int SwitchCpStateE(unsigned char OnOff)
  955. {
  956. /*
  957. * TODO: Request CP change to state E
  958. */
  959. if((OnOff != ENABLE) && (OnOff != DISABLE))
  960. {
  961. return -1;
  962. }
  963. struct ChargingInfoData *ccs;
  964. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  965. ccs->SwitchCpStateE_status = OnOff;
  966. //OnOff = 1 => switch State to E
  967. //OnOff = 0 => return noraml
  968. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  969. {
  970. if(OnOff == DISABLE)
  971. {
  972. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: released\n");
  973. CSUCOMMAC_SHM.CpSetStateE = DISABLE;
  974. }
  975. else
  976. {
  977. OutputCpPwmDuty(100); //set CP duty as 100, firstly.
  978. CSUCOMMAC_SHM.CpSetStateE = ENABLE;
  979. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: enabled!\n");
  980. }
  981. }
  982. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  983. {
  984. if(OnOff == DISABLE)
  985. {
  986. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: released\n");
  987. system("echo 0 > /sys/class/gpio/gpio86/value");
  988. }
  989. else
  990. {
  991. OutputCpPwmDuty(100); //set CP duty as 100, firstly.
  992. system("echo 1 > /sys/class/gpio/gpio86/value");
  993. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: enabled!\n");
  994. }
  995. }
  996. #endif
  997. if (ccs->SwitchCpStateE_status_pre != ccs->SwitchCpStateE_status)
  998. {
  999. sprintf((char*)buf_log_evcomm,
  1000. "SwitchCpStateE: %d >> %d",
  1001. ccs->SwitchCpStateE_status_pre,
  1002. ccs->SwitchCpStateE_status
  1003. );
  1004. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  1005. ccs->SwitchCpStateE_status_pre = ccs->SwitchCpStateE_status;
  1006. }
  1007. return 0;
  1008. }
  1009. /*===========================================================================
  1010. FUNCTION: OutputCpPwmDuty
  1011. DESCRIPTION:
  1012. PRE-CONDITION:
  1013. INPUT:
  1014. OUTPUT:
  1015. GLOBAL VARIABLES:
  1016. =============================================================================*/
  1017. int OutputCpPwmDuty(unsigned char Duty)
  1018. {
  1019. #if ((CCS_ENERGY_TRANSFER_MODE != MODE_AC_SINGLE_PHASE_CORE) && (CCS_ENERGY_TRANSFER_MODE != MODE_AC_THREE_PHASE_CORE))
  1020. int DutyInNanoSec;
  1021. #endif
  1022. struct ChargingInfoData *ccs;
  1023. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1024. if((Duty < 0)||(Duty > 100))
  1025. {
  1026. return -1;
  1027. }
  1028. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  1029. {
  1030. CSUCOMMAC_SHM.CpSetPWMDuty = Duty;
  1031. }
  1032. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  1033. {
  1034. DutyInNanoSec = 10000 * Duty;
  1035. sprintf((char*)buf_log_evcomm, "echo %d > /sys/class/pwm/pwmchip0/pwm0/duty_cycle", DutyInNanoSec);//nanoseconds
  1036. system((char*)buf_log_evcomm);
  1037. }
  1038. #endif
  1039. ccs->CpDuty = Duty;
  1040. //CP Duty
  1041. if (ccs->CpDuty != ccs->CpDuty_pre)
  1042. {
  1043. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  1044. sprintf((char*)buf_log_evcomm, "CP Duty: %d %% >> %d %%", ccs->CpDuty_pre, ccs->CpDuty);
  1045. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  1046. ccs->CpDuty_pre = ccs->CpDuty;
  1047. }
  1048. return 0;
  1049. }
  1050. /*===========================================================================
  1051. FUNCTION: Check_Plugin_Status_Update_fork1
  1052. DESCRIPTION:
  1053. PRE-CONDITION:
  1054. INPUT:
  1055. OUTPUT:
  1056. GLOBAL VARIABLES:
  1057. =============================================================================*/
  1058. //#if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  1059. void Check_Plugin_Status_Update_fork1(struct ChargingInfoData *ccs)
  1060. {
  1061. if (ccs->ConnectorPlugIn != ccs->ConnectorPlugIn_new)
  1062. {
  1063. sprintf((char*)buf_log_evcomm_fork1, "[fork1]Plugin: %d >> %d (CP=%.2fV, PP=%.2fV)",
  1064. ccs->ConnectorPlugIn,
  1065. ccs->ConnectorPlugIn_new,
  1066. ccs->CpVoltage,
  1067. ccs->PpVoltage
  1068. );
  1069. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork1);
  1070. ccs->ConnectorPlugIn_pre = ccs->ConnectorPlugIn;
  1071. ccs->ConnectorPlugIn = ccs->ConnectorPlugIn_new;
  1072. //ccs->CpVoltage_pre = ccs->CpVoltage;
  1073. }
  1074. }
  1075. //#endif
  1076. /*===========================================================================
  1077. FUNCTION: ConnectorPlugIn
  1078. DESCRIPTION:
  1079. PRE-CONDITION:
  1080. INPUT:
  1081. OUTPUT:
  1082. 0: Unplug
  1083. 1: Plug-in
  1084. GLOBAL VARIABLES:
  1085. =============================================================================*/
  1086. int CheckConnectorPlugIn()
  1087. {
  1088. /*
  1089. * TODO: Return connector status depedon CP
  1090. */
  1091. static struct ChargingInfoData *ccs;
  1092. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1093. #if (CP_PROTECTION_MECHANISM == ENABLE)
  1094. return (int)ccs->ConnectorPlugIn;
  1095. #else
  1096. return TRUE;
  1097. #endif
  1098. }
  1099. /*===========================================================================
  1100. FUNCTION: Check_CP_State_Error_fork1
  1101. DESCRIPTION:
  1102. PRE-CONDITION:
  1103. INPUT:
  1104. OUTPUT:
  1105. GLOBAL VARIABLES:
  1106. =============================================================================*/
  1107. int Check_CP_State_Error_fork1(struct ChargingInfoData *ccs)
  1108. {
  1109. #if (CP_PROTECTION_MECHANISM == DISABLE)
  1110. {
  1111. return -1;
  1112. }
  1113. #endif
  1114. unsigned char state = 0;
  1115. #if ((CCS_ENERGY_TRANSFER_MODE != MODE_AC_SINGLE_PHASE_CORE) && (CCS_ENERGY_TRANSFER_MODE != MODE_AC_THREE_PHASE_CORE))
  1116. double time_diff = 0;
  1117. #endif
  1118. state = Check_V2G_Flow_Status();
  1119. //SLAC, SLAAC, SDP, ..., ChargeParameterDiscovery
  1120. if (state >= CM_SLAC_PARM_CONF && //by considering 15118(SLAC first)
  1121. state < ChargeParameterDiscoveryRequest &&
  1122. state != IDLE &&
  1123. state != CM_SET_KEY_REQ &&
  1124. state != CM_SET_KEY_CNF &&
  1125. state != CM_VALIDATE_REQ &&
  1126. state != CM_VALIDATE_CNF)
  1127. {
  1128. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  1129. {
  1130. if((ccs->CpState != 2) && (ccs->CpState != 3))
  1131. {
  1132. if (ccs->CpState_err == FALSE)
  1133. {
  1134. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork1][CP][Error]before CPD"); //CPD: ChargeParameterDiscoveryRequest
  1135. //CPD: ChargeParameterDiscovery
  1136. }
  1137. ccs->CpState_err = TRUE;
  1138. }
  1139. }
  1140. #else
  1141. {
  1142. if(ccs->CpState != 3)
  1143. {
  1144. if (ccs->CpState_err == FALSE)
  1145. {
  1146. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork1][CP][Error]before CPD"); //CPD: ChargeParameterDiscoveryRequest
  1147. //CPD: ChargeParameterDiscovery
  1148. }
  1149. ccs->CpState_err = TRUE;
  1150. }
  1151. }
  1152. #endif
  1153. }
  1154. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  1155. {
  1156. //ChargeParameterDiscovery
  1157. if(state >= ChargeParameterDiscoveryRequest && //35
  1158. state <= ChargeParameterDiscoveryResponse) //36
  1159. {
  1160. if(ccs->CpState != 3)
  1161. {
  1162. if (ccs->CpState_err == FALSE)
  1163. {
  1164. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CP][Error]CPD");
  1165. //PRC: Precharge
  1166. //CUD: CurrentDemand
  1167. }
  1168. ccs->CpState_err = TRUE;
  1169. }
  1170. }
  1171. //ChargingStatus
  1172. if(state >= ChargingStatusRequest && //43
  1173. state <= ChargingStatusResponse) //44
  1174. {
  1175. if(ccs->CpState != 4 && ccs->CpState != 5)
  1176. {
  1177. if (ccs->CpState_err == FALSE)
  1178. {
  1179. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CP][Error]CGS");
  1180. //PRC: Precharge
  1181. //CUD: CurrentDemand
  1182. }
  1183. ccs->CpState_err = TRUE;
  1184. }
  1185. }
  1186. }
  1187. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  1188. {
  1189. //ChargeParameterDiscovery, CableCheck
  1190. if (state >= ChargeParameterDiscoveryRequest && //35
  1191. state <= CableCheckResponse) //38
  1192. {
  1193. if(ccs->CableCheckPreCountDownDone == FALSE &&
  1194. state >= CableCheckRequest)
  1195. {
  1196. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  1197. time_diff = DiffTimeb_fork1_Error_Monitor(EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start, EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  1198. if(time_diff >= V2G_SECC_CP_Timeout_CableCheck) //2 sec
  1199. {
  1200. sprintf((char*)buf_log_evcomm_fork1,
  1201. "[fork1][CP]check C(4),D(5): ON (%.02lf of %dms)",
  1202. time_diff,
  1203. V2G_SECC_CP_Timeout_CableCheck);
  1204. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork1);
  1205. ccs->CableCheckPreCountDownDone = TRUE;
  1206. }
  1207. }
  1208. if(ccs->CableCheckPreCountDownDone == TRUE)
  1209. {
  1210. if(ccs->CpState != 4 && ccs->CpState != 5)
  1211. {
  1212. if (ccs->CpState_err == FALSE)
  1213. {
  1214. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CP][Error]CPD and CCK (after CNT)");
  1215. //CPD: ChargeParameterDiscovery
  1216. //CCK: CableCheck
  1217. //CNT: count down
  1218. }
  1219. ccs->CpState_err = TRUE;
  1220. }
  1221. }
  1222. else
  1223. {
  1224. if(ccs->CpState != 3 && ccs->CpState != 4 && ccs->CpState != 5)
  1225. {
  1226. if (ccs->CpState_err == FALSE)
  1227. {
  1228. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CP][Error]CPD and CCK (before CNT)");
  1229. //CPD: ChargeParameterDiscovery
  1230. //CCK: CableCheck
  1231. //CNT: count down
  1232. }
  1233. ccs->CpState_err = TRUE;
  1234. }
  1235. }
  1236. }
  1237. //Precharge, CurrentDemand
  1238. if(state >= PreChargeRequest && //39
  1239. state <= CurrentDemandResponse) //46
  1240. {
  1241. if(ccs->CpState != 4 && ccs->CpState != 5)
  1242. {
  1243. if (ccs->CpState_err == FALSE)
  1244. {
  1245. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CP][Error]PRC and CUD");
  1246. //PRC: Precharge
  1247. //CUD: CurrentDemand
  1248. }
  1249. ccs->CpState_err = TRUE;
  1250. }
  1251. }
  1252. }
  1253. #endif
  1254. if(ccs->CpState_err == TRUE && ccs->CpState_err_logged == FALSE)
  1255. {
  1256. OutputCpPwmDuty(100);
  1257. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  1258. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1259. //CCS_SECC_CP_State_Error (023889)
  1260. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1261. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1262. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1263. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1264. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1265. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1266. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1267. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1268. sprintf((char*)buf_log_evcomm_fork1, "[fork1][Erorr]CP(%d) Error in state %d(%d)",
  1269. ccs->CpState,
  1270. state,
  1271. ccs->CableCheckPreCountDownDone
  1272. );
  1273. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork1);
  1274. ccs->CpState_err_logged = TRUE;
  1275. }
  1276. return 0;
  1277. }
  1278. /*===========================================================================
  1279. FUNCTION: Check_CP_State_Update_fork1
  1280. DESCRIPTION:
  1281. PRE-CONDITION:
  1282. INPUT:
  1283. OUTPUT:
  1284. GLOBAL VARIABLES:
  1285. =============================================================================*/
  1286. //#if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  1287. void Check_CP_State_Update_fork1(struct ChargingInfoData *ccs)
  1288. {
  1289. //CP State
  1290. if (ccs->CpState != ccs->CpState_pre)
  1291. {
  1292. sprintf((char*)buf_log_evcomm_fork1, "[fork1]CP State: %d >> %d (%.2fV)",
  1293. ccs->CpState_pre,
  1294. ccs->CpState,
  1295. ccs->CpVoltage
  1296. );
  1297. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork1);
  1298. ccs->CpState_pre = ccs->CpState;
  1299. }
  1300. }
  1301. //#endif
  1302. /*===========================================================================
  1303. FUNCTION: CP_Detection
  1304. DESCRIPTION:
  1305. 1. In order to detect CP in efficient response time, we creat an independent
  1306. thead for this procedure.
  1307. 2. The priority of this thread is set as the same as other tasks.
  1308. 3. fork1
  1309. PRE-CONDITION:
  1310. INPUT:
  1311. OUTPUT:
  1312. GLOBAL VARIABLES:
  1313. =============================================================================*/
  1314. void CP_Detection()
  1315. {
  1316. pid_t tmp = 0;
  1317. // struct timeb StartTime, EndTime;
  1318. #if ((CCS_ENERGY_TRANSFER_MODE != MODE_AC_SINGLE_PHASE_CORE) && (CCS_ENERGY_TRANSFER_MODE != MODE_AC_THREE_PHASE_CORE))
  1319. unsigned char Statetmp;
  1320. float TotalTmpVolt;
  1321. #endif
  1322. struct ChargingInfoData *ccs;
  1323. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1324. if(CP_Detection_Pid == 0)
  1325. {
  1326. tmp = fork();
  1327. if(tmp > 0)
  1328. {
  1329. CP_Detection_Pid = tmp;
  1330. #if 1
  1331. unsigned char buf[64];
  1332. memset(buf, 0, sizeof(buf));
  1333. //sprintf((char*)buf, "renice -20 -p %d", tmp);
  1334. sprintf((char*)buf, "renice -10 -p %d", tmp);
  1335. system((char*)buf);
  1336. #endif
  1337. return;
  1338. }
  1339. }
  1340. while(1)
  1341. {
  1342. //ADC_Voltage = (1+RE62/RE63)*0.9 - (RE62/RE63)*Pilot_Voltage, RE62/RE63=0.06
  1343. //=>Pilot_Voltage=(0.954-ADC_Voltage)/0.06
  1344. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  1345. {
  1346. ccs->CpVoltage = ShmInternalComm->AC_CpPositiveVoltage;
  1347. ccs->CpState = ShmInternalComm->AC_CpPresentState;
  1348. }
  1349. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  1350. {
  1351. TotalTmpVolt = ReadAdcVolt(3);
  1352. ccs->CpVoltage = TotalTmpVolt;
  1353. if (ccs->CpVoltage_pre != ccs->CpVoltage)
  1354. {
  1355. ccs->CpVoltage_pre = ccs->CpVoltage;
  1356. }
  1357. //printf("TotalTmpVolt = %.02f\n", TotalTmpVolt);
  1358. //If CP voltage is higer than 13.5V
  1359. if(TotalTmpVolt >= 13.5)
  1360. {
  1361. //Pilot Error
  1362. if((ccs->CpState == 1) &&
  1363. (TotalTmpVolt < 13.75))
  1364. {
  1365. //V_cp = 13.5 ~ 13.75
  1366. Statetmp = 1;
  1367. }
  1368. else
  1369. {
  1370. //V_cp = 13.5 ~
  1371. Statetmp = 8;
  1372. }
  1373. }
  1374. else if((TotalTmpVolt >= 10.5) && (TotalTmpVolt < 13.5)) //V_cp = 10.5 ~ 13.5
  1375. {
  1376. //State A (12V)
  1377. if((ccs->CpState >= 2) &&
  1378. (ccs->CpState <= 3) &&
  1379. (TotalTmpVolt < 10.75))
  1380. {
  1381. if((ccs->CpDuty >= 5) &&
  1382. (ccs->CpDuty < 100))
  1383. {
  1384. Statetmp = 3;
  1385. }
  1386. else
  1387. {
  1388. Statetmp = 2;
  1389. }
  1390. }
  1391. else if((ccs->CpState == 8) &&
  1392. (TotalTmpVolt >= 13.25))
  1393. {
  1394. Statetmp = 8;
  1395. }
  1396. else
  1397. {
  1398. Statetmp = 1;
  1399. }
  1400. }
  1401. else if((TotalTmpVolt >= 7.5) && (TotalTmpVolt < 10.5))
  1402. {
  1403. //State B (9V)
  1404. if((ccs->CpState == 4) && (TotalTmpVolt < 7.75))
  1405. {
  1406. Statetmp = 4;
  1407. }
  1408. else if((ccs->CpState == 1) && (TotalTmpVolt >= 10.25))
  1409. {
  1410. Statetmp = 1;
  1411. }
  1412. else
  1413. {
  1414. if((ccs->CpDuty >= 5) && (ccs->CpDuty < 100))
  1415. {
  1416. Statetmp = 3;
  1417. }
  1418. else
  1419. {
  1420. Statetmp = 2;
  1421. }
  1422. }
  1423. }
  1424. else if((TotalTmpVolt >= 4.5) && (TotalTmpVolt < 7.5))
  1425. {
  1426. //State C (6V)
  1427. if((ccs->CpState == 5) && (TotalTmpVolt < 4.75))
  1428. {
  1429. Statetmp = 5;
  1430. }
  1431. else if((ccs->CpState >= 2) && (ccs->CpState <= 3) && (TotalTmpVolt >= 7.25))
  1432. {
  1433. if((ccs->CpDuty >= 5)&&(ccs->CpDuty < 100))
  1434. {
  1435. Statetmp = 3;
  1436. }
  1437. else
  1438. {
  1439. Statetmp = 2;
  1440. }
  1441. }
  1442. else
  1443. {
  1444. Statetmp = 4;
  1445. }
  1446. }
  1447. else if((TotalTmpVolt >= 1.5) && (TotalTmpVolt < 4.5))
  1448. {
  1449. //State D (3V)
  1450. if((ccs->CpState == 6)&&(TotalTmpVolt < 1.75))
  1451. {
  1452. Statetmp = 6;
  1453. }
  1454. else if((ccs->CpState == 4)&&(TotalTmpVolt >= 4.25))
  1455. {
  1456. Statetmp = 4;
  1457. }
  1458. else
  1459. {
  1460. Statetmp = 5;
  1461. }
  1462. }
  1463. else if((TotalTmpVolt >= -1.5) && (TotalTmpVolt < 1.5)) //V_cp = -1.5V ~ 1.5V
  1464. {
  1465. //State E (0V)
  1466. if((ccs->CpState == 8) &&
  1467. (TotalTmpVolt < -1.25))
  1468. {
  1469. Statetmp = 8;
  1470. }
  1471. else if((ccs->CpState == 5) &&
  1472. (TotalTmpVolt >= 1.25))
  1473. {
  1474. Statetmp = 5;
  1475. }
  1476. else
  1477. {
  1478. Statetmp = 6;
  1479. }
  1480. }
  1481. else if((TotalTmpVolt >= -13.5) && (TotalTmpVolt < -10.5)) //V_cp = -10.5V ~ -13.5V
  1482. {
  1483. //State F (-12V)
  1484. if((ccs->CpState == 8) &&
  1485. (TotalTmpVolt >= -10.75))
  1486. {
  1487. Statetmp = 8;
  1488. }
  1489. else
  1490. {
  1491. Statetmp = 7;
  1492. }
  1493. }
  1494. else
  1495. {
  1496. //null
  1497. }
  1498. ccs->CpState = Statetmp;
  1499. }
  1500. #endif
  1501. Check_CP_State_Update_fork1(ccs);
  1502. Check_CP_State_Error_fork1(ccs);
  1503. //Updating Plugin status
  1504. #if (PP_PROTECTION_MECHANISM == ENABLE)
  1505. if((ccs->CpState >= 2 ) && (ccs->CpState <= 5 ) && (ccs->PpVoltage >= 1.0)) //PP >= 1.0V
  1506. #else
  1507. if((ccs->CpState >= 2 ) && (ccs->CpState <= 5 ))
  1508. #endif
  1509. {
  1510. ccs->ConnectorPlugIn_new = TRUE;
  1511. }
  1512. else
  1513. {
  1514. ccs->ConnectorPlugIn_new = FALSE;
  1515. OutputCpPwmDuty(100);
  1516. }
  1517. Check_Plugin_Status_Update_fork1(ccs);
  1518. //ftime(&EndTime);
  1519. //DEBUG_PRINTF_EVCOMM_DETAIL("duration:%.02lf\n", DiffTimeb(StartTime, EndTime));
  1520. usleep(1000);
  1521. }//while
  1522. }
  1523. /*===========================================================================
  1524. FUNCTION: PP_Detection
  1525. DESCRIPTION:
  1526. 0. SeccComm fork3
  1527. 1. In order to detect CP in efficient response time, we creat an independent
  1528. thead for this procedure.
  1529. 2. The priority of this thread is set as the same as other tasks.
  1530. PRE-CONDITION:
  1531. INPUT:
  1532. OUTPUT:
  1533. GLOBAL VARIABLES:
  1534. =============================================================================*/
  1535. void PP_Detection()
  1536. {
  1537. pid_t tmp = 0;
  1538. // struct timeb StartTime, EndTime;
  1539. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED))
  1540. //unsigned char Statetmp;
  1541. #endif
  1542. float TotalTmpVolt;
  1543. if(PP_Detection_Pid == 0)
  1544. {
  1545. tmp = fork();
  1546. if(tmp > 0)
  1547. {
  1548. PP_Detection_Pid = tmp;
  1549. #if 0
  1550. unsigned char buf[64];
  1551. memset(buf, 0, sizeof(buf));
  1552. sprintf((char*)buf, "renice -20 -p %d", tmp);
  1553. system(buf);
  1554. #endif
  1555. return;
  1556. }
  1557. }
  1558. while(1)
  1559. {
  1560. TotalTmpVolt = ReadAdcVolt_PP_fork3();
  1561. EVCOMM_SYS_INFO.PpVoltage = TotalTmpVolt;
  1562. if (EVCOMM_SYS_INFO.PpVoltage_pre != EVCOMM_SYS_INFO.PpVoltage)
  1563. {
  1564. if ((EVCOMM_SYS_INFO.PpVoltage_pre < 0.5 && EVCOMM_SYS_INFO.PpVoltage >= 1.0) ||
  1565. (EVCOMM_SYS_INFO.PpVoltage_pre >= 1.0 && EVCOMM_SYS_INFO.PpVoltage < 0.5))
  1566. {
  1567. sprintf((char*)buf_log_evcomm_fork3,
  1568. "[fork3]PP(%.2f >> %.2fV)",
  1569. EVCOMM_SYS_INFO.PpVoltage_pre,
  1570. EVCOMM_SYS_INFO.PpVoltage
  1571. );
  1572. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork3);
  1573. EVCOMM_SYS_INFO.PpVoltage_pre = EVCOMM_SYS_INFO.PpVoltage;
  1574. }
  1575. }
  1576. #if 0
  1577. sleep(5);
  1578. printf("V_pp = %.02f\n", TotalTmpVolt);
  1579. #endif
  1580. usleep(1000);
  1581. }//while
  1582. }
  1583. /*===========================================================================
  1584. FUNCTION: Error_Monitor
  1585. DESCRIPTION:
  1586. 1. This function only works in SeccComm fork2.
  1587. PRE-CONDITION:
  1588. INPUT:
  1589. OUTPUT:
  1590. GLOBAL VARIABLES:
  1591. =============================================================================*/
  1592. void Error_Monitor()
  1593. {
  1594. pid_t tmp = 0;
  1595. double time_diff = 0;
  1596. unsigned char status = 0;
  1597. struct ChargingInfoData *ccs;
  1598. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1599. if(Error_Monitor_Pid == 0)
  1600. {
  1601. tmp = fork(); //SeccComm fork2
  1602. if(tmp > 0)
  1603. {
  1604. Error_Monitor_Pid = tmp;
  1605. #if 0
  1606. unsigned char buf[64];
  1607. memset(buf, 0, sizeof(buf));
  1608. sprintf((char*)buf, "renice -20 -p %d", tmp);
  1609. system(buf);
  1610. #endif
  1611. return;
  1612. }
  1613. }
  1614. while(1)
  1615. {
  1616. //Step 0
  1617. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  1618. {
  1619. //If the End_Process is in processing, disable Error_Monitor.
  1620. continue;
  1621. }
  1622. //Step1 1: Check and Response to Plugin Status
  1623. if(CheckConnectorPlugIn() == FALSE)
  1624. {
  1625. status = Check_V2G_Flow_Status();
  1626. if (status > IDLE &&
  1627. status < Performance_Timeout &&
  1628. status != CM_SET_KEY_REQ &&
  1629. status != CM_SET_KEY_CNF &&
  1630. EVCOMM_SYS_INFO.End_Process_inused == FALSE)
  1631. {
  1632. #if (CP_PROTECTION_MECHANISM == ENABLE)
  1633. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork2] Emergency Stop (due to Connector is plugged out during communication.)");
  1634. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork2]Plug out Error => End_Process");
  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. #else
  1646. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "CP_PROTECTION_MECHANISM is disabled. Emergency Stop: skipped" );
  1647. #endif
  1648. }
  1649. }
  1650. //Step 2: Check for V2G_SECC_Sequence_Timeout
  1651. //#if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  1652. #if 1
  1653. status = Check_V2G_Flow_Status();
  1654. if (status >= SupportedAppProtocolRequest &&
  1655. status < SessionStopRequest)
  1656. {
  1657. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_End);
  1658. time_diff = DiffTimeb_fork2_Error_Monitor(EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start, EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_End);
  1659. if(time_diff > V2G_SECC_Sequence_Timeout) //60s
  1660. {
  1661. sprintf((char*)buf_log_evcomm_fork2,
  1662. "[fork2]V2G_SECC_Sequence_Timeout in state %d - (%.02lf of %d ms)\n",
  1663. status,
  1664. time_diff,
  1665. V2G_SECC_Sequence_Timeout);
  1666. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork2);
  1667. Update_V2G_Flow_Status(Sequence_Timeout);
  1668. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1669. //CCS_SECC_TIMEOUT_V2G_Sequence_Time (023844)
  1670. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1671. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1672. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1673. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1674. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  1675. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  1676. End_Process();
  1677. break;
  1678. }
  1679. else if (time_diff > 4000) //4s
  1680. {
  1681. //Check for CSU command of "Stop by EVSE"
  1682. if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_Shutdown)
  1683. {
  1684. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error_Monitor]EVSE_Shutdown");
  1685. Update_V2G_Flow_Status(Other_Fault);
  1686. }
  1687. else if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_EmergencyShutdown)
  1688. {
  1689. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error_Monitor]EVSE_EmergencyShutdown");
  1690. Update_V2G_Flow_Status(Other_Fault);
  1691. }
  1692. else if (ShmInternalComm->ChargingPermission == FALSE)
  1693. {
  1694. if (status >= ChargeParameterDiscoveryRequest) //&& status < SessionStopRequest
  1695. {
  1696. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error_Monitor]ChargingPermission = FALSE");
  1697. Update_V2G_Flow_Status(Other_Fault);
  1698. }
  1699. }
  1700. else
  1701. {
  1702. //null
  1703. }
  1704. }
  1705. else
  1706. {
  1707. //null
  1708. }
  1709. }
  1710. #endif
  1711. //Step 3: Check and Response to Error V2gFlowStatus
  1712. status = Check_V2G_Flow_Status();
  1713. if (status == Performance_Timeout ||
  1714. status == Sequence_Timeout ||
  1715. status == Other_Fault)
  1716. {
  1717. sprintf((char*)buf_log_evcomm_fork2,
  1718. "[fork2]Timeout or Fault State(%d) => End_Process",
  1719. status);
  1720. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork2);
  1721. //Normal Stop
  1722. //alarm and duty to 100%
  1723. //OutputCpPwmDuty(100);
  1724. //SwitchCpStateE(ENABLE); //Set CP duty as 100% and set CP state as E (0V).
  1725. //[Joseph/ To-Do] Set State E (0V) via GPIO setting
  1726. End_Process();
  1727. }
  1728. //Step 4: Check and Response to CP State Error
  1729. if(ccs->CpState_err == TRUE)
  1730. {
  1731. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork2]CP Error => End_Process");
  1732. Update_V2G_Flow_Status(Other_Fault);
  1733. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1734. //CCS_SECC_CP_State_Error (023889)
  1735. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1736. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1737. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1738. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1739. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1740. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1741. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1742. End_Process();
  1743. }
  1744. //Step 5: Check and Response to Shutdown Commnad from CSU
  1745. if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_Shutdown ||
  1746. EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_EmergencyShutdown)
  1747. {
  1748. if (Check_V2G_Flow_Status() <= SLACC_SDP_TCP_Connection)
  1749. {
  1750. sprintf((char*)buf_log_evcomm_fork2,
  1751. "[fork2]EVSE Shutdown(%d) => End_Process",
  1752. EVCOMM_SYS_INFO.DC_EVSEStatus);
  1753. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork2);
  1754. Update_V2G_Flow_Status(Other_Fault);
  1755. End_Process();
  1756. }
  1757. }
  1758. //Step 6: Check and Response to SessionStop
  1759. status = Check_V2G_Flow_Status();
  1760. if (status == SessionStopResponse)
  1761. {
  1762. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork2]SessionStopResponse => End_Process");
  1763. End_Process();
  1764. }
  1765. //Step 7: Check for ChargingPermission from TRUE to FALSE before V2G Messages
  1766. if ((ShmInternalComm->ChargingPermission == FALSE) &&
  1767. (ShmInternalComm->ChargingPermission_pre == TRUE) &&
  1768. (ccs->CpState >= 3) && (ccs->CpState <=5))
  1769. {
  1770. if (status >= CM_SLAC_PARM_REQ &&
  1771. status != CM_SET_KEY_REQ &&
  1772. status != CM_SET_KEY_CNF &&
  1773. status <= SLACC_SDP_TCP_Connection)
  1774. {
  1775. sprintf((char*)buf_log_evcomm_fork2,
  1776. "[fork2]Permission OFF before V2G msg(%d) => End_Process",
  1777. ShmInternalComm->ChargingPermission);
  1778. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork2);
  1779. Update_V2G_Flow_Status(Other_Fault);
  1780. End_Process();
  1781. }
  1782. }
  1783. //Step 8: DC OVP Protection
  1784. if (CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED &&
  1785. status > CableCheckResponse &&
  1786. status <= SessionStopRequest &&
  1787. status != ChargingStatusRequest &&
  1788. status != ChargingStatusResponse &&
  1789. EVCOMM_SYS_INFO.EvBatteryMaxVoltage != 0)
  1790. {
  1791. //Part A: OVP Protection
  1792. if (EVCOMM_SYS_INFO.PresentChargingVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02)) // 2%
  1793. {
  1794. sprintf((char*)buf_log_evcomm_fork2,
  1795. "[fork2][Error]OVP => End_Process (%.02f > %.02f)",
  1796. EVCOMM_SYS_INFO.PresentChargingVoltage,
  1797. (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02));
  1798. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork2);
  1799. Update_V2G_Flow_Status(Other_Fault);
  1800. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1801. //System CCS output OVP (012219)
  1802. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1803. ShmStatusCodeData->PresentStatusCode[0][1] = 1;
  1804. ShmStatusCodeData->PresentStatusCode[0][2] = 2;
  1805. ShmStatusCodeData->PresentStatusCode[0][3] = 2;
  1806. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  1807. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1808. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1809. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1810. End_Process();
  1811. }
  1812. //Part B: Over Voltage Request Protection
  1813. if (EVCOMM_SYS_INFO.EvBatterytargetVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02))
  1814. {
  1815. sprintf((char*)buf_log_evcomm_fork2,
  1816. "[fork2]Over V Req => End_Process (%.02f > %.02f)",
  1817. EVCOMM_SYS_INFO.EvBatterytargetVoltage,
  1818. (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02)
  1819. );
  1820. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork2);
  1821. Update_V2G_Flow_Status(Other_Fault);
  1822. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1823. //System CCS output OVP (012219)
  1824. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1825. ShmStatusCodeData->PresentStatusCode[0][1] = 1;
  1826. ShmStatusCodeData->PresentStatusCode[0][2] = 2;
  1827. ShmStatusCodeData->PresentStatusCode[0][3] = 2;
  1828. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  1829. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1830. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1831. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1832. End_Process();
  1833. }
  1834. }
  1835. //Step 9: Check 60V
  1836. if (CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED &&
  1837. ShmInternalComm->ChargingPermission == TRUE &&
  1838. status < CableCheckRequest)
  1839. {
  1840. if (EVCOMM_SYS_INFO.PresentChargingVoltage >= 60) //60V
  1841. {
  1842. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork2]DC Output Voltage is over 60V => End_Process");
  1843. Update_V2G_Flow_Status(Other_Fault);
  1844. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1845. //CCS_SECC_Unexpected_60V_Before_Charing_Error (023890)
  1846. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1847. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1848. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1849. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1850. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  1851. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  1852. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1853. //Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1854. End_Process();
  1855. }
  1856. }
  1857. //Step 10: Check if the connector is unplug from plugin
  1858. if (EVCOMM_SYS_INFO.ConnectorPlugIn_pre == TRUE && EVCOMM_SYS_INFO.ConnectorPlugIn == FALSE)
  1859. {
  1860. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork2]Unplug Reset => End_Process");
  1861. Update_V2G_Flow_Status(Other_Fault);
  1862. End_Process();
  1863. }
  1864. usleep(1000);
  1865. }//while
  1866. }
  1867. /*===========================================================================
  1868. FUNCTION: SendSetKey
  1869. DESCRIPTION:
  1870. PRE-CONDITION:
  1871. INPUT:
  1872. OUTPUT:
  1873. GLOBAL VARIABLES:
  1874. =============================================================================*/
  1875. int SendSetKey()
  1876. {
  1877. int i = 0;
  1878. unsigned char nRandValue = 0x0;
  1879. unsigned char ConstString[16] = "PhihongKey000000";
  1880. memset(&SendMmePacket,0,sizeof(struct MmeHeader));
  1881. memcpy(SendMmePacket.ODA,QcaMac,6);
  1882. memcpy(SendMmePacket.OSA,CsuMac,6);
  1883. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  1884. SendMmePacket.MMV = 0x01;
  1885. SendMmePacket.MMTYPE = MMTYPE_CM_SET_KEY_REQ;
  1886. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  1887. SendMmePacketSize = 0;
  1888. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//Fixed value (0x01) to indicate ��NMK��
  1889. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,4);//My Nonce, Fixed value(0x00000000), encrypted payload not used
  1890. SendMmePacketSize+=4;
  1891. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,4);//Your Nonce, Fixed value(0x00000000), encrypted payload not used
  1892. SendMmePacketSize+=4;
  1893. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x04;//PID, Fixed value (0x04) to indicate ��HLE protocol��
  1894. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,2);//PRN, Fixed value(0x00), encrypted payload not used
  1895. SendMmePacketSize+=2;
  1896. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00;//PMN, Fixed value(0x00) encrypted payload not used
  1897. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//CCo Capablility
  1898. srand(time(NULL));
  1899. for (i = 10; i < 16; i++)
  1900. {
  1901. nRandValue = (rand()%62) + 1;
  1902. if((nRandValue>=0)&&(nRandValue<=9)) // 0 ~ 9
  1903. {
  1904. ConstString[i]= nRandValue + 0x30;
  1905. }
  1906. else if((nRandValue>=10)&&(nRandValue<=35)) // A ~ Z
  1907. {
  1908. ConstString[i]= nRandValue -10 + 0x41;
  1909. }
  1910. else if((nRandValue>=36)&&(nRandValue<=61)) // a ~ z
  1911. {
  1912. ConstString[i]= nRandValue -37 + 0x61;
  1913. }
  1914. else
  1915. {
  1916. ConstString[i]= 0x30;
  1917. }
  1918. }
  1919. memset(NewNmkKey,0,sizeof(NewNmkKey));
  1920. memset(Nid,0,sizeof(Nid));
  1921. HPAVKeyNMK(NewNmkKey, (char*)ConstString);
  1922. HPAVKeyNID(Nid,NewNmkKey,DEFAULT_LEVEL);
  1923. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,Nid,sizeof(Nid)); //NID, 54 LSBs contain the NID 2 MSBs = 0b00
  1924. SendMmePacketSize+=sizeof(Nid);
  1925. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x01;//NewEKS,Fixed value (0x01)to indicate ��NMK��
  1926. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,NewNmkKey,sizeof(NewNmkKey));//NewKey
  1927. SendMmePacketSize += sizeof(NewNmkKey);
  1928. SendMmePacketSize += 19; //the size before MMENTRY
  1929. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[QCA7K][Tx]CM_SET_KEY_REQ");
  1930. i = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  1931. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  1932. DEBUG_PRINTF_EVCOMM_DETAIL("SendSetKey: send size =%d\n",i);
  1933. return 0;
  1934. }
  1935. /*===========================================================================
  1936. FUNCTION: GetQca7kMac
  1937. DESCRIPTION:
  1938. PRE-CONDITION:
  1939. INPUT:
  1940. OUTPUT:
  1941. GLOBAL VARIABLES:
  1942. =============================================================================*/
  1943. int GetQca7kMac()
  1944. {
  1945. struct QcaVendorMmeHeader SendPacket;
  1946. memset(&SendPacket, 0, sizeof(struct QcaVendorMmeHeader));
  1947. memset(SendPacket.ODA, 0xFF, 6); //broadcast
  1948. memcpy(SendPacket.OSA, CsuMac, 6);
  1949. SendPacket.MTYPE = htons(EtherType_HomePlug);
  1950. SendPacket.MMV = 0x00;
  1951. SendPacket.MMTYPE = MMTYPE_VENDOR_VS_NW_INFO;
  1952. SendPacket.OUI[0] = 0x00;
  1953. SendPacket.OUI[1] = 0xB0;
  1954. SendPacket.OUI[2] = 0x52;
  1955. DEBUG_PRINTF_EVCOMM_DETAIL("GetQca7kMac: send size =%d\n", sendto(RawSock, &SendPacket, 20, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll)));
  1956. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Req for QCA7K MacAddr");
  1957. return 0;
  1958. }
  1959. /*===========================================================================
  1960. FUNCTION: Array_Check_All_Zero
  1961. DESCRIPTION:
  1962. PRE-CONDITION:
  1963. INPUT:
  1964. OUTPUT:
  1965. result:
  1966. (1) TRUE: all zero
  1967. (2) FALSE: not all zero
  1968. GLOBAL VARIABLES:
  1969. =============================================================================*/
  1970. int Array_Check_All_Zero(unsigned char *ptr, int size)
  1971. {
  1972. int result = TRUE;
  1973. int i = 0;
  1974. for (i = 0; i < size; i++)
  1975. {
  1976. if (ptr[i] != 0)
  1977. {
  1978. result = FALSE;
  1979. break;
  1980. }
  1981. }
  1982. return result;
  1983. }
  1984. /*===========================================================================
  1985. FUNCTION: Array_Compare_Identity
  1986. DESCRIPTION:
  1987. PRE-CONDITION:
  1988. INPUT:
  1989. OUTPUT:
  1990. result = FALSE (not identical)
  1991. result = TRUE (identical)
  1992. GLOBAL VARIABLES:
  1993. =============================================================================*/
  1994. int Array_Compare_Identity(unsigned char *ptrA, unsigned char *ptrB, int size)
  1995. {
  1996. int result = TRUE;
  1997. int i = 0;
  1998. for (i = 0; i < size; i++)
  1999. {
  2000. if (ptrA[i] != ptrB[i])
  2001. {
  2002. result = FALSE;
  2003. #if 0
  2004. sprintf((char*)buf_log_evcomm,
  2005. "[Array_Compare_Identity]%02X%02X%02X%02X%02X%02X,%02X%02X%02X%02X%02X%02X(%d)\n",
  2006. ptrA[0], ptrA[1], ptrA[2], ptrA[3], ptrA[4], ptrA[5],
  2007. ptrB[0], ptrB[1], ptrB[2], ptrB[3], ptrB[4], ptrB[5],
  2008. result);
  2009. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2010. #endif
  2011. break;
  2012. }
  2013. }
  2014. return result;
  2015. }
  2016. /*===========================================================================
  2017. FUNCTION: SLAC_DB_Search_EvMac_idx
  2018. DESCRIPTION:
  2019. PRE-CONDITION:
  2020. INPUT:
  2021. OUTPUT:
  2022. idx = -1 (not found)
  2023. GLOBAL VARIABLES:
  2024. =============================================================================*/
  2025. int SLAC_DB_Search_EvMac_idx(struct EVCC_SLAC_DATA_TYPE *evcc, unsigned char *EvMac_in)
  2026. {
  2027. int idx = -1;
  2028. int i = 0;
  2029. if (evcc->arrayLen == 0)
  2030. {
  2031. //printf("[SLAC_DB_Search_EvMac_idx]arrayLen is empty (%d)\n", evcc->arrayLen);
  2032. //no need to search
  2033. }
  2034. else if (evcc->arrayLen > EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE)
  2035. {
  2036. //error
  2037. sprintf((char*)buf_log_evcomm,
  2038. "[ERROR][SLAC_DB_Search_EvMac_idx]DB length(%d) > %d",
  2039. evcc->arrayLen,
  2040. EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE);
  2041. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2042. evcc->arrayLen = 0; //reset
  2043. }
  2044. else
  2045. {
  2046. //start searching
  2047. for (i = 0; i < evcc->arrayLen; i++)
  2048. {
  2049. //printf("[SLAC_DB_Search_EvMac_idx]checking DB[%d]...\n", i);
  2050. if (Array_Compare_Identity(evcc->array[i].EvMac, EvMac_in, SLAC_EVMAC_LENGTH) == TRUE)
  2051. {
  2052. //printf("[SLAC_DB_Search_EvMac_idx]identical at DB[%d]...\n", i);
  2053. idx = i;
  2054. break;
  2055. }
  2056. }
  2057. }
  2058. //printf("[SLAC_DB_Search_EvMac_idx]return = %d\n", idx);
  2059. return idx;
  2060. }
  2061. /*===========================================================================
  2062. FUNCTION: SLAC_DB_Check_EvMac_RunID_Matching
  2063. DESCRIPTION:
  2064. PRE-CONDITION:
  2065. INPUT:
  2066. OUTPUT:
  2067. res = FALSE (unmatched)
  2068. res = TRUE (matched)
  2069. GLOBAL VARIABLES:
  2070. =============================================================================*/
  2071. int SLAC_DB_Check_EvMac_RunID_Matching(struct EVCC_SLAC_DATA_TYPE *evcc, unsigned char *EvMac_in, unsigned char *RunID_in)
  2072. {
  2073. int res = FALSE;
  2074. int idx = -1;
  2075. idx = SLAC_DB_Search_EvMac_idx(evcc, EvMac_in);
  2076. if (idx >= 0)
  2077. {
  2078. res = Array_Compare_Identity(evcc->array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2079. }
  2080. else
  2081. {
  2082. //not found the EvMac data in DB
  2083. res = FALSE;
  2084. }
  2085. return res;
  2086. }
  2087. /*===========================================================================
  2088. FUNCTION: SLAC_DB_Add
  2089. DESCRIPTION:
  2090. 1. Saving each CM_SLAC_PARM_REQ data into EVCC database if its
  2091. EvMac and RunID data are different, respectively.
  2092. PRE-CONDITION:
  2093. INPUT:
  2094. OUTPUT:
  2095. idx = saved index (must be a positive value)
  2096. GLOBAL VARIABLES:
  2097. =============================================================================*/
  2098. int SLAC_DB_Add(unsigned char *EvMac_in, unsigned char *RunID_in)
  2099. {
  2100. int idx = -1;
  2101. //Search if this EvMac and RunID already exists
  2102. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2103. if (idx < 0) //not exist, yet.
  2104. {
  2105. if (SLAC_INFO.arrayLen < EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE) //20
  2106. {
  2107. sprintf((char*)buf_log_evcomm,
  2108. "[SLAC_DB_Add]data does not exist => added to %d-th",
  2109. SLAC_INFO.arrayLen);
  2110. DEBUG_PRINTF_EVCOMM_DETAIL("%s\n", buf_log_evcomm);
  2111. if (SLAC_INFO.arrayLen >= 0)
  2112. {
  2113. memset(&SLAC_INFO.array[SLAC_INFO.arrayLen], 0, sizeof(struct EVCC_SLAC_DATA_ARRAY_TYPE));
  2114. memcpy(SLAC_INFO.array[SLAC_INFO.arrayLen].EvMac, EvMac_in, SLAC_EVMAC_LENGTH);
  2115. memcpy(SLAC_INFO.array[SLAC_INFO.arrayLen].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2116. idx = SLAC_INFO.arrayLen;
  2117. SLAC_INFO.arrayLen++;
  2118. }
  2119. else
  2120. {
  2121. sprintf((char*)buf_log_evcomm,
  2122. "[ERROR][SLAC_DB_Add]arrayLen: unexpected(%d)",
  2123. SLAC_INFO.arrayLen);
  2124. DEBUG_PRINTF_EVCOMM_DETAIL("%s\n", buf_log_evcomm);
  2125. SLAC_INFO.arrayLen = 0;
  2126. }
  2127. }
  2128. else
  2129. {
  2130. //DB is full
  2131. sprintf((char*)buf_log_evcomm,
  2132. "[SLAC_DB_Add]DB is full(%d) => bypass",
  2133. SLAC_INFO.arrayLen);
  2134. DEBUG_PRINTF_EVCOMM_DETAIL("%s\n", buf_log_evcomm);
  2135. }
  2136. }
  2137. else
  2138. {
  2139. #if 0
  2140. sprintf((char*)buf_log_evcomm,
  2141. "[SLAC_DB_Add]EvMac: existed (%d)",
  2142. idx);
  2143. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2144. #endif
  2145. //Check RunID
  2146. if (Array_Compare_Identity(SLAC_INFO.array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH) == TRUE)
  2147. {
  2148. //RunID is the same
  2149. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC_DB_Add]RunID: same");
  2150. }
  2151. else
  2152. {
  2153. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC_DB_Add]RunID: diff");
  2154. }
  2155. //Reset all corresponding parameters
  2156. #if 0
  2157. sprintf((char*)buf_log_evcomm,
  2158. "[SLAC_DB_Add]EvMac: reset para(%d)",
  2159. idx);
  2160. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2161. #endif
  2162. memset(&SLAC_INFO.array[idx], 0, sizeof(struct EVCC_SLAC_DATA_ARRAY_TYPE));
  2163. memcpy(SLAC_INFO.array[idx].EvMac, EvMac_in, SLAC_EVMAC_LENGTH);
  2164. memcpy(SLAC_INFO.array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2165. }
  2166. return idx;
  2167. }
  2168. /*===========================================================================
  2169. FUNCTION: SLAC_DB_Reset
  2170. DESCRIPTION:
  2171. PRE-CONDITION:
  2172. INPUT:
  2173. OUTPUT:
  2174. GLOBAL VARIABLES:
  2175. =============================================================================*/
  2176. int SLAC_DB_Reset()
  2177. {
  2178. memset(&SLAC_INFO, 0, sizeof(struct EVCC_SLAC_DATA_TYPE));
  2179. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC_DB_Reset]DONE");
  2180. return 0;
  2181. }
  2182. /*===========================================================================
  2183. FUNCTION: MmeProcess
  2184. DESCRIPTION:
  2185. PRE-CONDITION:
  2186. INPUT:
  2187. OUTPUT:
  2188. GLOBAL VARIABLES:
  2189. =============================================================================*/
  2190. int MmeProcess(unsigned char *Buffer, int DataLength)
  2191. {
  2192. //struct ethhdr *EthPacket;
  2193. struct MmeHeader *MmePacket;
  2194. static unsigned char counter;
  2195. unsigned char state = 0;
  2196. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2197. unsigned char tmpBuf[2048]={0};
  2198. #endif
  2199. int Rtn = 0;
  2200. #if(NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2201. int idx = 0;
  2202. unsigned char *EvMac_in;
  2203. unsigned char *RunID_in;
  2204. #endif
  2205. MmePacket = (struct MmeHeader *)Buffer;
  2206. state = Check_V2G_Flow_Status();
  2207. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2208. {
  2209. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  2210. DEBUG_PRINTF_EVCOMM_DETAIL("******* Received MME Packet *******\n");
  2211. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  2212. DEBUG_PRINTF_EVCOMM_DETAIL("DataLength=%d\n",DataLength);
  2213. DEBUG_PRINTF_EVCOMM_DETAIL("ODA: %02x:%02x:%02x:%02x:%02x:%02x\n", //Destination MAC Address
  2214. MmePacket->ODA[0], MmePacket->ODA[1],
  2215. MmePacket->ODA[2], MmePacket->ODA[3],
  2216. MmePacket->ODA[4], MmePacket->ODA[5]);
  2217. DEBUG_PRINTF_EVCOMM_DETAIL("OSA: %02x:%02x:%02x:%02x:%02x:%02x\n", //Source MAC Address (EV MAC)
  2218. MmePacket->OSA[0], MmePacket->OSA[1],
  2219. MmePacket->OSA[2], MmePacket->OSA[3],
  2220. MmePacket->OSA[4], MmePacket->OSA[5]);
  2221. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(MmePacket->MTYPE));
  2222. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", MmePacket->MMV);
  2223. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", MmePacket->MMTYPE);
  2224. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n",
  2225. MmePacket->FMI[0],MmePacket->FMI[1]);
  2226. }
  2227. #endif
  2228. #if (SLAC_FIRST_RESPONSE_METHOD == SET_NO_PWM_IF_NOT_GET_PERMISSION)
  2229. {
  2230. //Check CP as 5%
  2231. if (EVCOMM_SYS_INFO.CpState != 3 &&
  2232. EVCOMM_SYS_INFO.CpState != 4 &&
  2233. MmePacket->MMTYPE != MMTYPE_CM_SET_KEY_CNF &&
  2234. MmePacket->MMTYPE != MMTYPE_VENDOR_VS_HOST_ACTION &&
  2235. MmePacket->MMTYPE != MMTYPE_VENDOR_ATTEN_CHAR &&
  2236. MmePacket->MMTYPE != MMTYPE_VENDOR_VS_NW_INFO_CNF
  2237. )
  2238. {
  2239. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC]ignored(wrong CP state)");
  2240. return 0;
  2241. }
  2242. }
  2243. #endif
  2244. //[To-Do] Adding a pre-check filter mechanism for Source and Destination MAC Address
  2245. //check if the destination address is broadcast or EVSE itself, it can be ignore if not belong to itself.
  2246. switch(MmePacket->MMTYPE)
  2247. {
  2248. case MMTYPE_CM_SET_KEY_CNF:
  2249. {
  2250. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SET_KEY_CNF ---\n");
  2251. DEBUG_PRINTF_EVCOMM_DETAIL("Result: 0x%x\n", MmePacket->MMENTRY[0]);
  2252. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[QCA7K][Rx]CM_SET_KEY_CNF (SetKey: DONE)");
  2253. Update_V2G_Flow_Status(CM_SET_KEY_CNF);
  2254. break;
  2255. }
  2256. case MMTYPE_CM_SLAC_PARM_REQ:
  2257. {
  2258. //Check QCA7000 status
  2259. if (EVCOMM_SYS_INFO.QCA7K_SetKeyDone == FALSE)
  2260. {
  2261. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][Rx]CM_SLAC_PARM_REQ: ignored(QCA7K init...)");
  2262. break;
  2263. }
  2264. //Check error state
  2265. state = Check_V2G_Flow_Status();
  2266. if (state == Performance_Timeout || //253
  2267. state == Sequence_Timeout || //254
  2268. state == Other_Fault) //255
  2269. {
  2270. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][Rx]CM_SLAC_PARM_REQ: ignored(in error state)");
  2271. break;
  2272. }
  2273. //Printing EV MAC Address
  2274. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][Rx]CM_SLAC_PARM_REQ");
  2275. //Avoid Coupled SLAC_PARM_REQ
  2276. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2277. {
  2278. #if 0
  2279. sprintf((char*)buf_log_evcomm,
  2280. "[WARNING][SLAC][Rx]CM_SLAC_PARM_REQ: ignored(coupled SLAC,%d)",
  2281. CheckConnectorPlugIn());
  2282. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2283. #endif
  2284. break;
  2285. }
  2286. //[TC_SECC_VTB_CmSlacParm_003] SECURITY_TYPE needs to be 0x00 (no security)
  2287. if (MmePacket->MMENTRY[1] != 0)
  2288. {
  2289. sprintf((char*)buf_log_evcomm,
  2290. "[WARNING][SLAC][Rx]CM_SLAC_PARM_REQ: ignored(invalid SECURITY_TYPE,%d)", //Source MAC Address (EV MAC)
  2291. MmePacket->MMENTRY[1]);
  2292. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2293. break;
  2294. }
  2295. //=================== Legal CM_SLAC_PARM_REQ Zone =================
  2296. Update_V2G_Flow_Status(CM_SLAC_PARM_REQ);
  2297. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_RX_CM_SLAC_PARM_REQ)
  2298. {
  2299. //Once receiving CM_SLAC_PARM_REQ, set PWM as 5%
  2300. SwitchCpStateE(DISABLE);
  2301. OutputCpPwmDuty(5);
  2302. }
  2303. #endif
  2304. //Checking if this SLAC Req comes before 5% PWM (for 15118)
  2305. if(ShmInternalComm->ChargingPermission == FALSE)
  2306. {
  2307. //Sniffer_Tcpdump(ENABLE);
  2308. sprintf((char*)buf_log_evcomm, "Check Permission: %d (SLAC first => START)", ShmInternalComm->ChargingPermission);
  2309. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2310. }
  2311. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2312. {
  2313. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SLAC_PARM_REQ ---\n");
  2314. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2315. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2316. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2317. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2318. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2319. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2320. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2321. DEBUG_PRINTF_EVCOMM_DETAIL("CipherSuiteSetSize: 0x%x\n", MmePacket->MMENTRY[10]);
  2322. DEBUG_PRINTF_EVCOMM_DETAIL("CipherSuite [1]: 0x%x,0x%x\n",
  2323. MmePacket->MMENTRY[11], MmePacket->MMENTRY[12]);
  2324. }
  2325. #endif
  2326. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2327. {
  2328. //Saving each CM_SLAC_PARM_REQ data into EVCC database
  2329. EvMac_in = &MmePacket->OSA[0];
  2330. RunID_in = &MmePacket->MMENTRY[2];
  2331. idx = SLAC_DB_Add(EvMac_in, RunID_in); //(EvMac, RunID)
  2332. if (idx < 0)
  2333. {
  2334. sprintf((char*)buf_log_evcomm,
  2335. "[WARNING][CM_SLAC_PARM_REQ]DB is full or errors occour(%d) => ignore",
  2336. idx);
  2337. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2338. break;
  2339. }
  2340. //Select the 1st EV MAC address
  2341. if (SLAC_INFO.arrayLen == 1) //1st Req
  2342. {
  2343. #if 1
  2344. sprintf((char*)buf_log_evcomm,
  2345. "[SLAC][Rx]CM_SLAC_PARM_REQ[%d](%02X:%02X:%02X:%02X:%02X:%02X,%02X%02X%02X%02X%02X%02X%02X%02X):selected",
  2346. (idx + 1),
  2347. MmePacket->OSA[0], MmePacket->OSA[1], MmePacket->OSA[2], MmePacket->OSA[3], MmePacket->OSA[4], MmePacket->OSA[5],
  2348. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3], MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2349. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7], MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2350. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2351. #endif
  2352. /*
  2353. sprintf((char*)buf_log_evcomm,
  2354. "[SLAC][EVMAC][%d-th]%02X:%02X:%02X:%02X:%02X:%02X (selected)", //Source MAC Address (EV MAC)
  2355. SLAC_INFO.arrayLen,
  2356. MmePacket->OSA[0], MmePacket->OSA[1],
  2357. MmePacket->OSA[2], MmePacket->OSA[3],
  2358. MmePacket->OSA[4], MmePacket->OSA[5]);
  2359. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2360. sprintf((char*)buf_log_evcomm,
  2361. "[SLAC][RunID][%d-th]%02X%02X%02X%02X%02X%02X%02X%02X (selected)", //RunID (from EVCC)
  2362. SLAC_INFO.arrayLen,
  2363. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2364. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2365. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2366. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2367. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2368. */
  2369. }
  2370. else //2nd Req
  2371. {
  2372. #if 1
  2373. sprintf((char*)buf_log_evcomm,
  2374. "[SLAC][Rx]CM_SLAC_PARM_REQ[%d](%02X:%02X:%02X:%02X:%02X:%02X,%02X%02X%02X%02X%02X%02X%02X%02X):not selected",
  2375. (idx + 1),
  2376. MmePacket->OSA[0], MmePacket->OSA[1], MmePacket->OSA[2], MmePacket->OSA[3], MmePacket->OSA[4], MmePacket->OSA[5],
  2377. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3], MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2378. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7], MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2379. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2380. #endif
  2381. /*
  2382. sprintf((char*)buf_log_evcomm,
  2383. "[SLAC][EVMAC][%d-th]%02X:%02X:%02X:%02X:%02X:%02X (not selected)", //Source MAC Address (EV MAC)
  2384. SLAC_INFO.arrayLen,
  2385. MmePacket->OSA[0], MmePacket->OSA[1],
  2386. MmePacket->OSA[2], MmePacket->OSA[3],
  2387. MmePacket->OSA[4], MmePacket->OSA[5]);
  2388. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2389. sprintf((char*)buf_log_evcomm,
  2390. "[SLAC][RunID][%d-th]%02X%02X%02X%02X%02X%02X%02X%02X (not selected)", //RunID (from EVCC)
  2391. SLAC_INFO.arrayLen,
  2392. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2393. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2394. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2395. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2396. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2397. */
  2398. }
  2399. memcpy(EvMac, MmePacket->OSA, sizeof(EvMac));
  2400. memcpy(DestSocketAddress.sll_addr, MmePacket->OSA, SLAC_EVMAC_LENGTH);
  2401. memcpy(SlacRunId, MmePacket->MMENTRY + 2, SLAC_RUNID_LENGTH);
  2402. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2403. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  2404. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2405. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2406. SendMmePacket.MMV = MmePacket->MMV;
  2407. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_PARM_CNF;
  2408. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2409. SendMmePacketSize = 0;
  2410. memset(SendMmePacket.MMENTRY, 0xFF, 6); //M-SOUND_TARGET(6-byte:0xFFFFFFFFFFFF): Fixed value indicating that M-Sounds to be sent as Ethernet broadcast
  2411. SendMmePacketSize += 6;
  2412. 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
  2413. SendMmePacket.MMENTRY[SendMmePacketSize++] = 6; //Time_Out(0x06): unit = 100ms
  2414. 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
  2415. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SLAC_INFO.array[idx].EvMac, 6); //FORWARDING_STA(MAC Address of the EV HLE)
  2416. SendMmePacketSize += 6;
  2417. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00): 0x00(PEV-EVSE Association), 0x01-0xFF(Reserved)
  2418. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00): 0x00(No Security), 0x01(Public Key Signature), 0x02-0xFF(Reserved)
  2419. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SlacRunId, SLAC_RUNID_LENGTH); //RunID (8-byte)
  2420. SendMmePacketSize += SLAC_RUNID_LENGTH;
  2421. SendMmePacketSize += 19; //the size before MMENTRY
  2422. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2423. {
  2424. DEBUG_PRINTF_EVCOMM_DETAIL("***** Response MME Packet *****\n");
  2425. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2426. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  2427. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2428. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  2429. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  2430. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  2431. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  2432. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  2433. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_PARM_CNF ---\n");
  2434. DEBUG_PRINTF_EVCOMM_DETAIL("M-SOUND_TARGET: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2435. SendMmePacket.MMENTRY[0],SendMmePacket.MMENTRY[1],SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],
  2436. SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5]);
  2437. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", SendMmePacket.MMENTRY[6]);
  2438. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out: 0x%x\n", SendMmePacket.MMENTRY[7]);
  2439. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE: 0x%x\n", SendMmePacket.MMENTRY[8]);
  2440. DEBUG_PRINTF_EVCOMM_DETAIL("M-FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2441. SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],SendMmePacket.MMENTRY[12],
  2442. SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14]);
  2443. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[15]);
  2444. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[16]);
  2445. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2446. SendMmePacket.MMENTRY[17],SendMmePacket.MMENTRY[18],SendMmePacket.MMENTRY[19],SendMmePacket.MMENTRY[20],
  2447. SendMmePacket.MMENTRY[21],SendMmePacket.MMENTRY[22],SendMmePacket.MMENTRY[23],SendMmePacket.MMENTRY[24]);
  2448. }
  2449. #endif
  2450. Update_V2G_Flow_Status(CM_SLAC_PARM_CONF);
  2451. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2452. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  2453. ftime(&SeqStartTime);
  2454. counter = 0;
  2455. break;
  2456. }
  2457. #else
  2458. {
  2459. memcpy(EvMac, MmePacket->OSA, sizeof(EvMac));
  2460. memcpy(DestSocketAddress.sll_addr, MmePacket->OSA, sizeof(EvMac));
  2461. memcpy(SlacRunId,MmePacket->MMENTRY + 2, sizeof(SlacRunId));
  2462. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2463. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  2464. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2465. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2466. SendMmePacket.MMV = MmePacket->MMV;
  2467. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_PARM_CNF;
  2468. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2469. SendMmePacketSize = 0;
  2470. memset(SendMmePacket.MMENTRY, 0xFF, 6); //M-SOUND_TARGET(6-byte:0xFFFFFFFFFFFF): Fixed value indicating that M-Sounds to be sent as Ethernet broadcast
  2471. SendMmePacketSize += 6;
  2472. 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
  2473. SendMmePacket.MMENTRY[SendMmePacketSize++] = 6; //Time_Out(0x06): unit = 100ms
  2474. 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
  2475. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac, 6); //FORWARDING_STA(MAC Address of the EV HLE)
  2476. SendMmePacketSize += 6;
  2477. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00): 0x00(PEV-EVSE Association), 0x01-0xFF(Reserved)
  2478. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00): 0x00(No Security), 0x01(Public Key Signature), 0x02-0xFF(Reserved)
  2479. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SlacRunId, sizeof(SlacRunId)); //RunID (8-byte)
  2480. SendMmePacketSize += sizeof(SlacRunId);
  2481. SendMmePacketSize += 19; //the size before MMENTRY
  2482. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2483. {
  2484. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  2485. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2486. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  2487. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2488. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  2489. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  2490. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  2491. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  2492. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  2493. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_PARM_CNF ---\n");
  2494. DEBUG_PRINTF_EVCOMM_DETAIL("M-SOUND_TARGET: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2495. SendMmePacket.MMENTRY[0],SendMmePacket.MMENTRY[1],SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],
  2496. SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5]);
  2497. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", SendMmePacket.MMENTRY[6]);
  2498. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out: 0x%x\n", SendMmePacket.MMENTRY[7]);
  2499. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE: 0x%x\n", SendMmePacket.MMENTRY[8]);
  2500. DEBUG_PRINTF_EVCOMM_DETAIL("M-FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2501. SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],SendMmePacket.MMENTRY[12],
  2502. SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14]);
  2503. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[15]);
  2504. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[16]);
  2505. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2506. SendMmePacket.MMENTRY[17],SendMmePacket.MMENTRY[18],SendMmePacket.MMENTRY[19],SendMmePacket.MMENTRY[20],
  2507. SendMmePacket.MMENTRY[21],SendMmePacket.MMENTRY[22],SendMmePacket.MMENTRY[23],SendMmePacket.MMENTRY[24]);
  2508. }
  2509. #endif
  2510. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2511. Update_V2G_Flow_Status(CM_SLAC_PARM_CONF);
  2512. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  2513. ftime(&SeqStartTime);
  2514. counter = 0;
  2515. break;
  2516. }
  2517. #endif
  2518. }
  2519. case MMTYPE_CM_START_ATTEN_CHAR_IND:
  2520. {
  2521. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2522. {
  2523. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[WARNING][SLAC][Rx]CM_START_ATTEN_CHAR_IND: ignored(timeup)");
  2524. break;
  2525. }
  2526. //Avoid Coupled CM_START_ATTEN_CHAR_IND
  2527. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2528. {
  2529. sprintf((char*)buf_log_evcomm,
  2530. "[WARNING][SLAC][Rx]CM_START_ATTEN_CHAR_IND: ignored(coupled SLAC,%d)",
  2531. CheckConnectorPlugIn());
  2532. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2533. break;
  2534. }
  2535. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2536. {
  2537. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_START_ATTEN_CHAR_IND (counter : %d/3 ) ---\n", counter);
  2538. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2539. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2540. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", MmePacket->MMENTRY[2]);
  2541. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out 0x%x\n", MmePacket->MMENTRY[3]);
  2542. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE 0x%x\n", MmePacket->MMENTRY[4]); //Fixed value (0x01) indicating ��other Green PHY station��
  2543. DEBUG_PRINTF_EVCOMM_DETAIL("FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2544. MmePacket->MMENTRY[5],MmePacket->MMENTRY[6],MmePacket->MMENTRY[7],MmePacket->MMENTRY[8],
  2545. MmePacket->MMENTRY[9],MmePacket->MMENTRY[10]);
  2546. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2547. MmePacket->MMENTRY[11],MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],MmePacket->MMENTRY[14],
  2548. MmePacket->MMENTRY[15],MmePacket->MMENTRY[16],MmePacket->MMENTRY[17],MmePacket->MMENTRY[18]);
  2549. }
  2550. #endif
  2551. //New SLAC architecture designed by Joseph
  2552. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2553. {
  2554. EvMac_in = &MmePacket->OSA[0];
  2555. RunID_in = &MmePacket->MMENTRY[11];
  2556. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2557. if (idx >= 0)
  2558. {
  2559. Update_V2G_Flow_Status(CM_START_ATTEN_CHAR_IND);
  2560. counter++;
  2561. //[TC_SECC_VTB_AttenuationCharacterization_013]
  2562. if (MmePacket->MMENTRY[0] != 0) //APPLICATION_TYPE must be 0x00(EV-EVSE Matching)
  2563. {
  2564. sprintf((char*)buf_log_evcomm,
  2565. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]APPLICATION_TYPE(%d): invalid => ignore Req",
  2566. MmePacket->MMENTRY[0]);
  2567. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2568. break;
  2569. }
  2570. //[TC_SECC_VTB_AttenuationCharacterization_014]
  2571. if (MmePacket->MMENTRY[1] != 0) //SECURITY_TYPE must be 0x00(No Security)
  2572. {
  2573. sprintf((char*)buf_log_evcomm,
  2574. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]SECURITY_TYPE(%d): invalid => ignore Req",
  2575. MmePacket->MMENTRY[1]);
  2576. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2577. break;
  2578. }
  2579. //[TC_SECC_VTB_AttenuationCharacterization_017]
  2580. if (MmePacket->MMENTRY[4] != 0x01) //RESP_TYPE must be 0x01(Send to another GP STA(EV))
  2581. {
  2582. sprintf((char*)buf_log_evcomm,
  2583. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]RESP_TYPE(%d): invalid => ignore Req",
  2584. MmePacket->MMENTRY[4]);
  2585. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2586. break;
  2587. }
  2588. //[TC_SECC_VTB_AttenuationCharacterization_021]
  2589. //FORWARDING_STA: MAC Address of the EV HLE (station which the measurement results shall be sent to)
  2590. if (Array_Compare_Identity(EvMac_in, &MmePacket->MMENTRY[5], SLAC_EVMAC_LENGTH) == FALSE)
  2591. {
  2592. sprintf((char*)buf_log_evcomm,
  2593. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]FORWARDING_STA(%02X:%02X:%02X:%02X:%02X:%02X): invalid => ignore Req",
  2594. MmePacket->MMENTRY[5], MmePacket->MMENTRY[6],
  2595. MmePacket->MMENTRY[7], MmePacket->MMENTRY[8],
  2596. MmePacket->MMENTRY[9], MmePacket->MMENTRY[10]);
  2597. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2598. SLAC_INFO.array[idx].StartAttenCharErr = TRUE;
  2599. break;
  2600. }
  2601. //Check RunID
  2602. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE)
  2603. {
  2604. SLAC_INFO.array[idx].MnbcSoundNum = MmePacket->MMENTRY[2];
  2605. SLAC_INFO.array[idx].StartAttenCharCnt++;
  2606. #if 0
  2607. sprintf((char*)buf_log_evcomm,
  2608. "[SLAC][Rx]CM_START_ATTEN_CHAR_IND[%d]:%d-th",
  2609. (idx + 1),
  2610. SLAC_INFO.array[idx].StartAttenCharCnt);
  2611. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2612. #endif
  2613. if (SLAC_INFO.array[idx].StartAttenCharCnt == 1)
  2614. {
  2615. memset(SLAC_INFO.array[idx].AAG, 0, sizeof(SLAC_INFO.array[idx].AAG));
  2616. SLAC_INFO.array[idx].AttenProfileCnt = 0;
  2617. ftime(&SeqStartTime); //start TT_EVSE_match_MNBC
  2618. }
  2619. else if (SLAC_INFO.array[idx].StartAttenCharCnt >= 3)
  2620. {
  2621. sprintf((char*)buf_log_evcomm,
  2622. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]counter(%d): unexpected",
  2623. SLAC_INFO.array[idx].StartAttenCharCnt);
  2624. }
  2625. else
  2626. {
  2627. //null
  2628. }
  2629. }
  2630. else
  2631. {
  2632. //This RunID is not matched with this EvMac,
  2633. //or this RunID is not found in DB.
  2634. sprintf((char*)buf_log_evcomm,
  2635. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]EvMac-RunID: unmatched => ignore Req");
  2636. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2637. //Response: ignore
  2638. }
  2639. }
  2640. else
  2641. {
  2642. //this msg source is not in database
  2643. //ignore
  2644. }
  2645. break;
  2646. }
  2647. #else //Old SLAC architecture designed by Vern
  2648. {
  2649. MnbcSoundNum = MmePacket->MMENTRY[2];
  2650. Update_V2G_Flow_Status(CM_START_ATTEN_CHAR_IND);
  2651. counter++;
  2652. if(counter == 1)
  2653. {
  2654. memset(Aag, 0, sizeof(Aag));
  2655. AttenProfileCnt = 0;
  2656. ftime(&SeqStartTime); //start TT_EVSE_match_MNBC
  2657. }
  2658. else if(counter >= 3)
  2659. {
  2660. counter = 0;
  2661. }
  2662. break;
  2663. }
  2664. #endif
  2665. }
  2666. case MMTYPE_CM_MNBC_SOUND_IND:
  2667. {
  2668. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2669. {
  2670. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND: ignored(timeup)");
  2671. break;
  2672. }
  2673. //Avoid Coupled CM_MNBC_SOUND_IND
  2674. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2675. {
  2676. sprintf((char*)buf_log_evcomm,
  2677. "[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND: ignored(coupled SLAC,%d)",
  2678. CheckConnectorPlugIn());
  2679. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2680. break;
  2681. }
  2682. if(V2gFlowStatus == CM_START_ATTEN_CHAR_IND)
  2683. {
  2684. counter = 0;
  2685. }
  2686. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2687. {
  2688. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_MNBC_SOUND_IND (counter : %d/%d) ---\n", counter, SLAC_INFO.array[idx].MnbcSoundNum);
  2689. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2690. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2691. DEBUG_PRINTF_EVCOMM_DETAIL("SenderID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2692. MmePacket->MMENTRY[2],MmePacket->MMENTRY[3],MmePacket->MMENTRY[4],MmePacket->MMENTRY[5],
  2693. MmePacket->MMENTRY[6],MmePacket->MMENTRY[7],MmePacket->MMENTRY[8],MmePacket->MMENTRY[9],
  2694. MmePacket->MMENTRY[10],MmePacket->MMENTRY[11],MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],
  2695. MmePacket->MMENTRY[14],MmePacket->MMENTRY[15],MmePacket->MMENTRY[16],MmePacket->MMENTRY[17],
  2696. MmePacket->MMENTRY[18]);
  2697. DEBUG_PRINTF_EVCOMM_DETAIL("Cnt: 0x%x\n", MmePacket->MMENTRY[19]);
  2698. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2699. MmePacket->MMENTRY[20],MmePacket->MMENTRY[21],MmePacket->MMENTRY[22],MmePacket->MMENTRY[23],
  2700. MmePacket->MMENTRY[24],MmePacket->MMENTRY[25],MmePacket->MMENTRY[26],MmePacket->MMENTRY[27]);
  2701. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2702. MmePacket->MMENTRY[28],MmePacket->MMENTRY[29],MmePacket->MMENTRY[30],MmePacket->MMENTRY[31],
  2703. MmePacket->MMENTRY[32],MmePacket->MMENTRY[33],MmePacket->MMENTRY[34],MmePacket->MMENTRY[35]);
  2704. DEBUG_PRINTF_EVCOMM_DETAIL("Rnd: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2705. MmePacket->MMENTRY[36],MmePacket->MMENTRY[37],MmePacket->MMENTRY[38],MmePacket->MMENTRY[39],
  2706. MmePacket->MMENTRY[40],MmePacket->MMENTRY[41],MmePacket->MMENTRY[42],MmePacket->MMENTRY[43],
  2707. MmePacket->MMENTRY[44],MmePacket->MMENTRY[45],MmePacket->MMENTRY[46],MmePacket->MMENTRY[47],
  2708. MmePacket->MMENTRY[48],MmePacket->MMENTRY[49],MmePacket->MMENTRY[50],MmePacket->MMENTRY[51]);
  2709. }
  2710. #endif
  2711. //New SLAC architecture designed by Joseph
  2712. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2713. {
  2714. EvMac_in = &MmePacket->OSA[0];
  2715. RunID_in = &MmePacket->MMENTRY[20];
  2716. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2717. if (idx >= 0)
  2718. {
  2719. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2720. counter++;
  2721. //Check for RunID
  2722. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE)
  2723. {
  2724. SLAC_INFO.array[idx].MnbcSoundCnt++;
  2725. /*
  2726. sprintf((char*)buf_log_evcomm,
  2727. "[SLAC][Rx]CM_MNBC_SOUND_IND[%d]:%d-th",
  2728. (idx + 1),
  2729. SLAC_INFO.array[idx].MnbcSoundCnt);
  2730. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2731. */
  2732. }
  2733. else
  2734. {
  2735. //RunID is not matched or does not exist.
  2736. sprintf((char*)buf_log_evcomm,
  2737. "[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND]EvMac-RunID: unmatched");
  2738. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2739. }
  2740. }
  2741. else
  2742. {
  2743. //ignore
  2744. sprintf((char*)buf_log_evcomm,
  2745. "[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND]EvMac does not exist");
  2746. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2747. }
  2748. break;
  2749. }
  2750. #else //Old SLAC architecture designed by Vern
  2751. {
  2752. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2753. counter++;
  2754. break;
  2755. }
  2756. #endif
  2757. }
  2758. case MMTYPE_CM_ATTEN_PROFILE_IND:
  2759. {
  2760. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2761. {
  2762. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[WARNING][SLAC][Rx]CM_ATTEN_PROFILE_IND: ignore(timeup)");
  2763. break;
  2764. }
  2765. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2766. {
  2767. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_ATTEN_PROFILE_IND (counter : %d/%d) ---\n", counter, SLAC_INFO.array[idx].MnbcSoundNum);
  2768. DEBUG_PRINTF_EVCOMM_DETAIL("EV MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2769. MmePacket->MMENTRY[0], MmePacket->MMENTRY[1], MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2770. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5]);
  2771. DEBUG_PRINTF_EVCOMM_DETAIL("NumGroups: 0x%x\n", MmePacket->MMENTRY[6]); //NumGroups, Number of AAG Groups (ex: 0x3A = 58)
  2772. //NumGroups: Number of OFDM carrier groups used for the SLAC signal characterization.
  2773. //AAG[i]: Average Attenuation of Group i (i = 1 ~ 58)
  2774. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", MmePacket->MMENTRY[7]);
  2775. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  2776. for(Rtn = 0; Rtn < MmePacket->MMENTRY[6]; Rtn++)
  2777. {
  2778. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, MmePacket->MMENTRY[8 + Rtn]);
  2779. }
  2780. DEBUG_PRINTF_EVCOMM_DETAIL("AAG: %s\n", tmpBuf);
  2781. }
  2782. #endif
  2783. //New SLAC architecture designed by Joseph
  2784. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2785. {
  2786. EvMac_in = &MmePacket->MMENTRY[0]; //[CAUTION] The EvMac address is not &MmePacket->OSA[0]
  2787. //[CAUTION] There is no RunID information of CM_ATTEN_PROFILE_IND
  2788. // packet, which means SECC cannot use the RunID to
  2789. // distinguish those SLAC request with identical EvMac
  2790. // but with different RunID.
  2791. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2792. /*
  2793. printf("%d, %d, %d, %d\n",
  2794. idx,
  2795. SLAC_INFO.array[idx].AagGroupsNum,
  2796. MmePacket->MMENTRY[6],
  2797. SLAC_INFO.array[idx].AttenProfileCnt);
  2798. */
  2799. if (idx >= 0)
  2800. {
  2801. SLAC_INFO.array[idx].AttenProfileCnt++;
  2802. /*
  2803. sprintf((char*)buf_log_evcomm,
  2804. "[SLAC][Rx]CM_ATTEN_PROFILE_IND[%d]:%d-th",
  2805. (idx + 1),
  2806. SLAC_INFO.array[idx].AttenProfileCnt);
  2807. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2808. */
  2809. //printf("%d, %d\n", SLAC_INFO.array[idx].AagGroupsNum, MmePacket->MMENTRY[6]);
  2810. SLAC_INFO.array[idx].AagGroupsNum = MmePacket->MMENTRY[6];
  2811. ////NumGroups, Number of AAG Groups (ex: 0x3A = 58)
  2812. for(Rtn = 0; Rtn < SLAC_INFO.array[idx].AagGroupsNum; Rtn++) //ex:58
  2813. {
  2814. SLAC_INFO.array[idx].AAG[Rtn] += MmePacket->MMENTRY[8 + Rtn];
  2815. }
  2816. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2817. break;
  2818. }
  2819. else
  2820. {
  2821. //The EvMac is not in the database
  2822. //ignore
  2823. sprintf((char*)buf_log_evcomm,
  2824. "[SLAC][Rx][CM_ATTEN_PROFILE_IND]EvMac(%02X%02X%02X%02X%02X%02X): not exist => ignore",
  2825. EvMac_in[0], EvMac_in[1], EvMac_in[2], EvMac_in[3], EvMac_in[4], EvMac_in[5]);
  2826. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2827. break;
  2828. }
  2829. }
  2830. #else //Old SLAC architecture designed by Vern
  2831. {
  2832. AagGroupsNum = MmePacket->MMENTRY[6];
  2833. for(Rtn = 0; Rtn < MmePacket->MMENTRY[6]; Rtn++)
  2834. {
  2835. Aag[Rtn] += MmePacket->MMENTRY[8 + Rtn];
  2836. }
  2837. AttenProfileCnt++;
  2838. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2839. break;
  2840. }
  2841. #endif
  2842. }
  2843. case MMTYPE_CM_ATTEN_CHAR_RSP:
  2844. {
  2845. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2846. {
  2847. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_ATTEN_CHAR_RSP ---\n");
  2848. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2849. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2850. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2851. MmePacket->MMENTRY[2],MmePacket->MMENTRY[3],MmePacket->MMENTRY[4],MmePacket->MMENTRY[5],
  2852. MmePacket->MMENTRY[6],MmePacket->MMENTRY[7]);
  2853. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2854. MmePacket->MMENTRY[8],MmePacket->MMENTRY[9],MmePacket->MMENTRY[10],MmePacket->MMENTRY[11],
  2855. MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],MmePacket->MMENTRY[14],MmePacket->MMENTRY[15]);
  2856. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  2857. for(Rtn = 0; Rtn < 17; Rtn++)
  2858. {
  2859. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, MmePacket->MMENTRY[16 + Rtn]);
  2860. }
  2861. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: %s\n", tmpBuf);
  2862. ;
  2863. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  2864. for(Rtn = 0; Rtn < 17; Rtn++)
  2865. {
  2866. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, MmePacket->MMENTRY[33 + Rtn]);
  2867. }
  2868. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: %s\n", tmpBuf);
  2869. DEBUG_PRINTF_EVCOMM_DETAIL("Result: 0x%x\n", MmePacket->MMENTRY[50]); //Fixed value of 0x00 indicates a successful SLAC process
  2870. }
  2871. #endif
  2872. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2873. {
  2874. //Check ODA (Destination Address)
  2875. if (Array_Compare_Identity(CsuMac, MmePacket->ODA, SLAC_EVSE_MAC_LENGTH) == FALSE)
  2876. {
  2877. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][Rx][CM_ATTEN_CHAR_RSP]wrong ODA: ignore");
  2878. break;
  2879. }
  2880. EvMac_in = &MmePacket->OSA[0];
  2881. RunID_in = &MmePacket->MMENTRY[8];
  2882. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2883. //Check Parameters
  2884. if ((MmePacket->MMENTRY[0] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_005] applicationType must be 0x00
  2885. (MmePacket->MMENTRY[1] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_006] securityType must be 0x00
  2886. (SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in) < 0) || //[TC_SECC_VTB_AttenuationCharacterization_007] sourceAddress cannot not be all zero
  2887. (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_008] check for invalid runID
  2888. (Array_Check_All_Zero(&MmePacket->MMENTRY[16], 17) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_009] SourceID(17 bytes) must be all zero.
  2889. (Array_Check_All_Zero(&MmePacket->MMENTRY[33], 17) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_009] RESP_ID (17 bytes) must be all zero.
  2890. (MmePacket->MMENTRY[50] != 0) //Result: must be 0x00(Success)
  2891. )
  2892. {
  2893. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry++;
  2894. sprintf((char*)buf_log_evcomm,
  2895. "[WARNING][SLAC][Rx]CM_ATTEN_CHAR_RSP:invalid para(%d,%d,%d,%d,%d) => %d-th retry",
  2896. MmePacket->MMENTRY[0], //applicationType must be 0x00
  2897. MmePacket->MMENTRY[1], //securityType must be 0x00
  2898. SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in),
  2899. SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in),
  2900. MmePacket->MMENTRY[50],
  2901. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry
  2902. );
  2903. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2904. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry <= 2) //limited to 2 retries
  2905. {
  2906. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2907. ftime(&SeqStartTime);
  2908. break;
  2909. }
  2910. else
  2911. {
  2912. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR][SLAC][Rx]CM_ATTEN_CHAR_RSP:invalid para => 2-retry fail => End_Process");
  2913. Update_V2G_Flow_Status(Other_Fault);
  2914. break;
  2915. }
  2916. }
  2917. else
  2918. {
  2919. //The CM_ATTEN_CHAR_IND is legal
  2920. SLAC_INFO.array[idx].AttenCharRspCnt++;
  2921. sprintf((char*)buf_log_evcomm,
  2922. "[SLAC][Rx]CM_ATTEN_CHAR_RSP[%d]:%d-th",
  2923. (idx + 1),
  2924. SLAC_INFO.array[idx].AttenCharRspCnt);
  2925. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2926. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry = 0;
  2927. Update_V2G_Flow_Status(CM_ATTEN_CHAR_RSP);
  2928. ftime(&SeqStartTime);
  2929. break;
  2930. }
  2931. }
  2932. #else
  2933. {
  2934. //Check Parameters
  2935. if ((MmePacket->MMENTRY[0] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_005] applicationType must be 0x00
  2936. (MmePacket->MMENTRY[1] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_006] securityType must be 0x00
  2937. (Array_Compare_Identity(SLAC_INFO.array[0].EvMac, &MmePacket->MMENTRY[2], 6) == TRUE) || //[TC_SECC_VTB_AttenuationCharacterization_007] sourceAddress cannot not be all zero
  2938. (Array_Compare_Identity(SLAC_INFO.array[0].RunID, &MmePacket->MMENTRY[8], 8) == TRUE) //[TC_SECC_VTB_AttenuationCharacterization_008] check for invalid runID
  2939. )
  2940. {
  2941. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry++;
  2942. sprintf((char*)buf_log_evcomm,
  2943. "[WARNING][SLAC][Rx]CM_ATTEN_CHAR_RSP: invalid parameters(%d-th)",
  2944. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  2945. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2946. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry <= 2) //limited to 2 retries
  2947. {
  2948. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2949. ftime(&SeqStartTime);
  2950. break;
  2951. }
  2952. else
  2953. {
  2954. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]CM_ATTEN_CHAR_RSP: invalid parameters => End_Process");
  2955. Update_V2G_Flow_Status(Other_Fault);
  2956. ftime(&SeqStartTime);
  2957. break;
  2958. }
  2959. }
  2960. else
  2961. {
  2962. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry = 0;
  2963. Update_V2G_Flow_Status(CM_ATTEN_CHAR_RSP);
  2964. ftime(&SeqStartTime);
  2965. break;
  2966. }
  2967. }
  2968. #endif
  2969. }
  2970. case MMTYPE_CM_VALIDATE_REQ: //BCB Toggle
  2971. {
  2972. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2973. {
  2974. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_VALIDATE_REQ ---\n");
  2975. DEBUG_PRINTF_EVCOMM_DETAIL("Signal Type: 0x%x\n", MmePacket->MMENTRY[0]); //Fixed value (0x00) to indicate ��PEV S2 toggles on control pilot line��
  2976. 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.
  2977. 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��.
  2978. }
  2979. #endif
  2980. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2981. {
  2982. counter = 0;
  2983. EvMac_in = &MmePacket->OSA[0];
  2984. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2985. if (idx >= 0)
  2986. {
  2987. Update_V2G_Flow_Status(CM_VALIDATE_CNF);
  2988. SLAC_INFO.array[idx].ValidateReqCnt++;
  2989. sprintf((char*)buf_log_evcomm,
  2990. "[SLAC][Rx]CM_VALIDATE_REQ[%d]:%d-th",
  2991. (idx + 1),
  2992. SLAC_INFO.array[idx].ValidateReqCnt);
  2993. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2994. //[To-Do] Protection
  2995. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2996. memcpy(SendMmePacket.ODA, EvMac_in, SLAC_EVMAC_LENGTH);
  2997. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2998. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2999. SendMmePacket.MMV = 0x01;
  3000. SendMmePacket.MMTYPE = MMTYPE_CM_VALIDATE_CNF;
  3001. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3002. SendMmePacketSize = 0;
  3003. if(counter == 0)
  3004. {
  3005. //The First MMTYPE_CM_VALIDATE_REQ because Unicast
  3006. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SignalType(0x00): Fixed value to indicate "EV S2 toggles on control pilot line"
  3007. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //ToggleNum(0x00): Fixed value. In the first VALIDATE Request-Response exchange, the ToggleNum field shall be set to zero.
  3008. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  3009. SendMmePacket.MMENTRY[SendMmePacketSize++] = 1; //0x01 = Ready
  3010. #else
  3011. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  3012. #endif
  3013. }
  3014. else
  3015. {
  3016. //The Second MMTYPE_CM_VALIDATE_REQ because Broadcast
  3017. unsigned char PreStatus = 3;
  3018. unsigned char ToggleNum = 0;
  3019. ftime(&SeqStartTime);
  3020. while(1)
  3021. {
  3022. if((EVCOMM_SYS_INFO.CpState == 4) && (PreStatus == 3))
  3023. {
  3024. ToggleNum++;
  3025. PreStatus = 4;
  3026. }
  3027. else
  3028. {
  3029. PreStatus = 3;
  3030. }
  3031. ftime(&SeqEndTime);
  3032. if(DiffTimeb(SeqStartTime, SeqEndTime) >= (SendMmePacket.MMENTRY[1]*100 + 100))
  3033. {
  3034. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate "PEV S2 toggles on control pilot line"
  3035. SendMmePacket.MMENTRY[SendMmePacketSize++] = ToggleNum;
  3036. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  3037. SendMmePacket.MMENTRY[SendMmePacketSize++] = 2; //0x02 = Success
  3038. #else
  3039. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  3040. #endif
  3041. break;
  3042. }
  3043. }
  3044. }
  3045. SendMmePacketSize += 19; //the size before MMENTRY
  3046. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3047. ftime(&SeqStartTime);
  3048. }
  3049. else
  3050. {
  3051. //EvMac does not exist.
  3052. //ignore
  3053. }
  3054. break;
  3055. }
  3056. #else
  3057. {
  3058. counter = 0;
  3059. for(Rtn = 0; Rtn < 6; Rtn++)
  3060. {
  3061. if(MmePacket->ODA[Rtn] != CsuMac[Rtn])
  3062. {
  3063. counter = 1;
  3064. break;
  3065. }
  3066. }
  3067. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3068. memcpy(SendMmePacket.ODA, EvMac,6);
  3069. memcpy(SendMmePacket.OSA, CsuMac,6);
  3070. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3071. SendMmePacket.MMV = 0x01;
  3072. SendMmePacket.MMTYPE = MMTYPE_CM_VALIDATE_CNF;
  3073. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3074. SendMmePacketSize = 0;
  3075. if(counter == 0)
  3076. {
  3077. //The First MMTYPE_CM_VALIDATE_REQ because Unicast
  3078. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate ��PEV S2 toggles on control pilot line��
  3079. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value In the first VALIDATE Request-Response exchange, the ToggleNum field shall be set to zero.
  3080. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  3081. SendMmePacket.MMENTRY[SendMmePacketSize++] = 1; //0x01 = Ready
  3082. #else
  3083. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  3084. #endif
  3085. }
  3086. else
  3087. {
  3088. //The Second MMTYPE_CM_VALIDATE_REQ because Broadcast
  3089. unsigned char PreStatus = 3, ToggleNum = 0;
  3090. ftime(&SeqStartTime);
  3091. while(1)
  3092. {
  3093. ftime(&SeqEndTime);
  3094. if((EVCOMM_SYS_INFO.CpState == 4) && (PreStatus == 3))
  3095. {
  3096. ToggleNum++;
  3097. PreStatus = 4;
  3098. }
  3099. else
  3100. {
  3101. PreStatus = 3;
  3102. }
  3103. if(DiffTimeb(SeqStartTime, SeqEndTime) >= (SendMmePacket.MMENTRY[1]*100 + 100))
  3104. {
  3105. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate ��PEV S2 toggles on control pilot line��
  3106. SendMmePacket.MMENTRY[SendMmePacketSize++] = ToggleNum;
  3107. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  3108. SendMmePacket.MMENTRY[SendMmePacketSize++] = 2; //0x02 = Success
  3109. #else
  3110. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  3111. #endif
  3112. break;
  3113. }
  3114. }
  3115. }
  3116. SendMmePacketSize += 19; //the size before MMENTRY
  3117. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3118. Update_V2G_Flow_Status(CM_VALIDATE_CNF);
  3119. ftime(&SeqStartTime);
  3120. break;
  3121. }
  3122. #endif
  3123. }
  3124. case MMTYPE_CM_SLAC_MATCH_REQ:
  3125. {
  3126. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3127. {
  3128. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SLAC_MATCH_REQ ---\n");
  3129. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  3130. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  3131. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", MmePacket->MMENTRY[2],MmePacket->MMENTRY[3]); //Fixed value (0x3E) for matching
  3132. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3133. for(Rtn=0; Rtn<17; Rtn++)
  3134. {
  3135. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[4+Rtn]);
  3136. }
  3137. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3138. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3139. for(Rtn=0; Rtn<6; Rtn++)
  3140. {
  3141. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[21+Rtn]);
  3142. }
  3143. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3144. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3145. for(Rtn=0; Rtn<17; Rtn++)
  3146. {
  3147. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[27+Rtn]);
  3148. }
  3149. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3150. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3151. for(Rtn=0; Rtn<6; Rtn++)
  3152. {
  3153. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[44+Rtn]);
  3154. }
  3155. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3156. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3157. for(Rtn=0; Rtn<8; Rtn++)
  3158. {
  3159. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[50+Rtn]);
  3160. }
  3161. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3162. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3163. for(Rtn=0; Rtn<8; Rtn++)
  3164. {
  3165. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[58+Rtn]);
  3166. }
  3167. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3168. }
  3169. #endif
  3170. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3171. {
  3172. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][Rx]CM_SLAC_MATCH_REQ");
  3173. //Check ODA (Destination Address)
  3174. if (Array_Compare_Identity(CsuMac, MmePacket->ODA, SLAC_EVSE_MAC_LENGTH) == FALSE)
  3175. {
  3176. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][Rx][CM_SLAC_MATCH_REQ]wrong ODA: ignore");
  3177. //break; //patch for DEKRA I2SE EVCC (another EVSE MAC Address protection comes as below.)
  3178. }
  3179. EvMac_in = &MmePacket->OSA[0];
  3180. RunID_in = &MmePacket->MMENTRY[50];
  3181. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  3182. if (idx >= 0)
  3183. {
  3184. Update_V2G_Flow_Status(CM_SLAC_MATCH_REQ);
  3185. SLAC_INFO.array[idx].MatchReqNum++;
  3186. sprintf((char*)buf_log_evcomm,
  3187. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:%d-th",
  3188. (idx + 1),
  3189. SLAC_INFO.array[idx].MatchReqNum);
  3190. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3191. //[TC_SECC_VTB_CmSlacMatch_007] APPLICATION_TYPE must be 0x00(EV-EVSE Matching)
  3192. //[TC_SECC_VTB_CmSlacMatch_008]
  3193. if (MmePacket->MMENTRY[0] != 0)
  3194. {
  3195. sprintf((char*)buf_log_evcomm,
  3196. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:wrong APPLICATION_TYPE(%d)",
  3197. (idx + 1),
  3198. MmePacket->MMENTRY[0]);
  3199. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3200. break;
  3201. }
  3202. //[TC_SECC_VTB_CmSlacMatch_009] SECURITY_TYPE must be 0x00(No Security)
  3203. //[TC_SECC_VTB_CmSlacMatch_010]
  3204. if (MmePacket->MMENTRY[1] != 0)
  3205. {
  3206. sprintf((char*)buf_log_evcomm,
  3207. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:wrong SECURITY_TYPE(%d)",
  3208. (idx + 1),
  3209. MmePacket->MMENTRY[1]);
  3210. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3211. break;
  3212. }
  3213. //[TC_SECC_VTB_CmSlacMatch_011] MVFLength must be 0x3E(MatchVarField Length)
  3214. //[TC_SECC_VTB_CmSlacMatch_012]
  3215. if (MmePacket->MMENTRY[2] != 0x3E || MmePacket->MMENTRY[3] != 0x00)
  3216. {
  3217. sprintf((char*)buf_log_evcomm,
  3218. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:wrong MVFLength(%d,%d)",
  3219. (idx + 1),
  3220. MmePacket->MMENTRY[2],
  3221. MmePacket->MMENTRY[3]);
  3222. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3223. break;
  3224. }
  3225. //[TC_SECC_VTB_CmSlacMatch_013] EV ID (muxt be all zero)
  3226. //[TC_SECC_VTB_CmSlacMatch_014]
  3227. if (Array_Check_All_Zero(&MmePacket->MMENTRY[4], 17) == FALSE)
  3228. {
  3229. sprintf((char*)buf_log_evcomm,
  3230. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EV ID",
  3231. (idx + 1));
  3232. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3233. break;
  3234. }
  3235. //[TC_SECC_VTB_CmSlacMatch_015] EV MAC
  3236. //[TC_SECC_VTB_CmSlacMatch_016]
  3237. if (Array_Compare_Identity(EvMac_in, &MmePacket->MMENTRY[21], SLAC_EVMAC_LENGTH) == FALSE)
  3238. {
  3239. sprintf((char*)buf_log_evcomm,
  3240. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EV MAC(%02X:%02X:%02X:%02X:%02X:%02X)",
  3241. (idx + 1),
  3242. MmePacket->MMENTRY[21], MmePacket->MMENTRY[22], MmePacket->MMENTRY[23],
  3243. MmePacket->MMENTRY[24], MmePacket->MMENTRY[25], MmePacket->MMENTRY[26]);
  3244. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3245. break;
  3246. }
  3247. //[TC_SECC_VTB_CmSlacMatch_017] EVSE ID should be all zero
  3248. //[TC_SECC_VTB_CmSlacMatch_018]
  3249. if (Array_Check_All_Zero(&MmePacket->MMENTRY[27], 17) == FALSE)
  3250. {
  3251. sprintf((char*)buf_log_evcomm,
  3252. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EVSE ID",
  3253. (idx + 1));
  3254. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3255. break;
  3256. }
  3257. //[TC_SECC_VTB_CmSlacMatch_019] EVSE MAC
  3258. //[TC_SECC_VTB_CmSlacMatch_020]
  3259. if (Array_Compare_Identity(CsuMac, &MmePacket->MMENTRY[44], SLAC_EVSE_MAC_LENGTH) == FALSE)
  3260. {
  3261. sprintf((char*)buf_log_evcomm,
  3262. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EVSE MAC(%02X:%02X:%02X:%02X:%02X:%02X)",
  3263. (idx + 1),
  3264. MmePacket->MMENTRY[44], MmePacket->MMENTRY[45], MmePacket->MMENTRY[46],
  3265. MmePacket->MMENTRY[47], MmePacket->MMENTRY[48], MmePacket->MMENTRY[49]);
  3266. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3267. break;
  3268. }
  3269. //[TC_SECC_VTB_CmSlacMatch_021]runID: Check RunID
  3270. //[TC_SECC_VTB_CmSlacMatch_022]
  3271. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE &&
  3272. (idx == 0)) //only setup a successful link establishment with the first SLAC Req instance
  3273. {
  3274. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3275. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  3276. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3277. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3278. SendMmePacket.MMV = MmePacket->MMV;
  3279. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_MATCH_CNF;
  3280. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3281. SendMmePacketSize = 0;
  3282. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //APPLICATION_TYPE: Fixed value (0x00: EV-EVSE matching)
  3283. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //SECURITY_TYPE: Fixed value (0x00: No Security)
  3284. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x56; //MVFLength: MatchVarField Length (Fixed value: 0x0056)
  3285. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //MVFLength: MatchVarField Length (Fixed value: 0x0056)
  3286. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //EV ID
  3287. SendMmePacketSize += 17;
  3288. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac_in, SLAC_EVMAC_LENGTH); //EV MAC
  3289. SendMmePacketSize += 6;
  3290. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //EVSE ID
  3291. SendMmePacketSize += 17;
  3292. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, CsuMac, 6); //EVSE MAC
  3293. SendMmePacketSize += 6;
  3294. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, RunID_in, SLAC_RUNID_LENGTH);
  3295. SendMmePacketSize += SLAC_RUNID_LENGTH;
  3296. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 8); //RSVD
  3297. SendMmePacketSize += 8;
  3298. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, Nid, sizeof(Nid)); //NID: Network ID given by the CCo(EVSE)
  3299. SendMmePacketSize += sizeof(Nid); //NID caculated from the random NMK that will be set.
  3300. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //RSVD
  3301. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, NewNmkKey, sizeof(NewNmkKey)); //NMK: Random value
  3302. SendMmePacketSize += sizeof(NewNmkKey); //NMK: Private NMK of the EVSE (random value)
  3303. SendMmePacketSize += 19; //the size before MMENTRY
  3304. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3305. {
  3306. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  3307. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3308. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3309. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3310. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3311. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3312. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3313. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3314. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3315. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_MATCH_CNF ---\n");
  3316. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3317. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3318. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3]);
  3319. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3320. for(Rtn=0; Rtn<17; Rtn++)
  3321. {
  3322. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[4+Rtn]);
  3323. }
  3324. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3325. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3326. for(Rtn=0; Rtn<6; Rtn++)
  3327. {
  3328. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[21+Rtn]);
  3329. }
  3330. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3331. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3332. for(Rtn=0; Rtn<17; Rtn++)
  3333. {
  3334. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[27+Rtn]);
  3335. }
  3336. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3337. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3338. for(Rtn=0; Rtn<6; Rtn++)
  3339. {
  3340. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[44+Rtn]);
  3341. }
  3342. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3343. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3344. for(Rtn=0; Rtn<8; Rtn++)
  3345. {
  3346. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[50+Rtn]);
  3347. }
  3348. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3349. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3350. for(Rtn=0; Rtn<8; Rtn++)
  3351. {
  3352. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[58+Rtn]);
  3353. }
  3354. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3355. DEBUG_PRINTF_EVCOMM_DETAIL("NID: \n");
  3356. for(Rtn=0; Rtn<7; Rtn++)
  3357. {
  3358. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[66+Rtn]);
  3359. }
  3360. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3361. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", SendMmePacket.MMENTRY[73]);
  3362. DEBUG_PRINTF_EVCOMM_DETAIL("NMK: \n");
  3363. for(Rtn=0; Rtn<16; Rtn++)
  3364. {
  3365. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[74+Rtn]);
  3366. }
  3367. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3368. }
  3369. #endif
  3370. Update_V2G_Flow_Status(CM_SLAC_MATCH_CNF);
  3371. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3372. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  3373. sprintf((char*)buf_log_evcomm,
  3374. "[SLAC][Tx]CM_SLAC_MATCH_CNF[%d]",
  3375. (idx + 1));
  3376. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3377. ftime(&SeqStartTime);
  3378. }
  3379. else
  3380. {
  3381. //RunID does not match and it's not the first SLAC request
  3382. //Reset the SLAC database to embrace SLAC retry
  3383. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CM_SLAC_MATCH_REQ]No Real MATCH_REQ");
  3384. SLAC_DB_Reset();
  3385. }
  3386. }
  3387. else
  3388. {
  3389. //OSA(EvMac) does not exist
  3390. }
  3391. break;
  3392. }
  3393. #else
  3394. {
  3395. Update_V2G_Flow_Status(CM_SLAC_MATCH_REQ);
  3396. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][Rx]CM_SLAC_MATCH_REQ");
  3397. memset(&SendMmePacket,0,sizeof(struct MmeHeader));
  3398. memcpy(SendMmePacket.ODA,MmePacket->OSA,6);
  3399. memcpy(SendMmePacket.OSA,CsuMac,6);
  3400. SendMmePacket.MTYPE=htons(EtherType_HomePlug);
  3401. SendMmePacket.MMV=MmePacket->MMV;
  3402. SendMmePacket.MMTYPE=MMTYPE_CM_SLAC_MATCH_CNF;
  3403. SendMmePacket.FMI[0]=SendMmePacket.FMI[1]=0;
  3404. SendMmePacketSize=0;
  3405. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x00) indicating ��PEV-EVSE matching��
  3406. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x00) indicating ��No Security��
  3407. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x56; //Fixed value (0x0056) for matching
  3408. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x0056) for matching
  3409. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,17); //PEV ID
  3410. SendMmePacketSize+=17;
  3411. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,EvMac,6);
  3412. SendMmePacketSize+=6;
  3413. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,17); //EVSE ID
  3414. SendMmePacketSize+=17;
  3415. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,CsuMac,6);
  3416. SendMmePacketSize+=6;
  3417. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,SlacRunId,sizeof(SlacRunId));
  3418. SendMmePacketSize+=sizeof(SlacRunId);
  3419. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,8); //RSVD
  3420. SendMmePacketSize+=8;
  3421. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,Nid,sizeof(Nid));
  3422. SendMmePacketSize+=sizeof(Nid);
  3423. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //RSVD
  3424. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,NewNmkKey,sizeof(NewNmkKey));
  3425. SendMmePacketSize+=sizeof(NewNmkKey);
  3426. SendMmePacketSize+=19; //the size before MMENTRY
  3427. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3428. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  3429. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3430. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3431. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3432. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3433. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3434. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3435. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3436. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3437. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_MATCH_CNF ---\n");
  3438. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3439. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3440. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3]);
  3441. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3442. for(Rtn=0; Rtn<17; Rtn++)
  3443. {
  3444. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[4+Rtn]);
  3445. }
  3446. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3447. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3448. for(Rtn=0; Rtn<6; Rtn++)
  3449. {
  3450. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[21+Rtn]);
  3451. }
  3452. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3453. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3454. for(Rtn=0; Rtn<17; Rtn++)
  3455. {
  3456. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[27+Rtn]);
  3457. }
  3458. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3459. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3460. for(Rtn=0; Rtn<6; Rtn++)
  3461. {
  3462. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[44+Rtn]);
  3463. }
  3464. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3465. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3466. for(Rtn=0; Rtn<8; Rtn++)
  3467. {
  3468. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[50+Rtn]);
  3469. }
  3470. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3471. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3472. for(Rtn=0; Rtn<8; Rtn++)
  3473. {
  3474. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[58+Rtn]);
  3475. }
  3476. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3477. DEBUG_PRINTF_EVCOMM_DETAIL("NID: \n");
  3478. for(Rtn=0; Rtn<7; Rtn++)
  3479. {
  3480. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[66+Rtn]);
  3481. }
  3482. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3483. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", SendMmePacket.MMENTRY[73]);
  3484. DEBUG_PRINTF_EVCOMM_DETAIL("NMK: \n");
  3485. for(Rtn=0; Rtn<16; Rtn++)
  3486. {
  3487. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[74+Rtn]);
  3488. }
  3489. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3490. #endif
  3491. Update_V2G_Flow_Status(CM_SLAC_MATCH_CNF);
  3492. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3493. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  3494. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][Tx]CM_SLAC_MATCH_CNF");
  3495. ftime(&SeqStartTime);
  3496. break;
  3497. }
  3498. #endif
  3499. }
  3500. case MMTYPE_VENDOR_VS_HOST_ACTION:
  3501. {
  3502. struct QcaVendorMmeHeader *RecvPacket;
  3503. RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
  3504. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_VS_HOST_ACTION ---\n");
  3505. switch (RecvPacket->MBODY[0])
  3506. {
  3507. case 0x00:
  3508. //Loader (Device Softloader or Bootloader) ready
  3509. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Loader Ready\n");
  3510. break;
  3511. case 0x01:
  3512. //Firmware Upgrade Ready
  3513. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Firmware Upgrade Ready\n");
  3514. break;
  3515. case 0x02:
  3516. //PIB Update Ready
  3517. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: PIB Update Ready\n");
  3518. break;
  3519. case 0x03:
  3520. //Firmware Upgrade and PIB Update ready
  3521. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Firmware Upgrade and PIB Update ready\n");
  3522. break;
  3523. case 0x04:
  3524. //Loader (Bootloader) ready to receive SDRAM configuration.
  3525. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Loader ready to receive SDRAM configuration\n");
  3526. break;
  3527. case 0x05:
  3528. //Reset to Factory Defaults.
  3529. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Reset to Factory Defaults\n");
  3530. break;
  3531. default:
  3532. //Reserved
  3533. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Reserved\n");
  3534. break;
  3535. }
  3536. break;
  3537. }
  3538. case MMTYPE_VENDOR_ATTEN_CHAR:
  3539. {
  3540. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_ATTEN_CHAR ---\n");
  3541. break;
  3542. }
  3543. case MMTYPE_VENDOR_VS_NW_INFO_CNF:
  3544. {
  3545. memcpy(QcaMac, MmePacket->OSA, 6);
  3546. sprintf((char*)buf_log_evcomm,
  3547. "[QCA7K][Rx][VENDOR_VS_NW_INFO_CNF]Got QCA7K MacAddr:%02X:%02X:%02X:%02X:%02X:%02X (comm:OK)",
  3548. QcaMac[0], QcaMac[1], QcaMac[2], QcaMac[3], QcaMac[4], QcaMac[5]);
  3549. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3550. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_VS_NW_INFO_CNF ---\n");
  3551. DEBUG_PRINTF_EVCOMM_DETAIL("QcaMac: %02x:%02x:%02x:%02x:%02x:%02x\n",
  3552. QcaMac[0],
  3553. QcaMac[1],
  3554. QcaMac[2],
  3555. QcaMac[3],
  3556. QcaMac[4],
  3557. QcaMac[5]);
  3558. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  3559. ftime(&SeqStartTime);
  3560. break;
  3561. }
  3562. default:
  3563. {
  3564. break;
  3565. }
  3566. }
  3567. return 0;
  3568. }
  3569. /*===========================================================================
  3570. FUNCTION: SlacComm
  3571. DESCRIPTION:
  3572. PRE-CONDITION:
  3573. INPUT:
  3574. OUTPUT:
  3575. GLOBAL VARIABLES:
  3576. =============================================================================*/
  3577. int SlacComm()
  3578. {
  3579. static unsigned char qca7k_comm_retry = 0;
  3580. double t_diff = 0;
  3581. int packet_size = 0;
  3582. int count = 0;
  3583. //int idx = 0;
  3584. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3585. unsigned char tmpBuf[2048]={0};
  3586. #endif
  3587. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3588. unsigned char *EvMac_in;
  3589. unsigned char *RunID_in;
  3590. int i = 0;
  3591. #endif
  3592. if(RawSock >= 0)
  3593. {
  3594. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  3595. packet_size = recvfrom(RawSock, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, 0, NULL, NULL);
  3596. if(packet_size > 0)
  3597. {
  3598. /*#ifdef Debug
  3599. DEBUG_PRINTF_EVCOMM_DETAIL("Raw Data: ");
  3600. for(count=0;count<packet_size;count++)
  3601. DEBUG_PRINTF_EVCOMM_DETAIL("0x%x, ",V2gtpMsgRxBuf[count]);
  3602. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3603. #endif*/
  3604. MmeProcess(V2gtpMsgRxBuf, packet_size);
  3605. }
  3606. }
  3607. switch(Check_V2G_Flow_Status())
  3608. {
  3609. case IDLE:
  3610. {
  3611. if(RawSock < 0)
  3612. {
  3613. RawSock = socket(PF_PACKET, SOCK_RAW, htons(EtherType_HomePlug));
  3614. sprintf((char*)buf_log_evcomm, "[RawSock]opened(%d)", RawSock);
  3615. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3616. if(RawSock == -1)
  3617. {
  3618. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Failed to create socket");
  3619. Update_V2G_Flow_Status(Other_Fault);
  3620. return -1;
  3621. }
  3622. if (setsockopt(RawSock, SOL_SOCKET, SO_BINDTODEVICE, QcaInterface, 4) < 0)
  3623. {
  3624. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Set SO_BINDTODEVICE NG");
  3625. Update_V2G_Flow_Status(Other_Fault);
  3626. return -1;
  3627. }
  3628. struct timeval tv;
  3629. tv.tv_sec = 0;
  3630. tv.tv_usec = 100000; //100ms (Rx timeout)
  3631. if (setsockopt(RawSock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  3632. {
  3633. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Set SO_RCVTIMEO NG");
  3634. Update_V2G_Flow_Status(Other_Fault);
  3635. return -1;
  3636. }
  3637. tv.tv_usec = 100000; //100ms (Tx timeout)
  3638. if (setsockopt(RawSock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  3639. {
  3640. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Set SO_SNDTIMEO NG");
  3641. Update_V2G_Flow_Status(Other_Fault);
  3642. return -1;
  3643. }
  3644. memset(&Req, 0, sizeof(struct ifreq));
  3645. strcpy( (char*)Req.ifr_name, QcaInterface);
  3646. if (ioctl(RawSock, SIOCGIFINDEX, &Req) < 0)
  3647. {
  3648. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm: ioctl NG");
  3649. Update_V2G_Flow_Status(Other_Fault);
  3650. return -1;
  3651. }
  3652. memset( &DestSocketAddress, 0, sizeof(struct sockaddr_ll));
  3653. DestSocketAddress.sll_ifindex = Req.ifr_ifindex;
  3654. DestSocketAddress.sll_halen = ETH_ALEN;
  3655. PwmStartTime = 0;
  3656. EVCOMM_SYS_INFO.QCA7K_SetKeyDone = FALSE;
  3657. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[QCA7K]connecting...");
  3658. //Get QCA7K MAC address
  3659. GetQca7kMac();
  3660. ftime(&SeqStartTime);
  3661. break;
  3662. }
  3663. else //RawSock: opened
  3664. {
  3665. if(EVCOMM_SYS_INFO.QCA7K_SetKeyDone == FALSE)
  3666. {
  3667. ftime(&SeqEndTime);
  3668. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3669. if (t_diff > V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD) //3 secs
  3670. {
  3671. qca7k_comm_retry++;
  3672. sprintf((char*)buf_log_evcomm,
  3673. "Re-try connecting...(%.02lf/%dms)",
  3674. t_diff,
  3675. V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD);
  3676. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3677. GetQca7kMac(); //re-send req
  3678. ftime(&SeqStartTime);
  3679. break;
  3680. }
  3681. else
  3682. {
  3683. //null
  3684. }
  3685. //Retry by 3 times
  3686. if (qca7k_comm_retry >= 3)
  3687. {
  3688. sprintf((char*)buf_log_evcomm,
  3689. "[Error]Comm: fail (retry by %d times)",
  3690. qca7k_comm_retry);
  3691. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3692. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3693. //CCS_SECCC_TIMEOUT_QCA7000_COMM (023892): The firmware code of QCA7000 may not be installed, yet
  3694. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3695. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3696. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3697. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3698. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  3699. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  3700. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3701. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3702. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  3703. Update_V2G_Flow_Status(Sequence_Timeout);
  3704. qca7k_comm_retry = 0;
  3705. break;
  3706. }
  3707. }
  3708. else //RawSock: opened; Set Key: DONE
  3709. {
  3710. if((CheckConnectorPlugIn() == TRUE) && (ShmInternalComm->ChargingPermission == TRUE))
  3711. {
  3712. if(PwmStartTime <= 0)
  3713. {
  3714. //Sniffer_Tcpdump(ENABLE);
  3715. //#if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  3716. //sleep(1); //wait for tcpdump to be ready.
  3717. //#endif
  3718. SwitchCpStateE(DISABLE);
  3719. OutputCpPwmDuty(5);
  3720. PwmStartTime = time(NULL);
  3721. }
  3722. else
  3723. {
  3724. if((time(NULL) - PwmStartTime) > TT_EVSE_SLAC_init)
  3725. {
  3726. sprintf((char*)buf_log_evcomm,
  3727. "SlacComm: Wait CM_SLAC_PARM_REQ Timeout - TT_EVSE_SLAC_init, NowTime(%ld)-PwmStartTime(%d)>%d (sec)",
  3728. time(NULL),
  3729. PwmStartTime,
  3730. TT_EVSE_SLAC_init);
  3731. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3732. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3733. //CCS_SECC_TIMEOUT_SLAC_TT_EVSE_SLAC_init (023809)
  3734. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3735. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3736. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3737. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3738. ShmStatusCodeData->PresentStatusCode[0][4] = 0;
  3739. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  3740. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  3741. Update_V2G_Flow_Status(Sequence_Timeout);
  3742. PwmStartTime = 0;
  3743. return -1;
  3744. }
  3745. else
  3746. {
  3747. //waiting for CM_SLAC_PARM_REQ
  3748. }
  3749. }
  3750. }
  3751. else
  3752. {
  3753. PwmStartTime = 0;
  3754. }
  3755. }
  3756. }
  3757. break;
  3758. }
  3759. case CM_SET_KEY_REQ: //13
  3760. {
  3761. //CM_SET_KEY_REQ
  3762. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[QCA7K][Rx]CM_SET_KEY_REQ");
  3763. ftime(&SeqEndTime);
  3764. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3765. if (t_diff > V2G_SECC_QCA7000_COMM_TIMEOUT) //10 seconds
  3766. {
  3767. sprintf((char*)buf_log_evcomm,
  3768. "[QCA7K]Failed on SetKey => End_Process (%.02lf/%dms)",
  3769. t_diff,
  3770. V2G_SECC_QCA7000_COMM_TIMEOUT);
  3771. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3772. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3773. //CCS_SECCC_TIMEOUT_QCA7000_COMM (023892): The firmware code of QCA7000 may not be installed, yet
  3774. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3775. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3776. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3777. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3778. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  3779. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  3780. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3781. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3782. Update_V2G_Flow_Status(Sequence_Timeout);
  3783. }
  3784. else if (t_diff > V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD) //2 seconds
  3785. {
  3786. sprintf((char*)buf_log_evcomm,
  3787. "[QCA7K]SetKey: proceed (%.02lf/%dms)",
  3788. t_diff,
  3789. V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD);
  3790. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3791. SendSetKey();
  3792. ftime(&SeqStartTime);
  3793. }
  3794. else
  3795. {
  3796. //null
  3797. }
  3798. break;
  3799. }
  3800. case CM_SET_KEY_CNF: //14
  3801. {
  3802. sprintf((char*)buf_log_evcomm,
  3803. "[SECCReady]Wait: plugin(%d), matached(%d), permission(%d)...",
  3804. CheckConnectorPlugIn(),
  3805. CSUCOMMDC_TASK_FLAG.matched,
  3806. ShmInternalComm->ChargingPermission
  3807. );
  3808. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3809. EVCOMM_SYS_INFO.QCA7K_SetKeyDone = TRUE;
  3810. PwmStartTime = 0;
  3811. Update_V2G_Flow_Status(IDLE);
  3812. break;
  3813. }
  3814. case CM_SLAC_PARM_CONF:
  3815. {
  3816. ftime(&SeqEndTime);
  3817. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_sequence)
  3818. {
  3819. sprintf((char*)buf_log_evcomm,
  3820. "SlacComm: Wait CM_START_ATTEN_CHAR_IND Timeout - TT_match_sequence (%.02lf of %dms)",
  3821. DiffTimeb(SeqStartTime, SeqEndTime),
  3822. TT_match_sequence);
  3823. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3824. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3825. //CCS_SECC_TIMEOUT_CM_START_ATTEN_CHAR_IND (023811):
  3826. //[Possible Reason] CCS Board image might not be updated properly. The 2nd reboot process is not finished.
  3827. //[Verification Method] By tying reboot command to the terminal and see if it could be executed immediately.
  3828. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3829. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3830. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3831. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3832. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  3833. ShmStatusCodeData->PresentStatusCode[0][5] = 1;
  3834. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3835. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3836. Update_V2G_Flow_Status(Sequence_Timeout);
  3837. return -1;
  3838. }
  3839. break;
  3840. }
  3841. case CM_START_ATTEN_CHAR_IND:
  3842. {
  3843. ftime(&SeqEndTime);
  3844. if(DiffTimeb(SeqStartTime, SeqEndTime) > (TP_EV_batch_msg_interval)) //one more time interval for tolerance
  3845. {
  3846. sprintf((char*)buf_log_evcomm,
  3847. "SlacComm: Wait CM_MNBC_SOUND_IND Timeout - TP_EV_batch_msg_interval (%.02lf of %dms)",
  3848. DiffTimeb(SeqStartTime, SeqEndTime),
  3849. TP_EV_batch_msg_interval);
  3850. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3851. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3852. //CCS_SECC_TIMEOUT_SLAC_CM_MNBC_SOUND_IND (023818):
  3853. //[Possible Reason] CCS Board image might not be updated properly. The 2nd reboot process is not finished.
  3854. //[Verification Method] By tying reboot command to the terminal and see if it could be executed immediately.
  3855. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3856. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3857. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3858. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3859. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  3860. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  3861. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3862. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3863. Update_V2G_Flow_Status(Sequence_Timeout);
  3864. return -1;
  3865. }
  3866. break;
  3867. }
  3868. case CM_MNBC_SOUND_IND:
  3869. {
  3870. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3871. {
  3872. ftime(&SeqEndTime);
  3873. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3874. //printf("time:%.02lf, profilNum:%d\n",DiffTimeb(SeqStartTime, SeqEndTime),AttenProfileCnt); //added by Vern
  3875. if(t_diff > TT_EVSE_match_MNBC ||
  3876. (SLAC_INFO.array[0].AttenProfileCnt >= SLAC_INFO.array[0].MnbcSoundNum) ||
  3877. (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)) //TC_SECC_VTB_AttenuationCharacterization_003
  3878. {
  3879. //Wait for other SLAC Req sets
  3880. if ((SLAC_INFO.arrayLen >= 2) &&
  3881. (t_diff < TT_EVSE_match_MNBC) &&
  3882. (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry == 0)) //not a retry
  3883. {
  3884. break;
  3885. }
  3886. //Check if it is a timeup response
  3887. if (t_diff > TT_EVSE_match_MNBC)
  3888. {
  3889. sprintf((char*)buf_log_evcomm,
  3890. "[WARNING][SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: timeup(%.2f/%dms) => send",
  3891. (i + 1),
  3892. t_diff,
  3893. TT_EVSE_match_MNBC);
  3894. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3895. }
  3896. //Sending all CM_ATTEN_CHAR_IND according to all corresponding SLAC Req sets
  3897. for (i = 0; i < SLAC_INFO.arrayLen; i++)
  3898. {
  3899. if ((SLAC_INFO.array[i].AttenProfileCnt == 0) ||
  3900. (SLAC_INFO.array[i].AagGroupsNum == 0) ||
  3901. (SLAC_INFO.array[i].StartAttenCharCnt == 0) ||
  3902. (SLAC_INFO.array[i].MnbcSoundNum != 10) || //received in CM_START_ATTEN_CHAR_IND
  3903. (SLAC_INFO.array[i].StartAttenCharErr == TRUE)
  3904. )
  3905. {
  3906. //Ignoring those SLAC request sets without sending CM_MNBC_SOUND_IND(CM_ATTEN_PROFILE_IND)
  3907. sprintf((char*)buf_log_evcomm,
  3908. "[WARNING][SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: para err(%d,%d,%d,%d,%d) => canceled",
  3909. (i + 1),
  3910. SLAC_INFO.array[i].AttenProfileCnt,
  3911. SLAC_INFO.array[i].AagGroupsNum,
  3912. SLAC_INFO.array[i].StartAttenCharCnt,
  3913. SLAC_INFO.array[i].MnbcSoundNum,
  3914. SLAC_INFO.array[i].StartAttenCharErr);
  3915. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3916. continue;
  3917. }
  3918. //In CM_ATTEN_CHAR_IND retry process, here only re-send this message according to the 1st coming SLAC request
  3919. if ((EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0) && (i != 0))
  3920. {
  3921. sprintf((char*)buf_log_evcomm,
  3922. "[NOTE][SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: canceled",
  3923. (i + 1));
  3924. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3925. break;
  3926. }
  3927. EvMac_in = SLAC_INFO.array[i].EvMac;
  3928. RunID_in = SLAC_INFO.array[i].RunID;
  3929. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3930. memcpy(SendMmePacket.ODA, EvMac_in, SLAC_EVMAC_LENGTH);
  3931. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3932. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3933. SendMmePacket.MMV = 0x01;
  3934. SendMmePacket.MMTYPE = MMTYPE_CM_ATTEN_CHAR_IND;
  3935. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3936. SendMmePacketSize = 0;
  3937. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00: EV-EVSE Matching)
  3938. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00: No Security)
  3939. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac_in, SLAC_EVMAC_LENGTH); //SOURCE_ADDRESS, MAC address of the EV Host
  3940. SendMmePacketSize += SLAC_EVMAC_LENGTH;
  3941. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, RunID_in, SLAC_RUNID_LENGTH);
  3942. SendMmePacketSize += SLAC_RUNID_LENGTH;
  3943. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //SOURCE_ID(0x00)
  3944. SendMmePacketSize += 17;
  3945. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //RESP_ID(0x00)
  3946. SendMmePacketSize += 17;
  3947. SendMmePacket.MMENTRY[SendMmePacketSize++] = SLAC_INFO.array[i].AttenProfileCnt; //NumSounds: Number of M-Sounds used for generation of the ATTEN_PROFILE
  3948. SendMmePacket.MMENTRY[SendMmePacketSize++] = SLAC_INFO.array[i].AagGroupsNum; //NumGroups
  3949. for(count = 0; count < SLAC_INFO.array[i].AagGroupsNum; count++)
  3950. {
  3951. unsigned char TmpAag;
  3952. TmpAag = ((SLAC_INFO.array[i].AAG[count] / SLAC_INFO.array[i].AttenProfileCnt) & 0xFF);
  3953. SLAC_INFO.array[i].AAG_quality_ori += (float) TmpAag; //original signal quality
  3954. #if (SUDO_PSD_PARAMETER_MECHANISM == ENABLE) //default: ENABLE
  3955. #if 1
  3956. //TC_SECC_VTB_AttenuationCharacterization_019
  3957. TmpAag = TmpAag >> 1; //new method proposed by Joseph (divided by 2)
  3958. #else
  3959. if(TmpAag >= 39) //original method proposed by Vern
  3960. {
  3961. TmpAag = 37;
  3962. }
  3963. #endif
  3964. #endif
  3965. SendMmePacket.MMENTRY[SendMmePacketSize++] = TmpAag;
  3966. SLAC_INFO.array[i].AAG_quality_refined += (float) TmpAag; //refined signal quality
  3967. }
  3968. SendMmePacketSize += 19; //the size before MMENTRY
  3969. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3970. {
  3971. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Send MME Packet *****\n");
  3972. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3973. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3974. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3975. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3976. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3977. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3978. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3979. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3980. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_ATTEN_CHAR_IND ---\n");
  3981. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3982. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3983. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  3984. SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5],
  3985. SendMmePacket.MMENTRY[6],SendMmePacket.MMENTRY[7]);
  3986. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  3987. SendMmePacket.MMENTRY[8],SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],
  3988. SendMmePacket.MMENTRY[12],SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14],SendMmePacket.MMENTRY[15]);
  3989. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3990. for(count=0; count<17; count++)
  3991. {
  3992. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[16+count]);
  3993. }
  3994. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: %s\n", tmpBuf);
  3995. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3996. for(count=0; count<17; count++)
  3997. {
  3998. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[33+count]);
  3999. }
  4000. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: %s\n", tmpBuf);
  4001. DEBUG_PRINTF_EVCOMM_DETAIL("NumSounds: 0x%x\n", SendMmePacket.MMENTRY[50]);
  4002. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  4003. for(count=0; count<AagGroupsNum; count++)
  4004. {
  4005. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[51+count]);
  4006. }
  4007. DEBUG_PRINTF_EVCOMM_DETAIL("ATTEN_PROFILE: %s\n", tmpBuf);
  4008. }
  4009. #endif
  4010. count = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  4011. SLAC_INFO.array[i].AAG_quality_ori /= SLAC_INFO.array[i].AagGroupsNum;
  4012. SLAC_INFO.array[i].AAG_quality_refined /= SLAC_INFO.array[i].AagGroupsNum;
  4013. //Print log if this CM_ATTEN_CHAR_IND belongs to RETRY Tx message.
  4014. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)
  4015. {
  4016. sprintf((char*)buf_log_evcomm,
  4017. "[SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: %d-th resend (Q=%.2f/%.2f)(%d/%d)",
  4018. (i + 1),
  4019. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry,
  4020. SLAC_INFO.array[i].AAG_quality_refined,
  4021. SLAC_INFO.array[i].AAG_quality_ori,
  4022. SLAC_INFO.array[i].AttenProfileCnt,
  4023. SLAC_INFO.array[i].MnbcSoundNum);
  4024. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4025. }
  4026. else if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry == 0)
  4027. {
  4028. sprintf((char*)buf_log_evcomm,
  4029. "[SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: Q=%.2f/%.2f(%d/%d)",
  4030. (i + 1),
  4031. SLAC_INFO.array[i].AAG_quality_refined,
  4032. SLAC_INFO.array[i].AAG_quality_ori,
  4033. SLAC_INFO.array[i].AttenProfileCnt,
  4034. SLAC_INFO.array[i].MnbcSoundNum);
  4035. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4036. }
  4037. else
  4038. {
  4039. sprintf((char*)buf_log_evcomm,
  4040. "[SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: unexpected CM_ATTEN_CHAR_IND_retry(%d))",
  4041. i,
  4042. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  4043. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4044. }
  4045. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n", SendMmePacketSize,count);
  4046. } //end of for loop
  4047. Update_V2G_Flow_Status(CM_ATTEN_CHAR_IND);
  4048. ftime(&SeqStartTime);
  4049. }
  4050. break;
  4051. }
  4052. #else
  4053. {
  4054. ftime(&SeqEndTime);
  4055. //printf("time:%.02lf, profilNum:%d\n",DiffTimeb(SeqStartTime, SeqEndTime),AttenProfileCnt); //added by Vern
  4056. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_EVSE_match_MNBC || (AttenProfileCnt >= MnbcSoundNum) || (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0))
  4057. {
  4058. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  4059. memcpy(SendMmePacket.ODA, EvMac, 6);
  4060. memcpy(SendMmePacket.OSA, CsuMac, 6);
  4061. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  4062. SendMmePacket.MMV = 0x01;
  4063. SendMmePacket.MMTYPE = MMTYPE_CM_ATTEN_CHAR_IND;
  4064. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  4065. SendMmePacketSize = 0;
  4066. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00: EV-EVSE Matching)
  4067. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00: No Security)
  4068. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac, 6); //SOURCE_ADDRESS, MAC address of the EV Host
  4069. SendMmePacketSize += 6;
  4070. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize, SlacRunId, sizeof(SlacRunId));
  4071. SendMmePacketSize += sizeof(SlacRunId);
  4072. memset(SendMmePacket.MMENTRY+SendMmePacketSize, 0, 17); //SOURCE_ID
  4073. SendMmePacketSize += 17;
  4074. memset(SendMmePacket.MMENTRY+SendMmePacketSize, 0, 17); //RESP_ID
  4075. SendMmePacketSize += 17;
  4076. SendMmePacket.MMENTRY[SendMmePacketSize++] = AttenProfileCnt; //NumSounds
  4077. SendMmePacket.MMENTRY[SendMmePacketSize++] = AagGroupsNum; //NumGroups
  4078. for(count=0; count < AagGroupsNum; count++)
  4079. {
  4080. unsigned char TmpAag;
  4081. TmpAag = ((Aag[count] / AttenProfileCnt) & 0xFF);
  4082. #if (SUDO_PSD_PARAMETER_MECHANISM == ENABLE) //default: ENABLE
  4083. #if 1
  4084. //TC_SECC_VTB_AttenuationCharacterization_019
  4085. TmpAag = TmpAag >> 1; //new method proposed by Joseph (divided by 2)
  4086. #else
  4087. if(TmpAag >= 39) //original method proposed by Vern
  4088. {
  4089. /*
  4090. // [To-do] If this statement is enabled, SLAC will fail due to timeout.
  4091. {
  4092. unsigned char TmpBuf[64];
  4093. memset(TmpBuf,0,sizeof(TmpBuf));
  4094. sprintf((char*)TmpBuf,"SlacComm: bad Aag[%d]=%d",count,TmpAag);
  4095. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", TmpBuf);
  4096. }
  4097. */
  4098. printf("%d,", TmpAag);
  4099. TmpAag = 37;
  4100. }
  4101. #endif
  4102. #endif
  4103. SendMmePacket.MMENTRY[SendMmePacketSize++] = TmpAag;
  4104. }
  4105. SendMmePacketSize += 19; //the size before MMENTRY
  4106. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  4107. {
  4108. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Send MME Packet *****\n");
  4109. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  4110. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  4111. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  4112. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  4113. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  4114. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  4115. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  4116. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  4117. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_ATTEN_CHAR_IND ---\n");
  4118. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  4119. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  4120. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  4121. SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5],
  4122. SendMmePacket.MMENTRY[6],SendMmePacket.MMENTRY[7]);
  4123. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  4124. SendMmePacket.MMENTRY[8],SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],
  4125. SendMmePacket.MMENTRY[12],SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14],SendMmePacket.MMENTRY[15]);
  4126. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  4127. for(count=0; count<17; count++)
  4128. {
  4129. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[16+count]);
  4130. }
  4131. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: %s\n", tmpBuf);
  4132. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));;
  4133. for(count=0; count<17; count++)
  4134. {
  4135. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[33+count]);
  4136. }
  4137. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: %s\n", tmpBuf);
  4138. DEBUG_PRINTF_EVCOMM_DETAIL("NumSounds: 0x%x\n", SendMmePacket.MMENTRY[50]);
  4139. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  4140. for(count=0; count<AagGroupsNum; count++)
  4141. {
  4142. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[51+count]);
  4143. }
  4144. DEBUG_PRINTF_EVCOMM_DETAIL("ATTEN_PROFILE: %s\n", tmpBuf);
  4145. }
  4146. #endif
  4147. Update_V2G_Flow_Status(CM_ATTEN_CHAR_IND);
  4148. count = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  4149. //Print log if this CM_ATTEN_CHAR_IND belongs to RETRY Tx message.
  4150. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)
  4151. {
  4152. sprintf((char*)buf_log_evcomm,
  4153. "[SLAC][Tx]CM_ATTEN_CHAR_IND: resend(%d-th)",
  4154. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  4155. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4156. }
  4157. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n", SendMmePacketSize,count);
  4158. ftime(&SeqStartTime);
  4159. }
  4160. break;
  4161. }
  4162. #endif
  4163. }
  4164. case CM_ATTEN_CHAR_IND:
  4165. {
  4166. ftime(&SeqEndTime);
  4167. //if(DiffTimeb(SeqStartTime, SeqEndTime)>TT_match_response)
  4168. 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.
  4169. {
  4170. sprintf((char*)buf_log_evcomm,
  4171. "SlacComm: Wait CM_ATTEN_CHAR_RSP Timeout - TT_match_response (%.02lf of %dms)",
  4172. DiffTimeb(SeqStartTime, SeqEndTime),
  4173. TT_match_response);
  4174. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4175. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4176. //CCS_SECC_TIMEOUT_SLAC_CM_ATTEN_CHAR_RSP (023814):
  4177. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4178. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4179. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4180. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4181. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4182. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4183. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  4184. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4185. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4186. Update_V2G_Flow_Status(Sequence_Timeout);
  4187. return -1;
  4188. }
  4189. break;
  4190. }
  4191. case CM_ATTEN_CHAR_RSP:
  4192. {
  4193. ftime(&SeqEndTime);
  4194. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_EVSE_match_session)
  4195. {
  4196. sprintf((char*)buf_log_evcomm,
  4197. "SlacComm: Wait CM_VALIDATE_REQ_1ST or CM_SLAC_MATCH_REQ Timeout - TT_EVSE_match_session (%.02lf of %dms)",
  4198. DiffTimeb(SeqStartTime, SeqEndTime),
  4199. TT_EVSE_match_session);
  4200. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4201. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4202. //CCS_SECC_TIMEOUT_SLAC_CM_VALIDATE_REQ_1ST__CM_SLAC_MATCH_REQ (023815):
  4203. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4204. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4205. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4206. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4207. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4208. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4209. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  4210. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4211. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4212. Update_V2G_Flow_Status(Sequence_Timeout);
  4213. return -1;
  4214. }
  4215. break;
  4216. }
  4217. case CM_VALIDATE_CNF:
  4218. {
  4219. ftime(&SeqEndTime);
  4220. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_sequence)
  4221. {
  4222. sprintf((char*)buf_log_evcomm,
  4223. "SlacComm: Wait CM_VALIDATE_REQ_2ND or CM_SLAC_MATCH_REQ Timeout - TT_match_sequence (%.02lf of %dms)",
  4224. DiffTimeb(SeqStartTime, SeqEndTime),
  4225. TT_match_sequence);
  4226. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4227. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4228. //CCS_SECC_TIMEOUT_SLAC_CM_VALIDATE_REQ_2ND__CM_SLAC_MATCH_REQ (023819):
  4229. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4230. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4231. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4232. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4233. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4234. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4235. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  4236. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4237. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4238. Update_V2G_Flow_Status(Sequence_Timeout);
  4239. return -1;
  4240. }
  4241. break;
  4242. }
  4243. case CM_SLAC_MATCH_CNF:
  4244. {
  4245. if(UdpSock > 0)
  4246. {
  4247. close(UdpSock);
  4248. UdpSock = -1;
  4249. }
  4250. if(TcpSock > 0)
  4251. {
  4252. close(TcpSock);
  4253. TcpSock = -1;
  4254. }
  4255. ftime(&SeqStartTime);
  4256. V2gTcpConnected();
  4257. Update_V2G_Flow_Status(SLACC_SDP_UDP_Connection);
  4258. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SLAAC,SDP,UDP: connecting...");
  4259. break;
  4260. }
  4261. default:
  4262. {
  4263. break;
  4264. }
  4265. }
  4266. return 0;
  4267. }
  4268. /*===========================================================================
  4269. FUNCTION: V2gMsgDecoder
  4270. DESCRIPTION:
  4271. 1. Decode the V2GTP messages inside "msg" and save the decoded
  4272. messages in ccs_exi_doc_DIN, ccs_exi_doc_ISO1, and ccs_exi_doc_ISO2,
  4273. respectively.
  4274. 2. After decoding, V2gMsg_Process() could then use
  4275. ccs_exi_doc_DIN, ccs_exi_doc_ISO1, or ccs_exi_doc_ISO2
  4276. to deal with the corresponding Response messages, respectively.
  4277. PRE-CONDITION:
  4278. 1. msg_length > 0
  4279. INPUT:
  4280. 1. msg
  4281. 2. msg_length
  4282. OUTPUT:
  4283. 1. ccs_exi_doc_DIN //global variable
  4284. ccs_exi_doc_ISO1
  4285. ccs_exi_doc_ISO2
  4286. 2. v2g_state //Status Flag
  4287. //indicating the V2gMsg_Process_din to proceed
  4288. the next process.
  4289. 3. return value // < 0: ERROR
  4290. // > 0: Message Type
  4291. GLOBAL VARIABLES:
  4292. =============================================================================*/
  4293. int V2gMsgDecoder(unsigned char *msg, unsigned int msg_length, unsigned int v2g_state)
  4294. {
  4295. int errn = 0;
  4296. //Checking the minimum Header size requirement
  4297. if(msg_length < V2GTP_MSG_HEADER_LENGTH) //The minimum requirement should be 8-byte header.
  4298. {
  4299. errn = -1;
  4300. return errn;
  4301. }
  4302. //Decode the 1st V2GMSG: AppProtocol
  4303. if(v2g_state == SupportedAppProtocolRequest) //17
  4304. {
  4305. if ((errn = API_V2GMSG_EXI_Decoder_AppProtocol(msg, msg_length, &ccs_handshake)) < 0)
  4306. {
  4307. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR = %d (DEC)]V2gMsgDecoder: SupportedAppProtocolRequest()\n", errn);
  4308. }
  4309. else //decoded successfully.
  4310. {
  4311. //PRINT_XML_DOC_supportedAppProtocolReq(&ccs_handshake);
  4312. }
  4313. }
  4314. //Decode the subsequent V2GMSG (DIN 70121, ISO 15118-2, ISO 15118-20)
  4315. else if(v2g_state > SupportedAppProtocolRequest && v2g_state <= SessionStopResponse)
  4316. {
  4317. //Decoding according to its own protocol
  4318. switch (ShmCcsData->CommProtocol)
  4319. {
  4320. case V2GT_MSG_PROTOCOL_DIN70121: //0
  4321. {
  4322. //DIN
  4323. if((errn = API_V2GMSG_EXI_Decoder_DIN(msg, msg_length, &ccs_exi_doc_DIN)) < 0)
  4324. {
  4325. sprintf((char*)buf_log_evcomm,
  4326. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_DIN()",
  4327. errn);
  4328. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4329. }
  4330. break;
  4331. }
  4332. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  4333. {
  4334. //ISO1
  4335. if((errn = API_V2GMSG_EXI_Decoder_ISO1(msg, msg_length, &ccs_exi_doc_ISO1)) < 0)
  4336. {
  4337. sprintf((char*)buf_log_evcomm,
  4338. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_ISO1()",
  4339. errn);
  4340. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4341. }
  4342. break;
  4343. }
  4344. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  4345. {
  4346. //ISO2
  4347. if((errn = API_V2GMSG_EXI_Decoder_ISO2(msg, msg_length, &ccs_exi_doc_ISO2)) < 0)
  4348. {
  4349. sprintf((char*)buf_log_evcomm,
  4350. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_ISO2()",
  4351. errn);
  4352. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4353. }
  4354. break;
  4355. }
  4356. default:
  4357. break;
  4358. }
  4359. }
  4360. else
  4361. {
  4362. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR = %d (DEC)]V2gMsgDecoder: Unexpected v2g_state\n", errn);
  4363. errn = -1;
  4364. }
  4365. return errn;
  4366. }
  4367. /*===========================================================================
  4368. FUNCTION: encode_din_V2GTP_stream
  4369. DESCRIPTION:
  4370. PRE-CONDITION:
  4371. INPUT:
  4372. OUTPUT:
  4373. GLOBAL VARIABLES:
  4374. =============================================================================*/
  4375. int encode_din_V2GTP_stream(bitstream_t *v2g_tx_stream, struct dinEXIDocument *ccs_exi_doc_DIN)
  4376. {
  4377. int errn = 0;
  4378. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4379. errn = encode_dinExiDocument(v2g_tx_stream, ccs_exi_doc_DIN);
  4380. if (errn == 0)
  4381. {
  4382. //successfully encoded
  4383. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4384. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4385. if (errn != 0)
  4386. {
  4387. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_din_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4388. }
  4389. }
  4390. else
  4391. {
  4392. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_din_V2GTP_stream]encode_dinExiDocument(): %d (DEC)\n", errn);
  4393. }
  4394. return errn;
  4395. }
  4396. /*===========================================================================
  4397. FUNCTION: encode_iso1_V2GTP_stream
  4398. DESCRIPTION:
  4399. PRE-CONDITION:
  4400. INPUT:
  4401. OUTPUT:
  4402. GLOBAL VARIABLES:
  4403. =============================================================================*/
  4404. int encode_iso1_V2GTP_stream(bitstream_t *v2g_tx_stream, struct iso1EXIDocument *ccs_exi_doc_ISO1)
  4405. {
  4406. int errn = 0;
  4407. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4408. errn = encode_iso1ExiDocument(v2g_tx_stream, ccs_exi_doc_ISO1);
  4409. if (errn == 0)
  4410. {
  4411. //successfully encoded
  4412. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4413. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4414. if (errn != 0)
  4415. {
  4416. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso1_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4417. }
  4418. }
  4419. else
  4420. {
  4421. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso1_V2GTP_stream]encode_iso1ExiDocument(): %d (DEC)\n", errn);
  4422. }
  4423. return errn;
  4424. }
  4425. /*===========================================================================
  4426. FUNCTION: encode_iso2_V2GTP_stream
  4427. DESCRIPTION:
  4428. PRE-CONDITION:
  4429. INPUT:
  4430. OUTPUT:
  4431. GLOBAL VARIABLES:
  4432. =============================================================================*/
  4433. int encode_iso2_V2GTP_stream(bitstream_t *v2g_tx_stream, struct iso2EXIDocument *ccs_exi_doc_ISO2)
  4434. {
  4435. int errn = 0;
  4436. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4437. errn = encode_iso2ExiDocument(v2g_tx_stream, ccs_exi_doc_ISO2);
  4438. if (errn == 0)
  4439. {
  4440. //successfully encoded
  4441. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4442. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4443. if (errn != 0)
  4444. {
  4445. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso2_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4446. }
  4447. }
  4448. else
  4449. {
  4450. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso2_V2GTP_stream]encode_iso2ExiDocument(): %d (DEC)\n", errn);
  4451. }
  4452. return errn;
  4453. }
  4454. /*===========================================================================
  4455. FUNCTION: send_encoded_din_V2GTP_Stream
  4456. DESCRIPTION:
  4457. PRE-CONDITION:
  4458. INPUT:
  4459. OUTPUT:
  4460. GLOBAL VARIABLES:
  4461. =============================================================================*/
  4462. int send_encoded_din_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct dinEXIDocument *ccs_exi_doc_DIN)
  4463. {
  4464. int errn = 0;
  4465. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4466. errn = encode_din_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_DIN);
  4467. // STEP 2: =========== Send Response Packet ===========
  4468. int rtn = 0;
  4469. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4470. if (rtn == v2g_tx_stream->size)
  4471. {
  4472. /*
  4473. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][send_encoded_din_V2GTP_Stream] Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4474. rtn, v2g_tx_stream->size);
  4475. */
  4476. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4477. }
  4478. else if (rtn >= 0)
  4479. {
  4480. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][send_encoded_din_V2GTP_Stream]Imcomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n", rtn, v2g_tx_stream->size);
  4481. }
  4482. else
  4483. {
  4484. errn = rtn;
  4485. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][send_encoded_din_V2GTP_Stream]send(): %d (DEC)\n", errn);
  4486. }
  4487. //STEP 3: ========= Reset V2G MSG Flags ==========
  4488. init_dinBodyType(&ccs_exi_doc_DIN->V2G_Message.Body);
  4489. return errn;
  4490. }
  4491. /*===========================================================================
  4492. FUNCTION: send_encoded_iso1_V2GTP_Stream
  4493. DESCRIPTION:
  4494. PRE-CONDITION:
  4495. INPUT:
  4496. OUTPUT:
  4497. GLOBAL VARIABLES:
  4498. =============================================================================*/
  4499. int send_encoded_iso1_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct iso1EXIDocument *ccs_exi_doc_ISO1)
  4500. {
  4501. int errn = 0;
  4502. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4503. errn = encode_iso1_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_ISO1);
  4504. // STEP 2: =========== Send Response Packet ===========
  4505. int rtn = 0;
  4506. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4507. if (rtn == v2g_tx_stream->size)
  4508. {
  4509. /*
  4510. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][send_encoded_iso1_V2GTP_Stream] Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4511. rtn, v2g_tx_stream->size);
  4512. */
  4513. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4514. }
  4515. else if (rtn >= 0)
  4516. {
  4517. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][send_encoded_iso1_V2GTP_Stream]Imcomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n", rtn, v2g_tx_stream->size);
  4518. }
  4519. else
  4520. {
  4521. errn = rtn;
  4522. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][send_encoded_iso1_V2GTP_Stream]send(): %d (DEC)\n", errn);
  4523. }
  4524. //STEP 3: ========= Reset V2G MSG Flags ==========
  4525. init_iso1BodyType(&ccs_exi_doc_ISO1->V2G_Message.Body);
  4526. return errn;
  4527. }
  4528. /*===========================================================================
  4529. FUNCTION: send_encoded_iso2_V2GTP_Stream
  4530. DESCRIPTION:
  4531. PRE-CONDITION:
  4532. INPUT:
  4533. OUTPUT:
  4534. GLOBAL VARIABLES:
  4535. =============================================================================*/
  4536. int send_encoded_iso2_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct iso2EXIDocument *ccs_exi_doc_ISO2)
  4537. {
  4538. int errn = 0;
  4539. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4540. errn = encode_iso2_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_ISO2);
  4541. // STEP 2: =========== Send Response Packet ===========
  4542. int rtn = 0;
  4543. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4544. if (rtn == v2g_tx_stream->size)
  4545. {
  4546. /*
  4547. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][send_encoded_iso2_V2GTP_Stream] Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4548. rtn, v2g_tx_stream->size);
  4549. */
  4550. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4551. }
  4552. else if (rtn >= 0)
  4553. {
  4554. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][send_encoded_iso2_V2GTP_Stream]Imcomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n",
  4555. rtn, v2g_tx_stream->size);
  4556. }
  4557. else
  4558. {
  4559. errn = rtn;
  4560. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][send_encoded_iso2_V2GTP_Stream]send(): %d (DEC)\n", errn);
  4561. }
  4562. //STEP 3: ========= Reset V2G MSG Flags ==========
  4563. init_iso2BodyType(&ccs_exi_doc_ISO2->V2G_Message.Body);
  4564. return errn;
  4565. }
  4566. /*===========================================================================
  4567. FUNCTION: Check_din_V2G_Rx_MSG_SessionID
  4568. DESCRIPTION:
  4569. PRE-CONDITION:
  4570. INPUT:
  4571. OUTPUT:
  4572. GLOBAL VARIABLES:
  4573. =============================================================================*/
  4574. int Check_din_V2G_Rx_MSG_SessionID(struct dinEXIDocument *exi_doc_DIN)
  4575. {
  4576. int i = 0;
  4577. int leng = 0;
  4578. int errn = 0;
  4579. leng = exi_doc_DIN->V2G_Message.Header.SessionID.bytesLen;
  4580. //Step 1: Check SessionID Length
  4581. if (leng != 8) //8-byte
  4582. {
  4583. sprintf((char*)buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4584. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4585. errn = -1;
  4586. }
  4587. else
  4588. {
  4589. //Step 2-1: Check SessionID content
  4590. for (i = 0; i < leng; i++)
  4591. {
  4592. if (exi_doc_DIN->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4593. {
  4594. errn = -2;
  4595. break;
  4596. }
  4597. }
  4598. }
  4599. //Step 2-2: Print Incorrect ID
  4600. if (errn == -2) //incorrect ID
  4601. {
  4602. sprintf((char*)buf_log_evcomm,
  4603. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4604. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[0],
  4605. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[1],
  4606. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[2],
  4607. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[3],
  4608. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[4],
  4609. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[5],
  4610. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[6],
  4611. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[7],
  4612. EVCOMM_SYS_INFO.SessionID[0],
  4613. EVCOMM_SYS_INFO.SessionID[1],
  4614. EVCOMM_SYS_INFO.SessionID[2],
  4615. EVCOMM_SYS_INFO.SessionID[3],
  4616. EVCOMM_SYS_INFO.SessionID[4],
  4617. EVCOMM_SYS_INFO.SessionID[5],
  4618. EVCOMM_SYS_INFO.SessionID[6],
  4619. EVCOMM_SYS_INFO.SessionID[7]
  4620. );
  4621. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4622. }
  4623. //Step 3: Correct SessionID for Res Message
  4624. if (errn != 0)
  4625. {
  4626. exi_doc_DIN->V2G_Message.Header.SessionID.bytesLen = 8;
  4627. memset(exi_doc_DIN->V2G_Message.Header.SessionID.bytes, 0, 8);
  4628. memcpy(exi_doc_DIN->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4629. }
  4630. return errn;
  4631. }
  4632. /*===========================================================================
  4633. FUNCTION: Check_iso1_V2G_Rx_MSG_SessionID
  4634. DESCRIPTION:
  4635. PRE-CONDITION:
  4636. INPUT:
  4637. OUTPUT:
  4638. GLOBAL VARIABLES:
  4639. =============================================================================*/
  4640. int Check_iso1_V2G_Rx_MSG_SessionID(struct iso1EXIDocument *exi_doc_ISO1)
  4641. {
  4642. int i = 0;
  4643. int leng = 0;
  4644. int errn = 0;
  4645. leng = exi_doc_ISO1->V2G_Message.Header.SessionID.bytesLen;
  4646. //Step 1: Check SessionID Length
  4647. if (leng != 8) //8-byte
  4648. {
  4649. sprintf((char*)buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4650. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4651. errn = -1;
  4652. }
  4653. else
  4654. {
  4655. //Step 2-1: Check SessionID content
  4656. for (i = 0; i < leng; i++)
  4657. {
  4658. if (exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4659. {
  4660. errn = -2;
  4661. break;
  4662. }
  4663. }
  4664. }
  4665. //Step 2-2: Print Incorrect ID
  4666. if (errn == -2) //incorrect ID
  4667. {
  4668. sprintf((char*)buf_log_evcomm,
  4669. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4670. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[0],
  4671. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[1],
  4672. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[2],
  4673. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[3],
  4674. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[4],
  4675. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[5],
  4676. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[6],
  4677. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[7],
  4678. EVCOMM_SYS_INFO.SessionID[0],
  4679. EVCOMM_SYS_INFO.SessionID[1],
  4680. EVCOMM_SYS_INFO.SessionID[2],
  4681. EVCOMM_SYS_INFO.SessionID[3],
  4682. EVCOMM_SYS_INFO.SessionID[4],
  4683. EVCOMM_SYS_INFO.SessionID[5],
  4684. EVCOMM_SYS_INFO.SessionID[6],
  4685. EVCOMM_SYS_INFO.SessionID[7]
  4686. );
  4687. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4688. }
  4689. //Step 3: Correct SessionID for Res Message
  4690. if (errn != 0)
  4691. {
  4692. exi_doc_ISO1->V2G_Message.Header.SessionID.bytesLen = 8;
  4693. memset(exi_doc_ISO1->V2G_Message.Header.SessionID.bytes, 0, 8);
  4694. memcpy(exi_doc_ISO1->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4695. }
  4696. return errn;
  4697. }
  4698. /*===========================================================================
  4699. FUNCTION: Check_iso2_V2G_Rx_MSG_SessionID
  4700. DESCRIPTION:
  4701. PRE-CONDITION:
  4702. INPUT:
  4703. OUTPUT:
  4704. GLOBAL VARIABLES:
  4705. =============================================================================*/
  4706. int Check_iso2_V2G_Rx_MSG_SessionID(struct iso2EXIDocument *exi_doc_ISO2)
  4707. {
  4708. int i = 0;
  4709. int leng = 0;
  4710. int errn = 0;
  4711. leng = exi_doc_ISO2->V2G_Message.Header.SessionID.bytesLen;
  4712. //Step 1: Check SessionID Length
  4713. if (leng != 8) //8-byte
  4714. {
  4715. sprintf((char*)buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4716. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4717. errn = -1;
  4718. }
  4719. else
  4720. {
  4721. //Step 2-1: Check SessionID content
  4722. for (i = 0; i < leng; i++)
  4723. {
  4724. if (exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4725. {
  4726. errn = -2;
  4727. break;
  4728. }
  4729. }
  4730. }
  4731. //Step 2-2: Print Incorrect ID
  4732. if (errn == -2) //incorrect ID
  4733. {
  4734. sprintf((char*)buf_log_evcomm,
  4735. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4736. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[0],
  4737. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[1],
  4738. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[2],
  4739. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[3],
  4740. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[4],
  4741. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[5],
  4742. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[6],
  4743. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[7],
  4744. EVCOMM_SYS_INFO.SessionID[0],
  4745. EVCOMM_SYS_INFO.SessionID[1],
  4746. EVCOMM_SYS_INFO.SessionID[2],
  4747. EVCOMM_SYS_INFO.SessionID[3],
  4748. EVCOMM_SYS_INFO.SessionID[4],
  4749. EVCOMM_SYS_INFO.SessionID[5],
  4750. EVCOMM_SYS_INFO.SessionID[6],
  4751. EVCOMM_SYS_INFO.SessionID[7]
  4752. );
  4753. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4754. }
  4755. //Step 3: Correct SessionID for Res Message
  4756. if (errn != 0)
  4757. {
  4758. exi_doc_ISO2->V2G_Message.Header.SessionID.bytesLen = 8;
  4759. memset(exi_doc_ISO2->V2G_Message.Header.SessionID.bytes, 0, 8);
  4760. memcpy(exi_doc_ISO2->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4761. }
  4762. return errn;
  4763. }
  4764. /*===========================================================================
  4765. FUNCTION: GetSchemaID_of_Protocol
  4766. DESCRIPTION:
  4767. 1. Get the SchemaID accroding to the input target
  4768. *V2GT_MSG_PROTOCOL_DIN70121: choose DIN 70121
  4769. *V2GT_MSG_PROTOCOL_ISO15118_2014: choose ISO 15118-2 (ed1)
  4770. *V2GT_MSG_PROTOCOL_ISO15118_2018: choose ISO 15118-20 (ed2)
  4771. *V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY: choose the one with the highest priority
  4772. 2. [To-do] Checking Major and Minor version
  4773. 3. The parsing method will not support those private protocols,
  4774. such as "usr:tesla...," since "tesla" is 5 bytes but "din" and "iso" are 3 bytes.
  4775. 4. [To-do] If the target is selected as DIN," but there is no DIN.
  4776. However, if EV and EVSE all support ISO, how to use ISO instead?
  4777. PRE-CONDITION:
  4778. INPUT:
  4779. 1. target: target protocol
  4780. OUTPUT:
  4781. 1. id: SchemaID of selected protocol by EVSE
  4782. 2. ShmCcsData->CommProtocol (selected protocol)
  4783. 3. SupportedAppProtocol_result
  4784. (1) appHandresponseCodeType_OK_SuccessfulNegotiation = 0,
  4785. (2) appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation = 1,
  4786. (3) appHandresponseCodeType_Failed_NoNegotiation = 2
  4787. GLOBAL VARIABLES:
  4788. 1. ccs_handshake
  4789. 2. ShmCcsData
  4790. =============================================================================*/
  4791. int GetSchemaID_of_Protocol(unsigned char target)
  4792. {
  4793. int i = 0;
  4794. int ii = 0;
  4795. int id = 0;
  4796. //unsigned char tmp = 0;
  4797. unsigned char pri = 20; //priority = 1(highest)~20(lowerest)
  4798. char num[10];
  4799. //struct CCS_ProtocolNamespacestructCharacters pro;
  4800. //Choose the 1st protocol as default.
  4801. //id = CCS_HANDSHAKE_PROTOCOLS.array[0].SchemaID;
  4802. id = -1;
  4803. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4804. for(i = 0; i < CCS_HANDSHAKE_PROTOCOLS.arrayLen; i++)
  4805. {
  4806. //Checking for <ProtocolNamespace>urn:din:70121:2012:MsgDef</ProtocolNamespace>
  4807. //[To-Do] Ignoring the priority from EV and force DIN 70121 as our only option. (for temp)
  4808. //[CAUTION] The parsing method will not support those private protocols, such as "usr:tesla..."
  4809. num[0] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[8];
  4810. num[1] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[9];
  4811. num[2] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[10];
  4812. num[3] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[11];
  4813. num[4] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[12];
  4814. num[5] = '\0';
  4815. if (atoi(num) == 70121)
  4816. {
  4817. sprintf((char*)buf_log_evcomm,
  4818. "[GetSchemaID_of_Protocol]supported(%d-th/%d): DIN 70121(%d:v%d.%d;id=%d,pri=%d)",
  4819. (i+1),
  4820. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4821. atoi(num),
  4822. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4823. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4824. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4825. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4826. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4827. if (target == V2GT_MSG_PROTOCOL_DIN70121)
  4828. {
  4829. sprintf((char*)buf_log_evcomm,
  4830. "[GetSchemaID_of_Protocol]selected(%d-th/%d): DIN 70121(%d:v%d.%d;id=%d,pri=%d)",
  4831. (i+1),
  4832. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4833. atoi(num),
  4834. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4835. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4836. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4837. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4838. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4839. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == DIN_SPEC_70121_2012_VersionNumberMajor)
  4840. {
  4841. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == DIN_SPEC_70121_2012_VersionNumberMinor)
  4842. {
  4843. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4844. }
  4845. else
  4846. { //[TC_SECC_VTB_SupportedAppProtocol_005]
  4847. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4848. }
  4849. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4850. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4851. return id;
  4852. }
  4853. else
  4854. {
  4855. //keep looking for the suitable protocol
  4856. }
  4857. }
  4858. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4859. {
  4860. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4861. {
  4862. ii = i;
  4863. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4864. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4865. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4866. }
  4867. else
  4868. {
  4869. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  4870. }
  4871. }
  4872. else
  4873. {
  4874. //null
  4875. }
  4876. }
  4877. else if (atoi(num) == 15118)
  4878. {
  4879. //urn:din:70121:2012:MsgDef
  4880. //urn:iso:15118:2:2013:MsgDef
  4881. memset(num, 0, sizeof(num));
  4882. num[0] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[16];
  4883. num[1] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[17];
  4884. num[2] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[18];
  4885. num[3] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[19];
  4886. num[4] = '\0';
  4887. if (atoi(num) < 2018 && atoi(num) >= 2010)
  4888. {
  4889. sprintf((char*)buf_log_evcomm,
  4890. "[GetSchemaID_of_Protocol]supported(%d-th/%d): ISO 15118-2(ed1,%d:v%d.%d;id=%d,pri=%d)",
  4891. (i+1),
  4892. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4893. atoi(num),
  4894. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4895. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4896. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4897. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4898. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4899. if (target == V2GT_MSG_PROTOCOL_ISO15118_2014)
  4900. {
  4901. sprintf((char*)buf_log_evcomm,
  4902. "[GetSchemaID_of_Protocol]selected(%d-th/%d): ISO 15118-2,ed1(%d:v%d.%d;id=%d,pri=%d)",
  4903. (i+1),
  4904. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4905. atoi(num),
  4906. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4907. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4908. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4909. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4910. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4911. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == ISO1_15118_2013_VersionNumberMajor)
  4912. {
  4913. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == ISO1_15118_2013_VersionNumberMinor)
  4914. {
  4915. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4916. }
  4917. else
  4918. {
  4919. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4920. }
  4921. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4922. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2014;
  4923. return id;
  4924. }
  4925. else
  4926. {
  4927. //keep looking for the suitable protocol
  4928. }
  4929. }
  4930. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4931. {
  4932. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4933. {
  4934. ii = i;
  4935. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4936. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4937. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2014;
  4938. }
  4939. else
  4940. {
  4941. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  4942. }
  4943. }
  4944. else
  4945. {
  4946. //null
  4947. }
  4948. }
  4949. else if (atoi(num) >= 2018 && atoi(num) <= 2100) // >= 2018
  4950. {
  4951. sprintf((char*)buf_log_evcomm,
  4952. "[GetSchemaID_of_Protocol]supported(%d-th/%d): ISO 15118-20(ed2,%d:v%d.%d;id=%d,pri=%d)",
  4953. (i+1),
  4954. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4955. atoi(num),
  4956. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4957. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4958. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4959. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4960. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4961. if (target == V2GT_MSG_PROTOCOL_ISO15118_2018)
  4962. {
  4963. sprintf((char*)buf_log_evcomm,
  4964. "[GetSchemaID_of_Protocol]selected(%d-th/%d): ISO 15118-20,ed2(%d:v%d.%d;id=%d,pri=%d)",
  4965. (i+1),
  4966. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4967. atoi(num),
  4968. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4969. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4970. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4971. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4972. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4973. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == ISO2_15118_2018_VersionNumberMajor)
  4974. {
  4975. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == ISO2_15118_2018_VersionNumberMinor)
  4976. {
  4977. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4978. }
  4979. else
  4980. {
  4981. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4982. }
  4983. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4984. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2018;
  4985. return id;
  4986. }
  4987. else
  4988. {
  4989. //keep looking for the suitable protocol
  4990. }
  4991. }
  4992. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4993. {
  4994. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4995. {
  4996. ii = i;
  4997. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4998. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4999. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2018;
  5000. }
  5001. else
  5002. {
  5003. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  5004. }
  5005. }
  5006. else
  5007. {
  5008. //null
  5009. }
  5010. }
  5011. else
  5012. {
  5013. //Unexpected Year
  5014. sprintf((char*)buf_log_evcomm,
  5015. "[GetSchemaID_of_Protocol]unsupported(%d-th/%d): ISO 15118-X(unexpected year:%d,v%d.%d),id=%d,pri=%d",
  5016. (i+1),
  5017. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5018. atoi(num),
  5019. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  5020. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  5021. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  5022. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  5023. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5024. //return -1;
  5025. }
  5026. }
  5027. else
  5028. {
  5029. sprintf((char*)buf_log_evcomm,
  5030. "[GetSchemaID_of_Protocol]unsupported protocol(%d-th/%d)(%d:v%d.%d;id=%d,pri=%d)",
  5031. (i+1),
  5032. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5033. atoi(num),
  5034. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  5035. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  5036. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  5037. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  5038. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5039. //return -1;
  5040. }
  5041. }
  5042. //The final result of highest priority protocol
  5043. sprintf((char*)buf_log_evcomm,
  5044. "[GetSchemaID_of_Protocol]selected(%d-th/%d): pro=%d(0:DIN,1:ISO1,2:ISO2);id=%d,pri=%d",
  5045. (ii+1),
  5046. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5047. ShmCcsData->CommProtocol,
  5048. id,
  5049. pri);
  5050. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5051. if (id < 0)
  5052. {
  5053. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_Failed_NoNegotiation;
  5054. }
  5055. return id;
  5056. }
  5057. /*===========================================================================
  5058. FUNCTION: Proc_supportedAppProtocolRes
  5059. DESCRIPTION:
  5060. PRE-CONDITION:
  5061. INPUT:
  5062. OUTPUT:
  5063. GLOBAL VARIABLES:
  5064. =============================================================================*/
  5065. int Proc_supportedAppProtocolRes(int AcceptFd)
  5066. {
  5067. int errn = 0;
  5068. bitstream_t v2g_tx_stream;
  5069. static struct ChargingInfoData *sys;
  5070. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5071. //STEP 1: =========== Setting the Response Message ===========
  5072. init_appHandEXIDocument(&ccs_handshake);
  5073. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_OK_SuccessfulNegotiation;
  5074. ccs_handshake.supportedAppProtocolRes_isUsed = 1u;
  5075. //select the 1st one as the default
  5076. ccs_handshake.supportedAppProtocolRes.SchemaID = CCS_HANDSHAKE_PROTOCOLS.array[0].SchemaID;
  5077. ccs_handshake.supportedAppProtocolRes.SchemaID_isUsed = 1u;
  5078. int id = 0;
  5079. id = GetSchemaID_of_Protocol(V2GT_MSG_PROTOCOL_PREFERENCE); //output: EVCOMM_SYS_INFO.SupportedAppProtocol_result
  5080. ccs_handshake.supportedAppProtocolRes.ResponseCode = EVCOMM_SYS_INFO.SupportedAppProtocol_result; //updating the response code
  5081. if (id < 0)
  5082. {
  5083. sprintf((char*)buf_log_evcomm,
  5084. "[Error]No avalible CCS protocol (id = %d, preference = %d)",
  5085. id,
  5086. V2GT_MSG_PROTOCOL_PREFERENCE);
  5087. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5088. }
  5089. else
  5090. {
  5091. //selected SchemaID
  5092. ccs_handshake.supportedAppProtocolRes.SchemaID = (unsigned char) id;
  5093. }
  5094. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  5095. {
  5096. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_supportedAppProtocolRes]EVSE_Shutdown => End_Process");
  5097. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5098. errn = -1;
  5099. }
  5100. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5101. {
  5102. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_supportedAppProtocolRes]EVSE_EmergencyShutdown => End_Process");
  5103. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5104. errn = -1;
  5105. }
  5106. else
  5107. {
  5108. //null
  5109. }
  5110. //Check for Permission Changing from TRUE to FALSE
  5111. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  5112. ShmInternalComm->ChargingPermission == FALSE)
  5113. {
  5114. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][supportedAppProtocolRes]Permission OFF");
  5115. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5116. //errn = -1;
  5117. }
  5118. #if (CP_PROTECTION_MECHANISM == ENABLE)
  5119. {
  5120. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  5121. {
  5122. //Detect for CP State should be 9V with 5% PWM or 100%PWM (State B1, B2)
  5123. if (sys->CpState != 2 && sys->CpState != 3) //State B1, B2
  5124. {
  5125. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5126. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5127. Update_V2G_Flow_Status(Other_Fault);
  5128. sprintf((char*)buf_log_evcomm,
  5129. "[Proc_supportedAppProtocolRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  5130. sys->CpState,
  5131. sys->CpVoltage);
  5132. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5133. }
  5134. }
  5135. #else
  5136. {
  5137. //Detect for CP State should be 9V (State B)
  5138. if (sys->CpState != 3) //B2
  5139. {
  5140. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5141. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5142. Update_V2G_Flow_Status(Other_Fault);
  5143. sprintf((char*)buf_log_evcomm,
  5144. "[Proc_supportedAppProtocolRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  5145. sys->CpState,
  5146. sys->CpVoltage);
  5147. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5148. }
  5149. }
  5150. #endif
  5151. }
  5152. #endif
  5153. //STEP 2: =========== Encode into EXI ===========
  5154. if ((errn = API_V2GMSG_EXI_Encoder_AppProtocol(&ccs_handshake, &v2g_tx_stream)) !=0)
  5155. {
  5156. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Error]API_V2GMSG_EXI_Encoder_AppProtocol\n");
  5157. return errn;
  5158. }
  5159. //STEP 3: =========== Send Response Packet ===========
  5160. int Rtn = 0;
  5161. Rtn = send(AcceptFd, v2g_tx_stream.data, v2g_tx_stream.size, 0);
  5162. //Rtn = send(6, v2g_tx_stream.data, v2g_tx_stream.size, 0);
  5163. DEBUG_PRINTF_EVCOMM_DETAIL("Send V2GTP Packet Size = %d, Rtn = %d (Bytes, DEC)\n", v2g_tx_stream.size, Rtn);
  5164. if (Rtn < 0)
  5165. {
  5166. return Rtn;
  5167. }
  5168. //STEP 4: =========== Save into Share Memory =========
  5169. //[Joseph, To-Do] Adding a mechanism to choose DIN 70121 as our 1st priority. (for multiple protocols)
  5170. //STEP 5: =========== Updating the Flow State Flag =========
  5171. if (id < 0)
  5172. {
  5173. errn = -1;
  5174. }
  5175. //STEP 6: =========== Reset Flags ============
  5176. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  5177. init_appHandEXIDocument(&ccs_handshake);
  5178. return errn;
  5179. }
  5180. /*===========================================================================
  5181. FUNCTION: Proc_supportedAppProtocolReq
  5182. DESCRIPTION:
  5183. PRE-CONDITION:
  5184. INPUT:
  5185. OUTPUT:
  5186. GLOBAL VARIABLES:
  5187. =============================================================================*/
  5188. int Proc_supportedAppProtocolReq(int AcceptFd)
  5189. {
  5190. //[Joseph, To-Do] analysis on Req message and choose the prefered protocol
  5191. //Default: DIN 70121 (find SchemaID)
  5192. int errn = 0;
  5193. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]supportedAppProtocolReq");
  5194. SHM_Save_din_supportedAppProtocolReq(ShmCcsData, &ccs_handshake, ShmSysConfigAndInfo);
  5195. errn = Proc_supportedAppProtocolRes(AcceptFd);
  5196. if (errn == 0)
  5197. {
  5198. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Tx]supportedAppProtocolRes");
  5199. }
  5200. else
  5201. {
  5202. DEBUG_PRINTF_EVCOMM_DETAIL("[Error]Proc_supportedAppProtocolRes(): %d (DEC)\n", errn);
  5203. }
  5204. return errn;
  5205. }
  5206. /*===========================================================================
  5207. FUNCTION: Proc_din_SessionSetupRes
  5208. DESCRIPTION:
  5209. PRE-CONDITION:
  5210. INPUT:
  5211. OUTPUT:
  5212. GLOBAL VARIABLES:
  5213. =============================================================================*/
  5214. int Proc_din_SessionSetupRes(int AcceptFd)
  5215. {
  5216. //int i = 0;
  5217. int errn = 0;
  5218. bitstream_t v2g_tx_stream;
  5219. static struct ChargingInfoData *sys;
  5220. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5221. size_t pos = 0;
  5222. v2g_tx_stream.pos = &pos;
  5223. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5224. v2g_tx_stream.data = V2GTP_Tx_buf;
  5225. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5226. init_dinSessionSetupResType(&ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes);
  5227. // ====== [BODY (1/2) ResponseCode ======
  5228. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5229. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_OK_NewSessionEstablished;
  5230. //[HEADER] Assign Res SessionID
  5231. ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytesLen = 8;
  5232. memset(ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytes, 0, 8);
  5233. memcpy(ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5234. //Check for SequenceError
  5235. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5236. {
  5237. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError;
  5238. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5239. errn = -1;
  5240. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5241. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5242. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5243. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5244. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5245. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5246. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5247. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5248. }
  5249. //#if PARAMETER_NORMAL_MODE == ENABLE
  5250. //SHM_Read_din_V2GMSG_Header(&ccs_exi_doc_DIN, ShmCcsData);
  5251. //#endif
  5252. //Detect for CP State should be 9V (State B)
  5253. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5254. {
  5255. #if CP_PROTECTION_MECHANISM == ENABLE
  5256. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5257. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5258. Update_V2G_Flow_Status(Other_Fault);
  5259. errn = -1;
  5260. sprintf((char*)buf_log_evcomm,
  5261. "[Proc_din_SessionSetupRes]Emergency Stop by CP Error (%d)\n",
  5262. sys->CpState);
  5263. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5264. #else
  5265. sprintf((char*)buf_log_evcomm,
  5266. "[Proc_din_SessionSetupRes]Emergency Stop by CP Error (%d): ignored\n",
  5267. sys->CpState);
  5268. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5269. #endif
  5270. }
  5271. //Check for shutdown commands from EVSE(DC Main Board)
  5272. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5273. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5274. {
  5275. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5276. sprintf((char*)buf_log_evcomm, "[Proc_din_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5277. EVSE_Shutdown,
  5278. EVSE_EmergencyShutdown,
  5279. sys->DC_EVSEStatus);
  5280. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5281. errn = -1;
  5282. }
  5283. //Check for Permission Changing from TRUE to FALSE
  5284. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  5285. ShmInternalComm->ChargingPermission == FALSE)
  5286. {
  5287. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][SessionSetupRes]Permission OFF");
  5288. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5289. errn = -1;
  5290. }
  5291. // ====== [BODY (2/3) EVSEID ======
  5292. //EVSEID = all zero
  5293. memset(ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytes, 0, sizeof(ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytes));
  5294. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytesLen = 15; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5295. // ====== [BODY (3/3) DateTimeNow ======
  5296. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.DateTimeNow_isUsed = 1u;
  5297. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.DateTimeNow = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5298. #if PARAMETER_NORMAL_MODE == ENABLE
  5299. ///////////SHM_Read_din_SessionSetupRes(&ccs_exi_doc_DIN, ShmCcsData);
  5300. #endif
  5301. // ============ Encode and Send Response Message ===========
  5302. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5303. {
  5304. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_SessionSetupRes][Error]Tx encoded msg error");
  5305. errn = -1;
  5306. }
  5307. return errn;
  5308. }
  5309. /*===========================================================================
  5310. FUNCTION: Proc_iso1_SessionSetupRes
  5311. DESCRIPTION:
  5312. PRE-CONDITION:
  5313. INPUT:
  5314. OUTPUT:
  5315. GLOBAL VARIABLES:
  5316. =============================================================================*/
  5317. int Proc_iso1_SessionSetupRes(int AcceptFd)
  5318. {
  5319. //int i = 0;
  5320. int errn = 0;
  5321. bitstream_t v2g_tx_stream;
  5322. static struct ChargingInfoData *sys;
  5323. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5324. size_t pos = 0;
  5325. v2g_tx_stream.pos = &pos;
  5326. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5327. v2g_tx_stream.data = V2GTP_Tx_buf;
  5328. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5329. init_iso1SessionSetupResType(&ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes);
  5330. // ====== [BODY (1/2) ResponseCode ======
  5331. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5332. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_OK_NewSessionEstablished;
  5333. //[HEADER] Assign Res SessionID
  5334. ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytesLen = 8;
  5335. memset(ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytes, 0, 8);
  5336. memcpy(ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5337. //Check for SequenceError
  5338. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5339. {
  5340. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5341. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5342. errn = -1;
  5343. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5344. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5345. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5346. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5347. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5348. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5349. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5350. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5351. }
  5352. //#if PARAMETER_NORMAL_MODE == ENABLE
  5353. //SHM_Read_iso1_V2GMSG_Header(&ccs_exi_doc_ISO1, ShmCcsData);
  5354. //#endif
  5355. //Detect for CP State should be 9V (State B)
  5356. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5357. {
  5358. #if CP_PROTECTION_MECHANISM == ENABLE
  5359. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5360. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5361. Update_V2G_Flow_Status(Other_Fault);
  5362. errn = -1;
  5363. sprintf((char*)buf_log_evcomm,
  5364. "[Proc_iso1_SessionSetupRes]Emergency Stop by CP Error (%d)\n",
  5365. sys->CpState);
  5366. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5367. #else
  5368. sprintf((char*)buf_log_evcomm,
  5369. "[Proc_iso1_SessionSetupRes]Emergency Stop by CP Error (%d): ignored\n",
  5370. sys->CpState);
  5371. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5372. #endif
  5373. }
  5374. //Check for shutdown commands from EVSE(DC Main Board)
  5375. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5376. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5377. {
  5378. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5379. sprintf((char*)buf_log_evcomm, "[Proc_iso1_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5380. EVSE_Shutdown,
  5381. EVSE_EmergencyShutdown,
  5382. sys->DC_EVSEStatus);
  5383. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5384. errn = -1;
  5385. }
  5386. //Check for Permission Changing from TRUE to FALSE
  5387. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  5388. ShmInternalComm->ChargingPermission == FALSE)
  5389. {
  5390. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][ISO1][SessionSetupRes]Permission OFF");
  5391. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5392. errn = -1;
  5393. }
  5394. // ====== [BODY (2/3) EVSEID ======
  5395. //EVSEID = all zero
  5396. memset(ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters, 0, sizeof(ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters));
  5397. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 15; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5398. // ====== [BODY (3/3) DateTimeNow ======
  5399. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  5400. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSETimeStamp = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5401. #if PARAMETER_NORMAL_MODE == ENABLE
  5402. ///////////SHM_Read_iso1_SessionSetupRes(&ccs_exi_doc_ISO1, ShmCcsData);
  5403. #endif
  5404. // ============ Encode and Send Response Message ===========
  5405. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  5406. {
  5407. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_SessionSetupRes][Error]Tx encoded msg error");
  5408. errn = -1;
  5409. }
  5410. return errn;
  5411. }
  5412. /*===========================================================================
  5413. FUNCTION: Proc_iso2_SessionSetupRes
  5414. DESCRIPTION:
  5415. PRE-CONDITION:
  5416. INPUT:
  5417. OUTPUT:
  5418. GLOBAL VARIABLES:
  5419. =============================================================================*/
  5420. int Proc_iso2_SessionSetupRes(int AcceptFd)
  5421. {
  5422. //int i = 0;
  5423. int errn = 0;
  5424. bitstream_t v2g_tx_stream;
  5425. static struct ChargingInfoData *sys;
  5426. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5427. size_t pos = 0;
  5428. v2g_tx_stream.pos = &pos;
  5429. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5430. v2g_tx_stream.data = V2GTP_Tx_buf;
  5431. init_iso2BodyType(&ccs_exi_doc_ISO2.V2G_Message.Body);
  5432. init_iso2SessionSetupResType(&ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes);
  5433. // ====== [BODY (1/2) ResponseCode ======
  5434. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5435. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_OK_NewSessionEstablished;
  5436. //[HEADER] Assign Res SessionID
  5437. ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytesLen = 8;
  5438. memset(ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytes, 0, 8);
  5439. memcpy(ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5440. //Check for SequenceError
  5441. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5442. {
  5443. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5444. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5445. errn = -1;
  5446. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5447. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5448. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5449. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5450. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5451. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5452. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5453. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5454. }
  5455. //#if PARAMETER_NORMAL_MODE == ENABLE
  5456. //SHM_Read_iso2_V2GMSG_Header(&ccs_exi_doc_ISO2, ShmCcsData);
  5457. //#endif
  5458. //Detect for CP State should be 9V (State B)
  5459. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5460. {
  5461. #if CP_PROTECTION_MECHANISM == ENABLE
  5462. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5463. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5464. Update_V2G_Flow_Status(Other_Fault);
  5465. errn = -1;
  5466. sprintf((char*)buf_log_evcomm,
  5467. "[Proc_iso2_SessionSetupRes]Emergency Stop by CP Error (%d)",
  5468. sys->CpState);
  5469. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5470. #else
  5471. sprintf((char*)buf_log_evcomm,
  5472. "[Proc_iso2_SessionSetupRes]Emergency Stop by CP Error (%d): ignored",
  5473. sys->CpState);
  5474. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5475. #endif
  5476. }
  5477. //Check for shutdown commands from EVSE(DC Main Board)
  5478. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5479. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5480. {
  5481. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5482. sprintf((char*)buf_log_evcomm, "[Proc_iso2_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5483. EVSE_Shutdown,
  5484. EVSE_EmergencyShutdown,
  5485. sys->DC_EVSEStatus);
  5486. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5487. errn = -1;
  5488. }
  5489. //Check for Permission Changing from TRUE to FALSE
  5490. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  5491. ShmInternalComm->ChargingPermission == FALSE)
  5492. {
  5493. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][ISO2][SessionSetupRes]Permission OFF");
  5494. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5495. errn = -1;
  5496. }
  5497. // ====== [BODY (2/3) EVSEID ======
  5498. //EVSEID = all zero
  5499. memset(ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.characters, 0, sizeof(ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.characters));
  5500. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 15; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5501. // ====== [BODY (3/3) DateTimeNow ======
  5502. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  5503. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSETimeStamp = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5504. #if PARAMETER_NORMAL_MODE == ENABLE
  5505. ///////////SHM_Read_iso2_SessionSetupRes(&ccs_exi_doc_ISO2, ShmCcsData);
  5506. #endif
  5507. // ============ Encode and Send Response Message ===========
  5508. if (send_encoded_iso2_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO2) != 0)
  5509. {
  5510. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso2_SessionSetupRes][Error]Tx encoded msg error");
  5511. errn = -1;
  5512. }
  5513. return errn;
  5514. }
  5515. /*===========================================================================
  5516. FUNCTION: Proc_din_SessionSetupReq
  5517. DESCRIPTION:
  5518. PRE-CONDITION:
  5519. INPUT:
  5520. OUTPUT:
  5521. GLOBAL VARIABLES:
  5522. 2. ccs_exi_doc_DIN
  5523. =============================================================================*/
  5524. int Proc_din_SessionSetupReq(int AcceptFd)
  5525. {
  5526. int errn = 0;
  5527. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Proc_din_SessionSetupReq]Got SessionSetupReq\n");
  5528. //Print the decoded XML Document
  5529. PRINT_XML_DOC_DIN_SessionSetupReq(&ccs_exi_doc_DIN);
  5530. //Save into Share Memory
  5531. SHM_Save_din_SessionSetupReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  5532. errn = Proc_din_SessionSetupRes(AcceptFd);
  5533. if (errn == 0)
  5534. {
  5535. //successfully send response.
  5536. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][Tx]SessionSetupRes");
  5537. }
  5538. else
  5539. {
  5540. sprintf((char*)buf_log_evcomm,
  5541. "[Error]Proc_din_SessionSetupRes(): %d (DEC)",
  5542. errn);
  5543. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5544. }
  5545. return errn;
  5546. }
  5547. /*===========================================================================
  5548. FUNCTION: Proc_iso1_SessionSetupReq
  5549. DESCRIPTION:
  5550. PRE-CONDITION:
  5551. INPUT:
  5552. OUTPUT:
  5553. GLOBAL VARIABLES:
  5554. 2. ccs_exi_doc_ISO1
  5555. =============================================================================*/
  5556. int Proc_iso1_SessionSetupReq(int AcceptFd)
  5557. {
  5558. int errn = 0;
  5559. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Proc_iso1_SessionSetupReq]Got SessionSetupReq\n");
  5560. //Print the decoded XML Document
  5561. PRINT_XML_DOC_ISO1_SessionSetupReq(&ccs_exi_doc_ISO1);
  5562. //Save into Share Memory
  5563. SHM_Save_iso1_SessionSetupReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  5564. errn = Proc_iso1_SessionSetupRes(AcceptFd);
  5565. if (errn == 0)
  5566. {
  5567. //successfully send response.
  5568. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]SessionSetupRes");
  5569. }
  5570. else
  5571. {
  5572. sprintf((char*)buf_log_evcomm,
  5573. "[Error]Proc_iso1_SessionSetupRes(): %d (DEC)",
  5574. errn);
  5575. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5576. }
  5577. return errn;
  5578. }
  5579. /*===========================================================================
  5580. FUNCTION: Proc_iso2_SessionSetupReq
  5581. DESCRIPTION:
  5582. PRE-CONDITION:
  5583. INPUT:
  5584. OUTPUT:
  5585. GLOBAL VARIABLES:
  5586. 2. ccs_exi_doc_ISO2
  5587. =============================================================================*/
  5588. int Proc_iso2_SessionSetupReq(int AcceptFd)
  5589. {
  5590. int errn = 0;
  5591. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Proc_iso2_SessionSetupReq]Got SessionSetupReq\n");
  5592. //Print the decoded XML Document
  5593. PRINT_XML_DOC_ISO2_SessionSetupReq(&ccs_exi_doc_ISO2);
  5594. //Save into Share Memory
  5595. SHM_Save_iso2_SessionSetupReq(ShmCcsData, &ccs_exi_doc_ISO2, ShmSysConfigAndInfo);
  5596. errn = Proc_iso2_SessionSetupRes(AcceptFd);
  5597. if (errn == 0)
  5598. {
  5599. //successfully send response.
  5600. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO2][V2G][Tx]SessionSetupRes");
  5601. }
  5602. else
  5603. {
  5604. sprintf((char*)buf_log_evcomm,
  5605. "[Error]Proc_iso2_SessionSetupRes(): %d (DEC)",
  5606. errn);
  5607. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5608. }
  5609. return errn;
  5610. }
  5611. /*===========================================================================
  5612. FUNCTION: Proc_din_ServiceDiscoveryRes
  5613. DESCRIPTION:
  5614. PRE-CONDITION:
  5615. INPUT:
  5616. OUTPUT:
  5617. GLOBAL VARIABLES:
  5618. =============================================================================*/
  5619. int Proc_din_ServiceDiscoveryRes(int AcceptFd)
  5620. {
  5621. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5622. //if it is not the same, the packet should be ignored.
  5623. //int i = 0;
  5624. int errn = 0;
  5625. bitstream_t v2g_tx_stream;
  5626. struct ChargingInfoData *sys;
  5627. //struct ServiceDiscoveryRequest_DIN70121 *req;
  5628. struct ServiceDiscoveryResponse_DIN70121 *res;
  5629. size_t pos = 0;
  5630. v2g_tx_stream.pos = &pos;
  5631. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5632. v2g_tx_stream.data = V2GTP_Tx_buf;
  5633. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5634. //req = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryRequest;
  5635. res = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryResponse;
  5636. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5637. init_dinServiceDiscoveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes);
  5638. //[1/4] Response Code
  5639. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
  5640. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_OK;
  5641. //[HEADER] Check Req SessionID
  5642. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  5643. {
  5644. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  5645. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  5646. errn = -1;
  5647. }
  5648. //Check for SequenceError
  5649. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5650. {
  5651. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  5652. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5653. errn = -1;
  5654. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5655. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5656. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5657. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5658. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5659. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5660. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5661. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5662. }
  5663. //Detect for CP State should be 9V (State B)
  5664. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5665. {
  5666. #if CP_PROTECTION_MECHANISM == ENABLE
  5667. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5668. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5669. Update_V2G_Flow_Status(Other_Fault);
  5670. errn = -1;
  5671. sprintf((char*)buf_log_evcomm, "[Proc_din_ServiceDiscoveryRes]Emergency Stop by CP Error (%d)", sys->CpState);
  5672. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5673. #else
  5674. sprintf((char*)buf_log_evcomm,
  5675. "[Proc_din_ServiceDiscoveryRes]Emergency Stop by CP Error (%d): ignored",
  5676. sys->CpState);
  5677. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5678. #endif
  5679. }
  5680. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5681. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5682. {
  5683. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5684. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_ServiceDiscoveryRes]shutdown by EVSE");
  5685. errn = -1;
  5686. }
  5687. //Check for Permission Changing from TRUE to FALSE
  5688. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  5689. ShmInternalComm->ChargingPermission == FALSE)
  5690. {
  5691. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][ServiceDiscoveryRes]Permission OFF");
  5692. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5693. errn = -1;
  5694. }
  5695. //[2/4] PaymentOptions
  5696. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.arrayLen = 1u;
  5697. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.array[0] = dinpaymentOptionType_ExternalPayment; //1
  5698. //[3/4] Charge Service
  5699. res->ChargeService_DIN70121.Services.ServiceTag.ServiceID = 1;
  5700. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceID = (unsigned short) res->ChargeService_DIN70121.Services.ServiceTag.ServiceID;
  5701. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceCategory = dinserviceCategoryType_EVCharging;
  5702. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.FreeService = 1; //[Joseph] for test
  5703. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.EnergyTransferType = dinEVSESupportedEnergyTransferType_DC_extended;
  5704. //[4/4] Service List (null, not be uesed for now.)
  5705. //#if PARAMETER_NORMAL_MODE == ENABLE
  5706. ///////////////SHM_Read_din_ServiceDiscoveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  5707. //#endif
  5708. // ============ Encode and Send Response Message ===========
  5709. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5710. {
  5711. errn = -1;
  5712. }
  5713. return errn;
  5714. }
  5715. /*===========================================================================
  5716. FUNCTION: Proc_iso1_ServiceDiscoveryRes
  5717. DESCRIPTION:
  5718. PRE-CONDITION:
  5719. INPUT:
  5720. OUTPUT:
  5721. GLOBAL VARIABLES:
  5722. =============================================================================*/
  5723. int Proc_iso1_ServiceDiscoveryRes(int AcceptFd)
  5724. {
  5725. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5726. //if it is not the same, the packet should be ignored.
  5727. //int i = 0;
  5728. int errn = 0;
  5729. bitstream_t v2g_tx_stream;
  5730. struct ChargingInfoData *sys;
  5731. //struct ServiceDiscoveryRequest_ISO15118_2014 *req;
  5732. struct ServiceDiscoveryResponse_ISO15118_2014 *res;
  5733. size_t pos = 0;
  5734. v2g_tx_stream.pos = &pos;
  5735. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5736. v2g_tx_stream.data = V2GTP_Tx_buf;
  5737. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5738. //req = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryRequest;
  5739. res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryResponse;
  5740. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5741. init_iso1ServiceDiscoveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes);
  5742. //[1/4] Response Code
  5743. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
  5744. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_OK;
  5745. //[HEADER] Check Req SessionID
  5746. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  5747. {
  5748. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  5749. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  5750. errn = -1;
  5751. }
  5752. //Check for SequenceError
  5753. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5754. {
  5755. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5756. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5757. errn = -1;
  5758. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5759. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5760. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5761. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5762. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5763. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5764. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5765. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5766. }
  5767. //Detect for CP State should be 9V (State B)
  5768. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5769. {
  5770. #if CP_PROTECTION_MECHANISM == ENABLE
  5771. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5772. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5773. Update_V2G_Flow_Status(Other_Fault);
  5774. errn = -1;
  5775. sprintf((char*)buf_log_evcomm,
  5776. "[Proc_iso1_ServiceDiscoveryRes]Emergency Stop by CP Error (%d)",
  5777. sys->CpState);
  5778. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5779. #else
  5780. sprintf((char*)buf_log_evcomm,
  5781. "[Proc_iso1_ServiceDiscoveryRes]Emergency Stop by CP Error (%d): ignored",
  5782. sys->CpState);
  5783. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5784. #endif
  5785. }
  5786. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5787. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5788. {
  5789. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5790. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ServiceDiscoveryRes]shutdown by EVSE");
  5791. errn = -1;
  5792. }
  5793. //Check for Permission Changing from TRUE to FALSE
  5794. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  5795. ShmInternalComm->ChargingPermission == FALSE)
  5796. {
  5797. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][ISO1][ServiceDiscoveryRes]Permission OFF");
  5798. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5799. errn = -1;
  5800. }
  5801. //[2/4] PaymentOptionList
  5802. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.arrayLen = 1u;
  5803. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.array[0] = iso1paymentOptionType_ExternalPayment; //1
  5804. //[3/4] Charge Service
  5805. res->ChargeService.Services.ServiceID = 1;
  5806. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceID = (unsigned short) res->ChargeService.Services.ServiceID;
  5807. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName_isUsed = 1; //new in ISO1, not be used, yet.
  5808. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName.charactersLen = xxx;
  5809. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName.characters[i] = xxx;
  5810. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceCategory = iso1serviceCategoryType_EVCharging;
  5811. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.FreeService = 1; //[Joseph] for test
  5812. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.arrayLen = 1u; //[ISO1] max = 6
  5813. switch (ShmCcsData->EnergyTransferMode)
  5814. {
  5815. case DC_extended:
  5816. {
  5817. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_DC_extended;
  5818. break;
  5819. }
  5820. case AC_single_phase_core:
  5821. {
  5822. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_AC_single_phase_core;
  5823. break;
  5824. }
  5825. case AC_three_phase_core:
  5826. {
  5827. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_AC_three_phase_core;
  5828. break;
  5829. }
  5830. default:
  5831. {
  5832. sprintf((char*)buf_log_evcomm,
  5833. "[ISO1][ServiceDiscoveryRes][Warning]unexpected EnergyTransferMode(%d)",
  5834. ShmCcsData->EnergyTransferMode);
  5835. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5836. break;
  5837. }
  5838. }
  5839. //[4/4] Service List (null, not be uesed for now.)
  5840. //#if PARAMETER_NORMAL_MODE == ENABLE
  5841. ///////////////SHM_Read_iso1_ServiceDiscoveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  5842. //#endif
  5843. // ============ Encode and Send Response Message ===========
  5844. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  5845. {
  5846. errn = -1;
  5847. }
  5848. return errn;
  5849. }
  5850. /*===========================================================================
  5851. FUNCTION: Proc_din_ServiceDiscoveryReq
  5852. DESCRIPTION:
  5853. PRE-CONDITION:
  5854. INPUT:
  5855. OUTPUT:
  5856. GLOBAL VARIABLES:
  5857. =============================================================================*/
  5858. int Proc_din_ServiceDiscoveryReq(int AcceptFd)
  5859. {
  5860. int errn = 0;
  5861. DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_din_ServiceDiscoveryReq]Got ServiceDiscoveryReq\n");
  5862. //Print the decoded XML Document
  5863. PRINT_XML_DOC_DIN_ServiceDiscoveryReq(&ccs_exi_doc_DIN);
  5864. //Save into Share Memory
  5865. SHM_Save_din_ServiceDiscoveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  5866. errn = Proc_din_ServiceDiscoveryRes(AcceptFd);
  5867. if (errn == 0)
  5868. {
  5869. //send response successfully.
  5870. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][Tx]ServiceDiscoveryRes");
  5871. }
  5872. else
  5873. {
  5874. sprintf((char*)buf_log_evcomm,
  5875. "[Error][SeccComm][Proc_din_ServiceDiscoveryReq]Proc_din_ServiceDiscoveryRes(): %d (DEC)",
  5876. errn
  5877. );
  5878. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5879. }
  5880. return errn;
  5881. }
  5882. /*===========================================================================
  5883. FUNCTION: Proc_iso1_ServiceDiscoveryReq
  5884. DESCRIPTION:
  5885. PRE-CONDITION:
  5886. INPUT:
  5887. OUTPUT:
  5888. GLOBAL VARIABLES:
  5889. =============================================================================*/
  5890. int Proc_iso1_ServiceDiscoveryReq(int AcceptFd)
  5891. {
  5892. int errn = 0;
  5893. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][Proc_iso1_ServiceDiscoveryReq]Got ServiceDiscoveryReq\n");
  5894. //Print the decoded XML Document
  5895. PRINT_XML_DOC_ISO1_ServiceDiscoveryReq(&ccs_exi_doc_ISO1);
  5896. //Save into Share Memory
  5897. SHM_Save_iso1_ServiceDiscoveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  5898. errn = Proc_iso1_ServiceDiscoveryRes(AcceptFd);
  5899. if (errn == 0)
  5900. {
  5901. //send response successfully.
  5902. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]ServiceDiscoveryRes");
  5903. }
  5904. else
  5905. {
  5906. sprintf((char*)buf_log_evcomm,
  5907. "[Error][SeccComm][Proc_iso1_ServiceDiscoveryReq]Proc_iso1_ServiceDiscoveryRes(): %d (DEC)",
  5908. errn
  5909. );
  5910. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5911. }
  5912. return errn;
  5913. }
  5914. /*===========================================================================
  5915. FUNCTION: Proc_din_ServiceAndPaymentSelectionRes
  5916. DESCRIPTION:
  5917. PRE-CONDITION:
  5918. INPUT:
  5919. OUTPUT:
  5920. GLOBAL VARIABLES:
  5921. =============================================================================*/
  5922. int Proc_din_ServiceAndPaymentSelectionRes(int AcceptFd)
  5923. {
  5924. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5925. //if it is not the same, the packet should be ignored.
  5926. //int i = 0;
  5927. int errn = 0;
  5928. bitstream_t v2g_tx_stream;
  5929. struct ServiceAndPaymentSelectionRequest_DIN70121 *req;
  5930. //struct ServiceAndPaymentSelectionResponse_DIN70121 *res;
  5931. struct ServiceDiscoveryResponse_DIN70121 *sd_res;
  5932. struct ChargingInfoData *sys;
  5933. size_t pos = 0;
  5934. v2g_tx_stream.pos = &pos;
  5935. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5936. v2g_tx_stream.data = V2GTP_Tx_buf;
  5937. req = &ShmCcsData->V2GMessage_DIN70121.ServiceAndPaymentSelectionRequest;
  5938. //res = &ShmCcsData->V2GMessage_DIN70121.ServiceAndPaymentSelectionResponse;
  5939. sd_res = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryResponse;
  5940. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5941. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5942. init_dinServicePaymentSelectionResType(&ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes);
  5943. //[1/1] Response Code
  5944. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes_isUsed = 1u;
  5945. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_OK;
  5946. //[HEADER] Check Req SessionID
  5947. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  5948. {
  5949. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  5950. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  5951. errn = -1;
  5952. }
  5953. //Check for SequenceError
  5954. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5955. {
  5956. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  5957. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5958. errn = -1;
  5959. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5960. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5961. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5962. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5963. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5964. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5965. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5966. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5967. }
  5968. //Check for SelectedPaymentOption (TC_SECC_VTB_ServicePaymentSelection_007)
  5969. if (req->SelectedPaymentOption != ExternalPayment) //1
  5970. {
  5971. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_PaymentSelectionInvalid;
  5972. sprintf((char*)buf_log_evcomm,
  5973. "[ERROR]unexpected SelectedPaymentOption(%d) => End_Process (EIM only, no PnC, yet.)",
  5974. req->SelectedPaymentOption);
  5975. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5976. errn = -1;
  5977. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5978. //CCS_SECC_ResponseCode_FAILED_Payment SelectionInvalid (023762)
  5979. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5980. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5981. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5982. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5983. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  5984. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  5985. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5986. }
  5987. //Check for ServiceID (TC_SECC_VTB_ServicePaymentSelection_004)
  5988. if (req->SelectedServiceList.SelectedService[0].ServiceID != sd_res->ChargeService_DIN70121.Services.ServiceTag.ServiceID)
  5989. {
  5990. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_ServiceSelectionInvalid; //8
  5991. sprintf((char*)buf_log_evcomm,
  5992. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  5993. req->SelectedServiceList.SelectedService[0].ServiceID);
  5994. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5995. errn = -1;
  5996. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5997. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  5998. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5999. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6000. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6001. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6002. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6003. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  6004. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6005. }
  6006. //Detect for CP State should be 9V (State B)
  6007. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6008. {
  6009. #if CP_PROTECTION_MECHANISM == ENABLE
  6010. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  6011. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6012. Update_V2G_Flow_Status(Other_Fault);
  6013. errn = -1;
  6014. sprintf((char*)buf_log_evcomm,
  6015. "[Proc_din_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d)",
  6016. sys->CpState);
  6017. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6018. #else
  6019. sprintf((char*)buf_log_evcomm,
  6020. "[Proc_din_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d): ignored due to function is disabled",
  6021. sys->CpState);
  6022. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6023. #endif
  6024. }
  6025. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  6026. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6027. {
  6028. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_ServiceAndPaymentSelectionRes]shutdown by EVSE");
  6029. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  6030. errn = -1;
  6031. }
  6032. //Check for Permission Changing from TRUE to FALSE
  6033. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  6034. ShmInternalComm->ChargingPermission == FALSE)
  6035. {
  6036. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][ServicePaymentSelectionRes]Permission OFF");
  6037. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  6038. errn = -1;
  6039. }
  6040. // ============ Encode and Send Response Message ===========
  6041. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  6042. {
  6043. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_ServiceAndPaymentSelectionRes]Tx encoded msg error");
  6044. errn = -1;
  6045. }
  6046. return errn;
  6047. }
  6048. /*===========================================================================
  6049. FUNCTION: Proc_iso1_ServiceAndPaymentSelectionRes
  6050. DESCRIPTION:
  6051. PRE-CONDITION:
  6052. INPUT:
  6053. OUTPUT:
  6054. GLOBAL VARIABLES:
  6055. =============================================================================*/
  6056. int Proc_iso1_ServiceAndPaymentSelectionRes(int AcceptFd)
  6057. {
  6058. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6059. //if it is not the same, the packet should be ignored.
  6060. //int i = 0;
  6061. int errn = 0;
  6062. bitstream_t v2g_tx_stream;
  6063. struct ServiceAndPaymentSelectionRequest_ISO15118_2014 *req;
  6064. //struct ServiceAndPaymentSelectionResponse_ISO15118_2014 *res;
  6065. struct ServiceDiscoveryResponse_ISO15118_2014 *sd_res;
  6066. static struct ChargingInfoData *sys;
  6067. size_t pos = 0;
  6068. v2g_tx_stream.pos = &pos;
  6069. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6070. v2g_tx_stream.data = V2GTP_Tx_buf;
  6071. req = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceAndPaymentSelectionRequest;
  6072. //res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceAndPaymentSelectionResponse;
  6073. sd_res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryResponse;
  6074. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6075. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6076. init_iso1PaymentServiceSelectionResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes);
  6077. //[1/1] Response Code
  6078. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes_isUsed = 1u;
  6079. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_OK;
  6080. //[HEADER] Check Req SessionID
  6081. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  6082. {
  6083. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  6084. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  6085. errn = -1;
  6086. }
  6087. //Check for SequenceError
  6088. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6089. {
  6090. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  6091. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  6092. errn = -1;
  6093. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6094. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6095. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6096. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6097. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6098. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6099. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6100. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6101. }
  6102. //Check for SelectedPaymentOption (TC_SECC_VTB_ServicePaymentSelection_007)
  6103. if (req->SelectedPaymentOption != ExternalPayment) //1
  6104. {
  6105. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_PaymentSelectionInvalid;
  6106. sprintf((char*)buf_log_evcomm,
  6107. "[ERROR]unexpected SelectedPaymentOption(%d) => End_Process (EIM only, no PnC, yet.)",
  6108. req->SelectedPaymentOption);
  6109. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6110. errn = -1;
  6111. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6112. //CCS_SECC_ResponseCode_FAILED_Payment SelectionInvalid (023762)
  6113. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6114. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6115. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6116. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6117. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6118. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  6119. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6120. }
  6121. //Check for ServiceID (TC_SECC_VTB_ServicePaymentSelection_004)
  6122. if (req->SelectedServiceList.SelectedService[0].ServiceID != sd_res->ChargeService.Services.ServiceID)
  6123. {
  6124. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_ServiceSelectionInvalid; //8
  6125. sprintf((char*)buf_log_evcomm,
  6126. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  6127. req->SelectedServiceList.SelectedService[0].ServiceID);
  6128. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6129. errn = -1;
  6130. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6131. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  6132. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6133. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6134. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6135. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6136. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6137. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  6138. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6139. }
  6140. //Detect for CP State should be 9V (State B)
  6141. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6142. {
  6143. #if CP_PROTECTION_MECHANISM == ENABLE
  6144. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  6145. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6146. Update_V2G_Flow_Status(Other_Fault);
  6147. errn = -1;
  6148. sprintf((char*)buf_log_evcomm,
  6149. "[Proc_iso1_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d)",
  6150. sys->CpState);
  6151. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6152. #else
  6153. sprintf((char*)buf_log_evcomm,
  6154. "[Proc_iso1_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d): ignored due to function is disabled",
  6155. sys->CpState);
  6156. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6157. #endif
  6158. }
  6159. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  6160. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6161. {
  6162. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ServiceAndPaymentSelectionRes]shutdown by EVSE");
  6163. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  6164. errn = -1;
  6165. }
  6166. //Check for Permission Changing from TRUE to FALSE
  6167. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  6168. ShmInternalComm->ChargingPermission == FALSE)
  6169. {
  6170. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][ISO1][PaymentServiceSelectionRes]Permission OFF");
  6171. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  6172. errn = -1;
  6173. }
  6174. // ============ Encode and Send Response Message ===========
  6175. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  6176. {
  6177. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ServiceAndPaymentSelectionRes]Tx encoded msg error");
  6178. errn = -1;
  6179. }
  6180. return errn;
  6181. }
  6182. /*===========================================================================
  6183. FUNCTION: Proc_din_ServiceAndPaymentSelectionReq
  6184. DESCRIPTION:
  6185. PRE-CONDITION:
  6186. INPUT:
  6187. OUTPUT:
  6188. GLOBAL VARIABLES:
  6189. =============================================================================*/
  6190. int Proc_din_ServiceAndPaymentSelectionReq(int AcceptFd)
  6191. {
  6192. int errn = 0;
  6193. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][Proc_din_ServiceAndPaymentSelectionReq]Got ServiceAndPaymentSelectionReq");
  6194. //Print the decoded XML Document
  6195. PRINT_XML_DOC_DIN_ServiceAndPaymentSelectionReq(&ccs_exi_doc_DIN);
  6196. //Save into Share Memory
  6197. SHM_Save_din_ServiceAndPaymentSelectionReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  6198. errn = Proc_din_ServiceAndPaymentSelectionRes(AcceptFd);
  6199. if (errn == 0)
  6200. {
  6201. //send response successfully.
  6202. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][Tx]ServiceAndPaymentSelectionRes");
  6203. }
  6204. else
  6205. {
  6206. sprintf((char*)buf_log_evcomm,
  6207. "[Error][Proc_iso1_ServiceAndPaymentSelectionReq]Proc_iso1_ServiceAndPaymentSelectionRes(): %d (DEC)",
  6208. errn);
  6209. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6210. }
  6211. return errn;
  6212. }
  6213. /*===========================================================================
  6214. FUNCTION: Proc_iso1_ServiceAndPaymentSelectionReq
  6215. DESCRIPTION:
  6216. PRE-CONDITION:
  6217. INPUT:
  6218. OUTPUT:
  6219. GLOBAL VARIABLES:
  6220. =============================================================================*/
  6221. int Proc_iso1_ServiceAndPaymentSelectionReq(int AcceptFd)
  6222. {
  6223. int errn = 0;
  6224. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][Proc_iso1_ServiceAndPaymentSelectionReq]Got ServiceAndPaymentSelectionReq");
  6225. //Print the decoded XML Document
  6226. PRINT_XML_DOC_ISO1_ServiceAndPaymentSelectionReq(&ccs_exi_doc_ISO1);
  6227. //Save into Share Memory
  6228. SHM_Save_iso1_ServiceAndPaymentSelectionReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  6229. errn = Proc_iso1_ServiceAndPaymentSelectionRes(AcceptFd);
  6230. if (errn == 0)
  6231. {
  6232. //send response successfully.
  6233. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]ServiceAndPaymentSelectionRes");
  6234. }
  6235. else
  6236. {
  6237. sprintf((char*)buf_log_evcomm,
  6238. "[Error][Proc_iso1_ServiceAndPaymentSelectionReq]Proc_iso1_ServiceAndPaymentSelectionRes(): %d (DEC)",
  6239. errn);
  6240. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6241. }
  6242. return errn;
  6243. }
  6244. /*===========================================================================
  6245. FUNCTION: Proc_din_ContractAuthenticationRes
  6246. DESCRIPTION:
  6247. PRE-CONDITION:
  6248. INPUT:
  6249. OUTPUT:
  6250. GLOBAL VARIABLES:
  6251. =============================================================================*/
  6252. int Proc_din_ContractAuthenticationRes(int AcceptFd)
  6253. {
  6254. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6255. //if it is not the same, the packet should be ignored.
  6256. //int i = 0;
  6257. int errn = 0;
  6258. bitstream_t v2g_tx_stream;
  6259. static struct ChargingInfoData *sys;
  6260. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6261. size_t pos = 0;
  6262. v2g_tx_stream.pos = &pos;
  6263. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6264. v2g_tx_stream.data = V2GTP_Tx_buf;
  6265. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  6266. init_dinContractAuthenticationResType(&ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes);
  6267. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes_isUsed = 1u;
  6268. //[BODY (1/2)] ResponseCode
  6269. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_OK;
  6270. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Ongoing; //0
  6271. //[HEADER] Check Req SessionID
  6272. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  6273. {
  6274. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  6275. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  6276. errn = -1;
  6277. }
  6278. //Check for SequenceError
  6279. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6280. {
  6281. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  6282. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  6283. errn = -1;
  6284. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6285. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6286. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6287. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6288. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6289. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6290. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6291. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6292. }
  6293. //Detect for CP State should be 9V (State B)
  6294. #if CP_PROTECTION_MECHANISM == ENABLE
  6295. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6296. {
  6297. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6298. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6299. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6300. Update_V2G_Flow_Status(Other_Fault);
  6301. errn = -1;
  6302. sprintf((char*)buf_log_evcomm,
  6303. "[Proc_din_ContractAuthenticationRes]Emergency Stop by CP Error (%d)",
  6304. sys->CpState);
  6305. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6306. }
  6307. #endif
  6308. //Check for CSU command of "Stop by EVSE"
  6309. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6310. {
  6311. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6312. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6313. errn = -1;
  6314. }
  6315. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6316. {
  6317. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6318. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6319. errn = -1;
  6320. }
  6321. //[BODY (2/2)] EVSEProcessing
  6322. if(ShmInternalComm->ChargingPermission == TRUE)
  6323. {
  6324. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished; //0
  6325. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "CSU Permission: OK");
  6326. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  6327. {
  6328. //Set PWM as 5% (for SLAC first case)
  6329. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Set PWM as 5%%");
  6330. SwitchCpStateE(DISABLE);
  6331. OutputCpPwmDuty(5);
  6332. }
  6333. #endif
  6334. }
  6335. //Check for Permission Changing from TRUE to FALSE
  6336. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  6337. ShmInternalComm->ChargingPermission == FALSE)
  6338. {
  6339. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][ContractAuthenticationRes]Permission OFF");
  6340. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6341. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6342. errn = -1;
  6343. }
  6344. #if PARAMETER_NORMAL_MODE == ENABLE
  6345. ////////////SHM_Read_din_ContractAuthenticationRes(&ccs_exi_doc_DIN, ShmCcsData);
  6346. #endif
  6347. // ============ Encode and Send Response Message ===========
  6348. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  6349. {
  6350. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  6351. errn = -1;
  6352. }
  6353. return errn;
  6354. }
  6355. /*===========================================================================
  6356. FUNCTION: Proc_iso1_AuthorizationRes
  6357. DESCRIPTION:
  6358. PRE-CONDITION:
  6359. INPUT:
  6360. OUTPUT:
  6361. GLOBAL VARIABLES:
  6362. =============================================================================*/
  6363. int Proc_iso1_AuthorizationRes(int AcceptFd)
  6364. {
  6365. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6366. //if it is not the same, the packet should be ignored.
  6367. //int i = 0;
  6368. int errn = 0;
  6369. bitstream_t v2g_tx_stream;
  6370. static struct ChargingInfoData *sys;
  6371. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6372. size_t pos = 0;
  6373. v2g_tx_stream.pos = &pos;
  6374. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6375. v2g_tx_stream.data = V2GTP_Tx_buf;
  6376. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6377. init_iso1AuthorizationResType(&ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes);
  6378. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes_isUsed = 1u;
  6379. //[BODY (1/2)] ResponseCode
  6380. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_OK;
  6381. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Ongoing; //0
  6382. //[HEADER] Check Req SessionID
  6383. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  6384. {
  6385. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  6386. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  6387. errn = -1;
  6388. }
  6389. //Check for SequenceError
  6390. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6391. {
  6392. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  6393. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  6394. errn = -1;
  6395. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6396. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6397. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6398. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6399. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6400. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6401. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6402. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6403. }
  6404. //Detect for CP State should be 9V (State B)
  6405. #if CP_PROTECTION_MECHANISM == ENABLE
  6406. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6407. {
  6408. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED;
  6409. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6410. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6411. Update_V2G_Flow_Status(Other_Fault);
  6412. errn = -1;
  6413. sprintf((char*)buf_log_evcomm,
  6414. "[Proc_iso1_AuthorizationRes]Emergency Stop by CP Error (%d)",
  6415. sys->CpState);
  6416. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6417. }
  6418. #endif
  6419. //Check for CSU command of "Stop by EVSE"
  6420. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6421. {
  6422. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6423. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6424. errn = -1;
  6425. }
  6426. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6427. {
  6428. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6429. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6430. errn = -1;
  6431. }
  6432. //[BODY (2/2)] EVSEProcessing
  6433. //Check for Permission from CSU
  6434. if(ShmInternalComm->ChargingPermission == TRUE)
  6435. {
  6436. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  6437. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "CSU Permission: OK");
  6438. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  6439. {
  6440. //Set PWM as 5% (for SLAC first case)
  6441. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Set PWM as 5%");
  6442. SwitchCpStateE(DISABLE);
  6443. OutputCpPwmDuty(5);
  6444. }
  6445. #endif
  6446. }
  6447. //Check for Permission Changing from TRUE to FALSE
  6448. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  6449. ShmInternalComm->ChargingPermission == FALSE)
  6450. {
  6451. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][ISO1][AuthorizationRes]Permission OFF");
  6452. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6453. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6454. errn = -1;
  6455. }
  6456. #if PARAMETER_NORMAL_MODE == ENABLE
  6457. ////////////SHM_Read_iso1_AuthorizationRes(&ccs_exi_doc_ISO1, ShmCcsData);
  6458. #endif
  6459. // ============ Encode and Send Response Message ===========
  6460. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  6461. {
  6462. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  6463. errn = -1;
  6464. }
  6465. return errn;
  6466. }
  6467. /*===========================================================================
  6468. FUNCTION: Proc_din_ContractAuthenticationReq
  6469. DESCRIPTION:
  6470. PRE-CONDITION:
  6471. INPUT:
  6472. OUTPUT:
  6473. GLOBAL VARIABLES:
  6474. =============================================================================*/
  6475. int Proc_din_ContractAuthenticationReq(int AcceptFd)
  6476. {
  6477. int errn = 0;
  6478. DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_din_ContractAuthenticationReq]Got Proc_din_ContractAuthenticationReq\n");
  6479. //Print the decoded XML Document
  6480. PRINT_XML_DOC_DIN_ContractAuthenticationReq(&ccs_exi_doc_DIN);
  6481. //Save into Share Memory
  6482. SHM_Save_din_ContractAuthenticationReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  6483. errn = Proc_din_ContractAuthenticationRes(AcceptFd);
  6484. if (errn == 0)
  6485. {
  6486. //send response successfully.
  6487. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][Tx]ContractAuthenticationRes");
  6488. }
  6489. else
  6490. {
  6491. sprintf((char*)buf_log_evcomm,
  6492. "[Error][SeccComm][Proc_din_ContractAuthenticationReq]Proc_iso1_AuthenticationRes(): %d (DEC)",
  6493. errn);
  6494. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6495. }
  6496. return errn;
  6497. }
  6498. /*===========================================================================
  6499. FUNCTION: Proc_iso1_AuthenticationReq
  6500. DESCRIPTION:
  6501. PRE-CONDITION:
  6502. INPUT:
  6503. OUTPUT:
  6504. GLOBAL VARIABLES:
  6505. =============================================================================*/
  6506. int Proc_iso1_AuthenticationReq(int AcceptFd)
  6507. {
  6508. int errn = 0;
  6509. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][Proc_iso1_AuthenticationReq]Got AuthorizationReq\n");
  6510. //Print the decoded XML Document
  6511. PRINT_XML_DOC_ISO1_AuthorizationReq(&ccs_exi_doc_ISO1);
  6512. //Save into Share Memory
  6513. SHM_Save_iso1_AuthorizationReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  6514. errn = Proc_iso1_AuthorizationRes(AcceptFd);
  6515. if (errn == 0)
  6516. {
  6517. //send response successfully.
  6518. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]AuthorizationRes");
  6519. }
  6520. else
  6521. {
  6522. sprintf((char*)buf_log_evcomm,
  6523. "[Error][SeccComm][Proc_iso1_AuthenticationReq]Proc_iso1_AuthenticationRes(): %d (DEC)",
  6524. errn);
  6525. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6526. }
  6527. return errn;
  6528. }
  6529. /*===========================================================================
  6530. FUNCTION: SHM_Init_dinDC_EVSEStatusType
  6531. DESCRIPTION:
  6532. PRE-CONDITION:
  6533. INPUT:
  6534. 1. in
  6535. OUTPUT:
  6536. 2. out
  6537. GLOBAL VARIABLES:
  6538. =============================================================================*/
  6539. void SHM_Init_dinDC_EVSEStatusType(struct DC_EVSEStatusType_DIN70121 *in)
  6540. {
  6541. in->EVSEIsolationStatus = dinisolationLevelType_Valid;
  6542. // dinisolationLevelType_Invalid = 0,
  6543. // dinisolationLevelType_Valid = 1, (default)
  6544. // dinisolationLevelType_Warning = 2,
  6545. // dinisolationLevelType_Fault = 3
  6546. in->EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  6547. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6548. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1, (default)
  6549. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6550. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6551. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6552. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6553. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6554. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  6555. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  6556. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  6557. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  6558. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  6559. in->EVSENotification = dinEVSENotificationType_None;
  6560. // dinEVSENotificationType_None = 0, (default)
  6561. // dinEVSENotificationType_StopCharging = 1,
  6562. // dinEVSENotificationType_ReNegotiation = 2
  6563. }
  6564. /*===========================================================================
  6565. FUNCTION: SHM_Save_dinPhysicalValueType
  6566. DESCRIPTION:
  6567. PRE-CONDITION:
  6568. INPUT:
  6569. OUTPUT:
  6570. GLOBAL VARIABLES:
  6571. =============================================================================*/
  6572. void SHM_Save_dinPhysicalValueType(struct PhysicalValueType_DIN70121 *obj, short value, int multiplier, unsigned char unit)
  6573. {
  6574. obj->Value = value;
  6575. obj->Multiplier = multiplier;
  6576. obj->Unit =unit;
  6577. }
  6578. /*===========================================================================
  6579. FUNCTION: SHM_Init_din_ChargeParameterDiscoveryRes
  6580. DESCRIPTION:
  6581. PRE-CONDITION:
  6582. INPUT:
  6583. 1. shm_ccs
  6584. OUTPUT:
  6585. 2. shm_ccs
  6586. GLOBAL VARIABLES:
  6587. =============================================================================*/
  6588. void SHM_Init_din_ChargeParameterDiscoveryRes(struct CcsData *shm_ccs)
  6589. {
  6590. struct ChargeParameterDiscoveryResponse_DIN70121 *in;
  6591. in = &shm_ccs->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse;
  6592. //----- [BODY (1/5)] ResponseCode -----
  6593. in->ResponseCode = dinresponseCodeType_OK;
  6594. //----- [BODY (2/5)] EVSEProcessing -----
  6595. in->EVSEProcessing = dinEVSEProcessingType_Ongoing; //0
  6596. // dinEVSEProcessingType_Finished = 0,
  6597. // dinEVSEProcessingType_Ongoing = 1
  6598. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6599. //be fixed in another function.
  6600. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6601. //ignore, since DIN doesn't support AC
  6602. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6603. struct DC_EVSEChargeParameterType_DIN70121 *in_para;
  6604. in_para = &in->DC_EVSEChargeParameter;
  6605. //DC_EVSEStatus
  6606. SHM_Init_dinDC_EVSEStatusType(&in_para->DC_EVSEStatus);
  6607. in_para->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  6608. short value = 0; int multiplier = 0; unsigned char unit = 0;
  6609. //EVSEMaximumCurrentLimit
  6610. value = 600; multiplier = -1; unit = A_DIN70121; //60A
  6611. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumCurrentLimit, value, multiplier, unit);
  6612. //EVSEMaximumPowerLimit
  6613. value = 3000; multiplier = 1; unit = W_DIN70121; //30KW
  6614. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumPowerLimit, value, multiplier, unit);
  6615. //EVSEMaximumVoltageLimit
  6616. value = 7500; multiplier = -1; unit = V_DIN70121; //750V
  6617. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumVoltageLimit, value, multiplier, unit);
  6618. //EVSEMinimumVoltageLimit
  6619. value = 1500; multiplier = -1; unit = V_DIN70121; //150V
  6620. SHM_Save_dinPhysicalValueType(&in_para->EVSEMinimumVoltageLimit, value, multiplier, unit);
  6621. //EVSEMinimumCurrentLimit
  6622. value = 10; multiplier = -1; unit = A_DIN70121; //1A
  6623. SHM_Save_dinPhysicalValueType(&in_para->EVSEMinimumCurrentLimit, value, multiplier, unit);
  6624. //EVSECurrentRegulationTolerance
  6625. value = 10; multiplier = -1; unit = A_DIN70121; //1A
  6626. SHM_Save_dinPhysicalValueType(&in_para->EVSECurrentRegulationTolerance, value, multiplier, unit);
  6627. //EVSEPeakCurrentRipple
  6628. value = 2; multiplier = -1; unit = A_DIN70121; //0.2A
  6629. SHM_Save_dinPhysicalValueType(&in_para->EVSEPeakCurrentRipple, value, multiplier, unit);
  6630. //EVSEEnergyToBeDelivered (optional)
  6631. //SHM_Save_dinPhysicalValueType(&out_para->EVSEEnergyToBeDelivered, &in_para->EVSEEnergyToBeDelivered);
  6632. }
  6633. /*===========================================================================
  6634. FUNCTION: Sudo_Parameter_din_ChargeParameterDiscoveryRes
  6635. DESCRIPTION:
  6636. PRE-CONDITION:
  6637. INPUT:
  6638. OUTPUT:
  6639. GLOBAL VARIABLES:
  6640. =============================================================================*/
  6641. void Sudo_Parameter_din_ChargeParameterDiscoveryRes()
  6642. {
  6643. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  6644. init_dinChargeParameterDiscoveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes);
  6645. ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed = 1u;
  6646. //----- [BODY (1/5)] ResponseCode -----
  6647. struct dinChargeParameterDiscoveryResType *res;
  6648. res = &ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes;
  6649. res->ResponseCode = dinresponseCodeType_OK;
  6650. //----- [BODY (2/5)] EVSEProcessing -----
  6651. res->EVSEProcessing = dinEVSEProcessingType_Finished; //0
  6652. // dinEVSEProcessingType_Finished = 0,
  6653. // dinEVSEProcessingType_Ongoing = 1
  6654. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6655. res->SAScheduleList_isUsed = 1u;
  6656. struct dinSAScheduleListType *list;
  6657. list = &res->SAScheduleList;
  6658. //
  6659. list->SAScheduleTuple.arrayLen = 1;
  6660. list->SAScheduleTuple.array[0].SAScheduleTupleID = 0;
  6661. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleID = 0;
  6662. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.arrayLen = 1;
  6663. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval_isUsed = 1u;
  6664. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.start = 0;
  6665. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration = xxx
  6666. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration_isUsed = 1u;
  6667. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval_isUsed = 0u;
  6668. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval.xxx
  6669. //list->SAScheduleTuple.array[0].SalesTariff.xxx
  6670. //list->SAScheduleTuple.array[0].SalesTariff_isUsed = 0u;
  6671. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6672. //ignore, since DIN doesn't support AC
  6673. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6674. res->DC_EVSEChargeParameter_isUsed = 1u;
  6675. struct dinDC_EVSEChargeParameterType *para;
  6676. para = &res->DC_EVSEChargeParameter;
  6677. //DC_EVSEStatus
  6678. para->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  6679. para->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  6680. // dinisolationLevelType_Invalid = 0,
  6681. // dinisolationLevelType_Valid = 1,
  6682. // dinisolationLevelType_Warning = 2,
  6683. // dinisolationLevelType_Fault = 3
  6684. para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  6685. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6686. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  6687. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6688. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6689. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6690. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6691. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6692. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  6693. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  6694. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  6695. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  6696. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  6697. para->DC_EVSEStatus.NotificationMaxDelay = 0u;
  6698. para->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  6699. // dinEVSENotificationType_None = 0,
  6700. // dinEVSENotificationType_StopCharging = 1,
  6701. // dinEVSENotificationType_ReNegotiation = 2
  6702. //EVSEMaximumCurrentLimit
  6703. para->EVSEMaximumCurrentLimit.Value = 2400;
  6704. para->EVSEMaximumCurrentLimit.Multiplier = -1;
  6705. para->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  6706. para->EVSEMaximumCurrentLimit.Unit = dinunitSymbolType_A;
  6707. // dinunitSymbolType_h = 0,
  6708. // dinunitSymbolType_m = 1,
  6709. // dinunitSymbolType_s = 2,
  6710. // dinunitSymbolType_A = 3,
  6711. // dinunitSymbolType_Ah = 4,
  6712. // dinunitSymbolType_V = 5,
  6713. // dinunitSymbolType_VA = 6,
  6714. // dinunitSymbolType_W = 7,
  6715. // dinunitSymbolType_W_s = 8,
  6716. // dinunitSymbolType_Wh = 9
  6717. //EVSEMaximumPowerLimit
  6718. para->EVSEMaximumPowerLimit.Value = 6000;
  6719. para->EVSEMaximumPowerLimit.Multiplier = 1;
  6720. para->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  6721. para->EVSEMaximumPowerLimit.Unit = dinunitSymbolType_W;
  6722. //EVSEMaximumVoltageLimit
  6723. para->EVSEMaximumVoltageLimit.Value = 7500;
  6724. para->EVSEMaximumVoltageLimit.Multiplier = -1;
  6725. para->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  6726. para->EVSEMaximumVoltageLimit.Unit = dinunitSymbolType_V;
  6727. //EVSEMinimumVoltageLimit
  6728. para->EVSEMinimumVoltageLimit.Value = 1500;
  6729. para->EVSEMinimumVoltageLimit.Multiplier = -1;
  6730. para->EVSEMinimumVoltageLimit.Unit_isUsed = 1u;
  6731. para->EVSEMinimumVoltageLimit.Unit = dinunitSymbolType_V;
  6732. //EVSEMinimumCurrentLimit
  6733. para->EVSEMinimumCurrentLimit.Value = 20;
  6734. para->EVSEMinimumCurrentLimit.Multiplier = -1;
  6735. para->EVSEMinimumCurrentLimit.Unit_isUsed = 1u;
  6736. para->EVSEMinimumCurrentLimit.Unit = dinunitSymbolType_A;
  6737. //EVSECurrentRegulationTolerance_isUsed
  6738. para->EVSECurrentRegulationTolerance_isUsed = 1u;
  6739. //EVSECurrentRegulationTolerance
  6740. para->EVSECurrentRegulationTolerance.Value = 10;
  6741. para->EVSECurrentRegulationTolerance.Multiplier = -1;
  6742. para->EVSECurrentRegulationTolerance.Unit_isUsed = 1u;
  6743. para->EVSECurrentRegulationTolerance.Unit = dinunitSymbolType_A;
  6744. //EVSEEnergyToBeDelivered_isUsed
  6745. para->EVSEEnergyToBeDelivered_isUsed = 1u;
  6746. //EVSEPeakCurrentRipple
  6747. para->EVSEPeakCurrentRipple.Value = 2;
  6748. para->EVSEPeakCurrentRipple.Multiplier = -1;
  6749. para->EVSEPeakCurrentRipple.Unit_isUsed = 1u;
  6750. para->EVSEPeakCurrentRipple.Unit = dinunitSymbolType_A;
  6751. //EVSEEnergyToBeDelivered (optional)
  6752. /*
  6753. para->EVSEEnergyToBeDelivered.Value = 360;
  6754. para->EVSEEnergyToBeDelivered.Multiplier = 3;
  6755. para->EVSEEnergyToBeDelivered.Unit_isUsed = 1u;
  6756. para->EVSEEnergyToBeDelivered.Unit = dinunitSymbolType_Wh;
  6757. */
  6758. }
  6759. /*===========================================================================
  6760. FUNCTION: Sudo_Parameter_iso1_ChargeParameterDiscoveryRes
  6761. DESCRIPTION:
  6762. PRE-CONDITION:
  6763. INPUT:
  6764. OUTPUT:
  6765. GLOBAL VARIABLES:
  6766. =============================================================================*/
  6767. void Sudo_Parameter_iso1_ChargeParameterDiscoveryRes()
  6768. {
  6769. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6770. init_iso1ChargeParameterDiscoveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes);
  6771. ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed = 1u;
  6772. //----- [BODY (1/5)] ResponseCode -----
  6773. struct iso1ChargeParameterDiscoveryResType *res;
  6774. res = &ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes;
  6775. res->ResponseCode = iso1responseCodeType_OK;
  6776. //----- [BODY (2/5)] EVSEProcessing -----
  6777. res->EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  6778. // iso1EVSEProcessingType_Finished = 0,
  6779. // iso1EVSEProcessingType_Ongoing = 1
  6780. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6781. res->SAScheduleList_isUsed = 1u;
  6782. struct iso1SAScheduleListType *list;
  6783. list = &res->SAScheduleList;
  6784. //
  6785. list->SAScheduleTuple.arrayLen = 1;
  6786. list->SAScheduleTuple.array[0].SAScheduleTupleID = 0;
  6787. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.arrayLen = 1;
  6788. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval_isUsed = 1u;
  6789. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.start = 0;
  6790. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration = xxx
  6791. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration_isUsed = 1u;
  6792. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval_isUsed = 0u;
  6793. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval.xxx
  6794. //list->SAScheduleTuple.array[0].SalesTariff.xxx
  6795. //list->SAScheduleTuple.array[0].SalesTariff_isUsed = 0u;
  6796. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6797. //ignore, since our ISO1 doesn't support AC, yet
  6798. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6799. res->DC_EVSEChargeParameter_isUsed = 1u;
  6800. struct iso1DC_EVSEChargeParameterType *para;
  6801. para = &res->DC_EVSEChargeParameter;
  6802. //DC_EVSEStatus
  6803. para->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  6804. para->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  6805. // iso1isolationLevelType_Invalid = 0,
  6806. // iso1isolationLevelType_Valid = 1,
  6807. // iso1isolationLevelType_Warning = 2,
  6808. // iso1isolationLevelType_Fault = 3
  6809. para->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  6810. // iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6811. // iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  6812. // iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6813. // iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6814. // iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6815. // iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6816. // iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6817. // iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  6818. // iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  6819. // iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  6820. // iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  6821. // iso1DC_EVSEStatusCodeType_Reserved_C = 11
  6822. para->DC_EVSEStatus.NotificationMaxDelay = 0u;
  6823. para->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  6824. // iso1EVSENotificationType_None = 0,
  6825. // iso1EVSENotificationType_StopCharging = 1,
  6826. // iso1EVSENotificationType_ReNegotiation = 2
  6827. //EVSEMaximumCurrentLimit
  6828. para->EVSEMaximumCurrentLimit.Value = 2400;
  6829. para->EVSEMaximumCurrentLimit.Multiplier = -1;
  6830. //para->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  6831. para->EVSEMaximumCurrentLimit.Unit = iso1unitSymbolType_A;
  6832. //iso1unitSymbolType_h = 0,
  6833. //iso1unitSymbolType_m = 1,
  6834. //iso1unitSymbolType_s = 2,
  6835. //iso1unitSymbolType_A = 3,
  6836. //iso1unitSymbolType_V = 4,
  6837. //iso1unitSymbolType_W = 5,
  6838. //iso1unitSymbolType_Wh = 6
  6839. //EVSEMaximumPowerLimit
  6840. para->EVSEMaximumPowerLimit.Value = 6000;
  6841. para->EVSEMaximumPowerLimit.Multiplier = 1;
  6842. //para->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  6843. para->EVSEMaximumPowerLimit.Unit = iso1unitSymbolType_W;
  6844. //EVSEMaximumVoltageLimit
  6845. para->EVSEMaximumVoltageLimit.Value = 7500;
  6846. para->EVSEMaximumVoltageLimit.Multiplier = -1;
  6847. //para->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  6848. para->EVSEMaximumVoltageLimit.Unit = iso1unitSymbolType_V;
  6849. //EVSEMinimumVoltageLimit
  6850. para->EVSEMinimumVoltageLimit.Value = 1500;
  6851. para->EVSEMinimumVoltageLimit.Multiplier = -1;
  6852. //para->EVSEMinimumVoltageLimit.Unit_isUsed = 1u;
  6853. para->EVSEMinimumVoltageLimit.Unit = iso1unitSymbolType_V;
  6854. //EVSEMinimumCurrentLimit
  6855. para->EVSEMinimumCurrentLimit.Value = 20;
  6856. para->EVSEMinimumCurrentLimit.Multiplier = -1;
  6857. //para->EVSEMinimumCurrentLimit.Unit_isUsed = 1u;
  6858. para->EVSEMinimumCurrentLimit.Unit = iso1unitSymbolType_A;
  6859. //EVSECurrentRegulationTolerance_isUsed
  6860. para->EVSECurrentRegulationTolerance_isUsed = 1u;
  6861. //EVSECurrentRegulationTolerance
  6862. para->EVSECurrentRegulationTolerance.Value = 10;
  6863. para->EVSECurrentRegulationTolerance.Multiplier = -1;
  6864. //para->EVSECurrentRegulationTolerance.Unit_isUsed = 1u;
  6865. para->EVSECurrentRegulationTolerance.Unit = iso1unitSymbolType_A;
  6866. //EVSEEnergyToBeDelivered_isUsed
  6867. para->EVSEEnergyToBeDelivered_isUsed = 1u;
  6868. //EVSEPeakCurrentRipple
  6869. para->EVSEPeakCurrentRipple.Value = 2;
  6870. para->EVSEPeakCurrentRipple.Multiplier = -1;
  6871. //para->EVSEPeakCurrentRipple.Unit_isUsed = 1u;
  6872. para->EVSEPeakCurrentRipple.Unit = iso1unitSymbolType_A;
  6873. //EVSEEnergyToBeDelivered (optional)
  6874. /*
  6875. para->EVSEEnergyToBeDelivered.Value = 360;
  6876. para->EVSEEnergyToBeDelivered.Multiplier = 3;
  6877. para->EVSEEnergyToBeDelivered.Unit_isUsed = 1u;
  6878. para->EVSEEnergyToBeDelivered.Unit = iso1unitSymbolType_Wh;
  6879. */
  6880. }
  6881. /*===========================================================================
  6882. FUNCTION: Proc_din_ChargeParameterDiscoveryRes
  6883. DESCRIPTION:
  6884. PRE-CONDITION:
  6885. INPUT:
  6886. OUTPUT:
  6887. GLOBAL VARIABLES:
  6888. =============================================================================*/
  6889. int Proc_din_ChargeParameterDiscoveryRes(int AcceptFd)
  6890. {
  6891. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6892. //if it is not the same, the packet should be ignored.
  6893. //STEP 1: ============ Initialize ============
  6894. int errn = 0;
  6895. bitstream_t v2g_tx_stream;
  6896. struct ChargeParameterDiscoveryResponse_DIN70121 *res;
  6897. struct ChargeParameterDiscoveryRequest_DIN70121 *req;
  6898. struct DC_EVSEChargeParameterType_DIN70121 *dc_para;
  6899. struct ChargingInfoData *sys;
  6900. size_t pos = 0;
  6901. v2g_tx_stream.pos = &pos;
  6902. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6903. v2g_tx_stream.data = V2GTP_Tx_buf;
  6904. res = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse;
  6905. req = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest;
  6906. dc_para = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse.DC_EVSEChargeParameter;
  6907. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6908. res->ResponseCode = OK_DIN70121;
  6909. res->EVSEProcessing = Ongoing_DIN70121;
  6910. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready; //1
  6911. //[HEADER] Check Req SessionID
  6912. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  6913. {
  6914. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  6915. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  6916. errn = -1;
  6917. }
  6918. //Check for SequenceError
  6919. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6920. {
  6921. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  6922. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  6923. errn = -1;
  6924. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6925. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6926. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6927. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6928. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6929. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6930. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6931. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6932. }
  6933. //[TC_SECC_VTB_ChargeParameterDiscovery_005]
  6934. if (sys->EvBatteryMaxCurrent < 0)
  6935. {
  6936. sprintf((char*)buf_log_evcomm,
  6937. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  6938. sys->EvBatteryMaxCurrent);
  6939. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6940. res->ResponseCode = dinresponseCodeType_FAILED_WrongChargeParameter; //16
  6941. res->EVSEProcessing = Finished_DIN70121;
  6942. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6943. errn = -1;
  6944. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6945. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  6946. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6947. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6948. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6949. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6950. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  6951. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  6952. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6953. }
  6954. //STEP 2: ============ Modify Parameters of ShmCcsData ============
  6955. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_DIN70121);
  6956. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_DIN70121);
  6957. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_DIN70121);
  6958. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMinimumVoltageLimit, 1500, V_DIN70121); //150V
  6959. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMinimumCurrentLimit, 10, A_DIN70121); //1A
  6960. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSECurrentRegulationTolerance, 10, A_DIN70121); //1A
  6961. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEPeakCurrentRipple, 2, A_DIN70121); //0.2A
  6962. //SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEEnergyToBeDelivered, 0, WH_DIN70121); //optional
  6963. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  6964. if (sys->EvBatteryMaxVoltage <= 500)
  6965. {
  6966. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumVoltageLimit, (int) (500 * 10), V_DIN70121); //500V
  6967. }
  6968. #endif
  6969. //for test with Tesla Model 3, 10A
  6970. //SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumCurrentLimit, (int) (10 * 10), A_DIN70121); //10A, for testing with Tesla Model 3
  6971. //Check for EnergyTransferMode [TC_SECC_VTB_ChargeParameterDiscovery_004]
  6972. if (req->EVRequestedEnergyTransferType != DC_extended)
  6973. {
  6974. sprintf((char*)buf_log_evcomm,
  6975. "[ERROR]Wrong EVRequestedEnergyTransferType(%d,%d)",
  6976. req->EVRequestedEnergyTransferType,
  6977. dinEVSESupportedEnergyTransferType_DC_extended);
  6978. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6979. res->ResponseCode = FAILED_WrongEnergyTransferType_DIN70121;
  6980. res->EVSEProcessing = Finished_DIN70121;
  6981. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6982. errn = -1;
  6983. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6984. Update_V2G_Flow_Status(Other_Fault);
  6985. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6986. //CCS_SECC_ResponseCode_FAILED_WrongEnergyTransferMode (023774)
  6987. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6988. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6989. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6990. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6991. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  6992. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  6993. }
  6994. //Check for CSU command of "Stop by EVSE"
  6995. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6996. {
  6997. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_ChargeParameterDiscoveryRes]EVSE_Shutdown");
  6998. res->ResponseCode = FAILED_DIN70121;
  6999. res->EVSEProcessing = Finished_DIN70121;
  7000. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7001. errn = -1;
  7002. }
  7003. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7004. {
  7005. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_ChargeParameterDiscoveryRes]EVSE_EmergencyShutdown");
  7006. res->ResponseCode = FAILED_DIN70121;
  7007. res->EVSEProcessing = Finished_DIN70121;
  7008. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7009. errn = -1;
  7010. }
  7011. //Detect for CP State should be 9V (State B)
  7012. #if CP_PROTECTION_MECHANISM == ENABLE
  7013. if (sys->CpState != 3) //State B1, B2
  7014. {
  7015. res->ResponseCode = FAILED_DIN70121;
  7016. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7017. res->EVSEProcessing = Finished_DIN70121;
  7018. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7019. Update_V2G_Flow_Status(Other_Fault);
  7020. errn = -1;
  7021. sprintf((char*)buf_log_evcomm,
  7022. "[Proc_din_ChargeParameterDiscoveryRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  7023. sys->CpState,
  7024. sys->CpVoltage);
  7025. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7026. }
  7027. #endif
  7028. //Check for Permission from CSU
  7029. if (ShmInternalComm->ChargingPermission == TRUE)
  7030. {
  7031. res->EVSEProcessing = Finished_DIN70121;
  7032. }
  7033. //Check for Permission Off
  7034. if (ShmInternalComm->ChargingPermission == FALSE)
  7035. {
  7036. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][ChargeParameterDiscoveryRes]Permission OFF");
  7037. res->ResponseCode = FAILED_DIN70121;
  7038. res->EVSEProcessing = Finished_DIN70121;
  7039. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7040. errn = -1;
  7041. }
  7042. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7043. #if PARAMETER_NORMAL_MODE == ENABLE
  7044. SHM_Read_din_ChargeParameterDiscoveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  7045. #else
  7046. Sudo_Parameter_din_ChargeParameterDiscoveryRes();
  7047. #endif
  7048. //STEP 4: ============ Encode and Send Response Message ===========
  7049. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  7050. {
  7051. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  7052. errn = -1;
  7053. }
  7054. //STPE 5: ============ Update Flags ============
  7055. return errn;
  7056. }
  7057. /*===========================================================================
  7058. FUNCTION: Proc_iso1_ChargeParameterDiscoveryRes
  7059. DESCRIPTION:
  7060. PRE-CONDITION:
  7061. INPUT:
  7062. OUTPUT:
  7063. GLOBAL VARIABLES:
  7064. =============================================================================*/
  7065. int Proc_iso1_ChargeParameterDiscoveryRes(int AcceptFd)
  7066. {
  7067. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7068. //if it is not the same, the packet should be ignored.
  7069. //STEP 1: ============ Initialize ============
  7070. int errn = 0;
  7071. bitstream_t v2g_tx_stream;
  7072. struct ChargeParameterDiscoveryResponse_ISO15118_2014 *res;
  7073. struct ChargeParameterDiscoveryRequest_ISO15118_2014 *req;
  7074. struct DC_EVSEChargeParameterType_ISO15118_2014 *dc_para;
  7075. struct AC_EVSEChargeParameterType_ISO15118_2014 *ac_para;
  7076. struct ChargingInfoData *sys;
  7077. size_t pos = 0;
  7078. v2g_tx_stream.pos = &pos;
  7079. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7080. v2g_tx_stream.data = V2GTP_Tx_buf;
  7081. res = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse;
  7082. req = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest;
  7083. dc_para = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse.DC_EVSEChargeParameter;
  7084. ac_para = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse.AC_EVSEChargeParameter;
  7085. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7086. res->ResponseCode = OK_ISO15118_2014;
  7087. res->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  7088. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; //1
  7089. ac_para->AC_EVSEStatus.RCD = ShmInternalComm->AC_RcdStatus; //0:no error, 1:error
  7090. ac_para->AC_EVSEStatus.NotificationMaxDelay = 0; //unit: 1s
  7091. ac_para->AC_EVSEStatus.EVSENotification = ShmInternalComm->AC_EVSENotification; //0:none, 1:StopCharging, 2:RenNgotiation
  7092. //[HEADER] Check Req SessionID
  7093. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  7094. {
  7095. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  7096. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  7097. errn = -1;
  7098. }
  7099. //Check for SequenceError
  7100. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7101. {
  7102. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  7103. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  7104. errn = -1;
  7105. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7106. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7107. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7108. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7109. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7110. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7111. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7112. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7113. }
  7114. //[TC_SECC_VTB_ChargeParameterDiscovery_005]
  7115. if (sys->EvBatteryMaxCurrent < 0)
  7116. {
  7117. sprintf((char*)buf_log_evcomm,
  7118. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  7119. sys->EvBatteryMaxCurrent);
  7120. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7121. res->ResponseCode = iso1responseCodeType_FAILED_WrongChargeParameter; //16
  7122. res->EVSEProcessing = Finished_ISO15118_2014;
  7123. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7124. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7125. errn = -1;
  7126. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7127. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  7128. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7129. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7130. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7131. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7132. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  7133. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  7134. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7135. }
  7136. //STEP 2: ============ Modify Parameters of ShmCcsData ============
  7137. //DC
  7138. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_ISO15118_2014);
  7139. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  7140. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_ISO15118_2014);
  7141. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMinimumVoltageLimit, 1500, V_ISO15118_2014); //150V
  7142. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMinimumCurrentLimit, 10, A_ISO15118_2014); //1A
  7143. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSECurrentRegulationTolerance, 10, A_ISO15118_2014); //1A
  7144. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEPeakCurrentRipple, 2, A_ISO15118_2014); //0.2A
  7145. //SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEEnergyToBeDelivered, 0, Wh_ISO15118_2014); //optional
  7146. //AC
  7147. SAVE_PhysicalValueType_ISO15118_2014(&ac_para->EVSENominalVoltage, (int) (sys->AC_EVSENominalVoltage * 10), V_ISO15118_2014);
  7148. SAVE_PhysicalValueType_ISO15118_2014(&ac_para->EVSEMaxCurrent, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  7149. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  7150. if (sys->EvBatteryMaxVoltage <= 500)
  7151. {
  7152. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumVoltageLimit, (int) (500 * 10), V_ISO15118_2014); //500V
  7153. }
  7154. #endif
  7155. //for test with Tesla Model 3, 10A
  7156. //SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumCurrentLimit, (int) (10 * 10), A_ISO15118_2014); //10A, for testing with Tesla Model 3
  7157. //Check for EnergyTransferMode
  7158. if (req->RequestedEnergyTransferMode != ShmCcsData->EnergyTransferMode) //[CAUTION] Their table should be kept as the same.
  7159. {
  7160. sprintf((char*)buf_log_evcomm,
  7161. "[ERROR]Unmatched RequestedEnergyTransferMode(%d,%d)",
  7162. req->RequestedEnergyTransferMode,
  7163. ShmCcsData->EnergyTransferMode);
  7164. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7165. res->ResponseCode = FAILED_WrongEnergyTransferMode_ISO15118_2014;
  7166. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7167. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7168. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7169. errn = -1;
  7170. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7171. Update_V2G_Flow_Status(Other_Fault);
  7172. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7173. //CCS_SECC_ResponseCode_FAILED_WrongEnergyTransferMode (023774)
  7174. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7175. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7176. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7177. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7178. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  7179. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  7180. }
  7181. //Check for CSU command of "Stop by EVSE"
  7182. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7183. {
  7184. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ChargeParameterDiscoveryRes]EVSE_Shutdown");
  7185. res->ResponseCode = FAILED_ISO15118_2014;
  7186. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7187. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7188. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7189. errn = -1;
  7190. }
  7191. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7192. {
  7193. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ChargeParameterDiscoveryRes]EVSE_EmergencyShutdown");
  7194. res->ResponseCode = FAILED_ISO15118_2014;
  7195. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7196. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7197. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7198. errn = -1;
  7199. }
  7200. //Detect for CP State should be 9V (State B)
  7201. #if CP_PROTECTION_MECHANISM == ENABLE
  7202. if (sys->CpState != 3) //State B1, B2
  7203. {
  7204. res->ResponseCode = FAILED_ISO15118_2014;
  7205. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7206. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7207. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7208. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7209. Update_V2G_Flow_Status(Other_Fault);
  7210. errn = -1;
  7211. sprintf((char*)buf_log_evcomm,
  7212. "[Proc_iso1_ChargeParameterDiscoveryRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  7213. sys->CpState,
  7214. sys->CpVoltage);
  7215. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7216. }
  7217. #endif
  7218. //Check for Permission from CSU
  7219. if(ShmInternalComm->ChargingPermission == TRUE)
  7220. {
  7221. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7222. }
  7223. //Check for Permission Off
  7224. if (ShmInternalComm->ChargingPermission == FALSE)
  7225. {
  7226. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][ISO1][ChargeParameterDiscoveryRes]Permission OFF");
  7227. res->ResponseCode = FAILED_ISO15118_2014;
  7228. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7229. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7230. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7231. errn = -1;
  7232. }
  7233. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7234. #if PARAMETER_NORMAL_MODE == ENABLE
  7235. SHM_Read_iso1_ChargeParameterDiscoveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  7236. #else
  7237. Sudo_Parameter_iso1_ChargeParameterDiscoveryRes();
  7238. #endif
  7239. //STEP 4: ============ Encode and Send Response Message ===========
  7240. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  7241. {
  7242. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  7243. errn = -1;
  7244. }
  7245. //STPE 5: ============ Update Flags ============
  7246. return errn;
  7247. }
  7248. /*===========================================================================
  7249. FUNCTION: Proc_din_ChargeParameterDiscoveryReq
  7250. DESCRIPTION:
  7251. PRE-CONDITION:
  7252. INPUT:
  7253. OUTPUT:
  7254. GLOBAL VARIABLES:
  7255. =============================================================================*/
  7256. int Proc_din_ChargeParameterDiscoveryReq(int AcceptFd)
  7257. {
  7258. int errn = 0;
  7259. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_ChargeParameterDiscoveryReq] Got ChargeParameterDiscoveryReq");
  7260. //ftime(&SeqStartTime);
  7261. //Print the decoded XML Document
  7262. PRINT_XML_DOC_DIN_ChargeParameterDiscoveryReq(&ccs_exi_doc_DIN);
  7263. //Save into Share Memory
  7264. SHM_Save_din_ChargeParameterDiscoveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  7265. //Check for EV Error Code
  7266. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.DC_EVStatus.EVErrorCode);
  7267. errn = Proc_din_ChargeParameterDiscoveryRes(AcceptFd);
  7268. //ftime(&SeqEndTime);
  7269. //DEBUG_PRINTF_EVCOMM_DETAIL("\ndelta = %.02lf ms\n", DiffTimeb(SeqStartTime, SeqEndTime));
  7270. if ( errn == 0)
  7271. {
  7272. //send response successfully.
  7273. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][Tx]ChargeParameterDiscoveryRes");
  7274. }
  7275. else
  7276. {
  7277. sprintf((char*)buf_log_evcomm,
  7278. "[Error][DIN][ChargeParameterDiscoveryRes]%d (DEC)",
  7279. errn);
  7280. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7281. }
  7282. return errn;
  7283. }
  7284. /*===========================================================================
  7285. FUNCTION: Proc_iso1_ChargeParameterDiscoveryReq
  7286. DESCRIPTION:
  7287. PRE-CONDITION:
  7288. INPUT:
  7289. OUTPUT:
  7290. GLOBAL VARIABLES:
  7291. =============================================================================*/
  7292. int Proc_iso1_ChargeParameterDiscoveryReq(int AcceptFd)
  7293. {
  7294. int errn = 0;
  7295. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ChargeParameterDiscoveryReq] Got ChargeParameterDiscoveryReq");
  7296. //ftime(&SeqStartTime);
  7297. //Print the decoded XML Document
  7298. PRINT_XML_DOC_ISO1_ChargeParameterDiscoveryReq(&ccs_exi_doc_ISO1);
  7299. //Save into Share Memory
  7300. SHM_Save_iso1_ChargeParameterDiscoveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  7301. //Check for EV Error Code
  7302. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.DC_EVStatus.EVErrorCode);
  7303. errn = Proc_iso1_ChargeParameterDiscoveryRes(AcceptFd);
  7304. //ftime(&SeqEndTime);
  7305. //DEBUG_PRINTF_EVCOMM_DETAIL("\ndelta = %.02lf ms\n", DiffTimeb(SeqStartTime, SeqEndTime));
  7306. if (errn == 0)
  7307. {
  7308. //send response successfully.
  7309. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]ChargeParameterDiscoveryRes");
  7310. }
  7311. else
  7312. {
  7313. sprintf((char*)buf_log_evcomm,
  7314. "[Error][ISO1][ChargeParameterDiscoveryRes]%d (DEC)",
  7315. errn);
  7316. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7317. }
  7318. return errn;
  7319. }
  7320. /*===========================================================================
  7321. FUNCTION: SHM_Init_din_CableCheckRes
  7322. DESCRIPTION:
  7323. PRE-CONDITION:
  7324. INPUT:
  7325. 1. shm_ccs
  7326. OUTPUT:
  7327. 1. shm_ccs
  7328. GLOBAL VARIABLES:
  7329. =============================================================================*/
  7330. void SHM_Init_din_CableCheckRes(struct CcsData *shm_ccs)
  7331. {
  7332. struct CableCheckResponse_DIN70121 *in;
  7333. in = &shm_ccs->V2GMessage_DIN70121.CableCheckResponse;
  7334. //----- [BODY (1/3)] ResponseCode -----
  7335. in->ResponseCode = dinresponseCodeType_OK;
  7336. //----- [BODY (2/3)] EVSEProcessing -----
  7337. //in->EVSEProcessing = dinEVSEProcessingType_Finished; //for test
  7338. in->EVSEProcessing = dinEVSEProcessingType_Ongoing; //default
  7339. // dinEVSEProcessingType_Finished = 0,
  7340. // dinEVSEProcessingType_Ongoing = 1
  7341. //----- [BODY (3/3)] DC_EVSEStatus -----
  7342. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  7343. in->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0 (default)
  7344. // dinisolationLevelType_Invalid = 0,
  7345. // dinisolationLevelType_Valid = 1, (default)
  7346. // dinisolationLevelType_Warning = 2,
  7347. // dinisolationLevelType_Fault = 3
  7348. }
  7349. /*===========================================================================
  7350. FUNCTION: Sudo_Parameter_din_CableCheckRes
  7351. DESCRIPTION:
  7352. PRE-CONDITION:
  7353. INPUT:
  7354. OUTPUT:
  7355. GLOBAL VARIABLES:
  7356. =============================================================================*/
  7357. void Sudo_Parameter_din_CableCheckRes()
  7358. {
  7359. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  7360. init_dinCableCheckResType(&ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes);
  7361. ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes_isUsed = 1u;
  7362. //----- [BODY (1/3)] ResponseCode -----
  7363. struct dinCableCheckResType *res;
  7364. res = &ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes;
  7365. res->ResponseCode = dinresponseCodeType_OK;
  7366. //----- [BODY (2/3)] EVSEProcessing -----
  7367. res->EVSEProcessing = dinEVSEProcessingType_Finished; //0
  7368. // dinEVSEProcessingType_Finished = 0,
  7369. // dinEVSEProcessingType_Ongoing = 1
  7370. //----- [BODY (3/3)] DC_EVSEStatus -----
  7371. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7372. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7373. // dinisolationLevelType_Invalid = 0,
  7374. // dinisolationLevelType_Valid = 1,
  7375. // dinisolationLevelType_Warning = 2,
  7376. // dinisolationLevelType_Fault = 3
  7377. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7378. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7379. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  7380. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7381. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7382. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7383. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7384. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7385. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  7386. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  7387. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  7388. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  7389. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  7390. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7391. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  7392. // dinEVSENotificationType_None = 0,
  7393. // dinEVSENotificationType_StopCharging = 1,
  7394. // dinEVSENotificationType_ReNegotiation = 2
  7395. }
  7396. /*===========================================================================
  7397. FUNCTION: Sudo_Parameter_iso1_CableCheckRes
  7398. DESCRIPTION:
  7399. PRE-CONDITION:
  7400. INPUT:
  7401. OUTPUT:
  7402. GLOBAL VARIABLES:
  7403. =============================================================================*/
  7404. void Sudo_Parameter_iso1_CableCheckRes()
  7405. {
  7406. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  7407. init_iso1CableCheckResType(&ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes);
  7408. ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes_isUsed = 1u;
  7409. //----- [BODY (1/3)] ResponseCode -----
  7410. struct iso1CableCheckResType *res;
  7411. res = &ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes;
  7412. res->ResponseCode = iso1responseCodeType_OK;
  7413. //----- [BODY (2/3)] EVSEProcessing -----
  7414. res->EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  7415. //iso1EVSEProcessingType_Finished = 0,
  7416. //iso1EVSEProcessingType_Ongoing = 1,
  7417. //iso1EVSEProcessingType_Ongoing_WaitingForCustomerInteraction = 2
  7418. //----- [BODY (3/3)] DC_EVSEStatus -----
  7419. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7420. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  7421. //iso1isolationLevelType_Invalid = 0,
  7422. //iso1isolationLevelType_Valid = 1,
  7423. //iso1isolationLevelType_Warning = 2,
  7424. //iso1isolationLevelType_Fault = 3,
  7425. //iso1isolationLevelType_No_IMD = 4
  7426. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  7427. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7428. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  7429. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7430. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7431. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7432. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7433. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7434. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  7435. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  7436. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  7437. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  7438. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  7439. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7440. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  7441. //iso1EVSENotificationType_None = 0,
  7442. //iso1EVSENotificationType_StopCharging = 1,
  7443. //iso1EVSENotificationType_ReNegotiation = 2
  7444. }
  7445. /*===========================================================================
  7446. FUNCTION: Proc_din_CableCheckRes
  7447. DESCRIPTION:
  7448. PRE-CONDITION:
  7449. INPUT:
  7450. OUTPUT:
  7451. GLOBAL VARIABLES:
  7452. =============================================================================*/
  7453. int Proc_din_CableCheckRes(int AcceptFd)
  7454. {
  7455. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7456. //if it is not the same, the packet should be ignored.
  7457. //STEP 1: ============ Initialize ============
  7458. //int i = 0;
  7459. int errn = 0;
  7460. bitstream_t v2g_tx_stream;
  7461. static struct CableCheckResponse_DIN70121 *cab;
  7462. static struct ChargingInfoData *sys;
  7463. size_t pos = 0;
  7464. v2g_tx_stream.pos = &pos;
  7465. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7466. v2g_tx_stream.data = V2GTP_Tx_buf;
  7467. cab = &ShmCcsData->V2GMessage_DIN70121.CableCheckResponse;
  7468. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7469. cab->ResponseCode = OK_DIN70121;
  7470. cab->cnt++;
  7471. DEBUG_PRINTF_EVCOMM_DETAIL("CP_State = %d (%.02f V), V_now = %.02f, Isolation Status = %d, EVSEProcessing = %d\n",
  7472. sys->CpState,
  7473. sys->CpVoltage,
  7474. sys->PresentChargingVoltage,
  7475. sys->IsolationStatus,
  7476. cab->EVSEProcessing);
  7477. //[HEADER] Check Req SessionID
  7478. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  7479. {
  7480. cab->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  7481. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  7482. errn = -1;
  7483. }
  7484. //Check for SequenceError
  7485. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7486. {
  7487. cab->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  7488. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  7489. errn = -1;
  7490. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7491. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7492. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7493. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7494. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7495. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7496. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7497. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7498. }
  7499. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  7500. if (sys->IsolationStatus == GFD_Invalid) //0: on going
  7501. {
  7502. //For PSU
  7503. sys->EvBatterytargetVoltage = CABLECHECK_TARGET_VOLTAGE; //500V //[To-Do] this should be modified to auto decision.
  7504. sys->EvBatterytargetCurrent = CABLECHECK_TARGET_CURRENT; //2A(default), unit: 1A
  7505. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7506. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive; //4
  7507. cab->EVSEProcessing = dinEVSEProcessingType_Ongoing;
  7508. }
  7509. else if ((sys->IsolationStatus == GFD_Valid) || (sys->IsolationStatus == GFD_Warning)) //1: valid, 2: warning
  7510. {
  7511. //For PSU
  7512. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7513. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7514. if (sys->PresentChargingVoltage < 60) // < 60V
  7515. {
  7516. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  7517. sprintf((char*)buf_log_evcomm, "[V2G][CableCheck]Pass (V_now = %.02f, Isolated = %d)",
  7518. sys->PresentChargingVoltage,
  7519. sys->IsolationStatus);
  7520. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7521. //IsolationStatus
  7522. if (sys->IsolationStatus == GFD_Valid)
  7523. {
  7524. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7525. }
  7526. else if (sys->IsolationStatus == GFD_Warning)
  7527. {
  7528. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning;
  7529. }
  7530. else
  7531. {
  7532. sprintf((char*)buf_log_evcomm,
  7533. "[WARNING]unexpected IsolationStatus(%d)",
  7534. sys->IsolationStatus);
  7535. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7536. }
  7537. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7538. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7539. }
  7540. else
  7541. {
  7542. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7543. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7544. cab->EVSEProcessing = dinEVSEProcessingType_Ongoing;
  7545. }
  7546. }
  7547. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  7548. {
  7549. //For PSU
  7550. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7551. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7552. cab->ResponseCode = FAILED_DIN70121;
  7553. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7554. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_NotReady;
  7555. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7556. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_CableCheckRes]IsolationStatus = 3 (fault)");
  7557. errn = -1;
  7558. }
  7559. else
  7560. {
  7561. //For PSU
  7562. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7563. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7564. cab->ResponseCode = FAILED_DIN70121;
  7565. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7566. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_NotReady;
  7567. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7568. sprintf((char*)buf_log_evcomm,
  7569. "[Proc_din_CableCheckRes]Undefined Isolation Status(%d)",
  7570. sys->IsolationStatus);
  7571. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7572. }
  7573. //Check for CSU command of "Stop by EVSE"
  7574. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7575. {
  7576. cab->ResponseCode = FAILED_DIN70121;
  7577. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7578. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7579. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7580. errn = -1;
  7581. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_CableCheckRes]EVSE_Shutdown");
  7582. }
  7583. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7584. {
  7585. cab->ResponseCode = FAILED_DIN70121;
  7586. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7587. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7588. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7589. errn = -1;
  7590. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_CableCheckRes]EVSE_EmergencyShutdown");
  7591. }
  7592. else if (ShmInternalComm->ChargingPermission == FALSE)
  7593. {
  7594. cab->ResponseCode = FAILED_DIN70121;
  7595. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7596. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7597. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7598. errn = -1;
  7599. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_CableCheckRes]ChargingPermission = FALSE");
  7600. }
  7601. else
  7602. {
  7603. //null
  7604. }
  7605. //Response to CP Error
  7606. #if CP_PROTECTION_MECHANISM == ENABLE
  7607. //#if 1
  7608. if (sys->CableCheckPreCountDownDone == TRUE) //[To-Do] Here should be modified to 2 seconds
  7609. {
  7610. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  7611. {
  7612. cab->ResponseCode = FAILED_DIN70121;
  7613. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7614. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7615. Update_V2G_Flow_Status(Other_Fault);
  7616. errn = -1;
  7617. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7618. //CCS_SECC_CP_State_Error (023889)
  7619. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7620. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7621. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7622. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  7623. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  7624. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  7625. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  7626. sprintf((char*)buf_log_evcomm,
  7627. "[CableCheck]Emergency Stop by CP Error (%d, %.02f V, %d)\n",
  7628. sys->CpState,
  7629. sys->CpVoltage,
  7630. cab->cnt
  7631. );
  7632. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7633. //cab->cnt = 0;
  7634. }
  7635. }
  7636. #endif
  7637. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7638. #if PARAMETER_NORMAL_MODE == ENABLE
  7639. SHM_Read_din_CableCheckRes(&ccs_exi_doc_DIN, ShmCcsData);
  7640. #else
  7641. Sudo_Parameter_din_CableCheckRes();
  7642. #endif
  7643. //STEP 4: ============ Encode and Send Response Message ===========
  7644. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  7645. {
  7646. errn = -1;
  7647. }
  7648. //STEP 5: ============ Update Flags ===========
  7649. sys->ConnectorLocked = TRUE; //Inicating EVSE that the CCS Connector is Locked.
  7650. return errn;
  7651. }
  7652. /*===========================================================================
  7653. FUNCTION: Proc_iso1_CableCheckRes
  7654. DESCRIPTION:
  7655. PRE-CONDITION:
  7656. INPUT:
  7657. OUTPUT:
  7658. GLOBAL VARIABLES:
  7659. =============================================================================*/
  7660. int Proc_iso1_CableCheckRes(int AcceptFd)
  7661. {
  7662. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7663. //if it is not the same, the packet should be ignored.
  7664. //STEP 1: ============ Initialize ============
  7665. //int i = 0;
  7666. int errn = 0;
  7667. bitstream_t v2g_tx_stream;
  7668. static struct CableCheckResponse_ISO15118_2014 *cab;
  7669. static struct ChargingInfoData *sys;
  7670. size_t pos = 0;
  7671. v2g_tx_stream.pos = &pos;
  7672. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7673. v2g_tx_stream.data = V2GTP_Tx_buf;
  7674. cab = &ShmCcsData->V2GMessage_ISO15118_2014.CableCheckResponse;
  7675. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7676. cab->ResponseCode = OK_ISO15118_2014;
  7677. cab->cnt++;
  7678. DEBUG_PRINTF_EVCOMM_DETAIL("CP_State = %d (%.02f V), V_now = %.02f, Isolation Status = %d, EVSEProcessing = %d\n",
  7679. sys->CpState,
  7680. sys->CpVoltage,
  7681. sys->PresentChargingVoltage,
  7682. sys->IsolationStatus,
  7683. cab->EVSEProcessing);
  7684. //[HEADER] Check Req SessionID
  7685. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  7686. {
  7687. cab->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  7688. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  7689. errn = -1;
  7690. }
  7691. //Check for SequenceError
  7692. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7693. {
  7694. cab->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  7695. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  7696. errn = -1;
  7697. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7698. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7699. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7700. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7701. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7702. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7703. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7704. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7705. }
  7706. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  7707. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  7708. {
  7709. //For PSU
  7710. sys->EvBatterytargetVoltage = CABLECHECK_TARGET_VOLTAGE; //500V //[To-Do] this should be modified to auto decision.
  7711. sys->EvBatterytargetCurrent = CABLECHECK_TARGET_CURRENT; //2A(default), unit: 1A
  7712. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  7713. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7714. cab->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  7715. }
  7716. else if ((sys->IsolationStatus == GFD_Valid) || (sys->IsolationStatus == GFD_Warning)) //1: valid, 2:waring
  7717. {
  7718. //For PSU
  7719. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7720. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7721. if (sys->PresentChargingVoltage < 60) // < 60V
  7722. {
  7723. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  7724. sprintf((char*)buf_log_evcomm, "[V2G][CableCheck]Pass (V_now = %.02f, Isolated = %d)",
  7725. sys->PresentChargingVoltage,
  7726. sys->IsolationStatus);
  7727. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7728. //IsolationStatus
  7729. if (sys->IsolationStatus == GFD_Valid)
  7730. {
  7731. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  7732. }
  7733. else if (sys->IsolationStatus == GFD_Warning)
  7734. {
  7735. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning;
  7736. }
  7737. else
  7738. {
  7739. sprintf((char*)buf_log_evcomm,
  7740. "[WARNING]unexpected IsolationStatus(%d)",
  7741. sys->IsolationStatus);
  7742. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7743. }
  7744. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  7745. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7746. }
  7747. else
  7748. {
  7749. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  7750. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7751. cab->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  7752. }
  7753. }
  7754. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  7755. {
  7756. //For PSU
  7757. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7758. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7759. cab->ResponseCode = FAILED_ISO15118_2014;
  7760. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7761. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_NotReady;
  7762. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7763. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_CableCheckRes]IsolationStatus = 3 (fault)");
  7764. errn = -1;
  7765. }
  7766. //else if (sys->IsolationStatus == GFD_No_IMD){} //only for ISO15118
  7767. else
  7768. {
  7769. //For PSU
  7770. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7771. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7772. cab->ResponseCode = FAILED_ISO15118_2014;
  7773. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7774. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_NotReady;
  7775. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7776. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_CableCheckRes]Undefined Isolation Status.");
  7777. }
  7778. //Check for CSU command of "Stop by EVSE"
  7779. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7780. {
  7781. cab->ResponseCode = FAILED_ISO15118_2014;
  7782. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7783. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7784. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7785. errn = -1;
  7786. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_CableCheckRes]EVSE_Shutdown");
  7787. }
  7788. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7789. {
  7790. cab->ResponseCode = FAILED_ISO15118_2014;
  7791. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7792. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7793. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7794. errn = -1;
  7795. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_CableCheckRes]EVSE_EmergencyShutdown");
  7796. }
  7797. else if (ShmInternalComm->ChargingPermission == FALSE)
  7798. {
  7799. cab->ResponseCode = FAILED_ISO15118_2014;
  7800. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7801. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7802. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7803. errn = -1;
  7804. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_CableCheckRes]ChargingPermission = FALSE");
  7805. }
  7806. else
  7807. {
  7808. //null
  7809. }
  7810. //Response to CP Error
  7811. #if CP_PROTECTION_MECHANISM == ENABLE
  7812. if (sys->CableCheckPreCountDownDone == TRUE) //[To-Do] Here should be modified to 2 seconds
  7813. {
  7814. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  7815. {
  7816. cab->ResponseCode = FAILED_ISO15118_2014;
  7817. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7818. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7819. Update_V2G_Flow_Status(Other_Fault);
  7820. errn = -1;
  7821. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7822. //CCS_SECC_CP_State_Error (023889)
  7823. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7824. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7825. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7826. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  7827. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  7828. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  7829. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  7830. sprintf((char*)buf_log_evcomm,
  7831. "[CableCheck]Emergency Stop by CP Error (%d, %.02f V, %d)\n",
  7832. sys->CpState,
  7833. sys->CpVoltage,
  7834. cab->cnt
  7835. );
  7836. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7837. //cab->cnt = 0;
  7838. }
  7839. }
  7840. #endif
  7841. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7842. #if PARAMETER_NORMAL_MODE == ENABLE
  7843. SHM_Read_iso1_CableCheckRes(&ccs_exi_doc_ISO1, ShmCcsData);
  7844. #else
  7845. Sudo_Parameter_iso1_CableCheckRes();
  7846. #endif
  7847. //STEP 4: ============ Encode and Send Response Message ===========
  7848. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  7849. {
  7850. errn = -1;
  7851. }
  7852. //STEP 5: ============ Update Flags ===========
  7853. sys->ConnectorLocked = TRUE; //Inicating EVSE that the CCS Connector is Locked.
  7854. return errn;
  7855. }
  7856. /*===========================================================================
  7857. FUNCTION: Proc_din_CableCheckReq
  7858. DESCRIPTION:
  7859. PRE-CONDITION:
  7860. INPUT:
  7861. OUTPUT:
  7862. GLOBAL VARIABLES:
  7863. =============================================================================*/
  7864. int Proc_din_CableCheckReq(int AcceptFd)
  7865. {
  7866. int errn = 0;
  7867. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_CableCheckReq] Got CableCheckReq\n");
  7868. //Print the decoded XML Document
  7869. PRINT_XML_DOC_DIN_CableCheckReq(&ccs_exi_doc_DIN);
  7870. //Save into Share Memory
  7871. SHM_Save_din_CableCheckReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  7872. //Check for EV Error Code
  7873. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.CableCheckRequest.DC_EVStatus.EVErrorCode);
  7874. errn = Proc_din_CableCheckRes(AcceptFd);
  7875. if (errn == 0)
  7876. {
  7877. //send response successfully.
  7878. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][Tx]CableCheckRes");
  7879. }
  7880. else
  7881. {
  7882. sprintf((char*)buf_log_evcomm,
  7883. "[Error][SeccComm][Proc_din_CableCheckReq]Proc_iso1_CableCheckRes(): %d (DEC)",
  7884. errn);
  7885. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7886. }
  7887. return errn;
  7888. }
  7889. /*===========================================================================
  7890. FUNCTION: Proc_iso1_CableCheckReq
  7891. DESCRIPTION:
  7892. PRE-CONDITION:
  7893. INPUT:
  7894. OUTPUT:
  7895. GLOBAL VARIABLES:
  7896. =============================================================================*/
  7897. int Proc_iso1_CableCheckReq(int AcceptFd)
  7898. {
  7899. int errn = 0;
  7900. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_CableCheckReq] Got CableCheckReq");
  7901. //Print the decoded XML Document
  7902. PRINT_XML_DOC_ISO1_CableCheckReq(&ccs_exi_doc_ISO1);
  7903. //Save into Share Memory
  7904. SHM_Save_iso1_CableCheckReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  7905. //Check for EV Error Code
  7906. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.CableCheckRequest.DC_EVStatus.EVErrorCode);
  7907. errn = Proc_iso1_CableCheckRes(AcceptFd);
  7908. if (errn == 0)
  7909. {
  7910. //send response successfully.
  7911. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]CableCheckRes");
  7912. }
  7913. else
  7914. {
  7915. sprintf((char*)buf_log_evcomm,
  7916. "[Error][SeccComm][Proc_iso1_CableCheckReq]Proc_iso1_CableCheckRes(): %d (DEC)",
  7917. errn);
  7918. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7919. }
  7920. return errn;
  7921. }
  7922. /*===========================================================================
  7923. FUNCTION: SHM_Init_din_PreChargeRes
  7924. DESCRIPTION:
  7925. PRE-CONDITION:
  7926. INPUT:
  7927. 1. shm_ccs
  7928. OUTPUT:
  7929. 1. shm_ccs
  7930. GLOBAL VARIABLES:
  7931. =============================================================================*/
  7932. void SHM_Init_din_PreChargeRes(struct CcsData *shm_ccs)
  7933. {
  7934. struct PreChargeResponse_DIN70121 *in;
  7935. in = &shm_ccs->V2GMessage_DIN70121.PreChargeResponse;
  7936. //----- [BODY (1/3)] ResponseCode -----
  7937. in->ResponseCode = dinresponseCodeType_OK;
  7938. //----- [BODY (2/3)] EVSEPresentVoltage -----
  7939. short value = 0; int multiplier = 0; unsigned char unit = 0;
  7940. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for Test
  7941. value = 0; multiplier = 0; unit = V_DIN70121; //waiting for CsuComm to update V to fit EV Target
  7942. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  7943. //----- [BODY (3/3)] DC_EVSEStatus -----
  7944. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  7945. }
  7946. /*===========================================================================
  7947. FUNCTION: Sudo_Parameter_din_PreChargeRes
  7948. DESCRIPTION:
  7949. PRE-CONDITION:
  7950. INPUT:
  7951. OUTPUT:
  7952. GLOBAL VARIABLES:
  7953. =============================================================================*/
  7954. void Sudo_Parameter_din_PreChargeRes()
  7955. {
  7956. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  7957. init_dinPreChargeResType(&ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes);
  7958. ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes_isUsed = 1u;
  7959. //----- [BODY (1/3)] ResponseCode -----
  7960. struct dinPreChargeResType *res;
  7961. res = &ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes;
  7962. res->ResponseCode = dinresponseCodeType_OK;
  7963. //----- [BODY (2/3)] EVSEPresentVoltage -----
  7964. res->EVSEPresentVoltage.Value = 3820;
  7965. res->EVSEPresentVoltage.Multiplier = -1;
  7966. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  7967. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  7968. // dinunitSymbolType_h = 0,
  7969. // dinunitSymbolType_m = 1,
  7970. // dinunitSymbolType_s = 2,
  7971. // dinunitSymbolType_A = 3,
  7972. // dinunitSymbolType_Ah = 4,
  7973. // dinunitSymbolType_V = 5,
  7974. // dinunitSymbolType_VA = 6,
  7975. // dinunitSymbolType_W = 7,
  7976. // dinunitSymbolType_W_s = 8,
  7977. // dinunitSymbolType_Wh = 9
  7978. //----- [BODY (3/3)] DC_EVSEStatus -----
  7979. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7980. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7981. // dinisolationLevelType_Invalid = 0,
  7982. // dinisolationLevelType_Valid = 1,
  7983. // dinisolationLevelType_Warning = 2,
  7984. // dinisolationLevelType_Fault = 3
  7985. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7986. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7987. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  7988. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7989. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7990. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7991. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7992. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7993. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  7994. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  7995. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  7996. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  7997. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  7998. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7999. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  8000. // dinEVSENotificationType_None = 0,
  8001. // dinEVSENotificationType_StopCharging = 1,
  8002. // dinEVSENotificationType_ReNegotiation = 2
  8003. }
  8004. /*===========================================================================
  8005. FUNCTION: Sudo_Parameter_iso1_PreChargeRes
  8006. DESCRIPTION:
  8007. PRE-CONDITION:
  8008. INPUT:
  8009. OUTPUT:
  8010. GLOBAL VARIABLES:
  8011. =============================================================================*/
  8012. void Sudo_Parameter_iso1_PreChargeRes()
  8013. {
  8014. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8015. init_iso1PreChargeResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes);
  8016. ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes_isUsed = 1u;
  8017. //----- [BODY (1/3)] ResponseCode -----
  8018. struct iso1PreChargeResType *res;
  8019. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes;
  8020. res->ResponseCode = iso1responseCodeType_OK;
  8021. //----- [BODY (2/3)] EVSEPresentVoltage -----
  8022. res->EVSEPresentVoltage.Value = 3820;
  8023. res->EVSEPresentVoltage.Multiplier = -1;
  8024. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  8025. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  8026. //iso1unitSymbolType_h = 0,
  8027. //iso1unitSymbolType_m = 1,
  8028. //iso1unitSymbolType_s = 2,
  8029. //iso1unitSymbolType_A = 3,
  8030. //iso1unitSymbolType_V = 4,
  8031. //iso1unitSymbolType_W = 5,
  8032. //iso1unitSymbolType_Wh = 6
  8033. //----- [BODY (3/3)] DC_EVSEStatus -----
  8034. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8035. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  8036. //iso1isolationLevelType_Invalid = 0,
  8037. //iso1isolationLevelType_Valid = 1,
  8038. //iso1isolationLevelType_Warning = 2,
  8039. //iso1isolationLevelType_Fault = 3,
  8040. //iso1isolationLevelType_No_IMD = 4
  8041. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8042. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8043. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8044. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8045. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8046. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8047. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8048. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8049. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8050. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8051. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8052. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8053. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8054. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8055. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8056. //iso1EVSENotificationType_None = 0,
  8057. //iso1EVSENotificationType_StopCharging = 1,
  8058. //iso1EVSENotificationType_ReNegotiation = 2
  8059. }
  8060. /*===========================================================================
  8061. FUNCTION: Proc_din_PreChargeRes
  8062. DESCRIPTION:
  8063. PRE-CONDITION:
  8064. INPUT:
  8065. OUTPUT:
  8066. GLOBAL VARIABLES:
  8067. =============================================================================*/
  8068. int Proc_din_PreChargeRes(int AcceptFd)
  8069. {
  8070. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8071. //if it is not the same, the packet should be ignored.
  8072. //STEP 1: ============ Initialize ============
  8073. //int i = 0;
  8074. int errn = 0;
  8075. bitstream_t v2g_tx_stream;
  8076. static struct PreChargeResponse_DIN70121 *pre;
  8077. static struct ChargingInfoData *sys;
  8078. size_t pos = 0;
  8079. v2g_tx_stream.pos = &pos;
  8080. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8081. v2g_tx_stream.data = V2GTP_Tx_buf;
  8082. pre = &ShmCcsData->V2GMessage_DIN70121.PreChargeResponse;
  8083. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8084. pre->ResponseCode = OK_DIN70121;
  8085. //EVSE Status Code
  8086. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8087. //[HEADER] Check Req SessionID
  8088. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  8089. {
  8090. pre->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  8091. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8092. errn = -1;
  8093. }
  8094. //Check for SequenceError
  8095. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8096. {
  8097. pre->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  8098. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  8099. errn = -1;
  8100. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8101. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8102. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8103. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8104. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8105. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8106. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8107. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8108. }
  8109. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8110. SAVE_PhysicalValueType_DIN70121(&pre->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  8111. //Isolation Status
  8112. if (sys->IsolationStatus == GFD_Invalid) //0: invalid
  8113. {
  8114. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  8115. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8116. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8117. Update_V2G_Flow_Status(Other_Fault);
  8118. errn = -1;
  8119. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_PreChargeRes]IsolationStatus = %d", sys->IsolationStatus);
  8120. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8121. }
  8122. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  8123. {
  8124. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  8125. }
  8126. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  8127. {
  8128. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  8129. }
  8130. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  8131. {
  8132. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_PreChargeRes]GFD_Fault => Emergency Shutdown");
  8133. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  8134. pre->ResponseCode = FAILED_DIN70121;
  8135. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8136. errn = -1;
  8137. }
  8138. else //GFD_No_IMD or other unexpected status
  8139. {
  8140. pre->ResponseCode = FAILED_DIN70121;
  8141. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  8142. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8143. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8144. Update_V2G_Flow_Status(Other_Fault);
  8145. errn = -1;
  8146. sprintf((char*)buf_log_evcomm,
  8147. "[Error][Proc_din_PreChargeRes]IsolationStatus = %d (undefined)",
  8148. sys->IsolationStatus);
  8149. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8150. }
  8151. //Check for CSU command of "Stop by EVSE"
  8152. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8153. {
  8154. //Check for Alarm Code: CCS GFD trip (012235)
  8155. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8156. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8157. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8158. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8159. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8160. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8161. {
  8162. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_PreChargeRes]CCS GFD trip => EVSE_Shutdown");
  8163. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8164. }
  8165. else
  8166. {
  8167. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_PreChargeRes]EVSE_Shutdown");
  8168. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8169. }
  8170. pre->ResponseCode = FAILED_DIN70121;
  8171. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8172. errn = -1;
  8173. }
  8174. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8175. {
  8176. //Check for Alarm Code: CCS GFD trip (012235)
  8177. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8178. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8179. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8180. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8181. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8182. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8183. {
  8184. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_PreChargeRes]CCS GFD trip => EVSE_EmergencyShutdown");
  8185. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8186. }
  8187. else
  8188. {
  8189. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_PreChargeRes]EVSE_EmergencyShutdown");
  8190. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8191. }
  8192. pre->ResponseCode = FAILED_DIN70121;
  8193. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8194. errn = -1;
  8195. }
  8196. else if (ShmInternalComm->ChargingPermission == FALSE)
  8197. {
  8198. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_PreChargeRes]ChargingPermission = FALSE");
  8199. pre->ResponseCode = FAILED_DIN70121;
  8200. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8201. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8202. errn = -1;
  8203. }
  8204. else
  8205. {
  8206. //null
  8207. }
  8208. //Response to CP Error
  8209. #if CP_PROTECTION_MECHANISM == ENABLE
  8210. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  8211. {
  8212. pre->ResponseCode = FAILED_DIN70121;
  8213. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8214. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8215. Update_V2G_Flow_Status(Other_Fault);
  8216. errn = -1;
  8217. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8218. //CCS_SECC_CP_State_Error (023889)
  8219. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8220. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8221. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8222. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  8223. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  8224. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  8225. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  8226. sprintf((char*)buf_log_evcomm,
  8227. "[Error][Proc_din_PreChargeRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  8228. sys->CpState,
  8229. sys->CpVoltage
  8230. );
  8231. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8232. }
  8233. #endif
  8234. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8235. #if PARAMETER_NORMAL_MODE == ENABLE
  8236. SHM_Read_din_PreChargeRes(&ccs_exi_doc_DIN, ShmCcsData);
  8237. #else
  8238. Sudo_Parameter_din_PreChargeRes();
  8239. #endif
  8240. //STEP 4: ============ Encode and Send Response Message ===========
  8241. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  8242. {
  8243. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][send_encoded_din_V2GTP_Stream]:Tx encoded msg error");
  8244. errn = -1;
  8245. }
  8246. //STEP 5: ============ Update Flags ===========
  8247. return errn;
  8248. }
  8249. /*===========================================================================
  8250. FUNCTION: Proc_iso1_PreChargeRes
  8251. DESCRIPTION:
  8252. PRE-CONDITION:
  8253. INPUT:
  8254. OUTPUT:
  8255. GLOBAL VARIABLES:
  8256. =============================================================================*/
  8257. int Proc_iso1_PreChargeRes(int AcceptFd)
  8258. {
  8259. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8260. //if it is not the same, the packet should be ignored.
  8261. //STEP 1: ============ Initialize ============
  8262. //int i = 0;
  8263. int errn = 0;
  8264. bitstream_t v2g_tx_stream;
  8265. static struct PreChargeResponse_ISO15118_2014 *pre;
  8266. static struct ChargingInfoData *sys;
  8267. size_t pos = 0;
  8268. v2g_tx_stream.pos = &pos;
  8269. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8270. v2g_tx_stream.data = V2GTP_Tx_buf;
  8271. pre = &ShmCcsData->V2GMessage_ISO15118_2014.PreChargeResponse;
  8272. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8273. pre->ResponseCode = OK_ISO15118_2014;
  8274. //EVSE Status Code
  8275. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8276. //[HEADER] Check Req SessionID
  8277. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  8278. {
  8279. pre->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  8280. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8281. errn = -1;
  8282. }
  8283. //Check for SequenceError
  8284. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8285. {
  8286. pre->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  8287. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  8288. errn = -1;
  8289. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8290. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8291. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8292. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8293. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8294. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8295. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8296. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8297. }
  8298. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8299. SAVE_PhysicalValueType_ISO15118_2014(&pre->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  8300. //Isolation Status
  8301. if (sys->IsolationStatus == GFD_Invalid) //0: invalid(on going)
  8302. {
  8303. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  8304. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8305. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8306. Update_V2G_Flow_Status(Other_Fault);
  8307. errn = -1;
  8308. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_PreChargeRes]IsolationStatus = %d", sys->IsolationStatus);
  8309. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8310. }
  8311. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  8312. {
  8313. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  8314. }
  8315. else if (sys->IsolationStatus == GFD_Warning) //2: waring
  8316. {
  8317. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning; //1
  8318. }
  8319. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  8320. {
  8321. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_PreChargeRes]GFD_Fault => Emergency Shutdown");
  8322. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  8323. pre->ResponseCode = FAILED_ISO15118_2014;
  8324. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8325. errn = -1;
  8326. }
  8327. else
  8328. {
  8329. pre->ResponseCode = FAILED_ISO15118_2014;
  8330. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  8331. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8332. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8333. Update_V2G_Flow_Status(Other_Fault);
  8334. errn = -1;
  8335. sprintf((char*)buf_log_evcomm,
  8336. "[Error][Proc_iso1_PreChargeRes]IsolationStatus = %d (undefined)",
  8337. sys->IsolationStatus);
  8338. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8339. }
  8340. //Check for CSU command of "Stop by EVSE"
  8341. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8342. {
  8343. //Check for Alarm Code: CCS GFD trip (012235)
  8344. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8345. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8346. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8347. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8348. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8349. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8350. {
  8351. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_PreChargeRes]CCS GFD trip => EVSE_Shutdown");
  8352. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8353. }
  8354. else
  8355. {
  8356. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_PreChargeRes]EVSE_Shutdown");
  8357. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8358. }
  8359. pre->ResponseCode = FAILED_ISO15118_2014;
  8360. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8361. errn = -1;
  8362. }
  8363. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8364. {
  8365. //Check for Alarm Code: CCS GFD trip (012235)
  8366. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8367. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8368. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8369. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8370. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8371. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8372. {
  8373. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_PreChargeRes]CCS GFD trip => EVSE_EmergencyShutdown");
  8374. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8375. }
  8376. else
  8377. {
  8378. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_PreChargeRes]EVSE_EmergencyShutdown");
  8379. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8380. }
  8381. pre->ResponseCode = FAILED_ISO15118_2014;
  8382. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8383. errn = -1;
  8384. }
  8385. else if (ShmInternalComm->ChargingPermission == FALSE)
  8386. {
  8387. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_PreChargeRes]ChargingPermission = FALSE");
  8388. pre->ResponseCode = FAILED_ISO15118_2014;
  8389. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8390. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8391. errn = -1;
  8392. }
  8393. else
  8394. {
  8395. //null
  8396. }
  8397. //Response to CP Error
  8398. #if CP_PROTECTION_MECHANISM == ENABLE
  8399. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  8400. {
  8401. pre->ResponseCode = FAILED_ISO15118_2014;
  8402. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8403. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8404. Update_V2G_Flow_Status(Other_Fault);
  8405. errn = -1;
  8406. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8407. //CCS_SECC_CP_State_Error (023889)
  8408. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8409. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8410. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8411. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  8412. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  8413. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  8414. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  8415. sprintf((char*)buf_log_evcomm,
  8416. "[Error][Proc_iso1_PreChargeRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  8417. sys->CpState,
  8418. sys->CpVoltage
  8419. );
  8420. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8421. }
  8422. #endif
  8423. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8424. #if PARAMETER_NORMAL_MODE == ENABLE
  8425. SHM_Read_iso1_PreChargeRes(&ccs_exi_doc_ISO1, ShmCcsData);
  8426. #else
  8427. Sudo_Parameter_iso1_PreChargeRes();
  8428. #endif
  8429. //STEP 4: ============ Encode and Send Response Message ===========
  8430. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  8431. {
  8432. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][send_encoded_iso1_V2GTP_Stream]:Tx encoded msg error");
  8433. errn = -1;
  8434. }
  8435. //STEP 5: ============ Update Flags ===========
  8436. return errn;
  8437. }
  8438. /*===========================================================================
  8439. FUNCTION: Proc_din_PreChargeReq
  8440. DESCRIPTION:
  8441. PRE-CONDITION:
  8442. INPUT:
  8443. OUTPUT:
  8444. GLOBAL VARIABLES:
  8445. =============================================================================*/
  8446. int Proc_din_PreChargeReq(int AcceptFd)
  8447. {
  8448. int errn = 0;
  8449. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_PreChargeReq] Got PreChargeReq");
  8450. //Print the decoded XML Document
  8451. PRINT_XML_DOC_DIN_PreChargeReq(&ccs_exi_doc_DIN);
  8452. //Save into Share Memory
  8453. SHM_Save_din_PreChargeReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  8454. //Check for EV Error Code
  8455. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PreChargeRequest.DC_EVStatus.EVErrorCode);
  8456. errn = Proc_din_PreChargeRes(AcceptFd);
  8457. if (errn == 0)
  8458. {
  8459. //send response successfully.
  8460. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][Tx]PreChargeRes");
  8461. }
  8462. else
  8463. {
  8464. sprintf((char*)buf_log_evcomm,
  8465. "[Error][SeccComm][Proc_din_PreChargeReq]Proc_iso1_PreChargeRes(): %d (DEC)",
  8466. errn);
  8467. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8468. }
  8469. return errn;
  8470. }
  8471. /*===========================================================================
  8472. FUNCTION: Proc_iso1_PreChargeReq
  8473. DESCRIPTION:
  8474. PRE-CONDITION:
  8475. INPUT:
  8476. OUTPUT:
  8477. GLOBAL VARIABLES:
  8478. =============================================================================*/
  8479. int Proc_iso1_PreChargeReq(int AcceptFd)
  8480. {
  8481. int errn = 0;
  8482. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_PreChargeReq] Got PreChargeReq");
  8483. //Print the decoded XML Document
  8484. PRINT_XML_DOC_ISO1_PreChargeReq(&ccs_exi_doc_ISO1);
  8485. //Save into Share Memory
  8486. SHM_Save_iso1_PreChargeReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  8487. //Check for EV Error Code
  8488. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PreChargeRequest.DC_EVStatus.EVErrorCode);
  8489. errn = Proc_iso1_PreChargeRes(AcceptFd);
  8490. if (errn == 0)
  8491. {
  8492. //send response successfully.
  8493. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]PreChargeRes");
  8494. }
  8495. else
  8496. {
  8497. sprintf((char*)buf_log_evcomm,
  8498. "[Error][SeccComm][Proc_iso1_PreChargeReq]Proc_iso1_PreChargeRes(): %d (DEC)",
  8499. errn);
  8500. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8501. }
  8502. return errn;
  8503. }
  8504. /*===========================================================================
  8505. FUNCTION: SHM_Init_din_PowerDeliveryRes
  8506. DESCRIPTION:
  8507. PRE-CONDITION:
  8508. INPUT:
  8509. 1. shm_ccs
  8510. OUTPUT:
  8511. 1. shm_ccs
  8512. GLOBAL VARIABLES:
  8513. =============================================================================*/
  8514. void SHM_Init_din_PowerDeliveryRes(struct CcsData *shm_ccs)
  8515. {
  8516. struct PowerDeliveryResponse_DIN70121 *in;
  8517. in = &shm_ccs->V2GMessage_DIN70121.PowerDeliveryResponse;
  8518. //----- [BODY (1/3)] ResponseCode -----
  8519. in->ResponseCode = dinresponseCodeType_OK;
  8520. //----- [BODY (2/3)] AC_EVSEStatus -----
  8521. //ignore, since DIN 70121 doesn't support AC, yet.
  8522. //----- [BODY (2/3)] DC_EVSEStatus -----
  8523. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  8524. }
  8525. /*===========================================================================
  8526. FUNCTION: Sudo_Parameter_din_PowerDeliveryRes
  8527. DESCRIPTION:
  8528. PRE-CONDITION:
  8529. INPUT:
  8530. OUTPUT:
  8531. GLOBAL VARIABLES:
  8532. =============================================================================*/
  8533. void Sudo_Parameter_din_PowerDeliveryRes()
  8534. {
  8535. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  8536. init_dinPowerDeliveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes);
  8537. ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  8538. //----- [BODY (1/3)] ResponseCode -----
  8539. struct dinPowerDeliveryResType *res;
  8540. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  8541. res->ResponseCode = dinresponseCodeType_OK;
  8542. //----- [BODY (2/3)] AC_EVSEStatus -----
  8543. //ignore, since DIN 70121 doesn't support AC, yet.
  8544. //----- [BODY (2/3)] DC_EVSEStatus -----
  8545. res->DC_EVSEStatus_isUsed = 1u;
  8546. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8547. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  8548. // dinisolationLevelType_Invalid = 0,
  8549. // dinisolationLevelType_Valid = 1,
  8550. // dinisolationLevelType_Warning = 2,
  8551. // dinisolationLevelType_Fault = 3
  8552. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8553. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8554. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  8555. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8556. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8557. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8558. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8559. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8560. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  8561. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  8562. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  8563. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  8564. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  8565. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8566. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  8567. // dinEVSENotificationType_None = 0,
  8568. // dinEVSENotificationType_StopCharging = 1,
  8569. // dinEVSENotificationType_ReNegotiation = 2
  8570. }
  8571. /*===========================================================================
  8572. FUNCTION: Sudo_Parameter_iso1_PowerDeliveryRes
  8573. DESCRIPTION:
  8574. PRE-CONDITION:
  8575. INPUT:
  8576. OUTPUT:
  8577. GLOBAL VARIABLES:
  8578. =============================================================================*/
  8579. void Sudo_Parameter_iso1_PowerDeliveryRes()
  8580. {
  8581. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8582. init_iso1PowerDeliveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes);
  8583. ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  8584. //----- [BODY (1/3)] ResponseCode -----
  8585. struct iso1PowerDeliveryResType *res;
  8586. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  8587. res->ResponseCode = iso1responseCodeType_OK;
  8588. //----- [BODY (2/3)] AC_EVSEStatus -----
  8589. //ignore, since our ISO1 70121 doesn't support AC, yet.
  8590. //----- [BODY (2/3)] DC_EVSEStatus -----
  8591. res->DC_EVSEStatus_isUsed = 1u;
  8592. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8593. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  8594. //iso1isolationLevelType_Invalid = 0,
  8595. //iso1isolationLevelType_Valid = 1,
  8596. //iso1isolationLevelType_Warning = 2,
  8597. //iso1isolationLevelType_Fault = 3,
  8598. //iso1isolationLevelType_No_IMD = 4
  8599. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8600. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8601. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8602. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8603. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8604. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8605. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8606. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8607. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8608. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8609. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8610. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8611. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8612. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8613. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8614. //iso1EVSENotificationType_None = 0,
  8615. //iso1EVSENotificationType_StopCharging = 1,
  8616. //iso1EVSENotificationType_ReNegotiation = 2
  8617. }
  8618. /*===========================================================================
  8619. FUNCTION: Proc_din_PowerDeliveryStartRes
  8620. DESCRIPTION:
  8621. PRE-CONDITION:
  8622. INPUT:
  8623. OUTPUT:
  8624. GLOBAL VARIABLES:
  8625. =============================================================================*/
  8626. int Proc_din_PowerDeliveryStartRes(int AcceptFd)
  8627. {
  8628. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8629. //if it is not the same, the packet should be ignored.
  8630. //STEP 1: ============ Initialize ============
  8631. //int i = 0;
  8632. int errn = 0;
  8633. bitstream_t v2g_tx_stream;
  8634. struct dinPowerDeliveryResType *res;
  8635. struct ChargingInfoData *sys;
  8636. size_t pos = 0;
  8637. v2g_tx_stream.pos = &pos;
  8638. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8639. v2g_tx_stream.data = V2GTP_Tx_buf;
  8640. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  8641. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8642. res->ResponseCode = OK_DIN70121;
  8643. //[HEADER] Check Req SessionID
  8644. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  8645. {
  8646. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  8647. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8648. errn = -1;
  8649. }
  8650. //Check for SequenceError
  8651. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8652. {
  8653. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  8654. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  8655. errn = -1;
  8656. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8657. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8658. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8659. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8660. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8661. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8662. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8663. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8664. }
  8665. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8666. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8667. #if PARAMETER_NORMAL_MODE == ENABLE
  8668. SHM_Read_din_PowerDeliveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  8669. #else
  8670. Sudo_Parameter_din_PowerDeliveryRes();
  8671. #endif
  8672. //EVSE Status Code
  8673. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  8674. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8675. //Check for CSU command of "Stop by EVSE"
  8676. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8677. {
  8678. //res->ResponseCode = FAILED_DIN70121;
  8679. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8680. }
  8681. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8682. {
  8683. //res->ResponseCode = FAILED_DIN70121;
  8684. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8685. }
  8686. else if (ShmInternalComm->ChargingPermission == FALSE)
  8687. {
  8688. //res->ResponseCode = FAILED_DIN70121;
  8689. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8690. }
  8691. //STEP 4: ============ Encode and Send Response Message ===========
  8692. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  8693. {
  8694. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_PowerDeliveryStartRes][Error]Tx encoded msg error");
  8695. errn = -1;
  8696. }
  8697. //STEP 5: ============ Update Flags ===========
  8698. return errn;
  8699. }
  8700. /*===========================================================================
  8701. FUNCTION: Proc_iso1_PowerDeliveryStartRes
  8702. DESCRIPTION:
  8703. PRE-CONDITION:
  8704. INPUT:
  8705. OUTPUT:
  8706. GLOBAL VARIABLES:
  8707. =============================================================================*/
  8708. int Proc_iso1_PowerDeliveryStartRes(int AcceptFd)
  8709. {
  8710. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8711. //if it is not the same, the packet should be ignored.
  8712. //STEP 1: ============ Initialize ============
  8713. //int i = 0;
  8714. int errn = 0;
  8715. bitstream_t v2g_tx_stream;
  8716. struct iso1PowerDeliveryResType *res;
  8717. struct ChargingInfoData *sys;
  8718. size_t pos = 0;
  8719. v2g_tx_stream.pos = &pos;
  8720. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8721. v2g_tx_stream.data = V2GTP_Tx_buf;
  8722. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  8723. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8724. res->ResponseCode = OK_ISO15118_2014;
  8725. //[HEADER] Check Req SessionID
  8726. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  8727. {
  8728. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  8729. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8730. errn = -1;
  8731. }
  8732. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8733. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8734. #if PARAMETER_NORMAL_MODE == ENABLE
  8735. SHM_Read_iso1_PowerDeliveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  8736. #else
  8737. Sudo_Parameter_iso1_PowerDeliveryRes();
  8738. #endif
  8739. //EVSE Status Code
  8740. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  8741. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8742. //Check for CSU command of "Stop by EVSE"
  8743. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8744. {
  8745. //res->ResponseCode = FAILED_ISO15118_2014;
  8746. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8747. }
  8748. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8749. {
  8750. //res->ResponseCode = FAILED_ISO15118_2014;
  8751. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8752. }
  8753. else if (ShmInternalComm->ChargingPermission == FALSE)
  8754. {
  8755. //res->ResponseCode = FAILED_ISO15118_2014;
  8756. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8757. }
  8758. //STEP 4: ============ Encode and Send Response Message ===========
  8759. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  8760. {
  8761. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_PowerDeliveryStartRes][Error]Tx encoded msg error");
  8762. errn = -1;
  8763. }
  8764. //STEP 5: ============ Update Flags ===========
  8765. return errn;
  8766. }
  8767. /*===========================================================================
  8768. FUNCTION: Proc_din_PowerDeliveryStartReq
  8769. DESCRIPTION:
  8770. PRE-CONDITION:
  8771. INPUT:
  8772. OUTPUT:
  8773. GLOBAL VARIABLES:
  8774. =============================================================================*/
  8775. int Proc_din_PowerDeliveryStartReq(int AcceptFd)
  8776. {
  8777. int errn = 0;
  8778. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]PowerDeliveryStartReq");
  8779. //Print the decoded XML Document
  8780. PRINT_XML_DOC_DIN_PowerDeliveryReq(&ccs_exi_doc_DIN);
  8781. //Save into Share Memory
  8782. SHM_Save_din_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  8783. //Check for EV Error Code
  8784. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  8785. errn = Proc_din_PowerDeliveryStartRes(AcceptFd);
  8786. if (errn == 0)
  8787. {
  8788. //send response successfully.
  8789. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][Tx]PowerDeliveryStartRes");
  8790. }
  8791. else
  8792. {
  8793. sprintf((char*)buf_log_evcomm,
  8794. "[Error][Proc_din_PowerDeliveryStartReq]Proc_iso1_PowerDeliveryStartRes(): %d (DEC)",
  8795. errn);
  8796. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8797. }
  8798. return errn;
  8799. }
  8800. /*===========================================================================
  8801. FUNCTION: Proc_iso1_PowerDeliveryStartReq
  8802. DESCRIPTION:
  8803. PRE-CONDITION:
  8804. INPUT:
  8805. OUTPUT:
  8806. GLOBAL VARIABLES:
  8807. =============================================================================*/
  8808. int Proc_iso1_PowerDeliveryStartReq(int AcceptFd)
  8809. {
  8810. int errn = 0;
  8811. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]PowerDeliveryStartReq");
  8812. //Print the decoded XML Document
  8813. PRINT_XML_DOC_ISO1_PowerDeliveryReq(&ccs_exi_doc_ISO1);
  8814. //Save into Share Memory
  8815. SHM_Save_iso1_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  8816. //Check for EV Error Code
  8817. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  8818. errn = Proc_iso1_PowerDeliveryStartRes(AcceptFd);
  8819. if (errn == 0)
  8820. {
  8821. //send response successfully.
  8822. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]PowerDeliveryStartRes");
  8823. }
  8824. else
  8825. {
  8826. sprintf((char*)buf_log_evcomm,
  8827. "[Error][Proc_iso1_PowerDeliveryStartReq]Proc_iso1_PowerDeliveryStartRes(): %d (DEC)",
  8828. errn);
  8829. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8830. }
  8831. return errn;
  8832. }
  8833. /*===========================================================================
  8834. FUNCTION: SHM_Init_din_CurrentDemandRes
  8835. DESCRIPTION:
  8836. PRE-CONDITION:
  8837. INPUT:
  8838. 1. shm_ccs
  8839. OUTPUT:
  8840. 1. shm_ccs
  8841. GLOBAL VARIABLES:
  8842. =============================================================================*/
  8843. void SHM_Init_din_CurrentDemandRes(struct CcsData *shm_ccs)
  8844. {
  8845. struct CurrentDemandResponse_DIN70121 *in;
  8846. in = &shm_ccs->V2GMessage_DIN70121.CurrentDemandResponse;
  8847. //----- [BODY (1/10)] ResponseCode -----
  8848. in->ResponseCode = dinresponseCodeType_OK;
  8849. //----- [BODY (2/10)] DC_EVSEStatus -----
  8850. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  8851. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8852. short value = 0; int multiplier = 0; unsigned char unit = 0;
  8853. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for test only.
  8854. value = 0; multiplier = 0; unit = V_DIN70121;
  8855. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  8856. //----- [BODY (4/10)] EVSEPresentCurrent -----
  8857. //value = 600; multiplier = -1; unit = A_DIN70121; //60A, for test only.
  8858. value = 0; multiplier = 0; unit = A_DIN70121;
  8859. SHM_Save_dinPhysicalValueType(&in->EVSEPresentCurrent, value, multiplier, unit);
  8860. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  8861. in->EVSECurrentLimitAchieved = FALSE;
  8862. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  8863. in->EVSEVoltageLimitAchieved = FALSE;
  8864. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  8865. in->EVSEPowerLimitAchieved = FALSE;
  8866. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  8867. //value = 7500; multiplier = -1; unit = V_DIN70121; //750V
  8868. value = 5000; multiplier = -1; unit = V_DIN70121; //500V
  8869. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumVoltageLimit, value, multiplier, unit);
  8870. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  8871. value = 600; multiplier = -1; unit = A_DIN70121; //60A
  8872. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumCurrentLimit, value, multiplier, unit);
  8873. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  8874. value = 3000; multiplier = 1; unit = W_DIN70121; //30KW
  8875. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumPowerLimit, value, multiplier, unit);
  8876. }
  8877. /*===========================================================================
  8878. FUNCTION: Sudo_Parameter_din_CurrentDemandRes
  8879. DESCRIPTION:
  8880. PRE-CONDITION:
  8881. INPUT:
  8882. OUTPUT:
  8883. GLOBAL VARIABLES:
  8884. =============================================================================*/
  8885. void Sudo_Parameter_din_CurrentDemandRes()
  8886. {
  8887. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  8888. init_dinCurrentDemandResType(&ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes);
  8889. ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes_isUsed = 1u;
  8890. //----- [BODY (1/10)] ResponseCode -----
  8891. struct dinCurrentDemandResType *res;
  8892. res = &ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes;
  8893. res->ResponseCode = dinresponseCodeType_OK;
  8894. //----- [BODY (2/10)] DC_EVSEStatus -----
  8895. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8896. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  8897. // dinisolationLevelType_Invalid = 0,
  8898. // dinisolationLevelType_Valid = 1,
  8899. // dinisolationLevelType_Warning = 2,
  8900. // dinisolationLevelType_Fault = 3
  8901. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8902. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8903. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  8904. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8905. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8906. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8907. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8908. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8909. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  8910. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  8911. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  8912. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  8913. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  8914. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8915. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  8916. // dinEVSENotificationType_None = 0,
  8917. // dinEVSENotificationType_StopCharging = 1,
  8918. // dinEVSENotificationType_ReNegotiation = 2
  8919. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8920. res->EVSEPresentVoltage.Value = 3820;
  8921. res->EVSEPresentVoltage.Multiplier = -1;
  8922. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  8923. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  8924. //----- [BODY (4/10)] EVSEPresentCurrent -----
  8925. res->EVSEPresentCurrent.Value = 1200;
  8926. res->EVSEPresentCurrent.Multiplier = -1;
  8927. res->EVSEPresentCurrent.Unit_isUsed = 1u;
  8928. res->EVSEPresentCurrent.Unit = dinunitSymbolType_A;
  8929. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  8930. res->EVSECurrentLimitAchieved = 0;
  8931. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  8932. res->EVSEVoltageLimitAchieved = 0;
  8933. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  8934. res->EVSEPowerLimitAchieved = 0;
  8935. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  8936. res->EVSEMaximumVoltageLimit_isUsed = 1u;
  8937. res->EVSEMaximumVoltageLimit.Value = 7500;
  8938. res->EVSEMaximumVoltageLimit.Multiplier = -1;
  8939. res->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  8940. res->EVSEMaximumVoltageLimit.Unit = dinunitSymbolType_V;
  8941. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  8942. res->EVSEMaximumCurrentLimit_isUsed = 1u;
  8943. res->EVSEMaximumCurrentLimit.Value = 1200;
  8944. res->EVSEMaximumCurrentLimit.Multiplier = -1;
  8945. res->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  8946. res->EVSEMaximumCurrentLimit.Unit = dinunitSymbolType_A;
  8947. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  8948. res->EVSEMaximumPowerLimit_isUsed = 1u;
  8949. res->EVSEMaximumPowerLimit.Value = 6000;
  8950. res->EVSEMaximumPowerLimit.Multiplier = 1;
  8951. res->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  8952. res->EVSEMaximumPowerLimit.Unit = dinunitSymbolType_W;
  8953. }
  8954. /*===========================================================================
  8955. FUNCTION: Sudo_Parameter_iso1_CurrentDemandRes
  8956. DESCRIPTION:
  8957. PRE-CONDITION:
  8958. INPUT:
  8959. OUTPUT:
  8960. GLOBAL VARIABLES:
  8961. =============================================================================*/
  8962. void Sudo_Parameter_iso1_CurrentDemandRes()
  8963. {
  8964. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8965. init_iso1CurrentDemandResType(&ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes);
  8966. ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes_isUsed = 1u;
  8967. //----- [BODY (1/10)] ResponseCode -----
  8968. struct iso1CurrentDemandResType *res;
  8969. res = &ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes;
  8970. res->ResponseCode = iso1responseCodeType_OK;
  8971. //----- [BODY (2/10)] DC_EVSEStatus -----
  8972. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8973. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  8974. //iso1isolationLevelType_Invalid = 0,
  8975. //iso1isolationLevelType_Valid = 1,
  8976. //iso1isolationLevelType_Warning = 2,
  8977. //iso1isolationLevelType_Fault = 3,
  8978. //iso1isolationLevelType_No_IMD = 4
  8979. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8980. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8981. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8982. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8983. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8984. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8985. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8986. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8987. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8988. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8989. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8990. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8991. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8992. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8993. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8994. //iso1EVSENotificationType_None = 0,
  8995. //iso1EVSENotificationType_StopCharging = 1,
  8996. //iso1EVSENotificationType_ReNegotiation = 2
  8997. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8998. res->EVSEPresentVoltage.Value = 3820;
  8999. res->EVSEPresentVoltage.Multiplier = -1;
  9000. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  9001. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  9002. //----- [BODY (4/10)] EVSEPresentCurrent -----
  9003. res->EVSEPresentCurrent.Value = 1200;
  9004. res->EVSEPresentCurrent.Multiplier = -1;
  9005. //res->EVSEPresentCurrent.Unit_isUsed = 1u;
  9006. res->EVSEPresentCurrent.Unit = iso1unitSymbolType_A;
  9007. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  9008. res->EVSECurrentLimitAchieved = 0;
  9009. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  9010. res->EVSEVoltageLimitAchieved = 0;
  9011. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  9012. res->EVSEPowerLimitAchieved = 0;
  9013. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  9014. res->EVSEMaximumVoltageLimit_isUsed = 1u;
  9015. res->EVSEMaximumVoltageLimit.Value = 7500;
  9016. res->EVSEMaximumVoltageLimit.Multiplier = -1;
  9017. //res->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  9018. res->EVSEMaximumVoltageLimit.Unit = iso1unitSymbolType_V;
  9019. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  9020. res->EVSEMaximumCurrentLimit_isUsed = 1u;
  9021. res->EVSEMaximumCurrentLimit.Value = 1200;
  9022. res->EVSEMaximumCurrentLimit.Multiplier = -1;
  9023. //res->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  9024. res->EVSEMaximumCurrentLimit.Unit = iso1unitSymbolType_A;
  9025. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  9026. res->EVSEMaximumPowerLimit_isUsed = 1u;
  9027. res->EVSEMaximumPowerLimit.Value = 6000;
  9028. res->EVSEMaximumPowerLimit.Multiplier = 1;
  9029. //res->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  9030. res->EVSEMaximumPowerLimit.Unit = iso1unitSymbolType_W;
  9031. }
  9032. /*===========================================================================
  9033. FUNCTION: Sudo_Parameter_iso1_ChargingStatusRes
  9034. DESCRIPTION:
  9035. PRE-CONDITION:
  9036. INPUT:
  9037. OUTPUT:
  9038. GLOBAL VARIABLES:
  9039. =============================================================================*/
  9040. void Sudo_Parameter_iso1_ChargingStatusRes()
  9041. {
  9042. //int i = 0;
  9043. struct iso1ChargingStatusResType *res;
  9044. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  9045. init_iso1ChargingStatusResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes);
  9046. res = &ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes;
  9047. ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes_isUsed = 1u;
  9048. //----- [BODY (1/10)] ResponseCode -----
  9049. res->ResponseCode = OK_ISO15118_2014;
  9050. //----- [BODY (2/10)] AC_EVSEStatus -----
  9051. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  9052. res->AC_EVSEStatus.NotificationMaxDelay = 0;
  9053. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9054. // iso1EVSENotificationType_None = 0,
  9055. // iso1EVSENotificationType_StopCharging = 1,
  9056. // iso1EVSENotificationType_ReNegotiation = 2
  9057. //----- [BODY (3/10)] EVSEMaxCurrent -----
  9058. res->EVSEMaxCurrent_isUsed = 1u;
  9059. res->EVSEMaxCurrent.Value = 32;
  9060. res->EVSEMaxCurrent.Multiplier = 0;
  9061. res->EVSEMaxCurrent.Unit = iso1unitSymbolType_A;
  9062. //----- [BODY (4/10)] SAScheduleTupleID -----
  9063. res->SAScheduleTupleID = 0;
  9064. //----- [BODY (5/10)] EVSEID -----
  9065. res->EVSEID.charactersLen = 37;
  9066. memset(res->EVSEID.characters, 0, sizeof(res->EVSEID.characters));
  9067. //sprintf((char*)res->EVSEID.characters, CCS_AC_EVSEID);
  9068. //----- [BODY (6/10)] MeterInfo -----
  9069. res->MeterInfo_isUsed = 1u;
  9070. memset(res->MeterInfo.MeterID.characters, 0, sizeof(res->MeterInfo.MeterID.characters));
  9071. memset(res->MeterInfo.SigMeterReading.bytes, 0, sizeof(res->MeterInfo.SigMeterReading.bytes));
  9072. //[MeterInfo][1/5] MeterID
  9073. //sprintf((char*)res->MeterInfo.MeterID , CCS_AC_METER_ID);
  9074. //[MeterInfo][2/5] SigMeterReading (optional)
  9075. //sprintf((char*)res->MeterInfo.SigMeterReading , CCS_AC_SIG_METER_READING);
  9076. //[MeterInfo][3/5] MeterStatus (optional)
  9077. res->MeterInfo.MeterStatus = 0;
  9078. //[MeterInfo][4/5] MeterReading (optional)
  9079. res->MeterInfo.MeterReading = 12345;
  9080. //[MeterInfo][5/5] TMeter (optional)
  9081. res->MeterInfo.TMeter = 1586243587; //Unix Time Stamp format
  9082. //----- [BODY (7/10)] ReceiptRequired -----
  9083. res->ReceiptRequired_isUsed = 1u;
  9084. res->ReceiptRequired = FALSE; //optional
  9085. }
  9086. /*===========================================================================
  9087. FUNCTION: Check_EVErrorCode
  9088. DESCRIPTION:
  9089. PRE-CONDITION:
  9090. INPUT:
  9091. OUTPUT:
  9092. GLOBAL VARIABLES:
  9093. =============================================================================*/
  9094. void Check_EVErrorCode(int code)
  9095. {
  9096. if (code != NO_ERROR) //NO_ERROR = 0
  9097. {
  9098. //Asking CSU to Stop
  9099. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9100. //Update_V2G_Flow_Status(Other_Fault);
  9101. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  9102. sprintf((char*)buf_log_evcomm,
  9103. "Stop by EV (EVErrorCode = %d (DEC))",
  9104. code);
  9105. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9106. }
  9107. }
  9108. /*===========================================================================
  9109. FUNCTION: Proc_din_CurrentDemandRes
  9110. DESCRIPTION:
  9111. PRE-CONDITION:
  9112. INPUT:
  9113. OUTPUT:
  9114. GLOBAL VARIABLES:
  9115. =============================================================================*/
  9116. int Proc_din_CurrentDemandRes(int AcceptFd)
  9117. {
  9118. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9119. //if it is not the same, the packet should be ignored.
  9120. //STEP 1: ============ Initialize ============
  9121. int errn = 0;
  9122. bitstream_t v2g_tx_stream;
  9123. static struct CurrentDemandResponse_DIN70121 *cur;
  9124. static struct ChargingInfoData *sys;
  9125. // int i = 0;
  9126. // static int EVSE_max_current;
  9127. // int tmp = 0;
  9128. size_t pos = 0;
  9129. v2g_tx_stream.pos = &pos;
  9130. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9131. v2g_tx_stream.data = V2GTP_Tx_buf;
  9132. cur = &ShmCcsData->V2GMessage_DIN70121.CurrentDemandResponse;
  9133. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9134. cur->ResponseCode = OK_DIN70121;
  9135. //EVSE Status Code
  9136. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  9137. //[HEADER] Check Req SessionID
  9138. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  9139. {
  9140. cur->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  9141. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9142. errn = -1;
  9143. }
  9144. //Check for SequenceError
  9145. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9146. {
  9147. cur->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  9148. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9149. errn = -1;
  9150. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9151. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9152. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9153. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9154. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9155. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9156. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9157. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9158. }
  9159. //Check for negative EvBatteryMaxCurrent
  9160. if (sys->EvBatteryMaxCurrent < 0)
  9161. {
  9162. sprintf((char*)buf_log_evcomm,
  9163. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  9164. sys->EvBatteryMaxCurrent);
  9165. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9166. cur->DC_EVSEStatus.EVSEStatusCode = dinresponseCodeType_FAILED_WrongChargeParameter; //16
  9167. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9168. errn = -1;
  9169. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9170. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  9171. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9172. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9173. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9174. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9175. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  9176. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  9177. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9178. }
  9179. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9180. SAVE_PhysicalValueType_DIN70121(&cur->EVSEPresentCurrent, (int) (sys->PresentChargingCurrent * 10), A_DIN70121);
  9181. SAVE_PhysicalValueType_DIN70121(&cur->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  9182. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == DISABLE
  9183. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_DIN70121);
  9184. #endif
  9185. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_DIN70121);
  9186. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_DIN70121);
  9187. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  9188. if (sys->EvBatteryMaxVoltage <= 500)
  9189. {
  9190. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumVoltageLimit, (int) (500 * 10), V_DIN70121); //500V
  9191. }
  9192. #endif
  9193. //Limit the EVTargetCurrent should be under EVSEMaximumCurrentLimit
  9194. if (sys->EvBatterytargetCurrent > sys->AvailableChargingCurrent)
  9195. {
  9196. sys->EvBatterytargetCurrent = sys->AvailableChargingCurrent;
  9197. //[To-Do] Limit is achieved flag
  9198. }
  9199. //Isolation Status
  9200. if (sys->IsolationStatus == GFD_Invalid) //0:invalid (on going)
  9201. {
  9202. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  9203. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9204. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9205. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_CurrentDemandRes]IsolationStatus = %d", sys->IsolationStatus);
  9206. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9207. Update_V2G_Flow_Status(Other_Fault);
  9208. errn = -1;
  9209. }
  9210. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  9211. {
  9212. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  9213. }
  9214. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  9215. {
  9216. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  9217. }
  9218. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  9219. {
  9220. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  9221. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9222. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9223. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_CurrentDemandRes]GFD_Fault => Emergency Shutdown");
  9224. Update_V2G_Flow_Status(Other_Fault);
  9225. errn = -1;
  9226. }
  9227. else //GFD_No_IMD or other unexpected status
  9228. {
  9229. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  9230. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9231. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9232. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_CurrentDemandRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9233. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9234. Update_V2G_Flow_Status(Other_Fault);
  9235. errn = -1;
  9236. }
  9237. //For testing with Tesla Model 3
  9238. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == ENABLE
  9239. //[CAUTION][To-Do] Decresement of Current is not implemented.
  9240. //SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumCurrentLimit, 10, A_DIN70121);
  9241. if (sys->EvBatterytargetCurrent <= 0)
  9242. {
  9243. EVSE_max_current = 50; //10A
  9244. cur->EVSEMaximumCurrentLimit.Value = 50; //10A
  9245. /*
  9246. DEBUG_PRINTF_EVCOMM_DETAIL("1PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9247. sys->PresentChargingCurrent,
  9248. sys->EvBatterytargetCurrent,
  9249. EVSE_max_current,
  9250. cur->EVSEMaximumCurrentLimit.Value
  9251. );
  9252. */
  9253. }
  9254. else //1A
  9255. {
  9256. /*
  9257. DEBUG_PRINTF_EVCOMM_DETAIL("2PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9258. sys->PresentChargingCurrent,
  9259. sys->EvBatterytargetCurrent,
  9260. EVSE_max_current,
  9261. cur->EVSEMaximumCurrentLimit.Value
  9262. );
  9263. */
  9264. if ((abs((int)sys->PresentChargingCurrent - (int)sys->EvBatterytargetCurrent) < 3)&&(abs((int)(EVSE_max_current/10) - (int)sys->EvBatterytargetCurrent) < 3))
  9265. {
  9266. tmp = EVSE_max_current + 50; //10A
  9267. if (tmp <= (int)(sys->AvailableChargingCurrent * 10))
  9268. {
  9269. cur->EVSEMaximumCurrentLimit.Value = (int)tmp;
  9270. EVSE_max_current = tmp;
  9271. }
  9272. else
  9273. {
  9274. cur->EVSEMaximumCurrentLimit.Value = (int) (sys->AvailableChargingCurrent * 10); //max is set to 40A
  9275. EVSE_max_current = (int) (sys->AvailableChargingCurrent * 10);
  9276. }
  9277. }
  9278. }
  9279. #endif
  9280. //Check for CSU command of "Stop by EVSE"
  9281. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9282. {
  9283. //Check for Alarm Code: CCS GFD trip (012235)
  9284. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9285. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9286. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9287. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9288. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9289. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9290. {
  9291. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]CCS GFD trip => EVSE_Shutdown");
  9292. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  9293. }
  9294. else
  9295. {
  9296. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]EVSE_Shutdown");
  9297. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9298. }
  9299. //cur->ResponseCode = FAILED_DIN70121;
  9300. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9301. //errn = -1;
  9302. }
  9303. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9304. {
  9305. //Check for Alarm Code: CCS GFD trip (012235)
  9306. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9307. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9308. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9309. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9310. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9311. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9312. {
  9313. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]CCS GFD trip => EVSE_EmergencyShutdown");
  9314. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  9315. }
  9316. else
  9317. {
  9318. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]EVSE_EmergencyShutdown");
  9319. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9320. }
  9321. //cur->ResponseCode = FAILED_DIN70121;
  9322. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9323. //errn = -1;
  9324. }
  9325. else if (ShmInternalComm->ChargingPermission == FALSE)
  9326. {
  9327. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]Permission OFF");
  9328. //cur->ResponseCode = FAILED_DIN70121;
  9329. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9330. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9331. //errn = -1;
  9332. }
  9333. else
  9334. {
  9335. //null
  9336. }
  9337. //Response to CP Error
  9338. #if CP_PROTECTION_MECHANISM == ENABLE
  9339. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9340. {
  9341. cur->ResponseCode = FAILED_DIN70121;
  9342. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9343. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9344. Update_V2G_Flow_Status(Other_Fault);
  9345. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9346. //CCS_SECC_CP_State_Error (023889)
  9347. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9348. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9349. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9350. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9351. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9352. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9353. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9354. sprintf((char*)buf_log_evcomm,
  9355. "[CurrentDemand]Emergency Stop by CP Error (%d, %.02f V)",
  9356. sys->CpState,
  9357. sys->CpVoltage);
  9358. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9359. }
  9360. #endif
  9361. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9362. #if PARAMETER_NORMAL_MODE == ENABLE
  9363. SHM_Read_din_CurrentDemandRes(&ccs_exi_doc_DIN, ShmCcsData);
  9364. #else
  9365. Sudo_Parameter_din_CurrentDemandRes();
  9366. #endif
  9367. //STEP 4: ============ Encode and Send Response Message ===========
  9368. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  9369. {
  9370. errn = -1;
  9371. }
  9372. //STEP 5: ============ Update Flags ===========
  9373. return errn;
  9374. }
  9375. /*===========================================================================
  9376. FUNCTION: Proc_iso1_CurrentDemandRes
  9377. DESCRIPTION:
  9378. PRE-CONDITION:
  9379. INPUT:
  9380. OUTPUT:
  9381. GLOBAL VARIABLES:
  9382. =============================================================================*/
  9383. int Proc_iso1_CurrentDemandRes(int AcceptFd)
  9384. {
  9385. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9386. //if it is not the same, the packet should be ignored.
  9387. //STEP 1: ============ Initialize ============
  9388. int errn = 0;
  9389. bitstream_t v2g_tx_stream;
  9390. static struct CurrentDemandResponse_ISO15118_2014 *cur;
  9391. static struct ChargingInfoData *sys;
  9392. // int i = 0;
  9393. // static int EVSE_max_current;
  9394. // int tmp = 0;
  9395. size_t pos = 0;
  9396. v2g_tx_stream.pos = &pos;
  9397. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9398. v2g_tx_stream.data = V2GTP_Tx_buf;
  9399. cur = &ShmCcsData->V2GMessage_ISO15118_2014.CurrentDemandResponse;
  9400. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9401. cur->ResponseCode = OK_ISO15118_2014;
  9402. //EVSE Status Code
  9403. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  9404. //[HEADER] Check Req SessionID
  9405. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9406. {
  9407. cur->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9408. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9409. errn = -1;
  9410. }
  9411. //Check for SequenceError
  9412. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9413. {
  9414. cur->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  9415. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9416. errn = -1;
  9417. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9418. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9419. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9420. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9421. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9422. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9423. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9424. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9425. }
  9426. //Check for negative EvBatteryMaxCurrent
  9427. if (sys->EvBatteryMaxCurrent < 0)
  9428. {
  9429. sprintf((char*)buf_log_evcomm,
  9430. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  9431. sys->EvBatteryMaxCurrent);
  9432. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9433. cur->ResponseCode = iso1responseCodeType_FAILED_WrongChargeParameter; //16
  9434. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9435. errn = -1;
  9436. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9437. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  9438. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9439. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9440. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9441. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9442. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  9443. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  9444. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9445. }
  9446. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9447. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEPresentCurrent, (int) (sys->PresentChargingCurrent * 10), A_ISO15118_2014);
  9448. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  9449. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == DISABLE
  9450. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  9451. #endif
  9452. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_ISO15118_2014);
  9453. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_ISO15118_2014);
  9454. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  9455. if (sys->EvBatteryMaxVoltage <= 500)
  9456. {
  9457. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumVoltageLimit, (int) (500 * 10), V_ISO15118_2014); //500V
  9458. }
  9459. #endif
  9460. //Limit the EVTargetCurrent should be under EVSEMaximumCurrentLimit
  9461. if (sys->EvBatterytargetCurrent > sys->AvailableChargingCurrent)
  9462. {
  9463. sys->EvBatterytargetCurrent = sys->AvailableChargingCurrent;
  9464. //[To-Do] Limit is achieved flag
  9465. }
  9466. //Isolation Status
  9467. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  9468. {
  9469. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  9470. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9471. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9472. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_CurrentDemandRes]IsolationStatus = %d", sys->IsolationStatus);
  9473. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9474. Update_V2G_Flow_Status(Other_Fault);
  9475. errn = -1;
  9476. }
  9477. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  9478. {
  9479. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  9480. }
  9481. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  9482. {
  9483. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  9484. }
  9485. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  9486. {
  9487. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  9488. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9489. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9490. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_CurrentDemandRes]GFD_Fault => EmergencyShutdown");
  9491. Update_V2G_Flow_Status(Other_Fault);
  9492. errn = -1;
  9493. }
  9494. else
  9495. {
  9496. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  9497. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9498. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9499. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_CurrentDemandRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9500. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9501. Update_V2G_Flow_Status(Other_Fault);
  9502. errn = -1;
  9503. }
  9504. //For testing with Tesla Model 3
  9505. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == ENABLE
  9506. //[CAUTION][To-Do] Decresement of Current is not implemented.
  9507. //SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumCurrentLimit, 10, A_ISO15118_2014);
  9508. if (sys->EvBatterytargetCurrent <= 0)
  9509. {
  9510. EVSE_max_current = 50; //10A
  9511. cur->EVSEMaximumCurrentLimit.Value = 50; //10A
  9512. /*
  9513. DEBUG_PRINTF_EVCOMM_DETAIL("1PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9514. sys->PresentChargingCurrent,
  9515. sys->EvBatterytargetCurrent,
  9516. EVSE_max_current,
  9517. cur->EVSEMaximumCurrentLimit.Value
  9518. );
  9519. */
  9520. }
  9521. else //1A
  9522. {
  9523. /*
  9524. DEBUG_PRINTF_EVCOMM_DETAIL("2PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9525. sys->PresentChargingCurrent,
  9526. sys->EvBatterytargetCurrent,
  9527. EVSE_max_current,
  9528. cur->EVSEMaximumCurrentLimit.Value
  9529. );
  9530. */
  9531. if ((abs((int)sys->PresentChargingCurrent - (int)sys->EvBatterytargetCurrent) < 3)&&(abs((int)(EVSE_max_current/10) - (int)sys->EvBatterytargetCurrent) < 3))
  9532. {
  9533. tmp = EVSE_max_current + 50; //10A
  9534. if (tmp <= (int)(sys->AvailableChargingCurrent * 10))
  9535. {
  9536. cur->EVSEMaximumCurrentLimit.Value = (int)tmp;
  9537. EVSE_max_current = tmp;
  9538. }
  9539. else
  9540. {
  9541. cur->EVSEMaximumCurrentLimit.Value = (int) (sys->AvailableChargingCurrent * 10); //max is set to 40A
  9542. EVSE_max_current = (int) (sys->AvailableChargingCurrent * 10);
  9543. }
  9544. }
  9545. }
  9546. #endif
  9547. //Check for CSU command of "Stop by EVSE"
  9548. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9549. {
  9550. //Check for Alarm Code: CCS GFD trip (012235)
  9551. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9552. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9553. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9554. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9555. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9556. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9557. {
  9558. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][Error][CurrentDemandRes]CCS GFD trip => EVSE_Shutdown");
  9559. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  9560. }
  9561. else
  9562. {
  9563. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][Error][CurrentDemandRes]EVSE_Shutdown");
  9564. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9565. }
  9566. //cur->ResponseCode = FAILED_ISO15118_2014;
  9567. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9568. //errn = -1;
  9569. }
  9570. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9571. {
  9572. //Check for Alarm Code: CCS GFD trip (012235)
  9573. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9574. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9575. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9576. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9577. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9578. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9579. {
  9580. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][Error][CurrentDemandRes]CCS GFD trip => EVSE_EmergencyShutdown");
  9581. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  9582. }
  9583. else
  9584. {
  9585. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][Error][CurrentDemandRes]EVSE_EmergencyShutdown");
  9586. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9587. }
  9588. //cur->ResponseCode = FAILED_ISO15118_2014;
  9589. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9590. //errn = -1;
  9591. }
  9592. else if (ShmInternalComm->ChargingPermission == FALSE)
  9593. {
  9594. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][Error][CurrentDemandRes]Permission OFF");
  9595. //cur->ResponseCode = FAILED_ISO15118_2014;
  9596. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9597. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9598. //errn = -1;
  9599. }
  9600. else
  9601. {
  9602. //null
  9603. }
  9604. //Response to CP Error
  9605. #if CP_PROTECTION_MECHANISM == ENABLE
  9606. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9607. {
  9608. cur->ResponseCode = FAILED_ISO15118_2014;
  9609. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9610. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9611. Update_V2G_Flow_Status(Other_Fault);
  9612. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9613. //CCS_SECC_CP_State_Error (023889)
  9614. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9615. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9616. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9617. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9618. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9619. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9620. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9621. sprintf((char*)buf_log_evcomm,
  9622. "[CurrentDemand]Emergency Stop by CP Error (%d, %.02f V)",
  9623. sys->CpState,
  9624. sys->CpVoltage);
  9625. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9626. }
  9627. #endif
  9628. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9629. #if PARAMETER_NORMAL_MODE == ENABLE
  9630. SHM_Read_iso1_CurrentDemandRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9631. #else
  9632. Sudo_Parameter_iso1_CurrentDemandRes();
  9633. #endif
  9634. //STEP 4: ============ Encode and Send Response Message ===========
  9635. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9636. {
  9637. errn = -1;
  9638. }
  9639. //STEP 5: ============ Update Flags ===========
  9640. return errn;
  9641. }
  9642. /*===========================================================================
  9643. FUNCTION: Proc_iso1_ChargingStatusRes
  9644. DESCRIPTION:
  9645. PRE-CONDITION:
  9646. INPUT:
  9647. OUTPUT:
  9648. GLOBAL VARIABLES:
  9649. =============================================================================*/
  9650. int Proc_iso1_ChargingStatusRes(int AcceptFd)
  9651. {
  9652. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9653. //if it is not the same, the packet should be ignored.
  9654. //STEP 1: ============ Initialize ============
  9655. //int i = 0;
  9656. int errn = 0;
  9657. bitstream_t v2g_tx_stream;
  9658. static struct ChargingStatusResponse_ISO15118_2014 *res;
  9659. static struct ChargingInfoData *sys;
  9660. size_t pos = 0;
  9661. v2g_tx_stream.pos = &pos;
  9662. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9663. v2g_tx_stream.data = V2GTP_Tx_buf;
  9664. res = &ShmCcsData->V2GMessage_ISO15118_2014.ChargingStatusResponse;
  9665. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9666. //Init
  9667. res->ResponseCode = OK_ISO15118_2014;
  9668. res->ReceiptRequired = FALSE; //optional
  9669. res->SAScheduleTupleID = 0;
  9670. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  9671. res->AC_EVSEStatus.NotificationMaxDelay = 0;
  9672. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9673. // iso1EVSENotificationType_None = 0,
  9674. // iso1EVSENotificationType_StopCharging = 1,
  9675. // iso1EVSENotificationType_ReNegotiation = 2
  9676. //[HEADER] Check Req SessionID
  9677. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9678. {
  9679. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9680. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9681. errn = -1;
  9682. }
  9683. //Check for SequenceError
  9684. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9685. {
  9686. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  9687. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9688. errn = -1;
  9689. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9690. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9691. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9692. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9693. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9694. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9695. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9696. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9697. }
  9698. //EVSE ID
  9699. memset(res->EVSEID, 0, sizeof(res->EVSEID));
  9700. //sprintf((char*)res->EVSEID, CCS_AC_EVSEID);
  9701. //[MeterInfo][0/5] init
  9702. //memset(res->MeterInfo.MeterID.characters, 0, sizeof(res->MeterInfo.MeterID.characters));
  9703. //memset(res->MeterInfo.SigMeterReading.bytes, 0, sizeof(res->MeterInfo.SigMeterReading.bytes));
  9704. //[MeterInfo][1/5] MeterID
  9705. //sprintf((char*)res->MeterInfo.MeterID , CCS_AC_METER_ID);
  9706. //[MeterInfo][2/5] SigMeterReading (optional)
  9707. //sprintf((char*)res->MeterInfo.SigMeterReading , CCS_AC_SIG_METER_READING);
  9708. //[MeterInfo][3/5] MeterStatus (optional)
  9709. res->MeterInfo.MeterStatus = 0;
  9710. //[MeterInfo][4/5] MeterReading (optional)
  9711. res->MeterInfo.MeterReading = 12345;
  9712. //[MeterInfo][5/5] TMeter (optional)
  9713. res->MeterInfo.TMeter = 1586243587; //Unix Time Stamp format
  9714. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9715. SAVE_PhysicalValueType_ISO15118_2014(&res->EVSEMaxCurrent, (int)(sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  9716. //Isolation Status (RCD)
  9717. if (sys->IsolationStatus == 0) //Isolation is invalid
  9718. {
  9719. res->AC_EVSEStatus.RCD = TRUE; //FALSE(no error), TRUE(error is detected)
  9720. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9721. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9722. sprintf((char*)buf_log_evcomm, "[ISO1][Error][ChargingStatusRes]IsolationStatus = %d", sys->IsolationStatus);
  9723. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9724. Update_V2G_Flow_Status(Other_Fault);
  9725. errn = -1;
  9726. }
  9727. else if (sys->IsolationStatus == 1) //Isolation is valid
  9728. {
  9729. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  9730. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9731. }
  9732. else
  9733. {
  9734. res->AC_EVSEStatus.RCD = TRUE; //FALSE(no error), TRUE(error is detected)
  9735. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9736. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9737. sprintf((char*)buf_log_evcomm, "[ISO1][Error][ChargingStatusRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9738. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9739. Update_V2G_Flow_Status(Other_Fault);
  9740. errn = -1;
  9741. }
  9742. //Check for CSU command of "Stop by EVSE"
  9743. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9744. {
  9745. //res->ResponseCode = FAILED_ISO15118_2014;
  9746. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9747. //errn = -1;
  9748. }
  9749. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9750. {
  9751. //res->ResponseCode = FAILED_ISO15118_2014;
  9752. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9753. //errn = -1;
  9754. }
  9755. else if (ShmInternalComm->ChargingPermission == FALSE)
  9756. {
  9757. //res->ResponseCode = FAILED_ISO15118_2014;
  9758. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9759. //errn = -1;
  9760. }
  9761. //Response to CP Error
  9762. #if CP_PROTECTION_MECHANISM == ENABLE
  9763. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9764. {
  9765. res->ResponseCode = FAILED_ISO15118_2014;
  9766. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9767. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9768. Update_V2G_Flow_Status(Other_Fault);
  9769. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9770. //CCS_SECC_CP_State_Error (023889)
  9771. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9772. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9773. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9774. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9775. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9776. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9777. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9778. sprintf((char*)buf_log_evcomm,
  9779. "[ChargingStatus]Emergency Stop by CP Error (%d, %.02f V)",
  9780. sys->CpState,
  9781. sys->CpVoltage);
  9782. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9783. }
  9784. #endif
  9785. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9786. #if PARAMETER_NORMAL_MODE == ENABLE
  9787. SHM_Read_iso1_ChargingStatusRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9788. #else
  9789. Sudo_Parameter_iso1_ChargingStatusRes();
  9790. #endif
  9791. //STEP 4: ============ Encode and Send Response Message ===========
  9792. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9793. {
  9794. errn = -1;
  9795. }
  9796. //STEP 5: ============ Update Flags ===========
  9797. return errn;
  9798. }
  9799. /*===========================================================================
  9800. FUNCTION: Proc_din_CurrentDemandReq
  9801. DESCRIPTION:
  9802. PRE-CONDITION:
  9803. INPUT:
  9804. OUTPUT:
  9805. GLOBAL VARIABLES:
  9806. =============================================================================*/
  9807. int Proc_din_CurrentDemandReq(int AcceptFd)
  9808. {
  9809. int errn = 0;
  9810. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_CurrentDemandReq] Got CurrentDemandReq\n");
  9811. //Print the decoded XML Document
  9812. PRINT_XML_DOC_DIN_CurrentDemandReq(&ccs_exi_doc_DIN);
  9813. //Save into Share Memory
  9814. SHM_Save_din_CurrentDemandReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  9815. //Check for EV Error Code
  9816. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.CurrentDemandRequest.DC_EVStatus.EVErrorCode);
  9817. errn = Proc_din_CurrentDemandRes(AcceptFd);
  9818. if (errn == 0)
  9819. {
  9820. //Response is sent successfully.
  9821. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][Tx]CurrentDemandRes");
  9822. }
  9823. else
  9824. {
  9825. sprintf((char*)buf_log_evcomm,
  9826. "[DIN][Error][CurrentDemandReq]CurrentDemandRes: fail(%d,DEC)",
  9827. errn);
  9828. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9829. }
  9830. return errn;
  9831. }
  9832. /*===========================================================================
  9833. FUNCTION: Proc_iso1_CurrentDemandReq
  9834. DESCRIPTION:
  9835. PRE-CONDITION:
  9836. INPUT:
  9837. OUTPUT:
  9838. GLOBAL VARIABLES:
  9839. =============================================================================*/
  9840. int Proc_iso1_CurrentDemandReq(int AcceptFd)
  9841. {
  9842. int errn = 0;
  9843. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_CurrentDemandReq] Got CurrentDemandReq\n");
  9844. //Print the decoded XML Document
  9845. PRINT_XML_DOC_ISO1_CurrentDemandReq(&ccs_exi_doc_ISO1);
  9846. //Save into Share Memory
  9847. SHM_Save_iso1_CurrentDemandReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9848. //Check for EV Error Code
  9849. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.CurrentDemandRequest.DC_EVStatus.EVErrorCode);
  9850. errn = Proc_iso1_CurrentDemandRes(AcceptFd);
  9851. if (errn == 0)
  9852. {
  9853. //Response is sent successfully.
  9854. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]CurrentDemandRes");
  9855. }
  9856. else
  9857. {
  9858. sprintf((char*)buf_log_evcomm,
  9859. "[ISO1][Error][CurrentDemandReq]CurrentDemandRes: fail(%d,DEC)",
  9860. errn);
  9861. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9862. }
  9863. return errn;
  9864. }
  9865. /*===========================================================================
  9866. FUNCTION: Proc_iso1_ChargingStatusReq
  9867. DESCRIPTION:
  9868. PRE-CONDITION:
  9869. INPUT:
  9870. OUTPUT:
  9871. GLOBAL VARIABLES:
  9872. =============================================================================*/
  9873. int Proc_iso1_ChargingStatusReq(int AcceptFd)
  9874. {
  9875. int errn = 0;
  9876. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ChargingStatusReq] Got ChargingStatusReq\n");
  9877. //Print the decoded XML Document
  9878. PRINT_XML_DOC_ISO1_ChargingStatusReq(&ccs_exi_doc_ISO1);
  9879. //Save into Share Memory
  9880. SHM_Save_iso1_ChargingStatusReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9881. //Check for EV Error Code
  9882. //no content in ISO1
  9883. errn = Proc_iso1_ChargingStatusRes(AcceptFd);
  9884. if (errn == 0)
  9885. {
  9886. //Response is sent successfully.
  9887. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]ChargingStatusRes");
  9888. }
  9889. else
  9890. {
  9891. sprintf((char*)buf_log_evcomm,
  9892. "[ISO1][Error][ChargingStatusReq]ChargingStatusRes: fail(%d,DEC)",
  9893. errn);
  9894. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9895. }
  9896. return errn;
  9897. }
  9898. /*===========================================================================
  9899. FUNCTION: Proc_din_PowerDeliveryStopRes
  9900. DESCRIPTION:
  9901. PRE-CONDITION:
  9902. INPUT:
  9903. OUTPUT:
  9904. GLOBAL VARIABLES:
  9905. =============================================================================*/
  9906. int Proc_din_PowerDeliveryStopRes(int AcceptFd)
  9907. {
  9908. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9909. //if it is not the same, the packet should be ignored.
  9910. //STEP 1: ============ Initialize ============
  9911. //int i = 0;
  9912. int errn = 0;
  9913. bitstream_t v2g_tx_stream;
  9914. struct dinPowerDeliveryResType *res;
  9915. struct ChargingInfoData *sys;
  9916. size_t pos = 0;
  9917. v2g_tx_stream.pos = &pos;
  9918. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9919. v2g_tx_stream.data = V2GTP_Tx_buf;
  9920. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  9921. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9922. res->ResponseCode = OK_DIN70121;
  9923. //[HEADER] Check Req SessionID
  9924. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  9925. {
  9926. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  9927. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9928. errn = -1;
  9929. }
  9930. //Check for SequenceError
  9931. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9932. {
  9933. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  9934. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9935. errn = -1;
  9936. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9937. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9938. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9939. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9940. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9941. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9942. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9943. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9944. }
  9945. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9946. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9947. #if PARAMETER_NORMAL_MODE == ENABLE
  9948. ShmCcsData->V2GMessage_DIN70121.PowerDeliveryResponse.DC_EVSEStatus.EVSEStatusCode = EVSE_NotReady;
  9949. SHM_Read_din_PowerDeliveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  9950. #else
  9951. Sudo_Parameter_din_PreChargeRes();
  9952. #endif
  9953. //EVSE Status Code
  9954. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  9955. //Check for CSU command of "Stop by EVSE"
  9956. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9957. {
  9958. //res->ResponseCode = FAILED_DIN70121;
  9959. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9960. }
  9961. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9962. {
  9963. //res->ResponseCode = FAILED_DIN70121;
  9964. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9965. }
  9966. else if (ShmInternalComm->ChargingPermission == FALSE)
  9967. {
  9968. //res->ResponseCode = FAILED_DIN70121;
  9969. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9970. }
  9971. //STEP 4: ============ Encode and Send Response Message ===========
  9972. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  9973. {
  9974. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_PowerDeliveryStopRes][Error]Tx encoded msg error");
  9975. errn = -1;
  9976. }
  9977. //STEP 5: ============ Update Flags ===========
  9978. return errn;
  9979. }
  9980. /*===========================================================================
  9981. FUNCTION: Proc_iso1_PowerDeliveryStopRes
  9982. DESCRIPTION:
  9983. PRE-CONDITION:
  9984. INPUT:
  9985. OUTPUT:
  9986. GLOBAL VARIABLES:
  9987. =============================================================================*/
  9988. int Proc_iso1_PowerDeliveryStopRes(int AcceptFd)
  9989. {
  9990. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9991. //if it is not the same, the packet should be ignored.
  9992. //STEP 1: ============ Initialize ============
  9993. //int i = 0;
  9994. int errn = 0;
  9995. bitstream_t v2g_tx_stream;
  9996. struct iso1PowerDeliveryResType *res;
  9997. struct ChargingInfoData *sys;
  9998. size_t pos = 0;
  9999. v2g_tx_stream.pos = &pos;
  10000. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10001. v2g_tx_stream.data = V2GTP_Tx_buf;
  10002. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  10003. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10004. res->ResponseCode = OK_ISO15118_2014;
  10005. //[HEADER] Check Req SessionID
  10006. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10007. {
  10008. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10009. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10010. errn = -1;
  10011. }
  10012. //Check for SequenceError
  10013. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10014. {
  10015. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10016. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10017. errn = -1;
  10018. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10019. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10020. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10021. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10022. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10023. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10024. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10025. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10026. }
  10027. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10028. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10029. #if PARAMETER_NORMAL_MODE == ENABLE
  10030. ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryResponse.DC_EVSEStatus.DC_EVSEStatusCode = EVSE_NotReady;
  10031. SHM_Read_iso1_PowerDeliveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10032. #else
  10033. Sudo_Parameter_iso1_PreChargeRes();
  10034. #endif
  10035. //EVSE Status Code
  10036. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10037. //Check for CSU command of "Stop by EVSE"
  10038. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10039. {
  10040. //res->ResponseCode = FAILED_ISO15118_2014;
  10041. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10042. }
  10043. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10044. {
  10045. //res->ResponseCode = FAILED_ISO15118_2014;
  10046. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10047. }
  10048. else if (ShmInternalComm->ChargingPermission == FALSE)
  10049. {
  10050. //res->ResponseCode = FAILED_ISO15118_2014;
  10051. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10052. }
  10053. //STEP 4: ============ Encode and Send Response Message ===========
  10054. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10055. {
  10056. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_PowerDeliveryStopRes][Error]Tx encoded msg error");
  10057. errn = -1;
  10058. }
  10059. //STEP 5: ============ Update Flags ===========
  10060. return errn;
  10061. }
  10062. /*===========================================================================
  10063. FUNCTION: Proc_din_PowerDeliveryStopReq
  10064. DESCRIPTION:
  10065. PRE-CONDITION:
  10066. INPUT:
  10067. OUTPUT:
  10068. GLOBAL VARIABLES:
  10069. =============================================================================*/
  10070. int Proc_din_PowerDeliveryStopReq(int AcceptFd)
  10071. {
  10072. int errn = 0;
  10073. //Request CSU to STOP
  10074. //This should be reponsed as soon as possible once this message is received.
  10075. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10076. EVCOMM_SYS_INFO.EvBatterytargetVoltage = 0;
  10077. EVCOMM_SYS_INFO.EvBatterytargetCurrent = 0;
  10078. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]PowerDeliveryReq (2nd)\n");
  10079. //Print the decoded XML Document
  10080. PRINT_XML_DOC_DIN_PowerDeliveryReq(&ccs_exi_doc_DIN);
  10081. //Save into Share Memory
  10082. SHM_Save_din_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10083. //Check for EV Error Code
  10084. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  10085. //[To-Do] Sending response after the EVSE output voltage decreases to under 60V
  10086. usleep(1500000); //1.5 seconds
  10087. //sleep(1); //1 second
  10088. errn = Proc_din_PowerDeliveryStopRes(AcceptFd);
  10089. if (errn == 0)
  10090. {
  10091. //send response successfully.
  10092. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][Tx]PowerDeliveryRes (2nd)\n");
  10093. }
  10094. else
  10095. {
  10096. sprintf((char*)buf_log_evcomm,
  10097. "[Error][SeccComm][Proc_din_PowerDeliveryStopReq]Proc_iso1_PowerDeliveryStopRes(): %d (DEC)",
  10098. errn);
  10099. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10100. }
  10101. return errn;
  10102. }
  10103. /*===========================================================================
  10104. FUNCTION: Proc_iso1_PowerDeliveryStopReq
  10105. DESCRIPTION:
  10106. PRE-CONDITION:
  10107. INPUT:
  10108. OUTPUT:
  10109. GLOBAL VARIABLES:
  10110. =============================================================================*/
  10111. int Proc_iso1_PowerDeliveryStopReq(int AcceptFd)
  10112. {
  10113. int errn = 0;
  10114. //Request CSU to STOP
  10115. //This should be reponsed as soon as possible once this message is received.
  10116. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10117. EVCOMM_SYS_INFO.EvBatterytargetVoltage = 0;
  10118. EVCOMM_SYS_INFO.EvBatterytargetCurrent = 0;
  10119. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]PowerDeliveryReq (2nd)\n");
  10120. //Print the decoded XML Document
  10121. PRINT_XML_DOC_ISO1_PowerDeliveryReq(&ccs_exi_doc_ISO1);
  10122. //Save into Share Memory
  10123. SHM_Save_iso1_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10124. //Check for EV Error Code
  10125. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  10126. //[To-Do] Sending response after the EVSE output voltage decreases to under 60V
  10127. usleep(1500000); //1.5 seconds
  10128. //sleep(1); //1 second
  10129. errn = Proc_iso1_PowerDeliveryStopRes(AcceptFd);
  10130. if (errn == 0)
  10131. {
  10132. //send response successfully.
  10133. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]PowerDeliveryRes (2nd)");
  10134. }
  10135. else
  10136. {
  10137. sprintf((char*)buf_log_evcomm,
  10138. "[Error][SeccComm][Proc_iso1_PowerDeliveryStopReq]Proc_iso1_PowerDeliveryStopRes(): %d (DEC)",
  10139. errn);
  10140. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10141. }
  10142. return errn;
  10143. }
  10144. /*===========================================================================
  10145. FUNCTION: SHM_Init_din_WeldingDetectionRes
  10146. DESCRIPTION:
  10147. PRE-CONDITION:
  10148. INPUT:
  10149. 1. shm_ccs
  10150. OUTPUT:
  10151. 1. shm_ccs
  10152. GLOBAL VARIABLES:
  10153. =============================================================================*/
  10154. void SHM_Init_din_WeldingDetectionRes(struct CcsData *shm_ccs)
  10155. {
  10156. struct WeldingDetectionResponse_DIN70121 *in;
  10157. in = &shm_ccs->V2GMessage_DIN70121.WeldingDetectionResponse;
  10158. //----- [BODY (1/3)] ResponseCode -----
  10159. in->ResponseCode = dinresponseCodeType_OK;
  10160. //----- [BODY (2/3)] EVSEPresentVoltage -----
  10161. short value = 0; int multiplier = 0; unsigned char unit = 0;
  10162. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for test only.
  10163. value = 0; multiplier = 0; unit = V_DIN70121;
  10164. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  10165. //----- [BODY (3/3)] DC_EVSEStatus -----
  10166. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  10167. }
  10168. /*===========================================================================
  10169. FUNCTION: Sudo_Parameter_din_WeldingDetectionRes
  10170. DESCRIPTION:
  10171. PRE-CONDITION:
  10172. INPUT:
  10173. OUTPUT:
  10174. GLOBAL VARIABLES:
  10175. =============================================================================*/
  10176. void Sudo_Parameter_din_WeldingDetectionRes()
  10177. {
  10178. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  10179. init_dinWeldingDetectionResType(&ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes);
  10180. ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes_isUsed = 1u;
  10181. //----- [BODY (1/3)] ResponseCode -----
  10182. struct dinWeldingDetectionResType *res;
  10183. res = &ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes;
  10184. res->ResponseCode = dinresponseCodeType_OK;
  10185. //----- [BODY (2/3)] EVSEPresentVoltage -----
  10186. res->EVSEPresentVoltage.Value = 3820;
  10187. res->EVSEPresentVoltage.Multiplier = -1;
  10188. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  10189. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  10190. // dinunitSymbolType_h = 0,
  10191. // dinunitSymbolType_m = 1,
  10192. // dinunitSymbolType_s = 2,
  10193. // dinunitSymbolType_A = 3,
  10194. // dinunitSymbolType_Ah = 4,
  10195. // dinunitSymbolType_V = 5,
  10196. // dinunitSymbolType_VA = 6,
  10197. // dinunitSymbolType_W = 7,
  10198. // dinunitSymbolType_W_s = 8,
  10199. // dinunitSymbolType_Wh = 9
  10200. //----- [BODY (3/3)] DC_EVSEStatus -----
  10201. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  10202. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  10203. // dinisolationLevelType_Invalid = 0,
  10204. // dinisolationLevelType_Valid = 1,
  10205. // dinisolationLevelType_Warning = 2,
  10206. // dinisolationLevelType_Fault = 3
  10207. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  10208. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  10209. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  10210. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  10211. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  10212. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  10213. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  10214. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  10215. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  10216. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  10217. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  10218. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  10219. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  10220. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  10221. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  10222. // dinEVSENotificationType_None = 0,
  10223. // dinEVSENotificationType_StopCharging = 1,
  10224. // dinEVSENotificationType_ReNegotiation = 2
  10225. }
  10226. /*===========================================================================
  10227. FUNCTION: Sudo_Parameter_iso1_WeldingDetectionRes
  10228. DESCRIPTION:
  10229. PRE-CONDITION:
  10230. INPUT:
  10231. OUTPUT:
  10232. GLOBAL VARIABLES:
  10233. =============================================================================*/
  10234. void Sudo_Parameter_iso1_WeldingDetectionRes()
  10235. {
  10236. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  10237. init_iso1WeldingDetectionResType(&ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes);
  10238. ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes_isUsed = 1u;
  10239. //----- [BODY (1/3)] ResponseCode -----
  10240. struct iso1WeldingDetectionResType *res;
  10241. res = &ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes;
  10242. res->ResponseCode = iso1responseCodeType_OK;
  10243. //----- [BODY (2/3)] EVSEPresentVoltage -----
  10244. res->EVSEPresentVoltage.Value = 3820;
  10245. res->EVSEPresentVoltage.Multiplier = -1;
  10246. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  10247. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  10248. //iso1unitSymbolType_h = 0,
  10249. //iso1unitSymbolType_m = 1,
  10250. //iso1unitSymbolType_s = 2,
  10251. //iso1unitSymbolType_A = 3,
  10252. //iso1unitSymbolType_V = 4,
  10253. //iso1unitSymbolType_W = 5,
  10254. //iso1unitSymbolType_Wh = 6
  10255. //----- [BODY (3/3)] DC_EVSEStatus -----
  10256. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  10257. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  10258. //iso1isolationLevelType_Invalid = 0,
  10259. //iso1isolationLevelType_Valid = 1,
  10260. //iso1isolationLevelType_Warning = 2,
  10261. //iso1isolationLevelType_Fault = 3,
  10262. //iso1isolationLevelType_No_IMD = 4
  10263. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10264. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  10265. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  10266. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  10267. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  10268. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  10269. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  10270. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  10271. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  10272. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  10273. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  10274. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  10275. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  10276. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  10277. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  10278. //iso1EVSENotificationType_None = 0,
  10279. //iso1EVSENotificationType_StopCharging = 1,
  10280. //iso1EVSENotificationType_ReNegotiation = 2
  10281. }
  10282. /*===========================================================================
  10283. FUNCTION: Proc_din_WeldingDetectionRes
  10284. DESCRIPTION:
  10285. PRE-CONDITION:
  10286. INPUT:
  10287. OUTPUT:
  10288. GLOBAL VARIABLES:
  10289. =============================================================================*/
  10290. int Proc_din_WeldingDetectionRes(int AcceptFd)
  10291. {
  10292. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10293. //if it is not the same, the packet should be ignored.
  10294. //STEP 1: ============ Initialize ============
  10295. //int i = 0;
  10296. int errn = 0;
  10297. bitstream_t v2g_tx_stream;
  10298. static struct WeldingDetectionResponse_DIN70121 *wel;
  10299. static struct ChargingInfoData *sys;
  10300. size_t pos = 0;
  10301. v2g_tx_stream.pos = &pos;
  10302. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10303. v2g_tx_stream.data = V2GTP_Tx_buf;
  10304. wel = &ShmCcsData->V2GMessage_DIN70121.WeldingDetectionResponse;
  10305. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10306. wel->ResponseCode = OK_DIN70121;
  10307. //[HEADER] Check Req SessionID
  10308. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  10309. {
  10310. wel->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  10311. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10312. errn = -1;
  10313. }
  10314. //Check for SequenceError
  10315. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10316. {
  10317. wel->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  10318. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10319. errn = -1;
  10320. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10321. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10322. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10323. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10324. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10325. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10326. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10327. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10328. }
  10329. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10330. SAVE_PhysicalValueType_DIN70121(&wel->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  10331. //EVSE Status Code
  10332. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  10333. //Check for CSU command of "Stop by EVSE"
  10334. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10335. {
  10336. //wel->ResponseCode = FAILED_DIN70121;
  10337. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10338. }
  10339. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10340. {
  10341. //wel->ResponseCode = FAILED_DIN70121;
  10342. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10343. }
  10344. else if (ShmInternalComm->ChargingPermission == FALSE)
  10345. {
  10346. //wel->ResponseCode = FAILED_DIN70121;
  10347. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10348. }
  10349. //Isolation Status
  10350. if (sys->IsolationStatus == GFD_Invalid) //0:invalid (on going)
  10351. {
  10352. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  10353. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10354. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10355. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_WeldingDetectionRes]IsolationStatus = %d", sys->IsolationStatus);
  10356. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10357. Update_V2G_Flow_Status(Other_Fault);
  10358. errn = -1;
  10359. }
  10360. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  10361. {
  10362. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  10363. }
  10364. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  10365. {
  10366. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  10367. }
  10368. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  10369. {
  10370. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  10371. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10372. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10373. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_WeldingDetectionRes]GFD_Fault => Emergency Shutdown");
  10374. Update_V2G_Flow_Status(Other_Fault);
  10375. errn = -1;
  10376. }
  10377. else //GFD_No_IMD or other unexpected status
  10378. {
  10379. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  10380. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10381. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10382. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_WeldingDetectionRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  10383. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10384. Update_V2G_Flow_Status(Other_Fault);
  10385. errn = -1;
  10386. }
  10387. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10388. #if PARAMETER_NORMAL_MODE == ENABLE
  10389. SHM_Read_din_WeldingDetectionRes(&ccs_exi_doc_DIN, ShmCcsData);
  10390. #else
  10391. Sudo_Parameter_din_WeldingDetectionRes();
  10392. #endif
  10393. //STEP 4: ============ Encode and Send Response Message ===========
  10394. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  10395. {
  10396. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_WeldingDetectionRes][Error]Tx encoded msg error");
  10397. errn = -1;
  10398. }
  10399. //STEP 5: ============ Update Flags ===========
  10400. return errn;
  10401. }
  10402. /*===========================================================================
  10403. FUNCTION: Proc_iso1_WeldingDetectionRes
  10404. DESCRIPTION:
  10405. PRE-CONDITION:
  10406. INPUT:
  10407. OUTPUT:
  10408. GLOBAL VARIABLES:
  10409. =============================================================================*/
  10410. int Proc_iso1_WeldingDetectionRes(int AcceptFd)
  10411. {
  10412. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10413. //if it is not the same, the packet should be ignored.
  10414. //STEP 1: ============ Initialize ============
  10415. //int i = 0;
  10416. int errn = 0;
  10417. bitstream_t v2g_tx_stream;
  10418. static struct WeldingDetectionResponse_ISO15118_2014 *wel;
  10419. static struct ChargingInfoData *sys;
  10420. size_t pos = 0;
  10421. v2g_tx_stream.pos = &pos;
  10422. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10423. v2g_tx_stream.data = V2GTP_Tx_buf;
  10424. wel = &ShmCcsData->V2GMessage_ISO15118_2014.WeldingDetectionResponse;
  10425. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10426. wel->ResponseCode = OK_ISO15118_2014;
  10427. //[HEADER] Check Req SessionID
  10428. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10429. {
  10430. wel->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10431. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10432. errn = -1;
  10433. }
  10434. //Check for SequenceError
  10435. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10436. {
  10437. wel->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10438. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10439. errn = -1;
  10440. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10441. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10442. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10443. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10444. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10445. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10446. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10447. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10448. }
  10449. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10450. SAVE_PhysicalValueType_ISO15118_2014(&wel->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  10451. //EVSE Status Code
  10452. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10453. //Check for CSU command of "Stop by EVSE"
  10454. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10455. {
  10456. //wel->ResponseCode = FAILED_ISO15118_2014;
  10457. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10458. }
  10459. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10460. {
  10461. //wel->ResponseCode = FAILED_ISO15118_2014;
  10462. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10463. }
  10464. else if (ShmInternalComm->ChargingPermission == FALSE)
  10465. {
  10466. //wel->ResponseCode = FAILED_ISO15118_2014;
  10467. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10468. }
  10469. //Isolation Status
  10470. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  10471. {
  10472. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  10473. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10474. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10475. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_WeldingDetectionRes]IsolationStatus = %d", sys->IsolationStatus);
  10476. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10477. Update_V2G_Flow_Status(Other_Fault);
  10478. errn = -1;
  10479. }
  10480. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  10481. {
  10482. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  10483. }
  10484. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  10485. {
  10486. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  10487. }
  10488. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  10489. {
  10490. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  10491. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10492. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10493. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_WeldingDetectionRes]GFD_Fault => EmergencyShutdown");
  10494. Update_V2G_Flow_Status(Other_Fault);
  10495. errn = -1;
  10496. }
  10497. else
  10498. {
  10499. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  10500. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10501. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10502. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_WeldingDetectionRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  10503. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10504. Update_V2G_Flow_Status(Other_Fault);
  10505. errn = -1;
  10506. }
  10507. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10508. #if PARAMETER_NORMAL_MODE == ENABLE
  10509. SHM_Read_iso1_WeldingDetectionRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10510. #else
  10511. Sudo_Parameter_iso1_WeldingDetectionRes();
  10512. #endif
  10513. //STEP 4: ============ Encode and Send Response Message ===========
  10514. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10515. {
  10516. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_WeldingDetectionRes][Error]Tx encoded msg error");
  10517. errn = -1;
  10518. }
  10519. //STEP 5: ============ Update Flags ===========
  10520. return errn;
  10521. }
  10522. /*===========================================================================
  10523. FUNCTION: Proc_din_WeldingDetectionReq
  10524. DESCRIPTION:
  10525. PRE-CONDITION:
  10526. INPUT:
  10527. OUTPUT:
  10528. GLOBAL VARIABLES:
  10529. =============================================================================*/
  10530. int Proc_din_WeldingDetectionReq(int AcceptFd)
  10531. {
  10532. int errn = 0;
  10533. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_WeldingDetectionReq] Got WeldingDetectionReq\n");
  10534. //Print the decoded XML Document
  10535. PRINT_XML_DOC_DIN_WeldingDetectionReq(&ccs_exi_doc_DIN);
  10536. //Save into Share Memory
  10537. SHM_Save_din_WeldingDetectionReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10538. //Check for EV Error Code
  10539. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.WeldingDetectionRequest.DC_EVStatus.EVErrorCode);
  10540. errn = Proc_din_WeldingDetectionRes(AcceptFd);
  10541. if (errn == 0)
  10542. {
  10543. //send response successfully.
  10544. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][Tx]WeldingDetectionRes");
  10545. }
  10546. else
  10547. {
  10548. sprintf((char*)buf_log_evcomm,
  10549. "[Error][SeccComm][Proc_din_WeldingDetectionReq]Proc_din_WeldingDetectionRes(): %d (DEC)",
  10550. errn);
  10551. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10552. }
  10553. return errn;
  10554. }
  10555. /*===========================================================================
  10556. FUNCTION: Proc_iso1_WeldingDetectionReq
  10557. DESCRIPTION:
  10558. PRE-CONDITION:
  10559. INPUT:
  10560. OUTPUT:
  10561. GLOBAL VARIABLES:
  10562. =============================================================================*/
  10563. int Proc_iso1_WeldingDetectionReq(int AcceptFd)
  10564. {
  10565. int errn = 0;
  10566. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_WeldingDetectionReq] Got WeldingDetectionReq\n");
  10567. //Print the decoded XML Document
  10568. PRINT_XML_DOC_ISO1_WeldingDetectionReq(&ccs_exi_doc_ISO1);
  10569. //Save into Share Memory
  10570. SHM_Save_iso1_WeldingDetectionReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10571. //Check for EV Error Code
  10572. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.WeldingDetectionRequest.DC_EVStatus.EVErrorCode);
  10573. errn = Proc_iso1_WeldingDetectionRes(AcceptFd);
  10574. if (errn == 0)
  10575. {
  10576. //send response successfully.
  10577. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]WeldingDetectionRes");
  10578. }
  10579. else
  10580. {
  10581. sprintf((char*)buf_log_evcomm,
  10582. "[Error][SeccComm][Proc_iso1_WeldingDetectionReq]Proc_iso1_WeldingDetectionRes(): %d (DEC)",
  10583. errn);
  10584. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10585. }
  10586. return errn;
  10587. }
  10588. /*===========================================================================
  10589. FUNCTION: SHM_Init_din_SessionStopRes
  10590. DESCRIPTION:
  10591. PRE-CONDITION:
  10592. INPUT:
  10593. 1. shm_ccs
  10594. OUTPUT:
  10595. 1. shm_ccs
  10596. GLOBAL VARIABLES:
  10597. =============================================================================*/
  10598. void SHM_Init_din_SessionStopRes(struct CcsData *shm_ccs)
  10599. {
  10600. struct SessionStopResponse_DIN70121 *in;
  10601. in = &shm_ccs->V2GMessage_DIN70121.SessionStopResponse;
  10602. //----- [BODY (1/3)] ResponseCode -----
  10603. in->ResponseCode = dinresponseCodeType_OK;
  10604. }
  10605. /*===========================================================================
  10606. FUNCTION: Sudo_Parameter_din_SessionStopRes
  10607. DESCRIPTION:
  10608. PRE-CONDITION:
  10609. INPUT:
  10610. OUTPUT:
  10611. GLOBAL VARIABLES:
  10612. =============================================================================*/
  10613. void Sudo_Parameter_din_SessionStopRes()
  10614. {
  10615. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  10616. init_dinSessionStopResType(&ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes);
  10617. ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes_isUsed = 1u;
  10618. //----- [BODY (1/3)] ResponseCode -----
  10619. struct dinSessionStopResType *res;
  10620. res = &ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes;
  10621. res->ResponseCode = dinresponseCodeType_OK;
  10622. }
  10623. /*===========================================================================
  10624. FUNCTION: Sudo_Parameter_iso1_SessionStopRes
  10625. DESCRIPTION:
  10626. PRE-CONDITION:
  10627. INPUT:
  10628. OUTPUT:
  10629. GLOBAL VARIABLES:
  10630. =============================================================================*/
  10631. void Sudo_Parameter_iso1_SessionStopRes()
  10632. {
  10633. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  10634. init_iso1SessionStopResType(&ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes);
  10635. ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes_isUsed = 1u;
  10636. //----- [BODY (1/3)] ResponseCode -----
  10637. struct iso1SessionStopResType *res;
  10638. res = &ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes;
  10639. res->ResponseCode = iso1responseCodeType_OK;
  10640. }
  10641. /*===========================================================================
  10642. FUNCTION: Proc_din_SessionStopRes
  10643. DESCRIPTION:
  10644. PRE-CONDITION:
  10645. INPUT:
  10646. OUTPUT:
  10647. GLOBAL VARIABLES:
  10648. =============================================================================*/
  10649. int Proc_din_SessionStopRes(int AcceptFd)
  10650. {
  10651. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10652. //if it is not the same, the packet should be ignored.
  10653. //STEP 1: ============ Initialize ============
  10654. //int i = 0;
  10655. int errn = 0;
  10656. bitstream_t v2g_tx_stream;
  10657. struct SessionStopResponse_DIN70121 *stp;
  10658. size_t pos = 0;
  10659. v2g_tx_stream.pos = &pos;
  10660. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10661. v2g_tx_stream.data = V2GTP_Tx_buf;
  10662. stp = &ShmCcsData->V2GMessage_DIN70121.SessionStopResponse;
  10663. stp->ResponseCode = OK_DIN70121;
  10664. //[HEADER] Check Req SessionID
  10665. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  10666. {
  10667. stp->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  10668. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10669. errn = -1;
  10670. }
  10671. //Check for SequenceError
  10672. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10673. {
  10674. stp->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  10675. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10676. errn = -1;
  10677. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10678. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10679. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10680. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10681. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10682. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10683. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10684. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10685. }
  10686. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10687. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10688. #if PARAMETER_NORMAL_MODE == ENABLE
  10689. SHM_Read_din_SessionStopRes(&ccs_exi_doc_DIN, ShmCcsData);
  10690. #else
  10691. Sudo_Parameter_din_SessionStopRes();
  10692. #endif
  10693. //STEP 4: ============ Encode and Send Response Message ===========
  10694. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  10695. {
  10696. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Tx]SessionStopRes: fail");
  10697. errn = -1;
  10698. }
  10699. else
  10700. {
  10701. //send response successfully.
  10702. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Tx]SessionStopRes");
  10703. }
  10704. //STEP 5: ============ Update Flags ===========
  10705. EVCOMM_SYS_INFO.ConnectorLocked = FALSE; //Indicating CSU that the Connector is unlocked.
  10706. //Once this is set, the CSU should
  10707. // =========== Annouce to CSU [To-Be Implemented]=============
  10708. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE; //This should be also added to EV Error events.
  10709. // =========== Re-initialized [To-Be Implemented]=============
  10710. //Keep 5% PWM for 2 seconds
  10711. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 2");
  10712. sleep(1);
  10713. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 1");
  10714. sleep(1);
  10715. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 0");
  10716. OutputCpPwmDuty(100);
  10717. //[To-Do] Reset All Share memory
  10718. //[To-Do] CCS Module enter "idle" mode and CSU should check for this state.
  10719. //system("reboot -f");
  10720. //sleep(5);
  10721. //system("reboot -f");
  10722. return errn;
  10723. }
  10724. /*===========================================================================
  10725. FUNCTION: Proc_iso1_SessionStopRes
  10726. DESCRIPTION:
  10727. PRE-CONDITION:
  10728. INPUT:
  10729. OUTPUT:
  10730. GLOBAL VARIABLES:
  10731. =============================================================================*/
  10732. int Proc_iso1_SessionStopRes(int AcceptFd)
  10733. {
  10734. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10735. //if it is not the same, the packet should be ignored.
  10736. //STEP 1: ============ Initialize ============
  10737. //int i = 0;
  10738. int errn = 0;
  10739. bitstream_t v2g_tx_stream;
  10740. struct SessionStopResponse_ISO15118_2014 *stp;
  10741. //struct ChargingInfoData *sys;
  10742. size_t pos = 0;
  10743. v2g_tx_stream.pos = &pos;
  10744. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10745. v2g_tx_stream.data = V2GTP_Tx_buf;
  10746. stp = &ShmCcsData->V2GMessage_ISO15118_2014.SessionStopResponse;
  10747. //sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10748. stp->ResponseCode = OK_ISO15118_2014;
  10749. //[HEADER] Check Req SessionID
  10750. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10751. {
  10752. stp->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10753. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10754. errn = -1;
  10755. }
  10756. //Check for SequenceError
  10757. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10758. {
  10759. stp->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10760. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10761. errn = -1;
  10762. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10763. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10764. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10765. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10766. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10767. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10768. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10769. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10770. }
  10771. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10772. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10773. #if PARAMETER_NORMAL_MODE == ENABLE
  10774. SHM_Read_iso1_SessionStopRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10775. #else
  10776. Sudo_Parameter_iso1_SessionStopRes();
  10777. #endif
  10778. //STEP 4: ============ Encode and Send Response Message ===========
  10779. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10780. {
  10781. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Tx]SessionStopRes: fail");
  10782. errn = -1;
  10783. }
  10784. else
  10785. {
  10786. //send response successfully.
  10787. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Tx]SessionStopRes");
  10788. }
  10789. //STEP 5: ============ Update Flags ===========
  10790. EVCOMM_SYS_INFO.ConnectorLocked = FALSE; //Indicating CSU that the Connector is unlocked.
  10791. //Once this is set, the CSU should
  10792. // =========== Annouce to CSU [To-Be Implemented]=============
  10793. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE; //This should be also added to EV Error events.
  10794. // =========== Re-initialized [To-Be Implemented]=============
  10795. //Keep 5% PWM for 2 seconds
  10796. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 2");
  10797. sleep(1);
  10798. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 1");
  10799. sleep(1);
  10800. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 0");
  10801. OutputCpPwmDuty(100);
  10802. //[To-Do] Reset All Share memory
  10803. //[To-Do] CCS Module enter "idle" mode and CSU should check for this state.
  10804. //system("reboot -f");
  10805. //sleep(5);
  10806. //system("reboot -f");
  10807. return errn;
  10808. }
  10809. /*===========================================================================
  10810. FUNCTION: Proc_din_SessionStopReq
  10811. DESCRIPTION:
  10812. PRE-CONDITION:
  10813. INPUT:
  10814. OUTPUT:
  10815. GLOBAL VARIABLES:
  10816. =============================================================================*/
  10817. int Proc_din_SessionStopReq(int AcceptFd)
  10818. {
  10819. int errn = 0;
  10820. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]SessionStopReq");
  10821. //Print the decoded XML Document
  10822. PRINT_XML_DOC_DIN_SessionStopReq(&ccs_exi_doc_DIN);
  10823. //Save into Share Memory
  10824. SHM_Save_din_SessionStopReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10825. errn = Proc_din_SessionStopRes(AcceptFd);
  10826. if (errn == 0)
  10827. {
  10828. //send response successfully.
  10829. }
  10830. else
  10831. {
  10832. sprintf((char*)buf_log_evcomm,
  10833. "[Error][SeccComm][Proc_din_SessionStopReq]Proc_iso1_SessionStopRes(): %d (DEC)",
  10834. errn);
  10835. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10836. }
  10837. return errn;
  10838. }
  10839. /*===========================================================================
  10840. FUNCTION: Proc_iso1_SessionStopReq
  10841. DESCRIPTION:
  10842. PRE-CONDITION:
  10843. INPUT:
  10844. OUTPUT:
  10845. GLOBAL VARIABLES:
  10846. =============================================================================*/
  10847. int Proc_iso1_SessionStopReq(int AcceptFd)
  10848. {
  10849. int errn = 0;
  10850. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]SessionStopReq");
  10851. //Print the decoded XML Document
  10852. PRINT_XML_DOC_ISO1_SessionStopReq(&ccs_exi_doc_ISO1);
  10853. //Save into Share Memory
  10854. SHM_Save_iso1_SessionStopReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10855. errn = Proc_iso1_SessionStopRes(AcceptFd);
  10856. if (errn == 0)
  10857. {
  10858. //send response successfully.
  10859. }
  10860. else
  10861. {
  10862. sprintf((char*)buf_log_evcomm,
  10863. "[Error][SeccComm][Proc_iso1_SessionStopReq]Proc_iso1_SessionStopRes(): %d (DEC)",
  10864. errn);
  10865. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10866. }
  10867. return errn;
  10868. }
  10869. /*===========================================================================
  10870. FUNCTION: V2gMsg_Process_din
  10871. DESCRIPTION:
  10872. PRE-CONDITION:
  10873. INPUT:
  10874. 1. V2gFlowStatus
  10875. OUTPUT:
  10876. GLOBAL VARIABLES:
  10877. 1. V2gFlowStatus
  10878. =============================================================================*/
  10879. int V2gMsg_Process_din(int AcceptFd)
  10880. {
  10881. unsigned char req_is_responsed = FALSE;
  10882. while (req_is_responsed == FALSE)
  10883. {
  10884. //Check if it is in End_Process
  10885. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  10886. {
  10887. break;
  10888. }
  10889. switch(V2gFlowStatus)
  10890. {
  10891. //-------------------------------------------
  10892. case SupportedAppProtocolRequest:
  10893. {
  10894. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  10895. {
  10896. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  10897. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  10898. {
  10899. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10900. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  10901. }
  10902. else
  10903. {
  10904. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
  10905. Update_V2G_Flow_Status(Other_Fault);
  10906. }
  10907. }
  10908. req_is_responsed = TRUE;
  10909. break;
  10910. }
  10911. case SupportedAppProtocolResponse:
  10912. {
  10913. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  10914. {
  10915. Update_V2G_Flow_Status(SessionSetupRequest);
  10916. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10917. }
  10918. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10919. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10920. {
  10921. sprintf((char*)buf_log_evcomm,
  10922. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10923. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10924. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10925. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10926. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10927. }
  10928. else
  10929. {
  10930. }
  10931. break;
  10932. }
  10933. //-------------------------------------------
  10934. case SessionSetupRequest: //19
  10935. {
  10936. if (Proc_din_SessionSetupReq(AcceptFd) == 0)
  10937. {
  10938. Update_V2G_Flow_Status(SessionSetupResponse);
  10939. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10940. }
  10941. else
  10942. {
  10943. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
  10944. Update_V2G_Flow_Status(Other_Fault);
  10945. }
  10946. req_is_responsed = TRUE;
  10947. break;
  10948. }
  10949. case SessionSetupResponse: //20
  10950. {
  10951. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  10952. {
  10953. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  10954. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10955. }
  10956. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10957. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10958. {
  10959. sprintf((char*)buf_log_evcomm,
  10960. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10961. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10962. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10963. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10964. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10965. }
  10966. else
  10967. {
  10968. }
  10969. break;
  10970. }
  10971. //-------------------------------------------
  10972. case ServiceDiscoveryRequest: //21
  10973. {
  10974. if (Proc_din_ServiceDiscoveryReq(AcceptFd) == 0)
  10975. {
  10976. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  10977. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10978. }
  10979. else
  10980. {
  10981. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
  10982. Update_V2G_Flow_Status(Other_Fault);
  10983. }
  10984. req_is_responsed = TRUE;
  10985. break;
  10986. }
  10987. case ServiceDiscoveryResponse: //22
  10988. {
  10989. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  10990. {
  10991. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  10992. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10993. }
  10994. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10995. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10996. {
  10997. sprintf((char*)buf_log_evcomm, "[ERROR]SequenceError(%d) => Tx Res MSG", EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10998. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10999. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11000. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11001. }
  11002. else
  11003. {
  11004. }
  11005. break;
  11006. }
  11007. //-------------------------------------------
  11008. case ServiceAndPaymentSelectionRequest: //25
  11009. {
  11010. if (Proc_din_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  11011. {
  11012. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  11013. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11014. }
  11015. else
  11016. {
  11017. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
  11018. Update_V2G_Flow_Status(Other_Fault);
  11019. }
  11020. req_is_responsed = TRUE;
  11021. break;
  11022. }
  11023. case ServiceAndPaymentSelectionResponse: //26
  11024. {
  11025. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11026. {
  11027. Update_V2G_Flow_Status(AuthorizationRequest);
  11028. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11029. }
  11030. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11031. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11032. {
  11033. sprintf((char*)buf_log_evcomm,
  11034. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11035. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11036. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11037. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11038. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11039. }
  11040. else
  11041. {
  11042. }
  11043. break;
  11044. }
  11045. //-------------------------------------------
  11046. //case ContractAuthenticationReq:
  11047. case AuthorizationRequest: //29
  11048. {
  11049. if (Proc_din_ContractAuthenticationReq(AcceptFd) == 0)
  11050. {
  11051. Update_V2G_Flow_Status(AuthorizationResponse);
  11052. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11053. }
  11054. else
  11055. {
  11056. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  11057. Update_V2G_Flow_Status(Other_Fault);
  11058. }
  11059. req_is_responsed = TRUE;
  11060. break;
  11061. }
  11062. case AuthorizationResponse: //30
  11063. {
  11064. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11065. {
  11066. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11067. if (Proc_din_ContractAuthenticationReq(AcceptFd) == 0)
  11068. {
  11069. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11070. }
  11071. else
  11072. {
  11073. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  11074. Update_V2G_Flow_Status(Other_Fault);
  11075. }
  11076. req_is_responsed = TRUE;
  11077. }
  11078. //Check for ChargeParameterDiscoveryReq
  11079. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11080. {
  11081. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11082. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  11083. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  11084. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11085. ftime(&SeqStartTime);
  11086. #endif
  11087. }
  11088. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11089. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11090. {
  11091. sprintf((char*)buf_log_evcomm,
  11092. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11093. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11094. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11095. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11096. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11097. }
  11098. else
  11099. {
  11100. }
  11101. break;
  11102. }
  11103. //-------------------------------------------
  11104. case ChargeParameterDiscoveryRequest: //35
  11105. {
  11106. if (Proc_din_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11107. {
  11108. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  11109. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11110. }
  11111. else
  11112. {
  11113. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  11114. Update_V2G_Flow_Status(Other_Fault);
  11115. }
  11116. req_is_responsed = TRUE;
  11117. break;
  11118. }
  11119. case ChargeParameterDiscoveryResponse:
  11120. {
  11121. //STEP 1: Check for Process Timeout
  11122. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11123. ftime(&SeqEndTime);
  11124. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  11125. {
  11126. sprintf((char*)buf_log_evcomm,
  11127. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  11128. DiffTimeb(SeqStartTime, SeqEndTime),
  11129. V2G_SECC_ChargingParameter_Performance_Time);
  11130. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11131. Update_V2G_Flow_Status(Sequence_Timeout);
  11132. break;
  11133. }
  11134. #endif
  11135. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11136. {
  11137. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11138. if (Proc_din_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11139. {
  11140. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11141. }
  11142. else
  11143. {
  11144. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  11145. Update_V2G_Flow_Status(Other_Fault);
  11146. }
  11147. req_is_responsed = TRUE;
  11148. break;
  11149. }
  11150. //STEP 2: Check for CableCheckReq message
  11151. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11152. {
  11153. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11154. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]CableCheckReqReq: isolated?");
  11155. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  11156. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11157. Update_V2G_Flow_Status(CableCheckRequest);
  11158. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11159. ftime(&SeqStartTime);
  11160. #endif
  11161. }
  11162. //STEP 3: Wait for PowerDeliveryReq Message
  11163. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11164. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11165. {
  11166. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11167. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11168. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11169. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11170. ftime(&SeqStartTime);
  11171. #endif
  11172. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  11173. {
  11174. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11175. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11176. }
  11177. else
  11178. {
  11179. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11180. Update_V2G_Flow_Status(Other_Fault);
  11181. }
  11182. }
  11183. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11184. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11185. {
  11186. sprintf((char*)buf_log_evcomm,
  11187. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11188. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11189. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11190. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11191. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11192. }
  11193. else
  11194. {
  11195. }
  11196. break;
  11197. }
  11198. //-------------------------------------------
  11199. case CableCheckRequest: //37
  11200. {
  11201. //STEP 3: Execute Cable Check Process
  11202. if (Proc_din_CableCheckReq(AcceptFd) == 0)
  11203. {
  11204. Update_V2G_Flow_Status(CableCheckResponse);
  11205. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11206. }
  11207. else
  11208. {
  11209. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  11210. Update_V2G_Flow_Status(Other_Fault);
  11211. }
  11212. req_is_responsed = TRUE;
  11213. break;
  11214. }
  11215. case CableCheckResponse: //38
  11216. {
  11217. //STEP 1: Check for Process Timeout
  11218. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11219. ftime(&SeqEndTime);
  11220. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  11221. {
  11222. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CableCheck] end counting...");
  11223. sprintf((char*)buf_log_evcomm,
  11224. "CableCheck Timeout - (%.02lf of %d ms)\n",
  11225. DiffTimeb(SeqStartTime, SeqEndTime),
  11226. V2G_SECC_CableCheck_Performance_Time);
  11227. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11228. Update_V2G_Flow_Status(Sequence_Timeout);
  11229. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11230. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  11231. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11232. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11233. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11234. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11235. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  11236. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  11237. break;
  11238. }
  11239. #endif
  11240. //STEP 2: Check for CableCheckReq message
  11241. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11242. {
  11243. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11244. //STEP 3: Execute Cable Check Process
  11245. if (Proc_din_CableCheckReq(AcceptFd) == 0)
  11246. {
  11247. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11248. }
  11249. else
  11250. {
  11251. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  11252. Update_V2G_Flow_Status(Other_Fault);
  11253. }
  11254. req_is_responsed = TRUE;
  11255. }
  11256. //STEP 3: Check for PreChargeReq message
  11257. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11258. {
  11259. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11260. Update_V2G_Flow_Status(PreChargeRequest);
  11261. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]PreChargeReqReq: waiting for precharge voltage...");
  11262. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11263. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  11264. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11265. ftime(&SeqStartTime);
  11266. #endif
  11267. }
  11268. //STEP 3: Wait for PowerDeliveryReq Message
  11269. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11270. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11271. {
  11272. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11273. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11274. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11275. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11276. ftime(&SeqStartTime);
  11277. #endif
  11278. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  11279. {
  11280. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11281. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11282. }
  11283. else
  11284. {
  11285. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11286. Update_V2G_Flow_Status(Other_Fault);
  11287. }
  11288. }
  11289. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11290. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11291. {
  11292. sprintf((char*)buf_log_evcomm,
  11293. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11294. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11295. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11296. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11297. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11298. }
  11299. else
  11300. {
  11301. }
  11302. break;
  11303. }
  11304. //-------------------------------------------
  11305. case PreChargeRequest: //39
  11306. {
  11307. if (Proc_din_PreChargeReq(AcceptFd) == 0)
  11308. {
  11309. Update_V2G_Flow_Status(PreChargeResponse);
  11310. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11311. }
  11312. else
  11313. {
  11314. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  11315. Update_V2G_Flow_Status(Other_Fault);
  11316. }
  11317. req_is_responsed = TRUE;
  11318. break;
  11319. }
  11320. case PreChargeResponse: //40
  11321. {
  11322. //STEP 1: Check for Process Timeout
  11323. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11324. ftime(&SeqEndTime);
  11325. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  11326. {
  11327. sprintf((char*)buf_log_evcomm,
  11328. "Precharge Timeout - (%.02lf of %d ms)\n",
  11329. DiffTimeb(SeqStartTime, SeqEndTime),
  11330. V2G_SECC_PreCharge_Performance_Time);
  11331. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11332. Update_V2G_Flow_Status(Sequence_Timeout);
  11333. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11334. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  11335. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11336. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11337. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11338. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11339. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  11340. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  11341. break;
  11342. }
  11343. #endif
  11344. //STEP 2: Check for PreChargeReq message
  11345. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11346. {
  11347. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11348. if (Proc_din_PreChargeReq(AcceptFd) == 0)
  11349. {
  11350. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11351. }
  11352. else
  11353. {
  11354. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  11355. Update_V2G_Flow_Status(Other_Fault);
  11356. }
  11357. req_is_responsed = TRUE;
  11358. }
  11359. //STEP 3: Check for PowerDeliveryReq message
  11360. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11361. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11362. {
  11363. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11364. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  11365. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  11366. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11367. ftime(&SeqStartTime);
  11368. #endif
  11369. }
  11370. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11371. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11372. {
  11373. sprintf((char*)buf_log_evcomm,
  11374. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11375. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11376. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11377. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11378. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11379. }
  11380. else
  11381. {
  11382. }
  11383. break;
  11384. }
  11385. //-------------------------------------------
  11386. case PowerDeliveryRequestStart: //41
  11387. {
  11388. if (Proc_din_PowerDeliveryStartReq(AcceptFd) == 0)
  11389. {
  11390. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  11391. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11392. }
  11393. else
  11394. {
  11395. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
  11396. Update_V2G_Flow_Status(Other_Fault);
  11397. }
  11398. req_is_responsed = TRUE;
  11399. break;
  11400. }
  11401. case PowerDeliveryResponsetStart: //42
  11402. {
  11403. //STEP 1: Check for Process Timeout
  11404. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11405. if (ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  11406. {
  11407. ftime(&SeqEndTime);
  11408. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  11409. {
  11410. sprintf((char*)buf_log_evcomm,
  11411. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  11412. DiffTimeb(SeqStartTime, SeqEndTime),
  11413. 2000);
  11414. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11415. Update_V2G_Flow_Status(Sequence_Timeout);
  11416. }
  11417. break;
  11418. }
  11419. #endif
  11420. //STEP 2: Wait for CurrentDemandReq Message
  11421. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  11422. {
  11423. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11424. Update_V2G_Flow_Status(CurrentDemandRequest);
  11425. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]CurrentDemandReqReq: energy transfering...");
  11426. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  11427. }
  11428. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11429. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11430. {
  11431. sprintf((char*)buf_log_evcomm,
  11432. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11433. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11434. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11435. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11436. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11437. }
  11438. else
  11439. {
  11440. }
  11441. break;
  11442. }
  11443. //-------------------------------------------
  11444. case CurrentDemandRequest: //45,
  11445. {
  11446. if (Proc_din_CurrentDemandReq(AcceptFd) == 0)
  11447. {
  11448. Update_V2G_Flow_Status(CurrentDemandResponse);
  11449. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11450. }
  11451. else
  11452. {
  11453. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  11454. Update_V2G_Flow_Status(Other_Fault);
  11455. }
  11456. req_is_responsed = TRUE;
  11457. break;
  11458. }
  11459. case CurrentDemandResponse: //46,
  11460. {
  11461. //STEP 1: Wait for CurrentDemandReq Message
  11462. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  11463. {
  11464. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11465. if (Proc_din_CurrentDemandReq(AcceptFd) == 0)
  11466. {
  11467. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11468. }
  11469. else
  11470. {
  11471. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  11472. Update_V2G_Flow_Status(Other_Fault);
  11473. }
  11474. req_is_responsed = TRUE;
  11475. break;
  11476. }
  11477. //STEP 2: Wait for PowerDeliveryReq Message
  11478. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11479. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11480. {
  11481. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11482. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11483. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  11484. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11485. ftime(&SeqStartTime);
  11486. #endif
  11487. }
  11488. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11489. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11490. {
  11491. sprintf((char*)buf_log_evcomm,
  11492. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11493. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11494. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11495. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11496. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11497. }
  11498. else
  11499. {
  11500. }
  11501. break;
  11502. }
  11503. //-------------------------------------------
  11504. case PowerDeliveryRequestStop: //49,
  11505. {
  11506. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  11507. {
  11508. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11509. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11510. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11511. ftime(&SeqStartTime);
  11512. #endif
  11513. }
  11514. else
  11515. {
  11516. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11517. Update_V2G_Flow_Status(Other_Fault);
  11518. }
  11519. req_is_responsed = TRUE;
  11520. break;
  11521. }
  11522. case PowerDeliveryResponseStop: //50,
  11523. {
  11524. //STEP 1: Check for Process Timeout
  11525. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11526. ftime(&SeqEndTime);
  11527. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  11528. {
  11529. sprintf((char*)buf_log_evcomm,
  11530. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  11531. DiffTimeb(SeqStartTime, SeqEndTime),
  11532. 2000);
  11533. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11534. Update_V2G_Flow_Status(Sequence_Timeout);
  11535. break;
  11536. }
  11537. #endif
  11538. //STEP 2: Check for WeldingDetectionReq Message
  11539. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  11540. {
  11541. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11542. Update_V2G_Flow_Status(WeldingDetectionRequest);
  11543. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]WeldingDetectionReq: ongoing...");
  11544. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  11545. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11546. ftime(&SeqStartTime);
  11547. #endif
  11548. }
  11549. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  11550. {
  11551. Update_V2G_Flow_Status(SessionStopRequest);
  11552. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11553. if (Proc_din_SessionStopReq(AcceptFd) == 0)
  11554. {
  11555. Update_V2G_Flow_Status(SessionStopResponse);
  11556. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11557. }
  11558. else
  11559. {
  11560. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  11561. Update_V2G_Flow_Status(Other_Fault);
  11562. }
  11563. break;
  11564. }
  11565. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11566. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11567. {
  11568. sprintf((char*)buf_log_evcomm,
  11569. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11570. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11571. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11572. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11573. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11574. }
  11575. else
  11576. {
  11577. }
  11578. break;
  11579. }
  11580. //-------------------------------------------
  11581. case WeldingDetectionRequest: //51,
  11582. {
  11583. if (Proc_din_WeldingDetectionReq(AcceptFd) == 0)
  11584. {
  11585. Update_V2G_Flow_Status(WeldingDetectionResponse);
  11586. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11587. }
  11588. else
  11589. {
  11590. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  11591. Update_V2G_Flow_Status(Other_Fault);
  11592. }
  11593. req_is_responsed = TRUE;
  11594. break;
  11595. }
  11596. case WeldingDetectionResponse: //52,
  11597. {
  11598. //STEP 1: Check for Process Timeout
  11599. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11600. ftime(&SeqEndTime);
  11601. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  11602. {
  11603. sprintf((char*)buf_log_evcomm,
  11604. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  11605. DiffTimeb(SeqStartTime, SeqEndTime),
  11606. V2G_SECC_WeldingDetection_Performance_Time);
  11607. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11608. Update_V2G_Flow_Status(Sequence_Timeout);
  11609. break;
  11610. }
  11611. #endif
  11612. //STEP 2: Check for WeldingDetectionReq Message
  11613. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  11614. {
  11615. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11616. if (Proc_din_WeldingDetectionReq(AcceptFd) == 0)
  11617. {
  11618. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11619. }
  11620. else
  11621. {
  11622. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  11623. Update_V2G_Flow_Status(Other_Fault);
  11624. }
  11625. req_is_responsed = TRUE;
  11626. }
  11627. //STEP 3: Check for SessionStopReq Message
  11628. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  11629. {
  11630. Update_V2G_Flow_Status(SessionStopRequest);
  11631. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11632. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  11633. }
  11634. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11635. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11636. {
  11637. sprintf((char*)buf_log_evcomm,
  11638. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11639. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11640. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11641. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11642. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11643. }
  11644. else
  11645. {
  11646. }
  11647. break;
  11648. }
  11649. //-------------------------------------------
  11650. case SessionStopRequest: //53,
  11651. {
  11652. if (Proc_din_SessionStopReq(AcceptFd) == 0)
  11653. {
  11654. Update_V2G_Flow_Status(SessionStopResponse);
  11655. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11656. }
  11657. else
  11658. {
  11659. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  11660. Update_V2G_Flow_Status(Other_Fault);
  11661. }
  11662. req_is_responsed = TRUE;
  11663. break;
  11664. }
  11665. case SessionStopResponse: //54,
  11666. {
  11667. break;
  11668. }
  11669. //-------------------------------------------
  11670. default:
  11671. {
  11672. break;
  11673. }
  11674. }
  11675. }
  11676. return 0;
  11677. }
  11678. /*===========================================================================
  11679. FUNCTION: V2gMsg_Process_iso1_DC
  11680. DESCRIPTION:
  11681. PRE-CONDITION:
  11682. INPUT:
  11683. 1. V2gFlowStatus
  11684. OUTPUT:
  11685. GLOBAL VARIABLES:
  11686. 1. V2gFlowStatus
  11687. =============================================================================*/
  11688. int V2gMsg_Process_iso1_DC(int AcceptFd)
  11689. {
  11690. unsigned char req_is_responsed = FALSE;
  11691. while (req_is_responsed == FALSE)
  11692. {
  11693. //Check if it is in End_Process
  11694. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  11695. {
  11696. break;
  11697. }
  11698. switch(V2gFlowStatus)
  11699. {
  11700. //-------------------------------------------
  11701. case SupportedAppProtocolRequest:
  11702. {
  11703. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  11704. {
  11705. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  11706. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  11707. {
  11708. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11709. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  11710. }
  11711. else
  11712. {
  11713. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
  11714. Update_V2G_Flow_Status(Other_Fault);
  11715. }
  11716. }
  11717. req_is_responsed = TRUE;
  11718. break;
  11719. }
  11720. case SupportedAppProtocolResponse:
  11721. {
  11722. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  11723. {
  11724. Update_V2G_Flow_Status(SessionSetupRequest);
  11725. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11726. }
  11727. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11728. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11729. {
  11730. sprintf((char*)buf_log_evcomm,
  11731. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11732. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11733. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11734. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11735. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11736. }
  11737. else
  11738. {
  11739. }
  11740. break;
  11741. }
  11742. //-------------------------------------------
  11743. case SessionSetupRequest: //19
  11744. {
  11745. if (Proc_iso1_SessionSetupReq(AcceptFd) == 0)
  11746. {
  11747. Update_V2G_Flow_Status(SessionSetupResponse);
  11748. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11749. }
  11750. else
  11751. {
  11752. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
  11753. Update_V2G_Flow_Status(Other_Fault);
  11754. }
  11755. req_is_responsed = TRUE;
  11756. break;
  11757. }
  11758. case SessionSetupResponse: //20
  11759. {
  11760. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  11761. {
  11762. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  11763. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11764. }
  11765. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11766. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11767. {
  11768. sprintf((char*)buf_log_evcomm,
  11769. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11770. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11771. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11772. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11773. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11774. }
  11775. else
  11776. {
  11777. }
  11778. break;
  11779. }
  11780. //-------------------------------------------
  11781. case ServiceDiscoveryRequest: //21
  11782. {
  11783. if (Proc_iso1_ServiceDiscoveryReq(AcceptFd) == 0)
  11784. {
  11785. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  11786. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11787. }
  11788. else
  11789. {
  11790. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
  11791. Update_V2G_Flow_Status(Other_Fault);
  11792. }
  11793. req_is_responsed = TRUE;
  11794. break;
  11795. }
  11796. case ServiceDiscoveryResponse: //22
  11797. {
  11798. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  11799. {
  11800. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  11801. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11802. }
  11803. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11804. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11805. {
  11806. sprintf((char*)buf_log_evcomm,
  11807. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11808. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11809. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11810. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11811. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11812. }
  11813. else
  11814. {
  11815. }
  11816. break;
  11817. }
  11818. //-------------------------------------------
  11819. case ServiceAndPaymentSelectionRequest: //25
  11820. {
  11821. if (Proc_iso1_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  11822. {
  11823. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  11824. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11825. }
  11826. else
  11827. {
  11828. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
  11829. Update_V2G_Flow_Status(Other_Fault);
  11830. }
  11831. req_is_responsed = TRUE;
  11832. break;
  11833. }
  11834. case ServiceAndPaymentSelectionResponse: //26
  11835. {
  11836. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11837. {
  11838. Update_V2G_Flow_Status(AuthorizationRequest);
  11839. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11840. }
  11841. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11842. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11843. {
  11844. sprintf((char*)buf_log_evcomm,
  11845. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11846. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11847. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11848. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11849. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11850. }
  11851. else
  11852. {
  11853. }
  11854. break;
  11855. }
  11856. //-------------------------------------------
  11857. //case ContractAuthenticationReq:
  11858. case AuthorizationRequest: //29
  11859. {
  11860. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  11861. {
  11862. Update_V2G_Flow_Status(AuthorizationResponse);
  11863. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11864. }
  11865. else
  11866. {
  11867. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  11868. Update_V2G_Flow_Status(Other_Fault);
  11869. }
  11870. req_is_responsed = TRUE;
  11871. break;
  11872. }
  11873. case AuthorizationResponse: //30
  11874. {
  11875. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11876. {
  11877. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11878. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  11879. {
  11880. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11881. }
  11882. else
  11883. {
  11884. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  11885. Update_V2G_Flow_Status(Other_Fault);
  11886. }
  11887. req_is_responsed = TRUE;
  11888. }
  11889. //Check for ChargeParameterDiscoveryReq
  11890. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11891. {
  11892. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11893. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  11894. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  11895. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11896. ftime(&SeqStartTime);
  11897. #endif
  11898. }
  11899. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11900. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11901. {
  11902. sprintf((char*)buf_log_evcomm,
  11903. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11904. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11905. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11906. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11907. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11908. }
  11909. else
  11910. {
  11911. }
  11912. break;
  11913. }
  11914. //-------------------------------------------
  11915. case ChargeParameterDiscoveryRequest: //35
  11916. {
  11917. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11918. {
  11919. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  11920. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11921. }
  11922. else
  11923. {
  11924. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  11925. Update_V2G_Flow_Status(Other_Fault);
  11926. }
  11927. req_is_responsed = TRUE;
  11928. break;
  11929. }
  11930. case ChargeParameterDiscoveryResponse:
  11931. {
  11932. //STEP 1: Check for Process Timeout
  11933. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11934. ftime(&SeqEndTime);
  11935. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  11936. {
  11937. sprintf((char*)buf_log_evcomm,
  11938. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  11939. DiffTimeb(SeqStartTime, SeqEndTime),
  11940. V2G_SECC_ChargingParameter_Performance_Time);
  11941. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11942. Update_V2G_Flow_Status(Sequence_Timeout);
  11943. break;
  11944. }
  11945. #endif
  11946. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11947. {
  11948. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11949. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11950. {
  11951. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11952. }
  11953. else
  11954. {
  11955. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  11956. Update_V2G_Flow_Status(Other_Fault);
  11957. }
  11958. req_is_responsed = TRUE;
  11959. }
  11960. //STEP 2: Check for CableCheckReq message
  11961. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11962. {
  11963. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11964. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]CableCheckReqReq: isolated?");
  11965. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  11966. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11967. Update_V2G_Flow_Status(CableCheckRequest);
  11968. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11969. ftime(&SeqStartTime);
  11970. #endif
  11971. }
  11972. //STEP 3: Wait for PowerDeliveryReq Message
  11973. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11974. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11975. {
  11976. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11977. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11978. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11979. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11980. ftime(&SeqStartTime);
  11981. #endif
  11982. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  11983. {
  11984. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11985. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11986. }
  11987. else
  11988. {
  11989. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11990. Update_V2G_Flow_Status(Other_Fault);
  11991. }
  11992. break;
  11993. }
  11994. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11995. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11996. {
  11997. sprintf((char*)buf_log_evcomm,
  11998. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11999. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12000. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12001. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12002. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12003. }
  12004. else
  12005. {
  12006. }
  12007. break;
  12008. }
  12009. //-------------------------------------------
  12010. case CableCheckRequest: //37
  12011. {
  12012. //STEP 3: Execute Cable Check Process
  12013. if (Proc_iso1_CableCheckReq(AcceptFd) == 0)
  12014. {
  12015. Update_V2G_Flow_Status(CableCheckResponse);
  12016. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12017. }
  12018. else
  12019. {
  12020. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  12021. Update_V2G_Flow_Status(Other_Fault);
  12022. }
  12023. req_is_responsed = TRUE;
  12024. break;
  12025. }
  12026. case CableCheckResponse: //38
  12027. {
  12028. //STEP 1: Check for Process Timeout
  12029. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12030. ftime(&SeqEndTime);
  12031. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  12032. {
  12033. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CableCheck] end counting...");
  12034. sprintf((char*)buf_log_evcomm,
  12035. "CableCheck Timeout - (%.02lf of %d ms)\n",
  12036. DiffTimeb(SeqStartTime, SeqEndTime),
  12037. V2G_SECC_CableCheck_Performance_Time);
  12038. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12039. Update_V2G_Flow_Status(Sequence_Timeout);
  12040. //Update_ShmStatusCode(); //[To-Do] to be implemented
  12041. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  12042. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12043. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12044. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12045. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  12046. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  12047. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  12048. break;
  12049. }
  12050. #endif
  12051. //STEP 2: Check for CableCheckReq message
  12052. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  12053. {
  12054. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12055. //STEP 3: Execute Cable Check Process
  12056. if (Proc_iso1_CableCheckReq(AcceptFd) == 0)
  12057. {
  12058. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12059. }
  12060. else
  12061. {
  12062. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  12063. Update_V2G_Flow_Status(Other_Fault);
  12064. }
  12065. req_is_responsed = TRUE;
  12066. }
  12067. //STEP 3: Check for PreChargeReq message
  12068. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  12069. {
  12070. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12071. Update_V2G_Flow_Status(PreChargeRequest);
  12072. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]PreChargeReqReq: waiting for precharge voltage...");
  12073. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  12074. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  12075. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12076. ftime(&SeqStartTime);
  12077. #endif
  12078. }
  12079. //STEP 3: Wait for PowerDeliveryReq Message
  12080. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12081. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12082. {
  12083. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12084. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12085. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  12086. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12087. ftime(&SeqStartTime);
  12088. #endif
  12089. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12090. {
  12091. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12092. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12093. }
  12094. else
  12095. {
  12096. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  12097. Update_V2G_Flow_Status(Other_Fault);
  12098. }
  12099. }
  12100. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12101. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12102. {
  12103. sprintf((char*)buf_log_evcomm,
  12104. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12105. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12106. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12107. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12108. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12109. }
  12110. else
  12111. {
  12112. }
  12113. break;
  12114. }
  12115. //-------------------------------------------
  12116. case PreChargeRequest: //39
  12117. {
  12118. if (Proc_iso1_PreChargeReq(AcceptFd) == 0)
  12119. {
  12120. Update_V2G_Flow_Status(PreChargeResponse);
  12121. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12122. }
  12123. else
  12124. {
  12125. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  12126. Update_V2G_Flow_Status(Other_Fault);
  12127. }
  12128. req_is_responsed = TRUE;
  12129. break;
  12130. }
  12131. case PreChargeResponse: //40
  12132. {
  12133. //STEP 1: Check for Process Timeout
  12134. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12135. ftime(&SeqEndTime);
  12136. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  12137. {
  12138. sprintf((char*)buf_log_evcomm,
  12139. "Precharge Timeout - (%.02lf of %d ms)\n",
  12140. DiffTimeb(SeqStartTime, SeqEndTime),
  12141. V2G_SECC_PreCharge_Performance_Time);
  12142. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12143. Update_V2G_Flow_Status(Sequence_Timeout);
  12144. //Update_ShmStatusCode(); //[To-Do] to be implemented
  12145. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  12146. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12147. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12148. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12149. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  12150. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  12151. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  12152. break;
  12153. }
  12154. #endif
  12155. //STEP 2: Check for PreChargeReq message
  12156. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  12157. {
  12158. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12159. if (Proc_iso1_PreChargeReq(AcceptFd) == 0)
  12160. {
  12161. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12162. }
  12163. else
  12164. {
  12165. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  12166. Update_V2G_Flow_Status(Other_Fault);
  12167. }
  12168. req_is_responsed = TRUE;
  12169. }
  12170. //STEP 3: Check for PowerDeliveryReq message
  12171. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12172. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12173. {
  12174. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12175. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  12176. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  12177. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12178. ftime(&SeqStartTime);
  12179. #endif
  12180. }
  12181. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12182. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12183. {
  12184. sprintf((char*)buf_log_evcomm,
  12185. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12186. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12187. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12188. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12189. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12190. }
  12191. else
  12192. {
  12193. }
  12194. break;
  12195. }
  12196. //-------------------------------------------
  12197. case PowerDeliveryRequestStart: //41
  12198. {
  12199. if (Proc_iso1_PowerDeliveryStartReq(AcceptFd) == 0)
  12200. {
  12201. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  12202. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12203. }
  12204. else
  12205. {
  12206. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
  12207. Update_V2G_Flow_Status(Other_Fault);
  12208. }
  12209. req_is_responsed = TRUE;
  12210. break;
  12211. }
  12212. case PowerDeliveryResponsetStart: //42
  12213. {
  12214. //STEP 1: Check for Process Timeout
  12215. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12216. if (ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  12217. {
  12218. ftime(&SeqEndTime);
  12219. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  12220. {
  12221. sprintf((char*)buf_log_evcomm,
  12222. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  12223. DiffTimeb(SeqStartTime, SeqEndTime),
  12224. 2000);
  12225. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12226. Update_V2G_Flow_Status(Sequence_Timeout);
  12227. }
  12228. break;
  12229. }
  12230. #endif
  12231. //STEP 2: Wait for CurrentDemandReq Message
  12232. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  12233. {
  12234. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12235. Update_V2G_Flow_Status(CurrentDemandRequest);
  12236. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]CurrentDemandReqReq: energy transfering...");
  12237. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  12238. }
  12239. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12240. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12241. {
  12242. sprintf((char*)buf_log_evcomm,
  12243. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12244. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12245. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12246. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12247. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12248. }
  12249. else
  12250. {
  12251. }
  12252. break;
  12253. }
  12254. //-------------------------------------------
  12255. case CurrentDemandRequest: //45,
  12256. {
  12257. if (Proc_iso1_CurrentDemandReq(AcceptFd) == 0)
  12258. {
  12259. Update_V2G_Flow_Status(CurrentDemandResponse);
  12260. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12261. }
  12262. else
  12263. {
  12264. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  12265. Update_V2G_Flow_Status(Other_Fault);
  12266. }
  12267. req_is_responsed = TRUE;
  12268. break;
  12269. }
  12270. case CurrentDemandResponse: //46,
  12271. {
  12272. //STEP 1: Wait for CurrentDemandReq Message
  12273. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  12274. {
  12275. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12276. if (Proc_iso1_CurrentDemandReq(AcceptFd) == 0)
  12277. {
  12278. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12279. }
  12280. else
  12281. {
  12282. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  12283. Update_V2G_Flow_Status(Other_Fault);
  12284. }
  12285. req_is_responsed = TRUE;
  12286. }
  12287. //STEP 2: Wait for PowerDeliveryReq Message
  12288. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12289. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12290. {
  12291. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12292. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12293. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  12294. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12295. ftime(&SeqStartTime);
  12296. #endif
  12297. }
  12298. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12299. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12300. {
  12301. sprintf((char*)buf_log_evcomm,
  12302. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12303. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12304. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12305. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12306. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12307. }
  12308. else
  12309. {
  12310. }
  12311. break;
  12312. }
  12313. //-------------------------------------------
  12314. case PowerDeliveryRequestStop: //49,
  12315. {
  12316. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12317. {
  12318. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12319. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12320. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12321. ftime(&SeqStartTime);
  12322. #endif
  12323. }
  12324. else
  12325. {
  12326. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  12327. Update_V2G_Flow_Status(Other_Fault);
  12328. }
  12329. req_is_responsed = TRUE;
  12330. break;
  12331. }
  12332. case PowerDeliveryResponseStop: //50,
  12333. {
  12334. //STEP 1: Check for Process Timeout
  12335. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12336. ftime(&SeqEndTime);
  12337. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  12338. {
  12339. sprintf((char*)buf_log_evcomm,
  12340. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12341. DiffTimeb(SeqStartTime, SeqEndTime),
  12342. 2000);
  12343. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12344. Update_V2G_Flow_Status(Sequence_Timeout);
  12345. break;
  12346. }
  12347. #endif
  12348. //STEP 2: Check for WeldingDetectionReq Message
  12349. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  12350. {
  12351. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12352. Update_V2G_Flow_Status(WeldingDetectionRequest);
  12353. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]WeldingDetectionReq: ongoing...");
  12354. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  12355. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12356. ftime(&SeqStartTime);
  12357. #endif
  12358. }
  12359. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12360. {
  12361. Update_V2G_Flow_Status(SessionStopRequest);
  12362. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12363. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12364. {
  12365. Update_V2G_Flow_Status(SessionStopResponse);
  12366. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12367. }
  12368. else
  12369. {
  12370. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  12371. Update_V2G_Flow_Status(Other_Fault);
  12372. }
  12373. }
  12374. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12375. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12376. {
  12377. sprintf((char*)buf_log_evcomm,
  12378. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12379. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12380. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12381. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12382. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12383. }
  12384. else
  12385. {
  12386. }
  12387. break;
  12388. }
  12389. //-------------------------------------------
  12390. case WeldingDetectionRequest: //51,
  12391. {
  12392. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  12393. {
  12394. Update_V2G_Flow_Status(WeldingDetectionResponse);
  12395. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12396. }
  12397. else
  12398. {
  12399. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  12400. Update_V2G_Flow_Status(Other_Fault);
  12401. }
  12402. req_is_responsed = TRUE;
  12403. break;
  12404. }
  12405. case WeldingDetectionResponse: //52,
  12406. {
  12407. //STEP 1: Check for Process Timeout
  12408. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12409. ftime(&SeqEndTime);
  12410. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  12411. {
  12412. sprintf((char*)buf_log_evcomm,
  12413. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12414. DiffTimeb(SeqStartTime, SeqEndTime),
  12415. V2G_SECC_WeldingDetection_Performance_Time);
  12416. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12417. Update_V2G_Flow_Status(Sequence_Timeout);
  12418. break;
  12419. }
  12420. #endif
  12421. //STEP 2: Check for WeldingDetectionReq Message
  12422. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  12423. {
  12424. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12425. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  12426. {
  12427. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12428. }
  12429. else
  12430. {
  12431. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  12432. Update_V2G_Flow_Status(Other_Fault);
  12433. }
  12434. req_is_responsed = TRUE;
  12435. }
  12436. //STEP 3: Check for SessionStopReq Message
  12437. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12438. {
  12439. Update_V2G_Flow_Status(SessionStopRequest);
  12440. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12441. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  12442. }
  12443. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12444. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12445. {
  12446. sprintf((char*)buf_log_evcomm,
  12447. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12448. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12449. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12450. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12451. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12452. }
  12453. else
  12454. {
  12455. }
  12456. break;
  12457. }
  12458. //-------------------------------------------
  12459. case SessionStopRequest: //53,
  12460. {
  12461. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12462. {
  12463. Update_V2G_Flow_Status(SessionStopResponse);
  12464. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12465. }
  12466. else
  12467. {
  12468. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  12469. Update_V2G_Flow_Status(Other_Fault);
  12470. }
  12471. req_is_responsed = TRUE;
  12472. break;
  12473. }
  12474. case SessionStopResponse: //54,
  12475. {
  12476. break;
  12477. }
  12478. //-------------------------------------------
  12479. default:
  12480. {
  12481. break;
  12482. }
  12483. }
  12484. }
  12485. return 0;
  12486. }
  12487. /*===========================================================================
  12488. FUNCTION: V2gMsg_Process_iso1_AC
  12489. DESCRIPTION:
  12490. PRE-CONDITION:
  12491. INPUT:
  12492. 1. V2gFlowStatus
  12493. OUTPUT:
  12494. GLOBAL VARIABLES:
  12495. 1. V2gFlowStatus
  12496. =============================================================================*/
  12497. int V2gMsg_Process_iso1_AC(int AcceptFd)
  12498. {
  12499. unsigned char req_is_responsed = FALSE;
  12500. while (req_is_responsed == FALSE)
  12501. {
  12502. //Check if it is in End_Process
  12503. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  12504. {
  12505. break;
  12506. }
  12507. switch(V2gFlowStatus)
  12508. {
  12509. //-------------------------------------------
  12510. case SupportedAppProtocolRequest: //17
  12511. {
  12512. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  12513. {
  12514. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  12515. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  12516. {
  12517. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12518. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  12519. }
  12520. else
  12521. {
  12522. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
  12523. Update_V2G_Flow_Status(Other_Fault);
  12524. }
  12525. }
  12526. req_is_responsed = TRUE;
  12527. break;
  12528. }
  12529. case SupportedAppProtocolResponse: //18
  12530. {
  12531. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  12532. {
  12533. Update_V2G_Flow_Status(SessionSetupRequest);
  12534. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12535. }
  12536. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12537. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12538. {
  12539. sprintf((char*)buf_log_evcomm,
  12540. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12541. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12542. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12543. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12544. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12545. }
  12546. else
  12547. {
  12548. }
  12549. break;
  12550. }
  12551. //-------------------------------------------
  12552. case SessionSetupRequest: //19
  12553. {
  12554. if (Proc_iso1_SessionSetupReq(AcceptFd) == 0)
  12555. {
  12556. Update_V2G_Flow_Status(SessionSetupResponse);
  12557. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12558. }
  12559. else
  12560. {
  12561. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
  12562. Update_V2G_Flow_Status(Other_Fault);
  12563. }
  12564. req_is_responsed = TRUE;
  12565. break;
  12566. }
  12567. case SessionSetupResponse: //20
  12568. {
  12569. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  12570. {
  12571. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  12572. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12573. }
  12574. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12575. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12576. {
  12577. sprintf((char*)buf_log_evcomm,
  12578. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12579. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12580. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12581. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12582. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12583. }
  12584. else
  12585. {
  12586. }
  12587. break;
  12588. }
  12589. //-------------------------------------------
  12590. case ServiceDiscoveryRequest: //21
  12591. {
  12592. if (Proc_iso1_ServiceDiscoveryReq(AcceptFd) == 0)
  12593. {
  12594. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  12595. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12596. }
  12597. else
  12598. {
  12599. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
  12600. Update_V2G_Flow_Status(Other_Fault);
  12601. }
  12602. req_is_responsed = TRUE;
  12603. break;
  12604. }
  12605. case ServiceDiscoveryResponse: //22
  12606. {
  12607. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  12608. {
  12609. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  12610. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12611. }
  12612. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12613. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12614. {
  12615. sprintf((char*)buf_log_evcomm,
  12616. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12617. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12618. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12619. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12620. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12621. }
  12622. else
  12623. {
  12624. }
  12625. break;
  12626. }
  12627. //-------------------------------------------
  12628. case ServiceAndPaymentSelectionRequest: //25
  12629. {
  12630. if (Proc_iso1_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  12631. {
  12632. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  12633. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12634. }
  12635. else
  12636. {
  12637. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
  12638. Update_V2G_Flow_Status(Other_Fault);
  12639. }
  12640. req_is_responsed = TRUE;
  12641. break;
  12642. }
  12643. case ServiceAndPaymentSelectionResponse://26
  12644. {
  12645. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  12646. {
  12647. Update_V2G_Flow_Status(AuthorizationRequest);
  12648. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12649. }
  12650. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12651. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12652. {
  12653. sprintf((char*)buf_log_evcomm,
  12654. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12655. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12656. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12657. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12658. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12659. }
  12660. else
  12661. {
  12662. }
  12663. break;
  12664. }
  12665. //-------------------------------------------
  12666. //case ContractAuthenticationReq:
  12667. case AuthorizationRequest: //29
  12668. {
  12669. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  12670. {
  12671. Update_V2G_Flow_Status(AuthorizationResponse);
  12672. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12673. }
  12674. else
  12675. {
  12676. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  12677. Update_V2G_Flow_Status(Other_Fault);
  12678. }
  12679. break;
  12680. }
  12681. case AuthorizationResponse: //30
  12682. {
  12683. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  12684. {
  12685. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12686. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  12687. {
  12688. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12689. }
  12690. else
  12691. {
  12692. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  12693. Update_V2G_Flow_Status(Other_Fault);
  12694. }
  12695. req_is_responsed = TRUE;
  12696. }
  12697. //Check for ChargeParameterDiscoveryReq
  12698. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  12699. {
  12700. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12701. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  12702. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  12703. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12704. ftime(&SeqStartTime);
  12705. #endif
  12706. }
  12707. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12708. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12709. {
  12710. sprintf((char*)buf_log_evcomm,
  12711. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12712. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12713. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12714. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12715. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12716. }
  12717. else
  12718. {
  12719. }
  12720. break;
  12721. }
  12722. //-------------------------------------------
  12723. case ChargeParameterDiscoveryRequest: //35
  12724. {
  12725. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  12726. {
  12727. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  12728. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12729. }
  12730. else
  12731. {
  12732. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  12733. Update_V2G_Flow_Status(Other_Fault);
  12734. }
  12735. req_is_responsed = TRUE;
  12736. break;
  12737. }
  12738. case ChargeParameterDiscoveryResponse: //36
  12739. {
  12740. //STEP 1: Check for Process Timeout
  12741. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12742. ftime(&SeqEndTime);
  12743. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  12744. {
  12745. sprintf((char*)buf_log_evcomm,
  12746. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  12747. DiffTimeb(SeqStartTime, SeqEndTime),
  12748. V2G_SECC_ChargingParameter_Performance_Time);
  12749. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12750. Update_V2G_Flow_Status(Sequence_Timeout);
  12751. break;
  12752. }
  12753. #endif
  12754. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  12755. {
  12756. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12757. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  12758. {
  12759. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12760. }
  12761. else
  12762. {
  12763. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  12764. Update_V2G_Flow_Status(Other_Fault);
  12765. }
  12766. req_is_responsed = TRUE;
  12767. }
  12768. //STEP 3: Wait for PowerDeliveryReq Message
  12769. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12770. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12771. {
  12772. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  12773. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12774. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  12775. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12776. ftime(&SeqStartTime);
  12777. #endif
  12778. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12779. {
  12780. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12781. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12782. }
  12783. else
  12784. {
  12785. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  12786. Update_V2G_Flow_Status(Other_Fault);
  12787. }
  12788. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12789. ftime(&SeqStartTime);
  12790. #endif
  12791. }
  12792. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12793. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12794. {
  12795. sprintf((char*)buf_log_evcomm,
  12796. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12797. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12798. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12799. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12800. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12801. }
  12802. else
  12803. {
  12804. }
  12805. break;
  12806. }
  12807. //-------------------------------------------
  12808. case PowerDeliveryRequestStart: //41
  12809. {
  12810. if (Proc_iso1_PowerDeliveryStartReq(AcceptFd) == 0)
  12811. {
  12812. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  12813. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12814. }
  12815. else
  12816. {
  12817. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
  12818. Update_V2G_Flow_Status(Other_Fault);
  12819. }
  12820. req_is_responsed = TRUE;
  12821. break;
  12822. }
  12823. case PowerDeliveryResponsetStart: //42
  12824. {
  12825. //STEP 1: Check for Process Timeout
  12826. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12827. if (ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  12828. {
  12829. ftime(&SeqEndTime);
  12830. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  12831. {
  12832. sprintf((char*)buf_log_evcomm,
  12833. "Wait for ChargingStatusReq Timeout - (%.02lf of %d ms)\n",
  12834. DiffTimeb(SeqStartTime, SeqEndTime),
  12835. 2000);
  12836. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12837. Update_V2G_Flow_Status(Sequence_Timeout);
  12838. }
  12839. break;
  12840. }
  12841. #endif
  12842. //STEP 2: Wait for ChargingStatusReq Message
  12843. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargingStatusRequest)
  12844. {
  12845. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12846. Update_V2G_Flow_Status(ChargingStatusRequest);
  12847. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]ChargingStatusReq: energy transfering...");
  12848. ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_Start);
  12849. }
  12850. else
  12851. {
  12852. }
  12853. break;
  12854. }
  12855. //-------------------------------------------
  12856. case ChargingStatusRequest: //43
  12857. {
  12858. if (Proc_iso1_ChargingStatusReq(AcceptFd) == 0)
  12859. {
  12860. Update_V2G_Flow_Status(ChargingStatusResponse);
  12861. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12862. }
  12863. else
  12864. {
  12865. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargingStatusRes: fail");
  12866. Update_V2G_Flow_Status(Other_Fault);
  12867. }
  12868. req_is_responsed = TRUE;
  12869. break;
  12870. }
  12871. case ChargingStatusResponse: //44
  12872. {
  12873. //STEP 1: Wait for ChargingStatusReq Message
  12874. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargingStatusRequest)
  12875. {
  12876. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12877. if (Proc_iso1_ChargingStatusReq(AcceptFd) == 0)
  12878. {
  12879. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12880. }
  12881. else
  12882. {
  12883. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargingStatusRes: fail");
  12884. Update_V2G_Flow_Status(Other_Fault);
  12885. }
  12886. req_is_responsed = TRUE;
  12887. }
  12888. //STEP 2: Wait for PowerDeliveryReq Message
  12889. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12890. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12891. {
  12892. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12893. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12894. ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_End);
  12895. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12896. ftime(&SeqStartTime);
  12897. #endif
  12898. }
  12899. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12900. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12901. {
  12902. sprintf((char*)buf_log_evcomm,
  12903. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12904. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12905. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12906. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12907. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12908. }
  12909. else
  12910. {
  12911. }
  12912. break;
  12913. }
  12914. //-------------------------------------------
  12915. case PowerDeliveryRequestStop: //49
  12916. {
  12917. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12918. {
  12919. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12920. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12921. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12922. ftime(&SeqStartTime);
  12923. #endif
  12924. }
  12925. else
  12926. {
  12927. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  12928. Update_V2G_Flow_Status(Other_Fault);
  12929. }
  12930. req_is_responsed = TRUE;
  12931. break;
  12932. }
  12933. case PowerDeliveryResponseStop: //50
  12934. {
  12935. //STEP 1: Check for Process Timeout
  12936. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12937. ftime(&SeqEndTime);
  12938. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  12939. {
  12940. sprintf((char*)buf_log_evcomm,
  12941. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12942. DiffTimeb(SeqStartTime, SeqEndTime),
  12943. 2000);
  12944. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12945. Update_V2G_Flow_Status(Sequence_Timeout);
  12946. break;
  12947. }
  12948. #endif
  12949. //STEP 3: Check for SessionStopReq Message
  12950. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12951. {
  12952. Update_V2G_Flow_Status(SessionStopRequest);
  12953. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12954. }
  12955. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12956. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12957. {
  12958. sprintf((char*)buf_log_evcomm,
  12959. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12960. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12961. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12962. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12963. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12964. }
  12965. else
  12966. {
  12967. }
  12968. break;
  12969. }
  12970. //-------------------------------------------
  12971. case SessionStopRequest: //53
  12972. {
  12973. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12974. {
  12975. Update_V2G_Flow_Status(SessionStopResponse);
  12976. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12977. }
  12978. else
  12979. {
  12980. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  12981. Update_V2G_Flow_Status(Other_Fault);
  12982. }
  12983. req_is_responsed = TRUE;
  12984. break;
  12985. }
  12986. case SessionStopResponse: //54
  12987. {
  12988. break;
  12989. }
  12990. //-------------------------------------------
  12991. default:
  12992. {
  12993. break;
  12994. }
  12995. }
  12996. }
  12997. return 0;
  12998. }
  12999. /*===========================================================================
  13000. FUNCTION: V2gMsg_Process_iso1
  13001. DESCRIPTION:
  13002. 1. EnergyTransferMode:
  13003. AC_single_phase_core = 0,
  13004. AC_three_phase_core = 1,
  13005. DC_core = 2,
  13006. DC_extended = 3,
  13007. DC_combo_core = 4,
  13008. DC_unique = 5
  13009. iso1EnergyTransferModeType_AC_single_phase_core = 0,
  13010. iso1EnergyTransferModeType_AC_three_phase_core = 1,
  13011. iso1EnergyTransferModeType_DC_core = 2,
  13012. iso1EnergyTransferModeType_DC_extended = 3,
  13013. iso1EnergyTransferModeType_DC_combo_core = 4,
  13014. iso1EnergyTransferModeType_DC_unique = 5
  13015. PRE-CONDITION:
  13016. INPUT:
  13017. 1. V2gFlowStatus
  13018. OUTPUT:
  13019. GLOBAL VARIABLES:
  13020. 1. V2gFlowStatus
  13021. =============================================================================*/
  13022. int V2gMsg_Process_iso1(int AcceptFd, unsigned char EnergyTransferMode)
  13023. {
  13024. switch (EnergyTransferMode)
  13025. {
  13026. case DC_extended:
  13027. {
  13028. V2gMsg_Process_iso1_DC(AcceptFd);
  13029. break;
  13030. }
  13031. case AC_single_phase_core:
  13032. case AC_three_phase_core:
  13033. {
  13034. V2gMsg_Process_iso1_AC(AcceptFd);
  13035. break;
  13036. }
  13037. default:
  13038. {
  13039. sprintf((char*)buf_log_evcomm,
  13040. "[ISO1][Warning]Unexpected EnergyTransferMode(%d)",
  13041. EnergyTransferMode);
  13042. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13043. break;
  13044. }
  13045. }
  13046. return 0;
  13047. }
  13048. /*===========================================================================
  13049. FUNCTION: V2gMsg_Process_iso2_DC
  13050. DESCRIPTION:
  13051. PRE-CONDITION:
  13052. INPUT:
  13053. 1. V2gFlowStatus
  13054. OUTPUT:
  13055. GLOBAL VARIABLES:
  13056. 1. V2gFlowStatus
  13057. =============================================================================*/
  13058. int V2gMsg_Process_iso2_DC(int AcceptFd)
  13059. {
  13060. unsigned char req_is_responsed = FALSE;
  13061. while (req_is_responsed == FALSE)
  13062. {
  13063. //Check if it is in End_Process
  13064. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  13065. {
  13066. break;
  13067. }
  13068. switch(V2gFlowStatus)
  13069. {
  13070. //-------------------------------------------
  13071. case SupportedAppProtocolRequest:
  13072. {
  13073. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  13074. {
  13075. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  13076. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  13077. {
  13078. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13079. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  13080. }
  13081. else
  13082. {
  13083. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
  13084. Update_V2G_Flow_Status(Other_Fault);
  13085. }
  13086. }
  13087. req_is_responsed = TRUE;
  13088. break;
  13089. }
  13090. case SupportedAppProtocolResponse:
  13091. {
  13092. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  13093. {
  13094. Update_V2G_Flow_Status(SessionSetupRequest);
  13095. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13096. }
  13097. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13098. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13099. {
  13100. sprintf((char*)buf_log_evcomm,
  13101. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13102. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13103. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13104. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13105. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13106. }
  13107. else
  13108. {
  13109. }
  13110. break;
  13111. }
  13112. //-------------------------------------------
  13113. case SessionSetupRequest: //19
  13114. {
  13115. if (Proc_iso2_SessionSetupReq(AcceptFd) == 0)
  13116. {
  13117. Update_V2G_Flow_Status(SessionSetupResponse);
  13118. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13119. }
  13120. else
  13121. {
  13122. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
  13123. Update_V2G_Flow_Status(Other_Fault);
  13124. }
  13125. req_is_responsed = TRUE;
  13126. break;
  13127. }
  13128. case SessionSetupResponse: //20
  13129. {
  13130. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  13131. {
  13132. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  13133. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13134. }
  13135. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13136. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13137. {
  13138. sprintf((char*)buf_log_evcomm,
  13139. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13140. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13141. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13142. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13143. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13144. }
  13145. else
  13146. {
  13147. }
  13148. break;
  13149. }
  13150. #if 0
  13151. //-------------------------------------------
  13152. case ServiceDiscoveryRequest: //21
  13153. {
  13154. if (Proc_iso2_ServiceDiscoveryReq(AcceptFd) == 0)
  13155. {
  13156. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  13157. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13158. }
  13159. else
  13160. {
  13161. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
  13162. Update_V2G_Flow_Status(Other_Fault);
  13163. }
  13164. req_is_responsed = TRUE;
  13165. break;
  13166. }
  13167. case ServiceDiscoveryResponse: //22
  13168. {
  13169. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  13170. {
  13171. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  13172. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13173. }
  13174. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13175. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13176. {
  13177. sprintf((char*)buf_log_evcomm,
  13178. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13179. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13180. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13181. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13182. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13183. }
  13184. else
  13185. {
  13186. break;
  13187. }
  13188. }
  13189. //-------------------------------------------
  13190. case ServiceAndPaymentSelectionRequest: //25
  13191. {
  13192. if (Proc_iso2_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  13193. {
  13194. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  13195. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13196. }
  13197. else
  13198. {
  13199. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
  13200. Update_V2G_Flow_Status(Other_Fault);
  13201. }
  13202. req_is_responsed = TRUE;
  13203. break;
  13204. }
  13205. case ServiceAndPaymentSelectionResponse: //26
  13206. {
  13207. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  13208. {
  13209. Update_V2G_Flow_Status(AuthorizationRequest);
  13210. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13211. }
  13212. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13213. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13214. {
  13215. sprintf((char*)buf_log_evcomm,
  13216. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13217. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13218. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13219. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13220. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13221. }
  13222. else
  13223. {
  13224. break;
  13225. }
  13226. }
  13227. //-------------------------------------------
  13228. //case ContractAuthenticationReq:
  13229. case AuthorizationRequest: //29
  13230. {
  13231. if (Proc_iso2_AuthenticationReq(AcceptFd) == 0)
  13232. {
  13233. Update_V2G_Flow_Status(AuthorizationResponse);
  13234. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13235. }
  13236. else
  13237. {
  13238. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  13239. Update_V2G_Flow_Status(Other_Fault);
  13240. }
  13241. req_is_responsed = TRUE;
  13242. break;
  13243. }
  13244. case AuthorizationResponse: //30
  13245. {
  13246. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  13247. {
  13248. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13249. if (Proc_iso2_AuthenticationReq(AcceptFd) == 0)
  13250. {
  13251. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13252. }
  13253. else
  13254. {
  13255. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  13256. Update_V2G_Flow_Status(Other_Fault);
  13257. }
  13258. req_is_responsed = TRUE;
  13259. break;
  13260. }
  13261. //Check for ChargeParameterDiscoveryReq
  13262. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  13263. {
  13264. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13265. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  13266. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  13267. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13268. ftime(&SeqStartTime);
  13269. #endif
  13270. }
  13271. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13272. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13273. {
  13274. sprintf((char*)buf_log_evcomm,
  13275. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13276. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13277. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13278. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13279. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13280. }
  13281. else
  13282. {
  13283. break;
  13284. }
  13285. }
  13286. //-------------------------------------------
  13287. case ChargeParameterDiscoveryRequest: //35
  13288. {
  13289. if (Proc_iso2_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  13290. {
  13291. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  13292. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13293. }
  13294. else
  13295. {
  13296. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  13297. Update_V2G_Flow_Status(Other_Fault);
  13298. }
  13299. req_is_responsed = TRUE;
  13300. break;
  13301. }
  13302. case ChargeParameterDiscoveryResponse:
  13303. {
  13304. //STEP 1: Check for Process Timeout
  13305. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13306. ftime(&SeqEndTime);
  13307. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  13308. {
  13309. sprintf((char*)buf_log_evcomm,
  13310. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  13311. DiffTimeb(SeqStartTime, SeqEndTime),
  13312. V2G_SECC_ChargingParameter_Performance_Time);
  13313. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13314. Update_V2G_Flow_Status(Sequence_Timeout);
  13315. break;
  13316. }
  13317. #endif
  13318. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  13319. {
  13320. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13321. if (Proc_iso2_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  13322. {
  13323. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13324. }
  13325. else
  13326. {
  13327. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  13328. Update_V2G_Flow_Status(Other_Fault);
  13329. }
  13330. req_is_responsed = TRUE;
  13331. break;
  13332. }
  13333. //STEP 2: Check for CableCheckReq message
  13334. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  13335. {
  13336. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13337. Update_V2G_Flow_Status(CableCheckRequest);
  13338. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]CableCheckReqReq: isolated?");
  13339. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  13340. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  13341. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13342. ftime(&SeqStartTime);
  13343. #endif
  13344. }
  13345. //STEP 3: Wait for PowerDeliveryReq Message
  13346. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13347. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13348. {
  13349. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13350. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13351. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  13352. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13353. ftime(&SeqStartTime);
  13354. #endif
  13355. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13356. {
  13357. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13358. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13359. }
  13360. else
  13361. {
  13362. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  13363. Update_V2G_Flow_Status(Other_Fault);
  13364. }
  13365. break;
  13366. }
  13367. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13368. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13369. {
  13370. sprintf((char*)buf_log_evcomm,
  13371. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13372. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13373. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13374. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13375. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13376. }
  13377. else
  13378. {
  13379. break;
  13380. }
  13381. }
  13382. //-------------------------------------------
  13383. case CableCheckRequest: //37
  13384. {
  13385. //STEP 3: Execute Cable Check Process
  13386. if (Proc_iso2_CableCheckReq(AcceptFd) == 0)
  13387. {
  13388. Update_V2G_Flow_Status(CableCheckResponse);
  13389. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13390. }
  13391. else
  13392. {
  13393. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  13394. Update_V2G_Flow_Status(Other_Fault);
  13395. }
  13396. req_is_responsed = TRUE;
  13397. break;
  13398. }
  13399. case CableCheckResponse: //38
  13400. {
  13401. //STEP 1: Check for Process Timeout
  13402. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13403. ftime(&SeqEndTime);
  13404. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  13405. {
  13406. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CableCheck] end counting...");
  13407. sprintf((char*)buf_log_evcomm,
  13408. "CableCheck Timeout - (%.02lf of %d ms)\n",
  13409. DiffTimeb(SeqStartTime, SeqEndTime),
  13410. V2G_SECC_CableCheck_Performance_Time);
  13411. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13412. Update_V2G_Flow_Status(Sequence_Timeout);
  13413. //Update_ShmStatusCode(); //[To-Do] to be implemented
  13414. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  13415. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13416. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13417. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13418. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  13419. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  13420. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  13421. break;
  13422. }
  13423. #endif
  13424. //STEP 2: Check for CableCheckReq message
  13425. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  13426. {
  13427. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13428. //STEP 3: Execute Cable Check Process
  13429. if (Proc_iso2_CableCheckReq(AcceptFd) == 0)
  13430. {
  13431. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13432. }
  13433. else
  13434. {
  13435. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  13436. Update_V2G_Flow_Status(Other_Fault);
  13437. }
  13438. req_is_responsed = TRUE;
  13439. break;
  13440. }
  13441. //STEP 3: Check for PreChargeReq message
  13442. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  13443. {
  13444. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13445. Update_V2G_Flow_Status(PreChargeRequest);
  13446. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]PreChargeReqReq: waiting for precharge voltage...");
  13447. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  13448. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  13449. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13450. ftime(&SeqStartTime);
  13451. #endif
  13452. }
  13453. //STEP 3: Wait for PowerDeliveryReq Message
  13454. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13455. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13456. {
  13457. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13458. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13459. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  13460. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13461. ftime(&SeqStartTime);
  13462. #endif
  13463. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13464. {
  13465. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13466. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13467. }
  13468. else
  13469. {
  13470. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  13471. Update_V2G_Flow_Status(Other_Fault);
  13472. }
  13473. break;
  13474. }
  13475. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13476. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13477. {
  13478. sprintf((char*)buf_log_evcomm,
  13479. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13480. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13481. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13482. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13483. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13484. }
  13485. else
  13486. {
  13487. break;
  13488. }
  13489. }
  13490. //-------------------------------------------
  13491. case PreChargeRequest: //39
  13492. {
  13493. if (Proc_iso2_PreChargeReq(AcceptFd) == 0)
  13494. {
  13495. Update_V2G_Flow_Status(PreChargeResponse);
  13496. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13497. }
  13498. else
  13499. {
  13500. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  13501. Update_V2G_Flow_Status(Other_Fault);
  13502. }
  13503. req_is_responsed = TRUE;
  13504. break;
  13505. }
  13506. case PreChargeResponse: //40
  13507. {
  13508. //STEP 1: Check for Process Timeout
  13509. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13510. ftime(&SeqEndTime);
  13511. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  13512. {
  13513. sprintf((char*)buf_log_evcomm,
  13514. "Precharge Timeout - (%.02lf of %d ms)\n",
  13515. DiffTimeb(SeqStartTime, SeqEndTime),
  13516. V2G_SECC_PreCharge_Performance_Time);
  13517. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13518. Update_V2G_Flow_Status(Sequence_Timeout);
  13519. //Update_ShmStatusCode(); //[To-Do] to be implemented
  13520. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  13521. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13522. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13523. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13524. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  13525. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  13526. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  13527. break;
  13528. }
  13529. #endif
  13530. //STEP 2: Check for PreChargeReq message
  13531. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  13532. {
  13533. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13534. if (Proc_iso2_PreChargeReq(AcceptFd) == 0)
  13535. {
  13536. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13537. }
  13538. else
  13539. {
  13540. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  13541. Update_V2G_Flow_Status(Other_Fault);
  13542. }
  13543. req_is_responsed = TRUE;
  13544. break;
  13545. }
  13546. //STEP 3: Check for PowerDeliveryReq message
  13547. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13548. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13549. {
  13550. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13551. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  13552. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  13553. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13554. ftime(&SeqStartTime);
  13555. #endif
  13556. }
  13557. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13558. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13559. {
  13560. sprintf((char*)buf_log_evcomm,
  13561. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13562. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13563. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13564. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13565. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13566. }
  13567. else
  13568. {
  13569. break;
  13570. }
  13571. }
  13572. //-------------------------------------------
  13573. case PowerDeliveryRequestStart: //41
  13574. {
  13575. if (Proc_iso2_PowerDeliveryStartReq(AcceptFd) == 0)
  13576. {
  13577. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  13578. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13579. }
  13580. else
  13581. {
  13582. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
  13583. Update_V2G_Flow_Status(Other_Fault);
  13584. }
  13585. req_is_responsed = TRUE;
  13586. break;
  13587. }
  13588. case PowerDeliveryResponsetStart: //42
  13589. {
  13590. //STEP 1: Check for Process Timeout
  13591. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13592. if (ccs_exi_doc_ISO2.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  13593. {
  13594. ftime(&SeqEndTime);
  13595. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  13596. {
  13597. sprintf((char*)buf_log_evcomm,
  13598. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  13599. DiffTimeb(SeqStartTime, SeqEndTime),
  13600. 2000);
  13601. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13602. Update_V2G_Flow_Status(Sequence_Timeout);
  13603. }
  13604. break;
  13605. }
  13606. #endif
  13607. //STEP 2: Wait for CurrentDemandReq Message
  13608. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  13609. {
  13610. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13611. Update_V2G_Flow_Status(CurrentDemandRequest);
  13612. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]CurrentDemandReqReq: energy transfering...");
  13613. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  13614. }
  13615. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13616. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13617. {
  13618. sprintf((char*)buf_log_evcomm,
  13619. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13620. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13621. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13622. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13623. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13624. }
  13625. else
  13626. {
  13627. break;
  13628. }
  13629. }
  13630. //-------------------------------------------
  13631. case CurrentDemandRequest: //45,
  13632. {
  13633. if (Proc_iso2_CurrentDemandReq(AcceptFd) == 0)
  13634. {
  13635. Update_V2G_Flow_Status(CurrentDemandResponse);
  13636. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13637. }
  13638. else
  13639. {
  13640. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  13641. Update_V2G_Flow_Status(Other_Fault);
  13642. }
  13643. req_is_responsed = TRUE;
  13644. break;
  13645. }
  13646. case CurrentDemandResponse: //46,
  13647. {
  13648. //STEP 1: Wait for CurrentDemandReq Message
  13649. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  13650. {
  13651. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13652. if (Proc_iso2_CurrentDemandReq(AcceptFd) == 0)
  13653. {
  13654. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13655. }
  13656. else
  13657. {
  13658. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  13659. Update_V2G_Flow_Status(Other_Fault);
  13660. }
  13661. req_is_responsed = TRUE;
  13662. break;
  13663. }
  13664. //STEP 2: Wait for PowerDeliveryReq Message
  13665. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13666. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13667. {
  13668. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13669. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13670. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  13671. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13672. ftime(&SeqStartTime);
  13673. #endif
  13674. }
  13675. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13676. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13677. {
  13678. sprintf((char*)buf_log_evcomm,
  13679. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13680. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13681. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13682. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13683. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13684. }
  13685. else
  13686. {
  13687. break;
  13688. }
  13689. }
  13690. //-------------------------------------------
  13691. case PowerDeliveryRequestStop: //49,
  13692. {
  13693. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13694. {
  13695. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13696. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13697. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13698. ftime(&SeqStartTime);
  13699. #endif
  13700. }
  13701. else
  13702. {
  13703. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  13704. Update_V2G_Flow_Status(Other_Fault);
  13705. }
  13706. req_is_responsed = TRUE;
  13707. break;
  13708. }
  13709. case PowerDeliveryResponseStop: //50,
  13710. {
  13711. //STEP 1: Check for Process Timeout
  13712. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13713. ftime(&SeqEndTime);
  13714. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  13715. {
  13716. sprintf((char*)buf_log_evcomm,
  13717. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  13718. DiffTimeb(SeqStartTime, SeqEndTime),
  13719. 2000);
  13720. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13721. Update_V2G_Flow_Status(Sequence_Timeout);
  13722. break;
  13723. }
  13724. #endif
  13725. //STEP 2: Check for WeldingDetectionReq Message
  13726. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  13727. {
  13728. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13729. Update_V2G_Flow_Status(WeldingDetectionRequest);
  13730. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][Rx]WeldingDetectionReq: ongoing...");
  13731. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  13732. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13733. ftime(&SeqStartTime);
  13734. #endif
  13735. }
  13736. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  13737. {
  13738. Update_V2G_Flow_Status(SessionStopRequest);
  13739. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13740. if (Proc_iso2_SessionStopReq(AcceptFd) == 0)
  13741. {
  13742. Update_V2G_Flow_Status(SessionStopResponse);
  13743. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13744. }
  13745. else
  13746. {
  13747. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  13748. Update_V2G_Flow_Status(Other_Fault);
  13749. }
  13750. break;
  13751. }
  13752. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13753. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13754. {
  13755. sprintf((char*)buf_log_evcomm,
  13756. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13757. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13758. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13759. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13760. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13761. }
  13762. else
  13763. {
  13764. break;
  13765. }
  13766. }
  13767. //-------------------------------------------
  13768. case WeldingDetectionRequest: //51,
  13769. {
  13770. if (Proc_iso2_WeldingDetectionReq(AcceptFd) == 0)
  13771. {
  13772. Update_V2G_Flow_Status(WeldingDetectionResponse);
  13773. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13774. }
  13775. else
  13776. {
  13777. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  13778. Update_V2G_Flow_Status(Other_Fault);
  13779. }
  13780. req_is_responsed = TRUE;
  13781. break;
  13782. }
  13783. case WeldingDetectionResponse: //52,
  13784. {
  13785. //STEP 1: Check for Process Timeout
  13786. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13787. ftime(&SeqEndTime);
  13788. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  13789. {
  13790. sprintf((char*)buf_log_evcomm,
  13791. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  13792. DiffTimeb(SeqStartTime, SeqEndTime),
  13793. V2G_SECC_WeldingDetection_Performance_Time);
  13794. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13795. Update_V2G_Flow_Status(Sequence_Timeout);
  13796. break;
  13797. }
  13798. #endif
  13799. //STEP 2: Check for WeldingDetectionReq Message
  13800. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  13801. {
  13802. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13803. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  13804. {
  13805. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13806. }
  13807. else
  13808. {
  13809. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  13810. Update_V2G_Flow_Status(Other_Fault);
  13811. }
  13812. req_is_responsed = TRUE;
  13813. break;
  13814. }
  13815. //STEP 3: Check for SessionStopReq Message
  13816. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  13817. {
  13818. Update_V2G_Flow_Status(SessionStopRequest);
  13819. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13820. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  13821. }
  13822. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13823. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13824. {
  13825. sprintf((char*)buf_log_evcomm,
  13826. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13827. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13828. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13829. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13830. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13831. }
  13832. else
  13833. {
  13834. break;
  13835. }
  13836. }
  13837. //-------------------------------------------
  13838. case SessionStopRequest: //53,
  13839. {
  13840. if (Proc_iso2_SessionStopReq(AcceptFd) == 0)
  13841. {
  13842. Update_V2G_Flow_Status(SessionStopResponse);
  13843. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13844. }
  13845. else
  13846. {
  13847. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  13848. Update_V2G_Flow_Status(Other_Fault);
  13849. }
  13850. req_is_responsed = TRUE;
  13851. //break;
  13852. }
  13853. case SessionStopResponse: //54,
  13854. {
  13855. break;
  13856. }
  13857. #endif
  13858. //-------------------------------------------
  13859. default:
  13860. {
  13861. break;
  13862. }
  13863. }
  13864. }
  13865. return 0;
  13866. }
  13867. /*===========================================================================
  13868. FUNCTION: V2gMsg_Process_iso2_AC
  13869. DESCRIPTION:
  13870. PRE-CONDITION:
  13871. INPUT:
  13872. 1. V2gFlowStatus
  13873. OUTPUT:
  13874. GLOBAL VARIABLES:
  13875. 1. V2gFlowStatus
  13876. =============================================================================*/
  13877. int V2gMsg_Process_iso2_AC(int AcceptFd)
  13878. {
  13879. return 0;
  13880. }
  13881. /*===========================================================================
  13882. FUNCTION: V2gMsg_Process_iso2
  13883. DESCRIPTION:
  13884. PRE-CONDITION:
  13885. INPUT:
  13886. 1. V2gFlowStatus
  13887. OUTPUT:
  13888. GLOBAL VARIABLES:
  13889. 1. V2gFlowStatus
  13890. =============================================================================*/
  13891. int V2gMsg_Process_iso2(int AcceptFd, unsigned char EnergyTransferMode)
  13892. {
  13893. switch (EnergyTransferMode)
  13894. {
  13895. case DC_extended:
  13896. {
  13897. V2gMsg_Process_iso2_DC(AcceptFd);
  13898. break;
  13899. }
  13900. case AC_single_phase_core:
  13901. case AC_three_phase_core:
  13902. {
  13903. V2gMsg_Process_iso2_AC(AcceptFd);
  13904. break;
  13905. }
  13906. default:
  13907. {
  13908. sprintf((char*)buf_log_evcomm,
  13909. "[ISO2][Warning]Unexpected EnergyTransferMode(%d)",
  13910. EnergyTransferMode);
  13911. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13912. break;
  13913. }
  13914. }
  13915. return 0;
  13916. }
  13917. /*===========================================================================
  13918. FUNCTION: V2gMsg_Process
  13919. DESCRIPTION:
  13920. PRE-CONDITION:
  13921. INPUT:
  13922. OUTPUT:
  13923. GLOBAL VARIABLES:
  13924. =============================================================================*/
  13925. int V2gMsg_Process(int AcceptFd)
  13926. {
  13927. int errn = 0;
  13928. switch (ShmCcsData->CommProtocol)
  13929. {
  13930. case V2GT_MSG_PROTOCOL_DIN70121: //0
  13931. {
  13932. V2gMsg_Process_din(AcceptFd);
  13933. break;
  13934. }
  13935. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  13936. {
  13937. V2gMsg_Process_iso1(AcceptFd, ShmCcsData->EnergyTransferMode);
  13938. break;
  13939. }
  13940. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  13941. {
  13942. V2gMsg_Process_iso2(AcceptFd, ShmCcsData->EnergyTransferMode);
  13943. break;
  13944. }
  13945. default:
  13946. {
  13947. sprintf((char*)buf_log_evcomm,
  13948. "[Warning]Unexpected CommProtocol(%d)",
  13949. ShmCcsData->CommProtocol);
  13950. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13951. break;
  13952. }
  13953. }
  13954. return errn;
  13955. }
  13956. /*===========================================================================
  13957. FUNCTION: V2gMsg_Rx
  13958. DESCRIPTION:
  13959. PRE-CONDITION:
  13960. INPUT:
  13961. OUTPUT:
  13962. GLOBAL VARIABLES:
  13963. =============================================================================*/
  13964. int V2gMsg_Rx(int AcceptFd)
  13965. {
  13966. int errn = 0;
  13967. unsigned int packet_size = 0;
  13968. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  13969. packet_size = recv(AcceptFd, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, 0);
  13970. //[CAUTION] Everytime recv() is called, it will take a default time to wait for TCP packets.
  13971. //The more time you call recv(), the more time you will waste here.
  13972. //Here it is suggested that response immediatedly once you receive any packets.
  13973. //For configuring the Rx waiting time, please use setsockopt().
  13974. if(packet_size > 0) //[Joseph] If there is no data, ignore. (TBD)
  13975. {
  13976. //DEBUG_PRINTF_EVCOMM_DETAIL("\n\n Got TCP V2GTP Message: size = %d Bytes\n", packet_size);
  13977. errn = V2gMsgDecoder(V2gtpMsgRxBuf, packet_size, V2gFlowStatus);
  13978. if (errn < 0)
  13979. {
  13980. sprintf((char*)buf_log_evcomm, "[ERROR]V2gMsgDecoder (%d)", errn);
  13981. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13982. }
  13983. }
  13984. return errn;
  13985. }
  13986. /*===========================================================================
  13987. FUNCTION: V2gComm
  13988. DESCRIPTION:
  13989. PRE-CONDITION:
  13990. 1. TCP socket is connected.
  13991. INPUT:
  13992. 1. AcceptFd //TCP Connection ID
  13993. 2. V2gtpMsgRxBuf[] //V2GTP Messages (Header + Payload)
  13994. 3. V2GTP_MSG_RX_BUFFER_SIZE //64*1024 = 65,536 = 65.5K (Bytes)
  13995. OUTPUT:
  13996. GLOBAL VARIABLES:
  13997. 1. V2gtpMsgRxBuf[]
  13998. =============================================================================*/
  13999. int V2gComm(int AcceptFd)
  14000. {
  14001. int errn = 0;
  14002. if (V2gMsg_Rx(AcceptFd) < 0)
  14003. {
  14004. Update_V2G_Flow_Status(Other_Fault);
  14005. errn = -1;
  14006. }
  14007. //following are the response message handling according to status flag
  14008. if (V2gMsg_Process(AcceptFd) < 0)
  14009. {
  14010. errn = -1;
  14011. }
  14012. //Error Check
  14013. //V2G_Error_Monitor();
  14014. return errn;
  14015. }
  14016. /*===========================================================================
  14017. FUNCTION: SdpUdpConnected
  14018. DESCRIPTION:
  14019. PRE-CONDITION:
  14020. INPUT:
  14021. OUTPUT:
  14022. GLOBAL VARIABLES:
  14023. =============================================================================*/
  14024. int SdpUdpConnected()
  14025. {
  14026. int packet_size,Rtn;
  14027. struct sockaddr_in6 ServerAddr,ClientAddr;
  14028. struct V2gtpHeader *header;
  14029. unsigned char *payload;
  14030. if(UdpSock <= 0)
  14031. {
  14032. if ((UdpSock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
  14033. {
  14034. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SdpUdpConnected: Fail to open UdpSock");
  14035. return 0;
  14036. }
  14037. memset(&ServerAddr,0, sizeof(struct sockaddr_in));
  14038. ServerAddr.sin6_family = AF_INET6;
  14039. ServerAddr.sin6_addr = in6addr_any;
  14040. ServerAddr.sin6_port = htons(SdpUdpServerPort);
  14041. if(bind(UdpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) <0)
  14042. {
  14043. sprintf((char*)buf_log_evcomm,
  14044. "SdpUdpConnected: Fail to bind UdpSock(%d)",
  14045. UdpSock);
  14046. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14047. close(UdpSock);
  14048. UdpSock = -1;
  14049. return 0;
  14050. }
  14051. sprintf((char*)buf_log_evcomm, "[UdpSock]opend:%d", UdpSock);
  14052. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14053. sprintf((char*)buf_log_evcomm, "[SDP]Req from EVCC: waiting...(%d)", UdpSock);
  14054. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14055. }
  14056. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  14057. memset(&ClientAddr, 0, sizeof(struct sockaddr_in));
  14058. Rtn = sizeof(struct sockaddr_in6);
  14059. packet_size = recvfrom(UdpSock, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *)&ClientAddr, (socklen_t *)&Rtn);
  14060. if(packet_size > 0)
  14061. {
  14062. header = (struct V2gtpHeader *) V2gtpMsgRxBuf;
  14063. payload = V2gtpMsgRxBuf+sizeof(struct V2gtpHeader);
  14064. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  14065. {
  14066. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n Got UDP packet_size = %d (Bytes)\n", packet_size);
  14067. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***********************************\n");
  14068. DEBUG_PRINTF_EVCOMM_DETAIL("***** Received SDP Packet *****\n");
  14069. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  14070. DEBUG_PRINTF_EVCOMM_DETAIL("ClientAddress=");
  14071. for(Rtn = 0; Rtn < 16; Rtn += 2)
  14072. {
  14073. DEBUG_PRINTF_EVCOMM_DETAIL("%02x%02x:",ClientAddr.sin6_addr.s6_addr[Rtn],ClientAddr.sin6_addr.s6_addr[Rtn+1]);
  14074. }
  14075. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  14076. DEBUG_PRINTF_EVCOMM_DETAIL("ClientPort=%d\n",ClientAddr.sin6_port);
  14077. DEBUG_PRINTF_EVCOMM_DETAIL("ProtocolVersion=%d\n",header->ProtocolVersion);
  14078. DEBUG_PRINTF_EVCOMM_DETAIL("InverseProtocolVersion=0x%x\n",header->InverseProtocolVersion);
  14079. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadType=0x%x\n",htons(header->PayloadType));
  14080. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadLength=0x%x\n",htonl(header->PayloadLength));
  14081. DEBUG_PRINTF_EVCOMM_DETAIL("htons(header->PayloadType)=0x%x\n",htons(header->PayloadType));
  14082. }
  14083. #endif
  14084. if( (header->ProtocolVersion == 0x01) &&
  14085. (header->InverseProtocolVersion == 0xFE) &&
  14086. (htons(header->PayloadType) == V2GTP_PAYLOAD_TYPE_SDP_REQUEST))
  14087. {
  14088. sprintf((char*)buf_log_evcomm, "[SDP][Rx]Req from EVCC: GOT(%d)", UdpSock);
  14089. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14090. DEBUG_PRINTF_EVCOMM_DETAIL("Security=0x%x\n", *(payload + 0));
  14091. DEBUG_PRINTF_EVCOMM_DETAIL("TransportProtocol=0x%x\n", *(payload + 1));
  14092. header->PayloadType = htons(V2GTP_PAYLOAD_TYPE_SDP_RESPONSE);
  14093. header->PayloadLength = htonl(20); //Fixed Length=20
  14094. memset(payload, 0, 20);
  14095. // MAC address[0:2] + FFFE + MAC address[3:5]
  14096. payload[0] = (IPV6_LINK_LOCAL_PREFIX>>8) & 0xFF;
  14097. payload[1] = IPV6_LINK_LOCAL_PREFIX & 0xFF;
  14098. payload[8 ]= CsuMac[0];
  14099. payload[8] ^= 0x02;// bit 1 should complemented.
  14100. payload[9] = CsuMac[1];
  14101. payload[10] = CsuMac[2];
  14102. payload[11] = 0xFF;
  14103. payload[12] = 0xFE;
  14104. payload[13] = CsuMac[3];
  14105. payload[14] = CsuMac[4];
  14106. payload[15] = CsuMac[5];
  14107. //TCP port
  14108. payload[16] = (EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active>>8) & 0xFF;
  14109. payload[17] = EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active & 0xFF;
  14110. payload[18] = SDP_PAYLOAD_SECURITY_NONE; //Security
  14111. payload[19] = SDP_PAYLOAD_TRANS_PROTOCOL_TCP; //Transport protocol
  14112. //[To-Do] Setup the TCP in advance to receive the coming TCP handshke messages after SDP response.
  14113. Rtn = sendto(UdpSock, V2gtpMsgRxBuf, sizeof(struct V2gtpHeader) + htonl(header->PayloadLength), 0, (struct sockaddr *)&ClientAddr, sizeof(struct sockaddr_in6));
  14114. sprintf((char*)buf_log_evcomm, "[SDP][Tx]Res from SECC");
  14115. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14116. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  14117. {
  14118. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response SDP Packet *****\n");
  14119. DEBUG_PRINTF_EVCOMM_DETAIL("Send size=%d\n",Rtn);
  14120. DEBUG_PRINTF_EVCOMM_DETAIL("Destination Address=");
  14121. for(Rtn = 0; Rtn < 16; Rtn++)
  14122. {
  14123. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ", ClientAddr.sin6_addr.s6_addr[Rtn]);
  14124. }
  14125. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  14126. DEBUG_PRINTF_EVCOMM_DETAIL("Destination Port=%d\n", ClientAddr.sin6_port);
  14127. DEBUG_PRINTF_EVCOMM_DETAIL("ProtocolVersion=%d\n", header->ProtocolVersion);
  14128. DEBUG_PRINTF_EVCOMM_DETAIL("InverseProtocolVersion=0x%x\n", header->InverseProtocolVersion);
  14129. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadType=0x%x\n", htons(header->PayloadType));
  14130. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadLength=0x%x\n", htonl(header->PayloadLength));
  14131. DEBUG_PRINTF_EVCOMM_DETAIL("SECC Ipv6 Address=");
  14132. for(Rtn = 0; Rtn < 16; Rtn++)
  14133. {
  14134. DEBUG_PRINTF_EVCOMM_DETAIL("%02x:",payload[Rtn]);
  14135. }
  14136. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  14137. DEBUG_PRINTF_EVCOMM_DETAIL("SECC Port=%d\n", (payload[16]<<8 | payload[17]));
  14138. DEBUG_PRINTF_EVCOMM_DETAIL("Security=0x%x\n", payload[19]);
  14139. DEBUG_PRINTF_EVCOMM_DETAIL("TransportProtocol=0x%x\n", payload[20]);
  14140. }
  14141. #endif
  14142. if(Rtn > 0)
  14143. {
  14144. return 1;
  14145. }
  14146. }
  14147. }
  14148. return 0;
  14149. }
  14150. /*===========================================================================
  14151. FUNCTION: V2gTcpConnected
  14152. DESCRIPTION:
  14153. PRE-CONDITION:
  14154. INPUT:
  14155. OUTPUT:
  14156. GLOBAL VARIABLES:
  14157. =============================================================================*/
  14158. int V2gTcpConnected()
  14159. {
  14160. int Rtn,AcceptFd;
  14161. struct sockaddr_in6 ServerAddr,ClientAddr;
  14162. if(TcpSock <= 0)
  14163. {
  14164. if ((TcpSock = socket(PF_INET6, SOCK_STREAM, 0)) < 0)
  14165. {
  14166. sprintf((char*)buf_log_evcomm,
  14167. "V2gTcpConnected: Fail to open TcpSock (%s)",
  14168. strerror(errno));
  14169. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14170. usleep(100000); //100ms
  14171. return 0;
  14172. }
  14173. fcntl(TcpSock, F_SETFL, O_NONBLOCK); //set to O_NONBLOCK
  14174. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]socket set: DONE");
  14175. memset(&ServerAddr,0, sizeof(struct sockaddr_in));
  14176. ServerAddr.sin6_family = PF_INET6;
  14177. ServerAddr.sin6_addr = in6addr_any;
  14178. ServerAddr.sin6_port = htons(EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  14179. //ServerAddr.sin6_port = htons(SdpTcpServerPort + (rand() % 10) + 1);
  14180. //printf("SdpTcpServerPort = %d(DEC)\n", htons(ServerAddr.sin6_port));
  14181. if(bind(TcpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) < 0)
  14182. {
  14183. sprintf((char*)buf_log_evcomm,
  14184. "V2gTcpConnected: Fail to bind TcpSock (%s), SdpTcpServerPort = %d",
  14185. strerror(errno),
  14186. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active
  14187. );
  14188. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14189. //Change to another TCP port
  14190. /*
  14191. memset(&ServerAddr, 0, sizeof(struct sockaddr_in));
  14192. ServerAddr.sin6_family = PF_INET6;
  14193. ServerAddr.sin6_addr = in6addr_any;
  14194. //ServerAddr.sin6_port = htons(SdpTcpServerPort + (rand() % 1000) + 1);
  14195. ServerAddr.sin6_port = htons(EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  14196. */
  14197. if(bind(TcpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) < 0)
  14198. {
  14199. sprintf((char*)buf_log_evcomm,
  14200. "V2gTcpConnected: Fail to bind TcpSock (%s), SdpTcpServerPort = %d",
  14201. strerror(errno),
  14202. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active
  14203. );
  14204. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14205. usleep(100000); //100ms
  14206. close(TcpSock);
  14207. TcpSock = -1;
  14208. return 0;
  14209. }
  14210. }
  14211. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]blid: DONE");
  14212. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]listen: START");
  14213. if(listen(TcpSock, 1) == -1) //only accept one connection
  14214. {
  14215. sprintf((char*)buf_log_evcomm,
  14216. "V2gTcpConnected: Fail to listen TcpSock (%s)",
  14217. strerror(errno));
  14218. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14219. usleep(100000); //100ms
  14220. close(TcpSock);
  14221. TcpSock = -1;
  14222. return 0;
  14223. }
  14224. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]listen: DONE");
  14225. sprintf((char*)buf_log_evcomm, "[TCP]TcpSock: opened(%d), port=%d", TcpSock, htons(ServerAddr.sin6_port));
  14226. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14227. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]accept: START");
  14228. }
  14229. Rtn = sizeof(struct sockaddr_in6);
  14230. if((AcceptFd = accept(TcpSock, (struct sockaddr *)&ClientAddr, (socklen_t *)&Rtn)) == -1)
  14231. {
  14232. static BOOL tmp = 0;
  14233. if (tmp == 0)
  14234. {
  14235. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]Wait TCP connection...");
  14236. tmp = 1;
  14237. }
  14238. else
  14239. {
  14240. //DEBUG_PRINTF_EVCOMM_DETAIL(".");
  14241. }
  14242. return 0;
  14243. }
  14244. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]accept: DONE\n");
  14245. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  14246. {
  14247. DEBUG_PRINTF_EVCOMM_DETAIL("\n\nAccept one TCP connection:\n");
  14248. DEBUG_PRINTF_EVCOMM_DETAIL("AcceptFd=%d\n",AcceptFd);
  14249. DEBUG_PRINTF_EVCOMM_DETAIL("ClientAddress=");
  14250. for(Rtn = 0; Rtn < 16; Rtn += 2)
  14251. {
  14252. DEBUG_PRINTF_EVCOMM_DETAIL("%02x%02x:", ClientAddr.sin6_addr.s6_addr[Rtn], ClientAddr.sin6_addr.s6_addr[Rtn+1]);
  14253. }
  14254. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  14255. DEBUG_PRINTF_EVCOMM_DETAIL("ClientPort=%d\n", ClientAddr.sin6_port);
  14256. }
  14257. #endif
  14258. return AcceptFd;
  14259. }
  14260. /*===========================================================================
  14261. FUNCTION: End_Process
  14262. DESCRIPTION:
  14263. PRE-CONDITION:
  14264. 1. <CAUTION> This function could only be used in SeccComm fork2.
  14265. INPUT:
  14266. OUTPUT:
  14267. GLOBAL VARIABLES:
  14268. =============================================================================*/
  14269. int End_Process()
  14270. {
  14271. if(EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  14272. {
  14273. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "End_Process has been triggered by another event.");
  14274. return -1;
  14275. }
  14276. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Entering...");
  14277. //STEP 1: Ask CSU to Stop
  14278. EVCOMM_SYS_INFO.End_Process_inused = TRUE;
  14279. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  14280. EVCOMM_SYS_INFO.ConnectorLocked = FALSE;
  14281. ShmInternalComm->ChargingPermission = FALSE;
  14282. //Step 2: Close sockets
  14283. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Close sockets...");
  14284. if(RawSock > 0)
  14285. {
  14286. close(RawSock);
  14287. }
  14288. if(UdpSock > 0)
  14289. {
  14290. close(UdpSock);
  14291. }
  14292. if(TcpSock > 0)
  14293. {
  14294. close(TcpSock);
  14295. close(TcpAcceptFd);
  14296. }
  14297. RawSock = UdpSock = TcpSock = TcpAcceptFd = -1;
  14298. //STEP 3: Switch to State E
  14299. //SwitchCpStateE(ENABLE);
  14300. //STEP 4: Close tcpdump
  14301. Sniffer_Tcpdump(DISABLE);
  14302. //STEP 5: Keep 100% PWM for 5 seconds
  14303. OutputCpPwmDuty(100);
  14304. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 5");
  14305. sleep(1);
  14306. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 4");
  14307. sleep(1);
  14308. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 3");
  14309. sleep(1);
  14310. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 2");
  14311. sleep(1);
  14312. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 1");
  14313. sleep(1);
  14314. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 0");
  14315. AttenProfileCnt = 0;
  14316. init_appHandEXIDocument(&ccs_handshake);
  14317. //Qca7kPowerReset(); //reset QCA7000
  14318. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  14319. {
  14320. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[End_Process]1st sync...");
  14321. system("sync");
  14322. }
  14323. #endif
  14324. //STEP 4: Switch to State E
  14325. //Keep State E for 5 seconds
  14326. #if 0
  14327. SwitchCpStateE(ENABLE); //Set PWM Duty as 0 and set State as E (0V)
  14328. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 5");
  14329. sleep(1);
  14330. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 4");
  14331. sleep(1);
  14332. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 3");
  14333. sleep(1);
  14334. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 2");
  14335. sleep(1);
  14336. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 1");
  14337. sleep(1);
  14338. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 0");
  14339. #endif
  14340. //Reset Memory
  14341. unsigned char SlaveAddress_backup;
  14342. unsigned int matched_backup;
  14343. //unsigned char state_backup;
  14344. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Soft reset (closing SeccComm)...");
  14345. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------");
  14346. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "-- EVCOMM: END --");
  14347. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------\n");
  14348. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  14349. {
  14350. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "2nd sync...");
  14351. system("sync");
  14352. }
  14353. #endif
  14354. system("sleep 1");
  14355. //Backup CsuComm flags
  14356. SlaveAddress_backup = ShmInternalComm->SlaveAddress;
  14357. matched_backup = CSUCOMMDC_TASK_FLAG.matched;
  14358. //state_backup = Check_V2G_Flow_Status();
  14359. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  14360. memset(V2gtpMsgTxBuf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14361. memset(&ccs_handshake, 0, sizeof(struct appHandEXIDocument));
  14362. memset(&ccs_exi_doc_DIN, 0, sizeof(struct dinEXIDocument));
  14363. memset(V2GTP_Tx_buf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14364. memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  14365. memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
  14366. memset(ShmInternalComm, 0, sizeof(struct InternalComm));
  14367. memset(ShmCcsData, 0, sizeof(struct CcsData));
  14368. //Resume CsuComm flags
  14369. ShmInternalComm->SlaveAddress = SlaveAddress_backup;
  14370. CSUCOMMDC_TASK_FLAG.matched = matched_backup;
  14371. Sniffer_Candump(DISABLE);
  14372. Sniffer_Candump(ENABLE);
  14373. //memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo)); //EVCOMM_SYS_INFO.End_Process_inused = FALSE;
  14374. //EVCOMM_SYS_INFO.End_Process_inused = TRUE;
  14375. //Update_V2G_Flow_Status(state_backup);
  14376. //CP_Detection_Pid = 0;
  14377. //PP_Detection_Pid = 0;
  14378. //Error_Monitor_Pid = 0;
  14379. //system("cd /root;./reset_soft.sh");
  14380. system("pkill Module_CCS");
  14381. while(1)
  14382. {
  14383. //wait for CSU configrm
  14384. }
  14385. }
  14386. /*===========================================================================
  14387. FUNCTION: Parameters_Init
  14388. DESCRIPTION:
  14389. PRE-CONDITION:
  14390. INPUT:
  14391. OUTPUT:
  14392. GLOBAL VARIABLES:
  14393. =============================================================================*/
  14394. int Parameters_Init()
  14395. {
  14396. //Step 0: Generate random number
  14397. unsigned int value_random;
  14398. struct timeb time_seed;
  14399. ftime(&time_seed);
  14400. srand(time_seed.millitm);
  14401. //Step 1: Init SDP TCP Port
  14402. value_random = rand();
  14403. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active = (unsigned short)(SdpTcpServerPort + (value_random % 10000) + 1);
  14404. sprintf((char*)buf_log_evcomm,
  14405. "[Init]TCP Port:OK(%d)",
  14406. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  14407. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14408. //Step 2: Init SessionID
  14409. value_random = rand();
  14410. memcpy(&EVCOMM_SYS_INFO.SessionID[0], &value_random, 4);
  14411. value_random = rand();
  14412. memcpy(&EVCOMM_SYS_INFO.SessionID[4], &value_random, 4);
  14413. sprintf((char*)buf_log_evcomm,
  14414. "[Init]SessionID:OK(%02X%02X%02X%02X%02X%02X%02X%02X)",
  14415. EVCOMM_SYS_INFO.SessionID[0],
  14416. EVCOMM_SYS_INFO.SessionID[1],
  14417. EVCOMM_SYS_INFO.SessionID[2],
  14418. EVCOMM_SYS_INFO.SessionID[3],
  14419. EVCOMM_SYS_INFO.SessionID[4],
  14420. EVCOMM_SYS_INFO.SessionID[5],
  14421. EVCOMM_SYS_INFO.SessionID[6],
  14422. EVCOMM_SYS_INFO.SessionID[7]);
  14423. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14424. return 0;
  14425. }
  14426. /*===========================================================================
  14427. FUNCTION: AC share memory synchronize
  14428. DESCRIPTION:
  14429. PRE-CONDITION:
  14430. INPUT:
  14431. OUTPUT:
  14432. GLOBAL VARIABLES:
  14433. =============================================================================*/
  14434. int SyncAcShreaMemory()
  14435. {
  14436. #if (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE)
  14437. pid_t pid;
  14438. pid = fork();
  14439. if(pid == 0)
  14440. {
  14441. for(;;)
  14442. {
  14443. if(!EVCOMM_SYS_INFO.End_Process_inused)
  14444. {
  14445. for(uint8_t gun_index=0;gun_index<1;gun_index++)
  14446. {
  14447. //========================================
  14448. // CSU -> CCS setting
  14449. //========================================
  14450. // Permission
  14451. if(ShmInternalComm->ChargingPermission != ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission)
  14452. {
  14453. DEBUG_INFO("AC permission: %d -> %d\n", ShmInternalComm->ChargingPermission, ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission);
  14454. ShmInternalComm->ChargingPermission_new = ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission;
  14455. ShmInternalComm->ChargingPermission_pre = ShmInternalComm->ChargingPermission;
  14456. ShmInternalComm->ChargingPermission = ShmInternalComm->ChargingPermission_new;
  14457. }
  14458. // CP
  14459. ShmInternalComm->AC_CpPositiveVoltage = ShmCharger->gun_info[gun_index].acCcsInfo.CpPositiveVoltage;
  14460. if(ShmInternalComm->AC_CpPresentState != ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState)
  14461. {
  14462. DEBUG_INFO("CP state: %d -> %d\n", ShmInternalComm->AC_CpPresentState, ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState);
  14463. ShmInternalComm->AC_CpPresentState = ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState;
  14464. }
  14465. //========================================
  14466. // CCS -> CSU check
  14467. //========================================
  14468. // V2G message flow status
  14469. if(ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus != Check_V2G_Flow_Status())
  14470. {
  14471. //DEBUG_INFO("PresentMsgFlowStatus: %d -> %d\n", ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus, Check_V2G_Flow_Status());
  14472. ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus = Check_V2G_Flow_Status();
  14473. switch(ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus)
  14474. {
  14475. case PowerDeliveryRequestStart ... ChargingStatusResponse:
  14476. ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_START_MODE;
  14477. break;
  14478. case CM_SLAC_PARM_REQ ... PreChargeResponse:
  14479. ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_STANDBY_MODE;
  14480. break;
  14481. default:
  14482. ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_STOP_MODE;
  14483. break;
  14484. }
  14485. }
  14486. }
  14487. }
  14488. usleep(1000);
  14489. }
  14490. }
  14491. #endif
  14492. return 0;
  14493. }
  14494. /*===========================================================================
  14495. FUNCTION: main
  14496. DESCRIPTION:
  14497. PRE-CONDITION:
  14498. INPUT:
  14499. OUTPUT:
  14500. GLOBAL VARIABLES:
  14501. =============================================================================*/
  14502. int main(int argc, char *argv[])
  14503. {
  14504. //unsigned char Rtn;
  14505. //Initialization
  14506. ShareMemory_Init();
  14507. memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
  14508. if(RawSock > 0)
  14509. {
  14510. close(RawSock);
  14511. }
  14512. if(UdpSock > 0)
  14513. {
  14514. close(UdpSock);
  14515. }
  14516. if(TcpSock > 0)
  14517. {
  14518. close(TcpSock);
  14519. }
  14520. RawSock = UdpSock = TcpSock = -1;
  14521. Update_V2G_Flow_Status(IDLE);
  14522. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------");
  14523. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "-- EVCOMM: START --");
  14524. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------");
  14525. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "init...");
  14526. //Init V2G TCP/IPv6 packets buffer
  14527. V2gtpMsgRxBuf = (unsigned char *)malloc(V2GTP_MSG_RX_BUFFER_SIZE);
  14528. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  14529. V2gtpMsgTxBuf = (unsigned char *)malloc(V2GTP_MSG_TX_BUFFER_SIZE);
  14530. memset(V2gtpMsgTxBuf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14531. //Release State E Control
  14532. SwitchCpStateE(DISABLE);
  14533. OutputCpPwmDuty(100);
  14534. //start to detect CP pilot state
  14535. CP_Detection_Pid = 0;
  14536. CP_Detection(); //fork1
  14537. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork1]CP Detection: ON");
  14538. //start to detect errors
  14539. Error_Monitor(); //fork2
  14540. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork2]Error Monitor: ON");
  14541. //start to detect PP
  14542. PP_Detection_Pid = 0;
  14543. #if (PP_PROTECTION_MECHANISM == ENABLE)
  14544. PP_Detection();
  14545. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork3]PP Detection: ON");
  14546. #else
  14547. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork3]PP Detection: OFF");
  14548. #endif
  14549. //Init communication parameters
  14550. GetEthMac((uint8_t*)QcaInterface, CsuMac);
  14551. AttenProfileCnt = 0;
  14552. init_appHandEXIDocument(&ccs_handshake);
  14553. //Init Energy transfer mode
  14554. //[To-Do] Parsing Model Name
  14555. ShmCcsData->EnergyTransferMode = CCS_ENERGY_TRANSFER_MODE;
  14556. //struct ChargingInfoData *ccs;
  14557. //ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  14558. Parameters_Init();
  14559. Sniffer_Tcpdump(ENABLE);
  14560. #if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  14561. sleep(1); //wait for tcpdump getting ready
  14562. #endif
  14563. SyncAcShreaMemory();
  14564. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Init]DONE");
  14565. while(1)
  14566. {
  14567. //DEBUG_PRINTF_EVCOMM_DETAIL("\nV2gFlowStatus = %d\n", V2gFlowStatus);
  14568. //if((ShmInternalComm->ChargingPermission == 0x01) && (CheckConnectorPlugIn() == 1))
  14569. //if((CheckConnectorPlugIn() == TRUE) && (ShmInternalComm->ChargingPermission == TRUE))
  14570. //if(ShmInternalComm->ChargingPermission == 0x01)
  14571. //if(CheckConnectorPlugIn() == TRUE)
  14572. if (EVCOMM_SYS_INFO.End_Process_inused == FALSE)
  14573. {
  14574. if(V2gFlowStatus < SLACC_SDP_UDP_Connection)
  14575. {
  14576. SlacComm();
  14577. }
  14578. else if(V2gFlowStatus == SLACC_SDP_UDP_Connection)
  14579. {
  14580. if(SdpUdpConnected() == 1)
  14581. {
  14582. Update_V2G_Flow_Status(SLACC_SDP_TCP_Connection);
  14583. continue;
  14584. }
  14585. SlacComm(); //TC_SECC_VTB_CmSlacMatch_004
  14586. ftime(&SeqEndTime);
  14587. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_join)
  14588. {
  14589. sprintf((char*)buf_log_evcomm,
  14590. "Wait SLACC_SDP_UDP_Connection Timeout - TT_match_join (%.02lf of %d ms)\n",
  14591. DiffTimeb(SeqStartTime, SeqEndTime),
  14592. TT_match_join);
  14593. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14594. Update_V2G_Flow_Status(Sequence_Timeout);
  14595. //Update_ShmStatusCode(); //[To-Do] to be implemented
  14596. //CCS_SECC_TIMEOUT_SLACC_SDP_UDP_TT_match_join (023823)
  14597. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  14598. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  14599. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  14600. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  14601. ShmStatusCodeData->PresentStatusCode[0][4] = 2;
  14602. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  14603. //CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  14604. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  14605. }
  14606. }
  14607. else if(V2gFlowStatus == SLACC_SDP_TCP_Connection)
  14608. {
  14609. if((TcpAcceptFd = V2gTcpConnected()) > 0)
  14610. {
  14611. Update_V2G_Flow_Status(SupportedAppProtocolRequest);
  14612. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14613. continue;
  14614. }
  14615. SlacComm();
  14616. ftime(&SeqEndTime);
  14617. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_join)
  14618. {
  14619. sprintf((char*)buf_log_evcomm,
  14620. "Wait SLACC_SDP_TCP_Connection Timeout - TT_match_join (%.02lf / %d ms)",
  14621. DiffTimeb(SeqStartTime, SeqEndTime),
  14622. TT_match_join);
  14623. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14624. Update_V2G_Flow_Status(Sequence_Timeout);
  14625. //Update_ShmStatusCode(); //[To-Do] to be implemented
  14626. //CCS_SECC_TIMEOUT_SLACC_SDP_TCP_TT_match_join (023824)
  14627. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  14628. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  14629. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  14630. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  14631. ShmStatusCodeData->PresentStatusCode[0][4] = 2;
  14632. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  14633. //CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  14634. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  14635. }
  14636. }
  14637. else if(V2gFlowStatus <= SessionStopResponse)
  14638. {
  14639. if (V2gComm(TcpAcceptFd) < 0)
  14640. {
  14641. //error occours
  14642. }
  14643. }
  14644. else if (V2gFlowStatus >= Performance_Timeout)
  14645. {
  14646. //End_Process
  14647. }
  14648. else
  14649. {
  14650. //null
  14651. }
  14652. }
  14653. usleep(1000);
  14654. } //while
  14655. }//main while