SeccComm.c 711 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976
  1. /*===========================================================================
  2. Combined Charging System (CCS): SECC
  3. EVComm.c
  4. initiated by Vern, Joseph
  5. (since 2019/07/19)
  6. =============================================================================*/
  7. #include <netinet/ip.h>
  8. #include <arpa/inet.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <fcntl.h>
  12. #include <linux/termios.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <time.h>
  16. #include <stdlib.h>
  17. #include <sys/ipc.h>
  18. #include <sys/shm.h>
  19. #include <sys/mman.h>
  20. #include <linux/sockios.h>
  21. #include <linux/socket.h>
  22. #include <sys/socket.h>
  23. #include <netinet/in.h>
  24. #include <sys/time.h>
  25. #include <sys/timeb.h>
  26. #include <math.h>//for pow
  27. #include <unistd.h>
  28. #include <linux/if_packet.h>
  29. #include <netinet/if_ether.h>
  30. #include <net/if.h>
  31. #include <netinet/ether.h>
  32. #include <errno.h>
  33. #include <linux/can.h>
  34. #include <linux/can/raw.h>
  35. #include <openssl/ssl.h>
  36. #include <openssl/err.h>
  37. #include "define.h"
  38. #include "SeccComm.h"
  39. #include "NidNmk.h"
  40. #include "SeccComm.h"
  41. #include "CsuComm.h"
  42. #include "./exi_engine/api/api.h"
  43. #include "./exi_engine/appHandshake/appHandEXIDatatypes.h"
  44. #include "./exi_engine/transport/v2gtp.h"
  45. int MeterSMId[8];
  46. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  47. struct StatusCodeData *ShmStatusCodeData;
  48. struct CcsData *ShmCcsData;
  49. struct InternalComm *ShmInternalComm;
  50. //struct InternalCommAC *ShmInternalCommAC;
  51. struct appHandEXIDocument ccs_handshake;
  52. struct dinEXIDocument ccs_exi_doc_DIN;
  53. struct iso1EXIDocument ccs_exi_doc_ISO1;
  54. struct iso2EXIDocument ccs_exi_doc_ISO2;
  55. unsigned char V2GTP_Tx_buf[V2GTP_MSG_TX_BUFFER_SIZE]; //64*1024 ﺿ65,536 = 65.5KB
  56. unsigned char buf_log_evcomm[SIZE_OF_LOG_BUFFER];
  57. unsigned char buf_log_evcomm_fork1[SIZE_OF_LOG_BUFFER];
  58. unsigned char buf_log_evcomm_fork2[SIZE_OF_LOG_BUFFER];
  59. unsigned char buf_log_evcomm_fork3[SIZE_OF_LOG_BUFFER];
  60. pid_t CP_Detection_Pid = 0;
  61. pid_t PP_Detection_Pid = 0;
  62. pid_t Error_Monitor_Pid = 0;
  63. int TcpAcceptFd;
  64. #ifdef SUPPORT_TLS_CONNECTION
  65. SSL_CTX *ctx;
  66. SSL *ssl;
  67. unsigned char EvSecurity;
  68. #endif
  69. enum MsgFlowStatus V2gFlowStatus;
  70. int RawSock,UdpSock,TcpSock;
  71. unsigned char *V2gtpMsgRxBuf, *V2gtpMsgTxBuf;
  72. unsigned short Aag[64];
  73. struct MmeHeader SendMmePacket;
  74. int SendMmePacketSize;
  75. unsigned char CsuMac[6],QcaMac[6],EvMac[6],SlacRunId[8];
  76. struct sockaddr_ll DestSocketAddress;
  77. struct ifreq Req;
  78. unsigned int PwmStartTime;
  79. struct timeb SeqStartTime, SeqEndTime;
  80. unsigned char AagGroupsNum, MnbcSoundNum, AttenProfileCnt;
  81. unsigned char NewNmkKey[16], Nid[7];
  82. int writeStringToEXIString(unsigned char* string, exi_string_character_t* exiString)
  83. {
  84. int pos = 0;
  85. while(string[pos]!='\0')
  86. {
  87. exiString[pos] = string[pos];
  88. pos++;
  89. }
  90. return pos;
  91. }
  92. /*===========================================================================
  93. FUNCTION: Check_V2G_Flow_Status
  94. DESCRIPTION:
  95. PRE-CONDITION:
  96. INPUT:
  97. OUTPUT:
  98. GLOBAL VARIABLES:
  99. =============================================================================*/
  100. unsigned char Check_V2G_Flow_Status()
  101. {
  102. unsigned char result = 0;
  103. switch (ShmCcsData->CommProtocol)
  104. {
  105. case V2GT_MSG_PROTOCOL_DIN70121: //0
  106. {
  107. result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
  108. break;
  109. }
  110. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  111. {
  112. result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
  113. break;
  114. }
  115. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  116. {
  117. result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
  118. break;
  119. }
  120. default:
  121. break;
  122. }
  123. return result;
  124. }
  125. /*===========================================================================
  126. FUNCTION: StoreLogMsg
  127. DESCRIPTION:
  128. PRE-CONDITION:
  129. INPUT:
  130. OUTPUT:
  131. GLOBAL VARIABLES:
  132. =============================================================================*/
  133. #if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  134. int StoreLogMsg2(unsigned char *DataString)
  135. {
  136. static unsigned char Buf[1024];
  137. static time_t CurrentTime;
  138. static struct tm *tm;
  139. static struct timeval tv;
  140. memset(Buf, 0, sizeof(Buf));
  141. CurrentTime = time(NULL);
  142. tm = localtime(&CurrentTime);
  143. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  144. #ifdef AWCCS
  145. sprintf(Buf, "echo \"[%04d%02d%02d: %02d:%02d:%02d.%06d][SECC][%d][%02d]%s\" >> /Storage/SystemLog/[%04d.%02d]CCS-SystemLog",
  146. tm->tm_year + 1900,
  147. tm->tm_mon + 1,
  148. tm->tm_mday,
  149. tm->tm_hour,
  150. tm->tm_min,
  151. tm->tm_sec,
  152. tv.tv_usec,
  153. EVCOMM_SYS_INFO.CpState,
  154. Check_V2G_Flow_Status(),
  155. DataString,
  156. tm->tm_year + 1900,
  157. tm->tm_mon + 1);
  158. #else
  159. sprintf(Buf, "echo \"[%04d%02d%02d: %02d:%02d:%02d.%06d][SECC][%d][%02d]%s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  160. tm->tm_year + 1900,
  161. tm->tm_mon + 1,
  162. tm->tm_mday,
  163. tm->tm_hour,
  164. tm->tm_min,
  165. tm->tm_sec,
  166. tv.tv_usec,
  167. EVCOMM_SYS_INFO.CpState,
  168. Check_V2G_Flow_Status(),
  169. DataString,
  170. tm->tm_year + 1900,
  171. tm->tm_mon + 1);
  172. #endif
  173. system(Buf);
  174. DEBUG_PRINTF_EVCOMM_SYSTEM_LOG("[%02d:%02d:%02d.%06d][SECC][%d][%02d]%s \n",
  175. tm->tm_hour,
  176. tm->tm_min,
  177. tm->tm_sec,
  178. tv.tv_usec,
  179. EVCOMM_SYS_INFO.CpState,
  180. Check_V2G_Flow_Status(),
  181. DataString);
  182. //Reset the buf_log_evcomm Buffer, i.e. DataString
  183. memset(buf_log_evcomm, 0, SIZE_OF_LOG_BUFFER);
  184. }
  185. #endif
  186. /*===========================================================================
  187. FUNCTION: CAN_Tx_MSG
  188. DESCRIPTION:
  189. PRE-CONDITION:
  190. INPUT:
  191. OUTPUT:
  192. GLOBAL VARIABLES:
  193. =============================================================================*/
  194. int CAN_Tx_MSG(int Fd, unsigned int MsgId, unsigned char SlaveAddress, unsigned char DataLength, unsigned char *SendData)
  195. {
  196. struct can_frame frame;
  197. struct timeb StartTime, EndTime;
  198. unsigned int tmp = 0;
  199. int nbytes = 0;
  200. int i = 0;
  201. //Protection: To avoid unexpected length for CAN bus payload.
  202. if (DataLength > 8)
  203. {
  204. DataLength = 8;
  205. }
  206. memset(&frame, 0, sizeof(struct can_frame));
  207. frame.can_id = 0x80000000 | CAN_SEND_DIRECTION | MsgId | SlaveAddress; //0x80000000: extension ID format
  208. frame.can_dlc = DataLength;
  209. memcpy(frame.data, SendData, DataLength);
  210. nbytes = write(Fd, &frame, sizeof(struct can_frame));
  211. #if 0
  212. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][CAN_Tx_MSG] <%X> ", frame.can_id);
  213. for (i = 0; i < frame.can_dlc; i++)
  214. {
  215. DEBUG_PRINTF_EVCOMM_DETAIL("%02X ", frame.data[i]);
  216. }
  217. DEBUG_PRINTF_EVCOMM_DETAIL("(%d Bytes)\n", frame.can_dlc);
  218. #endif
  219. return nbytes;
  220. }
  221. /*===========================================================================
  222. FUNCTION: Proc_EVStopRes
  223. DESCRIPTION:
  224. PRE-CONDITION:
  225. INPUT:
  226. OUTPUT:
  227. GLOBAL VARIABLES:
  228. =============================================================================*/
  229. int Proc_EVStopRes(int Fd)
  230. {
  231. int nbytes;
  232. unsigned char Buffer[8];
  233. memset(Buffer, 0, sizeof(Buffer));
  234. if (CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency == TRUE)
  235. {
  236. Buffer[0] = EV_EMERGENCY_STOP; //2
  237. }
  238. else
  239. {
  240. Buffer[0] = EV_NORMAL_STOP; //1
  241. }
  242. /*
  243. if(strlen(ShmStatusCodeData->PresentStatusCode[0]) > 0)
  244. {
  245. memcpy(Buffer + 2, ShmStatusCodeData->PresentStatusCode[0], 6);
  246. }
  247. */
  248. Buffer[1] = ShmStatusCodeData->PresentStatusCode[0][0];
  249. Buffer[2] = ShmStatusCodeData->PresentStatusCode[0][1];
  250. Buffer[3] = ShmStatusCodeData->PresentStatusCode[0][2];
  251. Buffer[4] = ShmStatusCodeData->PresentStatusCode[0][3];
  252. Buffer[5] = ShmStatusCodeData->PresentStatusCode[0][4];
  253. Buffer[6] = ShmStatusCodeData->PresentStatusCode[0][5];
  254. nbytes = CAN_Tx_MSG(Fd, CAN_CMD_EV_STOP_EVENT, ShmInternalComm->SlaveAddress, 7, Buffer);
  255. //system("echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle"); //for test only
  256. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  257. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_EVStopRes] Sending STOP Command to CSU");
  258. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = FALSE;
  259. return nbytes;
  260. }
  261. /*===========================================================================
  262. FUNCTION: Sniffer_Candump
  263. DESCRIPTION:
  264. 1. Only used in End_Process(), which is in fork2 of SeccComm task.
  265. PRE-CONDITION:
  266. INPUT:
  267. OUTPUT:
  268. 0: accept
  269. -1: invalid
  270. GLOBAL VARIABLES:
  271. =============================================================================*/
  272. int Sniffer_Candump(char cmd)
  273. {
  274. #if (CANDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  275. if (cmd == ENABLE)
  276. {
  277. SAVE_SYS_LOG_MSG_EVCOMM("[candump]init");
  278. system("cd /mnt/;rm -rf candump/");
  279. system("cd /mnt/;mkdir candump");
  280. SAVE_SYS_LOG_MSG_EVCOMM("[candump]on");
  281. system("cd /mnt/candump;candump -l can0 &");
  282. return 0;
  283. }
  284. else if (cmd == DISABLE)
  285. {
  286. SAVE_SYS_LOG_MSG_EVCOMM("[candump]off");
  287. system("killall candump");
  288. SAVE_SYS_LOG_MSG_EVCOMM("[candump]save");
  289. system("cd /;cp -rfv /mnt/candump /Storage/SystemLog/");
  290. return 0;
  291. }
  292. else
  293. {
  294. sprintf(buf_log_evcomm_fork2, "[candump]unexpected cmd(%d)", cmd);
  295. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  296. return -1;
  297. }
  298. #endif
  299. }
  300. /*===========================================================================
  301. FUNCTION: Sniffer_Tcpdump
  302. DESCRIPTION:
  303. PRE-CONDITION:
  304. INPUT:
  305. OUTPUT:
  306. GLOBAL VARIABLES:
  307. =============================================================================*/
  308. int Sniffer_Tcpdump(char cmd)
  309. {
  310. #if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  311. if (cmd == ENABLE)
  312. {
  313. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]init...");
  314. system("cd /mnt/;rm -rf tcpdump/");
  315. system("cd /mnt/;mkdir tcpdump");
  316. unsigned char buf[256];
  317. time_t CurrentTime;
  318. struct tm *tm;
  319. struct timeval tv;
  320. memset(buf, 0, sizeof(buf));
  321. CurrentTime = time(NULL);
  322. tm = localtime(&CurrentTime);
  323. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  324. sprintf(buf,
  325. "tcpdump -i eth1 -w /mnt/tcpdump/[%s][%04d%02d%02d-%02d:%02d:%02d.%06d]packets.pcap&",
  326. FIRMWARE_VERSION,
  327. tm->tm_year + 1900,
  328. tm->tm_mon + 1,
  329. tm->tm_mday,
  330. tm->tm_hour,
  331. tm->tm_min,
  332. tm->tm_sec,
  333. tv.tv_usec
  334. );
  335. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]on");
  336. system(buf);
  337. return 0;
  338. }
  339. else if (cmd == DISABLE)
  340. {
  341. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]off");
  342. system("killall tcpdump");
  343. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]wait: 2s");
  344. sleep(1);
  345. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]wait: 1s");
  346. sleep(1);
  347. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]save");
  348. system("cd /;cp -rfv /mnt/tcpdump /Storage/SystemLog/");
  349. return 0;
  350. }
  351. else
  352. {
  353. sprintf(buf_log_evcomm, "[tcpdump]unexpected cmd(%d)", cmd);
  354. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  355. return -1;
  356. }
  357. #endif
  358. }
  359. /*===========================================================================
  360. FUNCTION: Check_V2G_Flow_Status_pre
  361. DESCRIPTION:
  362. PRE-CONDITION:
  363. INPUT:
  364. OUTPUT:
  365. GLOBAL VARIABLES:
  366. =============================================================================*/
  367. unsigned char Check_V2G_Flow_Status_pre()
  368. {
  369. unsigned char result = 0;
  370. switch (ShmCcsData->CommProtocol)
  371. {
  372. case V2GT_MSG_PROTOCOL_DIN70121: //0
  373. {
  374. result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus_pre;
  375. break;
  376. }
  377. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  378. {
  379. result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus_pre;
  380. break;
  381. }
  382. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  383. {
  384. result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus_pre;
  385. break;
  386. }
  387. default:
  388. break;
  389. }
  390. return result;
  391. }
  392. /*===========================================================================
  393. FUNCTION: Update_V2G_Flow_Status
  394. DESCRIPTION:
  395. PRE-CONDITION:
  396. INPUT:
  397. OUTPUT:
  398. 1. V2gFlowStatus
  399. GLOBAL VARIABLES:
  400. 1. V2gFlowStatus
  401. =============================================================================*/
  402. int Update_V2G_Flow_Status(unsigned int state_new)
  403. {
  404. unsigned char state_now;
  405. state_now = Check_V2G_Flow_Status();
  406. if (/*EVCOMM_SYS_INFO.End_Process_inused == TRUE ||*/
  407. CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused == TRUE)
  408. {
  409. if (state_now != Performance_Timeout && //253
  410. state_now != Sequence_Timeout && //254
  411. state_now != Other_Fault) //255
  412. {
  413. sprintf(buf_log_evcomm,
  414. "[Warning]state(%d) change: ignored (End_Process_inused:%d, FW_Update_Task_inused:%d)",
  415. state_new,
  416. EVCOMM_SYS_INFO.End_Process_inused,
  417. CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused
  418. );
  419. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  420. return -1;
  421. }
  422. }
  423. if (state_now != state_new)
  424. {
  425. //Step 1: Check if Error Occours
  426. if (state_now == Performance_Timeout || //253
  427. state_now == Sequence_Timeout || //254
  428. state_now == Other_Fault) //255
  429. {
  430. if (state_new != IDLE)
  431. {
  432. if (EVCOMM_SYS_INFO.State_Change_Ignored_Notice == FALSE)
  433. {
  434. EVCOMM_SYS_INFO.State_Change_Ignored_Notice = TRUE;
  435. sprintf(buf_log_evcomm,
  436. "[Warning]state(%d) change: ignored(now in error state)",
  437. state_new,
  438. state_now);
  439. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  440. }
  441. return -1;
  442. }
  443. }
  444. //Updating the state formally.
  445. sprintf(buf_log_evcomm,
  446. "[stt]%02d >> %02d",
  447. state_now,
  448. state_new
  449. );
  450. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  451. V2gFlowStatus = state_new;
  452. state_now = state_new;
  453. switch (ShmCcsData->CommProtocol)
  454. {
  455. case V2GT_MSG_PROTOCOL_DIN70121: //0
  456. {
  457. ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
  458. ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus = V2gFlowStatus;
  459. //break;
  460. }
  461. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  462. {
  463. ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
  464. ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus = V2gFlowStatus;
  465. //break;
  466. }
  467. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  468. {
  469. ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
  470. ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus = V2gFlowStatus;
  471. //break;
  472. }
  473. default:
  474. break;
  475. }
  476. }
  477. }
  478. double DiffTimeb(struct timeb ST, struct timeb ET)
  479. {
  480. //return milli-second
  481. double StartTime, EndTime;
  482. double t_diff;
  483. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  484. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  485. t_diff = EndTime - StartTime;
  486. if (t_diff < 0)
  487. {
  488. #if 0
  489. if (t_diff < -1000) //1000ms
  490. {
  491. sprintf(buf_log_evcomm,
  492. "[Warning]StartTime(%.02lf) > EndTime(%.02lf), d(%.02lf)",
  493. StartTime,
  494. EndTime,
  495. t_diff);
  496. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  497. }
  498. #endif
  499. return -1;
  500. }
  501. return t_diff;
  502. }
  503. double DiffTimeb_fork1_Error_Monitor(struct timeb ST, struct timeb ET)
  504. {
  505. //return milli-second
  506. static double StartTime, EndTime;
  507. static double t_diff;
  508. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  509. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  510. t_diff = EndTime - StartTime;
  511. if (t_diff < 0)
  512. {
  513. #if 0
  514. if (t_diff < -1000) //1000ms
  515. {
  516. sprintf(buf_log_evcomm_fork2,
  517. "[fork1][Warning]S(%.02lf) > E(%.02lf), d(%.02lf)",
  518. StartTime,
  519. EndTime,
  520. t_diff);
  521. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  522. }
  523. #endif
  524. return -1;
  525. }
  526. return t_diff;
  527. }
  528. double DiffTimeb_fork2_Error_Monitor(struct timeb ST, struct timeb ET)
  529. {
  530. //return milli-second
  531. static double StartTime, EndTime;
  532. static double t_diff;
  533. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  534. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  535. t_diff = EndTime - StartTime;
  536. if (t_diff < 0)
  537. {
  538. #if 0
  539. if (t_diff < -1000) //1000ms
  540. {
  541. sprintf(buf_log_evcomm_fork2,
  542. "[fork2][Warning]S(%.02lf) > E(%.02lf), d(%.02lf)",
  543. StartTime,
  544. EndTime,
  545. t_diff);
  546. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  547. }
  548. #endif
  549. return -1;
  550. }
  551. return t_diff;
  552. }
  553. int CreateShareMemory()
  554. {
  555. int MeterSMId;
  556. //create ShmSysConfigAndInfo
  557. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
  558. {
  559. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmget ShmSysConfigAndInfo NG");
  560. return 0;
  561. }
  562. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  563. {
  564. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmat ShmSysConfigAndInfo NG");
  565. return 0;
  566. }
  567. memset(ShmSysConfigAndInfo,0,sizeof(struct SysConfigAndInfo));
  568. //create ShmStatusCodeData
  569. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
  570. {
  571. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmget ShmStatusCodeData NG");
  572. return 0;
  573. }
  574. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  575. {
  576. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmat ShmStatusCodeData NG");
  577. return 0;
  578. }
  579. memset(ShmStatusCodeData,0,sizeof(struct StatusCodeData));
  580. //create ShmCcsData
  581. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
  582. {
  583. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmget ShmCcsData NG");
  584. return 0;
  585. }
  586. else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  587. {
  588. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmat ShmCcsData NG");
  589. return 0;
  590. }
  591. memset(ShmCcsData,0,sizeof(struct CcsData));
  592. return 1;
  593. }
  594. void DetachShareMemory()
  595. {
  596. if(MeterSMId[0]>0)
  597. {
  598. shmdt(ShmSysConfigAndInfo);
  599. shmctl(MeterSMId[0], IPC_RMID, 0);
  600. }
  601. if(MeterSMId[1]>0)
  602. {
  603. shmdt(ShmStatusCodeData);
  604. shmctl(MeterSMId[1], IPC_RMID, 0);
  605. }
  606. if(MeterSMId[2]>0)
  607. {
  608. shmdt(ShmCcsData);
  609. shmctl(MeterSMId[2], IPC_RMID, 0);
  610. }
  611. if(MeterSMId[3]>0)
  612. {
  613. shmdt(ShmInternalComm);
  614. shmctl(MeterSMId[3], IPC_RMID, 0);
  615. }
  616. /*if(MeterSMId[4]>0)
  617. {
  618. shmdt(ShmInternalCommAC);
  619. shmctl(MeterSMId[4], IPC_RMID, 0);
  620. }*/
  621. }
  622. /*===========================================================================
  623. FUNCTION: ShareMemory_Init
  624. DESCRIPTION:
  625. PRE-CONDITION:
  626. INPUT:
  627. OUTPUT:
  628. GLOBAL VARIABLES:
  629. =============================================================================*/
  630. int ShareMemory_Init()
  631. {
  632. memset(MeterSMId,0,sizeof(MeterSMId));
  633. //create ShmSysConfigAndInfo
  634. if ((MeterSMId[0] = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  635. {
  636. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmget ShmSysConfigAndInfo NG");
  637. return 0;
  638. }
  639. else if ((ShmSysConfigAndInfo = shmat(MeterSMId[0], NULL, 0)) == (void *) -1)
  640. {
  641. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmat ShmSysConfigAndInfo NG");
  642. return 0;
  643. }
  644. //create ShmStatusCodeData
  645. if ((MeterSMId[1] = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  646. {
  647. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmget ShmStatusCodeData NG");
  648. return 0;
  649. }
  650. else if ((ShmStatusCodeData = shmat(MeterSMId[1], NULL, 0)) == (void *) -1)
  651. {
  652. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmat ShmStatusCodeData NG");
  653. return 0;
  654. }
  655. //create ShmCcsData
  656. if ((MeterSMId[2] = shmget(ShmCcsCommKey, sizeof(struct CcsData), 0777)) < 0)
  657. {
  658. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmget ShmCcsData NG");
  659. return 0;
  660. }
  661. else if ((ShmCcsData = shmat(MeterSMId[2], NULL, 0)) == (void *) -1)
  662. {
  663. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmat ShmCcsData NG");
  664. return 0;
  665. }
  666. //create ShmInternalComm
  667. if ((MeterSMId[3] = shmget(ShmInternalCommKey, sizeof(struct InternalComm), 0777)) < 0)
  668. {
  669. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmget ShmInternalComm NG");
  670. return 0;
  671. }
  672. else if ((ShmInternalComm = shmat(MeterSMId[3], NULL, 0)) == (void *) -1)
  673. {
  674. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmat ShmInternalComm NG");
  675. return 0;
  676. }
  677. #if 0
  678. //create ShmInternalCommAC
  679. if ((MeterSMId[4] = shmget(ShmInternalCommACKey, sizeof(struct InternalCommAC), 0777)) < 0)
  680. {
  681. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmget ShmInternalCommAC NG");
  682. return 0;
  683. }
  684. else if ((ShmInternalCommAC = shmat(MeterSMId[4], NULL, 0)) == (void *) -1)
  685. {
  686. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmat ShmInternalCommAC NG");
  687. return 0;
  688. }
  689. #endif
  690. //[To-Do] The initialization here is reduntant and should be removed partially.
  691. //SHM_Init_supportedAppProtocolRes(ShmCcsData);
  692. //SHM_Init_din_SessionSetupRes(ShmCcsData);
  693. //SHM_Init_din_ServiceDiscoveryRes(ShmCcsData);
  694. //SHM_Init_din_ServiceAndPaymentSelectionRes(ShmCcsData);
  695. //SHM_Init_din_ContractAuthenticationRes(ShmCcsData);
  696. SHM_Init_din_ChargeParameterDiscoveryRes(ShmCcsData);
  697. SHM_Init_din_CableCheckRes(ShmCcsData);
  698. SHM_Init_din_PreChargeRes(ShmCcsData);
  699. SHM_Init_din_PowerDeliveryRes(ShmCcsData);
  700. SHM_Init_din_CurrentDemandRes(ShmCcsData);
  701. SHM_Init_din_WeldingDetectionRes(ShmCcsData);
  702. SHM_Init_din_SessionStopRes(ShmCcsData);
  703. return 1;
  704. }
  705. /*===========================================================================
  706. FUNCTION: GetEthMac
  707. DESCRIPTION:
  708. 1. Accessing current CsuMac address, if Eth = eth1
  709. 2. The address of eth1(for QCA7000) is a random number, which will be modified
  710. after each time of booting up system.
  711. PRE-CONDITION:
  712. INPUT:
  713. OUTPUT:
  714. GLOBAL VARIABLES:
  715. =============================================================================*/
  716. int GetEthMac(unsigned char *Eth, unsigned char *mac)
  717. {
  718. //Parameters:MAC,IP,Mask,Gateway
  719. int fd, rd = 0;
  720. unsigned char addr[18], Buffer[128];
  721. memset(Buffer, 0, sizeof(Buffer));
  722. sprintf(Buffer, "cat /sys/class/net/%s/address > /mnt/GetEthInfo", Eth); //CsuMac (Eth = eth1)
  723. system(Buffer);
  724. fd = open("/mnt/GetEthInfo", O_RDONLY);
  725. if(fd < 0)
  726. {
  727. system("rm -f /mnt/GetEthInfo");
  728. SAVE_SYS_LOG_MSG_EVCOMM("GetEthMac: MAC Address open error");
  729. return 0;
  730. }
  731. memset(mac, 0, 6);
  732. memset(addr, 0, sizeof(addr));
  733. rd = read(fd, addr, 17);
  734. close(fd);
  735. system("rm -f /mnt/GetEthInfo");
  736. sscanf(addr, "%02x:%02x:%02x:%02x:%02x:%02x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); //CsuMac (Eth = eth1)
  737. sprintf(buf_log_evcomm,
  738. "[GetEthMac]EVSE MACAddr(CsuMac): %02x:%02x:%02x:%02x:%02x:%02x",
  739. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); //CsuMac (Eth = eth1)
  740. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  741. return 1;
  742. }
  743. /*===========================================================================
  744. FUNCTION: ReadAdcVolt
  745. DESCRIPTION:
  746. 1. fork1
  747. PRE-CONDITION:
  748. INPUT:
  749. OUTPUT:
  750. GLOBAL VARIABLES:
  751. =============================================================================*/
  752. float ReadAdcVolt(unsigned char AdcChannel)
  753. {
  754. //AIN0=CCS GUN Temp 1
  755. //AIN1=CCS GUN Temp 2
  756. //AIN2=CCS_Proximity/2
  757. //AIN3=pilot voltage
  758. if(AdcChannel == 3)
  759. {
  760. int fd,count,AvgTimes;
  761. unsigned char SampleBuf[4];
  762. float TmpVolt, MinSample, AvgSample = 0;
  763. fd = open("/sys/bus/iio/devices/iio\:device0/in_voltage3_raw", O_RDONLY);
  764. if(fd > 0)
  765. {
  766. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  767. for(AvgTimes = 0; AvgTimes < 3; AvgTimes++) //period = 60~91 ms(renice -10, , CurrentDemand()) /*+++ 20200909, vern, extend detection time for interference ---*/
  768. {
  769. count = 0;
  770. MinSample = 2306;
  771. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  772. while(count < 30) //period = 21~42ms (renice -10, CurrentDemand())/*+++ 20200909, vern, extend detection time for interference ---*/
  773. {
  774. //re-sampling period = 3~13ms (renice -10, SLAC())
  775. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  776. read(fd, SampleBuf, 4); //period = 3.2~10ms (renice -10, SLAC())
  777. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  778. TmpVolt = atoi(SampleBuf);
  779. if((TmpVolt < 2306) && (TmpVolt > 0))//positive voltage
  780. {
  781. if(TmpVolt < MinSample)
  782. {
  783. MinSample = TmpVolt;
  784. }
  785. count++;
  786. }
  787. lseek(fd, 0, SEEK_SET);
  788. }
  789. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  790. AvgSample += MinSample;
  791. }
  792. AvgSample /= AvgTimes;
  793. close(fd);
  794. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  795. return ((0.954-(1.8*AvgSample/4095))/0.06);
  796. }
  797. else
  798. {
  799. return -1;
  800. }
  801. }
  802. else
  803. {
  804. FILE *fp;
  805. unsigned char str[64];
  806. unsigned char AdcValue[8];
  807. if(AdcChannel > 7)
  808. {
  809. return -1;
  810. }
  811. memset(str,0,sizeof(str));
  812. memset(AdcValue,0,sizeof(AdcValue));
  813. sprintf(str, "cat /sys/bus/iio/devices/iio\\:device0/in_voltage%d_raw", AdcChannel);
  814. fp=popen(str, "r");
  815. if(fgets(AdcValue,sizeof(AdcValue),fp) == NULL)
  816. {
  817. pclose(fp);
  818. return -1;
  819. }
  820. pclose(fp);
  821. //Vin = Vref *D / (2^n - 1)
  822. return ((float)1.8*(float)atoi(AdcValue))/4095;
  823. }
  824. }
  825. /*===========================================================================
  826. FUNCTION: ReadAdcVolt
  827. DESCRIPTION:
  828. //AIN0=CCS GUN Temp 1
  829. //AIN1=CCS GUN Temp 2
  830. //AIN2=CCS_Proximity/2
  831. //AIN3=pilot voltage
  832. PRE-CONDITION:
  833. INPUT:
  834. OUTPUT:
  835. GLOBAL VARIABLES:
  836. =============================================================================*/
  837. float ReadAdcVolt_PP_fork3()
  838. {
  839. int fd, AvgTimes;
  840. unsigned char SampleBuf[4];
  841. float TmpVolt = 0;
  842. float AvgSample = 0;
  843. float V_pp = 0;
  844. fd = open("/sys/bus/iio/devices/iio\:device0/in_voltage2_raw", O_RDONLY); //PP
  845. if(fd > 0)
  846. {
  847. for(AvgTimes = 0; AvgTimes < 5; AvgTimes++) //get 5 samples
  848. {
  849. read(fd, SampleBuf, 4);
  850. TmpVolt = atoi(SampleBuf);
  851. lseek(fd, 0, SEEK_SET);
  852. AvgSample += TmpVolt;
  853. }
  854. close(fd);
  855. AvgSample /= AvgTimes;
  856. V_pp = (1.8*AvgSample)/4095; //PP
  857. //CCS1: plug : 0.61<=V_pp<=1.18
  858. //CCS2:plug : 1.2<=V_pp<=2.4
  859. #if 0
  860. printf("PP_adc = %.02f, PP_v = %.02f\n", AvgSample, V_pp);
  861. usleep(3000000); //300ms
  862. #endif
  863. usleep(20000); //20ms
  864. return V_pp;
  865. }
  866. else
  867. {
  868. return -1;
  869. }
  870. }
  871. /*===========================================================================
  872. FUNCTION: Qca7kPowerReset
  873. DESCRIPTION:
  874. PRE-CONDITION:
  875. INPUT:
  876. OUTPUT:
  877. GLOBAL VARIABLES:
  878. =============================================================================*/
  879. void Qca7kPowerReset()
  880. {
  881. //printf("\n[CCS Board]Reset QCA7000...\n");
  882. system("echo 1 > /sys/class/gpio/gpio88/value");
  883. usleep(500000);
  884. system("echo 0 > /sys/class/gpio/gpio88/value");
  885. }
  886. /*===========================================================================
  887. FUNCTION: SwitchCpStateE
  888. DESCRIPTION:
  889. PRE-CONDITION:
  890. INPUT:
  891. OUTPUT:
  892. GLOBAL VARIABLES:
  893. =============================================================================*/
  894. int SwitchCpStateE(unsigned char OnOff)
  895. {
  896. if((OnOff != ENABLE) && (OnOff != DISABLE))
  897. {
  898. return -1;
  899. }
  900. struct ChargingInfoData *ccs;
  901. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  902. ccs->SwitchCpStateE_status = OnOff;
  903. //OnOff = 1 => switch State to E
  904. //OnOff = 0 => return noraml
  905. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  906. {
  907. if(OnOff == DISABLE)
  908. {
  909. //SAVE_SYS_LOG_MSG_EVCOMM("SwitchCpStateE: released\n");
  910. // CSUCOMMAC_SHM.CpSetStateE = DISABLE;
  911. }
  912. else
  913. {
  914. OutputCpPwmDuty(100); //set CP duty as 100, firstly.
  915. //CSUCOMMAC_SHM.CpSetStateE = ENABLE;
  916. //SAVE_SYS_LOG_MSG_EVCOMM("SwitchCpStateE: enabled!\n");
  917. }
  918. }
  919. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  920. {
  921. if(OnOff == DISABLE)
  922. {
  923. //SAVE_SYS_LOG_MSG_EVCOMM("SwitchCpStateE: released\n");
  924. system("echo 0 > /sys/class/gpio/gpio86/value");
  925. }
  926. else
  927. {
  928. OutputCpPwmDuty(100); //set CP duty as 100, firstly.
  929. system("echo 1 > /sys/class/gpio/gpio86/value");
  930. //SAVE_SYS_LOG_MSG_EVCOMM("SwitchCpStateE: enabled!\n");
  931. }
  932. }
  933. #endif
  934. if (ccs->SwitchCpStateE_status_pre != ccs->SwitchCpStateE_status)
  935. {
  936. sprintf(buf_log_evcomm,
  937. "SwitchCpStateE: %d >> %d",
  938. ccs->SwitchCpStateE_status_pre,
  939. ccs->SwitchCpStateE_status
  940. );
  941. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  942. ccs->SwitchCpStateE_status_pre = ccs->SwitchCpStateE_status;
  943. }
  944. }
  945. /*===========================================================================
  946. FUNCTION: OutputCpPwmDuty
  947. DESCRIPTION:
  948. PRE-CONDITION:
  949. INPUT:
  950. OUTPUT:
  951. GLOBAL VARIABLES:
  952. =============================================================================*/
  953. int OutputCpPwmDuty(unsigned char Duty)
  954. {
  955. int DutyInNanoSec;
  956. struct ChargingInfoData *ccs;
  957. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  958. if((Duty < 0)||(Duty > 100))
  959. {
  960. return -1;
  961. }
  962. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  963. {
  964. //CSUCOMMAC_SHM.CpSetPWMDuty = Duty;
  965. }
  966. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  967. {
  968. DutyInNanoSec = 10000 * Duty;
  969. sprintf(buf_log_evcomm, "echo %d > /sys/class/pwm/pwmchip0/pwm0/duty_cycle", DutyInNanoSec);//nanoseconds
  970. system(buf_log_evcomm);
  971. }
  972. #endif
  973. ccs->CpDuty = Duty;
  974. //CP Duty
  975. if (ccs->CpDuty != ccs->CpDuty_pre)
  976. {
  977. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  978. sprintf(buf_log_evcomm, "CP Duty: %d\% >> %d\%", ccs->CpDuty_pre, ccs->CpDuty);
  979. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  980. ccs->CpDuty_pre = ccs->CpDuty;
  981. }
  982. return 0;
  983. }
  984. /*===========================================================================
  985. FUNCTION: Check_Plugin_Status_Update_fork1
  986. DESCRIPTION:
  987. PRE-CONDITION:
  988. INPUT:
  989. OUTPUT:
  990. GLOBAL VARIABLES:
  991. =============================================================================*/
  992. //#if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  993. void Check_Plugin_Status_Update_fork1(struct ChargingInfoData *ccs)
  994. {
  995. if (ccs->ConnectorPlugIn != ccs->ConnectorPlugIn_new)
  996. {
  997. sprintf(buf_log_evcomm_fork1, "[fork1]Plugin: %d >> %d (CP=%.2fV, PP=%.2fV)",
  998. ccs->ConnectorPlugIn,
  999. ccs->ConnectorPlugIn_new,
  1000. ccs->CpVoltage,
  1001. ccs->PpVoltage
  1002. );
  1003. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork1);
  1004. ccs->ConnectorPlugIn_pre = ccs->ConnectorPlugIn;
  1005. ccs->ConnectorPlugIn = ccs->ConnectorPlugIn_new;
  1006. //ccs->CpVoltage_pre = ccs->CpVoltage;
  1007. }
  1008. }
  1009. //#endif
  1010. /*===========================================================================
  1011. FUNCTION: ConnectorPlugIn
  1012. DESCRIPTION:
  1013. PRE-CONDITION:
  1014. INPUT:
  1015. OUTPUT:
  1016. GLOBAL VARIABLES:
  1017. =============================================================================*/
  1018. int CheckConnectorPlugIn()
  1019. {
  1020. //return 0 => unplug
  1021. //return 1 => plug-in
  1022. //float TmpProximity;
  1023. //unsigned char Rtn = 0;
  1024. static struct ChargingInfoData *ccs;
  1025. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1026. #if (CP_PROTECTION_MECHANISM == ENABLE)
  1027. return (int)ccs->ConnectorPlugIn;
  1028. #else
  1029. return TRUE;
  1030. #endif
  1031. /*
  1032. // PP Detection
  1033. TmpProximity = ReadAdcVolt(ADC_CHANNEL_AIN2_PP);
  1034. //[CAUTION] This function takes a period of time to deal with.
  1035. //Designers should avoid to call it in main function, repeatly.
  1036. if(((FIRMWARE_VERSION & 0x0000FF00) >> 8) == 0x01)
  1037. {
  1038. //UL version: judge with CP and proximity
  1039. //TmpProximity = ReadAdcVolt(ADC_CHANNEL_AIN2_PP);
  1040. //SAVE_SYS_LOG_MSG_EVCOMM("Connector: UL");
  1041. if((ccs->CpState >= 2) &&
  1042. (ccs->CpState <= 5) &&
  1043. (TmpProximity >= 0.4) &&
  1044. (TmpProximity <= 0.9))
  1045. {
  1046. Rtn = 1;
  1047. }
  1048. }
  1049. else
  1050. {
  1051. //SAVE_SYS_LOG_MSG_EVCOMM("Connector: CE");
  1052. //CE version: judge with CP only
  1053. if((ccs->CpState >=2 ) &&
  1054. (ccs->CpState <=5 ))
  1055. {
  1056. Rtn = 1;
  1057. }
  1058. }
  1059. */
  1060. //CE version: judge with CP only
  1061. /*
  1062. if((ccs->CpState >= 2 ) &&
  1063. (ccs->CpState <= 5 ))
  1064. {
  1065. Rtn = TRUE;
  1066. }
  1067. ccs->ConnectorPlugIn = Rtn;
  1068. //ccs->PpVoltage = TmpProximity;
  1069. return Rtn;
  1070. */
  1071. }
  1072. /*===========================================================================
  1073. FUNCTION: Check_CP_State_Error_fork1
  1074. DESCRIPTION:
  1075. PRE-CONDITION:
  1076. INPUT:
  1077. OUTPUT:
  1078. GLOBAL VARIABLES:
  1079. =============================================================================*/
  1080. int Check_CP_State_Error_fork1(struct ChargingInfoData *ccs)
  1081. {
  1082. #if (CP_PROTECTION_MECHANISM == DISABLE)
  1083. {
  1084. return -1;
  1085. }
  1086. #endif
  1087. unsigned char state = 0;
  1088. double time_diff = 0;
  1089. state = Check_V2G_Flow_Status();
  1090. //SLAC, SLAAC, SDP, ..., ChargeParameterDiscovery
  1091. if (state >= CM_SLAC_PARM_CONF && //by considering 15118(SLAC first)
  1092. state < ChargeParameterDiscoveryRequest &&
  1093. state != IDLE &&
  1094. state != CM_SET_KEY_REQ &&
  1095. state != CM_SET_KEY_CNF &&
  1096. state != CM_VALIDATE_REQ &&
  1097. state != CM_VALIDATE_CNF)
  1098. {
  1099. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  1100. {
  1101. if((ccs->CpState != 2) && (ccs->CpState != 3))
  1102. {
  1103. if (ccs->CpState_err == FALSE)
  1104. {
  1105. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][CP][Error]before CPD"); //CPD: ChargeParameterDiscoveryRequest
  1106. //CPD: ChargeParameterDiscovery
  1107. }
  1108. ccs->CpState_err = TRUE;
  1109. }
  1110. }
  1111. #else
  1112. {
  1113. #ifdef AWCCS
  1114. if((ccs->CpState != 2) && (ccs->CpState != 3))
  1115. {
  1116. if (ccs->CpState_err == FALSE)
  1117. {
  1118. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][CP][Error]before CPD"); //CPD: ChargeParameterDiscoveryRequest
  1119. //CPD: ChargeParameterDiscovery
  1120. }
  1121. ccs->CpState_err = TRUE;
  1122. }
  1123. #else
  1124. if(ccs->CpState != 3)
  1125. {
  1126. if (ccs->CpState_err == FALSE)
  1127. {
  1128. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][CP][Error]before CPD"); //CPD: ChargeParameterDiscoveryRequest
  1129. //CPD: ChargeParameterDiscovery
  1130. }
  1131. ccs->CpState_err = TRUE;
  1132. }
  1133. #endif
  1134. }
  1135. #endif
  1136. }
  1137. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  1138. {
  1139. //ChargeParameterDiscovery
  1140. if(state >= ChargeParameterDiscoveryRequest && //35
  1141. state <= ChargeParameterDiscoveryResponse) //36
  1142. {
  1143. if(ccs->CpState != 3)
  1144. {
  1145. if (ccs->CpState_err == FALSE)
  1146. {
  1147. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD");
  1148. //PRC: Precharge
  1149. //CUD: CurrentDemand
  1150. }
  1151. ccs->CpState_err = TRUE;
  1152. }
  1153. }
  1154. //ChargingStatus
  1155. if(state >= ChargingStatusRequest && //43
  1156. state <= ChargingStatusResponse) //44
  1157. {
  1158. if(ccs->CpState != 4 && ccs->CpState != 5)
  1159. {
  1160. if (ccs->CpState_err == FALSE)
  1161. {
  1162. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CGS");
  1163. //PRC: Precharge
  1164. //CUD: CurrentDemand
  1165. }
  1166. ccs->CpState_err = TRUE;
  1167. }
  1168. }
  1169. }
  1170. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  1171. {
  1172. //ChargeParameterDiscovery, CableCheck
  1173. if (state >= ChargeParameterDiscoveryRequest && //35
  1174. state <= CableCheckResponse) //38
  1175. {
  1176. if(ccs->CableCheckPreCountDownDone == FALSE &&
  1177. state >= CableCheckRequest)
  1178. {
  1179. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  1180. time_diff = DiffTimeb_fork1_Error_Monitor(EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start, EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  1181. if(time_diff >= V2G_SECC_CP_Timeout_CableCheck) //2 sec
  1182. {
  1183. sprintf(buf_log_evcomm_fork1,
  1184. "[fork1][CP]check C(4),D(5): ON (%.02lf of %dms)",
  1185. time_diff,
  1186. V2G_SECC_CP_Timeout_CableCheck);
  1187. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork1);
  1188. ccs->CableCheckPreCountDownDone = TRUE;
  1189. }
  1190. }
  1191. if(ccs->CableCheckPreCountDownDone == TRUE)
  1192. {
  1193. if(ccs->CpState != 4 && ccs->CpState != 5)
  1194. {
  1195. if (ccs->CpState_err == FALSE)
  1196. {
  1197. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD and CCK (after CNT)");
  1198. //CPD: ChargeParameterDiscovery
  1199. //CCK: CableCheck
  1200. //CNT: count down
  1201. }
  1202. ccs->CpState_err = TRUE;
  1203. }
  1204. }
  1205. else
  1206. {
  1207. if(ccs->CpState != 3 && ccs->CpState != 4 && ccs->CpState != 5)
  1208. {
  1209. if (ccs->CpState_err == FALSE)
  1210. {
  1211. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD and CCK (before CNT)");
  1212. //CPD: ChargeParameterDiscovery
  1213. //CCK: CableCheck
  1214. //CNT: count down
  1215. }
  1216. ccs->CpState_err = TRUE;
  1217. }
  1218. }
  1219. }
  1220. //Precharge, CurrentDemand
  1221. if(state >= PreChargeRequest && //39
  1222. state <= CurrentDemandResponse) //46
  1223. {
  1224. //if(ccs->CpState != 4 && ccs->CpState != 5)
  1225. if( ccs->CpState <=1)
  1226. {
  1227. if (ccs->CpState_err == FALSE)
  1228. {
  1229. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]PRC and CUD");
  1230. //PRC: Precharge
  1231. //CUD: CurrentDemand
  1232. }
  1233. ccs->CpState_err = TRUE;
  1234. }
  1235. }
  1236. }
  1237. #endif
  1238. if(ccs->CpState_err == TRUE && ccs->CpState_err_logged == FALSE)
  1239. {
  1240. OutputCpPwmDuty(100);
  1241. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  1242. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1243. //CCS_SECC_CP_State_Error (023889)
  1244. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1245. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1246. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1247. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1248. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1249. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1250. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1251. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1252. sprintf(buf_log_evcomm_fork1, "[fork1][Erorr]CP(%d) Error in state %d(%d)",
  1253. ccs->CpState,
  1254. state,
  1255. ccs->CableCheckPreCountDownDone
  1256. );
  1257. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork1);
  1258. ccs->CpState_err_logged = TRUE;
  1259. }
  1260. return 0;
  1261. }
  1262. /*===========================================================================
  1263. FUNCTION: Check_CP_State_Update_fork1
  1264. DESCRIPTION:
  1265. PRE-CONDITION:
  1266. INPUT:
  1267. OUTPUT:
  1268. GLOBAL VARIABLES:
  1269. =============================================================================*/
  1270. //#if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  1271. void Check_CP_State_Update_fork1(struct ChargingInfoData *ccs)
  1272. {
  1273. //CP Voltage
  1274. /*
  1275. //Issues waiting to debug
  1276. //[CAUTION] This function shall not be used in charging state.
  1277. if (((int)(ccs->CpVoltage * 10)) != ((int)(ccs->CpVoltage_pre * 10)))
  1278. {
  1279. memset(buf, 0, sizeof(buf));
  1280. sprintf(buf, "CP Voltage: %.2lf >> %.2lf (%d >> %d)",
  1281. ccs->CpVoltage_pre,
  1282. ccs->CpVoltage,
  1283. (int)(ccs->CpVoltage_pre * 10),
  1284. (int)(ccs->CpVoltage * 10)
  1285. );
  1286. SAVE_SYS_LOG_MSG_EVCOMM(buf);
  1287. ccs->CpVoltage_pre = ccs->CpVoltage;
  1288. }
  1289. */
  1290. //CP State
  1291. if (ccs->CpState != ccs->CpState_pre)
  1292. {
  1293. sprintf(buf_log_evcomm_fork1, "[fork1]CP State: %d >> %d (%.2fV)",
  1294. ccs->CpState_pre,
  1295. ccs->CpState,
  1296. ccs->CpVoltage
  1297. );
  1298. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork1);
  1299. ccs->CpState_pre = ccs->CpState;
  1300. }
  1301. }
  1302. //#endif
  1303. /*===========================================================================
  1304. FUNCTION: CP_Detection
  1305. DESCRIPTION:
  1306. 1. In order to detect CP in efficient response time, we creat an independent
  1307. thead for this procedure.
  1308. 2. The priority of this thread is set as the same as other tasks.
  1309. 3. fork1
  1310. PRE-CONDITION:
  1311. INPUT:
  1312. OUTPUT:
  1313. GLOBAL VARIABLES:
  1314. =============================================================================*/
  1315. void CP_Detection()
  1316. {
  1317. pid_t tmp = 0;
  1318. // struct timeb StartTime, EndTime;
  1319. unsigned char Statetmp;
  1320. float TotalTmpVolt;
  1321. struct ChargingInfoData *ccs;
  1322. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1323. if(CP_Detection_Pid == 0)
  1324. {
  1325. tmp = fork();
  1326. if(tmp > 0)
  1327. {
  1328. CP_Detection_Pid = tmp;
  1329. #if 1
  1330. unsigned char buf[64];
  1331. memset(buf, 0, sizeof(buf));
  1332. //sprintf(buf, "renice -20 -p %d", tmp);
  1333. sprintf(buf, "renice -10 -p %d", tmp);
  1334. system(buf);
  1335. #endif
  1336. return;
  1337. }
  1338. }
  1339. while(1)
  1340. {
  1341. //ADC_Voltage = (1+RE62/RE63)*0.9 - (RE62/RE63)*Pilot_Voltage, RE62/RE63=0.06
  1342. //=>Pilot_Voltage=(0.954-ADC_Voltage)/0.06
  1343. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  1344. {
  1345. ccs->CpVoltage = ShmInternalComm->AC_CpPositiveVoltage;
  1346. ccs->CpState = ShmInternalComm->AC_CpPresentState;
  1347. }
  1348. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  1349. {
  1350. TotalTmpVolt = ReadAdcVolt(3);
  1351. ccs->CpVoltage = TotalTmpVolt;
  1352. if (ccs->CpVoltage_pre != ccs->CpVoltage)
  1353. {
  1354. ccs->CpVoltage_pre = ccs->CpVoltage;
  1355. }
  1356. //printf("TotalTmpVolt = %.02f\n", TotalTmpVolt);
  1357. //If CP voltage is higer than 13.5V
  1358. if(TotalTmpVolt >= 13.5)
  1359. {
  1360. //Pilot Error
  1361. if((ccs->CpState == 1) &&
  1362. (TotalTmpVolt < 13.75))
  1363. {
  1364. //V_cp = 13.5 ~ 13.75
  1365. Statetmp = 1;
  1366. }
  1367. else
  1368. {
  1369. //V_cp = 13.5 ~
  1370. Statetmp = 8;
  1371. }
  1372. }
  1373. else if((TotalTmpVolt >= 10.5) && (TotalTmpVolt < 13.5)) //V_cp = 10.5 ~ 13.5
  1374. {
  1375. //State A (12V)
  1376. if((ccs->CpState >= 2) &&
  1377. (ccs->CpState <= 3) &&
  1378. (TotalTmpVolt < 10.75))
  1379. {
  1380. if((ccs->CpDuty >= 5) &&
  1381. (ccs->CpDuty < 100))
  1382. {
  1383. Statetmp = 3;
  1384. }
  1385. else
  1386. {
  1387. Statetmp = 2;
  1388. }
  1389. }
  1390. else if((ccs->CpState == 8) &&
  1391. (TotalTmpVolt >= 13.25))
  1392. {
  1393. Statetmp = 8;
  1394. }
  1395. else
  1396. {
  1397. Statetmp = 1;
  1398. }
  1399. }
  1400. else if((TotalTmpVolt >= 7.5) && (TotalTmpVolt < 10.5))
  1401. {
  1402. //State B (9V)
  1403. if((ccs->CpState == 4) && (TotalTmpVolt < 7.75))
  1404. {
  1405. Statetmp = 4;
  1406. }
  1407. else if((ccs->CpState == 1) && (TotalTmpVolt >= 10.25))
  1408. {
  1409. Statetmp = 1;
  1410. }
  1411. else
  1412. {
  1413. if((ccs->CpDuty >= 5) && (ccs->CpDuty < 100))
  1414. {
  1415. Statetmp = 3;
  1416. }
  1417. else
  1418. {
  1419. Statetmp = 2;
  1420. }
  1421. }
  1422. }
  1423. else if((TotalTmpVolt >= 4.5) && (TotalTmpVolt < 7.5))
  1424. {
  1425. //State C (6V)
  1426. if((ccs->CpState == 5) && (TotalTmpVolt < 4.75))
  1427. {
  1428. Statetmp = 5;
  1429. }
  1430. else if((ccs->CpState >= 2) && (ccs->CpState <= 3) && (TotalTmpVolt >= 7.25))
  1431. {
  1432. if((ccs->CpDuty >= 5)&&(ccs->CpDuty < 100))
  1433. {
  1434. Statetmp = 3;
  1435. }
  1436. else
  1437. {
  1438. Statetmp = 2;
  1439. }
  1440. }
  1441. else
  1442. {
  1443. Statetmp = 4;
  1444. }
  1445. }
  1446. else if((TotalTmpVolt >= 1.5) && (TotalTmpVolt < 4.5))
  1447. {
  1448. //State D (3V)
  1449. if((ccs->CpState == 6)&&(TotalTmpVolt < 1.75))
  1450. {
  1451. Statetmp = 6;
  1452. }
  1453. else if((ccs->CpState == 4)&&(TotalTmpVolt >= 4.25))
  1454. {
  1455. Statetmp = 4;
  1456. }
  1457. else
  1458. {
  1459. Statetmp = 5;
  1460. }
  1461. }
  1462. else if((TotalTmpVolt >= -1.5) && (TotalTmpVolt < 1.5)) //V_cp = -1.5V ~ 1.5V
  1463. {
  1464. //State E (0V)
  1465. if((ccs->CpState == 8) &&
  1466. (TotalTmpVolt < -1.25))
  1467. {
  1468. Statetmp = 8;
  1469. }
  1470. else if((ccs->CpState == 5) &&
  1471. (TotalTmpVolt >= 1.25))
  1472. {
  1473. Statetmp = 5;
  1474. }
  1475. else
  1476. {
  1477. Statetmp = 6;
  1478. }
  1479. }
  1480. else if((TotalTmpVolt >= -13.5) && (TotalTmpVolt < -10.5)) //V_cp = -10.5V ~ -13.5V
  1481. {
  1482. //State F (-12V)
  1483. if((ccs->CpState == 8) &&
  1484. (TotalTmpVolt >= -10.75))
  1485. {
  1486. Statetmp = 8;
  1487. }
  1488. else
  1489. {
  1490. Statetmp = 7;
  1491. }
  1492. }
  1493. else
  1494. {
  1495. //null
  1496. }
  1497. ccs->CpState = Statetmp;
  1498. }
  1499. #endif
  1500. Check_CP_State_Update_fork1(ccs);
  1501. #ifndef AWCCS
  1502. Check_CP_State_Error_fork1(ccs);
  1503. #endif
  1504. //Updating Plugin status
  1505. #if (PP_PROTECTION_MECHANISM == ENABLE)
  1506. if((ccs->CpState >= 2 ) && (ccs->CpState <= 5 ) &&
  1507. (ShmInternalComm->CCSConnectorType>0?((EVCOMM_SYS_INFO.PpVoltage > 1.2)&&(EVCOMM_SYS_INFO.PpVoltage <= 2.4)):((EVCOMM_SYS_INFO.PpVoltage > 0.61)&&(EVCOMM_SYS_INFO.PpVoltage <= 1.185)))
  1508. )
  1509. #else
  1510. if((ccs->CpState >= 2 ) && (ccs->CpState <= 5 ))
  1511. #endif
  1512. {
  1513. ccs->ConnectorPlugIn_new = TRUE;
  1514. }
  1515. else
  1516. {
  1517. ccs->ConnectorPlugIn_new = FALSE;
  1518. OutputCpPwmDuty(100);
  1519. }
  1520. Check_Plugin_Status_Update_fork1(ccs);
  1521. //ftime(&EndTime);
  1522. //DEBUG_PRINTF_EVCOMM_DETAIL("duration:%.02lf\n", DiffTimeb(StartTime, EndTime));
  1523. }//while
  1524. }
  1525. /*===========================================================================
  1526. FUNCTION: PP_Detection
  1527. DESCRIPTION:
  1528. 0. SeccComm fork3
  1529. 1. In order to detect CP in efficient response time, we creat an independent
  1530. thead for this procedure.
  1531. 2. The priority of this thread is set as the same as other tasks.
  1532. PRE-CONDITION:
  1533. INPUT:
  1534. OUTPUT:
  1535. GLOBAL VARIABLES:
  1536. =============================================================================*/
  1537. void PP_Detection()
  1538. {
  1539. pid_t tmp = 0;
  1540. // struct timeb StartTime, EndTime;
  1541. unsigned char Statetmp;
  1542. float TotalTmpVolt;
  1543. if(PP_Detection_Pid == 0)
  1544. {
  1545. tmp = fork();
  1546. if(tmp > 0)
  1547. {
  1548. PP_Detection_Pid = tmp;
  1549. #if 0
  1550. unsigned char buf[64];
  1551. memset(buf, 0, sizeof(buf));
  1552. sprintf(buf, "renice -10 -p %d", tmp);
  1553. system(buf);
  1554. #endif
  1555. return;
  1556. }
  1557. }
  1558. TotalTmpVolt = ReadAdcVolt_PP_fork3();
  1559. while(1)
  1560. {
  1561. TotalTmpVolt = ReadAdcVolt_PP_fork3();
  1562. EVCOMM_SYS_INFO.PpVoltage = TotalTmpVolt;
  1563. if (EVCOMM_SYS_INFO.PpVoltage_pre != EVCOMM_SYS_INFO.PpVoltage)
  1564. {
  1565. if((( (ShmInternalComm->CCSConnectorType>0?((EVCOMM_SYS_INFO.PpVoltage > 1.2)&&(EVCOMM_SYS_INFO.PpVoltage <= 2.4)):((EVCOMM_SYS_INFO.PpVoltage > 0.61)&&(EVCOMM_SYS_INFO.PpVoltage <= 1.185))))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].ConnectorPlugIn==FALSE))
  1566. ||(( (ShmInternalComm->CCSConnectorType>0?((EVCOMM_SYS_INFO.PpVoltage <= 1.2)||(EVCOMM_SYS_INFO.PpVoltage > 2.4)):((EVCOMM_SYS_INFO.PpVoltage <= 0.61)||(EVCOMM_SYS_INFO.PpVoltage > 1.185))))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].ConnectorPlugIn==TRUE)))
  1567. {
  1568. // plug-in : CCS1 (0.61 < V <1.185), CCS2 (1.2 < V <2.4)
  1569. sprintf(buf_log_evcomm_fork3,
  1570. "[fork3]PP(%.2f >> %.2fV)",
  1571. EVCOMM_SYS_INFO.PpVoltage_pre,
  1572. EVCOMM_SYS_INFO.PpVoltage
  1573. );
  1574. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork3);
  1575. EVCOMM_SYS_INFO.PpVoltage_pre = EVCOMM_SYS_INFO.PpVoltage;
  1576. }
  1577. }
  1578. #if 0
  1579. sleep(5);
  1580. printf("V_pp = %.02f\n", TotalTmpVolt);
  1581. #endif
  1582. }//while
  1583. }
  1584. /*===========================================================================
  1585. FUNCTION: Error_Monitor
  1586. DESCRIPTION:
  1587. 1. This function only works in SeccComm fork2.
  1588. PRE-CONDITION:
  1589. INPUT:
  1590. OUTPUT:
  1591. GLOBAL VARIABLES:
  1592. =============================================================================*/
  1593. void Error_Monitor()
  1594. {
  1595. pid_t tmp = 0;
  1596. double time_diff = 0;
  1597. unsigned char status = 0;
  1598. struct ChargingInfoData *ccs;
  1599. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1600. if(Error_Monitor_Pid == 0)
  1601. {
  1602. tmp = fork(); //SeccComm fork2
  1603. if(tmp > 0)
  1604. {
  1605. Error_Monitor_Pid = tmp;
  1606. #if 0
  1607. unsigned char buf[64];
  1608. memset(buf, 0, sizeof(buf));
  1609. sprintf(buf, "renice -20 -p %d", tmp);
  1610. system(buf);
  1611. #endif
  1612. return;
  1613. }
  1614. }
  1615. while(1)
  1616. {
  1617. //Step 0
  1618. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  1619. {
  1620. //If the End_Process is in processing, disable Error_Monitor.
  1621. continue;
  1622. }
  1623. //Step1 1: Check and Response to Plugin Status
  1624. if(CheckConnectorPlugIn() == FALSE)
  1625. {
  1626. status = Check_V2G_Flow_Status();
  1627. if (status > IDLE &&
  1628. status < Performance_Timeout &&
  1629. status != CM_SET_KEY_REQ &&
  1630. status != CM_SET_KEY_CNF &&
  1631. EVCOMM_SYS_INFO.End_Process_inused == FALSE)
  1632. {
  1633. #if (CP_PROTECTION_MECHANISM == ENABLE)
  1634. //SAVE_SYS_LOG_MSG_EVCOMM("[fork2] Emergency Stop (due to Connector is plugged out during communication.)");
  1635. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Plug out Error => End_Process");
  1636. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1637. //CCS_SECC_CP_State_Error (023889)
  1638. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1639. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1640. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1641. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1642. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1643. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1644. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1645. End_Process();
  1646. #else
  1647. //SAVE_SYS_LOG_MSG_EVCOMM("CP_PROTECTION_MECHANISM is disabled. Emergency Stop: skipped" );
  1648. #endif
  1649. }
  1650. }
  1651. //Step 2: Check for V2G_SECC_Sequence_Timeout
  1652. //#if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  1653. #if 1
  1654. status = Check_V2G_Flow_Status();
  1655. if (status >= SupportedAppProtocolRequest &&
  1656. status < SessionStopRequest)
  1657. {
  1658. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_End);
  1659. time_diff = DiffTimeb_fork2_Error_Monitor(EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start, EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_End);
  1660. if(time_diff > V2G_SECC_Sequence_Timeout) //60s
  1661. {
  1662. sprintf(buf_log_evcomm_fork2,
  1663. "[fork2]V2G_SECC_Sequence_Timeout in state %d - (%.02lf of %d ms)\n",
  1664. status,
  1665. time_diff,
  1666. V2G_SECC_Sequence_Timeout);
  1667. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1668. Update_V2G_Flow_Status(Sequence_Timeout);
  1669. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1670. //CCS_SECC_TIMEOUT_V2G_Sequence_Time (023844)
  1671. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1672. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1673. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1674. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1675. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  1676. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  1677. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1678. End_Process();
  1679. break;
  1680. }
  1681. else if (time_diff > 4000) //4s
  1682. {
  1683. //Check for CSU command of "Stop by EVSE"
  1684. if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_Shutdown)
  1685. {
  1686. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]EVSE_Shutdown");
  1687. Update_V2G_Flow_Status(Other_Fault);
  1688. }
  1689. else if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_EmergencyShutdown)
  1690. {
  1691. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]EVSE_EmergencyShutdown");
  1692. Update_V2G_Flow_Status(Other_Fault);
  1693. }
  1694. else if (ShmInternalComm->ChargingPermission == FALSE)
  1695. {
  1696. if (status >= ChargeParameterDiscoveryRequest) //&& status < SessionStopRequest
  1697. {
  1698. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]ChargingPermission = FALSE");
  1699. Update_V2G_Flow_Status(Other_Fault);
  1700. }
  1701. }
  1702. else
  1703. {
  1704. //null
  1705. }
  1706. }
  1707. else
  1708. {
  1709. //null
  1710. }
  1711. }
  1712. #endif
  1713. //Step 3: Check and Response to Error V2gFlowStatus
  1714. status = Check_V2G_Flow_Status();
  1715. if (status == Performance_Timeout ||
  1716. status == Sequence_Timeout ||
  1717. status == Other_Fault)
  1718. {
  1719. sprintf(buf_log_evcomm_fork2,
  1720. "[fork2]Timeout or Fault State(%d) => End_Process",
  1721. status);
  1722. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1723. //Normal Stop
  1724. //alarm and duty to 100%
  1725. //OutputCpPwmDuty(100);
  1726. //SwitchCpStateE(ENABLE); //Set CP duty as 100% and set CP state as E (0V).
  1727. //[Joseph/ To-Do] Set State E (0V) via GPIO setting
  1728. End_Process();
  1729. }
  1730. //Step 4: Check and Response to CP State Error
  1731. if(ccs->CpState_err == TRUE)
  1732. {
  1733. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]CP Error => End_Process");
  1734. Update_V2G_Flow_Status(Other_Fault);
  1735. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1736. //CCS_SECC_CP_State_Error (023889)
  1737. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1738. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1739. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1740. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1741. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1742. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1743. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1744. End_Process();
  1745. }
  1746. //Step 5: Check and Response to Shutdown Commnad from CSU
  1747. if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_Shutdown ||
  1748. EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_EmergencyShutdown)
  1749. {
  1750. if (Check_V2G_Flow_Status() <= SLACC_SDP_TCP_Connection)
  1751. {
  1752. sprintf(buf_log_evcomm_fork2,
  1753. "[fork2]EVSE Shutdown(%d) => End_Process",
  1754. EVCOMM_SYS_INFO.DC_EVSEStatus);
  1755. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1756. Update_V2G_Flow_Status(Other_Fault);
  1757. End_Process();
  1758. }
  1759. }
  1760. //Step 6: Check and Response to SessionStop
  1761. status = Check_V2G_Flow_Status();
  1762. if (status == SessionStopResponse)
  1763. {
  1764. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]SessionStopResponse => End_Process");
  1765. End_Process();
  1766. }
  1767. //Step 7: Check for ChargingPermission from TRUE to FALSE before V2G Messages
  1768. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  1769. if ((ShmInternalComm->ChargingPermission == FALSE) &&
  1770. (ShmInternalComm->ChargingPermission_pre >=1) &&
  1771. (ccs->CpState >= 3) && (ccs->CpState <=5))
  1772. {
  1773. if (status >= CM_SLAC_PARM_REQ &&
  1774. status != CM_SET_KEY_REQ &&
  1775. status != CM_SET_KEY_CNF &&
  1776. status <= SLACC_SDP_TCP_Connection)
  1777. {
  1778. sprintf(buf_log_evcomm_fork2,
  1779. "[fork2]Permission OFF before V2G msg(%d) => End_Process",
  1780. ShmInternalComm->ChargingPermission);
  1781. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1782. Update_V2G_Flow_Status(Other_Fault);
  1783. End_Process();
  1784. }
  1785. }
  1786. #if 0
  1787. //Step 8: DC OVP Protection
  1788. if (CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED &&
  1789. status > CableCheckResponse &&
  1790. status <= SessionStopRequest &&
  1791. status != ChargingStatusRequest &&
  1792. status != ChargingStatusResponse &&
  1793. EVCOMM_SYS_INFO.EvBatteryMaxVoltage != 0)
  1794. {
  1795. //Part A: OVP Protection
  1796. if (EVCOMM_SYS_INFO.PresentChargingVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02)) // 2%
  1797. {
  1798. sprintf(buf_log_evcomm_fork2,
  1799. "[fork2][Error]OVP => End_Process (%.02f > %.02f)",
  1800. EVCOMM_SYS_INFO.PresentChargingVoltage,
  1801. (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02));
  1802. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1803. Update_V2G_Flow_Status(Other_Fault);
  1804. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1805. //System CCS output OVP (012219)
  1806. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1807. ShmStatusCodeData->PresentStatusCode[0][1] = 1;
  1808. ShmStatusCodeData->PresentStatusCode[0][2] = 2;
  1809. ShmStatusCodeData->PresentStatusCode[0][3] = 2;
  1810. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  1811. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1812. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1813. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1814. End_Process();
  1815. }
  1816. //Part B: Over Voltage Request Protection
  1817. if (EVCOMM_SYS_INFO.EvBatterytargetVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02))
  1818. {
  1819. sprintf(buf_log_evcomm_fork2,
  1820. "[fork2]Over V Req => End_Process (%.02f > %.02f)",
  1821. EVCOMM_SYS_INFO.EvBatterytargetVoltage,
  1822. (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02)
  1823. );
  1824. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1825. Update_V2G_Flow_Status(Other_Fault);
  1826. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1827. //System CCS output OVP (012219)
  1828. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1829. ShmStatusCodeData->PresentStatusCode[0][1] = 1;
  1830. ShmStatusCodeData->PresentStatusCode[0][2] = 2;
  1831. ShmStatusCodeData->PresentStatusCode[0][3] = 2;
  1832. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  1833. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1834. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1835. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1836. End_Process();
  1837. }
  1838. }
  1839. #endif
  1840. #if 1
  1841. //Step 9: Check 60V
  1842. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  1843. if (CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED &&
  1844. ShmInternalComm->ChargingPermission >=1 &&
  1845. status < CableCheckRequest)
  1846. {
  1847. if (EVCOMM_SYS_INFO.PresentChargingVoltage >= 60) //60V
  1848. {
  1849. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]DC Output Voltage is over 60V => End_Process");
  1850. Update_V2G_Flow_Status(Other_Fault);
  1851. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1852. //CCS_SECC_Unexpected_60V_Before_Charing_Error (023890)
  1853. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1854. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1855. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1856. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1857. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  1858. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  1859. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1860. //Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1861. End_Process();
  1862. }
  1863. }
  1864. #endif
  1865. //Step 10: Check if the connector is unplug from plugin
  1866. if (EVCOMM_SYS_INFO.ConnectorPlugIn_pre == TRUE && EVCOMM_SYS_INFO.ConnectorPlugIn == FALSE)
  1867. {
  1868. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Unplug Reset => End_Process");
  1869. Update_V2G_Flow_Status(Other_Fault);
  1870. End_Process();
  1871. }
  1872. }//while
  1873. }
  1874. /*===========================================================================
  1875. FUNCTION: SendSetKey
  1876. DESCRIPTION:
  1877. PRE-CONDITION:
  1878. INPUT:
  1879. OUTPUT:
  1880. GLOBAL VARIABLES:
  1881. =============================================================================*/
  1882. int SendSetKey()
  1883. {
  1884. int i = 0;
  1885. unsigned char nRandValue = 0x0;
  1886. unsigned char ConstString[16] = "PhihongKey000000";
  1887. memset(&SendMmePacket,0,sizeof(struct MmeHeader));
  1888. memcpy(SendMmePacket.ODA,QcaMac,6);
  1889. memcpy(SendMmePacket.OSA,CsuMac,6);
  1890. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  1891. SendMmePacket.MMV = 0x01;
  1892. SendMmePacket.MMTYPE = MMTYPE_CM_SET_KEY_REQ;
  1893. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  1894. SendMmePacketSize = 0;
  1895. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//Fixed value (0x01) to indicate ��NMK��
  1896. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,4);//My Nonce, Fixed value(0x00000000), encrypted payload not used
  1897. SendMmePacketSize+=4;
  1898. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,4);//Your Nonce, Fixed value(0x00000000), encrypted payload not used
  1899. SendMmePacketSize+=4;
  1900. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x04;//PID, Fixed value (0x04) to indicate ��HLE protocol��
  1901. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,2);//PRN, Fixed value(0x00), encrypted payload not used
  1902. SendMmePacketSize+=2;
  1903. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00;//PMN, Fixed value(0x00) encrypted payload not used
  1904. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//CCo Capablility
  1905. srand(time(NULL));
  1906. for (i = 10; i < 16; i++)
  1907. {
  1908. nRandValue = (rand()%62) + 1;
  1909. if((nRandValue>=0)&&(nRandValue<=9)) // 0 ~ 9
  1910. {
  1911. ConstString[i]= nRandValue + 0x30;
  1912. }
  1913. else if((nRandValue>=10)&&(nRandValue<=35)) // A ~ Z
  1914. {
  1915. ConstString[i]= nRandValue -10 + 0x41;
  1916. }
  1917. else if((nRandValue>=36)&&(nRandValue<=61)) // a ~ z
  1918. {
  1919. ConstString[i]= nRandValue -37 + 0x61;
  1920. }
  1921. else
  1922. {
  1923. ConstString[i]= 0x30;
  1924. }
  1925. }
  1926. memset(NewNmkKey,0,sizeof(NewNmkKey));
  1927. memset(Nid,0,sizeof(Nid));
  1928. HPAVKeyNMK(NewNmkKey, ConstString);
  1929. HPAVKeyNID(Nid,NewNmkKey,DEFAULT_LEVEL);
  1930. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,Nid,sizeof(Nid)); //NID, 54 LSBs contain the NID 2 MSBs = 0b00
  1931. SendMmePacketSize+=sizeof(Nid);
  1932. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x01;//NewEKS,Fixed value (0x01)to indicate ��NMK��
  1933. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,NewNmkKey,sizeof(NewNmkKey));//NewKey
  1934. SendMmePacketSize += sizeof(NewNmkKey);
  1935. SendMmePacketSize += 19; //the size before MMENTRY
  1936. SAVE_SYS_LOG_MSG_EVCOMM("[QCA7K][Tx]CM_SET_KEY_REQ");
  1937. i = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  1938. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  1939. DEBUG_PRINTF_EVCOMM_DETAIL("SendSetKey: send size =%d\n",i);
  1940. }
  1941. /*===========================================================================
  1942. FUNCTION: GetQca7kMac
  1943. DESCRIPTION:
  1944. PRE-CONDITION:
  1945. INPUT:
  1946. OUTPUT:
  1947. GLOBAL VARIABLES:
  1948. =============================================================================*/
  1949. int GetQca7kMac()
  1950. {
  1951. int i = 0;
  1952. struct QcaVendorMmeHeader SendPacket;
  1953. memset(&SendPacket, 0, sizeof(struct QcaVendorMmeHeader));
  1954. memset(SendPacket.ODA, 0xFF, 6); //broadcast
  1955. memcpy(SendPacket.OSA, CsuMac, 6);
  1956. SendPacket.MTYPE = htons(EtherType_HomePlug);
  1957. SendPacket.MMV = 0x00;
  1958. SendPacket.MMTYPE = MMTYPE_VENDOR_VS_NW_INFO;
  1959. SendPacket.OUI[0] = 0x00;
  1960. SendPacket.OUI[1] = 0xB0;
  1961. SendPacket.OUI[2] = 0x52;
  1962. i = sendto(RawSock, &SendPacket, 20, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  1963. DEBUG_PRINTF_EVCOMM_DETAIL("GetQca7kMac: send size =%d\n", i);
  1964. SAVE_SYS_LOG_MSG_EVCOMM("[QCA7K][Tx][VENDOR_VS_NW_INFO]Req for QCA7K MacAddr");
  1965. }
  1966. /*===========================================================================
  1967. FUNCTION: Array_Check_All_Zero
  1968. DESCRIPTION:
  1969. PRE-CONDITION:
  1970. INPUT:
  1971. OUTPUT:
  1972. result:
  1973. (1) TRUE: all zero
  1974. (2) FALSE: not all zero
  1975. GLOBAL VARIABLES:
  1976. =============================================================================*/
  1977. int Array_Check_All_Zero(unsigned char *ptr, int size)
  1978. {
  1979. int result = TRUE;
  1980. int i = 0;
  1981. for (i = 0; i < size; i++)
  1982. {
  1983. if (ptr[i] != 0)
  1984. {
  1985. result = FALSE;
  1986. break;
  1987. }
  1988. }
  1989. return result;
  1990. }
  1991. /*===========================================================================
  1992. FUNCTION: Array_Compare_Identity
  1993. DESCRIPTION:
  1994. PRE-CONDITION:
  1995. INPUT:
  1996. OUTPUT:
  1997. result = FALSE (not identical)
  1998. result = TRUE (identical)
  1999. GLOBAL VARIABLES:
  2000. =============================================================================*/
  2001. int Array_Compare_Identity(unsigned char *ptrA, unsigned char *ptrB, int size)
  2002. {
  2003. int result = TRUE;
  2004. int i = 0;
  2005. for (i = 0; i < size; i++)
  2006. {
  2007. if (ptrA[i] != ptrB[i])
  2008. {
  2009. result = FALSE;
  2010. #if 0
  2011. sprintf(buf_log_evcomm,
  2012. "[Array_Compare_Identity]%02X%02X%02X%02X%02X%02X,%02X%02X%02X%02X%02X%02X(%d)\n",
  2013. ptrA[0], ptrA[1], ptrA[2], ptrA[3], ptrA[4], ptrA[5],
  2014. ptrB[0], ptrB[1], ptrB[2], ptrB[3], ptrB[4], ptrB[5],
  2015. result);
  2016. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2017. #endif
  2018. break;
  2019. }
  2020. }
  2021. return result;
  2022. }
  2023. /*===========================================================================
  2024. FUNCTION: SLAC_DB_Search_EvMac_idx
  2025. DESCRIPTION:
  2026. PRE-CONDITION:
  2027. INPUT:
  2028. OUTPUT:
  2029. idx = -1 (not found)
  2030. GLOBAL VARIABLES:
  2031. =============================================================================*/
  2032. int SLAC_DB_Search_EvMac_idx(struct EVCC_SLAC_DATA_TYPE *evcc, unsigned char *EvMac_in)
  2033. {
  2034. int idx = -1;
  2035. int i = 0;
  2036. if (evcc->arrayLen == 0)
  2037. {
  2038. //printf("[SLAC_DB_Search_EvMac_idx]arrayLen is empty (%d)\n", evcc->arrayLen);
  2039. //no need to search
  2040. }
  2041. else if (evcc->arrayLen > EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE)
  2042. {
  2043. //error
  2044. sprintf(buf_log_evcomm,
  2045. "[ERROR][SLAC_DB_Search_EvMac_idx]DB length(%d) > %d",
  2046. evcc->arrayLen,
  2047. EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE);
  2048. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2049. evcc->arrayLen = 0; //reset
  2050. }
  2051. else
  2052. {
  2053. //start searching
  2054. for (i = 0; i < evcc->arrayLen; i++)
  2055. {
  2056. //printf("[SLAC_DB_Search_EvMac_idx]checking DB[%d]...\n", i);
  2057. if (Array_Compare_Identity(evcc->array[i].EvMac, EvMac_in, SLAC_EVMAC_LENGTH) == TRUE)
  2058. {
  2059. //printf("[SLAC_DB_Search_EvMac_idx]identical at DB[%d]...\n", i);
  2060. idx = i;
  2061. break;
  2062. }
  2063. }
  2064. }
  2065. //printf("[SLAC_DB_Search_EvMac_idx]return = %d\n", idx);
  2066. return idx;
  2067. }
  2068. /*===========================================================================
  2069. FUNCTION: SLAC_DB_Check_EvMac_RunID_Matching
  2070. DESCRIPTION:
  2071. PRE-CONDITION:
  2072. INPUT:
  2073. OUTPUT:
  2074. res = FALSE (unmatched)
  2075. res = TRUE (matched)
  2076. GLOBAL VARIABLES:
  2077. =============================================================================*/
  2078. int SLAC_DB_Check_EvMac_RunID_Matching(struct EVCC_SLAC_DATA_TYPE *evcc, unsigned char *EvMac_in, unsigned char *RunID_in)
  2079. {
  2080. int res = FALSE;
  2081. int idx = -1;
  2082. idx = SLAC_DB_Search_EvMac_idx(evcc, EvMac_in);
  2083. if (idx >= 0)
  2084. {
  2085. res = Array_Compare_Identity(evcc->array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2086. }
  2087. else
  2088. {
  2089. //not found the EvMac data in DB
  2090. res = FALSE;
  2091. }
  2092. return res;
  2093. }
  2094. /*===========================================================================
  2095. FUNCTION: SLAC_DB_Add
  2096. DESCRIPTION:
  2097. 1. Saving each CM_SLAC_PARM_REQ data into EVCC database if its
  2098. EvMac and RunID data are different, respectively.
  2099. PRE-CONDITION:
  2100. INPUT:
  2101. OUTPUT:
  2102. idx = saved index (must be a positive value)
  2103. GLOBAL VARIABLES:
  2104. =============================================================================*/
  2105. int SLAC_DB_Add(unsigned char *EvMac_in, unsigned char *RunID_in)
  2106. {
  2107. int idx = -1;
  2108. //Search if this EvMac and RunID already exists
  2109. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2110. if (idx < 0) //not exist, yet.
  2111. {
  2112. if (SLAC_INFO.arrayLen < EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE) //20
  2113. {
  2114. sprintf(buf_log_evcomm,
  2115. "[SLAC_DB_Add]data does not exist => added to %d-th",
  2116. SLAC_INFO.arrayLen);
  2117. DEBUG_PRINTF_EVCOMM_DETAIL(buf_log_evcomm);
  2118. if (SLAC_INFO.arrayLen >= 0)
  2119. {
  2120. memset(&SLAC_INFO.array[SLAC_INFO.arrayLen], 0, sizeof(struct EVCC_SLAC_DATA_ARRAY_TYPE));
  2121. memcpy(SLAC_INFO.array[SLAC_INFO.arrayLen].EvMac, EvMac_in, SLAC_EVMAC_LENGTH);
  2122. memcpy(SLAC_INFO.array[SLAC_INFO.arrayLen].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2123. idx = SLAC_INFO.arrayLen;
  2124. SLAC_INFO.arrayLen++;
  2125. }
  2126. else
  2127. {
  2128. sprintf(buf_log_evcomm,
  2129. "[ERROR][SLAC_DB_Add]arrayLen: unexpected(%d)",
  2130. SLAC_INFO.arrayLen);
  2131. DEBUG_PRINTF_EVCOMM_DETAIL(buf_log_evcomm);
  2132. SLAC_INFO.arrayLen = 0;
  2133. }
  2134. }
  2135. else
  2136. {
  2137. //DB is full
  2138. sprintf(buf_log_evcomm,
  2139. "[SLAC_DB_Add]DB is full(%d) => bypass",
  2140. SLAC_INFO.arrayLen);
  2141. DEBUG_PRINTF_EVCOMM_DETAIL(buf_log_evcomm);
  2142. }
  2143. }
  2144. else
  2145. {
  2146. #if 0
  2147. sprintf(buf_log_evcomm,
  2148. "[SLAC_DB_Add]EvMac: existed (%d)",
  2149. idx);
  2150. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2151. #endif
  2152. //Check RunID
  2153. if (Array_Compare_Identity(SLAC_INFO.array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH) == TRUE)
  2154. {
  2155. //RunID is the same
  2156. //SAVE_SYS_LOG_MSG_EVCOMM("[SLAC_DB_Add]RunID: same");
  2157. }
  2158. else
  2159. {
  2160. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC_DB_Add]RunID: diff");
  2161. }
  2162. //Reset all corresponding parameters
  2163. #if 0
  2164. sprintf(buf_log_evcomm,
  2165. "[SLAC_DB_Add]EvMac: reset para(%d)",
  2166. idx);
  2167. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2168. #endif
  2169. memset(&SLAC_INFO.array[idx], 0, sizeof(struct EVCC_SLAC_DATA_ARRAY_TYPE));
  2170. memcpy(SLAC_INFO.array[idx].EvMac, EvMac_in, SLAC_EVMAC_LENGTH);
  2171. memcpy(SLAC_INFO.array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2172. }
  2173. return idx;
  2174. }
  2175. /*===========================================================================
  2176. FUNCTION: SLAC_DB_Reset
  2177. DESCRIPTION:
  2178. PRE-CONDITION:
  2179. INPUT:
  2180. OUTPUT:
  2181. GLOBAL VARIABLES:
  2182. =============================================================================*/
  2183. int SLAC_DB_Reset()
  2184. {
  2185. memset(&SLAC_INFO, 0, sizeof(struct EVCC_SLAC_DATA_TYPE));
  2186. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC_DB_Reset]DONE");
  2187. }
  2188. /*===========================================================================
  2189. FUNCTION: MmeProcess
  2190. DESCRIPTION:
  2191. PRE-CONDITION:
  2192. INPUT:
  2193. OUTPUT:
  2194. GLOBAL VARIABLES:
  2195. =============================================================================*/
  2196. int MmeProcess(unsigned char *Buffer, int DataLength)
  2197. {
  2198. //struct ethhdr *EthPacket;
  2199. struct MmeHeader *MmePacket;
  2200. static unsigned char counter;
  2201. unsigned char state = 0;
  2202. unsigned char *EvMac_in;
  2203. unsigned char *RunID_in;
  2204. int Rtn = 0;
  2205. int idx = 0;
  2206. MmePacket = (struct MmeHeader *)Buffer;
  2207. state = Check_V2G_Flow_Status();
  2208. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2209. {
  2210. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***********************************\n");
  2211. DEBUG_PRINTF_EVCOMM_DETAIL("***** Received MME Packet *****\n");
  2212. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  2213. DEBUG_PRINTF_EVCOMM_DETAIL("DataLength=%d\n",DataLength);
  2214. DEBUG_PRINTF_EVCOMM_DETAIL("ODA: %02x:%02x:%02x:%02x:%02x:%02x\n", //Destination MAC Address
  2215. MmePacket->ODA[0], MmePacket->ODA[1],
  2216. MmePacket->ODA[2], MmePacket->ODA[3],
  2217. MmePacket->ODA[4], MmePacket->ODA[5]);
  2218. DEBUG_PRINTF_EVCOMM_DETAIL("OSA: %02x:%02x:%02x:%02x:%02x:%02x\n", //Source MAC Address (EV MAC)
  2219. MmePacket->OSA[0], MmePacket->OSA[1],
  2220. MmePacket->OSA[2], MmePacket->OSA[3],
  2221. MmePacket->OSA[4], MmePacket->OSA[5]);
  2222. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(MmePacket->MTYPE));
  2223. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", MmePacket->MMV);
  2224. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", MmePacket->MMTYPE);
  2225. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n",
  2226. MmePacket->FMI[0],MmePacket->FMI[1]);
  2227. }
  2228. #endif
  2229. #if (SLAC_FIRST_RESPONSE_METHOD == SET_NO_PWM_IF_NOT_GET_PERMISSION)
  2230. {
  2231. //Check CP as 5%
  2232. if (EVCOMM_SYS_INFO.CpState != 3 &&
  2233. EVCOMM_SYS_INFO.CpState != 4 &&
  2234. MmePacket->MMTYPE != MMTYPE_CM_SET_KEY_CNF &&
  2235. MmePacket->MMTYPE != MMTYPE_VENDOR_VS_HOST_ACTION &&
  2236. MmePacket->MMTYPE != MMTYPE_VENDOR_ATTEN_CHAR &&
  2237. MmePacket->MMTYPE != MMTYPE_VENDOR_VS_NW_INFO_CNF
  2238. )
  2239. {
  2240. //SAVE_SYS_LOG_MSG_EVCOMM("[SLAC]ignored(wrong CP state)");
  2241. return 0;
  2242. }
  2243. }
  2244. #endif
  2245. //[To-Do] Adding a pre-check filter mechanism for Source and Destination MAC Address
  2246. //check if the destination address is broadcast or EVSE itself, it can be ignore if not belong to itself.
  2247. switch(MmePacket->MMTYPE)
  2248. {
  2249. case MMTYPE_CM_SET_KEY_CNF:
  2250. {
  2251. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SET_KEY_CNF ---\n");
  2252. DEBUG_PRINTF_EVCOMM_DETAIL("Result: 0x%x\n", MmePacket->MMENTRY[0]);
  2253. SAVE_SYS_LOG_MSG_EVCOMM("[QCA7K][Rx]CM_SET_KEY_CNF (SetKey: DONE)");
  2254. Update_V2G_Flow_Status(CM_SET_KEY_CNF);
  2255. break;
  2256. }
  2257. case MMTYPE_CM_SLAC_PARM_REQ:
  2258. {
  2259. //Check QCA7000 status
  2260. if (EVCOMM_SYS_INFO.QCA7K_SetKeyDone == FALSE)
  2261. {
  2262. //SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx]CM_SLAC_PARM_REQ: ignored(QCA7K init...)");
  2263. break;
  2264. }
  2265. //Check error state
  2266. state = Check_V2G_Flow_Status();
  2267. if (state == Performance_Timeout || //253
  2268. state == Sequence_Timeout || //254
  2269. state == Other_Fault) //255
  2270. {
  2271. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx]CM_SLAC_PARM_REQ: ignored(in error state)");
  2272. break;
  2273. }
  2274. //Printing EV MAC Address
  2275. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx]CM_SLAC_PARM_REQ");
  2276. //Avoid Coupled SLAC_PARM_REQ
  2277. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2278. {
  2279. #if 0
  2280. sprintf(buf_log_evcomm,
  2281. "[WARNING][SLAC][Rx]CM_SLAC_PARM_REQ: ignored(coupled SLAC,%d)",
  2282. CheckConnectorPlugIn());
  2283. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2284. #endif
  2285. break;
  2286. }
  2287. //[TC_SECC_VTB_CmSlacParm_003] SECURITY_TYPE needs to be 0x00 (no security)
  2288. if (MmePacket->MMENTRY[1] != 0)
  2289. {
  2290. sprintf(buf_log_evcomm,
  2291. "[WARNING][SLAC][Rx]CM_SLAC_PARM_REQ: ignored(invalid SECURITY_TYPE,%d)", //Source MAC Address (EV MAC)
  2292. MmePacket->MMENTRY[1]);
  2293. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2294. break;
  2295. }
  2296. //=================== Legal CM_SLAC_PARM_REQ Zone =================
  2297. Update_V2G_Flow_Status(CM_SLAC_PARM_REQ);
  2298. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_RX_CM_SLAC_PARM_REQ)
  2299. {
  2300. //Once receiving CM_SLAC_PARM_REQ, set PWM as 5%
  2301. SwitchCpStateE(DISABLE);
  2302. OutputCpPwmDuty(5);
  2303. }
  2304. #endif
  2305. //Checking if this SLAC Req comes before 5% PWM (for 15118)
  2306. if(ShmInternalComm->ChargingPermission == FALSE)
  2307. {
  2308. //Sniffer_Tcpdump(ENABLE);
  2309. sprintf(buf_log_evcomm, "Check Permission: %d (SLAC first => START)", ShmInternalComm->ChargingPermission);
  2310. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2311. }
  2312. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2313. {
  2314. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SLAC_PARM_REQ ---\n");
  2315. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2316. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2317. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2318. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2319. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2320. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2321. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2322. DEBUG_PRINTF_EVCOMM_DETAIL("CipherSuiteSetSize: 0x%x\n", MmePacket->MMENTRY[10]);
  2323. DEBUG_PRINTF_EVCOMM_DETAIL("CipherSuite [1]: 0x%x,0x%x\n",
  2324. MmePacket->MMENTRY[11], MmePacket->MMENTRY[12]);
  2325. }
  2326. #endif
  2327. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2328. {
  2329. //Saving each CM_SLAC_PARM_REQ data into EVCC database
  2330. EvMac_in = &MmePacket->OSA[0];
  2331. RunID_in = &MmePacket->MMENTRY[2];
  2332. idx = SLAC_DB_Add(EvMac_in, RunID_in); //(EvMac, RunID)
  2333. if (idx < 0)
  2334. {
  2335. sprintf(buf_log_evcomm,
  2336. "[WARNING][CM_SLAC_PARM_REQ]DB is full or errors occour(%d) => ignore",
  2337. idx);
  2338. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2339. break;
  2340. }
  2341. //Select the 1st EV MAC address
  2342. if (SLAC_INFO.arrayLen == 1) //1st Req
  2343. {
  2344. #if 1
  2345. sprintf(buf_log_evcomm,
  2346. "[SLAC][Rx]CM_SLAC_PARM_REQ[%d](%02X:%02X:%02X:%02X:%02X:%02X,%02X%02X%02X%02X%02X%02X%02X%02X):selected",
  2347. (idx + 1),
  2348. MmePacket->OSA[0], MmePacket->OSA[1], MmePacket->OSA[2], MmePacket->OSA[3], MmePacket->OSA[4], MmePacket->OSA[5],
  2349. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3], MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2350. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7], MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2351. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2352. #endif
  2353. /*
  2354. sprintf(buf_log_evcomm,
  2355. "[SLAC][EVMAC][%d-th]%02X:%02X:%02X:%02X:%02X:%02X (selected)", //Source MAC Address (EV MAC)
  2356. SLAC_INFO.arrayLen,
  2357. MmePacket->OSA[0], MmePacket->OSA[1],
  2358. MmePacket->OSA[2], MmePacket->OSA[3],
  2359. MmePacket->OSA[4], MmePacket->OSA[5]);
  2360. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2361. sprintf(buf_log_evcomm,
  2362. "[SLAC][RunID][%d-th]%02X%02X%02X%02X%02X%02X%02X%02X (selected)", //RunID (from EVCC)
  2363. SLAC_INFO.arrayLen,
  2364. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2365. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2366. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2367. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2368. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2369. */
  2370. }
  2371. else //2nd Req
  2372. {
  2373. #if 1
  2374. sprintf(buf_log_evcomm,
  2375. "[SLAC][Rx]CM_SLAC_PARM_REQ[%d](%02X:%02X:%02X:%02X:%02X:%02X,%02X%02X%02X%02X%02X%02X%02X%02X):not selected",
  2376. (idx + 1),
  2377. MmePacket->OSA[0], MmePacket->OSA[1], MmePacket->OSA[2], MmePacket->OSA[3], MmePacket->OSA[4], MmePacket->OSA[5],
  2378. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3], MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2379. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7], MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2380. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2381. #endif
  2382. /*
  2383. sprintf(buf_log_evcomm,
  2384. "[SLAC][EVMAC][%d-th]%02X:%02X:%02X:%02X:%02X:%02X (not selected)", //Source MAC Address (EV MAC)
  2385. SLAC_INFO.arrayLen,
  2386. MmePacket->OSA[0], MmePacket->OSA[1],
  2387. MmePacket->OSA[2], MmePacket->OSA[3],
  2388. MmePacket->OSA[4], MmePacket->OSA[5]);
  2389. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2390. sprintf(buf_log_evcomm,
  2391. "[SLAC][RunID][%d-th]%02X%02X%02X%02X%02X%02X%02X%02X (not selected)", //RunID (from EVCC)
  2392. SLAC_INFO.arrayLen,
  2393. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2394. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2395. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2396. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2397. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2398. */
  2399. }
  2400. memcpy(EvMac, MmePacket->OSA, sizeof(EvMac));
  2401. memcpy(DestSocketAddress.sll_addr, MmePacket->OSA, SLAC_EVMAC_LENGTH);
  2402. memcpy(SlacRunId, MmePacket->MMENTRY + 2, SLAC_RUNID_LENGTH);
  2403. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2404. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  2405. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2406. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2407. SendMmePacket.MMV = MmePacket->MMV;
  2408. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_PARM_CNF;
  2409. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2410. SendMmePacketSize = 0;
  2411. memset(SendMmePacket.MMENTRY, 0xFF, 6); //M-SOUND_TARGET(6-byte:0xFFFFFFFFFFFF): Fixed value indicating that M-Sounds to be sent as Ethernet broadcast
  2412. SendMmePacketSize += 6;
  2413. 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
  2414. SendMmePacket.MMENTRY[SendMmePacketSize++] = 6; //Time_Out(0x06): unit = 100ms
  2415. 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
  2416. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SLAC_INFO.array[idx].EvMac, 6); //FORWARDING_STA(MAC Address of the EV HLE)
  2417. SendMmePacketSize += 6;
  2418. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00): 0x00(PEV-EVSE Association), 0x01-0xFF(Reserved)
  2419. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00): 0x00(No Security), 0x01(Public Key Signature), 0x02-0xFF(Reserved)
  2420. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SlacRunId, SLAC_RUNID_LENGTH); //RunID (8-byte)
  2421. SendMmePacketSize += SLAC_RUNID_LENGTH;
  2422. SendMmePacketSize += 19; //the size before MMENTRY
  2423. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2424. {
  2425. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  2426. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2427. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  2428. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2429. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  2430. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  2431. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  2432. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  2433. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  2434. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_PARM_CNF ---\n");
  2435. DEBUG_PRINTF_EVCOMM_DETAIL("M-SOUND_TARGET: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2436. SendMmePacket.MMENTRY[0],SendMmePacket.MMENTRY[1],SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],
  2437. SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5]);
  2438. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", SendMmePacket.MMENTRY[6]);
  2439. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out: 0x%x\n", SendMmePacket.MMENTRY[7]);
  2440. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE: 0x%x\n", SendMmePacket.MMENTRY[8]);
  2441. DEBUG_PRINTF_EVCOMM_DETAIL("M-FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2442. SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],SendMmePacket.MMENTRY[12],
  2443. SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14]);
  2444. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[15]);
  2445. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[16]);
  2446. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2447. SendMmePacket.MMENTRY[17],SendMmePacket.MMENTRY[18],SendMmePacket.MMENTRY[19],SendMmePacket.MMENTRY[20],
  2448. SendMmePacket.MMENTRY[21],SendMmePacket.MMENTRY[22],SendMmePacket.MMENTRY[23],SendMmePacket.MMENTRY[24]);
  2449. }
  2450. #endif
  2451. Update_V2G_Flow_Status(CM_SLAC_PARM_CONF);
  2452. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2453. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  2454. ftime(&SeqStartTime);
  2455. break;
  2456. }
  2457. #else
  2458. {
  2459. memcpy(EvMac, MmePacket->OSA, sizeof(EvMac));
  2460. memcpy(DestSocketAddress.sll_addr, MmePacket->OSA, sizeof(EvMac));
  2461. memcpy(SlacRunId,MmePacket->MMENTRY + 2, sizeof(SlacRunId));
  2462. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2463. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  2464. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2465. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2466. SendMmePacket.MMV = MmePacket->MMV;
  2467. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_PARM_CNF;
  2468. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2469. SendMmePacketSize = 0;
  2470. memset(SendMmePacket.MMENTRY, 0xFF, 6); //M-SOUND_TARGET(6-byte:0xFFFFFFFFFFFF): Fixed value indicating that M-Sounds to be sent as Ethernet broadcast
  2471. SendMmePacketSize += 6;
  2472. SendMmePacket.MMENTRY[SendMmePacketSize++] = C_EV_match_MNBC; //NUM_SOUNDS(0x0A): Number of M-Sounds to be transmitted by the EV GP Station during the SLAC process
  2473. SendMmePacket.MMENTRY[SendMmePacketSize++] = 6; //Time_Out(0x06): unit = 100ms
  2474. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01; //RESP_TYPE(0x01): Fixed value indicating Other GP station, 0x00 V HLE of the STA, 0x01 V Another GP STA, 0x02 V 0xFF V Reserved
  2475. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac, 6); //FORWARDING_STA(MAC Address of the EV HLE)
  2476. SendMmePacketSize += 6;
  2477. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00): 0x00(PEV-EVSE Association), 0x01-0xFF(Reserved)
  2478. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00): 0x00(No Security), 0x01(Public Key Signature), 0x02-0xFF(Reserved)
  2479. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SlacRunId, sizeof(SlacRunId)); //RunID (8-byte)
  2480. SendMmePacketSize += sizeof(SlacRunId);
  2481. SendMmePacketSize += 19; //the size before MMENTRY
  2482. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2483. {
  2484. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  2485. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2486. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  2487. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2488. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  2489. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  2490. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  2491. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  2492. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  2493. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_PARM_CNF ---\n");
  2494. DEBUG_PRINTF_EVCOMM_DETAIL("M-SOUND_TARGET: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2495. SendMmePacket.MMENTRY[0],SendMmePacket.MMENTRY[1],SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],
  2496. SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5]);
  2497. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", SendMmePacket.MMENTRY[6]);
  2498. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out: 0x%x\n", SendMmePacket.MMENTRY[7]);
  2499. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE: 0x%x\n", SendMmePacket.MMENTRY[8]);
  2500. DEBUG_PRINTF_EVCOMM_DETAIL("M-FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2501. SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],SendMmePacket.MMENTRY[12],
  2502. SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14]);
  2503. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[15]);
  2504. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[16]);
  2505. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2506. SendMmePacket.MMENTRY[17],SendMmePacket.MMENTRY[18],SendMmePacket.MMENTRY[19],SendMmePacket.MMENTRY[20],
  2507. SendMmePacket.MMENTRY[21],SendMmePacket.MMENTRY[22],SendMmePacket.MMENTRY[23],SendMmePacket.MMENTRY[24]);
  2508. }
  2509. #endif
  2510. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2511. Update_V2G_Flow_Status(CM_SLAC_PARM_CONF);
  2512. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  2513. ftime(&SeqStartTime);
  2514. counter = 0;
  2515. break;
  2516. }
  2517. #endif
  2518. }
  2519. case MMTYPE_CM_START_ATTEN_CHAR_IND:
  2520. {
  2521. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2522. {
  2523. SAVE_SYS_LOG_MSG_EVCOMM("[WARNING][SLAC][Rx]CM_START_ATTEN_CHAR_IND: ignored(timeup)");
  2524. break;
  2525. }
  2526. //Avoid Coupled CM_START_ATTEN_CHAR_IND
  2527. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2528. {
  2529. sprintf(buf_log_evcomm,
  2530. "[WARNING][SLAC][Rx]CM_START_ATTEN_CHAR_IND: ignored(coupled SLAC,%d)",
  2531. CheckConnectorPlugIn());
  2532. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2533. break;
  2534. }
  2535. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2536. {
  2537. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_START_ATTEN_CHAR_IND (counter : %d/3 ) ---\n",counter + 1);
  2538. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2539. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2540. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", MmePacket->MMENTRY[2]);
  2541. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out 0x%x\n", MmePacket->MMENTRY[3]);
  2542. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE 0x%x\n", MmePacket->MMENTRY[4]); //Fixed value (0x01) indicating other Green PHY station
  2543. DEBUG_PRINTF_EVCOMM_DETAIL("FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2544. MmePacket->MMENTRY[5],MmePacket->MMENTRY[6],MmePacket->MMENTRY[7],MmePacket->MMENTRY[8],
  2545. MmePacket->MMENTRY[9],MmePacket->MMENTRY[10]);
  2546. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2547. MmePacket->MMENTRY[11],MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],MmePacket->MMENTRY[14],
  2548. MmePacket->MMENTRY[15],MmePacket->MMENTRY[16],MmePacket->MMENTRY[17],MmePacket->MMENTRY[18]);
  2549. }
  2550. #endif
  2551. //New SLAC architecture designed by Joseph
  2552. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2553. {
  2554. EvMac_in = &MmePacket->OSA[0];
  2555. RunID_in = &MmePacket->MMENTRY[11];
  2556. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2557. if (idx >= 0)
  2558. {
  2559. Update_V2G_Flow_Status(CM_START_ATTEN_CHAR_IND);
  2560. //[TC_SECC_VTB_AttenuationCharacterization_013]
  2561. if (MmePacket->MMENTRY[0] != 0) //APPLICATION_TYPE must be 0x00(EV-EVSE Matching)
  2562. {
  2563. sprintf(buf_log_evcomm,
  2564. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]APPLICATION_TYPE(%d): invalid => ignore Req",
  2565. MmePacket->MMENTRY[0]);
  2566. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2567. break;
  2568. }
  2569. //[TC_SECC_VTB_AttenuationCharacterization_014]
  2570. if (MmePacket->MMENTRY[1] != 0) //SECURITY_TYPE must be 0x00(No Security)
  2571. {
  2572. sprintf(buf_log_evcomm,
  2573. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]SECURITY_TYPE(%d): invalid => ignore Req",
  2574. MmePacket->MMENTRY[1]);
  2575. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2576. break;
  2577. }
  2578. //[TC_SECC_VTB_AttenuationCharacterization_016]
  2579. if (MmePacket->MMENTRY[3] != 0x06) //Time_Out must be 0x06 , (600ms)
  2580. {
  2581. sprintf(buf_log_evcomm,
  2582. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]Time_Out(%d): invalid => ignore Req",
  2583. MmePacket->MMENTRY[3]);
  2584. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2585. break;
  2586. }
  2587. //[TC_SECC_VTB_AttenuationCharacterization_017]
  2588. if (MmePacket->MMENTRY[4] != 0x01) //RESP_TYPE must be 0x01(Send to another GP STA(EV))
  2589. {
  2590. sprintf(buf_log_evcomm,
  2591. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]RESP_TYPE(%d): invalid => ignore Req",
  2592. MmePacket->MMENTRY[4]);
  2593. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2594. break;
  2595. }
  2596. //[TC_SECC_VTB_AttenuationCharacterization_021]
  2597. //FORWARDING_STA: MAC Address of the EV HLE (station which the measurement results shall be sent to)
  2598. if (Array_Compare_Identity(EvMac_in, &MmePacket->MMENTRY[5], SLAC_EVMAC_LENGTH) == FALSE)
  2599. {
  2600. sprintf(buf_log_evcomm,
  2601. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]FORWARDING_STA(%02X:%02X:%02X:%02X:%02X:%02X): invalid => ignore Req",
  2602. MmePacket->MMENTRY[5], MmePacket->MMENTRY[6],
  2603. MmePacket->MMENTRY[7], MmePacket->MMENTRY[8],
  2604. MmePacket->MMENTRY[9], MmePacket->MMENTRY[10]);
  2605. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2606. SLAC_INFO.array[idx].StartAttenCharErr = TRUE;
  2607. break;
  2608. }
  2609. //Check RunID
  2610. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE)
  2611. {
  2612. SLAC_INFO.array[idx].MnbcSoundNum = MmePacket->MMENTRY[2];
  2613. SLAC_INFO.array[idx].StartAttenCharCnt++;
  2614. #if 0
  2615. sprintf(buf_log_evcomm,
  2616. "[SLAC][Rx]CM_START_ATTEN_CHAR_IND[%d]:%d-th",
  2617. (idx + 1),
  2618. SLAC_INFO.array[idx].StartAttenCharCnt);
  2619. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2620. #endif
  2621. if (SLAC_INFO.array[idx].StartAttenCharCnt == 1)
  2622. {
  2623. memset(SLAC_INFO.array[idx].AAG, 0, sizeof(SLAC_INFO.array[idx].AAG));
  2624. SLAC_INFO.array[idx].AttenProfileCnt = 0;
  2625. ftime(&SeqStartTime); //start TT_EVSE_match_MNBC
  2626. }
  2627. else if (SLAC_INFO.array[idx].StartAttenCharCnt >= 3)
  2628. {
  2629. sprintf(buf_log_evcomm,
  2630. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]counter(%d): unexpected",
  2631. SLAC_INFO.array[idx].StartAttenCharCnt);
  2632. }
  2633. else
  2634. {
  2635. //null
  2636. }
  2637. }
  2638. else
  2639. {
  2640. //This RunID is not matched with this EvMac,
  2641. //or this RunID is not found in DB.
  2642. sprintf(buf_log_evcomm,
  2643. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]EvMac-RunID: unmatched => ignore Req");
  2644. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2645. //Response: ignore
  2646. }
  2647. }
  2648. else
  2649. {
  2650. //this msg source is not in database
  2651. //ignore
  2652. }
  2653. break;
  2654. }
  2655. #else //Old SLAC architecture designed by Vern
  2656. {
  2657. MnbcSoundNum = MmePacket->MMENTRY[2];
  2658. Update_V2G_Flow_Status(CM_START_ATTEN_CHAR_IND);
  2659. counter++;
  2660. if(counter == 1)
  2661. {
  2662. memset(Aag, 0, sizeof(Aag));
  2663. AttenProfileCnt = 0;
  2664. ftime(&SeqStartTime); //start TT_EVSE_match_MNBC
  2665. }
  2666. else if(counter >= 3)
  2667. {
  2668. counter = 0;
  2669. }
  2670. break;
  2671. }
  2672. #endif
  2673. }
  2674. case MMTYPE_CM_MNBC_SOUND_IND:
  2675. {
  2676. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2677. {
  2678. SAVE_SYS_LOG_MSG_EVCOMM("[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND: ignored(timeup)");
  2679. break;
  2680. }
  2681. //Avoid Coupled CM_MNBC_SOUND_IND
  2682. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2683. {
  2684. sprintf(buf_log_evcomm,
  2685. "[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND: ignored(coupled SLAC,%d)",
  2686. CheckConnectorPlugIn());
  2687. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2688. break;
  2689. }
  2690. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == TRUE)
  2691. {
  2692. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_MNBC_SOUND_IND (counter : %d/%d) ---\n",counter + 1 , MnbcSoundNum);
  2693. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2694. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2695. DEBUG_PRINTF_EVCOMM_DETAIL("SenderID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2696. MmePacket->MMENTRY[2],MmePacket->MMENTRY[3],MmePacket->MMENTRY[4],MmePacket->MMENTRY[5],
  2697. MmePacket->MMENTRY[6],MmePacket->MMENTRY[7],MmePacket->MMENTRY[8],MmePacket->MMENTRY[9],
  2698. MmePacket->MMENTRY[10],MmePacket->MMENTRY[11],MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],
  2699. MmePacket->MMENTRY[14],MmePacket->MMENTRY[15],MmePacket->MMENTRY[16],MmePacket->MMENTRY[17],
  2700. MmePacket->MMENTRY[18]);
  2701. DEBUG_PRINTF_EVCOMM_DETAIL("Cnt: 0x%x\n", MmePacket->MMENTRY[19]);
  2702. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2703. MmePacket->MMENTRY[20],MmePacket->MMENTRY[21],MmePacket->MMENTRY[22],MmePacket->MMENTRY[23],
  2704. MmePacket->MMENTRY[24],MmePacket->MMENTRY[25],MmePacket->MMENTRY[26],MmePacket->MMENTRY[27]);
  2705. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2706. MmePacket->MMENTRY[28],MmePacket->MMENTRY[29],MmePacket->MMENTRY[30],MmePacket->MMENTRY[31],
  2707. MmePacket->MMENTRY[32],MmePacket->MMENTRY[33],MmePacket->MMENTRY[34],MmePacket->MMENTRY[35]);
  2708. DEBUG_PRINTF_EVCOMM_DETAIL("Rnd: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2709. MmePacket->MMENTRY[36],MmePacket->MMENTRY[37],MmePacket->MMENTRY[38],MmePacket->MMENTRY[39],
  2710. MmePacket->MMENTRY[40],MmePacket->MMENTRY[41],MmePacket->MMENTRY[42],MmePacket->MMENTRY[43],
  2711. MmePacket->MMENTRY[44],MmePacket->MMENTRY[45],MmePacket->MMENTRY[46],MmePacket->MMENTRY[47],
  2712. MmePacket->MMENTRY[48],MmePacket->MMENTRY[49],MmePacket->MMENTRY[50],MmePacket->MMENTRY[51]);
  2713. }
  2714. #endif
  2715. //New SLAC architecture designed by Joseph
  2716. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2717. {
  2718. EvMac_in = &MmePacket->OSA[0];
  2719. RunID_in = &MmePacket->MMENTRY[20];
  2720. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2721. if (idx >= 0)
  2722. {
  2723. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2724. //Check for RunID
  2725. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE)
  2726. {
  2727. SLAC_INFO.array[idx].MnbcSoundCnt++;
  2728. /*
  2729. sprintf(buf_log_evcomm,
  2730. "[SLAC][Rx]CM_MNBC_SOUND_IND[%d]:%d-th",
  2731. (idx + 1),
  2732. SLAC_INFO.array[idx].MnbcSoundCnt);
  2733. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2734. */
  2735. }
  2736. else
  2737. {
  2738. //RunID is not matched or does not exist.
  2739. sprintf(buf_log_evcomm,
  2740. "[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND]EvMac-RunID: unmatched");
  2741. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2742. }
  2743. }
  2744. else
  2745. {
  2746. //ignore
  2747. sprintf(buf_log_evcomm,
  2748. "[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND]EvMac does not exist");
  2749. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2750. }
  2751. break;
  2752. }
  2753. #else //Old SLAC architecture designed by Vern
  2754. {
  2755. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2756. counter++;
  2757. break;
  2758. }
  2759. #endif
  2760. }
  2761. case MMTYPE_CM_ATTEN_PROFILE_IND:
  2762. {
  2763. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2764. {
  2765. SAVE_SYS_LOG_MSG_EVCOMM("[WARNING][SLAC][Rx]CM_ATTEN_PROFILE_IND: ignore(timeup)");
  2766. break;
  2767. }
  2768. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == TRUE)
  2769. {
  2770. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_ATTEN_PROFILE_IND (counter : %d/%d) ---\n", counter, MnbcSoundNum);
  2771. DEBUG_PRINTF_EVCOMM_DETAIL("EV MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2772. MmePacket->MMENTRY[0], MmePacket->MMENTRY[1], MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2773. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5]);
  2774. DEBUG_PRINTF_EVCOMM_DETAIL("NumGroups: 0x%x\n", MmePacket->MMENTRY[6]); //NumGroups, Number of AAG Groups (ex: 0x3A = 58)
  2775. //NumGroups: Number of OFDM carrier groups used for the SLAC signal characterization.
  2776. //AAG[i]: Average Attenuation of Group i (i = 1 ~ 58)
  2777. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", MmePacket->MMENTRY[7]);
  2778. DEBUG_PRINTF_EVCOMM_DETAIL("AAG: \n");
  2779. for(Rtn = 0; Rtn < MmePacket->MMENTRY[6]; Rtn++)
  2780. {
  2781. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[8 + Rtn]);
  2782. }
  2783. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  2784. }
  2785. #endif
  2786. //New SLAC architecture designed by Joseph
  2787. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2788. {
  2789. EvMac_in = &MmePacket->MMENTRY[0]; //[CAUTION] The EvMac address is not &MmePacket->OSA[0]
  2790. //[CAUTION] There is no RunID information of CM_ATTEN_PROFILE_IND
  2791. // packet, which means SECC cannot use the RunID to
  2792. // distinguish those SLAC request with identical EvMac
  2793. // but with different RunID.
  2794. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2795. /*
  2796. printf("%d, %d, %d, %d\n",
  2797. idx,
  2798. SLAC_INFO.array[idx].AagGroupsNum,
  2799. MmePacket->MMENTRY[6],
  2800. SLAC_INFO.array[idx].AttenProfileCnt);
  2801. */
  2802. if (idx >= 0)
  2803. {
  2804. SLAC_INFO.array[idx].AttenProfileCnt++;
  2805. /*
  2806. sprintf(buf_log_evcomm,
  2807. "[SLAC][Rx]CM_ATTEN_PROFILE_IND[%d]:%d-th",
  2808. (idx + 1),
  2809. SLAC_INFO.array[idx].AttenProfileCnt);
  2810. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2811. */
  2812. //printf("%d, %d\n", SLAC_INFO.array[idx].AagGroupsNum, MmePacket->MMENTRY[6]);
  2813. SLAC_INFO.array[idx].AagGroupsNum = MmePacket->MMENTRY[6];
  2814. ////NumGroups, Number of AAG Groups (ex: 0x3A = 58)
  2815. for(Rtn = 0; Rtn < SLAC_INFO.array[idx].AagGroupsNum; Rtn++) //ex:58
  2816. {
  2817. SLAC_INFO.array[idx].AAG[Rtn] += MmePacket->MMENTRY[8 + Rtn];
  2818. }
  2819. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2820. break;
  2821. }
  2822. else
  2823. {
  2824. //The EvMac is not in the database
  2825. //ignore
  2826. sprintf(buf_log_evcomm,
  2827. "[SLAC][Rx][CM_ATTEN_PROFILE_IND]EvMac(%02X%02X%02X%02X%02X%02X): not exist => ignore",
  2828. EvMac_in[0], EvMac_in[1], EvMac_in[2], EvMac_in[3], EvMac_in[4], EvMac_in[5]);
  2829. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2830. break;
  2831. }
  2832. }
  2833. #else //Old SLAC architecture designed by Vern
  2834. {
  2835. AagGroupsNum = MmePacket->MMENTRY[6];
  2836. for(Rtn = 0; Rtn < MmePacket->MMENTRY[6]; Rtn++)
  2837. {
  2838. Aag[Rtn] += MmePacket->MMENTRY[8 + Rtn];
  2839. }
  2840. AttenProfileCnt++;
  2841. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2842. break;
  2843. }
  2844. #endif
  2845. }
  2846. case MMTYPE_CM_ATTEN_CHAR_RSP:
  2847. {
  2848. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2849. {
  2850. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_ATTEN_CHAR_RSP ---\n");
  2851. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2852. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2853. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2854. MmePacket->MMENTRY[2],MmePacket->MMENTRY[3],MmePacket->MMENTRY[4],MmePacket->MMENTRY[5],
  2855. MmePacket->MMENTRY[6],MmePacket->MMENTRY[7]);
  2856. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2857. MmePacket->MMENTRY[8],MmePacket->MMENTRY[9],MmePacket->MMENTRY[10],MmePacket->MMENTRY[11],
  2858. MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],MmePacket->MMENTRY[14],MmePacket->MMENTRY[15]);
  2859. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: \n");
  2860. for(Rtn = 0; Rtn < 17; Rtn++)
  2861. {
  2862. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[16 + Rtn]);
  2863. }
  2864. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  2865. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: \n");
  2866. for(Rtn = 0; Rtn < 17; Rtn++)
  2867. {
  2868. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[33 + Rtn]);
  2869. }
  2870. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  2871. DEBUG_PRINTF_EVCOMM_DETAIL("Result: 0x%x\n", MmePacket->MMENTRY[50]); //Fixed value of 0x00 indicates a successful SLAC process
  2872. }
  2873. #endif
  2874. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2875. {
  2876. //Check ODA (Destination Address)
  2877. if (Array_Compare_Identity(CsuMac, MmePacket->ODA, SLAC_EVSE_MAC_LENGTH) == FALSE)
  2878. {
  2879. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx][CM_ATTEN_CHAR_RSP]wrong ODA: ignore");
  2880. break;
  2881. }
  2882. EvMac_in = &MmePacket->OSA[0];
  2883. RunID_in = &MmePacket->MMENTRY[8];
  2884. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2885. //Check Parameters
  2886. if ((MmePacket->MMENTRY[0] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_005] applicationType must be 0x00
  2887. (MmePacket->MMENTRY[1] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_006] securityType must be 0x00
  2888. (SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in) < 0) || //[TC_SECC_VTB_AttenuationCharacterization_007] sourceAddress cannot not be all zero
  2889. (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_008] check for invalid runID
  2890. (Array_Check_All_Zero(&MmePacket->MMENTRY[16], 17) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_009] SourceID(17 bytes) must be all zero.
  2891. (Array_Check_All_Zero(&MmePacket->MMENTRY[33], 17) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_009] RESP_ID (17 bytes) must be all zero.
  2892. (MmePacket->MMENTRY[50] != 0) //Result: must be 0x00(Success)
  2893. )
  2894. {
  2895. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry++;
  2896. sprintf(buf_log_evcomm,
  2897. "[WARNING][SLAC][Rx]CM_ATTEN_CHAR_RSP:invalid para(%d,%d,%d,%d,%d) => %d-th retry",
  2898. MmePacket->MMENTRY[0], //applicationType must be 0x00
  2899. MmePacket->MMENTRY[1], //securityType must be 0x00
  2900. SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in),
  2901. SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in),
  2902. MmePacket->MMENTRY[50],
  2903. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry
  2904. );
  2905. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2906. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry <= 2) //limited to 2 retries
  2907. {
  2908. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2909. ftime(&SeqStartTime);
  2910. break;
  2911. }
  2912. else
  2913. {
  2914. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR][SLAC][Rx]CM_ATTEN_CHAR_RSP:invalid para => 2-retry fail => End_Process");
  2915. Update_V2G_Flow_Status(Other_Fault);
  2916. break;
  2917. }
  2918. }
  2919. else
  2920. {
  2921. //The CM_ATTEN_CHAR_IND is legal
  2922. SLAC_INFO.array[idx].AttenCharRspCnt++;
  2923. sprintf(buf_log_evcomm,
  2924. "[SLAC][Rx]CM_ATTEN_CHAR_RSP[%d]:%d-th",
  2925. (idx + 1),
  2926. SLAC_INFO.array[idx].AttenCharRspCnt);
  2927. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2928. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry = 0;
  2929. Update_V2G_Flow_Status(CM_ATTEN_CHAR_RSP);
  2930. ftime(&SeqStartTime);
  2931. break;
  2932. }
  2933. }
  2934. #else
  2935. {
  2936. //Check Parameters
  2937. if ((MmePacket->MMENTRY[0] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_005] applicationType must be 0x00
  2938. (MmePacket->MMENTRY[1] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_006] securityType must be 0x00
  2939. (Array_Compare_Identity(SLAC_INFO.array[0].EvMac, &MmePacket->MMENTRY[2], 6) == TRUE) || //[TC_SECC_VTB_AttenuationCharacterization_007] sourceAddress cannot not be all zero
  2940. (Array_Compare_Identity(SLAC_INFO.array[0].RunID, &MmePacket->MMENTRY[8], 8) == TRUE) //[TC_SECC_VTB_AttenuationCharacterization_008] check for invalid runID
  2941. )
  2942. {
  2943. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry++;
  2944. sprintf(buf_log_evcomm,
  2945. "[WARNING][SLAC][Rx]CM_ATTEN_CHAR_RSP: invalid parameters(%d-th)",
  2946. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  2947. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2948. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry <= 2) //limited to 2 retries
  2949. {
  2950. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2951. ftime(&SeqStartTime);
  2952. break;
  2953. }
  2954. else
  2955. {
  2956. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]CM_ATTEN_CHAR_RSP: invalid parameters => End_Process");
  2957. Update_V2G_Flow_Status(Other_Fault);
  2958. ftime(&SeqStartTime);
  2959. break;
  2960. }
  2961. }
  2962. else
  2963. {
  2964. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry = 0;
  2965. Update_V2G_Flow_Status(CM_ATTEN_CHAR_RSP);
  2966. ftime(&SeqStartTime);
  2967. break;
  2968. }
  2969. }
  2970. #endif
  2971. }
  2972. case MMTYPE_CM_VALIDATE_REQ: //BCB Toggle
  2973. {
  2974. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2975. {
  2976. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_VALIDATE_REQ ---\n");
  2977. DEBUG_PRINTF_EVCOMM_DETAIL("Signal Type: 0x%x\n", MmePacket->MMENTRY[0]); //Fixed value (0x00) to indicate ��PEV S2 toggles on control pilot line��
  2978. 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.
  2979. 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��.
  2980. }
  2981. #endif
  2982. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2983. {
  2984. counter = 0;
  2985. EvMac_in = &MmePacket->OSA[0];
  2986. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2987. if (idx >= 0)
  2988. {
  2989. Update_V2G_Flow_Status(CM_VALIDATE_CNF);
  2990. SLAC_INFO.array[idx].ValidateReqCnt++;
  2991. sprintf(buf_log_evcomm,
  2992. "[SLAC][Rx]CM_VALIDATE_REQ[%d]:%d-th",
  2993. (idx + 1),
  2994. SLAC_INFO.array[idx].ValidateReqCnt);
  2995. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2996. //[To-Do] Protection
  2997. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2998. memcpy(SendMmePacket.ODA, EvMac_in, SLAC_EVMAC_LENGTH);
  2999. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3000. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3001. SendMmePacket.MMV = 0x01;
  3002. SendMmePacket.MMTYPE = MMTYPE_CM_VALIDATE_CNF;
  3003. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3004. SendMmePacketSize = 0;
  3005. if(counter == 0)
  3006. {
  3007. //The First MMTYPE_CM_VALIDATE_REQ because Unicast
  3008. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SignalType(0x00): Fixed value to indicate "EV S2 toggles on control pilot line"
  3009. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //ToggleNum(0x00): Fixed value. In the first VALIDATE Request-Response exchange, the ToggleNum field shall be set to zero.
  3010. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  3011. SendMmePacket.MMENTRY[SendMmePacketSize++] = 1; //0x01 = Ready
  3012. #else
  3013. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  3014. #endif
  3015. }
  3016. else
  3017. {
  3018. //The Second MMTYPE_CM_VALIDATE_REQ because Broadcast
  3019. unsigned char PreStatus = 3;
  3020. unsigned char ToggleNum = 0;
  3021. ftime(&SeqStartTime);
  3022. while(1)
  3023. {
  3024. if((EVCOMM_SYS_INFO.CpState == 4) && (PreStatus == 3))
  3025. {
  3026. ToggleNum++;
  3027. PreStatus = 4;
  3028. }
  3029. else
  3030. {
  3031. PreStatus = 3;
  3032. }
  3033. ftime(&SeqEndTime);
  3034. if((DiffTimeb(SeqStartTime, SeqEndTime) >= (SendMmePacket.MMENTRY[1]*100 + 100))||(EVCOMM_SYS_INFO.CpState == 1))
  3035. {
  3036. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate "PEV S2 toggles on control pilot line"
  3037. SendMmePacket.MMENTRY[SendMmePacketSize++] = ToggleNum;
  3038. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  3039. if(ToggleNum==0)
  3040. SendMmePacket.MMENTRY[SendMmePacketSize++] = 3; //0x02 = Failure
  3041. else
  3042. SendMmePacket.MMENTRY[SendMmePacketSize++] = 2; //0x02 = Success
  3043. #else
  3044. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  3045. #endif
  3046. break;
  3047. }
  3048. }
  3049. }
  3050. SendMmePacketSize += 19; //the size before MMENTRY
  3051. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3052. ftime(&SeqStartTime);
  3053. }
  3054. else
  3055. {
  3056. //EvMac does not exist.
  3057. //ignore
  3058. }
  3059. break;
  3060. }
  3061. #else
  3062. {
  3063. counter = 0;
  3064. for(Rtn = 0; Rtn < 6; Rtn++)
  3065. {
  3066. if(MmePacket->ODA[Rtn] != CsuMac[Rtn])
  3067. {
  3068. counter = 1;
  3069. break;
  3070. }
  3071. }
  3072. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3073. memcpy(SendMmePacket.ODA, EvMac,6);
  3074. memcpy(SendMmePacket.OSA, CsuMac,6);
  3075. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3076. SendMmePacket.MMV = 0x01;
  3077. SendMmePacket.MMTYPE = MMTYPE_CM_VALIDATE_CNF;
  3078. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3079. SendMmePacketSize = 0;
  3080. if(counter == 0)
  3081. {
  3082. //The First MMTYPE_CM_VALIDATE_REQ because Unicast
  3083. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate PEV S2 toggles on control pilot line
  3084. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value In the first VALIDATE Request-Response exchange, the ToggleNum field shall be set to zero.
  3085. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  3086. SendMmePacket.MMENTRY[SendMmePacketSize++] = 1; //0x01 = Ready
  3087. #else
  3088. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  3089. #endif
  3090. }
  3091. else
  3092. {
  3093. //The Second MMTYPE_CM_VALIDATE_REQ because Broadcast
  3094. unsigned char PreStatus = 3, ToggleNum = 0;
  3095. ftime(&SeqStartTime);
  3096. while(1)
  3097. {
  3098. ftime(&SeqEndTime);
  3099. if((EVCOMM_SYS_INFO.CpState == 4) && (PreStatus == 3))
  3100. {
  3101. ToggleNum++;
  3102. PreStatus = 4;
  3103. }
  3104. else
  3105. {
  3106. PreStatus = 3;
  3107. }
  3108. if(DiffTimeb(SeqStartTime, SeqEndTime) >= (SendMmePacket.MMENTRY[1]*100 + 100))
  3109. {
  3110. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate ��PEV S2 toggles on control pilot line��
  3111. SendMmePacket.MMENTRY[SendMmePacketSize++] = ToggleNum;
  3112. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  3113. SendMmePacket.MMENTRY[SendMmePacketSize++] = 2; //0x02 = Success
  3114. #else
  3115. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  3116. #endif
  3117. break;
  3118. }
  3119. }
  3120. }
  3121. SendMmePacketSize += 19; //the size before MMENTRY
  3122. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3123. Update_V2G_Flow_Status(CM_VALIDATE_CNF);
  3124. ftime(&SeqStartTime);
  3125. break;
  3126. }
  3127. #endif
  3128. }
  3129. case MMTYPE_CM_SLAC_MATCH_REQ:
  3130. {
  3131. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3132. {
  3133. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SLAC_MATCH_REQ ---\n");
  3134. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  3135. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  3136. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", MmePacket->MMENTRY[2],MmePacket->MMENTRY[3]); //Fixed value (0x3E) for matching
  3137. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3138. for(Rtn=0; Rtn<17; Rtn++)
  3139. {
  3140. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[4+Rtn]);
  3141. }
  3142. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3143. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3144. for(Rtn=0; Rtn<6; Rtn++)
  3145. {
  3146. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[21+Rtn]);
  3147. }
  3148. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3149. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3150. for(Rtn=0; Rtn<17; Rtn++)
  3151. {
  3152. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[27+Rtn]);
  3153. }
  3154. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3155. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3156. for(Rtn=0; Rtn<6; Rtn++)
  3157. {
  3158. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[44+Rtn]);
  3159. }
  3160. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3161. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3162. for(Rtn=0; Rtn<8; Rtn++)
  3163. {
  3164. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[50+Rtn]);
  3165. }
  3166. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3167. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3168. for(Rtn=0; Rtn<8; Rtn++)
  3169. {
  3170. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[58+Rtn]);
  3171. }
  3172. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3173. }
  3174. #endif
  3175. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3176. {
  3177. //SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx]CM_SLAC_MATCH_REQ");
  3178. //Check ODA (Destination Address)
  3179. if (Array_Compare_Identity(CsuMac, MmePacket->ODA, SLAC_EVSE_MAC_LENGTH) == FALSE)
  3180. {
  3181. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx][CM_SLAC_MATCH_REQ]wrong ODA: ignore");
  3182. //break; //patch for DEKRA I2SE EVCC (another EVSE MAC Address protection comes as below.)
  3183. }
  3184. EvMac_in = &MmePacket->OSA[0];
  3185. RunID_in = &MmePacket->MMENTRY[50];
  3186. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  3187. if (idx >= 0)
  3188. {
  3189. Update_V2G_Flow_Status(CM_SLAC_MATCH_REQ);
  3190. SLAC_INFO.array[idx].MatchReqNum++;
  3191. sprintf(buf_log_evcomm,
  3192. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:%d-th",
  3193. (idx + 1),
  3194. SLAC_INFO.array[idx].MatchReqNum);
  3195. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3196. //[TC_SECC_VTB_CmSlacMatch_007] APPLICATION_TYPE must be 0x00(EV-EVSE Matching)
  3197. //[TC_SECC_VTB_CmSlacMatch_008]
  3198. if (MmePacket->MMENTRY[0] != 0)
  3199. {
  3200. sprintf(buf_log_evcomm,
  3201. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:wrong APPLICATION_TYPE(%d)",
  3202. (idx + 1),
  3203. MmePacket->MMENTRY[0]);
  3204. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3205. break;
  3206. }
  3207. //[TC_SECC_VTB_CmSlacMatch_009] SECURITY_TYPE must be 0x00(No Security)
  3208. //[TC_SECC_VTB_CmSlacMatch_010]
  3209. if (MmePacket->MMENTRY[1] != 0)
  3210. {
  3211. sprintf(buf_log_evcomm,
  3212. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:wrong SECURITY_TYPE(%d)",
  3213. (idx + 1),
  3214. MmePacket->MMENTRY[1]);
  3215. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3216. break;
  3217. }
  3218. //[TC_SECC_VTB_CmSlacMatch_011] MVFLength must be 0x3E(MatchVarField Length)
  3219. //[TC_SECC_VTB_CmSlacMatch_012]
  3220. if (MmePacket->MMENTRY[2] != 0x3E || MmePacket->MMENTRY[3] != 0x00)
  3221. {
  3222. sprintf(buf_log_evcomm,
  3223. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:wrong MVFLength(%d,%d)",
  3224. (idx + 1),
  3225. MmePacket->MMENTRY[2],
  3226. MmePacket->MMENTRY[3]);
  3227. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3228. break;
  3229. }
  3230. //[TC_SECC_VTB_CmSlacMatch_013] EV ID (muxt be all zero)
  3231. //[TC_SECC_VTB_CmSlacMatch_014]
  3232. if (Array_Check_All_Zero(&MmePacket->MMENTRY[4], 17) == FALSE)
  3233. {
  3234. sprintf(buf_log_evcomm,
  3235. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EV ID",
  3236. (idx + 1));
  3237. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3238. break;
  3239. }
  3240. //[TC_SECC_VTB_CmSlacMatch_015] EV MAC
  3241. //[TC_SECC_VTB_CmSlacMatch_016]
  3242. if (Array_Compare_Identity(EvMac_in, &MmePacket->MMENTRY[21], SLAC_EVMAC_LENGTH) == FALSE)
  3243. {
  3244. sprintf(buf_log_evcomm,
  3245. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EV MAC(%02X:%02X:%02X:%02X:%02X:%02X)",
  3246. (idx + 1),
  3247. MmePacket->MMENTRY[21], MmePacket->MMENTRY[22], MmePacket->MMENTRY[23],
  3248. MmePacket->MMENTRY[24], MmePacket->MMENTRY[25], MmePacket->MMENTRY[26]);
  3249. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3250. break;
  3251. }
  3252. //[TC_SECC_VTB_CmSlacMatch_017] EVSE ID should be all zero
  3253. //[TC_SECC_VTB_CmSlacMatch_018]
  3254. if (Array_Check_All_Zero(&MmePacket->MMENTRY[27], 17) == FALSE)
  3255. {
  3256. sprintf(buf_log_evcomm,
  3257. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EVSE ID",
  3258. (idx + 1));
  3259. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3260. break;
  3261. }
  3262. //[TC_SECC_VTB_CmSlacMatch_019] EVSE MAC
  3263. //[TC_SECC_VTB_CmSlacMatch_020]
  3264. if (Array_Compare_Identity(CsuMac, &MmePacket->MMENTRY[44], SLAC_EVSE_MAC_LENGTH) == FALSE)
  3265. {
  3266. sprintf(buf_log_evcomm,
  3267. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EVSE MAC(%02X:%02X:%02X:%02X:%02X:%02X)",
  3268. (idx + 1),
  3269. MmePacket->MMENTRY[44], MmePacket->MMENTRY[45], MmePacket->MMENTRY[46],
  3270. MmePacket->MMENTRY[47], MmePacket->MMENTRY[48], MmePacket->MMENTRY[49]);
  3271. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3272. break;
  3273. }
  3274. //[TC_SECC_VTB_CmSlacMatch_021]runID: Check RunID
  3275. //[TC_SECC_VTB_CmSlacMatch_022]
  3276. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE &&
  3277. (idx == 0)) //only setup a successful link establishment with the first SLAC Req instance
  3278. {
  3279. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3280. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  3281. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3282. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3283. SendMmePacket.MMV = MmePacket->MMV;
  3284. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_MATCH_CNF;
  3285. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3286. SendMmePacketSize = 0;
  3287. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //APPLICATION_TYPE: Fixed value (0x00: EV-EVSE matching)
  3288. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //SECURITY_TYPE: Fixed value (0x00: No Security)
  3289. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x56; //MVFLength: MatchVarField Length (Fixed value: 0x0056)
  3290. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //MVFLength: MatchVarField Length (Fixed value: 0x0056)
  3291. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //EV ID
  3292. SendMmePacketSize += 17;
  3293. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac_in, SLAC_EVMAC_LENGTH); //EV MAC
  3294. SendMmePacketSize += 6;
  3295. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //EVSE ID
  3296. SendMmePacketSize += 17;
  3297. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, CsuMac, 6); //EVSE MAC
  3298. SendMmePacketSize += 6;
  3299. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, RunID_in, SLAC_RUNID_LENGTH);
  3300. SendMmePacketSize += SLAC_RUNID_LENGTH;
  3301. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 8); //RSVD
  3302. SendMmePacketSize += 8;
  3303. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, Nid, sizeof(Nid)); //NID: Network ID given by the CCo(EVSE)
  3304. SendMmePacketSize += sizeof(Nid); //NID caculated from the random NMK that will be set.
  3305. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //RSVD
  3306. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, NewNmkKey, sizeof(NewNmkKey)); //NMK: Random value
  3307. SendMmePacketSize += sizeof(NewNmkKey); //NMK: Private NMK of the EVSE (random value)
  3308. SendMmePacketSize += 19; //the size before MMENTRY
  3309. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3310. {
  3311. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  3312. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3313. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3314. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3315. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3316. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3317. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3318. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3319. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3320. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_MATCH_CNF ---\n");
  3321. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3322. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3323. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3]);
  3324. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3325. for(Rtn=0; Rtn<17; Rtn++)
  3326. {
  3327. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[4+Rtn]);
  3328. }
  3329. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3330. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3331. for(Rtn=0; Rtn<6; Rtn++)
  3332. {
  3333. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[21+Rtn]);
  3334. }
  3335. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3336. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3337. for(Rtn=0; Rtn<17; Rtn++)
  3338. {
  3339. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[27+Rtn]);
  3340. }
  3341. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3342. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3343. for(Rtn=0; Rtn<6; Rtn++)
  3344. {
  3345. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[44+Rtn]);
  3346. }
  3347. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3348. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3349. for(Rtn=0; Rtn<8; Rtn++)
  3350. {
  3351. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[50+Rtn]);
  3352. }
  3353. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3354. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3355. for(Rtn=0; Rtn<8; Rtn++)
  3356. {
  3357. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[58+Rtn]);
  3358. }
  3359. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3360. DEBUG_PRINTF_EVCOMM_DETAIL("NID: \n");
  3361. for(Rtn=0; Rtn<7; Rtn++)
  3362. {
  3363. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[66+Rtn]);
  3364. }
  3365. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3366. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", SendMmePacket.MMENTRY[73]);
  3367. DEBUG_PRINTF_EVCOMM_DETAIL("NMK: \n");
  3368. for(Rtn=0; Rtn<16; Rtn++)
  3369. {
  3370. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[74+Rtn]);
  3371. }
  3372. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3373. }
  3374. #endif
  3375. Update_V2G_Flow_Status(CM_SLAC_MATCH_CNF);
  3376. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3377. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  3378. sprintf(buf_log_evcomm,
  3379. "[SLAC][Tx]CM_SLAC_MATCH_CNF[%d]",
  3380. (idx + 1));
  3381. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3382. ftime(&SeqStartTime);
  3383. }
  3384. else
  3385. {
  3386. //RunID does not match and it's not the first SLAC request
  3387. //Reset the SLAC database to embrace SLAC retry
  3388. SAVE_SYS_LOG_MSG_EVCOMM("[CM_SLAC_MATCH_REQ]No Real MATCH_REQ");
  3389. SLAC_DB_Reset();
  3390. }
  3391. }
  3392. else
  3393. {
  3394. //OSA(EvMac) does not exist
  3395. }
  3396. break;
  3397. }
  3398. #else
  3399. {
  3400. Update_V2G_Flow_Status(CM_SLAC_MATCH_REQ);
  3401. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx]CM_SLAC_MATCH_REQ");
  3402. memset(&SendMmePacket,0,sizeof(struct MmeHeader));
  3403. memcpy(SendMmePacket.ODA,MmePacket->OSA,6);
  3404. memcpy(SendMmePacket.OSA,CsuMac,6);
  3405. SendMmePacket.MTYPE=htons(EtherType_HomePlug);
  3406. SendMmePacket.MMV=MmePacket->MMV;
  3407. SendMmePacket.MMTYPE=MMTYPE_CM_SLAC_MATCH_CNF;
  3408. SendMmePacket.FMI[0]=SendMmePacket.FMI[1]=0;
  3409. SendMmePacketSize=0;
  3410. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x00) indicating PEV-EVSE matching
  3411. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x00) indicating No Security
  3412. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x56; //Fixed value (0x0056) for matching
  3413. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x0056) for matching
  3414. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,17); //PEV ID
  3415. SendMmePacketSize+=17;
  3416. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,EvMac,6);
  3417. SendMmePacketSize+=6;
  3418. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,17); //EVSE ID
  3419. SendMmePacketSize+=17;
  3420. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,CsuMac,6);
  3421. SendMmePacketSize+=6;
  3422. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,SlacRunId,sizeof(SlacRunId));
  3423. SendMmePacketSize+=sizeof(SlacRunId);
  3424. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,8); //RSVD
  3425. SendMmePacketSize+=8;
  3426. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,Nid,sizeof(Nid));
  3427. SendMmePacketSize+=sizeof(Nid);
  3428. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //RSVD
  3429. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,NewNmkKey,sizeof(NewNmkKey));
  3430. SendMmePacketSize+=sizeof(NewNmkKey);
  3431. SendMmePacketSize+=19; //the size before MMENTRY
  3432. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3433. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  3434. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3435. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3436. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3437. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3438. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3439. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3440. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3441. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3442. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_MATCH_CNF ---\n");
  3443. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3444. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3445. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3]);
  3446. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3447. for(Rtn=0; Rtn<17; Rtn++)
  3448. {
  3449. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[4+Rtn]);
  3450. }
  3451. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3452. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3453. for(Rtn=0; Rtn<6; Rtn++)
  3454. {
  3455. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[21+Rtn]);
  3456. }
  3457. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3458. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3459. for(Rtn=0; Rtn<17; Rtn++)
  3460. {
  3461. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[27+Rtn]);
  3462. }
  3463. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3464. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3465. for(Rtn=0; Rtn<6; Rtn++)
  3466. {
  3467. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[44+Rtn]);
  3468. }
  3469. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3470. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3471. for(Rtn=0; Rtn<8; Rtn++)
  3472. {
  3473. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[50+Rtn]);
  3474. }
  3475. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3476. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3477. for(Rtn=0; Rtn<8; Rtn++)
  3478. {
  3479. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[58+Rtn]);
  3480. }
  3481. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3482. DEBUG_PRINTF_EVCOMM_DETAIL("NID: \n");
  3483. for(Rtn=0; Rtn<7; Rtn++)
  3484. {
  3485. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[66+Rtn]);
  3486. }
  3487. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3488. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", SendMmePacket.MMENTRY[73]);
  3489. DEBUG_PRINTF_EVCOMM_DETAIL("NMK: \n");
  3490. for(Rtn=0; Rtn<16; Rtn++)
  3491. {
  3492. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[74+Rtn]);
  3493. }
  3494. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3495. #endif
  3496. Update_V2G_Flow_Status(CM_SLAC_MATCH_CNF);
  3497. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3498. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  3499. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Tx]CM_SLAC_MATCH_CNF");
  3500. ftime(&SeqStartTime);
  3501. break;
  3502. }
  3503. #endif
  3504. }
  3505. case MMTYPE_CM_AMP_MAP_REQ:
  3506. {
  3507. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3508. {
  3509. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SLAC_MATCH_REQ ---\n");
  3510. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  3511. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  3512. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", MmePacket->MMENTRY[2],MmePacket->MMENTRY[3]); //Fixed value (0x3E) for matching
  3513. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3514. for(Rtn=0; Rtn<17; Rtn++)
  3515. {
  3516. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[4+Rtn]);
  3517. }
  3518. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3519. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3520. for(Rtn=0; Rtn<6; Rtn++)
  3521. {
  3522. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[21+Rtn]);
  3523. }
  3524. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3525. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3526. for(Rtn=0; Rtn<17; Rtn++)
  3527. {
  3528. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[27+Rtn]);
  3529. }
  3530. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3531. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3532. for(Rtn=0; Rtn<6; Rtn++)
  3533. {
  3534. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[44+Rtn]);
  3535. }
  3536. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3537. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3538. for(Rtn=0; Rtn<8; Rtn++)
  3539. {
  3540. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[50+Rtn]);
  3541. }
  3542. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3543. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3544. for(Rtn=0; Rtn<8; Rtn++)
  3545. {
  3546. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[58+Rtn]);
  3547. }
  3548. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3549. }
  3550. #endif
  3551. //Check ODA (Destination Address)
  3552. if (Array_Compare_Identity(CsuMac, MmePacket->ODA, SLAC_EVSE_MAC_LENGTH) == FALSE)
  3553. {
  3554. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx][CM_AMP_MAP_REQ]wrong ODA: ignore");
  3555. //break; //patch for DEKRA I2SE EVCC (another EVSE MAC Address protection comes as below.)
  3556. }
  3557. EvMac_in = &MmePacket->OSA[0];
  3558. RunID_in = &MmePacket->MMENTRY[50];
  3559. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  3560. if (idx >= 0)
  3561. {
  3562. Update_V2G_Flow_Status(CM_AMP_MAP_REQ);
  3563. SLAC_INFO.array[idx].MatchReqNum++;
  3564. sprintf(buf_log_evcomm,
  3565. "[SLAC][Rx]CM_AMP_MAP_REQ[%d]:%d-th",
  3566. (idx + 1),
  3567. SLAC_INFO.array[idx].MatchReqNum);
  3568. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3569. //[TC_SECC_VTB_CmSlacMatch_007] APPLICATION_TYPE must be 0x00(EV-EVSE Matching)
  3570. //[TC_SECC_VTB_CmSlacMatch_008]
  3571. if ((MmePacket->MMENTRY[0] != 0x3A)||(MmePacket->MMENTRY[1] != 0))
  3572. {
  3573. sprintf(buf_log_evcomm,
  3574. "[SLAC][Rx]CM_AMP_MAP_REQ[%d]:wrong AMLEN(%d)",
  3575. (idx + 1),
  3576. MmePacket->MMENTRY[0]);
  3577. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3578. break;
  3579. }
  3580. //[TC_SECC_VTB_CmSlacMatch_021]runID: Check RunID
  3581. //[TC_SECC_VTB_CmSlacMatch_022]
  3582. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE &&
  3583. (idx == 0)) //only setup a successful link establishment with the first SLAC Req instance
  3584. {
  3585. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3586. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  3587. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3588. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3589. SendMmePacket.MMV = MmePacket->MMV;
  3590. SendMmePacket.MMTYPE = MMTYPE_CM_AMP_MAP_CNF;
  3591. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3592. SendMmePacketSize = 0;
  3593. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //success
  3594. Update_V2G_Flow_Status(CM_AMP_MAP_CNF);
  3595. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3596. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  3597. sprintf(buf_log_evcomm,
  3598. "[SLAC][Tx]CM_AMP_MAP_CNF[%d]",
  3599. (idx + 1));
  3600. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3601. ftime(&SeqStartTime);
  3602. }
  3603. else
  3604. {
  3605. //RunID does not match and it's not the first SLAC request
  3606. //Reset the SLAC database to embrace SLAC retry
  3607. SAVE_SYS_LOG_MSG_EVCOMM("[CM_SLAC_MATCH_REQ]No Real MATCH_REQ");
  3608. SLAC_DB_Reset();
  3609. }
  3610. }
  3611. else
  3612. {
  3613. //OSA(EvMac) does not exist
  3614. }
  3615. break;
  3616. }
  3617. case MMTYPE_VENDOR_VS_HOST_ACTION:
  3618. {
  3619. struct QcaVendorMmeHeader *RecvPacket;
  3620. RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
  3621. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_VS_HOST_ACTION ---\n");
  3622. switch (RecvPacket->MBODY[0])
  3623. {
  3624. case 0x00:
  3625. //Loader (Device Softloader or Bootloader) ready
  3626. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Loader Ready\n");
  3627. break;
  3628. case 0x01:
  3629. //Firmware Upgrade Ready
  3630. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Firmware Upgrade Ready\n");
  3631. break;
  3632. case 0x02:
  3633. //PIB Update Ready
  3634. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: PIB Update Ready\n");
  3635. break;
  3636. case 0x03:
  3637. //Firmware Upgrade and PIB Update ready
  3638. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Firmware Upgrade and PIB Update ready\n");
  3639. break;
  3640. case 0x04:
  3641. //Loader (Bootloader) ready to receive SDRAM configuration.
  3642. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Loader ready to receive SDRAM configuration\n");
  3643. break;
  3644. case 0x05:
  3645. //Reset to Factory Defaults.
  3646. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Reset to Factory Defaults\n");
  3647. break;
  3648. default:
  3649. //Reserved
  3650. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Reserved\n");
  3651. break;
  3652. }
  3653. break;
  3654. }
  3655. case MMTYPE_VENDOR_ATTEN_CHAR:
  3656. {
  3657. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_ATTEN_CHAR ---\n");
  3658. break;
  3659. }
  3660. case MMTYPE_VENDOR_VS_NW_INFO_CNF:
  3661. {
  3662. struct QcaVendorMmeHeader *RecvPacket;
  3663. RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
  3664. memcpy(QcaMac, RecvPacket->OSA, 6);
  3665. sprintf(buf_log_evcomm,
  3666. "[QCA7K][Rx][VENDOR_VS_NW_INFO_CNF]Got QCA7K MacAddr:%02X:%02X:%02X:%02X:%02X:%02X (comm:OK)",
  3667. QcaMac[0], QcaMac[1], QcaMac[2], QcaMac[3], QcaMac[4], QcaMac[5]);
  3668. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3669. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_VS_NW_INFO_CNF ---\n");
  3670. DEBUG_PRINTF_EVCOMM_DETAIL("QcaMac: %02x:%02x:%02x:%02x:%02x:%02x\n",
  3671. QcaMac[0],
  3672. QcaMac[1],
  3673. QcaMac[2],
  3674. QcaMac[3],
  3675. QcaMac[4],
  3676. QcaMac[5]);
  3677. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  3678. ftime(&SeqStartTime);
  3679. break;
  3680. }
  3681. case MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF:
  3682. {
  3683. struct QcaVendorMmeHeader *RecvPacket;
  3684. RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
  3685. if(RecvPacket->MBODY[1]==0)
  3686. {
  3687. //PLC disconnected
  3688. sprintf(buf_log_evcomm,
  3689. "[QCA7K][Rx][MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF]Got PLC Link Status:%d",
  3690. RecvPacket->MBODY[1]);
  3691. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3692. Update_V2G_Flow_Status(Other_Fault);
  3693. }
  3694. else
  3695. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  3696. ftime(&SeqStartTime);
  3697. break;
  3698. }
  3699. default:
  3700. {
  3701. break;
  3702. }
  3703. }
  3704. }
  3705. /*===========================================================================
  3706. FUNCTION: SlacComm
  3707. DESCRIPTION:
  3708. PRE-CONDITION:
  3709. INPUT:
  3710. OUTPUT:
  3711. GLOBAL VARIABLES:
  3712. =============================================================================*/
  3713. int SlacComm()
  3714. {
  3715. static unsigned char qca7k_comm_retry = 0;
  3716. unsigned char *EvMac_in;
  3717. unsigned char *RunID_in;
  3718. double t_diff = 0;
  3719. int packet_size = 0;
  3720. int count = 0;
  3721. int idx = 0;
  3722. int i = 0;
  3723. if(RawSock >= 0)
  3724. {
  3725. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  3726. packet_size = recvfrom(RawSock, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, 0, NULL, NULL);
  3727. if(packet_size > 0)
  3728. {
  3729. /*#ifdef Debug
  3730. DEBUG_PRINTF_EVCOMM_DETAIL("Raw Data: ");
  3731. for(count=0;count<packet_size;count++)
  3732. DEBUG_PRINTF_EVCOMM_DETAIL("0x%x, ",V2gtpMsgRxBuf[count]);
  3733. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3734. #endif*/
  3735. MmeProcess(V2gtpMsgRxBuf, packet_size);
  3736. }
  3737. }
  3738. switch(Check_V2G_Flow_Status())
  3739. {
  3740. case IDLE:
  3741. {
  3742. if(RawSock < 0)
  3743. {
  3744. RawSock = socket(PF_PACKET, SOCK_RAW, htons(EtherType_HomePlug));
  3745. sprintf(buf_log_evcomm, "[RawSock]opened(%d)", RawSock);
  3746. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3747. if(RawSock == -1)
  3748. {
  3749. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm:Failed to create socket");
  3750. Update_V2G_Flow_Status(Other_Fault);
  3751. return -1;
  3752. }
  3753. ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp=RawSock;
  3754. if (setsockopt(RawSock, SOL_SOCKET, SO_BINDTODEVICE, QcaInterface, 4) < 0)
  3755. {
  3756. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm:Set SO_BINDTODEVICE NG");
  3757. Update_V2G_Flow_Status(Other_Fault);
  3758. return -1;
  3759. }
  3760. struct timeval tv;
  3761. tv.tv_sec = 0;
  3762. tv.tv_usec = 100000; //100ms (Rx timeout)
  3763. if (setsockopt(RawSock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  3764. {
  3765. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm:Set SO_RCVTIMEO NG");
  3766. Update_V2G_Flow_Status(Other_Fault);
  3767. return -1;
  3768. }
  3769. tv.tv_usec = 100000; //100ms (Tx timeout)
  3770. if (setsockopt(RawSock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  3771. {
  3772. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm:Set SO_SNDTIMEO NG");
  3773. Update_V2G_Flow_Status(Other_Fault);
  3774. return -1;
  3775. }
  3776. memset(&Req, 0, sizeof(struct ifreq));
  3777. strcpy( (char*)Req.ifr_name, QcaInterface);
  3778. if (ioctl(RawSock, SIOCGIFINDEX, &Req) < 0)
  3779. {
  3780. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: ioctl NG");
  3781. Update_V2G_Flow_Status(Other_Fault);
  3782. return -1;
  3783. }
  3784. memset( &DestSocketAddress, 0, sizeof(struct sockaddr_ll));
  3785. DestSocketAddress.sll_ifindex = Req.ifr_ifindex;
  3786. DestSocketAddress.sll_halen = ETH_ALEN;
  3787. PwmStartTime = 0;
  3788. EVCOMM_SYS_INFO.QCA7K_SetKeyDone = FALSE;
  3789. SAVE_SYS_LOG_MSG_EVCOMM("[QCA7K]connecting...");
  3790. //Get QCA7K MAC address
  3791. GetQca7kMac();
  3792. ftime(&SeqStartTime);
  3793. break;
  3794. }
  3795. else //RawSock: opened
  3796. {
  3797. if(EVCOMM_SYS_INFO.QCA7K_SetKeyDone == FALSE)
  3798. {
  3799. ftime(&SeqEndTime);
  3800. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3801. if (t_diff > V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD) //3 secs
  3802. {
  3803. qca7k_comm_retry++;
  3804. sprintf(buf_log_evcomm,
  3805. "[QCA7K]re-try connecting...(%.02lf/%dms)",
  3806. t_diff,
  3807. V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD);
  3808. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3809. GetQca7kMac(); //re-send req
  3810. ftime(&SeqStartTime);
  3811. break;
  3812. }
  3813. else
  3814. {
  3815. //null
  3816. }
  3817. //Retry by 3 times
  3818. if (qca7k_comm_retry >= 3)
  3819. {
  3820. sprintf(buf_log_evcomm,
  3821. "[QCA7K][Error]comm: fail (retry by %d times)",
  3822. qca7k_comm_retry);
  3823. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3824. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3825. //CCS_SECCC_TIMEOUT_QCA7000_COMM (023892): The firmware code of QCA7000 may not be installed, yet
  3826. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3827. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3828. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3829. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3830. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  3831. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  3832. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  3833. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3834. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  3835. Update_V2G_Flow_Status(Sequence_Timeout);
  3836. qca7k_comm_retry = 0;
  3837. break;
  3838. }
  3839. }
  3840. else //RawSock: opened; Set Key: DONE
  3841. {
  3842. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  3843. if((CheckConnectorPlugIn() == TRUE) && (ShmInternalComm->ChargingPermission >=1))
  3844. {
  3845. if(PwmStartTime <= 0)
  3846. {
  3847. //Sniffer_Tcpdump(ENABLE);
  3848. //#if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  3849. //sleep(1); //wait for tcpdump to be ready.
  3850. //#endif
  3851. SwitchCpStateE(DISABLE);
  3852. OutputCpPwmDuty(5);
  3853. PwmStartTime = time(NULL);
  3854. }
  3855. else
  3856. {
  3857. if((time(NULL) - PwmStartTime) > TT_EVSE_SLAC_init)
  3858. {
  3859. sprintf(buf_log_evcomm,
  3860. "SlacComm: Wait CM_SLAC_PARM_REQ Timeout - TT_EVSE_SLAC_init, NowTime(%d)-PwmStartTime(%d)>%d (sec)",
  3861. time(NULL),
  3862. PwmStartTime,
  3863. TT_EVSE_SLAC_init);
  3864. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3865. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3866. //CCS_SECC_TIMEOUT_SLAC_TT_EVSE_SLAC_init (023809)
  3867. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3868. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3869. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3870. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3871. ShmStatusCodeData->PresentStatusCode[0][4] = 0;
  3872. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  3873. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  3874. Update_V2G_Flow_Status(Sequence_Timeout);
  3875. PwmStartTime = 0;
  3876. return -1;
  3877. }
  3878. else
  3879. {
  3880. //waiting for CM_SLAC_PARM_REQ
  3881. }
  3882. }
  3883. }
  3884. else
  3885. {
  3886. PwmStartTime = 0;
  3887. }
  3888. }
  3889. }
  3890. break;
  3891. }
  3892. case CM_SET_KEY_REQ: //13
  3893. {
  3894. //CM_SET_KEY_REQ
  3895. //SAVE_SYS_LOG_MSG_EVCOMM("[QCA7K][Rx]CM_SET_KEY_REQ");
  3896. ftime(&SeqEndTime);
  3897. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3898. if (t_diff > V2G_SECC_QCA7000_COMM_TIMEOUT) //10 seconds
  3899. {
  3900. sprintf(buf_log_evcomm,
  3901. "[QCA7K]Failed on SetKey => End_Process (%.02lf/%dms)",
  3902. t_diff,
  3903. V2G_SECC_QCA7000_COMM_TIMEOUT);
  3904. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3905. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3906. //CCS_SECCC_TIMEOUT_QCA7000_COMM (023892): The firmware code of QCA7000 may not be installed, yet
  3907. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3908. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3909. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3910. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3911. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  3912. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  3913. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  3914. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3915. Update_V2G_Flow_Status(Sequence_Timeout);
  3916. }
  3917. else if (t_diff > V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD) //2 seconds
  3918. {
  3919. sprintf(buf_log_evcomm,
  3920. "[QCA7K]SetKey: proceed (%.02lf/%dms)",
  3921. t_diff,
  3922. V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD);
  3923. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3924. SendSetKey();
  3925. ftime(&SeqStartTime);
  3926. }
  3927. else
  3928. {
  3929. //null
  3930. }
  3931. break;
  3932. }
  3933. case CM_SET_KEY_CNF: //14
  3934. {
  3935. sprintf(buf_log_evcomm,
  3936. "[SECCReady]Wait: plugin(%d), matached(%d), permission(%d)...",
  3937. CheckConnectorPlugIn(),
  3938. CSUCOMMDC_TASK_FLAG.matched,
  3939. ShmInternalComm->ChargingPermission
  3940. );
  3941. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3942. EVCOMM_SYS_INFO.QCA7K_SetKeyDone = TRUE;
  3943. PwmStartTime = 0;
  3944. Update_V2G_Flow_Status(IDLE);
  3945. break;
  3946. }
  3947. case CM_SLAC_PARM_CONF:
  3948. {
  3949. ftime(&SeqEndTime);
  3950. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_sequence)
  3951. {
  3952. sprintf(buf_log_evcomm,
  3953. "SlacComm: Wait CM_START_ATTEN_CHAR_IND Timeout - TT_match_sequence (%.02lf of %dms)",
  3954. DiffTimeb(SeqStartTime, SeqEndTime),
  3955. TT_match_sequence);
  3956. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3957. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3958. //CCS_SECC_TIMEOUT_CM_START_ATTEN_CHAR_IND (023811):
  3959. //[Possible Reason] CCS Board image might not be updated properly. The 2nd reboot process is not finished.
  3960. //[Verification Method] By tying reboot command to the terminal and see if it could be executed immediately.
  3961. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3962. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3963. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3964. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3965. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  3966. ShmStatusCodeData->PresentStatusCode[0][5] = 1;
  3967. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  3968. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3969. Update_V2G_Flow_Status(Sequence_Timeout);
  3970. return -1;
  3971. }
  3972. break;
  3973. }
  3974. case CM_START_ATTEN_CHAR_IND:
  3975. {
  3976. ftime(&SeqEndTime);
  3977. if(DiffTimeb(SeqStartTime, SeqEndTime) > (TP_EV_batch_msg_interval)) //one more time interval for tolerance
  3978. {
  3979. sprintf(buf_log_evcomm,
  3980. "SlacComm: Wait CM_MNBC_SOUND_IND Timeout - TP_EV_batch_msg_interval (%.02lf of %dms)",
  3981. DiffTimeb(SeqStartTime, SeqEndTime),
  3982. TP_EV_batch_msg_interval);
  3983. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3984. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3985. //CCS_SECC_TIMEOUT_SLAC_CM_MNBC_SOUND_IND (023818):
  3986. //[Possible Reason] CCS Board image might not be updated properly. The 2nd reboot process is not finished.
  3987. //[Verification Method] By tying reboot command to the terminal and see if it could be executed immediately.
  3988. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3989. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3990. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3991. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3992. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  3993. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  3994. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  3995. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3996. Update_V2G_Flow_Status(Sequence_Timeout);
  3997. return -1;
  3998. }
  3999. break;
  4000. }
  4001. case CM_MNBC_SOUND_IND:
  4002. {
  4003. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  4004. {
  4005. ftime(&SeqEndTime);
  4006. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  4007. //printf("time:%.02lf, profilNum:%d\n",DiffTimeb(SeqStartTime, SeqEndTime),AttenProfileCnt); //added by Vern
  4008. if(t_diff > TT_EVSE_match_MNBC ||
  4009. (SLAC_INFO.array[0].AttenProfileCnt >= SLAC_INFO.array[0].MnbcSoundNum) ||
  4010. (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)) //TC_SECC_VTB_AttenuationCharacterization_003
  4011. {
  4012. //Wait for other SLAC Req sets
  4013. if ((SLAC_INFO.arrayLen >= 2) &&
  4014. (t_diff < TT_EVSE_match_MNBC) &&
  4015. (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry == 0)) //not a retry
  4016. {
  4017. break;
  4018. }
  4019. //Check if it is a timeup response
  4020. if (t_diff > TT_EVSE_match_MNBC)
  4021. {
  4022. sprintf(buf_log_evcomm,
  4023. "[WARNING][SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: timeup(%.2f/%dms) => send",
  4024. (i + 1),
  4025. t_diff,
  4026. TT_EVSE_match_MNBC);
  4027. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4028. }
  4029. //Sending all CM_ATTEN_CHAR_IND according to all corresponding SLAC Req sets
  4030. for (i = 0; i < SLAC_INFO.arrayLen; i++)
  4031. {
  4032. if ((SLAC_INFO.array[i].AttenProfileCnt == 0) ||
  4033. (SLAC_INFO.array[i].AagGroupsNum == 0) ||
  4034. (SLAC_INFO.array[i].StartAttenCharCnt == 0) ||
  4035. (SLAC_INFO.array[i].MnbcSoundNum != 10) || //received in CM_START_ATTEN_CHAR_IND
  4036. (SLAC_INFO.array[i].StartAttenCharErr == TRUE)
  4037. )
  4038. {
  4039. //Ignoring those SLAC request sets without sending CM_MNBC_SOUND_IND(CM_ATTEN_PROFILE_IND)
  4040. sprintf(buf_log_evcomm,
  4041. "[WARNING][SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: para err(%d,%d,%d,%d,%d) => canceled",
  4042. (i + 1),
  4043. SLAC_INFO.array[i].AttenProfileCnt,
  4044. SLAC_INFO.array[i].AagGroupsNum,
  4045. SLAC_INFO.array[i].StartAttenCharCnt,
  4046. SLAC_INFO.array[i].MnbcSoundNum,
  4047. SLAC_INFO.array[i].StartAttenCharErr);
  4048. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4049. continue;
  4050. }
  4051. //In CM_ATTEN_CHAR_IND retry process, here only re-send this message according to the 1st coming SLAC request
  4052. if ((EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0) && (i != 0))
  4053. {
  4054. sprintf(buf_log_evcomm,
  4055. "[NOTE][SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: canceled",
  4056. (i + 1));
  4057. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4058. break;
  4059. }
  4060. EvMac_in = SLAC_INFO.array[i].EvMac;
  4061. RunID_in = SLAC_INFO.array[i].RunID;
  4062. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  4063. memcpy(SendMmePacket.ODA, EvMac_in, SLAC_EVMAC_LENGTH);
  4064. memcpy(SendMmePacket.OSA, CsuMac, 6);
  4065. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  4066. SendMmePacket.MMV = 0x01;
  4067. SendMmePacket.MMTYPE = MMTYPE_CM_ATTEN_CHAR_IND;
  4068. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  4069. SendMmePacketSize = 0;
  4070. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00: EV-EVSE Matching)
  4071. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00: No Security)
  4072. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac_in, SLAC_EVMAC_LENGTH); //SOURCE_ADDRESS, MAC address of the EV Host
  4073. SendMmePacketSize += SLAC_EVMAC_LENGTH;
  4074. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, RunID_in, SLAC_RUNID_LENGTH);
  4075. SendMmePacketSize += SLAC_RUNID_LENGTH;
  4076. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //SOURCE_ID(0x00)
  4077. SendMmePacketSize += 17;
  4078. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //RESP_ID(0x00)
  4079. SendMmePacketSize += 17;
  4080. SendMmePacket.MMENTRY[SendMmePacketSize++] = SLAC_INFO.array[i].AttenProfileCnt; //NumSounds: Number of M-Sounds used for generation of the ATTEN_PROFILE
  4081. SendMmePacket.MMENTRY[SendMmePacketSize++] = SLAC_INFO.array[i].AagGroupsNum; //NumGroups
  4082. for(count = 0; count < SLAC_INFO.array[i].AagGroupsNum; count++)
  4083. {
  4084. unsigned char TmpAag;
  4085. TmpAag = ((SLAC_INFO.array[i].AAG[count] / SLAC_INFO.array[i].AttenProfileCnt) & 0xFF);
  4086. SLAC_INFO.array[i].AAG_quality_ori += (float) TmpAag; //original signal quality
  4087. #if (SUDO_PSD_PARAMETER_MECHANISM == ENABLE) //default: ENABLE
  4088. #if 1
  4089. //TC_SECC_VTB_AttenuationCharacterization_019
  4090. TmpAag = TmpAag >> 1; //new method proposed by Joseph (divided by 2)
  4091. #else
  4092. if(TmpAag >= 39) //original method proposed by Vern
  4093. {
  4094. TmpAag = 37;
  4095. }
  4096. #endif
  4097. #endif
  4098. SendMmePacket.MMENTRY[SendMmePacketSize++] = TmpAag;
  4099. SLAC_INFO.array[i].AAG_quality_refined += (float) TmpAag; //refined signal quality
  4100. }
  4101. SendMmePacketSize += 19; //the size before MMENTRY
  4102. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == TRUE)
  4103. {
  4104. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Send MME Packet *****\n");
  4105. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  4106. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  4107. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  4108. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  4109. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  4110. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  4111. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  4112. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  4113. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_ATTEN_CHAR_IND ---\n");
  4114. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  4115. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  4116. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  4117. SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5],
  4118. SendMmePacket.MMENTRY[6],SendMmePacket.MMENTRY[7]);
  4119. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  4120. SendMmePacket.MMENTRY[8],SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],
  4121. SendMmePacket.MMENTRY[12],SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14],SendMmePacket.MMENTRY[15]);
  4122. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: \n");
  4123. for(count=0; count<17; count++)
  4124. {
  4125. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[16+count]);
  4126. }
  4127. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  4128. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: \n");
  4129. for(count=0; count<17; count++)
  4130. {
  4131. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[33+count]);
  4132. }
  4133. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  4134. DEBUG_PRINTF_EVCOMM_DETAIL("NumSounds: 0x%x\n", SendMmePacket.MMENTRY[50]);
  4135. DEBUG_PRINTF_EVCOMM_DETAIL("ATTEN_PROFILE: \n");
  4136. for(count=0; count<AagGroupsNum; count++)
  4137. {
  4138. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[51+count]);
  4139. }
  4140. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  4141. }
  4142. #endif
  4143. count = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  4144. SLAC_INFO.array[i].AAG_quality_ori /= SLAC_INFO.array[i].AagGroupsNum;
  4145. SLAC_INFO.array[i].AAG_quality_refined /= SLAC_INFO.array[i].AagGroupsNum;
  4146. //Print log if this CM_ATTEN_CHAR_IND belongs to RETRY Tx message.
  4147. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)
  4148. {
  4149. sprintf(buf_log_evcomm,
  4150. "[SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: %d-th resend (Q=%.2f/%.2f)(%d/%d)",
  4151. (i + 1),
  4152. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry,
  4153. SLAC_INFO.array[i].AAG_quality_refined,
  4154. SLAC_INFO.array[i].AAG_quality_ori,
  4155. SLAC_INFO.array[i].AttenProfileCnt,
  4156. SLAC_INFO.array[i].MnbcSoundNum);
  4157. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4158. }
  4159. else if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry == 0)
  4160. {
  4161. sprintf(buf_log_evcomm,
  4162. "[SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: Q=%.2f/%.2f(%d/%d)",
  4163. (i + 1),
  4164. SLAC_INFO.array[i].AAG_quality_refined,
  4165. SLAC_INFO.array[i].AAG_quality_ori,
  4166. SLAC_INFO.array[i].AttenProfileCnt,
  4167. SLAC_INFO.array[i].MnbcSoundNum);
  4168. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4169. }
  4170. else
  4171. {
  4172. sprintf(buf_log_evcomm,
  4173. "[SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: unexpected CM_ATTEN_CHAR_IND_retry(%d))",
  4174. i,
  4175. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  4176. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4177. }
  4178. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n", SendMmePacketSize,count);
  4179. } //end of for loop
  4180. Update_V2G_Flow_Status(CM_ATTEN_CHAR_IND);
  4181. ftime(&SeqStartTime);
  4182. }
  4183. break;
  4184. }
  4185. #else
  4186. {
  4187. ftime(&SeqEndTime);
  4188. //printf("time:%.02lf, profilNum:%d\n",DiffTimeb(SeqStartTime, SeqEndTime),AttenProfileCnt); //added by Vern
  4189. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_EVSE_match_MNBC || (AttenProfileCnt >= MnbcSoundNum) || (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0))
  4190. {
  4191. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  4192. memcpy(SendMmePacket.ODA, EvMac, 6);
  4193. memcpy(SendMmePacket.OSA, CsuMac, 6);
  4194. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  4195. SendMmePacket.MMV = 0x01;
  4196. SendMmePacket.MMTYPE = MMTYPE_CM_ATTEN_CHAR_IND;
  4197. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  4198. SendMmePacketSize = 0;
  4199. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00: EV-EVSE Matching)
  4200. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00: No Security)
  4201. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac, 6); //SOURCE_ADDRESS, MAC address of the EV Host
  4202. SendMmePacketSize += 6;
  4203. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize, SlacRunId, sizeof(SlacRunId));
  4204. SendMmePacketSize += sizeof(SlacRunId);
  4205. memset(SendMmePacket.MMENTRY+SendMmePacketSize, 0, 17); //SOURCE_ID
  4206. SendMmePacketSize += 17;
  4207. memset(SendMmePacket.MMENTRY+SendMmePacketSize, 0, 17); //RESP_ID
  4208. SendMmePacketSize += 17;
  4209. SendMmePacket.MMENTRY[SendMmePacketSize++] = AttenProfileCnt; //NumSounds
  4210. SendMmePacket.MMENTRY[SendMmePacketSize++] = AagGroupsNum; //NumGroups
  4211. for(count=0; count < AagGroupsNum; count++)
  4212. {
  4213. unsigned char TmpAag;
  4214. TmpAag = ((Aag[count] / AttenProfileCnt) & 0xFF);
  4215. #if (SUDO_PSD_PARAMETER_MECHANISM == ENABLE) //default: ENABLE
  4216. #if 1
  4217. //TC_SECC_VTB_AttenuationCharacterization_019
  4218. TmpAag = TmpAag >> 1; //new method proposed by Joseph (divided by 2)
  4219. #else
  4220. if(TmpAag >= 39) //original method proposed by Vern
  4221. {
  4222. /*
  4223. // [To-do] If this statement is enabled, SLAC will fail due to timeout.
  4224. {
  4225. unsigned char TmpBuf[64];
  4226. memset(TmpBuf,0,sizeof(TmpBuf));
  4227. sprintf(TmpBuf,"SlacComm: bad Aag[%d]=%d",count,TmpAag);
  4228. SAVE_SYS_LOG_MSG_EVCOMM(TmpBuf);
  4229. }
  4230. */
  4231. printf("%d,", TmpAag);
  4232. TmpAag = 37;
  4233. }
  4234. #endif
  4235. #endif
  4236. SendMmePacket.MMENTRY[SendMmePacketSize++] = TmpAag;
  4237. }
  4238. SendMmePacketSize += 19; //the size before MMENTRY
  4239. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == TRUE)
  4240. {
  4241. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Send MME Packet *****\n");
  4242. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  4243. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  4244. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  4245. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  4246. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  4247. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  4248. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  4249. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  4250. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_ATTEN_CHAR_IND ---\n");
  4251. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  4252. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  4253. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  4254. SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5],
  4255. SendMmePacket.MMENTRY[6],SendMmePacket.MMENTRY[7]);
  4256. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  4257. SendMmePacket.MMENTRY[8],SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],
  4258. SendMmePacket.MMENTRY[12],SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14],SendMmePacket.MMENTRY[15]);
  4259. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: \n");
  4260. for(count=0; count<17; count++)
  4261. {
  4262. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[16+count]);
  4263. }
  4264. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  4265. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: \n");
  4266. for(count=0; count<17; count++)
  4267. {
  4268. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[33+count]);
  4269. }
  4270. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  4271. DEBUG_PRINTF_EVCOMM_DETAIL("NumSounds: 0x%x\n", SendMmePacket.MMENTRY[50]);
  4272. DEBUG_PRINTF_EVCOMM_DETAIL("ATTEN_PROFILE: \n");
  4273. for(count=0; count<AagGroupsNum; count++)
  4274. {
  4275. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[51+count]);
  4276. }
  4277. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  4278. }
  4279. #endif
  4280. Update_V2G_Flow_Status(CM_ATTEN_CHAR_IND);
  4281. count = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  4282. //Print log if this CM_ATTEN_CHAR_IND belongs to RETRY Tx message.
  4283. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)
  4284. {
  4285. sprintf(buf_log_evcomm,
  4286. "[SLAC][Tx]CM_ATTEN_CHAR_IND: resend(%d-th)",
  4287. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  4288. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4289. }
  4290. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n", SendMmePacketSize,count);
  4291. ftime(&SeqStartTime);
  4292. }
  4293. break;
  4294. }
  4295. #endif
  4296. }
  4297. case CM_ATTEN_CHAR_IND:
  4298. {
  4299. ftime(&SeqEndTime);
  4300. //if(DiffTimeb(SeqStartTime, SeqEndTime)>TT_match_response)
  4301. 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.
  4302. {
  4303. sprintf(buf_log_evcomm,
  4304. "SlacComm: Wait CM_ATTEN_CHAR_RSP Timeout - TT_match_response (%.02lf of %dms)",
  4305. DiffTimeb(SeqStartTime, SeqEndTime),
  4306. TT_match_response);
  4307. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4308. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4309. //CCS_SECC_TIMEOUT_SLAC_CM_ATTEN_CHAR_RSP (023814):
  4310. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4311. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4312. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4313. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4314. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4315. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4316. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  4317. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  4318. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4319. Update_V2G_Flow_Status(Sequence_Timeout);
  4320. return -1;
  4321. }
  4322. break;
  4323. }
  4324. case CM_ATTEN_CHAR_RSP:
  4325. {
  4326. ftime(&SeqEndTime);
  4327. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_EVSE_match_session)
  4328. {
  4329. sprintf(buf_log_evcomm,
  4330. "SlacComm: Wait CM_VALIDATE_REQ_1ST or CM_SLAC_MATCH_REQ Timeout - TT_EVSE_match_session (%.02lf of %dms)",
  4331. DiffTimeb(SeqStartTime, SeqEndTime),
  4332. TT_EVSE_match_session);
  4333. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4334. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4335. //CCS_SECC_TIMEOUT_SLAC_CM_VALIDATE_REQ_1ST__CM_SLAC_MATCH_REQ (023815):
  4336. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4337. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4338. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4339. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4340. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4341. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4342. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  4343. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  4344. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4345. Update_V2G_Flow_Status(Sequence_Timeout);
  4346. return -1;
  4347. }
  4348. break;
  4349. }
  4350. case CM_VALIDATE_CNF:
  4351. {
  4352. ftime(&SeqEndTime);
  4353. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_sequence)
  4354. {
  4355. sprintf(buf_log_evcomm,
  4356. "SlacComm: Wait CM_VALIDATE_REQ_2ND or CM_SLAC_MATCH_REQ Timeout - TT_match_sequence (%.02lf of %dms)",
  4357. DiffTimeb(SeqStartTime, SeqEndTime),
  4358. TT_match_sequence);
  4359. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4360. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4361. //CCS_SECC_TIMEOUT_SLAC_CM_VALIDATE_REQ_2ND__CM_SLAC_MATCH_REQ (023819):
  4362. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4363. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4364. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4365. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4366. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4367. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4368. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  4369. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  4370. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4371. Update_V2G_Flow_Status(Sequence_Timeout);
  4372. return -1;
  4373. }
  4374. break;
  4375. }
  4376. case CM_AMP_MAP_CNF:
  4377. case CM_SLAC_MATCH_CNF:
  4378. {
  4379. if(UdpSock > 0)
  4380. {
  4381. close(UdpSock);
  4382. UdpSock = -1;
  4383. }
  4384. if(TcpSock > 0)
  4385. {
  4386. close(TcpSock);
  4387. TcpSock = -1;
  4388. }
  4389. ftime(&SeqStartTime);
  4390. V2gTcpConnected();
  4391. Update_V2G_Flow_Status(SLACC_SDP_UDP_Connection);
  4392. SAVE_SYS_LOG_MSG_EVCOMM("SLAAC,SDP,UDP: connecting...");
  4393. break;
  4394. }
  4395. default:
  4396. {
  4397. break;
  4398. }
  4399. }
  4400. return 0;
  4401. }
  4402. /*===========================================================================
  4403. FUNCTION: V2gMsgDecoder
  4404. DESCRIPTION:
  4405. 1. Decode the V2GTP messages inside "msg" and save the decoded
  4406. messages in ccs_exi_doc_DIN, ccs_exi_doc_ISO1, and ccs_exi_doc_ISO2,
  4407. respectively.
  4408. 2. After decoding, V2gMsg_Process() could then use
  4409. ccs_exi_doc_DIN, ccs_exi_doc_ISO1, or ccs_exi_doc_ISO2
  4410. to deal with the corresponding Response messages, respectively.
  4411. PRE-CONDITION:
  4412. 1. msg_length > 0
  4413. INPUT:
  4414. 1. msg
  4415. 2. msg_length
  4416. OUTPUT:
  4417. 1. ccs_exi_doc_DIN //global variable
  4418. ccs_exi_doc_ISO1
  4419. ccs_exi_doc_ISO2
  4420. 2. v2g_state //Status Flag
  4421. //indicating the V2gMsg_Process_din to proceed
  4422. the next process.
  4423. 3. return value // < 0: ERROR
  4424. // > 0: Message Type
  4425. GLOBAL VARIABLES:
  4426. =============================================================================*/
  4427. int V2gMsgDecoder(unsigned char *msg, unsigned int msg_length, unsigned int v2g_state)
  4428. {
  4429. int errn = 0;
  4430. //Checking the minimum Header size requirement
  4431. if(msg_length < V2GTP_MSG_HEADER_LENGTH) //The minimum requirement should be 8-byte header.
  4432. {
  4433. errn = -1;
  4434. return errn;
  4435. }
  4436. //Decode the 1st V2GMSG: AppProtocol
  4437. if(v2g_state == SupportedAppProtocolRequest) //17
  4438. {
  4439. if (errn = API_V2GMSG_EXI_Decoder_AppProtocol(msg, msg_length, &ccs_handshake) < 0)
  4440. {
  4441. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR = %d (DEC)]V2gMsgDecoder: SupportedAppProtocolRequest()\n", errn);
  4442. }
  4443. else //decoded successfully.
  4444. {
  4445. //PRINT_XML_DOC_supportedAppProtocolReq(&ccs_handshake);
  4446. }
  4447. }
  4448. //Decode the subsequent V2GMSG (DIN 70121, ISO 15118-2, ISO 15118-20)
  4449. else if(v2g_state > SupportedAppProtocolRequest && v2g_state <= SessionStopResponse)
  4450. {
  4451. //Decoding according to its own protocol
  4452. switch (ShmCcsData->CommProtocol)
  4453. {
  4454. case V2GT_MSG_PROTOCOL_DIN70121: //0
  4455. {
  4456. //DIN
  4457. if(errn = API_V2GMSG_EXI_Decoder_DIN(msg, msg_length, &ccs_exi_doc_DIN) < 0)
  4458. {
  4459. sprintf(buf_log_evcomm,
  4460. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_DIN()",
  4461. errn);
  4462. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4463. }
  4464. break;
  4465. }
  4466. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  4467. {
  4468. //ISO1
  4469. if(errn = API_V2GMSG_EXI_Decoder_ISO1(msg, msg_length, &ccs_exi_doc_ISO1) < 0)
  4470. {
  4471. sprintf(buf_log_evcomm,
  4472. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_ISO1()",
  4473. errn);
  4474. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4475. }
  4476. break;
  4477. }
  4478. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  4479. {
  4480. //ISO2
  4481. if(errn = API_V2GMSG_EXI_Decoder_ISO2(msg, msg_length, &ccs_exi_doc_ISO2) < 0)
  4482. {
  4483. sprintf(buf_log_evcomm,
  4484. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_ISO2()",
  4485. errn);
  4486. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4487. }
  4488. break;
  4489. }
  4490. default:
  4491. break;
  4492. }
  4493. }
  4494. else
  4495. {
  4496. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR = %d (DEC)]V2gMsgDecoder: Unexpected v2g_state\n", errn);
  4497. errn = -1;
  4498. }
  4499. return errn;
  4500. }
  4501. /*===========================================================================
  4502. FUNCTION: encode_din_V2GTP_stream
  4503. DESCRIPTION:
  4504. PRE-CONDITION:
  4505. INPUT:
  4506. OUTPUT:
  4507. GLOBAL VARIABLES:
  4508. =============================================================================*/
  4509. int encode_din_V2GTP_stream(bitstream_t *v2g_tx_stream, struct dinEXIDocument *ccs_exi_doc_DIN)
  4510. {
  4511. int errn = 0;
  4512. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4513. errn = encode_dinExiDocument(v2g_tx_stream, ccs_exi_doc_DIN);
  4514. if (errn == 0)
  4515. {
  4516. //successfully encoded
  4517. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4518. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4519. if (errn != 0)
  4520. {
  4521. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_din_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4522. }
  4523. }
  4524. else
  4525. {
  4526. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_din_V2GTP_stream]encode_dinExiDocument(): %d (DEC)\n", errn);
  4527. }
  4528. return errn;
  4529. }
  4530. /*===========================================================================
  4531. FUNCTION: encode_iso1_V2GTP_stream
  4532. DESCRIPTION:
  4533. PRE-CONDITION:
  4534. INPUT:
  4535. OUTPUT:
  4536. GLOBAL VARIABLES:
  4537. =============================================================================*/
  4538. int encode_iso1_V2GTP_stream(bitstream_t *v2g_tx_stream, struct iso1EXIDocument *ccs_exi_doc_ISO1)
  4539. {
  4540. int errn = 0;
  4541. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4542. errn = encode_iso1ExiDocument(v2g_tx_stream, ccs_exi_doc_ISO1);
  4543. if (errn == 0)
  4544. {
  4545. //successfully encoded
  4546. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4547. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4548. if (errn != 0)
  4549. {
  4550. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso1_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4551. }
  4552. }
  4553. else
  4554. {
  4555. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso1_V2GTP_stream]encode_iso1ExiDocument(): %d (DEC)\n", errn);
  4556. }
  4557. return errn;
  4558. }
  4559. /*===========================================================================
  4560. FUNCTION: encode_iso2_V2GTP_stream
  4561. DESCRIPTION:
  4562. PRE-CONDITION:
  4563. INPUT:
  4564. OUTPUT:
  4565. GLOBAL VARIABLES:
  4566. =============================================================================*/
  4567. int encode_iso2_V2GTP_stream(bitstream_t *v2g_tx_stream, struct iso2EXIDocument *ccs_exi_doc_ISO2)
  4568. {
  4569. int errn = 0;
  4570. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4571. errn = encode_iso2ExiDocument(v2g_tx_stream, ccs_exi_doc_ISO2);
  4572. if (errn == 0)
  4573. {
  4574. //successfully encoded
  4575. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4576. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4577. if (errn != 0)
  4578. {
  4579. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso2_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4580. }
  4581. }
  4582. else
  4583. {
  4584. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso2_V2GTP_stream]encode_iso2ExiDocument(): %d (DEC)\n", errn);
  4585. }
  4586. return errn;
  4587. }
  4588. /*===========================================================================
  4589. FUNCTION: send_encoded_din_V2GTP_Stream
  4590. DESCRIPTION:
  4591. PRE-CONDITION:
  4592. INPUT:
  4593. OUTPUT:
  4594. GLOBAL VARIABLES:
  4595. =============================================================================*/
  4596. int send_encoded_din_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct dinEXIDocument *ccs_exi_doc_DIN)
  4597. {
  4598. int errn = 0;
  4599. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4600. errn = encode_din_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_DIN);
  4601. // STEP 2: =========== Send Response Packet ===========
  4602. int rtn = 0;
  4603. #ifdef SUPPORT_TLS_CONNECTION
  4604. if(EvSecurity == 0)//support security
  4605. {
  4606. rtn = SSL_write(ssl, v2g_tx_stream->data, v2g_tx_stream->size);
  4607. }
  4608. else
  4609. {
  4610. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4611. }
  4612. #else
  4613. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4614. #endif
  4615. if (rtn == v2g_tx_stream->size)
  4616. {
  4617. /*
  4618. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][send_encoded_din_V2GTP_Stream] Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4619. rtn, v2g_tx_stream->size);
  4620. */
  4621. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4622. }
  4623. else if (rtn >= 0)
  4624. {
  4625. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][send_encoded_din_V2GTP_Stream]Imcomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n",
  4626. rtn, v2g_tx_stream->size);
  4627. }
  4628. else
  4629. {
  4630. errn = rtn;
  4631. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][send_encoded_din_V2GTP_Stream]send(): %d (DEC)\n", errn);
  4632. }
  4633. //STEP 3: ========= Reset V2G MSG Flags ==========
  4634. init_dinBodyType(&ccs_exi_doc_DIN->V2G_Message.Body);
  4635. return errn;
  4636. }
  4637. /*===========================================================================
  4638. FUNCTION: send_encoded_iso1_V2GTP_Stream
  4639. DESCRIPTION:
  4640. PRE-CONDITION:
  4641. INPUT:
  4642. OUTPUT:
  4643. GLOBAL VARIABLES:
  4644. =============================================================================*/
  4645. int send_encoded_iso1_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct iso1EXIDocument *ccs_exi_doc_ISO1)
  4646. {
  4647. int errn = 0;
  4648. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4649. errn = encode_iso1_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_ISO1);
  4650. // STEP 2: =========== Send Response Packet ===========
  4651. int rtn = 0;
  4652. #ifdef SUPPORT_TLS_CONNECTION
  4653. if(EvSecurity == 0)//support security
  4654. {
  4655. rtn = SSL_write(ssl, v2g_tx_stream->data, v2g_tx_stream->size);
  4656. }
  4657. else
  4658. {
  4659. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4660. }
  4661. #else
  4662. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4663. #endif
  4664. if (rtn == v2g_tx_stream->size)
  4665. {
  4666. /*
  4667. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][send_encoded_iso1_V2GTP_Stream] Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4668. rtn, v2g_tx_stream->size);
  4669. */
  4670. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4671. }
  4672. else if (rtn >= 0)
  4673. {
  4674. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][send_encoded_iso1_V2GTP_Stream]Imcomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n",
  4675. rtn, v2g_tx_stream->size);
  4676. }
  4677. else
  4678. {
  4679. errn = rtn;
  4680. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][send_encoded_iso1_V2GTP_Stream]send(): %d (DEC)\n", errn);
  4681. }
  4682. //STEP 3: ========= Reset V2G MSG Flags ==========
  4683. init_iso1BodyType(&ccs_exi_doc_ISO1->V2G_Message.Body);
  4684. return errn;
  4685. }
  4686. /*===========================================================================
  4687. FUNCTION: send_encoded_iso2_V2GTP_Stream
  4688. DESCRIPTION:
  4689. PRE-CONDITION:
  4690. INPUT:
  4691. OUTPUT:
  4692. GLOBAL VARIABLES:
  4693. =============================================================================*/
  4694. int send_encoded_iso2_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct iso2EXIDocument *ccs_exi_doc_ISO2)
  4695. {
  4696. int errn = 0;
  4697. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4698. errn = encode_iso2_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_ISO2);
  4699. // STEP 2: =========== Send Response Packet ===========
  4700. int rtn = 0;
  4701. #ifdef SUPPORT_TLS_CONNECTION
  4702. if(EvSecurity == 0)//support security
  4703. {
  4704. rtn = SSL_write(ssl, v2g_tx_stream->data, v2g_tx_stream->size);
  4705. }
  4706. else
  4707. {
  4708. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4709. }
  4710. #else
  4711. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4712. #endif
  4713. if (rtn == v2g_tx_stream->size)
  4714. {
  4715. /*
  4716. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][send_encoded_iso2_V2GTP_Stream] Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4717. rtn, v2g_tx_stream->size);
  4718. */
  4719. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4720. }
  4721. else if (rtn >= 0)
  4722. {
  4723. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][send_encoded_iso2_V2GTP_Stream]Imcomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n",
  4724. rtn, v2g_tx_stream->size);
  4725. }
  4726. else
  4727. {
  4728. errn = rtn;
  4729. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][send_encoded_iso2_V2GTP_Stream]send(): %d (DEC)\n", errn);
  4730. }
  4731. //STEP 3: ========= Reset V2G MSG Flags ==========
  4732. init_iso2BodyType(&ccs_exi_doc_ISO2->V2G_Message.Body);
  4733. return errn;
  4734. }
  4735. /*===========================================================================
  4736. FUNCTION: Check_din_V2G_Rx_MSG_SessionID
  4737. DESCRIPTION:
  4738. PRE-CONDITION:
  4739. INPUT:
  4740. OUTPUT:
  4741. GLOBAL VARIABLES:
  4742. =============================================================================*/
  4743. int Check_din_V2G_Rx_MSG_SessionID(struct dinEXIDocument *exi_doc_DIN)
  4744. {
  4745. int i = 0;
  4746. int leng = 0;
  4747. int errn = 0;
  4748. leng = exi_doc_DIN->V2G_Message.Header.SessionID.bytesLen;
  4749. //Step 1: Check SessionID Length
  4750. if (leng != 8) //8-byte
  4751. {
  4752. sprintf(buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4753. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4754. errn = -1;
  4755. }
  4756. else
  4757. {
  4758. //Step 2-1: Check SessionID content
  4759. for (i = 0; i < leng; i++)
  4760. {
  4761. if (exi_doc_DIN->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4762. {
  4763. errn = -2;
  4764. break;
  4765. }
  4766. }
  4767. }
  4768. //Step 2-2: Print Incorrect ID
  4769. if (errn == -2) //incorrect ID
  4770. {
  4771. sprintf(buf_log_evcomm,
  4772. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4773. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[0],
  4774. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[1],
  4775. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[2],
  4776. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[3],
  4777. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[4],
  4778. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[5],
  4779. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[6],
  4780. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[7],
  4781. EVCOMM_SYS_INFO.SessionID[0],
  4782. EVCOMM_SYS_INFO.SessionID[1],
  4783. EVCOMM_SYS_INFO.SessionID[2],
  4784. EVCOMM_SYS_INFO.SessionID[3],
  4785. EVCOMM_SYS_INFO.SessionID[4],
  4786. EVCOMM_SYS_INFO.SessionID[5],
  4787. EVCOMM_SYS_INFO.SessionID[6],
  4788. EVCOMM_SYS_INFO.SessionID[7]
  4789. );
  4790. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4791. }
  4792. //Step 3: Correct SessionID for Res Message
  4793. if (errn != 0)
  4794. {
  4795. exi_doc_DIN->V2G_Message.Header.SessionID.bytesLen = 8;
  4796. memset(exi_doc_DIN->V2G_Message.Header.SessionID.bytes, 0, 8);
  4797. memcpy(exi_doc_DIN->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4798. }
  4799. return errn;
  4800. }
  4801. /*===========================================================================
  4802. FUNCTION: Check_iso1_V2G_Rx_MSG_SessionID
  4803. DESCRIPTION:
  4804. PRE-CONDITION:
  4805. INPUT:
  4806. OUTPUT:
  4807. GLOBAL VARIABLES:
  4808. =============================================================================*/
  4809. int Check_iso1_V2G_Rx_MSG_SessionID(struct iso1EXIDocument *exi_doc_ISO1)
  4810. {
  4811. int i = 0;
  4812. int leng = 0;
  4813. int errn = 0;
  4814. leng = exi_doc_ISO1->V2G_Message.Header.SessionID.bytesLen;
  4815. //Step 1: Check SessionID Length
  4816. if (leng != 8) //8-byte
  4817. {
  4818. sprintf(buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4819. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4820. errn = -1;
  4821. }
  4822. else
  4823. {
  4824. //Step 2-1: Check SessionID content
  4825. for (i = 0; i < leng; i++)
  4826. {
  4827. if (exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4828. {
  4829. errn = -2;
  4830. break;
  4831. }
  4832. }
  4833. }
  4834. //Step 2-2: Print Incorrect ID
  4835. if (errn == -2) //incorrect ID
  4836. {
  4837. sprintf(buf_log_evcomm,
  4838. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4839. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[0],
  4840. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[1],
  4841. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[2],
  4842. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[3],
  4843. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[4],
  4844. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[5],
  4845. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[6],
  4846. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[7],
  4847. EVCOMM_SYS_INFO.SessionID[0],
  4848. EVCOMM_SYS_INFO.SessionID[1],
  4849. EVCOMM_SYS_INFO.SessionID[2],
  4850. EVCOMM_SYS_INFO.SessionID[3],
  4851. EVCOMM_SYS_INFO.SessionID[4],
  4852. EVCOMM_SYS_INFO.SessionID[5],
  4853. EVCOMM_SYS_INFO.SessionID[6],
  4854. EVCOMM_SYS_INFO.SessionID[7]
  4855. );
  4856. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4857. }
  4858. //Step 3: Correct SessionID for Res Message
  4859. if (errn != 0)
  4860. {
  4861. exi_doc_ISO1->V2G_Message.Header.SessionID.bytesLen = 8;
  4862. memset(exi_doc_ISO1->V2G_Message.Header.SessionID.bytes, 0, 8);
  4863. memcpy(exi_doc_ISO1->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4864. }
  4865. return errn;
  4866. }
  4867. /*===========================================================================
  4868. FUNCTION: Check_iso2_V2G_Rx_MSG_SessionID
  4869. DESCRIPTION:
  4870. PRE-CONDITION:
  4871. INPUT:
  4872. OUTPUT:
  4873. GLOBAL VARIABLES:
  4874. =============================================================================*/
  4875. int Check_iso2_V2G_Rx_MSG_SessionID(struct iso2EXIDocument *exi_doc_ISO2)
  4876. {
  4877. int i = 0;
  4878. int leng = 0;
  4879. int errn = 0;
  4880. leng = exi_doc_ISO2->V2G_Message.Header.SessionID.bytesLen;
  4881. //Step 1: Check SessionID Length
  4882. if (leng != 8) //8-byte
  4883. {
  4884. sprintf(buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4885. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4886. errn = -1;
  4887. }
  4888. else
  4889. {
  4890. //Step 2-1: Check SessionID content
  4891. for (i = 0; i < leng; i++)
  4892. {
  4893. if (exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4894. {
  4895. errn = -2;
  4896. break;
  4897. }
  4898. }
  4899. }
  4900. //Step 2-2: Print Incorrect ID
  4901. if (errn == -2) //incorrect ID
  4902. {
  4903. sprintf(buf_log_evcomm,
  4904. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4905. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[0],
  4906. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[1],
  4907. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[2],
  4908. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[3],
  4909. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[4],
  4910. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[5],
  4911. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[6],
  4912. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[7],
  4913. EVCOMM_SYS_INFO.SessionID[0],
  4914. EVCOMM_SYS_INFO.SessionID[1],
  4915. EVCOMM_SYS_INFO.SessionID[2],
  4916. EVCOMM_SYS_INFO.SessionID[3],
  4917. EVCOMM_SYS_INFO.SessionID[4],
  4918. EVCOMM_SYS_INFO.SessionID[5],
  4919. EVCOMM_SYS_INFO.SessionID[6],
  4920. EVCOMM_SYS_INFO.SessionID[7]
  4921. );
  4922. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4923. }
  4924. //Step 3: Correct SessionID for Res Message
  4925. if (errn != 0)
  4926. {
  4927. exi_doc_ISO2->V2G_Message.Header.SessionID.bytesLen = 8;
  4928. memset(exi_doc_ISO2->V2G_Message.Header.SessionID.bytes, 0, 8);
  4929. memcpy(exi_doc_ISO2->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4930. }
  4931. return errn;
  4932. }
  4933. /*===========================================================================
  4934. FUNCTION: GetSchemaID_of_Protocol
  4935. DESCRIPTION:
  4936. 1. Get the SchemaID accroding to the input target
  4937. *V2GT_MSG_PROTOCOL_DIN70121: choose DIN 70121
  4938. *V2GT_MSG_PROTOCOL_ISO15118_2014: choose ISO 15118-2 (ed1)
  4939. *V2GT_MSG_PROTOCOL_ISO15118_2018: choose ISO 15118-20 (ed2)
  4940. *V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY: choose the one with the highest priority
  4941. 2. [To-do] Checking Major and Minor version
  4942. 3. The parsing method will not support those private protocols,
  4943. such as "usr:tesla...," since "tesla" is 5 bytes but "din" and "iso" are 3 bytes.
  4944. 4. [To-do] If the target is selected as DIN," but there is no DIN.
  4945. However, if EV and EVSE all support ISO, how to use ISO instead?
  4946. PRE-CONDITION:
  4947. INPUT:
  4948. 1. target: target protocol
  4949. OUTPUT:
  4950. 1. id: SchemaID of selected protocol by EVSE
  4951. 2. ShmCcsData->CommProtocol (selected protocol)
  4952. 3. SupportedAppProtocol_result
  4953. (1) appHandresponseCodeType_OK_SuccessfulNegotiation = 0,
  4954. (2) appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation = 1,
  4955. (3) appHandresponseCodeType_Failed_NoNegotiation = 2
  4956. GLOBAL VARIABLES:
  4957. 1. ccs_handshake
  4958. 2. ShmCcsData
  4959. =============================================================================*/
  4960. int GetSchemaID_of_Protocol(unsigned char target)
  4961. {
  4962. int i = 0;
  4963. int ii = 0;
  4964. int id = 0;
  4965. unsigned char tmp = 0;
  4966. unsigned char pri = 20; //priority = 1(highest)~20(lowerest)
  4967. char num[10];
  4968. //struct CCS_ProtocolNamespacestructCharacters pro;
  4969. //Choose the 1st protocol as default.
  4970. //id = CCS_HANDSHAKE_PROTOCOLS.array[0].SchemaID;
  4971. id = -1;
  4972. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4973. for(i = 0; i < CCS_HANDSHAKE_PROTOCOLS.arrayLen; i++)
  4974. {
  4975. //Checking for <ProtocolNamespace>urn:din:70121:2012:MsgDef</ProtocolNamespace>
  4976. //[To-Do] Ignoring the priority from EV and force DIN 70121 as our only option. (for temp)
  4977. //[CAUTION] The parsing method will not support those private protocols, such as "usr:tesla..."
  4978. num[0] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[8];
  4979. num[1] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[9];
  4980. num[2] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[10];
  4981. num[3] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[11];
  4982. num[4] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[12];
  4983. num[5] = '\0';
  4984. if (atoi(num) == 70121)
  4985. {
  4986. sprintf(buf_log_evcomm,
  4987. "[GetSchemaID_of_Protocol]supported(%d-th/%d): DIN 70121(%d:v%d.%d;id=%d,pri=%d)",
  4988. (i+1),
  4989. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4990. atoi(num),
  4991. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4992. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4993. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4994. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4995. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4996. #ifdef AWCCS
  4997. continue;
  4998. #endif
  4999. if (target == V2GT_MSG_PROTOCOL_DIN70121)
  5000. {
  5001. sprintf(buf_log_evcomm,
  5002. "[GetSchemaID_of_Protocol]selected(%d-th/%d): DIN 70121(%d:v%d.%d;id=%d,pri=%d)",
  5003. (i+1),
  5004. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5005. atoi(num),
  5006. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  5007. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  5008. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  5009. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  5010. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5011. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == DIN_SPEC_70121_2012_VersionNumberMajor)
  5012. {
  5013. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == DIN_SPEC_70121_2012_VersionNumberMinor)
  5014. {
  5015. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  5016. }
  5017. else
  5018. { //[TC_SECC_VTB_SupportedAppProtocol_005]
  5019. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  5020. }
  5021. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  5022. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  5023. return id;
  5024. }
  5025. else
  5026. {
  5027. //keep looking for the suitable protocol
  5028. }
  5029. }
  5030. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  5031. {
  5032. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  5033. {
  5034. ii = i;
  5035. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  5036. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  5037. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  5038. }
  5039. else
  5040. {
  5041. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  5042. }
  5043. }
  5044. else
  5045. {
  5046. //null
  5047. }
  5048. }
  5049. else if (atoi(num) == 15118)
  5050. {
  5051. //urn:din:70121:2012:MsgDef
  5052. //urn:iso:15118:2:2013:MsgDef
  5053. memset(num, 0, sizeof(num));
  5054. num[0] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[16];
  5055. num[1] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[17];
  5056. num[2] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[18];
  5057. num[3] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[19];
  5058. num[4] = '\0';
  5059. if (atoi(num) < 2018 && atoi(num) >= 2010)
  5060. {
  5061. sprintf(buf_log_evcomm,
  5062. "[GetSchemaID_of_Protocol]supported(%d-th/%d): ISO 15118-2(ed1,%d:v%d.%d;id=%d,pri=%d)",
  5063. (i+1),
  5064. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5065. atoi(num),
  5066. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  5067. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  5068. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  5069. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  5070. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5071. if (target == V2GT_MSG_PROTOCOL_ISO15118_2014)
  5072. {
  5073. sprintf(buf_log_evcomm,
  5074. "[GetSchemaID_of_Protocol]selected(%d-th/%d): ISO 15118-2,ed1(%d:v%d.%d;id=%d,pri=%d)",
  5075. (i+1),
  5076. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5077. atoi(num),
  5078. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  5079. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  5080. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  5081. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  5082. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5083. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == ISO1_15118_2013_VersionNumberMajor)
  5084. {
  5085. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == ISO1_15118_2013_VersionNumberMinor)
  5086. {
  5087. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  5088. }
  5089. else
  5090. {
  5091. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  5092. }
  5093. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  5094. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2014;
  5095. return id;
  5096. }
  5097. else
  5098. {
  5099. //keep looking for the suitable protocol
  5100. }
  5101. }
  5102. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  5103. {
  5104. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  5105. {
  5106. ii = i;
  5107. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  5108. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  5109. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2014;
  5110. }
  5111. else
  5112. {
  5113. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  5114. }
  5115. }
  5116. else
  5117. {
  5118. //null
  5119. }
  5120. }
  5121. else if (atoi(num) >= 2018 && atoi(num) <= 2100) // >= 2018
  5122. {
  5123. sprintf(buf_log_evcomm,
  5124. "[GetSchemaID_of_Protocol]supported(%d-th/%d): ISO 15118-20(ed2,%d:v%d.%d;id=%d,pri=%d)",
  5125. (i+1),
  5126. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5127. atoi(num),
  5128. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  5129. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  5130. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  5131. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  5132. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5133. if (target == V2GT_MSG_PROTOCOL_ISO15118_2018)
  5134. {
  5135. sprintf(buf_log_evcomm,
  5136. "[GetSchemaID_of_Protocol]selected(%d-th/%d): ISO 15118-20,ed2(%d:v%d.%d;id=%d,pri=%d)",
  5137. (i+1),
  5138. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5139. atoi(num),
  5140. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  5141. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  5142. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  5143. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  5144. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5145. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == ISO2_15118_2018_VersionNumberMajor)
  5146. {
  5147. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == ISO2_15118_2018_VersionNumberMinor)
  5148. {
  5149. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  5150. }
  5151. else
  5152. {
  5153. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  5154. }
  5155. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  5156. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2018;
  5157. return id;
  5158. }
  5159. else
  5160. {
  5161. //keep looking for the suitable protocol
  5162. }
  5163. }
  5164. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  5165. {
  5166. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  5167. {
  5168. ii = i;
  5169. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  5170. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  5171. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2018;
  5172. }
  5173. else
  5174. {
  5175. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  5176. }
  5177. }
  5178. else
  5179. {
  5180. //null
  5181. }
  5182. }
  5183. else
  5184. {
  5185. //Unexpected Year
  5186. sprintf(buf_log_evcomm,
  5187. "[GetSchemaID_of_Protocol]unsupported(%d-th/%d): ISO 15118-X(unexpected year:%d,v%d.%d),id=%d,pri=%d",
  5188. (i+1),
  5189. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5190. atoi(num),
  5191. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  5192. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  5193. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  5194. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  5195. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5196. //return -1;
  5197. }
  5198. }
  5199. else
  5200. {
  5201. sprintf(buf_log_evcomm,
  5202. "[GetSchemaID_of_Protocol]unsupported protocol(%d-th/%d)(%d:v%d.%d;id=%d,pri=%d)",
  5203. (i+1),
  5204. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5205. atoi(num),
  5206. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  5207. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  5208. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  5209. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  5210. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5211. //return -1;
  5212. }
  5213. }
  5214. //The final result of highest priority protocol
  5215. sprintf(buf_log_evcomm,
  5216. "[GetSchemaID_of_Protocol]selected(%d-th/%d): pro=%d(0:DIN,1:ISO1,2:ISO2);id=%d,pri=%d",
  5217. (ii+1),
  5218. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5219. ShmCcsData->CommProtocol,
  5220. id,
  5221. pri);
  5222. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5223. if (id < 0)
  5224. {
  5225. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_Failed_NoNegotiation;
  5226. }
  5227. return id;
  5228. }
  5229. /*===========================================================================
  5230. FUNCTION: Proc_supportedAppProtocolRes
  5231. DESCRIPTION:
  5232. PRE-CONDITION:
  5233. INPUT:
  5234. OUTPUT:
  5235. GLOBAL VARIABLES:
  5236. =============================================================================*/
  5237. int Proc_supportedAppProtocolRes(int AcceptFd)
  5238. {
  5239. int errn = 0;
  5240. bitstream_t v2g_tx_stream;
  5241. static struct ChargingInfoData *sys;
  5242. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5243. //STEP 1: =========== Setting the Response Message ===========
  5244. init_appHandEXIDocument(&ccs_handshake);
  5245. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_OK_SuccessfulNegotiation;
  5246. ccs_handshake.supportedAppProtocolRes_isUsed = 1u;
  5247. //select the 1st one as the default
  5248. ccs_handshake.supportedAppProtocolRes.SchemaID = CCS_HANDSHAKE_PROTOCOLS.array[0].SchemaID;
  5249. ccs_handshake.supportedAppProtocolRes.SchemaID_isUsed = 1u;
  5250. int id = 0;
  5251. /*+++ 20200808, vern, support both DIN and ISO +++*/
  5252. id = GetSchemaID_of_Protocol(V2GT_MSG_PROTOCOL_PREFERENCE); //output: EVCOMM_SYS_INFO.SupportedAppProtocol_result
  5253. //id = GetSchemaID_of_Protocol(V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY); //output: EVCOMM_SYS_INFO.SupportedAppProtocol_result
  5254. /*--- 20200808, vern, support both DIN and ISO ---*/
  5255. ccs_handshake.supportedAppProtocolRes.ResponseCode = EVCOMM_SYS_INFO.SupportedAppProtocol_result; //updating the response code
  5256. if (id < 0)
  5257. {
  5258. sprintf(buf_log_evcomm,
  5259. "[Error]No avalible CCS protocol (id = %d, preference = %d)",
  5260. id,
  5261. V2GT_MSG_PROTOCOL_PREFERENCE);
  5262. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5263. }
  5264. else
  5265. {
  5266. //selected SchemaID
  5267. ccs_handshake.supportedAppProtocolRes.SchemaID = (unsigned char) id;
  5268. }
  5269. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  5270. {
  5271. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_supportedAppProtocolRes]EVSE_Shutdown => End_Process");
  5272. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5273. errn = -1;
  5274. }
  5275. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5276. {
  5277. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_supportedAppProtocolRes]EVSE_EmergencyShutdown => End_Process");
  5278. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5279. errn = -1;
  5280. }
  5281. else
  5282. {
  5283. //null
  5284. }
  5285. //Check for Permission Changing from TRUE to FALSE
  5286. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5287. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  5288. ShmInternalComm->ChargingPermission == FALSE)
  5289. {
  5290. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][supportedAppProtocolRes]Permission OFF");
  5291. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5292. //errn = -1;
  5293. }
  5294. #if (CP_PROTECTION_MECHANISM == ENABLE)
  5295. {
  5296. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  5297. {
  5298. //Detect for CP State should be 9V with 5% PWM or 100%PWM (State B1, B2)
  5299. if (sys->CpState != 2 && sys->CpState != 3) //State B1, B2
  5300. {
  5301. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5302. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5303. Update_V2G_Flow_Status(Other_Fault);
  5304. sprintf(buf_log_evcomm,
  5305. "[Proc_supportedAppProtocolRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  5306. sys->CpState,
  5307. sys->CpVoltage);
  5308. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5309. }
  5310. }
  5311. #else
  5312. {
  5313. //Detect for CP State should be 9V (State B)
  5314. if (sys->CpState != 3) //B2
  5315. {
  5316. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5317. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5318. Update_V2G_Flow_Status(Other_Fault);
  5319. sprintf(buf_log_evcomm,
  5320. "[Proc_supportedAppProtocolRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  5321. sys->CpState,
  5322. sys->CpVoltage);
  5323. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5324. }
  5325. }
  5326. #endif
  5327. }
  5328. #endif
  5329. //STEP 2: =========== Encode into EXI ===========
  5330. if (errn = API_V2GMSG_EXI_Encoder_AppProtocol(&ccs_handshake, &v2g_tx_stream) !=0)
  5331. {
  5332. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Error]API_V2GMSG_EXI_Encoder_AppProtocol\n");
  5333. return errn;
  5334. }
  5335. //STEP 3: =========== Send Response Packet ===========
  5336. int Rtn = 0;
  5337. #ifdef SUPPORT_TLS_CONNECTION
  5338. if(EvSecurity == 0)//support security
  5339. {
  5340. Rtn = SSL_write(ssl, v2g_tx_stream.data, v2g_tx_stream.size);
  5341. }
  5342. else
  5343. {
  5344. Rtn = send(AcceptFd, v2g_tx_stream.data, v2g_tx_stream.size, 0);
  5345. }
  5346. #else
  5347. Rtn = send(AcceptFd, v2g_tx_stream.data, v2g_tx_stream.size, 0);
  5348. #endif
  5349. //Rtn = send(6, v2g_tx_stream.data, v2g_tx_stream.size, 0);
  5350. DEBUG_PRINTF_EVCOMM_DETAIL("Send V2GTP Packet Size = %d, Rtn = %d (Bytes, DEC)\n", v2g_tx_stream.size, Rtn);
  5351. if (Rtn < 0)
  5352. {
  5353. return Rtn;
  5354. }
  5355. //STEP 4: =========== Save into Share Memory =========
  5356. //[Joseph, To-Do] Adding a mechanism to choose DIN 70121 as our 1st priority. (for multiple protocols)
  5357. //STEP 5: =========== Updating the Flow State Flag =========
  5358. if (id < 0)
  5359. {
  5360. errn = -1;
  5361. }
  5362. //STEP 6: =========== Reset Flags ============
  5363. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  5364. init_appHandEXIDocument(&ccs_handshake);
  5365. return errn;
  5366. }
  5367. /*===========================================================================
  5368. FUNCTION: Proc_supportedAppProtocolReq
  5369. DESCRIPTION:
  5370. PRE-CONDITION:
  5371. INPUT:
  5372. OUTPUT:
  5373. GLOBAL VARIABLES:
  5374. =============================================================================*/
  5375. int Proc_supportedAppProtocolReq(int AcceptFd)
  5376. {
  5377. //[Joseph, To-Do] analysis on Req message and choose the prefered protocol
  5378. //Default: DIN 70121 (find SchemaID)
  5379. int errn = 0;
  5380. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]supportedAppProtocolReq");
  5381. SHM_Save_din_supportedAppProtocolReq(ShmCcsData, &ccs_handshake, ShmSysConfigAndInfo);
  5382. errn = Proc_supportedAppProtocolRes(AcceptFd);
  5383. if (errn == 0)
  5384. {
  5385. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Tx]supportedAppProtocolRes");
  5386. }
  5387. else
  5388. {
  5389. DEBUG_PRINTF_EVCOMM_DETAIL("[Error]Proc_supportedAppProtocolRes(): %d (DEC)\n", errn);
  5390. }
  5391. return errn;
  5392. }
  5393. /*===========================================================================
  5394. FUNCTION: Proc_din_SessionSetupRes
  5395. DESCRIPTION:
  5396. PRE-CONDITION:
  5397. INPUT:
  5398. OUTPUT:
  5399. GLOBAL VARIABLES:
  5400. =============================================================================*/
  5401. int Proc_din_SessionSetupRes(int AcceptFd)
  5402. {
  5403. int i = 0;
  5404. int errn = 0;
  5405. bitstream_t v2g_tx_stream;
  5406. static struct ChargingInfoData *sys;
  5407. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5408. size_t pos = 0;
  5409. v2g_tx_stream.pos = &pos;
  5410. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5411. v2g_tx_stream.data = V2GTP_Tx_buf;
  5412. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5413. init_dinSessionSetupResType(&ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes);
  5414. // ====== [BODY (1/2) ResponseCode ======
  5415. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5416. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_OK_NewSessionEstablished;
  5417. //[HEADER] Assign Res SessionID
  5418. ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytesLen = 8;
  5419. memset(ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytes, 0, 8);
  5420. memcpy(ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5421. //Check for SequenceError
  5422. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5423. {
  5424. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError;
  5425. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  5426. errn = -1;
  5427. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5428. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5429. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5430. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5431. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5432. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5433. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5434. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5435. }
  5436. //#if PARAMETER_NORMAL_MODE == ENABLE
  5437. //SHM_Read_din_V2GMSG_Header(&ccs_exi_doc_DIN, ShmCcsData);
  5438. //#endif
  5439. //Detect for CP State should be 9V (State B)
  5440. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5441. {
  5442. #if CP_PROTECTION_MECHANISM == ENABLE
  5443. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5444. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5445. Update_V2G_Flow_Status(Other_Fault);
  5446. errn = -1;
  5447. sprintf(buf_log_evcomm,
  5448. "[Proc_din_SessionSetupRes]Emergency Stop by CP Error (%d)\n",
  5449. sys->CpState);
  5450. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5451. #else
  5452. sprintf(buf_log_evcomm,
  5453. "[Proc_din_SessionSetupRes]Emergency Stop by CP Error (%d): ignored\n",
  5454. sys->CpState);
  5455. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5456. #endif
  5457. }
  5458. //Check for shutdown commands from EVSE(DC Main Board)
  5459. if (/*sys->DC_EVSEStatus == EVSE_Shutdown ||*/
  5460. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5461. {
  5462. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5463. sprintf(buf_log_evcomm, "[Proc_din_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5464. EVSE_Shutdown,
  5465. EVSE_EmergencyShutdown,
  5466. sys->DC_EVSEStatus);
  5467. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5468. errn = -1;
  5469. }
  5470. else if (sys->DC_EVSEStatus == EVSE_Shutdown/* ||
  5471. sys->DC_EVSEStatus == EVSE_EmergencyShutdown*/)
  5472. {
  5473. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5474. sprintf(buf_log_evcomm, "[Proc_din_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5475. EVSE_Shutdown,
  5476. EVSE_EmergencyShutdown,
  5477. sys->DC_EVSEStatus);
  5478. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5479. //errn = -1;
  5480. }
  5481. //Check for Permission Changing from TRUE to FALSE
  5482. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5483. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  5484. ShmInternalComm->ChargingPermission == FALSE)
  5485. {
  5486. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][SessionSetupRes]Permission OFF");
  5487. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5488. errn = -1;
  5489. }
  5490. // ====== [BODY (2/3) EVSEID ======
  5491. //EVSEID = all zero
  5492. memset(ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytes, 0, sizeof(ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytes));
  5493. //vern, should be encode by SN
  5494. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytesLen = 1; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5495. // ====== [BODY (3/3) DateTimeNow ======
  5496. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.DateTimeNow_isUsed = 1u;
  5497. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.DateTimeNow = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5498. #if PARAMETER_NORMAL_MODE == ENABLE
  5499. ///////////SHM_Read_din_SessionSetupRes(&ccs_exi_doc_DIN, ShmCcsData);
  5500. #endif
  5501. // ============ Encode and Send Response Message ===========
  5502. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5503. {
  5504. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_SessionSetupRes][Error]Tx encoded msg error");
  5505. errn = -1;
  5506. }
  5507. return errn;
  5508. }
  5509. /*===========================================================================
  5510. FUNCTION: Proc_iso1_SessionSetupRes
  5511. DESCRIPTION:
  5512. PRE-CONDITION:
  5513. INPUT:
  5514. OUTPUT:
  5515. GLOBAL VARIABLES:
  5516. =============================================================================*/
  5517. int Proc_iso1_SessionSetupRes(int AcceptFd)
  5518. {
  5519. int i = 0;
  5520. int errn = 0;
  5521. bitstream_t v2g_tx_stream;
  5522. static struct ChargingInfoData *sys;
  5523. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5524. size_t pos = 0;
  5525. v2g_tx_stream.pos = &pos;
  5526. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5527. v2g_tx_stream.data = V2GTP_Tx_buf;
  5528. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5529. init_iso1SessionSetupResType(&ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes);
  5530. // ====== [BODY (1/2) ResponseCode ======
  5531. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5532. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_OK_NewSessionEstablished;
  5533. //[HEADER] Assign Res SessionID
  5534. ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytesLen = 8;
  5535. memset(ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytes, 0, 8);
  5536. memcpy(ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5537. //Check for SequenceError
  5538. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5539. {
  5540. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5541. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  5542. errn = -1;
  5543. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5544. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5545. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5546. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5547. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5548. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5549. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5550. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5551. }
  5552. //#if PARAMETER_NORMAL_MODE == ENABLE
  5553. //SHM_Read_iso1_V2GMSG_Header(&ccs_exi_doc_ISO1, ShmCcsData);
  5554. //#endif
  5555. //Detect for CP State should be 9V (State B)
  5556. //if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2 //Benz already CP=4
  5557. if ((sys->CpState < 2) ||(sys->CpState > 5)) //State B1, B2 //Benz already CP=4
  5558. {
  5559. #if CP_PROTECTION_MECHANISM == ENABLE
  5560. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5561. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5562. Update_V2G_Flow_Status(Other_Fault);
  5563. errn = -1;
  5564. sprintf(buf_log_evcomm,
  5565. "[Proc_iso1_SessionSetupRes]Emergency Stop by CP Error (%d)\n",
  5566. sys->CpState);
  5567. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5568. #else
  5569. sprintf(buf_log_evcomm,
  5570. "[Proc_iso1_SessionSetupRes]Emergency Stop by CP Error (%d): ignored\n",
  5571. sys->CpState);
  5572. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5573. #endif
  5574. }
  5575. //Check for shutdown commands from EVSE(DC Main Board)
  5576. if (/*sys->DC_EVSEStatus == EVSE_Shutdown ||*/
  5577. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5578. {
  5579. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5580. sprintf(buf_log_evcomm, "[Proc_iso1_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5581. EVSE_Shutdown,
  5582. EVSE_EmergencyShutdown,
  5583. sys->DC_EVSEStatus);
  5584. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5585. errn = -1;
  5586. }
  5587. else if (sys->DC_EVSEStatus == EVSE_Shutdown /*||
  5588. sys->DC_EVSEStatus == EVSE_EmergencyShutdown*/)
  5589. {
  5590. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5591. sprintf(buf_log_evcomm, "[Proc_iso1_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5592. EVSE_Shutdown,
  5593. EVSE_EmergencyShutdown,
  5594. sys->DC_EVSEStatus);
  5595. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5596. // errn = -1;
  5597. }
  5598. //Check for Permission Changing from TRUE to FALSE
  5599. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  5600. ShmInternalComm->ChargingPermission == FALSE)
  5601. {
  5602. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO1][SessionSetupRes]Permission OFF");
  5603. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5604. //errn = -1;
  5605. }
  5606. // ====== [BODY (2/3) EVSEID ======
  5607. //EVSEID = all zero
  5608. memset(ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters, 0, sizeof(ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters));
  5609. /*+++ 20200808, vern, set default EVSEID +++*/
  5610. //vern, should be encoded by SN
  5611. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[0]='Z';
  5612. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[1]='Z';
  5613. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[2]='0';
  5614. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[3]='0';
  5615. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[4]='0';
  5616. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[5]='0';
  5617. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[6]='0';
  5618. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 7; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5619. /*--- 20200808, vern, set default EVSEID ---*/
  5620. // ====== [BODY (3/3) DateTimeNow ======
  5621. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  5622. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSETimeStamp = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5623. #if PARAMETER_NORMAL_MODE == ENABLE
  5624. ///////////SHM_Read_iso1_SessionSetupRes(&ccs_exi_doc_ISO1, ShmCcsData);
  5625. #endif
  5626. // ============ Encode and Send Response Message ===========
  5627. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  5628. {
  5629. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_SessionSetupRes][Error]Tx encoded msg error");
  5630. errn = -1;
  5631. }
  5632. return errn;
  5633. }
  5634. /*===========================================================================
  5635. FUNCTION: Proc_iso2_SessionSetupRes
  5636. DESCRIPTION:
  5637. PRE-CONDITION:
  5638. INPUT:
  5639. OUTPUT:
  5640. GLOBAL VARIABLES:
  5641. =============================================================================*/
  5642. int Proc_iso2_SessionSetupRes(int AcceptFd)
  5643. {
  5644. int i = 0;
  5645. int errn = 0;
  5646. bitstream_t v2g_tx_stream;
  5647. static struct ChargingInfoData *sys;
  5648. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5649. size_t pos = 0;
  5650. v2g_tx_stream.pos = &pos;
  5651. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5652. v2g_tx_stream.data = V2GTP_Tx_buf;
  5653. init_iso2BodyType(&ccs_exi_doc_ISO2.V2G_Message.Body);
  5654. init_iso2SessionSetupResType(&ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes);
  5655. // ====== [BODY (1/2) ResponseCode ======
  5656. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5657. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_OK_NewSessionEstablished;
  5658. //[HEADER] Assign Res SessionID
  5659. ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytesLen = 8;
  5660. memset(ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytes, 0, 8);
  5661. memcpy(ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5662. //Check for SequenceError
  5663. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5664. {
  5665. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5666. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  5667. errn = -1;
  5668. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5669. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5670. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5671. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5672. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5673. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5674. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5675. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5676. }
  5677. //#if PARAMETER_NORMAL_MODE == ENABLE
  5678. //SHM_Read_iso2_V2GMSG_Header(&ccs_exi_doc_ISO2, ShmCcsData);
  5679. //#endif
  5680. //Detect for CP State should be 9V (State B)
  5681. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5682. {
  5683. #if CP_PROTECTION_MECHANISM == ENABLE
  5684. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5685. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5686. Update_V2G_Flow_Status(Other_Fault);
  5687. errn = -1;
  5688. sprintf(buf_log_evcomm,
  5689. "[Proc_iso2_SessionSetupRes]Emergency Stop by CP Error (%d)",
  5690. sys->CpState);
  5691. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5692. #else
  5693. sprintf(buf_log_evcomm,
  5694. "[Proc_iso2_SessionSetupRes]Emergency Stop by CP Error (%d): ignored",
  5695. sys->CpState);
  5696. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5697. #endif
  5698. }
  5699. //Check for shutdown commands from EVSE(DC Main Board)
  5700. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5701. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5702. {
  5703. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5704. sprintf(buf_log_evcomm, "[Proc_iso2_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5705. EVSE_Shutdown,
  5706. EVSE_EmergencyShutdown,
  5707. sys->DC_EVSEStatus);
  5708. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5709. errn = -1;
  5710. }
  5711. //Check for Permission Changing from TRUE to FALSE
  5712. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5713. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  5714. ShmInternalComm->ChargingPermission == FALSE)
  5715. {
  5716. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO2][SessionSetupRes]Permission OFF");
  5717. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5718. errn = -1;
  5719. }
  5720. // ====== [BODY (2/3) EVSEID ======
  5721. //EVSEID = all zero
  5722. memset(ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.characters, 0, sizeof(ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.characters));
  5723. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 15; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5724. // ====== [BODY (3/3) DateTimeNow ======
  5725. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  5726. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSETimeStamp = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5727. #if PARAMETER_NORMAL_MODE == ENABLE
  5728. ///////////SHM_Read_iso2_SessionSetupRes(&ccs_exi_doc_ISO2, ShmCcsData);
  5729. #endif
  5730. // ============ Encode and Send Response Message ===========
  5731. if (send_encoded_iso2_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO2) != 0)
  5732. {
  5733. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso2_SessionSetupRes][Error]Tx encoded msg error");
  5734. errn = -1;
  5735. }
  5736. return errn;
  5737. }
  5738. /*===========================================================================
  5739. FUNCTION: Proc_din_SessionSetupReq
  5740. DESCRIPTION:
  5741. PRE-CONDITION:
  5742. INPUT:
  5743. OUTPUT:
  5744. GLOBAL VARIABLES:
  5745. 2. ccs_exi_doc_DIN
  5746. =============================================================================*/
  5747. int Proc_din_SessionSetupReq(int AcceptFd)
  5748. {
  5749. int errn = 0;
  5750. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Proc_din_SessionSetupReq]Got SessionSetupReq\n");
  5751. //Print the decoded XML Document
  5752. PRINT_XML_DOC_DIN_SessionSetupReq(&ccs_exi_doc_DIN);
  5753. //Save into Share Memory
  5754. SHM_Save_din_SessionSetupReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  5755. errn = Proc_din_SessionSetupRes(AcceptFd);
  5756. if (errn == 0)
  5757. {
  5758. //successfully send response.
  5759. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]SessionSetupRes");
  5760. }
  5761. else
  5762. {
  5763. sprintf(buf_log_evcomm,
  5764. "[Error]Proc_din_SessionSetupRes(): %d (DEC)",
  5765. errn);
  5766. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5767. }
  5768. return errn;
  5769. }
  5770. /*===========================================================================
  5771. FUNCTION: Proc_iso1_SessionSetupReq
  5772. DESCRIPTION:
  5773. PRE-CONDITION:
  5774. INPUT:
  5775. OUTPUT:
  5776. GLOBAL VARIABLES:
  5777. 2. ccs_exi_doc_ISO1
  5778. =============================================================================*/
  5779. int Proc_iso1_SessionSetupReq(int AcceptFd)
  5780. {
  5781. int errn = 0;
  5782. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Proc_iso1_SessionSetupReq]Got SessionSetupReq\n");
  5783. //Print the decoded XML Document
  5784. PRINT_XML_DOC_ISO1_SessionSetupReq(&ccs_exi_doc_ISO1);
  5785. //Save into Share Memory
  5786. SHM_Save_iso1_SessionSetupReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  5787. errn = Proc_iso1_SessionSetupRes(AcceptFd);
  5788. if (errn == 0)
  5789. {
  5790. //successfully send response.
  5791. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]SessionSetupRes");
  5792. }
  5793. else
  5794. {
  5795. sprintf(buf_log_evcomm,
  5796. "[Error]Proc_iso1_SessionSetupRes(): %d (DEC)",
  5797. errn);
  5798. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5799. }
  5800. return errn;
  5801. }
  5802. /*===========================================================================
  5803. FUNCTION: Proc_iso2_SessionSetupReq
  5804. DESCRIPTION:
  5805. PRE-CONDITION:
  5806. INPUT:
  5807. OUTPUT:
  5808. GLOBAL VARIABLES:
  5809. 2. ccs_exi_doc_ISO2
  5810. =============================================================================*/
  5811. int Proc_iso2_SessionSetupReq(int AcceptFd)
  5812. {
  5813. int errn = 0;
  5814. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Proc_iso2_SessionSetupReq]Got SessionSetupReq\n");
  5815. //Print the decoded XML Document
  5816. PRINT_XML_DOC_ISO2_SessionSetupReq(&ccs_exi_doc_ISO2);
  5817. //Save into Share Memory
  5818. SHM_Save_iso2_SessionSetupReq(ShmCcsData, &ccs_exi_doc_ISO2, ShmSysConfigAndInfo);
  5819. errn = Proc_iso2_SessionSetupRes(AcceptFd);
  5820. if (errn == 0)
  5821. {
  5822. //successfully send response.
  5823. SAVE_SYS_LOG_MSG_EVCOMM("[ISO2][V2G][Tx]SessionSetupRes");
  5824. }
  5825. else
  5826. {
  5827. sprintf(buf_log_evcomm,
  5828. "[Error]Proc_iso2_SessionSetupRes(): %d (DEC)",
  5829. errn);
  5830. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5831. }
  5832. return errn;
  5833. }
  5834. /*===========================================================================
  5835. FUNCTION: Proc_din_ServiceDiscoveryRes
  5836. DESCRIPTION:
  5837. PRE-CONDITION:
  5838. INPUT:
  5839. OUTPUT:
  5840. GLOBAL VARIABLES:
  5841. =============================================================================*/
  5842. int Proc_din_ServiceDiscoveryRes(int AcceptFd)
  5843. {
  5844. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5845. //if it is not the same, the packet should be ignored.
  5846. int i = 0;
  5847. int errn = 0;
  5848. bitstream_t v2g_tx_stream;
  5849. struct ChargingInfoData *sys;
  5850. struct ServiceDiscoveryRequest_DIN70121 *req;
  5851. struct ServiceDiscoveryResponse_DIN70121 *res;
  5852. size_t pos = 0;
  5853. v2g_tx_stream.pos = &pos;
  5854. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5855. v2g_tx_stream.data = V2GTP_Tx_buf;
  5856. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5857. req = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryRequest;
  5858. res = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryResponse;
  5859. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5860. init_dinServiceDiscoveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes);
  5861. //[1/4] Response Code
  5862. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
  5863. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_OK;
  5864. //[HEADER] Check Req SessionID
  5865. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  5866. {
  5867. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  5868. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  5869. errn = -1;
  5870. }
  5871. //Check for SequenceError
  5872. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5873. {
  5874. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  5875. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  5876. errn = -1;
  5877. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5878. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5879. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5880. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5881. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5882. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5883. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5884. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5885. }
  5886. //Detect for CP State should be 9V (State B)
  5887. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5888. {
  5889. #if CP_PROTECTION_MECHANISM == ENABLE
  5890. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5891. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5892. Update_V2G_Flow_Status(Other_Fault);
  5893. errn = -1;
  5894. sprintf(buf_log_evcomm,
  5895. "[Proc_din_ServiceDiscoveryRes]Emergency Stop by CP Error (%d)",
  5896. sys->CpState);
  5897. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5898. #else
  5899. sprintf(buf_log_evcomm,
  5900. "[Proc_din_ServiceDiscoveryRes]Emergency Stop by CP Error (%d): ignored",
  5901. sys->CpState);
  5902. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5903. #endif
  5904. }
  5905. if (sys->DC_EVSEStatus == EVSE_Shutdown /*||
  5906. sys->DC_EVSEStatus == EVSE_EmergencyShutdown*/)
  5907. {
  5908. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5909. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ServiceDiscoveryRes]shutdown by EVSE");
  5910. // errn = -1;
  5911. }
  5912. else if (/*sys->DC_EVSEStatus == EVSE_Shutdown ||*/
  5913. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5914. {
  5915. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5916. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ServiceDiscoveryRes]shutdown by EVSE");
  5917. errn = -1;
  5918. }
  5919. //Check for Permission Changing from TRUE to FALSE
  5920. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5921. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  5922. ShmInternalComm->ChargingPermission == FALSE)
  5923. {
  5924. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][ServiceDiscoveryRes]Permission OFF");
  5925. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5926. // errn = -1;
  5927. }
  5928. //[2/4] PaymentOptions
  5929. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.arrayLen = 1u;
  5930. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.array[0] = dinpaymentOptionType_ExternalPayment; //1
  5931. //[3/4] Charge Service
  5932. res->ChargeService_DIN70121.Services.ServiceTag.ServiceID = 1;
  5933. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceID = (unsigned short) res->ChargeService_DIN70121.Services.ServiceTag.ServiceID;
  5934. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceCategory = dinserviceCategoryType_EVCharging;
  5935. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.FreeService = 1; //[Joseph] for test
  5936. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.EnergyTransferType = dinEVSESupportedEnergyTransferType_DC_extended;
  5937. //[4/4] Service List (null, not be uesed for now.)
  5938. //#if PARAMETER_NORMAL_MODE == ENABLE
  5939. ///////////////SHM_Read_din_ServiceDiscoveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  5940. //#endif
  5941. // ============ Encode and Send Response Message ===========
  5942. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5943. {
  5944. errn = -1;
  5945. }
  5946. return errn;
  5947. }
  5948. /*===========================================================================
  5949. FUNCTION: Proc_iso1_ServiceDiscoveryRes
  5950. DESCRIPTION:
  5951. PRE-CONDITION:
  5952. INPUT:
  5953. OUTPUT:
  5954. GLOBAL VARIABLES:
  5955. =============================================================================*/
  5956. int Proc_iso1_ServiceDiscoveryRes(int AcceptFd)
  5957. {
  5958. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5959. //if it is not the same, the packet should be ignored.
  5960. int i = 0;
  5961. int errn = 0;
  5962. bitstream_t v2g_tx_stream;
  5963. struct ChargingInfoData *sys;
  5964. struct ServiceDiscoveryRequest_ISO15118_2014 *req;
  5965. struct ServiceDiscoveryResponse_ISO15118_2014 *res;
  5966. size_t pos = 0;
  5967. v2g_tx_stream.pos = &pos;
  5968. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5969. v2g_tx_stream.data = V2GTP_Tx_buf;
  5970. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5971. req = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryRequest;
  5972. res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryResponse;
  5973. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5974. init_iso1ServiceDiscoveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes);
  5975. //[1/4] Response Code
  5976. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
  5977. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_OK;
  5978. //[HEADER] Check Req SessionID
  5979. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  5980. {
  5981. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  5982. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  5983. errn = -1;
  5984. }
  5985. //Check for SequenceError
  5986. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5987. {
  5988. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5989. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  5990. errn = -1;
  5991. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5992. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5993. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5994. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5995. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5996. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5997. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5998. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5999. }
  6000. //Detect for CP State should be 9V (State B)
  6001. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6002. {
  6003. #if CP_PROTECTION_MECHANISM == ENABLE
  6004. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  6005. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6006. Update_V2G_Flow_Status(Other_Fault);
  6007. errn = -1;
  6008. sprintf(buf_log_evcomm,
  6009. "[Proc_iso1_ServiceDiscoveryRes]Emergency Stop by CP Error (%d)",
  6010. sys->CpState);
  6011. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6012. #else
  6013. sprintf(buf_log_evcomm,
  6014. "[Proc_iso1_ServiceDiscoveryRes]Emergency Stop by CP Error (%d): ignored",
  6015. sys->CpState);
  6016. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6017. #endif
  6018. }
  6019. if (/*sys->DC_EVSEStatus == EVSE_Shutdown ||*/
  6020. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6021. {
  6022. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  6023. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ServiceDiscoveryRes]shutdown by EVSE");
  6024. errn = -1;
  6025. }
  6026. else if (sys->DC_EVSEStatus == EVSE_Shutdown /*||
  6027. sys->DC_EVSEStatus == EVSE_EmergencyShutdown*/)
  6028. {
  6029. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  6030. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ServiceDiscoveryRes]shutdown by EVSE");
  6031. // errn = -1;
  6032. }
  6033. //Check for Permission Changing from TRUE to FALSE
  6034. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  6035. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  6036. ShmInternalComm->ChargingPermission == FALSE)
  6037. {
  6038. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO1][ServiceDiscoveryRes]Permission OFF");
  6039. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  6040. // errn = -1;
  6041. }
  6042. //[2/4] PaymentOptionList
  6043. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.arrayLen = 1u;
  6044. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.array[0] = iso1paymentOptionType_ExternalPayment; //1
  6045. #ifdef SUPPORT_ISO15118_PnC
  6046. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.arrayLen = 2u;
  6047. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.array[1] = iso1paymentOptionType_Contract; //0
  6048. #endif
  6049. //[3/4] Charge Service
  6050. res->ChargeService.Services.ServiceID = 1;
  6051. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceID = (unsigned short) res->ChargeService.Services.ServiceID;
  6052. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName_isUsed = 1;
  6053. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName.charactersLen = strlen("AC_DC_Charging");//AC_Charging
  6054. writeStringToEXIString("AC_DC_Charging", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName.characters);
  6055. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceCategory = iso1serviceCategoryType_EVCharging;
  6056. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.FreeService = 1;
  6057. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.arrayLen = 1u; //[ISO1] max = 6
  6058. switch (ShmCcsData->EnergyTransferMode)
  6059. {
  6060. case DC_extended:
  6061. {
  6062. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_DC_extended;
  6063. break;
  6064. }
  6065. case AC_single_phase_core:
  6066. {
  6067. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_AC_single_phase_core;
  6068. break;
  6069. }
  6070. case AC_three_phase_core:
  6071. {
  6072. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_AC_three_phase_core;
  6073. break;
  6074. }
  6075. default:
  6076. {
  6077. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_DC_extended;
  6078. sprintf(buf_log_evcomm,
  6079. "[ISO1][ServiceDiscoveryRes][Warning]unexpected EnergyTransferMode(%d)",
  6080. ShmCcsData->EnergyTransferMode);
  6081. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6082. break;
  6083. }
  6084. }
  6085. //[4/4] Service List
  6086. i=0;
  6087. #ifdef SUPPORT_ISO15118_PnC
  6088. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList_isUsed = 1u;
  6089. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.arrayLen=i;
  6090. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].ServiceID = 2;
  6091. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].ServiceName_isUsed = 1;
  6092. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].ServiceName.charactersLen = strlen("Certificate");
  6093. writeStringToEXIString("Certificate", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].ServiceName.characters);
  6094. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].ServiceCategory = iso1serviceCategoryType_ContractCertificate;
  6095. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].FreeService = 0;
  6096. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.arrayLen++;
  6097. i++;
  6098. #endif
  6099. #ifdef SUPPORT_ISO15118_VAS
  6100. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList_isUsed = 1u;
  6101. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.arrayLen=i;
  6102. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].ServiceID = 3;
  6103. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].ServiceName_isUsed = 1;
  6104. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].ServiceName.charactersLen = strlen("InternetAccess");
  6105. writeStringToEXIString("InternetAccess", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].ServiceName.characters);
  6106. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].ServiceCategory = iso1serviceCategoryType_Internet;
  6107. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].FreeService = 0;
  6108. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.arrayLen++;
  6109. i++;
  6110. #endif
  6111. // ============ Encode and Send Response Message ===========
  6112. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  6113. {
  6114. errn = -1;
  6115. }
  6116. return errn;
  6117. }
  6118. /*===========================================================================
  6119. FUNCTION: Proc_iso1_ServiceDetailReq
  6120. DESCRIPTION:
  6121. PRE-CONDITION:
  6122. INPUT:
  6123. OUTPUT:
  6124. GLOBAL VARIABLES:
  6125. =============================================================================*/
  6126. int Proc_iso1_ServiceDetailReq(int AcceptFd)
  6127. {
  6128. int errn = 0;
  6129. //Save into Share Memory
  6130. SHM_Save_iso1_ServiceDetailReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  6131. errn = Proc_iso1_ServiceDetailRes(AcceptFd);
  6132. if (errn == 0)
  6133. {
  6134. //send response successfully.
  6135. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]ServiceDetailRes");
  6136. }
  6137. else
  6138. {
  6139. sprintf(buf_log_evcomm,
  6140. "[Error][SeccComm][Proc_iso1_ServiceDetailReq]Proc_iso1_ServiceDetailRes(): %d (DEC)",
  6141. errn
  6142. );
  6143. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6144. }
  6145. return errn;
  6146. }
  6147. /*===========================================================================
  6148. FUNCTION: Proc_iso1_ServiceDetailRes
  6149. DESCRIPTION:
  6150. PRE-CONDITION:
  6151. INPUT:
  6152. OUTPUT:
  6153. GLOBAL VARIABLES:
  6154. =============================================================================*/
  6155. int Proc_iso1_ServiceDetailRes(int AcceptFd)
  6156. {
  6157. int i = 0;
  6158. int errn = 0;
  6159. bitstream_t v2g_tx_stream;
  6160. struct ChargingInfoData *sys;
  6161. struct ServiceDetailRequest_ISO15118_2014 *req;
  6162. struct ServiceDetailResponse_ISO15118_2014 *res;
  6163. size_t pos = 0;
  6164. v2g_tx_stream.pos = &pos;
  6165. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6166. v2g_tx_stream.data = V2GTP_Tx_buf;
  6167. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6168. req = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDetailRequest;
  6169. res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDetailResponse;
  6170. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6171. init_iso1ServiceDetailResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes);
  6172. //[1/4] Response Code
  6173. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes_isUsed = 1u;
  6174. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ResponseCode = iso1responseCodeType_OK;
  6175. //[HEADER] Check Req SessionID
  6176. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  6177. {
  6178. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  6179. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  6180. errn = -1;
  6181. }
  6182. //Check for SequenceError
  6183. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6184. {
  6185. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  6186. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  6187. errn = -1;
  6188. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6189. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6190. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6191. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6192. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6193. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6194. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6195. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6196. }
  6197. //Detect for CP State should be 9V (State B)
  6198. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6199. {
  6200. #if CP_PROTECTION_MECHANISM == ENABLE
  6201. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ResponseCode = iso1responseCodeType_FAILED;
  6202. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6203. Update_V2G_Flow_Status(Other_Fault);
  6204. errn = -1;
  6205. sprintf(buf_log_evcomm,
  6206. "[ServiceDetailRes]Emergency Stop by CP Error (%d)",
  6207. sys->CpState);
  6208. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6209. #else
  6210. sprintf(buf_log_evcomm,
  6211. "[ServiceDetailRes]Emergency Stop by CP Error (%d): ignored",
  6212. sys->CpState);
  6213. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6214. #endif
  6215. }
  6216. if (/*sys->DC_EVSEStatus == EVSE_Shutdown ||*/
  6217. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6218. {
  6219. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ResponseCode = iso1responseCodeType_FAILED;
  6220. SAVE_SYS_LOG_MSG_EVCOMM("[ServiceDetailRes]shutdown by EVSE");
  6221. errn = -1;
  6222. }
  6223. else if (sys->DC_EVSEStatus == EVSE_Shutdown /*||
  6224. sys->DC_EVSEStatus == EVSE_EmergencyShutdown*/)
  6225. {
  6226. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ResponseCode = iso1responseCodeType_FAILED;
  6227. SAVE_SYS_LOG_MSG_EVCOMM("[ServiceDetailRes]shutdown by EVSE");
  6228. // errn = -1;
  6229. }
  6230. //Check for Permission Changing from TRUE to FALSE
  6231. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  6232. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  6233. ShmInternalComm->ChargingPermission == FALSE)
  6234. {
  6235. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO1][ServiceDetailRes]Permission OFF");
  6236. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDetailRes.ResponseCode = iso1responseCodeType_FAILED;
  6237. // errn = -1;
  6238. }
  6239. switch (req->ServiceID)
  6240. {
  6241. #ifdef SUPPORT_ISO15118_PnC
  6242. case 2:
  6243. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceID = req->ServiceID;
  6244. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList_isUsed = 1;
  6245. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.arrayLen = 2;//Installation(1), Update(2)
  6246. //=============Set ParameterSet===================
  6247. {
  6248. unsigned char ServiceName[16];
  6249. for(int j=0;j<ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.arrayLen;j++)
  6250. {
  6251. memset(ServiceName,0,sizeof(ServiceName));
  6252. switch (j)
  6253. {
  6254. case 0://ftp with port 20
  6255. strcpy(ServiceName,"Installation");
  6256. break;
  6257. case 1://ftp with port 21
  6258. strcpy(ServiceName,"Update");
  6259. break;
  6260. default:
  6261. break;
  6262. }
  6263. if(strlen(ServiceName)>0)
  6264. {
  6265. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].ParameterSetID=j+1;
  6266. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.arrayLen=1;//Service
  6267. //Name= Protocol
  6268. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[0].Name.charactersLen= strlen("Service");
  6269. writeStringToEXIString("Service", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[0].Name.characters);
  6270. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[0].stringValue_isUsed=1;
  6271. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[0].stringValue.charactersLen=strlen(ServiceName);
  6272. writeStringToEXIString(ServiceName, ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[0].stringValue.characters);
  6273. }
  6274. else
  6275. break;
  6276. }//for
  6277. }
  6278. break;
  6279. #endif
  6280. #ifdef SUPPORT_ISO15118_VAS
  6281. case 3:
  6282. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceID = req->ServiceID;
  6283. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList_isUsed = 1;
  6284. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.arrayLen = 4;//ftp(1), ftp(2), http(3), https(4)
  6285. //=============Set ParameterSet===================
  6286. {
  6287. unsigned char ProtocolName[16];
  6288. int ProtocolPort;
  6289. for(int j=0;j<ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.arrayLen;j++)
  6290. {
  6291. memset(ProtocolName,0,sizeof(ProtocolName));
  6292. switch (j)
  6293. {
  6294. case 0://ftp with port 20
  6295. strcpy(ProtocolName,"ftp");
  6296. ProtocolPort=20;
  6297. break;
  6298. case 1://ftp with port 21
  6299. strcpy(ProtocolName,"ftp");
  6300. ProtocolPort=21;
  6301. break;
  6302. case 2://http with port 80
  6303. strcpy(ProtocolName,"http");
  6304. ProtocolPort=80;
  6305. break;
  6306. case 3://https with port 443
  6307. strcpy(ProtocolName,"https");
  6308. ProtocolPort=443;
  6309. break;
  6310. default:
  6311. break;
  6312. }
  6313. if(strlen(ProtocolName)>0)
  6314. {
  6315. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].ParameterSetID=j+1;
  6316. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.arrayLen=2;//protocol and port
  6317. //Name= Protocol
  6318. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[0].Name.charactersLen= strlen("Protocol");
  6319. writeStringToEXIString("Protocol", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[0].Name.characters);
  6320. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[0].stringValue_isUsed=1;
  6321. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[0].stringValue.charactersLen=strlen(ProtocolName);
  6322. writeStringToEXIString(ProtocolName, ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[0].stringValue.characters);
  6323. //Name= Port
  6324. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[1].Name.charactersLen= strlen("Port");
  6325. writeStringToEXIString("Port", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[1].Name.characters);
  6326. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[1].intValue_isUsed=1;
  6327. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[j].Parameter.array[1].intValue=ProtocolPort;
  6328. }
  6329. else
  6330. break;
  6331. }//for
  6332. }
  6333. /*
  6334. //=============http,ParameterSetID=3===================
  6335. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].ParameterSetID=3;//http
  6336. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.arrayLen=2;//protocol and port
  6337. //Name= Protocol, value= "HTTP"
  6338. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.charactersLen= strlen("Protocol");
  6339. writeStringToEXIString("Protocol", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters);
  6340. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].stringValue_isUsed=1;
  6341. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].stringValue.charactersLen=strlen("http");
  6342. writeStringToEXIString("http", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].stringValue.characters);
  6343. //Name= Port, value= 80
  6344. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.charactersLen= strlen("Port");
  6345. writeStringToEXIString("Port", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.characters);
  6346. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].intValue_isUsed=1;
  6347. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].intValue=80;
  6348. //==================https,ParameterSetID=4=====================
  6349. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].ParameterSetID=4;//https
  6350. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.arrayLen=2;//protocol and port
  6351. //Name= Protocol, value= "HTTP"
  6352. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.charactersLen= strlen("Protocol");
  6353. writeStringToEXIString("Protocol", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters);
  6354. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].stringValue_isUsed=1;
  6355. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].stringValue.charactersLen=strlen("https");
  6356. writeStringToEXIString("https", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].stringValue.characters);
  6357. //Name= Port, value= 443
  6358. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[1].Name.charactersLen= strlen("Port");
  6359. writeStringToEXIString("Port", ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[1].Name.characters);
  6360. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[1].intValue_isUsed=1;
  6361. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[1].intValue=443;
  6362. */
  6363. break;
  6364. #endif
  6365. default:
  6366. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceID = req->ServiceID;
  6367. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ServiceParameterList_isUsed = 0;
  6368. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDetailRes.ResponseCode = iso1responseCodeType_FAILED_ServiceIDInvalid;
  6369. break;
  6370. }
  6371. // ============ Encode and Send Response Message ===========
  6372. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  6373. {
  6374. errn = -1;
  6375. }
  6376. return errn;
  6377. }
  6378. /*===========================================================================
  6379. FUNCTION: Proc_din_ServiceDiscoveryReq
  6380. DESCRIPTION:
  6381. PRE-CONDITION:
  6382. INPUT:
  6383. OUTPUT:
  6384. GLOBAL VARIABLES:
  6385. =============================================================================*/
  6386. int Proc_din_ServiceDiscoveryReq(int AcceptFd)
  6387. {
  6388. int errn = 0;
  6389. DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_din_ServiceDiscoveryReq]Got ServiceDiscoveryReq\n");
  6390. //Print the decoded XML Document
  6391. PRINT_XML_DOC_DIN_ServiceDiscoveryReq(&ccs_exi_doc_DIN);
  6392. //Save into Share Memory
  6393. SHM_Save_din_ServiceDiscoveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  6394. errn = Proc_din_ServiceDiscoveryRes(AcceptFd);
  6395. if (errn == 0)
  6396. {
  6397. //send response successfully.
  6398. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]ServiceDiscoveryRes");
  6399. }
  6400. else
  6401. {
  6402. sprintf(buf_log_evcomm,
  6403. "[Error][SeccComm][Proc_din_ServiceDiscoveryReq]Proc_din_ServiceDiscoveryRes(): %d (DEC)",
  6404. errn
  6405. );
  6406. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6407. }
  6408. return errn;
  6409. }
  6410. /*===========================================================================
  6411. FUNCTION: Proc_iso1_ServiceDiscoveryReq
  6412. DESCRIPTION:
  6413. PRE-CONDITION:
  6414. INPUT:
  6415. OUTPUT:
  6416. GLOBAL VARIABLES:
  6417. =============================================================================*/
  6418. int Proc_iso1_ServiceDiscoveryReq(int AcceptFd)
  6419. {
  6420. int errn = 0;
  6421. DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_iso1_ServiceDiscoveryReq]Got ServiceDiscoveryReq\n");
  6422. //Print the decoded XML Document
  6423. PRINT_XML_DOC_ISO1_ServiceDiscoveryReq(&ccs_exi_doc_ISO1);
  6424. //Save into Share Memory
  6425. SHM_Save_iso1_ServiceDiscoveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  6426. errn = Proc_iso1_ServiceDiscoveryRes(AcceptFd);
  6427. if (errn == 0)
  6428. {
  6429. //send response successfully.
  6430. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]ServiceDiscoveryRes");
  6431. }
  6432. else
  6433. {
  6434. sprintf(buf_log_evcomm,
  6435. "[Error][SeccComm][Proc_iso1_ServiceDiscoveryReq]Proc_iso1_ServiceDiscoveryRes(): %d (DEC)",
  6436. errn
  6437. );
  6438. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6439. }
  6440. return errn;
  6441. }
  6442. /*===========================================================================
  6443. FUNCTION: Proc_din_ServiceAndPaymentSelectionRes
  6444. DESCRIPTION:
  6445. PRE-CONDITION:
  6446. INPUT:
  6447. OUTPUT:
  6448. GLOBAL VARIABLES:
  6449. =============================================================================*/
  6450. int Proc_din_ServiceAndPaymentSelectionRes(int AcceptFd)
  6451. {
  6452. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6453. //if it is not the same, the packet should be ignored.
  6454. int i = 0;
  6455. int errn = 0;
  6456. bitstream_t v2g_tx_stream;
  6457. struct ServiceAndPaymentSelectionRequest_DIN70121 *req;
  6458. struct ServiceAndPaymentSelectionResponse_DIN70121 *res;
  6459. struct ServiceDiscoveryResponse_DIN70121 *sd_res;
  6460. struct ChargingInfoData *sys;
  6461. size_t pos = 0;
  6462. v2g_tx_stream.pos = &pos;
  6463. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6464. v2g_tx_stream.data = V2GTP_Tx_buf;
  6465. req = &ShmCcsData->V2GMessage_DIN70121.ServiceAndPaymentSelectionRequest;
  6466. res = &ShmCcsData->V2GMessage_DIN70121.ServiceAndPaymentSelectionResponse;
  6467. sd_res = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryResponse;
  6468. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6469. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  6470. init_dinServicePaymentSelectionResType(&ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes);
  6471. //[1/1] Response Code
  6472. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes_isUsed = 1u;
  6473. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_OK;
  6474. //[HEADER] Check Req SessionID
  6475. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  6476. {
  6477. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  6478. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  6479. errn = -1;
  6480. }
  6481. //Check for SequenceError
  6482. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6483. {
  6484. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  6485. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  6486. errn = -1;
  6487. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6488. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6489. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6490. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6491. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6492. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6493. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6494. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6495. }
  6496. //Check for SelectedPaymentOption (TC_SECC_VTB_ServicePaymentSelection_007)
  6497. if (req->SelectedPaymentOption != dinpaymentOptionType_ExternalPayment) //1
  6498. {
  6499. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_PaymentSelectionInvalid;
  6500. sprintf(buf_log_evcomm,
  6501. "[ERROR]unexpected SelectedPaymentOption(%d) => End_Process (EIM only, no PnC, yet.)",
  6502. req->SelectedPaymentOption);
  6503. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6504. errn = -1;
  6505. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6506. //CCS_SECC_ResponseCode_FAILED_Payment SelectionInvalid (023762)
  6507. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6508. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6509. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6510. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6511. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6512. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  6513. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6514. }
  6515. //Check for ServiceID (TC_SECC_VTB_ServicePaymentSelection_004)
  6516. if (req->SelectedServiceList.SelectedService[0].ServiceID != sd_res->ChargeService_DIN70121.Services.ServiceTag.ServiceID)
  6517. {
  6518. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_ServiceSelectionInvalid; //8
  6519. sprintf(buf_log_evcomm,
  6520. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  6521. req->SelectedServiceList.SelectedService[0].ServiceID);
  6522. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6523. errn = -1;
  6524. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6525. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  6526. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6527. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6528. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6529. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6530. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6531. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  6532. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6533. }
  6534. //Detect for CP State should be 9V (State B)
  6535. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6536. {
  6537. #if CP_PROTECTION_MECHANISM == ENABLE
  6538. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  6539. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6540. Update_V2G_Flow_Status(Other_Fault);
  6541. errn = -1;
  6542. sprintf(buf_log_evcomm,
  6543. "[Proc_din_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d)",
  6544. sys->CpState);
  6545. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6546. #else
  6547. sprintf(buf_log_evcomm,
  6548. "[Proc_din_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d): ignored due to function is disabled",
  6549. sys->CpState);
  6550. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6551. #endif
  6552. }
  6553. if (sys->DC_EVSEStatus == EVSE_Shutdown /*||
  6554. sys->DC_EVSEStatus == EVSE_EmergencyShutdown*/)
  6555. {
  6556. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ServiceAndPaymentSelectionRes]shutdown by EVSE");
  6557. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  6558. // errn = -1;
  6559. }
  6560. else if (/*sys->DC_EVSEStatus == EVSE_Shutdown ||*/
  6561. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6562. {
  6563. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ServiceAndPaymentSelectionRes]shutdown by EVSE");
  6564. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  6565. errn = -1;
  6566. }
  6567. //Check for Permission Changing from TRUE to FALSE
  6568. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  6569. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  6570. ShmInternalComm->ChargingPermission == FALSE)
  6571. {
  6572. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][ServicePaymentSelectionRes]Permission OFF");
  6573. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  6574. //errn = -1;
  6575. }
  6576. // ============ Encode and Send Response Message ===========
  6577. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  6578. {
  6579. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ServiceAndPaymentSelectionRes]Tx encoded msg error");
  6580. errn = -1;
  6581. }
  6582. return errn;
  6583. }
  6584. /*===========================================================================
  6585. FUNCTION: Proc_iso1_ServiceAndPaymentSelectionRes
  6586. DESCRIPTION:
  6587. PRE-CONDITION:
  6588. INPUT:
  6589. OUTPUT:
  6590. GLOBAL VARIABLES:
  6591. =============================================================================*/
  6592. int Proc_iso1_ServiceAndPaymentSelectionRes(int AcceptFd)
  6593. {
  6594. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6595. //if it is not the same, the packet should be ignored.
  6596. int i = 0;
  6597. int errn = 0;
  6598. bitstream_t v2g_tx_stream;
  6599. struct ServiceAndPaymentSelectionRequest_ISO15118_2014 *req;
  6600. struct ServiceAndPaymentSelectionResponse_ISO15118_2014 *res;
  6601. struct ServiceDiscoveryResponse_ISO15118_2014 *sd_res;
  6602. static struct ChargingInfoData *sys;
  6603. size_t pos = 0;
  6604. v2g_tx_stream.pos = &pos;
  6605. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6606. v2g_tx_stream.data = V2GTP_Tx_buf;
  6607. req = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceAndPaymentSelectionRequest;
  6608. res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceAndPaymentSelectionResponse;
  6609. sd_res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryResponse;
  6610. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6611. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6612. init_iso1PaymentServiceSelectionResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes);
  6613. //[1/1] Response Code
  6614. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes_isUsed = 1u;
  6615. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_OK;
  6616. //[HEADER] Check Req SessionID
  6617. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  6618. {
  6619. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  6620. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  6621. errn = -1;
  6622. }
  6623. //Check for SequenceError
  6624. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6625. {
  6626. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  6627. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  6628. errn = -1;
  6629. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6630. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6631. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6632. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6633. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6634. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6635. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6636. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6637. }
  6638. #ifdef SUPPORT_ISO15118_PnC
  6639. if (req->SelectedPaymentOption > iso1paymentOptionType_ExternalPayment) //1
  6640. {
  6641. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_PaymentSelectionInvalid;
  6642. sprintf(buf_log_evcomm,
  6643. "[ERROR]unexpected SelectedPaymentOption(%d) => End_Process (EIM only, no PnC, yet.)",
  6644. req->SelectedPaymentOption);
  6645. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6646. errn = -1;
  6647. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6648. //CCS_SECC_ResponseCode_FAILED_Payment SelectionInvalid (023762)
  6649. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6650. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6651. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6652. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6653. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6654. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  6655. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6656. }
  6657. #else
  6658. //Check for SelectedPaymentOption (TC_SECC_VTB_ServicePaymentSelection_007)
  6659. if (req->SelectedPaymentOption != iso1paymentOptionType_ExternalPayment) //1
  6660. {
  6661. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_PaymentSelectionInvalid;
  6662. sprintf(buf_log_evcomm,
  6663. "[ERROR]unexpected SelectedPaymentOption(%d) => End_Process (EIM only, no PnC, yet.)",
  6664. req->SelectedPaymentOption);
  6665. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6666. errn = -1;
  6667. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6668. //CCS_SECC_ResponseCode_FAILED_Payment SelectionInvalid (023762)
  6669. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6670. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6671. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6672. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6673. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6674. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  6675. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6676. }
  6677. #endif
  6678. for(i=0;i<req->SelectedServiceList.SelectedServiceLen;i++)
  6679. {
  6680. switch(req->SelectedServiceList.SelectedService[i].ServiceID)
  6681. {
  6682. case 1:
  6683. break;
  6684. case 2:
  6685. #ifndef SUPPORT_ISO15118_PnC
  6686. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_ServiceSelectionInvalid; //8
  6687. sprintf(buf_log_evcomm,
  6688. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  6689. req->SelectedServiceList.SelectedService[0].ServiceID);
  6690. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6691. errn = -1;
  6692. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6693. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  6694. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6695. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6696. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6697. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6698. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6699. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  6700. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6701. #endif
  6702. break;
  6703. case 3:
  6704. #ifndef SUPPORT_ISO15118_VAS
  6705. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_ServiceSelectionInvalid; //8
  6706. sprintf(buf_log_evcomm,
  6707. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  6708. req->SelectedServiceList.SelectedService[0].ServiceID);
  6709. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6710. errn = -1;
  6711. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6712. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  6713. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6714. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6715. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6716. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6717. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6718. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  6719. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6720. #endif
  6721. break;
  6722. default:
  6723. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_ServiceSelectionInvalid; //8
  6724. sprintf(buf_log_evcomm,
  6725. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  6726. req->SelectedServiceList.SelectedService[0].ServiceID);
  6727. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6728. errn = -1;
  6729. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6730. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  6731. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6732. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6733. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6734. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6735. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6736. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  6737. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6738. break;
  6739. }
  6740. }
  6741. //Detect for CP State should be 9V (State B)
  6742. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6743. {
  6744. #if CP_PROTECTION_MECHANISM == ENABLE
  6745. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  6746. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6747. Update_V2G_Flow_Status(Other_Fault);
  6748. errn = -1;
  6749. sprintf(buf_log_evcomm,
  6750. "[Proc_iso1_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d)",
  6751. sys->CpState);
  6752. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6753. #else
  6754. sprintf(buf_log_evcomm,
  6755. "[Proc_iso1_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d): ignored due to function is disabled",
  6756. sys->CpState);
  6757. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6758. #endif
  6759. }
  6760. if (sys->DC_EVSEStatus == EVSE_Shutdown /*||
  6761. sys->DC_EVSEStatus == EVSE_EmergencyShutdown*/)
  6762. {
  6763. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ServiceAndPaymentSelectionRes]shutdown by EVSE");
  6764. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  6765. //errn = -1;
  6766. }
  6767. else if (/*sys->DC_EVSEStatus == EVSE_Shutdown ||*/
  6768. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6769. {
  6770. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ServiceAndPaymentSelectionRes]shutdown by EVSE");
  6771. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  6772. errn = -1;
  6773. }
  6774. //Check for Permission Changing from TRUE to FALSE
  6775. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  6776. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  6777. ShmInternalComm->ChargingPermission == FALSE)
  6778. {
  6779. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO1][PaymentServiceSelectionRes]Permission OFF");
  6780. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  6781. // errn = -1;
  6782. }
  6783. // ============ Encode and Send Response Message ===========
  6784. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  6785. {
  6786. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ServiceAndPaymentSelectionRes]Tx encoded msg error");
  6787. errn = -1;
  6788. }
  6789. return errn;
  6790. }
  6791. /*===========================================================================
  6792. FUNCTION: Proc_din_ServiceAndPaymentSelectionReq
  6793. DESCRIPTION:
  6794. PRE-CONDITION:
  6795. INPUT:
  6796. OUTPUT:
  6797. GLOBAL VARIABLES:
  6798. =============================================================================*/
  6799. int Proc_din_ServiceAndPaymentSelectionReq(int AcceptFd)
  6800. {
  6801. int errn = 0;
  6802. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][Proc_din_ServiceAndPaymentSelectionReq]Got ServiceAndPaymentSelectionReq");
  6803. //Print the decoded XML Document
  6804. PRINT_XML_DOC_DIN_ServiceAndPaymentSelectionReq(&ccs_exi_doc_DIN);
  6805. //Save into Share Memory
  6806. SHM_Save_din_ServiceAndPaymentSelectionReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  6807. errn = Proc_din_ServiceAndPaymentSelectionRes(AcceptFd);
  6808. if (errn == 0)
  6809. {
  6810. //send response successfully.
  6811. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]ServiceAndPaymentSelectionRes");
  6812. }
  6813. else
  6814. {
  6815. sprintf(buf_log_evcomm,
  6816. "[Error][Proc_iso1_ServiceAndPaymentSelectionReq]Proc_iso1_ServiceAndPaymentSelectionRes(): %d (DEC)",
  6817. errn);
  6818. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6819. }
  6820. return errn;
  6821. }
  6822. /*===========================================================================
  6823. FUNCTION: Proc_iso1_ServiceAndPaymentSelectionReq
  6824. DESCRIPTION:
  6825. PRE-CONDITION:
  6826. INPUT:
  6827. OUTPUT:
  6828. GLOBAL VARIABLES:
  6829. =============================================================================*/
  6830. int Proc_iso1_ServiceAndPaymentSelectionReq(int AcceptFd)
  6831. {
  6832. int errn = 0;
  6833. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][Proc_iso1_ServiceAndPaymentSelectionReq]Got ServiceAndPaymentSelectionReq");
  6834. //Print the decoded XML Document
  6835. PRINT_XML_DOC_ISO1_ServiceAndPaymentSelectionReq(&ccs_exi_doc_ISO1);
  6836. //Save into Share Memory
  6837. SHM_Save_iso1_ServiceAndPaymentSelectionReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  6838. errn = Proc_iso1_ServiceAndPaymentSelectionRes(AcceptFd);
  6839. if (errn == 0)
  6840. {
  6841. //send response successfully.
  6842. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]ServiceAndPaymentSelectionRes");
  6843. }
  6844. else
  6845. {
  6846. sprintf(buf_log_evcomm,
  6847. "[Error][Proc_iso1_ServiceAndPaymentSelectionReq]Proc_iso1_ServiceAndPaymentSelectionRes(): %d (DEC)",
  6848. errn);
  6849. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6850. }
  6851. return errn;
  6852. }
  6853. /*===========================================================================
  6854. FUNCTION: Proc_din_ContractAuthenticationRes
  6855. DESCRIPTION:
  6856. PRE-CONDITION:
  6857. INPUT:
  6858. OUTPUT:
  6859. GLOBAL VARIABLES:
  6860. =============================================================================*/
  6861. int Proc_din_ContractAuthenticationRes(int AcceptFd)
  6862. {
  6863. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6864. //if it is not the same, the packet should be ignored.
  6865. int i = 0;
  6866. int errn = 0;
  6867. bitstream_t v2g_tx_stream;
  6868. static struct ChargingInfoData *sys;
  6869. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6870. size_t pos = 0;
  6871. v2g_tx_stream.pos = &pos;
  6872. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6873. v2g_tx_stream.data = V2GTP_Tx_buf;
  6874. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  6875. init_dinContractAuthenticationResType(&ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes);
  6876. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes_isUsed = 1u;
  6877. //[BODY (1/2)] ResponseCode
  6878. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_OK;
  6879. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Ongoing; //0
  6880. //[HEADER] Check Req SessionID
  6881. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  6882. {
  6883. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  6884. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  6885. errn = -1;
  6886. }
  6887. //Check for SequenceError
  6888. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6889. {
  6890. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  6891. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  6892. errn = -1;
  6893. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6894. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6895. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6896. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6897. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6898. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6899. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6900. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6901. }
  6902. //Detect for CP State should be 9V (State B)
  6903. #if CP_PROTECTION_MECHANISM == ENABLE
  6904. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6905. {
  6906. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6907. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6908. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6909. Update_V2G_Flow_Status(Other_Fault);
  6910. errn = -1;
  6911. sprintf(buf_log_evcomm,
  6912. "[Proc_din_ContractAuthenticationRes]Emergency Stop by CP Error (%d)",
  6913. sys->CpState);
  6914. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6915. }
  6916. #endif
  6917. //Check for CSU command of "Stop by EVSE"
  6918. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6919. {
  6920. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6921. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6922. // errn = -1;
  6923. }
  6924. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6925. {
  6926. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6927. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6928. errn = -1;
  6929. }
  6930. //[BODY (2/2)] EVSEProcessing
  6931. if(ShmInternalComm->ChargingPermission == TRUE)
  6932. {
  6933. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished; //0
  6934. SAVE_SYS_LOG_MSG_EVCOMM("CSU Permission: OK");
  6935. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  6936. {
  6937. //Set PWM as 5% (for SLAC first case)
  6938. SAVE_SYS_LOG_MSG_EVCOMM("Set PWM as 5%%");
  6939. SwitchCpStateE(DISABLE);
  6940. OutputCpPwmDuty(5);
  6941. }
  6942. #endif
  6943. }
  6944. //Check for Permission Changing from TRUE to FALSE
  6945. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  6946. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  6947. ShmInternalComm->ChargingPermission == FALSE)
  6948. {
  6949. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][ContractAuthenticationRes]Permission OFF");
  6950. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6951. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6952. // errn = -1;
  6953. }
  6954. #if PARAMETER_NORMAL_MODE == ENABLE
  6955. ////////////SHM_Read_din_ContractAuthenticationRes(&ccs_exi_doc_DIN, ShmCcsData);
  6956. #endif
  6957. // ============ Encode and Send Response Message ===========
  6958. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  6959. {
  6960. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  6961. errn = -1;
  6962. }
  6963. return errn;
  6964. }
  6965. /*===========================================================================
  6966. FUNCTION: Proc_iso1_AuthorizationRes
  6967. DESCRIPTION:
  6968. PRE-CONDITION:
  6969. INPUT:
  6970. OUTPUT:
  6971. GLOBAL VARIABLES:
  6972. =============================================================================*/
  6973. int Proc_iso1_AuthorizationRes(int AcceptFd)
  6974. {
  6975. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6976. //if it is not the same, the packet should be ignored.
  6977. int i = 0;
  6978. int errn = 0;
  6979. bitstream_t v2g_tx_stream;
  6980. static struct ChargingInfoData *sys;
  6981. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6982. size_t pos = 0;
  6983. v2g_tx_stream.pos = &pos;
  6984. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6985. v2g_tx_stream.data = V2GTP_Tx_buf;
  6986. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6987. init_iso1AuthorizationResType(&ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes);
  6988. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes_isUsed = 1u;
  6989. //[BODY (1/2)] ResponseCode
  6990. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_OK;
  6991. /*+++ 20200808, vern, EVSEProcessing should be waiting for Customer during authrization +++*/
  6992. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Ongoing_WaitingForCustomerInteraction; //0
  6993. /*--- 20200808, vern, should be waiting for Customer during authrization ---*/
  6994. //[HEADER] Check Req SessionID
  6995. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  6996. {
  6997. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  6998. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  6999. errn = -1;
  7000. }
  7001. //Check for SequenceError
  7002. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7003. {
  7004. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  7005. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  7006. errn = -1;
  7007. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7008. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7009. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7010. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7011. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7012. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7013. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7014. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7015. }
  7016. //Detect for CP State should be 9V (State B)
  7017. #if CP_PROTECTION_MECHANISM == ENABLE
  7018. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  7019. {
  7020. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED;
  7021. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  7022. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7023. Update_V2G_Flow_Status(Other_Fault);
  7024. errn = -1;
  7025. sprintf(buf_log_evcomm,
  7026. "[Proc_iso1_AuthorizationRes]Emergency Stop by CP Error (%d)",
  7027. sys->CpState);
  7028. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7029. }
  7030. #endif
  7031. //Check for CSU command of "Stop by EVSE"
  7032. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7033. {
  7034. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  7035. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  7036. //errn = -1;
  7037. }
  7038. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7039. {
  7040. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  7041. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  7042. errn = -1;
  7043. }
  7044. //[BODY (2/2)] EVSEProcessing
  7045. //Check for Permission from CSU
  7046. if(ShmInternalComm->ChargingPermission == TRUE)
  7047. {
  7048. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  7049. SAVE_SYS_LOG_MSG_EVCOMM("CSU Permission: OK");
  7050. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  7051. {
  7052. //Set PWM as 5% (for SLAC first case)
  7053. SAVE_SYS_LOG_MSG_EVCOMM("Set PWM as 5%%");
  7054. SwitchCpStateE(DISABLE);
  7055. OutputCpPwmDuty(5);
  7056. }
  7057. #endif
  7058. }
  7059. //Check for Permission Changing from TRUE to FALSE
  7060. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  7061. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  7062. ShmInternalComm->ChargingPermission == FALSE)
  7063. {
  7064. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO1][AuthorizationRes]Permission OFF");
  7065. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  7066. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  7067. // errn = -1;
  7068. }
  7069. #if PARAMETER_NORMAL_MODE == ENABLE
  7070. ////////////SHM_Read_iso1_AuthorizationRes(&ccs_exi_doc_ISO1, ShmCcsData);
  7071. #endif
  7072. // ============ Encode and Send Response Message ===========
  7073. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  7074. {
  7075. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  7076. errn = -1;
  7077. }
  7078. return errn;
  7079. }
  7080. /*===========================================================================
  7081. FUNCTION: Proc_din_ContractAuthenticationReq
  7082. DESCRIPTION:
  7083. PRE-CONDITION:
  7084. INPUT:
  7085. OUTPUT:
  7086. GLOBAL VARIABLES:
  7087. =============================================================================*/
  7088. int Proc_din_ContractAuthenticationReq(int AcceptFd)
  7089. {
  7090. int errn = 0;
  7091. DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_din_ContractAuthenticationReq]Got Proc_din_ContractAuthenticationReq\n");
  7092. //Print the decoded XML Document
  7093. PRINT_XML_DOC_DIN_ContractAuthenticationReq(&ccs_exi_doc_DIN);
  7094. //Save into Share Memory
  7095. SHM_Save_din_ContractAuthenticationReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  7096. errn = Proc_din_ContractAuthenticationRes(AcceptFd);
  7097. if (errn == 0)
  7098. {
  7099. //send response successfully.
  7100. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]ContractAuthenticationRes");
  7101. }
  7102. else
  7103. {
  7104. sprintf(buf_log_evcomm,
  7105. "[Error][SeccComm][Proc_din_ContractAuthenticationReq]Proc_iso1_AuthenticationRes(): %d (DEC)",
  7106. errn);
  7107. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7108. }
  7109. return errn;
  7110. }
  7111. /*===========================================================================
  7112. FUNCTION: Proc_iso1_AuthenticationReq
  7113. DESCRIPTION:
  7114. PRE-CONDITION:
  7115. INPUT:
  7116. OUTPUT:
  7117. GLOBAL VARIABLES:
  7118. =============================================================================*/
  7119. int Proc_iso1_AuthenticationReq(int AcceptFd)
  7120. {
  7121. int errn = 0;
  7122. DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_iso1_AuthenticationReq]Got AuthorizationReq\n");
  7123. //Print the decoded XML Document
  7124. PRINT_XML_DOC_ISO1_AuthorizationReq(&ccs_exi_doc_ISO1);
  7125. //Save into Share Memory
  7126. SHM_Save_iso1_AuthorizationReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  7127. errn = Proc_iso1_AuthorizationRes(AcceptFd);
  7128. if (errn == 0)
  7129. {
  7130. //send response successfully.
  7131. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]AuthorizationRes");
  7132. }
  7133. else
  7134. {
  7135. sprintf(buf_log_evcomm,
  7136. "[Error][SeccComm][Proc_iso1_AuthenticationReq]Proc_iso1_AuthenticationRes(): %d (DEC)",
  7137. errn);
  7138. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7139. }
  7140. return errn;
  7141. }
  7142. /*===========================================================================
  7143. FUNCTION: SHM_Init_dinDC_EVSEStatusType
  7144. DESCRIPTION:
  7145. PRE-CONDITION:
  7146. INPUT:
  7147. 1. in
  7148. OUTPUT:
  7149. 2. out
  7150. GLOBAL VARIABLES:
  7151. =============================================================================*/
  7152. void SHM_Init_dinDC_EVSEStatusType(struct DC_EVSEStatusType_DIN70121 *in)
  7153. {
  7154. in->EVSEIsolationStatus = dinisolationLevelType_Valid;
  7155. // dinisolationLevelType_Invalid = 0,
  7156. // dinisolationLevelType_Valid = 1, (default)
  7157. // dinisolationLevelType_Warning = 2,
  7158. // dinisolationLevelType_Fault = 3
  7159. in->EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7160. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7161. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1, (default)
  7162. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7163. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7164. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7165. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7166. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7167. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  7168. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  7169. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  7170. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  7171. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  7172. in->EVSENotification = dinEVSENotificationType_None;
  7173. // dinEVSENotificationType_None = 0, (default)
  7174. // dinEVSENotificationType_StopCharging = 1,
  7175. // dinEVSENotificationType_ReNegotiation = 2
  7176. }
  7177. /*===========================================================================
  7178. FUNCTION: SHM_Save_dinPhysicalValueType
  7179. DESCRIPTION:
  7180. PRE-CONDITION:
  7181. INPUT:
  7182. OUTPUT:
  7183. GLOBAL VARIABLES:
  7184. =============================================================================*/
  7185. void SHM_Save_dinPhysicalValueType(struct PhysicalValueType_DIN70121 *obj, short value, int multiplier, unsigned char unit)
  7186. {
  7187. obj->Value = value;
  7188. obj->Multiplier = multiplier;
  7189. obj->Unit =unit;
  7190. }
  7191. /*===========================================================================
  7192. FUNCTION: SHM_Init_din_ChargeParameterDiscoveryRes
  7193. DESCRIPTION:
  7194. PRE-CONDITION:
  7195. INPUT:
  7196. 1. shm_ccs
  7197. OUTPUT:
  7198. 2. shm_ccs
  7199. GLOBAL VARIABLES:
  7200. =============================================================================*/
  7201. void SHM_Init_din_ChargeParameterDiscoveryRes(struct CcsData *shm_ccs)
  7202. {
  7203. struct ChargeParameterDiscoveryResponse_DIN70121 *in;
  7204. in = &shm_ccs->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse;
  7205. //----- [BODY (1/5)] ResponseCode -----
  7206. in->ResponseCode = dinresponseCodeType_OK;
  7207. //----- [BODY (2/5)] EVSEProcessing -----
  7208. in->EVSEProcessing = dinEVSEProcessingType_Ongoing; //0
  7209. // dinEVSEProcessingType_Finished = 0,
  7210. // dinEVSEProcessingType_Ongoing = 1
  7211. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  7212. //be fixed in another function.
  7213. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  7214. //ignore, since DIN doesn't support AC
  7215. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  7216. struct DC_EVSEChargeParameterType_DIN70121 *in_para;
  7217. in_para = &in->DC_EVSEChargeParameter;
  7218. //DC_EVSEStatus
  7219. SHM_Init_dinDC_EVSEStatusType(&in_para->DC_EVSEStatus);
  7220. in_para->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7221. short value = 0; int multiplier = 0; unsigned char unit = 0;
  7222. //EVSEMaximumCurrentLimit
  7223. value = 600; multiplier = -1; unit = A_DIN70121; //60A
  7224. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumCurrentLimit, value, multiplier, unit);
  7225. //EVSEMaximumPowerLimit
  7226. value = 3000; multiplier = 1; unit = W_DIN70121; //30KW
  7227. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumPowerLimit, value, multiplier, unit);
  7228. //EVSEMaximumVoltageLimit
  7229. value = 7500; multiplier = -1; unit = V_DIN70121; //750V
  7230. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumVoltageLimit, value, multiplier, unit);
  7231. //EVSEMinimumVoltageLimit
  7232. value = 1500; multiplier = -1; unit = V_DIN70121; //150V
  7233. SHM_Save_dinPhysicalValueType(&in_para->EVSEMinimumVoltageLimit, value, multiplier, unit);
  7234. //EVSEMinimumCurrentLimit
  7235. value = 10; multiplier = -1; unit = A_DIN70121; //1A
  7236. SHM_Save_dinPhysicalValueType(&in_para->EVSEMinimumCurrentLimit, value, multiplier, unit);
  7237. //EVSECurrentRegulationTolerance
  7238. value = 10; multiplier = -1; unit = A_DIN70121; //1A
  7239. SHM_Save_dinPhysicalValueType(&in_para->EVSECurrentRegulationTolerance, value, multiplier, unit);
  7240. //EVSEPeakCurrentRipple
  7241. value = 2; multiplier = -1; unit = A_DIN70121; //0.2A
  7242. SHM_Save_dinPhysicalValueType(&in_para->EVSEPeakCurrentRipple, value, multiplier, unit);
  7243. //EVSEEnergyToBeDelivered (optional)
  7244. //SHM_Save_dinPhysicalValueType(&out_para->EVSEEnergyToBeDelivered, &in_para->EVSEEnergyToBeDelivered);
  7245. }
  7246. /*===========================================================================
  7247. FUNCTION: Sudo_Parameter_din_ChargeParameterDiscoveryRes
  7248. DESCRIPTION:
  7249. PRE-CONDITION:
  7250. INPUT:
  7251. OUTPUT:
  7252. GLOBAL VARIABLES:
  7253. =============================================================================*/
  7254. void Sudo_Parameter_din_ChargeParameterDiscoveryRes()
  7255. {
  7256. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  7257. init_dinChargeParameterDiscoveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes);
  7258. ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed = 1u;
  7259. //----- [BODY (1/5)] ResponseCode -----
  7260. struct dinChargeParameterDiscoveryResType *res;
  7261. res = &ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes;
  7262. res->ResponseCode = dinresponseCodeType_OK;
  7263. //----- [BODY (2/5)] EVSEProcessing -----
  7264. res->EVSEProcessing = dinEVSEProcessingType_Finished; //0
  7265. // dinEVSEProcessingType_Finished = 0,
  7266. // dinEVSEProcessingType_Ongoing = 1
  7267. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  7268. res->SAScheduleList_isUsed = 1u;
  7269. struct dinSAScheduleListType *list;
  7270. list = &res->SAScheduleList;
  7271. //
  7272. list->SAScheduleTuple.arrayLen = 1;
  7273. list->SAScheduleTuple.array[0].SAScheduleTupleID = 0;
  7274. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleID = 0;
  7275. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.arrayLen = 1;
  7276. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval_isUsed = 1u;
  7277. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.start = 0;
  7278. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration = xxx
  7279. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration_isUsed = 1u;
  7280. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval_isUsed = 0u;
  7281. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval.xxx
  7282. //list->SAScheduleTuple.array[0].SalesTariff.xxx
  7283. //list->SAScheduleTuple.array[0].SalesTariff_isUsed = 0u;
  7284. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  7285. //ignore, since DIN doesn't support AC
  7286. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  7287. res->DC_EVSEChargeParameter_isUsed = 1u;
  7288. struct dinDC_EVSEChargeParameterType *para;
  7289. para = &res->DC_EVSEChargeParameter;
  7290. //DC_EVSEStatus
  7291. para->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7292. para->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7293. // dinisolationLevelType_Invalid = 0,
  7294. // dinisolationLevelType_Valid = 1,
  7295. // dinisolationLevelType_Warning = 2,
  7296. // dinisolationLevelType_Fault = 3
  7297. para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7298. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7299. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  7300. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7301. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7302. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7303. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7304. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7305. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  7306. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  7307. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  7308. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  7309. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  7310. para->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7311. para->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  7312. // dinEVSENotificationType_None = 0,
  7313. // dinEVSENotificationType_StopCharging = 1,
  7314. // dinEVSENotificationType_ReNegotiation = 2
  7315. //EVSEMaximumCurrentLimit
  7316. para->EVSEMaximumCurrentLimit.Value = 2400;
  7317. para->EVSEMaximumCurrentLimit.Multiplier = -1;
  7318. para->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  7319. para->EVSEMaximumCurrentLimit.Unit = dinunitSymbolType_A;
  7320. // dinunitSymbolType_h = 0,
  7321. // dinunitSymbolType_m = 1,
  7322. // dinunitSymbolType_s = 2,
  7323. // dinunitSymbolType_A = 3,
  7324. // dinunitSymbolType_Ah = 4,
  7325. // dinunitSymbolType_V = 5,
  7326. // dinunitSymbolType_VA = 6,
  7327. // dinunitSymbolType_W = 7,
  7328. // dinunitSymbolType_W_s = 8,
  7329. // dinunitSymbolType_Wh = 9
  7330. //EVSEMaximumPowerLimit
  7331. para->EVSEMaximumPowerLimit.Value = 6000;
  7332. para->EVSEMaximumPowerLimit.Multiplier = 1;
  7333. para->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  7334. para->EVSEMaximumPowerLimit.Unit = dinunitSymbolType_W;
  7335. //EVSEMaximumVoltageLimit
  7336. para->EVSEMaximumVoltageLimit.Value = 7500;
  7337. para->EVSEMaximumVoltageLimit.Multiplier = -1;
  7338. para->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  7339. para->EVSEMaximumVoltageLimit.Unit = dinunitSymbolType_V;
  7340. //EVSEMinimumVoltageLimit
  7341. para->EVSEMinimumVoltageLimit.Value = 1500;
  7342. para->EVSEMinimumVoltageLimit.Multiplier = -1;
  7343. para->EVSEMinimumVoltageLimit.Unit_isUsed = 1u;
  7344. para->EVSEMinimumVoltageLimit.Unit = dinunitSymbolType_V;
  7345. //EVSEMinimumCurrentLimit
  7346. para->EVSEMinimumCurrentLimit.Value = 20;
  7347. para->EVSEMinimumCurrentLimit.Multiplier = -1;
  7348. para->EVSEMinimumCurrentLimit.Unit_isUsed = 1u;
  7349. para->EVSEMinimumCurrentLimit.Unit = dinunitSymbolType_A;
  7350. //EVSECurrentRegulationTolerance_isUsed
  7351. para->EVSECurrentRegulationTolerance_isUsed = 1u;
  7352. //EVSECurrentRegulationTolerance
  7353. para->EVSECurrentRegulationTolerance.Value = 10;
  7354. para->EVSECurrentRegulationTolerance.Multiplier = -1;
  7355. para->EVSECurrentRegulationTolerance.Unit_isUsed = 1u;
  7356. para->EVSECurrentRegulationTolerance.Unit = dinunitSymbolType_A;
  7357. //EVSEEnergyToBeDelivered_isUsed
  7358. para->EVSEEnergyToBeDelivered_isUsed = 1u;
  7359. //EVSEPeakCurrentRipple
  7360. para->EVSEPeakCurrentRipple.Value = 2;
  7361. para->EVSEPeakCurrentRipple.Multiplier = -1;
  7362. para->EVSEPeakCurrentRipple.Unit_isUsed = 1u;
  7363. para->EVSEPeakCurrentRipple.Unit = dinunitSymbolType_A;
  7364. //EVSEEnergyToBeDelivered (optional)
  7365. /*
  7366. para->EVSEEnergyToBeDelivered.Value = 360;
  7367. para->EVSEEnergyToBeDelivered.Multiplier = 3;
  7368. para->EVSEEnergyToBeDelivered.Unit_isUsed = 1u;
  7369. para->EVSEEnergyToBeDelivered.Unit = dinunitSymbolType_Wh;
  7370. */
  7371. }
  7372. /*===========================================================================
  7373. FUNCTION: Sudo_Parameter_iso1_ChargeParameterDiscoveryRes
  7374. DESCRIPTION:
  7375. PRE-CONDITION:
  7376. INPUT:
  7377. OUTPUT:
  7378. GLOBAL VARIABLES:
  7379. =============================================================================*/
  7380. void Sudo_Parameter_iso1_ChargeParameterDiscoveryRes()
  7381. {
  7382. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  7383. init_iso1ChargeParameterDiscoveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes);
  7384. ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed = 1u;
  7385. //----- [BODY (1/5)] ResponseCode -----
  7386. struct iso1ChargeParameterDiscoveryResType *res;
  7387. res = &ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes;
  7388. res->ResponseCode = iso1responseCodeType_OK;
  7389. //----- [BODY (2/5)] EVSEProcessing -----
  7390. res->EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  7391. // iso1EVSEProcessingType_Finished = 0,
  7392. // iso1EVSEProcessingType_Ongoing = 1
  7393. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  7394. res->SAScheduleList_isUsed = 1u;
  7395. struct iso1SAScheduleListType *list;
  7396. list = &res->SAScheduleList;
  7397. //
  7398. list->SAScheduleTuple.arrayLen = 1;
  7399. list->SAScheduleTuple.array[0].SAScheduleTupleID = 0;
  7400. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.arrayLen = 1;
  7401. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval_isUsed = 1u;
  7402. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.start = 0;
  7403. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration = xxx
  7404. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration_isUsed = 1u;
  7405. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval_isUsed = 0u;
  7406. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval.xxx
  7407. //list->SAScheduleTuple.array[0].SalesTariff.xxx
  7408. //list->SAScheduleTuple.array[0].SalesTariff_isUsed = 0u;
  7409. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  7410. //ignore, since our ISO1 doesn't support AC, yet
  7411. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  7412. res->DC_EVSEChargeParameter_isUsed = 1u;
  7413. struct iso1DC_EVSEChargeParameterType *para;
  7414. para = &res->DC_EVSEChargeParameter;
  7415. //DC_EVSEStatus
  7416. para->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7417. para->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  7418. // iso1isolationLevelType_Invalid = 0,
  7419. // iso1isolationLevelType_Valid = 1,
  7420. // iso1isolationLevelType_Warning = 2,
  7421. // iso1isolationLevelType_Fault = 3
  7422. para->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  7423. // iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7424. // iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  7425. // iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7426. // iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7427. // iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7428. // iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7429. // iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7430. // iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  7431. // iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  7432. // iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  7433. // iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  7434. // iso1DC_EVSEStatusCodeType_Reserved_C = 11
  7435. para->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7436. para->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  7437. // iso1EVSENotificationType_None = 0,
  7438. // iso1EVSENotificationType_StopCharging = 1,
  7439. // iso1EVSENotificationType_ReNegotiation = 2
  7440. //EVSEMaximumCurrentLimit
  7441. para->EVSEMaximumCurrentLimit.Value = 2400;
  7442. para->EVSEMaximumCurrentLimit.Multiplier = -1;
  7443. //para->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  7444. para->EVSEMaximumCurrentLimit.Unit = iso1unitSymbolType_A;
  7445. //iso1unitSymbolType_h = 0,
  7446. //iso1unitSymbolType_m = 1,
  7447. //iso1unitSymbolType_s = 2,
  7448. //iso1unitSymbolType_A = 3,
  7449. //iso1unitSymbolType_V = 4,
  7450. //iso1unitSymbolType_W = 5,
  7451. //iso1unitSymbolType_Wh = 6
  7452. //EVSEMaximumPowerLimit
  7453. para->EVSEMaximumPowerLimit.Value = 6000;
  7454. para->EVSEMaximumPowerLimit.Multiplier = 1;
  7455. //para->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  7456. para->EVSEMaximumPowerLimit.Unit = iso1unitSymbolType_W;
  7457. //EVSEMaximumVoltageLimit
  7458. para->EVSEMaximumVoltageLimit.Value = 7500;
  7459. para->EVSEMaximumVoltageLimit.Multiplier = -1;
  7460. //para->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  7461. para->EVSEMaximumVoltageLimit.Unit = iso1unitSymbolType_V;
  7462. //EVSEMinimumVoltageLimit
  7463. para->EVSEMinimumVoltageLimit.Value = 1500;
  7464. para->EVSEMinimumVoltageLimit.Multiplier = -1;
  7465. //para->EVSEMinimumVoltageLimit.Unit_isUsed = 1u;
  7466. para->EVSEMinimumVoltageLimit.Unit = iso1unitSymbolType_V;
  7467. //EVSEMinimumCurrentLimit
  7468. para->EVSEMinimumCurrentLimit.Value = 20;
  7469. para->EVSEMinimumCurrentLimit.Multiplier = -1;
  7470. //para->EVSEMinimumCurrentLimit.Unit_isUsed = 1u;
  7471. para->EVSEMinimumCurrentLimit.Unit = iso1unitSymbolType_A;
  7472. //EVSECurrentRegulationTolerance_isUsed
  7473. para->EVSECurrentRegulationTolerance_isUsed = 1u;
  7474. //EVSECurrentRegulationTolerance
  7475. para->EVSECurrentRegulationTolerance.Value = 10;
  7476. para->EVSECurrentRegulationTolerance.Multiplier = -1;
  7477. //para->EVSECurrentRegulationTolerance.Unit_isUsed = 1u;
  7478. para->EVSECurrentRegulationTolerance.Unit = iso1unitSymbolType_A;
  7479. //EVSEEnergyToBeDelivered_isUsed
  7480. para->EVSEEnergyToBeDelivered_isUsed = 1u;
  7481. //EVSEPeakCurrentRipple
  7482. para->EVSEPeakCurrentRipple.Value = 2;
  7483. para->EVSEPeakCurrentRipple.Multiplier = -1;
  7484. //para->EVSEPeakCurrentRipple.Unit_isUsed = 1u;
  7485. para->EVSEPeakCurrentRipple.Unit = iso1unitSymbolType_A;
  7486. //EVSEEnergyToBeDelivered (optional)
  7487. /*
  7488. para->EVSEEnergyToBeDelivered.Value = 360;
  7489. para->EVSEEnergyToBeDelivered.Multiplier = 3;
  7490. para->EVSEEnergyToBeDelivered.Unit_isUsed = 1u;
  7491. para->EVSEEnergyToBeDelivered.Unit = iso1unitSymbolType_Wh;
  7492. */
  7493. }
  7494. /*===========================================================================
  7495. FUNCTION: Proc_din_ChargeParameterDiscoveryRes
  7496. DESCRIPTION:
  7497. PRE-CONDITION:
  7498. INPUT:
  7499. OUTPUT:
  7500. GLOBAL VARIABLES:
  7501. =============================================================================*/
  7502. int Proc_din_ChargeParameterDiscoveryRes(int AcceptFd)
  7503. {
  7504. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7505. //if it is not the same, the packet should be ignored.
  7506. //STEP 1: ============ Initialize ============
  7507. int errn = 0;
  7508. bitstream_t v2g_tx_stream;
  7509. struct ChargeParameterDiscoveryResponse_DIN70121 *res;
  7510. struct ChargeParameterDiscoveryRequest_DIN70121 *req;
  7511. struct DC_EVSEChargeParameterType_DIN70121 *dc_para;
  7512. struct ChargingInfoData *sys;
  7513. size_t pos = 0;
  7514. v2g_tx_stream.pos = &pos;
  7515. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7516. v2g_tx_stream.data = V2GTP_Tx_buf;
  7517. res = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse;
  7518. req = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest;
  7519. dc_para = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse.DC_EVSEChargeParameter;
  7520. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7521. res->ResponseCode = OK_DIN70121;
  7522. res->EVSEProcessing = Ongoing_DIN70121;
  7523. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready; //1
  7524. //[HEADER] Check Req SessionID
  7525. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  7526. {
  7527. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  7528. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  7529. errn = -1;
  7530. }
  7531. //Check for SequenceError
  7532. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7533. {
  7534. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  7535. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  7536. errn = -1;
  7537. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7538. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7539. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7540. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7541. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7542. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7543. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7544. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7545. }
  7546. //[TC_SECC_VTB_ChargeParameterDiscovery_005]
  7547. if ( (sys->EvBatteryMaxCurrent < 0) ||
  7548. (sys->EvBatteryMaxVoltage<150)
  7549. )
  7550. {
  7551. sprintf(buf_log_evcomm,
  7552. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  7553. sys->EvBatteryMaxCurrent);
  7554. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7555. res->ResponseCode = dinresponseCodeType_FAILED_WrongChargeParameter; //16
  7556. res->EVSEProcessing = Finished_DIN70121;
  7557. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7558. errn = -1;
  7559. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7560. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  7561. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7562. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7563. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7564. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7565. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  7566. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  7567. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7568. }
  7569. //STEP 2: ============ Modify Parameters of ShmCcsData ============
  7570. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_DIN70121);
  7571. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_DIN70121);
  7572. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_DIN70121);
  7573. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMinimumVoltageLimit, 1500, V_DIN70121); //150V
  7574. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMinimumCurrentLimit, MIN_SUPPORTED_CURRENT*10, A_DIN70121); //1A
  7575. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSECurrentRegulationTolerance, 10, A_DIN70121); //1A
  7576. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEPeakCurrentRipple, 2, A_DIN70121); //0.2A
  7577. //SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEEnergyToBeDelivered, 0, WH_DIN70121); //optional
  7578. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  7579. if (sys->EvBatteryMaxVoltage <= 500)
  7580. {
  7581. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumVoltageLimit, (int) (500 * 10), V_DIN70121); //500V
  7582. }
  7583. #endif
  7584. //for test with Tesla Model 3, 10A
  7585. //SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumCurrentLimit, (int) (10 * 10), A_DIN70121); //10A, for testing with Tesla Model 3
  7586. //Check for EnergyTransferMode [TC_SECC_VTB_ChargeParameterDiscovery_004]
  7587. if (req->EVRequestedEnergyTransferType != dinEVSESupportedEnergyTransferType_DC_extended)
  7588. {
  7589. sprintf(buf_log_evcomm,
  7590. "[ERROR]Wrong EVRequestedEnergyTransferType(%d,%d)",
  7591. req->EVRequestedEnergyTransferType,
  7592. dinEVSESupportedEnergyTransferType_DC_extended);
  7593. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7594. res->ResponseCode = FAILED_WrongEnergyTransferType_DIN70121;
  7595. res->EVSEProcessing = Finished_DIN70121;
  7596. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7597. errn = -1;
  7598. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7599. Update_V2G_Flow_Status(Other_Fault);
  7600. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7601. //CCS_SECC_ResponseCode_FAILED_WrongEnergyTransferMode (023774)
  7602. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7603. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7604. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7605. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7606. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  7607. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  7608. }
  7609. //Check for CSU command of "Stop by EVSE"
  7610. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7611. {
  7612. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes]EVSE_Shutdown");
  7613. res->ResponseCode = FAILED_DIN70121;
  7614. res->EVSEProcessing = Finished_DIN70121;
  7615. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7616. // errn = -1;
  7617. }
  7618. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7619. {
  7620. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes]EVSE_EmergencyShutdown");
  7621. res->ResponseCode = FAILED_DIN70121;
  7622. res->EVSEProcessing = Finished_DIN70121;
  7623. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7624. errn = -1;
  7625. }
  7626. //Detect for CP State should be 9V (State B)
  7627. #if CP_PROTECTION_MECHANISM == ENABLE
  7628. if (sys->CpState != 3) //State B1, B2
  7629. {
  7630. res->ResponseCode = FAILED_DIN70121;
  7631. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7632. res->EVSEProcessing = Finished_DIN70121;
  7633. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7634. Update_V2G_Flow_Status(Other_Fault);
  7635. errn = -1;
  7636. sprintf(buf_log_evcomm,
  7637. "[Proc_din_ChargeParameterDiscoveryRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  7638. sys->CpState,
  7639. sys->CpVoltage);
  7640. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7641. }
  7642. #endif
  7643. //Check for Permission from CSU
  7644. if (ShmInternalComm->ChargingPermission == TRUE)
  7645. {
  7646. res->EVSEProcessing = Finished_DIN70121;
  7647. }
  7648. //Check for Permission Off
  7649. if (ShmInternalComm->ChargingPermission == FALSE)
  7650. {
  7651. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][ChargeParameterDiscoveryRes]Permission OFF");
  7652. res->ResponseCode = FAILED_DIN70121;
  7653. res->EVSEProcessing = Finished_DIN70121;
  7654. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7655. // errn = -1;
  7656. }
  7657. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7658. #if PARAMETER_NORMAL_MODE == ENABLE
  7659. SHM_Read_din_ChargeParameterDiscoveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  7660. #else
  7661. Sudo_Parameter_din_ChargeParameterDiscoveryRes();
  7662. #endif
  7663. //STEP 4: ============ Encode and Send Response Message ===========
  7664. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  7665. {
  7666. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  7667. errn = -1;
  7668. }
  7669. //STPE 5: ============ Update Flags ============
  7670. return errn;
  7671. }
  7672. /*===========================================================================
  7673. FUNCTION: Proc_iso1_ChargeParameterDiscoveryRes
  7674. DESCRIPTION:
  7675. PRE-CONDITION:
  7676. INPUT:
  7677. OUTPUT:
  7678. GLOBAL VARIABLES:
  7679. =============================================================================*/
  7680. int Proc_iso1_ChargeParameterDiscoveryRes(int AcceptFd)
  7681. {
  7682. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7683. //if it is not the same, the packet should be ignored.
  7684. //STEP 1: ============ Initialize ============
  7685. int errn = 0;
  7686. bitstream_t v2g_tx_stream;
  7687. struct ChargeParameterDiscoveryResponse_ISO15118_2014 *res;
  7688. struct ChargeParameterDiscoveryRequest_ISO15118_2014 *req;
  7689. struct DC_EVSEChargeParameterType_ISO15118_2014 *dc_para;
  7690. struct AC_EVSEChargeParameterType_ISO15118_2014 *ac_para;
  7691. struct ChargingInfoData *sys;
  7692. size_t pos = 0;
  7693. v2g_tx_stream.pos = &pos;
  7694. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7695. v2g_tx_stream.data = V2GTP_Tx_buf;
  7696. res = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse;
  7697. req = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest;
  7698. dc_para = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse.DC_EVSEChargeParameter;
  7699. ac_para = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse.AC_EVSEChargeParameter;
  7700. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7701. res->ResponseCode = OK_ISO15118_2014;
  7702. /*+++ 20200808, vern, EVSEProcessing should be on-going during ChargeParameterDiscovery +++*/
  7703. res->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  7704. /*--- 20200808, vern, EVSEProcessing should be on-going during ChargeParameterDiscovery ---*/
  7705. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; //1
  7706. ac_para->AC_EVSEStatus.RCD = ShmInternalComm->AC_RcdStatus; //0:no error, 1:error
  7707. ac_para->AC_EVSEStatus.NotificationMaxDelay = 0; //unit: 1s
  7708. ac_para->AC_EVSEStatus.EVSENotification = ShmInternalComm->AC_EVSENotification; //0:none, 1:StopCharging, 2:RenNgotiation
  7709. //[HEADER] Check Req SessionID
  7710. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  7711. {
  7712. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  7713. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  7714. errn = -1;
  7715. }
  7716. //Check for SequenceError
  7717. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7718. {
  7719. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  7720. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  7721. errn = -1;
  7722. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7723. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7724. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7725. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7726. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7727. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7728. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7729. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7730. }
  7731. /* printf("req->RequestedEnergyTransferMode=%d\n",req->RequestedEnergyTransferMode);
  7732. printf("req->AC_EVChargeParameter.DepartureTime=%d\n",req->AC_EVChargeParameter.DepartureTime);
  7733. printf("req->AC_EVChargeParameter.EAmount.Multiplier=%d\n",req->AC_EVChargeParameter.EAmount.Multiplier);
  7734. printf("req->AC_EVChargeParameter.EAmount.Unit=%d\n",req->AC_EVChargeParameter.EAmount.Unit);
  7735. printf("req->AC_EVChargeParameter.EAmount.Value=%d\n",req->AC_EVChargeParameter.EAmount.Value);
  7736. printf("req->AC_EVChargeParameter.EVMaxVoltage.Multiplier=%d\n",req->AC_EVChargeParameter.EVMaxVoltage.Multiplier);
  7737. printf("req->AC_EVChargeParameter.EVMaxVoltage.Unit=%d\n",req->AC_EVChargeParameter.EVMaxVoltage.Unit);
  7738. printf("req->AC_EVChargeParameter.EVMaxVoltage.Value=%d\n",req->AC_EVChargeParameter.EVMaxVoltage.Value);
  7739. printf("req->AC_EVChargeParameter.EVMaxCurrent.Multiplier=%d\n",req->AC_EVChargeParameter.EVMaxCurrent.Multiplier);
  7740. printf("req->AC_EVChargeParameter.EVMaxCurrent.Unit=%d\n",req->AC_EVChargeParameter.EVMaxCurrent.Unit);
  7741. printf("req->AC_EVChargeParameter.EVMaxCurrent.Value=%d\n",req->AC_EVChargeParameter.EVMaxCurrent.Value);
  7742. printf("req->AC_EVChargeParameter.EVMinCurrent.Multiplier=%d\n",req->AC_EVChargeParameter.EVMinCurrent.Multiplier);
  7743. printf("req->AC_EVChargeParameter.EVMinCurrent.Unit=%d\n",req->AC_EVChargeParameter.EVMinCurrent.Unit);
  7744. printf("req->AC_EVChargeParameter.EVMinCurrent.Value=%d\n",req->AC_EVChargeParameter.EVMinCurrent.Value);*/
  7745. if(req->RequestedEnergyTransferMode <= 1)//0 for 1P, 1 for 3P
  7746. {
  7747. //AC parameters
  7748. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryRes]AC charging");
  7749. //AC
  7750. SAVE_PhysicalValueType_ISO15118_2014(&ac_para->EVSENominalVoltage, (int) (sys->AC_EVSENominalVoltage * 10), V_ISO15118_2014);
  7751. //SAVE_PhysicalValueType_ISO15118_2014(&ac_para->EVSEMaxCurrent, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  7752. SAVE_PhysicalValueType_ISO15118_2014(&ac_para->EVSEMaxCurrent, (int) (ShmInternalComm->AC_EVSEMaxCurrent * 10), A_ISO15118_2014);
  7753. }
  7754. else
  7755. {
  7756. //DC parameters
  7757. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryRes]DC charging");
  7758. //[TC_SECC_VTB_ChargeParameterDiscovery_005]
  7759. /*+++ 20200808, vern, should check the voltage and current to see if the range of battery parameter is accepted by charger ---*/
  7760. if ((sys->EvBatteryMaxCurrent < 0) ||(sys->EvBatteryMaxVoltage<150))
  7761. {
  7762. sprintf(buf_log_evcomm,
  7763. "[ERROR]EvBatteryMaxCurrent/MaxVolatge is mismatch(current=%.02f, voltage=%.02f) => End_Process",
  7764. sys->EvBatteryMaxCurrent,sys->EvBatteryMaxVoltage);
  7765. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7766. res->ResponseCode = iso1responseCodeType_FAILED_WrongChargeParameter; //16
  7767. res->EVSEProcessing = Finished_ISO15118_2014;
  7768. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7769. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7770. errn = -1;
  7771. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7772. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  7773. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7774. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7775. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7776. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7777. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  7778. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  7779. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7780. }
  7781. //STEP 2: ============ Modify Parameters of ShmCcsData ============
  7782. //DC
  7783. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_ISO15118_2014);
  7784. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  7785. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_ISO15118_2014);
  7786. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMinimumVoltageLimit, 1500, V_ISO15118_2014); //150V
  7787. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMinimumCurrentLimit, MIN_SUPPORTED_CURRENT*10, A_ISO15118_2014); //1A
  7788. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSECurrentRegulationTolerance, 10, A_ISO15118_2014); //1A
  7789. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEPeakCurrentRipple, 2, A_ISO15118_2014); //0.2A
  7790. //SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEEnergyToBeDelivered, 0, Wh_ISO15118_2014); //optional
  7791. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  7792. if (sys->EvBatteryMaxVoltage <= 500)
  7793. {
  7794. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumVoltageLimit, (int) (500 * 10), V_ISO15118_2014); //500V
  7795. }
  7796. #endif
  7797. //Check for CSU command of "Stop by EVSE"
  7798. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7799. {
  7800. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryRes]EVSE_Shutdown");
  7801. res->ResponseCode = FAILED_ISO15118_2014;
  7802. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7803. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7804. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7805. // errn = -1;
  7806. }
  7807. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7808. {
  7809. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryRes]EVSE_EmergencyShutdown");
  7810. res->ResponseCode = FAILED_ISO15118_2014;
  7811. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7812. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7813. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7814. errn = -1;
  7815. }
  7816. //Detect for CP State should be 9V (State B)
  7817. #if CP_PROTECTION_MECHANISM == ENABLE
  7818. if (sys->CpState != 3) //State B1, B2
  7819. {
  7820. res->ResponseCode = FAILED_ISO15118_2014;
  7821. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7822. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7823. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7824. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7825. Update_V2G_Flow_Status(Other_Fault);
  7826. errn = -1;
  7827. sprintf(buf_log_evcomm,
  7828. "[Proc_iso1_ChargeParameterDiscoveryRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  7829. sys->CpState,
  7830. sys->CpVoltage);
  7831. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7832. }
  7833. #endif
  7834. }
  7835. //for test with Tesla Model 3, 10A
  7836. //SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumCurrentLimit, (int) (10 * 10), A_ISO15118_2014); //10A, for testing with Tesla Model 3
  7837. //Check for EnergyTransferMode
  7838. if (req->RequestedEnergyTransferMode != ShmCcsData->EnergyTransferMode) //[CAUTION] Their table should be kept as the same.
  7839. {
  7840. sprintf(buf_log_evcomm,
  7841. "[ERROR]Unmatched RequestedEnergyTransferMode(%d,%d)",
  7842. req->RequestedEnergyTransferMode,
  7843. ShmCcsData->EnergyTransferMode);
  7844. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7845. res->ResponseCode = FAILED_WrongEnergyTransferMode_ISO15118_2014;
  7846. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7847. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7848. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7849. errn = -1;
  7850. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7851. Update_V2G_Flow_Status(Other_Fault);
  7852. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7853. //CCS_SECC_ResponseCode_FAILED_WrongEnergyTransferMode (023774)
  7854. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7855. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7856. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7857. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7858. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  7859. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  7860. }
  7861. //Check for Permission from CSU
  7862. if(ShmInternalComm->ChargingPermission == TRUE)
  7863. {
  7864. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7865. }
  7866. //Check for Permission Off
  7867. if (ShmInternalComm->ChargingPermission == FALSE)
  7868. {
  7869. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO1][ChargeParameterDiscoveryRes]Permission OFF");
  7870. res->ResponseCode = FAILED_ISO15118_2014;
  7871. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7872. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7873. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7874. // errn = -1;
  7875. }
  7876. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7877. #if PARAMETER_NORMAL_MODE == ENABLE
  7878. SHM_Read_iso1_ChargeParameterDiscoveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  7879. #else
  7880. Sudo_Parameter_iso1_ChargeParameterDiscoveryRes();
  7881. #endif
  7882. //STEP 4: ============ Encode and Send Response Message ===========
  7883. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  7884. {
  7885. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  7886. errn = -1;
  7887. }
  7888. //STPE 5: ============ Update Flags ============
  7889. return errn;
  7890. }
  7891. /*===========================================================================
  7892. FUNCTION: Proc_din_ChargeParameterDiscoveryReq
  7893. DESCRIPTION:
  7894. PRE-CONDITION:
  7895. INPUT:
  7896. OUTPUT:
  7897. GLOBAL VARIABLES:
  7898. =============================================================================*/
  7899. int Proc_din_ChargeParameterDiscoveryReq(int AcceptFd)
  7900. {
  7901. int errn = 0;
  7902. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryReq] Got ChargeParameterDiscoveryReq");
  7903. //ftime(&SeqStartTime);
  7904. //Print the decoded XML Document
  7905. PRINT_XML_DOC_DIN_ChargeParameterDiscoveryReq(&ccs_exi_doc_DIN);
  7906. //Save into Share Memory
  7907. SHM_Save_din_ChargeParameterDiscoveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  7908. //Check for EV Error Code
  7909. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.DC_EVStatus.EVErrorCode);
  7910. errn = Proc_din_ChargeParameterDiscoveryRes(AcceptFd);
  7911. //ftime(&SeqEndTime);
  7912. //DEBUG_PRINTF_EVCOMM_DETAIL("\ndelta = %.02lf ms\n", DiffTimeb(SeqStartTime, SeqEndTime));
  7913. if ( errn == 0)
  7914. {
  7915. //send response successfully.
  7916. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]ChargeParameterDiscoveryRes");
  7917. }
  7918. else
  7919. {
  7920. sprintf(buf_log_evcomm,
  7921. "[Error][DIN][ChargeParameterDiscoveryRes]%d (DEC)",
  7922. errn);
  7923. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7924. }
  7925. return errn;
  7926. }
  7927. /*===========================================================================
  7928. FUNCTION: Proc_iso1_ChargeParameterDiscoveryReq
  7929. DESCRIPTION:
  7930. PRE-CONDITION:
  7931. INPUT:
  7932. OUTPUT:
  7933. GLOBAL VARIABLES:
  7934. =============================================================================*/
  7935. int Proc_iso1_ChargeParameterDiscoveryReq(int AcceptFd)
  7936. {
  7937. int errn = 0;
  7938. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryReq] Got ChargeParameterDiscoveryReq");
  7939. //ftime(&SeqStartTime);
  7940. //Print the decoded XML Document
  7941. PRINT_XML_DOC_ISO1_ChargeParameterDiscoveryReq(&ccs_exi_doc_ISO1);
  7942. //Save into Share Memory
  7943. SHM_Save_iso1_ChargeParameterDiscoveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  7944. //Check for EV Error Code
  7945. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.DC_EVStatus.EVErrorCode);
  7946. errn = Proc_iso1_ChargeParameterDiscoveryRes(AcceptFd);
  7947. //ftime(&SeqEndTime);
  7948. //DEBUG_PRINTF_EVCOMM_DETAIL("\ndelta = %.02lf ms\n", DiffTimeb(SeqStartTime, SeqEndTime));
  7949. if (errn == 0)
  7950. {
  7951. //send response successfully.
  7952. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]ChargeParameterDiscoveryRes");
  7953. }
  7954. else
  7955. {
  7956. sprintf(buf_log_evcomm,
  7957. "[Error][ISO1][ChargeParameterDiscoveryRes]%d (DEC)",
  7958. errn);
  7959. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7960. }
  7961. return errn;
  7962. }
  7963. /*===========================================================================
  7964. FUNCTION: SHM_Init_din_CableCheckRes
  7965. DESCRIPTION:
  7966. PRE-CONDITION:
  7967. INPUT:
  7968. 1. shm_ccs
  7969. OUTPUT:
  7970. 1. shm_ccs
  7971. GLOBAL VARIABLES:
  7972. =============================================================================*/
  7973. void SHM_Init_din_CableCheckRes(struct CcsData *shm_ccs)
  7974. {
  7975. struct CableCheckResponse_DIN70121 *in;
  7976. in = &shm_ccs->V2GMessage_DIN70121.CableCheckResponse;
  7977. //----- [BODY (1/3)] ResponseCode -----
  7978. in->ResponseCode = dinresponseCodeType_OK;
  7979. //----- [BODY (2/3)] EVSEProcessing -----
  7980. //in->EVSEProcessing = dinEVSEProcessingType_Finished; //for test
  7981. in->EVSEProcessing = dinEVSEProcessingType_Ongoing; //default
  7982. // dinEVSEProcessingType_Finished = 0,
  7983. // dinEVSEProcessingType_Ongoing = 1
  7984. //----- [BODY (3/3)] DC_EVSEStatus -----
  7985. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  7986. in->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0 (default)
  7987. // dinisolationLevelType_Invalid = 0,
  7988. // dinisolationLevelType_Valid = 1, (default)
  7989. // dinisolationLevelType_Warning = 2,
  7990. // dinisolationLevelType_Fault = 3
  7991. }
  7992. /*===========================================================================
  7993. FUNCTION: Sudo_Parameter_din_CableCheckRes
  7994. DESCRIPTION:
  7995. PRE-CONDITION:
  7996. INPUT:
  7997. OUTPUT:
  7998. GLOBAL VARIABLES:
  7999. =============================================================================*/
  8000. void Sudo_Parameter_din_CableCheckRes()
  8001. {
  8002. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  8003. init_dinCableCheckResType(&ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes);
  8004. ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes_isUsed = 1u;
  8005. //----- [BODY (1/3)] ResponseCode -----
  8006. struct dinCableCheckResType *res;
  8007. res = &ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes;
  8008. res->ResponseCode = dinresponseCodeType_OK;
  8009. //----- [BODY (2/3)] EVSEProcessing -----
  8010. res->EVSEProcessing = dinEVSEProcessingType_Finished; //0
  8011. // dinEVSEProcessingType_Finished = 0,
  8012. // dinEVSEProcessingType_Ongoing = 1
  8013. //----- [BODY (3/3)] DC_EVSEStatus -----
  8014. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8015. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  8016. // dinisolationLevelType_Invalid = 0,
  8017. // dinisolationLevelType_Valid = 1,
  8018. // dinisolationLevelType_Warning = 2,
  8019. // dinisolationLevelType_Fault = 3
  8020. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8021. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8022. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  8023. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8024. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8025. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8026. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8027. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8028. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  8029. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  8030. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  8031. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  8032. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  8033. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8034. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  8035. // dinEVSENotificationType_None = 0,
  8036. // dinEVSENotificationType_StopCharging = 1,
  8037. // dinEVSENotificationType_ReNegotiation = 2
  8038. }
  8039. /*===========================================================================
  8040. FUNCTION: Sudo_Parameter_iso1_CableCheckRes
  8041. DESCRIPTION:
  8042. PRE-CONDITION:
  8043. INPUT:
  8044. OUTPUT:
  8045. GLOBAL VARIABLES:
  8046. =============================================================================*/
  8047. void Sudo_Parameter_iso1_CableCheckRes()
  8048. {
  8049. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8050. init_iso1CableCheckResType(&ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes);
  8051. ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes_isUsed = 1u;
  8052. //----- [BODY (1/3)] ResponseCode -----
  8053. struct iso1CableCheckResType *res;
  8054. res = &ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes;
  8055. res->ResponseCode = iso1responseCodeType_OK;
  8056. //----- [BODY (2/3)] EVSEProcessing -----
  8057. res->EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  8058. //iso1EVSEProcessingType_Finished = 0,
  8059. //iso1EVSEProcessingType_Ongoing = 1,
  8060. //iso1EVSEProcessingType_Ongoing_WaitingForCustomerInteraction = 2
  8061. //----- [BODY (3/3)] DC_EVSEStatus -----
  8062. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8063. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  8064. //iso1isolationLevelType_Invalid = 0,
  8065. //iso1isolationLevelType_Valid = 1,
  8066. //iso1isolationLevelType_Warning = 2,
  8067. //iso1isolationLevelType_Fault = 3,
  8068. //iso1isolationLevelType_No_IMD = 4
  8069. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8070. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8071. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8072. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8073. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8074. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8075. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8076. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8077. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8078. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8079. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8080. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8081. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8082. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8083. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8084. //iso1EVSENotificationType_None = 0,
  8085. //iso1EVSENotificationType_StopCharging = 1,
  8086. //iso1EVSENotificationType_ReNegotiation = 2
  8087. }
  8088. /*===========================================================================
  8089. FUNCTION: Proc_din_CableCheckRes
  8090. DESCRIPTION:
  8091. PRE-CONDITION:
  8092. INPUT:
  8093. OUTPUT:
  8094. GLOBAL VARIABLES:
  8095. =============================================================================*/
  8096. int Proc_din_CableCheckRes(int AcceptFd)
  8097. {
  8098. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8099. //if it is not the same, the packet should be ignored.
  8100. //STEP 1: ============ Initialize ============
  8101. int i = 0;
  8102. int errn = 0;
  8103. bitstream_t v2g_tx_stream;
  8104. static struct CableCheckResponse_DIN70121 *cab;
  8105. static struct ChargingInfoData *sys;
  8106. size_t pos = 0;
  8107. v2g_tx_stream.pos = &pos;
  8108. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8109. v2g_tx_stream.data = V2GTP_Tx_buf;
  8110. cab = &ShmCcsData->V2GMessage_DIN70121.CableCheckResponse;
  8111. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8112. cab->ResponseCode = OK_DIN70121;
  8113. cab->cnt++;
  8114. DEBUG_PRINTF_EVCOMM_DETAIL("CP_State = %d (%.02f V), V_now = %.02f, Isolation Status = %d, EVSEProcessing = %d\n",
  8115. sys->CpState,
  8116. sys->CpVoltage,
  8117. sys->PresentChargingVoltage,
  8118. sys->IsolationStatus,
  8119. cab->EVSEProcessing);
  8120. //[HEADER] Check Req SessionID
  8121. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  8122. {
  8123. cab->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  8124. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  8125. errn = -1;
  8126. }
  8127. //Check for SequenceError
  8128. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8129. {
  8130. cab->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  8131. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  8132. errn = -1;
  8133. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8134. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8135. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8136. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8137. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8138. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8139. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8140. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8141. }
  8142. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8143. if (sys->IsolationStatus == GFD_Invalid) //0: on going
  8144. {
  8145. //For PSU
  8146. sys->EvBatterytargetVoltage = CABLECHECK_TARGET_VOLTAGE; //500V //[To-Do] this should be modified to auto decision.
  8147. sys->EvBatterytargetCurrent = CABLECHECK_TARGET_CURRENT; //2A(default), unit: 1A
  8148. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  8149. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive; //4
  8150. cab->EVSEProcessing = dinEVSEProcessingType_Ongoing;
  8151. }
  8152. else if ((sys->IsolationStatus == GFD_Valid) || (sys->IsolationStatus == GFD_Warning)) //1: valid, 2: warning
  8153. {
  8154. //For PSU
  8155. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  8156. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  8157. if (sys->PresentChargingVoltage < 60) // < 60V
  8158. {
  8159. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  8160. sprintf(buf_log_evcomm, "[V2G][CableCheck]Pass (V_now = %.02f, Isolated = %d)",
  8161. sys->PresentChargingVoltage,
  8162. sys->IsolationStatus);
  8163. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8164. //IsolationStatus
  8165. if (sys->IsolationStatus == GFD_Valid)
  8166. {
  8167. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  8168. }
  8169. else if (sys->IsolationStatus == GFD_Warning)
  8170. {
  8171. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning;
  8172. }
  8173. else
  8174. {
  8175. sprintf(buf_log_evcomm,
  8176. "[WARNING]unexpected IsolationStatus(%d)",
  8177. sys->IsolationStatus);
  8178. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8179. }
  8180. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8181. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  8182. }
  8183. else
  8184. {
  8185. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  8186. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  8187. cab->EVSEProcessing = dinEVSEProcessingType_Ongoing;
  8188. }
  8189. }
  8190. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  8191. {
  8192. //For PSU
  8193. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  8194. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  8195. cab->ResponseCode = FAILED_DIN70121;
  8196. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8197. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_NotReady;
  8198. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  8199. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_CableCheckRes]IsolationStatus = 3 (fault)");
  8200. errn = -1;
  8201. }
  8202. else
  8203. {
  8204. //For PSU
  8205. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  8206. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  8207. cab->ResponseCode = FAILED_DIN70121;
  8208. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  8209. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_NotReady;
  8210. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  8211. sprintf(buf_log_evcomm,
  8212. "[Proc_din_CableCheckRes]Undefined Isolation Status(%d)",
  8213. sys->IsolationStatus);
  8214. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8215. }
  8216. //Check for CSU command of "Stop by EVSE"
  8217. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8218. {
  8219. cab->ResponseCode = FAILED_DIN70121;
  8220. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8221. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8222. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  8223. // errn = -1;
  8224. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_CableCheckRes]EVSE_Shutdown");
  8225. }
  8226. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8227. {
  8228. cab->ResponseCode = FAILED_DIN70121;
  8229. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8230. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8231. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  8232. errn = -1;
  8233. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_CableCheckRes]EVSE_EmergencyShutdown");
  8234. }
  8235. else if (ShmInternalComm->ChargingPermission == FALSE)
  8236. {
  8237. cab->ResponseCode = FAILED_DIN70121;
  8238. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8239. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8240. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  8241. // errn = -1;
  8242. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_CableCheckRes]ChargingPermission = FALSE");
  8243. }
  8244. else
  8245. {
  8246. //null
  8247. }
  8248. //Response to CP Error
  8249. #if CP_PROTECTION_MECHANISM == ENABLE
  8250. //#if 1
  8251. if (sys->CableCheckPreCountDownDone == TRUE) //[To-Do] Here should be modified to 2 seconds
  8252. {
  8253. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  8254. {
  8255. cab->ResponseCode = FAILED_DIN70121;
  8256. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8257. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8258. Update_V2G_Flow_Status(Other_Fault);
  8259. errn = -1;
  8260. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8261. //CCS_SECC_CP_State_Error (023889)
  8262. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8263. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8264. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8265. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  8266. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  8267. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  8268. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  8269. sprintf(buf_log_evcomm,
  8270. "[CableCheck]Emergency Stop by CP Error (%d, %.02f V, %d)\n",
  8271. sys->CpState,
  8272. sys->CpVoltage,
  8273. cab->cnt
  8274. );
  8275. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8276. //cab->cnt = 0;
  8277. }
  8278. }
  8279. #endif
  8280. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8281. #if PARAMETER_NORMAL_MODE == ENABLE
  8282. SHM_Read_din_CableCheckRes(&ccs_exi_doc_DIN, ShmCcsData);
  8283. #else
  8284. Sudo_Parameter_din_CableCheckRes();
  8285. #endif
  8286. //STEP 4: ============ Encode and Send Response Message ===========
  8287. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  8288. {
  8289. errn = -1;
  8290. }
  8291. //STEP 5: ============ Update Flags ===========
  8292. sys->ConnectorLocked = TRUE; //Inicating EVSE that the CCS Connector is Locked.
  8293. return errn;
  8294. }
  8295. /*===========================================================================
  8296. FUNCTION: Proc_iso1_CableCheckRes
  8297. DESCRIPTION:
  8298. PRE-CONDITION:
  8299. INPUT:
  8300. OUTPUT:
  8301. GLOBAL VARIABLES:
  8302. =============================================================================*/
  8303. int Proc_iso1_CableCheckRes(int AcceptFd)
  8304. {
  8305. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8306. //if it is not the same, the packet should be ignored.
  8307. //STEP 1: ============ Initialize ============
  8308. int i = 0;
  8309. int errn = 0;
  8310. bitstream_t v2g_tx_stream;
  8311. static struct CableCheckResponse_ISO15118_2014 *cab;
  8312. static struct ChargingInfoData *sys;
  8313. size_t pos = 0;
  8314. v2g_tx_stream.pos = &pos;
  8315. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8316. v2g_tx_stream.data = V2GTP_Tx_buf;
  8317. cab = &ShmCcsData->V2GMessage_ISO15118_2014.CableCheckResponse;
  8318. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8319. cab->ResponseCode = OK_ISO15118_2014;
  8320. cab->cnt++;
  8321. DEBUG_PRINTF_EVCOMM_DETAIL("CP_State = %d (%.02f V), V_now = %.02f, Isolation Status = %d, EVSEProcessing = %d\n",
  8322. sys->CpState,
  8323. sys->CpVoltage,
  8324. sys->PresentChargingVoltage,
  8325. sys->IsolationStatus,
  8326. cab->EVSEProcessing);
  8327. //[HEADER] Check Req SessionID
  8328. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  8329. {
  8330. cab->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  8331. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  8332. errn = -1;
  8333. }
  8334. //Check for SequenceError
  8335. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8336. {
  8337. cab->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  8338. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  8339. errn = -1;
  8340. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8341. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8342. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8343. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8344. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8345. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8346. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8347. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8348. }
  8349. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8350. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  8351. {
  8352. //For PSU
  8353. sys->EvBatterytargetVoltage = CABLECHECK_TARGET_VOLTAGE; //500V //[To-Do] this should be modified to auto decision.
  8354. sys->EvBatterytargetCurrent = CABLECHECK_TARGET_CURRENT; //2A(default), unit: 1A
  8355. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  8356. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  8357. cab->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  8358. }
  8359. else if ((sys->IsolationStatus == GFD_Valid) || (sys->IsolationStatus == GFD_Warning)) //1: valid, 2:waring
  8360. {
  8361. //For PSU
  8362. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  8363. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  8364. if (sys->PresentChargingVoltage < 60) // < 60V
  8365. {
  8366. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  8367. sprintf(buf_log_evcomm, "[V2G][CableCheck]Pass (V_now = %.02f, Isolated = %d)",
  8368. sys->PresentChargingVoltage,
  8369. sys->IsolationStatus);
  8370. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8371. //IsolationStatus
  8372. if (sys->IsolationStatus == GFD_Valid)
  8373. {
  8374. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  8375. }
  8376. else if (sys->IsolationStatus == GFD_Warning)
  8377. {
  8378. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning;
  8379. }
  8380. else
  8381. {
  8382. sprintf(buf_log_evcomm,
  8383. "[WARNING]unexpected IsolationStatus(%d)",
  8384. sys->IsolationStatus);
  8385. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8386. }
  8387. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8388. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  8389. }
  8390. else
  8391. {
  8392. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  8393. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  8394. cab->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  8395. }
  8396. }
  8397. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  8398. {
  8399. //For PSU
  8400. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  8401. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  8402. cab->ResponseCode = FAILED_ISO15118_2014;
  8403. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8404. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_NotReady;
  8405. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  8406. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CableCheckRes]IsolationStatus = 3 (fault)");
  8407. errn = -1;
  8408. }
  8409. //else if (sys->IsolationStatus == GFD_No_IMD){} //only for ISO15118
  8410. else
  8411. {
  8412. //For PSU
  8413. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  8414. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  8415. cab->ResponseCode = FAILED_ISO15118_2014;
  8416. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8417. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_NotReady;
  8418. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  8419. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CableCheckRes]Undefined Isolation Status.");
  8420. }
  8421. //Check for CSU command of "Stop by EVSE"
  8422. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8423. {
  8424. cab->ResponseCode = FAILED_ISO15118_2014;
  8425. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8426. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8427. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  8428. // errn = -1;
  8429. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CableCheckRes]EVSE_Shutdown");
  8430. }
  8431. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8432. {
  8433. cab->ResponseCode = FAILED_ISO15118_2014;
  8434. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8435. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8436. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  8437. errn = -1;
  8438. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CableCheckRes]EVSE_EmergencyShutdown");
  8439. }
  8440. else if (ShmInternalComm->ChargingPermission == FALSE)
  8441. {
  8442. cab->ResponseCode = FAILED_ISO15118_2014;
  8443. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8444. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8445. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  8446. // errn = -1;
  8447. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_CableCheckRes]ChargingPermission = FALSE");
  8448. }
  8449. else
  8450. {
  8451. //null
  8452. }
  8453. //Response to CP Error
  8454. #if CP_PROTECTION_MECHANISM == ENABLE
  8455. if (sys->CableCheckPreCountDownDone == TRUE) //[To-Do] Here should be modified to 2 seconds
  8456. {
  8457. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  8458. {
  8459. cab->ResponseCode = FAILED_ISO15118_2014;
  8460. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8461. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8462. Update_V2G_Flow_Status(Other_Fault);
  8463. errn = -1;
  8464. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8465. //CCS_SECC_CP_State_Error (023889)
  8466. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8467. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8468. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8469. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  8470. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  8471. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  8472. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  8473. sprintf(buf_log_evcomm,
  8474. "[CableCheck]Emergency Stop by CP Error (%d, %.02f V, %d)\n",
  8475. sys->CpState,
  8476. sys->CpVoltage,
  8477. cab->cnt
  8478. );
  8479. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8480. //cab->cnt = 0;
  8481. }
  8482. }
  8483. #endif
  8484. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8485. #if PARAMETER_NORMAL_MODE == ENABLE
  8486. SHM_Read_iso1_CableCheckRes(&ccs_exi_doc_ISO1, ShmCcsData);
  8487. #else
  8488. Sudo_Parameter_iso1_CableCheckRes();
  8489. #endif
  8490. //STEP 4: ============ Encode and Send Response Message ===========
  8491. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  8492. {
  8493. errn = -1;
  8494. }
  8495. //STEP 5: ============ Update Flags ===========
  8496. sys->ConnectorLocked = TRUE; //Inicating EVSE that the CCS Connector is Locked.
  8497. return errn;
  8498. }
  8499. /*===========================================================================
  8500. FUNCTION: Proc_din_CableCheckReq
  8501. DESCRIPTION:
  8502. PRE-CONDITION:
  8503. INPUT:
  8504. OUTPUT:
  8505. GLOBAL VARIABLES:
  8506. =============================================================================*/
  8507. int Proc_din_CableCheckReq(int AcceptFd)
  8508. {
  8509. int errn = 0;
  8510. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_CableCheckReq] Got CableCheckReq\n");
  8511. //Print the decoded XML Document
  8512. PRINT_XML_DOC_DIN_CableCheckReq(&ccs_exi_doc_DIN);
  8513. //Save into Share Memory
  8514. SHM_Save_din_CableCheckReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  8515. //Check for EV Error Code
  8516. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.CableCheckRequest.DC_EVStatus.EVErrorCode);
  8517. errn = Proc_din_CableCheckRes(AcceptFd);
  8518. if (errn == 0)
  8519. {
  8520. //send response successfully.
  8521. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]CableCheckRes");
  8522. }
  8523. else
  8524. {
  8525. sprintf(buf_log_evcomm,
  8526. "[Error][SeccComm][Proc_din_CableCheckReq]Proc_iso1_CableCheckRes(): %d (DEC)",
  8527. errn);
  8528. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8529. }
  8530. return errn;
  8531. }
  8532. /*===========================================================================
  8533. FUNCTION: Proc_iso1_CableCheckReq
  8534. DESCRIPTION:
  8535. PRE-CONDITION:
  8536. INPUT:
  8537. OUTPUT:
  8538. GLOBAL VARIABLES:
  8539. =============================================================================*/
  8540. int Proc_iso1_CableCheckReq(int AcceptFd)
  8541. {
  8542. int errn = 0;
  8543. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CableCheckReq] Got CableCheckReq");
  8544. //Print the decoded XML Document
  8545. PRINT_XML_DOC_ISO1_CableCheckReq(&ccs_exi_doc_ISO1);
  8546. //Save into Share Memory
  8547. SHM_Save_iso1_CableCheckReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  8548. //Check for EV Error Code
  8549. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.CableCheckRequest.DC_EVStatus.EVErrorCode);
  8550. errn = Proc_iso1_CableCheckRes(AcceptFd);
  8551. if (errn == 0)
  8552. {
  8553. //send response successfully.
  8554. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]CableCheckRes");
  8555. }
  8556. else
  8557. {
  8558. sprintf(buf_log_evcomm,
  8559. "[Error][SeccComm][Proc_iso1_CableCheckReq]Proc_iso1_CableCheckRes(): %d (DEC)",
  8560. errn);
  8561. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8562. }
  8563. return errn;
  8564. }
  8565. /*===========================================================================
  8566. FUNCTION: SHM_Init_din_PreChargeRes
  8567. DESCRIPTION:
  8568. PRE-CONDITION:
  8569. INPUT:
  8570. 1. shm_ccs
  8571. OUTPUT:
  8572. 1. shm_ccs
  8573. GLOBAL VARIABLES:
  8574. =============================================================================*/
  8575. void SHM_Init_din_PreChargeRes(struct CcsData *shm_ccs)
  8576. {
  8577. struct PreChargeResponse_DIN70121 *in;
  8578. in = &shm_ccs->V2GMessage_DIN70121.PreChargeResponse;
  8579. //----- [BODY (1/3)] ResponseCode -----
  8580. in->ResponseCode = dinresponseCodeType_OK;
  8581. //----- [BODY (2/3)] EVSEPresentVoltage -----
  8582. short value = 0; int multiplier = 0; unsigned char unit = 0;
  8583. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for Test
  8584. value = 0; multiplier = 0; unit = V_DIN70121; //waiting for CsuComm to update V to fit EV Target
  8585. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  8586. //----- [BODY (3/3)] DC_EVSEStatus -----
  8587. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  8588. }
  8589. /*===========================================================================
  8590. FUNCTION: Sudo_Parameter_din_PreChargeRes
  8591. DESCRIPTION:
  8592. PRE-CONDITION:
  8593. INPUT:
  8594. OUTPUT:
  8595. GLOBAL VARIABLES:
  8596. =============================================================================*/
  8597. void Sudo_Parameter_din_PreChargeRes()
  8598. {
  8599. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  8600. init_dinPreChargeResType(&ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes);
  8601. ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes_isUsed = 1u;
  8602. //----- [BODY (1/3)] ResponseCode -----
  8603. struct dinPreChargeResType *res;
  8604. res = &ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes;
  8605. res->ResponseCode = dinresponseCodeType_OK;
  8606. //----- [BODY (2/3)] EVSEPresentVoltage -----
  8607. res->EVSEPresentVoltage.Value = 3820;
  8608. res->EVSEPresentVoltage.Multiplier = -1;
  8609. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  8610. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  8611. // dinunitSymbolType_h = 0,
  8612. // dinunitSymbolType_m = 1,
  8613. // dinunitSymbolType_s = 2,
  8614. // dinunitSymbolType_A = 3,
  8615. // dinunitSymbolType_Ah = 4,
  8616. // dinunitSymbolType_V = 5,
  8617. // dinunitSymbolType_VA = 6,
  8618. // dinunitSymbolType_W = 7,
  8619. // dinunitSymbolType_W_s = 8,
  8620. // dinunitSymbolType_Wh = 9
  8621. //----- [BODY (3/3)] DC_EVSEStatus -----
  8622. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8623. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  8624. // dinisolationLevelType_Invalid = 0,
  8625. // dinisolationLevelType_Valid = 1,
  8626. // dinisolationLevelType_Warning = 2,
  8627. // dinisolationLevelType_Fault = 3
  8628. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8629. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8630. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  8631. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8632. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8633. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8634. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8635. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8636. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  8637. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  8638. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  8639. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  8640. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  8641. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8642. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  8643. // dinEVSENotificationType_None = 0,
  8644. // dinEVSENotificationType_StopCharging = 1,
  8645. // dinEVSENotificationType_ReNegotiation = 2
  8646. }
  8647. /*===========================================================================
  8648. FUNCTION: Sudo_Parameter_iso1_PreChargeRes
  8649. DESCRIPTION:
  8650. PRE-CONDITION:
  8651. INPUT:
  8652. OUTPUT:
  8653. GLOBAL VARIABLES:
  8654. =============================================================================*/
  8655. void Sudo_Parameter_iso1_PreChargeRes()
  8656. {
  8657. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8658. init_iso1PreChargeResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes);
  8659. ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes_isUsed = 1u;
  8660. //----- [BODY (1/3)] ResponseCode -----
  8661. struct iso1PreChargeResType *res;
  8662. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes;
  8663. res->ResponseCode = iso1responseCodeType_OK;
  8664. //----- [BODY (2/3)] EVSEPresentVoltage -----
  8665. res->EVSEPresentVoltage.Value = 3820;
  8666. res->EVSEPresentVoltage.Multiplier = -1;
  8667. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  8668. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  8669. //iso1unitSymbolType_h = 0,
  8670. //iso1unitSymbolType_m = 1,
  8671. //iso1unitSymbolType_s = 2,
  8672. //iso1unitSymbolType_A = 3,
  8673. //iso1unitSymbolType_V = 4,
  8674. //iso1unitSymbolType_W = 5,
  8675. //iso1unitSymbolType_Wh = 6
  8676. //----- [BODY (3/3)] DC_EVSEStatus -----
  8677. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8678. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  8679. //iso1isolationLevelType_Invalid = 0,
  8680. //iso1isolationLevelType_Valid = 1,
  8681. //iso1isolationLevelType_Warning = 2,
  8682. //iso1isolationLevelType_Fault = 3,
  8683. //iso1isolationLevelType_No_IMD = 4
  8684. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8685. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8686. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8687. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8688. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8689. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8690. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8691. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8692. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8693. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8694. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8695. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8696. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8697. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8698. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8699. //iso1EVSENotificationType_None = 0,
  8700. //iso1EVSENotificationType_StopCharging = 1,
  8701. //iso1EVSENotificationType_ReNegotiation = 2
  8702. }
  8703. /*===========================================================================
  8704. FUNCTION: Proc_din_PreChargeRes
  8705. DESCRIPTION:
  8706. PRE-CONDITION:
  8707. INPUT:
  8708. OUTPUT:
  8709. GLOBAL VARIABLES:
  8710. =============================================================================*/
  8711. int Proc_din_PreChargeRes(int AcceptFd)
  8712. {
  8713. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8714. //if it is not the same, the packet should be ignored.
  8715. //STEP 1: ============ Initialize ============
  8716. int i = 0;
  8717. int errn = 0;
  8718. bitstream_t v2g_tx_stream;
  8719. static struct PreChargeResponse_DIN70121 *pre;
  8720. static struct ChargingInfoData *sys;
  8721. size_t pos = 0;
  8722. v2g_tx_stream.pos = &pos;
  8723. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8724. v2g_tx_stream.data = V2GTP_Tx_buf;
  8725. pre = &ShmCcsData->V2GMessage_DIN70121.PreChargeResponse;
  8726. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8727. pre->ResponseCode = OK_DIN70121;
  8728. //EVSE Status Code
  8729. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8730. //[HEADER] Check Req SessionID
  8731. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  8732. {
  8733. pre->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  8734. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  8735. errn = -1;
  8736. }
  8737. //Check for SequenceError
  8738. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8739. {
  8740. pre->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  8741. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  8742. errn = -1;
  8743. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8744. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8745. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8746. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8747. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8748. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8749. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8750. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8751. }
  8752. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8753. SAVE_PhysicalValueType_DIN70121(&pre->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  8754. //Isolation Status
  8755. if (sys->IsolationStatus == GFD_Invalid) //0: invalid
  8756. {
  8757. #if 0
  8758. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  8759. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8760. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8761. Update_V2G_Flow_Status(Other_Fault);
  8762. errn = -1;
  8763. sprintf(buf_log_evcomm, "[Error][Proc_din_PreChargeRes]IsolationStatus = %d", sys->IsolationStatus);
  8764. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8765. #else
  8766. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  8767. #endif
  8768. }
  8769. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  8770. {
  8771. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  8772. }
  8773. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  8774. {
  8775. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  8776. }
  8777. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  8778. {
  8779. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]GFD_Fault => Emergency Shutdown");
  8780. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  8781. pre->ResponseCode = FAILED_DIN70121;
  8782. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8783. errn = -1;
  8784. }
  8785. else //GFD_No_IMD or other unexpected status
  8786. {
  8787. pre->ResponseCode = FAILED_DIN70121;
  8788. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  8789. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8790. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8791. Update_V2G_Flow_Status(Other_Fault);
  8792. errn = -1;
  8793. sprintf(buf_log_evcomm,
  8794. "[Error][Proc_din_PreChargeRes]IsolationStatus = %d (undefined)",
  8795. sys->IsolationStatus);
  8796. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8797. }
  8798. //Check for CSU command of "Stop by EVSE"
  8799. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8800. {
  8801. //Check for Alarm Code: CCS GFD trip (012235)
  8802. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8803. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8804. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8805. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8806. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8807. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8808. {
  8809. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]CCS GFD trip => EVSE_Shutdown");
  8810. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8811. }
  8812. else
  8813. {
  8814. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]EVSE_Shutdown");
  8815. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8816. }
  8817. pre->ResponseCode = FAILED_DIN70121;
  8818. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8819. errn = -1;
  8820. }
  8821. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8822. {
  8823. //Check for Alarm Code: CCS GFD trip (012235)
  8824. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8825. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8826. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8827. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8828. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8829. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8830. {
  8831. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]CCS GFD trip => EVSE_EmergencyShutdown");
  8832. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8833. }
  8834. else
  8835. {
  8836. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]EVSE_EmergencyShutdown");
  8837. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8838. }
  8839. pre->ResponseCode = FAILED_DIN70121;
  8840. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8841. errn = -1;
  8842. }
  8843. else if (ShmInternalComm->ChargingPermission == FALSE)
  8844. {
  8845. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]ChargingPermission = FALSE");
  8846. pre->ResponseCode = FAILED_DIN70121;
  8847. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8848. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8849. errn = -1;
  8850. }
  8851. else
  8852. {
  8853. //null
  8854. }
  8855. //Response to CP Error
  8856. #if CP_PROTECTION_MECHANISM == ENABLE
  8857. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  8858. {
  8859. pre->ResponseCode = FAILED_DIN70121;
  8860. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8861. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8862. Update_V2G_Flow_Status(Other_Fault);
  8863. errn = -1;
  8864. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8865. //CCS_SECC_CP_State_Error (023889)
  8866. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8867. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8868. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8869. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  8870. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  8871. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  8872. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  8873. sprintf(buf_log_evcomm,
  8874. "[Error][Proc_din_PreChargeRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  8875. sys->CpState,
  8876. sys->CpVoltage
  8877. );
  8878. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8879. }
  8880. #endif
  8881. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8882. #if PARAMETER_NORMAL_MODE == ENABLE
  8883. SHM_Read_din_PreChargeRes(&ccs_exi_doc_DIN, ShmCcsData);
  8884. #else
  8885. Sudo_Parameter_din_PreChargeRes();
  8886. #endif
  8887. //STEP 4: ============ Encode and Send Response Message ===========
  8888. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  8889. {
  8890. SAVE_SYS_LOG_MSG_EVCOMM("[Error][send_encoded_din_V2GTP_Stream]:Tx encoded msg error");
  8891. errn = -1;
  8892. }
  8893. //STEP 5: ============ Update Flags ===========
  8894. return errn;
  8895. }
  8896. /*===========================================================================
  8897. FUNCTION: Proc_iso1_PreChargeRes
  8898. DESCRIPTION:
  8899. PRE-CONDITION:
  8900. INPUT:
  8901. OUTPUT:
  8902. GLOBAL VARIABLES:
  8903. =============================================================================*/
  8904. int Proc_iso1_PreChargeRes(int AcceptFd)
  8905. {
  8906. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8907. //if it is not the same, the packet should be ignored.
  8908. //STEP 1: ============ Initialize ============
  8909. int i = 0;
  8910. int errn = 0;
  8911. bitstream_t v2g_tx_stream;
  8912. static struct PreChargeResponse_ISO15118_2014 *pre;
  8913. static struct ChargingInfoData *sys;
  8914. size_t pos = 0;
  8915. v2g_tx_stream.pos = &pos;
  8916. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8917. v2g_tx_stream.data = V2GTP_Tx_buf;
  8918. pre = &ShmCcsData->V2GMessage_ISO15118_2014.PreChargeResponse;
  8919. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8920. pre->ResponseCode = OK_ISO15118_2014;
  8921. //EVSE Status Code
  8922. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8923. //[HEADER] Check Req SessionID
  8924. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  8925. {
  8926. pre->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  8927. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  8928. errn = -1;
  8929. }
  8930. //Check for SequenceError
  8931. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8932. {
  8933. pre->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  8934. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  8935. errn = -1;
  8936. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8937. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8938. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8939. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8940. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8941. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8942. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8943. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8944. }
  8945. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8946. SAVE_PhysicalValueType_ISO15118_2014(&pre->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  8947. //Isolation Status
  8948. if (sys->IsolationStatus == GFD_Invalid) //0: invalid(on going)
  8949. {
  8950. #if 0
  8951. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  8952. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8953. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8954. // Update_V2G_Flow_Status(Other_Fault);
  8955. // errn = -1;
  8956. sprintf(buf_log_evcomm, "[Error][Proc_iso1_PreChargeRes]IsolationStatus = %d", sys->IsolationStatus);
  8957. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8958. #else
  8959. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  8960. #endif
  8961. }
  8962. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  8963. {
  8964. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  8965. }
  8966. else if (sys->IsolationStatus == GFD_Warning) //2: waring
  8967. {
  8968. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning; //1
  8969. }
  8970. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  8971. {
  8972. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]GFD_Fault => Emergency Shutdown");
  8973. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  8974. pre->ResponseCode = FAILED_ISO15118_2014;
  8975. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8976. errn = -1;
  8977. }
  8978. else
  8979. {
  8980. pre->ResponseCode = FAILED_ISO15118_2014;
  8981. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  8982. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8983. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8984. Update_V2G_Flow_Status(Other_Fault);
  8985. errn = -1;
  8986. sprintf(buf_log_evcomm,
  8987. "[Error][Proc_iso1_PreChargeRes]IsolationStatus = %d (undefined)",
  8988. sys->IsolationStatus);
  8989. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8990. }
  8991. //Check for CSU command of "Stop by EVSE"
  8992. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8993. {
  8994. //Check for Alarm Code: CCS GFD trip (012235)
  8995. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8996. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8997. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8998. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8999. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9000. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9001. {
  9002. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]CCS GFD trip => EVSE_Shutdown");
  9003. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  9004. }
  9005. else
  9006. {
  9007. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]EVSE_Shutdown");
  9008. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9009. }
  9010. pre->ResponseCode = FAILED_ISO15118_2014;
  9011. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9012. // errn = -1;
  9013. }
  9014. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9015. {
  9016. //Check for Alarm Code: CCS GFD trip (012235)
  9017. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9018. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9019. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9020. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9021. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9022. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9023. {
  9024. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]CCS GFD trip => EVSE_EmergencyShutdown");
  9025. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  9026. }
  9027. else
  9028. {
  9029. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]EVSE_EmergencyShutdown");
  9030. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9031. }
  9032. pre->ResponseCode = FAILED_ISO15118_2014;
  9033. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9034. errn = -1;
  9035. }
  9036. else if (ShmInternalComm->ChargingPermission == FALSE)
  9037. {
  9038. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]ChargingPermission = FALSE");
  9039. pre->ResponseCode = FAILED_ISO15118_2014;
  9040. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9041. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9042. // errn = -1;
  9043. }
  9044. else
  9045. {
  9046. //null
  9047. }
  9048. //Response to CP Error
  9049. #if CP_PROTECTION_MECHANISM == ENABLE
  9050. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9051. {
  9052. pre->ResponseCode = FAILED_ISO15118_2014;
  9053. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9054. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9055. Update_V2G_Flow_Status(Other_Fault);
  9056. errn = -1;
  9057. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9058. //CCS_SECC_CP_State_Error (023889)
  9059. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9060. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9061. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9062. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9063. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9064. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9065. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9066. sprintf(buf_log_evcomm,
  9067. "[Error][Proc_iso1_PreChargeRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  9068. sys->CpState,
  9069. sys->CpVoltage
  9070. );
  9071. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9072. }
  9073. #endif
  9074. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9075. #if PARAMETER_NORMAL_MODE == ENABLE
  9076. SHM_Read_iso1_PreChargeRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9077. #else
  9078. Sudo_Parameter_iso1_PreChargeRes();
  9079. #endif
  9080. //STEP 4: ============ Encode and Send Response Message ===========
  9081. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9082. {
  9083. SAVE_SYS_LOG_MSG_EVCOMM("[Error][send_encoded_iso1_V2GTP_Stream]:Tx encoded msg error");
  9084. errn = -1;
  9085. }
  9086. //STEP 5: ============ Update Flags ===========
  9087. return errn;
  9088. }
  9089. /*===========================================================================
  9090. FUNCTION: Proc_din_PreChargeReq
  9091. DESCRIPTION:
  9092. PRE-CONDITION:
  9093. INPUT:
  9094. OUTPUT:
  9095. GLOBAL VARIABLES:
  9096. =============================================================================*/
  9097. int Proc_din_PreChargeReq(int AcceptFd)
  9098. {
  9099. int errn = 0;
  9100. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_PreChargeReq] Got PreChargeReq");
  9101. //Print the decoded XML Document
  9102. PRINT_XML_DOC_DIN_PreChargeReq(&ccs_exi_doc_DIN);
  9103. //Save into Share Memory
  9104. SHM_Save_din_PreChargeReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  9105. //Check for EV Error Code
  9106. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PreChargeRequest.DC_EVStatus.EVErrorCode);
  9107. errn = Proc_din_PreChargeRes(AcceptFd);
  9108. if (errn == 0)
  9109. {
  9110. //send response successfully.
  9111. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]PreChargeRes");
  9112. }
  9113. else
  9114. {
  9115. sprintf(buf_log_evcomm,
  9116. "[Error][SeccComm][Proc_din_PreChargeReq]Proc_iso1_PreChargeRes(): %d (DEC)",
  9117. errn);
  9118. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9119. }
  9120. return errn;
  9121. }
  9122. /*===========================================================================
  9123. FUNCTION: Proc_iso1_PreChargeReq
  9124. DESCRIPTION:
  9125. PRE-CONDITION:
  9126. INPUT:
  9127. OUTPUT:
  9128. GLOBAL VARIABLES:
  9129. =============================================================================*/
  9130. int Proc_iso1_PreChargeReq(int AcceptFd)
  9131. {
  9132. int errn = 0;
  9133. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_PreChargeReq] Got PreChargeReq");
  9134. //Print the decoded XML Document
  9135. PRINT_XML_DOC_ISO1_PreChargeReq(&ccs_exi_doc_ISO1);
  9136. //Save into Share Memory
  9137. SHM_Save_iso1_PreChargeReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9138. //Check for EV Error Code
  9139. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PreChargeRequest.DC_EVStatus.EVErrorCode);
  9140. errn = Proc_iso1_PreChargeRes(AcceptFd);
  9141. if (errn == 0)
  9142. {
  9143. //send response successfully.
  9144. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]PreChargeRes");
  9145. }
  9146. else
  9147. {
  9148. sprintf(buf_log_evcomm,
  9149. "[Error][SeccComm][Proc_iso1_PreChargeReq]Proc_iso1_PreChargeRes(): %d (DEC)",
  9150. errn);
  9151. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9152. }
  9153. return errn;
  9154. }
  9155. /*===========================================================================
  9156. FUNCTION: SHM_Init_din_PowerDeliveryRes
  9157. DESCRIPTION:
  9158. PRE-CONDITION:
  9159. INPUT:
  9160. 1. shm_ccs
  9161. OUTPUT:
  9162. 1. shm_ccs
  9163. GLOBAL VARIABLES:
  9164. =============================================================================*/
  9165. void SHM_Init_din_PowerDeliveryRes(struct CcsData *shm_ccs)
  9166. {
  9167. struct PowerDeliveryResponse_DIN70121 *in;
  9168. in = &shm_ccs->V2GMessage_DIN70121.PowerDeliveryResponse;
  9169. //----- [BODY (1/3)] ResponseCode -----
  9170. in->ResponseCode = dinresponseCodeType_OK;
  9171. //----- [BODY (2/3)] AC_EVSEStatus -----
  9172. //ignore, since DIN 70121 doesn't support AC, yet.
  9173. //----- [BODY (2/3)] DC_EVSEStatus -----
  9174. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  9175. }
  9176. /*===========================================================================
  9177. FUNCTION: Sudo_Parameter_din_PowerDeliveryRes
  9178. DESCRIPTION:
  9179. PRE-CONDITION:
  9180. INPUT:
  9181. OUTPUT:
  9182. GLOBAL VARIABLES:
  9183. =============================================================================*/
  9184. void Sudo_Parameter_din_PowerDeliveryRes()
  9185. {
  9186. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  9187. init_dinPowerDeliveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes);
  9188. ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  9189. //----- [BODY (1/3)] ResponseCode -----
  9190. struct dinPowerDeliveryResType *res;
  9191. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  9192. res->ResponseCode = dinresponseCodeType_OK;
  9193. //----- [BODY (2/3)] AC_EVSEStatus -----
  9194. //ignore, since DIN 70121 doesn't support AC, yet.
  9195. //----- [BODY (2/3)] DC_EVSEStatus -----
  9196. res->DC_EVSEStatus_isUsed = 1u;
  9197. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  9198. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  9199. // dinisolationLevelType_Invalid = 0,
  9200. // dinisolationLevelType_Valid = 1,
  9201. // dinisolationLevelType_Warning = 2,
  9202. // dinisolationLevelType_Fault = 3
  9203. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  9204. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  9205. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  9206. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  9207. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  9208. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  9209. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  9210. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  9211. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  9212. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  9213. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  9214. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  9215. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  9216. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  9217. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  9218. // dinEVSENotificationType_None = 0,
  9219. // dinEVSENotificationType_StopCharging = 1,
  9220. // dinEVSENotificationType_ReNegotiation = 2
  9221. }
  9222. /*===========================================================================
  9223. FUNCTION: Sudo_Parameter_iso1_PowerDeliveryRes
  9224. DESCRIPTION:
  9225. PRE-CONDITION:
  9226. INPUT:
  9227. OUTPUT:
  9228. GLOBAL VARIABLES:
  9229. =============================================================================*/
  9230. void Sudo_Parameter_iso1_PowerDeliveryRes()
  9231. {
  9232. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  9233. init_iso1PowerDeliveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes);
  9234. ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  9235. //----- [BODY (1/3)] ResponseCode -----
  9236. struct iso1PowerDeliveryResType *res;
  9237. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  9238. res->ResponseCode = iso1responseCodeType_OK;
  9239. //----- [BODY (2/3)] AC_EVSEStatus -----
  9240. //ignore, since our ISO1 70121 doesn't support AC, yet.
  9241. //----- [BODY (2/3)] DC_EVSEStatus -----
  9242. res->DC_EVSEStatus_isUsed = 1u;
  9243. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  9244. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  9245. //iso1isolationLevelType_Invalid = 0,
  9246. //iso1isolationLevelType_Valid = 1,
  9247. //iso1isolationLevelType_Warning = 2,
  9248. //iso1isolationLevelType_Fault = 3,
  9249. //iso1isolationLevelType_No_IMD = 4
  9250. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  9251. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  9252. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  9253. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  9254. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  9255. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  9256. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  9257. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  9258. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  9259. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  9260. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  9261. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  9262. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  9263. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  9264. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9265. //iso1EVSENotificationType_None = 0,
  9266. //iso1EVSENotificationType_StopCharging = 1,
  9267. //iso1EVSENotificationType_ReNegotiation = 2
  9268. }
  9269. /*===========================================================================
  9270. FUNCTION: Proc_din_PowerDeliveryStartRes
  9271. DESCRIPTION:
  9272. PRE-CONDITION:
  9273. INPUT:
  9274. OUTPUT:
  9275. GLOBAL VARIABLES:
  9276. =============================================================================*/
  9277. int Proc_din_PowerDeliveryStartRes(int AcceptFd)
  9278. {
  9279. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9280. //if it is not the same, the packet should be ignored.
  9281. //STEP 1: ============ Initialize ============
  9282. int i = 0;
  9283. int errn = 0;
  9284. bitstream_t v2g_tx_stream;
  9285. struct dinPowerDeliveryResType *res;
  9286. struct ChargingInfoData *sys;
  9287. size_t pos = 0;
  9288. v2g_tx_stream.pos = &pos;
  9289. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9290. v2g_tx_stream.data = V2GTP_Tx_buf;
  9291. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  9292. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9293. res->ResponseCode = OK_DIN70121;
  9294. //[HEADER] Check Req SessionID
  9295. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  9296. {
  9297. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  9298. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  9299. errn = -1;
  9300. }
  9301. //Check for SequenceError
  9302. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9303. {
  9304. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  9305. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  9306. errn = -1;
  9307. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9308. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9309. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9310. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9311. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9312. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9313. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9314. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9315. }
  9316. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9317. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9318. #if PARAMETER_NORMAL_MODE == ENABLE
  9319. SHM_Read_din_PowerDeliveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  9320. #else
  9321. Sudo_Parameter_din_PowerDeliveryRes();
  9322. #endif
  9323. //EVSE Status Code
  9324. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  9325. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  9326. //Check for CSU command of "Stop by EVSE"
  9327. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9328. {
  9329. //res->ResponseCode = FAILED_DIN70121;
  9330. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9331. }
  9332. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9333. {
  9334. //res->ResponseCode = FAILED_DIN70121;
  9335. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9336. errn = -1;
  9337. }
  9338. else if (ShmInternalComm->ChargingPermission == FALSE)
  9339. {
  9340. //res->ResponseCode = FAILED_DIN70121;
  9341. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9342. }
  9343. //STEP 4: ============ Encode and Send Response Message ===========
  9344. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  9345. {
  9346. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_PowerDeliveryStartRes][Error]Tx encoded msg error");
  9347. errn = -1;
  9348. }
  9349. //STEP 5: ============ Update Flags ===========
  9350. return errn;
  9351. }
  9352. /*===========================================================================
  9353. FUNCTION: Proc_iso1_PowerDeliveryStartRes
  9354. DESCRIPTION:
  9355. PRE-CONDITION:
  9356. INPUT:
  9357. OUTPUT:
  9358. GLOBAL VARIABLES:
  9359. =============================================================================*/
  9360. int Proc_iso1_PowerDeliveryStartRes(int AcceptFd)
  9361. {
  9362. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9363. //if it is not the same, the packet should be ignored.
  9364. //STEP 1: ============ Initialize ============
  9365. int i = 0;
  9366. int errn = 0;
  9367. bitstream_t v2g_tx_stream;
  9368. struct iso1PowerDeliveryResType *res;
  9369. struct ChargingInfoData *sys;
  9370. size_t pos = 0;
  9371. v2g_tx_stream.pos = &pos;
  9372. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9373. v2g_tx_stream.data = V2GTP_Tx_buf;
  9374. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  9375. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9376. res->ResponseCode = OK_ISO15118_2014;
  9377. //[HEADER] Check Req SessionID
  9378. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9379. {
  9380. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9381. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  9382. errn = -1;
  9383. }
  9384. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9385. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9386. #if PARAMETER_NORMAL_MODE == ENABLE
  9387. SHM_Read_iso1_PowerDeliveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9388. #else
  9389. Sudo_Parameter_iso1_PowerDeliveryRes();
  9390. #endif
  9391. //EVSE Status Code
  9392. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  9393. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  9394. //Check for CSU command of "Stop by EVSE"
  9395. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9396. {
  9397. //res->ResponseCode = FAILED_ISO15118_2014;
  9398. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9399. }
  9400. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9401. {
  9402. //res->ResponseCode = FAILED_ISO15118_2014;
  9403. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9404. errn = -1;
  9405. }
  9406. else if (ShmInternalComm->ChargingPermission == FALSE)
  9407. {
  9408. //res->ResponseCode = FAILED_ISO15118_2014;
  9409. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9410. }
  9411. //STEP 4: ============ Encode and Send Response Message ===========
  9412. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9413. {
  9414. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_PowerDeliveryStartRes][Error]Tx encoded msg error");
  9415. errn = -1;
  9416. }
  9417. //STEP 5: ============ Update Flags ===========
  9418. return errn;
  9419. }
  9420. /*===========================================================================
  9421. FUNCTION: Proc_din_PowerDeliveryStartReq
  9422. DESCRIPTION:
  9423. PRE-CONDITION:
  9424. INPUT:
  9425. OUTPUT:
  9426. GLOBAL VARIABLES:
  9427. =============================================================================*/
  9428. int Proc_din_PowerDeliveryStartReq(int AcceptFd)
  9429. {
  9430. int errn = 0;
  9431. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PowerDeliveryStartReq");
  9432. //Print the decoded XML Document
  9433. PRINT_XML_DOC_DIN_PowerDeliveryReq(&ccs_exi_doc_DIN);
  9434. //Save into Share Memory
  9435. SHM_Save_din_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  9436. //Check for EV Error Code
  9437. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  9438. errn = Proc_din_PowerDeliveryStartRes(AcceptFd);
  9439. if (errn == 0)
  9440. {
  9441. //send response successfully.
  9442. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]PowerDeliveryStartRes");
  9443. }
  9444. else
  9445. {
  9446. sprintf(buf_log_evcomm,
  9447. "[Error][Proc_din_PowerDeliveryStartReq]Proc_iso1_PowerDeliveryStartRes(): %d (DEC)",
  9448. errn);
  9449. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9450. }
  9451. return errn;
  9452. }
  9453. /*===========================================================================
  9454. FUNCTION: Proc_iso1_PowerDeliveryStartReq
  9455. DESCRIPTION:
  9456. PRE-CONDITION:
  9457. INPUT:
  9458. OUTPUT:
  9459. GLOBAL VARIABLES:
  9460. =============================================================================*/
  9461. int Proc_iso1_PowerDeliveryStartReq(int AcceptFd)
  9462. {
  9463. int errn = 0;
  9464. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PowerDeliveryStartReq");
  9465. //Print the decoded XML Document
  9466. PRINT_XML_DOC_ISO1_PowerDeliveryReq(&ccs_exi_doc_ISO1);
  9467. //Save into Share Memory
  9468. SHM_Save_iso1_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9469. //Check for EV Error Code
  9470. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  9471. errn = Proc_iso1_PowerDeliveryStartRes(AcceptFd);
  9472. if (errn == 0)
  9473. {
  9474. //send response successfully.
  9475. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]PowerDeliveryStartRes");
  9476. }
  9477. else
  9478. {
  9479. sprintf(buf_log_evcomm,
  9480. "[Error][Proc_iso1_PowerDeliveryStartReq]Proc_iso1_PowerDeliveryStartRes(): %d (DEC)",
  9481. errn);
  9482. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9483. }
  9484. return errn;
  9485. }
  9486. /*===========================================================================
  9487. FUNCTION: SHM_Init_din_CurrentDemandRes
  9488. DESCRIPTION:
  9489. PRE-CONDITION:
  9490. INPUT:
  9491. 1. shm_ccs
  9492. OUTPUT:
  9493. 1. shm_ccs
  9494. GLOBAL VARIABLES:
  9495. =============================================================================*/
  9496. void SHM_Init_din_CurrentDemandRes(struct CcsData *shm_ccs)
  9497. {
  9498. struct CurrentDemandResponse_DIN70121 *in;
  9499. in = &shm_ccs->V2GMessage_DIN70121.CurrentDemandResponse;
  9500. //----- [BODY (1/10)] ResponseCode -----
  9501. in->ResponseCode = dinresponseCodeType_OK;
  9502. //----- [BODY (2/10)] DC_EVSEStatus -----
  9503. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  9504. //----- [BODY (3/10)] EVSEPresentVoltage -----
  9505. short value = 0; int multiplier = 0; unsigned char unit = 0;
  9506. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for test only.
  9507. value = 0; multiplier = 0; unit = V_DIN70121;
  9508. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  9509. //----- [BODY (4/10)] EVSEPresentCurrent -----
  9510. //value = 600; multiplier = -1; unit = A_DIN70121; //60A, for test only.
  9511. value = 0; multiplier = 0; unit = A_DIN70121;
  9512. SHM_Save_dinPhysicalValueType(&in->EVSEPresentCurrent, value, multiplier, unit);
  9513. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  9514. in->EVSECurrentLimitAchieved = FALSE;
  9515. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  9516. in->EVSEVoltageLimitAchieved = FALSE;
  9517. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  9518. in->EVSEPowerLimitAchieved = FALSE;
  9519. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  9520. //value = 7500; multiplier = -1; unit = V_DIN70121; //750V
  9521. value = 5000; multiplier = -1; unit = V_DIN70121; //500V
  9522. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumVoltageLimit, value, multiplier, unit);
  9523. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  9524. value = 600; multiplier = -1; unit = A_DIN70121; //60A
  9525. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumCurrentLimit, value, multiplier, unit);
  9526. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  9527. value = 3000; multiplier = 1; unit = W_DIN70121; //30KW
  9528. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumPowerLimit, value, multiplier, unit);
  9529. }
  9530. /*===========================================================================
  9531. FUNCTION: Sudo_Parameter_din_CurrentDemandRes
  9532. DESCRIPTION:
  9533. PRE-CONDITION:
  9534. INPUT:
  9535. OUTPUT:
  9536. GLOBAL VARIABLES:
  9537. =============================================================================*/
  9538. void Sudo_Parameter_din_CurrentDemandRes()
  9539. {
  9540. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  9541. init_dinCurrentDemandResType(&ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes);
  9542. ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes_isUsed = 1u;
  9543. //----- [BODY (1/10)] ResponseCode -----
  9544. struct dinCurrentDemandResType *res;
  9545. res = &ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes;
  9546. res->ResponseCode = dinresponseCodeType_OK;
  9547. //----- [BODY (2/10)] DC_EVSEStatus -----
  9548. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  9549. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  9550. // dinisolationLevelType_Invalid = 0,
  9551. // dinisolationLevelType_Valid = 1,
  9552. // dinisolationLevelType_Warning = 2,
  9553. // dinisolationLevelType_Fault = 3
  9554. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  9555. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  9556. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  9557. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  9558. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  9559. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  9560. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  9561. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  9562. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  9563. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  9564. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  9565. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  9566. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  9567. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  9568. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  9569. // dinEVSENotificationType_None = 0,
  9570. // dinEVSENotificationType_StopCharging = 1,
  9571. // dinEVSENotificationType_ReNegotiation = 2
  9572. //----- [BODY (3/10)] EVSEPresentVoltage -----
  9573. res->EVSEPresentVoltage.Value = 3820;
  9574. res->EVSEPresentVoltage.Multiplier = -1;
  9575. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  9576. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  9577. //----- [BODY (4/10)] EVSEPresentCurrent -----
  9578. res->EVSEPresentCurrent.Value = 1200;
  9579. res->EVSEPresentCurrent.Multiplier = -1;
  9580. res->EVSEPresentCurrent.Unit_isUsed = 1u;
  9581. res->EVSEPresentCurrent.Unit = dinunitSymbolType_A;
  9582. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  9583. res->EVSECurrentLimitAchieved = 0;
  9584. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  9585. res->EVSEVoltageLimitAchieved = 0;
  9586. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  9587. res->EVSEPowerLimitAchieved = 0;
  9588. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  9589. res->EVSEMaximumVoltageLimit_isUsed = 1u;
  9590. res->EVSEMaximumVoltageLimit.Value = 7500;
  9591. res->EVSEMaximumVoltageLimit.Multiplier = -1;
  9592. res->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  9593. res->EVSEMaximumVoltageLimit.Unit = dinunitSymbolType_V;
  9594. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  9595. res->EVSEMaximumCurrentLimit_isUsed = 1u;
  9596. res->EVSEMaximumCurrentLimit.Value = 1200;
  9597. res->EVSEMaximumCurrentLimit.Multiplier = -1;
  9598. res->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  9599. res->EVSEMaximumCurrentLimit.Unit = dinunitSymbolType_A;
  9600. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  9601. res->EVSEMaximumPowerLimit_isUsed = 1u;
  9602. res->EVSEMaximumPowerLimit.Value = 6000;
  9603. res->EVSEMaximumPowerLimit.Multiplier = 1;
  9604. res->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  9605. res->EVSEMaximumPowerLimit.Unit = dinunitSymbolType_W;
  9606. }
  9607. /*===========================================================================
  9608. FUNCTION: Sudo_Parameter_iso1_CurrentDemandRes
  9609. DESCRIPTION:
  9610. PRE-CONDITION:
  9611. INPUT:
  9612. OUTPUT:
  9613. GLOBAL VARIABLES:
  9614. =============================================================================*/
  9615. void Sudo_Parameter_iso1_CurrentDemandRes()
  9616. {
  9617. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  9618. init_iso1CurrentDemandResType(&ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes);
  9619. ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes_isUsed = 1u;
  9620. //----- [BODY (1/10)] ResponseCode -----
  9621. struct iso1CurrentDemandResType *res;
  9622. res = &ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes;
  9623. res->ResponseCode = iso1responseCodeType_OK;
  9624. //----- [BODY (2/10)] DC_EVSEStatus -----
  9625. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  9626. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  9627. //iso1isolationLevelType_Invalid = 0,
  9628. //iso1isolationLevelType_Valid = 1,
  9629. //iso1isolationLevelType_Warning = 2,
  9630. //iso1isolationLevelType_Fault = 3,
  9631. //iso1isolationLevelType_No_IMD = 4
  9632. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  9633. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  9634. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  9635. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  9636. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  9637. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  9638. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  9639. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  9640. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  9641. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  9642. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  9643. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  9644. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  9645. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  9646. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9647. //iso1EVSENotificationType_None = 0,
  9648. //iso1EVSENotificationType_StopCharging = 1,
  9649. //iso1EVSENotificationType_ReNegotiation = 2
  9650. //----- [BODY (3/10)] EVSEPresentVoltage -----
  9651. res->EVSEPresentVoltage.Value = 3820;
  9652. res->EVSEPresentVoltage.Multiplier = -1;
  9653. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  9654. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  9655. //----- [BODY (4/10)] EVSEPresentCurrent -----
  9656. res->EVSEPresentCurrent.Value = 1200;
  9657. res->EVSEPresentCurrent.Multiplier = -1;
  9658. //res->EVSEPresentCurrent.Unit_isUsed = 1u;
  9659. res->EVSEPresentCurrent.Unit = iso1unitSymbolType_A;
  9660. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  9661. res->EVSECurrentLimitAchieved = 0;
  9662. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  9663. res->EVSEVoltageLimitAchieved = 0;
  9664. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  9665. res->EVSEPowerLimitAchieved = 0;
  9666. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  9667. res->EVSEMaximumVoltageLimit_isUsed = 1u;
  9668. res->EVSEMaximumVoltageLimit.Value = 7500;
  9669. res->EVSEMaximumVoltageLimit.Multiplier = -1;
  9670. //res->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  9671. res->EVSEMaximumVoltageLimit.Unit = iso1unitSymbolType_V;
  9672. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  9673. res->EVSEMaximumCurrentLimit_isUsed = 1u;
  9674. res->EVSEMaximumCurrentLimit.Value = 1200;
  9675. res->EVSEMaximumCurrentLimit.Multiplier = -1;
  9676. //res->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  9677. res->EVSEMaximumCurrentLimit.Unit = iso1unitSymbolType_A;
  9678. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  9679. res->EVSEMaximumPowerLimit_isUsed = 1u;
  9680. res->EVSEMaximumPowerLimit.Value = 6000;
  9681. res->EVSEMaximumPowerLimit.Multiplier = 1;
  9682. //res->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  9683. res->EVSEMaximumPowerLimit.Unit = iso1unitSymbolType_W;
  9684. }
  9685. /*===========================================================================
  9686. FUNCTION: Sudo_Parameter_iso1_ChargingStatusRes
  9687. DESCRIPTION:
  9688. PRE-CONDITION:
  9689. INPUT:
  9690. OUTPUT:
  9691. GLOBAL VARIABLES:
  9692. =============================================================================*/
  9693. void Sudo_Parameter_iso1_ChargingStatusRes()
  9694. {
  9695. int i = 0;
  9696. struct iso1ChargingStatusResType *res;
  9697. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  9698. init_iso1ChargingStatusResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes);
  9699. res = &ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes;
  9700. ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes_isUsed = 1u;
  9701. //----- [BODY (1/10)] ResponseCode -----
  9702. res->ResponseCode = OK_ISO15118_2014;
  9703. //----- [BODY (2/10)] AC_EVSEStatus -----
  9704. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  9705. res->AC_EVSEStatus.NotificationMaxDelay = 0;
  9706. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9707. // iso1EVSENotificationType_None = 0,
  9708. // iso1EVSENotificationType_StopCharging = 1,
  9709. // iso1EVSENotificationType_ReNegotiation = 2
  9710. //----- [BODY (3/10)] EVSEMaxCurrent -----
  9711. res->EVSEMaxCurrent_isUsed = 1u;
  9712. res->EVSEMaxCurrent.Value = 32;
  9713. res->EVSEMaxCurrent.Multiplier = 0;
  9714. res->EVSEMaxCurrent.Unit = iso1unitSymbolType_A;
  9715. //----- [BODY (4/10)] SAScheduleTupleID -----
  9716. res->SAScheduleTupleID = 0;
  9717. //----- [BODY (5/10)] EVSEID -----
  9718. res->EVSEID.charactersLen = 37;
  9719. memset(res->EVSEID.characters, 0, sizeof(res->EVSEID.characters));
  9720. //sprintf(res->EVSEID.characters, CCS_AC_EVSEID);
  9721. //----- [BODY (6/10)] MeterInfo -----
  9722. res->MeterInfo_isUsed = 1u;
  9723. memset(res->MeterInfo.MeterID.characters, 0, sizeof(res->MeterInfo.MeterID.characters));
  9724. memset(res->MeterInfo.SigMeterReading.bytes, 0, sizeof(res->MeterInfo.SigMeterReading.bytes));
  9725. //[MeterInfo][1/5] MeterID
  9726. //sprintf(res->MeterInfo.MeterID , CCS_AC_METER_ID);
  9727. //[MeterInfo][2/5] SigMeterReading (optional)
  9728. //sprintf(res->MeterInfo.SigMeterReading , CCS_AC_SIG_METER_READING);
  9729. //[MeterInfo][3/5] MeterStatus (optional)
  9730. res->MeterInfo.MeterStatus = 0;
  9731. //[MeterInfo][4/5] MeterReading (optional)
  9732. res->MeterInfo.MeterReading = 12345;
  9733. //[MeterInfo][5/5] TMeter (optional)
  9734. res->MeterInfo.TMeter = 1586243587; //Unix Time Stamp format
  9735. //----- [BODY (7/10)] ReceiptRequired -----
  9736. res->ReceiptRequired_isUsed = 1u;
  9737. res->ReceiptRequired = FALSE; //optional
  9738. }
  9739. /*===========================================================================
  9740. FUNCTION: Check_EVErrorCode
  9741. DESCRIPTION:
  9742. PRE-CONDITION:
  9743. INPUT:
  9744. OUTPUT:
  9745. GLOBAL VARIABLES:
  9746. =============================================================================*/
  9747. void Check_EVErrorCode(int code)
  9748. {
  9749. struct ChargingInfoData *sys;
  9750. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9751. if (code != NO_ERROR) //NO_ERROR = 0
  9752. {
  9753. //Asking CSU to Stop
  9754. switch (code)
  9755. {
  9756. /*case dinDC_EVErrorCodeType_NO_ERROR: // = 0,
  9757. {
  9758. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(NO_ERROR)");
  9759. break;
  9760. }*/
  9761. case dinDC_EVErrorCodeType_FAILED_RESSTemperatureInhibit: // = 1,
  9762. { //023737
  9763. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9764. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9765. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9766. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9767. ShmStatusCodeData->PresentStatusCode[0][4] = 3;
  9768. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  9769. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(FAILED_RESSTemperatureInhibit)");
  9770. break;
  9771. }
  9772. case dinDC_EVErrorCodeType_FAILED_EVShiftPosition: // = 2,
  9773. {//023738
  9774. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9775. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9776. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9777. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9778. ShmStatusCodeData->PresentStatusCode[0][4] = 3;
  9779. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9780. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(FAILED_EVShiftPosition)");
  9781. break;
  9782. }
  9783. case dinDC_EVErrorCodeType_FAILED_ChargerConnectorLockFault: // = 3,
  9784. {
  9785. //023739
  9786. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9787. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9788. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9789. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9790. ShmStatusCodeData->PresentStatusCode[0][4] = 3;
  9791. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9792. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(ChargerConnectorLockFault)");
  9793. break;
  9794. }
  9795. case dinDC_EVErrorCodeType_FAILED_EVRESSMalfunction: // = 4,
  9796. {
  9797. //023740
  9798. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9799. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9800. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9801. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9802. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  9803. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  9804. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(FAILED_EVRESSMalfunction)");
  9805. break;
  9806. }
  9807. case dinDC_EVErrorCodeType_FAILED_ChargingCurrentdifferential: // = 5,
  9808. {
  9809. //023741
  9810. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9811. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9812. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9813. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9814. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  9815. ShmStatusCodeData->PresentStatusCode[0][5] = 1;
  9816. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(FAILED_ChargingCurrentdifferential)");
  9817. break;
  9818. }
  9819. case dinDC_EVErrorCodeType_FAILED_ChargingVoltageOutOfRange: // = 6,
  9820. {
  9821. //023742
  9822. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9823. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9824. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9825. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9826. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  9827. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  9828. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(FAILED_ChargingVoltageOutOfRange)");
  9829. break;
  9830. }
  9831. case dinDC_EVErrorCodeType_Reserved_A: // = 7,
  9832. {
  9833. //023983
  9834. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9835. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9836. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9837. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  9838. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9839. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  9840. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(Reserved_A)");
  9841. break;
  9842. }
  9843. case dinDC_EVErrorCodeType_Reserved_B: // = 8,
  9844. {
  9845. //023983
  9846. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9847. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9848. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9849. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  9850. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9851. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  9852. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(Reserved_B)");
  9853. break;
  9854. }
  9855. case dinDC_EVErrorCodeType_Reserved_C: // = 9,
  9856. {
  9857. //023983
  9858. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9859. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9860. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9861. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  9862. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9863. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  9864. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(Reserved_C)");
  9865. break;
  9866. }
  9867. case dinDC_EVErrorCodeType_FAILED_ChargingSystemIncompatibility:// = 10,
  9868. {
  9869. //023743
  9870. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9871. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9872. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9873. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9874. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  9875. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  9876. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(FAILED_ChargingSystemIncompatibility)");
  9877. break;
  9878. }
  9879. case dinDC_EVErrorCodeType_NoData: // = 11
  9880. {
  9881. //023746
  9882. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9883. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9884. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9885. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9886. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  9887. ShmStatusCodeData->PresentStatusCode[0][5] = 6;
  9888. DEBUG_PRINTF_EXI_ENGINE_DETAIL("(NoData)");
  9889. break;
  9890. }
  9891. default:
  9892. {
  9893. if(sys->EvBatterySoc==100)
  9894. {
  9895. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9896. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9897. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9898. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  9899. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  9900. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9901. }
  9902. else
  9903. {
  9904. //023983
  9905. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9906. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9907. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9908. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  9909. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9910. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  9911. }
  9912. DEBUG_PRINTF_EXI_ENGINE_DETAIL("([WARNING] Unexpected din EVErrorCode)");
  9913. break;
  9914. }
  9915. }
  9916. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9917. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9918. //Update_V2G_Flow_Status(Other_Fault);
  9919. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  9920. sprintf(buf_log_evcomm,
  9921. "Stop by EV (EVErrorCode = %d (DEC))",
  9922. code);
  9923. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9924. }
  9925. else
  9926. {
  9927. if(Check_V2G_Flow_Status()>=49)
  9928. {
  9929. if((sys->EvBatterySoc==100)||(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.ChargingComplete))
  9930. {
  9931. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9932. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9933. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9934. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  9935. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  9936. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9937. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  9938. sprintf(buf_log_evcomm,
  9939. "Check_EVErrorCode => Stop by EV (EVErrorCode = %d (023979))",
  9940. code);
  9941. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9942. }
  9943. else if(ShmStatusCodeData->PresentStatusCode[0][1] ==0)
  9944. {
  9945. if(!( (ShmInternalComm->ChargingPermission == FALSE)||
  9946. (sys->DC_EVSEStatus == EVSE_Shutdown)||
  9947. (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)))
  9948. {
  9949. //023983
  9950. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9951. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9952. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9953. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  9954. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9955. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  9956. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9957. sprintf(buf_log_evcomm,
  9958. "Check_EVErrorCode => Stop by EV (EVErrorCode = %d (023983))",
  9959. code);
  9960. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9961. }
  9962. }
  9963. }
  9964. }
  9965. }
  9966. /*===========================================================================
  9967. FUNCTION: Proc_din_CurrentDemandRes
  9968. DESCRIPTION:
  9969. PRE-CONDITION:
  9970. INPUT:
  9971. OUTPUT:
  9972. GLOBAL VARIABLES:
  9973. =============================================================================*/
  9974. int Proc_din_CurrentDemandRes(int AcceptFd)
  9975. {
  9976. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9977. //if it is not the same, the packet should be ignored.
  9978. //STEP 1: ============ Initialize ============
  9979. int i = 0;
  9980. int errn = 0;
  9981. bitstream_t v2g_tx_stream;
  9982. static struct CurrentDemandResponse_DIN70121 *cur;
  9983. static struct ChargingInfoData *sys;
  9984. static int EVSE_max_current;
  9985. int tmp = 0;
  9986. size_t pos = 0;
  9987. v2g_tx_stream.pos = &pos;
  9988. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9989. v2g_tx_stream.data = V2GTP_Tx_buf;
  9990. cur = &ShmCcsData->V2GMessage_DIN70121.CurrentDemandResponse;
  9991. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9992. cur->ResponseCode = OK_DIN70121;
  9993. //EVSE Status Code
  9994. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  9995. //[HEADER] Check Req SessionID
  9996. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  9997. {
  9998. cur->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  9999. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  10000. errn = -1;
  10001. }
  10002. //Check for SequenceError
  10003. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10004. {
  10005. cur->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  10006. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  10007. errn = -1;
  10008. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10009. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10010. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10011. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10012. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10013. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10014. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10015. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10016. }
  10017. //Check for negative EvBatteryMaxCurrent
  10018. if (sys->EvBatteryMaxCurrent < 0)
  10019. {
  10020. sprintf(buf_log_evcomm,
  10021. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  10022. sys->EvBatteryMaxCurrent);
  10023. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10024. cur->DC_EVSEStatus.EVSEStatusCode = dinresponseCodeType_FAILED_WrongChargeParameter; //16
  10025. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10026. errn = -1;
  10027. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10028. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  10029. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10030. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10031. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10032. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10033. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  10034. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  10035. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10036. }
  10037. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10038. SAVE_PhysicalValueType_DIN70121(&cur->EVSEPresentCurrent, (int) (sys->PresentChargingCurrent * 10), A_DIN70121);
  10039. SAVE_PhysicalValueType_DIN70121(&cur->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  10040. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == DISABLE
  10041. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_DIN70121);
  10042. #endif
  10043. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_DIN70121);
  10044. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_DIN70121);
  10045. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  10046. if (sys->EvBatteryMaxVoltage <= 500)
  10047. {
  10048. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumVoltageLimit, (int) (500 * 10), V_DIN70121); //500V
  10049. }
  10050. #endif
  10051. //Limit the EVTargetCurrent should be under EVSEMaximumCurrentLimit
  10052. if (sys->EvBatterytargetCurrent > sys->AvailableChargingCurrent)
  10053. {
  10054. sys->EvBatterytargetCurrent = sys->AvailableChargingCurrent;
  10055. //[To-Do] Limit is achieved flag
  10056. }
  10057. //Isolation Status
  10058. if (sys->IsolationStatus == GFD_Invalid) //0:invalid (on going)
  10059. {
  10060. #if 0
  10061. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  10062. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10063. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10064. sprintf(buf_log_evcomm, "[Error][Proc_din_CurrentDemandRes]IsolationStatus = %d", sys->IsolationStatus);
  10065. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10066. //Update_V2G_Flow_Status(Other_Fault);
  10067. //errn = -1;
  10068. #else
  10069. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  10070. #endif
  10071. }
  10072. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  10073. {
  10074. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  10075. }
  10076. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  10077. {
  10078. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  10079. }
  10080. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  10081. {
  10082. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  10083. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10084. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10085. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_CurrentDemandRes]GFD_Fault => Emergency Shutdown");
  10086. Update_V2G_Flow_Status(Other_Fault);
  10087. errn = -1;
  10088. }
  10089. else //GFD_No_IMD or other unexpected status
  10090. {
  10091. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  10092. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10093. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10094. sprintf(buf_log_evcomm, "[Error][Proc_din_CurrentDemandRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  10095. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10096. Update_V2G_Flow_Status(Other_Fault);
  10097. errn = -1;
  10098. }
  10099. //For testing with Tesla Model 3
  10100. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == ENABLE
  10101. //[CAUTION][To-Do] Decresement of Current is not implemented.
  10102. //SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumCurrentLimit, 10, A_DIN70121);
  10103. if (sys->EvBatterytargetCurrent <= 0)
  10104. {
  10105. EVSE_max_current = 50; //10A
  10106. cur->EVSEMaximumCurrentLimit.Value = 50; //10A
  10107. /*
  10108. DEBUG_PRINTF_EVCOMM_DETAIL("1PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  10109. sys->PresentChargingCurrent,
  10110. sys->EvBatterytargetCurrent,
  10111. EVSE_max_current,
  10112. cur->EVSEMaximumCurrentLimit.Value
  10113. );
  10114. */
  10115. }
  10116. else //1A
  10117. {
  10118. /*
  10119. DEBUG_PRINTF_EVCOMM_DETAIL("2PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  10120. sys->PresentChargingCurrent,
  10121. sys->EvBatterytargetCurrent,
  10122. EVSE_max_current,
  10123. cur->EVSEMaximumCurrentLimit.Value
  10124. );
  10125. */
  10126. if ((abs((int)sys->PresentChargingCurrent - (int)sys->EvBatterytargetCurrent) < 3)&&(abs((int)(EVSE_max_current/10) - (int)sys->EvBatterytargetCurrent) < 3))
  10127. {
  10128. tmp = EVSE_max_current + 50; //10A
  10129. if (tmp <= (int)(sys->AvailableChargingCurrent * 10))
  10130. {
  10131. cur->EVSEMaximumCurrentLimit.Value = (int)tmp;
  10132. EVSE_max_current = tmp;
  10133. }
  10134. else
  10135. {
  10136. cur->EVSEMaximumCurrentLimit.Value = (int) (sys->AvailableChargingCurrent * 10); //max is set to 40A
  10137. EVSE_max_current = (int) (sys->AvailableChargingCurrent * 10);
  10138. }
  10139. }
  10140. }
  10141. #endif
  10142. //Check for CSU command of "Stop by EVSE"
  10143. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10144. {
  10145. //Check for Alarm Code: CCS GFD trip (012235)
  10146. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  10147. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  10148. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  10149. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  10150. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  10151. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  10152. {
  10153. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][Error][CurrentDemandRes]CCS GFD trip => EVSE_Shutdown");
  10154. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  10155. }
  10156. else
  10157. {
  10158. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][Error][CurrentDemandRes]EVSE_Shutdown");
  10159. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  10160. }
  10161. //cur->ResponseCode = FAILED_DIN70121;
  10162. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10163. //errn = -1;
  10164. }
  10165. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10166. {
  10167. //Check for Alarm Code: CCS GFD trip (012235)
  10168. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  10169. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  10170. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  10171. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  10172. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  10173. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  10174. {
  10175. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][Error][CurrentDemandRes]CCS GFD trip => EVSE_EmergencyShutdown");
  10176. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  10177. }
  10178. else
  10179. {
  10180. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][Error][CurrentDemandRes]EVSE_EmergencyShutdown");
  10181. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  10182. }
  10183. //cur->ResponseCode = FAILED_DIN70121;
  10184. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10185. errn = -1;
  10186. }
  10187. else if (ShmInternalComm->ChargingPermission == FALSE)
  10188. {
  10189. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][Error][CurrentDemandRes]Permission OFF");
  10190. //cur->ResponseCode = FAILED_DIN70121;
  10191. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  10192. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10193. //errn = -1;
  10194. }
  10195. else
  10196. {
  10197. //null
  10198. }
  10199. //Response to CP Error
  10200. #if CP_PROTECTION_MECHANISM == ENABLE
  10201. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  10202. {
  10203. if(sys->CpState <= 1)
  10204. {
  10205. cur->ResponseCode = FAILED_DIN70121;
  10206. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10207. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10208. Update_V2G_Flow_Status(Other_Fault);
  10209. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10210. //CCS_SECC_CP_State_Error (023889)
  10211. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10212. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10213. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10214. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  10215. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  10216. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  10217. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  10218. sprintf(buf_log_evcomm,
  10219. "[CurrentDemand]Emergency Stop by CP Error (%d, %.02f V)",
  10220. sys->CpState,
  10221. sys->CpVoltage);
  10222. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10223. }
  10224. else
  10225. {
  10226. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][Error][CurrentDemandRes]EVSE Normal Stop");
  10227. //cur->ResponseCode = FAILED_DIN70121;
  10228. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  10229. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10230. //errn = -1;
  10231. }
  10232. }
  10233. #endif
  10234. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10235. #if PARAMETER_NORMAL_MODE == ENABLE
  10236. SHM_Read_din_CurrentDemandRes(&ccs_exi_doc_DIN, ShmCcsData);
  10237. #else
  10238. Sudo_Parameter_din_CurrentDemandRes();
  10239. #endif
  10240. //STEP 4: ============ Encode and Send Response Message ===========
  10241. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  10242. {
  10243. errn = -1;
  10244. }
  10245. //STEP 5: ============ Update Flags ===========
  10246. return errn;
  10247. }
  10248. /*===========================================================================
  10249. FUNCTION: Proc_iso1_CurrentDemandRes
  10250. DESCRIPTION:
  10251. PRE-CONDITION:
  10252. INPUT:
  10253. OUTPUT:
  10254. GLOBAL VARIABLES:
  10255. =============================================================================*/
  10256. int Proc_iso1_CurrentDemandRes(int AcceptFd)
  10257. {
  10258. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10259. //if it is not the same, the packet should be ignored.
  10260. //STEP 1: ============ Initialize ============
  10261. int i = 0;
  10262. int errn = 0;
  10263. bitstream_t v2g_tx_stream;
  10264. static struct CurrentDemandResponse_ISO15118_2014 *cur;
  10265. static struct ChargingInfoData *sys;
  10266. static int EVSE_max_current;
  10267. int tmp = 0;
  10268. size_t pos = 0;
  10269. v2g_tx_stream.pos = &pos;
  10270. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10271. v2g_tx_stream.data = V2GTP_Tx_buf;
  10272. cur = &ShmCcsData->V2GMessage_ISO15118_2014.CurrentDemandResponse;
  10273. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10274. cur->ResponseCode = OK_ISO15118_2014;
  10275. //EVSE Status Code
  10276. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10277. //[HEADER] Check Req SessionID
  10278. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10279. {
  10280. cur->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10281. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  10282. errn = -1;
  10283. }
  10284. //Check for SequenceError
  10285. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10286. {
  10287. cur->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10288. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  10289. errn = -1;
  10290. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10291. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10292. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10293. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10294. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10295. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10296. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10297. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10298. }
  10299. //Check for negative EvBatteryMaxCurrent
  10300. if (sys->EvBatteryMaxCurrent < 0)
  10301. {
  10302. sprintf(buf_log_evcomm,
  10303. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  10304. sys->EvBatteryMaxCurrent);
  10305. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10306. cur->ResponseCode = iso1responseCodeType_FAILED_WrongChargeParameter; //16
  10307. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10308. errn = -1;
  10309. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10310. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  10311. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10312. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10313. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10314. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10315. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  10316. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  10317. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10318. }
  10319. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10320. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEPresentCurrent, (int) (sys->PresentChargingCurrent * 10), A_ISO15118_2014);
  10321. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  10322. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == DISABLE
  10323. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  10324. #endif
  10325. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_ISO15118_2014);
  10326. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_ISO15118_2014);
  10327. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  10328. if (sys->EvBatteryMaxVoltage <= 500)
  10329. {
  10330. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumVoltageLimit, (int) (500 * 10), V_ISO15118_2014); //500V
  10331. }
  10332. #endif
  10333. //Limit the EVTargetCurrent should be under EVSEMaximumCurrentLimit
  10334. if (sys->EvBatterytargetCurrent > sys->AvailableChargingCurrent)
  10335. {
  10336. sys->EvBatterytargetCurrent = sys->AvailableChargingCurrent;
  10337. //[To-Do] Limit is achieved flag
  10338. }
  10339. //Isolation Status
  10340. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  10341. {
  10342. #if 0
  10343. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  10344. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10345. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10346. sprintf(buf_log_evcomm, "[Error][Proc_iso1_CurrentDemandRes]IsolationStatus = %d", sys->IsolationStatus);
  10347. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10348. // Update_V2G_Flow_Status(Other_Fault);
  10349. //errn = -1;
  10350. #else
  10351. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  10352. #endif
  10353. }
  10354. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  10355. {
  10356. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  10357. }
  10358. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  10359. {
  10360. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning; //2
  10361. }
  10362. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  10363. {
  10364. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  10365. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10366. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10367. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_CurrentDemandRes]GFD_Fault => EmergencyShutdown");
  10368. Update_V2G_Flow_Status(Other_Fault);
  10369. errn = -1;
  10370. }
  10371. else
  10372. {
  10373. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  10374. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10375. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10376. sprintf(buf_log_evcomm, "[Error][Proc_iso1_CurrentDemandRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  10377. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10378. Update_V2G_Flow_Status(Other_Fault);
  10379. errn = -1;
  10380. }
  10381. //For testing with Tesla Model 3
  10382. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == ENABLE
  10383. //[CAUTION][To-Do] Decresement of Current is not implemented.
  10384. //SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumCurrentLimit, 10, A_ISO15118_2014);
  10385. if (sys->EvBatterytargetCurrent <= 0)
  10386. {
  10387. EVSE_max_current = 50; //10A
  10388. cur->EVSEMaximumCurrentLimit.Value = 50; //10A
  10389. /*
  10390. DEBUG_PRINTF_EVCOMM_DETAIL("1PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  10391. sys->PresentChargingCurrent,
  10392. sys->EvBatterytargetCurrent,
  10393. EVSE_max_current,
  10394. cur->EVSEMaximumCurrentLimit.Value
  10395. );
  10396. */
  10397. }
  10398. else //1A
  10399. {
  10400. /*
  10401. DEBUG_PRINTF_EVCOMM_DETAIL("2PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  10402. sys->PresentChargingCurrent,
  10403. sys->EvBatterytargetCurrent,
  10404. EVSE_max_current,
  10405. cur->EVSEMaximumCurrentLimit.Value
  10406. );
  10407. */
  10408. if ((abs((int)sys->PresentChargingCurrent - (int)sys->EvBatterytargetCurrent) < 3)&&(abs((int)(EVSE_max_current/10) - (int)sys->EvBatterytargetCurrent) < 3))
  10409. {
  10410. tmp = EVSE_max_current + 50; //10A
  10411. if (tmp <= (int)(sys->AvailableChargingCurrent * 10))
  10412. {
  10413. cur->EVSEMaximumCurrentLimit.Value = (int)tmp;
  10414. EVSE_max_current = tmp;
  10415. }
  10416. else
  10417. {
  10418. cur->EVSEMaximumCurrentLimit.Value = (int) (sys->AvailableChargingCurrent * 10); //max is set to 40A
  10419. EVSE_max_current = (int) (sys->AvailableChargingCurrent * 10);
  10420. }
  10421. }
  10422. }
  10423. #endif
  10424. //Check for CSU command of "Stop by EVSE"
  10425. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10426. {
  10427. //Check for Alarm Code: CCS GFD trip (012235)
  10428. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  10429. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  10430. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  10431. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  10432. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  10433. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  10434. {
  10435. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][Error][CurrentDemandRes]CCS GFD trip => EVSE_Shutdown");
  10436. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  10437. }
  10438. else
  10439. {
  10440. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][Error][CurrentDemandRes]EVSE_Shutdown");
  10441. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  10442. }
  10443. //cur->ResponseCode = FAILED_ISO15118_2014;
  10444. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10445. //errn = -1;
  10446. }
  10447. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10448. {
  10449. //Check for Alarm Code: CCS GFD trip (012235)
  10450. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  10451. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  10452. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  10453. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  10454. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  10455. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  10456. {
  10457. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][Error][CurrentDemandRes]CCS GFD trip => EVSE_EmergencyShutdown");
  10458. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  10459. }
  10460. else
  10461. {
  10462. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][Error][CurrentDemandRes]EVSE_EmergencyShutdown");
  10463. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  10464. }
  10465. //cur->ResponseCode = FAILED_ISO15118_2014;
  10466. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10467. errn = -1;
  10468. }
  10469. else if (ShmInternalComm->ChargingPermission == FALSE)
  10470. {
  10471. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][Error][CurrentDemandRes]Permission OFF");
  10472. //cur->ResponseCode = FAILED_ISO15118_2014;
  10473. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  10474. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10475. //errn = -1;
  10476. }
  10477. else
  10478. {
  10479. //null
  10480. }
  10481. //Response to CP Error
  10482. #if CP_PROTECTION_MECHANISM == ENABLE
  10483. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  10484. {
  10485. if(sys->CpState <= 1)
  10486. {
  10487. cur->ResponseCode = FAILED_ISO15118_2014;
  10488. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10489. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10490. Update_V2G_Flow_Status(Other_Fault);
  10491. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10492. //CCS_SECC_CP_State_Error (023889)
  10493. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10494. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10495. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10496. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  10497. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  10498. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  10499. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  10500. sprintf(buf_log_evcomm,
  10501. "[CurrentDemand]Emergency Stop by CP Error (%d, %.02f V)",
  10502. sys->CpState,
  10503. sys->CpVoltage);
  10504. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10505. }
  10506. else
  10507. {
  10508. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][Error][CurrentDemandRes]EVSE Normal Stop");
  10509. //cur->ResponseCode = FAILED_ISO15118_2014;
  10510. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  10511. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10512. }
  10513. }
  10514. #endif
  10515. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10516. #if PARAMETER_NORMAL_MODE == ENABLE
  10517. SHM_Read_iso1_CurrentDemandRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10518. #else
  10519. Sudo_Parameter_iso1_CurrentDemandRes();
  10520. #endif
  10521. //STEP 4: ============ Encode and Send Response Message ===========
  10522. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10523. {
  10524. errn = -1;
  10525. }
  10526. //STEP 5: ============ Update Flags ===========
  10527. return errn;
  10528. }
  10529. /*===========================================================================
  10530. FUNCTION: Proc_iso1_ChargingStatusRes
  10531. DESCRIPTION:
  10532. PRE-CONDITION:
  10533. INPUT:
  10534. OUTPUT:
  10535. GLOBAL VARIABLES:
  10536. =============================================================================*/
  10537. int Proc_iso1_ChargingStatusRes(int AcceptFd)
  10538. {
  10539. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10540. //if it is not the same, the packet should be ignored.
  10541. //STEP 1: ============ Initialize ============
  10542. int i = 0;
  10543. int errn = 0;
  10544. bitstream_t v2g_tx_stream;
  10545. static struct ChargingStatusResponse_ISO15118_2014 *res;
  10546. static struct ChargingInfoData *sys;
  10547. size_t pos = 0;
  10548. v2g_tx_stream.pos = &pos;
  10549. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10550. v2g_tx_stream.data = V2GTP_Tx_buf;
  10551. res = &ShmCcsData->V2GMessage_ISO15118_2014.ChargingStatusResponse;
  10552. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10553. //Init
  10554. res->ResponseCode = OK_ISO15118_2014;
  10555. res->ReceiptRequired = FALSE; //optional
  10556. res->SAScheduleTupleID = 1;
  10557. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  10558. res->AC_EVSEStatus.NotificationMaxDelay = 0;
  10559. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  10560. // iso1EVSENotificationType_None = 0,
  10561. // iso1EVSENotificationType_StopCharging = 1,
  10562. // iso1EVSENotificationType_ReNegotiation = 2
  10563. //[HEADER] Check Req SessionID
  10564. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10565. {
  10566. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10567. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  10568. errn = -1;
  10569. }
  10570. //Check for SequenceError
  10571. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10572. {
  10573. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10574. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  10575. errn = -1;
  10576. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10577. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10578. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10579. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10580. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10581. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10582. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10583. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10584. }
  10585. //EVSE ID
  10586. memset(res->EVSEID, 0, sizeof(res->EVSEID));
  10587. res->EVSEID[0]='Z';
  10588. res->EVSEID[1]='Z';
  10589. res->EVSEID[2]='0';
  10590. res->EVSEID[3]='0';
  10591. res->EVSEID[4]='0';
  10592. res->EVSEID[5]='0';
  10593. res->EVSEID[6]='0';
  10594. //sprintf(res->EVSEID, CCS_AC_EVSEID);
  10595. //[MeterInfo][0/5] init
  10596. //memset(res->MeterInfo.MeterID.characters, 0, sizeof(res->MeterInfo.MeterID.characters));
  10597. //memset(res->MeterInfo.SigMeterReading.bytes, 0, sizeof(res->MeterInfo.SigMeterReading.bytes));
  10598. //[MeterInfo][1/5] MeterID
  10599. strcpy(res->MeterInfo.MeterID , ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10600. //[MeterInfo][2/5] SigMeterReading (optional)
  10601. //sprintf(res->MeterInfo.SigMeterReading , CCS_AC_SIG_METER_READING);
  10602. //[MeterInfo][3/5] MeterStatus (optional)
  10603. res->MeterInfo.MeterStatus = 1;
  10604. //[MeterInfo][4/5] MeterReading (optional)
  10605. res->MeterInfo.MeterReading = ShmInternalComm->AC_MeterReadingValue;//Wh
  10606. //[MeterInfo][5/5] TMeter (optional)
  10607. res->MeterInfo.TMeter = time(NULL); //Unix Time Stamp format
  10608. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10609. SAVE_PhysicalValueType_ISO15118_2014(&res->EVSEMaxCurrent, (int)(sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  10610. //Isolation Status (RCD)
  10611. if (ShmInternalComm->AC_RcdStatus == 1) //RCD tripped,Isolation is invalid
  10612. {
  10613. res->AC_EVSEStatus.RCD = TRUE; //FALSE(no error), TRUE(error is detected)
  10614. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  10615. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10616. sprintf(buf_log_evcomm, "[ISO1][Error][ChargingStatusRes]IsolationStatus = %d", sys->IsolationStatus);
  10617. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10618. Update_V2G_Flow_Status(Other_Fault);
  10619. errn = -1;
  10620. }
  10621. if (ShmInternalComm->ChargingPermission == FALSE)
  10622. {
  10623. //res->ResponseCode = FAILED_ISO15118_2014;
  10624. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  10625. sprintf(buf_log_evcomm, "[ISO1][ChargingStatusRes]ChargingPermission = FALSE");
  10626. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10627. //errn = -1;
  10628. }
  10629. //Response to CP Error
  10630. //#if CP_PROTECTION_MECHANISM == ENABLE
  10631. #if 1
  10632. // if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  10633. if ((sys->CpState < 3) || (sys->CpState > 5)) //State C (6V), D (3V)
  10634. {
  10635. res->ResponseCode = FAILED_ISO15118_2014;
  10636. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  10637. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10638. Update_V2G_Flow_Status(Other_Fault);
  10639. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10640. //CCS_SECC_CP_State_Error (023889)
  10641. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10642. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10643. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10644. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  10645. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  10646. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  10647. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  10648. sprintf(buf_log_evcomm,
  10649. "[ChargingStatus]Emergency Stop by CP Error (%d, %.02f V)",
  10650. sys->CpState,
  10651. sys->CpVoltage);
  10652. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10653. }
  10654. #endif
  10655. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10656. #if PARAMETER_NORMAL_MODE == ENABLE
  10657. SHM_Read_iso1_ChargingStatusRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10658. #else
  10659. Sudo_Parameter_iso1_ChargingStatusRes();
  10660. #endif
  10661. //STEP 4: ============ Encode and Send Response Message ===========
  10662. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10663. {
  10664. errn = -1;
  10665. }
  10666. //STEP 5: ============ Update Flags ===========
  10667. return errn;
  10668. }
  10669. /*===========================================================================
  10670. FUNCTION: Proc_din_CurrentDemandReq
  10671. DESCRIPTION:
  10672. PRE-CONDITION:
  10673. INPUT:
  10674. OUTPUT:
  10675. GLOBAL VARIABLES:
  10676. =============================================================================*/
  10677. int Proc_din_CurrentDemandReq(int AcceptFd)
  10678. {
  10679. int errn = 0;
  10680. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_CurrentDemandReq] Got CurrentDemandReq\n");
  10681. //Print the decoded XML Document
  10682. PRINT_XML_DOC_DIN_CurrentDemandReq(&ccs_exi_doc_DIN);
  10683. //Save into Share Memory
  10684. SHM_Save_din_CurrentDemandReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10685. //Check for EV Error Code
  10686. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.CurrentDemandRequest.DC_EVStatus.EVErrorCode);
  10687. errn = Proc_din_CurrentDemandRes(AcceptFd);
  10688. if (errn == 0)
  10689. {
  10690. //Response is sent successfully.
  10691. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]CurrentDemandRes");
  10692. }
  10693. else
  10694. {
  10695. sprintf(buf_log_evcomm,
  10696. "[DIN][Error][CurrentDemandReq]CurrentDemandRes: fail(%d,DEC)",
  10697. errn);
  10698. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10699. }
  10700. return errn;
  10701. }
  10702. /*===========================================================================
  10703. FUNCTION: Proc_iso1_CurrentDemandReq
  10704. DESCRIPTION:
  10705. PRE-CONDITION:
  10706. INPUT:
  10707. OUTPUT:
  10708. GLOBAL VARIABLES:
  10709. =============================================================================*/
  10710. int Proc_iso1_CurrentDemandReq(int AcceptFd)
  10711. {
  10712. int errn = 0;
  10713. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CurrentDemandReq] Got CurrentDemandReq\n");
  10714. //Print the decoded XML Document
  10715. PRINT_XML_DOC_ISO1_CurrentDemandReq(&ccs_exi_doc_ISO1);
  10716. //Save into Share Memory
  10717. SHM_Save_iso1_CurrentDemandReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10718. //Check for EV Error Code
  10719. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.CurrentDemandRequest.DC_EVStatus.EVErrorCode);
  10720. errn = Proc_iso1_CurrentDemandRes(AcceptFd);
  10721. if (errn == 0)
  10722. {
  10723. //Response is sent successfully.
  10724. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]CurrentDemandRes");
  10725. }
  10726. else
  10727. {
  10728. sprintf(buf_log_evcomm,
  10729. "[ISO1][Error][CurrentDemandReq]CurrentDemandRes: fail(%d,DEC)",
  10730. errn);
  10731. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10732. }
  10733. return errn;
  10734. }
  10735. /*===========================================================================
  10736. FUNCTION: Proc_iso1_ChargingStatusReq
  10737. DESCRIPTION:
  10738. PRE-CONDITION:
  10739. INPUT:
  10740. OUTPUT:
  10741. GLOBAL VARIABLES:
  10742. =============================================================================*/
  10743. int Proc_iso1_ChargingStatusReq(int AcceptFd)
  10744. {
  10745. int errn = 0;
  10746. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargingStatusReq] Got ChargingStatusReq\n");
  10747. //Print the decoded XML Document
  10748. PRINT_XML_DOC_ISO1_ChargingStatusReq(&ccs_exi_doc_ISO1);
  10749. //Save into Share Memory
  10750. SHM_Save_iso1_ChargingStatusReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10751. //Check for EV Error Code
  10752. //no content in ISO1
  10753. errn = Proc_iso1_ChargingStatusRes(AcceptFd);
  10754. if (errn == 0)
  10755. {
  10756. //Response is sent successfully.
  10757. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]ChargingStatusRes");
  10758. }
  10759. else
  10760. {
  10761. sprintf(buf_log_evcomm,
  10762. "[ISO1][Error][ChargingStatusReq]ChargingStatusRes: fail(%d,DEC)",
  10763. errn);
  10764. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10765. }
  10766. return errn;
  10767. }
  10768. /*===========================================================================
  10769. FUNCTION: Proc_din_PowerDeliveryStopRes
  10770. DESCRIPTION:
  10771. PRE-CONDITION:
  10772. INPUT:
  10773. OUTPUT:
  10774. GLOBAL VARIABLES:
  10775. =============================================================================*/
  10776. int Proc_din_PowerDeliveryStopRes(int AcceptFd)
  10777. {
  10778. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10779. //if it is not the same, the packet should be ignored.
  10780. //STEP 1: ============ Initialize ============
  10781. int i = 0;
  10782. int errn = 0;
  10783. bitstream_t v2g_tx_stream;
  10784. struct dinPowerDeliveryResType *res;
  10785. struct ChargingInfoData *sys;
  10786. size_t pos = 0;
  10787. v2g_tx_stream.pos = &pos;
  10788. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10789. v2g_tx_stream.data = V2GTP_Tx_buf;
  10790. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  10791. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10792. res->ResponseCode = OK_DIN70121;
  10793. //[HEADER] Check Req SessionID
  10794. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  10795. {
  10796. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  10797. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  10798. errn = -1;
  10799. }
  10800. //Check for SequenceError
  10801. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10802. {
  10803. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  10804. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  10805. errn = -1;
  10806. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10807. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10808. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10809. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10810. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10811. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10812. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10813. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10814. }
  10815. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10816. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10817. #if PARAMETER_NORMAL_MODE == ENABLE
  10818. ShmCcsData->V2GMessage_DIN70121.PowerDeliveryResponse.DC_EVSEStatus.EVSEStatusCode = EVSE_NotReady;
  10819. SHM_Read_din_PowerDeliveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  10820. #else
  10821. Sudo_Parameter_din_PreChargeRes();
  10822. #endif
  10823. //EVSE Status Code
  10824. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  10825. //Check for CSU command of "Stop by EVSE"
  10826. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10827. {
  10828. //res->ResponseCode = FAILED_DIN70121;
  10829. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10830. }
  10831. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10832. {
  10833. //res->ResponseCode = FAILED_DIN70121;
  10834. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10835. errn = -1;
  10836. }
  10837. else if (ShmInternalComm->ChargingPermission == FALSE)
  10838. {
  10839. //res->ResponseCode = FAILED_DIN70121;
  10840. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10841. }
  10842. //STEP 4: ============ Encode and Send Response Message ===========
  10843. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  10844. {
  10845. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_PowerDeliveryStopRes][Error]Tx encoded msg error");
  10846. errn = -1;
  10847. }
  10848. //STEP 5: ============ Update Flags ===========
  10849. return errn;
  10850. }
  10851. /*===========================================================================
  10852. FUNCTION: Proc_iso1_PowerDeliveryStopRes
  10853. DESCRIPTION:
  10854. PRE-CONDITION:
  10855. INPUT:
  10856. OUTPUT:
  10857. GLOBAL VARIABLES:
  10858. =============================================================================*/
  10859. int Proc_iso1_PowerDeliveryStopRes(int AcceptFd)
  10860. {
  10861. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10862. //if it is not the same, the packet should be ignored.
  10863. //STEP 1: ============ Initialize ============
  10864. int i = 0;
  10865. int errn = 0;
  10866. bitstream_t v2g_tx_stream;
  10867. struct iso1PowerDeliveryResType *res;
  10868. struct ChargingInfoData *sys;
  10869. size_t pos = 0;
  10870. v2g_tx_stream.pos = &pos;
  10871. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10872. v2g_tx_stream.data = V2GTP_Tx_buf;
  10873. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  10874. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10875. res->ResponseCode = OK_ISO15118_2014;
  10876. //[HEADER] Check Req SessionID
  10877. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10878. {
  10879. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10880. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  10881. errn = -1;
  10882. }
  10883. //Check for SequenceError
  10884. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10885. {
  10886. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10887. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  10888. errn = -1;
  10889. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10890. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10891. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10892. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10893. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10894. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10895. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10896. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10897. }
  10898. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10899. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10900. #if PARAMETER_NORMAL_MODE == ENABLE
  10901. if(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.ChargeProgress==iso1chargeProgressType_Stop)
  10902. ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryResponse.DC_EVSEStatus.DC_EVSEStatusCode = EVSE_NotReady;
  10903. SHM_Read_iso1_PowerDeliveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10904. #else
  10905. Sudo_Parameter_iso1_PreChargeRes();
  10906. #endif
  10907. //EVSE Status Code
  10908. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10909. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1 /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  10910. //Check for CSU command of "Stop by EVSE"
  10911. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10912. {
  10913. //res->ResponseCode = FAILED_ISO15118_2014;
  10914. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  10915. }
  10916. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10917. {
  10918. //res->ResponseCode = FAILED_ISO15118_2014;
  10919. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10920. errn = -1;
  10921. }
  10922. else if (ShmInternalComm->ChargingPermission == FALSE)
  10923. {
  10924. //res->ResponseCode = FAILED_ISO15118_2014;
  10925. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  10926. }
  10927. //STEP 4: ============ Encode and Send Response Message ===========
  10928. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10929. {
  10930. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_PowerDeliveryStopRes][Error]Tx encoded msg error");
  10931. errn = -1;
  10932. }
  10933. //STEP 5: ============ Update Flags ===========
  10934. return errn;
  10935. }
  10936. /*===========================================================================
  10937. FUNCTION: Proc_din_PowerDeliveryStopReq
  10938. DESCRIPTION:
  10939. PRE-CONDITION:
  10940. INPUT:
  10941. OUTPUT:
  10942. GLOBAL VARIABLES:
  10943. =============================================================================*/
  10944. int Proc_din_PowerDeliveryStopReq(int AcceptFd)
  10945. {
  10946. int errn = 0;
  10947. struct ChargingInfoData *sys;
  10948. //Request CSU to STOP
  10949. //This should be reponsed as soon as possible once this message is received.
  10950. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10951. EVCOMM_SYS_INFO.EvBatterytargetVoltage = 0;
  10952. EVCOMM_SYS_INFO.EvBatterytargetCurrent = 0;
  10953. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PowerDeliveryReq (2nd)\n");
  10954. //Print the decoded XML Document
  10955. PRINT_XML_DOC_DIN_PowerDeliveryReq(&ccs_exi_doc_DIN);
  10956. //Save into Share Memory
  10957. SHM_Save_din_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10958. //Check for EV Error Code
  10959. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  10960. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10961. //[To-Do] Sending response after the EVSE output voltage decreases to under 60V
  10962. usleep(1500000); //1.5 seconds
  10963. //sleep(1); //1 second
  10964. errn = Proc_din_PowerDeliveryStopRes(AcceptFd);
  10965. if (errn == 0)
  10966. {
  10967. //send response successfully.
  10968. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]PowerDeliveryRes (2nd)\n");
  10969. }
  10970. else
  10971. {
  10972. sprintf(buf_log_evcomm,
  10973. "[Error][SeccComm][Proc_din_PowerDeliveryStopReq]Proc_iso1_PowerDeliveryStopRes(): %d (DEC)",
  10974. errn);
  10975. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10976. }
  10977. return errn;
  10978. }
  10979. /*===========================================================================
  10980. FUNCTION: Proc_iso1_PowerDeliveryStopReq
  10981. DESCRIPTION:
  10982. PRE-CONDITION:
  10983. INPUT:
  10984. OUTPUT:
  10985. GLOBAL VARIABLES:
  10986. =============================================================================*/
  10987. int Proc_iso1_PowerDeliveryStopReq(int AcceptFd)
  10988. {
  10989. int errn = 0;
  10990. struct ChargingInfoData *sys;
  10991. //Request CSU to STOP
  10992. //This should be reponsed as soon as possible once this message is received.
  10993. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10994. //Print the decoded XML Document
  10995. PRINT_XML_DOC_ISO1_PowerDeliveryReq(&ccs_exi_doc_ISO1);
  10996. //Save into Share Memory
  10997. SHM_Save_iso1_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10998. if(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.ChargeProgress==iso1chargeProgressType_Stop)
  10999. {
  11000. //CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  11001. EVCOMM_SYS_INFO.EvBatterytargetVoltage = 0;
  11002. EVCOMM_SYS_INFO.EvBatterytargetCurrent = 0;
  11003. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  11004. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PowerDeliveryReq (2nd-Stop)\n");
  11005. //[To-Do] Sending response after the EVSE output voltage decreases to under 60V
  11006. usleep(1500000); //1.5 seconds
  11007. //sleep(1); //1 second
  11008. }
  11009. else
  11010. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PowerDeliveryReq (2nd-Renegotiation)\n");
  11011. //Check for EV Error Code
  11012. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  11013. errn = Proc_iso1_PowerDeliveryStopRes(AcceptFd);
  11014. if (errn == 0)
  11015. {
  11016. //send response successfully.
  11017. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]PowerDeliveryRes (2nd-stop)");
  11018. }
  11019. else
  11020. {
  11021. sprintf(buf_log_evcomm,
  11022. "[Error][SeccComm][Proc_iso1_PowerDeliveryStopReq]Proc_iso1_PowerDeliveryStopRes(): %d (DEC)",
  11023. errn);
  11024. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11025. }
  11026. return errn;
  11027. }
  11028. /*===========================================================================
  11029. FUNCTION: SHM_Init_din_WeldingDetectionRes
  11030. DESCRIPTION:
  11031. PRE-CONDITION:
  11032. INPUT:
  11033. 1. shm_ccs
  11034. OUTPUT:
  11035. 1. shm_ccs
  11036. GLOBAL VARIABLES:
  11037. =============================================================================*/
  11038. void SHM_Init_din_WeldingDetectionRes(struct CcsData *shm_ccs)
  11039. {
  11040. struct WeldingDetectionResponse_DIN70121 *in;
  11041. in = &shm_ccs->V2GMessage_DIN70121.WeldingDetectionResponse;
  11042. //----- [BODY (1/3)] ResponseCode -----
  11043. in->ResponseCode = dinresponseCodeType_OK;
  11044. //----- [BODY (2/3)] EVSEPresentVoltage -----
  11045. short value = 0; int multiplier = 0; unsigned char unit = 0;
  11046. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for test only.
  11047. value = 0; multiplier = 0; unit = V_DIN70121;
  11048. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  11049. //----- [BODY (3/3)] DC_EVSEStatus -----
  11050. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  11051. }
  11052. /*===========================================================================
  11053. FUNCTION: Sudo_Parameter_din_WeldingDetectionRes
  11054. DESCRIPTION:
  11055. PRE-CONDITION:
  11056. INPUT:
  11057. OUTPUT:
  11058. GLOBAL VARIABLES:
  11059. =============================================================================*/
  11060. void Sudo_Parameter_din_WeldingDetectionRes()
  11061. {
  11062. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  11063. init_dinWeldingDetectionResType(&ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes);
  11064. ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes_isUsed = 1u;
  11065. //----- [BODY (1/3)] ResponseCode -----
  11066. struct dinWeldingDetectionResType *res;
  11067. res = &ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes;
  11068. res->ResponseCode = dinresponseCodeType_OK;
  11069. //----- [BODY (2/3)] EVSEPresentVoltage -----
  11070. res->EVSEPresentVoltage.Value = 3820;
  11071. res->EVSEPresentVoltage.Multiplier = -1;
  11072. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  11073. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  11074. // dinunitSymbolType_h = 0,
  11075. // dinunitSymbolType_m = 1,
  11076. // dinunitSymbolType_s = 2,
  11077. // dinunitSymbolType_A = 3,
  11078. // dinunitSymbolType_Ah = 4,
  11079. // dinunitSymbolType_V = 5,
  11080. // dinunitSymbolType_VA = 6,
  11081. // dinunitSymbolType_W = 7,
  11082. // dinunitSymbolType_W_s = 8,
  11083. // dinunitSymbolType_Wh = 9
  11084. //----- [BODY (3/3)] DC_EVSEStatus -----
  11085. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  11086. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  11087. // dinisolationLevelType_Invalid = 0,
  11088. // dinisolationLevelType_Valid = 1,
  11089. // dinisolationLevelType_Warning = 2,
  11090. // dinisolationLevelType_Fault = 3
  11091. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  11092. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  11093. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  11094. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  11095. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  11096. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  11097. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  11098. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  11099. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  11100. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  11101. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  11102. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  11103. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  11104. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  11105. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  11106. // dinEVSENotificationType_None = 0,
  11107. // dinEVSENotificationType_StopCharging = 1,
  11108. // dinEVSENotificationType_ReNegotiation = 2
  11109. }
  11110. /*===========================================================================
  11111. FUNCTION: Sudo_Parameter_iso1_WeldingDetectionRes
  11112. DESCRIPTION:
  11113. PRE-CONDITION:
  11114. INPUT:
  11115. OUTPUT:
  11116. GLOBAL VARIABLES:
  11117. =============================================================================*/
  11118. void Sudo_Parameter_iso1_WeldingDetectionRes()
  11119. {
  11120. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  11121. init_iso1WeldingDetectionResType(&ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes);
  11122. ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes_isUsed = 1u;
  11123. //----- [BODY (1/3)] ResponseCode -----
  11124. struct iso1WeldingDetectionResType *res;
  11125. res = &ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes;
  11126. res->ResponseCode = iso1responseCodeType_OK;
  11127. //----- [BODY (2/3)] EVSEPresentVoltage -----
  11128. res->EVSEPresentVoltage.Value = 3820;
  11129. res->EVSEPresentVoltage.Multiplier = -1;
  11130. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  11131. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  11132. //iso1unitSymbolType_h = 0,
  11133. //iso1unitSymbolType_m = 1,
  11134. //iso1unitSymbolType_s = 2,
  11135. //iso1unitSymbolType_A = 3,
  11136. //iso1unitSymbolType_V = 4,
  11137. //iso1unitSymbolType_W = 5,
  11138. //iso1unitSymbolType_Wh = 6
  11139. //----- [BODY (3/3)] DC_EVSEStatus -----
  11140. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  11141. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  11142. //iso1isolationLevelType_Invalid = 0,
  11143. //iso1isolationLevelType_Valid = 1,
  11144. //iso1isolationLevelType_Warning = 2,
  11145. //iso1isolationLevelType_Fault = 3,
  11146. //iso1isolationLevelType_No_IMD = 4
  11147. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  11148. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  11149. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  11150. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  11151. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  11152. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  11153. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  11154. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  11155. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  11156. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  11157. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  11158. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  11159. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  11160. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  11161. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  11162. //iso1EVSENotificationType_None = 0,
  11163. //iso1EVSENotificationType_StopCharging = 1,
  11164. //iso1EVSENotificationType_ReNegotiation = 2
  11165. }
  11166. /*===========================================================================
  11167. FUNCTION: Proc_din_WeldingDetectionRes
  11168. DESCRIPTION:
  11169. PRE-CONDITION:
  11170. INPUT:
  11171. OUTPUT:
  11172. GLOBAL VARIABLES:
  11173. =============================================================================*/
  11174. int Proc_din_WeldingDetectionRes(int AcceptFd)
  11175. {
  11176. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  11177. //if it is not the same, the packet should be ignored.
  11178. //STEP 1: ============ Initialize ============
  11179. int i = 0;
  11180. int errn = 0;
  11181. bitstream_t v2g_tx_stream;
  11182. static struct WeldingDetectionResponse_DIN70121 *wel;
  11183. static struct ChargingInfoData *sys;
  11184. size_t pos = 0;
  11185. v2g_tx_stream.pos = &pos;
  11186. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  11187. v2g_tx_stream.data = V2GTP_Tx_buf;
  11188. wel = &ShmCcsData->V2GMessage_DIN70121.WeldingDetectionResponse;
  11189. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  11190. wel->ResponseCode = OK_DIN70121;
  11191. //[HEADER] Check Req SessionID
  11192. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  11193. {
  11194. wel->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  11195. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  11196. errn = -1;
  11197. }
  11198. //Check for SequenceError
  11199. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  11200. {
  11201. wel->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  11202. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  11203. errn = -1;
  11204. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11205. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  11206. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11207. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11208. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11209. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  11210. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  11211. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  11212. }
  11213. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  11214. SAVE_PhysicalValueType_DIN70121(&wel->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  11215. //EVSE Status Code
  11216. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  11217. //Check for CSU command of "Stop by EVSE"
  11218. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  11219. {
  11220. //wel->ResponseCode = FAILED_DIN70121;
  11221. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  11222. }
  11223. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  11224. {
  11225. //wel->ResponseCode = FAILED_DIN70121;
  11226. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  11227. errn = -1;
  11228. }
  11229. else if (ShmInternalComm->ChargingPermission == FALSE)
  11230. {
  11231. //wel->ResponseCode = FAILED_DIN70121;
  11232. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  11233. }
  11234. //Isolation Status
  11235. if (sys->IsolationStatus == GFD_Invalid) //0:invalid (on going)
  11236. {
  11237. // wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  11238. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  11239. //wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  11240. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  11241. sprintf(buf_log_evcomm, "[Error][Proc_din_WeldingDetectionRes]IsolationStatus = %d", sys->IsolationStatus);
  11242. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11243. //Update_V2G_Flow_Status(Other_Fault);
  11244. // errn = -1;
  11245. }
  11246. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  11247. {
  11248. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  11249. }
  11250. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  11251. {
  11252. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  11253. }
  11254. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  11255. {
  11256. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  11257. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  11258. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  11259. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_WeldingDetectionRes]GFD_Fault => Emergency Shutdown");
  11260. Update_V2G_Flow_Status(Other_Fault);
  11261. errn = -1;
  11262. }
  11263. else //GFD_No_IMD or other unexpected status
  11264. {
  11265. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  11266. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  11267. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  11268. sprintf(buf_log_evcomm, "[Error][Proc_din_WeldingDetectionRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  11269. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11270. Update_V2G_Flow_Status(Other_Fault);
  11271. errn = -1;
  11272. }
  11273. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  11274. #if PARAMETER_NORMAL_MODE == ENABLE
  11275. SHM_Read_din_WeldingDetectionRes(&ccs_exi_doc_DIN, ShmCcsData);
  11276. #else
  11277. Sudo_Parameter_din_WeldingDetectionRes();
  11278. #endif
  11279. //STEP 4: ============ Encode and Send Response Message ===========
  11280. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  11281. {
  11282. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_WeldingDetectionRes][Error]Tx encoded msg error");
  11283. errn = -1;
  11284. }
  11285. //STEP 5: ============ Update Flags ===========
  11286. return errn;
  11287. }
  11288. /*===========================================================================
  11289. FUNCTION: Proc_iso1_WeldingDetectionRes
  11290. DESCRIPTION:
  11291. PRE-CONDITION:
  11292. INPUT:
  11293. OUTPUT:
  11294. GLOBAL VARIABLES:
  11295. =============================================================================*/
  11296. int Proc_iso1_WeldingDetectionRes(int AcceptFd)
  11297. {
  11298. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  11299. //if it is not the same, the packet should be ignored.
  11300. //STEP 1: ============ Initialize ============
  11301. int i = 0;
  11302. int errn = 0;
  11303. bitstream_t v2g_tx_stream;
  11304. static struct WeldingDetectionResponse_ISO15118_2014 *wel;
  11305. static struct ChargingInfoData *sys;
  11306. size_t pos = 0;
  11307. v2g_tx_stream.pos = &pos;
  11308. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  11309. v2g_tx_stream.data = V2GTP_Tx_buf;
  11310. wel = &ShmCcsData->V2GMessage_ISO15118_2014.WeldingDetectionResponse;
  11311. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  11312. wel->ResponseCode = OK_ISO15118_2014;
  11313. //[HEADER] Check Req SessionID
  11314. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  11315. {
  11316. wel->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  11317. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  11318. errn = -1;
  11319. }
  11320. //Check for SequenceError
  11321. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  11322. {
  11323. wel->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  11324. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  11325. errn = -1;
  11326. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11327. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  11328. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11329. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11330. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11331. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  11332. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  11333. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  11334. }
  11335. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  11336. SAVE_PhysicalValueType_ISO15118_2014(&wel->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  11337. //EVSE Status Code
  11338. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  11339. //Check for CSU command of "Stop by EVSE"
  11340. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  11341. {
  11342. //wel->ResponseCode = FAILED_ISO15118_2014;
  11343. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  11344. }
  11345. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  11346. {
  11347. //wel->ResponseCode = FAILED_ISO15118_2014;
  11348. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  11349. errn = -1;
  11350. }
  11351. else if (ShmInternalComm->ChargingPermission == FALSE)
  11352. {
  11353. //wel->ResponseCode = FAILED_ISO15118_2014;
  11354. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  11355. }
  11356. //Isolation Status
  11357. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  11358. {
  11359. //wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  11360. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  11361. // wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  11362. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  11363. sprintf(buf_log_evcomm, "[Error][Proc_iso1_WeldingDetectionRes]IsolationStatus = %d", sys->IsolationStatus);
  11364. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11365. // Update_V2G_Flow_Status(Other_Fault);
  11366. // errn = -1;
  11367. }
  11368. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  11369. {
  11370. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  11371. }
  11372. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  11373. {
  11374. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  11375. }
  11376. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  11377. {
  11378. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  11379. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  11380. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  11381. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_WeldingDetectionRes]GFD_Fault => EmergencyShutdown");
  11382. Update_V2G_Flow_Status(Other_Fault);
  11383. errn = -1;
  11384. }
  11385. else
  11386. {
  11387. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  11388. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  11389. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  11390. sprintf(buf_log_evcomm, "[Error][Proc_iso1_WeldingDetectionRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  11391. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11392. Update_V2G_Flow_Status(Other_Fault);
  11393. errn = -1;
  11394. }
  11395. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  11396. #if PARAMETER_NORMAL_MODE == ENABLE
  11397. SHM_Read_iso1_WeldingDetectionRes(&ccs_exi_doc_ISO1, ShmCcsData);
  11398. #else
  11399. Sudo_Parameter_iso1_WeldingDetectionRes();
  11400. #endif
  11401. //STEP 4: ============ Encode and Send Response Message ===========
  11402. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  11403. {
  11404. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_WeldingDetectionRes][Error]Tx encoded msg error");
  11405. errn = -1;
  11406. }
  11407. //STEP 5: ============ Update Flags ===========
  11408. return errn;
  11409. }
  11410. /*===========================================================================
  11411. FUNCTION: Proc_din_WeldingDetectionReq
  11412. DESCRIPTION:
  11413. PRE-CONDITION:
  11414. INPUT:
  11415. OUTPUT:
  11416. GLOBAL VARIABLES:
  11417. =============================================================================*/
  11418. int Proc_din_WeldingDetectionReq(int AcceptFd)
  11419. {
  11420. int errn = 0;
  11421. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_WeldingDetectionReq] Got WeldingDetectionReq\n");
  11422. //Print the decoded XML Document
  11423. PRINT_XML_DOC_DIN_WeldingDetectionReq(&ccs_exi_doc_DIN);
  11424. //Save into Share Memory
  11425. SHM_Save_din_WeldingDetectionReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  11426. //Check for EV Error Code
  11427. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.WeldingDetectionRequest.DC_EVStatus.EVErrorCode);
  11428. errn = Proc_din_WeldingDetectionRes(AcceptFd);
  11429. if (errn == 0)
  11430. {
  11431. //send response successfully.
  11432. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]WeldingDetectionRes");
  11433. }
  11434. else
  11435. {
  11436. sprintf(buf_log_evcomm,
  11437. "[Error][SeccComm][Proc_din_WeldingDetectionReq]Proc_din_WeldingDetectionRes(): %d (DEC)",
  11438. errn);
  11439. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11440. }
  11441. return errn;
  11442. }
  11443. /*===========================================================================
  11444. FUNCTION: Proc_iso1_WeldingDetectionReq
  11445. DESCRIPTION:
  11446. PRE-CONDITION:
  11447. INPUT:
  11448. OUTPUT:
  11449. GLOBAL VARIABLES:
  11450. =============================================================================*/
  11451. int Proc_iso1_WeldingDetectionReq(int AcceptFd)
  11452. {
  11453. int errn = 0;
  11454. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_WeldingDetectionReq] Got WeldingDetectionReq\n");
  11455. //Print the decoded XML Document
  11456. PRINT_XML_DOC_ISO1_WeldingDetectionReq(&ccs_exi_doc_ISO1);
  11457. //Save into Share Memory
  11458. SHM_Save_iso1_WeldingDetectionReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  11459. //Check for EV Error Code
  11460. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.WeldingDetectionRequest.DC_EVStatus.EVErrorCode);
  11461. errn = Proc_iso1_WeldingDetectionRes(AcceptFd);
  11462. if (errn == 0)
  11463. {
  11464. //send response successfully.
  11465. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]WeldingDetectionRes");
  11466. }
  11467. else
  11468. {
  11469. sprintf(buf_log_evcomm,
  11470. "[Error][SeccComm][Proc_iso1_WeldingDetectionReq]Proc_iso1_WeldingDetectionRes(): %d (DEC)",
  11471. errn);
  11472. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11473. }
  11474. return errn;
  11475. }
  11476. /*===========================================================================
  11477. FUNCTION: SHM_Init_din_SessionStopRes
  11478. DESCRIPTION:
  11479. PRE-CONDITION:
  11480. INPUT:
  11481. 1. shm_ccs
  11482. OUTPUT:
  11483. 1. shm_ccs
  11484. GLOBAL VARIABLES:
  11485. =============================================================================*/
  11486. void SHM_Init_din_SessionStopRes(struct CcsData *shm_ccs)
  11487. {
  11488. struct SessionStopResponse_DIN70121 *in;
  11489. in = &shm_ccs->V2GMessage_DIN70121.SessionStopResponse;
  11490. //----- [BODY (1/3)] ResponseCode -----
  11491. in->ResponseCode = dinresponseCodeType_OK;
  11492. }
  11493. /*===========================================================================
  11494. FUNCTION: Sudo_Parameter_din_SessionStopRes
  11495. DESCRIPTION:
  11496. PRE-CONDITION:
  11497. INPUT:
  11498. OUTPUT:
  11499. GLOBAL VARIABLES:
  11500. =============================================================================*/
  11501. void Sudo_Parameter_din_SessionStopRes()
  11502. {
  11503. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  11504. init_dinSessionStopResType(&ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes);
  11505. ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes_isUsed = 1u;
  11506. //----- [BODY (1/3)] ResponseCode -----
  11507. struct dinSessionStopResType *res;
  11508. res = &ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes;
  11509. res->ResponseCode = dinresponseCodeType_OK;
  11510. }
  11511. /*===========================================================================
  11512. FUNCTION: Sudo_Parameter_iso1_SessionStopRes
  11513. DESCRIPTION:
  11514. PRE-CONDITION:
  11515. INPUT:
  11516. OUTPUT:
  11517. GLOBAL VARIABLES:
  11518. =============================================================================*/
  11519. void Sudo_Parameter_iso1_SessionStopRes()
  11520. {
  11521. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  11522. init_iso1SessionStopResType(&ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes);
  11523. ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes_isUsed = 1u;
  11524. //----- [BODY (1/3)] ResponseCode -----
  11525. struct iso1SessionStopResType *res;
  11526. res = &ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes;
  11527. res->ResponseCode = iso1responseCodeType_OK;
  11528. }
  11529. /*===========================================================================
  11530. FUNCTION: Proc_din_SessionStopRes
  11531. DESCRIPTION:
  11532. PRE-CONDITION:
  11533. INPUT:
  11534. OUTPUT:
  11535. GLOBAL VARIABLES:
  11536. =============================================================================*/
  11537. int Proc_din_SessionStopRes(int AcceptFd)
  11538. {
  11539. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  11540. //if it is not the same, the packet should be ignored.
  11541. //STEP 1: ============ Initialize ============
  11542. int i = 0;
  11543. int errn = 0;
  11544. bitstream_t v2g_tx_stream;
  11545. struct SessionStopResponse_DIN70121 *stp;
  11546. struct ChargingInfoData *sys;
  11547. size_t pos = 0;
  11548. v2g_tx_stream.pos = &pos;
  11549. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  11550. v2g_tx_stream.data = V2GTP_Tx_buf;
  11551. stp = &ShmCcsData->V2GMessage_DIN70121.SessionStopResponse;
  11552. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  11553. stp->ResponseCode = OK_DIN70121;
  11554. //[HEADER] Check Req SessionID
  11555. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  11556. {
  11557. stp->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  11558. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  11559. errn = -1;
  11560. }
  11561. //Check for SequenceError
  11562. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  11563. {
  11564. stp->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  11565. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  11566. errn = -1;
  11567. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11568. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  11569. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11570. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11571. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11572. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  11573. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  11574. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  11575. }
  11576. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  11577. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  11578. #if PARAMETER_NORMAL_MODE == ENABLE
  11579. SHM_Read_din_SessionStopRes(&ccs_exi_doc_DIN, ShmCcsData);
  11580. #else
  11581. Sudo_Parameter_din_SessionStopRes();
  11582. #endif
  11583. //STEP 4: ============ Encode and Send Response Message ===========
  11584. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  11585. {
  11586. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Tx]SessionStopRes: fail");
  11587. errn = -1;
  11588. }
  11589. else
  11590. {
  11591. //send response successfully.
  11592. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Tx]SessionStopRes");
  11593. }
  11594. //STEP 5: ============ Update Flags ===========
  11595. EVCOMM_SYS_INFO.ConnectorLocked = FALSE; //Indicating CSU that the Connector is unlocked.
  11596. //Once this is set, the CSU should
  11597. // =========== Annouce to CSU [To-Be Implemented]=============
  11598. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE; //This should be also added to EV Error events.
  11599. // =========== Re-initialized [To-Be Implemented]=============
  11600. //Keep 5% PWM for 2 seconds
  11601. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 2");
  11602. sleep(1);
  11603. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 1");
  11604. sleep(1);
  11605. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 0");
  11606. OutputCpPwmDuty(100);
  11607. //[To-Do] Reset All Share memory
  11608. //[To-Do] CCS Module enter "idle" mode and CSU should check for this state.
  11609. //system("reboot -f");
  11610. //sleep(5);
  11611. //system("reboot -f");
  11612. return errn;
  11613. }
  11614. /*===========================================================================
  11615. FUNCTION: Proc_iso1_SessionStopRes
  11616. DESCRIPTION:
  11617. PRE-CONDITION:
  11618. INPUT:
  11619. OUTPUT:
  11620. GLOBAL VARIABLES:
  11621. =============================================================================*/
  11622. int Proc_iso1_SessionStopRes(int AcceptFd)
  11623. {
  11624. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  11625. //if it is not the same, the packet should be ignored.
  11626. //STEP 1: ============ Initialize ============
  11627. int i = 0;
  11628. int errn = 0;
  11629. bitstream_t v2g_tx_stream;
  11630. struct SessionStopResponse_ISO15118_2014 *stp;
  11631. struct ChargingInfoData *sys;
  11632. size_t pos = 0;
  11633. v2g_tx_stream.pos = &pos;
  11634. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  11635. v2g_tx_stream.data = V2GTP_Tx_buf;
  11636. stp = &ShmCcsData->V2GMessage_ISO15118_2014.SessionStopResponse;
  11637. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  11638. stp->ResponseCode = OK_ISO15118_2014;
  11639. //[HEADER] Check Req SessionID
  11640. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  11641. {
  11642. stp->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  11643. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  11644. errn = -1;
  11645. }
  11646. //Check for SequenceError
  11647. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  11648. {
  11649. stp->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  11650. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  11651. errn = -1;
  11652. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11653. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  11654. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11655. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11656. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11657. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  11658. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  11659. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  11660. }
  11661. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  11662. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  11663. #if PARAMETER_NORMAL_MODE == ENABLE
  11664. SHM_Read_iso1_SessionStopRes(&ccs_exi_doc_ISO1, ShmCcsData);
  11665. #else
  11666. Sudo_Parameter_iso1_SessionStopRes();
  11667. #endif
  11668. //STEP 4: ============ Encode and Send Response Message ===========
  11669. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  11670. {
  11671. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Tx]SessionStopRes: fail");
  11672. errn = -1;
  11673. }
  11674. else
  11675. {
  11676. //send response successfully.
  11677. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Tx]SessionStopRes");
  11678. }
  11679. //STEP 5: ============ Update Flags ===========
  11680. EVCOMM_SYS_INFO.ConnectorLocked = FALSE; //Indicating CSU that the Connector is unlocked.
  11681. //Once this is set, the CSU should
  11682. // =========== Annouce to CSU [To-Be Implemented]=============
  11683. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE; //This should be also added to EV Error events.
  11684. // =========== Re-initialized [To-Be Implemented]=============
  11685. //Keep 5% PWM for 2 seconds
  11686. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 2");
  11687. sleep(1);
  11688. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 1");
  11689. sleep(1);
  11690. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 0");
  11691. OutputCpPwmDuty(100);
  11692. //[To-Do] Reset All Share memory
  11693. //[To-Do] CCS Module enter "idle" mode and CSU should check for this state.
  11694. //system("reboot -f");
  11695. //sleep(5);
  11696. //system("reboot -f");
  11697. return errn;
  11698. }
  11699. /*===========================================================================
  11700. FUNCTION: Proc_din_SessionStopReq
  11701. DESCRIPTION:
  11702. PRE-CONDITION:
  11703. INPUT:
  11704. OUTPUT:
  11705. GLOBAL VARIABLES:
  11706. =============================================================================*/
  11707. int Proc_din_SessionStopReq(int AcceptFd)
  11708. {
  11709. int errn = 0;
  11710. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]SessionStopReq");
  11711. //Print the decoded XML Document
  11712. PRINT_XML_DOC_DIN_SessionStopReq(&ccs_exi_doc_DIN);
  11713. //Save into Share Memory
  11714. SHM_Save_din_SessionStopReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  11715. errn = Proc_din_SessionStopRes(AcceptFd);
  11716. if (errn == 0)
  11717. {
  11718. //send response successfully.
  11719. }
  11720. else
  11721. {
  11722. sprintf(buf_log_evcomm,
  11723. "[Error][SeccComm][Proc_din_SessionStopReq]Proc_iso1_SessionStopRes(): %d (DEC)",
  11724. errn);
  11725. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11726. }
  11727. return errn;
  11728. }
  11729. /*===========================================================================
  11730. FUNCTION: Proc_iso1_SessionStopReq
  11731. DESCRIPTION:
  11732. PRE-CONDITION:
  11733. INPUT:
  11734. OUTPUT:
  11735. GLOBAL VARIABLES:
  11736. =============================================================================*/
  11737. int Proc_iso1_SessionStopReq(int AcceptFd)
  11738. {
  11739. int errn = 0;
  11740. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]SessionStopReq");
  11741. //Print the decoded XML Document
  11742. PRINT_XML_DOC_ISO1_SessionStopReq(&ccs_exi_doc_ISO1);
  11743. //Save into Share Memory
  11744. SHM_Save_iso1_SessionStopReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  11745. errn = Proc_iso1_SessionStopRes(AcceptFd);
  11746. if (errn == 0)
  11747. {
  11748. //send response successfully.
  11749. }
  11750. else
  11751. {
  11752. sprintf(buf_log_evcomm,
  11753. "[Error][SeccComm][Proc_iso1_SessionStopReq]Proc_iso1_SessionStopRes(): %d (DEC)",
  11754. errn);
  11755. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11756. }
  11757. return errn;
  11758. }
  11759. /*===========================================================================
  11760. FUNCTION: V2gMsg_Process_din
  11761. DESCRIPTION:
  11762. PRE-CONDITION:
  11763. INPUT:
  11764. 1. V2gFlowStatus
  11765. OUTPUT:
  11766. GLOBAL VARIABLES:
  11767. 1. V2gFlowStatus
  11768. =============================================================================*/
  11769. int V2gMsg_Process_din(int AcceptFd)
  11770. {
  11771. unsigned char req_is_responsed = FALSE;
  11772. while (req_is_responsed == FALSE)
  11773. {
  11774. //Check if it is in End_Process
  11775. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  11776. {
  11777. break;
  11778. }
  11779. switch(V2gFlowStatus)
  11780. {
  11781. //-------------------------------------------
  11782. case SupportedAppProtocolRequest:
  11783. {
  11784. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  11785. {
  11786. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  11787. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  11788. {
  11789. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11790. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  11791. }
  11792. else
  11793. {
  11794. SAVE_SYS_LOG_MSG_EVCOMM("[Error]supportedAppProtocolResReq: fail");
  11795. Update_V2G_Flow_Status(Other_Fault);
  11796. }
  11797. }
  11798. req_is_responsed = TRUE;
  11799. break;
  11800. }
  11801. case SupportedAppProtocolResponse:
  11802. {
  11803. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  11804. {
  11805. Update_V2G_Flow_Status(SessionSetupRequest);
  11806. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11807. }
  11808. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11809. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  11810. {
  11811. sprintf(buf_log_evcomm,
  11812. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11813. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11814. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11815. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11816. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11817. }
  11818. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  11819. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11820. {
  11821. sprintf(buf_log_evcomm,
  11822. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  11823. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11824. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11825. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11826. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  11827. {
  11828. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11829. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11830. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11831. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  11832. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  11833. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  11834. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  11835. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  11836. }
  11837. }
  11838. else
  11839. {
  11840. break;
  11841. }
  11842. break;
  11843. }
  11844. //-------------------------------------------
  11845. case SessionSetupRequest: //19
  11846. {
  11847. if (Proc_din_SessionSetupReq(AcceptFd) == 0)
  11848. {
  11849. Update_V2G_Flow_Status(SessionSetupResponse);
  11850. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11851. }
  11852. else
  11853. {
  11854. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionSetupReqRes: fail");
  11855. Update_V2G_Flow_Status(Other_Fault);
  11856. }
  11857. req_is_responsed = TRUE;
  11858. break;
  11859. }
  11860. case SessionSetupResponse: //20
  11861. {
  11862. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  11863. {
  11864. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  11865. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11866. }
  11867. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11868. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  11869. {
  11870. sprintf(buf_log_evcomm,
  11871. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11872. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11873. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11874. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11875. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11876. }
  11877. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  11878. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11879. {
  11880. sprintf(buf_log_evcomm,
  11881. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  11882. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11883. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11884. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11885. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  11886. {
  11887. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11888. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11889. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11890. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  11891. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  11892. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  11893. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  11894. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  11895. }
  11896. }
  11897. else
  11898. {
  11899. break;
  11900. }
  11901. break;
  11902. }
  11903. //-------------------------------------------
  11904. case ServiceDiscoveryRequest: //21
  11905. {
  11906. if (Proc_din_ServiceDiscoveryReq(AcceptFd) == 0)
  11907. {
  11908. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  11909. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11910. }
  11911. else
  11912. {
  11913. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceDiscoveryReqRes: fail");
  11914. Update_V2G_Flow_Status(Other_Fault);
  11915. }
  11916. req_is_responsed = TRUE;
  11917. break;
  11918. }
  11919. case ServiceDiscoveryResponse: //22
  11920. {
  11921. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  11922. {
  11923. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  11924. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11925. }
  11926. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11927. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  11928. {
  11929. sprintf(buf_log_evcomm,
  11930. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11931. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11932. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11933. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11934. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11935. }
  11936. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  11937. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11938. {
  11939. sprintf(buf_log_evcomm,
  11940. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  11941. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11942. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11943. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11944. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  11945. {
  11946. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11947. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11948. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11949. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  11950. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  11951. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  11952. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  11953. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  11954. }
  11955. }
  11956. else
  11957. {
  11958. break;
  11959. }
  11960. break;
  11961. }
  11962. //-------------------------------------------
  11963. case ServiceAndPaymentSelectionRequest: //25
  11964. {
  11965. if (Proc_din_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  11966. {
  11967. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  11968. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11969. }
  11970. else
  11971. {
  11972. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceAndPaymentSelectionReqRes: fail");
  11973. Update_V2G_Flow_Status(Other_Fault);
  11974. }
  11975. req_is_responsed = TRUE;
  11976. break;
  11977. }
  11978. case ServiceAndPaymentSelectionResponse: //26
  11979. {
  11980. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11981. {
  11982. Update_V2G_Flow_Status(AuthorizationRequest);
  11983. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11984. }
  11985. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11986. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  11987. {
  11988. sprintf(buf_log_evcomm,
  11989. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11990. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11991. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11992. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11993. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11994. }
  11995. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  11996. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11997. {
  11998. sprintf(buf_log_evcomm,
  11999. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  12000. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12001. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12002. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12003. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  12004. {
  12005. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12006. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12007. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12008. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  12009. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  12010. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  12011. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  12012. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  12013. }
  12014. }
  12015. else
  12016. {
  12017. break;
  12018. }
  12019. break;
  12020. }
  12021. //-------------------------------------------
  12022. //case ContractAuthenticationReq:
  12023. case AuthorizationRequest: //29
  12024. {
  12025. if (Proc_din_ContractAuthenticationReq(AcceptFd) == 0)
  12026. {
  12027. Update_V2G_Flow_Status(AuthorizationResponse);
  12028. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12029. }
  12030. else
  12031. {
  12032. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  12033. Update_V2G_Flow_Status(Other_Fault);
  12034. }
  12035. req_is_responsed = TRUE;
  12036. break;
  12037. }
  12038. case AuthorizationResponse: //30
  12039. {
  12040. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  12041. {
  12042. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12043. if (Proc_din_ContractAuthenticationReq(AcceptFd) == 0)
  12044. {
  12045. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12046. }
  12047. else
  12048. {
  12049. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  12050. Update_V2G_Flow_Status(Other_Fault);
  12051. }
  12052. req_is_responsed = TRUE;
  12053. break;
  12054. }
  12055. //Check for ChargeParameterDiscoveryReq
  12056. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  12057. {
  12058. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12059. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  12060. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  12061. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12062. ftime(&SeqStartTime);
  12063. #endif
  12064. }
  12065. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12066. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  12067. {
  12068. sprintf(buf_log_evcomm,
  12069. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12070. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12071. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12072. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12073. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12074. }
  12075. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  12076. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12077. {
  12078. sprintf(buf_log_evcomm,
  12079. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  12080. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12081. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12082. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12083. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  12084. {
  12085. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12086. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12087. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12088. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  12089. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  12090. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  12091. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  12092. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  12093. }
  12094. }
  12095. else
  12096. {
  12097. break;
  12098. }
  12099. break;
  12100. }
  12101. //-------------------------------------------
  12102. case ChargeParameterDiscoveryRequest: //35
  12103. {
  12104. if (Proc_din_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  12105. {
  12106. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  12107. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12108. }
  12109. else
  12110. {
  12111. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  12112. Update_V2G_Flow_Status(Other_Fault);
  12113. }
  12114. req_is_responsed = TRUE;
  12115. break;
  12116. }
  12117. case ChargeParameterDiscoveryResponse:
  12118. {
  12119. //STEP 1: Check for Process Timeout
  12120. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12121. ftime(&SeqEndTime);
  12122. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  12123. {
  12124. sprintf(buf_log_evcomm,
  12125. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  12126. DiffTimeb(SeqStartTime, SeqEndTime),
  12127. V2G_SECC_ChargingParameter_Performance_Time);
  12128. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12129. Update_V2G_Flow_Status(Sequence_Timeout);
  12130. break;
  12131. }
  12132. #endif
  12133. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  12134. {
  12135. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12136. if (Proc_din_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  12137. {
  12138. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12139. }
  12140. else
  12141. {
  12142. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  12143. Update_V2G_Flow_Status(Other_Fault);
  12144. }
  12145. req_is_responsed = TRUE;
  12146. break;
  12147. }
  12148. //STEP 2: Check for CableCheckReq message
  12149. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  12150. {
  12151. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12152. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CableCheckReqReq: isolated?");
  12153. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  12154. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  12155. Update_V2G_Flow_Status(CableCheckRequest);
  12156. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12157. ftime(&SeqStartTime);
  12158. #endif
  12159. }
  12160. //STEP 3: Wait for PowerDeliveryReq Message
  12161. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12162. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12163. {
  12164. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12165. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12166. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  12167. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12168. ftime(&SeqStartTime);
  12169. #endif
  12170. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  12171. {
  12172. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12173. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12174. }
  12175. else
  12176. {
  12177. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  12178. Update_V2G_Flow_Status(Other_Fault);
  12179. }
  12180. break;
  12181. }
  12182. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12183. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  12184. {
  12185. sprintf(buf_log_evcomm,
  12186. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12187. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12188. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12189. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12190. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12191. }
  12192. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  12193. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12194. {
  12195. sprintf(buf_log_evcomm,
  12196. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  12197. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12198. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12199. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12200. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  12201. {
  12202. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12203. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12204. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12205. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  12206. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  12207. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  12208. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  12209. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  12210. }
  12211. }
  12212. else
  12213. {
  12214. break;
  12215. }
  12216. break;
  12217. }
  12218. //-------------------------------------------
  12219. case CableCheckRequest: //37
  12220. {
  12221. //STEP 3: Execute Cable Check Process
  12222. if (Proc_din_CableCheckReq(AcceptFd) == 0)
  12223. {
  12224. Update_V2G_Flow_Status(CableCheckResponse);
  12225. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12226. }
  12227. else
  12228. {
  12229. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  12230. Update_V2G_Flow_Status(Other_Fault);
  12231. }
  12232. req_is_responsed = TRUE;
  12233. break;
  12234. }
  12235. case CableCheckResponse: //38
  12236. {
  12237. //STEP 1: Check for Process Timeout
  12238. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12239. ftime(&SeqEndTime);
  12240. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  12241. {
  12242. //SAVE_SYS_LOG_MSG_EVCOMM("[CableCheck] end counting...");
  12243. sprintf(buf_log_evcomm,
  12244. "CableCheck Timeout - (%.02lf of %d ms)\n",
  12245. DiffTimeb(SeqStartTime, SeqEndTime),
  12246. V2G_SECC_CableCheck_Performance_Time);
  12247. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12248. Update_V2G_Flow_Status(Sequence_Timeout);
  12249. //Update_ShmStatusCode(); //[To-Do] to be implemented
  12250. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  12251. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12252. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12253. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12254. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  12255. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  12256. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  12257. break;
  12258. }
  12259. #endif
  12260. //STEP 2: Check for CableCheckReq message
  12261. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  12262. {
  12263. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12264. //STEP 3: Execute Cable Check Process
  12265. if (Proc_din_CableCheckReq(AcceptFd) == 0)
  12266. {
  12267. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12268. }
  12269. else
  12270. {
  12271. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  12272. Update_V2G_Flow_Status(Other_Fault);
  12273. }
  12274. req_is_responsed = TRUE;
  12275. break;
  12276. }
  12277. //STEP 3: Check for PreChargeReq message
  12278. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  12279. {
  12280. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12281. Update_V2G_Flow_Status(PreChargeRequest);
  12282. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PreChargeReqReq: waiting for precharge voltage...");
  12283. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  12284. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  12285. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12286. ftime(&SeqStartTime);
  12287. #endif
  12288. }
  12289. //STEP 3: Wait for PowerDeliveryReq Message
  12290. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12291. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12292. {
  12293. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12294. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12295. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  12296. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12297. ftime(&SeqStartTime);
  12298. #endif
  12299. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  12300. {
  12301. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12302. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12303. }
  12304. else
  12305. {
  12306. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  12307. Update_V2G_Flow_Status(Other_Fault);
  12308. }
  12309. break;
  12310. }
  12311. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12312. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  12313. {
  12314. sprintf(buf_log_evcomm,
  12315. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12316. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12317. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12318. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12319. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12320. }
  12321. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  12322. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12323. {
  12324. sprintf(buf_log_evcomm,
  12325. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  12326. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12327. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12328. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12329. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  12330. {
  12331. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12332. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12333. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12334. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  12335. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  12336. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  12337. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  12338. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  12339. }
  12340. }
  12341. else
  12342. {
  12343. break;
  12344. }
  12345. break;
  12346. }
  12347. //-------------------------------------------
  12348. case PreChargeRequest: //39
  12349. {
  12350. if (Proc_din_PreChargeReq(AcceptFd) == 0)
  12351. {
  12352. Update_V2G_Flow_Status(PreChargeResponse);
  12353. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12354. }
  12355. else
  12356. {
  12357. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  12358. Update_V2G_Flow_Status(Other_Fault);
  12359. }
  12360. req_is_responsed = TRUE;
  12361. break;
  12362. }
  12363. case PreChargeResponse: //40
  12364. {
  12365. //STEP 1: Check for Process Timeout
  12366. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12367. ftime(&SeqEndTime);
  12368. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  12369. {
  12370. sprintf(buf_log_evcomm,
  12371. "Precharge Timeout - (%.02lf of %d ms)\n",
  12372. DiffTimeb(SeqStartTime, SeqEndTime),
  12373. V2G_SECC_PreCharge_Performance_Time);
  12374. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12375. Update_V2G_Flow_Status(Sequence_Timeout);
  12376. //Update_ShmStatusCode(); //[To-Do] to be implemented
  12377. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  12378. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12379. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12380. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12381. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  12382. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  12383. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  12384. break;
  12385. }
  12386. #endif
  12387. //STEP 2: Check for PreChargeReq message
  12388. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  12389. {
  12390. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12391. if (Proc_din_PreChargeReq(AcceptFd) == 0)
  12392. {
  12393. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12394. }
  12395. else
  12396. {
  12397. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  12398. Update_V2G_Flow_Status(Other_Fault);
  12399. }
  12400. req_is_responsed = TRUE;
  12401. break;
  12402. }
  12403. //STEP 3: Check for PowerDeliveryReq message
  12404. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12405. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12406. {
  12407. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12408. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  12409. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  12410. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12411. ftime(&SeqStartTime);
  12412. #endif
  12413. }
  12414. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12415. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  12416. {
  12417. sprintf(buf_log_evcomm,
  12418. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12419. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12420. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12421. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12422. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12423. }
  12424. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  12425. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12426. {
  12427. sprintf(buf_log_evcomm,
  12428. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  12429. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12430. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12431. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12432. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  12433. {
  12434. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12435. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12436. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12437. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  12438. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  12439. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  12440. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  12441. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  12442. }
  12443. }
  12444. else
  12445. {
  12446. break;
  12447. }
  12448. break;
  12449. }
  12450. //-------------------------------------------
  12451. case PowerDeliveryRequestStart: //41
  12452. {
  12453. if (Proc_din_PowerDeliveryStartReq(AcceptFd) == 0)
  12454. {
  12455. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  12456. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12457. }
  12458. else
  12459. {
  12460. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStartReqRes: fail");
  12461. Update_V2G_Flow_Status(Other_Fault);
  12462. }
  12463. req_is_responsed = TRUE;
  12464. break;
  12465. }
  12466. case PowerDeliveryResponsetStart: //42
  12467. {
  12468. //STEP 1: Check for Process Timeout
  12469. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12470. if (ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  12471. {
  12472. ftime(&SeqEndTime);
  12473. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  12474. {
  12475. sprintf(buf_log_evcomm,
  12476. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  12477. DiffTimeb(SeqStartTime, SeqEndTime),
  12478. 2000);
  12479. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12480. Update_V2G_Flow_Status(Sequence_Timeout);
  12481. }
  12482. break;
  12483. }
  12484. #endif
  12485. //STEP 2: Wait for CurrentDemandReq Message
  12486. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  12487. {
  12488. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12489. Update_V2G_Flow_Status(CurrentDemandRequest);
  12490. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CurrentDemandReqReq: energy transfering...");
  12491. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  12492. }
  12493. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12494. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  12495. {
  12496. sprintf(buf_log_evcomm,
  12497. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12498. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12499. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12500. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12501. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12502. }
  12503. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  12504. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12505. {
  12506. sprintf(buf_log_evcomm,
  12507. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  12508. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12509. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12510. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12511. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  12512. {
  12513. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12514. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12515. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12516. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  12517. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  12518. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  12519. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  12520. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  12521. }
  12522. }
  12523. else
  12524. {
  12525. break;
  12526. }
  12527. break;
  12528. }
  12529. //-------------------------------------------
  12530. case CurrentDemandRequest: //45,
  12531. {
  12532. if (Proc_din_CurrentDemandReq(AcceptFd) == 0)
  12533. {
  12534. Update_V2G_Flow_Status(CurrentDemandResponse);
  12535. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12536. }
  12537. else
  12538. {
  12539. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  12540. Update_V2G_Flow_Status(Other_Fault);
  12541. }
  12542. req_is_responsed = TRUE;
  12543. break;
  12544. }
  12545. case CurrentDemandResponse: //46,
  12546. {
  12547. //STEP 1: Wait for CurrentDemandReq Message
  12548. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  12549. {
  12550. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12551. if (Proc_din_CurrentDemandReq(AcceptFd) == 0)
  12552. {
  12553. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12554. }
  12555. else
  12556. {
  12557. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  12558. Update_V2G_Flow_Status(Other_Fault);
  12559. }
  12560. req_is_responsed = TRUE;
  12561. break;
  12562. }
  12563. //STEP 2: Wait for PowerDeliveryReq Message
  12564. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12565. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12566. {
  12567. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12568. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12569. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  12570. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  12571. {
  12572. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12573. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12574. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12575. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  12576. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  12577. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  12578. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  12579. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  12580. }
  12581. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12582. ftime(&SeqStartTime);
  12583. #endif
  12584. }
  12585. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12586. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  12587. {
  12588. sprintf(buf_log_evcomm,
  12589. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12590. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12591. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12592. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12593. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12594. }
  12595. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  12596. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12597. {
  12598. sprintf(buf_log_evcomm,
  12599. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  12600. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12601. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12602. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12603. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  12604. {
  12605. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12606. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12607. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12608. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  12609. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  12610. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  12611. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  12612. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  12613. }
  12614. }
  12615. else
  12616. {
  12617. break;
  12618. }
  12619. break;
  12620. }
  12621. //-------------------------------------------
  12622. case PowerDeliveryRequestStop: //49,
  12623. {
  12624. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  12625. {
  12626. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12627. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12628. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12629. ftime(&SeqStartTime);
  12630. #endif
  12631. }
  12632. else
  12633. {
  12634. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  12635. Update_V2G_Flow_Status(Other_Fault);
  12636. }
  12637. req_is_responsed = TRUE;
  12638. break;
  12639. }
  12640. case PowerDeliveryResponseStop: //50,
  12641. {
  12642. //STEP 1: Check for Process Timeout
  12643. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12644. ftime(&SeqEndTime);
  12645. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  12646. {
  12647. sprintf(buf_log_evcomm,
  12648. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12649. DiffTimeb(SeqStartTime, SeqEndTime),
  12650. 2000);
  12651. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12652. Update_V2G_Flow_Status(Sequence_Timeout);
  12653. break;
  12654. }
  12655. #endif
  12656. //STEP 2: Check for WeldingDetectionReq Message
  12657. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  12658. {
  12659. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12660. Update_V2G_Flow_Status(WeldingDetectionRequest);
  12661. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]WeldingDetectionReq: ongoing...");
  12662. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  12663. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12664. ftime(&SeqStartTime);
  12665. #endif
  12666. }
  12667. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12668. {
  12669. Update_V2G_Flow_Status(SessionStopRequest);
  12670. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12671. if (Proc_din_SessionStopReq(AcceptFd) == 0)
  12672. {
  12673. Update_V2G_Flow_Status(SessionStopResponse);
  12674. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12675. }
  12676. else
  12677. {
  12678. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  12679. Update_V2G_Flow_Status(Other_Fault);
  12680. }
  12681. break;
  12682. }
  12683. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12684. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12685. {
  12686. sprintf(buf_log_evcomm,
  12687. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12688. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12689. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12690. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12691. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12692. }
  12693. else
  12694. {
  12695. break;
  12696. }
  12697. break;
  12698. }
  12699. //-------------------------------------------
  12700. case WeldingDetectionRequest: //51,
  12701. {
  12702. if (Proc_din_WeldingDetectionReq(AcceptFd) == 0)
  12703. {
  12704. Update_V2G_Flow_Status(WeldingDetectionResponse);
  12705. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12706. }
  12707. else
  12708. {
  12709. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  12710. Update_V2G_Flow_Status(Other_Fault);
  12711. }
  12712. req_is_responsed = TRUE;
  12713. break;
  12714. }
  12715. case WeldingDetectionResponse: //52,
  12716. {
  12717. //STEP 1: Check for Process Timeout
  12718. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12719. ftime(&SeqEndTime);
  12720. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  12721. {
  12722. sprintf(buf_log_evcomm,
  12723. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12724. DiffTimeb(SeqStartTime, SeqEndTime),
  12725. V2G_SECC_WeldingDetection_Performance_Time);
  12726. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12727. Update_V2G_Flow_Status(Sequence_Timeout);
  12728. break;
  12729. }
  12730. #endif
  12731. //STEP 2: Check for WeldingDetectionReq Message
  12732. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  12733. {
  12734. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12735. if (Proc_din_WeldingDetectionReq(AcceptFd) == 0)
  12736. {
  12737. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12738. }
  12739. else
  12740. {
  12741. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  12742. Update_V2G_Flow_Status(Other_Fault);
  12743. }
  12744. req_is_responsed = TRUE;
  12745. break;
  12746. }
  12747. //STEP 3: Check for SessionStopReq Message
  12748. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12749. {
  12750. Update_V2G_Flow_Status(SessionStopRequest);
  12751. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12752. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  12753. }
  12754. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12755. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12756. {
  12757. sprintf(buf_log_evcomm,
  12758. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12759. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12760. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12761. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12762. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12763. }
  12764. else
  12765. {
  12766. break;
  12767. }
  12768. break;
  12769. }
  12770. //-------------------------------------------
  12771. case SessionStopRequest: //53,
  12772. {
  12773. if (Proc_din_SessionStopReq(AcceptFd) == 0)
  12774. {
  12775. Update_V2G_Flow_Status(SessionStopResponse);
  12776. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12777. }
  12778. else
  12779. {
  12780. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  12781. Update_V2G_Flow_Status(Other_Fault);
  12782. }
  12783. req_is_responsed = TRUE;
  12784. break;
  12785. }
  12786. case SessionStopResponse: //54,
  12787. {
  12788. break;
  12789. }
  12790. //-------------------------------------------
  12791. default:
  12792. {
  12793. break;
  12794. }
  12795. }
  12796. }
  12797. }
  12798. /*===========================================================================
  12799. FUNCTION: V2gMsg_Process_iso1_DC
  12800. DESCRIPTION:
  12801. PRE-CONDITION:
  12802. INPUT:
  12803. 1. V2gFlowStatus
  12804. OUTPUT:
  12805. GLOBAL VARIABLES:
  12806. 1. V2gFlowStatus
  12807. =============================================================================*/
  12808. int V2gMsg_Process_iso1_DC(int AcceptFd)
  12809. {
  12810. unsigned char req_is_responsed = FALSE;
  12811. while (req_is_responsed == FALSE)
  12812. {
  12813. //Check if it is in End_Process
  12814. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  12815. {
  12816. break;
  12817. }
  12818. switch(V2gFlowStatus)
  12819. {
  12820. //-------------------------------------------
  12821. case SupportedAppProtocolRequest:
  12822. {
  12823. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  12824. {
  12825. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  12826. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  12827. {
  12828. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12829. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  12830. }
  12831. else
  12832. {
  12833. SAVE_SYS_LOG_MSG_EVCOMM("[Error]supportedAppProtocolResReq: fail");
  12834. Update_V2G_Flow_Status(Other_Fault);
  12835. }
  12836. }
  12837. req_is_responsed = TRUE;
  12838. break;
  12839. }
  12840. case SupportedAppProtocolResponse:
  12841. {
  12842. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  12843. {
  12844. Update_V2G_Flow_Status(SessionSetupRequest);
  12845. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12846. }
  12847. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12848. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  12849. {
  12850. sprintf(buf_log_evcomm,
  12851. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12852. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12853. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12854. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12855. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12856. }
  12857. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  12858. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12859. {
  12860. sprintf(buf_log_evcomm,
  12861. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  12862. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12863. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12864. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12865. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  12866. {
  12867. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12868. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12869. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12870. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  12871. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  12872. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  12873. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  12874. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  12875. }
  12876. }
  12877. else
  12878. {
  12879. break;
  12880. }
  12881. break;
  12882. }
  12883. //-------------------------------------------
  12884. case SessionSetupRequest: //19
  12885. {
  12886. if (Proc_iso1_SessionSetupReq(AcceptFd) == 0)
  12887. {
  12888. Update_V2G_Flow_Status(SessionSetupResponse);
  12889. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12890. }
  12891. else
  12892. {
  12893. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionSetupReqRes: fail");
  12894. Update_V2G_Flow_Status(Other_Fault);
  12895. }
  12896. req_is_responsed = TRUE;
  12897. break;
  12898. }
  12899. case SessionSetupResponse: //20
  12900. {
  12901. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  12902. {
  12903. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  12904. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12905. }
  12906. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12907. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  12908. {
  12909. sprintf(buf_log_evcomm,
  12910. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12911. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12912. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12913. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12914. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12915. }
  12916. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  12917. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12918. {
  12919. sprintf(buf_log_evcomm,
  12920. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  12921. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12922. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12923. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12924. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  12925. {
  12926. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12927. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12928. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12929. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  12930. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  12931. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  12932. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  12933. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  12934. }
  12935. }
  12936. else
  12937. {
  12938. break;
  12939. }
  12940. break;
  12941. }
  12942. //-------------------------------------------
  12943. case ServiceDiscoveryRequest: //21
  12944. {
  12945. if (Proc_iso1_ServiceDiscoveryReq(AcceptFd) == 0)
  12946. {
  12947. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  12948. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12949. }
  12950. else
  12951. {
  12952. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceDiscoveryReqRes: fail");
  12953. Update_V2G_Flow_Status(Other_Fault);
  12954. }
  12955. req_is_responsed = TRUE;
  12956. break;
  12957. }
  12958. case ServiceDiscoveryResponse: //22
  12959. {
  12960. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  12961. {
  12962. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  12963. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12964. }
  12965. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12966. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  12967. {
  12968. sprintf(buf_log_evcomm,
  12969. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12970. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12971. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12972. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12973. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12974. }
  12975. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  12976. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12977. {
  12978. sprintf(buf_log_evcomm,
  12979. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  12980. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12981. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12982. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12983. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  12984. {
  12985. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12986. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12987. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12988. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  12989. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  12990. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  12991. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  12992. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  12993. }
  12994. }
  12995. else
  12996. {
  12997. break;
  12998. }
  12999. break;
  13000. }
  13001. //-------------------------------------------
  13002. case ServiceAndPaymentSelectionRequest: //25
  13003. {
  13004. if (Proc_iso1_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  13005. {
  13006. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  13007. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13008. }
  13009. else
  13010. {
  13011. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceAndPaymentSelectionReqRes: fail");
  13012. Update_V2G_Flow_Status(Other_Fault);
  13013. }
  13014. req_is_responsed = TRUE;
  13015. break;
  13016. }
  13017. case ServiceAndPaymentSelectionResponse: //26
  13018. {
  13019. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  13020. {
  13021. Update_V2G_Flow_Status(AuthorizationRequest);
  13022. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13023. }
  13024. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13025. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  13026. {
  13027. sprintf(buf_log_evcomm,
  13028. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13029. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13030. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13031. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13032. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13033. }
  13034. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  13035. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13036. {
  13037. sprintf(buf_log_evcomm,
  13038. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  13039. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13040. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13041. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13042. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  13043. {
  13044. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13045. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13046. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13047. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  13048. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  13049. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  13050. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  13051. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  13052. }
  13053. }
  13054. else
  13055. {
  13056. break;
  13057. }
  13058. break;
  13059. }
  13060. //-------------------------------------------
  13061. //case ContractAuthenticationReq:
  13062. case AuthorizationRequest: //29
  13063. {
  13064. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  13065. {
  13066. Update_V2G_Flow_Status(AuthorizationResponse);
  13067. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13068. }
  13069. else
  13070. {
  13071. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  13072. Update_V2G_Flow_Status(Other_Fault);
  13073. }
  13074. req_is_responsed = TRUE;
  13075. break;
  13076. }
  13077. case AuthorizationResponse: //30
  13078. {
  13079. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  13080. {
  13081. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13082. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  13083. {
  13084. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13085. }
  13086. else
  13087. {
  13088. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  13089. Update_V2G_Flow_Status(Other_Fault);
  13090. }
  13091. req_is_responsed = TRUE;
  13092. break;
  13093. }
  13094. //Check for ChargeParameterDiscoveryReq
  13095. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  13096. {
  13097. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13098. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  13099. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  13100. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13101. ftime(&SeqStartTime);
  13102. #endif
  13103. }
  13104. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13105. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  13106. {
  13107. sprintf(buf_log_evcomm,
  13108. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13109. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13110. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13111. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13112. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13113. }
  13114. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  13115. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13116. {
  13117. sprintf(buf_log_evcomm,
  13118. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  13119. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13120. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13121. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13122. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  13123. {
  13124. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13125. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13126. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13127. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  13128. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  13129. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  13130. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  13131. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  13132. }
  13133. }
  13134. else
  13135. {
  13136. break;
  13137. }
  13138. break;
  13139. }
  13140. //-------------------------------------------
  13141. case ChargeParameterDiscoveryRequest: //35
  13142. {
  13143. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  13144. {
  13145. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  13146. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13147. }
  13148. else
  13149. {
  13150. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  13151. Update_V2G_Flow_Status(Other_Fault);
  13152. }
  13153. req_is_responsed = TRUE;
  13154. break;
  13155. }
  13156. case ChargeParameterDiscoveryResponse:
  13157. {
  13158. //STEP 1: Check for Process Timeout
  13159. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13160. ftime(&SeqEndTime);
  13161. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  13162. {
  13163. sprintf(buf_log_evcomm,
  13164. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  13165. DiffTimeb(SeqStartTime, SeqEndTime),
  13166. V2G_SECC_ChargingParameter_Performance_Time);
  13167. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13168. Update_V2G_Flow_Status(Sequence_Timeout);
  13169. break;
  13170. }
  13171. #endif
  13172. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  13173. {
  13174. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13175. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  13176. {
  13177. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13178. }
  13179. else
  13180. {
  13181. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  13182. Update_V2G_Flow_Status(Other_Fault);
  13183. }
  13184. req_is_responsed = TRUE;
  13185. break;
  13186. }
  13187. //STEP 2: Check for CableCheckReq message
  13188. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  13189. {
  13190. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13191. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CableCheckReqReq: isolated?");
  13192. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  13193. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  13194. Update_V2G_Flow_Status(CableCheckRequest);
  13195. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13196. ftime(&SeqStartTime);
  13197. #endif
  13198. }
  13199. //STEP 3: Wait for PowerDeliveryReq Message
  13200. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13201. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13202. {
  13203. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13204. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13205. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  13206. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13207. ftime(&SeqStartTime);
  13208. #endif
  13209. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  13210. {
  13211. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13212. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13213. }
  13214. else
  13215. {
  13216. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  13217. Update_V2G_Flow_Status(Other_Fault);
  13218. }
  13219. break;
  13220. }
  13221. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13222. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  13223. {
  13224. sprintf(buf_log_evcomm,
  13225. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13226. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13227. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13228. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13229. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13230. }
  13231. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  13232. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13233. {
  13234. sprintf(buf_log_evcomm,
  13235. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  13236. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13237. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13238. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13239. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  13240. {
  13241. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13242. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13243. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13244. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  13245. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  13246. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  13247. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  13248. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  13249. }
  13250. }
  13251. else
  13252. {
  13253. break;
  13254. }
  13255. break;
  13256. }
  13257. //-------------------------------------------
  13258. case CableCheckRequest: //37
  13259. {
  13260. //STEP 3: Execute Cable Check Process
  13261. if (Proc_iso1_CableCheckReq(AcceptFd) == 0)
  13262. {
  13263. Update_V2G_Flow_Status(CableCheckResponse);
  13264. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13265. }
  13266. else
  13267. {
  13268. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  13269. Update_V2G_Flow_Status(Other_Fault);
  13270. }
  13271. req_is_responsed = TRUE;
  13272. break;
  13273. }
  13274. case CableCheckResponse: //38
  13275. {
  13276. //STEP 1: Check for Process Timeout
  13277. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13278. ftime(&SeqEndTime);
  13279. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  13280. {
  13281. //SAVE_SYS_LOG_MSG_EVCOMM("[CableCheck] end counting...");
  13282. sprintf(buf_log_evcomm,
  13283. "CableCheck Timeout - (%.02lf of %d ms)\n",
  13284. DiffTimeb(SeqStartTime, SeqEndTime),
  13285. V2G_SECC_CableCheck_Performance_Time);
  13286. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13287. Update_V2G_Flow_Status(Sequence_Timeout);
  13288. //Update_ShmStatusCode(); //[To-Do] to be implemented
  13289. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  13290. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  13291. {
  13292. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13293. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13294. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13295. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  13296. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  13297. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  13298. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  13299. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  13300. }
  13301. break;
  13302. }
  13303. #endif
  13304. //STEP 2: Check for CableCheckReq message
  13305. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  13306. {
  13307. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13308. //STEP 3: Execute Cable Check Process
  13309. if (Proc_iso1_CableCheckReq(AcceptFd) == 0)
  13310. {
  13311. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13312. }
  13313. else
  13314. {
  13315. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  13316. Update_V2G_Flow_Status(Other_Fault);
  13317. }
  13318. req_is_responsed = TRUE;
  13319. break;
  13320. }
  13321. //STEP 3: Check for PreChargeReq message
  13322. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  13323. {
  13324. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13325. Update_V2G_Flow_Status(PreChargeRequest);
  13326. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PreChargeReqReq: waiting for precharge voltage...");
  13327. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  13328. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  13329. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13330. ftime(&SeqStartTime);
  13331. #endif
  13332. }
  13333. //STEP 3: Wait for PowerDeliveryReq Message
  13334. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13335. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13336. {
  13337. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13338. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13339. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  13340. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13341. ftime(&SeqStartTime);
  13342. #endif
  13343. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  13344. {
  13345. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13346. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13347. }
  13348. else
  13349. {
  13350. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  13351. Update_V2G_Flow_Status(Other_Fault);
  13352. }
  13353. break;
  13354. }
  13355. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13356. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  13357. {
  13358. sprintf(buf_log_evcomm,
  13359. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13360. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13361. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13362. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13363. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13364. }
  13365. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  13366. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13367. {
  13368. sprintf(buf_log_evcomm,
  13369. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  13370. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13371. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13372. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13373. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  13374. {
  13375. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13376. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13377. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13378. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  13379. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  13380. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  13381. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  13382. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  13383. }
  13384. }
  13385. else
  13386. {
  13387. break;
  13388. }
  13389. break;
  13390. }
  13391. //-------------------------------------------
  13392. case PreChargeRequest: //39
  13393. {
  13394. if (Proc_iso1_PreChargeReq(AcceptFd) == 0)
  13395. {
  13396. Update_V2G_Flow_Status(PreChargeResponse);
  13397. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13398. }
  13399. else
  13400. {
  13401. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  13402. Update_V2G_Flow_Status(Other_Fault);
  13403. }
  13404. req_is_responsed = TRUE;
  13405. break;
  13406. }
  13407. case PreChargeResponse: //40
  13408. {
  13409. //STEP 1: Check for Process Timeout
  13410. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13411. ftime(&SeqEndTime);
  13412. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  13413. {
  13414. sprintf(buf_log_evcomm,
  13415. "Precharge Timeout - (%.02lf of %d ms)\n",
  13416. DiffTimeb(SeqStartTime, SeqEndTime),
  13417. V2G_SECC_PreCharge_Performance_Time);
  13418. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13419. Update_V2G_Flow_Status(Sequence_Timeout);
  13420. //Update_ShmStatusCode(); //[To-Do] to be implemented
  13421. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  13422. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13423. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13424. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13425. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  13426. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  13427. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  13428. break;
  13429. }
  13430. #endif
  13431. //STEP 2: Check for PreChargeReq message
  13432. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  13433. {
  13434. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13435. if (Proc_iso1_PreChargeReq(AcceptFd) == 0)
  13436. {
  13437. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13438. }
  13439. else
  13440. {
  13441. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  13442. Update_V2G_Flow_Status(Other_Fault);
  13443. }
  13444. req_is_responsed = TRUE;
  13445. break;
  13446. }
  13447. //STEP 3: Check for PowerDeliveryReq message
  13448. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13449. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13450. {
  13451. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13452. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  13453. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  13454. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13455. ftime(&SeqStartTime);
  13456. #endif
  13457. }
  13458. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13459. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  13460. {
  13461. sprintf(buf_log_evcomm,
  13462. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13463. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13464. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13465. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13466. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13467. }
  13468. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  13469. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13470. {
  13471. sprintf(buf_log_evcomm,
  13472. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  13473. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13474. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13475. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13476. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  13477. {
  13478. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13479. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13480. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13481. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  13482. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  13483. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  13484. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  13485. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  13486. }
  13487. }
  13488. else
  13489. {
  13490. break;
  13491. }
  13492. break;
  13493. }
  13494. //-------------------------------------------
  13495. case PowerDeliveryRequestStart: //41
  13496. {
  13497. if (Proc_iso1_PowerDeliveryStartReq(AcceptFd) == 0)
  13498. {
  13499. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  13500. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13501. }
  13502. else
  13503. {
  13504. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStartReqRes: fail");
  13505. Update_V2G_Flow_Status(Other_Fault);
  13506. }
  13507. req_is_responsed = TRUE;
  13508. break;
  13509. }
  13510. case PowerDeliveryResponsetStart: //42
  13511. {
  13512. //STEP 1: Check for Process Timeout
  13513. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13514. if (ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  13515. {
  13516. ftime(&SeqEndTime);
  13517. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  13518. {
  13519. sprintf(buf_log_evcomm,
  13520. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  13521. DiffTimeb(SeqStartTime, SeqEndTime),
  13522. 2000);
  13523. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13524. Update_V2G_Flow_Status(Sequence_Timeout);
  13525. }
  13526. break;
  13527. }
  13528. #endif
  13529. //STEP 2: Wait for CurrentDemandReq Message
  13530. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  13531. {
  13532. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13533. Update_V2G_Flow_Status(CurrentDemandRequest);
  13534. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CurrentDemandReqReq: energy transfering...");
  13535. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  13536. }
  13537. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13538. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  13539. {
  13540. sprintf(buf_log_evcomm,
  13541. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13542. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13543. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13544. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13545. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13546. }
  13547. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  13548. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13549. {
  13550. sprintf(buf_log_evcomm,
  13551. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  13552. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13553. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13554. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13555. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  13556. {
  13557. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13558. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13559. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13560. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  13561. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  13562. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  13563. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  13564. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  13565. }
  13566. }
  13567. else
  13568. {
  13569. break;
  13570. }
  13571. break;
  13572. }
  13573. //-------------------------------------------
  13574. case CurrentDemandRequest: //45,
  13575. {
  13576. if (Proc_iso1_CurrentDemandReq(AcceptFd) == 0)
  13577. {
  13578. Update_V2G_Flow_Status(CurrentDemandResponse);
  13579. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13580. }
  13581. else
  13582. {
  13583. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  13584. Update_V2G_Flow_Status(Other_Fault);
  13585. }
  13586. req_is_responsed = TRUE;
  13587. break;
  13588. }
  13589. case CurrentDemandResponse: //46,
  13590. {
  13591. //STEP 1: Wait for CurrentDemandReq Message
  13592. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  13593. {
  13594. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13595. if (Proc_iso1_CurrentDemandReq(AcceptFd) == 0)
  13596. {
  13597. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13598. }
  13599. else
  13600. {
  13601. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  13602. Update_V2G_Flow_Status(Other_Fault);
  13603. }
  13604. req_is_responsed = TRUE;
  13605. break;
  13606. }
  13607. //STEP 2: Wait for PowerDeliveryReq Message
  13608. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13609. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13610. {
  13611. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13612. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13613. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  13614. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13615. ftime(&SeqStartTime);
  13616. #endif
  13617. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  13618. {
  13619. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13620. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13621. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13622. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  13623. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  13624. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  13625. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  13626. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  13627. }
  13628. }
  13629. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13630. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  13631. {
  13632. sprintf(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 if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  13640. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13641. {
  13642. sprintf(buf_log_evcomm,
  13643. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  13644. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13645. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13646. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13647. if((EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown) && (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown))
  13648. {
  13649. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13650. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13651. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13652. ShmStatusCodeData->PresentStatusCode[0][3] = 9;
  13653. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  13654. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  13655. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  13656. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  13657. }
  13658. }
  13659. else
  13660. {
  13661. break;
  13662. }
  13663. break;
  13664. }
  13665. //-------------------------------------------
  13666. case PowerDeliveryRequestStop: //49,
  13667. {
  13668. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  13669. {
  13670. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13671. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13672. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13673. ftime(&SeqStartTime);
  13674. #endif
  13675. }
  13676. else
  13677. {
  13678. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  13679. Update_V2G_Flow_Status(Other_Fault);
  13680. }
  13681. req_is_responsed = TRUE;
  13682. break;
  13683. }
  13684. case PowerDeliveryResponseStop: //50,
  13685. {
  13686. //STEP 1: Check for Process Timeout
  13687. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13688. ftime(&SeqEndTime);
  13689. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  13690. {
  13691. sprintf(buf_log_evcomm,
  13692. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  13693. DiffTimeb(SeqStartTime, SeqEndTime),
  13694. 2000);
  13695. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13696. Update_V2G_Flow_Status(Sequence_Timeout);
  13697. break;
  13698. }
  13699. #endif
  13700. //STEP 2: Check for WeldingDetectionReq Message
  13701. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  13702. {
  13703. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13704. Update_V2G_Flow_Status(WeldingDetectionRequest);
  13705. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]WeldingDetectionReq: ongoing...");
  13706. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  13707. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13708. ftime(&SeqStartTime);
  13709. #endif
  13710. }
  13711. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  13712. {
  13713. Update_V2G_Flow_Status(SessionStopRequest);
  13714. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13715. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  13716. {
  13717. Update_V2G_Flow_Status(SessionStopResponse);
  13718. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13719. }
  13720. else
  13721. {
  13722. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  13723. Update_V2G_Flow_Status(Other_Fault);
  13724. }
  13725. break;
  13726. }
  13727. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13728. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  13729. {
  13730. sprintf(buf_log_evcomm,
  13731. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13732. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13733. if(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.ChargeProgress==iso1chargeProgressType_Stop)
  13734. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13735. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13736. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13737. }
  13738. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  13739. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13740. {
  13741. sprintf(buf_log_evcomm,
  13742. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  13743. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13744. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13745. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13746. }
  13747. else
  13748. {
  13749. break;
  13750. }
  13751. break;
  13752. }
  13753. //-------------------------------------------
  13754. case WeldingDetectionRequest: //51,
  13755. {
  13756. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  13757. {
  13758. Update_V2G_Flow_Status(WeldingDetectionResponse);
  13759. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13760. }
  13761. else
  13762. {
  13763. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  13764. Update_V2G_Flow_Status(Other_Fault);
  13765. }
  13766. req_is_responsed = TRUE;
  13767. break;
  13768. }
  13769. case WeldingDetectionResponse: //52,
  13770. {
  13771. //STEP 1: Check for Process Timeout
  13772. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13773. ftime(&SeqEndTime);
  13774. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  13775. {
  13776. sprintf(buf_log_evcomm,
  13777. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  13778. DiffTimeb(SeqStartTime, SeqEndTime),
  13779. V2G_SECC_WeldingDetection_Performance_Time);
  13780. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13781. Update_V2G_Flow_Status(Sequence_Timeout);
  13782. break;
  13783. }
  13784. #endif
  13785. //STEP 2: Check for WeldingDetectionReq Message
  13786. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  13787. {
  13788. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13789. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  13790. {
  13791. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13792. }
  13793. else
  13794. {
  13795. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  13796. Update_V2G_Flow_Status(Other_Fault);
  13797. }
  13798. req_is_responsed = TRUE;
  13799. break;
  13800. }
  13801. //STEP 3: Check for SessionStopReq Message
  13802. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  13803. {
  13804. Update_V2G_Flow_Status(SessionStopRequest);
  13805. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13806. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  13807. }
  13808. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13809. EVCOMM_SYS_INFO.V2G_Rx_Msg < PowerDeliveryRequestStop)
  13810. {
  13811. sprintf(buf_log_evcomm,
  13812. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13813. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13814. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13815. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13816. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13817. }
  13818. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= PowerDeliveryRequestStop &&
  13819. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13820. {
  13821. sprintf(buf_log_evcomm,
  13822. "[ERROR]Receive EV Stop Message(%d) => Tx Res MSG",
  13823. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13824. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13825. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13826. }
  13827. else
  13828. {
  13829. break;
  13830. }
  13831. break;
  13832. }
  13833. //-------------------------------------------
  13834. case SessionStopRequest: //53,
  13835. {
  13836. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  13837. {
  13838. Update_V2G_Flow_Status(SessionStopResponse);
  13839. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13840. }
  13841. else
  13842. {
  13843. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  13844. Update_V2G_Flow_Status(Other_Fault);
  13845. }
  13846. req_is_responsed = TRUE;
  13847. break;
  13848. }
  13849. case SessionStopResponse: //54,
  13850. {
  13851. break;
  13852. }
  13853. //-------------------------------------------
  13854. default:
  13855. {
  13856. break;
  13857. }
  13858. }
  13859. }
  13860. }
  13861. /*===========================================================================
  13862. FUNCTION: V2gMsg_Process_iso1_AC
  13863. DESCRIPTION:
  13864. PRE-CONDITION:
  13865. INPUT:
  13866. 1. V2gFlowStatus
  13867. OUTPUT:
  13868. GLOBAL VARIABLES:
  13869. 1. V2gFlowStatus
  13870. =============================================================================*/
  13871. int V2gMsg_Process_iso1_AC(int AcceptFd)
  13872. {
  13873. unsigned char req_is_responsed = FALSE;
  13874. while (req_is_responsed == FALSE)
  13875. {
  13876. //Check if it is in End_Process
  13877. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  13878. {
  13879. break;
  13880. }
  13881. switch(V2gFlowStatus)
  13882. {
  13883. //-------------------------------------------
  13884. case SupportedAppProtocolRequest: //17
  13885. {
  13886. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  13887. {
  13888. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  13889. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  13890. {
  13891. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13892. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  13893. }
  13894. else
  13895. {
  13896. SAVE_SYS_LOG_MSG_EVCOMM("[Error]supportedAppProtocolResReq: fail");
  13897. Update_V2G_Flow_Status(Other_Fault);
  13898. }
  13899. }
  13900. req_is_responsed = TRUE;
  13901. break;
  13902. }
  13903. case SupportedAppProtocolResponse: //18
  13904. {
  13905. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  13906. {
  13907. Update_V2G_Flow_Status(SessionSetupRequest);
  13908. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13909. }
  13910. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13911. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13912. {
  13913. sprintf(buf_log_evcomm,
  13914. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13915. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13916. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13917. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13918. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13919. }
  13920. else
  13921. {
  13922. break;
  13923. }
  13924. break;
  13925. }
  13926. //-------------------------------------------
  13927. case SessionSetupRequest: //19
  13928. {
  13929. if (Proc_iso1_SessionSetupReq(AcceptFd) == 0)
  13930. {
  13931. Update_V2G_Flow_Status(SessionSetupResponse);
  13932. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13933. }
  13934. else
  13935. {
  13936. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionSetupReqRes: fail");
  13937. Update_V2G_Flow_Status(Other_Fault);
  13938. }
  13939. req_is_responsed = TRUE;
  13940. break;
  13941. }
  13942. case SessionSetupResponse: //20
  13943. {
  13944. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  13945. {
  13946. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  13947. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13948. }
  13949. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13950. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13951. {
  13952. sprintf(buf_log_evcomm,
  13953. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13954. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13955. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13956. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13957. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13958. }
  13959. else
  13960. {
  13961. break;
  13962. }
  13963. break;
  13964. }
  13965. //-------------------------------------------
  13966. case ServiceDiscoveryRequest: //21
  13967. {
  13968. if (Proc_iso1_ServiceDiscoveryReq(AcceptFd) == 0)
  13969. {
  13970. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  13971. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13972. }
  13973. else
  13974. {
  13975. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceDiscoveryReqRes: fail");
  13976. Update_V2G_Flow_Status(Other_Fault);
  13977. }
  13978. req_is_responsed = TRUE;
  13979. break;
  13980. }
  13981. case ServiceDiscoveryResponse: //22
  13982. {
  13983. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  13984. {
  13985. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  13986. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13987. }
  13988. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13989. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13990. {
  13991. sprintf(buf_log_evcomm,
  13992. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13993. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13994. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13995. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13996. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13997. }
  13998. else
  13999. {
  14000. break;
  14001. }
  14002. break;
  14003. }
  14004. //-------------------------------------------
  14005. case ServiceAndPaymentSelectionRequest: //25
  14006. {
  14007. if (Proc_iso1_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  14008. {
  14009. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  14010. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14011. }
  14012. else
  14013. {
  14014. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceAndPaymentSelectionReqRes: fail");
  14015. Update_V2G_Flow_Status(Other_Fault);
  14016. }
  14017. req_is_responsed = TRUE;
  14018. break;
  14019. }
  14020. case ServiceAndPaymentSelectionResponse://26
  14021. {
  14022. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  14023. {
  14024. Update_V2G_Flow_Status(AuthorizationRequest);
  14025. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14026. }
  14027. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14028. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14029. {
  14030. sprintf(buf_log_evcomm,
  14031. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14032. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14033. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14034. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14035. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14036. }
  14037. else
  14038. {
  14039. break;
  14040. }
  14041. break;
  14042. }
  14043. //-------------------------------------------
  14044. //case ContractAuthenticationReq:
  14045. case AuthorizationRequest: //29
  14046. {
  14047. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  14048. {
  14049. Update_V2G_Flow_Status(AuthorizationResponse);
  14050. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14051. }
  14052. else
  14053. {
  14054. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  14055. Update_V2G_Flow_Status(Other_Fault);
  14056. }
  14057. req_is_responsed = TRUE;
  14058. break;
  14059. }
  14060. case AuthorizationResponse: //30
  14061. {
  14062. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  14063. {
  14064. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14065. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  14066. {
  14067. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14068. }
  14069. else
  14070. {
  14071. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  14072. Update_V2G_Flow_Status(Other_Fault);
  14073. }
  14074. req_is_responsed = TRUE;
  14075. break;
  14076. }
  14077. //Check for ChargeParameterDiscoveryReq
  14078. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  14079. {
  14080. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14081. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  14082. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  14083. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14084. ftime(&SeqStartTime);
  14085. #endif
  14086. }
  14087. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14088. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14089. {
  14090. sprintf(buf_log_evcomm,
  14091. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14092. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14093. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14094. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14095. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14096. }
  14097. else
  14098. {
  14099. break;
  14100. }
  14101. break;
  14102. }
  14103. //-------------------------------------------
  14104. case ChargeParameterDiscoveryRequest: //35
  14105. {
  14106. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  14107. {
  14108. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  14109. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14110. }
  14111. else
  14112. {
  14113. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  14114. Update_V2G_Flow_Status(Other_Fault);
  14115. }
  14116. req_is_responsed = TRUE;
  14117. break;
  14118. }
  14119. case ChargeParameterDiscoveryResponse: //36
  14120. {
  14121. //STEP 1: Check for Process Timeout
  14122. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14123. ftime(&SeqEndTime);
  14124. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  14125. {
  14126. sprintf(buf_log_evcomm,
  14127. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  14128. DiffTimeb(SeqStartTime, SeqEndTime),
  14129. V2G_SECC_ChargingParameter_Performance_Time);
  14130. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14131. Update_V2G_Flow_Status(Sequence_Timeout);
  14132. break;
  14133. }
  14134. #endif
  14135. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  14136. {
  14137. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14138. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  14139. {
  14140. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14141. }
  14142. else
  14143. {
  14144. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  14145. Update_V2G_Flow_Status(Other_Fault);
  14146. }
  14147. req_is_responsed = TRUE;
  14148. break;
  14149. }
  14150. //STEP 3: Wait for PowerDeliveryReq Message
  14151. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  14152. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  14153. {
  14154. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  14155. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14156. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  14157. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14158. ftime(&SeqStartTime);
  14159. #endif
  14160. break;
  14161. }
  14162. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14163. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14164. {
  14165. sprintf(buf_log_evcomm,
  14166. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14167. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14168. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14169. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14170. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14171. }
  14172. else
  14173. {
  14174. break;
  14175. }
  14176. break;
  14177. }
  14178. //-------------------------------------------
  14179. case PowerDeliveryRequestStart: //41
  14180. {
  14181. if (Proc_iso1_PowerDeliveryStartReq(AcceptFd) == 0)
  14182. {
  14183. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  14184. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14185. }
  14186. else
  14187. {
  14188. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStartReqRes: fail");
  14189. Update_V2G_Flow_Status(Other_Fault);
  14190. }
  14191. req_is_responsed = TRUE;
  14192. break;
  14193. }
  14194. case PowerDeliveryResponsetStart: //42
  14195. {
  14196. //STEP 1: Check for Process Timeout
  14197. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14198. if (ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  14199. {
  14200. ftime(&SeqEndTime);
  14201. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  14202. {
  14203. sprintf(buf_log_evcomm,
  14204. "Wait for ChargingStatusReq Timeout - (%.02lf of %d ms)\n",
  14205. DiffTimeb(SeqStartTime, SeqEndTime),
  14206. 2000);
  14207. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14208. Update_V2G_Flow_Status(Sequence_Timeout);
  14209. }
  14210. break;
  14211. }
  14212. #endif
  14213. //STEP 2: Wait for ChargingStatusReq Message
  14214. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargingStatusRequest)
  14215. {
  14216. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14217. Update_V2G_Flow_Status(ChargingStatusRequest);
  14218. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]ChargingStatusReq: energy transfering...");
  14219. ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_Start);
  14220. }
  14221. else
  14222. {
  14223. break;
  14224. }
  14225. break;
  14226. }
  14227. //-------------------------------------------
  14228. case ChargingStatusRequest: //43
  14229. {
  14230. if (Proc_iso1_ChargingStatusReq(AcceptFd) == 0)
  14231. {
  14232. Update_V2G_Flow_Status(ChargingStatusResponse);
  14233. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14234. }
  14235. else
  14236. {
  14237. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingStatusRes: fail");
  14238. Update_V2G_Flow_Status(Other_Fault);
  14239. }
  14240. req_is_responsed = TRUE;
  14241. break;
  14242. }
  14243. case ChargingStatusResponse: //44
  14244. {
  14245. //STEP 1: Wait for ChargingStatusReq Message
  14246. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargingStatusRequest)
  14247. {
  14248. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14249. if (Proc_iso1_ChargingStatusReq(AcceptFd) == 0)
  14250. {
  14251. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14252. }
  14253. else
  14254. {
  14255. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingStatusRes: fail");
  14256. Update_V2G_Flow_Status(Other_Fault);
  14257. }
  14258. req_is_responsed = TRUE;
  14259. break;
  14260. }
  14261. //STEP 2: Wait for PowerDeliveryReq Message
  14262. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  14263. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  14264. {
  14265. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  14266. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14267. ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_End);
  14268. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14269. ftime(&SeqStartTime);
  14270. #endif
  14271. }
  14272. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14273. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14274. {
  14275. sprintf(buf_log_evcomm,
  14276. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14277. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14278. // EVCOMM_SYS_INFO.SequenceError = TRUE;
  14279. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14280. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14281. break;
  14282. }
  14283. else
  14284. {
  14285. break;
  14286. }
  14287. break;
  14288. }
  14289. //-------------------------------------------
  14290. case PowerDeliveryRequestStop: //49
  14291. {
  14292. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  14293. {
  14294. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  14295. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14296. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14297. ftime(&SeqStartTime);
  14298. #endif
  14299. }
  14300. else
  14301. {
  14302. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  14303. Update_V2G_Flow_Status(Other_Fault);
  14304. }
  14305. req_is_responsed = TRUE;
  14306. break;
  14307. }
  14308. case PowerDeliveryResponseStop: //50
  14309. {
  14310. //STEP 1: Check for Process Timeout
  14311. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14312. ftime(&SeqEndTime);
  14313. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  14314. {
  14315. sprintf(buf_log_evcomm,
  14316. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  14317. DiffTimeb(SeqStartTime, SeqEndTime),
  14318. 2000);
  14319. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14320. Update_V2G_Flow_Status(Sequence_Timeout);
  14321. break;
  14322. }
  14323. #endif
  14324. //STEP 3: Check for SessionStopReq Message
  14325. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  14326. {
  14327. Update_V2G_Flow_Status(SessionStopRequest);
  14328. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14329. }
  14330. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14331. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14332. {
  14333. sprintf(buf_log_evcomm,
  14334. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14335. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14336. if(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.ChargeProgress==iso1chargeProgressType_Stop)
  14337. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14338. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14339. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14340. }
  14341. else
  14342. {
  14343. break;
  14344. }
  14345. break;
  14346. }
  14347. //-------------------------------------------
  14348. case SessionStopRequest: //53
  14349. {
  14350. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  14351. {
  14352. Update_V2G_Flow_Status(SessionStopResponse);
  14353. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14354. }
  14355. else
  14356. {
  14357. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  14358. Update_V2G_Flow_Status(Other_Fault);
  14359. }
  14360. req_is_responsed = TRUE;
  14361. break;
  14362. }
  14363. case SessionStopResponse: //54
  14364. {
  14365. break;
  14366. }
  14367. //-------------------------------------------
  14368. default:
  14369. {
  14370. break;
  14371. }
  14372. }
  14373. }
  14374. }
  14375. /*===========================================================================
  14376. FUNCTION: V2gMsg_Process_iso1
  14377. DESCRIPTION:
  14378. 1. EnergyTransferMode:
  14379. AC_single_phase_core = 0,
  14380. AC_three_phase_core = 1,
  14381. DC_core = 2,
  14382. DC_extended = 3,
  14383. DC_combo_core = 4,
  14384. DC_unique = 5
  14385. iso1EnergyTransferModeType_AC_single_phase_core = 0,
  14386. iso1EnergyTransferModeType_AC_three_phase_core = 1,
  14387. iso1EnergyTransferModeType_DC_core = 2,
  14388. iso1EnergyTransferModeType_DC_extended = 3,
  14389. iso1EnergyTransferModeType_DC_combo_core = 4,
  14390. iso1EnergyTransferModeType_DC_unique = 5
  14391. PRE-CONDITION:
  14392. INPUT:
  14393. 1. V2gFlowStatus
  14394. OUTPUT:
  14395. GLOBAL VARIABLES:
  14396. 1. V2gFlowStatus
  14397. =============================================================================*/
  14398. int V2gMsg_Process_iso1(int AcceptFd, unsigned char EnergyTransferMode)
  14399. {
  14400. switch (EnergyTransferMode)
  14401. {
  14402. case DC_extended:
  14403. {
  14404. V2gMsg_Process_iso1_DC(AcceptFd);
  14405. break;
  14406. }
  14407. case AC_single_phase_core:
  14408. case AC_three_phase_core:
  14409. {
  14410. V2gMsg_Process_iso1_AC(AcceptFd);
  14411. break;
  14412. }
  14413. default:
  14414. {
  14415. sprintf(buf_log_evcomm,
  14416. "[ISO1][Warning]Unexpected EnergyTransferMode(%d)",
  14417. EnergyTransferMode);
  14418. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14419. break;
  14420. }
  14421. }
  14422. }
  14423. /*===========================================================================
  14424. FUNCTION: V2gMsg_Process_iso2_DC
  14425. DESCRIPTION:
  14426. PRE-CONDITION:
  14427. INPUT:
  14428. 1. V2gFlowStatus
  14429. OUTPUT:
  14430. GLOBAL VARIABLES:
  14431. 1. V2gFlowStatus
  14432. =============================================================================*/
  14433. int V2gMsg_Process_iso2_DC(int AcceptFd)
  14434. {
  14435. unsigned char req_is_responsed = FALSE;
  14436. while (req_is_responsed == FALSE)
  14437. {
  14438. //Check if it is in End_Process
  14439. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  14440. {
  14441. break;
  14442. }
  14443. switch(V2gFlowStatus)
  14444. {
  14445. //-------------------------------------------
  14446. case SupportedAppProtocolRequest:
  14447. {
  14448. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  14449. {
  14450. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  14451. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  14452. {
  14453. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14454. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  14455. }
  14456. else
  14457. {
  14458. SAVE_SYS_LOG_MSG_EVCOMM("[Error]supportedAppProtocolResReq: fail");
  14459. Update_V2G_Flow_Status(Other_Fault);
  14460. }
  14461. }
  14462. req_is_responsed = TRUE;
  14463. break;
  14464. }
  14465. case SupportedAppProtocolResponse:
  14466. {
  14467. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  14468. {
  14469. Update_V2G_Flow_Status(SessionSetupRequest);
  14470. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14471. }
  14472. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14473. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14474. {
  14475. sprintf(buf_log_evcomm,
  14476. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14477. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14478. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14479. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14480. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14481. }
  14482. else
  14483. {
  14484. break;
  14485. }
  14486. break;
  14487. }
  14488. //-------------------------------------------
  14489. case SessionSetupRequest: //19
  14490. {
  14491. if (Proc_iso2_SessionSetupReq(AcceptFd) == 0)
  14492. {
  14493. Update_V2G_Flow_Status(SessionSetupResponse);
  14494. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14495. }
  14496. else
  14497. {
  14498. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionSetupReqRes: fail");
  14499. Update_V2G_Flow_Status(Other_Fault);
  14500. }
  14501. req_is_responsed = TRUE;
  14502. break;
  14503. }
  14504. case SessionSetupResponse: //20
  14505. {
  14506. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  14507. {
  14508. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  14509. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14510. }
  14511. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14512. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14513. {
  14514. sprintf(buf_log_evcomm,
  14515. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14516. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14517. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14518. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14519. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14520. }
  14521. else
  14522. {
  14523. break;
  14524. }
  14525. break;
  14526. }
  14527. #if 0
  14528. //-------------------------------------------
  14529. case ServiceDiscoveryRequest: //21
  14530. {
  14531. if (Proc_iso2_ServiceDiscoveryReq(AcceptFd) == 0)
  14532. {
  14533. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  14534. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14535. }
  14536. else
  14537. {
  14538. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceDiscoveryReqRes: fail");
  14539. Update_V2G_Flow_Status(Other_Fault);
  14540. }
  14541. req_is_responsed = TRUE;
  14542. break;
  14543. }
  14544. case ServiceDiscoveryResponse: //22
  14545. {
  14546. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  14547. {
  14548. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  14549. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14550. }
  14551. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14552. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14553. {
  14554. sprintf(buf_log_evcomm,
  14555. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14556. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14557. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14558. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14559. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14560. }
  14561. else
  14562. {
  14563. break;
  14564. }
  14565. break;
  14566. }
  14567. //-------------------------------------------
  14568. case ServiceAndPaymentSelectionRequest: //25
  14569. {
  14570. if (Proc_iso2_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  14571. {
  14572. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  14573. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14574. }
  14575. else
  14576. {
  14577. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceAndPaymentSelectionReqRes: fail");
  14578. Update_V2G_Flow_Status(Other_Fault);
  14579. }
  14580. req_is_responsed = TRUE;
  14581. break;
  14582. }
  14583. case ServiceAndPaymentSelectionResponse: //26
  14584. {
  14585. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  14586. {
  14587. Update_V2G_Flow_Status(AuthorizationRequest);
  14588. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14589. }
  14590. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14591. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14592. {
  14593. sprintf(buf_log_evcomm,
  14594. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14595. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14596. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14597. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14598. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14599. }
  14600. else
  14601. {
  14602. break;
  14603. }
  14604. break;
  14605. }
  14606. //-------------------------------------------
  14607. //case ContractAuthenticationReq:
  14608. case AuthorizationRequest: //29
  14609. {
  14610. if (Proc_iso2_AuthenticationReq(AcceptFd) == 0)
  14611. {
  14612. Update_V2G_Flow_Status(AuthorizationResponse);
  14613. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14614. }
  14615. else
  14616. {
  14617. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  14618. Update_V2G_Flow_Status(Other_Fault);
  14619. }
  14620. req_is_responsed = TRUE;
  14621. break;
  14622. }
  14623. case AuthorizationResponse: //30
  14624. {
  14625. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  14626. {
  14627. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14628. if (Proc_iso2_AuthenticationReq(AcceptFd) == 0)
  14629. {
  14630. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14631. }
  14632. else
  14633. {
  14634. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  14635. Update_V2G_Flow_Status(Other_Fault);
  14636. }
  14637. req_is_responsed = TRUE;
  14638. break;
  14639. }
  14640. //Check for ChargeParameterDiscoveryReq
  14641. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  14642. {
  14643. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14644. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  14645. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  14646. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14647. ftime(&SeqStartTime);
  14648. #endif
  14649. }
  14650. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14651. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14652. {
  14653. sprintf(buf_log_evcomm,
  14654. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14655. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14656. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14657. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14658. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14659. }
  14660. else
  14661. {
  14662. break;
  14663. }
  14664. break;
  14665. }
  14666. //-------------------------------------------
  14667. case ChargeParameterDiscoveryRequest: //35
  14668. {
  14669. if (Proc_iso2_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  14670. {
  14671. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  14672. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14673. }
  14674. else
  14675. {
  14676. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  14677. Update_V2G_Flow_Status(Other_Fault);
  14678. }
  14679. req_is_responsed = TRUE;
  14680. break;
  14681. }
  14682. case ChargeParameterDiscoveryResponse:
  14683. {
  14684. //STEP 1: Check for Process Timeout
  14685. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14686. ftime(&SeqEndTime);
  14687. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  14688. {
  14689. sprintf(buf_log_evcomm,
  14690. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  14691. DiffTimeb(SeqStartTime, SeqEndTime),
  14692. V2G_SECC_ChargingParameter_Performance_Time);
  14693. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14694. Update_V2G_Flow_Status(Sequence_Timeout);
  14695. break;
  14696. }
  14697. #endif
  14698. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  14699. {
  14700. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14701. if (Proc_iso2_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  14702. {
  14703. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14704. }
  14705. else
  14706. {
  14707. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  14708. Update_V2G_Flow_Status(Other_Fault);
  14709. }
  14710. req_is_responsed = TRUE;
  14711. break;
  14712. }
  14713. //STEP 2: Check for CableCheckReq message
  14714. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  14715. {
  14716. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14717. Update_V2G_Flow_Status(CableCheckRequest);
  14718. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CableCheckReqReq: isolated?");
  14719. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  14720. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  14721. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14722. ftime(&SeqStartTime);
  14723. #endif
  14724. }
  14725. //STEP 3: Wait for PowerDeliveryReq Message
  14726. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  14727. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  14728. {
  14729. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  14730. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14731. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  14732. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14733. ftime(&SeqStartTime);
  14734. #endif
  14735. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  14736. {
  14737. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  14738. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14739. }
  14740. else
  14741. {
  14742. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  14743. Update_V2G_Flow_Status(Other_Fault);
  14744. }
  14745. break;
  14746. }
  14747. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14748. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14749. {
  14750. sprintf(buf_log_evcomm,
  14751. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14752. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14753. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14754. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14755. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14756. }
  14757. else
  14758. {
  14759. break;
  14760. }
  14761. break;
  14762. }
  14763. //-------------------------------------------
  14764. case CableCheckRequest: //37
  14765. {
  14766. //STEP 3: Execute Cable Check Process
  14767. if (Proc_iso2_CableCheckReq(AcceptFd) == 0)
  14768. {
  14769. Update_V2G_Flow_Status(CableCheckResponse);
  14770. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14771. }
  14772. else
  14773. {
  14774. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  14775. Update_V2G_Flow_Status(Other_Fault);
  14776. }
  14777. req_is_responsed = TRUE;
  14778. break;
  14779. }
  14780. case CableCheckResponse: //38
  14781. {
  14782. //STEP 1: Check for Process Timeout
  14783. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14784. ftime(&SeqEndTime);
  14785. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  14786. {
  14787. //SAVE_SYS_LOG_MSG_EVCOMM("[CableCheck] end counting...");
  14788. sprintf(buf_log_evcomm,
  14789. "CableCheck Timeout - (%.02lf of %d ms)\n",
  14790. DiffTimeb(SeqStartTime, SeqEndTime),
  14791. V2G_SECC_CableCheck_Performance_Time);
  14792. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14793. Update_V2G_Flow_Status(Sequence_Timeout);
  14794. //Update_ShmStatusCode(); //[To-Do] to be implemented
  14795. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  14796. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  14797. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  14798. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  14799. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  14800. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  14801. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  14802. break;
  14803. }
  14804. #endif
  14805. //STEP 2: Check for CableCheckReq message
  14806. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  14807. {
  14808. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14809. //STEP 3: Execute Cable Check Process
  14810. if (Proc_iso2_CableCheckReq(AcceptFd) == 0)
  14811. {
  14812. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14813. }
  14814. else
  14815. {
  14816. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  14817. Update_V2G_Flow_Status(Other_Fault);
  14818. }
  14819. req_is_responsed = TRUE;
  14820. break;
  14821. }
  14822. //STEP 3: Check for PreChargeReq message
  14823. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  14824. {
  14825. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14826. Update_V2G_Flow_Status(PreChargeRequest);
  14827. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PreChargeReqReq: waiting for precharge voltage...");
  14828. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  14829. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  14830. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14831. ftime(&SeqStartTime);
  14832. #endif
  14833. }
  14834. //STEP 3: Wait for PowerDeliveryReq Message
  14835. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  14836. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  14837. {
  14838. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  14839. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14840. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  14841. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14842. ftime(&SeqStartTime);
  14843. #endif
  14844. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  14845. {
  14846. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  14847. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14848. }
  14849. else
  14850. {
  14851. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  14852. Update_V2G_Flow_Status(Other_Fault);
  14853. }
  14854. break;
  14855. }
  14856. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14857. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14858. {
  14859. sprintf(buf_log_evcomm,
  14860. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14861. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14862. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14863. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14864. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14865. }
  14866. else
  14867. {
  14868. break;
  14869. }
  14870. break;
  14871. }
  14872. //-------------------------------------------
  14873. case PreChargeRequest: //39
  14874. {
  14875. if (Proc_iso2_PreChargeReq(AcceptFd) == 0)
  14876. {
  14877. Update_V2G_Flow_Status(PreChargeResponse);
  14878. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14879. }
  14880. else
  14881. {
  14882. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  14883. Update_V2G_Flow_Status(Other_Fault);
  14884. }
  14885. req_is_responsed = TRUE;
  14886. break;
  14887. }
  14888. case PreChargeResponse: //40
  14889. {
  14890. //STEP 1: Check for Process Timeout
  14891. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14892. ftime(&SeqEndTime);
  14893. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  14894. {
  14895. sprintf(buf_log_evcomm,
  14896. "Precharge Timeout - (%.02lf of %d ms)\n",
  14897. DiffTimeb(SeqStartTime, SeqEndTime),
  14898. V2G_SECC_PreCharge_Performance_Time);
  14899. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14900. Update_V2G_Flow_Status(Sequence_Timeout);
  14901. //Update_ShmStatusCode(); //[To-Do] to be implemented
  14902. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  14903. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  14904. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  14905. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  14906. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  14907. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  14908. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  14909. break;
  14910. }
  14911. #endif
  14912. //STEP 2: Check for PreChargeReq message
  14913. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  14914. {
  14915. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14916. if (Proc_iso2_PreChargeReq(AcceptFd) == 0)
  14917. {
  14918. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14919. }
  14920. else
  14921. {
  14922. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  14923. Update_V2G_Flow_Status(Other_Fault);
  14924. }
  14925. req_is_responsed = TRUE;
  14926. break;
  14927. }
  14928. //STEP 3: Check for PowerDeliveryReq message
  14929. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  14930. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  14931. {
  14932. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14933. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  14934. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  14935. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14936. ftime(&SeqStartTime);
  14937. #endif
  14938. }
  14939. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14940. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  14941. {
  14942. sprintf(buf_log_evcomm,
  14943. "[ERROR]SequenceError(%d) => Tx Res MSG",
  14944. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14945. EVCOMM_SYS_INFO.SequenceError = TRUE;
  14946. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  14947. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14948. }
  14949. else
  14950. {
  14951. break;
  14952. }
  14953. break;
  14954. }
  14955. //-------------------------------------------
  14956. case PowerDeliveryRequestStart: //41
  14957. {
  14958. if (Proc_iso2_PowerDeliveryStartReq(AcceptFd) == 0)
  14959. {
  14960. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  14961. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14962. }
  14963. else
  14964. {
  14965. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStartReqRes: fail");
  14966. Update_V2G_Flow_Status(Other_Fault);
  14967. }
  14968. req_is_responsed = TRUE;
  14969. break;
  14970. }
  14971. case PowerDeliveryResponsetStart: //42
  14972. {
  14973. //STEP 1: Check for Process Timeout
  14974. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  14975. if (ccs_exi_doc_ISO2.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  14976. {
  14977. ftime(&SeqEndTime);
  14978. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  14979. {
  14980. sprintf(buf_log_evcomm,
  14981. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  14982. DiffTimeb(SeqStartTime, SeqEndTime),
  14983. 2000);
  14984. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14985. Update_V2G_Flow_Status(Sequence_Timeout);
  14986. }
  14987. break;
  14988. }
  14989. #endif
  14990. //STEP 2: Wait for CurrentDemandReq Message
  14991. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  14992. {
  14993. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  14994. Update_V2G_Flow_Status(CurrentDemandRequest);
  14995. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CurrentDemandReqReq: energy transfering...");
  14996. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  14997. }
  14998. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  14999. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  15000. {
  15001. sprintf(buf_log_evcomm,
  15002. "[ERROR]SequenceError(%d) => Tx Res MSG",
  15003. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  15004. EVCOMM_SYS_INFO.SequenceError = TRUE;
  15005. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  15006. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  15007. }
  15008. else
  15009. {
  15010. break;
  15011. }
  15012. break;
  15013. }
  15014. //-------------------------------------------
  15015. case CurrentDemandRequest: //45,
  15016. {
  15017. if (Proc_iso2_CurrentDemandReq(AcceptFd) == 0)
  15018. {
  15019. Update_V2G_Flow_Status(CurrentDemandResponse);
  15020. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  15021. }
  15022. else
  15023. {
  15024. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  15025. Update_V2G_Flow_Status(Other_Fault);
  15026. }
  15027. req_is_responsed = TRUE;
  15028. break;
  15029. }
  15030. case CurrentDemandResponse: //46,
  15031. {
  15032. //STEP 1: Wait for CurrentDemandReq Message
  15033. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  15034. {
  15035. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  15036. if (Proc_iso2_CurrentDemandReq(AcceptFd) == 0)
  15037. {
  15038. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  15039. }
  15040. else
  15041. {
  15042. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  15043. Update_V2G_Flow_Status(Other_Fault);
  15044. }
  15045. req_is_responsed = TRUE;
  15046. break;
  15047. }
  15048. //STEP 2: Wait for PowerDeliveryReq Message
  15049. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  15050. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  15051. {
  15052. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  15053. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  15054. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  15055. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  15056. ftime(&SeqStartTime);
  15057. #endif
  15058. }
  15059. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  15060. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  15061. {
  15062. sprintf(buf_log_evcomm,
  15063. "[ERROR]SequenceError(%d) => Tx Res MSG",
  15064. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  15065. EVCOMM_SYS_INFO.SequenceError = TRUE;
  15066. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  15067. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  15068. }
  15069. else
  15070. {
  15071. break;
  15072. }
  15073. break;
  15074. }
  15075. //-------------------------------------------
  15076. case PowerDeliveryRequestStop: //49,
  15077. {
  15078. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  15079. {
  15080. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  15081. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  15082. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  15083. ftime(&SeqStartTime);
  15084. #endif
  15085. }
  15086. else
  15087. {
  15088. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  15089. Update_V2G_Flow_Status(Other_Fault);
  15090. }
  15091. req_is_responsed = TRUE;
  15092. break;
  15093. }
  15094. case PowerDeliveryResponseStop: //50,
  15095. {
  15096. //STEP 1: Check for Process Timeout
  15097. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  15098. ftime(&SeqEndTime);
  15099. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  15100. {
  15101. sprintf(buf_log_evcomm,
  15102. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  15103. DiffTimeb(SeqStartTime, SeqEndTime),
  15104. 2000);
  15105. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15106. Update_V2G_Flow_Status(Sequence_Timeout);
  15107. break;
  15108. }
  15109. #endif
  15110. //STEP 2: Check for WeldingDetectionReq Message
  15111. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  15112. {
  15113. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  15114. Update_V2G_Flow_Status(WeldingDetectionRequest);
  15115. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]WeldingDetectionReq: ongoing...");
  15116. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  15117. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  15118. ftime(&SeqStartTime);
  15119. #endif
  15120. }
  15121. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  15122. {
  15123. Update_V2G_Flow_Status(SessionStopRequest);
  15124. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  15125. if (Proc_iso2_SessionStopReq(AcceptFd) == 0)
  15126. {
  15127. Update_V2G_Flow_Status(SessionStopResponse);
  15128. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  15129. }
  15130. else
  15131. {
  15132. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  15133. Update_V2G_Flow_Status(Other_Fault);
  15134. }
  15135. break;
  15136. }
  15137. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  15138. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  15139. {
  15140. sprintf(buf_log_evcomm,
  15141. "[ERROR]SequenceError(%d) => Tx Res MSG",
  15142. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  15143. EVCOMM_SYS_INFO.SequenceError = TRUE;
  15144. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  15145. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  15146. }
  15147. else
  15148. {
  15149. break;
  15150. }
  15151. break;
  15152. }
  15153. //-------------------------------------------
  15154. case WeldingDetectionRequest: //51,
  15155. {
  15156. if (Proc_iso2_WeldingDetectionReq(AcceptFd) == 0)
  15157. {
  15158. Update_V2G_Flow_Status(WeldingDetectionResponse);
  15159. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  15160. }
  15161. else
  15162. {
  15163. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  15164. Update_V2G_Flow_Status(Other_Fault);
  15165. }
  15166. req_is_responsed = TRUE;
  15167. break;
  15168. }
  15169. case WeldingDetectionResponse: //52,
  15170. {
  15171. //STEP 1: Check for Process Timeout
  15172. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  15173. ftime(&SeqEndTime);
  15174. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  15175. {
  15176. sprintf(buf_log_evcomm,
  15177. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  15178. DiffTimeb(SeqStartTime, SeqEndTime),
  15179. V2G_SECC_WeldingDetection_Performance_Time);
  15180. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15181. Update_V2G_Flow_Status(Sequence_Timeout);
  15182. break;
  15183. }
  15184. #endif
  15185. //STEP 2: Check for WeldingDetectionReq Message
  15186. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  15187. {
  15188. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  15189. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  15190. {
  15191. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  15192. }
  15193. else
  15194. {
  15195. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  15196. Update_V2G_Flow_Status(Other_Fault);
  15197. }
  15198. req_is_responsed = TRUE;
  15199. break;
  15200. }
  15201. //STEP 3: Check for SessionStopReq Message
  15202. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  15203. {
  15204. Update_V2G_Flow_Status(SessionStopRequest);
  15205. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  15206. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  15207. }
  15208. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  15209. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  15210. {
  15211. sprintf(buf_log_evcomm,
  15212. "[ERROR]SequenceError(%d) => Tx Res MSG",
  15213. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  15214. EVCOMM_SYS_INFO.SequenceError = TRUE;
  15215. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  15216. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  15217. }
  15218. else
  15219. {
  15220. break;
  15221. }
  15222. break;
  15223. }
  15224. //-------------------------------------------
  15225. case SessionStopRequest: //53,
  15226. {
  15227. if (Proc_iso2_SessionStopReq(AcceptFd) == 0)
  15228. {
  15229. Update_V2G_Flow_Status(SessionStopResponse);
  15230. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  15231. }
  15232. else
  15233. {
  15234. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  15235. Update_V2G_Flow_Status(Other_Fault);
  15236. }
  15237. req_is_responsed = TRUE;
  15238. break;
  15239. }
  15240. case SessionStopResponse: //54,
  15241. {
  15242. break;
  15243. }
  15244. #endif
  15245. //-------------------------------------------
  15246. default:
  15247. {
  15248. break;
  15249. }
  15250. }
  15251. }
  15252. }
  15253. /*===========================================================================
  15254. FUNCTION: V2gMsg_Process_iso2_AC
  15255. DESCRIPTION:
  15256. PRE-CONDITION:
  15257. INPUT:
  15258. 1. V2gFlowStatus
  15259. OUTPUT:
  15260. GLOBAL VARIABLES:
  15261. 1. V2gFlowStatus
  15262. =============================================================================*/
  15263. int V2gMsg_Process_iso2_AC(int AcceptFd)
  15264. {
  15265. }
  15266. /*===========================================================================
  15267. FUNCTION: V2gMsg_Process_iso2
  15268. DESCRIPTION:
  15269. PRE-CONDITION:
  15270. INPUT:
  15271. 1. V2gFlowStatus
  15272. OUTPUT:
  15273. GLOBAL VARIABLES:
  15274. 1. V2gFlowStatus
  15275. =============================================================================*/
  15276. int V2gMsg_Process_iso2(int AcceptFd, unsigned char EnergyTransferMode)
  15277. {
  15278. switch (EnergyTransferMode)
  15279. {
  15280. case DC_extended:
  15281. {
  15282. V2gMsg_Process_iso2_DC(AcceptFd);
  15283. break;
  15284. }
  15285. case AC_single_phase_core:
  15286. case AC_three_phase_core:
  15287. {
  15288. V2gMsg_Process_iso2_AC(AcceptFd);
  15289. break;
  15290. }
  15291. default:
  15292. {
  15293. sprintf(buf_log_evcomm,
  15294. "[ISO2][Warning]Unexpected EnergyTransferMode(%d)",
  15295. EnergyTransferMode);
  15296. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15297. break;
  15298. }
  15299. }
  15300. }
  15301. /*===========================================================================
  15302. FUNCTION: V2gMsg_Process
  15303. DESCRIPTION:
  15304. PRE-CONDITION:
  15305. INPUT:
  15306. OUTPUT:
  15307. GLOBAL VARIABLES:
  15308. =============================================================================*/
  15309. int V2gMsg_Process(int AcceptFd)
  15310. {
  15311. int errn = 0;
  15312. switch (ShmCcsData->CommProtocol)
  15313. {
  15314. case V2GT_MSG_PROTOCOL_DIN70121: //0
  15315. {
  15316. V2gMsg_Process_din(AcceptFd);
  15317. break;
  15318. }
  15319. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  15320. {
  15321. V2gMsg_Process_iso1(AcceptFd, ShmCcsData->EnergyTransferMode);
  15322. break;
  15323. }
  15324. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  15325. {
  15326. V2gMsg_Process_iso2(AcceptFd, ShmCcsData->EnergyTransferMode);
  15327. break;
  15328. }
  15329. default:
  15330. {
  15331. sprintf(buf_log_evcomm,
  15332. "[Warning]Unexpected CommProtocol(%d)",
  15333. ShmCcsData->CommProtocol);
  15334. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15335. break;
  15336. }
  15337. }
  15338. return errn;
  15339. }
  15340. /*===========================================================================
  15341. FUNCTION: V2gMsg_Rx
  15342. DESCRIPTION:
  15343. PRE-CONDITION:
  15344. INPUT:
  15345. OUTPUT:
  15346. GLOBAL VARIABLES:
  15347. =============================================================================*/
  15348. int V2gMsg_Rx(int AcceptFd)
  15349. {
  15350. int errn = 0;
  15351. unsigned int packet_size = 0;
  15352. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  15353. #ifdef SUPPORT_TLS_CONNECTION
  15354. if(EvSecurity == 0)//support security
  15355. {
  15356. packet_size = SSL_read(ssl, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE);
  15357. }
  15358. else
  15359. {
  15360. packet_size = recv(AcceptFd, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, 0);
  15361. }
  15362. #else
  15363. packet_size = recv(AcceptFd, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, 0);
  15364. #endif
  15365. //[CAUTION] Everytime recv() is called, it will take a default time to wait for TCP packets.
  15366. //The more time you call recv(), the more time you will waste here.
  15367. //Here it is suggested that response immediatedly once you receive any packets.
  15368. //For configuring the Rx waiting time, please use setsockopt().
  15369. if(packet_size > 0) //[Joseph] If there is no data, ignore. (TBD)
  15370. {
  15371. //DEBUG_PRINTF_EVCOMM_DETAIL("\n\n Got TCP V2GTP Message: size = %d Bytes\n", packet_size);
  15372. errn = V2gMsgDecoder(V2gtpMsgRxBuf, packet_size, V2gFlowStatus);
  15373. if (errn < 0)
  15374. {
  15375. sprintf(buf_log_evcomm, "[ERROR]V2gMsgDecoder", errn);
  15376. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15377. }
  15378. }
  15379. return errn;
  15380. }
  15381. /*===========================================================================
  15382. FUNCTION: V2gComm
  15383. DESCRIPTION:
  15384. PRE-CONDITION:
  15385. 1. TCP socket is connected.
  15386. INPUT:
  15387. 1. AcceptFd //TCP Connection ID
  15388. 2. V2gtpMsgRxBuf[] //V2GTP Messages (Header + Payload)
  15389. 3. V2GTP_MSG_RX_BUFFER_SIZE //64*1024 = 65,536 = 65.5K (Bytes)
  15390. OUTPUT:
  15391. GLOBAL VARIABLES:
  15392. 1. V2gtpMsgRxBuf[]
  15393. =============================================================================*/
  15394. int V2gComm(int AcceptFd)
  15395. {
  15396. int errn = 0;
  15397. if (V2gMsg_Rx(AcceptFd) < 0)
  15398. {
  15399. Update_V2G_Flow_Status(Other_Fault);
  15400. errn = -1;
  15401. }
  15402. //following are the response message handling according to status flag
  15403. if (V2gMsg_Process(AcceptFd) < 0)
  15404. {
  15405. errn = -1;
  15406. }
  15407. //Error Check
  15408. //V2G_Error_Monitor();
  15409. return errn;
  15410. }
  15411. /*===========================================================================
  15412. FUNCTION: SdpUdpConnected
  15413. DESCRIPTION:
  15414. PRE-CONDITION:
  15415. INPUT:
  15416. OUTPUT:
  15417. GLOBAL VARIABLES:
  15418. =============================================================================*/
  15419. int SdpUdpConnected()
  15420. {
  15421. int packet_size,Rtn;
  15422. struct sockaddr_in6 ServerAddr,ClientAddr;
  15423. struct V2gtpHeader *header;
  15424. unsigned char *payload;
  15425. if(UdpSock <= 0)
  15426. {
  15427. if ((UdpSock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
  15428. {
  15429. SAVE_SYS_LOG_MSG_EVCOMM("SdpUdpConnected: Fail to open UdpSock");
  15430. return 0;
  15431. }
  15432. ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp=UdpSock;
  15433. memset(&ServerAddr,0, sizeof(struct sockaddr_in));
  15434. ServerAddr.sin6_family = AF_INET6;
  15435. ServerAddr.sin6_addr = in6addr_any;
  15436. ServerAddr.sin6_port = htons(SdpUdpServerPort);
  15437. if(bind(UdpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) <0)
  15438. {
  15439. sprintf(buf_log_evcomm,
  15440. "SdpUdpConnected: Fail to bind UdpSock(%d)",
  15441. UdpSock);
  15442. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15443. close(UdpSock);
  15444. UdpSock = -1;
  15445. return 0;
  15446. }
  15447. sprintf(buf_log_evcomm, "[UdpSock]opend:%d", UdpSock);
  15448. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15449. sprintf(buf_log_evcomm, "[SDP]Req from EVCC: waiting...(%d)", UdpSock);
  15450. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15451. }
  15452. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  15453. memset(&ClientAddr, 0, sizeof(struct sockaddr_in));
  15454. Rtn = sizeof(struct sockaddr_in6);
  15455. packet_size = recvfrom(UdpSock, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *)&ClientAddr, &Rtn);
  15456. if(packet_size > 0)
  15457. {
  15458. header = (struct V2gtpHeader *) V2gtpMsgRxBuf;
  15459. payload = V2gtpMsgRxBuf+sizeof(struct V2gtpHeader);
  15460. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  15461. {
  15462. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n Got UDP packet_size = %d (Bytes)\n", packet_size);
  15463. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***********************************\n");
  15464. DEBUG_PRINTF_EVCOMM_DETAIL("***** Received SDP Packet *****\n");
  15465. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  15466. DEBUG_PRINTF_EVCOMM_DETAIL("ClientAddress=");
  15467. for(Rtn = 0; Rtn < 16; Rtn += 2)
  15468. {
  15469. DEBUG_PRINTF_EVCOMM_DETAIL("%02x%02x:",ClientAddr.sin6_addr.s6_addr[Rtn],ClientAddr.sin6_addr.s6_addr[Rtn+1]);
  15470. }
  15471. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  15472. DEBUG_PRINTF_EVCOMM_DETAIL("ClientPort=%d\n",ClientAddr.sin6_port);
  15473. DEBUG_PRINTF_EVCOMM_DETAIL("ProtocolVersion=%d\n",header->ProtocolVersion);
  15474. DEBUG_PRINTF_EVCOMM_DETAIL("InverseProtocolVersion=0x%x\n",header->InverseProtocolVersion);
  15475. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadType=0x%x\n",htons(header->PayloadType));
  15476. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadLength=0x%x\n",htonl(header->PayloadLength));
  15477. DEBUG_PRINTF_EVCOMM_DETAIL("htons(header->PayloadType)=0x%x\n",htons(header->PayloadType));
  15478. }
  15479. #endif
  15480. if( (header->ProtocolVersion == 0x01) &&
  15481. (header->InverseProtocolVersion == 0xFE) &&
  15482. (htons(header->PayloadType) == V2GTP_PAYLOAD_TYPE_SDP_REQUEST))
  15483. {
  15484. sprintf(buf_log_evcomm, "[SDP][Rx]Req from EVCC: GOT(%d)", UdpSock);
  15485. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15486. DEBUG_PRINTF_EVCOMM_DETAIL("Security=0x%x\n", *(payload + 0));
  15487. DEBUG_PRINTF_EVCOMM_DETAIL("TransportProtocol=0x%x\n", *(payload + 1));
  15488. #ifdef SUPPORT_TLS_CONNECTION
  15489. EvSecurity= *(payload);
  15490. #endif
  15491. header->PayloadType = htons(V2GTP_PAYLOAD_TYPE_SDP_RESPONSE);
  15492. header->PayloadLength = htonl(20); //Fixed Length=20
  15493. memset(payload, 0, 20);
  15494. // MAC address[0:2] + FFFE + MAC address[3:5]
  15495. payload[0] = (IPV6_LINK_LOCAL_PREFIX>>8) & 0xFF;
  15496. payload[1] = IPV6_LINK_LOCAL_PREFIX & 0xFF;
  15497. payload[8 ]= CsuMac[0];
  15498. payload[8] ^= 0x02;// bit 1 should complemented.
  15499. payload[9] = CsuMac[1];
  15500. payload[10] = CsuMac[2];
  15501. payload[11] = 0xFF;
  15502. payload[12] = 0xFE;
  15503. payload[13] = CsuMac[3];
  15504. payload[14] = CsuMac[4];
  15505. payload[15] = CsuMac[5];
  15506. //TCP port
  15507. payload[16] = (EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active>>8) & 0xFF;
  15508. payload[17] = EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active & 0xFF;
  15509. #ifdef SUPPORT_TLS_CONNECTION
  15510. if(EvSecurity == 0)//support security
  15511. payload[18] = SDP_PAYLOAD_SECURITY_TLS; //Security
  15512. else
  15513. payload[18] = SDP_PAYLOAD_SECURITY_NONE; // No Security
  15514. #else
  15515. payload[18] = SDP_PAYLOAD_SECURITY_NONE; //No Security
  15516. #endif
  15517. payload[19] = SDP_PAYLOAD_TRANS_PROTOCOL_TCP; //Transport protocol
  15518. //[To-Do] Setup the TCP in advance to receive the coming TCP handshke messages after SDP response.
  15519. Rtn = sendto(UdpSock, V2gtpMsgRxBuf, sizeof(struct V2gtpHeader) + htonl(header->PayloadLength), 0, (struct sockaddr *)&ClientAddr, sizeof(struct sockaddr_in6));
  15520. sprintf(buf_log_evcomm, "[SDP][Tx]Res from SECC");
  15521. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15522. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  15523. {
  15524. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response SDP Packet *****\n");
  15525. DEBUG_PRINTF_EVCOMM_DETAIL("Send size=%d\n",Rtn);
  15526. DEBUG_PRINTF_EVCOMM_DETAIL("Destination Address=");
  15527. for(Rtn = 0; Rtn < 16; Rtn++)
  15528. {
  15529. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ", ClientAddr.sin6_addr.s6_addr[Rtn]);
  15530. }
  15531. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  15532. DEBUG_PRINTF_EVCOMM_DETAIL("Destination Port=%d\n", ClientAddr.sin6_port);
  15533. DEBUG_PRINTF_EVCOMM_DETAIL("ProtocolVersion=%d\n", header->ProtocolVersion);
  15534. DEBUG_PRINTF_EVCOMM_DETAIL("InverseProtocolVersion=0x%x\n", header->InverseProtocolVersion);
  15535. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadType=0x%x\n", htons(header->PayloadType));
  15536. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadLength=0x%x\n", htonl(header->PayloadLength));
  15537. DEBUG_PRINTF_EVCOMM_DETAIL("SECC Ipv6 Address=");
  15538. for(Rtn = 0; Rtn < 16; Rtn++)
  15539. {
  15540. DEBUG_PRINTF_EVCOMM_DETAIL("%02x:",payload[Rtn]);
  15541. }
  15542. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  15543. DEBUG_PRINTF_EVCOMM_DETAIL("SECC Port=%d\n", (payload[16]<<8 | payload[17]));
  15544. DEBUG_PRINTF_EVCOMM_DETAIL("Security=0x%x\n", payload[19]);
  15545. DEBUG_PRINTF_EVCOMM_DETAIL("TransportProtocol=0x%x\n", payload[20]);
  15546. }
  15547. #endif
  15548. if(Rtn >= 28)
  15549. {
  15550. return 1;
  15551. }
  15552. }
  15553. }
  15554. return 0;
  15555. }
  15556. /*===========================================================================
  15557. FUNCTION: V2gTcpConnected
  15558. DESCRIPTION:
  15559. PRE-CONDITION:
  15560. INPUT:
  15561. OUTPUT:
  15562. GLOBAL VARIABLES:
  15563. =============================================================================*/
  15564. int V2gTcpConnected()
  15565. {
  15566. int packet_size,Rtn,AcceptFd;
  15567. struct sockaddr_in6 ServerAddr,ClientAddr;
  15568. if(TcpSock <= 0)
  15569. {
  15570. if ((TcpSock = socket(PF_INET6, SOCK_STREAM, 0)) < 0)
  15571. {
  15572. sprintf(buf_log_evcomm,
  15573. "V2gTcpConnected: Fail to open TcpSock (%s)",
  15574. strerror(errno));
  15575. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15576. usleep(100000); //100ms
  15577. return 0;
  15578. }
  15579. ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp=TcpSock;
  15580. fcntl(TcpSock, F_SETFL, O_NONBLOCK); //set to O_NONBLOCK
  15581. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]socket set: DONE");
  15582. memset(&ServerAddr,0, sizeof(struct sockaddr_in));
  15583. ServerAddr.sin6_family = PF_INET6;
  15584. ServerAddr.sin6_addr = in6addr_any;
  15585. ServerAddr.sin6_port = htons(EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  15586. //ServerAddr.sin6_port = htons(SdpTcpServerPort + (rand() % 10) + 1);
  15587. //printf("SdpTcpServerPort = %d(DEC)\n", htons(ServerAddr.sin6_port));
  15588. if(bind(TcpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) < 0)
  15589. {
  15590. sprintf(buf_log_evcomm,
  15591. "V2gTcpConnected: Fail to bind TcpSock (%s), SdpTcpServerPort = %d",
  15592. strerror(errno),
  15593. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active
  15594. );
  15595. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15596. //Change to another TCP port
  15597. /*
  15598. memset(&ServerAddr, 0, sizeof(struct sockaddr_in));
  15599. ServerAddr.sin6_family = PF_INET6;
  15600. ServerAddr.sin6_addr = in6addr_any;
  15601. //ServerAddr.sin6_port = htons(SdpTcpServerPort + (rand() % 1000) + 1);
  15602. ServerAddr.sin6_port = htons(EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  15603. */
  15604. if(bind(TcpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) < 0)
  15605. {
  15606. sprintf(buf_log_evcomm,
  15607. "V2gTcpConnected: Fail to bind TcpSock (%s), SdpTcpServerPort = %d",
  15608. strerror(errno),
  15609. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active
  15610. );
  15611. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15612. usleep(100000); //100ms
  15613. close(TcpSock);
  15614. TcpSock = -1;
  15615. return 0;
  15616. }
  15617. }
  15618. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]blid: DONE");
  15619. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]listen: START");
  15620. if(listen(TcpSock, 1) < 0) //only accept one connection
  15621. {
  15622. sprintf(buf_log_evcomm,
  15623. "V2gTcpConnected: Fail to listen TcpSock (%s)",
  15624. strerror(errno));
  15625. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15626. usleep(100000); //100ms
  15627. close(TcpSock);
  15628. TcpSock = -1;
  15629. return 0;
  15630. }
  15631. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]listen: DONE");
  15632. sprintf(buf_log_evcomm, "[TCP]TcpSock: opened(%d), port=%d", TcpSock, htons(ServerAddr.sin6_port));
  15633. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15634. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]accept: START");
  15635. }
  15636. Rtn = sizeof(struct sockaddr_in6);
  15637. if((AcceptFd = accept(TcpSock, (struct sockaddr *)&ClientAddr, &Rtn)) < 0 )
  15638. {
  15639. static BOOL tmp = 0;
  15640. if (tmp = 0)
  15641. {
  15642. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]Wait TCP connection...");
  15643. tmp = 1;
  15644. }
  15645. else
  15646. {
  15647. //DEBUG_PRINTF_EVCOMM_DETAIL(".");
  15648. }
  15649. return 0;
  15650. }
  15651. ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed=AcceptFd;
  15652. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]accept: DONE\n");
  15653. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  15654. {
  15655. DEBUG_PRINTF_EVCOMM_DETAIL("\n\nAccept one TCP connection:\n");
  15656. DEBUG_PRINTF_EVCOMM_DETAIL("AcceptFd=%d\n",AcceptFd);
  15657. DEBUG_PRINTF_EVCOMM_DETAIL("ClientAddress=");
  15658. for(Rtn = 0; Rtn < 16; Rtn += 2)
  15659. {
  15660. DEBUG_PRINTF_EVCOMM_DETAIL("%02x%02x:", ClientAddr.sin6_addr.s6_addr[Rtn], ClientAddr.sin6_addr.s6_addr[Rtn+1]);
  15661. }
  15662. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  15663. DEBUG_PRINTF_EVCOMM_DETAIL("ClientPort=%d\n", ClientAddr.sin6_port);
  15664. }
  15665. #endif
  15666. #ifdef SUPPORT_TLS_CONNECTION
  15667. /* TCP connection is ready. Do server side SSL connection. */
  15668. if(EvSecurity == 0)//support security
  15669. {
  15670. ssl = SSL_new(ctx);
  15671. SSL_set_fd(ssl, AcceptFd);
  15672. if (SSL_accept(ssl) <= 0)
  15673. {
  15674. //SAVE_SYS_LOG_MSG_EVCOMM("[SSL]SSL_accept Failed");
  15675. //SSL_free(ssl);
  15676. //close(AcceptFd);
  15677. //AcceptFd = -1;
  15678. return 0;
  15679. }
  15680. }
  15681. #endif
  15682. return AcceptFd;
  15683. }
  15684. /*===========================================================================
  15685. FUNCTION: End_Process
  15686. DESCRIPTION:
  15687. PRE-CONDITION:
  15688. 1. <CAUTION> This function could only be used in SeccComm fork2.
  15689. INPUT:
  15690. OUTPUT:
  15691. GLOBAL VARIABLES:
  15692. =============================================================================*/
  15693. int End_Process()
  15694. {
  15695. if(EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  15696. {
  15697. SAVE_SYS_LOG_MSG_EVCOMM("End_Process has been triggered by another event.");
  15698. return -1;
  15699. }
  15700. SAVE_SYS_LOG_MSG_EVCOMM("[End_Process]entering...");
  15701. //STEP 1: Ask CSU to Stop
  15702. EVCOMM_SYS_INFO.End_Process_inused = TRUE;
  15703. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  15704. EVCOMM_SYS_INFO.ConnectorLocked = FALSE;
  15705. ShmInternalComm->ChargingPermission = FALSE;
  15706. //Step 2: Close sockets
  15707. SAVE_SYS_LOG_MSG_EVCOMM("[End_Process]close sockets...");
  15708. if(RawSock > 0)
  15709. {
  15710. close(RawSock);
  15711. }
  15712. if(UdpSock > 0)
  15713. {
  15714. close(UdpSock);
  15715. }
  15716. if(TcpSock > 0)
  15717. {
  15718. close(TcpSock);
  15719. close(TcpAcceptFd);
  15720. }
  15721. RawSock = UdpSock = TcpSock = TcpAcceptFd = -1;
  15722. if(ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp > 0)
  15723. {
  15724. close(ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp);
  15725. ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp=0;
  15726. }
  15727. if(ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp > 0)
  15728. {
  15729. close(ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp);
  15730. ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp=0;
  15731. }
  15732. if(ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp > 0)
  15733. {
  15734. close(ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp);
  15735. close(ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed);
  15736. ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp=0;
  15737. ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed=0;
  15738. }
  15739. /*#ifdef SUPPORT_TLS_CONNECTION
  15740. if(EvSecurity == 0)//support security
  15741. {
  15742. SSL_shutdown(ssl);
  15743. SSL_free (ssl);
  15744. }
  15745. SSL_CTX_free (ctx);
  15746. #endif*/
  15747. //STEP 3: Switch to State E
  15748. //SwitchCpStateE(ENABLE);
  15749. //STEP 4: Close tcpdump
  15750. Sniffer_Tcpdump(DISABLE);
  15751. //STEP 5: Keep 100% PWM for 5 seconds
  15752. OutputCpPwmDuty(100);
  15753. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 5");
  15754. sleep(1);
  15755. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 4");
  15756. sleep(1);
  15757. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 3");
  15758. sleep(1);
  15759. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 2");
  15760. sleep(1);
  15761. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 1");
  15762. sleep(1);
  15763. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 0");
  15764. AttenProfileCnt = 0;
  15765. init_appHandEXIDocument(&ccs_handshake);
  15766. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  15767. {
  15768. SAVE_SYS_LOG_MSG_EVCOMM("[End_Process]1st sync...");
  15769. system("sync");
  15770. }
  15771. #endif
  15772. //STEP 4: Switch to State E
  15773. //Keep State E for 5 seconds
  15774. #if 0
  15775. SwitchCpStateE(ENABLE); //Set PWM Duty as 0 and set State as E (0V)
  15776. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 5");
  15777. sleep(1);
  15778. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 4");
  15779. sleep(1);
  15780. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 3");
  15781. sleep(1);
  15782. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 2");
  15783. sleep(1);
  15784. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 1");
  15785. sleep(1);
  15786. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 0");
  15787. #endif
  15788. //Reset Memory
  15789. unsigned char SlaveAddress_backup;
  15790. unsigned int matched_backup;
  15791. //unsigned char state_backup;
  15792. SAVE_SYS_LOG_MSG_EVCOMM("[CCS Board]soft reset (closing SeccComm)...");
  15793. SAVE_SYS_LOG_MSG_EVCOMM("---------------------------------------------");
  15794. SAVE_SYS_LOG_MSG_EVCOMM("-- EVCOMM: END --");
  15795. SAVE_SYS_LOG_MSG_EVCOMM("-----------------------------------------\n");
  15796. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  15797. {
  15798. SAVE_SYS_LOG_MSG_EVCOMM("[End_Process]2nd sync...");
  15799. system("sync");
  15800. }
  15801. #endif
  15802. // system("sleep 1");
  15803. //Backup CsuComm flags
  15804. SlaveAddress_backup = ShmInternalComm->SlaveAddress;
  15805. matched_backup = CSUCOMMDC_TASK_FLAG.matched;
  15806. //state_backup = Check_V2G_Flow_Status();
  15807. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  15808. memset(V2gtpMsgTxBuf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  15809. memset(&ccs_handshake, 0, sizeof(struct appHandEXIDocument));
  15810. memset(&ccs_exi_doc_DIN, 0, sizeof(struct dinEXIDocument));
  15811. memset(V2GTP_Tx_buf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  15812. memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  15813. memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
  15814. memset(ShmInternalComm, 0, sizeof(struct InternalComm));
  15815. memset(ShmCcsData, 0, sizeof(struct CcsData));
  15816. ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.ChargeProgress= 0xFF;
  15817. //Resume CsuComm flags
  15818. ShmInternalComm->SlaveAddress = SlaveAddress_backup;
  15819. CSUCOMMDC_TASK_FLAG.matched = matched_backup;
  15820. Sniffer_Candump(DISABLE);
  15821. Sniffer_Candump(ENABLE);
  15822. //memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo)); //EVCOMM_SYS_INFO.End_Process_inused = FALSE;
  15823. //EVCOMM_SYS_INFO.End_Process_inused = TRUE;
  15824. EVCOMM_SYS_INFO.DC_EVSEStatus=EVSE_NotReady;
  15825. //Update_V2G_Flow_Status(state_backup);
  15826. //CP_Detection_Pid = 0;
  15827. //PP_Detection_Pid = 0;
  15828. //Error_Monitor_Pid = 0;
  15829. /* while(CheckConnectorPlugIn() != TRUE)
  15830. {
  15831. sleep(1);
  15832. }*/
  15833. free(V2gtpMsgRxBuf);
  15834. free(V2gtpMsgTxBuf);
  15835. //DetachShareMemory();
  15836. Qca7kPowerReset(); //reset QCA7000 /* +++ 20200808, vern, should disconnected PLC connection after session stop ---*/
  15837. system("cd /root;./reset_soft.sh");
  15838. while(1)
  15839. {
  15840. //wait for CSU configrm
  15841. }
  15842. }
  15843. /*===========================================================================
  15844. FUNCTION: Parameters_Init
  15845. DESCRIPTION:
  15846. PRE-CONDITION:
  15847. INPUT:
  15848. OUTPUT:
  15849. GLOBAL VARIABLES:
  15850. =============================================================================*/
  15851. int Parameters_Init()
  15852. {
  15853. //Step 0: Generate random number
  15854. unsigned int value_random;
  15855. struct timeb time_seed;
  15856. ftime(&time_seed);
  15857. srand(time_seed.millitm);
  15858. //Step 1: Init SDP TCP Port
  15859. value_random = rand();
  15860. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active = (unsigned short)(SdpTcpServerPort + (value_random % 10000) + 1);
  15861. if((EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active <= 49152)||(EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active >= 65535))//49152-65535
  15862. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active=59438;
  15863. sprintf(buf_log_evcomm,
  15864. "[Init]TCP Port:OK(%d)",
  15865. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  15866. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15867. //Step 2: Init SessionID
  15868. value_random = rand();
  15869. memcpy(&EVCOMM_SYS_INFO.SessionID[0], &value_random, 4);
  15870. value_random = rand();
  15871. memcpy(&EVCOMM_SYS_INFO.SessionID[4], &value_random, 4);
  15872. sprintf(buf_log_evcomm,
  15873. "[Init]SessionID:OK(%02X%02X%02X%02X%02X%02X%02X%02X)",
  15874. EVCOMM_SYS_INFO.SessionID[0],
  15875. EVCOMM_SYS_INFO.SessionID[1],
  15876. EVCOMM_SYS_INFO.SessionID[2],
  15877. EVCOMM_SYS_INFO.SessionID[3],
  15878. EVCOMM_SYS_INFO.SessionID[4],
  15879. EVCOMM_SYS_INFO.SessionID[5],
  15880. EVCOMM_SYS_INFO.SessionID[6],
  15881. EVCOMM_SYS_INFO.SessionID[7]);
  15882. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15883. }
  15884. #ifdef SUPPORT_TLS_CONNECTION
  15885. SSL_CTX *create_sslcontext()
  15886. {
  15887. const SSL_METHOD *method;
  15888. SSL_CTX *ctx;
  15889. // Support only TLSv1.2
  15890. method = TLSv1_2_server_method();
  15891. // Create context
  15892. ctx = SSL_CTX_new(method);
  15893. if (!ctx)
  15894. {
  15895. ERR_print_errors_fp(stderr);
  15896. return NULL;
  15897. }
  15898. return ctx;
  15899. }
  15900. int configure_sslcertkey_file(SSL_CTX *ctx)
  15901. {
  15902. SSL_CTX_set_ecdh_auto(ctx, 1);
  15903. // Load certificate file
  15904. if (SSL_CTX_use_certificate_file(ctx, "/root/cacert.pem", SSL_FILETYPE_PEM) <= 0)
  15905. {
  15906. ERR_print_errors_fp(stderr);
  15907. return -1;
  15908. }
  15909. // Load private key file
  15910. if (SSL_CTX_use_PrivateKey_file(ctx, "/root/cakey.pem", SSL_FILETYPE_PEM) <= 0 )
  15911. {
  15912. ERR_print_errors_fp(stderr);
  15913. return -1;
  15914. }
  15915. return 0;
  15916. }
  15917. #endif
  15918. /*===========================================================================
  15919. FUNCTION: main
  15920. DESCRIPTION:
  15921. PRE-CONDITION:
  15922. INPUT:
  15923. OUTPUT:
  15924. GLOBAL VARIABLES:
  15925. =============================================================================*/
  15926. int main(int argc, char *argv[])
  15927. {
  15928. unsigned char Rtn;
  15929. //Initialization
  15930. if(ShareMemory_Init()==0)
  15931. {
  15932. system("reboot -f");
  15933. sleep(5);
  15934. system("reboot -f");
  15935. }
  15936. memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
  15937. if(RawSock > 0)
  15938. {
  15939. close(RawSock);
  15940. }
  15941. if(UdpSock > 0)
  15942. {
  15943. close(UdpSock);
  15944. }
  15945. if(TcpSock > 0)
  15946. {
  15947. close(TcpSock);
  15948. }
  15949. RawSock = UdpSock = TcpSock = -1;
  15950. Update_V2G_Flow_Status(IDLE);
  15951. SAVE_SYS_LOG_MSG_EVCOMM("---------------------------------------------");
  15952. SAVE_SYS_LOG_MSG_EVCOMM("-- EVCOMM: START --");
  15953. SAVE_SYS_LOG_MSG_EVCOMM("---------------------------------------------\n");
  15954. //Print Linux Kernel Version
  15955. sprintf(buf_log_evcomm, "\nLinux Image SHA1: %s\n", LINUX_IMAGE_VERSION);
  15956. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15957. //Print Hardware Version
  15958. sprintf(buf_log_evcomm, "HW: %s\n", HARDWARE_VERSION);
  15959. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15960. //Print Firmware Version
  15961. sprintf(buf_log_evcomm, "FW: %s\n", FIRMWARE_VERSION);
  15962. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15963. SAVE_SYS_LOG_MSG_EVCOMM("init...");
  15964. //Init V2G TCP/IPv6 packets buffer
  15965. V2gtpMsgRxBuf = (unsigned char *)malloc(V2GTP_MSG_RX_BUFFER_SIZE);
  15966. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  15967. V2gtpMsgTxBuf = (unsigned char *)malloc(V2GTP_MSG_TX_BUFFER_SIZE);
  15968. memset(V2gtpMsgTxBuf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  15969. //Release State E Control
  15970. SwitchCpStateE(DISABLE);
  15971. OutputCpPwmDuty(100);
  15972. //start to detect CP pilot state
  15973. CP_Detection_Pid = 0;
  15974. CP_Detection(); //fork1
  15975. SAVE_SYS_LOG_MSG_EVCOMM("[fork1]CP Detection: ON");
  15976. //start to detect errors
  15977. Error_Monitor(); //fork2
  15978. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Error Monitor: ON");
  15979. //CCS connector type
  15980. sprintf(buf_log_evcomm, "CCS connector type : %s\n", ShmInternalComm->CCSConnectorType > 0? "CCS2":"CCS1" );
  15981. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  15982. //start to detect PP
  15983. PP_Detection_Pid = 0;
  15984. #if (PP_PROTECTION_MECHANISM == ENABLE)
  15985. PP_Detection();
  15986. SAVE_SYS_LOG_MSG_EVCOMM("[fork3]PP Detection: ON");
  15987. #else
  15988. SAVE_SYS_LOG_MSG_EVCOMM("[fork3]PP Detection: OFF");
  15989. #endif
  15990. //Init communication parameters
  15991. GetEthMac(QcaInterface, CsuMac);
  15992. AttenProfileCnt = 0;
  15993. init_appHandEXIDocument(&ccs_handshake);
  15994. //Init Energy transfer mode
  15995. //[To-Do] Parsing Model Name
  15996. ShmCcsData->EnergyTransferMode = CCS_ENERGY_TRANSFER_MODE;
  15997. struct ChargingInfoData *ccs;
  15998. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  15999. Parameters_Init();
  16000. Sniffer_Tcpdump(ENABLE);
  16001. #if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  16002. sleep(1); //wait for tcpdump getting ready
  16003. #endif
  16004. #ifdef SUPPORT_TLS_CONNECTION
  16005. // SSL init
  16006. //SSL_free (ssl);
  16007. //SSL_CTX_free (ctx);
  16008. SSL_load_error_strings();
  16009. OpenSSL_add_ssl_algorithms();
  16010. // Create SSL_CTX
  16011. ctx = create_sslcontext();
  16012. if (ctx == NULL)
  16013. {
  16014. SAVE_SYS_LOG_MSG_EVCOMM("[SSL]create_sslcontext Failed");
  16015. }
  16016. else
  16017. SAVE_SYS_LOG_MSG_EVCOMM("[SSL]create_sslcontext OK");
  16018. // Configure cert and key
  16019. if (configure_sslcertkey_file(ctx) < 0)
  16020. {
  16021. SAVE_SYS_LOG_MSG_EVCOMM("[SSL]configure_sslcertkey_file Failed");
  16022. }
  16023. else
  16024. SAVE_SYS_LOG_MSG_EVCOMM("[SSL]configure_sslcertkey_file OK");
  16025. #endif
  16026. SAVE_SYS_LOG_MSG_EVCOMM("[Init]DONE");
  16027. while(1)
  16028. {
  16029. //DEBUG_PRINTF_EVCOMM_DETAIL("\nV2gFlowStatus = %d\n", V2gFlowStatus);
  16030. //if((ShmInternalComm->ChargingPermission == 0x01) && (CheckConnectorPlugIn() == 1))
  16031. //if((CheckConnectorPlugIn() == TRUE) && (ShmInternalComm->ChargingPermission == TRUE))
  16032. //if(ShmInternalComm->ChargingPermission == 0x01)
  16033. //if(CheckConnectorPlugIn() == TRUE)
  16034. if (EVCOMM_SYS_INFO.End_Process_inused == FALSE)
  16035. {
  16036. if(V2gFlowStatus < SLACC_SDP_UDP_Connection)
  16037. {
  16038. SlacComm();
  16039. }
  16040. else if(V2gFlowStatus == SLACC_SDP_UDP_Connection)
  16041. {
  16042. if(SdpUdpConnected() == 1)
  16043. {
  16044. Update_V2G_Flow_Status(SLACC_SDP_TCP_Connection);
  16045. continue;
  16046. }
  16047. SlacComm(); //TC_SECC_VTB_CmSlacMatch_004
  16048. ftime(&SeqEndTime);
  16049. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_join)
  16050. {
  16051. sprintf(buf_log_evcomm,
  16052. "Wait SLACC_SDP_UDP_Connection Timeout - TT_match_join (%.02lf of %d ms)\n",
  16053. DiffTimeb(SeqStartTime, SeqEndTime),
  16054. TT_match_join);
  16055. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  16056. Update_V2G_Flow_Status(Sequence_Timeout);
  16057. //Update_ShmStatusCode(); //[To-Do] to be implemented
  16058. //CCS_SECC_TIMEOUT_SLACC_SDP_UDP_TT_match_join (023823)
  16059. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  16060. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  16061. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  16062. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  16063. ShmStatusCodeData->PresentStatusCode[0][4] = 2;
  16064. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  16065. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  16066. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  16067. }
  16068. }
  16069. else if(V2gFlowStatus == SLACC_SDP_TCP_Connection)
  16070. {
  16071. if((TcpAcceptFd = V2gTcpConnected()) > 0)
  16072. {
  16073. Update_V2G_Flow_Status(SupportedAppProtocolRequest);
  16074. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  16075. continue;
  16076. }
  16077. SlacComm();
  16078. ftime(&SeqEndTime);
  16079. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_join)
  16080. {
  16081. sprintf(buf_log_evcomm,
  16082. "Wait SLACC_SDP_TCP_Connection Timeout - TT_match_join (%.02lf / %d ms)",
  16083. DiffTimeb(SeqStartTime, SeqEndTime),
  16084. TT_match_join);
  16085. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  16086. Update_V2G_Flow_Status(Sequence_Timeout);
  16087. //Update_ShmStatusCode(); //[To-Do] to be implemented
  16088. //CCS_SECC_TIMEOUT_SLACC_SDP_TCP_TT_match_join (023824)
  16089. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  16090. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  16091. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  16092. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  16093. ShmStatusCodeData->PresentStatusCode[0][4] = 2;
  16094. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  16095. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  16096. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  16097. }
  16098. }
  16099. else if(V2gFlowStatus <= SessionStopResponse)
  16100. {
  16101. if (V2gComm(TcpAcceptFd) < 0)
  16102. {
  16103. //error occours
  16104. }
  16105. if(V2gFlowStatus == SessionStopResponse)
  16106. {
  16107. if(RawSock > 0)
  16108. {
  16109. close(RawSock);
  16110. }
  16111. if(UdpSock > 0)
  16112. {
  16113. close(UdpSock);
  16114. }
  16115. if(TcpSock > 0)
  16116. {
  16117. close(TcpSock);
  16118. close(TcpAcceptFd);
  16119. }
  16120. RawSock = UdpSock = TcpSock = TcpAcceptFd = -1;
  16121. #ifdef SUPPORT_TLS_CONNECTION
  16122. if(EvSecurity == 0)//support security
  16123. {
  16124. SSL_shutdown(ssl);
  16125. SSL_free (ssl);
  16126. }
  16127. SSL_CTX_free (ctx);
  16128. #endif
  16129. }
  16130. }
  16131. else if (V2gFlowStatus >= Performance_Timeout)
  16132. {
  16133. //End_Process
  16134. if(RawSock > 0)
  16135. {
  16136. close(RawSock);
  16137. }
  16138. if(UdpSock > 0)
  16139. {
  16140. close(UdpSock);
  16141. }
  16142. if(TcpSock > 0)
  16143. {
  16144. close(TcpSock);
  16145. close(TcpAcceptFd);
  16146. }
  16147. RawSock = UdpSock = TcpSock = TcpAcceptFd = -1;
  16148. #ifdef SUPPORT_TLS_CONNECTION
  16149. if(EvSecurity == 0)//support security
  16150. {
  16151. SSL_shutdown(ssl);
  16152. SSL_free (ssl);
  16153. }
  16154. SSL_CTX_free (ctx);
  16155. #endif
  16156. }
  16157. else
  16158. {
  16159. //null
  16160. }
  16161. }
  16162. // printf("V2gFlowStatus=%d, socket=%d,%d,%d\n",V2gFlowStatus,RawSock,UdpSock,TcpSock);
  16163. } //while
  16164. }//main while