Module_CCS.c 651 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275
  1. /*
  2. * Module_CCS.c
  3. *
  4. * Created on: 2020/03/16
  5. * Author: foluswen
  6. */
  7. #include "Module_CCS.h"
  8. #include "define_ccs.h"
  9. #include "main.h"
  10. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  11. struct StatusCodeData *ShmStatusCodeData;
  12. struct CcsData *ShmCcsData;
  13. struct InternalComm *ShmInternalComm;
  14. struct Charger *ShmCharger;
  15. struct appHandEXIDocument ccs_handshake;
  16. struct dinEXIDocument ccs_exi_doc_DIN;
  17. struct iso1EXIDocument ccs_exi_doc_ISO1;
  18. struct iso2EXIDocument ccs_exi_doc_ISO2;
  19. unsigned char V2GTP_Tx_buf[V2GTP_MSG_TX_BUFFER_SIZE]; //64*1024 = 65,536 = 65.5KB
  20. unsigned char buf_log_evcomm[SIZE_OF_LOG_BUFFER];
  21. unsigned char buf_log_evcomm_fork1[SIZE_OF_LOG_BUFFER];
  22. unsigned char buf_log_evcomm_fork2[SIZE_OF_LOG_BUFFER];
  23. unsigned char buf_log_evcomm_fork3[SIZE_OF_LOG_BUFFER];
  24. pid_t CP_Detection_Pid = 0;
  25. pid_t PP_Detection_Pid = 0;
  26. pid_t Error_Monitor_Pid = 0;
  27. int TcpAcceptFd;
  28. enum MsgFlowStatus V2gFlowStatus;
  29. int RawSock,UdpSock,TcpSock;
  30. unsigned char V2gtpMsgRxBuf[V2GTP_MSG_RX_BUFFER_SIZE] = {0};
  31. unsigned char V2gtpMsgTxBuf[V2GTP_MSG_TX_BUFFER_SIZE] = {0};
  32. unsigned short Aag[64];
  33. struct MmeHeader SendMmePacket;
  34. int SendMmePacketSize;
  35. unsigned char CsuMac[6],QcaMac[6],EvMac[6],SlacRunId[8],eth0Mac[6];
  36. struct sockaddr_ll DestSocketAddress;
  37. struct ifreq Req;
  38. unsigned int PwmStartTime=0;
  39. struct timeb SeqStartTime, SeqEndTime;
  40. unsigned char AagGroupsNum, MnbcSoundNum, AttenProfileCnt;
  41. unsigned char NewNmkKey[16], Nid[7];
  42. uint8_t get_V2G_Status_Name(uint8_t statusCode, char *statusName)
  43. {
  44. int result = PASS;
  45. switch(statusCode)
  46. {
  47. case IDLE:
  48. sprintf(statusName, "IDLE");
  49. break;
  50. case CM_SLAC_PARM_REQ:
  51. sprintf(statusName, "CM_SLAC_PARM_REQ");
  52. break;
  53. case CM_SLAC_PARM_CONF:
  54. sprintf(statusName, "CM_SLAC_PARM_CONF");
  55. break;
  56. case CM_START_ATTEN_CHAR_IND:
  57. sprintf(statusName, "CM_START_ATTEN_CHAR_IND");
  58. break;
  59. case CM_MNBC_SOUND_IND:
  60. sprintf(statusName, "CM_MNBC_SOUND_IND");
  61. break;
  62. case CM_ATTEN_CHAR_IND:
  63. sprintf(statusName, "CM_ATTEN_CHAR_IND");
  64. break;
  65. case CM_ATTEN_CHAR_RSP:
  66. sprintf(statusName, "CM_ATTEN_CHAR_RSP");
  67. break;
  68. case CM_VALIDATE_REQ:
  69. sprintf(statusName, "CM_VALIDATE_REQ");
  70. break;
  71. case CM_VALIDATE_CNF:
  72. sprintf(statusName, "CM_VALIDATE_CNF");
  73. break;
  74. case CM_SLAC_MATCH_REQ:
  75. sprintf(statusName, "CM_SLAC_MATCH_REQ");
  76. break;
  77. case CM_SLAC_MATCH_CNF:
  78. sprintf(statusName, "CM_SLAC_MATCH_CNF");
  79. break;
  80. case CM_AMP_MAP_REQ:
  81. sprintf(statusName, "CM_AMP_MAP_REQ");
  82. break;
  83. case CM_AMP_MAP_CNF:
  84. sprintf(statusName, "CM_AMP_MAP_CNF");
  85. break;
  86. case CM_SET_KEY_REQ:
  87. sprintf(statusName, "CM_SET_KEY_REQ");
  88. break;
  89. case CM_SET_KEY_CNF:
  90. sprintf(statusName, "CM_SET_KEY_CNF");
  91. break;
  92. case SLACC_SDP_UDP_Connection:
  93. sprintf(statusName, "SLACC_SDP_UDP_Connection");
  94. break;
  95. case SLACC_SDP_TCP_Connection:
  96. sprintf(statusName, "SLACC_SDP_TCP_Connection");
  97. break;
  98. case SupportedAppProtocolRequest:
  99. sprintf(statusName, "SupportedAppProtocolRequest");
  100. break;
  101. case SupportedAppProtocolResponse:
  102. sprintf(statusName, "SupportedAppProtocolResponse");
  103. break;
  104. case SessionSetupRequest:
  105. sprintf(statusName, "SessionSetupRequest");
  106. break;
  107. case SessionSetupResponse:
  108. sprintf(statusName, "UnSessionSetupResponseknown");
  109. break;
  110. case ServiceDiscoveryRequest:
  111. sprintf(statusName, "ServiceDiscoveryRequest");
  112. break;
  113. case ServiceDiscoveryResponse:
  114. sprintf(statusName, "ServiceDiscoveryResponse");
  115. break;
  116. case ServiceDetailRequest:
  117. sprintf(statusName, "ServiceDetailRequest");
  118. break;
  119. case ServiceDetailResponse:
  120. sprintf(statusName, "ServiceDetailResponse");
  121. break;
  122. case ServiceAndPaymentSelectionRequest:
  123. sprintf(statusName, "ServiceAndPaymentSelectionRequest");
  124. break;
  125. case ServiceAndPaymentSelectionResponse:
  126. sprintf(statusName, "ServiceAndPaymentSelectionResponse");
  127. break;
  128. case PaymentDetailsRequest:
  129. sprintf(statusName, "PaymentDetailsRequest");
  130. break;
  131. case PaymentDetailsResponse:
  132. sprintf(statusName, "PaymentDetailsResponse");
  133. break;
  134. case AuthorizationRequest:
  135. sprintf(statusName, "AuthorizationRequest");
  136. break;
  137. case AuthorizationResponse:
  138. sprintf(statusName, "AuthorizationResponse");
  139. break;
  140. case CertificateUpdateRequest:
  141. sprintf(statusName, "CertificateUpdateRequest");
  142. break;
  143. case CertificateUpdateResponse:
  144. sprintf(statusName, "CertificateUpdateResponse");
  145. break;
  146. case CertificateInstallationRequest:
  147. sprintf(statusName, "CertificateInstallationRequest");
  148. break;
  149. case CertificateInstallationResponse:
  150. sprintf(statusName, "CertificateInstallationResponse");
  151. break;
  152. case ChargeParameterDiscoveryRequest:
  153. sprintf(statusName, "ChargeParameterDiscoveryRequest");
  154. break;
  155. case ChargeParameterDiscoveryResponse:
  156. sprintf(statusName, "ChargeParameterDiscoveryResponse");
  157. break;
  158. case CableCheckRequest:
  159. sprintf(statusName, "CableCheckRequest");
  160. break;
  161. case CableCheckResponse:
  162. sprintf(statusName, "CableCheckResponse");
  163. break;
  164. case PreChargeRequest:
  165. sprintf(statusName, "PreChargeRequest");
  166. break;
  167. case PreChargeResponse:
  168. sprintf(statusName, "PreChargeResponse");
  169. break;
  170. case PowerDeliveryRequestStart:
  171. sprintf(statusName, "PowerDeliveryRequestStart");
  172. break;
  173. case PowerDeliveryResponsetStart:
  174. sprintf(statusName, "PowerDeliveryResponsetStart");
  175. break;
  176. case ChargingStatusRequest:
  177. sprintf(statusName, "ChargingStatusRequest");
  178. break;
  179. case ChargingStatusResponse:
  180. sprintf(statusName, "ChargingStatusResponse");
  181. break;
  182. case CurrentDemandRequest:
  183. sprintf(statusName, "CurrentDemandRequest");
  184. break;
  185. case CurrentDemandResponse:
  186. sprintf(statusName, "CurrentDemandResponse");
  187. break;
  188. case MeteringReceiptRequest:
  189. sprintf(statusName, "MeteringReceiptRequest");
  190. break;
  191. case MeteringReceiptResponse:
  192. sprintf(statusName, "MeteringReceiptResponse");
  193. break;
  194. case PowerDeliveryRequestStop:
  195. sprintf(statusName, "PowerDeliveryRequestStop");
  196. break;
  197. case PowerDeliveryResponseStop:
  198. sprintf(statusName, "PowerDeliveryResponseStop");
  199. break;
  200. case WeldingDetectionRequest:
  201. sprintf(statusName, "WeldingDetectionRequest");
  202. break;
  203. case WeldingDetectionResponse:
  204. sprintf(statusName, "WeldingDetectionResponse");
  205. break;
  206. case SessionStopRequest:
  207. sprintf(statusName, "SessionStopRequest");
  208. break;
  209. case SessionStopResponse:
  210. sprintf(statusName, "SessionStopResponse");
  211. break;
  212. case Performance_Timeout:
  213. sprintf(statusName, "Performance_Timeout");
  214. break;
  215. case Sequence_Timeout:
  216. sprintf(statusName, "Sequence_Timeout");
  217. break;
  218. case Other_Fault:
  219. sprintf(statusName, "Other_Fault");
  220. break;
  221. default:
  222. sprintf(statusName, "Unknown");
  223. result = FAIL;
  224. break;
  225. }
  226. return result;
  227. }
  228. /*===========================================================================
  229. FUNCTION: Check_V2G_Flow_Status
  230. DESCRIPTION:
  231. PRE-CONDITION:
  232. INPUT:
  233. OUTPUT:
  234. GLOBAL VARIABLES:
  235. =============================================================================*/
  236. unsigned char Check_V2G_Flow_Status()
  237. {
  238. unsigned char result = 0;
  239. switch (ShmCcsData->CommProtocol)
  240. {
  241. case V2GT_MSG_PROTOCOL_DIN70121: //0
  242. {
  243. result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
  244. break;
  245. }
  246. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  247. {
  248. result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
  249. break;
  250. }
  251. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  252. {
  253. result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
  254. break;
  255. }
  256. default:
  257. break;
  258. }
  259. return result;
  260. }
  261. /*===========================================================================
  262. FUNCTION: CAN_Tx_MSG
  263. DESCRIPTION:
  264. PRE-CONDITION:
  265. INPUT:
  266. OUTPUT:
  267. GLOBAL VARIABLES:
  268. =============================================================================*/
  269. int CAN_Tx_MSG(int Fd, unsigned int MsgId, unsigned char SlaveAddress, unsigned char DataLength, unsigned char *SendData)
  270. {
  271. #if 0
  272. struct can_frame frame;
  273. struct timeb StartTime, EndTime;
  274. unsigned int tmp = 0;
  275. int nbytes = 0;
  276. int i = 0;
  277. //Protection: To avoid unexpected length for CAN bus payload.
  278. if (DataLength > 8)
  279. {
  280. DataLength = 8;
  281. }
  282. memset(&frame, 0, sizeof(struct can_frame));
  283. frame.can_id = 0x80000000 | CAN_SEND_DIRECTION | MsgId | SlaveAddress; //0x80000000: extension ID format
  284. frame.can_dlc = DataLength;
  285. memcpy(frame.data, SendData, DataLength);
  286. nbytes = write(Fd, &frame, sizeof(struct can_frame));
  287. #if 0
  288. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][CAN_Tx_MSG] <%X> ", frame.can_id);
  289. for (i = 0; i < frame.can_dlc; i++)
  290. {
  291. DEBUG_PRINTF_EVCOMM_DETAIL("%02X ", frame.data[i]);
  292. }
  293. DEBUG_PRINTF_EVCOMM_DETAIL("(%d Bytes)\n", frame.can_dlc);
  294. #endif
  295. return nbytes;
  296. #else
  297. return -1;
  298. #endif
  299. }
  300. /*===========================================================================
  301. FUNCTION: Proc_EVStopRes
  302. DESCRIPTION:
  303. PRE-CONDITION:
  304. INPUT:
  305. OUTPUT:
  306. GLOBAL VARIABLES:
  307. =============================================================================*/
  308. int Proc_EVStopRes(int Fd)
  309. {
  310. int nbytes;
  311. unsigned char Buffer[8];
  312. memset(Buffer, 0, sizeof(Buffer));
  313. if (CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency == TRUE)
  314. {
  315. Buffer[0] = EV_EMERGENCY_STOP; //2
  316. }
  317. else
  318. {
  319. Buffer[0] = EV_NORMAL_STOP; //1
  320. }
  321. /*
  322. if(strlen(ShmStatusCodeData->PresentStatusCode[0]) > 0)
  323. {
  324. memcpy(Buffer + 2, ShmStatusCodeData->PresentStatusCode[0], 6);
  325. }
  326. */
  327. Buffer[1] = ShmStatusCodeData->PresentStatusCode[0][0];
  328. Buffer[2] = ShmStatusCodeData->PresentStatusCode[0][1];
  329. Buffer[3] = ShmStatusCodeData->PresentStatusCode[0][2];
  330. Buffer[4] = ShmStatusCodeData->PresentStatusCode[0][3];
  331. Buffer[5] = ShmStatusCodeData->PresentStatusCode[0][4];
  332. Buffer[6] = ShmStatusCodeData->PresentStatusCode[0][5];
  333. nbytes = CAN_Tx_MSG(Fd, CAN_CMD_EV_STOP_EVENT, ShmInternalComm->SlaveAddress, 7, Buffer);
  334. //system("echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle"); //for test only
  335. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  336. SAVE_SYS_LOG_MSG_EVCOMM("Sending STOP Command to CSU\n");
  337. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = FALSE;
  338. return nbytes;
  339. }
  340. /*===========================================================================
  341. FUNCTION: Sniffer_Candump
  342. DESCRIPTION:
  343. 1. Only used in End_Process(), which is in fork2 of SeccComm task.
  344. PRE-CONDITION:
  345. INPUT:
  346. OUTPUT:
  347. 0: accept
  348. -1: invalid
  349. GLOBAL VARIABLES:
  350. =============================================================================*/
  351. int Sniffer_Candump(char cmd)
  352. {
  353. #if (CANDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  354. if (cmd == ENABLE)
  355. {
  356. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]init");
  357. system("cd /mnt/;rm -rf candump/");
  358. system("cd /mnt/;mkdir candump");
  359. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]on");
  360. system("cd /mnt/candump;candump -l can0 &");
  361. return 0;
  362. }
  363. else if (cmd == DISABLE)
  364. {
  365. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]off");
  366. system("killall candump");
  367. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]save");
  368. system("cd /;cp -rfv /mnt/candump /Storage/SystemLog/");
  369. return 0;
  370. }
  371. else
  372. {
  373. sprintf((char*)buf_log_evcomm_fork2, "[candump]unexpected cmd(%d)", cmd);
  374. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork2);
  375. return -1;
  376. }
  377. #endif
  378. return 0;
  379. }
  380. /*===========================================================================
  381. FUNCTION: Sniffer_Tcpdump
  382. DESCRIPTION:
  383. PRE-CONDITION:
  384. INPUT:
  385. OUTPUT:
  386. GLOBAL VARIABLES:
  387. =============================================================================*/
  388. int Sniffer_Tcpdump(char cmd)
  389. {
  390. #if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  391. if (cmd == ENABLE)
  392. {
  393. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]init...");
  394. system("cd /mnt/;rm -rf tcpdump/");
  395. system("cd /mnt/;mkdir tcpdump");
  396. unsigned char buf[256];
  397. time_t CurrentTime;
  398. struct tm *tm;
  399. struct timeval tv;
  400. memset(buf, 0, sizeof(buf));
  401. CurrentTime = time(NULL);
  402. tm = localtime(&CurrentTime);
  403. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  404. sprintf((char*)buf,
  405. "tcpdump -i eth1 -w /mnt/tcpdump/[%s][%04d%02d%02d-%02d:%02d:%02d.%06d]packets.pcap&",
  406. FIRMWARE_VERSION,
  407. tm->tm_year + 1900,
  408. tm->tm_mon + 1,
  409. tm->tm_mday,
  410. tm->tm_hour,
  411. tm->tm_min,
  412. tm->tm_sec,
  413. tv.tv_usec
  414. );
  415. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]on");
  416. system(buf);
  417. return 0;
  418. }
  419. else if (cmd == DISABLE)
  420. {
  421. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]off");
  422. system("killall tcpdump");
  423. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]wait: 2s");
  424. sleep(1);
  425. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]wait: 1s");
  426. sleep(1);
  427. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]save");
  428. system("cd /;cp -rfv /mnt/tcpdump /Storage/SystemLog/");
  429. return 0;
  430. }
  431. else
  432. {
  433. sprintf((char*)buf_log_evcomm, "[tcpdump]unexpected cmd(%d)", cmd);
  434. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  435. return -1;
  436. }
  437. #endif
  438. return 0;
  439. }
  440. /*===========================================================================
  441. FUNCTION: Check_V2G_Flow_Status_pre
  442. DESCRIPTION:
  443. PRE-CONDITION:
  444. INPUT:
  445. OUTPUT:
  446. GLOBAL VARIABLES:
  447. =============================================================================*/
  448. unsigned char Check_V2G_Flow_Status_pre()
  449. {
  450. unsigned char result = 0;
  451. switch (ShmCcsData->CommProtocol)
  452. {
  453. case V2GT_MSG_PROTOCOL_DIN70121: //0
  454. {
  455. result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus_pre;
  456. break;
  457. }
  458. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  459. {
  460. result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus_pre;
  461. break;
  462. }
  463. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  464. {
  465. result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus_pre;
  466. break;
  467. }
  468. default:
  469. break;
  470. }
  471. return result;
  472. }
  473. /*===========================================================================
  474. FUNCTION: Update_V2G_Flow_Status
  475. DESCRIPTION:
  476. PRE-CONDITION:
  477. INPUT:
  478. OUTPUT:
  479. 1. V2gFlowStatus
  480. GLOBAL VARIABLES:
  481. 1. V2gFlowStatus
  482. =============================================================================*/
  483. int Update_V2G_Flow_Status(unsigned int state_new)
  484. {
  485. unsigned char state_now;
  486. char nameNow[64], nameNew[64];
  487. state_now = Check_V2G_Flow_Status();
  488. get_V2G_Status_Name(state_now, nameNow);
  489. get_V2G_Status_Name(state_new, nameNew);
  490. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE ||
  491. CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused == TRUE)
  492. {
  493. if (state_now != Performance_Timeout && //253
  494. state_now != Sequence_Timeout && //254
  495. state_now != Other_Fault) //255
  496. {
  497. SAVE_SYS_LOG_MSG_EVCOMM("[Warning]state-%s(%d) change: ignored (End_Process_inused:%d, FW_Update_Task_inused:%d)\n",
  498. nameNew, state_new,
  499. EVCOMM_SYS_INFO.End_Process_inused,
  500. CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused);
  501. return -1;
  502. }
  503. }
  504. if (state_now != state_new)
  505. {
  506. //Step 1: Check if Error Occours
  507. if (state_now == Performance_Timeout || //253
  508. state_now == Sequence_Timeout || //254
  509. state_now == Other_Fault) //255
  510. {
  511. if (state_new != IDLE)
  512. {
  513. if (EVCOMM_SYS_INFO.State_Change_Ignored_Notice == FALSE)
  514. {
  515. EVCOMM_SYS_INFO.State_Change_Ignored_Notice = TRUE;
  516. SAVE_SYS_LOG_MSG_EVCOMM("[Warning]state-%s(%d) change: ignored(now in error state-%s(%d))\n",
  517. nameNow, state_new,
  518. nameNew, state_now);
  519. }
  520. return -1;
  521. }
  522. }
  523. //Updating the state formally.
  524. SAVE_SYS_LOG_MSG_EVCOMM("%s(%02d) >> %s(%02d)\n",
  525. nameNow, state_now,
  526. nameNew, state_new);
  527. V2gFlowStatus = state_new;
  528. state_now = state_new;
  529. switch (ShmCcsData->CommProtocol)
  530. {
  531. case V2GT_MSG_PROTOCOL_DIN70121: //0
  532. {
  533. ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
  534. ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus = V2gFlowStatus;
  535. break;
  536. }
  537. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  538. {
  539. ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
  540. ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus = V2gFlowStatus;
  541. break;
  542. }
  543. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  544. {
  545. ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
  546. ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus = V2gFlowStatus;
  547. break;
  548. }
  549. default:
  550. break;
  551. }
  552. }
  553. return 0;
  554. }
  555. double DiffTimeb(struct timeb ST, struct timeb ET)
  556. {
  557. //return milli-second
  558. double StartTime, EndTime;
  559. double t_diff;
  560. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  561. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  562. t_diff = EndTime - StartTime;
  563. if (t_diff < 0)
  564. {
  565. return -1;
  566. }
  567. return t_diff;
  568. }
  569. double DiffTimeb_fork1_Error_Monitor(struct timeb ST, struct timeb ET)
  570. {
  571. //return milli-second
  572. static double StartTime, EndTime;
  573. static double t_diff;
  574. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  575. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  576. t_diff = EndTime - StartTime;
  577. if (t_diff < 0)
  578. {
  579. return -1;
  580. }
  581. return t_diff;
  582. }
  583. double DiffTimeb_fork2_Error_Monitor(struct timeb ST, struct timeb ET)
  584. {
  585. //return milli-second
  586. static double StartTime, EndTime;
  587. static double t_diff;
  588. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  589. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  590. t_diff = EndTime - StartTime;
  591. if (t_diff < 0)
  592. {
  593. return -1;
  594. }
  595. return t_diff;
  596. }
  597. /*===========================================================================
  598. FUNCTION: ShareMemory_Init
  599. DESCRIPTION:
  600. PRE-CONDITION:
  601. INPUT:
  602. OUTPUT:
  603. GLOBAL VARIABLES:
  604. =============================================================================*/
  605. int ShareMemory_Init()
  606. {
  607. int MeterSMId;
  608. //create ShmSysConfigAndInfo
  609. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
  610. {
  611. DEBUG_ERROR("ShareMemory_Init:shmget ShmSysConfigAndInfo NG");
  612. return 0;
  613. }
  614. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  615. {
  616. DEBUG_ERROR("ShareMemory_Init:shmat ShmSysConfigAndInfo NG\n");
  617. return 0;
  618. }
  619. //create ShmStatusCodeData
  620. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
  621. {
  622. DEBUG_ERROR("ShareMemory_Init:shmget ShmStatusCodeData NG");
  623. return 0;
  624. }
  625. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  626. {
  627. DEBUG_ERROR("ShareMemory_Init:shmat ShmStatusCodeData NG");
  628. return 0;
  629. }
  630. //create ShmCcsData
  631. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
  632. {
  633. DEBUG_ERROR("ShareMemory_Init:shmget ShmCcsData NG");
  634. return 0;
  635. }
  636. else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  637. {
  638. DEBUG_ERROR("ShareMemory_Init:shmat ShmCcsData NG");
  639. return 0;
  640. }
  641. //create ShmInternalComm
  642. if ((MeterSMId = shmget(ShmInternalCommKey, sizeof(struct InternalComm), IPC_CREAT | 0777)) < 0)
  643. {
  644. DEBUG_ERROR("ShareMemory_Init:shmget ShmInternalComm NG");
  645. return 0;
  646. }
  647. else if ((ShmInternalComm = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  648. {
  649. DEBUG_ERROR("ShareMemory_Init:shmat ShmInternalComm NG");
  650. return 0;
  651. }
  652. //Initial ShmCharger
  653. if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
  654. {
  655. DEBUG_ERROR("shmget ShmChargerKey NG\r\n");
  656. return 0;
  657. }
  658. else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  659. {
  660. DEBUG_ERROR("shmat ShmChargerKey NG\r\n");
  661. return 0;
  662. }
  663. //[To-Do] The initialization here is reduntant and should be removed partially.
  664. //SHM_Init_supportedAppProtocolRes(ShmCcsData);
  665. //SHM_Init_din_SessionSetupRes(ShmCcsData);
  666. //SHM_Init_din_ServiceDiscoveryRes(ShmCcsData);
  667. //SHM_Init_din_ServiceAndPaymentSelectionRes(ShmCcsData);
  668. //SHM_Init_din_ContractAuthenticationRes(ShmCcsData);
  669. SHM_Init_din_ChargeParameterDiscoveryRes(ShmCcsData);
  670. SHM_Init_din_CableCheckRes(ShmCcsData);
  671. SHM_Init_din_PreChargeRes(ShmCcsData);
  672. SHM_Init_din_PowerDeliveryRes(ShmCcsData);
  673. SHM_Init_din_CurrentDemandRes(ShmCcsData);
  674. SHM_Init_din_WeldingDetectionRes(ShmCcsData);
  675. SHM_Init_din_SessionStopRes(ShmCcsData);
  676. return 1;
  677. }
  678. /*===========================================================================
  679. FUNCTION: GetEthMac
  680. DESCRIPTION:
  681. 1. Accessing current CsuMac address, if Eth = eth1
  682. 2. The address of eth1(for QCA7000) is a random number, which will be modified
  683. after each time of booting up system.
  684. PRE-CONDITION:
  685. INPUT:
  686. OUTPUT:
  687. GLOBAL VARIABLES:
  688. =============================================================================*/
  689. int GetEthMac(unsigned char *Eth, unsigned char *mac)
  690. {
  691. //Parameters:MAC,IP,Mask,Gateway
  692. int fd;
  693. unsigned char addr[18], Buffer[128];
  694. memset(Buffer, 0, sizeof(Buffer));
  695. sprintf((char*)Buffer, "cat /sys/class/net/%s/address > /mnt/GetEthInfo", Eth); //CsuMac (Eth = eth1)
  696. system((char*)Buffer);
  697. fd = open("/mnt/GetEthInfo", O_RDONLY);
  698. if(fd < 0)
  699. {
  700. system("rm -f /mnt/GetEthInfo");
  701. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "GetEthMac: MAC Address open error");
  702. return 0;
  703. }
  704. memset(mac, 0, 6);
  705. memset(addr, 0, sizeof(addr));
  706. read(fd, addr, 17);
  707. close(fd);
  708. system("rm -f /mnt/GetEthInfo");
  709. sscanf((char*)addr, "%02x:%02x:%02x:%02x:%02x:%02x", (uint32_t *)&mac[0], (uint32_t *)&mac[1], (uint32_t *)&mac[2], (uint32_t *)&mac[3], (uint32_t *)&mac[4], (uint32_t *)&mac[5]); //CsuMac (Eth = eth1)
  710. SAVE_SYS_LOG_MSG_EVCOMM("EVSE MAC address(%s): %02X:%02X:%02X:%02X:%02X:%02X\n",
  711. Eth, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  712. return 1;
  713. }
  714. /*===========================================================================
  715. FUNCTION: ReadAdcVolt
  716. DESCRIPTION:
  717. 1. fork1
  718. PRE-CONDITION:
  719. INPUT:
  720. OUTPUT:
  721. GLOBAL VARIABLES:
  722. =============================================================================*/
  723. float ReadAdcVolt(unsigned char AdcChannel)
  724. {
  725. //AIN0=CCS GUN Temp 1
  726. //AIN1=CCS GUN Temp 2
  727. //AIN2=CCS_Proximity/2
  728. //AIN3=pilot voltage
  729. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  730. return 0;
  731. #else
  732. if(AdcChannel == 3)
  733. {
  734. int fd,count,AvgTimes;
  735. unsigned char SampleBuf[4];
  736. float TmpVolt, MinSample, AvgSample = 0;
  737. fd = open("/sys/bus/iio/devices/iio\\:device0/in_voltage3_raw", O_RDONLY);
  738. if(fd > 0)
  739. {
  740. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  741. for(AvgTimes = 0; AvgTimes < 3; AvgTimes++) //period = 60~91 ms(renice -10, , CurrentDemand()) /*+++ 20200909, vern, extend detection time for interference ---*/
  742. {
  743. count = 0;
  744. MinSample = 2306;
  745. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  746. while(count < 40) //period = 21~42ms (renice -10, CurrentDemand()) /*+++ 20200909, vern, extend detection time for interference ---*/
  747. {
  748. //re-sampling period = 3~13ms (renice -10, SLAC())
  749. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  750. read(fd, SampleBuf, 4); //period = 3.2~10ms (renice -10, SLAC())
  751. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  752. TmpVolt = atoi((char*)SampleBuf);
  753. if((TmpVolt < 2306) && (TmpVolt > 0))//positive voltage
  754. {
  755. if(TmpVolt < MinSample)
  756. {
  757. MinSample = TmpVolt;
  758. }
  759. count++;
  760. }
  761. lseek(fd, 0, SEEK_SET);
  762. }
  763. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  764. AvgSample += MinSample;
  765. }
  766. AvgSample /= AvgTimes;
  767. close(fd);
  768. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  769. return ((0.954-(1.8*AvgSample/4095))/0.06);
  770. }
  771. else
  772. {
  773. return -1;
  774. }
  775. }
  776. else
  777. {
  778. FILE *fp;
  779. unsigned char str[64];
  780. unsigned char AdcValue[8];
  781. if(AdcChannel > 7)
  782. {
  783. return -1;
  784. }
  785. memset(str,0,sizeof(str));
  786. memset(AdcValue,0,sizeof(AdcValue));
  787. sprintf((char*)str, "cat /sys/bus/iio/devices/iio\\:device0/in_voltage%d_raw", AdcChannel);
  788. fp=popen((char*)str, "r");
  789. if(fgets((char*)AdcValue,sizeof(AdcValue),fp) == NULL)
  790. {
  791. pclose(fp);
  792. return -1;
  793. }
  794. pclose(fp);
  795. //Vin = Vref *D / (2^n - 1)
  796. return ((float)1.8*(float)atoi((char*)AdcValue))/4095;
  797. }
  798. #endif
  799. }
  800. /*===========================================================================
  801. FUNCTION: ReadAdcVolt
  802. DESCRIPTION:
  803. //AIN0=CCS GUN Temp 1
  804. //AIN1=CCS GUN Temp 2
  805. //AIN2=CCS_Proximity/2
  806. //AIN3=pilot voltage
  807. PRE-CONDITION:
  808. INPUT:
  809. OUTPUT:
  810. GLOBAL VARIABLES:
  811. =============================================================================*/
  812. float ReadAdcVolt_PP_fork3()
  813. {
  814. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  815. return 0;
  816. #else
  817. int fd, AvgTimes;
  818. unsigned char SampleBuf[4];
  819. float TmpVolt = 0;
  820. float AvgSample = 0;
  821. float V_pp = 0;
  822. fd = open("/sys/bus/iio/devices/iio\\:device0/in_voltage2_raw", O_RDONLY); //PP
  823. if(fd > 0)
  824. {
  825. for(AvgTimes = 0; AvgTimes < 5; AvgTimes++) //get 5 samples
  826. {
  827. read(fd, SampleBuf, 4);
  828. TmpVolt = atoi((char*)SampleBuf);
  829. lseek(fd, 0, SEEK_SET);
  830. AvgSample += TmpVolt;
  831. }
  832. close(fd);
  833. AvgSample /= AvgTimes;
  834. V_pp = (3.6*AvgSample)/4095; //PP
  835. #if 0
  836. printf("PP_adc = %.02f, PP_v = %.02f\n", AvgSample, V_pp);
  837. usleep(3000000); //300ms
  838. #endif
  839. usleep(20000); //20ms
  840. return V_pp;
  841. }
  842. else
  843. {
  844. return -1;
  845. }
  846. #endif
  847. }
  848. /*===========================================================================
  849. FUNCTION: Qca7kPowerReset
  850. DESCRIPTION:
  851. PRE-CONDITION:
  852. INPUT:
  853. OUTPUT:
  854. GLOBAL VARIABLES:
  855. =============================================================================*/
  856. void Qca7kPowerReset()
  857. {
  858. SAVE_SYS_LOG_MSG_EVCOMM("QCA7000 reset...\n");
  859. system("ifconfig eth1 down");
  860. usleep(500000);
  861. system("echo 0 > /sys/class/gpio/gpio115/value");
  862. usleep(500000);
  863. system("echo 1 > /sys/class/gpio/gpio115/value");
  864. usleep(500000);
  865. system("ifconfig eth1 up");
  866. usleep(500000);
  867. }
  868. /*===========================================================================
  869. FUNCTION: SwitchCpStateE
  870. DESCRIPTION:
  871. PRE-CONDITION:
  872. INPUT:
  873. OUTPUT:
  874. GLOBAL VARIABLES:
  875. =============================================================================*/
  876. int SwitchCpStateE(unsigned char OnOff)
  877. {
  878. /*
  879. * TODO: Request CP change to state E
  880. */
  881. if((OnOff != ENABLE) && (OnOff != DISABLE))
  882. {
  883. return -1;
  884. }
  885. struct ChargingInfoData *ccs;
  886. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  887. ccs->SwitchCpStateE_status = OnOff;
  888. //OnOff = 1 => switch State to E
  889. //OnOff = 0 => return noraml
  890. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  891. {
  892. if(OnOff == DISABLE)
  893. {
  894. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: released\n");
  895. CSUCOMMAC_SHM.CpSetStateE = DISABLE;
  896. }
  897. else
  898. {
  899. OutputCpPwmDuty(100); //set CP duty as 100, firstly.
  900. CSUCOMMAC_SHM.CpSetStateE = ENABLE;
  901. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: enabled!\n");
  902. }
  903. }
  904. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  905. {
  906. if(OnOff == DISABLE)
  907. {
  908. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: released\n");
  909. system("echo 0 > /sys/class/gpio/gpio86/value");
  910. }
  911. else
  912. {
  913. OutputCpPwmDuty(100); //set CP duty as 100, firstly.
  914. system("echo 1 > /sys/class/gpio/gpio86/value");
  915. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: enabled!\n");
  916. }
  917. }
  918. #endif
  919. if (ccs->SwitchCpStateE_status_pre != ccs->SwitchCpStateE_status)
  920. {
  921. SAVE_SYS_LOG_MSG_EVCOMM("SwitchCpStateE: %d >> %d\n",
  922. ccs->SwitchCpStateE_status_pre,
  923. ccs->SwitchCpStateE_status);
  924. ccs->SwitchCpStateE_status_pre = ccs->SwitchCpStateE_status;
  925. }
  926. return 0;
  927. }
  928. /*===========================================================================
  929. FUNCTION: OutputCpPwmDuty
  930. DESCRIPTION:
  931. PRE-CONDITION:
  932. INPUT:
  933. OUTPUT:
  934. GLOBAL VARIABLES:
  935. =============================================================================*/
  936. int OutputCpPwmDuty(unsigned char Duty)
  937. {
  938. #if ((CCS_ENERGY_TRANSFER_MODE != MODE_AC_SINGLE_PHASE_CORE) && (CCS_ENERGY_TRANSFER_MODE != MODE_AC_THREE_PHASE_CORE))
  939. int DutyInNanoSec;
  940. #endif
  941. struct ChargingInfoData *ccs;
  942. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  943. if((Duty < 0)||(Duty > 100))
  944. {
  945. return -1;
  946. }
  947. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  948. {
  949. CSUCOMMAC_SHM.CpSetPWMDuty = Duty;
  950. }
  951. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  952. {
  953. DutyInNanoSec = 10000 * Duty;
  954. sprintf((char*)buf_log_evcomm, "echo %d > /sys/class/pwm/pwmchip0/pwm0/duty_cycle", DutyInNanoSec);//nanoseconds
  955. system((char*)buf_log_evcomm);
  956. }
  957. #endif
  958. ccs->CpDuty = Duty;
  959. //CP Duty
  960. if (ccs->CpDuty != ccs->CpDuty_pre)
  961. {
  962. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  963. SAVE_SYS_LOG_MSG_EVCOMM("CP Duty: %d%% >> %d%%\n", ccs->CpDuty_pre, ccs->CpDuty);
  964. ccs->CpDuty_pre = ccs->CpDuty;
  965. }
  966. return 0;
  967. }
  968. /*===========================================================================
  969. FUNCTION: Check_Plugin_Status_Update_fork1
  970. DESCRIPTION:
  971. PRE-CONDITION:
  972. INPUT:
  973. OUTPUT:
  974. GLOBAL VARIABLES:
  975. =============================================================================*/
  976. //#if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  977. void Check_Plugin_Status_Update_fork1(struct ChargingInfoData *ccs)
  978. {
  979. if (ccs->ConnectorPlugIn != ccs->ConnectorPlugIn_new)
  980. {
  981. SAVE_SYS_LOG_MSG_EVCOMM("Plugin: %d >> %d (CP=%.2fV, PP=%.2fV)\n",
  982. ccs->ConnectorPlugIn,
  983. ccs->ConnectorPlugIn_new,
  984. ccs->CpVoltage,
  985. ccs->PpVoltage);
  986. ccs->ConnectorPlugIn_pre = ccs->ConnectorPlugIn;
  987. ccs->ConnectorPlugIn = ccs->ConnectorPlugIn_new;
  988. //ccs->CpVoltage_pre = ccs->CpVoltage;
  989. }
  990. }
  991. //#endif
  992. /*===========================================================================
  993. FUNCTION: ConnectorPlugIn
  994. DESCRIPTION:
  995. PRE-CONDITION:
  996. INPUT:
  997. OUTPUT:
  998. 0: Unplug
  999. 1: Plug-in
  1000. GLOBAL VARIABLES:
  1001. =============================================================================*/
  1002. int CheckConnectorPlugIn()
  1003. {
  1004. /*
  1005. * TODO: Return connector status depedon CP
  1006. */
  1007. static struct ChargingInfoData *ccs;
  1008. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1009. #if (CP_PROTECTION_MECHANISM == ENABLE)
  1010. return (int)ccs->ConnectorPlugIn;
  1011. #else
  1012. return TRUE;
  1013. #endif
  1014. }
  1015. /*===========================================================================
  1016. FUNCTION: Check_CP_State_Error_fork1
  1017. DESCRIPTION:
  1018. PRE-CONDITION:
  1019. INPUT:
  1020. OUTPUT:
  1021. GLOBAL VARIABLES:
  1022. =============================================================================*/
  1023. int Check_CP_State_Error_fork1(struct ChargingInfoData *ccs)
  1024. {
  1025. #if (CP_PROTECTION_MECHANISM == DISABLE)
  1026. {
  1027. return -1;
  1028. }
  1029. #endif
  1030. unsigned char state = 0;
  1031. #if ((CCS_ENERGY_TRANSFER_MODE != MODE_AC_SINGLE_PHASE_CORE) && (CCS_ENERGY_TRANSFER_MODE != MODE_AC_THREE_PHASE_CORE))
  1032. double time_diff = 0;
  1033. #endif
  1034. state = Check_V2G_Flow_Status();
  1035. //SLAC, SLAAC, SDP, ..., ChargeParameterDiscovery
  1036. if (state >= CM_SLAC_PARM_CONF && //by considering 15118(SLAC first)
  1037. state < ChargeParameterDiscoveryRequest &&
  1038. state != IDLE &&
  1039. state != CM_SET_KEY_REQ &&
  1040. state != CM_SET_KEY_CNF &&
  1041. state != CM_VALIDATE_REQ &&
  1042. state != CM_VALIDATE_CNF)
  1043. {
  1044. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  1045. {
  1046. #ifdef TEST_WITH_ETH0
  1047. if((ShmCcsData->EnergyTransferMode == MODE_DC_EXTENDED) && ((ccs->CpState != 2) && (ccs->CpState != 3)))
  1048. #else
  1049. if((ccs->CpState != 2) && (ccs->CpState != 3))
  1050. #endif
  1051. {
  1052. if (ccs->CpState_err == FALSE)
  1053. {
  1054. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][CP][Error]before CPD\n"); //CPD: ChargeParameterDiscoveryRequest
  1055. //CPD: ChargeParameterDiscovery
  1056. }
  1057. ccs->CpState_err = TRUE;
  1058. }
  1059. }
  1060. #else
  1061. {
  1062. if(ccs->CpState != 3)
  1063. {
  1064. if (ccs->CpState_err == FALSE)
  1065. {
  1066. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][CP][Error]before CPD\n"); //CPD: ChargeParameterDiscoveryRequest
  1067. //CPD: ChargeParameterDiscovery
  1068. }
  1069. ccs->CpState_err = TRUE;
  1070. }
  1071. }
  1072. #endif
  1073. }
  1074. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  1075. {
  1076. //ChargeParameterDiscovery
  1077. if(state >= ChargeParameterDiscoveryRequest && //35
  1078. state <= ChargeParameterDiscoveryResponse) //36
  1079. {
  1080. #ifdef TEST_WITH_ETH0
  1081. if((ccs->CpState != 3) && ((ShmCcsData->EnergyTransferMode != MODE_DC_EXTENDED) && (ccs->CpState != 4)))
  1082. #else
  1083. if(ccs->CpState != 3)
  1084. #endif
  1085. {
  1086. if (ccs->CpState_err == FALSE)
  1087. {
  1088. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD\n");
  1089. //PRC: Precharge
  1090. //CUD: CurrentDemand
  1091. }
  1092. ccs->CpState_err = TRUE;
  1093. }
  1094. }
  1095. //ChargingStatus
  1096. if(state >= ChargingStatusRequest && //43
  1097. state <= ChargingStatusResponse) //44
  1098. {
  1099. if(ccs->CpState != 4 && ccs->CpState != 5)
  1100. {
  1101. if (ccs->CpState_err == FALSE)
  1102. {
  1103. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CGS\n");
  1104. //PRC: Precharge
  1105. //CUD: CurrentDemand
  1106. }
  1107. ccs->CpState_err = TRUE;
  1108. }
  1109. }
  1110. }
  1111. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  1112. {
  1113. //ChargeParameterDiscovery, CableCheck
  1114. if (state >= ChargeParameterDiscoveryRequest && //35
  1115. state <= CableCheckResponse) //38
  1116. {
  1117. if(ccs->CableCheckPreCountDownDone == FALSE &&
  1118. state >= CableCheckRequest)
  1119. {
  1120. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  1121. time_diff = DiffTimeb_fork1_Error_Monitor(EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start, EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  1122. if(time_diff >= V2G_SECC_CP_Timeout_CableCheck) //2 sec
  1123. {
  1124. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][CP]check C(4),D(5): ON (%.02lf of %dms)\n",
  1125. time_diff,
  1126. V2G_SECC_CP_Timeout_CableCheck);
  1127. ccs->CableCheckPreCountDownDone = TRUE;
  1128. }
  1129. }
  1130. if(ccs->CableCheckPreCountDownDone == TRUE)
  1131. {
  1132. if(ccs->CpState != 4 && ccs->CpState != 5)
  1133. {
  1134. if (ccs->CpState_err == FALSE)
  1135. {
  1136. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD and CCK (after CNT)\n");
  1137. //CPD: ChargeParameterDiscovery
  1138. //CCK: CableCheck
  1139. //CNT: count down
  1140. }
  1141. ccs->CpState_err = TRUE;
  1142. }
  1143. }
  1144. else
  1145. {
  1146. if(ccs->CpState != 3 && ccs->CpState != 4 && ccs->CpState != 5)
  1147. {
  1148. if (ccs->CpState_err == FALSE)
  1149. {
  1150. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD and CCK (before CNT)\n");
  1151. //CPD: ChargeParameterDiscovery
  1152. //CCK: CableCheck
  1153. //CNT: count down
  1154. }
  1155. ccs->CpState_err = TRUE;
  1156. }
  1157. }
  1158. }
  1159. //Precharge, CurrentDemand
  1160. if(state >= PreChargeRequest && //39
  1161. state <= CurrentDemandResponse) //46
  1162. {
  1163. if(ccs->CpState != 4 && ccs->CpState != 5)
  1164. {
  1165. if (ccs->CpState_err == FALSE)
  1166. {
  1167. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]PRC and CUD\n");
  1168. //PRC: Precharge
  1169. //CUD: CurrentDemand
  1170. }
  1171. ccs->CpState_err = TRUE;
  1172. }
  1173. }
  1174. }
  1175. #endif
  1176. if(ccs->CpState_err == TRUE && ccs->CpState_err_logged == FALSE)
  1177. {
  1178. OutputCpPwmDuty(100);
  1179. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  1180. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1181. //CCS_SECC_CP_State_Error (023889)
  1182. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1183. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1184. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1185. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1186. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1187. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1188. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1189. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1190. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][Error]CP(%d) Error in state %d(%d)\n",
  1191. ccs->CpState,
  1192. state,
  1193. ccs->CableCheckPreCountDownDone);
  1194. ccs->CpState_err_logged = TRUE;
  1195. }
  1196. return 0;
  1197. }
  1198. /*===========================================================================
  1199. FUNCTION: Check_CP_State_Update_fork1
  1200. DESCRIPTION:
  1201. PRE-CONDITION:
  1202. INPUT:
  1203. OUTPUT:
  1204. GLOBAL VARIABLES:
  1205. =============================================================================*/
  1206. //#if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  1207. void Check_CP_State_Update_fork1(struct ChargingInfoData *ccs)
  1208. {
  1209. //CP State
  1210. if (ccs->CpState != ccs->CpState_pre)
  1211. {
  1212. SAVE_SYS_LOG_MSG_EVCOMM("CP State: %d >> %d (%.2fV)\n",
  1213. ccs->CpState_pre,
  1214. ccs->CpState,
  1215. ccs->CpVoltage);
  1216. ccs->CpState_pre = ccs->CpState;
  1217. }
  1218. }
  1219. //#endif
  1220. /*===========================================================================
  1221. FUNCTION: CP_Detection
  1222. DESCRIPTION:
  1223. 1. In order to detect CP in efficient response time, we creat an independent
  1224. thead for this procedure.
  1225. 2. The priority of this thread is set as the same as other tasks.
  1226. 3. fork1
  1227. PRE-CONDITION:
  1228. INPUT:
  1229. OUTPUT:
  1230. GLOBAL VARIABLES:
  1231. =============================================================================*/
  1232. void CP_Detection()
  1233. {
  1234. pid_t tmp = 0;
  1235. // struct timeb StartTime, EndTime;
  1236. #if ((CCS_ENERGY_TRANSFER_MODE != MODE_AC_SINGLE_PHASE_CORE) && (CCS_ENERGY_TRANSFER_MODE != MODE_AC_THREE_PHASE_CORE))
  1237. unsigned char Statetmp;
  1238. float TotalTmpVolt;
  1239. #endif
  1240. struct ChargingInfoData *ccs;
  1241. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1242. if(CP_Detection_Pid == 0)
  1243. {
  1244. tmp = fork();
  1245. if(tmp > 0)
  1246. {
  1247. CP_Detection_Pid = tmp;
  1248. #if 1
  1249. unsigned char buf[64];
  1250. memset(buf, 0, sizeof(buf));
  1251. //sprintf((char*)buf, "renice -20 -p %d", tmp);
  1252. sprintf((char*)buf, "renice -10 -p %d", tmp);
  1253. system((char*)buf);
  1254. #endif
  1255. return;
  1256. }
  1257. }
  1258. while(1)
  1259. {
  1260. //ADC_Voltage = (1+RE62/RE63)*0.9 - (RE62/RE63)*Pilot_Voltage, RE62/RE63=0.06
  1261. //=>Pilot_Voltage=(0.954-ADC_Voltage)/0.06
  1262. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  1263. {
  1264. ccs->CpVoltage = ShmInternalComm->AC_CpPositiveVoltage;
  1265. ccs->CpState = ShmInternalComm->AC_CpPresentState;
  1266. }
  1267. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  1268. {
  1269. TotalTmpVolt = ReadAdcVolt(3);
  1270. ccs->CpVoltage = TotalTmpVolt;
  1271. if (ccs->CpVoltage_pre != ccs->CpVoltage)
  1272. {
  1273. ccs->CpVoltage_pre = ccs->CpVoltage;
  1274. }
  1275. //printf("TotalTmpVolt = %.02f\n", TotalTmpVolt);
  1276. //If CP voltage is higer than 13.5V
  1277. if(TotalTmpVolt >= 13.5)
  1278. {
  1279. //Pilot Error
  1280. if((ccs->CpState == 1) &&
  1281. (TotalTmpVolt < 13.75))
  1282. {
  1283. //V_cp = 13.5 ~ 13.75
  1284. Statetmp = 1;
  1285. }
  1286. else
  1287. {
  1288. //V_cp = 13.5 ~
  1289. Statetmp = 8;
  1290. }
  1291. }
  1292. else if((TotalTmpVolt >= 10.5) && (TotalTmpVolt < 13.5)) //V_cp = 10.5 ~ 13.5
  1293. {
  1294. //State A (12V)
  1295. if((ccs->CpState >= 2) &&
  1296. (ccs->CpState <= 3) &&
  1297. (TotalTmpVolt < 10.75))
  1298. {
  1299. if((ccs->CpDuty >= 5) &&
  1300. (ccs->CpDuty < 100))
  1301. {
  1302. Statetmp = 3;
  1303. }
  1304. else
  1305. {
  1306. Statetmp = 2;
  1307. }
  1308. }
  1309. else if((ccs->CpState == 8) &&
  1310. (TotalTmpVolt >= 13.25))
  1311. {
  1312. Statetmp = 8;
  1313. }
  1314. else
  1315. {
  1316. Statetmp = 1;
  1317. }
  1318. }
  1319. else if((TotalTmpVolt >= 7.5) && (TotalTmpVolt < 10.5))
  1320. {
  1321. //State B (9V)
  1322. if((ccs->CpState == 4) && (TotalTmpVolt < 7.75))
  1323. {
  1324. Statetmp = 4;
  1325. }
  1326. else if((ccs->CpState == 1) && (TotalTmpVolt >= 10.25))
  1327. {
  1328. Statetmp = 1;
  1329. }
  1330. else
  1331. {
  1332. if((ccs->CpDuty >= 5) && (ccs->CpDuty < 100))
  1333. {
  1334. Statetmp = 3;
  1335. }
  1336. else
  1337. {
  1338. Statetmp = 2;
  1339. }
  1340. }
  1341. }
  1342. else if((TotalTmpVolt >= 4.5) && (TotalTmpVolt < 7.5))
  1343. {
  1344. //State C (6V)
  1345. if((ccs->CpState == 5) && (TotalTmpVolt < 4.75))
  1346. {
  1347. Statetmp = 5;
  1348. }
  1349. else if((ccs->CpState >= 2) && (ccs->CpState <= 3) && (TotalTmpVolt >= 7.25))
  1350. {
  1351. if((ccs->CpDuty >= 5)&&(ccs->CpDuty < 100))
  1352. {
  1353. Statetmp = 3;
  1354. }
  1355. else
  1356. {
  1357. Statetmp = 2;
  1358. }
  1359. }
  1360. else
  1361. {
  1362. Statetmp = 4;
  1363. }
  1364. }
  1365. else if((TotalTmpVolt >= 1.5) && (TotalTmpVolt < 4.5))
  1366. {
  1367. //State D (3V)
  1368. if((ccs->CpState == 6)&&(TotalTmpVolt < 1.75))
  1369. {
  1370. Statetmp = 6;
  1371. }
  1372. else if((ccs->CpState == 4)&&(TotalTmpVolt >= 4.25))
  1373. {
  1374. Statetmp = 4;
  1375. }
  1376. else
  1377. {
  1378. Statetmp = 5;
  1379. }
  1380. }
  1381. else if((TotalTmpVolt >= -1.5) && (TotalTmpVolt < 1.5)) //V_cp = -1.5V ~ 1.5V
  1382. {
  1383. //State E (0V)
  1384. if((ccs->CpState == 8) &&
  1385. (TotalTmpVolt < -1.25))
  1386. {
  1387. Statetmp = 8;
  1388. }
  1389. else if((ccs->CpState == 5) &&
  1390. (TotalTmpVolt >= 1.25))
  1391. {
  1392. Statetmp = 5;
  1393. }
  1394. else
  1395. {
  1396. Statetmp = 6;
  1397. }
  1398. }
  1399. else if((TotalTmpVolt >= -13.5) && (TotalTmpVolt < -10.5)) //V_cp = -10.5V ~ -13.5V
  1400. {
  1401. //State F (-12V)
  1402. if((ccs->CpState == 8) &&
  1403. (TotalTmpVolt >= -10.75))
  1404. {
  1405. Statetmp = 8;
  1406. }
  1407. else
  1408. {
  1409. Statetmp = 7;
  1410. }
  1411. }
  1412. else
  1413. {
  1414. //null
  1415. }
  1416. ccs->CpState = Statetmp;
  1417. }
  1418. #endif
  1419. Check_CP_State_Update_fork1(ccs);
  1420. Check_CP_State_Error_fork1(ccs);
  1421. //Updating Plugin status
  1422. #if (PP_PROTECTION_MECHANISM == ENABLE)
  1423. if((ccs->CpState >= 2 ) && (ccs->CpState <= 5 ) && (ccs->PpVoltage >= 1.0)) //PP >= 1.0V
  1424. #else
  1425. if((ccs->CpState >= 2 ) && (ccs->CpState <= 5 ))
  1426. #endif
  1427. {
  1428. ccs->ConnectorPlugIn_new = TRUE;
  1429. }
  1430. else
  1431. {
  1432. ccs->ConnectorPlugIn_new = FALSE;
  1433. OutputCpPwmDuty(100);
  1434. }
  1435. Check_Plugin_Status_Update_fork1(ccs);
  1436. //ftime(&EndTime);
  1437. //DEBUG_PRINTF_EVCOMM_DETAIL("duration:%.02lf\n", DiffTimeb(StartTime, EndTime));
  1438. usleep(1000);
  1439. }//while
  1440. }
  1441. /*===========================================================================
  1442. FUNCTION: PP_Detection
  1443. DESCRIPTION:
  1444. 0. SeccComm fork3
  1445. 1. In order to detect CP in efficient response time, we creat an independent
  1446. thead for this procedure.
  1447. 2. The priority of this thread is set as the same as other tasks.
  1448. PRE-CONDITION:
  1449. INPUT:
  1450. OUTPUT:
  1451. GLOBAL VARIABLES:
  1452. =============================================================================*/
  1453. void PP_Detection()
  1454. {
  1455. pid_t tmp = 0;
  1456. // struct timeb StartTime, EndTime;
  1457. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED))
  1458. //unsigned char Statetmp;
  1459. #endif
  1460. float TotalTmpVolt;
  1461. if(PP_Detection_Pid == 0)
  1462. {
  1463. tmp = fork();
  1464. if(tmp > 0)
  1465. {
  1466. PP_Detection_Pid = tmp;
  1467. #if 0
  1468. unsigned char buf[64];
  1469. memset(buf, 0, sizeof(buf));
  1470. sprintf((char*)buf, "renice -20 -p %d", tmp);
  1471. system(buf);
  1472. #endif
  1473. return;
  1474. }
  1475. }
  1476. while(1)
  1477. {
  1478. TotalTmpVolt = ReadAdcVolt_PP_fork3();
  1479. EVCOMM_SYS_INFO.PpVoltage = TotalTmpVolt;
  1480. if (EVCOMM_SYS_INFO.PpVoltage_pre != EVCOMM_SYS_INFO.PpVoltage)
  1481. {
  1482. if ((EVCOMM_SYS_INFO.PpVoltage_pre < 0.5 && EVCOMM_SYS_INFO.PpVoltage >= 1.0) ||
  1483. (EVCOMM_SYS_INFO.PpVoltage_pre >= 1.0 && EVCOMM_SYS_INFO.PpVoltage < 0.5))
  1484. {
  1485. SAVE_SYS_LOG_MSG_EVCOMM("[fork3]PP(%.2f >> %.2fV)\n",
  1486. EVCOMM_SYS_INFO.PpVoltage_pre,
  1487. EVCOMM_SYS_INFO.PpVoltage);
  1488. EVCOMM_SYS_INFO.PpVoltage_pre = EVCOMM_SYS_INFO.PpVoltage;
  1489. }
  1490. }
  1491. #if 0
  1492. sleep(5);
  1493. printf("V_pp = %.02f\n", TotalTmpVolt);
  1494. #endif
  1495. usleep(1000);
  1496. }//while
  1497. }
  1498. /*===========================================================================
  1499. FUNCTION: Error_Monitor
  1500. DESCRIPTION:
  1501. 1. This function only works in SeccComm fork2.
  1502. PRE-CONDITION:
  1503. INPUT:
  1504. OUTPUT:
  1505. GLOBAL VARIABLES:
  1506. =============================================================================*/
  1507. void Error_Monitor()
  1508. {
  1509. pid_t tmp = 0;
  1510. double time_diff = 0;
  1511. unsigned char status = 0;
  1512. struct ChargingInfoData *ccs;
  1513. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1514. if(Error_Monitor_Pid == 0)
  1515. {
  1516. tmp = fork(); //SeccComm fork2
  1517. if(tmp > 0)
  1518. {
  1519. Error_Monitor_Pid = tmp;
  1520. #if 0
  1521. unsigned char buf[64];
  1522. memset(buf, 0, sizeof(buf));
  1523. sprintf((char*)buf, "renice -20 -p %d", tmp);
  1524. system(buf);
  1525. #endif
  1526. return;
  1527. }
  1528. }
  1529. while(1)
  1530. {
  1531. //Step 0
  1532. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  1533. {
  1534. //If the End_Process is in processing, disable Error_Monitor.
  1535. continue;
  1536. }
  1537. //Step1 1: Check and Response to Plugin Status
  1538. if(CheckConnectorPlugIn() == FALSE)
  1539. {
  1540. status = Check_V2G_Flow_Status();
  1541. if (status > IDLE &&
  1542. status < Performance_Timeout &&
  1543. status != CM_SET_KEY_REQ &&
  1544. status != CM_SET_KEY_CNF &&
  1545. EVCOMM_SYS_INFO.End_Process_inused == FALSE)
  1546. {
  1547. #if (CP_PROTECTION_MECHANISM == ENABLE)
  1548. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork2] Emergency Stop (due to Connector is plugged out during communication.)");
  1549. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Plug out Error => End_Process\n");
  1550. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1551. //CCS_SECC_CP_State_Error (023889)
  1552. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1553. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1554. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1555. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1556. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1557. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1558. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1559. End_Process();
  1560. #else
  1561. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "CP_PROTECTION_MECHANISM is disabled. Emergency Stop: skipped" );
  1562. #endif
  1563. }
  1564. }
  1565. //Step 2: Check for V2G_SECC_Sequence_Timeout
  1566. //#if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  1567. #if 1
  1568. status = Check_V2G_Flow_Status();
  1569. if (status >= SupportedAppProtocolRequest &&
  1570. status < SessionStopRequest)
  1571. {
  1572. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_End);
  1573. time_diff = DiffTimeb_fork2_Error_Monitor(EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start, EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_End);
  1574. if(time_diff > V2G_SECC_Sequence_Timeout) //60s
  1575. {
  1576. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]V2G_SECC_Sequence_Timeout in state %d - (%.02lf of %d ms)\n",
  1577. status,
  1578. time_diff,
  1579. V2G_SECC_Sequence_Timeout);
  1580. Update_V2G_Flow_Status(Sequence_Timeout);
  1581. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1582. //CCS_SECC_TIMEOUT_V2G_Sequence_Time (023844)
  1583. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1584. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1585. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1586. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1587. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  1588. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  1589. End_Process();
  1590. break;
  1591. }
  1592. else if (time_diff > 4000) //4s
  1593. {
  1594. //Check for CSU command of "Stop by EVSE"
  1595. if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_Shutdown)
  1596. {
  1597. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]EVSE_Shutdown\n");
  1598. Update_V2G_Flow_Status(Other_Fault);
  1599. }
  1600. else if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_EmergencyShutdown)
  1601. {
  1602. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]EVSE_EmergencyShutdown\n");
  1603. Update_V2G_Flow_Status(Other_Fault);
  1604. }
  1605. else if (ShmInternalComm->ChargingPermission == FALSE)
  1606. {
  1607. if (status >= ChargeParameterDiscoveryRequest) //&& status < SessionStopRequest
  1608. {
  1609. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]ChargingPermission = FALSE\n");
  1610. Update_V2G_Flow_Status(Other_Fault);
  1611. }
  1612. }
  1613. else
  1614. {
  1615. //null
  1616. }
  1617. }
  1618. else
  1619. {
  1620. //null
  1621. }
  1622. }
  1623. #endif
  1624. //Step 3: Check and Response to Error V2gFlowStatus
  1625. status = Check_V2G_Flow_Status();
  1626. if (status == Performance_Timeout ||
  1627. status == Sequence_Timeout ||
  1628. status == Other_Fault)
  1629. {
  1630. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Timeout or Fault State(%d) => End_Process\n", status);
  1631. //Normal Stop
  1632. //alarm and duty to 100%
  1633. //OutputCpPwmDuty(100);
  1634. //SwitchCpStateE(ENABLE); //Set CP duty as 100% and set CP state as E (0V).
  1635. //[Joseph/ To-Do] Set State E (0V) via GPIO setting
  1636. End_Process();
  1637. }
  1638. //Step 4: Check and Response to CP State Error
  1639. if(ccs->CpState_err == TRUE)
  1640. {
  1641. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]CP Error => End_Process\n");
  1642. Update_V2G_Flow_Status(Other_Fault);
  1643. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1644. //CCS_SECC_CP_State_Error (023889)
  1645. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1646. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1647. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1648. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1649. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1650. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1651. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1652. End_Process();
  1653. }
  1654. //Step 5: Check and Response to Shutdown Commnad from CSU
  1655. if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_Shutdown ||
  1656. EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_EmergencyShutdown)
  1657. {
  1658. if (Check_V2G_Flow_Status() <= SLACC_SDP_TCP_Connection)
  1659. {
  1660. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]EVSE Shutdown(%d) => End_Process\n", EVCOMM_SYS_INFO.DC_EVSEStatus);
  1661. Update_V2G_Flow_Status(Other_Fault);
  1662. End_Process();
  1663. }
  1664. }
  1665. //Step 6: Check and Response to SessionStop
  1666. status = Check_V2G_Flow_Status();
  1667. if (status == SessionStopResponse)
  1668. {
  1669. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]SessionStopResponse => End_Process\n");
  1670. End_Process();
  1671. }
  1672. //Step 7: Check for ChargingPermission from TRUE to FALSE before V2G Messages
  1673. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  1674. if ((ShmInternalComm->ChargingPermission == FALSE) &&
  1675. (ShmInternalComm->ChargingPermission_pre >= 1) &&
  1676. (ccs->CpState >= 3) && (ccs->CpState <=5))
  1677. {
  1678. if (status >= CM_SLAC_PARM_REQ &&
  1679. status != CM_SET_KEY_REQ &&
  1680. status != CM_SET_KEY_CNF &&
  1681. status <= SLACC_SDP_TCP_Connection)
  1682. {
  1683. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Permission OFF before V2G msg(%d) => End_Process\n", ShmInternalComm->ChargingPermission);
  1684. Update_V2G_Flow_Status(Other_Fault);
  1685. End_Process();
  1686. }
  1687. }
  1688. //Step 8: DC OVP Protection
  1689. if (CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED &&
  1690. status > CableCheckResponse &&
  1691. status <= SessionStopRequest &&
  1692. status != ChargingStatusRequest &&
  1693. status != ChargingStatusResponse &&
  1694. EVCOMM_SYS_INFO.EvBatteryMaxVoltage != 0)
  1695. {
  1696. //Part A: OVP Protection
  1697. if (EVCOMM_SYS_INFO.PresentChargingVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02)) // 2%
  1698. {
  1699. SAVE_SYS_LOG_MSG_EVCOMM("[fork2][Error]OVP => End_Process (%.02f > %.02f)\n",
  1700. EVCOMM_SYS_INFO.PresentChargingVoltage,
  1701. (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02));
  1702. Update_V2G_Flow_Status(Other_Fault);
  1703. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1704. //System CCS output OVP (012219)
  1705. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1706. ShmStatusCodeData->PresentStatusCode[0][1] = 1;
  1707. ShmStatusCodeData->PresentStatusCode[0][2] = 2;
  1708. ShmStatusCodeData->PresentStatusCode[0][3] = 2;
  1709. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  1710. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1711. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1712. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1713. End_Process();
  1714. }
  1715. //Part B: Over Voltage Request Protection
  1716. if (EVCOMM_SYS_INFO.EvBatterytargetVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02))
  1717. {
  1718. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Over V Req => End_Process (%.02f > %.02f)\n",
  1719. EVCOMM_SYS_INFO.EvBatterytargetVoltage,
  1720. (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02));
  1721. Update_V2G_Flow_Status(Other_Fault);
  1722. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1723. //System CCS output OVP (012219)
  1724. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1725. ShmStatusCodeData->PresentStatusCode[0][1] = 1;
  1726. ShmStatusCodeData->PresentStatusCode[0][2] = 2;
  1727. ShmStatusCodeData->PresentStatusCode[0][3] = 2;
  1728. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  1729. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1730. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1731. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1732. End_Process();
  1733. }
  1734. }
  1735. //Step 9: Check 60V
  1736. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  1737. if (CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED &&
  1738. ShmInternalComm->ChargingPermission >= 1 &&
  1739. status < CableCheckRequest)
  1740. {
  1741. if (EVCOMM_SYS_INFO.PresentChargingVoltage >= 60) //60V
  1742. {
  1743. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]DC Output Voltage is over 60V => End_Process\n");
  1744. Update_V2G_Flow_Status(Other_Fault);
  1745. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1746. //CCS_SECC_Unexpected_60V_Before_Charing_Error (023890)
  1747. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1748. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1749. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1750. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1751. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  1752. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  1753. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1754. //Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1755. End_Process();
  1756. }
  1757. }
  1758. //Step 10: Check if the connector is unplug from plugin
  1759. if (EVCOMM_SYS_INFO.ConnectorPlugIn_pre == TRUE && EVCOMM_SYS_INFO.ConnectorPlugIn == FALSE)
  1760. {
  1761. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Unplug Reset => End_Process\n");
  1762. Update_V2G_Flow_Status(Other_Fault);
  1763. End_Process();
  1764. }
  1765. usleep(1000);
  1766. }//while
  1767. }
  1768. /*===========================================================================
  1769. FUNCTION: SendSetKey
  1770. DESCRIPTION:
  1771. PRE-CONDITION:
  1772. INPUT:
  1773. OUTPUT:
  1774. GLOBAL VARIABLES:
  1775. =============================================================================*/
  1776. int SendSetKey()
  1777. {
  1778. int i = 0;
  1779. unsigned char nRandValue = 0x0;
  1780. unsigned char ConstString[16] = "PhihongKey000000";
  1781. memset(&SendMmePacket,0,sizeof(struct MmeHeader));
  1782. memcpy(SendMmePacket.ODA,QcaMac,6);
  1783. memcpy(SendMmePacket.OSA,CsuMac,6);
  1784. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  1785. SendMmePacket.MMV = 0x01;
  1786. SendMmePacket.MMTYPE = MMTYPE_CM_SET_KEY_REQ;
  1787. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  1788. SendMmePacketSize = 0;
  1789. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//Fixed value (0x01) to indicate ��NMK��
  1790. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,4);//My Nonce, Fixed value(0x00000000), encrypted payload not used
  1791. SendMmePacketSize+=4;
  1792. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,4);//Your Nonce, Fixed value(0x00000000), encrypted payload not used
  1793. SendMmePacketSize+=4;
  1794. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x04;//PID, Fixed value (0x04) to indicate ��HLE protocol��
  1795. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,2);//PRN, Fixed value(0x00), encrypted payload not used
  1796. SendMmePacketSize+=2;
  1797. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00;//PMN, Fixed value(0x00) encrypted payload not used
  1798. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//CCo Capablility
  1799. srand(time(NULL));
  1800. for (i = 10; i < 16; i++)
  1801. {
  1802. nRandValue = (rand()%62) + 1;
  1803. if((nRandValue>=0)&&(nRandValue<=9)) // 0 ~ 9
  1804. {
  1805. ConstString[i]= nRandValue + 0x30;
  1806. }
  1807. else if((nRandValue>=10)&&(nRandValue<=35)) // A ~ Z
  1808. {
  1809. ConstString[i]= nRandValue -10 + 0x41;
  1810. }
  1811. else if((nRandValue>=36)&&(nRandValue<=61)) // a ~ z
  1812. {
  1813. ConstString[i]= nRandValue -37 + 0x61;
  1814. }
  1815. else
  1816. {
  1817. ConstString[i]= 0x30;
  1818. }
  1819. }
  1820. memset(NewNmkKey, 0, sizeof(NewNmkKey));
  1821. memset(Nid, 0, sizeof(Nid));
  1822. HPAVKeyNMK(NewNmkKey, (char*)ConstString);
  1823. HPAVKeyNID(Nid, NewNmkKey, DEFAULT_LEVEL);
  1824. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize, Nid, sizeof(Nid)); //NID, 54 LSBs contain the NID 2 MSBs = 0b00
  1825. SendMmePacketSize += sizeof(Nid);
  1826. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//NewEKS,Fixed value (0x01)to indicate ��NMK��
  1827. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,NewNmkKey,sizeof(NewNmkKey));//NewKey
  1828. SendMmePacketSize += sizeof(NewNmkKey);
  1829. SendMmePacketSize += 19; //the size before MMENTRY
  1830. SAVE_SYS_LOG_MSG_EVCOMM("QCA7000 [TX]CM_SET_KEY_REQ\n");
  1831. i = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  1832. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  1833. DEBUG_PRINTF_EVCOMM_DETAIL("SendSetKey: send size: %d\n",i);
  1834. return 0;
  1835. }
  1836. /*===========================================================================
  1837. FUNCTION: GetQca7kMac
  1838. DESCRIPTION:
  1839. PRE-CONDITION:
  1840. INPUT:
  1841. OUTPUT:
  1842. GLOBAL VARIABLES:
  1843. =============================================================================*/
  1844. int GetQca7kMac()
  1845. {
  1846. struct QcaVendorMmeHeader SendPacket;
  1847. SAVE_SYS_LOG_MSG_EVCOMM("Req for QCA7K MacAddr\n");
  1848. memset(&SendPacket, 0, sizeof(struct QcaVendorMmeHeader));
  1849. memset(SendPacket.ODA, 0xFF, 6); //broadcast
  1850. memcpy(SendPacket.OSA, CsuMac, 6);
  1851. SendPacket.MTYPE = htons(EtherType_HomePlug);
  1852. SendPacket.MMV = 0x00;
  1853. SendPacket.MMTYPE = MMTYPE_VENDOR_VS_NW_INFO;
  1854. SendPacket.OUI[0] = 0x00;
  1855. SendPacket.OUI[1] = 0xB0;
  1856. SendPacket.OUI[2] = 0x52;
  1857. DEBUG_PRINTF_EVCOMM_DETAIL("GetQca7kMac: send size: %d\n", sendto(RawSock, &SendPacket, 20, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll)));
  1858. return 0;
  1859. }
  1860. /*===========================================================================
  1861. FUNCTION: Array_Check_All_Zero
  1862. DESCRIPTION:
  1863. PRE-CONDITION:
  1864. INPUT:
  1865. OUTPUT:
  1866. result:
  1867. (1) TRUE: all zero
  1868. (2) FALSE: not all zero
  1869. GLOBAL VARIABLES:
  1870. =============================================================================*/
  1871. int Array_Check_All_Zero(unsigned char *ptr, int size)
  1872. {
  1873. int result = TRUE;
  1874. int i = 0;
  1875. for (i = 0; i < size; i++)
  1876. {
  1877. if (ptr[i] != 0)
  1878. {
  1879. result = FALSE;
  1880. break;
  1881. }
  1882. }
  1883. return result;
  1884. }
  1885. /*===========================================================================
  1886. FUNCTION: Array_Compare_Identity
  1887. DESCRIPTION:
  1888. PRE-CONDITION:
  1889. INPUT:
  1890. OUTPUT:
  1891. result = FALSE (not identical)
  1892. result = TRUE (identical)
  1893. GLOBAL VARIABLES:
  1894. =============================================================================*/
  1895. int Array_Compare_Identity(unsigned char *ptrA, unsigned char *ptrB, int size)
  1896. {
  1897. int result = TRUE;
  1898. int i = 0;
  1899. for (i = 0; i < size; i++)
  1900. {
  1901. if (ptrA[i] != ptrB[i])
  1902. {
  1903. result = FALSE;
  1904. #if 0
  1905. sprintf((char*)buf_log_evcomm,
  1906. "[Array_Compare_Identity]%02X%02X%02X%02X%02X%02X,%02X%02X%02X%02X%02X%02X(%d)\n",
  1907. ptrA[0], ptrA[1], ptrA[2], ptrA[3], ptrA[4], ptrA[5],
  1908. ptrB[0], ptrB[1], ptrB[2], ptrB[3], ptrB[4], ptrB[5],
  1909. result);
  1910. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  1911. #endif
  1912. break;
  1913. }
  1914. }
  1915. return result;
  1916. }
  1917. /*===========================================================================
  1918. FUNCTION: SLAC_DB_Search_EvMac_idx
  1919. DESCRIPTION:
  1920. PRE-CONDITION:
  1921. INPUT:
  1922. OUTPUT:
  1923. idx = -1 (not found)
  1924. GLOBAL VARIABLES:
  1925. =============================================================================*/
  1926. int SLAC_DB_Search_EvMac_idx(struct EVCC_SLAC_DATA_TYPE *evcc, unsigned char *EvMac_in)
  1927. {
  1928. int idx = -1;
  1929. int i = 0;
  1930. if (evcc->arrayLen == 0)
  1931. {
  1932. //printf("[SLAC_DB_Search_EvMac_idx]arrayLen is empty (%d)\n", evcc->arrayLen);
  1933. //no need to search
  1934. }
  1935. else if (evcc->arrayLen > EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE)
  1936. {
  1937. //error
  1938. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]DB length(%d) > %d\n",
  1939. evcc->arrayLen,
  1940. EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE);
  1941. evcc->arrayLen = 0; //reset
  1942. }
  1943. else
  1944. {
  1945. //start searching
  1946. for (i = 0; i < evcc->arrayLen; i++)
  1947. {
  1948. //printf("[SLAC_DB_Search_EvMac_idx]checking DB[%d]...\n", i);
  1949. if (Array_Compare_Identity(evcc->array[i].EvMac, EvMac_in, SLAC_EVMAC_LENGTH) == TRUE)
  1950. {
  1951. //printf("[SLAC_DB_Search_EvMac_idx]identical at DB[%d]...\n", i);
  1952. idx = i;
  1953. break;
  1954. }
  1955. }
  1956. }
  1957. //printf("[SLAC_DB_Search_EvMac_idx]return = %d\n", idx);
  1958. return idx;
  1959. }
  1960. /*===========================================================================
  1961. FUNCTION: SLAC_DB_Check_EvMac_RunID_Matching
  1962. DESCRIPTION:
  1963. PRE-CONDITION:
  1964. INPUT:
  1965. OUTPUT:
  1966. res = FALSE (unmatched)
  1967. res = TRUE (matched)
  1968. GLOBAL VARIABLES:
  1969. =============================================================================*/
  1970. int SLAC_DB_Check_EvMac_RunID_Matching(struct EVCC_SLAC_DATA_TYPE *evcc, unsigned char *EvMac_in, unsigned char *RunID_in)
  1971. {
  1972. int res = FALSE;
  1973. int idx = -1;
  1974. idx = SLAC_DB_Search_EvMac_idx(evcc, EvMac_in);
  1975. if (idx >= 0)
  1976. {
  1977. res = Array_Compare_Identity(evcc->array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH);
  1978. }
  1979. else
  1980. {
  1981. //not found the EvMac data in DB
  1982. res = FALSE;
  1983. }
  1984. return res;
  1985. }
  1986. /*===========================================================================
  1987. FUNCTION: SLAC_DB_Add
  1988. DESCRIPTION:
  1989. 1. Saving each CM_SLAC_PARM_REQ data into EVCC database if its
  1990. EvMac and RunID data are different, respectively.
  1991. PRE-CONDITION:
  1992. INPUT:
  1993. OUTPUT:
  1994. idx = saved index (must be a positive value)
  1995. GLOBAL VARIABLES:
  1996. =============================================================================*/
  1997. int SLAC_DB_Add(unsigned char *EvMac_in, unsigned char *RunID_in)
  1998. {
  1999. int idx = -1;
  2000. //Search if this EvMac and RunID already exists
  2001. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2002. if (idx < 0) //not exist, yet.
  2003. {
  2004. if (SLAC_INFO.arrayLen < EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE) //20
  2005. {
  2006. DEBUG_PRINTF_EVCOMM_DETAIL("data does not exist => added to %d-th\n", SLAC_INFO.arrayLen);
  2007. if (SLAC_INFO.arrayLen >= 0)
  2008. {
  2009. memset(&SLAC_INFO.array[SLAC_INFO.arrayLen], 0, sizeof(struct EVCC_SLAC_DATA_ARRAY_TYPE));
  2010. memcpy(SLAC_INFO.array[SLAC_INFO.arrayLen].EvMac, EvMac_in, SLAC_EVMAC_LENGTH);
  2011. memcpy(SLAC_INFO.array[SLAC_INFO.arrayLen].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2012. idx = SLAC_INFO.arrayLen;
  2013. SLAC_INFO.arrayLen++;
  2014. }
  2015. else
  2016. {
  2017. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]arrayLen: unexpected(%d)\n", SLAC_INFO.arrayLen);
  2018. SLAC_INFO.arrayLen = 0;
  2019. }
  2020. }
  2021. else
  2022. {
  2023. //DB is full
  2024. DEBUG_PRINTF_EVCOMM_DETAIL("DB is full(%d) => bypass\n", SLAC_INFO.arrayLen);
  2025. }
  2026. }
  2027. else
  2028. {
  2029. #if 0
  2030. sprintf((char*)buf_log_evcomm,
  2031. "[SLAC_DB_Add]EvMac: existed (%d)",
  2032. idx);
  2033. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2034. #endif
  2035. //Check RunID
  2036. if (Array_Compare_Identity(SLAC_INFO.array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH) == TRUE)
  2037. {
  2038. //RunID is the same
  2039. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC_DB_Add]RunID: same");
  2040. }
  2041. else
  2042. {
  2043. SAVE_SYS_LOG_MSG_EVCOMM("RunID: diff\n");
  2044. }
  2045. //Reset all corresponding parameters
  2046. #if 0
  2047. sprintf((char*)buf_log_evcomm,
  2048. "[SLAC_DB_Add]EvMac: reset para(%d)",
  2049. idx);
  2050. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2051. #endif
  2052. memset(&SLAC_INFO.array[idx], 0, sizeof(struct EVCC_SLAC_DATA_ARRAY_TYPE));
  2053. memcpy(SLAC_INFO.array[idx].EvMac, EvMac_in, SLAC_EVMAC_LENGTH);
  2054. memcpy(SLAC_INFO.array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2055. }
  2056. return idx;
  2057. }
  2058. /*===========================================================================
  2059. FUNCTION: SLAC_DB_Reset
  2060. DESCRIPTION:
  2061. PRE-CONDITION:
  2062. INPUT:
  2063. OUTPUT:
  2064. GLOBAL VARIABLES:
  2065. =============================================================================*/
  2066. int SLAC_DB_Reset()
  2067. {
  2068. memset(&SLAC_INFO, 0, sizeof(struct EVCC_SLAC_DATA_TYPE));
  2069. SAVE_SYS_LOG_MSG_EVCOMM("DONE\n");
  2070. return 0;
  2071. }
  2072. /*===========================================================================
  2073. FUNCTION: MmeProcess
  2074. DESCRIPTION:
  2075. PRE-CONDITION:
  2076. INPUT:
  2077. OUTPUT:
  2078. GLOBAL VARIABLES:
  2079. =============================================================================*/
  2080. int MmeProcess(unsigned char *Buffer, int DataLength)
  2081. {
  2082. //struct ethhdr *EthPacket;
  2083. struct MmeHeader *MmePacket;
  2084. static unsigned char counter;
  2085. unsigned char state = 0;
  2086. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2087. unsigned char tmpBuf[2048]={0};
  2088. #endif
  2089. int Rtn = 0;
  2090. #if(NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2091. int idx = 0;
  2092. unsigned char *EvMac_in;
  2093. unsigned char *RunID_in;
  2094. #endif
  2095. MmePacket = (struct MmeHeader *)Buffer;
  2096. state = Check_V2G_Flow_Status();
  2097. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2098. {
  2099. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  2100. DEBUG_PRINTF_EVCOMM_DETAIL("******* Received MME Packet *******\n");
  2101. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  2102. DEBUG_PRINTF_EVCOMM_DETAIL("DataLength=%d\n",DataLength);
  2103. DEBUG_PRINTF_EVCOMM_DETAIL("ODA: %02x:%02x:%02x:%02x:%02x:%02x\n", //Destination MAC Address
  2104. MmePacket->ODA[0], MmePacket->ODA[1],
  2105. MmePacket->ODA[2], MmePacket->ODA[3],
  2106. MmePacket->ODA[4], MmePacket->ODA[5]);
  2107. DEBUG_PRINTF_EVCOMM_DETAIL("OSA: %02x:%02x:%02x:%02x:%02x:%02x\n", //Source MAC Address (EV MAC)
  2108. MmePacket->OSA[0], MmePacket->OSA[1],
  2109. MmePacket->OSA[2], MmePacket->OSA[3],
  2110. MmePacket->OSA[4], MmePacket->OSA[5]);
  2111. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(MmePacket->MTYPE));
  2112. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", MmePacket->MMV);
  2113. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", MmePacket->MMTYPE);
  2114. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n",
  2115. MmePacket->FMI[0],MmePacket->FMI[1]);
  2116. }
  2117. #endif
  2118. #if (SLAC_FIRST_RESPONSE_METHOD == SET_NO_PWM_IF_NOT_GET_PERMISSION)
  2119. {
  2120. //Check CP as 5%
  2121. if (EVCOMM_SYS_INFO.CpState != 3 &&
  2122. EVCOMM_SYS_INFO.CpState != 4 &&
  2123. MmePacket->MMTYPE != MMTYPE_CM_SET_KEY_CNF &&
  2124. MmePacket->MMTYPE != MMTYPE_VENDOR_VS_HOST_ACTION &&
  2125. MmePacket->MMTYPE != MMTYPE_VENDOR_ATTEN_CHAR &&
  2126. MmePacket->MMTYPE != MMTYPE_VENDOR_VS_NW_INFO_CNF
  2127. )
  2128. {
  2129. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC]ignored(wrong CP state)");
  2130. return 0;
  2131. }
  2132. }
  2133. #endif
  2134. //[To-Do] Adding a pre-check filter mechanism for Source and Destination MAC Address
  2135. //check if the destination address is broadcast or EVSE itself, it can be ignore if not belong to itself.
  2136. switch(MmePacket->MMTYPE)
  2137. {
  2138. case MMTYPE_CM_SET_KEY_CNF:
  2139. {
  2140. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SET_KEY_CNF ---\n");
  2141. DEBUG_PRINTF_EVCOMM_DETAIL("Result: 0x%02x\n", MmePacket->MMENTRY[0]);
  2142. SAVE_SYS_LOG_MSG_EVCOMM("CM_SET_KEY_CNF (SetKey: DONE)\n\n");
  2143. Update_V2G_Flow_Status(CM_SET_KEY_CNF);
  2144. break;
  2145. }
  2146. case MMTYPE_CM_SLAC_PARM_REQ:
  2147. {
  2148. //Check QCA7000 status
  2149. if (EVCOMM_SYS_INFO.QCA7K_SetKeyDone == FALSE)
  2150. {
  2151. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][RX]CM_SLAC_PARM_REQ: ignored(QCA7K init...)");
  2152. break;
  2153. }
  2154. //Check error state
  2155. state = Check_V2G_Flow_Status();
  2156. if (state == Performance_Timeout || //253
  2157. state == Sequence_Timeout || //254
  2158. state == Other_Fault) //255
  2159. {
  2160. SAVE_SYS_LOG_MSG_EVCOMM("CM_SLAC_PARM_REQ: ignored(in error state)\n");
  2161. break;
  2162. }
  2163. //Printing EV MAC Address
  2164. SAVE_SYS_LOG_MSG_EVCOMM("CM_SLAC_PARM_REQ\n");
  2165. //Avoid Coupled SLAC_PARM_REQ
  2166. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2167. {
  2168. #if 0
  2169. sprintf((char*)buf_log_evcomm,
  2170. "[WARNING][SLAC][RX]CM_SLAC_PARM_REQ: ignored(coupled SLAC,%d)",
  2171. CheckConnectorPlugIn());
  2172. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2173. #endif
  2174. break;
  2175. }
  2176. //[TC_SECC_VTB_CmSlacParm_003] SECURITY_TYPE needs to be 0x00 (no security)
  2177. if (MmePacket->MMENTRY[1] != 0)
  2178. {
  2179. SAVE_SYS_LOG_MSG_EVCOMM("CM_SLAC_PARM_REQ: ignored(invalid SECURITY_TYPE,%d)\n", //Source MAC Address (EV MAC)
  2180. MmePacket->MMENTRY[1]);
  2181. break;
  2182. }
  2183. //=================== Legal CM_SLAC_PARM_REQ Zone =================
  2184. Update_V2G_Flow_Status(CM_SLAC_PARM_REQ);
  2185. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_RX_CM_SLAC_PARM_REQ)
  2186. {
  2187. //Once receiving CM_SLAC_PARM_REQ, set PWM as 5%
  2188. SwitchCpStateE(DISABLE);
  2189. OutputCpPwmDuty(5);
  2190. }
  2191. #endif
  2192. //Checking if this SLAC Req comes before 5% PWM (for 15118)
  2193. if(ShmInternalComm->ChargingPermission == FALSE)
  2194. {
  2195. //Sniffer_Tcpdump(ENABLE);
  2196. SAVE_SYS_LOG_MSG_EVCOMM("Check Permission: %d (SLAC first => START)\n", ShmInternalComm->ChargingPermission);
  2197. }
  2198. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2199. {
  2200. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SLAC_PARM_REQ ---\n");
  2201. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2202. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2203. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2204. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2205. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2206. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2207. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2208. DEBUG_PRINTF_EVCOMM_DETAIL("CipherSuiteSetSize: 0x%x\n", MmePacket->MMENTRY[10]);
  2209. DEBUG_PRINTF_EVCOMM_DETAIL("CipherSuite [1]: 0x%x,0x%x\n",
  2210. MmePacket->MMENTRY[11], MmePacket->MMENTRY[12]);
  2211. }
  2212. #endif
  2213. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2214. {
  2215. //Saving each CM_SLAC_PARM_REQ data into EVCC database
  2216. EvMac_in = &MmePacket->OSA[0];
  2217. RunID_in = &MmePacket->MMENTRY[2];
  2218. idx = SLAC_DB_Add(EvMac_in, RunID_in); //(EvMac, RunID)
  2219. if (idx < 0)
  2220. {
  2221. SAVE_SYS_LOG_MSG_EVCOMM("DB is full or errors occour(%d) => ignore\n", idx);
  2222. break;
  2223. }
  2224. //Select the 1st EV MAC address
  2225. if (SLAC_INFO.arrayLen == 1) //1st Req
  2226. {
  2227. #if 1
  2228. SAVE_SYS_LOG_MSG_EVCOMM("CM_SLAC_PARM_REQ[%d](%02X:%02X:%02X:%02X:%02X:%02X, %02X%02X%02X%02X%02X%02X%02X%02X):selected\n",
  2229. (idx + 1),
  2230. MmePacket->OSA[0], MmePacket->OSA[1], MmePacket->OSA[2], MmePacket->OSA[3], MmePacket->OSA[4], MmePacket->OSA[5],
  2231. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3], MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2232. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7], MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2233. #endif
  2234. /*
  2235. sprintf((char*)buf_log_evcomm,
  2236. "[SLAC][EVMAC][%d-th]%02X:%02X:%02X:%02X:%02X:%02X (selected)", //Source MAC Address (EV MAC)
  2237. SLAC_INFO.arrayLen,
  2238. MmePacket->OSA[0], MmePacket->OSA[1],
  2239. MmePacket->OSA[2], MmePacket->OSA[3],
  2240. MmePacket->OSA[4], MmePacket->OSA[5]);
  2241. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2242. sprintf((char*)buf_log_evcomm,
  2243. "[SLAC][RunID][%d-th]%02X%02X%02X%02X%02X%02X%02X%02X (selected)", //RunID (from EVCC)
  2244. SLAC_INFO.arrayLen,
  2245. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2246. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2247. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2248. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2249. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2250. */
  2251. }
  2252. else //2nd Req
  2253. {
  2254. #if 1
  2255. SAVE_SYS_LOG_MSG_EVCOMM("CM_SLAC_PARM_REQ[%d](%02X:%02X:%02X:%02X:%02X:%02X, %02X%02X%02X%02X%02X%02X%02X%02X):not selected\n",
  2256. (idx + 1),
  2257. MmePacket->OSA[0], MmePacket->OSA[1], MmePacket->OSA[2], MmePacket->OSA[3], MmePacket->OSA[4], MmePacket->OSA[5],
  2258. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3], MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2259. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7], MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2260. #endif
  2261. /*
  2262. sprintf((char*)buf_log_evcomm,
  2263. "[SLAC][EVMAC][%d-th]%02X:%02X:%02X:%02X:%02X:%02X (not selected)", //Source MAC Address (EV MAC)
  2264. SLAC_INFO.arrayLen,
  2265. MmePacket->OSA[0], MmePacket->OSA[1],
  2266. MmePacket->OSA[2], MmePacket->OSA[3],
  2267. MmePacket->OSA[4], MmePacket->OSA[5]);
  2268. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2269. sprintf((char*)buf_log_evcomm,
  2270. "[SLAC][RunID][%d-th]%02X%02X%02X%02X%02X%02X%02X%02X (not selected)", //RunID (from EVCC)
  2271. SLAC_INFO.arrayLen,
  2272. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2273. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2274. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2275. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2276. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2277. */
  2278. }
  2279. memcpy(EvMac, MmePacket->OSA, sizeof(EvMac));
  2280. memcpy(DestSocketAddress.sll_addr, MmePacket->OSA, SLAC_EVMAC_LENGTH);
  2281. memcpy(SlacRunId, MmePacket->MMENTRY + 2, SLAC_RUNID_LENGTH);
  2282. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2283. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  2284. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2285. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2286. SendMmePacket.MMV = MmePacket->MMV;
  2287. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_PARM_CNF;
  2288. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2289. SendMmePacketSize = 0;
  2290. memset(SendMmePacket.MMENTRY, 0xFF, 6); //M-SOUND_TARGET(6-byte:0xFFFFFFFFFFFF): Fixed value indicating that M-Sounds to be sent as Ethernet broadcast
  2291. SendMmePacketSize += 6;
  2292. 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
  2293. SendMmePacket.MMENTRY[SendMmePacketSize++] = 6; //Time_Out(0x06): unit = 100ms
  2294. 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
  2295. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SLAC_INFO.array[idx].EvMac, 6); //FORWARDING_STA(MAC Address of the EV HLE)
  2296. SendMmePacketSize += 6;
  2297. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00): 0x00(PEV-EVSE Association), 0x01-0xFF(Reserved)
  2298. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00): 0x00(No Security), 0x01(Public Key Signature), 0x02-0xFF(Reserved)
  2299. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SlacRunId, SLAC_RUNID_LENGTH); //RunID (8-byte)
  2300. SendMmePacketSize += SLAC_RUNID_LENGTH;
  2301. SendMmePacketSize += 19; //the size before MMENTRY
  2302. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2303. {
  2304. DEBUG_PRINTF_EVCOMM_DETAIL("***** Response MME Packet *****\n");
  2305. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2306. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  2307. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2308. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  2309. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  2310. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  2311. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  2312. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  2313. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_PARM_CNF ---\n");
  2314. DEBUG_PRINTF_EVCOMM_DETAIL("M-SOUND_TARGET: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2315. SendMmePacket.MMENTRY[0],SendMmePacket.MMENTRY[1],SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],
  2316. SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5]);
  2317. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", SendMmePacket.MMENTRY[6]);
  2318. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out: 0x%x\n", SendMmePacket.MMENTRY[7]);
  2319. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE: 0x%x\n", SendMmePacket.MMENTRY[8]);
  2320. DEBUG_PRINTF_EVCOMM_DETAIL("M-FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2321. SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],SendMmePacket.MMENTRY[12],
  2322. SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14]);
  2323. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[15]);
  2324. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[16]);
  2325. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2326. SendMmePacket.MMENTRY[17],SendMmePacket.MMENTRY[18],SendMmePacket.MMENTRY[19],SendMmePacket.MMENTRY[20],
  2327. SendMmePacket.MMENTRY[21],SendMmePacket.MMENTRY[22],SendMmePacket.MMENTRY[23],SendMmePacket.MMENTRY[24]);
  2328. }
  2329. #endif
  2330. Update_V2G_Flow_Status(CM_SLAC_PARM_CONF);
  2331. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2332. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d, Rtn=%d\n",SendMmePacketSize,Rtn);
  2333. ftime(&SeqStartTime);
  2334. counter = 0;
  2335. break;
  2336. }
  2337. #else
  2338. {
  2339. memcpy(EvMac, MmePacket->OSA, sizeof(EvMac));
  2340. memcpy(DestSocketAddress.sll_addr, MmePacket->OSA, sizeof(EvMac));
  2341. memcpy(SlacRunId,MmePacket->MMENTRY + 2, sizeof(SlacRunId));
  2342. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2343. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  2344. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2345. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2346. SendMmePacket.MMV = MmePacket->MMV;
  2347. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_PARM_CNF;
  2348. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2349. SendMmePacketSize = 0;
  2350. memset(SendMmePacket.MMENTRY, 0xFF, 6); //M-SOUND_TARGET(6-byte:0xFFFFFFFFFFFF): Fixed value indicating that M-Sounds to be sent as Ethernet broadcast
  2351. SendMmePacketSize += 6;
  2352. 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
  2353. SendMmePacket.MMENTRY[SendMmePacketSize++] = 6; //Time_Out(0x06): unit = 100ms
  2354. 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
  2355. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac, 6); //FORWARDING_STA(MAC Address of the EV HLE)
  2356. SendMmePacketSize += 6;
  2357. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00): 0x00(PEV-EVSE Association), 0x01-0xFF(Reserved)
  2358. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00): 0x00(No Security), 0x01(Public Key Signature), 0x02-0xFF(Reserved)
  2359. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SlacRunId, sizeof(SlacRunId)); //RunID (8-byte)
  2360. SendMmePacketSize += sizeof(SlacRunId);
  2361. SendMmePacketSize += 19; //the size before MMENTRY
  2362. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2363. {
  2364. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  2365. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2366. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  2367. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2368. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  2369. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  2370. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  2371. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  2372. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  2373. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_PARM_CNF ---\n");
  2374. DEBUG_PRINTF_EVCOMM_DETAIL("M-SOUND_TARGET: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2375. SendMmePacket.MMENTRY[0],SendMmePacket.MMENTRY[1],SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],
  2376. SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5]);
  2377. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", SendMmePacket.MMENTRY[6]);
  2378. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out: 0x%x\n", SendMmePacket.MMENTRY[7]);
  2379. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE: 0x%x\n", SendMmePacket.MMENTRY[8]);
  2380. DEBUG_PRINTF_EVCOMM_DETAIL("M-FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2381. SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],SendMmePacket.MMENTRY[12],
  2382. SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14]);
  2383. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[15]);
  2384. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[16]);
  2385. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2386. SendMmePacket.MMENTRY[17],SendMmePacket.MMENTRY[18],SendMmePacket.MMENTRY[19],SendMmePacket.MMENTRY[20],
  2387. SendMmePacket.MMENTRY[21],SendMmePacket.MMENTRY[22],SendMmePacket.MMENTRY[23],SendMmePacket.MMENTRY[24]);
  2388. }
  2389. #endif
  2390. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2391. Update_V2G_Flow_Status(CM_SLAC_PARM_CONF);
  2392. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  2393. ftime(&SeqStartTime);
  2394. counter = 0;
  2395. break;
  2396. }
  2397. #endif
  2398. }
  2399. case MMTYPE_CM_START_ATTEN_CHAR_IND:
  2400. {
  2401. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2402. {
  2403. SAVE_SYS_LOG_MSG_EVCOMM("CM_START_ATTEN_CHAR_IND: ignored(time up)\n");
  2404. break;
  2405. }
  2406. //Avoid Coupled CM_START_ATTEN_CHAR_IND
  2407. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2408. {
  2409. SAVE_SYS_LOG_MSG_EVCOMM("CM_START_ATTEN_CHAR_IND: ignored(coupled SLAC,%d)\n", CheckConnectorPlugIn());
  2410. break;
  2411. }
  2412. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2413. {
  2414. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_START_ATTEN_CHAR_IND (counter : %d/3 ) ---\n", counter);
  2415. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2416. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2417. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", MmePacket->MMENTRY[2]);
  2418. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out 0x%x\n", MmePacket->MMENTRY[3]);
  2419. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE 0x%x\n", MmePacket->MMENTRY[4]); //Fixed value (0x01) indicating ��other Green PHY station��
  2420. DEBUG_PRINTF_EVCOMM_DETAIL("FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2421. MmePacket->MMENTRY[5],MmePacket->MMENTRY[6],MmePacket->MMENTRY[7],MmePacket->MMENTRY[8],
  2422. MmePacket->MMENTRY[9],MmePacket->MMENTRY[10]);
  2423. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2424. MmePacket->MMENTRY[11],MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],MmePacket->MMENTRY[14],
  2425. MmePacket->MMENTRY[15],MmePacket->MMENTRY[16],MmePacket->MMENTRY[17],MmePacket->MMENTRY[18]);
  2426. }
  2427. #endif
  2428. //New SLAC architecture designed by Joseph
  2429. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2430. {
  2431. EvMac_in = &MmePacket->OSA[0];
  2432. RunID_in = &MmePacket->MMENTRY[11];
  2433. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2434. if (idx >= 0)
  2435. {
  2436. Update_V2G_Flow_Status(CM_START_ATTEN_CHAR_IND);
  2437. counter++;
  2438. //[TC_SECC_VTB_AttenuationCharacterization_013]
  2439. if (MmePacket->MMENTRY[0] != 0) //APPLICATION_TYPE must be 0x00(EV-EVSE Matching)
  2440. {
  2441. sprintf((char*)buf_log_evcomm,
  2442. "[CM_START_ATTEN_CHAR_IND]APPLICATION_TYPE(%d): invalid => ignore Req",
  2443. MmePacket->MMENTRY[0]);
  2444. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2445. break;
  2446. }
  2447. //[TC_SECC_VTB_AttenuationCharacterization_014]
  2448. if (MmePacket->MMENTRY[1] != 0) //SECURITY_TYPE must be 0x00(No Security)
  2449. {
  2450. sprintf((char*)buf_log_evcomm,
  2451. "[CM_START_ATTEN_CHAR_IND]SECURITY_TYPE(%d): invalid => ignore Req",
  2452. MmePacket->MMENTRY[1]);
  2453. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2454. break;
  2455. }
  2456. //[TC_SECC_VTB_AttenuationCharacterization_017]
  2457. if (MmePacket->MMENTRY[4] != 0x01) //RESP_TYPE must be 0x01(Send to another GP STA(EV))
  2458. {
  2459. sprintf((char*)buf_log_evcomm,
  2460. "[CM_START_ATTEN_CHAR_IND]RESP_TYPE(%d): invalid => ignore Req",
  2461. MmePacket->MMENTRY[4]);
  2462. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2463. break;
  2464. }
  2465. //[TC_SECC_VTB_AttenuationCharacterization_021]
  2466. //FORWARDING_STA: MAC Address of the EV HLE (station which the measurement results shall be sent to)
  2467. if (Array_Compare_Identity(EvMac_in, &MmePacket->MMENTRY[5], SLAC_EVMAC_LENGTH) == FALSE)
  2468. {
  2469. sprintf((char*)buf_log_evcomm,
  2470. "[CM_START_ATTEN_CHAR_IND]FORWARDING_STA(%02X:%02X:%02X:%02X:%02X:%02X): invalid => ignore Req",
  2471. MmePacket->MMENTRY[5], MmePacket->MMENTRY[6],
  2472. MmePacket->MMENTRY[7], MmePacket->MMENTRY[8],
  2473. MmePacket->MMENTRY[9], MmePacket->MMENTRY[10]);
  2474. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2475. SLAC_INFO.array[idx].StartAttenCharErr = TRUE;
  2476. break;
  2477. }
  2478. //Check RunID
  2479. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE)
  2480. {
  2481. SLAC_INFO.array[idx].MnbcSoundNum = MmePacket->MMENTRY[2];
  2482. SLAC_INFO.array[idx].StartAttenCharCnt++;
  2483. #if 0
  2484. sprintf((char*)buf_log_evcomm,
  2485. "[SLAC][RX]CM_START_ATTEN_CHAR_IND[%d]:%d-th",
  2486. (idx + 1),
  2487. SLAC_INFO.array[idx].StartAttenCharCnt);
  2488. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2489. #endif
  2490. if (SLAC_INFO.array[idx].StartAttenCharCnt == 1)
  2491. {
  2492. memset(SLAC_INFO.array[idx].AAG, 0, sizeof(SLAC_INFO.array[idx].AAG));
  2493. SLAC_INFO.array[idx].AttenProfileCnt = 0;
  2494. ftime(&SeqStartTime); //start TT_EVSE_match_MNBC
  2495. }
  2496. else if (SLAC_INFO.array[idx].StartAttenCharCnt >= 3)
  2497. {
  2498. sprintf((char*)buf_log_evcomm,
  2499. "[CM_START_ATTEN_CHAR_IND]counter(%d): unexpected",
  2500. SLAC_INFO.array[idx].StartAttenCharCnt);
  2501. }
  2502. else
  2503. {
  2504. //null
  2505. }
  2506. }
  2507. else
  2508. {
  2509. //This RunID is not matched with this EvMac,
  2510. //or this RunID is not found in DB.
  2511. sprintf((char*)buf_log_evcomm,
  2512. "[CM_START_ATTEN_CHAR_IND]EvMac-RunID: unmatched => ignore Req");
  2513. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2514. //Response: ignore
  2515. }
  2516. }
  2517. else
  2518. {
  2519. //this msg source is not in database
  2520. //ignore
  2521. }
  2522. break;
  2523. }
  2524. #else //Old SLAC architecture designed by Vern
  2525. {
  2526. MnbcSoundNum = MmePacket->MMENTRY[2];
  2527. Update_V2G_Flow_Status(CM_START_ATTEN_CHAR_IND);
  2528. counter++;
  2529. if(counter == 1)
  2530. {
  2531. memset(Aag, 0, sizeof(Aag));
  2532. AttenProfileCnt = 0;
  2533. ftime(&SeqStartTime); //start TT_EVSE_match_MNBC
  2534. }
  2535. else if(counter >= 3)
  2536. {
  2537. counter = 0;
  2538. }
  2539. break;
  2540. }
  2541. #endif
  2542. }
  2543. case MMTYPE_CM_MNBC_SOUND_IND:
  2544. {
  2545. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2546. {
  2547. SAVE_SYS_LOG_MSG_EVCOMM("CM_MNBC_SOUND_IND: ignored(timeup)\n");
  2548. break;
  2549. }
  2550. //Avoid Coupled CM_MNBC_SOUND_IND
  2551. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2552. {
  2553. sprintf((char*)buf_log_evcomm,
  2554. "CM_MNBC_SOUND_IND: ignored(coupled SLAC,%d)",
  2555. CheckConnectorPlugIn());
  2556. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2557. break;
  2558. }
  2559. if(V2gFlowStatus == CM_START_ATTEN_CHAR_IND)
  2560. {
  2561. counter = 0;
  2562. }
  2563. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2564. {
  2565. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_MNBC_SOUND_IND (counter : %d/%d) ---\n", counter, SLAC_INFO.array[idx].MnbcSoundNum);
  2566. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2567. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2568. DEBUG_PRINTF_EVCOMM_DETAIL("SenderID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2569. MmePacket->MMENTRY[2],MmePacket->MMENTRY[3],MmePacket->MMENTRY[4],MmePacket->MMENTRY[5],
  2570. MmePacket->MMENTRY[6],MmePacket->MMENTRY[7],MmePacket->MMENTRY[8],MmePacket->MMENTRY[9],
  2571. MmePacket->MMENTRY[10],MmePacket->MMENTRY[11],MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],
  2572. MmePacket->MMENTRY[14],MmePacket->MMENTRY[15],MmePacket->MMENTRY[16],MmePacket->MMENTRY[17],
  2573. MmePacket->MMENTRY[18]);
  2574. DEBUG_PRINTF_EVCOMM_DETAIL("Cnt: 0x%x\n", MmePacket->MMENTRY[19]);
  2575. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2576. MmePacket->MMENTRY[20],MmePacket->MMENTRY[21],MmePacket->MMENTRY[22],MmePacket->MMENTRY[23],
  2577. MmePacket->MMENTRY[24],MmePacket->MMENTRY[25],MmePacket->MMENTRY[26],MmePacket->MMENTRY[27]);
  2578. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2579. MmePacket->MMENTRY[28],MmePacket->MMENTRY[29],MmePacket->MMENTRY[30],MmePacket->MMENTRY[31],
  2580. MmePacket->MMENTRY[32],MmePacket->MMENTRY[33],MmePacket->MMENTRY[34],MmePacket->MMENTRY[35]);
  2581. DEBUG_PRINTF_EVCOMM_DETAIL("Rnd: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2582. MmePacket->MMENTRY[36],MmePacket->MMENTRY[37],MmePacket->MMENTRY[38],MmePacket->MMENTRY[39],
  2583. MmePacket->MMENTRY[40],MmePacket->MMENTRY[41],MmePacket->MMENTRY[42],MmePacket->MMENTRY[43],
  2584. MmePacket->MMENTRY[44],MmePacket->MMENTRY[45],MmePacket->MMENTRY[46],MmePacket->MMENTRY[47],
  2585. MmePacket->MMENTRY[48],MmePacket->MMENTRY[49],MmePacket->MMENTRY[50],MmePacket->MMENTRY[51]);
  2586. }
  2587. #endif
  2588. //New SLAC architecture designed by Joseph
  2589. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2590. {
  2591. EvMac_in = &MmePacket->OSA[0];
  2592. RunID_in = &MmePacket->MMENTRY[20];
  2593. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2594. if (idx >= 0)
  2595. {
  2596. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2597. counter++;
  2598. //Check for RunID
  2599. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE)
  2600. {
  2601. SLAC_INFO.array[idx].MnbcSoundCnt++;
  2602. /*
  2603. sprintf((char*)buf_log_evcomm,
  2604. "[SLAC][RX]CM_MNBC_SOUND_IND[%d]:%d-th",
  2605. (idx + 1),
  2606. SLAC_INFO.array[idx].MnbcSoundCnt);
  2607. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2608. */
  2609. }
  2610. else
  2611. {
  2612. //RunID is not matched or does not exist.
  2613. sprintf((char*)buf_log_evcomm,
  2614. "CM_MNBC_SOUND_IND]EvMac-RunID: unmatched");
  2615. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2616. }
  2617. }
  2618. else
  2619. {
  2620. //ignore
  2621. sprintf((char*)buf_log_evcomm,
  2622. "CM_MNBC_SOUND_IND]EvMac does not exist");
  2623. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2624. }
  2625. break;
  2626. }
  2627. #else //Old SLAC architecture designed by Vern
  2628. {
  2629. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2630. counter++;
  2631. break;
  2632. }
  2633. #endif
  2634. }
  2635. case MMTYPE_CM_ATTEN_PROFILE_IND:
  2636. {
  2637. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2638. {
  2639. SAVE_SYS_LOG_MSG_EVCOMM("CM_ATTEN_PROFILE_IND: ignore(timeup)\n");
  2640. break;
  2641. }
  2642. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2643. {
  2644. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_ATTEN_PROFILE_IND (counter : %d/%d) ---\n", counter, SLAC_INFO.array[idx].MnbcSoundNum);
  2645. DEBUG_PRINTF_EVCOMM_DETAIL("EV MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2646. MmePacket->MMENTRY[0], MmePacket->MMENTRY[1], MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2647. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5]);
  2648. DEBUG_PRINTF_EVCOMM_DETAIL("NumGroups: 0x%x\n", MmePacket->MMENTRY[6]); //NumGroups, Number of AAG Groups (ex: 0x3A = 58)
  2649. //NumGroups: Number of OFDM carrier groups used for the SLAC signal characterization.
  2650. //AAG[i]: Average Attenuation of Group i (i = 1 ~ 58)
  2651. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", MmePacket->MMENTRY[7]);
  2652. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  2653. for(Rtn = 0; Rtn < MmePacket->MMENTRY[6]; Rtn++)
  2654. {
  2655. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, MmePacket->MMENTRY[8 + Rtn]);
  2656. }
  2657. DEBUG_PRINTF_EVCOMM_DETAIL("AAG: %s\n", tmpBuf);
  2658. }
  2659. #endif
  2660. //New SLAC architecture designed by Joseph
  2661. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2662. {
  2663. EvMac_in = &MmePacket->MMENTRY[0]; //[CAUTION] The EvMac address is not &MmePacket->OSA[0]
  2664. //[CAUTION] There is no RunID information of CM_ATTEN_PROFILE_IND
  2665. // packet, which means SECC cannot use the RunID to
  2666. // distinguish those SLAC request with identical EvMac
  2667. // but with different RunID.
  2668. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2669. /*
  2670. printf("%d, %d, %d, %d\n",
  2671. idx,
  2672. SLAC_INFO.array[idx].AagGroupsNum,
  2673. MmePacket->MMENTRY[6],
  2674. SLAC_INFO.array[idx].AttenProfileCnt);
  2675. */
  2676. if (idx >= 0)
  2677. {
  2678. SLAC_INFO.array[idx].AttenProfileCnt++;
  2679. /*
  2680. sprintf((char*)buf_log_evcomm,
  2681. "[SLAC][RX]CM_ATTEN_PROFILE_IND[%d]:%d-th",
  2682. (idx + 1),
  2683. SLAC_INFO.array[idx].AttenProfileCnt);
  2684. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2685. */
  2686. //printf("%d, %d\n", SLAC_INFO.array[idx].AagGroupsNum, MmePacket->MMENTRY[6]);
  2687. SLAC_INFO.array[idx].AagGroupsNum = MmePacket->MMENTRY[6];
  2688. ////NumGroups, Number of AAG Groups (ex: 0x3A = 58)
  2689. for(Rtn = 0; Rtn < SLAC_INFO.array[idx].AagGroupsNum; Rtn++) //ex:58
  2690. {
  2691. SLAC_INFO.array[idx].AAG[Rtn] += MmePacket->MMENTRY[8 + Rtn];
  2692. }
  2693. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2694. break;
  2695. }
  2696. else
  2697. {
  2698. //The EvMac is not in the database
  2699. //ignore
  2700. sprintf((char*)buf_log_evcomm,
  2701. "[CM_ATTEN_PROFILE_IND]EvMac(%02X%02X%02X%02X%02X%02X): not exist => ignore",
  2702. EvMac_in[0], EvMac_in[1], EvMac_in[2], EvMac_in[3], EvMac_in[4], EvMac_in[5]);
  2703. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2704. break;
  2705. }
  2706. }
  2707. #else //Old SLAC architecture designed by Vern
  2708. {
  2709. AagGroupsNum = MmePacket->MMENTRY[6];
  2710. for(Rtn = 0; Rtn < MmePacket->MMENTRY[6]; Rtn++)
  2711. {
  2712. Aag[Rtn] += MmePacket->MMENTRY[8 + Rtn];
  2713. }
  2714. AttenProfileCnt++;
  2715. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2716. break;
  2717. }
  2718. #endif
  2719. }
  2720. case MMTYPE_CM_ATTEN_CHAR_RSP:
  2721. {
  2722. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2723. {
  2724. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_ATTEN_CHAR_RSP ---\n");
  2725. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2726. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2727. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2728. MmePacket->MMENTRY[2],MmePacket->MMENTRY[3],MmePacket->MMENTRY[4],MmePacket->MMENTRY[5],
  2729. MmePacket->MMENTRY[6],MmePacket->MMENTRY[7]);
  2730. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2731. MmePacket->MMENTRY[8],MmePacket->MMENTRY[9],MmePacket->MMENTRY[10],MmePacket->MMENTRY[11],
  2732. MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],MmePacket->MMENTRY[14],MmePacket->MMENTRY[15]);
  2733. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  2734. for(Rtn = 0; Rtn < 17; Rtn++)
  2735. {
  2736. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, MmePacket->MMENTRY[16 + Rtn]);
  2737. }
  2738. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: %s\n", tmpBuf);
  2739. ;
  2740. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  2741. for(Rtn = 0; Rtn < 17; Rtn++)
  2742. {
  2743. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, MmePacket->MMENTRY[33 + Rtn]);
  2744. }
  2745. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: %s\n", tmpBuf);
  2746. DEBUG_PRINTF_EVCOMM_DETAIL("Result: 0x%x\n", MmePacket->MMENTRY[50]); //Fixed value of 0x00 indicates a successful SLAC process
  2747. }
  2748. #endif
  2749. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2750. {
  2751. //Check ODA (Destination Address)
  2752. if (Array_Compare_Identity(CsuMac, MmePacket->ODA, SLAC_EVSE_MAC_LENGTH) == FALSE)
  2753. {
  2754. SAVE_SYS_LOG_MSG_EVCOMM("[CM_ATTEN_CHAR_RSP]wrong ODA: ignore\n");
  2755. break;
  2756. }
  2757. EvMac_in = &MmePacket->OSA[0];
  2758. RunID_in = &MmePacket->MMENTRY[8];
  2759. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2760. //Check Parameters
  2761. if ((MmePacket->MMENTRY[0] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_005] applicationType must be 0x00
  2762. (MmePacket->MMENTRY[1] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_006] securityType must be 0x00
  2763. (SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in) < 0) || //[TC_SECC_VTB_AttenuationCharacterization_007] sourceAddress cannot not be all zero
  2764. (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_008] check for invalid runID
  2765. (Array_Check_All_Zero(&MmePacket->MMENTRY[16], 17) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_009] SourceID(17 bytes) must be all zero.
  2766. (Array_Check_All_Zero(&MmePacket->MMENTRY[33], 17) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_009] RESP_ID (17 bytes) must be all zero.
  2767. (MmePacket->MMENTRY[50] != 0) //Result: must be 0x00(Success)
  2768. )
  2769. {
  2770. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry++;
  2771. sprintf((char*)buf_log_evcomm,
  2772. "[WARNING][SLAC][RX]CM_ATTEN_CHAR_RSP:invalid para(%d,%d,%d,%d,%d) => %d-th retry",
  2773. MmePacket->MMENTRY[0], //applicationType must be 0x00
  2774. MmePacket->MMENTRY[1], //securityType must be 0x00
  2775. SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in),
  2776. SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in),
  2777. MmePacket->MMENTRY[50],
  2778. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry
  2779. );
  2780. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2781. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry <= 2) //limited to 2 retries
  2782. {
  2783. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2784. ftime(&SeqStartTime);
  2785. break;
  2786. }
  2787. else
  2788. {
  2789. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR][SLAC][RX]CM_ATTEN_CHAR_RSP:invalid para => 2-retry fail => End_Process");
  2790. Update_V2G_Flow_Status(Other_Fault);
  2791. break;
  2792. }
  2793. }
  2794. else
  2795. {
  2796. //The CM_ATTEN_CHAR_IND is legal
  2797. SLAC_INFO.array[idx].AttenCharRspCnt++;
  2798. sprintf((char*)buf_log_evcomm,
  2799. "[SLAC][RX]CM_ATTEN_CHAR_RSP[%d]:%d-th",
  2800. (idx + 1),
  2801. SLAC_INFO.array[idx].AttenCharRspCnt);
  2802. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2803. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry = 0;
  2804. Update_V2G_Flow_Status(CM_ATTEN_CHAR_RSP);
  2805. ftime(&SeqStartTime);
  2806. break;
  2807. }
  2808. }
  2809. #else
  2810. {
  2811. //Check Parameters
  2812. if ((MmePacket->MMENTRY[0] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_005] applicationType must be 0x00
  2813. (MmePacket->MMENTRY[1] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_006] securityType must be 0x00
  2814. (Array_Compare_Identity(SLAC_INFO.array[0].EvMac, &MmePacket->MMENTRY[2], 6) == TRUE) || //[TC_SECC_VTB_AttenuationCharacterization_007] sourceAddress cannot not be all zero
  2815. (Array_Compare_Identity(SLAC_INFO.array[0].RunID, &MmePacket->MMENTRY[8], 8) == TRUE) //[TC_SECC_VTB_AttenuationCharacterization_008] check for invalid runID
  2816. )
  2817. {
  2818. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry++;
  2819. sprintf((char*)buf_log_evcomm,
  2820. "[WARNING][SLAC][RX]CM_ATTEN_CHAR_RSP: invalid parameters(%d-th)",
  2821. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  2822. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2823. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry <= 2) //limited to 2 retries
  2824. {
  2825. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2826. ftime(&SeqStartTime);
  2827. break;
  2828. }
  2829. else
  2830. {
  2831. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]CM_ATTEN_CHAR_RSP: invalid parameters => End_Process");
  2832. Update_V2G_Flow_Status(Other_Fault);
  2833. ftime(&SeqStartTime);
  2834. break;
  2835. }
  2836. }
  2837. else
  2838. {
  2839. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry = 0;
  2840. Update_V2G_Flow_Status(CM_ATTEN_CHAR_RSP);
  2841. ftime(&SeqStartTime);
  2842. break;
  2843. }
  2844. }
  2845. #endif
  2846. }
  2847. case MMTYPE_CM_VALIDATE_REQ: //BCB Toggle
  2848. {
  2849. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2850. {
  2851. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_VALIDATE_REQ ---\n");
  2852. DEBUG_PRINTF_EVCOMM_DETAIL("Signal Type: 0x%x\n", MmePacket->MMENTRY[0]); //Fixed value (0x00) to indicate ��PEV S2 toggles on control pilot line��
  2853. 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.
  2854. 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��.
  2855. }
  2856. #endif
  2857. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2858. {
  2859. counter = 0;
  2860. EvMac_in = &MmePacket->OSA[0];
  2861. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2862. if (idx >= 0)
  2863. {
  2864. Update_V2G_Flow_Status(CM_VALIDATE_CNF);
  2865. SLAC_INFO.array[idx].ValidateReqCnt++;
  2866. sprintf((char*)buf_log_evcomm,
  2867. "[SLAC][RX]CM_VALIDATE_REQ[%d]:%d-th",
  2868. (idx + 1),
  2869. SLAC_INFO.array[idx].ValidateReqCnt);
  2870. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2871. //[To-Do] Protection
  2872. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2873. memcpy(SendMmePacket.ODA, EvMac_in, SLAC_EVMAC_LENGTH);
  2874. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2875. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2876. SendMmePacket.MMV = 0x01;
  2877. SendMmePacket.MMTYPE = MMTYPE_CM_VALIDATE_CNF;
  2878. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2879. SendMmePacketSize = 0;
  2880. if(counter == 0)
  2881. {
  2882. //The First MMTYPE_CM_VALIDATE_REQ because Unicast
  2883. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SignalType(0x00): Fixed value to indicate "EV S2 toggles on control pilot line"
  2884. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //ToggleNum(0x00): Fixed value. In the first VALIDATE Request-Response exchange, the ToggleNum field shall be set to zero.
  2885. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  2886. SendMmePacket.MMENTRY[SendMmePacketSize++] = 1; //0x01 = Ready
  2887. #else
  2888. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  2889. #endif
  2890. }
  2891. else
  2892. {
  2893. //The Second MMTYPE_CM_VALIDATE_REQ because Broadcast
  2894. unsigned char PreStatus = 3;
  2895. unsigned char ToggleNum = 0;
  2896. ftime(&SeqStartTime);
  2897. while(1)
  2898. {
  2899. if((EVCOMM_SYS_INFO.CpState == 4) && (PreStatus == 3))
  2900. {
  2901. ToggleNum++;
  2902. PreStatus = 4;
  2903. }
  2904. else
  2905. {
  2906. PreStatus = 3;
  2907. }
  2908. ftime(&SeqEndTime);
  2909. if(DiffTimeb(SeqStartTime, SeqEndTime) >= (SendMmePacket.MMENTRY[1]*100 + 100))
  2910. {
  2911. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate "PEV S2 toggles on control pilot line"
  2912. SendMmePacket.MMENTRY[SendMmePacketSize++] = ToggleNum;
  2913. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  2914. SendMmePacket.MMENTRY[SendMmePacketSize++] = 2; //0x02 = Success
  2915. #else
  2916. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  2917. #endif
  2918. break;
  2919. }
  2920. usleep(1000);
  2921. }
  2922. }
  2923. SendMmePacketSize += 19; //the size before MMENTRY
  2924. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2925. ftime(&SeqStartTime);
  2926. }
  2927. else
  2928. {
  2929. //EvMac does not exist.
  2930. //ignore
  2931. }
  2932. break;
  2933. }
  2934. #else
  2935. {
  2936. counter = 0;
  2937. for(Rtn = 0; Rtn < 6; Rtn++)
  2938. {
  2939. if(MmePacket->ODA[Rtn] != CsuMac[Rtn])
  2940. {
  2941. counter = 1;
  2942. break;
  2943. }
  2944. }
  2945. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2946. memcpy(SendMmePacket.ODA, EvMac,6);
  2947. memcpy(SendMmePacket.OSA, CsuMac,6);
  2948. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2949. SendMmePacket.MMV = 0x01;
  2950. SendMmePacket.MMTYPE = MMTYPE_CM_VALIDATE_CNF;
  2951. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2952. SendMmePacketSize = 0;
  2953. if(counter == 0)
  2954. {
  2955. //The First MMTYPE_CM_VALIDATE_REQ because Unicast
  2956. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate ��PEV S2 toggles on control pilot line��
  2957. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value In the first VALIDATE Request-Response exchange, the ToggleNum field shall be set to zero.
  2958. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  2959. SendMmePacket.MMENTRY[SendMmePacketSize++] = 1; //0x01 = Ready
  2960. #else
  2961. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  2962. #endif
  2963. }
  2964. else
  2965. {
  2966. //The Second MMTYPE_CM_VALIDATE_REQ because Broadcast
  2967. unsigned char PreStatus = 3, ToggleNum = 0;
  2968. ftime(&SeqStartTime);
  2969. while(1)
  2970. {
  2971. ftime(&SeqEndTime);
  2972. if((EVCOMM_SYS_INFO.CpState == 4) && (PreStatus == 3))
  2973. {
  2974. ToggleNum++;
  2975. PreStatus = 4;
  2976. }
  2977. else
  2978. {
  2979. PreStatus = 3;
  2980. }
  2981. if(DiffTimeb(SeqStartTime, SeqEndTime) >= (SendMmePacket.MMENTRY[1]*100 + 100))
  2982. {
  2983. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate ��PEV S2 toggles on control pilot line��
  2984. SendMmePacket.MMENTRY[SendMmePacketSize++] = ToggleNum;
  2985. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  2986. SendMmePacket.MMENTRY[SendMmePacketSize++] = 2; //0x02 = Success
  2987. #else
  2988. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  2989. #endif
  2990. break;
  2991. }
  2992. usleep(1000);
  2993. }
  2994. }
  2995. SendMmePacketSize += 19; //the size before MMENTRY
  2996. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2997. Update_V2G_Flow_Status(CM_VALIDATE_CNF);
  2998. ftime(&SeqStartTime);
  2999. break;
  3000. }
  3001. #endif
  3002. }
  3003. case MMTYPE_CM_SLAC_MATCH_REQ:
  3004. {
  3005. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3006. {
  3007. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SLAC_MATCH_REQ ---\n");
  3008. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  3009. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  3010. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", MmePacket->MMENTRY[2],MmePacket->MMENTRY[3]); //Fixed value (0x3E) for matching
  3011. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3012. for(Rtn=0; Rtn<17; Rtn++)
  3013. {
  3014. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[4+Rtn]);
  3015. }
  3016. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3017. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3018. for(Rtn=0; Rtn<6; Rtn++)
  3019. {
  3020. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[21+Rtn]);
  3021. }
  3022. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3023. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3024. for(Rtn=0; Rtn<17; Rtn++)
  3025. {
  3026. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[27+Rtn]);
  3027. }
  3028. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3029. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3030. for(Rtn=0; Rtn<6; Rtn++)
  3031. {
  3032. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[44+Rtn]);
  3033. }
  3034. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3035. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3036. for(Rtn=0; Rtn<8; Rtn++)
  3037. {
  3038. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[50+Rtn]);
  3039. }
  3040. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3041. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3042. for(Rtn=0; Rtn<8; Rtn++)
  3043. {
  3044. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[58+Rtn]);
  3045. }
  3046. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3047. }
  3048. #endif
  3049. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3050. {
  3051. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][RX]CM_SLAC_MATCH_REQ");
  3052. //Check ODA (Destination Address)
  3053. if (Array_Compare_Identity(CsuMac, MmePacket->ODA, SLAC_EVSE_MAC_LENGTH) == FALSE)
  3054. {
  3055. SAVE_SYS_LOG_MSG_EVCOMM("[CM_SLAC_MATCH_REQ]wrong ODA: ignore");
  3056. //break; //patch for DEKRA I2SE EVCC (another EVSE MAC Address protection comes as below.)
  3057. }
  3058. EvMac_in = &MmePacket->OSA[0];
  3059. RunID_in = &MmePacket->MMENTRY[50];
  3060. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  3061. if (idx >= 0)
  3062. {
  3063. Update_V2G_Flow_Status(CM_SLAC_MATCH_REQ);
  3064. SLAC_INFO.array[idx].MatchReqNum++;
  3065. sprintf((char*)buf_log_evcomm,
  3066. "CM_SLAC_MATCH_REQ[%d]:%d-th",
  3067. (idx + 1),
  3068. SLAC_INFO.array[idx].MatchReqNum);
  3069. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3070. //[TC_SECC_VTB_CmSlacMatch_007] APPLICATION_TYPE must be 0x00(EV-EVSE Matching)
  3071. //[TC_SECC_VTB_CmSlacMatch_008]
  3072. if (MmePacket->MMENTRY[0] != 0)
  3073. {
  3074. sprintf((char*)buf_log_evcomm,
  3075. "CM_SLAC_MATCH_REQ[%d]:wrong APPLICATION_TYPE(%d)",
  3076. (idx + 1),
  3077. MmePacket->MMENTRY[0]);
  3078. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3079. break;
  3080. }
  3081. //[TC_SECC_VTB_CmSlacMatch_009] SECURITY_TYPE must be 0x00(No Security)
  3082. //[TC_SECC_VTB_CmSlacMatch_010]
  3083. if (MmePacket->MMENTRY[1] != 0)
  3084. {
  3085. sprintf((char*)buf_log_evcomm,
  3086. "CM_SLAC_MATCH_REQ[%d]:wrong SECURITY_TYPE(%d)",
  3087. (idx + 1),
  3088. MmePacket->MMENTRY[1]);
  3089. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3090. break;
  3091. }
  3092. //[TC_SECC_VTB_CmSlacMatch_011] MVFLength must be 0x3E(MatchVarField Length)
  3093. //[TC_SECC_VTB_CmSlacMatch_012]
  3094. if (MmePacket->MMENTRY[2] != 0x3E || MmePacket->MMENTRY[3] != 0x00)
  3095. {
  3096. sprintf((char*)buf_log_evcomm,
  3097. "CM_SLAC_MATCH_REQ[%d]:wrong MVFLength(%d,%d)",
  3098. (idx + 1),
  3099. MmePacket->MMENTRY[2],
  3100. MmePacket->MMENTRY[3]);
  3101. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3102. break;
  3103. }
  3104. //[TC_SECC_VTB_CmSlacMatch_013] EV ID (muxt be all zero)
  3105. //[TC_SECC_VTB_CmSlacMatch_014]
  3106. if (Array_Check_All_Zero(&MmePacket->MMENTRY[4], 17) == FALSE)
  3107. {
  3108. sprintf((char*)buf_log_evcomm,
  3109. "CM_SLAC_MATCH_REQ[%d]: wrong EV ID",
  3110. (idx + 1));
  3111. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3112. break;
  3113. }
  3114. //[TC_SECC_VTB_CmSlacMatch_015] EV MAC
  3115. //[TC_SECC_VTB_CmSlacMatch_016]
  3116. if (Array_Compare_Identity(EvMac_in, &MmePacket->MMENTRY[21], SLAC_EVMAC_LENGTH) == FALSE)
  3117. {
  3118. sprintf((char*)buf_log_evcomm,
  3119. "CM_SLAC_MATCH_REQ[%d]: wrong EV MAC(%02X:%02X:%02X:%02X:%02X:%02X)",
  3120. (idx + 1),
  3121. MmePacket->MMENTRY[21], MmePacket->MMENTRY[22], MmePacket->MMENTRY[23],
  3122. MmePacket->MMENTRY[24], MmePacket->MMENTRY[25], MmePacket->MMENTRY[26]);
  3123. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3124. break;
  3125. }
  3126. //[TC_SECC_VTB_CmSlacMatch_017] EVSE ID should be all zero
  3127. //[TC_SECC_VTB_CmSlacMatch_018]
  3128. if (Array_Check_All_Zero(&MmePacket->MMENTRY[27], 17) == FALSE)
  3129. {
  3130. sprintf((char*)buf_log_evcomm,
  3131. "CM_SLAC_MATCH_REQ[%d]: wrong EVSE ID",
  3132. (idx + 1));
  3133. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3134. break;
  3135. }
  3136. //[TC_SECC_VTB_CmSlacMatch_019] EVSE MAC
  3137. //[TC_SECC_VTB_CmSlacMatch_020]
  3138. if (Array_Compare_Identity(CsuMac, &MmePacket->MMENTRY[44], SLAC_EVSE_MAC_LENGTH) == FALSE)
  3139. {
  3140. sprintf((char*)buf_log_evcomm,
  3141. "CM_SLAC_MATCH_REQ[%d]: wrong EVSE MAC(%02X:%02X:%02X:%02X:%02X:%02X)",
  3142. (idx + 1),
  3143. MmePacket->MMENTRY[44], MmePacket->MMENTRY[45], MmePacket->MMENTRY[46],
  3144. MmePacket->MMENTRY[47], MmePacket->MMENTRY[48], MmePacket->MMENTRY[49]);
  3145. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3146. break;
  3147. }
  3148. //[TC_SECC_VTB_CmSlacMatch_021]runID: Check RunID
  3149. //[TC_SECC_VTB_CmSlacMatch_022]
  3150. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE &&
  3151. (idx == 0)) //only setup a successful link establishment with the first SLAC Req instance
  3152. {
  3153. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3154. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  3155. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3156. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3157. SendMmePacket.MMV = MmePacket->MMV;
  3158. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_MATCH_CNF;
  3159. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3160. SendMmePacketSize = 0;
  3161. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //APPLICATION_TYPE: Fixed value (0x00: EV-EVSE matching)
  3162. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //SECURITY_TYPE: Fixed value (0x00: No Security)
  3163. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x56; //MVFLength: MatchVarField Length (Fixed value: 0x0056)
  3164. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //MVFLength: MatchVarField Length (Fixed value: 0x0056)
  3165. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //EV ID
  3166. SendMmePacketSize += 17;
  3167. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac_in, SLAC_EVMAC_LENGTH); //EV MAC
  3168. SendMmePacketSize += 6;
  3169. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //EVSE ID
  3170. SendMmePacketSize += 17;
  3171. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, CsuMac, 6); //EVSE MAC
  3172. SendMmePacketSize += 6;
  3173. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, RunID_in, SLAC_RUNID_LENGTH);
  3174. SendMmePacketSize += SLAC_RUNID_LENGTH;
  3175. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 8); //RSVD
  3176. SendMmePacketSize += 8;
  3177. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, Nid, sizeof(Nid)); //NID: Network ID given by the CCo(EVSE)
  3178. SendMmePacketSize += sizeof(Nid); //NID caculated from the random NMK that will be set.
  3179. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //RSVD
  3180. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, NewNmkKey, sizeof(NewNmkKey)); //NMK: Random value
  3181. SendMmePacketSize += sizeof(NewNmkKey); //NMK: Private NMK of the EVSE (random value)
  3182. SendMmePacketSize += 19; //the size before MMENTRY
  3183. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3184. {
  3185. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  3186. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3187. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3188. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3189. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3190. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3191. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3192. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3193. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3194. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_MATCH_CNF ---\n");
  3195. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3196. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3197. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3]);
  3198. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3199. for(Rtn=0; Rtn<17; Rtn++)
  3200. {
  3201. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[4+Rtn]);
  3202. }
  3203. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3204. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3205. for(Rtn=0; Rtn<6; Rtn++)
  3206. {
  3207. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[21+Rtn]);
  3208. }
  3209. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3210. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3211. for(Rtn=0; Rtn<17; Rtn++)
  3212. {
  3213. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[27+Rtn]);
  3214. }
  3215. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3216. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3217. for(Rtn=0; Rtn<6; Rtn++)
  3218. {
  3219. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[44+Rtn]);
  3220. }
  3221. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3222. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3223. for(Rtn=0; Rtn<8; Rtn++)
  3224. {
  3225. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[50+Rtn]);
  3226. }
  3227. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3228. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3229. for(Rtn=0; Rtn<8; Rtn++)
  3230. {
  3231. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[58+Rtn]);
  3232. }
  3233. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3234. DEBUG_PRINTF_EVCOMM_DETAIL("NID: \n");
  3235. for(Rtn=0; Rtn<7; Rtn++)
  3236. {
  3237. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[66+Rtn]);
  3238. }
  3239. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3240. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", SendMmePacket.MMENTRY[73]);
  3241. DEBUG_PRINTF_EVCOMM_DETAIL("NMK: \n");
  3242. for(Rtn=0; Rtn<16; Rtn++)
  3243. {
  3244. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[74+Rtn]);
  3245. }
  3246. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3247. }
  3248. #endif
  3249. Update_V2G_Flow_Status(CM_SLAC_MATCH_CNF);
  3250. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3251. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  3252. sprintf((char*)buf_log_evcomm,
  3253. "CM_SLAC_MATCH_CNF[%d]",
  3254. (idx + 1));
  3255. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3256. ftime(&SeqStartTime);
  3257. }
  3258. else
  3259. {
  3260. //RunID does not match and it's not the first SLAC request
  3261. //Reset the SLAC database to embrace SLAC retry
  3262. SAVE_SYS_LOG_MSG_EVCOMM("[CM_SLAC_MATCH_REQ]No Real MATCH_REQ\n");
  3263. SLAC_DB_Reset();
  3264. }
  3265. }
  3266. else
  3267. {
  3268. //OSA(EvMac) does not exist
  3269. }
  3270. break;
  3271. }
  3272. #else
  3273. {
  3274. Update_V2G_Flow_Status(CM_SLAC_MATCH_REQ);
  3275. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][RX]CM_SLAC_MATCH_REQ");
  3276. memset(&SendMmePacket,0,sizeof(struct MmeHeader));
  3277. memcpy(SendMmePacket.ODA,MmePacket->OSA,6);
  3278. memcpy(SendMmePacket.OSA,CsuMac,6);
  3279. SendMmePacket.MTYPE=htons(EtherType_HomePlug);
  3280. SendMmePacket.MMV=MmePacket->MMV;
  3281. SendMmePacket.MMTYPE=MMTYPE_CM_SLAC_MATCH_CNF;
  3282. SendMmePacket.FMI[0]=SendMmePacket.FMI[1]=0;
  3283. SendMmePacketSize=0;
  3284. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x00) indicating ��PEV-EVSE matching��
  3285. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x00) indicating ��No Security��
  3286. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x56; //Fixed value (0x0056) for matching
  3287. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x0056) for matching
  3288. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,17); //PEV ID
  3289. SendMmePacketSize+=17;
  3290. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,EvMac,6);
  3291. SendMmePacketSize+=6;
  3292. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,17); //EVSE ID
  3293. SendMmePacketSize+=17;
  3294. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,CsuMac,6);
  3295. SendMmePacketSize+=6;
  3296. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,SlacRunId,sizeof(SlacRunId));
  3297. SendMmePacketSize+=sizeof(SlacRunId);
  3298. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,8); //RSVD
  3299. SendMmePacketSize+=8;
  3300. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,Nid,sizeof(Nid));
  3301. SendMmePacketSize+=sizeof(Nid);
  3302. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //RSVD
  3303. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,NewNmkKey,sizeof(NewNmkKey));
  3304. SendMmePacketSize+=sizeof(NewNmkKey);
  3305. SendMmePacketSize+=19; //the size before MMENTRY
  3306. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3307. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  3308. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3309. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3310. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3311. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3312. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3313. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3314. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3315. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3316. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_MATCH_CNF ---\n");
  3317. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3318. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3319. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3]);
  3320. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3321. for(Rtn=0; Rtn<17; Rtn++)
  3322. {
  3323. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[4+Rtn]);
  3324. }
  3325. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3326. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3327. for(Rtn=0; Rtn<6; Rtn++)
  3328. {
  3329. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[21+Rtn]);
  3330. }
  3331. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3332. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3333. for(Rtn=0; Rtn<17; Rtn++)
  3334. {
  3335. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[27+Rtn]);
  3336. }
  3337. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3338. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3339. for(Rtn=0; Rtn<6; Rtn++)
  3340. {
  3341. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[44+Rtn]);
  3342. }
  3343. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3344. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3345. for(Rtn=0; Rtn<8; Rtn++)
  3346. {
  3347. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[50+Rtn]);
  3348. }
  3349. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3350. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3351. for(Rtn=0; Rtn<8; Rtn++)
  3352. {
  3353. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[58+Rtn]);
  3354. }
  3355. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3356. DEBUG_PRINTF_EVCOMM_DETAIL("NID: \n");
  3357. for(Rtn=0; Rtn<7; Rtn++)
  3358. {
  3359. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[66+Rtn]);
  3360. }
  3361. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3362. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", SendMmePacket.MMENTRY[73]);
  3363. DEBUG_PRINTF_EVCOMM_DETAIL("NMK: \n");
  3364. for(Rtn=0; Rtn<16; Rtn++)
  3365. {
  3366. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[74+Rtn]);
  3367. }
  3368. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  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. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][TX]CM_SLAC_MATCH_CNF");
  3374. ftime(&SeqStartTime);
  3375. break;
  3376. }
  3377. #endif
  3378. }
  3379. case MMTYPE_VENDOR_VS_HOST_ACTION:
  3380. {
  3381. struct QcaVendorMmeHeader *RecvPacket;
  3382. RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
  3383. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_VS_HOST_ACTION ---\n");
  3384. switch (RecvPacket->MBODY[0])
  3385. {
  3386. case 0x00:
  3387. //Loader (Device Softloader or Bootloader) ready
  3388. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Loader Ready\n");
  3389. break;
  3390. case 0x01:
  3391. //Firmware Upgrade Ready
  3392. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Firmware Upgrade Ready\n");
  3393. break;
  3394. case 0x02:
  3395. //PIB Update Ready
  3396. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: PIB Update Ready\n");
  3397. break;
  3398. case 0x03:
  3399. //Firmware Upgrade and PIB Update ready
  3400. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Firmware Upgrade and PIB Update ready\n");
  3401. break;
  3402. case 0x04:
  3403. //Loader (Bootloader) ready to receive SDRAM configuration.
  3404. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Loader ready to receive SDRAM configuration\n");
  3405. break;
  3406. case 0x05:
  3407. //Reset to Factory Defaults.
  3408. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Reset to Factory Defaults\n");
  3409. break;
  3410. default:
  3411. //Reserved
  3412. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Reserved\n");
  3413. break;
  3414. }
  3415. break;
  3416. }
  3417. case MMTYPE_VENDOR_ATTEN_CHAR:
  3418. {
  3419. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_ATTEN_CHAR ---\n");
  3420. break;
  3421. }
  3422. case MMTYPE_VENDOR_VS_NW_INFO_CNF:
  3423. {
  3424. // Only Set key for local QCA7000
  3425. if((MmePacket->OSA[0] == MmePacket->MMENTRY[12]) &&
  3426. (MmePacket->OSA[1] == MmePacket->MMENTRY[13]) &&
  3427. (MmePacket->OSA[2] == MmePacket->MMENTRY[14]) &&
  3428. (MmePacket->OSA[3] == MmePacket->MMENTRY[15]) &&
  3429. (MmePacket->OSA[4] == MmePacket->MMENTRY[16]) &&
  3430. (MmePacket->OSA[5] == MmePacket->MMENTRY[17]))
  3431. {
  3432. memcpy(QcaMac, MmePacket->OSA, 6);
  3433. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_VS_NW_INFO_CNF ---\n");
  3434. SAVE_SYS_LOG_MSG_EVCOMM("EVSE MAC address(QCA7K): %02X:%02X:%02X:%02X:%02X:%02X (comm:OK)\n",
  3435. QcaMac[0], QcaMac[1], QcaMac[2], QcaMac[3], QcaMac[4], QcaMac[5]);
  3436. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  3437. ftime(&SeqStartTime);
  3438. }
  3439. break;
  3440. }
  3441. case MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF:
  3442. {
  3443. struct QcaVendorMmeHeader *RecvPacket;
  3444. RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
  3445. if(RecvPacket->MBODY[1]==0)
  3446. {
  3447. //PLC disconnected
  3448. sprintf((char*)buf_log_evcomm,
  3449. "[MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF]Got PLC Link Status:%d",
  3450. RecvPacket->MBODY[1]);
  3451. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3452. Update_V2G_Flow_Status(Other_Fault);
  3453. }
  3454. else
  3455. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  3456. ftime(&SeqStartTime);
  3457. break;
  3458. }
  3459. default:
  3460. {
  3461. break;
  3462. }
  3463. }
  3464. return 0;
  3465. }
  3466. /*===========================================================================
  3467. FUNCTION: SlacComm
  3468. DESCRIPTION:
  3469. PRE-CONDITION:
  3470. INPUT:
  3471. OUTPUT:
  3472. GLOBAL VARIABLES:
  3473. =============================================================================*/
  3474. int SlacComm()
  3475. {
  3476. static unsigned char qca7k_comm_retry = 0;
  3477. double t_diff = 0;
  3478. int packet_size = 0;
  3479. int count = 0;
  3480. //int idx = 0;
  3481. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3482. unsigned char tmpBuf[2048]={0};
  3483. #endif
  3484. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3485. unsigned char *EvMac_in;
  3486. unsigned char *RunID_in;
  3487. int i = 0;
  3488. #endif
  3489. if(RawSock >= 0)
  3490. {
  3491. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  3492. packet_size = recvfrom(RawSock, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, 0, NULL, NULL);
  3493. if(packet_size > 0)
  3494. {
  3495. MmeProcess(V2gtpMsgRxBuf, packet_size);
  3496. }
  3497. }
  3498. switch(Check_V2G_Flow_Status())
  3499. {
  3500. case IDLE:
  3501. {
  3502. if(RawSock < 0)
  3503. {
  3504. RawSock = socket(PF_PACKET, SOCK_RAW, htons(EtherType_HomePlug));
  3505. SAVE_SYS_LOG_MSG_EVCOMM("[RawSock]opened(%d)\n", RawSock);
  3506. if(RawSock == -1)
  3507. {
  3508. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Failed to create socket");
  3509. Update_V2G_Flow_Status(Other_Fault);
  3510. return -1;
  3511. }
  3512. if (setsockopt(RawSock, SOL_SOCKET, SO_BINDTODEVICE, QcaInterface, 4) < 0)
  3513. {
  3514. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Set SO_BINDTODEVICE NG");
  3515. Update_V2G_Flow_Status(Other_Fault);
  3516. return -1;
  3517. }
  3518. struct timeval tv;
  3519. tv.tv_sec = 0;
  3520. tv.tv_usec = 100000; //100ms (Rx timeout)
  3521. if (setsockopt(RawSock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  3522. {
  3523. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Set SO_RCVTIMEO NG");
  3524. Update_V2G_Flow_Status(Other_Fault);
  3525. return -1;
  3526. }
  3527. tv.tv_usec = 100000; //100ms (Tx timeout)
  3528. if (setsockopt(RawSock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  3529. {
  3530. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Set SO_SNDTIMEO NG");
  3531. Update_V2G_Flow_Status(Other_Fault);
  3532. return -1;
  3533. }
  3534. memset(&Req, 0, sizeof(struct ifreq));
  3535. strcpy( (char*)Req.ifr_name, QcaInterface);
  3536. if (ioctl(RawSock, SIOCGIFINDEX, &Req) < 0)
  3537. {
  3538. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm: ioctl NG");
  3539. Update_V2G_Flow_Status(Other_Fault);
  3540. return -1;
  3541. }
  3542. memset( &DestSocketAddress, 0, sizeof(struct sockaddr_ll));
  3543. DestSocketAddress.sll_ifindex = Req.ifr_ifindex;
  3544. DestSocketAddress.sll_halen = ETH_ALEN;
  3545. PwmStartTime = 0;
  3546. EVCOMM_SYS_INFO.QCA7K_SetKeyDone = FALSE;
  3547. SAVE_SYS_LOG_MSG_EVCOMM("QCA7000 connecting...\n");
  3548. //Get QCA7K MAC address
  3549. GetQca7kMac();
  3550. ftime(&SeqStartTime);
  3551. break;
  3552. }
  3553. else //RawSock: opened
  3554. {
  3555. if(EVCOMM_SYS_INFO.QCA7K_SetKeyDone == FALSE)
  3556. {
  3557. ftime(&SeqEndTime);
  3558. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3559. if (t_diff > V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD) //3 secs
  3560. {
  3561. qca7k_comm_retry++;
  3562. SAVE_SYS_LOG_MSG_EVCOMM("Re-try connecting...(%.02lf/%dms)\n", t_diff, V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD);
  3563. GetQca7kMac(); //re-send req
  3564. ftime(&SeqStartTime);
  3565. break;
  3566. }
  3567. else
  3568. {}
  3569. //Retry by 3 times
  3570. if (qca7k_comm_retry >= 3)
  3571. {
  3572. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Comm: fail (retry by %d times)\n", qca7k_comm_retry);
  3573. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3574. //CCS_SECCC_TIMEOUT_QCA7000_COMM (023892): The firmware code of QCA7000 may not be installed, yet
  3575. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3576. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3577. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3578. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3579. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  3580. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  3581. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3582. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3583. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  3584. Update_V2G_Flow_Status(Sequence_Timeout);
  3585. qca7k_comm_retry = 0;
  3586. break;
  3587. }
  3588. }
  3589. else //RawSock: opened; Set Key: DONE
  3590. {
  3591. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  3592. if((CheckConnectorPlugIn() == TRUE) && (ShmInternalComm->ChargingPermission >= 1))
  3593. {
  3594. if(PwmStartTime <= 0)
  3595. {
  3596. //Sniffer_Tcpdump(ENABLE);
  3597. //#if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  3598. //sleep(1); //wait for tcpdump to be ready.
  3599. //#endif
  3600. SwitchCpStateE(DISABLE);
  3601. OutputCpPwmDuty(5);
  3602. PwmStartTime = time(NULL);
  3603. #ifdef TEST_WITH_ETH0
  3604. Update_V2G_Flow_Status(SLACC_SDP_UDP_Connection);
  3605. #endif
  3606. }
  3607. else
  3608. {
  3609. if((time(NULL) - PwmStartTime) > TT_EVSE_SLAC_init)
  3610. {
  3611. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_SLAC_PARM_REQ Timeout - TT_EVSE_SLAC_init, NowTime(%ld)-PwmStartTime(%d)>%d (sec)\n", time(NULL), PwmStartTime, TT_EVSE_SLAC_init);
  3612. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3613. //CCS_SECC_TIMEOUT_SLAC_TT_EVSE_SLAC_init (023809)
  3614. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3615. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3616. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3617. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3618. ShmStatusCodeData->PresentStatusCode[0][4] = 0;
  3619. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  3620. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  3621. Update_V2G_Flow_Status(Sequence_Timeout);
  3622. PwmStartTime = 0;
  3623. return -1;
  3624. }
  3625. else
  3626. {
  3627. //waiting for CM_SLAC_PARM_REQ
  3628. }
  3629. }
  3630. }
  3631. else
  3632. {
  3633. PwmStartTime = 0;
  3634. }
  3635. }
  3636. }
  3637. break;
  3638. }
  3639. case CM_SET_KEY_REQ: //13
  3640. {
  3641. //CM_SET_KEY_REQ
  3642. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "QCA7000 [RX]CM_SET_KEY_REQ");
  3643. ftime(&SeqEndTime);
  3644. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3645. if (t_diff > V2G_SECC_QCA7000_COMM_TIMEOUT) //10 seconds
  3646. {
  3647. SAVE_SYS_LOG_MSG_EVCOMM("QCA7000 Failed on SetKey => End_Process (%.02lf/%dms)\n", t_diff, V2G_SECC_QCA7000_COMM_TIMEOUT);
  3648. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3649. //CCS_SECCC_TIMEOUT_QCA7000_COMM (023892): The firmware code of QCA7000 may not be installed, yet
  3650. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3651. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3652. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3653. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3654. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  3655. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  3656. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3657. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3658. Update_V2G_Flow_Status(Sequence_Timeout);
  3659. }
  3660. else if (t_diff > V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD) //2 seconds
  3661. {
  3662. SAVE_SYS_LOG_MSG_EVCOMM("QCA7000 SetKey: proceed (%.02lf/%dms)\n", t_diff, V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD);
  3663. SendSetKey();
  3664. ftime(&SeqStartTime);
  3665. }
  3666. else
  3667. {
  3668. //null
  3669. }
  3670. break;
  3671. }
  3672. case CM_SET_KEY_CNF: //14
  3673. {
  3674. SAVE_SYS_LOG_MSG_EVCOMM("Wait: plugin(%d), matached(%d), permission(%d)...\n", CheckConnectorPlugIn(), CSUCOMMDC_TASK_FLAG.matched, ShmInternalComm->ChargingPermission);
  3675. EVCOMM_SYS_INFO.QCA7K_SetKeyDone = TRUE;
  3676. PwmStartTime = 0;
  3677. Update_V2G_Flow_Status(IDLE);
  3678. break;
  3679. }
  3680. case CM_SLAC_PARM_CONF:
  3681. {
  3682. ftime(&SeqEndTime);
  3683. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_sequence)
  3684. {
  3685. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_START_ATTEN_CHAR_IND Timeout - TT_match_sequence (%.02lf of %dms)\n", DiffTimeb(SeqStartTime, SeqEndTime), TT_match_sequence);
  3686. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3687. //CCS_SECC_TIMEOUT_CM_START_ATTEN_CHAR_IND (023811):
  3688. //[Possible Reason] CCS Board image might not be updated properly. The 2nd reboot process is not finished.
  3689. //[Verification Method] By tying reboot command to the terminal and see if it could be executed immediately.
  3690. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3691. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3692. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3693. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3694. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  3695. ShmStatusCodeData->PresentStatusCode[0][5] = 1;
  3696. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3697. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3698. Update_V2G_Flow_Status(Sequence_Timeout);
  3699. return -1;
  3700. }
  3701. break;
  3702. }
  3703. case CM_START_ATTEN_CHAR_IND:
  3704. {
  3705. ftime(&SeqEndTime);
  3706. if(DiffTimeb(SeqStartTime, SeqEndTime) > (TP_EV_batch_msg_interval)) //one more time interval for tolerance
  3707. {
  3708. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_MNBC_SOUND_IND Timeout - TP_EV_batch_msg_interval (%.02lf of %dms)\n", DiffTimeb(SeqStartTime, SeqEndTime), TP_EV_batch_msg_interval);
  3709. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3710. //CCS_SECC_TIMEOUT_SLAC_CM_MNBC_SOUND_IND (023818):
  3711. //[Possible Reason] CCS Board image might not be updated properly. The 2nd reboot process is not finished.
  3712. //[Verification Method] By tying reboot command to the terminal and see if it could be executed immediately.
  3713. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3714. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3715. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3716. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3717. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  3718. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  3719. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3720. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3721. Update_V2G_Flow_Status(Sequence_Timeout);
  3722. return -1;
  3723. }
  3724. break;
  3725. }
  3726. case CM_MNBC_SOUND_IND:
  3727. {
  3728. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3729. {
  3730. ftime(&SeqEndTime);
  3731. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3732. //printf("time:%.02lf, profilNum:%d\n",DiffTimeb(SeqStartTime, SeqEndTime),AttenProfileCnt); //added by Vern
  3733. if(t_diff > TT_EVSE_match_MNBC ||
  3734. (SLAC_INFO.array[0].AttenProfileCnt >= SLAC_INFO.array[0].MnbcSoundNum) ||
  3735. (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)) //TC_SECC_VTB_AttenuationCharacterization_003
  3736. {
  3737. //Wait for other SLAC Req sets
  3738. if ((SLAC_INFO.arrayLen >= 2) &&
  3739. (t_diff < TT_EVSE_match_MNBC) &&
  3740. (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry == 0)) //not a retry
  3741. {
  3742. break;
  3743. }
  3744. //Check if it is a timeup response
  3745. if (t_diff > TT_EVSE_match_MNBC)
  3746. {
  3747. SAVE_SYS_LOG_MSG_EVCOMM("[WARNING][SLAC][TX]CM_ATTEN_CHAR_IND[%d]: timeup(%.2f/%dms) => send\n", (i + 1), t_diff, TT_EVSE_match_MNBC);
  3748. }
  3749. //Sending all CM_ATTEN_CHAR_IND according to all corresponding SLAC Req sets
  3750. for (i = 0; i < SLAC_INFO.arrayLen; i++)
  3751. {
  3752. if ((SLAC_INFO.array[i].AttenProfileCnt == 0) ||
  3753. (SLAC_INFO.array[i].AagGroupsNum == 0) ||
  3754. (SLAC_INFO.array[i].StartAttenCharCnt == 0) ||
  3755. (SLAC_INFO.array[i].MnbcSoundNum != 10) || //received in CM_START_ATTEN_CHAR_IND
  3756. (SLAC_INFO.array[i].StartAttenCharErr == TRUE)
  3757. )
  3758. {
  3759. //Ignoring those SLAC request sets without sending CM_MNBC_SOUND_IND(CM_ATTEN_PROFILE_IND)
  3760. SAVE_SYS_LOG_MSG_EVCOMM("[WARNING][SLAC][TX]CM_ATTEN_CHAR_IND[%d]: para err(%d,%d,%d,%d,%d) => canceled\n",
  3761. (i + 1), SLAC_INFO.array[i].AttenProfileCnt, SLAC_INFO.array[i].AagGroupsNum, SLAC_INFO.array[i].StartAttenCharCnt, SLAC_INFO.array[i].MnbcSoundNum, SLAC_INFO.array[i].StartAttenCharErr);
  3762. continue;
  3763. }
  3764. //In CM_ATTEN_CHAR_IND retry process, here only re-send this message according to the 1st coming SLAC request
  3765. if ((EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0) && (i != 0))
  3766. {
  3767. SAVE_SYS_LOG_MSG_EVCOMM("[NOTE][SLAC][TX]CM_ATTEN_CHAR_IND[%d]: canceled\n", (i + 1));
  3768. break;
  3769. }
  3770. EvMac_in = SLAC_INFO.array[i].EvMac;
  3771. RunID_in = SLAC_INFO.array[i].RunID;
  3772. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3773. memcpy(SendMmePacket.ODA, EvMac_in, SLAC_EVMAC_LENGTH);
  3774. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3775. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3776. SendMmePacket.MMV = 0x01;
  3777. SendMmePacket.MMTYPE = MMTYPE_CM_ATTEN_CHAR_IND;
  3778. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3779. SendMmePacketSize = 0;
  3780. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00: EV-EVSE Matching)
  3781. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00: No Security)
  3782. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac_in, SLAC_EVMAC_LENGTH); //SOURCE_ADDRESS, MAC address of the EV Host
  3783. SendMmePacketSize += SLAC_EVMAC_LENGTH;
  3784. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, RunID_in, SLAC_RUNID_LENGTH);
  3785. SendMmePacketSize += SLAC_RUNID_LENGTH;
  3786. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //SOURCE_ID(0x00)
  3787. SendMmePacketSize += 17;
  3788. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //RESP_ID(0x00)
  3789. SendMmePacketSize += 17;
  3790. SendMmePacket.MMENTRY[SendMmePacketSize++] = SLAC_INFO.array[i].AttenProfileCnt; //NumSounds: Number of M-Sounds used for generation of the ATTEN_PROFILE
  3791. SendMmePacket.MMENTRY[SendMmePacketSize++] = SLAC_INFO.array[i].AagGroupsNum; //NumGroups
  3792. for(count = 0; count < SLAC_INFO.array[i].AagGroupsNum; count++)
  3793. {
  3794. unsigned char TmpAag;
  3795. TmpAag = ((SLAC_INFO.array[i].AAG[count] / SLAC_INFO.array[i].AttenProfileCnt) & 0xFF);
  3796. SLAC_INFO.array[i].AAG_quality_ori += (float) TmpAag; //original signal quality
  3797. #if (SUDO_PSD_PARAMETER_MECHANISM == ENABLE) //default: ENABLE
  3798. #if 1
  3799. //TC_SECC_VTB_AttenuationCharacterization_019
  3800. TmpAag = TmpAag >> 1; //new method proposed by Joseph (divided by 2)
  3801. #else
  3802. if(TmpAag >= 39) //original method proposed by Vern
  3803. {
  3804. TmpAag = 37;
  3805. }
  3806. #endif
  3807. #endif
  3808. SendMmePacket.MMENTRY[SendMmePacketSize++] = TmpAag;
  3809. SLAC_INFO.array[i].AAG_quality_refined += (float) TmpAag; //refined signal quality
  3810. }
  3811. SendMmePacketSize += 19; //the size before MMENTRY
  3812. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3813. {
  3814. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Send MME Packet *****\n");
  3815. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3816. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3817. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3818. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3819. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3820. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3821. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3822. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3823. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_ATTEN_CHAR_IND ---\n");
  3824. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3825. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3826. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  3827. SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5],
  3828. SendMmePacket.MMENTRY[6],SendMmePacket.MMENTRY[7]);
  3829. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  3830. SendMmePacket.MMENTRY[8],SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],
  3831. SendMmePacket.MMENTRY[12],SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14],SendMmePacket.MMENTRY[15]);
  3832. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3833. for(count=0; count<17; count++)
  3834. {
  3835. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[16+count]);
  3836. }
  3837. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: %s\n", tmpBuf);
  3838. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3839. for(count=0; count<17; count++)
  3840. {
  3841. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[33+count]);
  3842. }
  3843. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: %s\n", tmpBuf);
  3844. DEBUG_PRINTF_EVCOMM_DETAIL("NumSounds: 0x%x\n", SendMmePacket.MMENTRY[50]);
  3845. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3846. for(count=0; count<AagGroupsNum; count++)
  3847. {
  3848. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[51+count]);
  3849. }
  3850. DEBUG_PRINTF_EVCOMM_DETAIL("ATTEN_PROFILE: %s\n", tmpBuf);
  3851. }
  3852. #endif
  3853. count = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3854. SLAC_INFO.array[i].AAG_quality_ori /= SLAC_INFO.array[i].AagGroupsNum;
  3855. SLAC_INFO.array[i].AAG_quality_refined /= SLAC_INFO.array[i].AagGroupsNum;
  3856. //Print log if this CM_ATTEN_CHAR_IND belongs to RETRY Tx message.
  3857. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)
  3858. {
  3859. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][TX]CM_ATTEN_CHAR_IND[%d]: %d-th resend (Q=%.2f/%.2f)(%d/%d)\n",
  3860. (i + 1),
  3861. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry,
  3862. SLAC_INFO.array[i].AAG_quality_refined,
  3863. SLAC_INFO.array[i].AAG_quality_ori,
  3864. SLAC_INFO.array[i].AttenProfileCnt,
  3865. SLAC_INFO.array[i].MnbcSoundNum);
  3866. }
  3867. else if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry == 0)
  3868. {
  3869. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][TX]CM_ATTEN_CHAR_IND[%d]: Q=%.2f/%.2f(%d/%d)\n",
  3870. (i + 1),
  3871. SLAC_INFO.array[i].AAG_quality_refined,
  3872. SLAC_INFO.array[i].AAG_quality_ori,
  3873. SLAC_INFO.array[i].AttenProfileCnt,
  3874. SLAC_INFO.array[i].MnbcSoundNum);
  3875. }
  3876. else
  3877. {
  3878. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][TX]CM_ATTEN_CHAR_IND[%d]: unexpected CM_ATTEN_CHAR_IND_retry(%d))\n", i, EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  3879. }
  3880. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n", SendMmePacketSize,count);
  3881. } //end of for loop
  3882. Update_V2G_Flow_Status(CM_ATTEN_CHAR_IND);
  3883. ftime(&SeqStartTime);
  3884. }
  3885. break;
  3886. }
  3887. #else
  3888. {
  3889. ftime(&SeqEndTime);
  3890. //printf("time:%.02lf, profilNum:%d\n",DiffTimeb(SeqStartTime, SeqEndTime),AttenProfileCnt); //added by Vern
  3891. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_EVSE_match_MNBC || (AttenProfileCnt >= MnbcSoundNum) || (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0))
  3892. {
  3893. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3894. memcpy(SendMmePacket.ODA, EvMac, 6);
  3895. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3896. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3897. SendMmePacket.MMV = 0x01;
  3898. SendMmePacket.MMTYPE = MMTYPE_CM_ATTEN_CHAR_IND;
  3899. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3900. SendMmePacketSize = 0;
  3901. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00: EV-EVSE Matching)
  3902. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00: No Security)
  3903. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac, 6); //SOURCE_ADDRESS, MAC address of the EV Host
  3904. SendMmePacketSize += 6;
  3905. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize, SlacRunId, sizeof(SlacRunId));
  3906. SendMmePacketSize += sizeof(SlacRunId);
  3907. memset(SendMmePacket.MMENTRY+SendMmePacketSize, 0, 17); //SOURCE_ID
  3908. SendMmePacketSize += 17;
  3909. memset(SendMmePacket.MMENTRY+SendMmePacketSize, 0, 17); //RESP_ID
  3910. SendMmePacketSize += 17;
  3911. SendMmePacket.MMENTRY[SendMmePacketSize++] = AttenProfileCnt; //NumSounds
  3912. SendMmePacket.MMENTRY[SendMmePacketSize++] = AagGroupsNum; //NumGroups
  3913. for(count=0; count < AagGroupsNum; count++)
  3914. {
  3915. unsigned char TmpAag;
  3916. TmpAag = ((Aag[count] / AttenProfileCnt) & 0xFF);
  3917. #if (SUDO_PSD_PARAMETER_MECHANISM == ENABLE) //default: ENABLE
  3918. #if 1
  3919. //TC_SECC_VTB_AttenuationCharacterization_019
  3920. TmpAag = TmpAag >> 1; //new method proposed by Joseph (divided by 2)
  3921. #else
  3922. if(TmpAag >= 39) //original method proposed by Vern
  3923. {
  3924. /*
  3925. // [To-do] If this statement is enabled, SLAC will fail due to timeout.
  3926. {
  3927. unsigned char TmpBuf[64];
  3928. memset(TmpBuf,0,sizeof(TmpBuf));
  3929. sprintf((char*)TmpBuf,"SlacComm: bad Aag[%d]=%d",count,TmpAag);
  3930. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", TmpBuf);
  3931. }
  3932. */
  3933. printf("%d,", TmpAag);
  3934. TmpAag = 37;
  3935. }
  3936. #endif
  3937. #endif
  3938. SendMmePacket.MMENTRY[SendMmePacketSize++] = TmpAag;
  3939. }
  3940. SendMmePacketSize += 19; //the size before MMENTRY
  3941. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3942. {
  3943. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Send MME Packet *****\n");
  3944. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3945. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3946. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3947. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3948. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3949. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3950. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3951. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3952. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_ATTEN_CHAR_IND ---\n");
  3953. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3954. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3955. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  3956. SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5],
  3957. SendMmePacket.MMENTRY[6],SendMmePacket.MMENTRY[7]);
  3958. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  3959. SendMmePacket.MMENTRY[8],SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],
  3960. SendMmePacket.MMENTRY[12],SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14],SendMmePacket.MMENTRY[15]);
  3961. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3962. for(count=0; count<17; count++)
  3963. {
  3964. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[16+count]);
  3965. }
  3966. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: %s\n", tmpBuf);
  3967. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));;
  3968. for(count=0; count<17; count++)
  3969. {
  3970. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[33+count]);
  3971. }
  3972. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: %s\n", tmpBuf);
  3973. DEBUG_PRINTF_EVCOMM_DETAIL("NumSounds: 0x%x\n", SendMmePacket.MMENTRY[50]);
  3974. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3975. for(count=0; count<AagGroupsNum; count++)
  3976. {
  3977. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[51+count]);
  3978. }
  3979. DEBUG_PRINTF_EVCOMM_DETAIL("ATTEN_PROFILE: %s\n", tmpBuf);
  3980. }
  3981. #endif
  3982. Update_V2G_Flow_Status(CM_ATTEN_CHAR_IND);
  3983. count = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3984. //Print log if this CM_ATTEN_CHAR_IND belongs to RETRY Tx message.
  3985. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)
  3986. {
  3987. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][TX]CM_ATTEN_CHAR_IND: resend(%d-th)\n", EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  3988. }
  3989. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n", SendMmePacketSize,count);
  3990. ftime(&SeqStartTime);
  3991. }
  3992. break;
  3993. }
  3994. #endif
  3995. }
  3996. case CM_ATTEN_CHAR_IND:
  3997. {
  3998. ftime(&SeqEndTime);
  3999. //if(DiffTimeb(SeqStartTime, SeqEndTime)>TT_match_response)
  4000. 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.
  4001. {
  4002. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_ATTEN_CHAR_RSP Timeout - TT_match_response (%.02lf of %dms)\n", DiffTimeb(SeqStartTime, SeqEndTime), TT_match_response);
  4003. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4004. //CCS_SECC_TIMEOUT_SLAC_CM_ATTEN_CHAR_RSP (023814):
  4005. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4006. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4007. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4008. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4009. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4010. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4011. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  4012. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4013. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4014. Update_V2G_Flow_Status(Sequence_Timeout);
  4015. return -1;
  4016. }
  4017. break;
  4018. }
  4019. case CM_ATTEN_CHAR_RSP:
  4020. {
  4021. ftime(&SeqEndTime);
  4022. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_EVSE_match_session)
  4023. {
  4024. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_VALIDATE_REQ_1ST or CM_SLAC_MATCH_REQ Timeout - TT_EVSE_match_session (%.02lf of %dms)\n", DiffTimeb(SeqStartTime, SeqEndTime), TT_EVSE_match_session);
  4025. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4026. //CCS_SECC_TIMEOUT_SLAC_CM_VALIDATE_REQ_1ST__CM_SLAC_MATCH_REQ (023815):
  4027. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4028. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4029. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4030. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4031. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4032. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4033. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  4034. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4035. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4036. Update_V2G_Flow_Status(Sequence_Timeout);
  4037. return -1;
  4038. }
  4039. break;
  4040. }
  4041. case CM_VALIDATE_CNF:
  4042. {
  4043. ftime(&SeqEndTime);
  4044. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_sequence)
  4045. {
  4046. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_VALIDATE_REQ_2ND or CM_SLAC_MATCH_REQ Timeout - TT_match_sequence (%.02lf of %dms)\n", DiffTimeb(SeqStartTime, SeqEndTime), TT_match_sequence);
  4047. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4048. //CCS_SECC_TIMEOUT_SLAC_CM_VALIDATE_REQ_2ND__CM_SLAC_MATCH_REQ (023819):
  4049. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4050. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4051. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4052. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4053. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4054. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4055. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  4056. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4057. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4058. Update_V2G_Flow_Status(Sequence_Timeout);
  4059. return -1;
  4060. }
  4061. break;
  4062. }
  4063. case CM_SLAC_MATCH_CNF:
  4064. {
  4065. if(UdpSock > 0)
  4066. {
  4067. close(UdpSock);
  4068. UdpSock = -1;
  4069. }
  4070. if(TcpSock > 0)
  4071. {
  4072. close(TcpSock);
  4073. TcpSock = -1;
  4074. }
  4075. ftime(&SeqStartTime);
  4076. V2gTcpConnected();
  4077. Update_V2G_Flow_Status(SLACC_SDP_UDP_Connection);
  4078. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SLAAC,SDP,UDP: connecting...");
  4079. break;
  4080. }
  4081. default:
  4082. {
  4083. break;
  4084. }
  4085. }
  4086. return 0;
  4087. }
  4088. /*===========================================================================
  4089. FUNCTION: V2gMsgDecoder
  4090. DESCRIPTION:
  4091. 1. Decode the V2GTP messages inside "msg" and save the decoded
  4092. messages in ccs_exi_doc_DIN, ccs_exi_doc_ISO1, and ccs_exi_doc_ISO2,
  4093. respectively.
  4094. 2. After decoding, V2gMsg_Process() could then use
  4095. ccs_exi_doc_DIN, ccs_exi_doc_ISO1, or ccs_exi_doc_ISO2
  4096. to deal with the corresponding Response messages, respectively.
  4097. PRE-CONDITION:
  4098. 1. msg_length > 0
  4099. INPUT:
  4100. 1. msg
  4101. 2. msg_length
  4102. OUTPUT:
  4103. 1. ccs_exi_doc_DIN //global variable
  4104. ccs_exi_doc_ISO1
  4105. ccs_exi_doc_ISO2
  4106. 2. v2g_state //Status Flag
  4107. //indicating the V2gMsg_Process_din to proceed
  4108. the next process.
  4109. 3. return value // < 0: ERROR
  4110. // > 0: Message Type
  4111. GLOBAL VARIABLES:
  4112. =============================================================================*/
  4113. int V2gMsgDecoder(unsigned char *msg, unsigned int msg_length, unsigned int v2g_state)
  4114. {
  4115. int errn = 0;
  4116. //Checking the minimum Header size requirement
  4117. if(msg_length < V2GTP_MSG_HEADER_LENGTH) //The minimum requirement should be 8-byte header.
  4118. {
  4119. errn = -1;
  4120. return errn;
  4121. }
  4122. //Decode the 1st V2GMSG: AppProtocol
  4123. if(v2g_state == SupportedAppProtocolRequest) //17
  4124. {
  4125. if ((errn = API_V2GMSG_EXI_Decoder_AppProtocol(msg, msg_length, &ccs_handshake)) < 0)
  4126. {
  4127. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR = %d (DEC)]V2gMsgDecoder: SupportedAppProtocolRequest()\n", errn);
  4128. }
  4129. else //decoded successfully.
  4130. {
  4131. //PRINT_XML_DOC_supportedAppProtocolReq(&ccs_handshake);
  4132. }
  4133. }
  4134. //Decode the subsequent V2GMSG (DIN 70121, ISO 15118-2, ISO 15118-20)
  4135. else if(v2g_state > SupportedAppProtocolRequest && v2g_state <= SessionStopResponse)
  4136. {
  4137. //Decoding according to its own protocol
  4138. switch (ShmCcsData->CommProtocol)
  4139. {
  4140. case V2GT_MSG_PROTOCOL_DIN70121: //0
  4141. {
  4142. //DIN
  4143. if((errn = API_V2GMSG_EXI_Decoder_DIN(msg, msg_length, &ccs_exi_doc_DIN)) < 0)
  4144. {
  4145. sprintf((char*)buf_log_evcomm,
  4146. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_DIN()",
  4147. errn);
  4148. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4149. }
  4150. break;
  4151. }
  4152. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  4153. {
  4154. //ISO1
  4155. if((errn = API_V2GMSG_EXI_Decoder_ISO1(msg, msg_length, &ccs_exi_doc_ISO1)) < 0)
  4156. {
  4157. sprintf((char*)buf_log_evcomm,
  4158. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_ISO1()",
  4159. errn);
  4160. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4161. }
  4162. break;
  4163. }
  4164. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  4165. {
  4166. //ISO2
  4167. if((errn = API_V2GMSG_EXI_Decoder_ISO2(msg, msg_length, &ccs_exi_doc_ISO2)) < 0)
  4168. {
  4169. sprintf((char*)buf_log_evcomm,
  4170. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_ISO2()",
  4171. errn);
  4172. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4173. }
  4174. break;
  4175. }
  4176. default:
  4177. break;
  4178. }
  4179. }
  4180. else
  4181. {
  4182. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR = %d (DEC)]V2gMsgDecoder: Unexpected v2g_state\n", errn);
  4183. errn = -1;
  4184. }
  4185. return errn;
  4186. }
  4187. /*===========================================================================
  4188. FUNCTION: encode_din_V2GTP_stream
  4189. DESCRIPTION:
  4190. PRE-CONDITION:
  4191. INPUT:
  4192. OUTPUT:
  4193. GLOBAL VARIABLES:
  4194. =============================================================================*/
  4195. int encode_din_V2GTP_stream(bitstream_t *v2g_tx_stream, struct dinEXIDocument *ccs_exi_doc_DIN)
  4196. {
  4197. int errn = 0;
  4198. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4199. errn = encode_dinExiDocument(v2g_tx_stream, ccs_exi_doc_DIN);
  4200. if (errn == 0)
  4201. {
  4202. //successfully encoded
  4203. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4204. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4205. if (errn != 0)
  4206. {
  4207. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_din_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4208. }
  4209. }
  4210. else
  4211. {
  4212. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_din_V2GTP_stream]encode_dinExiDocument(): %d (DEC)\n", errn);
  4213. }
  4214. return errn;
  4215. }
  4216. /*===========================================================================
  4217. FUNCTION: encode_iso1_V2GTP_stream
  4218. DESCRIPTION:
  4219. PRE-CONDITION:
  4220. INPUT:
  4221. OUTPUT:
  4222. GLOBAL VARIABLES:
  4223. =============================================================================*/
  4224. int encode_iso1_V2GTP_stream(bitstream_t *v2g_tx_stream, struct iso1EXIDocument *ccs_exi_doc_ISO1)
  4225. {
  4226. int errn = 0;
  4227. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4228. errn = encode_iso1ExiDocument(v2g_tx_stream, ccs_exi_doc_ISO1);
  4229. if (errn == 0)
  4230. {
  4231. //successfully encoded
  4232. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4233. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4234. if (errn != 0)
  4235. {
  4236. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso1_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4237. }
  4238. }
  4239. else
  4240. {
  4241. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso1_V2GTP_stream]encode_iso1ExiDocument(): %d (DEC)\n", errn);
  4242. }
  4243. return errn;
  4244. }
  4245. /*===========================================================================
  4246. FUNCTION: encode_iso2_V2GTP_stream
  4247. DESCRIPTION:
  4248. PRE-CONDITION:
  4249. INPUT:
  4250. OUTPUT:
  4251. GLOBAL VARIABLES:
  4252. =============================================================================*/
  4253. int encode_iso2_V2GTP_stream(bitstream_t *v2g_tx_stream, struct iso2EXIDocument *ccs_exi_doc_ISO2)
  4254. {
  4255. int errn = 0;
  4256. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4257. errn = encode_iso2ExiDocument(v2g_tx_stream, ccs_exi_doc_ISO2);
  4258. if (errn == 0)
  4259. {
  4260. //successfully encoded
  4261. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4262. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4263. if (errn != 0)
  4264. {
  4265. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso2_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4266. }
  4267. }
  4268. else
  4269. {
  4270. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso2_V2GTP_stream]encode_iso2ExiDocument(): %d (DEC)\n", errn);
  4271. }
  4272. return errn;
  4273. }
  4274. /*===========================================================================
  4275. FUNCTION: send_encoded_din_V2GTP_Stream
  4276. DESCRIPTION:
  4277. PRE-CONDITION:
  4278. INPUT:
  4279. OUTPUT:
  4280. GLOBAL VARIABLES:
  4281. =============================================================================*/
  4282. int send_encoded_din_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct dinEXIDocument *ccs_exi_doc_DIN)
  4283. {
  4284. int errn = 0;
  4285. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4286. errn = encode_din_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_DIN);
  4287. // STEP 2: =========== Send Response Packet ===========
  4288. int rtn = 0;
  4289. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4290. if (rtn == v2g_tx_stream->size)
  4291. {
  4292. /*
  4293. DEBUG_PRINTF_EVCOMM_DETAIL("Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4294. rtn, v2g_tx_stream->size);
  4295. */
  4296. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4297. }
  4298. else if (rtn >= 0)
  4299. {
  4300. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]Incomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n", rtn, v2g_tx_stream->size);
  4301. }
  4302. else
  4303. {
  4304. errn = rtn;
  4305. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]send(): %d (DEC)\n", errn);
  4306. }
  4307. //STEP 3: ========= Reset V2G MSG Flags ==========
  4308. init_dinBodyType(&ccs_exi_doc_DIN->V2G_Message.Body);
  4309. return errn;
  4310. }
  4311. /*===========================================================================
  4312. FUNCTION: send_encoded_iso1_V2GTP_Stream
  4313. DESCRIPTION:
  4314. PRE-CONDITION:
  4315. INPUT:
  4316. OUTPUT:
  4317. GLOBAL VARIABLES:
  4318. =============================================================================*/
  4319. int send_encoded_iso1_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct iso1EXIDocument *ccs_exi_doc_ISO1)
  4320. {
  4321. int errn = 0;
  4322. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4323. errn = encode_iso1_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_ISO1);
  4324. // STEP 2: =========== Send Response Packet ===========
  4325. int rtn = 0;
  4326. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4327. if (rtn == v2g_tx_stream->size)
  4328. {
  4329. //DEBUG_PRINTF_EVCOMM_DETAIL("Response message sent (%d/%d)(Bytes, DEC): OK\n", rtn, v2g_tx_stream->size);
  4330. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4331. }
  4332. else if (rtn >= 0)
  4333. {
  4334. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]Incomplete Tx (%d/%d)(Bytes, DEC): FAIL\n", rtn, v2g_tx_stream->size);
  4335. }
  4336. else
  4337. {
  4338. errn = rtn;
  4339. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]send(): %d(DEC)\n", errn);
  4340. }
  4341. //STEP 3: ========= Reset V2G MSG Flags ==========
  4342. init_iso1BodyType(&ccs_exi_doc_ISO1->V2G_Message.Body);
  4343. return errn;
  4344. }
  4345. /*===========================================================================
  4346. FUNCTION: send_encoded_iso2_V2GTP_Stream
  4347. DESCRIPTION:
  4348. PRE-CONDITION:
  4349. INPUT:
  4350. OUTPUT:
  4351. GLOBAL VARIABLES:
  4352. =============================================================================*/
  4353. int send_encoded_iso2_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct iso2EXIDocument *ccs_exi_doc_ISO2)
  4354. {
  4355. int errn = 0;
  4356. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4357. errn = encode_iso2_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_ISO2);
  4358. // STEP 2: =========== Send Response Packet ===========
  4359. int rtn = 0;
  4360. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4361. if (rtn == v2g_tx_stream->size)
  4362. {
  4363. /*
  4364. DEBUG_PRINTF_EVCOMM_DETAIL("Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4365. rtn, v2g_tx_stream->size);
  4366. */
  4367. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4368. }
  4369. else if (rtn >= 0)
  4370. {
  4371. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]Incomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n",
  4372. rtn, v2g_tx_stream->size);
  4373. }
  4374. else
  4375. {
  4376. errn = rtn;
  4377. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]send(): %d (DEC)\n", errn);
  4378. }
  4379. //STEP 3: ========= Reset V2G MSG Flags ==========
  4380. init_iso2BodyType(&ccs_exi_doc_ISO2->V2G_Message.Body);
  4381. return errn;
  4382. }
  4383. /*===========================================================================
  4384. FUNCTION: Check_din_V2G_Rx_MSG_SessionID
  4385. DESCRIPTION:
  4386. PRE-CONDITION:
  4387. INPUT:
  4388. OUTPUT:
  4389. GLOBAL VARIABLES:
  4390. =============================================================================*/
  4391. int Check_din_V2G_Rx_MSG_SessionID(struct dinEXIDocument *exi_doc_DIN)
  4392. {
  4393. int i = 0;
  4394. int leng = 0;
  4395. int errn = 0;
  4396. leng = exi_doc_DIN->V2G_Message.Header.SessionID.bytesLen;
  4397. //Step 1: Check SessionID Length
  4398. if (leng != 8) //8-byte
  4399. {
  4400. sprintf((char*)buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4401. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4402. errn = -1;
  4403. }
  4404. else
  4405. {
  4406. //Step 2-1: Check SessionID content
  4407. for (i = 0; i < leng; i++)
  4408. {
  4409. if (exi_doc_DIN->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4410. {
  4411. errn = -2;
  4412. break;
  4413. }
  4414. }
  4415. }
  4416. //Step 2-2: Print Incorrect ID
  4417. if (errn == -2) //incorrect ID
  4418. {
  4419. sprintf((char*)buf_log_evcomm,
  4420. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4421. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[0],
  4422. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[1],
  4423. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[2],
  4424. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[3],
  4425. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[4],
  4426. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[5],
  4427. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[6],
  4428. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[7],
  4429. EVCOMM_SYS_INFO.SessionID[0],
  4430. EVCOMM_SYS_INFO.SessionID[1],
  4431. EVCOMM_SYS_INFO.SessionID[2],
  4432. EVCOMM_SYS_INFO.SessionID[3],
  4433. EVCOMM_SYS_INFO.SessionID[4],
  4434. EVCOMM_SYS_INFO.SessionID[5],
  4435. EVCOMM_SYS_INFO.SessionID[6],
  4436. EVCOMM_SYS_INFO.SessionID[7]
  4437. );
  4438. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4439. }
  4440. //Step 3: Correct SessionID for Res Message
  4441. if (errn != 0)
  4442. {
  4443. exi_doc_DIN->V2G_Message.Header.SessionID.bytesLen = 8;
  4444. memset(exi_doc_DIN->V2G_Message.Header.SessionID.bytes, 0, 8);
  4445. memcpy(exi_doc_DIN->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4446. }
  4447. return errn;
  4448. }
  4449. /*===========================================================================
  4450. FUNCTION: Check_iso1_V2G_Rx_MSG_SessionID
  4451. DESCRIPTION:
  4452. PRE-CONDITION:
  4453. INPUT:
  4454. OUTPUT:
  4455. GLOBAL VARIABLES:
  4456. =============================================================================*/
  4457. int Check_iso1_V2G_Rx_MSG_SessionID(struct iso1EXIDocument *exi_doc_ISO1)
  4458. {
  4459. int i = 0;
  4460. int leng = 0;
  4461. int errn = 0;
  4462. leng = exi_doc_ISO1->V2G_Message.Header.SessionID.bytesLen;
  4463. //Step 1: Check SessionID Length
  4464. if (leng != 8) //8-byte
  4465. {
  4466. sprintf((char*)buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4467. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4468. errn = -1;
  4469. }
  4470. else
  4471. {
  4472. //Step 2-1: Check SessionID content
  4473. for (i = 0; i < leng; i++)
  4474. {
  4475. if (exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4476. {
  4477. errn = -2;
  4478. break;
  4479. }
  4480. }
  4481. }
  4482. //Step 2-2: Print Incorrect ID
  4483. if (errn == -2) //incorrect ID
  4484. {
  4485. sprintf((char*)buf_log_evcomm,
  4486. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4487. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[0],
  4488. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[1],
  4489. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[2],
  4490. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[3],
  4491. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[4],
  4492. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[5],
  4493. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[6],
  4494. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[7],
  4495. EVCOMM_SYS_INFO.SessionID[0],
  4496. EVCOMM_SYS_INFO.SessionID[1],
  4497. EVCOMM_SYS_INFO.SessionID[2],
  4498. EVCOMM_SYS_INFO.SessionID[3],
  4499. EVCOMM_SYS_INFO.SessionID[4],
  4500. EVCOMM_SYS_INFO.SessionID[5],
  4501. EVCOMM_SYS_INFO.SessionID[6],
  4502. EVCOMM_SYS_INFO.SessionID[7]
  4503. );
  4504. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4505. }
  4506. //Step 3: Correct SessionID for Res Message
  4507. if (errn != 0)
  4508. {
  4509. exi_doc_ISO1->V2G_Message.Header.SessionID.bytesLen = 8;
  4510. memset(exi_doc_ISO1->V2G_Message.Header.SessionID.bytes, 0, 8);
  4511. memcpy(exi_doc_ISO1->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4512. }
  4513. return errn;
  4514. }
  4515. /*===========================================================================
  4516. FUNCTION: Check_iso2_V2G_Rx_MSG_SessionID
  4517. DESCRIPTION:
  4518. PRE-CONDITION:
  4519. INPUT:
  4520. OUTPUT:
  4521. GLOBAL VARIABLES:
  4522. =============================================================================*/
  4523. int Check_iso2_V2G_Rx_MSG_SessionID(struct iso2EXIDocument *exi_doc_ISO2)
  4524. {
  4525. int i = 0;
  4526. int leng = 0;
  4527. int errn = 0;
  4528. leng = exi_doc_ISO2->V2G_Message.Header.SessionID.bytesLen;
  4529. //Step 1: Check SessionID Length
  4530. if (leng != 8) //8-byte
  4531. {
  4532. sprintf((char*)buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4533. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4534. errn = -1;
  4535. }
  4536. else
  4537. {
  4538. //Step 2-1: Check SessionID content
  4539. for (i = 0; i < leng; i++)
  4540. {
  4541. if (exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4542. {
  4543. errn = -2;
  4544. break;
  4545. }
  4546. }
  4547. }
  4548. //Step 2-2: Print Incorrect ID
  4549. if (errn == -2) //incorrect ID
  4550. {
  4551. sprintf((char*)buf_log_evcomm,
  4552. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4553. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[0],
  4554. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[1],
  4555. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[2],
  4556. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[3],
  4557. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[4],
  4558. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[5],
  4559. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[6],
  4560. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[7],
  4561. EVCOMM_SYS_INFO.SessionID[0],
  4562. EVCOMM_SYS_INFO.SessionID[1],
  4563. EVCOMM_SYS_INFO.SessionID[2],
  4564. EVCOMM_SYS_INFO.SessionID[3],
  4565. EVCOMM_SYS_INFO.SessionID[4],
  4566. EVCOMM_SYS_INFO.SessionID[5],
  4567. EVCOMM_SYS_INFO.SessionID[6],
  4568. EVCOMM_SYS_INFO.SessionID[7]
  4569. );
  4570. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4571. }
  4572. //Step 3: Correct SessionID for Res Message
  4573. if (errn != 0)
  4574. {
  4575. exi_doc_ISO2->V2G_Message.Header.SessionID.bytesLen = 8;
  4576. memset(exi_doc_ISO2->V2G_Message.Header.SessionID.bytes, 0, 8);
  4577. memcpy(exi_doc_ISO2->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4578. }
  4579. return errn;
  4580. }
  4581. /*===========================================================================
  4582. FUNCTION: GetSchemaID_of_Protocol
  4583. DESCRIPTION:
  4584. 1. Get the SchemaID accroding to the input target
  4585. *V2GT_MSG_PROTOCOL_DIN70121: choose DIN 70121
  4586. *V2GT_MSG_PROTOCOL_ISO15118_2014: choose ISO 15118-2 (ed1)
  4587. *V2GT_MSG_PROTOCOL_ISO15118_2018: choose ISO 15118-20 (ed2)
  4588. *V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY: choose the one with the highest priority
  4589. 2. [To-do] Checking Major and Minor version
  4590. 3. The parsing method will not support those private protocols,
  4591. such as "usr:tesla...," since "tesla" is 5 bytes but "din" and "iso" are 3 bytes.
  4592. 4. [To-do] If the target is selected as DIN," but there is no DIN.
  4593. However, if EV and EVSE all support ISO, how to use ISO instead?
  4594. PRE-CONDITION:
  4595. INPUT:
  4596. 1. target: target protocol
  4597. OUTPUT:
  4598. 1. id: SchemaID of selected protocol by EVSE
  4599. 2. ShmCcsData->CommProtocol (selected protocol)
  4600. 3. SupportedAppProtocol_result
  4601. (1) appHandresponseCodeType_OK_SuccessfulNegotiation = 0,
  4602. (2) appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation = 1,
  4603. (3) appHandresponseCodeType_Failed_NoNegotiation = 2
  4604. GLOBAL VARIABLES:
  4605. 1. ccs_handshake
  4606. 2. ShmCcsData
  4607. =============================================================================*/
  4608. int GetSchemaID_of_Protocol(unsigned char target)
  4609. {
  4610. int i = 0;
  4611. int ii = 0;
  4612. int id = 0;
  4613. //unsigned char tmp = 0;
  4614. unsigned char pri = 20; //priority = 1(highest)~20(lowerest)
  4615. char num[10];
  4616. //struct CCS_ProtocolNamespacestructCharacters pro;
  4617. //Choose the 1st protocol as default.
  4618. //id = CCS_HANDSHAKE_PROTOCOLS.array[0].SchemaID;
  4619. id = -1;
  4620. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4621. for(i = 0; i < CCS_HANDSHAKE_PROTOCOLS.arrayLen; i++)
  4622. {
  4623. //Checking for <ProtocolNamespace>urn:din:70121:2012:MsgDef</ProtocolNamespace>
  4624. //[To-Do] Ignoring the priority from EV and force DIN 70121 as our only option. (for temp)
  4625. //[CAUTION] The parsing method will not support those private protocols, such as "usr:tesla..."
  4626. num[0] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[8];
  4627. num[1] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[9];
  4628. num[2] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[10];
  4629. num[3] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[11];
  4630. num[4] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[12];
  4631. num[5] = '\0';
  4632. if (atoi(num) == 70121)
  4633. {
  4634. sprintf((char*)buf_log_evcomm,
  4635. "supported(%d-th/%d): DIN 70121(%d:v%d.%d;id=%d,pri=%d)",
  4636. (i+1),
  4637. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4638. atoi(num),
  4639. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4640. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4641. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4642. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4643. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4644. if (target == V2GT_MSG_PROTOCOL_DIN70121)
  4645. {
  4646. sprintf((char*)buf_log_evcomm,
  4647. "selected(%d-th/%d): DIN 70121(%d:v%d.%d;id=%d,pri=%d)",
  4648. (i+1),
  4649. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4650. atoi(num),
  4651. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4652. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4653. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4654. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4655. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4656. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == DIN_SPEC_70121_2012_VersionNumberMajor)
  4657. {
  4658. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == DIN_SPEC_70121_2012_VersionNumberMinor)
  4659. {
  4660. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4661. }
  4662. else
  4663. { //[TC_SECC_VTB_SupportedAppProtocol_005]
  4664. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4665. }
  4666. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4667. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4668. return id;
  4669. }
  4670. else
  4671. {
  4672. //keep looking for the suitable protocol
  4673. }
  4674. }
  4675. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4676. {
  4677. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4678. {
  4679. ii = i;
  4680. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4681. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4682. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4683. }
  4684. else
  4685. {
  4686. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  4687. }
  4688. }
  4689. else
  4690. {
  4691. //null
  4692. }
  4693. }
  4694. else if (atoi(num) == 15118)
  4695. {
  4696. //urn:din:70121:2012:MsgDef
  4697. //urn:iso:15118:2:2013:MsgDef
  4698. memset(num, 0, sizeof(num));
  4699. num[0] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[16];
  4700. num[1] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[17];
  4701. num[2] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[18];
  4702. num[3] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[19];
  4703. num[4] = '\0';
  4704. if (atoi(num) < 2018 && atoi(num) >= 2010)
  4705. {
  4706. sprintf((char*)buf_log_evcomm,
  4707. "supported(%d-th/%d): ISO 15118-2(ed1,%d:v%d.%d;id=%d,pri=%d)",
  4708. (i+1),
  4709. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4710. atoi(num),
  4711. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4712. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4713. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4714. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4715. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4716. if (target == V2GT_MSG_PROTOCOL_ISO15118_2014)
  4717. {
  4718. sprintf((char*)buf_log_evcomm,
  4719. "selected(%d-th/%d): ISO 15118-2,ed1(%d:v%d.%d;id=%d,pri=%d)",
  4720. (i+1),
  4721. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4722. atoi(num),
  4723. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4724. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4725. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4726. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4727. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4728. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == ISO1_15118_2013_VersionNumberMajor)
  4729. {
  4730. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == ISO1_15118_2013_VersionNumberMinor)
  4731. {
  4732. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4733. }
  4734. else
  4735. {
  4736. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4737. }
  4738. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4739. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2014;
  4740. return id;
  4741. }
  4742. else
  4743. {
  4744. //keep looking for the suitable protocol
  4745. }
  4746. }
  4747. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4748. {
  4749. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4750. {
  4751. ii = i;
  4752. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4753. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4754. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2014;
  4755. }
  4756. else
  4757. {
  4758. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  4759. }
  4760. }
  4761. else
  4762. {
  4763. //null
  4764. }
  4765. }
  4766. else if (atoi(num) >= 2018 && atoi(num) <= 2100) // >= 2018
  4767. {
  4768. sprintf((char*)buf_log_evcomm,
  4769. "supported(%d-th/%d): ISO 15118-20(ed2,%d:v%d.%d;id=%d,pri=%d)",
  4770. (i+1),
  4771. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4772. atoi(num),
  4773. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4774. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4775. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4776. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4777. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4778. if (target == V2GT_MSG_PROTOCOL_ISO15118_2018)
  4779. {
  4780. sprintf((char*)buf_log_evcomm,
  4781. "selected(%d-th/%d): ISO 15118-20,ed2(%d:v%d.%d;id=%d,pri=%d)",
  4782. (i+1),
  4783. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4784. atoi(num),
  4785. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4786. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4787. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4788. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4789. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4790. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == ISO2_15118_2018_VersionNumberMajor)
  4791. {
  4792. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == ISO2_15118_2018_VersionNumberMinor)
  4793. {
  4794. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4795. }
  4796. else
  4797. {
  4798. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4799. }
  4800. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4801. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2018;
  4802. return id;
  4803. }
  4804. else
  4805. {
  4806. //keep looking for the suitable protocol
  4807. }
  4808. }
  4809. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4810. {
  4811. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4812. {
  4813. ii = i;
  4814. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4815. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4816. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2018;
  4817. }
  4818. else
  4819. {
  4820. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  4821. }
  4822. }
  4823. else
  4824. {
  4825. //null
  4826. }
  4827. }
  4828. else
  4829. {
  4830. //Unexpected Year
  4831. sprintf((char*)buf_log_evcomm,
  4832. "unsupported(%d-th/%d): ISO 15118-X(unexpected year:%d,v%d.%d),id=%d,pri=%d",
  4833. (i+1),
  4834. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4835. atoi(num),
  4836. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4837. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4838. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4839. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4840. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4841. //return -1;
  4842. }
  4843. }
  4844. else
  4845. {
  4846. sprintf((char*)buf_log_evcomm,
  4847. "unsupported protocol(%d-th/%d)(%d:v%d.%d;id=%d,pri=%d)",
  4848. (i+1),
  4849. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4850. atoi(num),
  4851. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4852. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4853. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4854. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4855. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4856. //return -1;
  4857. }
  4858. }
  4859. //The final result of highest priority protocol
  4860. sprintf((char*)buf_log_evcomm,
  4861. "selected(%d-th/%d): pro=%d(0:DIN,1:ISO1,2:ISO2);id=%d,pri=%d",
  4862. (ii+1),
  4863. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4864. ShmCcsData->CommProtocol,
  4865. id,
  4866. pri);
  4867. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4868. if (id < 0)
  4869. {
  4870. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_Failed_NoNegotiation;
  4871. }
  4872. return id;
  4873. }
  4874. /*===========================================================================
  4875. FUNCTION: Proc_supportedAppProtocolRes
  4876. DESCRIPTION:
  4877. PRE-CONDITION:
  4878. INPUT:
  4879. OUTPUT:
  4880. GLOBAL VARIABLES:
  4881. =============================================================================*/
  4882. int Proc_supportedAppProtocolRes(int AcceptFd)
  4883. {
  4884. int errn = 0;
  4885. bitstream_t v2g_tx_stream;
  4886. static struct ChargingInfoData *sys;
  4887. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  4888. //STEP 1: =========== Setting the Response Message ===========
  4889. init_appHandEXIDocument(&ccs_handshake);
  4890. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4891. ccs_handshake.supportedAppProtocolRes_isUsed = 1u;
  4892. //select the 1st one as the default
  4893. ccs_handshake.supportedAppProtocolRes.SchemaID = CCS_HANDSHAKE_PROTOCOLS.array[0].SchemaID;
  4894. ccs_handshake.supportedAppProtocolRes.SchemaID_isUsed = 1u;
  4895. int id = 0;
  4896. /*+++ 20200808, vern, support both DIN and ISO +++*/
  4897. //id = GetSchemaID_of_Protocol(V2GT_MSG_PROTOCOL_PREFERENCE); //output: EVCOMM_SYS_INFO.SupportedAppProtocol_result
  4898. id = GetSchemaID_of_Protocol(V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY); //output: EVCOMM_SYS_INFO.SupportedAppProtocol_result
  4899. /*--- 20200808, vern, support both DIN and ISO ---*/
  4900. ccs_handshake.supportedAppProtocolRes.ResponseCode = EVCOMM_SYS_INFO.SupportedAppProtocol_result; //updating the response code
  4901. if (id < 0)
  4902. {
  4903. sprintf((char*)buf_log_evcomm,
  4904. "[Error]No avalible CCS protocol (id = %d, preference = %d)",
  4905. id,
  4906. V2GT_MSG_PROTOCOL_PREFERENCE);
  4907. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4908. }
  4909. else
  4910. {
  4911. //selected SchemaID
  4912. ccs_handshake.supportedAppProtocolRes.SchemaID = (unsigned char) id;
  4913. }
  4914. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  4915. {
  4916. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_supportedAppProtocolRes]EVSE_Shutdown => End_Process");
  4917. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  4918. errn = -1;
  4919. }
  4920. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  4921. {
  4922. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_supportedAppProtocolRes]EVSE_EmergencyShutdown => End_Process");
  4923. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  4924. errn = -1;
  4925. }
  4926. else
  4927. {
  4928. //null
  4929. }
  4930. //Check for Permission Changing from TRUE to FALSE
  4931. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  4932. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  4933. ShmInternalComm->ChargingPermission == FALSE)
  4934. {
  4935. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][supportedAppProtocolRes]Permission OFF");
  4936. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  4937. //errn = -1;
  4938. }
  4939. #if (CP_PROTECTION_MECHANISM == ENABLE)
  4940. {
  4941. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  4942. {
  4943. //Detect for CP State should be 9V with 5% PWM or 100%PWM (State B1, B2)
  4944. if (sys->CpState != 2 && sys->CpState != 3) //State B1, B2
  4945. {
  4946. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  4947. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4948. Update_V2G_Flow_Status(Other_Fault);
  4949. sprintf((char*)buf_log_evcomm,
  4950. "[Proc_supportedAppProtocolRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  4951. sys->CpState,
  4952. sys->CpVoltage);
  4953. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4954. }
  4955. }
  4956. #else
  4957. {
  4958. //Detect for CP State should be 9V (State B)
  4959. if (sys->CpState != 3) //B2
  4960. {
  4961. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  4962. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4963. Update_V2G_Flow_Status(Other_Fault);
  4964. sprintf((char*)buf_log_evcomm,
  4965. "[Proc_supportedAppProtocolRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  4966. sys->CpState,
  4967. sys->CpVoltage);
  4968. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4969. }
  4970. }
  4971. #endif
  4972. }
  4973. #endif
  4974. //STEP 2: =========== Encode into EXI ===========
  4975. if ((errn = API_V2GMSG_EXI_Encoder_AppProtocol(&ccs_handshake, &v2g_tx_stream)) !=0)
  4976. {
  4977. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Error]API_V2GMSG_EXI_Encoder_AppProtocol\n");
  4978. return errn;
  4979. }
  4980. //STEP 3: =========== Send Response Packet ===========
  4981. int Rtn = 0;
  4982. Rtn = send(AcceptFd, v2g_tx_stream.data, v2g_tx_stream.size, 0);
  4983. //Rtn = send(6, v2g_tx_stream.data, v2g_tx_stream.size, 0);
  4984. DEBUG_PRINTF_EVCOMM_DETAIL("Send V2GTP Packet Size = %d, Rtn = %d (Bytes, DEC)\n", v2g_tx_stream.size, Rtn);
  4985. if (Rtn < 0)
  4986. {
  4987. return Rtn;
  4988. }
  4989. //STEP 4: =========== Save into Share Memory =========
  4990. //[Joseph, To-Do] Adding a mechanism to choose DIN 70121 as our 1st priority. (for multiple protocols)
  4991. //STEP 5: =========== Updating the Flow State Flag =========
  4992. if (id < 0)
  4993. {
  4994. errn = -1;
  4995. }
  4996. //STEP 6: =========== Reset Flags ============
  4997. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4998. init_appHandEXIDocument(&ccs_handshake);
  4999. return errn;
  5000. }
  5001. /*===========================================================================
  5002. FUNCTION: Proc_supportedAppProtocolReq
  5003. DESCRIPTION:
  5004. PRE-CONDITION:
  5005. INPUT:
  5006. OUTPUT:
  5007. GLOBAL VARIABLES:
  5008. =============================================================================*/
  5009. int Proc_supportedAppProtocolReq(int AcceptFd)
  5010. {
  5011. //[Joseph, To-Do] analysis on Req message and choose the prefered protocol
  5012. //Default: DIN 70121 (find SchemaID)
  5013. int errn = 0;
  5014. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]supportedAppProtocolReq\n");
  5015. SHM_Save_din_supportedAppProtocolReq(ShmCcsData, &ccs_handshake, ShmSysConfigAndInfo);
  5016. errn = Proc_supportedAppProtocolRes(AcceptFd);
  5017. if (errn == 0)
  5018. {
  5019. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]supportedAppProtocolRes\n");
  5020. }
  5021. else
  5022. {
  5023. DEBUG_PRINTF_EVCOMM_DETAIL("[Error]Proc_supportedAppProtocolRes(): %d (DEC)\n", errn);
  5024. }
  5025. return errn;
  5026. }
  5027. /*===========================================================================
  5028. FUNCTION: Proc_din_SessionSetupRes
  5029. DESCRIPTION:
  5030. PRE-CONDITION:
  5031. INPUT:
  5032. OUTPUT:
  5033. GLOBAL VARIABLES:
  5034. =============================================================================*/
  5035. int Proc_din_SessionSetupRes(int AcceptFd)
  5036. {
  5037. //int i = 0;
  5038. int errn = 0;
  5039. bitstream_t v2g_tx_stream;
  5040. static struct ChargingInfoData *sys;
  5041. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5042. size_t pos = 0;
  5043. v2g_tx_stream.pos = &pos;
  5044. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5045. v2g_tx_stream.data = V2GTP_Tx_buf;
  5046. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5047. init_dinSessionSetupResType(&ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes);
  5048. // ====== [BODY (1/2) ResponseCode ======
  5049. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5050. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_OK_NewSessionEstablished;
  5051. //[HEADER] Assign Res SessionID
  5052. ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytesLen = 8;
  5053. memset(ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytes, 0, 8);
  5054. memcpy(ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5055. //Check for SequenceError
  5056. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5057. {
  5058. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError;
  5059. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5060. errn = -1;
  5061. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5062. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5063. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5064. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5065. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5066. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5067. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5068. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5069. }
  5070. //#if PARAMETER_NORMAL_MODE == ENABLE
  5071. //SHM_Read_din_V2GMSG_Header(&ccs_exi_doc_DIN, ShmCcsData);
  5072. //#endif
  5073. //Detect for CP State should be 9V (State B)
  5074. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5075. {
  5076. #if CP_PROTECTION_MECHANISM == ENABLE
  5077. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5078. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5079. Update_V2G_Flow_Status(Other_Fault);
  5080. errn = -1;
  5081. sprintf((char*)buf_log_evcomm,
  5082. "[Proc_din_SessionSetupRes]Emergency Stop by CP Error (%d)\n",
  5083. sys->CpState);
  5084. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5085. #else
  5086. sprintf((char*)buf_log_evcomm,
  5087. "[Proc_din_SessionSetupRes]Emergency Stop by CP Error (%d): ignored\n",
  5088. sys->CpState);
  5089. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5090. #endif
  5091. }
  5092. //Check for shutdown commands from EVSE(DC Main Board)
  5093. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5094. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5095. {
  5096. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5097. sprintf((char*)buf_log_evcomm, "[Proc_din_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5098. EVSE_Shutdown,
  5099. EVSE_EmergencyShutdown,
  5100. sys->DC_EVSEStatus);
  5101. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5102. errn = -1;
  5103. }
  5104. //Check for Permission Changing from TRUE to FALSE
  5105. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5106. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5107. ShmInternalComm->ChargingPermission == FALSE)
  5108. {
  5109. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][SessionSetupRes]Permission OFF");
  5110. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5111. errn = -1;
  5112. }
  5113. // ====== [BODY (2/3) EVSEID ======
  5114. //EVSEID = all zero
  5115. memset(ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytes, 0, sizeof(ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytes));
  5116. //vern, should be encode by SN
  5117. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytesLen = 1; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5118. // ====== [BODY (3/3) DateTimeNow ======
  5119. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.DateTimeNow_isUsed = 1u;
  5120. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.DateTimeNow = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5121. #if PARAMETER_NORMAL_MODE == ENABLE
  5122. ///////////SHM_Read_din_SessionSetupRes(&ccs_exi_doc_DIN, ShmCcsData);
  5123. #endif
  5124. // ============ Encode and Send Response Message ===========
  5125. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5126. {
  5127. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_SessionSetupRes][Error]Tx encoded msg error");
  5128. errn = -1;
  5129. }
  5130. return errn;
  5131. }
  5132. /*===========================================================================
  5133. FUNCTION: Proc_iso1_SessionSetupRes
  5134. DESCRIPTION:
  5135. PRE-CONDITION:
  5136. INPUT:
  5137. OUTPUT:
  5138. GLOBAL VARIABLES:
  5139. =============================================================================*/
  5140. int Proc_iso1_SessionSetupRes(int AcceptFd)
  5141. {
  5142. //int i = 0;
  5143. int errn = 0;
  5144. bitstream_t v2g_tx_stream;
  5145. static struct ChargingInfoData *sys;
  5146. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5147. size_t pos = 0;
  5148. v2g_tx_stream.pos = &pos;
  5149. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5150. v2g_tx_stream.data = V2GTP_Tx_buf;
  5151. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5152. init_iso1SessionSetupResType(&ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes);
  5153. // ====== [BODY (1/2) ResponseCode ======
  5154. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5155. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_OK_NewSessionEstablished;
  5156. //[HEADER] Assign Res SessionID
  5157. ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytesLen = 8;
  5158. memset(ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytes, 0, 8);
  5159. memcpy(ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5160. //Check for SequenceError
  5161. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5162. {
  5163. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5164. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5165. errn = -1;
  5166. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5167. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5168. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5169. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5170. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5171. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5172. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5173. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5174. }
  5175. //#if PARAMETER_NORMAL_MODE == ENABLE
  5176. //SHM_Read_iso1_V2GMSG_Header(&ccs_exi_doc_ISO1, ShmCcsData);
  5177. //#endif
  5178. //Detect for CP State should be 9V (State B)
  5179. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5180. {
  5181. #if CP_PROTECTION_MECHANISM == ENABLE
  5182. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5183. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5184. Update_V2G_Flow_Status(Other_Fault);
  5185. errn = -1;
  5186. sprintf((char*)buf_log_evcomm,
  5187. "[Proc_iso1_SessionSetupRes]Emergency Stop by CP Error (%d)\n",
  5188. sys->CpState);
  5189. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5190. #else
  5191. sprintf((char*)buf_log_evcomm,
  5192. "[Proc_iso1_SessionSetupRes]Emergency Stop by CP Error (%d): ignored\n",
  5193. sys->CpState);
  5194. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5195. #endif
  5196. }
  5197. //Check for shutdown commands from EVSE(DC Main Board)
  5198. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5199. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5200. {
  5201. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5202. sprintf((char*)buf_log_evcomm, "[Proc_iso1_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5203. EVSE_Shutdown,
  5204. EVSE_EmergencyShutdown,
  5205. sys->DC_EVSEStatus);
  5206. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5207. errn = -1;
  5208. }
  5209. //Check for Permission Changing from TRUE to FALSE
  5210. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  5211. ShmInternalComm->ChargingPermission == FALSE)
  5212. {
  5213. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][SessionSetupRes]Permission OFF");
  5214. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5215. errn = -1;
  5216. }
  5217. // ====== [BODY (2/3) EVSEID ======
  5218. //EVSEID = all zero
  5219. memset(ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters, 0, sizeof(ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters));
  5220. /*+++ 20200808, vern, set default EVSEID +++*/
  5221. //vern, should be encoded by SN
  5222. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[0]='Z';
  5223. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[1]='Z';
  5224. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[2]='0';
  5225. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[3]='0';
  5226. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[4]='0';
  5227. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[5]='0';
  5228. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[6]='0';
  5229. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 7; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5230. /*--- 20200808, vern, set default EVSEID ---*/
  5231. // ====== [BODY (3/3) DateTimeNow ======
  5232. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  5233. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSETimeStamp = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5234. #if PARAMETER_NORMAL_MODE == ENABLE
  5235. ///////////SHM_Read_iso1_SessionSetupRes(&ccs_exi_doc_ISO1, ShmCcsData);
  5236. #endif
  5237. // ============ Encode and Send Response Message ===========
  5238. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  5239. {
  5240. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_SessionSetupRes][Error]Tx encoded msg error");
  5241. errn = -1;
  5242. }
  5243. return errn;
  5244. }
  5245. /*===========================================================================
  5246. FUNCTION: Proc_iso2_SessionSetupRes
  5247. DESCRIPTION:
  5248. PRE-CONDITION:
  5249. INPUT:
  5250. OUTPUT:
  5251. GLOBAL VARIABLES:
  5252. =============================================================================*/
  5253. int Proc_iso2_SessionSetupRes(int AcceptFd)
  5254. {
  5255. //int i = 0;
  5256. int errn = 0;
  5257. bitstream_t v2g_tx_stream;
  5258. static struct ChargingInfoData *sys;
  5259. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5260. size_t pos = 0;
  5261. v2g_tx_stream.pos = &pos;
  5262. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5263. v2g_tx_stream.data = V2GTP_Tx_buf;
  5264. init_iso2BodyType(&ccs_exi_doc_ISO2.V2G_Message.Body);
  5265. init_iso2SessionSetupResType(&ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes);
  5266. // ====== [BODY (1/2) ResponseCode ======
  5267. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5268. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_OK_NewSessionEstablished;
  5269. //[HEADER] Assign Res SessionID
  5270. ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytesLen = 8;
  5271. memset(ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytes, 0, 8);
  5272. memcpy(ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5273. //Check for SequenceError
  5274. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5275. {
  5276. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5277. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5278. errn = -1;
  5279. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5280. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5281. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5282. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5283. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5284. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5285. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5286. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5287. }
  5288. //#if PARAMETER_NORMAL_MODE == ENABLE
  5289. //SHM_Read_iso2_V2GMSG_Header(&ccs_exi_doc_ISO2, ShmCcsData);
  5290. //#endif
  5291. //Detect for CP State should be 9V (State B)
  5292. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5293. {
  5294. #if CP_PROTECTION_MECHANISM == ENABLE
  5295. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5296. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5297. Update_V2G_Flow_Status(Other_Fault);
  5298. errn = -1;
  5299. sprintf((char*)buf_log_evcomm,
  5300. "[Proc_iso2_SessionSetupRes]Emergency Stop by CP Error (%d)",
  5301. sys->CpState);
  5302. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5303. #else
  5304. sprintf((char*)buf_log_evcomm,
  5305. "[Proc_iso2_SessionSetupRes]Emergency Stop by CP Error (%d): ignored",
  5306. sys->CpState);
  5307. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5308. #endif
  5309. }
  5310. //Check for shutdown commands from EVSE(DC Main Board)
  5311. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5312. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5313. {
  5314. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5315. sprintf((char*)buf_log_evcomm, "[Proc_iso2_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5316. EVSE_Shutdown,
  5317. EVSE_EmergencyShutdown,
  5318. sys->DC_EVSEStatus);
  5319. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5320. errn = -1;
  5321. }
  5322. //Check for Permission Changing from TRUE to FALSE
  5323. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5324. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5325. ShmInternalComm->ChargingPermission == FALSE)
  5326. {
  5327. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][ISO2][SessionSetupRes]Permission OFF");
  5328. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5329. errn = -1;
  5330. }
  5331. // ====== [BODY (2/3) EVSEID ======
  5332. //EVSEID = all zero
  5333. memset(ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.characters, 0, sizeof(ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.characters));
  5334. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 15; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5335. // ====== [BODY (3/3) DateTimeNow ======
  5336. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  5337. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSETimeStamp = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5338. #if PARAMETER_NORMAL_MODE == ENABLE
  5339. ///////////SHM_Read_iso2_SessionSetupRes(&ccs_exi_doc_ISO2, ShmCcsData);
  5340. #endif
  5341. // ============ Encode and Send Response Message ===========
  5342. if (send_encoded_iso2_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO2) != 0)
  5343. {
  5344. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso2_SessionSetupRes][Error]Tx encoded msg error");
  5345. errn = -1;
  5346. }
  5347. return errn;
  5348. }
  5349. /*===========================================================================
  5350. FUNCTION: Proc_din_SessionSetupReq
  5351. DESCRIPTION:
  5352. PRE-CONDITION:
  5353. INPUT:
  5354. OUTPUT:
  5355. GLOBAL VARIABLES:
  5356. 2. ccs_exi_doc_DIN
  5357. =============================================================================*/
  5358. int Proc_din_SessionSetupReq(int AcceptFd)
  5359. {
  5360. int errn = 0;
  5361. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]SessionSetupReq\n");
  5362. //Print the decoded XML Document
  5363. PRINT_XML_DOC_DIN_SessionSetupReq(&ccs_exi_doc_DIN);
  5364. //Save into Share Memory
  5365. SHM_Save_din_SessionSetupReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  5366. errn = Proc_din_SessionSetupRes(AcceptFd);
  5367. if (errn == 0)
  5368. {
  5369. //successfully send response.
  5370. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]SessionSetupRes\n");
  5371. }
  5372. else
  5373. {
  5374. sprintf((char*)buf_log_evcomm,
  5375. "[Error]Proc_din_SessionSetupRes(): %d (DEC)",
  5376. errn);
  5377. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5378. }
  5379. return errn;
  5380. }
  5381. /*===========================================================================
  5382. FUNCTION: Proc_iso1_SessionSetupReq
  5383. DESCRIPTION:
  5384. PRE-CONDITION:
  5385. INPUT:
  5386. OUTPUT:
  5387. GLOBAL VARIABLES:
  5388. 2. ccs_exi_doc_ISO1
  5389. =============================================================================*/
  5390. int Proc_iso1_SessionSetupReq(int AcceptFd)
  5391. {
  5392. int errn = 0;
  5393. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]SessionSetupReq\n");
  5394. //Print the decoded XML Document
  5395. PRINT_XML_DOC_ISO1_SessionSetupReq(&ccs_exi_doc_ISO1);
  5396. //Save into Share Memory
  5397. SHM_Save_iso1_SessionSetupReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  5398. errn = Proc_iso1_SessionSetupRes(AcceptFd);
  5399. if (errn == 0)
  5400. {
  5401. //successfully send response.
  5402. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionSetupRes");
  5403. }
  5404. else
  5405. {
  5406. sprintf((char*)buf_log_evcomm,
  5407. "[Error]Proc_iso1_SessionSetupRes(): %d (DEC)",
  5408. errn);
  5409. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5410. }
  5411. return errn;
  5412. }
  5413. /*===========================================================================
  5414. FUNCTION: Proc_iso2_SessionSetupReq
  5415. DESCRIPTION:
  5416. PRE-CONDITION:
  5417. INPUT:
  5418. OUTPUT:
  5419. GLOBAL VARIABLES:
  5420. 2. ccs_exi_doc_ISO2
  5421. =============================================================================*/
  5422. int Proc_iso2_SessionSetupReq(int AcceptFd)
  5423. {
  5424. int errn = 0;
  5425. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]SessionSetupReq\n");
  5426. //Print the decoded XML Document
  5427. PRINT_XML_DOC_ISO2_SessionSetupReq(&ccs_exi_doc_ISO2);
  5428. //Save into Share Memory
  5429. SHM_Save_iso2_SessionSetupReq(ShmCcsData, &ccs_exi_doc_ISO2, ShmSysConfigAndInfo);
  5430. errn = Proc_iso2_SessionSetupRes(AcceptFd);
  5431. if (errn == 0)
  5432. {
  5433. //successfully send response.
  5434. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionSetupRes");
  5435. }
  5436. else
  5437. {
  5438. sprintf((char*)buf_log_evcomm,
  5439. "[Error]Proc_iso2_SessionSetupRes(): %d (DEC)",
  5440. errn);
  5441. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5442. }
  5443. return errn;
  5444. }
  5445. /*===========================================================================
  5446. FUNCTION: Proc_din_ServiceDiscoveryRes
  5447. DESCRIPTION:
  5448. PRE-CONDITION:
  5449. INPUT:
  5450. OUTPUT:
  5451. GLOBAL VARIABLES:
  5452. =============================================================================*/
  5453. int Proc_din_ServiceDiscoveryRes(int AcceptFd)
  5454. {
  5455. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5456. //if it is not the same, the packet should be ignored.
  5457. //int i = 0;
  5458. int errn = 0;
  5459. bitstream_t v2g_tx_stream;
  5460. struct ChargingInfoData *sys;
  5461. //struct ServiceDiscoveryRequest_DIN70121 *req;
  5462. struct ServiceDiscoveryResponse_DIN70121 *res;
  5463. size_t pos = 0;
  5464. v2g_tx_stream.pos = &pos;
  5465. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5466. v2g_tx_stream.data = V2GTP_Tx_buf;
  5467. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5468. //req = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryRequest;
  5469. res = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryResponse;
  5470. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5471. init_dinServiceDiscoveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes);
  5472. //[1/4] Response Code
  5473. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
  5474. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_OK;
  5475. //[HEADER] Check Req SessionID
  5476. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  5477. {
  5478. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  5479. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  5480. errn = -1;
  5481. }
  5482. //Check for SequenceError
  5483. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5484. {
  5485. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  5486. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5487. errn = -1;
  5488. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5489. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5490. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5491. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5492. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5493. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5494. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5495. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5496. }
  5497. //Detect for CP State should be 9V (State B)
  5498. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5499. {
  5500. #if CP_PROTECTION_MECHANISM == ENABLE
  5501. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5502. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5503. Update_V2G_Flow_Status(Other_Fault);
  5504. errn = -1;
  5505. sprintf((char*)buf_log_evcomm, "[Proc_din_ServiceDiscoveryRes]Emergency Stop by CP Error (%d)", sys->CpState);
  5506. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5507. #else
  5508. sprintf((char*)buf_log_evcomm,
  5509. "[Proc_din_ServiceDiscoveryRes]Emergency Stop by CP Error (%d): ignored",
  5510. sys->CpState);
  5511. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5512. #endif
  5513. }
  5514. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5515. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5516. {
  5517. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5518. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_ServiceDiscoveryRes]shutdown by EVSE");
  5519. errn = -1;
  5520. }
  5521. //Check for Permission Changing from TRUE to FALSE
  5522. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5523. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5524. ShmInternalComm->ChargingPermission == FALSE)
  5525. {
  5526. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][ServiceDiscoveryRes]Permission OFF");
  5527. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5528. errn = -1;
  5529. }
  5530. //[2/4] PaymentOptions
  5531. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.arrayLen = 1u;
  5532. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.array[0] = dinpaymentOptionType_ExternalPayment; //1
  5533. //[3/4] Charge Service
  5534. res->ChargeService_DIN70121.Services.ServiceTag.ServiceID = 1;
  5535. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceID = (unsigned short) res->ChargeService_DIN70121.Services.ServiceTag.ServiceID;
  5536. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceCategory = dinserviceCategoryType_EVCharging;
  5537. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.FreeService = 1; //[Joseph] for test
  5538. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.EnergyTransferType = dinEVSESupportedEnergyTransferType_DC_extended;
  5539. //[4/4] Service List (null, not be uesed for now.)
  5540. //#if PARAMETER_NORMAL_MODE == ENABLE
  5541. ///////////////SHM_Read_din_ServiceDiscoveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  5542. //#endif
  5543. // ============ Encode and Send Response Message ===========
  5544. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5545. {
  5546. errn = -1;
  5547. }
  5548. return errn;
  5549. }
  5550. /*===========================================================================
  5551. FUNCTION: Proc_iso1_ServiceDiscoveryRes
  5552. DESCRIPTION:
  5553. PRE-CONDITION:
  5554. INPUT:
  5555. OUTPUT:
  5556. GLOBAL VARIABLES:
  5557. =============================================================================*/
  5558. int Proc_iso1_ServiceDiscoveryRes(int AcceptFd)
  5559. {
  5560. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5561. //if it is not the same, the packet should be ignored.
  5562. //int i = 0;
  5563. int errn = 0;
  5564. bitstream_t v2g_tx_stream;
  5565. struct ChargingInfoData *sys;
  5566. //struct ServiceDiscoveryRequest_ISO15118_2014 *req;
  5567. struct ServiceDiscoveryResponse_ISO15118_2014 *res;
  5568. size_t pos = 0;
  5569. v2g_tx_stream.pos = &pos;
  5570. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5571. v2g_tx_stream.data = V2GTP_Tx_buf;
  5572. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5573. //req = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryRequest;
  5574. res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryResponse;
  5575. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5576. init_iso1ServiceDiscoveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes);
  5577. //[1/4] Response Code
  5578. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
  5579. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_OK;
  5580. //[HEADER] Check Req SessionID
  5581. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  5582. {
  5583. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  5584. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  5585. errn = -1;
  5586. }
  5587. //Check for SequenceError
  5588. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5589. {
  5590. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5591. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5592. errn = -1;
  5593. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5594. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5595. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5596. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5597. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5598. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5599. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5600. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5601. }
  5602. //Detect for CP State should be 9V (State B)
  5603. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5604. {
  5605. #if CP_PROTECTION_MECHANISM == ENABLE
  5606. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5607. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5608. Update_V2G_Flow_Status(Other_Fault);
  5609. errn = -1;
  5610. sprintf((char*)buf_log_evcomm,
  5611. "[Proc_iso1_ServiceDiscoveryRes]Emergency Stop by CP Error (%d)",
  5612. sys->CpState);
  5613. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5614. #else
  5615. sprintf((char*)buf_log_evcomm,
  5616. "[Proc_iso1_ServiceDiscoveryRes]Emergency Stop by CP Error (%d): ignored",
  5617. sys->CpState);
  5618. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5619. #endif
  5620. }
  5621. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5622. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5623. {
  5624. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5625. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ServiceDiscoveryRes]shutdown by EVSE");
  5626. errn = -1;
  5627. }
  5628. //Check for Permission Changing from TRUE to FALSE
  5629. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5630. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5631. ShmInternalComm->ChargingPermission == FALSE)
  5632. {
  5633. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][ServiceDiscoveryRes]Permission OFF");
  5634. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5635. errn = -1;
  5636. }
  5637. //[2/4] PaymentOptionList
  5638. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.arrayLen = 1u;
  5639. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.array[0] = iso1paymentOptionType_ExternalPayment; //1
  5640. //[3/4] Charge Service
  5641. res->ChargeService.Services.ServiceID = 1;
  5642. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceID = (unsigned short) res->ChargeService.Services.ServiceID;
  5643. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName_isUsed = 1; //new in ISO1, not be used, yet.
  5644. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName.charactersLen = xxx;
  5645. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName.characters[i] = xxx;
  5646. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceCategory = iso1serviceCategoryType_EVCharging;
  5647. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.FreeService = 1; //[Joseph] for test
  5648. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.arrayLen = 1u; // max = 6
  5649. switch (ShmCcsData->EnergyTransferMode)
  5650. {
  5651. case DC_extended:
  5652. {
  5653. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_DC_extended;
  5654. break;
  5655. }
  5656. case AC_single_phase_core:
  5657. {
  5658. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_AC_single_phase_core;
  5659. break;
  5660. }
  5661. case AC_three_phase_core:
  5662. {
  5663. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_AC_three_phase_core;
  5664. break;
  5665. }
  5666. default:
  5667. {
  5668. SAVE_SYS_LOG_MSG_EVCOMM("[Warning]unexpected EnergyTransferMode(%d)\n", ShmCcsData->EnergyTransferMode);
  5669. break;
  5670. }
  5671. }
  5672. //[4/4] Service List (null, not be uesed for now.)
  5673. //#if PARAMETER_NORMAL_MODE == ENABLE
  5674. ///////////////SHM_Read_iso1_ServiceDiscoveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  5675. //#endif
  5676. // ============ Encode and Send Response Message ===========
  5677. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  5678. {
  5679. errn = -1;
  5680. }
  5681. return errn;
  5682. }
  5683. /*===========================================================================
  5684. FUNCTION: Proc_din_ServiceDiscoveryReq
  5685. DESCRIPTION:
  5686. PRE-CONDITION:
  5687. INPUT:
  5688. OUTPUT:
  5689. GLOBAL VARIABLES:
  5690. =============================================================================*/
  5691. int Proc_din_ServiceDiscoveryReq(int AcceptFd)
  5692. {
  5693. int errn = 0;
  5694. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]ServiceDiscoveryReq\n");
  5695. //Print the decoded XML Document
  5696. PRINT_XML_DOC_DIN_ServiceDiscoveryReq(&ccs_exi_doc_DIN);
  5697. //Save into Share Memory
  5698. SHM_Save_din_ServiceDiscoveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  5699. errn = Proc_din_ServiceDiscoveryRes(AcceptFd);
  5700. if (errn == 0)
  5701. {
  5702. //send response successfully.
  5703. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]ServiceDiscoveryRes");
  5704. }
  5705. else
  5706. {
  5707. sprintf((char*)buf_log_evcomm,
  5708. "[Error]Proc_din_ServiceDiscoveryRes(): %d (DEC)",
  5709. errn
  5710. );
  5711. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5712. }
  5713. return errn;
  5714. }
  5715. /*===========================================================================
  5716. FUNCTION: Proc_iso1_ServiceDiscoveryReq
  5717. DESCRIPTION:
  5718. PRE-CONDITION:
  5719. INPUT:
  5720. OUTPUT:
  5721. GLOBAL VARIABLES:
  5722. =============================================================================*/
  5723. int Proc_iso1_ServiceDiscoveryReq(int AcceptFd)
  5724. {
  5725. int errn = 0;
  5726. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]ServiceDiscoveryReq\n");
  5727. //Print the decoded XML Document
  5728. PRINT_XML_DOC_ISO1_ServiceDiscoveryReq(&ccs_exi_doc_ISO1);
  5729. //Save into Share Memory
  5730. SHM_Save_iso1_ServiceDiscoveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  5731. errn = Proc_iso1_ServiceDiscoveryRes(AcceptFd);
  5732. if (errn == 0)
  5733. {
  5734. //send response successfully.
  5735. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ServiceDiscoveryRes\n");
  5736. }
  5737. else
  5738. {
  5739. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Proc_iso1_ServiceDiscoveryRes(): %d (DEC)\n", errn);
  5740. }
  5741. return errn;
  5742. }
  5743. /*===========================================================================
  5744. FUNCTION: Proc_din_ServiceAndPaymentSelectionRes
  5745. DESCRIPTION:
  5746. PRE-CONDITION:
  5747. INPUT:
  5748. OUTPUT:
  5749. GLOBAL VARIABLES:
  5750. =============================================================================*/
  5751. int Proc_din_ServiceAndPaymentSelectionRes(int AcceptFd)
  5752. {
  5753. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5754. //if it is not the same, the packet should be ignored.
  5755. //int i = 0;
  5756. int errn = 0;
  5757. bitstream_t v2g_tx_stream;
  5758. struct ServiceAndPaymentSelectionRequest_DIN70121 *req;
  5759. //struct ServiceAndPaymentSelectionResponse_DIN70121 *res;
  5760. struct ServiceDiscoveryResponse_DIN70121 *sd_res;
  5761. struct ChargingInfoData *sys;
  5762. size_t pos = 0;
  5763. v2g_tx_stream.pos = &pos;
  5764. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5765. v2g_tx_stream.data = V2GTP_Tx_buf;
  5766. req = &ShmCcsData->V2GMessage_DIN70121.ServiceAndPaymentSelectionRequest;
  5767. //res = &ShmCcsData->V2GMessage_DIN70121.ServiceAndPaymentSelectionResponse;
  5768. sd_res = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryResponse;
  5769. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5770. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5771. init_dinServicePaymentSelectionResType(&ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes);
  5772. //[1/1] Response Code
  5773. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes_isUsed = 1u;
  5774. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_OK;
  5775. //[HEADER] Check Req SessionID
  5776. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  5777. {
  5778. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  5779. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  5780. errn = -1;
  5781. }
  5782. //Check for SequenceError
  5783. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5784. {
  5785. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  5786. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5787. errn = -1;
  5788. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5789. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5790. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5791. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5792. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5793. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5794. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5795. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5796. }
  5797. //Check for SelectedPaymentOption (TC_SECC_VTB_ServicePaymentSelection_007)
  5798. if (req->SelectedPaymentOption != ExternalPayment) //1
  5799. {
  5800. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_PaymentSelectionInvalid;
  5801. sprintf((char*)buf_log_evcomm,
  5802. "[ERROR]unexpected SelectedPaymentOption(%d) => End_Process (EIM only, no PnC, yet.)",
  5803. req->SelectedPaymentOption);
  5804. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5805. errn = -1;
  5806. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5807. //CCS_SECC_ResponseCode_FAILED_Payment SelectionInvalid (023762)
  5808. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5809. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5810. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5811. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5812. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  5813. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  5814. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5815. }
  5816. //Check for ServiceID (TC_SECC_VTB_ServicePaymentSelection_004)
  5817. if (req->SelectedServiceList.SelectedService[0].ServiceID != sd_res->ChargeService_DIN70121.Services.ServiceTag.ServiceID)
  5818. {
  5819. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_ServiceSelectionInvalid; //8
  5820. sprintf((char*)buf_log_evcomm,
  5821. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  5822. req->SelectedServiceList.SelectedService[0].ServiceID);
  5823. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5824. errn = -1;
  5825. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5826. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  5827. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5828. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5829. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5830. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5831. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  5832. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  5833. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5834. }
  5835. //Detect for CP State should be 9V (State B)
  5836. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5837. {
  5838. #if CP_PROTECTION_MECHANISM == ENABLE
  5839. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  5840. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5841. Update_V2G_Flow_Status(Other_Fault);
  5842. errn = -1;
  5843. sprintf((char*)buf_log_evcomm,
  5844. "Emergency Stop by CP Error (%d)",
  5845. sys->CpState);
  5846. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5847. #else
  5848. sprintf((char*)buf_log_evcomm,
  5849. "Emergency Stop by CP Error (%d): ignored due to function is disabled",
  5850. sys->CpState);
  5851. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5852. #endif
  5853. }
  5854. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5855. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5856. {
  5857. SAVE_SYS_LOG_MSG_EVCOMM("shutdown by EVSE\n");
  5858. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  5859. errn = -1;
  5860. }
  5861. //Check for Permission Changing from TRUE to FALSE
  5862. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5863. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5864. ShmInternalComm->ChargingPermission == FALSE)
  5865. {
  5866. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Permission OFF\n");
  5867. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  5868. errn = -1;
  5869. }
  5870. // ============ Encode and Send Response Message ===========
  5871. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5872. {
  5873. SAVE_SYS_LOG_MSG_EVCOMM("Tx encoded msg error\n");
  5874. errn = -1;
  5875. }
  5876. return errn;
  5877. }
  5878. /*===========================================================================
  5879. FUNCTION: Proc_iso1_ServiceAndPaymentSelectionRes
  5880. DESCRIPTION:
  5881. PRE-CONDITION:
  5882. INPUT:
  5883. OUTPUT:
  5884. GLOBAL VARIABLES:
  5885. =============================================================================*/
  5886. int Proc_iso1_ServiceAndPaymentSelectionRes(int AcceptFd)
  5887. {
  5888. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5889. //if it is not the same, the packet should be ignored.
  5890. //int i = 0;
  5891. int errn = 0;
  5892. bitstream_t v2g_tx_stream;
  5893. struct ServiceAndPaymentSelectionRequest_ISO15118_2014 *req;
  5894. //struct ServiceAndPaymentSelectionResponse_ISO15118_2014 *res;
  5895. struct ServiceDiscoveryResponse_ISO15118_2014 *sd_res;
  5896. static struct ChargingInfoData *sys;
  5897. size_t pos = 0;
  5898. v2g_tx_stream.pos = &pos;
  5899. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5900. v2g_tx_stream.data = V2GTP_Tx_buf;
  5901. req = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceAndPaymentSelectionRequest;
  5902. //res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceAndPaymentSelectionResponse;
  5903. sd_res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryResponse;
  5904. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5905. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5906. init_iso1PaymentServiceSelectionResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes);
  5907. //[1/1] Response Code
  5908. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes_isUsed = 1u;
  5909. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_OK;
  5910. //[HEADER] Check Req SessionID
  5911. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  5912. {
  5913. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  5914. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  5915. errn = -1;
  5916. }
  5917. //Check for SequenceError
  5918. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5919. {
  5920. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5921. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5922. errn = -1;
  5923. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5924. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5925. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5926. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5927. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5928. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5929. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5930. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5931. }
  5932. //Check for SelectedPaymentOption (TC_SECC_VTB_ServicePaymentSelection_007)
  5933. if (req->SelectedPaymentOption != ExternalPayment) //1
  5934. {
  5935. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_PaymentSelectionInvalid;
  5936. sprintf((char*)buf_log_evcomm,
  5937. "[ERROR]unexpected SelectedPaymentOption(%d) => End_Process (EIM only, no PnC, yet.)",
  5938. req->SelectedPaymentOption);
  5939. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5940. errn = -1;
  5941. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5942. //CCS_SECC_ResponseCode_FAILED_Payment SelectionInvalid (023762)
  5943. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5944. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5945. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5946. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5947. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  5948. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  5949. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5950. }
  5951. //Check for ServiceID (TC_SECC_VTB_ServicePaymentSelection_004)
  5952. if (req->SelectedServiceList.SelectedService[0].ServiceID != sd_res->ChargeService.Services.ServiceID)
  5953. {
  5954. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_ServiceSelectionInvalid; //8
  5955. sprintf((char*)buf_log_evcomm,
  5956. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  5957. req->SelectedServiceList.SelectedService[0].ServiceID);
  5958. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5959. errn = -1;
  5960. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5961. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  5962. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5963. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5964. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5965. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5966. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  5967. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  5968. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5969. }
  5970. //Detect for CP State should be 9V (State B)
  5971. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5972. {
  5973. #if CP_PROTECTION_MECHANISM == ENABLE
  5974. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  5975. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5976. Update_V2G_Flow_Status(Other_Fault);
  5977. errn = -1;
  5978. sprintf((char*)buf_log_evcomm,
  5979. "Emergency Stop by CP Error (%d)",
  5980. sys->CpState);
  5981. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5982. #else
  5983. sprintf((char*)buf_log_evcomm,
  5984. "Emergency Stop by CP Error (%d): ignored due to function is disabled",
  5985. sys->CpState);
  5986. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5987. #endif
  5988. }
  5989. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5990. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5991. {
  5992. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ServiceAndPaymentSelectionRes]shutdown by EVSE\n");
  5993. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  5994. errn = -1;
  5995. }
  5996. //Check for Permission Changing from TRUE to FALSE
  5997. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5998. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5999. ShmInternalComm->ChargingPermission == FALSE)
  6000. {
  6001. SAVE_SYS_LOG_MSG_EVCOMM("[Error][PaymentServiceSelectionRes]Permission OFF\n");
  6002. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  6003. errn = -1;
  6004. }
  6005. // ============ Encode and Send Response Message ===========
  6006. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  6007. {
  6008. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ServiceAndPaymentSelectionRes]Tx encoded msg error");
  6009. errn = -1;
  6010. }
  6011. return errn;
  6012. }
  6013. /*===========================================================================
  6014. FUNCTION: Proc_din_ServiceAndPaymentSelectionReq
  6015. DESCRIPTION:
  6016. PRE-CONDITION:
  6017. INPUT:
  6018. OUTPUT:
  6019. GLOBAL VARIABLES:
  6020. =============================================================================*/
  6021. int Proc_din_ServiceAndPaymentSelectionReq(int AcceptFd)
  6022. {
  6023. int errn = 0;
  6024. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]ServiceAndPaymentSelectionReq");
  6025. //Print the decoded XML Document
  6026. PRINT_XML_DOC_DIN_ServiceAndPaymentSelectionReq(&ccs_exi_doc_DIN);
  6027. //Save into Share Memory
  6028. SHM_Save_din_ServiceAndPaymentSelectionReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  6029. errn = Proc_din_ServiceAndPaymentSelectionRes(AcceptFd);
  6030. if (errn == 0)
  6031. {
  6032. //send response successfully.
  6033. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ServiceAndPaymentSelectionRes\n");
  6034. }
  6035. else
  6036. {
  6037. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_ServiceAndPaymentSelectionReq]Proc_iso1_ServiceAndPaymentSelectionRes(): %d (DEC)\n", errn);
  6038. }
  6039. return errn;
  6040. }
  6041. /*===========================================================================
  6042. FUNCTION: Proc_iso1_ServiceAndPaymentSelectionReq
  6043. DESCRIPTION:
  6044. PRE-CONDITION:
  6045. INPUT:
  6046. OUTPUT:
  6047. GLOBAL VARIABLES:
  6048. =============================================================================*/
  6049. int Proc_iso1_ServiceAndPaymentSelectionReq(int AcceptFd)
  6050. {
  6051. int errn = 0;
  6052. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]ServiceAndPaymentSelectionReq\n");
  6053. //Print the decoded XML Document
  6054. PRINT_XML_DOC_ISO1_ServiceAndPaymentSelectionReq(&ccs_exi_doc_ISO1);
  6055. //Save into Share Memory
  6056. SHM_Save_iso1_ServiceAndPaymentSelectionReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  6057. errn = Proc_iso1_ServiceAndPaymentSelectionRes(AcceptFd);
  6058. if (errn == 0)
  6059. {
  6060. //send response successfully.
  6061. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ServiceAndPaymentSelectionRes.\n");
  6062. }
  6063. else
  6064. {
  6065. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Proc_iso1_ServiceAndPaymentSelectionRes(): %d (DEC)\n", errn);
  6066. }
  6067. return errn;
  6068. }
  6069. /*===========================================================================
  6070. FUNCTION: Proc_din_ContractAuthenticationRes
  6071. DESCRIPTION:
  6072. PRE-CONDITION:
  6073. INPUT:
  6074. OUTPUT:
  6075. GLOBAL VARIABLES:
  6076. =============================================================================*/
  6077. int Proc_din_ContractAuthenticationRes(int AcceptFd)
  6078. {
  6079. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6080. //if it is not the same, the packet should be ignored.
  6081. //int i = 0;
  6082. int errn = 0;
  6083. bitstream_t v2g_tx_stream;
  6084. static struct ChargingInfoData *sys;
  6085. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6086. size_t pos = 0;
  6087. v2g_tx_stream.pos = &pos;
  6088. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6089. v2g_tx_stream.data = V2GTP_Tx_buf;
  6090. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  6091. init_dinContractAuthenticationResType(&ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes);
  6092. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes_isUsed = 1u;
  6093. //[BODY (1/2)] ResponseCode
  6094. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_OK;
  6095. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Ongoing; //0
  6096. //[HEADER] Check Req SessionID
  6097. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  6098. {
  6099. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  6100. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  6101. errn = -1;
  6102. }
  6103. //Check for SequenceError
  6104. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6105. {
  6106. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  6107. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  6108. errn = -1;
  6109. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6110. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6111. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6112. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6113. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6114. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6115. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6116. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6117. }
  6118. //Detect for CP State should be 9V (State B)
  6119. #if CP_PROTECTION_MECHANISM == ENABLE
  6120. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6121. {
  6122. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6123. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6124. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6125. Update_V2G_Flow_Status(Other_Fault);
  6126. errn = -1;
  6127. sprintf((char*)buf_log_evcomm,
  6128. "Emergency Stop by CP Error (%d)",
  6129. sys->CpState);
  6130. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6131. }
  6132. #endif
  6133. //Check for CSU command of "Stop by EVSE"
  6134. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6135. {
  6136. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6137. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6138. errn = -1;
  6139. }
  6140. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6141. {
  6142. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6143. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6144. errn = -1;
  6145. }
  6146. //[BODY (2/2)] EVSEProcessing
  6147. if(ShmInternalComm->ChargingPermission == TRUE)
  6148. {
  6149. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished; //0
  6150. SAVE_SYS_LOG_MSG_EVCOMM("CSU Permission: OK\n");
  6151. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  6152. {
  6153. //Set PWM as 5% (for SLAC first case)
  6154. SAVE_SYS_LOG_MSG_EVCOMM("Set PWM as 5%%\n");
  6155. SwitchCpStateE(DISABLE);
  6156. OutputCpPwmDuty(5);
  6157. }
  6158. #endif
  6159. }
  6160. //Check for Permission Changing from TRUE to FALSE
  6161. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  6162. ShmInternalComm->ChargingPermission == FALSE)
  6163. {
  6164. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Permission OFF\n");
  6165. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6166. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6167. errn = -1;
  6168. }
  6169. #if PARAMETER_NORMAL_MODE == ENABLE
  6170. ////////////SHM_Read_din_ContractAuthenticationRes(&ccs_exi_doc_DIN, ShmCcsData);
  6171. #endif
  6172. // ============ Encode and Send Response Message ===========
  6173. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  6174. {
  6175. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Tx encoded msg error\n");
  6176. errn = -1;
  6177. }
  6178. return errn;
  6179. }
  6180. /*===========================================================================
  6181. FUNCTION: Proc_iso1_AuthorizationRes
  6182. DESCRIPTION:
  6183. PRE-CONDITION:
  6184. INPUT:
  6185. OUTPUT:
  6186. GLOBAL VARIABLES:
  6187. =============================================================================*/
  6188. int Proc_iso1_AuthorizationRes(int AcceptFd)
  6189. {
  6190. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6191. //if it is not the same, the packet should be ignored.
  6192. //int i = 0;
  6193. int errn = 0;
  6194. bitstream_t v2g_tx_stream;
  6195. static struct ChargingInfoData *sys;
  6196. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6197. size_t pos = 0;
  6198. v2g_tx_stream.pos = &pos;
  6199. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6200. v2g_tx_stream.data = V2GTP_Tx_buf;
  6201. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6202. init_iso1AuthorizationResType(&ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes);
  6203. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes_isUsed = 1u;
  6204. //[BODY (1/2)] ResponseCode
  6205. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_OK;
  6206. /*+++ 20200808, vern, EVSEProcessing should be waiting for Customer during authrization +++*/
  6207. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Ongoing_WaitingForCustomerInteraction; //0
  6208. /*--- 20200808, vern, should be waiting for Customer during authrization ---*/
  6209. //[HEADER] Check Req SessionID
  6210. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  6211. {
  6212. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  6213. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  6214. errn = -1;
  6215. }
  6216. //Check for SequenceError
  6217. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6218. {
  6219. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  6220. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  6221. errn = -1;
  6222. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6223. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6224. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6225. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6226. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6227. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6228. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6229. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6230. }
  6231. //Detect for CP State should be 9V (State B)
  6232. #if CP_PROTECTION_MECHANISM == ENABLE
  6233. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6234. {
  6235. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED;
  6236. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6237. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6238. Update_V2G_Flow_Status(Other_Fault);
  6239. errn = -1;
  6240. sprintf((char*)buf_log_evcomm,
  6241. "Emergency Stop by CP Error (%d)",
  6242. sys->CpState);
  6243. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6244. }
  6245. #endif
  6246. //Check for CSU command of "Stop by EVSE"
  6247. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6248. {
  6249. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6250. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6251. errn = -1;
  6252. }
  6253. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6254. {
  6255. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6256. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6257. errn = -1;
  6258. }
  6259. //[BODY (2/2)] EVSEProcessing
  6260. //Check for Permission from CSU
  6261. if(ShmInternalComm->ChargingPermission == TRUE)
  6262. {
  6263. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  6264. SAVE_SYS_LOG_MSG_EVCOMM("CSU Permission: OK\n");
  6265. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  6266. {
  6267. //Set PWM as 5% (for SLAC first case)
  6268. SAVE_SYS_LOG_MSG_EVCOMM("Set PWM as 5%%\n");
  6269. SwitchCpStateE(DISABLE);
  6270. OutputCpPwmDuty(5);
  6271. }
  6272. #endif
  6273. }
  6274. //Check for Permission Changing from TRUE to FALSE
  6275. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  6276. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  6277. ShmInternalComm->ChargingPermission == FALSE)
  6278. {
  6279. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Permission OFF\n");
  6280. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6281. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6282. errn = -1;
  6283. }
  6284. #if PARAMETER_NORMAL_MODE == ENABLE
  6285. ////////////SHM_Read_iso1_AuthorizationRes(&ccs_exi_doc_ISO1, ShmCcsData);
  6286. #endif
  6287. // ============ Encode and Send Response Message ===========
  6288. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  6289. {
  6290. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Tx encoded msg error\n");
  6291. errn = -1;
  6292. }
  6293. return errn;
  6294. }
  6295. /*===========================================================================
  6296. FUNCTION: Proc_din_ContractAuthenticationReq
  6297. DESCRIPTION:
  6298. PRE-CONDITION:
  6299. INPUT:
  6300. OUTPUT:
  6301. GLOBAL VARIABLES:
  6302. =============================================================================*/
  6303. int Proc_din_ContractAuthenticationReq(int AcceptFd)
  6304. {
  6305. int errn = 0;
  6306. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]Proc_din_ContractAuthenticationReq\n");
  6307. //Print the decoded XML Document
  6308. PRINT_XML_DOC_DIN_ContractAuthenticationReq(&ccs_exi_doc_DIN);
  6309. //Save into Share Memory
  6310. SHM_Save_din_ContractAuthenticationReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  6311. errn = Proc_din_ContractAuthenticationRes(AcceptFd);
  6312. if (errn == 0)
  6313. {
  6314. //send response successfully.
  6315. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ContractAuthenticationRes\n");
  6316. }
  6317. else
  6318. {
  6319. sprintf((char*)buf_log_evcomm,
  6320. "[Error]Proc_iso1_AuthenticationRes(): %d (DEC)",
  6321. errn);
  6322. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6323. }
  6324. return errn;
  6325. }
  6326. /*===========================================================================
  6327. FUNCTION: Proc_iso1_AuthenticationReq
  6328. DESCRIPTION:
  6329. PRE-CONDITION:
  6330. INPUT:
  6331. OUTPUT:
  6332. GLOBAL VARIABLES:
  6333. =============================================================================*/
  6334. int Proc_iso1_AuthenticationReq(int AcceptFd)
  6335. {
  6336. int errn = 0;
  6337. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]AuthorizationReq\n");
  6338. //Print the decoded XML Document
  6339. PRINT_XML_DOC_ISO1_AuthorizationReq(&ccs_exi_doc_ISO1);
  6340. //Save into Share Memory
  6341. SHM_Save_iso1_AuthorizationReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  6342. errn = Proc_iso1_AuthorizationRes(AcceptFd);
  6343. if (errn == 0)
  6344. {
  6345. //send response successfully.
  6346. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]AuthorizationRes\n");
  6347. }
  6348. else
  6349. {
  6350. sprintf((char*)buf_log_evcomm,
  6351. "[Error]Proc_iso1_AuthenticationRes(): %d (DEC)",
  6352. errn);
  6353. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6354. }
  6355. return errn;
  6356. }
  6357. /*===========================================================================
  6358. FUNCTION: SHM_Init_dinDC_EVSEStatusType
  6359. DESCRIPTION:
  6360. PRE-CONDITION:
  6361. INPUT:
  6362. 1. in
  6363. OUTPUT:
  6364. 2. out
  6365. GLOBAL VARIABLES:
  6366. =============================================================================*/
  6367. void SHM_Init_dinDC_EVSEStatusType(struct DC_EVSEStatusType_DIN70121 *in)
  6368. {
  6369. in->EVSEIsolationStatus = dinisolationLevelType_Valid;
  6370. // dinisolationLevelType_Invalid = 0,
  6371. // dinisolationLevelType_Valid = 1, (default)
  6372. // dinisolationLevelType_Warning = 2,
  6373. // dinisolationLevelType_Fault = 3
  6374. in->EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  6375. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6376. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1, (default)
  6377. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6378. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6379. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6380. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6381. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6382. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  6383. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  6384. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  6385. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  6386. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  6387. in->EVSENotification = dinEVSENotificationType_None;
  6388. // dinEVSENotificationType_None = 0, (default)
  6389. // dinEVSENotificationType_StopCharging = 1,
  6390. // dinEVSENotificationType_ReNegotiation = 2
  6391. }
  6392. /*===========================================================================
  6393. FUNCTION: SHM_Save_dinPhysicalValueType
  6394. DESCRIPTION:
  6395. PRE-CONDITION:
  6396. INPUT:
  6397. OUTPUT:
  6398. GLOBAL VARIABLES:
  6399. =============================================================================*/
  6400. void SHM_Save_dinPhysicalValueType(struct PhysicalValueType_DIN70121 *obj, short value, int multiplier, unsigned char unit)
  6401. {
  6402. obj->Value = value;
  6403. obj->Multiplier = multiplier;
  6404. obj->Unit =unit;
  6405. }
  6406. /*===========================================================================
  6407. FUNCTION: SHM_Init_din_ChargeParameterDiscoveryRes
  6408. DESCRIPTION:
  6409. PRE-CONDITION:
  6410. INPUT:
  6411. 1. shm_ccs
  6412. OUTPUT:
  6413. 2. shm_ccs
  6414. GLOBAL VARIABLES:
  6415. =============================================================================*/
  6416. void SHM_Init_din_ChargeParameterDiscoveryRes(struct CcsData *shm_ccs)
  6417. {
  6418. struct ChargeParameterDiscoveryResponse_DIN70121 *in;
  6419. in = &shm_ccs->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse;
  6420. //----- [BODY (1/5)] ResponseCode -----
  6421. in->ResponseCode = dinresponseCodeType_OK;
  6422. //----- [BODY (2/5)] EVSEProcessing -----
  6423. in->EVSEProcessing = dinEVSEProcessingType_Ongoing; //0
  6424. // dinEVSEProcessingType_Finished = 0,
  6425. // dinEVSEProcessingType_Ongoing = 1
  6426. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6427. //be fixed in another function.
  6428. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6429. //ignore, since DIN doesn't support AC
  6430. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6431. struct DC_EVSEChargeParameterType_DIN70121 *in_para;
  6432. in_para = &in->DC_EVSEChargeParameter;
  6433. //DC_EVSEStatus
  6434. SHM_Init_dinDC_EVSEStatusType(&in_para->DC_EVSEStatus);
  6435. in_para->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  6436. short value = 0; int multiplier = 0; unsigned char unit = 0;
  6437. //EVSEMaximumCurrentLimit
  6438. value = 600; multiplier = -1; unit = A_DIN70121; //60A
  6439. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumCurrentLimit, value, multiplier, unit);
  6440. //EVSEMaximumPowerLimit
  6441. value = 3000; multiplier = 1; unit = W_DIN70121; //30KW
  6442. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumPowerLimit, value, multiplier, unit);
  6443. //EVSEMaximumVoltageLimit
  6444. value = 7500; multiplier = -1; unit = V_DIN70121; //750V
  6445. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumVoltageLimit, value, multiplier, unit);
  6446. //EVSEMinimumVoltageLimit
  6447. value = 1500; multiplier = -1; unit = V_DIN70121; //150V
  6448. SHM_Save_dinPhysicalValueType(&in_para->EVSEMinimumVoltageLimit, value, multiplier, unit);
  6449. //EVSEMinimumCurrentLimit
  6450. value = 10; multiplier = -1; unit = A_DIN70121; //1A
  6451. SHM_Save_dinPhysicalValueType(&in_para->EVSEMinimumCurrentLimit, value, multiplier, unit);
  6452. //EVSECurrentRegulationTolerance
  6453. value = 10; multiplier = -1; unit = A_DIN70121; //1A
  6454. SHM_Save_dinPhysicalValueType(&in_para->EVSECurrentRegulationTolerance, value, multiplier, unit);
  6455. //EVSEPeakCurrentRipple
  6456. value = 2; multiplier = -1; unit = A_DIN70121; //0.2A
  6457. SHM_Save_dinPhysicalValueType(&in_para->EVSEPeakCurrentRipple, value, multiplier, unit);
  6458. //EVSEEnergyToBeDelivered (optional)
  6459. //SHM_Save_dinPhysicalValueType(&out_para->EVSEEnergyToBeDelivered, &in_para->EVSEEnergyToBeDelivered);
  6460. }
  6461. /*===========================================================================
  6462. FUNCTION: Sudo_Parameter_din_ChargeParameterDiscoveryRes
  6463. DESCRIPTION:
  6464. PRE-CONDITION:
  6465. INPUT:
  6466. OUTPUT:
  6467. GLOBAL VARIABLES:
  6468. =============================================================================*/
  6469. void Sudo_Parameter_din_ChargeParameterDiscoveryRes()
  6470. {
  6471. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  6472. init_dinChargeParameterDiscoveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes);
  6473. ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed = 1u;
  6474. //----- [BODY (1/5)] ResponseCode -----
  6475. struct dinChargeParameterDiscoveryResType *res;
  6476. res = &ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes;
  6477. res->ResponseCode = dinresponseCodeType_OK;
  6478. //----- [BODY (2/5)] EVSEProcessing -----
  6479. res->EVSEProcessing = dinEVSEProcessingType_Finished; //0
  6480. // dinEVSEProcessingType_Finished = 0,
  6481. // dinEVSEProcessingType_Ongoing = 1
  6482. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6483. res->SAScheduleList_isUsed = 1u;
  6484. struct dinSAScheduleListType *list;
  6485. list = &res->SAScheduleList;
  6486. //
  6487. list->SAScheduleTuple.arrayLen = 1;
  6488. list->SAScheduleTuple.array[0].SAScheduleTupleID = 0;
  6489. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleID = 0;
  6490. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.arrayLen = 1;
  6491. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval_isUsed = 1u;
  6492. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.start = 0;
  6493. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration = xxx
  6494. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration_isUsed = 1u;
  6495. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval_isUsed = 0u;
  6496. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval.xxx
  6497. //list->SAScheduleTuple.array[0].SalesTariff.xxx
  6498. //list->SAScheduleTuple.array[0].SalesTariff_isUsed = 0u;
  6499. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6500. //ignore, since DIN doesn't support AC
  6501. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6502. res->DC_EVSEChargeParameter_isUsed = 1u;
  6503. struct dinDC_EVSEChargeParameterType *para;
  6504. para = &res->DC_EVSEChargeParameter;
  6505. //DC_EVSEStatus
  6506. para->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  6507. para->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  6508. // dinisolationLevelType_Invalid = 0,
  6509. // dinisolationLevelType_Valid = 1,
  6510. // dinisolationLevelType_Warning = 2,
  6511. // dinisolationLevelType_Fault = 3
  6512. para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  6513. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6514. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  6515. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6516. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6517. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6518. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6519. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6520. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  6521. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  6522. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  6523. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  6524. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  6525. para->DC_EVSEStatus.NotificationMaxDelay = 0u;
  6526. para->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  6527. // dinEVSENotificationType_None = 0,
  6528. // dinEVSENotificationType_StopCharging = 1,
  6529. // dinEVSENotificationType_ReNegotiation = 2
  6530. //EVSEMaximumCurrentLimit
  6531. para->EVSEMaximumCurrentLimit.Value = 2400;
  6532. para->EVSEMaximumCurrentLimit.Multiplier = -1;
  6533. para->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  6534. para->EVSEMaximumCurrentLimit.Unit = dinunitSymbolType_A;
  6535. // dinunitSymbolType_h = 0,
  6536. // dinunitSymbolType_m = 1,
  6537. // dinunitSymbolType_s = 2,
  6538. // dinunitSymbolType_A = 3,
  6539. // dinunitSymbolType_Ah = 4,
  6540. // dinunitSymbolType_V = 5,
  6541. // dinunitSymbolType_VA = 6,
  6542. // dinunitSymbolType_W = 7,
  6543. // dinunitSymbolType_W_s = 8,
  6544. // dinunitSymbolType_Wh = 9
  6545. //EVSEMaximumPowerLimit
  6546. para->EVSEMaximumPowerLimit.Value = 6000;
  6547. para->EVSEMaximumPowerLimit.Multiplier = 1;
  6548. para->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  6549. para->EVSEMaximumPowerLimit.Unit = dinunitSymbolType_W;
  6550. //EVSEMaximumVoltageLimit
  6551. para->EVSEMaximumVoltageLimit.Value = 7500;
  6552. para->EVSEMaximumVoltageLimit.Multiplier = -1;
  6553. para->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  6554. para->EVSEMaximumVoltageLimit.Unit = dinunitSymbolType_V;
  6555. //EVSEMinimumVoltageLimit
  6556. para->EVSEMinimumVoltageLimit.Value = 1500;
  6557. para->EVSEMinimumVoltageLimit.Multiplier = -1;
  6558. para->EVSEMinimumVoltageLimit.Unit_isUsed = 1u;
  6559. para->EVSEMinimumVoltageLimit.Unit = dinunitSymbolType_V;
  6560. //EVSEMinimumCurrentLimit
  6561. para->EVSEMinimumCurrentLimit.Value = 20;
  6562. para->EVSEMinimumCurrentLimit.Multiplier = -1;
  6563. para->EVSEMinimumCurrentLimit.Unit_isUsed = 1u;
  6564. para->EVSEMinimumCurrentLimit.Unit = dinunitSymbolType_A;
  6565. //EVSECurrentRegulationTolerance_isUsed
  6566. para->EVSECurrentRegulationTolerance_isUsed = 1u;
  6567. //EVSECurrentRegulationTolerance
  6568. para->EVSECurrentRegulationTolerance.Value = 10;
  6569. para->EVSECurrentRegulationTolerance.Multiplier = -1;
  6570. para->EVSECurrentRegulationTolerance.Unit_isUsed = 1u;
  6571. para->EVSECurrentRegulationTolerance.Unit = dinunitSymbolType_A;
  6572. //EVSEEnergyToBeDelivered_isUsed
  6573. para->EVSEEnergyToBeDelivered_isUsed = 1u;
  6574. //EVSEPeakCurrentRipple
  6575. para->EVSEPeakCurrentRipple.Value = 2;
  6576. para->EVSEPeakCurrentRipple.Multiplier = -1;
  6577. para->EVSEPeakCurrentRipple.Unit_isUsed = 1u;
  6578. para->EVSEPeakCurrentRipple.Unit = dinunitSymbolType_A;
  6579. //EVSEEnergyToBeDelivered (optional)
  6580. /*
  6581. para->EVSEEnergyToBeDelivered.Value = 360;
  6582. para->EVSEEnergyToBeDelivered.Multiplier = 3;
  6583. para->EVSEEnergyToBeDelivered.Unit_isUsed = 1u;
  6584. para->EVSEEnergyToBeDelivered.Unit = dinunitSymbolType_Wh;
  6585. */
  6586. }
  6587. /*===========================================================================
  6588. FUNCTION: Sudo_Parameter_iso1_ChargeParameterDiscoveryRes
  6589. DESCRIPTION:
  6590. PRE-CONDITION:
  6591. INPUT:
  6592. OUTPUT:
  6593. GLOBAL VARIABLES:
  6594. =============================================================================*/
  6595. void Sudo_Parameter_iso1_ChargeParameterDiscoveryRes()
  6596. {
  6597. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6598. init_iso1ChargeParameterDiscoveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes);
  6599. ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed = 1u;
  6600. //----- [BODY (1/5)] ResponseCode -----
  6601. struct iso1ChargeParameterDiscoveryResType *res;
  6602. res = &ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes;
  6603. res->ResponseCode = iso1responseCodeType_OK;
  6604. //----- [BODY (2/5)] EVSEProcessing -----
  6605. res->EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  6606. // iso1EVSEProcessingType_Finished = 0,
  6607. // iso1EVSEProcessingType_Ongoing = 1
  6608. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6609. res->SAScheduleList_isUsed = 1u;
  6610. struct iso1SAScheduleListType *list;
  6611. list = &res->SAScheduleList;
  6612. //
  6613. list->SAScheduleTuple.arrayLen = 1;
  6614. list->SAScheduleTuple.array[0].SAScheduleTupleID = 0;
  6615. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.arrayLen = 1;
  6616. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval_isUsed = 1u;
  6617. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.start = 0;
  6618. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration = xxx
  6619. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration_isUsed = 1u;
  6620. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval_isUsed = 0u;
  6621. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval.xxx
  6622. //list->SAScheduleTuple.array[0].SalesTariff.xxx
  6623. //list->SAScheduleTuple.array[0].SalesTariff_isUsed = 0u;
  6624. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6625. //ignore, since our ISO1 doesn't support AC, yet
  6626. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6627. res->DC_EVSEChargeParameter_isUsed = 1u;
  6628. struct iso1DC_EVSEChargeParameterType *para;
  6629. para = &res->DC_EVSEChargeParameter;
  6630. //DC_EVSEStatus
  6631. para->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  6632. para->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  6633. // iso1isolationLevelType_Invalid = 0,
  6634. // iso1isolationLevelType_Valid = 1,
  6635. // iso1isolationLevelType_Warning = 2,
  6636. // iso1isolationLevelType_Fault = 3
  6637. para->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  6638. // iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6639. // iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  6640. // iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6641. // iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6642. // iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6643. // iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6644. // iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6645. // iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  6646. // iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  6647. // iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  6648. // iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  6649. // iso1DC_EVSEStatusCodeType_Reserved_C = 11
  6650. para->DC_EVSEStatus.NotificationMaxDelay = 0u;
  6651. para->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  6652. // iso1EVSENotificationType_None = 0,
  6653. // iso1EVSENotificationType_StopCharging = 1,
  6654. // iso1EVSENotificationType_ReNegotiation = 2
  6655. //EVSEMaximumCurrentLimit
  6656. para->EVSEMaximumCurrentLimit.Value = 2400;
  6657. para->EVSEMaximumCurrentLimit.Multiplier = -1;
  6658. //para->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  6659. para->EVSEMaximumCurrentLimit.Unit = iso1unitSymbolType_A;
  6660. //iso1unitSymbolType_h = 0,
  6661. //iso1unitSymbolType_m = 1,
  6662. //iso1unitSymbolType_s = 2,
  6663. //iso1unitSymbolType_A = 3,
  6664. //iso1unitSymbolType_V = 4,
  6665. //iso1unitSymbolType_W = 5,
  6666. //iso1unitSymbolType_Wh = 6
  6667. //EVSEMaximumPowerLimit
  6668. para->EVSEMaximumPowerLimit.Value = 6000;
  6669. para->EVSEMaximumPowerLimit.Multiplier = 1;
  6670. //para->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  6671. para->EVSEMaximumPowerLimit.Unit = iso1unitSymbolType_W;
  6672. //EVSEMaximumVoltageLimit
  6673. para->EVSEMaximumVoltageLimit.Value = 7500;
  6674. para->EVSEMaximumVoltageLimit.Multiplier = -1;
  6675. //para->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  6676. para->EVSEMaximumVoltageLimit.Unit = iso1unitSymbolType_V;
  6677. //EVSEMinimumVoltageLimit
  6678. para->EVSEMinimumVoltageLimit.Value = 1500;
  6679. para->EVSEMinimumVoltageLimit.Multiplier = -1;
  6680. //para->EVSEMinimumVoltageLimit.Unit_isUsed = 1u;
  6681. para->EVSEMinimumVoltageLimit.Unit = iso1unitSymbolType_V;
  6682. //EVSEMinimumCurrentLimit
  6683. para->EVSEMinimumCurrentLimit.Value = 20;
  6684. para->EVSEMinimumCurrentLimit.Multiplier = -1;
  6685. //para->EVSEMinimumCurrentLimit.Unit_isUsed = 1u;
  6686. para->EVSEMinimumCurrentLimit.Unit = iso1unitSymbolType_A;
  6687. //EVSECurrentRegulationTolerance_isUsed
  6688. para->EVSECurrentRegulationTolerance_isUsed = 1u;
  6689. //EVSECurrentRegulationTolerance
  6690. para->EVSECurrentRegulationTolerance.Value = 10;
  6691. para->EVSECurrentRegulationTolerance.Multiplier = -1;
  6692. //para->EVSECurrentRegulationTolerance.Unit_isUsed = 1u;
  6693. para->EVSECurrentRegulationTolerance.Unit = iso1unitSymbolType_A;
  6694. //EVSEEnergyToBeDelivered_isUsed
  6695. para->EVSEEnergyToBeDelivered_isUsed = 1u;
  6696. //EVSEPeakCurrentRipple
  6697. para->EVSEPeakCurrentRipple.Value = 2;
  6698. para->EVSEPeakCurrentRipple.Multiplier = -1;
  6699. //para->EVSEPeakCurrentRipple.Unit_isUsed = 1u;
  6700. para->EVSEPeakCurrentRipple.Unit = iso1unitSymbolType_A;
  6701. //EVSEEnergyToBeDelivered (optional)
  6702. /*
  6703. para->EVSEEnergyToBeDelivered.Value = 360;
  6704. para->EVSEEnergyToBeDelivered.Multiplier = 3;
  6705. para->EVSEEnergyToBeDelivered.Unit_isUsed = 1u;
  6706. para->EVSEEnergyToBeDelivered.Unit = iso1unitSymbolType_Wh;
  6707. */
  6708. }
  6709. /*===========================================================================
  6710. FUNCTION: Proc_din_ChargeParameterDiscoveryRes
  6711. DESCRIPTION:
  6712. PRE-CONDITION:
  6713. INPUT:
  6714. OUTPUT:
  6715. GLOBAL VARIABLES:
  6716. =============================================================================*/
  6717. int Proc_din_ChargeParameterDiscoveryRes(int AcceptFd)
  6718. {
  6719. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6720. //if it is not the same, the packet should be ignored.
  6721. //STEP 1: ============ Initialize ============
  6722. int errn = 0;
  6723. bitstream_t v2g_tx_stream;
  6724. struct ChargeParameterDiscoveryResponse_DIN70121 *res;
  6725. struct ChargeParameterDiscoveryRequest_DIN70121 *req;
  6726. struct DC_EVSEChargeParameterType_DIN70121 *dc_para;
  6727. struct ChargingInfoData *sys;
  6728. size_t pos = 0;
  6729. v2g_tx_stream.pos = &pos;
  6730. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6731. v2g_tx_stream.data = V2GTP_Tx_buf;
  6732. res = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse;
  6733. req = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest;
  6734. dc_para = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse.DC_EVSEChargeParameter;
  6735. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6736. res->ResponseCode = OK_DIN70121;
  6737. res->EVSEProcessing = Ongoing_DIN70121;
  6738. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready; //1
  6739. //[HEADER] Check Req SessionID
  6740. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  6741. {
  6742. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  6743. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  6744. errn = -1;
  6745. }
  6746. //Check for SequenceError
  6747. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6748. {
  6749. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  6750. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  6751. errn = -1;
  6752. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6753. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6754. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6755. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6756. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6757. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6758. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6759. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6760. }
  6761. //[TC_SECC_VTB_ChargeParameterDiscovery_005]
  6762. if (sys->EvBatteryMaxCurrent < 0)
  6763. {
  6764. sprintf((char*)buf_log_evcomm,
  6765. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  6766. sys->EvBatteryMaxCurrent);
  6767. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6768. res->ResponseCode = dinresponseCodeType_FAILED_WrongChargeParameter; //16
  6769. res->EVSEProcessing = Finished_DIN70121;
  6770. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6771. errn = -1;
  6772. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6773. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  6774. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6775. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6776. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6777. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6778. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  6779. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  6780. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6781. }
  6782. //STEP 2: ============ Modify Parameters of ShmCcsData ============
  6783. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_DIN70121);
  6784. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_DIN70121);
  6785. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_DIN70121);
  6786. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMinimumVoltageLimit, 1500, V_DIN70121); //150V
  6787. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMinimumCurrentLimit, 10, A_DIN70121); //1A
  6788. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSECurrentRegulationTolerance, 10, A_DIN70121); //1A
  6789. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEPeakCurrentRipple, 2, A_DIN70121); //0.2A
  6790. //SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEEnergyToBeDelivered, 0, WH_DIN70121); //optional
  6791. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  6792. if (sys->EvBatteryMaxVoltage <= 500)
  6793. {
  6794. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumVoltageLimit, (int) (500 * 10), V_DIN70121); //500V
  6795. }
  6796. #endif
  6797. //for test with Tesla Model 3, 10A
  6798. //SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumCurrentLimit, (int) (10 * 10), A_DIN70121); //10A, for testing with Tesla Model 3
  6799. //Check for EnergyTransferMode [TC_SECC_VTB_ChargeParameterDiscovery_004]
  6800. if (req->EVRequestedEnergyTransferType != DC_extended)
  6801. {
  6802. sprintf((char*)buf_log_evcomm,
  6803. "[ERROR]Wrong EVRequestedEnergyTransferType(%d,%d)",
  6804. req->EVRequestedEnergyTransferType,
  6805. dinEVSESupportedEnergyTransferType_DC_extended);
  6806. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6807. res->ResponseCode = FAILED_WrongEnergyTransferType_DIN70121;
  6808. res->EVSEProcessing = Finished_DIN70121;
  6809. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6810. errn = -1;
  6811. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6812. Update_V2G_Flow_Status(Other_Fault);
  6813. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6814. //CCS_SECC_ResponseCode_FAILED_WrongEnergyTransferMode (023774)
  6815. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6816. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6817. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6818. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6819. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  6820. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  6821. }
  6822. //Check for CSU command of "Stop by EVSE"
  6823. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6824. {
  6825. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes]EVSE_Shutdown\n");
  6826. res->ResponseCode = FAILED_DIN70121;
  6827. res->EVSEProcessing = Finished_DIN70121;
  6828. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6829. errn = -1;
  6830. }
  6831. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6832. {
  6833. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes]EVSE_EmergencyShutdown\n");
  6834. res->ResponseCode = FAILED_DIN70121;
  6835. res->EVSEProcessing = Finished_DIN70121;
  6836. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  6837. errn = -1;
  6838. }
  6839. //Detect for CP State should be 9V (State B)
  6840. #if CP_PROTECTION_MECHANISM == ENABLE
  6841. if (sys->CpState != 3) //State B1, B2
  6842. {
  6843. res->ResponseCode = FAILED_DIN70121;
  6844. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  6845. res->EVSEProcessing = Finished_DIN70121;
  6846. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6847. Update_V2G_Flow_Status(Other_Fault);
  6848. errn = -1;
  6849. sprintf((char*)buf_log_evcomm,
  6850. "Emergency Stop by CP Error (%d, %.02f V)\n",
  6851. sys->CpState,
  6852. sys->CpVoltage);
  6853. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6854. }
  6855. #endif
  6856. //Check for Permission from CSU
  6857. if (ShmInternalComm->ChargingPermission == TRUE)
  6858. {
  6859. res->EVSEProcessing = Finished_DIN70121;
  6860. }
  6861. //Check for Permission Off
  6862. if (ShmInternalComm->ChargingPermission == FALSE)
  6863. {
  6864. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Permission OFF\n");
  6865. res->ResponseCode = FAILED_DIN70121;
  6866. res->EVSEProcessing = Finished_DIN70121;
  6867. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6868. errn = -1;
  6869. }
  6870. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  6871. #if PARAMETER_NORMAL_MODE == ENABLE
  6872. SHM_Read_din_ChargeParameterDiscoveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  6873. #else
  6874. Sudo_Parameter_din_ChargeParameterDiscoveryRes();
  6875. #endif
  6876. //STEP 4: ============ Encode and Send Response Message ===========
  6877. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  6878. {
  6879. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Tx encoded msg error\n");
  6880. errn = -1;
  6881. }
  6882. //STPE 5: ============ Update Flags ============
  6883. return errn;
  6884. }
  6885. /*===========================================================================
  6886. FUNCTION: Proc_iso1_ChargeParameterDiscoveryRes
  6887. DESCRIPTION:
  6888. PRE-CONDITION:
  6889. INPUT:
  6890. OUTPUT:
  6891. GLOBAL VARIABLES:
  6892. =============================================================================*/
  6893. int Proc_iso1_ChargeParameterDiscoveryRes(int AcceptFd)
  6894. {
  6895. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6896. //if it is not the same, the packet should be ignored.
  6897. //STEP 1: ============ Initialize ============
  6898. int errn = 0;
  6899. bitstream_t v2g_tx_stream;
  6900. struct ChargeParameterDiscoveryResponse_ISO15118_2014 *res;
  6901. struct ChargeParameterDiscoveryRequest_ISO15118_2014 *req;
  6902. struct DC_EVSEChargeParameterType_ISO15118_2014 *dc_para;
  6903. struct AC_EVSEChargeParameterType_ISO15118_2014 *ac_para;
  6904. struct ChargingInfoData *sys;
  6905. size_t pos = 0;
  6906. v2g_tx_stream.pos = &pos;
  6907. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6908. v2g_tx_stream.data = V2GTP_Tx_buf;
  6909. res = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse;
  6910. req = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest;
  6911. dc_para = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse.DC_EVSEChargeParameter;
  6912. ac_para = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse.AC_EVSEChargeParameter;
  6913. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6914. res->ResponseCode = OK_ISO15118_2014;
  6915. /*+++ 20200808, vern, EVSEProcessing should be on-going during ChargeParameterDiscovery +++*/
  6916. res->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  6917. /*--- 20200808, vern, EVSEProcessing should be on-going during ChargeParameterDiscovery ---*/
  6918. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; //1
  6919. ac_para->AC_EVSEStatus.RCD = ShmInternalComm->AC_RcdStatus; //0:no error, 1:error
  6920. ac_para->AC_EVSEStatus.NotificationMaxDelay = 0; //unit: 1s
  6921. ac_para->AC_EVSEStatus.EVSENotification = ShmInternalComm->AC_EVSENotification; //0:none, 1:StopCharging, 2:RenNgotiation
  6922. //[HEADER] Check Req SessionID
  6923. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  6924. {
  6925. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  6926. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  6927. errn = -1;
  6928. }
  6929. //Check for SequenceError
  6930. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6931. {
  6932. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  6933. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  6934. errn = -1;
  6935. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6936. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6937. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6938. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6939. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6940. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6941. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6942. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6943. }
  6944. //[TC_SECC_VTB_ChargeParameterDiscovery_005]
  6945. /*+++ 20200808, vern, should check the voltage and current to see if the range of battery parameter is accepted by charger ---*/
  6946. #ifdef TEST_WITH_ETH0
  6947. if((ShmCcsData->EnergyTransferMode == MODE_DC_EXTENDED) && ((sys->EvBatteryMaxCurrent < 0) || (sys->EvBatteryMaxVoltage<150)))
  6948. #else
  6949. if ((sys->EvBatteryMaxCurrent < 0) ||(sys->EvBatteryMaxVoltage<150))
  6950. #endif
  6951. {
  6952. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]EvBatteryMaxCurrent is negative(%.02f) or EvBatteryMaxVoltage is under 150(%.02f)=> End_Process\n", sys->EvBatteryMaxCurrent, sys->EvBatteryMaxVoltage);
  6953. res->ResponseCode = iso1responseCodeType_FAILED_WrongChargeParameter; //16
  6954. res->EVSEProcessing = Finished_ISO15118_2014;
  6955. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  6956. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  6957. errn = -1;
  6958. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6959. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  6960. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6961. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6962. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6963. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6964. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  6965. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  6966. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6967. }
  6968. //STEP 2: ============ Modify Parameters of ShmCcsData ============
  6969. //DC
  6970. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_ISO15118_2014);
  6971. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  6972. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_ISO15118_2014);
  6973. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMinimumVoltageLimit, 1500, V_ISO15118_2014); //150V
  6974. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMinimumCurrentLimit, 10, A_ISO15118_2014); //1A
  6975. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSECurrentRegulationTolerance, 10, A_ISO15118_2014); //1A
  6976. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEPeakCurrentRipple, 2, A_ISO15118_2014); //0.2A
  6977. //SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEEnergyToBeDelivered, 0, Wh_ISO15118_2014); //optional
  6978. //AC
  6979. SAVE_PhysicalValueType_ISO15118_2014(&ac_para->EVSENominalVoltage, (int) (sys->AC_EVSENominalVoltage * 10), V_ISO15118_2014);
  6980. SAVE_PhysicalValueType_ISO15118_2014(&ac_para->EVSEMaxCurrent, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  6981. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  6982. if (sys->EvBatteryMaxVoltage <= 500)
  6983. {
  6984. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumVoltageLimit, (int) (500 * 10), V_ISO15118_2014); //500V
  6985. }
  6986. #endif
  6987. //for test with Tesla Model 3, 10A
  6988. //SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumCurrentLimit, (int) (10 * 10), A_ISO15118_2014); //10A, for testing with Tesla Model 3
  6989. //Check for EnergyTransferMode
  6990. if (req->RequestedEnergyTransferMode != ShmCcsData->EnergyTransferMode) //[CAUTION] Their table should be kept as the same.
  6991. {
  6992. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]Unmatched RequestedEnergyTransferMode(%d,%d)\n",
  6993. req->RequestedEnergyTransferMode,
  6994. ShmCcsData->EnergyTransferMode);
  6995. res->ResponseCode = FAILED_WrongEnergyTransferMode_ISO15118_2014;
  6996. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  6997. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  6998. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  6999. errn = -1;
  7000. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7001. Update_V2G_Flow_Status(Other_Fault);
  7002. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7003. //CCS_SECC_ResponseCode_FAILED_WrongEnergyTransferMode (023774)
  7004. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7005. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7006. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7007. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7008. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  7009. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  7010. }
  7011. //Check for CSU command of "Stop by EVSE"
  7012. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7013. {
  7014. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_Shutdown\n");
  7015. res->ResponseCode = FAILED_ISO15118_2014;
  7016. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7017. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7018. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7019. errn = -1;
  7020. }
  7021. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7022. {
  7023. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_EmergencyShutdown\n");
  7024. res->ResponseCode = FAILED_ISO15118_2014;
  7025. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7026. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7027. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7028. errn = -1;
  7029. }
  7030. //Detect for CP State should be 9V (State B)
  7031. #if CP_PROTECTION_MECHANISM == ENABLE
  7032. if (sys->CpState != 3) //State B1, B2
  7033. {
  7034. res->ResponseCode = FAILED_ISO15118_2014;
  7035. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7036. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7037. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7038. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7039. Update_V2G_Flow_Status(Other_Fault);
  7040. errn = -1;
  7041. sprintf((char*)buf_log_evcomm,
  7042. "Emergency Stop by CP Error (%d, %.02f V)\n",
  7043. sys->CpState,
  7044. sys->CpVoltage);
  7045. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7046. }
  7047. #endif
  7048. //Check for Permission from CSU
  7049. if(ShmInternalComm->ChargingPermission == TRUE)
  7050. {
  7051. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7052. }
  7053. //Check for Permission Off
  7054. if (ShmInternalComm->ChargingPermission == FALSE)
  7055. {
  7056. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Permission OFF\n");
  7057. res->ResponseCode = FAILED_ISO15118_2014;
  7058. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7059. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7060. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7061. errn = -1;
  7062. }
  7063. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7064. #if PARAMETER_NORMAL_MODE == ENABLE
  7065. SHM_Read_iso1_ChargeParameterDiscoveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  7066. #else
  7067. Sudo_Parameter_iso1_ChargeParameterDiscoveryRes();
  7068. #endif
  7069. //STEP 4: ============ Encode and Send Response Message ===========
  7070. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  7071. {
  7072. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Tx encoded msg error\n");
  7073. errn = -1;
  7074. }
  7075. //STPE 5: ============ Update Flags ============
  7076. return errn;
  7077. }
  7078. /*===========================================================================
  7079. FUNCTION: Proc_din_ChargeParameterDiscoveryReq
  7080. DESCRIPTION:
  7081. PRE-CONDITION:
  7082. INPUT:
  7083. OUTPUT:
  7084. GLOBAL VARIABLES:
  7085. =============================================================================*/
  7086. int Proc_din_ChargeParameterDiscoveryReq(int AcceptFd)
  7087. {
  7088. int errn = 0;
  7089. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]ChargeParameterDiscoveryReq");
  7090. //ftime(&SeqStartTime);
  7091. //Print the decoded XML Document
  7092. PRINT_XML_DOC_DIN_ChargeParameterDiscoveryReq(&ccs_exi_doc_DIN);
  7093. //Save into Share Memory
  7094. SHM_Save_din_ChargeParameterDiscoveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  7095. //Check for EV Error Code
  7096. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.DC_EVStatus.EVErrorCode);
  7097. errn = Proc_din_ChargeParameterDiscoveryRes(AcceptFd);
  7098. //ftime(&SeqEndTime);
  7099. //DEBUG_PRINTF_EVCOMM_DETAIL("\ndelta = %.02lf ms\n", DiffTimeb(SeqStartTime, SeqEndTime));
  7100. if ( errn == 0)
  7101. {
  7102. //send response successfully.
  7103. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ChargeParameterDiscoveryRes\n");
  7104. }
  7105. else
  7106. {
  7107. sprintf((char*)buf_log_evcomm,
  7108. "[Error]%d (DEC)",
  7109. errn);
  7110. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7111. }
  7112. return errn;
  7113. }
  7114. /*===========================================================================
  7115. FUNCTION: Proc_iso1_ChargeParameterDiscoveryReq
  7116. DESCRIPTION:
  7117. PRE-CONDITION:
  7118. INPUT:
  7119. OUTPUT:
  7120. GLOBAL VARIABLES:
  7121. =============================================================================*/
  7122. int Proc_iso1_ChargeParameterDiscoveryReq(int AcceptFd)
  7123. {
  7124. int errn = 0;
  7125. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]ChargeParameterDiscoveryReq\n");
  7126. //ftime(&SeqStartTime);
  7127. //Print the decoded XML Document
  7128. PRINT_XML_DOC_ISO1_ChargeParameterDiscoveryReq(&ccs_exi_doc_ISO1);
  7129. //Save into Share Memory
  7130. SHM_Save_iso1_ChargeParameterDiscoveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  7131. //Check for EV Error Code
  7132. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.DC_EVStatus.EVErrorCode);
  7133. errn = Proc_iso1_ChargeParameterDiscoveryRes(AcceptFd);
  7134. //ftime(&SeqEndTime);
  7135. //DEBUG_PRINTF_EVCOMM_DETAIL("\ndelta = %.02lf ms\n", DiffTimeb(SeqStartTime, SeqEndTime));
  7136. if (errn == 0)
  7137. {
  7138. //send response successfully.
  7139. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ChargeParameterDiscoveryRes\n");
  7140. }
  7141. else
  7142. {
  7143. SAVE_SYS_LOG_MSG_EVCOMM("[Error]%d (DEC)\n", errn);
  7144. }
  7145. return errn;
  7146. }
  7147. /*===========================================================================
  7148. FUNCTION: SHM_Init_din_CableCheckRes
  7149. DESCRIPTION:
  7150. PRE-CONDITION:
  7151. INPUT:
  7152. 1. shm_ccs
  7153. OUTPUT:
  7154. 1. shm_ccs
  7155. GLOBAL VARIABLES:
  7156. =============================================================================*/
  7157. void SHM_Init_din_CableCheckRes(struct CcsData *shm_ccs)
  7158. {
  7159. struct CableCheckResponse_DIN70121 *in;
  7160. in = &shm_ccs->V2GMessage_DIN70121.CableCheckResponse;
  7161. //----- [BODY (1/3)] ResponseCode -----
  7162. in->ResponseCode = dinresponseCodeType_OK;
  7163. //----- [BODY (2/3)] EVSEProcessing -----
  7164. //in->EVSEProcessing = dinEVSEProcessingType_Finished; //for test
  7165. in->EVSEProcessing = dinEVSEProcessingType_Ongoing; //default
  7166. // dinEVSEProcessingType_Finished = 0,
  7167. // dinEVSEProcessingType_Ongoing = 1
  7168. //----- [BODY (3/3)] DC_EVSEStatus -----
  7169. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  7170. in->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0 (default)
  7171. // dinisolationLevelType_Invalid = 0,
  7172. // dinisolationLevelType_Valid = 1, (default)
  7173. // dinisolationLevelType_Warning = 2,
  7174. // dinisolationLevelType_Fault = 3
  7175. }
  7176. /*===========================================================================
  7177. FUNCTION: Sudo_Parameter_din_CableCheckRes
  7178. DESCRIPTION:
  7179. PRE-CONDITION:
  7180. INPUT:
  7181. OUTPUT:
  7182. GLOBAL VARIABLES:
  7183. =============================================================================*/
  7184. void Sudo_Parameter_din_CableCheckRes()
  7185. {
  7186. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  7187. init_dinCableCheckResType(&ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes);
  7188. ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes_isUsed = 1u;
  7189. //----- [BODY (1/3)] ResponseCode -----
  7190. struct dinCableCheckResType *res;
  7191. res = &ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes;
  7192. res->ResponseCode = dinresponseCodeType_OK;
  7193. //----- [BODY (2/3)] EVSEProcessing -----
  7194. res->EVSEProcessing = dinEVSEProcessingType_Finished; //0
  7195. // dinEVSEProcessingType_Finished = 0,
  7196. // dinEVSEProcessingType_Ongoing = 1
  7197. //----- [BODY (3/3)] DC_EVSEStatus -----
  7198. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7199. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7200. // dinisolationLevelType_Invalid = 0,
  7201. // dinisolationLevelType_Valid = 1,
  7202. // dinisolationLevelType_Warning = 2,
  7203. // dinisolationLevelType_Fault = 3
  7204. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7205. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7206. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  7207. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7208. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7209. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7210. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7211. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7212. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  7213. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  7214. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  7215. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  7216. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  7217. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7218. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  7219. // dinEVSENotificationType_None = 0,
  7220. // dinEVSENotificationType_StopCharging = 1,
  7221. // dinEVSENotificationType_ReNegotiation = 2
  7222. }
  7223. /*===========================================================================
  7224. FUNCTION: Sudo_Parameter_iso1_CableCheckRes
  7225. DESCRIPTION:
  7226. PRE-CONDITION:
  7227. INPUT:
  7228. OUTPUT:
  7229. GLOBAL VARIABLES:
  7230. =============================================================================*/
  7231. void Sudo_Parameter_iso1_CableCheckRes()
  7232. {
  7233. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  7234. init_iso1CableCheckResType(&ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes);
  7235. ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes_isUsed = 1u;
  7236. //----- [BODY (1/3)] ResponseCode -----
  7237. struct iso1CableCheckResType *res;
  7238. res = &ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes;
  7239. res->ResponseCode = iso1responseCodeType_OK;
  7240. //----- [BODY (2/3)] EVSEProcessing -----
  7241. res->EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  7242. //iso1EVSEProcessingType_Finished = 0,
  7243. //iso1EVSEProcessingType_Ongoing = 1,
  7244. //iso1EVSEProcessingType_Ongoing_WaitingForCustomerInteraction = 2
  7245. //----- [BODY (3/3)] DC_EVSEStatus -----
  7246. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7247. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  7248. //iso1isolationLevelType_Invalid = 0,
  7249. //iso1isolationLevelType_Valid = 1,
  7250. //iso1isolationLevelType_Warning = 2,
  7251. //iso1isolationLevelType_Fault = 3,
  7252. //iso1isolationLevelType_No_IMD = 4
  7253. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  7254. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7255. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  7256. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7257. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7258. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7259. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7260. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7261. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  7262. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  7263. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  7264. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  7265. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  7266. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7267. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  7268. //iso1EVSENotificationType_None = 0,
  7269. //iso1EVSENotificationType_StopCharging = 1,
  7270. //iso1EVSENotificationType_ReNegotiation = 2
  7271. }
  7272. /*===========================================================================
  7273. FUNCTION: Proc_din_CableCheckRes
  7274. DESCRIPTION:
  7275. PRE-CONDITION:
  7276. INPUT:
  7277. OUTPUT:
  7278. GLOBAL VARIABLES:
  7279. =============================================================================*/
  7280. int Proc_din_CableCheckRes(int AcceptFd)
  7281. {
  7282. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7283. //if it is not the same, the packet should be ignored.
  7284. //STEP 1: ============ Initialize ============
  7285. //int i = 0;
  7286. int errn = 0;
  7287. bitstream_t v2g_tx_stream;
  7288. static struct CableCheckResponse_DIN70121 *cab;
  7289. static struct ChargingInfoData *sys;
  7290. size_t pos = 0;
  7291. v2g_tx_stream.pos = &pos;
  7292. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7293. v2g_tx_stream.data = V2GTP_Tx_buf;
  7294. cab = &ShmCcsData->V2GMessage_DIN70121.CableCheckResponse;
  7295. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7296. cab->ResponseCode = OK_DIN70121;
  7297. cab->cnt++;
  7298. DEBUG_PRINTF_EVCOMM_DETAIL("CP_State = %d (%.02f V), V_now = %.02f, Isolation Status = %d, EVSEProcessing = %d\n",
  7299. sys->CpState,
  7300. sys->CpVoltage,
  7301. sys->PresentChargingVoltage,
  7302. sys->IsolationStatus,
  7303. cab->EVSEProcessing);
  7304. //[HEADER] Check Req SessionID
  7305. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  7306. {
  7307. cab->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  7308. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  7309. errn = -1;
  7310. }
  7311. //Check for SequenceError
  7312. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7313. {
  7314. cab->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  7315. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  7316. errn = -1;
  7317. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7318. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7319. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7320. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7321. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7322. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7323. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7324. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7325. }
  7326. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  7327. if (sys->IsolationStatus == GFD_Invalid) //0: on going
  7328. {
  7329. //For PSU
  7330. sys->EvBatterytargetVoltage = CABLECHECK_TARGET_VOLTAGE; //500V //[To-Do] this should be modified to auto decision.
  7331. sys->EvBatterytargetCurrent = CABLECHECK_TARGET_CURRENT; //2A(default), unit: 1A
  7332. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7333. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive; //4
  7334. cab->EVSEProcessing = dinEVSEProcessingType_Ongoing;
  7335. }
  7336. else if ((sys->IsolationStatus == GFD_Valid) || (sys->IsolationStatus == GFD_Warning)) //1: valid, 2: warning
  7337. {
  7338. //For PSU
  7339. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7340. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7341. if (sys->PresentChargingVoltage < 60) // < 60V
  7342. {
  7343. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  7344. sprintf((char*)buf_log_evcomm, "[V2G][CableCheck]Pass (V_now = %.02f, Isolated = %d)",
  7345. sys->PresentChargingVoltage,
  7346. sys->IsolationStatus);
  7347. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7348. //IsolationStatus
  7349. if (sys->IsolationStatus == GFD_Valid)
  7350. {
  7351. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7352. }
  7353. else if (sys->IsolationStatus == GFD_Warning)
  7354. {
  7355. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning;
  7356. }
  7357. else
  7358. {
  7359. sprintf((char*)buf_log_evcomm,
  7360. "[WARNING]unexpected IsolationStatus(%d)",
  7361. sys->IsolationStatus);
  7362. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7363. }
  7364. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7365. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7366. }
  7367. else
  7368. {
  7369. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7370. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7371. cab->EVSEProcessing = dinEVSEProcessingType_Ongoing;
  7372. }
  7373. }
  7374. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  7375. {
  7376. //For PSU
  7377. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7378. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7379. cab->ResponseCode = FAILED_DIN70121;
  7380. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7381. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_NotReady;
  7382. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7383. SAVE_SYS_LOG_MSG_EVCOMM("IsolationStatus = 3 (fault)\n");
  7384. errn = -1;
  7385. }
  7386. else
  7387. {
  7388. //For PSU
  7389. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7390. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7391. cab->ResponseCode = FAILED_DIN70121;
  7392. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7393. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_NotReady;
  7394. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7395. sprintf((char*)buf_log_evcomm,
  7396. "Undefined Isolation Status(%d)",
  7397. sys->IsolationStatus);
  7398. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7399. }
  7400. //Check for CSU command of "Stop by EVSE"
  7401. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7402. {
  7403. cab->ResponseCode = FAILED_DIN70121;
  7404. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7405. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7406. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7407. errn = -1;
  7408. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_Shutdown\n");
  7409. }
  7410. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7411. {
  7412. cab->ResponseCode = FAILED_DIN70121;
  7413. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7414. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7415. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7416. errn = -1;
  7417. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_EmergencyShutdown\n");
  7418. }
  7419. else if (ShmInternalComm->ChargingPermission == FALSE)
  7420. {
  7421. cab->ResponseCode = FAILED_DIN70121;
  7422. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7423. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7424. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7425. errn = -1;
  7426. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingPermission = FALSE\n");
  7427. }
  7428. else
  7429. {
  7430. //null
  7431. }
  7432. //Response to CP Error
  7433. #if CP_PROTECTION_MECHANISM == ENABLE
  7434. //#if 1
  7435. if (sys->CableCheckPreCountDownDone == TRUE) //[To-Do] Here should be modified to 2 seconds
  7436. {
  7437. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  7438. {
  7439. cab->ResponseCode = FAILED_DIN70121;
  7440. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7441. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7442. Update_V2G_Flow_Status(Other_Fault);
  7443. errn = -1;
  7444. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7445. //CCS_SECC_CP_State_Error (023889)
  7446. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7447. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7448. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7449. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  7450. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  7451. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  7452. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  7453. sprintf((char*)buf_log_evcomm,
  7454. "[CableCheck]Emergency Stop by CP Error (%d, %.02f V, %d)\n",
  7455. sys->CpState,
  7456. sys->CpVoltage,
  7457. cab->cnt
  7458. );
  7459. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7460. //cab->cnt = 0;
  7461. }
  7462. }
  7463. #endif
  7464. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7465. #if PARAMETER_NORMAL_MODE == ENABLE
  7466. SHM_Read_din_CableCheckRes(&ccs_exi_doc_DIN, ShmCcsData);
  7467. #else
  7468. Sudo_Parameter_din_CableCheckRes();
  7469. #endif
  7470. //STEP 4: ============ Encode and Send Response Message ===========
  7471. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  7472. {
  7473. errn = -1;
  7474. }
  7475. //STEP 5: ============ Update Flags ===========
  7476. sys->ConnectorLocked = TRUE; //Inicating EVSE that the CCS Connector is Locked.
  7477. return errn;
  7478. }
  7479. /*===========================================================================
  7480. FUNCTION: Proc_iso1_CableCheckRes
  7481. DESCRIPTION:
  7482. PRE-CONDITION:
  7483. INPUT:
  7484. OUTPUT:
  7485. GLOBAL VARIABLES:
  7486. =============================================================================*/
  7487. int Proc_iso1_CableCheckRes(int AcceptFd)
  7488. {
  7489. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7490. //if it is not the same, the packet should be ignored.
  7491. //STEP 1: ============ Initialize ============
  7492. //int i = 0;
  7493. int errn = 0;
  7494. bitstream_t v2g_tx_stream;
  7495. static struct CableCheckResponse_ISO15118_2014 *cab;
  7496. static struct ChargingInfoData *sys;
  7497. size_t pos = 0;
  7498. v2g_tx_stream.pos = &pos;
  7499. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7500. v2g_tx_stream.data = V2GTP_Tx_buf;
  7501. cab = &ShmCcsData->V2GMessage_ISO15118_2014.CableCheckResponse;
  7502. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7503. cab->ResponseCode = OK_ISO15118_2014;
  7504. cab->cnt++;
  7505. DEBUG_PRINTF_EVCOMM_DETAIL("CP_State = %d (%.02f V), V_now = %.02f, Isolation Status = %d, EVSEProcessing = %d\n",
  7506. sys->CpState,
  7507. sys->CpVoltage,
  7508. sys->PresentChargingVoltage,
  7509. sys->IsolationStatus,
  7510. cab->EVSEProcessing);
  7511. //[HEADER] Check Req SessionID
  7512. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  7513. {
  7514. cab->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  7515. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  7516. errn = -1;
  7517. }
  7518. //Check for SequenceError
  7519. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7520. {
  7521. cab->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  7522. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  7523. errn = -1;
  7524. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7525. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7526. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7527. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7528. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7529. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7530. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7531. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7532. }
  7533. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  7534. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  7535. {
  7536. //For PSU
  7537. sys->EvBatterytargetVoltage = CABLECHECK_TARGET_VOLTAGE; //500V //[To-Do] this should be modified to auto decision.
  7538. sys->EvBatterytargetCurrent = CABLECHECK_TARGET_CURRENT; //2A(default), unit: 1A
  7539. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  7540. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7541. cab->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  7542. }
  7543. else if ((sys->IsolationStatus == GFD_Valid) || (sys->IsolationStatus == GFD_Warning)) //1: valid, 2:waring
  7544. {
  7545. //For PSU
  7546. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7547. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7548. if (sys->PresentChargingVoltage < 60) // < 60V
  7549. {
  7550. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  7551. sprintf((char*)buf_log_evcomm, "[V2G][CableCheck]Pass (V_now = %.02f, Isolated = %d)",
  7552. sys->PresentChargingVoltage,
  7553. sys->IsolationStatus);
  7554. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7555. //IsolationStatus
  7556. if (sys->IsolationStatus == GFD_Valid)
  7557. {
  7558. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  7559. }
  7560. else if (sys->IsolationStatus == GFD_Warning)
  7561. {
  7562. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning;
  7563. }
  7564. else
  7565. {
  7566. sprintf((char*)buf_log_evcomm,
  7567. "[WARNING]unexpected IsolationStatus(%d)",
  7568. sys->IsolationStatus);
  7569. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7570. }
  7571. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  7572. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7573. }
  7574. else
  7575. {
  7576. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  7577. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7578. cab->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  7579. }
  7580. }
  7581. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  7582. {
  7583. //For PSU
  7584. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7585. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7586. cab->ResponseCode = FAILED_ISO15118_2014;
  7587. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7588. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_NotReady;
  7589. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7590. SAVE_SYS_LOG_MSG_EVCOMM("IsolationStatus = 3 (fault)\n");
  7591. errn = -1;
  7592. }
  7593. //else if (sys->IsolationStatus == GFD_No_IMD){} //only for ISO15118
  7594. else
  7595. {
  7596. //For PSU
  7597. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7598. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7599. cab->ResponseCode = FAILED_ISO15118_2014;
  7600. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7601. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_NotReady;
  7602. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7603. SAVE_SYS_LOG_MSG_EVCOMM("Undefined Isolation Status.\n");
  7604. }
  7605. //Check for CSU command of "Stop by EVSE"
  7606. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7607. {
  7608. cab->ResponseCode = FAILED_ISO15118_2014;
  7609. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7610. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7611. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7612. errn = -1;
  7613. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_Shutdown\n");
  7614. }
  7615. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7616. {
  7617. cab->ResponseCode = FAILED_ISO15118_2014;
  7618. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7619. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7620. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7621. errn = -1;
  7622. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_EmergencyShutdown\n");
  7623. }
  7624. else if (ShmInternalComm->ChargingPermission == FALSE)
  7625. {
  7626. cab->ResponseCode = FAILED_ISO15118_2014;
  7627. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7628. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7629. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7630. errn = -1;
  7631. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingPermission = FALSE\n");
  7632. }
  7633. else
  7634. {
  7635. //null
  7636. }
  7637. //Response to CP Error
  7638. #if CP_PROTECTION_MECHANISM == ENABLE
  7639. if (sys->CableCheckPreCountDownDone == TRUE) //[To-Do] Here should be modified to 2 seconds
  7640. {
  7641. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  7642. {
  7643. cab->ResponseCode = FAILED_ISO15118_2014;
  7644. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7645. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7646. Update_V2G_Flow_Status(Other_Fault);
  7647. errn = -1;
  7648. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7649. //CCS_SECC_CP_State_Error (023889)
  7650. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7651. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7652. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7653. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  7654. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  7655. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  7656. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  7657. sprintf((char*)buf_log_evcomm,
  7658. "[CableCheck]Emergency Stop by CP Error (%d, %.02f V, %d)\n",
  7659. sys->CpState,
  7660. sys->CpVoltage,
  7661. cab->cnt
  7662. );
  7663. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7664. //cab->cnt = 0;
  7665. }
  7666. }
  7667. #endif
  7668. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7669. #if PARAMETER_NORMAL_MODE == ENABLE
  7670. SHM_Read_iso1_CableCheckRes(&ccs_exi_doc_ISO1, ShmCcsData);
  7671. #else
  7672. Sudo_Parameter_iso1_CableCheckRes();
  7673. #endif
  7674. //STEP 4: ============ Encode and Send Response Message ===========
  7675. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  7676. {
  7677. errn = -1;
  7678. }
  7679. //STEP 5: ============ Update Flags ===========
  7680. sys->ConnectorLocked = TRUE; //Inicating EVSE that the CCS Connector is Locked.
  7681. return errn;
  7682. }
  7683. /*===========================================================================
  7684. FUNCTION: Proc_din_CableCheckReq
  7685. DESCRIPTION:
  7686. PRE-CONDITION:
  7687. INPUT:
  7688. OUTPUT:
  7689. GLOBAL VARIABLES:
  7690. =============================================================================*/
  7691. int Proc_din_CableCheckReq(int AcceptFd)
  7692. {
  7693. int errn = 0;
  7694. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]CableCheckReq\n");
  7695. //Print the decoded XML Document
  7696. PRINT_XML_DOC_DIN_CableCheckReq(&ccs_exi_doc_DIN);
  7697. //Save into Share Memory
  7698. SHM_Save_din_CableCheckReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  7699. //Check for EV Error Code
  7700. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.CableCheckRequest.DC_EVStatus.EVErrorCode);
  7701. errn = Proc_din_CableCheckRes(AcceptFd);
  7702. if (errn == 0)
  7703. {
  7704. //send response successfully.
  7705. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]CableCheckRes\n");
  7706. }
  7707. else
  7708. {
  7709. sprintf((char*)buf_log_evcomm,
  7710. "[Error]Proc_iso1_CableCheckRes(): %d (DEC)",
  7711. errn);
  7712. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7713. }
  7714. return errn;
  7715. }
  7716. /*===========================================================================
  7717. FUNCTION: Proc_iso1_CableCheckReq
  7718. DESCRIPTION:
  7719. PRE-CONDITION:
  7720. INPUT:
  7721. OUTPUT:
  7722. GLOBAL VARIABLES:
  7723. =============================================================================*/
  7724. int Proc_iso1_CableCheckReq(int AcceptFd)
  7725. {
  7726. int errn = 0;
  7727. SAVE_SYS_LOG_MSG_EVCOMM("CableCheckReq\n");
  7728. //Print the decoded XML Document
  7729. PRINT_XML_DOC_ISO1_CableCheckReq(&ccs_exi_doc_ISO1);
  7730. //Save into Share Memory
  7731. SHM_Save_iso1_CableCheckReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  7732. //Check for EV Error Code
  7733. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.CableCheckRequest.DC_EVStatus.EVErrorCode);
  7734. errn = Proc_iso1_CableCheckRes(AcceptFd);
  7735. if (errn == 0)
  7736. {
  7737. //send response successfully.
  7738. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]CableCheckRes\n");
  7739. }
  7740. else
  7741. {
  7742. sprintf((char*)buf_log_evcomm,
  7743. "[Error]Proc_iso1_CableCheckRes(): %d (DEC)",
  7744. errn);
  7745. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7746. }
  7747. return errn;
  7748. }
  7749. /*===========================================================================
  7750. FUNCTION: SHM_Init_din_PreChargeRes
  7751. DESCRIPTION:
  7752. PRE-CONDITION:
  7753. INPUT:
  7754. 1. shm_ccs
  7755. OUTPUT:
  7756. 1. shm_ccs
  7757. GLOBAL VARIABLES:
  7758. =============================================================================*/
  7759. void SHM_Init_din_PreChargeRes(struct CcsData *shm_ccs)
  7760. {
  7761. struct PreChargeResponse_DIN70121 *in;
  7762. in = &shm_ccs->V2GMessage_DIN70121.PreChargeResponse;
  7763. //----- [BODY (1/3)] ResponseCode -----
  7764. in->ResponseCode = dinresponseCodeType_OK;
  7765. //----- [BODY (2/3)] EVSEPresentVoltage -----
  7766. short value = 0; int multiplier = 0; unsigned char unit = 0;
  7767. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for Test
  7768. value = 0; multiplier = 0; unit = V_DIN70121; //waiting for CsuComm to update V to fit EV Target
  7769. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  7770. //----- [BODY (3/3)] DC_EVSEStatus -----
  7771. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  7772. }
  7773. /*===========================================================================
  7774. FUNCTION: Sudo_Parameter_din_PreChargeRes
  7775. DESCRIPTION:
  7776. PRE-CONDITION:
  7777. INPUT:
  7778. OUTPUT:
  7779. GLOBAL VARIABLES:
  7780. =============================================================================*/
  7781. void Sudo_Parameter_din_PreChargeRes()
  7782. {
  7783. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  7784. init_dinPreChargeResType(&ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes);
  7785. ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes_isUsed = 1u;
  7786. //----- [BODY (1/3)] ResponseCode -----
  7787. struct dinPreChargeResType *res;
  7788. res = &ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes;
  7789. res->ResponseCode = dinresponseCodeType_OK;
  7790. //----- [BODY (2/3)] EVSEPresentVoltage -----
  7791. res->EVSEPresentVoltage.Value = 3820;
  7792. res->EVSEPresentVoltage.Multiplier = -1;
  7793. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  7794. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  7795. // dinunitSymbolType_h = 0,
  7796. // dinunitSymbolType_m = 1,
  7797. // dinunitSymbolType_s = 2,
  7798. // dinunitSymbolType_A = 3,
  7799. // dinunitSymbolType_Ah = 4,
  7800. // dinunitSymbolType_V = 5,
  7801. // dinunitSymbolType_VA = 6,
  7802. // dinunitSymbolType_W = 7,
  7803. // dinunitSymbolType_W_s = 8,
  7804. // dinunitSymbolType_Wh = 9
  7805. //----- [BODY (3/3)] DC_EVSEStatus -----
  7806. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7807. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7808. // dinisolationLevelType_Invalid = 0,
  7809. // dinisolationLevelType_Valid = 1,
  7810. // dinisolationLevelType_Warning = 2,
  7811. // dinisolationLevelType_Fault = 3
  7812. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7813. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7814. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  7815. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7816. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7817. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7818. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7819. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7820. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  7821. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  7822. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  7823. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  7824. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  7825. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7826. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  7827. // dinEVSENotificationType_None = 0,
  7828. // dinEVSENotificationType_StopCharging = 1,
  7829. // dinEVSENotificationType_ReNegotiation = 2
  7830. }
  7831. /*===========================================================================
  7832. FUNCTION: Sudo_Parameter_iso1_PreChargeRes
  7833. DESCRIPTION:
  7834. PRE-CONDITION:
  7835. INPUT:
  7836. OUTPUT:
  7837. GLOBAL VARIABLES:
  7838. =============================================================================*/
  7839. void Sudo_Parameter_iso1_PreChargeRes()
  7840. {
  7841. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  7842. init_iso1PreChargeResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes);
  7843. ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes_isUsed = 1u;
  7844. //----- [BODY (1/3)] ResponseCode -----
  7845. struct iso1PreChargeResType *res;
  7846. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes;
  7847. res->ResponseCode = iso1responseCodeType_OK;
  7848. //----- [BODY (2/3)] EVSEPresentVoltage -----
  7849. res->EVSEPresentVoltage.Value = 3820;
  7850. res->EVSEPresentVoltage.Multiplier = -1;
  7851. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  7852. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  7853. //iso1unitSymbolType_h = 0,
  7854. //iso1unitSymbolType_m = 1,
  7855. //iso1unitSymbolType_s = 2,
  7856. //iso1unitSymbolType_A = 3,
  7857. //iso1unitSymbolType_V = 4,
  7858. //iso1unitSymbolType_W = 5,
  7859. //iso1unitSymbolType_Wh = 6
  7860. //----- [BODY (3/3)] DC_EVSEStatus -----
  7861. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7862. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  7863. //iso1isolationLevelType_Invalid = 0,
  7864. //iso1isolationLevelType_Valid = 1,
  7865. //iso1isolationLevelType_Warning = 2,
  7866. //iso1isolationLevelType_Fault = 3,
  7867. //iso1isolationLevelType_No_IMD = 4
  7868. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  7869. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7870. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  7871. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7872. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7873. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7874. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7875. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7876. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  7877. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  7878. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  7879. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  7880. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  7881. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7882. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  7883. //iso1EVSENotificationType_None = 0,
  7884. //iso1EVSENotificationType_StopCharging = 1,
  7885. //iso1EVSENotificationType_ReNegotiation = 2
  7886. }
  7887. /*===========================================================================
  7888. FUNCTION: Proc_din_PreChargeRes
  7889. DESCRIPTION:
  7890. PRE-CONDITION:
  7891. INPUT:
  7892. OUTPUT:
  7893. GLOBAL VARIABLES:
  7894. =============================================================================*/
  7895. int Proc_din_PreChargeRes(int AcceptFd)
  7896. {
  7897. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7898. //if it is not the same, the packet should be ignored.
  7899. //STEP 1: ============ Initialize ============
  7900. //int i = 0;
  7901. int errn = 0;
  7902. bitstream_t v2g_tx_stream;
  7903. static struct PreChargeResponse_DIN70121 *pre;
  7904. static struct ChargingInfoData *sys;
  7905. size_t pos = 0;
  7906. v2g_tx_stream.pos = &pos;
  7907. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7908. v2g_tx_stream.data = V2GTP_Tx_buf;
  7909. pre = &ShmCcsData->V2GMessage_DIN70121.PreChargeResponse;
  7910. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7911. pre->ResponseCode = OK_DIN70121;
  7912. //EVSE Status Code
  7913. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7914. //[HEADER] Check Req SessionID
  7915. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  7916. {
  7917. pre->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  7918. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  7919. errn = -1;
  7920. }
  7921. //Check for SequenceError
  7922. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7923. {
  7924. pre->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  7925. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  7926. errn = -1;
  7927. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7928. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7929. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7930. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7931. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7932. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7933. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7934. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7935. }
  7936. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  7937. SAVE_PhysicalValueType_DIN70121(&pre->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  7938. //Isolation Status
  7939. if (sys->IsolationStatus == GFD_Invalid) //0: invalid
  7940. {
  7941. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  7942. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7943. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7944. Update_V2G_Flow_Status(Other_Fault);
  7945. errn = -1;
  7946. sprintf((char*)buf_log_evcomm, "[Error]IsolationStatus = %d", sys->IsolationStatus);
  7947. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7948. }
  7949. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  7950. {
  7951. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  7952. }
  7953. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  7954. {
  7955. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  7956. }
  7957. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  7958. {
  7959. SAVE_SYS_LOG_MSG_EVCOMM("[Error]GFD_Fault => Emergency Shutdown\n");
  7960. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  7961. pre->ResponseCode = FAILED_DIN70121;
  7962. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7963. errn = -1;
  7964. }
  7965. else //GFD_No_IMD or other unexpected status
  7966. {
  7967. pre->ResponseCode = FAILED_DIN70121;
  7968. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  7969. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7970. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7971. Update_V2G_Flow_Status(Other_Fault);
  7972. errn = -1;
  7973. sprintf((char*)buf_log_evcomm,
  7974. "[Error]IsolationStatus = %d (undefined)",
  7975. sys->IsolationStatus);
  7976. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7977. }
  7978. //Check for CSU command of "Stop by EVSE"
  7979. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7980. {
  7981. //Check for Alarm Code: CCS GFD trip (012235)
  7982. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  7983. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  7984. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  7985. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  7986. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  7987. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  7988. {
  7989. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CCS GFD trip => EVSE_Shutdown\n");
  7990. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7991. }
  7992. else
  7993. {
  7994. SAVE_SYS_LOG_MSG_EVCOMM("[Error]EVSE_Shutdown\n");
  7995. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  7996. }
  7997. pre->ResponseCode = FAILED_DIN70121;
  7998. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7999. errn = -1;
  8000. }
  8001. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8002. {
  8003. //Check for Alarm Code: CCS GFD trip (012235)
  8004. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8005. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8006. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8007. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8008. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8009. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8010. {
  8011. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CCS GFD trip => EVSE_EmergencyShutdown\n");
  8012. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8013. }
  8014. else
  8015. {
  8016. SAVE_SYS_LOG_MSG_EVCOMM("[Error]EVSE_EmergencyShutdown\n");
  8017. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8018. }
  8019. pre->ResponseCode = FAILED_DIN70121;
  8020. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8021. errn = -1;
  8022. }
  8023. else if (ShmInternalComm->ChargingPermission == FALSE)
  8024. {
  8025. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingPermission = FALSE\n");
  8026. pre->ResponseCode = FAILED_DIN70121;
  8027. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8028. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8029. errn = -1;
  8030. }
  8031. else
  8032. {
  8033. //null
  8034. }
  8035. //Response to CP Error
  8036. #if CP_PROTECTION_MECHANISM == ENABLE
  8037. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  8038. {
  8039. pre->ResponseCode = FAILED_DIN70121;
  8040. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8041. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8042. Update_V2G_Flow_Status(Other_Fault);
  8043. errn = -1;
  8044. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8045. //CCS_SECC_CP_State_Error (023889)
  8046. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8047. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8048. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8049. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  8050. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  8051. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  8052. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  8053. sprintf((char*)buf_log_evcomm,
  8054. "[Error]Emergency Stop by CP Error (%d, %.02f V)\n",
  8055. sys->CpState,
  8056. sys->CpVoltage
  8057. );
  8058. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8059. }
  8060. #endif
  8061. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8062. #if PARAMETER_NORMAL_MODE == ENABLE
  8063. SHM_Read_din_PreChargeRes(&ccs_exi_doc_DIN, ShmCcsData);
  8064. #else
  8065. Sudo_Parameter_din_PreChargeRes();
  8066. #endif
  8067. //STEP 4: ============ Encode and Send Response Message ===========
  8068. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  8069. {
  8070. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Tx encoded msg error\n");
  8071. errn = -1;
  8072. }
  8073. //STEP 5: ============ Update Flags ===========
  8074. return errn;
  8075. }
  8076. /*===========================================================================
  8077. FUNCTION: Proc_iso1_PreChargeRes
  8078. DESCRIPTION:
  8079. PRE-CONDITION:
  8080. INPUT:
  8081. OUTPUT:
  8082. GLOBAL VARIABLES:
  8083. =============================================================================*/
  8084. int Proc_iso1_PreChargeRes(int AcceptFd)
  8085. {
  8086. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8087. //if it is not the same, the packet should be ignored.
  8088. //STEP 1: ============ Initialize ============
  8089. //int i = 0;
  8090. int errn = 0;
  8091. bitstream_t v2g_tx_stream;
  8092. static struct PreChargeResponse_ISO15118_2014 *pre;
  8093. static struct ChargingInfoData *sys;
  8094. size_t pos = 0;
  8095. v2g_tx_stream.pos = &pos;
  8096. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8097. v2g_tx_stream.data = V2GTP_Tx_buf;
  8098. pre = &ShmCcsData->V2GMessage_ISO15118_2014.PreChargeResponse;
  8099. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8100. pre->ResponseCode = OK_ISO15118_2014;
  8101. //EVSE Status Code
  8102. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8103. //[HEADER] Check Req SessionID
  8104. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  8105. {
  8106. pre->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  8107. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8108. errn = -1;
  8109. }
  8110. //Check for SequenceError
  8111. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8112. {
  8113. pre->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  8114. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  8115. errn = -1;
  8116. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8117. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8118. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8119. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8120. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8121. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8122. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8123. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8124. }
  8125. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8126. SAVE_PhysicalValueType_ISO15118_2014(&pre->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  8127. //Isolation Status
  8128. if (sys->IsolationStatus == GFD_Invalid) //0: invalid(on going)
  8129. {
  8130. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  8131. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8132. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8133. Update_V2G_Flow_Status(Other_Fault);
  8134. errn = -1;
  8135. sprintf((char*)buf_log_evcomm, "[Error]IsolationStatus = %d", sys->IsolationStatus);
  8136. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8137. }
  8138. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  8139. {
  8140. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  8141. }
  8142. else if (sys->IsolationStatus == GFD_Warning) //2: waring
  8143. {
  8144. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning; //1
  8145. }
  8146. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  8147. {
  8148. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]GFD_Fault => Emergency Shutdown");
  8149. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  8150. pre->ResponseCode = FAILED_ISO15118_2014;
  8151. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8152. errn = -1;
  8153. }
  8154. else
  8155. {
  8156. pre->ResponseCode = FAILED_ISO15118_2014;
  8157. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  8158. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8159. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8160. Update_V2G_Flow_Status(Other_Fault);
  8161. errn = -1;
  8162. sprintf((char*)buf_log_evcomm,
  8163. "[Error][Proc_iso1_PreChargeRes]IsolationStatus = %d (undefined)",
  8164. sys->IsolationStatus);
  8165. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8166. }
  8167. //Check for CSU command of "Stop by EVSE"
  8168. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8169. {
  8170. //Check for Alarm Code: CCS GFD trip (012235)
  8171. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8172. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8173. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8174. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8175. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8176. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8177. {
  8178. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CCS GFD trip => EVSE_Shutdown");
  8179. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8180. }
  8181. else
  8182. {
  8183. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]EVSE_Shutdown");
  8184. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8185. }
  8186. pre->ResponseCode = FAILED_ISO15118_2014;
  8187. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8188. errn = -1;
  8189. }
  8190. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8191. {
  8192. //Check for Alarm Code: CCS GFD trip (012235)
  8193. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8194. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8195. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8196. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8197. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8198. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8199. {
  8200. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CCS GFD trip => EVSE_EmergencyShutdown");
  8201. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8202. }
  8203. else
  8204. {
  8205. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]EVSE_EmergencyShutdown");
  8206. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8207. }
  8208. pre->ResponseCode = FAILED_ISO15118_2014;
  8209. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8210. errn = -1;
  8211. }
  8212. else if (ShmInternalComm->ChargingPermission == FALSE)
  8213. {
  8214. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargingPermission = FALSE");
  8215. pre->ResponseCode = FAILED_ISO15118_2014;
  8216. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8217. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8218. errn = -1;
  8219. }
  8220. else
  8221. {
  8222. //null
  8223. }
  8224. //Response to CP Error
  8225. #if CP_PROTECTION_MECHANISM == ENABLE
  8226. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  8227. {
  8228. pre->ResponseCode = FAILED_ISO15118_2014;
  8229. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8230. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8231. Update_V2G_Flow_Status(Other_Fault);
  8232. errn = -1;
  8233. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8234. //CCS_SECC_CP_State_Error (023889)
  8235. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8236. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8237. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8238. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  8239. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  8240. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  8241. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  8242. sprintf((char*)buf_log_evcomm,
  8243. "[Error]Emergency Stop by CP Error (%d, %.02f V)\n",
  8244. sys->CpState,
  8245. sys->CpVoltage
  8246. );
  8247. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8248. }
  8249. #endif
  8250. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8251. #if PARAMETER_NORMAL_MODE == ENABLE
  8252. SHM_Read_iso1_PreChargeRes(&ccs_exi_doc_ISO1, ShmCcsData);
  8253. #else
  8254. Sudo_Parameter_iso1_PreChargeRes();
  8255. #endif
  8256. //STEP 4: ============ Encode and Send Response Message ===========
  8257. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  8258. {
  8259. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]Tx encoded msg error");
  8260. errn = -1;
  8261. }
  8262. //STEP 5: ============ Update Flags ===========
  8263. return errn;
  8264. }
  8265. /*===========================================================================
  8266. FUNCTION: Proc_din_PreChargeReq
  8267. DESCRIPTION:
  8268. PRE-CONDITION:
  8269. INPUT:
  8270. OUTPUT:
  8271. GLOBAL VARIABLES:
  8272. =============================================================================*/
  8273. int Proc_din_PreChargeReq(int AcceptFd)
  8274. {
  8275. int errn = 0;
  8276. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]PreChargeReq\n");
  8277. //Print the decoded XML Document
  8278. PRINT_XML_DOC_DIN_PreChargeReq(&ccs_exi_doc_DIN);
  8279. //Save into Share Memory
  8280. SHM_Save_din_PreChargeReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  8281. //Check for EV Error Code
  8282. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PreChargeRequest.DC_EVStatus.EVErrorCode);
  8283. errn = Proc_din_PreChargeRes(AcceptFd);
  8284. if (errn == 0)
  8285. {
  8286. //send response successfully.
  8287. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]PreChargeRes\n");
  8288. }
  8289. else
  8290. {
  8291. sprintf((char*)buf_log_evcomm,
  8292. "[Error]Proc_iso1_PreChargeRes(): %d (DEC)",
  8293. errn);
  8294. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8295. }
  8296. return errn;
  8297. }
  8298. /*===========================================================================
  8299. FUNCTION: Proc_iso1_PreChargeReq
  8300. DESCRIPTION:
  8301. PRE-CONDITION:
  8302. INPUT:
  8303. OUTPUT:
  8304. GLOBAL VARIABLES:
  8305. =============================================================================*/
  8306. int Proc_iso1_PreChargeReq(int AcceptFd)
  8307. {
  8308. int errn = 0;
  8309. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]PreChargeReq\n");
  8310. //Print the decoded XML Document
  8311. PRINT_XML_DOC_ISO1_PreChargeReq(&ccs_exi_doc_ISO1);
  8312. //Save into Share Memory
  8313. SHM_Save_iso1_PreChargeReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  8314. //Check for EV Error Code
  8315. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PreChargeRequest.DC_EVStatus.EVErrorCode);
  8316. errn = Proc_iso1_PreChargeRes(AcceptFd);
  8317. if (errn == 0)
  8318. {
  8319. //send response successfully.
  8320. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]PreChargeRes\n");
  8321. }
  8322. else
  8323. {
  8324. sprintf((char*)buf_log_evcomm,
  8325. "[Error][SeccComm][Proc_iso1_PreChargeReq]Proc_iso1_PreChargeRes(): %d (DEC)",
  8326. errn);
  8327. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8328. }
  8329. return errn;
  8330. }
  8331. /*===========================================================================
  8332. FUNCTION: SHM_Init_din_PowerDeliveryRes
  8333. DESCRIPTION:
  8334. PRE-CONDITION:
  8335. INPUT:
  8336. 1. shm_ccs
  8337. OUTPUT:
  8338. 1. shm_ccs
  8339. GLOBAL VARIABLES:
  8340. =============================================================================*/
  8341. void SHM_Init_din_PowerDeliveryRes(struct CcsData *shm_ccs)
  8342. {
  8343. struct PowerDeliveryResponse_DIN70121 *in;
  8344. in = &shm_ccs->V2GMessage_DIN70121.PowerDeliveryResponse;
  8345. //----- [BODY (1/3)] ResponseCode -----
  8346. in->ResponseCode = dinresponseCodeType_OK;
  8347. //----- [BODY (2/3)] AC_EVSEStatus -----
  8348. //ignore, since DIN 70121 doesn't support AC, yet.
  8349. //----- [BODY (2/3)] DC_EVSEStatus -----
  8350. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  8351. }
  8352. /*===========================================================================
  8353. FUNCTION: Sudo_Parameter_din_PowerDeliveryRes
  8354. DESCRIPTION:
  8355. PRE-CONDITION:
  8356. INPUT:
  8357. OUTPUT:
  8358. GLOBAL VARIABLES:
  8359. =============================================================================*/
  8360. void Sudo_Parameter_din_PowerDeliveryRes()
  8361. {
  8362. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  8363. init_dinPowerDeliveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes);
  8364. ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  8365. //----- [BODY (1/3)] ResponseCode -----
  8366. struct dinPowerDeliveryResType *res;
  8367. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  8368. res->ResponseCode = dinresponseCodeType_OK;
  8369. //----- [BODY (2/3)] AC_EVSEStatus -----
  8370. //ignore, since DIN 70121 doesn't support AC, yet.
  8371. //----- [BODY (2/3)] DC_EVSEStatus -----
  8372. res->DC_EVSEStatus_isUsed = 1u;
  8373. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8374. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  8375. // dinisolationLevelType_Invalid = 0,
  8376. // dinisolationLevelType_Valid = 1,
  8377. // dinisolationLevelType_Warning = 2,
  8378. // dinisolationLevelType_Fault = 3
  8379. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8380. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8381. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  8382. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8383. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8384. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8385. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8386. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8387. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  8388. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  8389. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  8390. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  8391. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  8392. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8393. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  8394. // dinEVSENotificationType_None = 0,
  8395. // dinEVSENotificationType_StopCharging = 1,
  8396. // dinEVSENotificationType_ReNegotiation = 2
  8397. }
  8398. /*===========================================================================
  8399. FUNCTION: Sudo_Parameter_iso1_PowerDeliveryRes
  8400. DESCRIPTION:
  8401. PRE-CONDITION:
  8402. INPUT:
  8403. OUTPUT:
  8404. GLOBAL VARIABLES:
  8405. =============================================================================*/
  8406. void Sudo_Parameter_iso1_PowerDeliveryRes()
  8407. {
  8408. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8409. init_iso1PowerDeliveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes);
  8410. ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  8411. //----- [BODY (1/3)] ResponseCode -----
  8412. struct iso1PowerDeliveryResType *res;
  8413. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  8414. res->ResponseCode = iso1responseCodeType_OK;
  8415. //----- [BODY (2/3)] AC_EVSEStatus -----
  8416. //ignore, since our ISO1 70121 doesn't support AC, yet.
  8417. //----- [BODY (2/3)] DC_EVSEStatus -----
  8418. res->DC_EVSEStatus_isUsed = 1u;
  8419. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8420. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  8421. //iso1isolationLevelType_Invalid = 0,
  8422. //iso1isolationLevelType_Valid = 1,
  8423. //iso1isolationLevelType_Warning = 2,
  8424. //iso1isolationLevelType_Fault = 3,
  8425. //iso1isolationLevelType_No_IMD = 4
  8426. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8427. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8428. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8429. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8430. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8431. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8432. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8433. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8434. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8435. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8436. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8437. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8438. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8439. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8440. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8441. //iso1EVSENotificationType_None = 0,
  8442. //iso1EVSENotificationType_StopCharging = 1,
  8443. //iso1EVSENotificationType_ReNegotiation = 2
  8444. }
  8445. /*===========================================================================
  8446. FUNCTION: Proc_din_PowerDeliveryStartRes
  8447. DESCRIPTION:
  8448. PRE-CONDITION:
  8449. INPUT:
  8450. OUTPUT:
  8451. GLOBAL VARIABLES:
  8452. =============================================================================*/
  8453. int Proc_din_PowerDeliveryStartRes(int AcceptFd)
  8454. {
  8455. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8456. //if it is not the same, the packet should be ignored.
  8457. //STEP 1: ============ Initialize ============
  8458. //int i = 0;
  8459. int errn = 0;
  8460. bitstream_t v2g_tx_stream;
  8461. struct dinPowerDeliveryResType *res;
  8462. struct ChargingInfoData *sys;
  8463. size_t pos = 0;
  8464. v2g_tx_stream.pos = &pos;
  8465. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8466. v2g_tx_stream.data = V2GTP_Tx_buf;
  8467. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  8468. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8469. res->ResponseCode = OK_DIN70121;
  8470. //[HEADER] Check Req SessionID
  8471. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  8472. {
  8473. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  8474. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8475. errn = -1;
  8476. }
  8477. //Check for SequenceError
  8478. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8479. {
  8480. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  8481. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  8482. errn = -1;
  8483. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8484. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8485. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8486. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8487. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8488. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8489. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8490. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8491. }
  8492. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8493. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8494. #if PARAMETER_NORMAL_MODE == ENABLE
  8495. SHM_Read_din_PowerDeliveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  8496. #else
  8497. Sudo_Parameter_din_PowerDeliveryRes();
  8498. #endif
  8499. //EVSE Status Code
  8500. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  8501. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8502. //Check for CSU command of "Stop by EVSE"
  8503. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8504. {
  8505. //res->ResponseCode = FAILED_DIN70121;
  8506. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8507. }
  8508. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8509. {
  8510. //res->ResponseCode = FAILED_DIN70121;
  8511. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8512. }
  8513. else if (ShmInternalComm->ChargingPermission == FALSE)
  8514. {
  8515. //res->ResponseCode = FAILED_DIN70121;
  8516. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8517. }
  8518. //STEP 4: ============ Encode and Send Response Message ===========
  8519. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  8520. {
  8521. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_PowerDeliveryStartRes][Error]Tx encoded msg error");
  8522. errn = -1;
  8523. }
  8524. //STEP 5: ============ Update Flags ===========
  8525. return errn;
  8526. }
  8527. /*===========================================================================
  8528. FUNCTION: Proc_iso1_PowerDeliveryStartRes
  8529. DESCRIPTION:
  8530. PRE-CONDITION:
  8531. INPUT:
  8532. OUTPUT:
  8533. GLOBAL VARIABLES:
  8534. =============================================================================*/
  8535. int Proc_iso1_PowerDeliveryStartRes(int AcceptFd)
  8536. {
  8537. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8538. //if it is not the same, the packet should be ignored.
  8539. //STEP 1: ============ Initialize ============
  8540. //int i = 0;
  8541. int errn = 0;
  8542. bitstream_t v2g_tx_stream;
  8543. struct iso1PowerDeliveryResType *res;
  8544. struct ChargingInfoData *sys;
  8545. size_t pos = 0;
  8546. v2g_tx_stream.pos = &pos;
  8547. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8548. v2g_tx_stream.data = V2GTP_Tx_buf;
  8549. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  8550. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8551. res->ResponseCode = OK_ISO15118_2014;
  8552. //[HEADER] Check Req SessionID
  8553. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  8554. {
  8555. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  8556. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8557. errn = -1;
  8558. }
  8559. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8560. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8561. #if PARAMETER_NORMAL_MODE == ENABLE
  8562. SHM_Read_iso1_PowerDeliveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  8563. #else
  8564. Sudo_Parameter_iso1_PowerDeliveryRes();
  8565. #endif
  8566. //EVSE Status Code
  8567. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  8568. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8569. //Check for CSU command of "Stop by EVSE"
  8570. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8571. {
  8572. //res->ResponseCode = FAILED_ISO15118_2014;
  8573. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8574. }
  8575. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8576. {
  8577. //res->ResponseCode = FAILED_ISO15118_2014;
  8578. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8579. }
  8580. else if (ShmInternalComm->ChargingPermission == FALSE)
  8581. {
  8582. //res->ResponseCode = FAILED_ISO15118_2014;
  8583. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8584. }
  8585. //STEP 4: ============ Encode and Send Response Message ===========
  8586. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  8587. {
  8588. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_PowerDeliveryStartRes][Error]Tx encoded msg error");
  8589. errn = -1;
  8590. }
  8591. //STEP 5: ============ Update Flags ===========
  8592. return errn;
  8593. }
  8594. /*===========================================================================
  8595. FUNCTION: Proc_din_PowerDeliveryStartReq
  8596. DESCRIPTION:
  8597. PRE-CONDITION:
  8598. INPUT:
  8599. OUTPUT:
  8600. GLOBAL VARIABLES:
  8601. =============================================================================*/
  8602. int Proc_din_PowerDeliveryStartReq(int AcceptFd)
  8603. {
  8604. int errn = 0;
  8605. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PowerDeliveryStartReq");
  8606. //Print the decoded XML Document
  8607. PRINT_XML_DOC_DIN_PowerDeliveryReq(&ccs_exi_doc_DIN);
  8608. //Save into Share Memory
  8609. SHM_Save_din_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  8610. //Check for EV Error Code
  8611. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  8612. errn = Proc_din_PowerDeliveryStartRes(AcceptFd);
  8613. if (errn == 0)
  8614. {
  8615. //send response successfully.
  8616. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][TX]PowerDeliveryStartRes");
  8617. }
  8618. else
  8619. {
  8620. sprintf((char*)buf_log_evcomm,
  8621. "[Error][Proc_din_PowerDeliveryStartReq]Proc_iso1_PowerDeliveryStartRes(): %d (DEC)",
  8622. errn);
  8623. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8624. }
  8625. return errn;
  8626. }
  8627. /*===========================================================================
  8628. FUNCTION: Proc_iso1_PowerDeliveryStartReq
  8629. DESCRIPTION:
  8630. PRE-CONDITION:
  8631. INPUT:
  8632. OUTPUT:
  8633. GLOBAL VARIABLES:
  8634. =============================================================================*/
  8635. int Proc_iso1_PowerDeliveryStartReq(int AcceptFd)
  8636. {
  8637. int errn = 0;
  8638. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PowerDeliveryStartReq");
  8639. //Print the decoded XML Document
  8640. PRINT_XML_DOC_ISO1_PowerDeliveryReq(&ccs_exi_doc_ISO1);
  8641. //Save into Share Memory
  8642. SHM_Save_iso1_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  8643. //Check for EV Error Code
  8644. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  8645. errn = Proc_iso1_PowerDeliveryStartRes(AcceptFd);
  8646. if (errn == 0)
  8647. {
  8648. //send response successfully.
  8649. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]PowerDeliveryStartRes");
  8650. }
  8651. else
  8652. {
  8653. sprintf((char*)buf_log_evcomm,
  8654. "[Error][Proc_iso1_PowerDeliveryStartReq]Proc_iso1_PowerDeliveryStartRes(): %d (DEC)",
  8655. errn);
  8656. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8657. }
  8658. return errn;
  8659. }
  8660. /*===========================================================================
  8661. FUNCTION: SHM_Init_din_CurrentDemandRes
  8662. DESCRIPTION:
  8663. PRE-CONDITION:
  8664. INPUT:
  8665. 1. shm_ccs
  8666. OUTPUT:
  8667. 1. shm_ccs
  8668. GLOBAL VARIABLES:
  8669. =============================================================================*/
  8670. void SHM_Init_din_CurrentDemandRes(struct CcsData *shm_ccs)
  8671. {
  8672. struct CurrentDemandResponse_DIN70121 *in;
  8673. in = &shm_ccs->V2GMessage_DIN70121.CurrentDemandResponse;
  8674. //----- [BODY (1/10)] ResponseCode -----
  8675. in->ResponseCode = dinresponseCodeType_OK;
  8676. //----- [BODY (2/10)] DC_EVSEStatus -----
  8677. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  8678. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8679. short value = 0; int multiplier = 0; unsigned char unit = 0;
  8680. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for test only.
  8681. value = 0; multiplier = 0; unit = V_DIN70121;
  8682. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  8683. //----- [BODY (4/10)] EVSEPresentCurrent -----
  8684. //value = 600; multiplier = -1; unit = A_DIN70121; //60A, for test only.
  8685. value = 0; multiplier = 0; unit = A_DIN70121;
  8686. SHM_Save_dinPhysicalValueType(&in->EVSEPresentCurrent, value, multiplier, unit);
  8687. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  8688. in->EVSECurrentLimitAchieved = FALSE;
  8689. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  8690. in->EVSEVoltageLimitAchieved = FALSE;
  8691. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  8692. in->EVSEPowerLimitAchieved = FALSE;
  8693. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  8694. //value = 7500; multiplier = -1; unit = V_DIN70121; //750V
  8695. value = 5000; multiplier = -1; unit = V_DIN70121; //500V
  8696. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumVoltageLimit, value, multiplier, unit);
  8697. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  8698. value = 600; multiplier = -1; unit = A_DIN70121; //60A
  8699. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumCurrentLimit, value, multiplier, unit);
  8700. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  8701. value = 3000; multiplier = 1; unit = W_DIN70121; //30KW
  8702. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumPowerLimit, value, multiplier, unit);
  8703. }
  8704. /*===========================================================================
  8705. FUNCTION: Sudo_Parameter_din_CurrentDemandRes
  8706. DESCRIPTION:
  8707. PRE-CONDITION:
  8708. INPUT:
  8709. OUTPUT:
  8710. GLOBAL VARIABLES:
  8711. =============================================================================*/
  8712. void Sudo_Parameter_din_CurrentDemandRes()
  8713. {
  8714. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  8715. init_dinCurrentDemandResType(&ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes);
  8716. ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes_isUsed = 1u;
  8717. //----- [BODY (1/10)] ResponseCode -----
  8718. struct dinCurrentDemandResType *res;
  8719. res = &ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes;
  8720. res->ResponseCode = dinresponseCodeType_OK;
  8721. //----- [BODY (2/10)] DC_EVSEStatus -----
  8722. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8723. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  8724. // dinisolationLevelType_Invalid = 0,
  8725. // dinisolationLevelType_Valid = 1,
  8726. // dinisolationLevelType_Warning = 2,
  8727. // dinisolationLevelType_Fault = 3
  8728. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8729. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8730. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  8731. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8732. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8733. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8734. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8735. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8736. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  8737. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  8738. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  8739. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  8740. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  8741. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8742. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  8743. // dinEVSENotificationType_None = 0,
  8744. // dinEVSENotificationType_StopCharging = 1,
  8745. // dinEVSENotificationType_ReNegotiation = 2
  8746. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8747. res->EVSEPresentVoltage.Value = 3820;
  8748. res->EVSEPresentVoltage.Multiplier = -1;
  8749. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  8750. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  8751. //----- [BODY (4/10)] EVSEPresentCurrent -----
  8752. res->EVSEPresentCurrent.Value = 1200;
  8753. res->EVSEPresentCurrent.Multiplier = -1;
  8754. res->EVSEPresentCurrent.Unit_isUsed = 1u;
  8755. res->EVSEPresentCurrent.Unit = dinunitSymbolType_A;
  8756. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  8757. res->EVSECurrentLimitAchieved = 0;
  8758. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  8759. res->EVSEVoltageLimitAchieved = 0;
  8760. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  8761. res->EVSEPowerLimitAchieved = 0;
  8762. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  8763. res->EVSEMaximumVoltageLimit_isUsed = 1u;
  8764. res->EVSEMaximumVoltageLimit.Value = 7500;
  8765. res->EVSEMaximumVoltageLimit.Multiplier = -1;
  8766. res->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  8767. res->EVSEMaximumVoltageLimit.Unit = dinunitSymbolType_V;
  8768. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  8769. res->EVSEMaximumCurrentLimit_isUsed = 1u;
  8770. res->EVSEMaximumCurrentLimit.Value = 1200;
  8771. res->EVSEMaximumCurrentLimit.Multiplier = -1;
  8772. res->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  8773. res->EVSEMaximumCurrentLimit.Unit = dinunitSymbolType_A;
  8774. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  8775. res->EVSEMaximumPowerLimit_isUsed = 1u;
  8776. res->EVSEMaximumPowerLimit.Value = 6000;
  8777. res->EVSEMaximumPowerLimit.Multiplier = 1;
  8778. res->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  8779. res->EVSEMaximumPowerLimit.Unit = dinunitSymbolType_W;
  8780. }
  8781. /*===========================================================================
  8782. FUNCTION: Sudo_Parameter_iso1_CurrentDemandRes
  8783. DESCRIPTION:
  8784. PRE-CONDITION:
  8785. INPUT:
  8786. OUTPUT:
  8787. GLOBAL VARIABLES:
  8788. =============================================================================*/
  8789. void Sudo_Parameter_iso1_CurrentDemandRes()
  8790. {
  8791. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8792. init_iso1CurrentDemandResType(&ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes);
  8793. ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes_isUsed = 1u;
  8794. //----- [BODY (1/10)] ResponseCode -----
  8795. struct iso1CurrentDemandResType *res;
  8796. res = &ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes;
  8797. res->ResponseCode = iso1responseCodeType_OK;
  8798. //----- [BODY (2/10)] DC_EVSEStatus -----
  8799. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8800. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  8801. //iso1isolationLevelType_Invalid = 0,
  8802. //iso1isolationLevelType_Valid = 1,
  8803. //iso1isolationLevelType_Warning = 2,
  8804. //iso1isolationLevelType_Fault = 3,
  8805. //iso1isolationLevelType_No_IMD = 4
  8806. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8807. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8808. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8809. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8810. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8811. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8812. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8813. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8814. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8815. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8816. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8817. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8818. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8819. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8820. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8821. //iso1EVSENotificationType_None = 0,
  8822. //iso1EVSENotificationType_StopCharging = 1,
  8823. //iso1EVSENotificationType_ReNegotiation = 2
  8824. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8825. res->EVSEPresentVoltage.Value = 3820;
  8826. res->EVSEPresentVoltage.Multiplier = -1;
  8827. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  8828. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  8829. //----- [BODY (4/10)] EVSEPresentCurrent -----
  8830. res->EVSEPresentCurrent.Value = 1200;
  8831. res->EVSEPresentCurrent.Multiplier = -1;
  8832. //res->EVSEPresentCurrent.Unit_isUsed = 1u;
  8833. res->EVSEPresentCurrent.Unit = iso1unitSymbolType_A;
  8834. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  8835. res->EVSECurrentLimitAchieved = 0;
  8836. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  8837. res->EVSEVoltageLimitAchieved = 0;
  8838. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  8839. res->EVSEPowerLimitAchieved = 0;
  8840. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  8841. res->EVSEMaximumVoltageLimit_isUsed = 1u;
  8842. res->EVSEMaximumVoltageLimit.Value = 7500;
  8843. res->EVSEMaximumVoltageLimit.Multiplier = -1;
  8844. //res->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  8845. res->EVSEMaximumVoltageLimit.Unit = iso1unitSymbolType_V;
  8846. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  8847. res->EVSEMaximumCurrentLimit_isUsed = 1u;
  8848. res->EVSEMaximumCurrentLimit.Value = 1200;
  8849. res->EVSEMaximumCurrentLimit.Multiplier = -1;
  8850. //res->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  8851. res->EVSEMaximumCurrentLimit.Unit = iso1unitSymbolType_A;
  8852. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  8853. res->EVSEMaximumPowerLimit_isUsed = 1u;
  8854. res->EVSEMaximumPowerLimit.Value = 6000;
  8855. res->EVSEMaximumPowerLimit.Multiplier = 1;
  8856. //res->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  8857. res->EVSEMaximumPowerLimit.Unit = iso1unitSymbolType_W;
  8858. }
  8859. /*===========================================================================
  8860. FUNCTION: Sudo_Parameter_iso1_ChargingStatusRes
  8861. DESCRIPTION:
  8862. PRE-CONDITION:
  8863. INPUT:
  8864. OUTPUT:
  8865. GLOBAL VARIABLES:
  8866. =============================================================================*/
  8867. void Sudo_Parameter_iso1_ChargingStatusRes()
  8868. {
  8869. //int i = 0;
  8870. struct iso1ChargingStatusResType *res;
  8871. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8872. init_iso1ChargingStatusResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes);
  8873. res = &ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes;
  8874. ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes_isUsed = 1u;
  8875. //----- [BODY (1/10)] ResponseCode -----
  8876. res->ResponseCode = OK_ISO15118_2014;
  8877. //----- [BODY (2/10)] AC_EVSEStatus -----
  8878. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  8879. res->AC_EVSEStatus.NotificationMaxDelay = 0;
  8880. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8881. // iso1EVSENotificationType_None = 0,
  8882. // iso1EVSENotificationType_StopCharging = 1,
  8883. // iso1EVSENotificationType_ReNegotiation = 2
  8884. //----- [BODY (3/10)] EVSEMaxCurrent -----
  8885. res->EVSEMaxCurrent_isUsed = 1u;
  8886. res->EVSEMaxCurrent.Value = 32;
  8887. res->EVSEMaxCurrent.Multiplier = 0;
  8888. res->EVSEMaxCurrent.Unit = iso1unitSymbolType_A;
  8889. //----- [BODY (4/10)] SAScheduleTupleID -----
  8890. res->SAScheduleTupleID = 0;
  8891. //----- [BODY (5/10)] EVSEID -----
  8892. res->EVSEID.charactersLen = 37;
  8893. memset(res->EVSEID.characters, 0, sizeof(res->EVSEID.characters));
  8894. //sprintf((char*)res->EVSEID.characters, CCS_AC_EVSEID);
  8895. //----- [BODY (6/10)] MeterInfo -----
  8896. res->MeterInfo_isUsed = 1u;
  8897. memset(res->MeterInfo.MeterID.characters, 0, sizeof(res->MeterInfo.MeterID.characters));
  8898. memset(res->MeterInfo.SigMeterReading.bytes, 0, sizeof(res->MeterInfo.SigMeterReading.bytes));
  8899. //[MeterInfo][1/5] MeterID
  8900. //sprintf((char*)res->MeterInfo.MeterID , CCS_AC_METER_ID);
  8901. //[MeterInfo][2/5] SigMeterReading (optional)
  8902. //sprintf((char*)res->MeterInfo.SigMeterReading , CCS_AC_SIG_METER_READING);
  8903. //[MeterInfo][3/5] MeterStatus (optional)
  8904. res->MeterInfo.MeterStatus = 0;
  8905. //[MeterInfo][4/5] MeterReading (optional)
  8906. res->MeterInfo.MeterReading = 12345;
  8907. //[MeterInfo][5/5] TMeter (optional)
  8908. res->MeterInfo.TMeter = 1586243587; //Unix Time Stamp format
  8909. //----- [BODY (7/10)] ReceiptRequired -----
  8910. res->ReceiptRequired_isUsed = 1u;
  8911. res->ReceiptRequired = FALSE; //optional
  8912. }
  8913. /*===========================================================================
  8914. FUNCTION: Check_EVErrorCode
  8915. DESCRIPTION:
  8916. PRE-CONDITION:
  8917. INPUT:
  8918. OUTPUT:
  8919. GLOBAL VARIABLES:
  8920. =============================================================================*/
  8921. void Check_EVErrorCode(int code)
  8922. {
  8923. if (code != NO_ERROR) //NO_ERROR = 0
  8924. {
  8925. //Asking CSU to Stop
  8926. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8927. //Update_V2G_Flow_Status(Other_Fault);
  8928. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  8929. sprintf((char*)buf_log_evcomm,
  8930. "Stop by EV (EVErrorCode = %d (DEC))",
  8931. code);
  8932. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8933. }
  8934. }
  8935. /*===========================================================================
  8936. FUNCTION: Proc_din_CurrentDemandRes
  8937. DESCRIPTION:
  8938. PRE-CONDITION:
  8939. INPUT:
  8940. OUTPUT:
  8941. GLOBAL VARIABLES:
  8942. =============================================================================*/
  8943. int Proc_din_CurrentDemandRes(int AcceptFd)
  8944. {
  8945. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8946. //if it is not the same, the packet should be ignored.
  8947. //STEP 1: ============ Initialize ============
  8948. int errn = 0;
  8949. bitstream_t v2g_tx_stream;
  8950. static struct CurrentDemandResponse_DIN70121 *cur;
  8951. static struct ChargingInfoData *sys;
  8952. // int i = 0;
  8953. // static int EVSE_max_current;
  8954. // int tmp = 0;
  8955. size_t pos = 0;
  8956. v2g_tx_stream.pos = &pos;
  8957. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8958. v2g_tx_stream.data = V2GTP_Tx_buf;
  8959. cur = &ShmCcsData->V2GMessage_DIN70121.CurrentDemandResponse;
  8960. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8961. cur->ResponseCode = OK_DIN70121;
  8962. //EVSE Status Code
  8963. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8964. //[HEADER] Check Req SessionID
  8965. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  8966. {
  8967. cur->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  8968. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8969. errn = -1;
  8970. }
  8971. //Check for SequenceError
  8972. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8973. {
  8974. cur->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  8975. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  8976. errn = -1;
  8977. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8978. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8979. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8980. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8981. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8982. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8983. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8984. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8985. }
  8986. //Check for negative EvBatteryMaxCurrent
  8987. if (sys->EvBatteryMaxCurrent < 0)
  8988. {
  8989. sprintf((char*)buf_log_evcomm,
  8990. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  8991. sys->EvBatteryMaxCurrent);
  8992. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8993. cur->DC_EVSEStatus.EVSEStatusCode = dinresponseCodeType_FAILED_WrongChargeParameter; //16
  8994. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8995. errn = -1;
  8996. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8997. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  8998. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8999. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9000. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9001. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9002. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  9003. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  9004. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9005. }
  9006. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9007. SAVE_PhysicalValueType_DIN70121(&cur->EVSEPresentCurrent, (int) (sys->PresentChargingCurrent * 10), A_DIN70121);
  9008. SAVE_PhysicalValueType_DIN70121(&cur->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  9009. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == DISABLE
  9010. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_DIN70121);
  9011. #endif
  9012. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_DIN70121);
  9013. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_DIN70121);
  9014. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  9015. if (sys->EvBatteryMaxVoltage <= 500)
  9016. {
  9017. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumVoltageLimit, (int) (500 * 10), V_DIN70121); //500V
  9018. }
  9019. #endif
  9020. //Limit the EVTargetCurrent should be under EVSEMaximumCurrentLimit
  9021. if (sys->EvBatterytargetCurrent > sys->AvailableChargingCurrent)
  9022. {
  9023. sys->EvBatterytargetCurrent = sys->AvailableChargingCurrent;
  9024. //[To-Do] Limit is achieved flag
  9025. }
  9026. //Isolation Status
  9027. if (sys->IsolationStatus == GFD_Invalid) //0:invalid (on going)
  9028. {
  9029. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  9030. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9031. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9032. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_CurrentDemandRes]IsolationStatus = %d", sys->IsolationStatus);
  9033. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9034. Update_V2G_Flow_Status(Other_Fault);
  9035. errn = -1;
  9036. }
  9037. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  9038. {
  9039. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  9040. }
  9041. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  9042. {
  9043. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  9044. }
  9045. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  9046. {
  9047. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  9048. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9049. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9050. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_CurrentDemandRes]GFD_Fault => Emergency Shutdown");
  9051. Update_V2G_Flow_Status(Other_Fault);
  9052. errn = -1;
  9053. }
  9054. else //GFD_No_IMD or other unexpected status
  9055. {
  9056. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  9057. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9058. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9059. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_CurrentDemandRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9060. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9061. Update_V2G_Flow_Status(Other_Fault);
  9062. errn = -1;
  9063. }
  9064. //For testing with Tesla Model 3
  9065. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == ENABLE
  9066. //[CAUTION][To-Do] Decresement of Current is not implemented.
  9067. //SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumCurrentLimit, 10, A_DIN70121);
  9068. if (sys->EvBatterytargetCurrent <= 0)
  9069. {
  9070. EVSE_max_current = 50; //10A
  9071. cur->EVSEMaximumCurrentLimit.Value = 50; //10A
  9072. /*
  9073. DEBUG_PRINTF_EVCOMM_DETAIL("1PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9074. sys->PresentChargingCurrent,
  9075. sys->EvBatterytargetCurrent,
  9076. EVSE_max_current,
  9077. cur->EVSEMaximumCurrentLimit.Value
  9078. );
  9079. */
  9080. }
  9081. else //1A
  9082. {
  9083. /*
  9084. DEBUG_PRINTF_EVCOMM_DETAIL("2PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9085. sys->PresentChargingCurrent,
  9086. sys->EvBatterytargetCurrent,
  9087. EVSE_max_current,
  9088. cur->EVSEMaximumCurrentLimit.Value
  9089. );
  9090. */
  9091. if ((abs((int)sys->PresentChargingCurrent - (int)sys->EvBatterytargetCurrent) < 3)&&(abs((int)(EVSE_max_current/10) - (int)sys->EvBatterytargetCurrent) < 3))
  9092. {
  9093. tmp = EVSE_max_current + 50; //10A
  9094. if (tmp <= (int)(sys->AvailableChargingCurrent * 10))
  9095. {
  9096. cur->EVSEMaximumCurrentLimit.Value = (int)tmp;
  9097. EVSE_max_current = tmp;
  9098. }
  9099. else
  9100. {
  9101. cur->EVSEMaximumCurrentLimit.Value = (int) (sys->AvailableChargingCurrent * 10); //max is set to 40A
  9102. EVSE_max_current = (int) (sys->AvailableChargingCurrent * 10);
  9103. }
  9104. }
  9105. }
  9106. #endif
  9107. //Check for CSU command of "Stop by EVSE"
  9108. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9109. {
  9110. //Check for Alarm Code: CCS GFD trip (012235)
  9111. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9112. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9113. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9114. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9115. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9116. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9117. {
  9118. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]CCS GFD trip => EVSE_Shutdown");
  9119. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  9120. }
  9121. else
  9122. {
  9123. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]EVSE_Shutdown");
  9124. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9125. }
  9126. //cur->ResponseCode = FAILED_DIN70121;
  9127. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9128. //errn = -1;
  9129. }
  9130. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9131. {
  9132. //Check for Alarm Code: CCS GFD trip (012235)
  9133. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9134. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9135. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9136. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9137. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9138. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9139. {
  9140. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]CCS GFD trip => EVSE_EmergencyShutdown");
  9141. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  9142. }
  9143. else
  9144. {
  9145. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]EVSE_EmergencyShutdown");
  9146. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9147. }
  9148. //cur->ResponseCode = FAILED_DIN70121;
  9149. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9150. //errn = -1;
  9151. }
  9152. else if (ShmInternalComm->ChargingPermission == FALSE)
  9153. {
  9154. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]Permission OFF");
  9155. //cur->ResponseCode = FAILED_DIN70121;
  9156. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9157. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9158. //errn = -1;
  9159. }
  9160. else
  9161. {
  9162. //null
  9163. }
  9164. //Response to CP Error
  9165. #if CP_PROTECTION_MECHANISM == ENABLE
  9166. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9167. {
  9168. cur->ResponseCode = FAILED_DIN70121;
  9169. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9170. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9171. Update_V2G_Flow_Status(Other_Fault);
  9172. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9173. //CCS_SECC_CP_State_Error (023889)
  9174. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9175. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9176. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9177. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9178. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9179. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9180. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9181. sprintf((char*)buf_log_evcomm,
  9182. "[CurrentDemand]Emergency Stop by CP Error (%d, %.02f V)",
  9183. sys->CpState,
  9184. sys->CpVoltage);
  9185. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9186. }
  9187. #endif
  9188. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9189. #if PARAMETER_NORMAL_MODE == ENABLE
  9190. SHM_Read_din_CurrentDemandRes(&ccs_exi_doc_DIN, ShmCcsData);
  9191. #else
  9192. Sudo_Parameter_din_CurrentDemandRes();
  9193. #endif
  9194. //STEP 4: ============ Encode and Send Response Message ===========
  9195. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  9196. {
  9197. errn = -1;
  9198. }
  9199. //STEP 5: ============ Update Flags ===========
  9200. return errn;
  9201. }
  9202. /*===========================================================================
  9203. FUNCTION: Proc_iso1_CurrentDemandRes
  9204. DESCRIPTION:
  9205. PRE-CONDITION:
  9206. INPUT:
  9207. OUTPUT:
  9208. GLOBAL VARIABLES:
  9209. =============================================================================*/
  9210. int Proc_iso1_CurrentDemandRes(int AcceptFd)
  9211. {
  9212. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9213. //if it is not the same, the packet should be ignored.
  9214. //STEP 1: ============ Initialize ============
  9215. int errn = 0;
  9216. bitstream_t v2g_tx_stream;
  9217. static struct CurrentDemandResponse_ISO15118_2014 *cur;
  9218. static struct ChargingInfoData *sys;
  9219. // int i = 0;
  9220. // static int EVSE_max_current;
  9221. // int tmp = 0;
  9222. size_t pos = 0;
  9223. v2g_tx_stream.pos = &pos;
  9224. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9225. v2g_tx_stream.data = V2GTP_Tx_buf;
  9226. cur = &ShmCcsData->V2GMessage_ISO15118_2014.CurrentDemandResponse;
  9227. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9228. cur->ResponseCode = OK_ISO15118_2014;
  9229. //EVSE Status Code
  9230. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  9231. //[HEADER] Check Req SessionID
  9232. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9233. {
  9234. cur->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9235. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9236. errn = -1;
  9237. }
  9238. //Check for SequenceError
  9239. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9240. {
  9241. cur->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  9242. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9243. errn = -1;
  9244. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9245. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9246. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9247. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9248. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9249. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9250. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9251. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9252. }
  9253. //Check for negative EvBatteryMaxCurrent
  9254. if (sys->EvBatteryMaxCurrent < 0)
  9255. {
  9256. sprintf((char*)buf_log_evcomm,
  9257. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  9258. sys->EvBatteryMaxCurrent);
  9259. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9260. cur->ResponseCode = iso1responseCodeType_FAILED_WrongChargeParameter; //16
  9261. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9262. errn = -1;
  9263. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9264. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  9265. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9266. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9267. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9268. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9269. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  9270. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  9271. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9272. }
  9273. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9274. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEPresentCurrent, (int) (sys->PresentChargingCurrent * 10), A_ISO15118_2014);
  9275. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  9276. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == DISABLE
  9277. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  9278. #endif
  9279. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_ISO15118_2014);
  9280. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_ISO15118_2014);
  9281. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  9282. if (sys->EvBatteryMaxVoltage <= 500)
  9283. {
  9284. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumVoltageLimit, (int) (500 * 10), V_ISO15118_2014); //500V
  9285. }
  9286. #endif
  9287. //Limit the EVTargetCurrent should be under EVSEMaximumCurrentLimit
  9288. if (sys->EvBatterytargetCurrent > sys->AvailableChargingCurrent)
  9289. {
  9290. sys->EvBatterytargetCurrent = sys->AvailableChargingCurrent;
  9291. //[To-Do] Limit is achieved flag
  9292. }
  9293. //Isolation Status
  9294. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  9295. {
  9296. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  9297. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9298. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9299. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_CurrentDemandRes]IsolationStatus = %d", sys->IsolationStatus);
  9300. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9301. Update_V2G_Flow_Status(Other_Fault);
  9302. errn = -1;
  9303. }
  9304. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  9305. {
  9306. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  9307. }
  9308. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  9309. {
  9310. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  9311. }
  9312. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  9313. {
  9314. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  9315. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9316. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9317. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_CurrentDemandRes]GFD_Fault => EmergencyShutdown");
  9318. Update_V2G_Flow_Status(Other_Fault);
  9319. errn = -1;
  9320. }
  9321. else
  9322. {
  9323. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  9324. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9325. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9326. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_CurrentDemandRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9327. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9328. Update_V2G_Flow_Status(Other_Fault);
  9329. errn = -1;
  9330. }
  9331. //For testing with Tesla Model 3
  9332. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == ENABLE
  9333. //[CAUTION][To-Do] Decresement of Current is not implemented.
  9334. //SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumCurrentLimit, 10, A_ISO15118_2014);
  9335. if (sys->EvBatterytargetCurrent <= 0)
  9336. {
  9337. EVSE_max_current = 50; //10A
  9338. cur->EVSEMaximumCurrentLimit.Value = 50; //10A
  9339. /*
  9340. DEBUG_PRINTF_EVCOMM_DETAIL("1PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9341. sys->PresentChargingCurrent,
  9342. sys->EvBatterytargetCurrent,
  9343. EVSE_max_current,
  9344. cur->EVSEMaximumCurrentLimit.Value
  9345. );
  9346. */
  9347. }
  9348. else //1A
  9349. {
  9350. /*
  9351. DEBUG_PRINTF_EVCOMM_DETAIL("2PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9352. sys->PresentChargingCurrent,
  9353. sys->EvBatterytargetCurrent,
  9354. EVSE_max_current,
  9355. cur->EVSEMaximumCurrentLimit.Value
  9356. );
  9357. */
  9358. if ((abs((int)sys->PresentChargingCurrent - (int)sys->EvBatterytargetCurrent) < 3)&&(abs((int)(EVSE_max_current/10) - (int)sys->EvBatterytargetCurrent) < 3))
  9359. {
  9360. tmp = EVSE_max_current + 50; //10A
  9361. if (tmp <= (int)(sys->AvailableChargingCurrent * 10))
  9362. {
  9363. cur->EVSEMaximumCurrentLimit.Value = (int)tmp;
  9364. EVSE_max_current = tmp;
  9365. }
  9366. else
  9367. {
  9368. cur->EVSEMaximumCurrentLimit.Value = (int) (sys->AvailableChargingCurrent * 10); //max is set to 40A
  9369. EVSE_max_current = (int) (sys->AvailableChargingCurrent * 10);
  9370. }
  9371. }
  9372. }
  9373. #endif
  9374. //Check for CSU command of "Stop by EVSE"
  9375. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9376. {
  9377. //Check for Alarm Code: CCS GFD trip (012235)
  9378. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9379. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9380. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9381. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9382. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9383. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9384. {
  9385. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][CurrentDemandRes]CCS GFD trip => EVSE_Shutdown");
  9386. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  9387. }
  9388. else
  9389. {
  9390. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][CurrentDemandRes]EVSE_Shutdown");
  9391. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9392. }
  9393. //cur->ResponseCode = FAILED_ISO15118_2014;
  9394. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9395. //errn = -1;
  9396. }
  9397. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9398. {
  9399. //Check for Alarm Code: CCS GFD trip (012235)
  9400. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9401. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9402. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9403. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9404. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9405. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9406. {
  9407. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][CurrentDemandRes]CCS GFD trip => EVSE_EmergencyShutdown");
  9408. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  9409. }
  9410. else
  9411. {
  9412. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][CurrentDemandRes]EVSE_EmergencyShutdown");
  9413. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9414. }
  9415. //cur->ResponseCode = FAILED_ISO15118_2014;
  9416. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9417. //errn = -1;
  9418. }
  9419. else if (ShmInternalComm->ChargingPermission == FALSE)
  9420. {
  9421. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][CurrentDemandRes]Permission OFF");
  9422. //cur->ResponseCode = FAILED_ISO15118_2014;
  9423. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9424. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9425. //errn = -1;
  9426. }
  9427. else
  9428. {
  9429. //null
  9430. }
  9431. //Response to CP Error
  9432. #if CP_PROTECTION_MECHANISM == ENABLE
  9433. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9434. {
  9435. cur->ResponseCode = FAILED_ISO15118_2014;
  9436. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9437. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9438. Update_V2G_Flow_Status(Other_Fault);
  9439. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9440. //CCS_SECC_CP_State_Error (023889)
  9441. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9442. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9443. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9444. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9445. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9446. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9447. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9448. sprintf((char*)buf_log_evcomm,
  9449. "[CurrentDemand]Emergency Stop by CP Error (%d, %.02f V)",
  9450. sys->CpState,
  9451. sys->CpVoltage);
  9452. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9453. }
  9454. #endif
  9455. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9456. #if PARAMETER_NORMAL_MODE == ENABLE
  9457. SHM_Read_iso1_CurrentDemandRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9458. #else
  9459. Sudo_Parameter_iso1_CurrentDemandRes();
  9460. #endif
  9461. //STEP 4: ============ Encode and Send Response Message ===========
  9462. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9463. {
  9464. errn = -1;
  9465. }
  9466. //STEP 5: ============ Update Flags ===========
  9467. return errn;
  9468. }
  9469. /*===========================================================================
  9470. FUNCTION: Proc_iso1_ChargingStatusRes
  9471. DESCRIPTION:
  9472. PRE-CONDITION:
  9473. INPUT:
  9474. OUTPUT:
  9475. GLOBAL VARIABLES:
  9476. =============================================================================*/
  9477. int Proc_iso1_ChargingStatusRes(int AcceptFd)
  9478. {
  9479. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9480. //if it is not the same, the packet should be ignored.
  9481. //STEP 1: ============ Initialize ============
  9482. //int i = 0;
  9483. int errn = 0;
  9484. bitstream_t v2g_tx_stream;
  9485. static struct ChargingStatusResponse_ISO15118_2014 *res;
  9486. static struct ChargingInfoData *sys;
  9487. size_t pos = 0;
  9488. v2g_tx_stream.pos = &pos;
  9489. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9490. v2g_tx_stream.data = V2GTP_Tx_buf;
  9491. res = &ShmCcsData->V2GMessage_ISO15118_2014.ChargingStatusResponse;
  9492. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9493. //Init
  9494. res->ResponseCode = OK_ISO15118_2014;
  9495. res->ReceiptRequired = FALSE; //optional
  9496. res->SAScheduleTupleID = 0;
  9497. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  9498. res->AC_EVSEStatus.NotificationMaxDelay = 0;
  9499. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9500. // iso1EVSENotificationType_None = 0,
  9501. // iso1EVSENotificationType_StopCharging = 1,
  9502. // iso1EVSENotificationType_ReNegotiation = 2
  9503. //[HEADER] Check Req SessionID
  9504. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9505. {
  9506. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9507. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9508. errn = -1;
  9509. }
  9510. //Check for SequenceError
  9511. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9512. {
  9513. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  9514. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9515. errn = -1;
  9516. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9517. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9518. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9519. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9520. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9521. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9522. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9523. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9524. }
  9525. //EVSE ID
  9526. memset(res->EVSEID, 0, sizeof(res->EVSEID));
  9527. //sprintf((char*)res->EVSEID, CCS_AC_EVSEID);
  9528. //[MeterInfo][0/5] init
  9529. //memset(res->MeterInfo.MeterID.characters, 0, sizeof(res->MeterInfo.MeterID.characters));
  9530. //memset(res->MeterInfo.SigMeterReading.bytes, 0, sizeof(res->MeterInfo.SigMeterReading.bytes));
  9531. //[MeterInfo][1/5] MeterID
  9532. //sprintf((char*)res->MeterInfo.MeterID , CCS_AC_METER_ID);
  9533. //[MeterInfo][2/5] SigMeterReading (optional)
  9534. //sprintf((char*)res->MeterInfo.SigMeterReading , CCS_AC_SIG_METER_READING);
  9535. //[MeterInfo][3/5] MeterStatus (optional)
  9536. res->MeterInfo.MeterStatus = 0;
  9537. //[MeterInfo][4/5] MeterReading (optional)
  9538. res->MeterInfo.MeterReading = 12345;
  9539. //[MeterInfo][5/5] TMeter (optional)
  9540. res->MeterInfo.TMeter = 1586243587; //Unix Time Stamp format
  9541. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9542. SAVE_PhysicalValueType_ISO15118_2014(&res->EVSEMaxCurrent, (int)(sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  9543. //Isolation Status (RCD)
  9544. if (sys->IsolationStatus == 0) //Isolation is invalid
  9545. {
  9546. res->AC_EVSEStatus.RCD = TRUE; //FALSE(no error), TRUE(error is detected)
  9547. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9548. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9549. sprintf((char*)buf_log_evcomm, "[Error][ChargingStatusRes]IsolationStatus = %d", sys->IsolationStatus);
  9550. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9551. Update_V2G_Flow_Status(Other_Fault);
  9552. errn = -1;
  9553. }
  9554. else if (sys->IsolationStatus == 1) //Isolation is valid
  9555. {
  9556. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  9557. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9558. }
  9559. else
  9560. {
  9561. res->AC_EVSEStatus.RCD = TRUE; //FALSE(no error), TRUE(error is detected)
  9562. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9563. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9564. sprintf((char*)buf_log_evcomm, "[Error][ChargingStatusRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9565. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9566. Update_V2G_Flow_Status(Other_Fault);
  9567. errn = -1;
  9568. }
  9569. //Check for CSU command of "Stop by EVSE"
  9570. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9571. {
  9572. //res->ResponseCode = FAILED_ISO15118_2014;
  9573. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9574. //errn = -1;
  9575. }
  9576. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9577. {
  9578. //res->ResponseCode = FAILED_ISO15118_2014;
  9579. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9580. //errn = -1;
  9581. }
  9582. else if (ShmInternalComm->ChargingPermission == FALSE)
  9583. {
  9584. //res->ResponseCode = FAILED_ISO15118_2014;
  9585. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9586. //errn = -1;
  9587. }
  9588. //Response to CP Error
  9589. #if CP_PROTECTION_MECHANISM == ENABLE
  9590. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9591. {
  9592. res->ResponseCode = FAILED_ISO15118_2014;
  9593. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9594. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9595. Update_V2G_Flow_Status(Other_Fault);
  9596. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9597. //CCS_SECC_CP_State_Error (023889)
  9598. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9599. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9600. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9601. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9602. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9603. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9604. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9605. sprintf((char*)buf_log_evcomm,
  9606. "[ChargingStatus]Emergency Stop by CP Error (%d, %.02f V)",
  9607. sys->CpState,
  9608. sys->CpVoltage);
  9609. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9610. }
  9611. #endif
  9612. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9613. #if PARAMETER_NORMAL_MODE == ENABLE
  9614. SHM_Read_iso1_ChargingStatusRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9615. #else
  9616. Sudo_Parameter_iso1_ChargingStatusRes();
  9617. #endif
  9618. //STEP 4: ============ Encode and Send Response Message ===========
  9619. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9620. {
  9621. errn = -1;
  9622. }
  9623. //STEP 5: ============ Update Flags ===========
  9624. return errn;
  9625. }
  9626. /*===========================================================================
  9627. FUNCTION: Proc_din_CurrentDemandReq
  9628. DESCRIPTION:
  9629. PRE-CONDITION:
  9630. INPUT:
  9631. OUTPUT:
  9632. GLOBAL VARIABLES:
  9633. =============================================================================*/
  9634. int Proc_din_CurrentDemandReq(int AcceptFd)
  9635. {
  9636. int errn = 0;
  9637. SAVE_SYS_LOG_MSG_EVCOMM("[V2G[RX]]CurrentDemandReq\n");
  9638. //Print the decoded XML Document
  9639. PRINT_XML_DOC_DIN_CurrentDemandReq(&ccs_exi_doc_DIN);
  9640. //Save into Share Memory
  9641. SHM_Save_din_CurrentDemandReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  9642. //Check for EV Error Code
  9643. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.CurrentDemandRequest.DC_EVStatus.EVErrorCode);
  9644. errn = Proc_din_CurrentDemandRes(AcceptFd);
  9645. if (errn == 0)
  9646. {
  9647. //Response is sent successfully.
  9648. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]CurrentDemandRes\n");
  9649. }
  9650. else
  9651. {
  9652. sprintf((char*)buf_log_evcomm,
  9653. "[Error]CurrentDemandRes: fail(%d,DEC)",
  9654. errn);
  9655. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9656. }
  9657. return errn;
  9658. }
  9659. /*===========================================================================
  9660. FUNCTION: Proc_iso1_CurrentDemandReq
  9661. DESCRIPTION:
  9662. PRE-CONDITION:
  9663. INPUT:
  9664. OUTPUT:
  9665. GLOBAL VARIABLES:
  9666. =============================================================================*/
  9667. int Proc_iso1_CurrentDemandReq(int AcceptFd)
  9668. {
  9669. int errn = 0;
  9670. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]CurrentDemandReq\n");
  9671. //Print the decoded XML Document
  9672. PRINT_XML_DOC_ISO1_CurrentDemandReq(&ccs_exi_doc_ISO1);
  9673. //Save into Share Memory
  9674. SHM_Save_iso1_CurrentDemandReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9675. //Check for EV Error Code
  9676. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.CurrentDemandRequest.DC_EVStatus.EVErrorCode);
  9677. errn = Proc_iso1_CurrentDemandRes(AcceptFd);
  9678. if (errn == 0)
  9679. {
  9680. //Response is sent successfully.
  9681. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]CurrentDemandRes\n");
  9682. }
  9683. else
  9684. {
  9685. sprintf((char*)buf_log_evcomm,
  9686. "[Error]CurrentDemandRes: fail(%d,DEC)",
  9687. errn);
  9688. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9689. }
  9690. return errn;
  9691. }
  9692. /*===========================================================================
  9693. FUNCTION: Proc_iso1_ChargingStatusReq
  9694. DESCRIPTION:
  9695. PRE-CONDITION:
  9696. INPUT:
  9697. OUTPUT:
  9698. GLOBAL VARIABLES:
  9699. =============================================================================*/
  9700. int Proc_iso1_ChargingStatusReq(int AcceptFd)
  9701. {
  9702. int errn = 0;
  9703. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]Got ChargingStatusReq\n");
  9704. //Print the decoded XML Document
  9705. PRINT_XML_DOC_ISO1_ChargingStatusReq(&ccs_exi_doc_ISO1);
  9706. //Save into Share Memory
  9707. SHM_Save_iso1_ChargingStatusReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9708. //Check for EV Error Code
  9709. //no content in ISO1
  9710. errn = Proc_iso1_ChargingStatusRes(AcceptFd);
  9711. if (errn == 0)
  9712. {
  9713. //Response is sent successfully.
  9714. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ChargingStatusRes\n");
  9715. }
  9716. else
  9717. {
  9718. sprintf((char*)buf_log_evcomm,
  9719. "[Error]ChargingStatusRes: fail(%d,DEC)",
  9720. errn);
  9721. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9722. }
  9723. return errn;
  9724. }
  9725. /*===========================================================================
  9726. FUNCTION: Proc_din_PowerDeliveryStopRes
  9727. DESCRIPTION:
  9728. PRE-CONDITION:
  9729. INPUT:
  9730. OUTPUT:
  9731. GLOBAL VARIABLES:
  9732. =============================================================================*/
  9733. int Proc_din_PowerDeliveryStopRes(int AcceptFd)
  9734. {
  9735. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9736. //if it is not the same, the packet should be ignored.
  9737. //STEP 1: ============ Initialize ============
  9738. //int i = 0;
  9739. int errn = 0;
  9740. bitstream_t v2g_tx_stream;
  9741. struct dinPowerDeliveryResType *res;
  9742. struct ChargingInfoData *sys;
  9743. size_t pos = 0;
  9744. v2g_tx_stream.pos = &pos;
  9745. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9746. v2g_tx_stream.data = V2GTP_Tx_buf;
  9747. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  9748. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9749. res->ResponseCode = OK_DIN70121;
  9750. //[HEADER] Check Req SessionID
  9751. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  9752. {
  9753. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  9754. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9755. errn = -1;
  9756. }
  9757. //Check for SequenceError
  9758. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9759. {
  9760. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  9761. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9762. errn = -1;
  9763. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9764. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9765. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9766. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9767. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9768. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9769. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9770. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9771. }
  9772. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9773. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9774. #if PARAMETER_NORMAL_MODE == ENABLE
  9775. ShmCcsData->V2GMessage_DIN70121.PowerDeliveryResponse.DC_EVSEStatus.EVSEStatusCode = EVSE_NotReady;
  9776. SHM_Read_din_PowerDeliveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  9777. #else
  9778. Sudo_Parameter_din_PreChargeRes();
  9779. #endif
  9780. //EVSE Status Code
  9781. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  9782. //Check for CSU command of "Stop by EVSE"
  9783. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9784. {
  9785. //res->ResponseCode = FAILED_DIN70121;
  9786. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9787. }
  9788. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9789. {
  9790. //res->ResponseCode = FAILED_DIN70121;
  9791. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9792. }
  9793. else if (ShmInternalComm->ChargingPermission == FALSE)
  9794. {
  9795. //res->ResponseCode = FAILED_DIN70121;
  9796. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9797. }
  9798. //STEP 4: ============ Encode and Send Response Message ===========
  9799. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  9800. {
  9801. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_PowerDeliveryStopRes][Error]Tx encoded msg error");
  9802. errn = -1;
  9803. }
  9804. //STEP 5: ============ Update Flags ===========
  9805. return errn;
  9806. }
  9807. /*===========================================================================
  9808. FUNCTION: Proc_iso1_PowerDeliveryStopRes
  9809. DESCRIPTION:
  9810. PRE-CONDITION:
  9811. INPUT:
  9812. OUTPUT:
  9813. GLOBAL VARIABLES:
  9814. =============================================================================*/
  9815. int Proc_iso1_PowerDeliveryStopRes(int AcceptFd)
  9816. {
  9817. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9818. //if it is not the same, the packet should be ignored.
  9819. //STEP 1: ============ Initialize ============
  9820. //int i = 0;
  9821. int errn = 0;
  9822. bitstream_t v2g_tx_stream;
  9823. struct iso1PowerDeliveryResType *res;
  9824. struct ChargingInfoData *sys;
  9825. size_t pos = 0;
  9826. v2g_tx_stream.pos = &pos;
  9827. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9828. v2g_tx_stream.data = V2GTP_Tx_buf;
  9829. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  9830. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9831. res->ResponseCode = OK_ISO15118_2014;
  9832. //[HEADER] Check Req SessionID
  9833. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9834. {
  9835. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9836. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9837. errn = -1;
  9838. }
  9839. //Check for SequenceError
  9840. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9841. {
  9842. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  9843. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9844. errn = -1;
  9845. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9846. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9847. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9848. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9849. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9850. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9851. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9852. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9853. }
  9854. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9855. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9856. #if PARAMETER_NORMAL_MODE == ENABLE
  9857. ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryResponse.DC_EVSEStatus.DC_EVSEStatusCode = EVSE_NotReady;
  9858. SHM_Read_iso1_PowerDeliveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9859. #else
  9860. Sudo_Parameter_iso1_PreChargeRes();
  9861. #endif
  9862. //EVSE Status Code
  9863. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  9864. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1 /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  9865. //Check for CSU command of "Stop by EVSE"
  9866. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9867. {
  9868. //res->ResponseCode = FAILED_ISO15118_2014;
  9869. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  9870. }
  9871. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9872. {
  9873. //res->ResponseCode = FAILED_ISO15118_2014;
  9874. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9875. }
  9876. else if (ShmInternalComm->ChargingPermission == FALSE)
  9877. {
  9878. //res->ResponseCode = FAILED_ISO15118_2014;
  9879. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  9880. }
  9881. //STEP 4: ============ Encode and Send Response Message ===========
  9882. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9883. {
  9884. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_PowerDeliveryStopRes][Error]Tx encoded msg error");
  9885. errn = -1;
  9886. }
  9887. //STEP 5: ============ Update Flags ===========
  9888. return errn;
  9889. }
  9890. /*===========================================================================
  9891. FUNCTION: Proc_din_PowerDeliveryStopReq
  9892. DESCRIPTION:
  9893. PRE-CONDITION:
  9894. INPUT:
  9895. OUTPUT:
  9896. GLOBAL VARIABLES:
  9897. =============================================================================*/
  9898. int Proc_din_PowerDeliveryStopReq(int AcceptFd)
  9899. {
  9900. int errn = 0;
  9901. //Request CSU to STOP
  9902. //This should be reponsed as soon as possible once this message is received.
  9903. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9904. EVCOMM_SYS_INFO.EvBatterytargetVoltage = 0;
  9905. EVCOMM_SYS_INFO.EvBatterytargetCurrent = 0;
  9906. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PowerDeliveryReq (2nd)\n");
  9907. //Print the decoded XML Document
  9908. PRINT_XML_DOC_DIN_PowerDeliveryReq(&ccs_exi_doc_DIN);
  9909. //Save into Share Memory
  9910. SHM_Save_din_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  9911. //Check for EV Error Code
  9912. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  9913. //[To-Do] Sending response after the EVSE output voltage decreases to under 60V
  9914. usleep(1500000); //1.5 seconds
  9915. //sleep(1); //1 second
  9916. errn = Proc_din_PowerDeliveryStopRes(AcceptFd);
  9917. if (errn == 0)
  9918. {
  9919. //send response successfully.
  9920. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][TX]PowerDeliveryRes (2nd)\n");
  9921. }
  9922. else
  9923. {
  9924. sprintf((char*)buf_log_evcomm,
  9925. "[Error][SeccComm][Proc_din_PowerDeliveryStopReq]Proc_iso1_PowerDeliveryStopRes(): %d (DEC)",
  9926. errn);
  9927. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9928. }
  9929. return errn;
  9930. }
  9931. /*===========================================================================
  9932. FUNCTION: Proc_iso1_PowerDeliveryStopReq
  9933. DESCRIPTION:
  9934. PRE-CONDITION:
  9935. INPUT:
  9936. OUTPUT:
  9937. GLOBAL VARIABLES:
  9938. =============================================================================*/
  9939. int Proc_iso1_PowerDeliveryStopReq(int AcceptFd)
  9940. {
  9941. int errn = 0;
  9942. //Request CSU to STOP
  9943. //This should be reponsed as soon as possible once this message is received.
  9944. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9945. EVCOMM_SYS_INFO.EvBatterytargetVoltage = 0;
  9946. EVCOMM_SYS_INFO.EvBatterytargetCurrent = 0;
  9947. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PowerDeliveryReq (2nd)\n");
  9948. //Print the decoded XML Document
  9949. PRINT_XML_DOC_ISO1_PowerDeliveryReq(&ccs_exi_doc_ISO1);
  9950. //Save into Share Memory
  9951. SHM_Save_iso1_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9952. //Check for EV Error Code
  9953. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  9954. //[To-Do] Sending response after the EVSE output voltage decreases to under 60V
  9955. usleep(1500000); //1.5 seconds
  9956. //sleep(1); //1 second
  9957. errn = Proc_iso1_PowerDeliveryStopRes(AcceptFd);
  9958. if (errn == 0)
  9959. {
  9960. //send response successfully.
  9961. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]PowerDeliveryRes (2nd)");
  9962. }
  9963. else
  9964. {
  9965. sprintf((char*)buf_log_evcomm,
  9966. "[Error][SeccComm][Proc_iso1_PowerDeliveryStopReq]Proc_iso1_PowerDeliveryStopRes(): %d (DEC)",
  9967. errn);
  9968. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9969. }
  9970. return errn;
  9971. }
  9972. /*===========================================================================
  9973. FUNCTION: SHM_Init_din_WeldingDetectionRes
  9974. DESCRIPTION:
  9975. PRE-CONDITION:
  9976. INPUT:
  9977. 1. shm_ccs
  9978. OUTPUT:
  9979. 1. shm_ccs
  9980. GLOBAL VARIABLES:
  9981. =============================================================================*/
  9982. void SHM_Init_din_WeldingDetectionRes(struct CcsData *shm_ccs)
  9983. {
  9984. struct WeldingDetectionResponse_DIN70121 *in;
  9985. in = &shm_ccs->V2GMessage_DIN70121.WeldingDetectionResponse;
  9986. //----- [BODY (1/3)] ResponseCode -----
  9987. in->ResponseCode = dinresponseCodeType_OK;
  9988. //----- [BODY (2/3)] EVSEPresentVoltage -----
  9989. short value = 0; int multiplier = 0; unsigned char unit = 0;
  9990. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for test only.
  9991. value = 0; multiplier = 0; unit = V_DIN70121;
  9992. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  9993. //----- [BODY (3/3)] DC_EVSEStatus -----
  9994. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  9995. }
  9996. /*===========================================================================
  9997. FUNCTION: Sudo_Parameter_din_WeldingDetectionRes
  9998. DESCRIPTION:
  9999. PRE-CONDITION:
  10000. INPUT:
  10001. OUTPUT:
  10002. GLOBAL VARIABLES:
  10003. =============================================================================*/
  10004. void Sudo_Parameter_din_WeldingDetectionRes()
  10005. {
  10006. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  10007. init_dinWeldingDetectionResType(&ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes);
  10008. ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes_isUsed = 1u;
  10009. //----- [BODY (1/3)] ResponseCode -----
  10010. struct dinWeldingDetectionResType *res;
  10011. res = &ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes;
  10012. res->ResponseCode = dinresponseCodeType_OK;
  10013. //----- [BODY (2/3)] EVSEPresentVoltage -----
  10014. res->EVSEPresentVoltage.Value = 3820;
  10015. res->EVSEPresentVoltage.Multiplier = -1;
  10016. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  10017. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  10018. // dinunitSymbolType_h = 0,
  10019. // dinunitSymbolType_m = 1,
  10020. // dinunitSymbolType_s = 2,
  10021. // dinunitSymbolType_A = 3,
  10022. // dinunitSymbolType_Ah = 4,
  10023. // dinunitSymbolType_V = 5,
  10024. // dinunitSymbolType_VA = 6,
  10025. // dinunitSymbolType_W = 7,
  10026. // dinunitSymbolType_W_s = 8,
  10027. // dinunitSymbolType_Wh = 9
  10028. //----- [BODY (3/3)] DC_EVSEStatus -----
  10029. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  10030. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  10031. // dinisolationLevelType_Invalid = 0,
  10032. // dinisolationLevelType_Valid = 1,
  10033. // dinisolationLevelType_Warning = 2,
  10034. // dinisolationLevelType_Fault = 3
  10035. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  10036. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  10037. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  10038. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  10039. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  10040. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  10041. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  10042. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  10043. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  10044. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  10045. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  10046. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  10047. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  10048. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  10049. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  10050. // dinEVSENotificationType_None = 0,
  10051. // dinEVSENotificationType_StopCharging = 1,
  10052. // dinEVSENotificationType_ReNegotiation = 2
  10053. }
  10054. /*===========================================================================
  10055. FUNCTION: Sudo_Parameter_iso1_WeldingDetectionRes
  10056. DESCRIPTION:
  10057. PRE-CONDITION:
  10058. INPUT:
  10059. OUTPUT:
  10060. GLOBAL VARIABLES:
  10061. =============================================================================*/
  10062. void Sudo_Parameter_iso1_WeldingDetectionRes()
  10063. {
  10064. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  10065. init_iso1WeldingDetectionResType(&ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes);
  10066. ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes_isUsed = 1u;
  10067. //----- [BODY (1/3)] ResponseCode -----
  10068. struct iso1WeldingDetectionResType *res;
  10069. res = &ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes;
  10070. res->ResponseCode = iso1responseCodeType_OK;
  10071. //----- [BODY (2/3)] EVSEPresentVoltage -----
  10072. res->EVSEPresentVoltage.Value = 3820;
  10073. res->EVSEPresentVoltage.Multiplier = -1;
  10074. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  10075. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  10076. //iso1unitSymbolType_h = 0,
  10077. //iso1unitSymbolType_m = 1,
  10078. //iso1unitSymbolType_s = 2,
  10079. //iso1unitSymbolType_A = 3,
  10080. //iso1unitSymbolType_V = 4,
  10081. //iso1unitSymbolType_W = 5,
  10082. //iso1unitSymbolType_Wh = 6
  10083. //----- [BODY (3/3)] DC_EVSEStatus -----
  10084. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  10085. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  10086. //iso1isolationLevelType_Invalid = 0,
  10087. //iso1isolationLevelType_Valid = 1,
  10088. //iso1isolationLevelType_Warning = 2,
  10089. //iso1isolationLevelType_Fault = 3,
  10090. //iso1isolationLevelType_No_IMD = 4
  10091. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10092. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  10093. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  10094. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  10095. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  10096. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  10097. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  10098. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  10099. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  10100. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  10101. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  10102. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  10103. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  10104. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  10105. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  10106. //iso1EVSENotificationType_None = 0,
  10107. //iso1EVSENotificationType_StopCharging = 1,
  10108. //iso1EVSENotificationType_ReNegotiation = 2
  10109. }
  10110. /*===========================================================================
  10111. FUNCTION: Proc_din_WeldingDetectionRes
  10112. DESCRIPTION:
  10113. PRE-CONDITION:
  10114. INPUT:
  10115. OUTPUT:
  10116. GLOBAL VARIABLES:
  10117. =============================================================================*/
  10118. int Proc_din_WeldingDetectionRes(int AcceptFd)
  10119. {
  10120. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10121. //if it is not the same, the packet should be ignored.
  10122. //STEP 1: ============ Initialize ============
  10123. //int i = 0;
  10124. int errn = 0;
  10125. bitstream_t v2g_tx_stream;
  10126. static struct WeldingDetectionResponse_DIN70121 *wel;
  10127. static struct ChargingInfoData *sys;
  10128. size_t pos = 0;
  10129. v2g_tx_stream.pos = &pos;
  10130. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10131. v2g_tx_stream.data = V2GTP_Tx_buf;
  10132. wel = &ShmCcsData->V2GMessage_DIN70121.WeldingDetectionResponse;
  10133. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10134. wel->ResponseCode = OK_DIN70121;
  10135. //[HEADER] Check Req SessionID
  10136. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  10137. {
  10138. wel->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  10139. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10140. errn = -1;
  10141. }
  10142. //Check for SequenceError
  10143. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10144. {
  10145. wel->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  10146. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10147. errn = -1;
  10148. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10149. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10150. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10151. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10152. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10153. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10154. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10155. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10156. }
  10157. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10158. SAVE_PhysicalValueType_DIN70121(&wel->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  10159. //EVSE Status Code
  10160. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  10161. //Check for CSU command of "Stop by EVSE"
  10162. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10163. {
  10164. //wel->ResponseCode = FAILED_DIN70121;
  10165. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10166. }
  10167. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10168. {
  10169. //wel->ResponseCode = FAILED_DIN70121;
  10170. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10171. }
  10172. else if (ShmInternalComm->ChargingPermission == FALSE)
  10173. {
  10174. //wel->ResponseCode = FAILED_DIN70121;
  10175. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10176. }
  10177. //Isolation Status
  10178. if (sys->IsolationStatus == GFD_Invalid) //0:invalid (on going)
  10179. {
  10180. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  10181. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10182. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10183. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_WeldingDetectionRes]IsolationStatus = %d", sys->IsolationStatus);
  10184. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10185. Update_V2G_Flow_Status(Other_Fault);
  10186. errn = -1;
  10187. }
  10188. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  10189. {
  10190. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  10191. }
  10192. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  10193. {
  10194. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  10195. }
  10196. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  10197. {
  10198. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  10199. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10200. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10201. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_WeldingDetectionRes]GFD_Fault => Emergency Shutdown");
  10202. Update_V2G_Flow_Status(Other_Fault);
  10203. errn = -1;
  10204. }
  10205. else //GFD_No_IMD or other unexpected status
  10206. {
  10207. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  10208. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10209. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10210. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_WeldingDetectionRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  10211. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10212. Update_V2G_Flow_Status(Other_Fault);
  10213. errn = -1;
  10214. }
  10215. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10216. #if PARAMETER_NORMAL_MODE == ENABLE
  10217. SHM_Read_din_WeldingDetectionRes(&ccs_exi_doc_DIN, ShmCcsData);
  10218. #else
  10219. Sudo_Parameter_din_WeldingDetectionRes();
  10220. #endif
  10221. //STEP 4: ============ Encode and Send Response Message ===========
  10222. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  10223. {
  10224. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_WeldingDetectionRes][Error]Tx encoded msg error");
  10225. errn = -1;
  10226. }
  10227. //STEP 5: ============ Update Flags ===========
  10228. return errn;
  10229. }
  10230. /*===========================================================================
  10231. FUNCTION: Proc_iso1_WeldingDetectionRes
  10232. DESCRIPTION:
  10233. PRE-CONDITION:
  10234. INPUT:
  10235. OUTPUT:
  10236. GLOBAL VARIABLES:
  10237. =============================================================================*/
  10238. int Proc_iso1_WeldingDetectionRes(int AcceptFd)
  10239. {
  10240. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10241. //if it is not the same, the packet should be ignored.
  10242. //STEP 1: ============ Initialize ============
  10243. //int i = 0;
  10244. int errn = 0;
  10245. bitstream_t v2g_tx_stream;
  10246. static struct WeldingDetectionResponse_ISO15118_2014 *wel;
  10247. static struct ChargingInfoData *sys;
  10248. size_t pos = 0;
  10249. v2g_tx_stream.pos = &pos;
  10250. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10251. v2g_tx_stream.data = V2GTP_Tx_buf;
  10252. wel = &ShmCcsData->V2GMessage_ISO15118_2014.WeldingDetectionResponse;
  10253. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10254. wel->ResponseCode = OK_ISO15118_2014;
  10255. //[HEADER] Check Req SessionID
  10256. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10257. {
  10258. wel->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10259. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10260. errn = -1;
  10261. }
  10262. //Check for SequenceError
  10263. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10264. {
  10265. wel->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10266. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10267. errn = -1;
  10268. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10269. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10270. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10271. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10272. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10273. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10274. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10275. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10276. }
  10277. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10278. SAVE_PhysicalValueType_ISO15118_2014(&wel->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  10279. //EVSE Status Code
  10280. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10281. //Check for CSU command of "Stop by EVSE"
  10282. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10283. {
  10284. //wel->ResponseCode = FAILED_ISO15118_2014;
  10285. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10286. }
  10287. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10288. {
  10289. //wel->ResponseCode = FAILED_ISO15118_2014;
  10290. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10291. }
  10292. else if (ShmInternalComm->ChargingPermission == FALSE)
  10293. {
  10294. //wel->ResponseCode = FAILED_ISO15118_2014;
  10295. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10296. }
  10297. //Isolation Status
  10298. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  10299. {
  10300. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  10301. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10302. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10303. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_WeldingDetectionRes]IsolationStatus = %d", sys->IsolationStatus);
  10304. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10305. Update_V2G_Flow_Status(Other_Fault);
  10306. errn = -1;
  10307. }
  10308. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  10309. {
  10310. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  10311. }
  10312. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  10313. {
  10314. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  10315. }
  10316. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  10317. {
  10318. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  10319. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10320. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10321. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_WeldingDetectionRes]GFD_Fault => EmergencyShutdown");
  10322. Update_V2G_Flow_Status(Other_Fault);
  10323. errn = -1;
  10324. }
  10325. else
  10326. {
  10327. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  10328. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10329. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10330. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_WeldingDetectionRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  10331. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10332. Update_V2G_Flow_Status(Other_Fault);
  10333. errn = -1;
  10334. }
  10335. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10336. #if PARAMETER_NORMAL_MODE == ENABLE
  10337. SHM_Read_iso1_WeldingDetectionRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10338. #else
  10339. Sudo_Parameter_iso1_WeldingDetectionRes();
  10340. #endif
  10341. //STEP 4: ============ Encode and Send Response Message ===========
  10342. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10343. {
  10344. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_WeldingDetectionRes][Error]Tx encoded msg error");
  10345. errn = -1;
  10346. }
  10347. //STEP 5: ============ Update Flags ===========
  10348. return errn;
  10349. }
  10350. /*===========================================================================
  10351. FUNCTION: Proc_din_WeldingDetectionReq
  10352. DESCRIPTION:
  10353. PRE-CONDITION:
  10354. INPUT:
  10355. OUTPUT:
  10356. GLOBAL VARIABLES:
  10357. =============================================================================*/
  10358. int Proc_din_WeldingDetectionReq(int AcceptFd)
  10359. {
  10360. int errn = 0;
  10361. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]WeldingDetectionReq\n");
  10362. //Print the decoded XML Document
  10363. PRINT_XML_DOC_DIN_WeldingDetectionReq(&ccs_exi_doc_DIN);
  10364. //Save into Share Memory
  10365. SHM_Save_din_WeldingDetectionReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10366. //Check for EV Error Code
  10367. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.WeldingDetectionRequest.DC_EVStatus.EVErrorCode);
  10368. errn = Proc_din_WeldingDetectionRes(AcceptFd);
  10369. if (errn == 0)
  10370. {
  10371. //send response successfully.
  10372. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]WeldingDetectionRes\n");
  10373. }
  10374. else
  10375. {
  10376. sprintf((char*)buf_log_evcomm,
  10377. "[Error]Proc_din_WeldingDetectionRes(): %d (DEC)",
  10378. errn);
  10379. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10380. }
  10381. return errn;
  10382. }
  10383. /*===========================================================================
  10384. FUNCTION: Proc_iso1_WeldingDetectionReq
  10385. DESCRIPTION:
  10386. PRE-CONDITION:
  10387. INPUT:
  10388. OUTPUT:
  10389. GLOBAL VARIABLES:
  10390. =============================================================================*/
  10391. int Proc_iso1_WeldingDetectionReq(int AcceptFd)
  10392. {
  10393. int errn = 0;
  10394. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]WeldingDetectionReq\n");
  10395. //Print the decoded XML Document
  10396. PRINT_XML_DOC_ISO1_WeldingDetectionReq(&ccs_exi_doc_ISO1);
  10397. //Save into Share Memory
  10398. SHM_Save_iso1_WeldingDetectionReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10399. //Check for EV Error Code
  10400. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.WeldingDetectionRequest.DC_EVStatus.EVErrorCode);
  10401. errn = Proc_iso1_WeldingDetectionRes(AcceptFd);
  10402. if (errn == 0)
  10403. {
  10404. //send response successfully.
  10405. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]WeldingDetectionRes\n");
  10406. }
  10407. else
  10408. {
  10409. sprintf((char*)buf_log_evcomm,
  10410. "[Error]Proc_iso1_WeldingDetectionRes(): %d (DEC)",
  10411. errn);
  10412. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10413. }
  10414. return errn;
  10415. }
  10416. /*===========================================================================
  10417. FUNCTION: SHM_Init_din_SessionStopRes
  10418. DESCRIPTION:
  10419. PRE-CONDITION:
  10420. INPUT:
  10421. 1. shm_ccs
  10422. OUTPUT:
  10423. 1. shm_ccs
  10424. GLOBAL VARIABLES:
  10425. =============================================================================*/
  10426. void SHM_Init_din_SessionStopRes(struct CcsData *shm_ccs)
  10427. {
  10428. struct SessionStopResponse_DIN70121 *in;
  10429. in = &shm_ccs->V2GMessage_DIN70121.SessionStopResponse;
  10430. //----- [BODY (1/3)] ResponseCode -----
  10431. in->ResponseCode = dinresponseCodeType_OK;
  10432. }
  10433. /*===========================================================================
  10434. FUNCTION: Sudo_Parameter_din_SessionStopRes
  10435. DESCRIPTION:
  10436. PRE-CONDITION:
  10437. INPUT:
  10438. OUTPUT:
  10439. GLOBAL VARIABLES:
  10440. =============================================================================*/
  10441. void Sudo_Parameter_din_SessionStopRes()
  10442. {
  10443. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  10444. init_dinSessionStopResType(&ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes);
  10445. ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes_isUsed = 1u;
  10446. //----- [BODY (1/3)] ResponseCode -----
  10447. struct dinSessionStopResType *res;
  10448. res = &ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes;
  10449. res->ResponseCode = dinresponseCodeType_OK;
  10450. }
  10451. /*===========================================================================
  10452. FUNCTION: Sudo_Parameter_iso1_SessionStopRes
  10453. DESCRIPTION:
  10454. PRE-CONDITION:
  10455. INPUT:
  10456. OUTPUT:
  10457. GLOBAL VARIABLES:
  10458. =============================================================================*/
  10459. void Sudo_Parameter_iso1_SessionStopRes()
  10460. {
  10461. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  10462. init_iso1SessionStopResType(&ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes);
  10463. ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes_isUsed = 1u;
  10464. //----- [BODY (1/3)] ResponseCode -----
  10465. struct iso1SessionStopResType *res;
  10466. res = &ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes;
  10467. res->ResponseCode = iso1responseCodeType_OK;
  10468. }
  10469. /*===========================================================================
  10470. FUNCTION: Proc_din_SessionStopRes
  10471. DESCRIPTION:
  10472. PRE-CONDITION:
  10473. INPUT:
  10474. OUTPUT:
  10475. GLOBAL VARIABLES:
  10476. =============================================================================*/
  10477. int Proc_din_SessionStopRes(int AcceptFd)
  10478. {
  10479. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10480. //if it is not the same, the packet should be ignored.
  10481. //STEP 1: ============ Initialize ============
  10482. //int i = 0;
  10483. int errn = 0;
  10484. bitstream_t v2g_tx_stream;
  10485. struct SessionStopResponse_DIN70121 *stp;
  10486. size_t pos = 0;
  10487. v2g_tx_stream.pos = &pos;
  10488. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10489. v2g_tx_stream.data = V2GTP_Tx_buf;
  10490. stp = &ShmCcsData->V2GMessage_DIN70121.SessionStopResponse;
  10491. stp->ResponseCode = OK_DIN70121;
  10492. //[HEADER] Check Req SessionID
  10493. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  10494. {
  10495. stp->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  10496. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10497. errn = -1;
  10498. }
  10499. //Check for SequenceError
  10500. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10501. {
  10502. stp->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  10503. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10504. errn = -1;
  10505. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10506. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10507. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10508. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10509. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10510. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10511. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10512. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10513. }
  10514. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10515. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10516. #if PARAMETER_NORMAL_MODE == ENABLE
  10517. SHM_Read_din_SessionStopRes(&ccs_exi_doc_DIN, ShmCcsData);
  10518. #else
  10519. Sudo_Parameter_din_SessionStopRes();
  10520. #endif
  10521. //STEP 4: ============ Encode and Send Response Message ===========
  10522. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  10523. {
  10524. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionStopRes: fail");
  10525. errn = -1;
  10526. }
  10527. else
  10528. {
  10529. //send response successfully.
  10530. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionStopRes");
  10531. }
  10532. //STEP 5: ============ Update Flags ===========
  10533. EVCOMM_SYS_INFO.ConnectorLocked = FALSE; //Indicating CSU that the Connector is unlocked.
  10534. //Once this is set, the CSU should
  10535. // =========== Annouce to CSU [To-Be Implemented]=============
  10536. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE; //This should be also added to EV Error events.
  10537. // =========== Re-initialized [To-Be Implemented]=============
  10538. //Keep 5% PWM for 2 seconds
  10539. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 2");
  10540. sleep(1);
  10541. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 1");
  10542. sleep(1);
  10543. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 0");
  10544. OutputCpPwmDuty(100);
  10545. //[To-Do] Reset All Share memory
  10546. //[To-Do] CCS Module enter "idle" mode and CSU should check for this state.
  10547. //system("reboot -f");
  10548. //sleep(5);
  10549. //system("reboot -f");
  10550. return errn;
  10551. }
  10552. /*===========================================================================
  10553. FUNCTION: Proc_iso1_SessionStopRes
  10554. DESCRIPTION:
  10555. PRE-CONDITION:
  10556. INPUT:
  10557. OUTPUT:
  10558. GLOBAL VARIABLES:
  10559. =============================================================================*/
  10560. int Proc_iso1_SessionStopRes(int AcceptFd)
  10561. {
  10562. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10563. //if it is not the same, the packet should be ignored.
  10564. //STEP 1: ============ Initialize ============
  10565. //int i = 0;
  10566. int errn = 0;
  10567. bitstream_t v2g_tx_stream;
  10568. struct SessionStopResponse_ISO15118_2014 *stp;
  10569. //struct ChargingInfoData *sys;
  10570. size_t pos = 0;
  10571. v2g_tx_stream.pos = &pos;
  10572. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10573. v2g_tx_stream.data = V2GTP_Tx_buf;
  10574. stp = &ShmCcsData->V2GMessage_ISO15118_2014.SessionStopResponse;
  10575. //sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10576. stp->ResponseCode = OK_ISO15118_2014;
  10577. //[HEADER] Check Req SessionID
  10578. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10579. {
  10580. stp->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10581. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10582. errn = -1;
  10583. }
  10584. //Check for SequenceError
  10585. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10586. {
  10587. stp->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10588. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10589. errn = -1;
  10590. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10591. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10592. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10593. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10594. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10595. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10596. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10597. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10598. }
  10599. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10600. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10601. #if PARAMETER_NORMAL_MODE == ENABLE
  10602. SHM_Read_iso1_SessionStopRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10603. #else
  10604. Sudo_Parameter_iso1_SessionStopRes();
  10605. #endif
  10606. //STEP 4: ============ Encode and Send Response Message ===========
  10607. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10608. {
  10609. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionStopRes: fail");
  10610. errn = -1;
  10611. }
  10612. else
  10613. {
  10614. //send response successfully.
  10615. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionStopRes");
  10616. }
  10617. //STEP 5: ============ Update Flags ===========
  10618. EVCOMM_SYS_INFO.ConnectorLocked = FALSE; //Indicating CSU that the Connector is unlocked.
  10619. //Once this is set, the CSU should
  10620. // =========== Annouce to CSU [To-Be Implemented]=============
  10621. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE; //This should be also added to EV Error events.
  10622. // =========== Re-initialized [To-Be Implemented]=============
  10623. //Keep 5% PWM for 2 seconds
  10624. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 2");
  10625. sleep(1);
  10626. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 1");
  10627. sleep(1);
  10628. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 0");
  10629. OutputCpPwmDuty(100);
  10630. //[To-Do] Reset All Share memory
  10631. //[To-Do] CCS Module enter "idle" mode and CSU should check for this state.
  10632. //system("reboot -f");
  10633. //sleep(5);
  10634. //system("reboot -f");
  10635. return errn;
  10636. }
  10637. /*===========================================================================
  10638. FUNCTION: Proc_din_SessionStopReq
  10639. DESCRIPTION:
  10640. PRE-CONDITION:
  10641. INPUT:
  10642. OUTPUT:
  10643. GLOBAL VARIABLES:
  10644. =============================================================================*/
  10645. int Proc_din_SessionStopReq(int AcceptFd)
  10646. {
  10647. int errn = 0;
  10648. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]SessionStopReq");
  10649. //Print the decoded XML Document
  10650. PRINT_XML_DOC_DIN_SessionStopReq(&ccs_exi_doc_DIN);
  10651. //Save into Share Memory
  10652. SHM_Save_din_SessionStopReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10653. errn = Proc_din_SessionStopRes(AcceptFd);
  10654. if (errn == 0)
  10655. {
  10656. //send response successfully.
  10657. }
  10658. else
  10659. {
  10660. sprintf((char*)buf_log_evcomm,
  10661. "[Error][SeccComm][Proc_din_SessionStopReq]Proc_iso1_SessionStopRes(): %d (DEC)",
  10662. errn);
  10663. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10664. }
  10665. return errn;
  10666. }
  10667. /*===========================================================================
  10668. FUNCTION: Proc_iso1_SessionStopReq
  10669. DESCRIPTION:
  10670. PRE-CONDITION:
  10671. INPUT:
  10672. OUTPUT:
  10673. GLOBAL VARIABLES:
  10674. =============================================================================*/
  10675. int Proc_iso1_SessionStopReq(int AcceptFd)
  10676. {
  10677. int errn = 0;
  10678. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]SessionStopReq");
  10679. //Print the decoded XML Document
  10680. PRINT_XML_DOC_ISO1_SessionStopReq(&ccs_exi_doc_ISO1);
  10681. //Save into Share Memory
  10682. SHM_Save_iso1_SessionStopReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10683. errn = Proc_iso1_SessionStopRes(AcceptFd);
  10684. if (errn == 0)
  10685. {
  10686. //send response successfully.
  10687. }
  10688. else
  10689. {
  10690. sprintf((char*)buf_log_evcomm,
  10691. "[Error][SeccComm][Proc_iso1_SessionStopReq]Proc_iso1_SessionStopRes(): %d (DEC)",
  10692. errn);
  10693. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10694. }
  10695. return errn;
  10696. }
  10697. /*===========================================================================
  10698. FUNCTION: V2gMsg_Process_din
  10699. DESCRIPTION:
  10700. PRE-CONDITION:
  10701. INPUT:
  10702. 1. V2gFlowStatus
  10703. OUTPUT:
  10704. GLOBAL VARIABLES:
  10705. 1. V2gFlowStatus
  10706. =============================================================================*/
  10707. int V2gMsg_Process_din(int AcceptFd)
  10708. {
  10709. unsigned char req_is_responsed = FALSE;
  10710. while (req_is_responsed == FALSE)
  10711. {
  10712. //Check if it is in End_Process
  10713. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  10714. {
  10715. break;
  10716. }
  10717. switch(V2gFlowStatus)
  10718. {
  10719. //-------------------------------------------
  10720. case SupportedAppProtocolRequest:
  10721. {
  10722. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  10723. {
  10724. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  10725. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  10726. {
  10727. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10728. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  10729. }
  10730. else
  10731. {
  10732. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
  10733. Update_V2G_Flow_Status(Other_Fault);
  10734. }
  10735. }
  10736. req_is_responsed = TRUE;
  10737. break;
  10738. }
  10739. case SupportedAppProtocolResponse:
  10740. {
  10741. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  10742. {
  10743. Update_V2G_Flow_Status(SessionSetupRequest);
  10744. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10745. }
  10746. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10747. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10748. {
  10749. sprintf((char*)buf_log_evcomm,
  10750. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10751. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10752. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10753. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10754. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10755. }
  10756. else
  10757. {
  10758. }
  10759. break;
  10760. }
  10761. //-------------------------------------------
  10762. case SessionSetupRequest: //19
  10763. {
  10764. if (Proc_din_SessionSetupReq(AcceptFd) == 0)
  10765. {
  10766. Update_V2G_Flow_Status(SessionSetupResponse);
  10767. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10768. }
  10769. else
  10770. {
  10771. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
  10772. Update_V2G_Flow_Status(Other_Fault);
  10773. }
  10774. req_is_responsed = TRUE;
  10775. break;
  10776. }
  10777. case SessionSetupResponse: //20
  10778. {
  10779. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  10780. {
  10781. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  10782. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10783. }
  10784. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10785. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10786. {
  10787. sprintf((char*)buf_log_evcomm,
  10788. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10789. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10790. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10791. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10792. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10793. }
  10794. else
  10795. {
  10796. }
  10797. break;
  10798. }
  10799. //-------------------------------------------
  10800. case ServiceDiscoveryRequest: //21
  10801. {
  10802. if (Proc_din_ServiceDiscoveryReq(AcceptFd) == 0)
  10803. {
  10804. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  10805. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10806. }
  10807. else
  10808. {
  10809. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
  10810. Update_V2G_Flow_Status(Other_Fault);
  10811. }
  10812. req_is_responsed = TRUE;
  10813. break;
  10814. }
  10815. case ServiceDiscoveryResponse: //22
  10816. {
  10817. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  10818. {
  10819. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  10820. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10821. }
  10822. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10823. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10824. {
  10825. sprintf((char*)buf_log_evcomm, "[ERROR]SequenceError(%d) => Tx Res MSG", EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10826. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10827. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10828. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10829. }
  10830. else
  10831. {
  10832. }
  10833. break;
  10834. }
  10835. //-------------------------------------------
  10836. case ServiceAndPaymentSelectionRequest: //25
  10837. {
  10838. if (Proc_din_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  10839. {
  10840. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  10841. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10842. }
  10843. else
  10844. {
  10845. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
  10846. Update_V2G_Flow_Status(Other_Fault);
  10847. }
  10848. req_is_responsed = TRUE;
  10849. break;
  10850. }
  10851. case ServiceAndPaymentSelectionResponse: //26
  10852. {
  10853. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  10854. {
  10855. Update_V2G_Flow_Status(AuthorizationRequest);
  10856. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10857. }
  10858. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10859. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10860. {
  10861. sprintf((char*)buf_log_evcomm,
  10862. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10863. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10864. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10865. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10866. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10867. }
  10868. else
  10869. {
  10870. }
  10871. break;
  10872. }
  10873. //-------------------------------------------
  10874. //case ContractAuthenticationReq:
  10875. case AuthorizationRequest: //29
  10876. {
  10877. if (Proc_din_ContractAuthenticationReq(AcceptFd) == 0)
  10878. {
  10879. Update_V2G_Flow_Status(AuthorizationResponse);
  10880. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10881. }
  10882. else
  10883. {
  10884. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  10885. Update_V2G_Flow_Status(Other_Fault);
  10886. }
  10887. req_is_responsed = TRUE;
  10888. break;
  10889. }
  10890. case AuthorizationResponse: //30
  10891. {
  10892. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  10893. {
  10894. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10895. if (Proc_din_ContractAuthenticationReq(AcceptFd) == 0)
  10896. {
  10897. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10898. }
  10899. else
  10900. {
  10901. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  10902. Update_V2G_Flow_Status(Other_Fault);
  10903. }
  10904. req_is_responsed = TRUE;
  10905. }
  10906. //Check for ChargeParameterDiscoveryReq
  10907. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  10908. {
  10909. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10910. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  10911. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  10912. ftime(&SeqStartTime);
  10913. #endif
  10914. }
  10915. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10916. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10917. {
  10918. sprintf((char*)buf_log_evcomm,
  10919. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10920. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10921. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10922. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10923. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10924. }
  10925. else
  10926. {
  10927. }
  10928. break;
  10929. }
  10930. //-------------------------------------------
  10931. case ChargeParameterDiscoveryRequest: //35
  10932. {
  10933. if (Proc_din_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  10934. {
  10935. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  10936. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10937. }
  10938. else
  10939. {
  10940. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  10941. Update_V2G_Flow_Status(Other_Fault);
  10942. }
  10943. req_is_responsed = TRUE;
  10944. break;
  10945. }
  10946. case ChargeParameterDiscoveryResponse:
  10947. {
  10948. //STEP 1: Check for Process Timeout
  10949. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  10950. ftime(&SeqEndTime);
  10951. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  10952. {
  10953. sprintf((char*)buf_log_evcomm,
  10954. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  10955. DiffTimeb(SeqStartTime, SeqEndTime),
  10956. V2G_SECC_ChargingParameter_Performance_Time);
  10957. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10958. Update_V2G_Flow_Status(Sequence_Timeout);
  10959. break;
  10960. }
  10961. #endif
  10962. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  10963. {
  10964. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10965. if (Proc_din_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  10966. {
  10967. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10968. }
  10969. else
  10970. {
  10971. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  10972. Update_V2G_Flow_Status(Other_Fault);
  10973. }
  10974. req_is_responsed = TRUE;
  10975. break;
  10976. }
  10977. //STEP 2: Check for CableCheckReq message
  10978. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  10979. {
  10980. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10981. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CableCheckReqReq: isolated?");
  10982. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  10983. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  10984. Update_V2G_Flow_Status(CableCheckRequest);
  10985. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  10986. ftime(&SeqStartTime);
  10987. #endif
  10988. }
  10989. //STEP 3: Wait for PowerDeliveryReq Message
  10990. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  10991. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  10992. {
  10993. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  10994. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10995. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  10996. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  10997. ftime(&SeqStartTime);
  10998. #endif
  10999. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  11000. {
  11001. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11002. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11003. }
  11004. else
  11005. {
  11006. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11007. Update_V2G_Flow_Status(Other_Fault);
  11008. }
  11009. }
  11010. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11011. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11012. {
  11013. sprintf((char*)buf_log_evcomm,
  11014. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11015. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11016. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11017. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11018. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11019. }
  11020. else
  11021. {
  11022. }
  11023. break;
  11024. }
  11025. //-------------------------------------------
  11026. case CableCheckRequest: //37
  11027. {
  11028. //STEP 3: Execute Cable Check Process
  11029. if (Proc_din_CableCheckReq(AcceptFd) == 0)
  11030. {
  11031. Update_V2G_Flow_Status(CableCheckResponse);
  11032. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11033. }
  11034. else
  11035. {
  11036. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  11037. Update_V2G_Flow_Status(Other_Fault);
  11038. }
  11039. req_is_responsed = TRUE;
  11040. break;
  11041. }
  11042. case CableCheckResponse: //38
  11043. {
  11044. //STEP 1: Check for Process Timeout
  11045. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11046. ftime(&SeqEndTime);
  11047. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  11048. {
  11049. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CableCheck] end counting...");
  11050. sprintf((char*)buf_log_evcomm,
  11051. "CableCheck Timeout - (%.02lf of %d ms)\n",
  11052. DiffTimeb(SeqStartTime, SeqEndTime),
  11053. V2G_SECC_CableCheck_Performance_Time);
  11054. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11055. Update_V2G_Flow_Status(Sequence_Timeout);
  11056. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11057. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  11058. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11059. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11060. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11061. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11062. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  11063. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  11064. break;
  11065. }
  11066. #endif
  11067. //STEP 2: Check for CableCheckReq message
  11068. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11069. {
  11070. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11071. //STEP 3: Execute Cable Check Process
  11072. if (Proc_din_CableCheckReq(AcceptFd) == 0)
  11073. {
  11074. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11075. }
  11076. else
  11077. {
  11078. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  11079. Update_V2G_Flow_Status(Other_Fault);
  11080. }
  11081. req_is_responsed = TRUE;
  11082. }
  11083. //STEP 3: Check for PreChargeReq message
  11084. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11085. {
  11086. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11087. Update_V2G_Flow_Status(PreChargeRequest);
  11088. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PreChargeReqReq: waiting for precharge voltage...");
  11089. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11090. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  11091. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11092. ftime(&SeqStartTime);
  11093. #endif
  11094. }
  11095. //STEP 3: Wait for PowerDeliveryReq Message
  11096. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11097. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11098. {
  11099. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11100. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11101. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11102. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11103. ftime(&SeqStartTime);
  11104. #endif
  11105. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  11106. {
  11107. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11108. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11109. }
  11110. else
  11111. {
  11112. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11113. Update_V2G_Flow_Status(Other_Fault);
  11114. }
  11115. }
  11116. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11117. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11118. {
  11119. sprintf((char*)buf_log_evcomm,
  11120. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11121. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11122. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11123. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11124. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11125. }
  11126. else
  11127. {
  11128. }
  11129. break;
  11130. }
  11131. //-------------------------------------------
  11132. case PreChargeRequest: //39
  11133. {
  11134. if (Proc_din_PreChargeReq(AcceptFd) == 0)
  11135. {
  11136. Update_V2G_Flow_Status(PreChargeResponse);
  11137. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11138. }
  11139. else
  11140. {
  11141. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  11142. Update_V2G_Flow_Status(Other_Fault);
  11143. }
  11144. req_is_responsed = TRUE;
  11145. break;
  11146. }
  11147. case PreChargeResponse: //40
  11148. {
  11149. //STEP 1: Check for Process Timeout
  11150. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11151. ftime(&SeqEndTime);
  11152. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  11153. {
  11154. sprintf((char*)buf_log_evcomm,
  11155. "Precharge Timeout - (%.02lf of %d ms)\n",
  11156. DiffTimeb(SeqStartTime, SeqEndTime),
  11157. V2G_SECC_PreCharge_Performance_Time);
  11158. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11159. Update_V2G_Flow_Status(Sequence_Timeout);
  11160. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11161. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  11162. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11163. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11164. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11165. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11166. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  11167. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  11168. break;
  11169. }
  11170. #endif
  11171. //STEP 2: Check for PreChargeReq message
  11172. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11173. {
  11174. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11175. if (Proc_din_PreChargeReq(AcceptFd) == 0)
  11176. {
  11177. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11178. }
  11179. else
  11180. {
  11181. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  11182. Update_V2G_Flow_Status(Other_Fault);
  11183. }
  11184. req_is_responsed = TRUE;
  11185. }
  11186. //STEP 3: Check for PowerDeliveryReq message
  11187. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11188. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11189. {
  11190. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11191. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  11192. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  11193. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11194. ftime(&SeqStartTime);
  11195. #endif
  11196. }
  11197. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11198. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11199. {
  11200. sprintf((char*)buf_log_evcomm,
  11201. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11202. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11203. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11204. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11205. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11206. }
  11207. else
  11208. {
  11209. }
  11210. break;
  11211. }
  11212. //-------------------------------------------
  11213. case PowerDeliveryRequestStart: //41
  11214. {
  11215. if (Proc_din_PowerDeliveryStartReq(AcceptFd) == 0)
  11216. {
  11217. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  11218. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11219. }
  11220. else
  11221. {
  11222. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
  11223. Update_V2G_Flow_Status(Other_Fault);
  11224. }
  11225. req_is_responsed = TRUE;
  11226. break;
  11227. }
  11228. case PowerDeliveryResponsetStart: //42
  11229. {
  11230. //STEP 1: Check for Process Timeout
  11231. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11232. if (ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  11233. {
  11234. ftime(&SeqEndTime);
  11235. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  11236. {
  11237. sprintf((char*)buf_log_evcomm,
  11238. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  11239. DiffTimeb(SeqStartTime, SeqEndTime),
  11240. 2000);
  11241. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11242. Update_V2G_Flow_Status(Sequence_Timeout);
  11243. }
  11244. break;
  11245. }
  11246. #endif
  11247. //STEP 2: Wait for CurrentDemandReq Message
  11248. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  11249. {
  11250. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11251. Update_V2G_Flow_Status(CurrentDemandRequest);
  11252. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CurrentDemandReqReq: energy transfering...");
  11253. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  11254. }
  11255. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11256. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11257. {
  11258. sprintf((char*)buf_log_evcomm,
  11259. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11260. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11261. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11262. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11263. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11264. }
  11265. else
  11266. {
  11267. }
  11268. break;
  11269. }
  11270. //-------------------------------------------
  11271. case CurrentDemandRequest: //45,
  11272. {
  11273. if (Proc_din_CurrentDemandReq(AcceptFd) == 0)
  11274. {
  11275. Update_V2G_Flow_Status(CurrentDemandResponse);
  11276. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11277. }
  11278. else
  11279. {
  11280. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  11281. Update_V2G_Flow_Status(Other_Fault);
  11282. }
  11283. req_is_responsed = TRUE;
  11284. break;
  11285. }
  11286. case CurrentDemandResponse: //46,
  11287. {
  11288. //STEP 1: Wait for CurrentDemandReq Message
  11289. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  11290. {
  11291. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11292. if (Proc_din_CurrentDemandReq(AcceptFd) == 0)
  11293. {
  11294. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11295. }
  11296. else
  11297. {
  11298. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  11299. Update_V2G_Flow_Status(Other_Fault);
  11300. }
  11301. req_is_responsed = TRUE;
  11302. break;
  11303. }
  11304. //STEP 2: Wait for PowerDeliveryReq Message
  11305. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11306. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11307. {
  11308. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11309. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11310. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  11311. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11312. ftime(&SeqStartTime);
  11313. #endif
  11314. }
  11315. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11316. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11317. {
  11318. sprintf((char*)buf_log_evcomm,
  11319. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11320. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11321. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11322. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11323. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11324. }
  11325. else
  11326. {
  11327. }
  11328. break;
  11329. }
  11330. //-------------------------------------------
  11331. case PowerDeliveryRequestStop: //49,
  11332. {
  11333. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  11334. {
  11335. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11336. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11337. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11338. ftime(&SeqStartTime);
  11339. #endif
  11340. }
  11341. else
  11342. {
  11343. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11344. Update_V2G_Flow_Status(Other_Fault);
  11345. }
  11346. req_is_responsed = TRUE;
  11347. break;
  11348. }
  11349. case PowerDeliveryResponseStop: //50,
  11350. {
  11351. //STEP 1: Check for Process Timeout
  11352. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11353. ftime(&SeqEndTime);
  11354. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  11355. {
  11356. sprintf((char*)buf_log_evcomm,
  11357. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  11358. DiffTimeb(SeqStartTime, SeqEndTime),
  11359. 2000);
  11360. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11361. Update_V2G_Flow_Status(Sequence_Timeout);
  11362. break;
  11363. }
  11364. #endif
  11365. //STEP 2: Check for WeldingDetectionReq Message
  11366. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  11367. {
  11368. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11369. Update_V2G_Flow_Status(WeldingDetectionRequest);
  11370. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]WeldingDetectionReq: ongoing...");
  11371. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  11372. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11373. ftime(&SeqStartTime);
  11374. #endif
  11375. }
  11376. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  11377. {
  11378. Update_V2G_Flow_Status(SessionStopRequest);
  11379. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11380. if (Proc_din_SessionStopReq(AcceptFd) == 0)
  11381. {
  11382. Update_V2G_Flow_Status(SessionStopResponse);
  11383. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11384. }
  11385. else
  11386. {
  11387. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  11388. Update_V2G_Flow_Status(Other_Fault);
  11389. }
  11390. break;
  11391. }
  11392. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11393. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11394. {
  11395. sprintf((char*)buf_log_evcomm,
  11396. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11397. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11398. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11399. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11400. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11401. }
  11402. else
  11403. {
  11404. }
  11405. break;
  11406. }
  11407. //-------------------------------------------
  11408. case WeldingDetectionRequest: //51,
  11409. {
  11410. if (Proc_din_WeldingDetectionReq(AcceptFd) == 0)
  11411. {
  11412. Update_V2G_Flow_Status(WeldingDetectionResponse);
  11413. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11414. }
  11415. else
  11416. {
  11417. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  11418. Update_V2G_Flow_Status(Other_Fault);
  11419. }
  11420. req_is_responsed = TRUE;
  11421. break;
  11422. }
  11423. case WeldingDetectionResponse: //52,
  11424. {
  11425. //STEP 1: Check for Process Timeout
  11426. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11427. ftime(&SeqEndTime);
  11428. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  11429. {
  11430. sprintf((char*)buf_log_evcomm,
  11431. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  11432. DiffTimeb(SeqStartTime, SeqEndTime),
  11433. V2G_SECC_WeldingDetection_Performance_Time);
  11434. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11435. Update_V2G_Flow_Status(Sequence_Timeout);
  11436. break;
  11437. }
  11438. #endif
  11439. //STEP 2: Check for WeldingDetectionReq Message
  11440. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  11441. {
  11442. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11443. if (Proc_din_WeldingDetectionReq(AcceptFd) == 0)
  11444. {
  11445. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11446. }
  11447. else
  11448. {
  11449. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  11450. Update_V2G_Flow_Status(Other_Fault);
  11451. }
  11452. req_is_responsed = TRUE;
  11453. }
  11454. //STEP 3: Check for SessionStopReq Message
  11455. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  11456. {
  11457. Update_V2G_Flow_Status(SessionStopRequest);
  11458. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11459. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  11460. }
  11461. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11462. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11463. {
  11464. sprintf((char*)buf_log_evcomm,
  11465. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11466. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11467. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11468. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11469. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11470. }
  11471. else
  11472. {
  11473. }
  11474. break;
  11475. }
  11476. //-------------------------------------------
  11477. case SessionStopRequest: //53,
  11478. {
  11479. if (Proc_din_SessionStopReq(AcceptFd) == 0)
  11480. {
  11481. Update_V2G_Flow_Status(SessionStopResponse);
  11482. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11483. }
  11484. else
  11485. {
  11486. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  11487. Update_V2G_Flow_Status(Other_Fault);
  11488. }
  11489. req_is_responsed = TRUE;
  11490. break;
  11491. }
  11492. case SessionStopResponse: //54,
  11493. {
  11494. break;
  11495. }
  11496. //-------------------------------------------
  11497. default:
  11498. {
  11499. break;
  11500. }
  11501. }
  11502. usleep(1000);
  11503. }
  11504. return 0;
  11505. }
  11506. /*===========================================================================
  11507. FUNCTION: V2gMsg_Process_iso1_DC
  11508. DESCRIPTION:
  11509. PRE-CONDITION:
  11510. INPUT:
  11511. 1. V2gFlowStatus
  11512. OUTPUT:
  11513. GLOBAL VARIABLES:
  11514. 1. V2gFlowStatus
  11515. =============================================================================*/
  11516. int V2gMsg_Process_iso1_DC(int AcceptFd)
  11517. {
  11518. unsigned char req_is_responsed = FALSE;
  11519. while (req_is_responsed == FALSE)
  11520. {
  11521. //Check if it is in End_Process
  11522. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  11523. {
  11524. break;
  11525. }
  11526. switch(V2gFlowStatus)
  11527. {
  11528. //-------------------------------------------
  11529. case SupportedAppProtocolRequest:
  11530. {
  11531. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  11532. {
  11533. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  11534. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  11535. {
  11536. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11537. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  11538. }
  11539. else
  11540. {
  11541. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
  11542. Update_V2G_Flow_Status(Other_Fault);
  11543. }
  11544. }
  11545. req_is_responsed = TRUE;
  11546. break;
  11547. }
  11548. case SupportedAppProtocolResponse:
  11549. {
  11550. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  11551. {
  11552. Update_V2G_Flow_Status(SessionSetupRequest);
  11553. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11554. }
  11555. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11556. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11557. {
  11558. sprintf((char*)buf_log_evcomm,
  11559. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11560. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11561. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11562. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11563. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11564. }
  11565. else
  11566. {
  11567. }
  11568. break;
  11569. }
  11570. //-------------------------------------------
  11571. case SessionSetupRequest: //19
  11572. {
  11573. if (Proc_iso1_SessionSetupReq(AcceptFd) == 0)
  11574. {
  11575. Update_V2G_Flow_Status(SessionSetupResponse);
  11576. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11577. }
  11578. else
  11579. {
  11580. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
  11581. Update_V2G_Flow_Status(Other_Fault);
  11582. }
  11583. req_is_responsed = TRUE;
  11584. break;
  11585. }
  11586. case SessionSetupResponse: //20
  11587. {
  11588. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  11589. {
  11590. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  11591. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11592. }
  11593. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11594. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11595. {
  11596. sprintf((char*)buf_log_evcomm,
  11597. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11598. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11599. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11600. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11601. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11602. }
  11603. else
  11604. {
  11605. }
  11606. break;
  11607. }
  11608. //-------------------------------------------
  11609. case ServiceDiscoveryRequest: //21
  11610. {
  11611. if (Proc_iso1_ServiceDiscoveryReq(AcceptFd) == 0)
  11612. {
  11613. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  11614. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11615. }
  11616. else
  11617. {
  11618. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
  11619. Update_V2G_Flow_Status(Other_Fault);
  11620. }
  11621. req_is_responsed = TRUE;
  11622. break;
  11623. }
  11624. case ServiceDiscoveryResponse: //22
  11625. {
  11626. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  11627. {
  11628. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  11629. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11630. }
  11631. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11632. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11633. {
  11634. sprintf((char*)buf_log_evcomm,
  11635. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11636. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11637. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11638. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11639. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11640. }
  11641. else
  11642. {
  11643. }
  11644. break;
  11645. }
  11646. //-------------------------------------------
  11647. case ServiceAndPaymentSelectionRequest: //25
  11648. {
  11649. if (Proc_iso1_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  11650. {
  11651. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  11652. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11653. }
  11654. else
  11655. {
  11656. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
  11657. Update_V2G_Flow_Status(Other_Fault);
  11658. }
  11659. req_is_responsed = TRUE;
  11660. break;
  11661. }
  11662. case ServiceAndPaymentSelectionResponse: //26
  11663. {
  11664. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11665. {
  11666. Update_V2G_Flow_Status(AuthorizationRequest);
  11667. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11668. }
  11669. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11670. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11671. {
  11672. sprintf((char*)buf_log_evcomm,
  11673. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11674. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11675. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11676. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11677. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11678. }
  11679. else
  11680. {
  11681. }
  11682. break;
  11683. }
  11684. //-------------------------------------------
  11685. //case ContractAuthenticationReq:
  11686. case AuthorizationRequest: //29
  11687. {
  11688. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  11689. {
  11690. Update_V2G_Flow_Status(AuthorizationResponse);
  11691. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11692. }
  11693. else
  11694. {
  11695. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  11696. Update_V2G_Flow_Status(Other_Fault);
  11697. }
  11698. req_is_responsed = TRUE;
  11699. break;
  11700. }
  11701. case AuthorizationResponse: //30
  11702. {
  11703. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11704. {
  11705. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11706. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  11707. {
  11708. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11709. }
  11710. else
  11711. {
  11712. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  11713. Update_V2G_Flow_Status(Other_Fault);
  11714. }
  11715. req_is_responsed = TRUE;
  11716. }
  11717. //Check for ChargeParameterDiscoveryReq
  11718. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11719. {
  11720. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11721. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  11722. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]ChargeParameterDiscoveryReq: CSU Permission?");
  11723. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11724. ftime(&SeqStartTime);
  11725. #endif
  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 ChargeParameterDiscoveryRequest: //35
  11744. {
  11745. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11746. {
  11747. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  11748. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11749. }
  11750. else
  11751. {
  11752. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  11753. Update_V2G_Flow_Status(Other_Fault);
  11754. }
  11755. req_is_responsed = TRUE;
  11756. break;
  11757. }
  11758. case ChargeParameterDiscoveryResponse:
  11759. {
  11760. //STEP 1: Check for Process Timeout
  11761. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11762. ftime(&SeqEndTime);
  11763. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  11764. {
  11765. sprintf((char*)buf_log_evcomm,
  11766. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  11767. DiffTimeb(SeqStartTime, SeqEndTime),
  11768. V2G_SECC_ChargingParameter_Performance_Time);
  11769. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11770. Update_V2G_Flow_Status(Sequence_Timeout);
  11771. break;
  11772. }
  11773. #endif
  11774. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11775. {
  11776. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11777. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11778. {
  11779. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11780. }
  11781. else
  11782. {
  11783. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  11784. Update_V2G_Flow_Status(Other_Fault);
  11785. }
  11786. req_is_responsed = TRUE;
  11787. }
  11788. //STEP 2: Check for CableCheckReq message
  11789. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11790. {
  11791. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11792. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CableCheckReqReq: isolated?");
  11793. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  11794. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11795. Update_V2G_Flow_Status(CableCheckRequest);
  11796. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11797. ftime(&SeqStartTime);
  11798. #endif
  11799. }
  11800. //STEP 3: Wait for PowerDeliveryReq Message
  11801. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11802. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11803. {
  11804. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11805. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11806. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11807. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11808. ftime(&SeqStartTime);
  11809. #endif
  11810. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  11811. {
  11812. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11813. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11814. }
  11815. else
  11816. {
  11817. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11818. Update_V2G_Flow_Status(Other_Fault);
  11819. }
  11820. break;
  11821. }
  11822. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11823. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11824. {
  11825. sprintf((char*)buf_log_evcomm,
  11826. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11827. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11828. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11829. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11830. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11831. }
  11832. else
  11833. {
  11834. }
  11835. break;
  11836. }
  11837. //-------------------------------------------
  11838. case CableCheckRequest: //37
  11839. {
  11840. //STEP 3: Execute Cable Check Process
  11841. if (Proc_iso1_CableCheckReq(AcceptFd) == 0)
  11842. {
  11843. Update_V2G_Flow_Status(CableCheckResponse);
  11844. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11845. }
  11846. else
  11847. {
  11848. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  11849. Update_V2G_Flow_Status(Other_Fault);
  11850. }
  11851. req_is_responsed = TRUE;
  11852. break;
  11853. }
  11854. case CableCheckResponse: //38
  11855. {
  11856. //STEP 1: Check for Process Timeout
  11857. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11858. ftime(&SeqEndTime);
  11859. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  11860. {
  11861. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CableCheck] end counting...");
  11862. sprintf((char*)buf_log_evcomm,
  11863. "CableCheck Timeout - (%.02lf of %d ms)\n",
  11864. DiffTimeb(SeqStartTime, SeqEndTime),
  11865. V2G_SECC_CableCheck_Performance_Time);
  11866. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11867. Update_V2G_Flow_Status(Sequence_Timeout);
  11868. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11869. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  11870. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11871. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11872. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11873. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11874. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  11875. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  11876. break;
  11877. }
  11878. #endif
  11879. //STEP 2: Check for CableCheckReq message
  11880. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11881. {
  11882. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11883. //STEP 3: Execute Cable Check Process
  11884. if (Proc_iso1_CableCheckReq(AcceptFd) == 0)
  11885. {
  11886. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11887. }
  11888. else
  11889. {
  11890. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  11891. Update_V2G_Flow_Status(Other_Fault);
  11892. }
  11893. req_is_responsed = TRUE;
  11894. }
  11895. //STEP 3: Check for PreChargeReq message
  11896. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11897. {
  11898. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11899. Update_V2G_Flow_Status(PreChargeRequest);
  11900. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PreChargeReqReq: waiting for precharge voltage...");
  11901. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11902. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  11903. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11904. ftime(&SeqStartTime);
  11905. #endif
  11906. }
  11907. //STEP 3: Wait for PowerDeliveryReq Message
  11908. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11909. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11910. {
  11911. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11912. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11913. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11914. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11915. ftime(&SeqStartTime);
  11916. #endif
  11917. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  11918. {
  11919. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11920. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11921. }
  11922. else
  11923. {
  11924. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11925. Update_V2G_Flow_Status(Other_Fault);
  11926. }
  11927. }
  11928. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11929. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11930. {
  11931. sprintf((char*)buf_log_evcomm,
  11932. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11933. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11934. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11935. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11936. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11937. }
  11938. else
  11939. {
  11940. }
  11941. break;
  11942. }
  11943. //-------------------------------------------
  11944. case PreChargeRequest: //39
  11945. {
  11946. if (Proc_iso1_PreChargeReq(AcceptFd) == 0)
  11947. {
  11948. Update_V2G_Flow_Status(PreChargeResponse);
  11949. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11950. }
  11951. else
  11952. {
  11953. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  11954. Update_V2G_Flow_Status(Other_Fault);
  11955. }
  11956. req_is_responsed = TRUE;
  11957. break;
  11958. }
  11959. case PreChargeResponse: //40
  11960. {
  11961. //STEP 1: Check for Process Timeout
  11962. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11963. ftime(&SeqEndTime);
  11964. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  11965. {
  11966. sprintf((char*)buf_log_evcomm,
  11967. "Precharge Timeout - (%.02lf of %d ms)\n",
  11968. DiffTimeb(SeqStartTime, SeqEndTime),
  11969. V2G_SECC_PreCharge_Performance_Time);
  11970. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11971. Update_V2G_Flow_Status(Sequence_Timeout);
  11972. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11973. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  11974. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11975. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11976. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11977. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11978. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  11979. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  11980. break;
  11981. }
  11982. #endif
  11983. //STEP 2: Check for PreChargeReq message
  11984. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11985. {
  11986. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11987. if (Proc_iso1_PreChargeReq(AcceptFd) == 0)
  11988. {
  11989. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11990. }
  11991. else
  11992. {
  11993. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  11994. Update_V2G_Flow_Status(Other_Fault);
  11995. }
  11996. req_is_responsed = TRUE;
  11997. }
  11998. //STEP 3: Check for PowerDeliveryReq message
  11999. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12000. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12001. {
  12002. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12003. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  12004. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  12005. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12006. ftime(&SeqStartTime);
  12007. #endif
  12008. }
  12009. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12010. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12011. {
  12012. sprintf((char*)buf_log_evcomm,
  12013. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12014. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12015. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12016. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12017. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12018. }
  12019. else
  12020. {
  12021. }
  12022. break;
  12023. }
  12024. //-------------------------------------------
  12025. case PowerDeliveryRequestStart: //41
  12026. {
  12027. if (Proc_iso1_PowerDeliveryStartReq(AcceptFd) == 0)
  12028. {
  12029. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  12030. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12031. }
  12032. else
  12033. {
  12034. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
  12035. Update_V2G_Flow_Status(Other_Fault);
  12036. }
  12037. req_is_responsed = TRUE;
  12038. break;
  12039. }
  12040. case PowerDeliveryResponsetStart: //42
  12041. {
  12042. //STEP 1: Check for Process Timeout
  12043. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12044. if (ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  12045. {
  12046. ftime(&SeqEndTime);
  12047. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  12048. {
  12049. sprintf((char*)buf_log_evcomm,
  12050. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  12051. DiffTimeb(SeqStartTime, SeqEndTime),
  12052. 2000);
  12053. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12054. Update_V2G_Flow_Status(Sequence_Timeout);
  12055. }
  12056. break;
  12057. }
  12058. #endif
  12059. //STEP 2: Wait for CurrentDemandReq Message
  12060. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  12061. {
  12062. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12063. Update_V2G_Flow_Status(CurrentDemandRequest);
  12064. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CurrentDemandReqReq: energy transfering...");
  12065. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  12066. }
  12067. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12068. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12069. {
  12070. sprintf((char*)buf_log_evcomm,
  12071. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12072. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12073. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12074. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12075. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12076. }
  12077. else
  12078. {
  12079. }
  12080. break;
  12081. }
  12082. //-------------------------------------------
  12083. case CurrentDemandRequest: //45,
  12084. {
  12085. if (Proc_iso1_CurrentDemandReq(AcceptFd) == 0)
  12086. {
  12087. Update_V2G_Flow_Status(CurrentDemandResponse);
  12088. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12089. }
  12090. else
  12091. {
  12092. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  12093. Update_V2G_Flow_Status(Other_Fault);
  12094. }
  12095. req_is_responsed = TRUE;
  12096. break;
  12097. }
  12098. case CurrentDemandResponse: //46,
  12099. {
  12100. //STEP 1: Wait for CurrentDemandReq Message
  12101. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  12102. {
  12103. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12104. if (Proc_iso1_CurrentDemandReq(AcceptFd) == 0)
  12105. {
  12106. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12107. }
  12108. else
  12109. {
  12110. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  12111. Update_V2G_Flow_Status(Other_Fault);
  12112. }
  12113. req_is_responsed = TRUE;
  12114. }
  12115. //STEP 2: Wait for PowerDeliveryReq Message
  12116. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12117. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12118. {
  12119. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12120. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12121. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  12122. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12123. ftime(&SeqStartTime);
  12124. #endif
  12125. }
  12126. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12127. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12128. {
  12129. sprintf((char*)buf_log_evcomm,
  12130. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12131. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12132. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12133. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12134. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12135. }
  12136. else
  12137. {
  12138. }
  12139. break;
  12140. }
  12141. //-------------------------------------------
  12142. case PowerDeliveryRequestStop: //49,
  12143. {
  12144. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12145. {
  12146. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12147. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12148. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12149. ftime(&SeqStartTime);
  12150. #endif
  12151. }
  12152. else
  12153. {
  12154. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  12155. Update_V2G_Flow_Status(Other_Fault);
  12156. }
  12157. req_is_responsed = TRUE;
  12158. break;
  12159. }
  12160. case PowerDeliveryResponseStop: //50,
  12161. {
  12162. //STEP 1: Check for Process Timeout
  12163. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12164. ftime(&SeqEndTime);
  12165. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  12166. {
  12167. sprintf((char*)buf_log_evcomm,
  12168. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12169. DiffTimeb(SeqStartTime, SeqEndTime),
  12170. 2000);
  12171. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12172. Update_V2G_Flow_Status(Sequence_Timeout);
  12173. break;
  12174. }
  12175. #endif
  12176. //STEP 2: Check for WeldingDetectionReq Message
  12177. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  12178. {
  12179. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12180. Update_V2G_Flow_Status(WeldingDetectionRequest);
  12181. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]WeldingDetectionReq: ongoing...");
  12182. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  12183. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12184. ftime(&SeqStartTime);
  12185. #endif
  12186. }
  12187. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12188. {
  12189. Update_V2G_Flow_Status(SessionStopRequest);
  12190. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12191. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12192. {
  12193. Update_V2G_Flow_Status(SessionStopResponse);
  12194. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12195. }
  12196. else
  12197. {
  12198. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  12199. Update_V2G_Flow_Status(Other_Fault);
  12200. }
  12201. }
  12202. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12203. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12204. {
  12205. sprintf((char*)buf_log_evcomm,
  12206. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12207. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12208. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12209. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12210. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12211. }
  12212. else
  12213. {
  12214. }
  12215. break;
  12216. }
  12217. //-------------------------------------------
  12218. case WeldingDetectionRequest: //51,
  12219. {
  12220. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  12221. {
  12222. Update_V2G_Flow_Status(WeldingDetectionResponse);
  12223. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12224. }
  12225. else
  12226. {
  12227. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  12228. Update_V2G_Flow_Status(Other_Fault);
  12229. }
  12230. req_is_responsed = TRUE;
  12231. break;
  12232. }
  12233. case WeldingDetectionResponse: //52,
  12234. {
  12235. //STEP 1: Check for Process Timeout
  12236. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12237. ftime(&SeqEndTime);
  12238. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  12239. {
  12240. sprintf((char*)buf_log_evcomm,
  12241. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12242. DiffTimeb(SeqStartTime, SeqEndTime),
  12243. V2G_SECC_WeldingDetection_Performance_Time);
  12244. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12245. Update_V2G_Flow_Status(Sequence_Timeout);
  12246. break;
  12247. }
  12248. #endif
  12249. //STEP 2: Check for WeldingDetectionReq Message
  12250. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  12251. {
  12252. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12253. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  12254. {
  12255. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12256. }
  12257. else
  12258. {
  12259. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  12260. Update_V2G_Flow_Status(Other_Fault);
  12261. }
  12262. req_is_responsed = TRUE;
  12263. }
  12264. //STEP 3: Check for SessionStopReq Message
  12265. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12266. {
  12267. Update_V2G_Flow_Status(SessionStopRequest);
  12268. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12269. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  12270. }
  12271. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12272. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12273. {
  12274. sprintf((char*)buf_log_evcomm,
  12275. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12276. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12277. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12278. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12279. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12280. }
  12281. else
  12282. {
  12283. }
  12284. break;
  12285. }
  12286. //-------------------------------------------
  12287. case SessionStopRequest: //53,
  12288. {
  12289. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12290. {
  12291. Update_V2G_Flow_Status(SessionStopResponse);
  12292. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12293. }
  12294. else
  12295. {
  12296. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  12297. Update_V2G_Flow_Status(Other_Fault);
  12298. }
  12299. req_is_responsed = TRUE;
  12300. break;
  12301. }
  12302. case SessionStopResponse: //54,
  12303. {
  12304. break;
  12305. }
  12306. //-------------------------------------------
  12307. default:
  12308. {
  12309. break;
  12310. }
  12311. }
  12312. usleep(1000);
  12313. }
  12314. return 0;
  12315. }
  12316. /*===========================================================================
  12317. FUNCTION: V2gMsg_Process_iso1_AC
  12318. DESCRIPTION:
  12319. PRE-CONDITION:
  12320. INPUT:
  12321. 1. V2gFlowStatus
  12322. OUTPUT:
  12323. GLOBAL VARIABLES:
  12324. 1. V2gFlowStatus
  12325. =============================================================================*/
  12326. int V2gMsg_Process_iso1_AC(int AcceptFd)
  12327. {
  12328. unsigned char req_is_responsed = FALSE;
  12329. while (req_is_responsed == FALSE)
  12330. {
  12331. //Check if it is in End_Process
  12332. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  12333. {
  12334. break;
  12335. }
  12336. switch(V2gFlowStatus)
  12337. {
  12338. //-------------------------------------------
  12339. case SupportedAppProtocolRequest: //17
  12340. {
  12341. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  12342. {
  12343. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  12344. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  12345. {
  12346. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12347. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  12348. }
  12349. else
  12350. {
  12351. SAVE_SYS_LOG_MSG_EVCOMM("[Error]supportedAppProtocolResReq: fail\n");
  12352. Update_V2G_Flow_Status(Other_Fault);
  12353. }
  12354. }
  12355. req_is_responsed = TRUE;
  12356. break;
  12357. }
  12358. case SupportedAppProtocolResponse: //18
  12359. {
  12360. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  12361. {
  12362. Update_V2G_Flow_Status(SessionSetupRequest);
  12363. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12364. }
  12365. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12366. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12367. {
  12368. sprintf((char*)buf_log_evcomm,
  12369. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12370. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12371. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12372. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12373. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12374. }
  12375. else
  12376. {}
  12377. break;
  12378. }
  12379. //-------------------------------------------
  12380. case SessionSetupRequest: //19
  12381. {
  12382. if (Proc_iso1_SessionSetupReq(AcceptFd) == 0)
  12383. {
  12384. Update_V2G_Flow_Status(SessionSetupResponse);
  12385. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12386. }
  12387. else
  12388. {
  12389. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionSetupReqRes: fail\n");
  12390. Update_V2G_Flow_Status(Other_Fault);
  12391. }
  12392. req_is_responsed = TRUE;
  12393. break;
  12394. }
  12395. case SessionSetupResponse: //20
  12396. {
  12397. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  12398. {
  12399. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  12400. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12401. }
  12402. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12403. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12404. {
  12405. sprintf((char*)buf_log_evcomm,
  12406. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12407. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12408. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12409. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12410. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12411. }
  12412. else
  12413. {}
  12414. break;
  12415. }
  12416. //-------------------------------------------
  12417. case ServiceDiscoveryRequest: //21
  12418. {
  12419. if (Proc_iso1_ServiceDiscoveryReq(AcceptFd) == 0)
  12420. {
  12421. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  12422. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12423. }
  12424. else
  12425. {
  12426. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceDiscoveryReqRes: fail\n");
  12427. Update_V2G_Flow_Status(Other_Fault);
  12428. }
  12429. req_is_responsed = TRUE;
  12430. break;
  12431. }
  12432. case ServiceDiscoveryResponse: //22
  12433. {
  12434. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  12435. {
  12436. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  12437. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12438. }
  12439. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12440. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12441. {
  12442. sprintf((char*)buf_log_evcomm,
  12443. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12444. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12445. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12446. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12447. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12448. }
  12449. else
  12450. {}
  12451. break;
  12452. }
  12453. //-------------------------------------------
  12454. case ServiceAndPaymentSelectionRequest: //25
  12455. {
  12456. if (Proc_iso1_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  12457. {
  12458. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  12459. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12460. }
  12461. else
  12462. {
  12463. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceAndPaymentSelectionReqRes: fail\n");
  12464. Update_V2G_Flow_Status(Other_Fault);
  12465. }
  12466. req_is_responsed = TRUE;
  12467. break;
  12468. }
  12469. case ServiceAndPaymentSelectionResponse://26
  12470. {
  12471. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  12472. {
  12473. Update_V2G_Flow_Status(AuthorizationRequest);
  12474. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12475. }
  12476. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12477. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12478. {
  12479. sprintf((char*)buf_log_evcomm,
  12480. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12481. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12482. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12483. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12484. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12485. }
  12486. else
  12487. {}
  12488. break;
  12489. }
  12490. //-------------------------------------------
  12491. //case ContractAuthenticationReq:
  12492. case AuthorizationRequest: //29
  12493. {
  12494. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  12495. {
  12496. Update_V2G_Flow_Status(AuthorizationResponse);
  12497. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12498. }
  12499. else
  12500. {
  12501. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail\n");
  12502. Update_V2G_Flow_Status(Other_Fault);
  12503. }
  12504. req_is_responsed = TRUE;
  12505. break;
  12506. }
  12507. case AuthorizationResponse: //30
  12508. {
  12509. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  12510. {
  12511. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12512. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  12513. {
  12514. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12515. }
  12516. else
  12517. {
  12518. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail\n");
  12519. Update_V2G_Flow_Status(Other_Fault);
  12520. }
  12521. req_is_responsed = TRUE;
  12522. }
  12523. //Check for ChargeParameterDiscoveryReq
  12524. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  12525. {
  12526. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12527. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  12528. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12529. ftime(&SeqStartTime);
  12530. #endif
  12531. }
  12532. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12533. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12534. {
  12535. sprintf((char*)buf_log_evcomm,
  12536. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12537. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12538. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12539. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12540. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12541. }
  12542. else
  12543. {}
  12544. break;
  12545. }
  12546. //-------------------------------------------
  12547. case ChargeParameterDiscoveryRequest: //35
  12548. {
  12549. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  12550. {
  12551. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  12552. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12553. }
  12554. else
  12555. {
  12556. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail\n");
  12557. Update_V2G_Flow_Status(Other_Fault);
  12558. }
  12559. req_is_responsed = TRUE;
  12560. break;
  12561. }
  12562. case ChargeParameterDiscoveryResponse: //36
  12563. {
  12564. //STEP 1: Check for Process Timeout
  12565. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12566. ftime(&SeqEndTime);
  12567. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  12568. {
  12569. SAVE_SYS_LOG_MSG_EVCOMM("ChargingParameter Timeout - (%.02lf of %d ms)\n", DiffTimeb(SeqStartTime, SeqEndTime), V2G_SECC_ChargingParameter_Performance_Time);
  12570. Update_V2G_Flow_Status(Sequence_Timeout);
  12571. break;
  12572. }
  12573. #endif
  12574. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  12575. {
  12576. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12577. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  12578. {
  12579. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12580. }
  12581. else
  12582. {
  12583. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail\n");
  12584. Update_V2G_Flow_Status(Other_Fault);
  12585. }
  12586. req_is_responsed = TRUE;
  12587. }
  12588. //STEP 3: Wait for PowerDeliveryReq Message
  12589. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12590. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12591. {
  12592. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  12593. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12594. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  12595. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12596. ftime(&SeqStartTime);
  12597. #endif
  12598. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12599. {
  12600. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12601. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12602. }
  12603. else
  12604. {
  12605. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail\n");
  12606. Update_V2G_Flow_Status(Other_Fault);
  12607. }
  12608. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12609. ftime(&SeqStartTime);
  12610. #endif
  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 PowerDeliveryRequestStart: //41
  12629. {
  12630. if (Proc_iso1_PowerDeliveryStartReq(AcceptFd) == 0)
  12631. {
  12632. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  12633. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12634. }
  12635. else
  12636. {
  12637. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStartReqRes: fail\n");
  12638. Update_V2G_Flow_Status(Other_Fault);
  12639. }
  12640. req_is_responsed = TRUE;
  12641. break;
  12642. }
  12643. case PowerDeliveryResponsetStart: //42
  12644. {
  12645. //STEP 1: Check for Process Timeout
  12646. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12647. if (ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  12648. {
  12649. ftime(&SeqEndTime);
  12650. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  12651. {
  12652. SAVE_SYS_LOG_MSG_EVCOMM("Wait for ChargingStatusReq Timeout - (%.02lf of %d ms)\n", DiffTimeb(SeqStartTime, SeqEndTime), 2000);
  12653. Update_V2G_Flow_Status(Sequence_Timeout);
  12654. }
  12655. break;
  12656. }
  12657. #endif
  12658. //STEP 2: Wait for ChargingStatusReq Message
  12659. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargingStatusRequest)
  12660. {
  12661. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12662. Update_V2G_Flow_Status(ChargingStatusRequest);
  12663. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]ChargingStatusReq: energy transfering...\n");
  12664. ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_Start);
  12665. }
  12666. else
  12667. {}
  12668. break;
  12669. }
  12670. //-------------------------------------------
  12671. case ChargingStatusRequest: //43
  12672. {
  12673. if (Proc_iso1_ChargingStatusReq(AcceptFd) == 0)
  12674. {
  12675. Update_V2G_Flow_Status(ChargingStatusResponse);
  12676. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12677. }
  12678. else
  12679. {
  12680. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingStatusRes: fail\n");
  12681. Update_V2G_Flow_Status(Other_Fault);
  12682. }
  12683. req_is_responsed = TRUE;
  12684. break;
  12685. }
  12686. case ChargingStatusResponse: //44
  12687. {
  12688. //STEP 1: Wait for ChargingStatusReq Message
  12689. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargingStatusRequest)
  12690. {
  12691. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12692. if (Proc_iso1_ChargingStatusReq(AcceptFd) == 0)
  12693. {
  12694. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12695. }
  12696. else
  12697. {
  12698. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingStatusRes: fail\n");
  12699. Update_V2G_Flow_Status(Other_Fault);
  12700. }
  12701. req_is_responsed = TRUE;
  12702. }
  12703. //STEP 2: Wait for PowerDeliveryReq Message
  12704. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12705. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12706. {
  12707. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12708. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12709. ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_End);
  12710. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12711. ftime(&SeqStartTime);
  12712. #endif
  12713. }
  12714. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12715. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12716. {
  12717. sprintf((char*)buf_log_evcomm,
  12718. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12719. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12720. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12721. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12722. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12723. }
  12724. else
  12725. {}
  12726. break;
  12727. }
  12728. //-------------------------------------------
  12729. case PowerDeliveryRequestStop: //49
  12730. {
  12731. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12732. {
  12733. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12734. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12735. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12736. ftime(&SeqStartTime);
  12737. #endif
  12738. }
  12739. else
  12740. {
  12741. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail\n");
  12742. Update_V2G_Flow_Status(Other_Fault);
  12743. }
  12744. req_is_responsed = TRUE;
  12745. break;
  12746. }
  12747. case PowerDeliveryResponseStop: //50
  12748. {
  12749. //STEP 1: Check for Process Timeout
  12750. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12751. ftime(&SeqEndTime);
  12752. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  12753. {
  12754. SAVE_SYS_LOG_MSG_EVCOMM("Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n", DiffTimeb(SeqStartTime, SeqEndTime), 2000);
  12755. Update_V2G_Flow_Status(Sequence_Timeout);
  12756. break;
  12757. }
  12758. #endif
  12759. //STEP 3: Check for SessionStopReq Message
  12760. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12761. {
  12762. Update_V2G_Flow_Status(SessionStopRequest);
  12763. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12764. }
  12765. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12766. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12767. {
  12768. sprintf((char*)buf_log_evcomm,
  12769. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12770. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12771. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12772. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12773. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12774. }
  12775. else
  12776. {}
  12777. break;
  12778. }
  12779. case SessionStopRequest: //53
  12780. {
  12781. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12782. {
  12783. Update_V2G_Flow_Status(SessionStopResponse);
  12784. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12785. }
  12786. else
  12787. {
  12788. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail\n");
  12789. Update_V2G_Flow_Status(Other_Fault);
  12790. }
  12791. req_is_responsed = TRUE;
  12792. break;
  12793. }
  12794. case SessionStopResponse: //54
  12795. {
  12796. break;
  12797. }
  12798. default:
  12799. {
  12800. break;
  12801. }
  12802. }
  12803. usleep(1000);
  12804. }
  12805. return 0;
  12806. }
  12807. /*===========================================================================
  12808. FUNCTION: V2gMsg_Process_iso1
  12809. DESCRIPTION:
  12810. 1. EnergyTransferMode:
  12811. AC_single_phase_core = 0,
  12812. AC_three_phase_core = 1,
  12813. DC_core = 2,
  12814. DC_extended = 3,
  12815. DC_combo_core = 4,
  12816. DC_unique = 5
  12817. iso1EnergyTransferModeType_AC_single_phase_core = 0,
  12818. iso1EnergyTransferModeType_AC_three_phase_core = 1,
  12819. iso1EnergyTransferModeType_DC_core = 2,
  12820. iso1EnergyTransferModeType_DC_extended = 3,
  12821. iso1EnergyTransferModeType_DC_combo_core = 4,
  12822. iso1EnergyTransferModeType_DC_unique = 5
  12823. PRE-CONDITION:
  12824. INPUT:
  12825. 1. V2gFlowStatus
  12826. OUTPUT:
  12827. GLOBAL VARIABLES:
  12828. 1. V2gFlowStatus
  12829. =============================================================================*/
  12830. int V2gMsg_Process_iso1(int AcceptFd, unsigned char EnergyTransferMode)
  12831. {
  12832. switch (EnergyTransferMode)
  12833. {
  12834. case DC_extended:
  12835. {
  12836. //SAVE_SYS_LOG_MSG_EVCOMM("EnergyTransferMode: DC_extended\n");
  12837. V2gMsg_Process_iso1_DC(AcceptFd);
  12838. break;
  12839. }
  12840. case AC_single_phase_core:
  12841. case AC_three_phase_core:
  12842. {
  12843. //SAVE_SYS_LOG_MSG_EVCOMM("EnergyTransferMode: AC_single_phase_core or AC_three_phase_core\n");
  12844. V2gMsg_Process_iso1_AC(AcceptFd);
  12845. break;
  12846. }
  12847. default:
  12848. {
  12849. SAVE_SYS_LOG_MSG_EVCOMM("[Warning]Unexpected EnergyTransferMode(%d)\n", EnergyTransferMode);
  12850. break;
  12851. }
  12852. }
  12853. return 0;
  12854. }
  12855. /*===========================================================================
  12856. FUNCTION: V2gMsg_Process_iso2_DC
  12857. DESCRIPTION:
  12858. PRE-CONDITION:
  12859. INPUT:
  12860. 1. V2gFlowStatus
  12861. OUTPUT:
  12862. GLOBAL VARIABLES:
  12863. 1. V2gFlowStatus
  12864. =============================================================================*/
  12865. int V2gMsg_Process_iso2_DC(int AcceptFd)
  12866. {
  12867. unsigned char req_is_responsed = FALSE;
  12868. while (req_is_responsed == FALSE)
  12869. {
  12870. //Check if it is in End_Process
  12871. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  12872. {
  12873. break;
  12874. }
  12875. switch(V2gFlowStatus)
  12876. {
  12877. //-------------------------------------------
  12878. case SupportedAppProtocolRequest:
  12879. {
  12880. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  12881. {
  12882. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  12883. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  12884. {
  12885. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12886. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  12887. }
  12888. else
  12889. {
  12890. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
  12891. Update_V2G_Flow_Status(Other_Fault);
  12892. }
  12893. }
  12894. req_is_responsed = TRUE;
  12895. break;
  12896. }
  12897. case SupportedAppProtocolResponse:
  12898. {
  12899. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  12900. {
  12901. Update_V2G_Flow_Status(SessionSetupRequest);
  12902. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12903. }
  12904. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12905. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12906. {
  12907. sprintf((char*)buf_log_evcomm,
  12908. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12909. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12910. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12911. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12912. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12913. }
  12914. else
  12915. {
  12916. }
  12917. break;
  12918. }
  12919. //-------------------------------------------
  12920. case SessionSetupRequest: //19
  12921. {
  12922. if (Proc_iso2_SessionSetupReq(AcceptFd) == 0)
  12923. {
  12924. Update_V2G_Flow_Status(SessionSetupResponse);
  12925. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12926. }
  12927. else
  12928. {
  12929. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
  12930. Update_V2G_Flow_Status(Other_Fault);
  12931. }
  12932. req_is_responsed = TRUE;
  12933. break;
  12934. }
  12935. case SessionSetupResponse: //20
  12936. {
  12937. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  12938. {
  12939. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  12940. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12941. }
  12942. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12943. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12944. {
  12945. sprintf((char*)buf_log_evcomm,
  12946. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12947. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12948. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12949. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12950. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12951. }
  12952. else
  12953. {
  12954. }
  12955. break;
  12956. }
  12957. #if 0
  12958. //-------------------------------------------
  12959. case ServiceDiscoveryRequest: //21
  12960. {
  12961. if (Proc_iso2_ServiceDiscoveryReq(AcceptFd) == 0)
  12962. {
  12963. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  12964. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12965. }
  12966. else
  12967. {
  12968. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
  12969. Update_V2G_Flow_Status(Other_Fault);
  12970. }
  12971. req_is_responsed = TRUE;
  12972. break;
  12973. }
  12974. case ServiceDiscoveryResponse: //22
  12975. {
  12976. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  12977. {
  12978. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  12979. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12980. }
  12981. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12982. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12983. {
  12984. sprintf((char*)buf_log_evcomm,
  12985. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12986. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12987. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12988. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12989. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12990. }
  12991. else
  12992. {
  12993. break;
  12994. }
  12995. }
  12996. //-------------------------------------------
  12997. case ServiceAndPaymentSelectionRequest: //25
  12998. {
  12999. if (Proc_iso2_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  13000. {
  13001. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  13002. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13003. }
  13004. else
  13005. {
  13006. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
  13007. Update_V2G_Flow_Status(Other_Fault);
  13008. }
  13009. req_is_responsed = TRUE;
  13010. break;
  13011. }
  13012. case ServiceAndPaymentSelectionResponse: //26
  13013. {
  13014. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  13015. {
  13016. Update_V2G_Flow_Status(AuthorizationRequest);
  13017. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13018. }
  13019. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13020. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13021. {
  13022. sprintf((char*)buf_log_evcomm,
  13023. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13024. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13025. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13026. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13027. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13028. }
  13029. else
  13030. {
  13031. break;
  13032. }
  13033. }
  13034. //-------------------------------------------
  13035. //case ContractAuthenticationReq:
  13036. case AuthorizationRequest: //29
  13037. {
  13038. if (Proc_iso2_AuthenticationReq(AcceptFd) == 0)
  13039. {
  13040. Update_V2G_Flow_Status(AuthorizationResponse);
  13041. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13042. }
  13043. else
  13044. {
  13045. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  13046. Update_V2G_Flow_Status(Other_Fault);
  13047. }
  13048. req_is_responsed = TRUE;
  13049. break;
  13050. }
  13051. case AuthorizationResponse: //30
  13052. {
  13053. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  13054. {
  13055. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13056. if (Proc_iso2_AuthenticationReq(AcceptFd) == 0)
  13057. {
  13058. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13059. }
  13060. else
  13061. {
  13062. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  13063. Update_V2G_Flow_Status(Other_Fault);
  13064. }
  13065. req_is_responsed = TRUE;
  13066. break;
  13067. }
  13068. //Check for ChargeParameterDiscoveryReq
  13069. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  13070. {
  13071. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13072. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  13073. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]ChargeParameterDiscoveryReq: CSU Permission?");
  13074. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13075. ftime(&SeqStartTime);
  13076. #endif
  13077. }
  13078. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13079. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13080. {
  13081. sprintf((char*)buf_log_evcomm,
  13082. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13083. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13084. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13085. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13086. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13087. }
  13088. else
  13089. {
  13090. break;
  13091. }
  13092. }
  13093. //-------------------------------------------
  13094. case ChargeParameterDiscoveryRequest: //35
  13095. {
  13096. if (Proc_iso2_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  13097. {
  13098. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  13099. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13100. }
  13101. else
  13102. {
  13103. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  13104. Update_V2G_Flow_Status(Other_Fault);
  13105. }
  13106. req_is_responsed = TRUE;
  13107. break;
  13108. }
  13109. case ChargeParameterDiscoveryResponse:
  13110. {
  13111. //STEP 1: Check for Process Timeout
  13112. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13113. ftime(&SeqEndTime);
  13114. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  13115. {
  13116. sprintf((char*)buf_log_evcomm,
  13117. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  13118. DiffTimeb(SeqStartTime, SeqEndTime),
  13119. V2G_SECC_ChargingParameter_Performance_Time);
  13120. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13121. Update_V2G_Flow_Status(Sequence_Timeout);
  13122. break;
  13123. }
  13124. #endif
  13125. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  13126. {
  13127. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13128. if (Proc_iso2_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  13129. {
  13130. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13131. }
  13132. else
  13133. {
  13134. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  13135. Update_V2G_Flow_Status(Other_Fault);
  13136. }
  13137. req_is_responsed = TRUE;
  13138. break;
  13139. }
  13140. //STEP 2: Check for CableCheckReq message
  13141. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  13142. {
  13143. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13144. Update_V2G_Flow_Status(CableCheckRequest);
  13145. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CableCheckReqReq: isolated?");
  13146. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  13147. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  13148. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13149. ftime(&SeqStartTime);
  13150. #endif
  13151. }
  13152. //STEP 3: Wait for PowerDeliveryReq Message
  13153. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13154. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13155. {
  13156. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13157. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13158. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  13159. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13160. ftime(&SeqStartTime);
  13161. #endif
  13162. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13163. {
  13164. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13165. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13166. }
  13167. else
  13168. {
  13169. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  13170. Update_V2G_Flow_Status(Other_Fault);
  13171. }
  13172. break;
  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 CableCheckRequest: //37
  13191. {
  13192. //STEP 3: Execute Cable Check Process
  13193. if (Proc_iso2_CableCheckReq(AcceptFd) == 0)
  13194. {
  13195. Update_V2G_Flow_Status(CableCheckResponse);
  13196. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13197. }
  13198. else
  13199. {
  13200. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  13201. Update_V2G_Flow_Status(Other_Fault);
  13202. }
  13203. req_is_responsed = TRUE;
  13204. break;
  13205. }
  13206. case CableCheckResponse: //38
  13207. {
  13208. //STEP 1: Check for Process Timeout
  13209. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13210. ftime(&SeqEndTime);
  13211. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  13212. {
  13213. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CableCheck] end counting...");
  13214. sprintf((char*)buf_log_evcomm,
  13215. "CableCheck Timeout - (%.02lf of %d ms)\n",
  13216. DiffTimeb(SeqStartTime, SeqEndTime),
  13217. V2G_SECC_CableCheck_Performance_Time);
  13218. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13219. Update_V2G_Flow_Status(Sequence_Timeout);
  13220. //Update_ShmStatusCode(); //[To-Do] to be implemented
  13221. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  13222. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13223. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13224. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13225. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  13226. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  13227. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  13228. break;
  13229. }
  13230. #endif
  13231. //STEP 2: Check for CableCheckReq message
  13232. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  13233. {
  13234. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13235. //STEP 3: Execute Cable Check Process
  13236. if (Proc_iso2_CableCheckReq(AcceptFd) == 0)
  13237. {
  13238. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13239. }
  13240. else
  13241. {
  13242. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  13243. Update_V2G_Flow_Status(Other_Fault);
  13244. }
  13245. req_is_responsed = TRUE;
  13246. break;
  13247. }
  13248. //STEP 3: Check for PreChargeReq message
  13249. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  13250. {
  13251. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13252. Update_V2G_Flow_Status(PreChargeRequest);
  13253. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PreChargeReqReq: waiting for precharge voltage...");
  13254. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  13255. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  13256. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13257. ftime(&SeqStartTime);
  13258. #endif
  13259. }
  13260. //STEP 3: Wait for PowerDeliveryReq Message
  13261. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13262. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13263. {
  13264. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13265. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13266. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  13267. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13268. ftime(&SeqStartTime);
  13269. #endif
  13270. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13271. {
  13272. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13273. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13274. }
  13275. else
  13276. {
  13277. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  13278. Update_V2G_Flow_Status(Other_Fault);
  13279. }
  13280. break;
  13281. }
  13282. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13283. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13284. {
  13285. sprintf((char*)buf_log_evcomm,
  13286. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13287. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13288. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13289. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13290. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13291. }
  13292. else
  13293. {
  13294. break;
  13295. }
  13296. }
  13297. //-------------------------------------------
  13298. case PreChargeRequest: //39
  13299. {
  13300. if (Proc_iso2_PreChargeReq(AcceptFd) == 0)
  13301. {
  13302. Update_V2G_Flow_Status(PreChargeResponse);
  13303. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13304. }
  13305. else
  13306. {
  13307. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  13308. Update_V2G_Flow_Status(Other_Fault);
  13309. }
  13310. req_is_responsed = TRUE;
  13311. break;
  13312. }
  13313. case PreChargeResponse: //40
  13314. {
  13315. //STEP 1: Check for Process Timeout
  13316. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13317. ftime(&SeqEndTime);
  13318. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  13319. {
  13320. sprintf((char*)buf_log_evcomm,
  13321. "Precharge Timeout - (%.02lf of %d ms)\n",
  13322. DiffTimeb(SeqStartTime, SeqEndTime),
  13323. V2G_SECC_PreCharge_Performance_Time);
  13324. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13325. Update_V2G_Flow_Status(Sequence_Timeout);
  13326. //Update_ShmStatusCode(); //[To-Do] to be implemented
  13327. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  13328. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13329. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13330. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13331. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  13332. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  13333. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  13334. break;
  13335. }
  13336. #endif
  13337. //STEP 2: Check for PreChargeReq message
  13338. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  13339. {
  13340. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13341. if (Proc_iso2_PreChargeReq(AcceptFd) == 0)
  13342. {
  13343. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13344. }
  13345. else
  13346. {
  13347. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  13348. Update_V2G_Flow_Status(Other_Fault);
  13349. }
  13350. req_is_responsed = TRUE;
  13351. break;
  13352. }
  13353. //STEP 3: Check for PowerDeliveryReq message
  13354. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13355. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13356. {
  13357. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13358. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  13359. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  13360. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13361. ftime(&SeqStartTime);
  13362. #endif
  13363. }
  13364. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13365. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13366. {
  13367. sprintf((char*)buf_log_evcomm,
  13368. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13369. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13370. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13371. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13372. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13373. }
  13374. else
  13375. {
  13376. break;
  13377. }
  13378. }
  13379. //-------------------------------------------
  13380. case PowerDeliveryRequestStart: //41
  13381. {
  13382. if (Proc_iso2_PowerDeliveryStartReq(AcceptFd) == 0)
  13383. {
  13384. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  13385. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13386. }
  13387. else
  13388. {
  13389. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
  13390. Update_V2G_Flow_Status(Other_Fault);
  13391. }
  13392. req_is_responsed = TRUE;
  13393. break;
  13394. }
  13395. case PowerDeliveryResponsetStart: //42
  13396. {
  13397. //STEP 1: Check for Process Timeout
  13398. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13399. if (ccs_exi_doc_ISO2.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  13400. {
  13401. ftime(&SeqEndTime);
  13402. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  13403. {
  13404. sprintf((char*)buf_log_evcomm,
  13405. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  13406. DiffTimeb(SeqStartTime, SeqEndTime),
  13407. 2000);
  13408. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13409. Update_V2G_Flow_Status(Sequence_Timeout);
  13410. }
  13411. break;
  13412. }
  13413. #endif
  13414. //STEP 2: Wait for CurrentDemandReq Message
  13415. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  13416. {
  13417. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13418. Update_V2G_Flow_Status(CurrentDemandRequest);
  13419. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CurrentDemandReqReq: energy transfering...");
  13420. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  13421. }
  13422. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13423. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13424. {
  13425. sprintf((char*)buf_log_evcomm,
  13426. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13427. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13428. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13429. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13430. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13431. }
  13432. else
  13433. {
  13434. break;
  13435. }
  13436. }
  13437. //-------------------------------------------
  13438. case CurrentDemandRequest: //45,
  13439. {
  13440. if (Proc_iso2_CurrentDemandReq(AcceptFd) == 0)
  13441. {
  13442. Update_V2G_Flow_Status(CurrentDemandResponse);
  13443. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13444. }
  13445. else
  13446. {
  13447. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  13448. Update_V2G_Flow_Status(Other_Fault);
  13449. }
  13450. req_is_responsed = TRUE;
  13451. break;
  13452. }
  13453. case CurrentDemandResponse: //46,
  13454. {
  13455. //STEP 1: Wait for CurrentDemandReq Message
  13456. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  13457. {
  13458. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13459. if (Proc_iso2_CurrentDemandReq(AcceptFd) == 0)
  13460. {
  13461. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13462. }
  13463. else
  13464. {
  13465. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  13466. Update_V2G_Flow_Status(Other_Fault);
  13467. }
  13468. req_is_responsed = TRUE;
  13469. break;
  13470. }
  13471. //STEP 2: Wait for PowerDeliveryReq Message
  13472. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13473. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13474. {
  13475. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13476. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13477. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  13478. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13479. ftime(&SeqStartTime);
  13480. #endif
  13481. }
  13482. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13483. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13484. {
  13485. sprintf((char*)buf_log_evcomm,
  13486. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13487. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13488. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13489. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13490. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13491. }
  13492. else
  13493. {
  13494. break;
  13495. }
  13496. }
  13497. //-------------------------------------------
  13498. case PowerDeliveryRequestStop: //49,
  13499. {
  13500. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13501. {
  13502. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13503. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13504. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13505. ftime(&SeqStartTime);
  13506. #endif
  13507. }
  13508. else
  13509. {
  13510. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  13511. Update_V2G_Flow_Status(Other_Fault);
  13512. }
  13513. req_is_responsed = TRUE;
  13514. break;
  13515. }
  13516. case PowerDeliveryResponseStop: //50,
  13517. {
  13518. //STEP 1: Check for Process Timeout
  13519. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13520. ftime(&SeqEndTime);
  13521. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  13522. {
  13523. sprintf((char*)buf_log_evcomm,
  13524. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  13525. DiffTimeb(SeqStartTime, SeqEndTime),
  13526. 2000);
  13527. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13528. Update_V2G_Flow_Status(Sequence_Timeout);
  13529. break;
  13530. }
  13531. #endif
  13532. //STEP 2: Check for WeldingDetectionReq Message
  13533. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  13534. {
  13535. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13536. Update_V2G_Flow_Status(WeldingDetectionRequest);
  13537. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]WeldingDetectionReq: ongoing...");
  13538. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  13539. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13540. ftime(&SeqStartTime);
  13541. #endif
  13542. }
  13543. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  13544. {
  13545. Update_V2G_Flow_Status(SessionStopRequest);
  13546. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13547. if (Proc_iso2_SessionStopReq(AcceptFd) == 0)
  13548. {
  13549. Update_V2G_Flow_Status(SessionStopResponse);
  13550. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13551. }
  13552. else
  13553. {
  13554. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  13555. Update_V2G_Flow_Status(Other_Fault);
  13556. }
  13557. break;
  13558. }
  13559. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13560. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13561. {
  13562. sprintf((char*)buf_log_evcomm,
  13563. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13564. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13565. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13566. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13567. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13568. }
  13569. else
  13570. {
  13571. break;
  13572. }
  13573. }
  13574. //-------------------------------------------
  13575. case WeldingDetectionRequest: //51,
  13576. {
  13577. if (Proc_iso2_WeldingDetectionReq(AcceptFd) == 0)
  13578. {
  13579. Update_V2G_Flow_Status(WeldingDetectionResponse);
  13580. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13581. }
  13582. else
  13583. {
  13584. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  13585. Update_V2G_Flow_Status(Other_Fault);
  13586. }
  13587. req_is_responsed = TRUE;
  13588. break;
  13589. }
  13590. case WeldingDetectionResponse: //52,
  13591. {
  13592. //STEP 1: Check for Process Timeout
  13593. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13594. ftime(&SeqEndTime);
  13595. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  13596. {
  13597. sprintf((char*)buf_log_evcomm,
  13598. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  13599. DiffTimeb(SeqStartTime, SeqEndTime),
  13600. V2G_SECC_WeldingDetection_Performance_Time);
  13601. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13602. Update_V2G_Flow_Status(Sequence_Timeout);
  13603. break;
  13604. }
  13605. #endif
  13606. //STEP 2: Check for WeldingDetectionReq Message
  13607. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  13608. {
  13609. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13610. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  13611. {
  13612. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13613. }
  13614. else
  13615. {
  13616. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  13617. Update_V2G_Flow_Status(Other_Fault);
  13618. }
  13619. req_is_responsed = TRUE;
  13620. break;
  13621. }
  13622. //STEP 3: Check for SessionStopReq Message
  13623. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  13624. {
  13625. Update_V2G_Flow_Status(SessionStopRequest);
  13626. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13627. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  13628. }
  13629. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13630. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13631. {
  13632. sprintf((char*)buf_log_evcomm,
  13633. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13634. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13635. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13636. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13637. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13638. }
  13639. else
  13640. {
  13641. break;
  13642. }
  13643. }
  13644. //-------------------------------------------
  13645. case SessionStopRequest: //53,
  13646. {
  13647. if (Proc_iso2_SessionStopReq(AcceptFd) == 0)
  13648. {
  13649. Update_V2G_Flow_Status(SessionStopResponse);
  13650. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13651. }
  13652. else
  13653. {
  13654. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  13655. Update_V2G_Flow_Status(Other_Fault);
  13656. }
  13657. req_is_responsed = TRUE;
  13658. //break;
  13659. }
  13660. case SessionStopResponse: //54,
  13661. {
  13662. break;
  13663. }
  13664. #endif
  13665. //-------------------------------------------
  13666. default:
  13667. {
  13668. break;
  13669. }
  13670. }
  13671. usleep(1000);
  13672. }
  13673. return 0;
  13674. }
  13675. /*===========================================================================
  13676. FUNCTION: V2gMsg_Process_iso2_AC
  13677. DESCRIPTION:
  13678. PRE-CONDITION:
  13679. INPUT:
  13680. 1. V2gFlowStatus
  13681. OUTPUT:
  13682. GLOBAL VARIABLES:
  13683. 1. V2gFlowStatus
  13684. =============================================================================*/
  13685. int V2gMsg_Process_iso2_AC(int AcceptFd)
  13686. {
  13687. return 0;
  13688. }
  13689. /*===========================================================================
  13690. FUNCTION: V2gMsg_Process_iso2
  13691. DESCRIPTION:
  13692. PRE-CONDITION:
  13693. INPUT:
  13694. 1. V2gFlowStatus
  13695. OUTPUT:
  13696. GLOBAL VARIABLES:
  13697. 1. V2gFlowStatus
  13698. =============================================================================*/
  13699. int V2gMsg_Process_iso2(int AcceptFd, unsigned char EnergyTransferMode)
  13700. {
  13701. switch (EnergyTransferMode)
  13702. {
  13703. case DC_extended:
  13704. {
  13705. V2gMsg_Process_iso2_DC(AcceptFd);
  13706. break;
  13707. }
  13708. case AC_single_phase_core:
  13709. case AC_three_phase_core:
  13710. {
  13711. V2gMsg_Process_iso2_AC(AcceptFd);
  13712. break;
  13713. }
  13714. default:
  13715. {
  13716. sprintf((char*)buf_log_evcomm,
  13717. "[ISO2][Warning]Unexpected EnergyTransferMode(%d)",
  13718. EnergyTransferMode);
  13719. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13720. break;
  13721. }
  13722. }
  13723. return 0;
  13724. }
  13725. /*===========================================================================
  13726. FUNCTION: V2gMsg_Process
  13727. DESCRIPTION:
  13728. PRE-CONDITION:
  13729. INPUT:
  13730. OUTPUT:
  13731. GLOBAL VARIABLES:
  13732. =============================================================================*/
  13733. int V2gMsg_Process(int AcceptFd)
  13734. {
  13735. int errn = 0;
  13736. switch (ShmCcsData->CommProtocol)
  13737. {
  13738. case V2GT_MSG_PROTOCOL_DIN70121: //0
  13739. {
  13740. V2gMsg_Process_din(AcceptFd);
  13741. break;
  13742. }
  13743. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  13744. {
  13745. V2gMsg_Process_iso1(AcceptFd, ShmCcsData->EnergyTransferMode);
  13746. break;
  13747. }
  13748. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  13749. {
  13750. V2gMsg_Process_iso2(AcceptFd, ShmCcsData->EnergyTransferMode);
  13751. break;
  13752. }
  13753. default:
  13754. {
  13755. SAVE_SYS_LOG_MSG_EVCOMM("[Warning]Unexpected CommProtocol(%d)\n", ShmCcsData->CommProtocol);
  13756. break;
  13757. }
  13758. }
  13759. return errn;
  13760. }
  13761. /*===========================================================================
  13762. FUNCTION: V2gMsg_Rx
  13763. DESCRIPTION:
  13764. PRE-CONDITION:
  13765. INPUT:
  13766. OUTPUT:
  13767. GLOBAL VARIABLES:
  13768. =============================================================================*/
  13769. int V2gMsg_Rx(int AcceptFd)
  13770. {
  13771. int errn = 0;
  13772. unsigned int packet_size = 0;
  13773. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  13774. packet_size = recv(AcceptFd, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, 0);
  13775. //[CAUTION] Everytime recv() is called, it will take a default time to wait for TCP packets.
  13776. //The more time you call recv(), the more time you will waste here.
  13777. //Here it is suggested that response immediatedly once you receive any packets.
  13778. //For configuring the Rx waiting time, please use setsockopt().
  13779. if(packet_size > 0) //[Joseph] If there is no data, ignore. (TBD)
  13780. {
  13781. //DEBUG_PRINTF_EVCOMM_DETAIL("\n\n Got TCP V2GTP Message: size = %d Bytes\n", packet_size);
  13782. errn = V2gMsgDecoder(V2gtpMsgRxBuf, packet_size, V2gFlowStatus);
  13783. if (errn < 0)
  13784. {
  13785. sprintf((char*)buf_log_evcomm, "[ERROR]V2gMsgDecoder (%d)", errn);
  13786. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13787. }
  13788. }
  13789. return errn;
  13790. }
  13791. /*===========================================================================
  13792. FUNCTION: V2gComm
  13793. DESCRIPTION:
  13794. PRE-CONDITION:
  13795. 1. TCP socket is connected.
  13796. INPUT:
  13797. 1. AcceptFd //TCP Connection ID
  13798. 2. V2gtpMsgRxBuf[] //V2GTP Messages (Header + Payload)
  13799. 3. V2GTP_MSG_RX_BUFFER_SIZE //64*1024 = 65,536 = 65.5K (Bytes)
  13800. OUTPUT:
  13801. GLOBAL VARIABLES:
  13802. 1. V2gtpMsgRxBuf[]
  13803. =============================================================================*/
  13804. int V2gComm(int AcceptFd)
  13805. {
  13806. int errn = 0;
  13807. if (V2gMsg_Rx(AcceptFd) < 0)
  13808. {
  13809. Update_V2G_Flow_Status(Other_Fault);
  13810. errn = -1;
  13811. }
  13812. //following are the response message handling according to status flag
  13813. if (V2gMsg_Process(AcceptFd) < 0)
  13814. {
  13815. errn = -1;
  13816. }
  13817. //Error Check
  13818. //V2G_Error_Monitor();
  13819. return errn;
  13820. }
  13821. /*===========================================================================
  13822. FUNCTION: SdpUdpConnected
  13823. DESCRIPTION:
  13824. PRE-CONDITION:
  13825. INPUT:
  13826. OUTPUT:
  13827. GLOBAL VARIABLES:
  13828. =============================================================================*/
  13829. int SdpUdpConnected()
  13830. {
  13831. int packet_size,Rtn;
  13832. struct sockaddr_in6 ServerAddr,ClientAddr;
  13833. struct V2gtpHeader *header;
  13834. unsigned char *payload;
  13835. if(UdpSock <= 0)
  13836. {
  13837. if ((UdpSock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
  13838. {
  13839. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SdpUdpConnected: Fail to open UdpSock");
  13840. return 0;
  13841. }
  13842. memset(&ServerAddr,0, sizeof(struct sockaddr_in));
  13843. ServerAddr.sin6_family = AF_INET6;
  13844. ServerAddr.sin6_addr = in6addr_any;
  13845. ServerAddr.sin6_port = htons(SdpUdpServerPort);
  13846. if(bind(UdpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) <0)
  13847. {
  13848. sprintf((char*)buf_log_evcomm,
  13849. "SdpUdpConnected: Fail to bind UdpSock(%d)",
  13850. UdpSock);
  13851. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13852. close(UdpSock);
  13853. UdpSock = -1;
  13854. return 0;
  13855. }
  13856. sprintf((char*)buf_log_evcomm, "[UdpSock]opend:%d", UdpSock);
  13857. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13858. sprintf((char*)buf_log_evcomm, "[SDP]Req from EVCC: waiting...(%d)", UdpSock);
  13859. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13860. }
  13861. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  13862. memset(&ClientAddr, 0, sizeof(struct sockaddr_in));
  13863. Rtn = sizeof(struct sockaddr_in6);
  13864. packet_size = recvfrom(UdpSock, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *)&ClientAddr, (socklen_t *)&Rtn);
  13865. if(packet_size > 0)
  13866. {
  13867. header = (struct V2gtpHeader *) V2gtpMsgRxBuf;
  13868. payload = V2gtpMsgRxBuf+sizeof(struct V2gtpHeader);
  13869. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  13870. {
  13871. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n Got UDP packet_size = %d (Bytes)\n", packet_size);
  13872. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***********************************\n");
  13873. DEBUG_PRINTF_EVCOMM_DETAIL("***** Received SDP Packet *****\n");
  13874. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  13875. DEBUG_PRINTF_EVCOMM_DETAIL("ClientAddress=");
  13876. for(Rtn = 0; Rtn < 16; Rtn += 2)
  13877. {
  13878. DEBUG_PRINTF_EVCOMM_DETAIL("%02x%02x:",ClientAddr.sin6_addr.s6_addr[Rtn],ClientAddr.sin6_addr.s6_addr[Rtn+1]);
  13879. }
  13880. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  13881. DEBUG_PRINTF_EVCOMM_DETAIL("ClientPort=%d\n",ClientAddr.sin6_port);
  13882. DEBUG_PRINTF_EVCOMM_DETAIL("ProtocolVersion=%d\n",header->ProtocolVersion);
  13883. DEBUG_PRINTF_EVCOMM_DETAIL("InverseProtocolVersion=0x%x\n",header->InverseProtocolVersion);
  13884. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadType=0x%x\n",htons(header->PayloadType));
  13885. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadLength=0x%x\n",htonl(header->PayloadLength));
  13886. DEBUG_PRINTF_EVCOMM_DETAIL("htons(header->PayloadType)=0x%x\n",htons(header->PayloadType));
  13887. }
  13888. #endif
  13889. if( (header->ProtocolVersion == 0x01) &&
  13890. (header->InverseProtocolVersion == 0xFE) &&
  13891. (htons(header->PayloadType) == V2GTP_PAYLOAD_TYPE_SDP_REQUEST))
  13892. {
  13893. sprintf((char*)buf_log_evcomm, "[SDP][RX]Req from EVCC: GOT(%d)", UdpSock);
  13894. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13895. DEBUG_PRINTF_EVCOMM_DETAIL("Security=0x%x\n", *(payload + 0));
  13896. DEBUG_PRINTF_EVCOMM_DETAIL("TransportProtocol=0x%x\n", *(payload + 1));
  13897. header->PayloadType = htons(V2GTP_PAYLOAD_TYPE_SDP_RESPONSE);
  13898. header->PayloadLength = htonl(20); //Fixed Length=20
  13899. memset(payload, 0, 20);
  13900. // MAC address[0:2] + FFFE + MAC address[3:5]
  13901. payload[0] = (IPV6_LINK_LOCAL_PREFIX>>8) & 0xFF;
  13902. payload[1] = IPV6_LINK_LOCAL_PREFIX & 0xFF;
  13903. #ifdef TEST_WITH_ETH0
  13904. payload[8] = eth0Mac[0];
  13905. payload[8] ^= 0x02;// bit 1 should complemented.
  13906. payload[9] = eth0Mac[1];
  13907. payload[10] = eth0Mac[2];
  13908. payload[11] = 0xFF;
  13909. payload[12] = 0xFE;
  13910. payload[13] = eth0Mac[3];
  13911. payload[14] = eth0Mac[4];
  13912. payload[15] = eth0Mac[5];
  13913. #else
  13914. payload[8] = CsuMac[0];
  13915. payload[8] ^= 0x02;// bit 1 should complemented.
  13916. payload[9] = CsuMac[1];
  13917. payload[10] = CsuMac[2];
  13918. payload[11] = 0xFF;
  13919. payload[12] = 0xFE;
  13920. payload[13] = CsuMac[3];
  13921. payload[14] = CsuMac[4];
  13922. payload[15] = CsuMac[5];
  13923. #endif
  13924. //TCP port
  13925. payload[16] = (EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active>>8) & 0xFF;
  13926. payload[17] = EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active & 0xFF;
  13927. payload[18] = SDP_PAYLOAD_SECURITY_NONE; //Security
  13928. payload[19] = SDP_PAYLOAD_TRANS_PROTOCOL_TCP; //Transport protocol
  13929. //[To-Do] Setup the TCP in advance to receive the coming TCP handshke messages after SDP response.
  13930. Rtn = sendto(UdpSock, V2gtpMsgRxBuf, sizeof(struct V2gtpHeader) + htonl(header->PayloadLength), 0, (struct sockaddr *)&ClientAddr, sizeof(struct sockaddr_in6));
  13931. sprintf((char*)buf_log_evcomm, "[SDP][TX]Res from SECC");
  13932. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13933. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  13934. {
  13935. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response SDP Packet *****\n");
  13936. DEBUG_PRINTF_EVCOMM_DETAIL("Send size=%d\n",Rtn);
  13937. DEBUG_PRINTF_EVCOMM_DETAIL("Destination Address=");
  13938. for(Rtn = 0; Rtn < 16; Rtn++)
  13939. {
  13940. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ", ClientAddr.sin6_addr.s6_addr[Rtn]);
  13941. }
  13942. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  13943. DEBUG_PRINTF_EVCOMM_DETAIL("Destination Port=%d\n", ClientAddr.sin6_port);
  13944. DEBUG_PRINTF_EVCOMM_DETAIL("ProtocolVersion=%d\n", header->ProtocolVersion);
  13945. DEBUG_PRINTF_EVCOMM_DETAIL("InverseProtocolVersion=0x%x\n", header->InverseProtocolVersion);
  13946. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadType=0x%x\n", htons(header->PayloadType));
  13947. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadLength=0x%x\n", htonl(header->PayloadLength));
  13948. DEBUG_PRINTF_EVCOMM_DETAIL("SECC Ipv6 Address=");
  13949. for(Rtn = 0; Rtn < 16; Rtn++)
  13950. {
  13951. DEBUG_PRINTF_EVCOMM_DETAIL("%02x:",payload[Rtn]);
  13952. }
  13953. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  13954. DEBUG_PRINTF_EVCOMM_DETAIL("SECC Port=%d\n", (payload[16]<<8 | payload[17]));
  13955. DEBUG_PRINTF_EVCOMM_DETAIL("Security=0x%x\n", payload[19]);
  13956. DEBUG_PRINTF_EVCOMM_DETAIL("TransportProtocol=0x%x\n", payload[20]);
  13957. }
  13958. #endif
  13959. if(Rtn > 0)
  13960. {
  13961. return 1;
  13962. }
  13963. }
  13964. }
  13965. return 0;
  13966. }
  13967. /*===========================================================================
  13968. FUNCTION: V2gTcpConnected
  13969. DESCRIPTION:
  13970. PRE-CONDITION:
  13971. INPUT:
  13972. OUTPUT:
  13973. GLOBAL VARIABLES:
  13974. =============================================================================*/
  13975. int V2gTcpConnected()
  13976. {
  13977. int Rtn,AcceptFd;
  13978. struct sockaddr_in6 ServerAddr,ClientAddr;
  13979. if(TcpSock <= 0)
  13980. {
  13981. if ((TcpSock = socket(PF_INET6, SOCK_STREAM, 0)) < 0)
  13982. {
  13983. sprintf((char*)buf_log_evcomm,
  13984. "V2gTcpConnected: Fail to open TcpSock (%s)",
  13985. strerror(errno));
  13986. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13987. usleep(100000); //100ms
  13988. return 0;
  13989. }
  13990. fcntl(TcpSock, F_SETFL, O_NONBLOCK); //set to O_NONBLOCK
  13991. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]socket set: DONE");
  13992. memset(&ServerAddr,0, sizeof(struct sockaddr_in));
  13993. ServerAddr.sin6_family = PF_INET6;
  13994. ServerAddr.sin6_addr = in6addr_any;
  13995. ServerAddr.sin6_port = htons(EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  13996. //ServerAddr.sin6_port = htons(SdpTcpServerPort + (rand() % 10) + 1);
  13997. //printf("SdpTcpServerPort = %d(DEC)\n", htons(ServerAddr.sin6_port));
  13998. if(bind(TcpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) < 0)
  13999. {
  14000. sprintf((char*)buf_log_evcomm,
  14001. "V2gTcpConnected: Fail to bind TcpSock (%s), SdpTcpServerPort = %d",
  14002. strerror(errno),
  14003. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active
  14004. );
  14005. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14006. //Change to another TCP port
  14007. /*
  14008. memset(&ServerAddr, 0, sizeof(struct sockaddr_in));
  14009. ServerAddr.sin6_family = PF_INET6;
  14010. ServerAddr.sin6_addr = in6addr_any;
  14011. //ServerAddr.sin6_port = htons(SdpTcpServerPort + (rand() % 1000) + 1);
  14012. ServerAddr.sin6_port = htons(EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  14013. */
  14014. if(bind(TcpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) < 0)
  14015. {
  14016. sprintf((char*)buf_log_evcomm,
  14017. "V2gTcpConnected: Fail to bind TcpSock (%s), SdpTcpServerPort = %d",
  14018. strerror(errno),
  14019. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active
  14020. );
  14021. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14022. usleep(100000); //100ms
  14023. close(TcpSock);
  14024. TcpSock = -1;
  14025. return 0;
  14026. }
  14027. }
  14028. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]blid: DONE");
  14029. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]listen: START");
  14030. if(listen(TcpSock, 1) == -1) //only accept one connection
  14031. {
  14032. sprintf((char*)buf_log_evcomm,
  14033. "V2gTcpConnected: Fail to listen TcpSock (%s)",
  14034. strerror(errno));
  14035. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14036. usleep(100000); //100ms
  14037. close(TcpSock);
  14038. TcpSock = -1;
  14039. return 0;
  14040. }
  14041. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]listen: DONE");
  14042. sprintf((char*)buf_log_evcomm, "[TCP]TcpSock: opened(%d), port=%d", TcpSock, htons(ServerAddr.sin6_port));
  14043. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14044. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]accept: START");
  14045. }
  14046. Rtn = sizeof(struct sockaddr_in6);
  14047. if((AcceptFd = accept(TcpSock, (struct sockaddr *)&ClientAddr, (socklen_t *)&Rtn)) == -1)
  14048. {
  14049. static BOOL tmp = 0;
  14050. if (tmp == 0)
  14051. {
  14052. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]Wait TCP connection...");
  14053. tmp = 1;
  14054. }
  14055. else
  14056. {
  14057. //DEBUG_PRINTF_EVCOMM_DETAIL(".");
  14058. }
  14059. return 0;
  14060. }
  14061. SAVE_SYS_LOG_MSG_EVCOMM("%s", "[TCP]accept: DONE\n");
  14062. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  14063. {
  14064. DEBUG_PRINTF_EVCOMM_DETAIL("\n\nAccept one TCP connection:\n");
  14065. DEBUG_PRINTF_EVCOMM_DETAIL("AcceptFd=%d\n",AcceptFd);
  14066. DEBUG_PRINTF_EVCOMM_DETAIL("ClientAddress=");
  14067. for(Rtn = 0; Rtn < 16; Rtn += 2)
  14068. {
  14069. DEBUG_PRINTF_EVCOMM_DETAIL("%02x%02x:", ClientAddr.sin6_addr.s6_addr[Rtn], ClientAddr.sin6_addr.s6_addr[Rtn+1]);
  14070. }
  14071. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  14072. DEBUG_PRINTF_EVCOMM_DETAIL("ClientPort=%d\n", ClientAddr.sin6_port);
  14073. }
  14074. #endif
  14075. return AcceptFd;
  14076. }
  14077. /*===========================================================================
  14078. FUNCTION: End_Process
  14079. DESCRIPTION:
  14080. PRE-CONDITION:
  14081. 1. <CAUTION> This function could only be used in SeccComm fork2.
  14082. INPUT:
  14083. OUTPUT:
  14084. GLOBAL VARIABLES:
  14085. =============================================================================*/
  14086. int End_Process()
  14087. {
  14088. if(EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  14089. {
  14090. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "End_Process has been triggered by another event.");
  14091. return -1;
  14092. }
  14093. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Entering...");
  14094. //STEP 1: Ask CSU to Stop
  14095. EVCOMM_SYS_INFO.End_Process_inused = TRUE;
  14096. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  14097. EVCOMM_SYS_INFO.ConnectorLocked = FALSE;
  14098. ShmInternalComm->ChargingPermission = FALSE;
  14099. //Step 2: Close sockets
  14100. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Close sockets...");
  14101. if(RawSock > 0)
  14102. {
  14103. close(RawSock);
  14104. }
  14105. if(UdpSock > 0)
  14106. {
  14107. close(UdpSock);
  14108. }
  14109. if(TcpSock > 0)
  14110. {
  14111. close(TcpSock);
  14112. close(TcpAcceptFd);
  14113. }
  14114. RawSock = UdpSock = TcpSock = TcpAcceptFd = -1;
  14115. //STEP 3: Switch to State E
  14116. //SwitchCpStateE(ENABLE);
  14117. //STEP 4: Close tcpdump
  14118. Sniffer_Tcpdump(DISABLE);
  14119. //STEP 5: Keep 100% PWM for 5 seconds
  14120. OutputCpPwmDuty(100);
  14121. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 5");
  14122. sleep(1);
  14123. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 4");
  14124. sleep(1);
  14125. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 3");
  14126. sleep(1);
  14127. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 2");
  14128. sleep(1);
  14129. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 1");
  14130. sleep(1);
  14131. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 0");
  14132. AttenProfileCnt = 0;
  14133. init_appHandEXIDocument(&ccs_handshake);
  14134. // Qca7kPowerReset(); //reset QCA7000 /* +++ 20200808, vern, should disconnected PLC connection after session stop ---*/
  14135. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  14136. {
  14137. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[End_Process]1st sync...");
  14138. system("sync");
  14139. }
  14140. #endif
  14141. //STEP 4: Switch to State E
  14142. //Keep State E for 5 seconds
  14143. #if 0
  14144. SwitchCpStateE(ENABLE); //Set PWM Duty as 0 and set State as E (0V)
  14145. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 5");
  14146. sleep(1);
  14147. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 4");
  14148. sleep(1);
  14149. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 3");
  14150. sleep(1);
  14151. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 2");
  14152. sleep(1);
  14153. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 1");
  14154. sleep(1);
  14155. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 0");
  14156. #endif
  14157. //Reset Memory
  14158. unsigned char SlaveAddress_backup;
  14159. unsigned int matched_backup;
  14160. //unsigned char state_backup;
  14161. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Soft reset (closing SeccComm)...");
  14162. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------");
  14163. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "-- EVCOMM: END --");
  14164. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------\n");
  14165. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  14166. {
  14167. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "2nd sync...");
  14168. system("sync");
  14169. }
  14170. #endif
  14171. system("sleep 1");
  14172. //Backup CsuComm flags
  14173. SlaveAddress_backup = ShmInternalComm->SlaveAddress;
  14174. matched_backup = CSUCOMMDC_TASK_FLAG.matched;
  14175. //state_backup = Check_V2G_Flow_Status();
  14176. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  14177. memset(V2gtpMsgTxBuf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14178. memset(&ccs_handshake, 0, sizeof(struct appHandEXIDocument));
  14179. memset(&ccs_exi_doc_DIN, 0, sizeof(struct dinEXIDocument));
  14180. memset(V2GTP_Tx_buf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14181. memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  14182. memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
  14183. memset(ShmInternalComm, 0, sizeof(struct InternalComm));
  14184. memset(ShmCcsData, 0, sizeof(struct CcsData));
  14185. //Resume CsuComm flags
  14186. ShmInternalComm->SlaveAddress = SlaveAddress_backup;
  14187. CSUCOMMDC_TASK_FLAG.matched = matched_backup;
  14188. Sniffer_Candump(DISABLE);
  14189. Sniffer_Candump(ENABLE);
  14190. //memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo)); //EVCOMM_SYS_INFO.End_Process_inused = FALSE;
  14191. //EVCOMM_SYS_INFO.End_Process_inused = TRUE;
  14192. //Update_V2G_Flow_Status(state_backup);
  14193. //CP_Detection_Pid = 0;
  14194. //PP_Detection_Pid = 0;
  14195. //Error_Monitor_Pid = 0;
  14196. //system("cd /root;./reset_soft.sh");
  14197. system("pkill Module_CCS");
  14198. while(1)
  14199. {
  14200. //wait for CSU confirm
  14201. usleep(1000);
  14202. }
  14203. }
  14204. /*===========================================================================
  14205. FUNCTION: Parameters_Init
  14206. DESCRIPTION:
  14207. PRE-CONDITION:
  14208. INPUT:
  14209. OUTPUT:
  14210. GLOBAL VARIABLES:
  14211. =============================================================================*/
  14212. int Parameters_Init()
  14213. {
  14214. //Step 0: Generate random number
  14215. unsigned int value_random;
  14216. struct timeb time_seed;
  14217. ftime(&time_seed);
  14218. srand(time_seed.millitm);
  14219. //Step 1: Init SDP TCP Port
  14220. value_random = rand();
  14221. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active = (unsigned short)(SdpTcpServerPort + (value_random % 10000) + 1);
  14222. sprintf((char*)buf_log_evcomm,
  14223. "[Init]TCP Port:OK(%d)",
  14224. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  14225. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14226. //Step 2: Init SessionID
  14227. value_random = rand();
  14228. memcpy(&EVCOMM_SYS_INFO.SessionID[0], &value_random, 4);
  14229. value_random = rand();
  14230. memcpy(&EVCOMM_SYS_INFO.SessionID[4], &value_random, 4);
  14231. sprintf((char*)buf_log_evcomm,
  14232. "[Init]SessionID:OK(%02X%02X%02X%02X%02X%02X%02X%02X)",
  14233. EVCOMM_SYS_INFO.SessionID[0],
  14234. EVCOMM_SYS_INFO.SessionID[1],
  14235. EVCOMM_SYS_INFO.SessionID[2],
  14236. EVCOMM_SYS_INFO.SessionID[3],
  14237. EVCOMM_SYS_INFO.SessionID[4],
  14238. EVCOMM_SYS_INFO.SessionID[5],
  14239. EVCOMM_SYS_INFO.SessionID[6],
  14240. EVCOMM_SYS_INFO.SessionID[7]);
  14241. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14242. return 0;
  14243. }
  14244. /*===========================================================================
  14245. FUNCTION: AC share memory synchronize
  14246. DESCRIPTION:
  14247. PRE-CONDITION:
  14248. INPUT:
  14249. OUTPUT:
  14250. GLOBAL VARIABLES:
  14251. =============================================================================*/
  14252. int SyncAcShreaMemory()
  14253. {
  14254. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  14255. pid_t pid;
  14256. pid = fork();
  14257. if(pid == 0)
  14258. {
  14259. for(;;)
  14260. {
  14261. if(!EVCOMM_SYS_INFO.End_Process_inused)
  14262. {
  14263. for(uint8_t gun_index=0;gun_index<1;gun_index++)
  14264. {
  14265. //========================================
  14266. // CSU -> CCS setting
  14267. //========================================
  14268. // Permission
  14269. if(ShmInternalComm->ChargingPermission != ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission)
  14270. {
  14271. DEBUG_INFO("AC permission: %d -> %d\n", ShmInternalComm->ChargingPermission, ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission);
  14272. ShmInternalComm->ChargingPermission_new = ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission;
  14273. ShmInternalComm->ChargingPermission_pre = ShmInternalComm->ChargingPermission;
  14274. ShmInternalComm->ChargingPermission = ShmInternalComm->ChargingPermission_new;
  14275. }
  14276. // CP
  14277. ShmInternalComm->AC_CpPositiveVoltage = ShmCharger->gun_info[gun_index].acCcsInfo.CpPositiveVoltage;
  14278. if(ShmInternalComm->AC_CpPresentState != ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState)
  14279. {
  14280. DEBUG_INFO("CP state: %d -> %d\n", ShmInternalComm->AC_CpPresentState, ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState);
  14281. ShmInternalComm->AC_CpPresentState = ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState;
  14282. }
  14283. //========================================
  14284. // CCS -> CSU check
  14285. //========================================
  14286. // V2G message flow status
  14287. if(ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus != Check_V2G_Flow_Status())
  14288. {
  14289. //DEBUG_INFO("PresentMsgFlowStatus: %d -> %d\n", ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus, Check_V2G_Flow_Status());
  14290. ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus = Check_V2G_Flow_Status();
  14291. switch(ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus)
  14292. {
  14293. case PowerDeliveryRequestStart ... ChargingStatusResponse:
  14294. ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_START_MODE;
  14295. break;
  14296. case CM_SLAC_PARM_REQ ... PreChargeResponse:
  14297. ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_STANDBY_MODE;
  14298. break;
  14299. default:
  14300. ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_STOP_MODE;
  14301. break;
  14302. }
  14303. }
  14304. }
  14305. }
  14306. usleep(1000);
  14307. }
  14308. }
  14309. #endif
  14310. return 0;
  14311. }
  14312. /*===========================================================================
  14313. FUNCTION: main
  14314. DESCRIPTION:
  14315. PRE-CONDITION:
  14316. INPUT:
  14317. OUTPUT:
  14318. GLOBAL VARIABLES:
  14319. =============================================================================*/
  14320. int main(int argc, char *argv[])
  14321. {
  14322. //unsigned char Rtn;
  14323. Qca7kPowerReset();
  14324. //Initialization
  14325. ShareMemory_Init();
  14326. memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
  14327. if(RawSock > 0)
  14328. {
  14329. close(RawSock);
  14330. }
  14331. if(UdpSock > 0)
  14332. {
  14333. close(UdpSock);
  14334. }
  14335. if(TcpSock > 0)
  14336. {
  14337. close(TcpSock);
  14338. }
  14339. RawSock = UdpSock = TcpSock = -1;
  14340. Update_V2G_Flow_Status(IDLE);
  14341. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------");
  14342. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "-- EVCOMM: START --");
  14343. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------");
  14344. //Init V2G TCP/IPv6 packets buffer
  14345. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  14346. memset(V2gtpMsgTxBuf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14347. //Release State E Control
  14348. SwitchCpStateE(DISABLE);
  14349. OutputCpPwmDuty(100);
  14350. //start to detect CP pilot state
  14351. CP_Detection_Pid = 0;
  14352. CP_Detection(); //fork1
  14353. SAVE_SYS_LOG_MSG_EVCOMM("[fork1]CP Detection: ON\n");
  14354. //start to detect errors
  14355. Error_Monitor(); //fork2
  14356. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Error Monitor: ON\n");
  14357. //start to detect PP
  14358. PP_Detection_Pid = 0;
  14359. #if (PP_PROTECTION_MECHANISM == ENABLE)
  14360. PP_Detection();
  14361. SAVE_SYS_LOG_MSG_EVCOMM("[fork3]PP Detection: ON\n");
  14362. #else
  14363. SAVE_SYS_LOG_MSG_EVCOMM("[fork3]PP Detection: OFF\n");
  14364. #endif
  14365. //Init communication parameters
  14366. GetEthMac((uint8_t*)QcaInterface, CsuMac);
  14367. GetEthMac((uint8_t*)"eth0", eth0Mac);
  14368. AttenProfileCnt = 0;
  14369. init_appHandEXIDocument(&ccs_handshake);
  14370. //Init Energy transfer mode
  14371. //[To-Do] Parsing Model Name
  14372. ShmCcsData->EnergyTransferMode = CCS_ENERGY_TRANSFER_MODE;
  14373. //struct ChargingInfoData *ccs;
  14374. //ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  14375. Parameters_Init();
  14376. Sniffer_Tcpdump(ENABLE);
  14377. #if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  14378. sleep(1); //wait for tcpdump getting ready
  14379. #endif
  14380. SyncAcShreaMemory();
  14381. SAVE_SYS_LOG_MSG_EVCOMM("Initialize OK.\n");
  14382. while(1)
  14383. {
  14384. //DEBUG_PRINTF_EVCOMM_DETAIL("\nV2gFlowStatus = %d\n", V2gFlowStatus);
  14385. //if((ShmInternalComm->ChargingPermission == 0x01) && (CheckConnectorPlugIn() == 1))
  14386. //if((CheckConnectorPlugIn() == TRUE) && (ShmInternalComm->ChargingPermission == TRUE))
  14387. //if(ShmInternalComm->ChargingPermission == 0x01)
  14388. //if(CheckConnectorPlugIn() == TRUE)
  14389. if (EVCOMM_SYS_INFO.End_Process_inused == FALSE)
  14390. {
  14391. if(V2gFlowStatus < SLACC_SDP_UDP_Connection)
  14392. {
  14393. SlacComm();
  14394. }
  14395. else if(V2gFlowStatus == SLACC_SDP_UDP_Connection)
  14396. {
  14397. if(SdpUdpConnected() == 1)
  14398. {
  14399. Update_V2G_Flow_Status(SLACC_SDP_TCP_Connection);
  14400. continue;
  14401. }
  14402. SlacComm(); //TC_SECC_VTB_CmSlacMatch_004
  14403. ftime(&SeqEndTime);
  14404. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_join)
  14405. {
  14406. sprintf((char*)buf_log_evcomm,
  14407. "Wait SLACC_SDP_UDP_Connection Timeout - TT_match_join (%.02lf of %d ms)\n",
  14408. DiffTimeb(SeqStartTime, SeqEndTime),
  14409. TT_match_join);
  14410. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14411. Update_V2G_Flow_Status(Sequence_Timeout);
  14412. //Update_ShmStatusCode(); //[To-Do] to be implemented
  14413. //CCS_SECC_TIMEOUT_SLACC_SDP_UDP_TT_match_join (023823)
  14414. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  14415. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  14416. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  14417. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  14418. ShmStatusCodeData->PresentStatusCode[0][4] = 2;
  14419. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  14420. //CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  14421. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  14422. }
  14423. }
  14424. else if(V2gFlowStatus == SLACC_SDP_TCP_Connection)
  14425. {
  14426. if((TcpAcceptFd = V2gTcpConnected()) > 0)
  14427. {
  14428. Update_V2G_Flow_Status(SupportedAppProtocolRequest);
  14429. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14430. continue;
  14431. }
  14432. SlacComm();
  14433. ftime(&SeqEndTime);
  14434. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_join)
  14435. {
  14436. sprintf((char*)buf_log_evcomm,
  14437. "Wait SLACC_SDP_TCP_Connection Timeout - TT_match_join (%.02lf / %d ms)",
  14438. DiffTimeb(SeqStartTime, SeqEndTime),
  14439. TT_match_join);
  14440. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14441. Update_V2G_Flow_Status(Sequence_Timeout);
  14442. //Update_ShmStatusCode(); //[To-Do] to be implemented
  14443. //CCS_SECC_TIMEOUT_SLACC_SDP_TCP_TT_match_join (023824)
  14444. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  14445. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  14446. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  14447. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  14448. ShmStatusCodeData->PresentStatusCode[0][4] = 2;
  14449. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  14450. //CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  14451. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  14452. }
  14453. }
  14454. else if(V2gFlowStatus <= SessionStopResponse)
  14455. {
  14456. if (V2gComm(TcpAcceptFd) < 0)
  14457. {
  14458. //error occours
  14459. }
  14460. }
  14461. else if (V2gFlowStatus >= Performance_Timeout)
  14462. {
  14463. //End_Process
  14464. }
  14465. else
  14466. {
  14467. //null
  14468. }
  14469. }
  14470. usleep(1000);
  14471. } //while
  14472. }//main while