SeccComm.c 652 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354
  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 "define.h"
  36. #include "SeccComm.h"
  37. #include "NidNmk.h"
  38. #include "SeccComm.h"
  39. #include "CsuComm.h"
  40. #include "./exi_engine/api/api.h"
  41. #include "./exi_engine/appHandshake/appHandEXIDatatypes.h"
  42. #include "./exi_engine/transport/v2gtp.h"
  43. int MeterSMId[8];
  44. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  45. struct StatusCodeData *ShmStatusCodeData;
  46. struct CcsData *ShmCcsData;
  47. struct InternalComm *ShmInternalComm;
  48. struct InternalCommAC *ShmInternalCommAC;
  49. struct appHandEXIDocument ccs_handshake;
  50. struct dinEXIDocument ccs_exi_doc_DIN;
  51. struct iso1EXIDocument ccs_exi_doc_ISO1;
  52. struct iso2EXIDocument ccs_exi_doc_ISO2;
  53. unsigned char V2GTP_Tx_buf[V2GTP_MSG_TX_BUFFER_SIZE]; //64*1024 ﺿ65,536 = 65.5KB
  54. unsigned char buf_log_evcomm[SIZE_OF_LOG_BUFFER];
  55. unsigned char buf_log_evcomm_fork1[SIZE_OF_LOG_BUFFER];
  56. unsigned char buf_log_evcomm_fork2[SIZE_OF_LOG_BUFFER];
  57. unsigned char buf_log_evcomm_fork3[SIZE_OF_LOG_BUFFER];
  58. pid_t CP_Detection_Pid = 0;
  59. pid_t PP_Detection_Pid = 0;
  60. pid_t Error_Monitor_Pid = 0;
  61. int TcpAcceptFd;
  62. enum MsgFlowStatus V2gFlowStatus;
  63. int RawSock,UdpSock,TcpSock;
  64. unsigned char *V2gtpMsgRxBuf, *V2gtpMsgTxBuf;
  65. unsigned short Aag[64];
  66. struct MmeHeader SendMmePacket;
  67. int SendMmePacketSize;
  68. unsigned char CsuMac[6],QcaMac[6],EvMac[6],SlacRunId[8];
  69. struct sockaddr_ll DestSocketAddress;
  70. struct ifreq Req;
  71. unsigned int PwmStartTime;
  72. struct timeb SeqStartTime, SeqEndTime;
  73. unsigned char AagGroupsNum, MnbcSoundNum, AttenProfileCnt;
  74. unsigned char NewNmkKey[16], Nid[7];
  75. /*===========================================================================
  76. FUNCTION: Check_V2G_Flow_Status
  77. DESCRIPTION:
  78. PRE-CONDITION:
  79. INPUT:
  80. OUTPUT:
  81. GLOBAL VARIABLES:
  82. =============================================================================*/
  83. unsigned char Check_V2G_Flow_Status()
  84. {
  85. unsigned char result = 0;
  86. switch (ShmCcsData->CommProtocol)
  87. {
  88. case V2GT_MSG_PROTOCOL_DIN70121: //0
  89. {
  90. result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
  91. break;
  92. }
  93. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  94. {
  95. result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
  96. break;
  97. }
  98. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  99. {
  100. result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
  101. break;
  102. }
  103. default:
  104. break;
  105. }
  106. return result;
  107. }
  108. /*===========================================================================
  109. FUNCTION: StoreLogMsg
  110. DESCRIPTION:
  111. PRE-CONDITION:
  112. INPUT:
  113. OUTPUT:
  114. GLOBAL VARIABLES:
  115. =============================================================================*/
  116. #if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  117. int StoreLogMsg(unsigned char *DataString)
  118. {
  119. static unsigned char Buf[1024];
  120. static time_t CurrentTime;
  121. static struct tm *tm;
  122. static struct timeval tv;
  123. memset(Buf, 0, sizeof(Buf));
  124. CurrentTime = time(NULL);
  125. tm = localtime(&CurrentTime);
  126. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  127. sprintf(Buf, "echo \"[%04d%02d%02d: %02d:%02d:%02d.%06d][SECC][%d][%02d]%s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  128. tm->tm_year + 1900,
  129. tm->tm_mon + 1,
  130. tm->tm_mday,
  131. tm->tm_hour,
  132. tm->tm_min,
  133. tm->tm_sec,
  134. tv.tv_usec,
  135. EVCOMM_SYS_INFO.CpState,
  136. Check_V2G_Flow_Status(),
  137. DataString,
  138. tm->tm_year + 1900,
  139. tm->tm_mon + 1);
  140. system(Buf);
  141. DEBUG_PRINTF_EVCOMM_SYSTEM_LOG("[%02d:%02d:%02d.%06d][SECC][%d][%02d]%s \n",
  142. tm->tm_hour,
  143. tm->tm_min,
  144. tm->tm_sec,
  145. tv.tv_usec,
  146. EVCOMM_SYS_INFO.CpState,
  147. Check_V2G_Flow_Status(),
  148. DataString);
  149. //Reset the buf_log_evcomm Buffer, i.e. DataString
  150. memset(buf_log_evcomm, 0, SIZE_OF_LOG_BUFFER);
  151. }
  152. #endif
  153. /*===========================================================================
  154. FUNCTION: CAN_Tx_MSG
  155. DESCRIPTION:
  156. PRE-CONDITION:
  157. INPUT:
  158. OUTPUT:
  159. GLOBAL VARIABLES:
  160. =============================================================================*/
  161. int CAN_Tx_MSG(int Fd, unsigned int MsgId, unsigned char SlaveAddress, unsigned char DataLength, unsigned char *SendData)
  162. {
  163. struct can_frame frame;
  164. struct timeb StartTime, EndTime;
  165. unsigned int tmp = 0;
  166. int nbytes = 0;
  167. int i = 0;
  168. //Protection: To avoid unexpected length for CAN bus payload.
  169. if (DataLength > 8)
  170. {
  171. DataLength = 8;
  172. }
  173. memset(&frame, 0, sizeof(struct can_frame));
  174. frame.can_id = 0x80000000 | CAN_SEND_DIRECTION | MsgId | SlaveAddress; //0x80000000: extension ID format
  175. frame.can_dlc = DataLength;
  176. memcpy(frame.data, SendData, DataLength);
  177. nbytes = write(Fd, &frame, sizeof(struct can_frame));
  178. #if 0
  179. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][CAN_Tx_MSG] <%X> ", frame.can_id);
  180. for (i = 0; i < frame.can_dlc; i++)
  181. {
  182. DEBUG_PRINTF_EVCOMM_DETAIL("%02X ", frame.data[i]);
  183. }
  184. DEBUG_PRINTF_EVCOMM_DETAIL("(%d Bytes)\n", frame.can_dlc);
  185. #endif
  186. return nbytes;
  187. }
  188. /*===========================================================================
  189. FUNCTION: Proc_EVStopRes
  190. DESCRIPTION:
  191. PRE-CONDITION:
  192. INPUT:
  193. OUTPUT:
  194. GLOBAL VARIABLES:
  195. =============================================================================*/
  196. int Proc_EVStopRes(int Fd)
  197. {
  198. int nbytes;
  199. unsigned char Buffer[8];
  200. memset(Buffer, 0, sizeof(Buffer));
  201. if (CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency == TRUE)
  202. {
  203. Buffer[0] = EV_EMERGENCY_STOP; //2
  204. }
  205. else
  206. {
  207. Buffer[0] = EV_NORMAL_STOP; //1
  208. }
  209. /*
  210. if(strlen(ShmStatusCodeData->PresentStatusCode[0]) > 0)
  211. {
  212. memcpy(Buffer + 2, ShmStatusCodeData->PresentStatusCode[0], 6);
  213. }
  214. */
  215. Buffer[1] = ShmStatusCodeData->PresentStatusCode[0][0];
  216. Buffer[2] = ShmStatusCodeData->PresentStatusCode[0][1];
  217. Buffer[3] = ShmStatusCodeData->PresentStatusCode[0][2];
  218. Buffer[4] = ShmStatusCodeData->PresentStatusCode[0][3];
  219. Buffer[5] = ShmStatusCodeData->PresentStatusCode[0][4];
  220. Buffer[6] = ShmStatusCodeData->PresentStatusCode[0][5];
  221. nbytes = CAN_Tx_MSG(Fd, CAN_CMD_EV_STOP_EVENT, ShmInternalComm->SlaveAddress, 7, Buffer);
  222. //system("echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle"); //for test only
  223. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  224. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_EVStopRes] Sending STOP Command to CSU");
  225. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = FALSE;
  226. return nbytes;
  227. }
  228. /*===========================================================================
  229. FUNCTION: Sniffer_Candump
  230. DESCRIPTION:
  231. 1. Only used in End_Process(), which is in fork2 of SeccComm task.
  232. PRE-CONDITION:
  233. INPUT:
  234. OUTPUT:
  235. 0: accept
  236. -1: invalid
  237. GLOBAL VARIABLES:
  238. =============================================================================*/
  239. int Sniffer_Candump(char cmd)
  240. {
  241. #if (CANDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  242. if (cmd == ENABLE)
  243. {
  244. SAVE_SYS_LOG_MSG_EVCOMM("[candump]init");
  245. system("cd /mnt/;rm -rf candump/");
  246. system("cd /mnt/;mkdir candump");
  247. SAVE_SYS_LOG_MSG_EVCOMM("[candump]on");
  248. system("cd /mnt/candump;candump -l can0 &");
  249. return 0;
  250. }
  251. else if (cmd == DISABLE)
  252. {
  253. SAVE_SYS_LOG_MSG_EVCOMM("[candump]off");
  254. system("killall candump");
  255. SAVE_SYS_LOG_MSG_EVCOMM("[candump]save");
  256. system("cd /;cp -rfv /mnt/candump /Storage/SystemLog/");
  257. return 0;
  258. }
  259. else
  260. {
  261. sprintf(buf_log_evcomm_fork2, "[candump]unexpected cmd(%d)", cmd);
  262. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  263. return -1;
  264. }
  265. #endif
  266. }
  267. /*===========================================================================
  268. FUNCTION: Sniffer_Tcpdump
  269. DESCRIPTION:
  270. PRE-CONDITION:
  271. INPUT:
  272. OUTPUT:
  273. GLOBAL VARIABLES:
  274. =============================================================================*/
  275. int Sniffer_Tcpdump(char cmd)
  276. {
  277. #if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  278. if (cmd == ENABLE)
  279. {
  280. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]init...");
  281. system("cd /mnt/;rm -rf tcpdump/");
  282. system("cd /mnt/;mkdir tcpdump");
  283. unsigned char buf[256];
  284. time_t CurrentTime;
  285. struct tm *tm;
  286. struct timeval tv;
  287. memset(buf, 0, sizeof(buf));
  288. CurrentTime = time(NULL);
  289. tm = localtime(&CurrentTime);
  290. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  291. sprintf(buf,
  292. "tcpdump -i eth1 -w /mnt/tcpdump/[%s][%04d%02d%02d-%02d:%02d:%02d.%06d]packets.pcap&",
  293. FIRMWARE_VERSION,
  294. tm->tm_year + 1900,
  295. tm->tm_mon + 1,
  296. tm->tm_mday,
  297. tm->tm_hour,
  298. tm->tm_min,
  299. tm->tm_sec,
  300. tv.tv_usec
  301. );
  302. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]on");
  303. system(buf);
  304. return 0;
  305. }
  306. else if (cmd == DISABLE)
  307. {
  308. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]off");
  309. system("killall tcpdump");
  310. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]wait: 2s");
  311. sleep(1);
  312. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]wait: 1s");
  313. sleep(1);
  314. SAVE_SYS_LOG_MSG_EVCOMM("[tcpdump]save");
  315. system("cd /;cp -rfv /mnt/tcpdump /Storage/SystemLog/");
  316. return 0;
  317. }
  318. else
  319. {
  320. sprintf(buf_log_evcomm, "[tcpdump]unexpected cmd(%d)", cmd);
  321. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  322. return -1;
  323. }
  324. #endif
  325. }
  326. /*===========================================================================
  327. FUNCTION: Check_V2G_Flow_Status_pre
  328. DESCRIPTION:
  329. PRE-CONDITION:
  330. INPUT:
  331. OUTPUT:
  332. GLOBAL VARIABLES:
  333. =============================================================================*/
  334. unsigned char Check_V2G_Flow_Status_pre()
  335. {
  336. unsigned char result = 0;
  337. switch (ShmCcsData->CommProtocol)
  338. {
  339. case V2GT_MSG_PROTOCOL_DIN70121: //0
  340. {
  341. result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus_pre;
  342. break;
  343. }
  344. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  345. {
  346. result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus_pre;
  347. break;
  348. }
  349. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  350. {
  351. result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus_pre;
  352. break;
  353. }
  354. default:
  355. break;
  356. }
  357. return result;
  358. }
  359. /*===========================================================================
  360. FUNCTION: Update_V2G_Flow_Status
  361. DESCRIPTION:
  362. PRE-CONDITION:
  363. INPUT:
  364. OUTPUT:
  365. 1. V2gFlowStatus
  366. GLOBAL VARIABLES:
  367. 1. V2gFlowStatus
  368. =============================================================================*/
  369. int Update_V2G_Flow_Status(unsigned int state_new)
  370. {
  371. unsigned char state_now;
  372. state_now = Check_V2G_Flow_Status();
  373. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE ||
  374. CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused == TRUE)
  375. {
  376. if (state_now != Performance_Timeout && //253
  377. state_now != Sequence_Timeout && //254
  378. state_now != Other_Fault) //255
  379. {
  380. sprintf(buf_log_evcomm,
  381. "[Warning]state(%d) change: ignored (End_Process_inused:%d, FW_Update_Task_inused:%d)",
  382. state_new,
  383. EVCOMM_SYS_INFO.End_Process_inused,
  384. CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused
  385. );
  386. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  387. return -1;
  388. }
  389. }
  390. if (state_now != state_new)
  391. {
  392. //Step 1: Check if Error Occours
  393. if (state_now == Performance_Timeout || //253
  394. state_now == Sequence_Timeout || //254
  395. state_now == Other_Fault) //255
  396. {
  397. if (state_new != IDLE)
  398. {
  399. if (EVCOMM_SYS_INFO.State_Change_Ignored_Notice == FALSE)
  400. {
  401. EVCOMM_SYS_INFO.State_Change_Ignored_Notice = TRUE;
  402. sprintf(buf_log_evcomm,
  403. "[Warning]state(%d) change: ignored(now in error state)",
  404. state_new,
  405. state_now);
  406. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  407. }
  408. return -1;
  409. }
  410. }
  411. //Updating the state formally.
  412. sprintf(buf_log_evcomm,
  413. "[stt]%02d >> %02d",
  414. state_now,
  415. state_new
  416. );
  417. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  418. V2gFlowStatus = state_new;
  419. state_now = state_new;
  420. switch (ShmCcsData->CommProtocol)
  421. {
  422. case V2GT_MSG_PROTOCOL_DIN70121: //0
  423. {
  424. ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
  425. ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus = V2gFlowStatus;
  426. //break;
  427. }
  428. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  429. {
  430. ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
  431. ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus = V2gFlowStatus;
  432. //break;
  433. }
  434. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  435. {
  436. ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
  437. ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus = V2gFlowStatus;
  438. //break;
  439. }
  440. default:
  441. break;
  442. }
  443. }
  444. }
  445. double DiffTimeb(struct timeb ST, struct timeb ET)
  446. {
  447. //return milli-second
  448. double StartTime, EndTime;
  449. double t_diff;
  450. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  451. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  452. t_diff = EndTime - StartTime;
  453. if (t_diff < 0)
  454. {
  455. #if 0
  456. if (t_diff < -1000) //1000ms
  457. {
  458. sprintf(buf_log_evcomm,
  459. "[Warning]StartTime(%.02lf) > EndTime(%.02lf), d(%.02lf)",
  460. StartTime,
  461. EndTime,
  462. t_diff);
  463. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  464. }
  465. #endif
  466. return -1;
  467. }
  468. return t_diff;
  469. }
  470. double DiffTimeb_fork1_Error_Monitor(struct timeb ST, struct timeb ET)
  471. {
  472. //return milli-second
  473. static double StartTime, EndTime;
  474. static double t_diff;
  475. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  476. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  477. t_diff = EndTime - StartTime;
  478. if (t_diff < 0)
  479. {
  480. #if 0
  481. if (t_diff < -1000) //1000ms
  482. {
  483. sprintf(buf_log_evcomm_fork2,
  484. "[fork1][Warning]S(%.02lf) > E(%.02lf), d(%.02lf)",
  485. StartTime,
  486. EndTime,
  487. t_diff);
  488. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  489. }
  490. #endif
  491. return -1;
  492. }
  493. return t_diff;
  494. }
  495. double DiffTimeb_fork2_Error_Monitor(struct timeb ST, struct timeb ET)
  496. {
  497. //return milli-second
  498. static double StartTime, EndTime;
  499. static double t_diff;
  500. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  501. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  502. t_diff = EndTime - StartTime;
  503. if (t_diff < 0)
  504. {
  505. #if 0
  506. if (t_diff < -1000) //1000ms
  507. {
  508. sprintf(buf_log_evcomm_fork2,
  509. "[fork2][Warning]S(%.02lf) > E(%.02lf), d(%.02lf)",
  510. StartTime,
  511. EndTime,
  512. t_diff);
  513. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  514. }
  515. #endif
  516. return -1;
  517. }
  518. return t_diff;
  519. }
  520. int CreateShareMemory()
  521. {
  522. int MeterSMId;
  523. //create ShmSysConfigAndInfo
  524. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
  525. {
  526. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmget ShmSysConfigAndInfo NG");
  527. return 0;
  528. }
  529. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  530. {
  531. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmat ShmSysConfigAndInfo NG");
  532. return 0;
  533. }
  534. memset(ShmSysConfigAndInfo,0,sizeof(struct SysConfigAndInfo));
  535. //create ShmStatusCodeData
  536. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
  537. {
  538. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmget ShmStatusCodeData NG");
  539. return 0;
  540. }
  541. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  542. {
  543. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmat ShmStatusCodeData NG");
  544. return 0;
  545. }
  546. memset(ShmStatusCodeData,0,sizeof(struct StatusCodeData));
  547. //create ShmCcsData
  548. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
  549. {
  550. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmget ShmCcsData NG");
  551. return 0;
  552. }
  553. else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  554. {
  555. SAVE_SYS_LOG_MSG_EVCOMM("[main]CreateShareMemory:shmat ShmCcsData NG");
  556. return 0;
  557. }
  558. memset(ShmCcsData,0,sizeof(struct CcsData));
  559. return 1;
  560. }
  561. void DetachShareMemory()
  562. {
  563. if(MeterSMId[0]>0)
  564. {
  565. shmdt(ShmSysConfigAndInfo);
  566. shmctl(MeterSMId[0], IPC_RMID, 0);
  567. }
  568. if(MeterSMId[1]>0)
  569. {
  570. shmdt(ShmStatusCodeData);
  571. shmctl(MeterSMId[1], IPC_RMID, 0);
  572. }
  573. if(MeterSMId[2]>0)
  574. {
  575. shmdt(ShmCcsData);
  576. shmctl(MeterSMId[2], IPC_RMID, 0);
  577. }
  578. if(MeterSMId[3]>0)
  579. {
  580. shmdt(ShmInternalComm);
  581. shmctl(MeterSMId[3], IPC_RMID, 0);
  582. }
  583. if(MeterSMId[4]>0)
  584. {
  585. shmdt(ShmInternalCommAC);
  586. shmctl(MeterSMId[4], IPC_RMID, 0);
  587. }
  588. }
  589. /*===========================================================================
  590. FUNCTION: ShareMemory_Init
  591. DESCRIPTION:
  592. PRE-CONDITION:
  593. INPUT:
  594. OUTPUT:
  595. GLOBAL VARIABLES:
  596. =============================================================================*/
  597. int ShareMemory_Init()
  598. {
  599. memset(MeterSMId,0,sizeof(MeterSMId));
  600. //create ShmSysConfigAndInfo
  601. if ((MeterSMId[0] = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  602. {
  603. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmget ShmSysConfigAndInfo NG");
  604. return 0;
  605. }
  606. else if ((ShmSysConfigAndInfo = shmat(MeterSMId[0], NULL, 0)) == (void *) -1)
  607. {
  608. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmat ShmSysConfigAndInfo NG");
  609. return 0;
  610. }
  611. //create ShmStatusCodeData
  612. if ((MeterSMId[1] = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  613. {
  614. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmget ShmStatusCodeData NG");
  615. return 0;
  616. }
  617. else if ((ShmStatusCodeData = shmat(MeterSMId[1], NULL, 0)) == (void *) -1)
  618. {
  619. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmat ShmStatusCodeData NG");
  620. return 0;
  621. }
  622. //create ShmCcsData
  623. if ((MeterSMId[2] = shmget(ShmCcsCommKey, sizeof(struct CcsData), 0777)) < 0)
  624. {
  625. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmget ShmCcsData NG");
  626. return 0;
  627. }
  628. else if ((ShmCcsData = shmat(MeterSMId[2], NULL, 0)) == (void *) -1)
  629. {
  630. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmat ShmCcsData NG");
  631. return 0;
  632. }
  633. //create ShmInternalComm
  634. if ((MeterSMId[3] = shmget(ShmInternalCommKey, sizeof(struct InternalComm), 0777)) < 0)
  635. {
  636. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmget ShmInternalComm NG");
  637. return 0;
  638. }
  639. else if ((ShmInternalComm = shmat(MeterSMId[3], NULL, 0)) == (void *) -1)
  640. {
  641. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmat ShmInternalComm NG");
  642. return 0;
  643. }
  644. //create ShmInternalCommAC
  645. if ((MeterSMId[4] = shmget(ShmInternalCommACKey, sizeof(struct InternalCommAC), 0777)) < 0)
  646. {
  647. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmget ShmInternalCommAC NG");
  648. return 0;
  649. }
  650. else if ((ShmInternalCommAC = shmat(MeterSMId[4], NULL, 0)) == (void *) -1)
  651. {
  652. SAVE_SYS_LOG_MSG_EVCOMM("ShareMemory_Init:shmat ShmInternalCommAC NG");
  653. return 0;
  654. }
  655. //[To-Do] The initialization here is reduntant and should be removed partially.
  656. //SHM_Init_supportedAppProtocolRes(ShmCcsData);
  657. //SHM_Init_din_SessionSetupRes(ShmCcsData);
  658. //SHM_Init_din_ServiceDiscoveryRes(ShmCcsData);
  659. //SHM_Init_din_ServiceAndPaymentSelectionRes(ShmCcsData);
  660. //SHM_Init_din_ContractAuthenticationRes(ShmCcsData);
  661. SHM_Init_din_ChargeParameterDiscoveryRes(ShmCcsData);
  662. SHM_Init_din_CableCheckRes(ShmCcsData);
  663. SHM_Init_din_PreChargeRes(ShmCcsData);
  664. SHM_Init_din_PowerDeliveryRes(ShmCcsData);
  665. SHM_Init_din_CurrentDemandRes(ShmCcsData);
  666. SHM_Init_din_WeldingDetectionRes(ShmCcsData);
  667. SHM_Init_din_SessionStopRes(ShmCcsData);
  668. return 1;
  669. }
  670. /*===========================================================================
  671. FUNCTION: GetEthMac
  672. DESCRIPTION:
  673. 1. Accessing current CsuMac address, if Eth = eth1
  674. 2. The address of eth1(for QCA7000) is a random number, which will be modified
  675. after each time of booting up system.
  676. PRE-CONDITION:
  677. INPUT:
  678. OUTPUT:
  679. GLOBAL VARIABLES:
  680. =============================================================================*/
  681. int GetEthMac(unsigned char *Eth, unsigned char *mac)
  682. {
  683. //Parameters:MAC,IP,Mask,Gateway
  684. int fd, rd = 0;
  685. unsigned char addr[18], Buffer[128];
  686. memset(Buffer, 0, sizeof(Buffer));
  687. sprintf(Buffer, "cat /sys/class/net/%s/address > /mnt/GetEthInfo", Eth); //CsuMac (Eth = eth1)
  688. system(Buffer);
  689. fd = open("/mnt/GetEthInfo", O_RDONLY);
  690. if(fd < 0)
  691. {
  692. system("rm -f /mnt/GetEthInfo");
  693. SAVE_SYS_LOG_MSG_EVCOMM("GetEthMac: MAC Address open error");
  694. return 0;
  695. }
  696. memset(mac, 0, 6);
  697. memset(addr, 0, sizeof(addr));
  698. rd = read(fd, addr, 17);
  699. close(fd);
  700. system("rm -f /mnt/GetEthInfo");
  701. sscanf(addr, "%02x:%02x:%02x:%02x:%02x:%02x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); //CsuMac (Eth = eth1)
  702. sprintf(buf_log_evcomm,
  703. "[GetEthMac]EVSE MACAddr(CsuMac): %02x:%02x:%02x:%02x:%02x:%02x",
  704. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); //CsuMac (Eth = eth1)
  705. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  706. return 1;
  707. }
  708. /*===========================================================================
  709. FUNCTION: ReadAdcVolt
  710. DESCRIPTION:
  711. 1. fork1
  712. PRE-CONDITION:
  713. INPUT:
  714. OUTPUT:
  715. GLOBAL VARIABLES:
  716. =============================================================================*/
  717. float ReadAdcVolt(unsigned char AdcChannel)
  718. {
  719. //AIN0=CCS GUN Temp 1
  720. //AIN1=CCS GUN Temp 2
  721. //AIN2=CCS_Proximity/2
  722. //AIN3=pilot voltage
  723. if(AdcChannel == 3)
  724. {
  725. int fd,count,AvgTimes;
  726. unsigned char SampleBuf[4];
  727. float TmpVolt, MinSample, AvgSample = 0;
  728. fd = open("/sys/bus/iio/devices/iio\:device0/in_voltage3_raw", O_RDONLY);
  729. if(fd > 0)
  730. {
  731. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  732. for(AvgTimes = 0; AvgTimes < 3; AvgTimes++) //period = 60~91 ms(renice -10, , CurrentDemand()) /*+++ 20200909, vern, extend detection time for interference ---*/
  733. {
  734. count = 0;
  735. MinSample = 2306;
  736. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  737. while(count < 40) //period = 21~42ms (renice -10, CurrentDemand())/*+++ 20200909, vern, extend detection time for interference ---*/
  738. {
  739. //re-sampling period = 3~13ms (renice -10, SLAC())
  740. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  741. read(fd, SampleBuf, 4); //period = 3.2~10ms (renice -10, SLAC())
  742. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  743. TmpVolt = atoi(SampleBuf);
  744. if((TmpVolt < 2306) && (TmpVolt > 0))//positive voltage
  745. {
  746. if(TmpVolt < MinSample)
  747. {
  748. MinSample = TmpVolt;
  749. }
  750. count++;
  751. }
  752. lseek(fd, 0, SEEK_SET);
  753. }
  754. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  755. AvgSample += MinSample;
  756. }
  757. AvgSample /= AvgTimes;
  758. close(fd);
  759. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  760. return ((0.954-(1.8*AvgSample/4095))/0.06);
  761. }
  762. else
  763. {
  764. return -1;
  765. }
  766. }
  767. else
  768. {
  769. FILE *fp;
  770. unsigned char str[64];
  771. unsigned char AdcValue[8];
  772. if(AdcChannel > 7)
  773. {
  774. return -1;
  775. }
  776. memset(str,0,sizeof(str));
  777. memset(AdcValue,0,sizeof(AdcValue));
  778. sprintf(str, "cat /sys/bus/iio/devices/iio\\:device0/in_voltage%d_raw", AdcChannel);
  779. fp=popen(str, "r");
  780. if(fgets(AdcValue,sizeof(AdcValue),fp) == NULL)
  781. {
  782. pclose(fp);
  783. return -1;
  784. }
  785. pclose(fp);
  786. //Vin = Vref *D / (2^n - 1)
  787. return ((float)1.8*(float)atoi(AdcValue))/4095;
  788. }
  789. }
  790. /*===========================================================================
  791. FUNCTION: ReadAdcVolt
  792. DESCRIPTION:
  793. //AIN0=CCS GUN Temp 1
  794. //AIN1=CCS GUN Temp 2
  795. //AIN2=CCS_Proximity/2
  796. //AIN3=pilot voltage
  797. PRE-CONDITION:
  798. INPUT:
  799. OUTPUT:
  800. GLOBAL VARIABLES:
  801. =============================================================================*/
  802. float ReadAdcVolt_PP_fork3()
  803. {
  804. int fd, AvgTimes;
  805. unsigned char SampleBuf[4];
  806. float TmpVolt = 0;
  807. float AvgSample = 0;
  808. float V_pp = 0;
  809. fd = open("/sys/bus/iio/devices/iio\:device0/in_voltage2_raw", O_RDONLY); //PP
  810. if(fd > 0)
  811. {
  812. for(AvgTimes = 0; AvgTimes < 5; AvgTimes++) //get 5 samples
  813. {
  814. read(fd, SampleBuf, 4);
  815. TmpVolt = atoi(SampleBuf);
  816. lseek(fd, 0, SEEK_SET);
  817. AvgSample += TmpVolt;
  818. }
  819. close(fd);
  820. AvgSample /= AvgTimes;
  821. V_pp = (3.6*AvgSample)/4095; //PP
  822. #if 0
  823. printf("PP_adc = %.02f, PP_v = %.02f\n", AvgSample, V_pp);
  824. usleep(3000000); //300ms
  825. #endif
  826. usleep(20000); //20ms
  827. return V_pp;
  828. }
  829. else
  830. {
  831. return -1;
  832. }
  833. }
  834. /*===========================================================================
  835. FUNCTION: Qca7kPowerReset
  836. DESCRIPTION:
  837. PRE-CONDITION:
  838. INPUT:
  839. OUTPUT:
  840. GLOBAL VARIABLES:
  841. =============================================================================*/
  842. void Qca7kPowerReset()
  843. {
  844. //printf("\n[CCS Board]Reset QCA7000...\n");
  845. system("echo 1 > /sys/class/gpio/gpio88/value");
  846. usleep(500000);
  847. system("echo 0 > /sys/class/gpio/gpio88/value");
  848. }
  849. /*===========================================================================
  850. FUNCTION: SwitchCpStateE
  851. DESCRIPTION:
  852. PRE-CONDITION:
  853. INPUT:
  854. OUTPUT:
  855. GLOBAL VARIABLES:
  856. =============================================================================*/
  857. int SwitchCpStateE(unsigned char OnOff)
  858. {
  859. if((OnOff != ENABLE) && (OnOff != DISABLE))
  860. {
  861. return -1;
  862. }
  863. struct ChargingInfoData *ccs;
  864. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  865. ccs->SwitchCpStateE_status = OnOff;
  866. //OnOff = 1 => switch State to E
  867. //OnOff = 0 => return noraml
  868. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  869. {
  870. if(OnOff == DISABLE)
  871. {
  872. //SAVE_SYS_LOG_MSG_EVCOMM("SwitchCpStateE: released\n");
  873. CSUCOMMAC_SHM.CpSetStateE = DISABLE;
  874. }
  875. else
  876. {
  877. OutputCpPwmDuty(100); //set CP duty as 100, firstly.
  878. CSUCOMMAC_SHM.CpSetStateE = ENABLE;
  879. //SAVE_SYS_LOG_MSG_EVCOMM("SwitchCpStateE: enabled!\n");
  880. }
  881. }
  882. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  883. {
  884. if(OnOff == DISABLE)
  885. {
  886. //SAVE_SYS_LOG_MSG_EVCOMM("SwitchCpStateE: released\n");
  887. system("echo 0 > /sys/class/gpio/gpio86/value");
  888. }
  889. else
  890. {
  891. OutputCpPwmDuty(100); //set CP duty as 100, firstly.
  892. system("echo 1 > /sys/class/gpio/gpio86/value");
  893. //SAVE_SYS_LOG_MSG_EVCOMM("SwitchCpStateE: enabled!\n");
  894. }
  895. }
  896. #endif
  897. if (ccs->SwitchCpStateE_status_pre != ccs->SwitchCpStateE_status)
  898. {
  899. sprintf(buf_log_evcomm,
  900. "SwitchCpStateE: %d >> %d",
  901. ccs->SwitchCpStateE_status_pre,
  902. ccs->SwitchCpStateE_status
  903. );
  904. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  905. ccs->SwitchCpStateE_status_pre = ccs->SwitchCpStateE_status;
  906. }
  907. }
  908. /*===========================================================================
  909. FUNCTION: OutputCpPwmDuty
  910. DESCRIPTION:
  911. PRE-CONDITION:
  912. INPUT:
  913. OUTPUT:
  914. GLOBAL VARIABLES:
  915. =============================================================================*/
  916. int OutputCpPwmDuty(unsigned char Duty)
  917. {
  918. int DutyInNanoSec;
  919. struct ChargingInfoData *ccs;
  920. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  921. if((Duty < 0)||(Duty > 100))
  922. {
  923. return -1;
  924. }
  925. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  926. {
  927. CSUCOMMAC_SHM.CpSetPWMDuty = Duty;
  928. }
  929. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  930. {
  931. DutyInNanoSec = 10000 * Duty;
  932. sprintf(buf_log_evcomm, "echo %d > /sys/class/pwm/pwmchip0/pwm0/duty_cycle", DutyInNanoSec);//nanoseconds
  933. system(buf_log_evcomm);
  934. }
  935. #endif
  936. ccs->CpDuty = Duty;
  937. //CP Duty
  938. if (ccs->CpDuty != ccs->CpDuty_pre)
  939. {
  940. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  941. sprintf(buf_log_evcomm, "CP Duty: %d\% >> %d\%", ccs->CpDuty_pre, ccs->CpDuty);
  942. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  943. ccs->CpDuty_pre = ccs->CpDuty;
  944. }
  945. return 0;
  946. }
  947. /*===========================================================================
  948. FUNCTION: Check_Plugin_Status_Update_fork1
  949. DESCRIPTION:
  950. PRE-CONDITION:
  951. INPUT:
  952. OUTPUT:
  953. GLOBAL VARIABLES:
  954. =============================================================================*/
  955. //#if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  956. void Check_Plugin_Status_Update_fork1(struct ChargingInfoData *ccs)
  957. {
  958. if (ccs->ConnectorPlugIn != ccs->ConnectorPlugIn_new)
  959. {
  960. sprintf(buf_log_evcomm_fork1, "[fork1]Plugin: %d >> %d (CP=%.2fV, PP=%.2fV)",
  961. ccs->ConnectorPlugIn,
  962. ccs->ConnectorPlugIn_new,
  963. ccs->CpVoltage,
  964. ccs->PpVoltage
  965. );
  966. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork1);
  967. ccs->ConnectorPlugIn_pre = ccs->ConnectorPlugIn;
  968. ccs->ConnectorPlugIn = ccs->ConnectorPlugIn_new;
  969. //ccs->CpVoltage_pre = ccs->CpVoltage;
  970. }
  971. }
  972. //#endif
  973. /*===========================================================================
  974. FUNCTION: ConnectorPlugIn
  975. DESCRIPTION:
  976. PRE-CONDITION:
  977. INPUT:
  978. OUTPUT:
  979. GLOBAL VARIABLES:
  980. =============================================================================*/
  981. int CheckConnectorPlugIn()
  982. {
  983. //return 0 => unplug
  984. //return 1 => plug-in
  985. //float TmpProximity;
  986. //unsigned char Rtn = 0;
  987. static struct ChargingInfoData *ccs;
  988. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  989. #if (CP_PROTECTION_MECHANISM == ENABLE)
  990. return (int)ccs->ConnectorPlugIn;
  991. #else
  992. return TRUE;
  993. #endif
  994. /*
  995. // PP Detection
  996. TmpProximity = ReadAdcVolt(ADC_CHANNEL_AIN2_PP);
  997. //[CAUTION] This function takes a period of time to deal with.
  998. //Designers should avoid to call it in main function, repeatly.
  999. if(((FIRMWARE_VERSION & 0x0000FF00) >> 8) == 0x01)
  1000. {
  1001. //UL version: judge with CP and proximity
  1002. //TmpProximity = ReadAdcVolt(ADC_CHANNEL_AIN2_PP);
  1003. //SAVE_SYS_LOG_MSG_EVCOMM("Connector: UL");
  1004. if((ccs->CpState >= 2) &&
  1005. (ccs->CpState <= 5) &&
  1006. (TmpProximity >= 0.4) &&
  1007. (TmpProximity <= 0.9))
  1008. {
  1009. Rtn = 1;
  1010. }
  1011. }
  1012. else
  1013. {
  1014. //SAVE_SYS_LOG_MSG_EVCOMM("Connector: CE");
  1015. //CE version: judge with CP only
  1016. if((ccs->CpState >=2 ) &&
  1017. (ccs->CpState <=5 ))
  1018. {
  1019. Rtn = 1;
  1020. }
  1021. }
  1022. */
  1023. //CE version: judge with CP only
  1024. /*
  1025. if((ccs->CpState >= 2 ) &&
  1026. (ccs->CpState <= 5 ))
  1027. {
  1028. Rtn = TRUE;
  1029. }
  1030. ccs->ConnectorPlugIn = Rtn;
  1031. //ccs->PpVoltage = TmpProximity;
  1032. return Rtn;
  1033. */
  1034. }
  1035. /*===========================================================================
  1036. FUNCTION: Check_CP_State_Error_fork1
  1037. DESCRIPTION:
  1038. PRE-CONDITION:
  1039. INPUT:
  1040. OUTPUT:
  1041. GLOBAL VARIABLES:
  1042. =============================================================================*/
  1043. int Check_CP_State_Error_fork1(struct ChargingInfoData *ccs)
  1044. {
  1045. #if (CP_PROTECTION_MECHANISM == DISABLE)
  1046. {
  1047. return -1;
  1048. }
  1049. #endif
  1050. unsigned char state = 0;
  1051. double time_diff = 0;
  1052. state = Check_V2G_Flow_Status();
  1053. //SLAC, SLAAC, SDP, ..., ChargeParameterDiscovery
  1054. if (state >= CM_SLAC_PARM_CONF && //by considering 15118(SLAC first)
  1055. state < ChargeParameterDiscoveryRequest &&
  1056. state != IDLE &&
  1057. state != CM_SET_KEY_REQ &&
  1058. state != CM_SET_KEY_CNF &&
  1059. state != CM_VALIDATE_REQ &&
  1060. state != CM_VALIDATE_CNF)
  1061. {
  1062. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  1063. {
  1064. if((ccs->CpState != 2) && (ccs->CpState != 3))
  1065. {
  1066. if (ccs->CpState_err == FALSE)
  1067. {
  1068. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][CP][Error]before CPD"); //CPD: ChargeParameterDiscoveryRequest
  1069. //CPD: ChargeParameterDiscovery
  1070. }
  1071. ccs->CpState_err = TRUE;
  1072. }
  1073. }
  1074. #else
  1075. {
  1076. if(ccs->CpState != 3)
  1077. {
  1078. if (ccs->CpState_err == FALSE)
  1079. {
  1080. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][CP][Error]before CPD"); //CPD: ChargeParameterDiscoveryRequest
  1081. //CPD: ChargeParameterDiscovery
  1082. }
  1083. ccs->CpState_err = TRUE;
  1084. }
  1085. }
  1086. #endif
  1087. }
  1088. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  1089. {
  1090. //ChargeParameterDiscovery
  1091. if(state >= ChargeParameterDiscoveryRequest && //35
  1092. state <= ChargeParameterDiscoveryResponse) //36
  1093. {
  1094. if(ccs->CpState != 3)
  1095. {
  1096. if (ccs->CpState_err == FALSE)
  1097. {
  1098. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD");
  1099. //PRC: Precharge
  1100. //CUD: CurrentDemand
  1101. }
  1102. ccs->CpState_err = TRUE;
  1103. }
  1104. }
  1105. //ChargingStatus
  1106. if(state >= ChargingStatusRequest && //43
  1107. state <= ChargingStatusResponse) //44
  1108. {
  1109. if(ccs->CpState != 4 && ccs->CpState != 5)
  1110. {
  1111. if (ccs->CpState_err == FALSE)
  1112. {
  1113. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CGS");
  1114. //PRC: Precharge
  1115. //CUD: CurrentDemand
  1116. }
  1117. ccs->CpState_err = TRUE;
  1118. }
  1119. }
  1120. }
  1121. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  1122. {
  1123. //ChargeParameterDiscovery, CableCheck
  1124. if (state >= ChargeParameterDiscoveryRequest && //35
  1125. state <= CableCheckResponse) //38
  1126. {
  1127. if(ccs->CableCheckPreCountDownDone == FALSE &&
  1128. state >= CableCheckRequest)
  1129. {
  1130. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  1131. time_diff = DiffTimeb_fork1_Error_Monitor(EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start, EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  1132. if(time_diff >= V2G_SECC_CP_Timeout_CableCheck) //2 sec
  1133. {
  1134. sprintf(buf_log_evcomm_fork1,
  1135. "[fork1][CP]check C(4),D(5): ON (%.02lf of %dms)",
  1136. time_diff,
  1137. V2G_SECC_CP_Timeout_CableCheck);
  1138. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork1);
  1139. ccs->CableCheckPreCountDownDone = TRUE;
  1140. }
  1141. }
  1142. if(ccs->CableCheckPreCountDownDone == TRUE)
  1143. {
  1144. if(ccs->CpState != 4 && ccs->CpState != 5)
  1145. {
  1146. if (ccs->CpState_err == FALSE)
  1147. {
  1148. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD and CCK (after CNT)");
  1149. //CPD: ChargeParameterDiscovery
  1150. //CCK: CableCheck
  1151. //CNT: count down
  1152. }
  1153. ccs->CpState_err = TRUE;
  1154. }
  1155. }
  1156. else
  1157. {
  1158. if(ccs->CpState != 3 && ccs->CpState != 4 && ccs->CpState != 5)
  1159. {
  1160. if (ccs->CpState_err == FALSE)
  1161. {
  1162. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD and CCK (before CNT)");
  1163. //CPD: ChargeParameterDiscovery
  1164. //CCK: CableCheck
  1165. //CNT: count down
  1166. }
  1167. ccs->CpState_err = TRUE;
  1168. }
  1169. }
  1170. }
  1171. //Precharge, CurrentDemand
  1172. if(state >= PreChargeRequest && //39
  1173. state <= CurrentDemandResponse) //46
  1174. {
  1175. if(ccs->CpState != 4 && ccs->CpState != 5)
  1176. {
  1177. if (ccs->CpState_err == FALSE)
  1178. {
  1179. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]PRC and CUD");
  1180. //PRC: Precharge
  1181. //CUD: CurrentDemand
  1182. }
  1183. ccs->CpState_err = TRUE;
  1184. }
  1185. }
  1186. }
  1187. #endif
  1188. if(ccs->CpState_err == TRUE && ccs->CpState_err_logged == FALSE)
  1189. {
  1190. OutputCpPwmDuty(100);
  1191. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  1192. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1193. //CCS_SECC_CP_State_Error (023889)
  1194. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1195. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1196. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1197. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1198. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1199. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1200. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1201. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1202. sprintf(buf_log_evcomm_fork1, "[fork1][Erorr]CP(%d) Error in state %d(%d)",
  1203. ccs->CpState,
  1204. state,
  1205. ccs->CableCheckPreCountDownDone
  1206. );
  1207. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork1);
  1208. ccs->CpState_err_logged = TRUE;
  1209. }
  1210. return 0;
  1211. }
  1212. /*===========================================================================
  1213. FUNCTION: Check_CP_State_Update_fork1
  1214. DESCRIPTION:
  1215. PRE-CONDITION:
  1216. INPUT:
  1217. OUTPUT:
  1218. GLOBAL VARIABLES:
  1219. =============================================================================*/
  1220. //#if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  1221. void Check_CP_State_Update_fork1(struct ChargingInfoData *ccs)
  1222. {
  1223. //CP Voltage
  1224. /*
  1225. //Issues waiting to debug
  1226. //[CAUTION] This function shall not be used in charging state.
  1227. if (((int)(ccs->CpVoltage * 10)) != ((int)(ccs->CpVoltage_pre * 10)))
  1228. {
  1229. memset(buf, 0, sizeof(buf));
  1230. sprintf(buf, "CP Voltage: %.2lf >> %.2lf (%d >> %d)",
  1231. ccs->CpVoltage_pre,
  1232. ccs->CpVoltage,
  1233. (int)(ccs->CpVoltage_pre * 10),
  1234. (int)(ccs->CpVoltage * 10)
  1235. );
  1236. SAVE_SYS_LOG_MSG_EVCOMM(buf);
  1237. ccs->CpVoltage_pre = ccs->CpVoltage;
  1238. }
  1239. */
  1240. //CP State
  1241. if (ccs->CpState != ccs->CpState_pre)
  1242. {
  1243. sprintf(buf_log_evcomm_fork1, "[fork1]CP State: %d >> %d (%.2fV)",
  1244. ccs->CpState_pre,
  1245. ccs->CpState,
  1246. ccs->CpVoltage
  1247. );
  1248. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork1);
  1249. ccs->CpState_pre = ccs->CpState;
  1250. }
  1251. }
  1252. //#endif
  1253. /*===========================================================================
  1254. FUNCTION: CP_Detection
  1255. DESCRIPTION:
  1256. 1. In order to detect CP in efficient response time, we creat an independent
  1257. thead for this procedure.
  1258. 2. The priority of this thread is set as the same as other tasks.
  1259. 3. fork1
  1260. PRE-CONDITION:
  1261. INPUT:
  1262. OUTPUT:
  1263. GLOBAL VARIABLES:
  1264. =============================================================================*/
  1265. void CP_Detection()
  1266. {
  1267. pid_t tmp = 0;
  1268. // struct timeb StartTime, EndTime;
  1269. unsigned char Statetmp;
  1270. float TotalTmpVolt;
  1271. struct ChargingInfoData *ccs;
  1272. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1273. if(CP_Detection_Pid == 0)
  1274. {
  1275. tmp = fork();
  1276. if(tmp > 0)
  1277. {
  1278. CP_Detection_Pid = tmp;
  1279. #if 1
  1280. unsigned char buf[64];
  1281. memset(buf, 0, sizeof(buf));
  1282. //sprintf(buf, "renice -20 -p %d", tmp);
  1283. sprintf(buf, "renice -10 -p %d", tmp);
  1284. system(buf);
  1285. #endif
  1286. return;
  1287. }
  1288. }
  1289. while(1)
  1290. {
  1291. //ADC_Voltage = (1+RE62/RE63)*0.9 - (RE62/RE63)*Pilot_Voltage, RE62/RE63=0.06
  1292. //=>Pilot_Voltage=(0.954-ADC_Voltage)/0.06
  1293. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  1294. {
  1295. ccs->CpVoltage = ShmInternalComm->AC_CpPositiveVoltage;
  1296. ccs->CpState = ShmInternalComm->AC_CpPresentState;
  1297. }
  1298. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  1299. {
  1300. TotalTmpVolt = ReadAdcVolt(3);
  1301. ccs->CpVoltage = TotalTmpVolt;
  1302. if (ccs->CpVoltage_pre != ccs->CpVoltage)
  1303. {
  1304. ccs->CpVoltage_pre = ccs->CpVoltage;
  1305. }
  1306. //printf("TotalTmpVolt = %.02f\n", TotalTmpVolt);
  1307. //If CP voltage is higer than 13.5V
  1308. if(TotalTmpVolt >= 13.5)
  1309. {
  1310. //Pilot Error
  1311. if((ccs->CpState == 1) &&
  1312. (TotalTmpVolt < 13.75))
  1313. {
  1314. //V_cp = 13.5 ~ 13.75
  1315. Statetmp = 1;
  1316. }
  1317. else
  1318. {
  1319. //V_cp = 13.5 ~
  1320. Statetmp = 8;
  1321. }
  1322. }
  1323. else if((TotalTmpVolt >= 10.5) && (TotalTmpVolt < 13.5)) //V_cp = 10.5 ~ 13.5
  1324. {
  1325. //State A (12V)
  1326. if((ccs->CpState >= 2) &&
  1327. (ccs->CpState <= 3) &&
  1328. (TotalTmpVolt < 10.75))
  1329. {
  1330. if((ccs->CpDuty >= 5) &&
  1331. (ccs->CpDuty < 100))
  1332. {
  1333. Statetmp = 3;
  1334. }
  1335. else
  1336. {
  1337. Statetmp = 2;
  1338. }
  1339. }
  1340. else if((ccs->CpState == 8) &&
  1341. (TotalTmpVolt >= 13.25))
  1342. {
  1343. Statetmp = 8;
  1344. }
  1345. else
  1346. {
  1347. Statetmp = 1;
  1348. }
  1349. }
  1350. else if((TotalTmpVolt >= 7.5) && (TotalTmpVolt < 10.5))
  1351. {
  1352. //State B (9V)
  1353. if((ccs->CpState == 4) && (TotalTmpVolt < 7.75))
  1354. {
  1355. Statetmp = 4;
  1356. }
  1357. else if((ccs->CpState == 1) && (TotalTmpVolt >= 10.25))
  1358. {
  1359. Statetmp = 1;
  1360. }
  1361. else
  1362. {
  1363. if((ccs->CpDuty >= 5) && (ccs->CpDuty < 100))
  1364. {
  1365. Statetmp = 3;
  1366. }
  1367. else
  1368. {
  1369. Statetmp = 2;
  1370. }
  1371. }
  1372. }
  1373. else if((TotalTmpVolt >= 4.5) && (TotalTmpVolt < 7.5))
  1374. {
  1375. //State C (6V)
  1376. if((ccs->CpState == 5) && (TotalTmpVolt < 4.75))
  1377. {
  1378. Statetmp = 5;
  1379. }
  1380. else if((ccs->CpState >= 2) && (ccs->CpState <= 3) && (TotalTmpVolt >= 7.25))
  1381. {
  1382. if((ccs->CpDuty >= 5)&&(ccs->CpDuty < 100))
  1383. {
  1384. Statetmp = 3;
  1385. }
  1386. else
  1387. {
  1388. Statetmp = 2;
  1389. }
  1390. }
  1391. else
  1392. {
  1393. Statetmp = 4;
  1394. }
  1395. }
  1396. else if((TotalTmpVolt >= 1.5) && (TotalTmpVolt < 4.5))
  1397. {
  1398. //State D (3V)
  1399. if((ccs->CpState == 6)&&(TotalTmpVolt < 1.75))
  1400. {
  1401. Statetmp = 6;
  1402. }
  1403. else if((ccs->CpState == 4)&&(TotalTmpVolt >= 4.25))
  1404. {
  1405. Statetmp = 4;
  1406. }
  1407. else
  1408. {
  1409. Statetmp = 5;
  1410. }
  1411. }
  1412. else if((TotalTmpVolt >= -1.5) && (TotalTmpVolt < 1.5)) //V_cp = -1.5V ~ 1.5V
  1413. {
  1414. //State E (0V)
  1415. if((ccs->CpState == 8) &&
  1416. (TotalTmpVolt < -1.25))
  1417. {
  1418. Statetmp = 8;
  1419. }
  1420. else if((ccs->CpState == 5) &&
  1421. (TotalTmpVolt >= 1.25))
  1422. {
  1423. Statetmp = 5;
  1424. }
  1425. else
  1426. {
  1427. Statetmp = 6;
  1428. }
  1429. }
  1430. else if((TotalTmpVolt >= -13.5) && (TotalTmpVolt < -10.5)) //V_cp = -10.5V ~ -13.5V
  1431. {
  1432. //State F (-12V)
  1433. if((ccs->CpState == 8) &&
  1434. (TotalTmpVolt >= -10.75))
  1435. {
  1436. Statetmp = 8;
  1437. }
  1438. else
  1439. {
  1440. Statetmp = 7;
  1441. }
  1442. }
  1443. else
  1444. {
  1445. //null
  1446. }
  1447. ccs->CpState = Statetmp;
  1448. }
  1449. #endif
  1450. Check_CP_State_Update_fork1(ccs);
  1451. Check_CP_State_Error_fork1(ccs);
  1452. //Updating Plugin status
  1453. #if (PP_PROTECTION_MECHANISM == ENABLE)
  1454. if((ccs->CpState >= 2 ) && (ccs->CpState <= 5 ) && (ccs->PpVoltage >= 1.0)) //PP >= 1.0V
  1455. #else
  1456. if((ccs->CpState >= 2 ) && (ccs->CpState <= 5 ))
  1457. #endif
  1458. {
  1459. ccs->ConnectorPlugIn_new = TRUE;
  1460. }
  1461. else
  1462. {
  1463. ccs->ConnectorPlugIn_new = FALSE;
  1464. OutputCpPwmDuty(100);
  1465. }
  1466. Check_Plugin_Status_Update_fork1(ccs);
  1467. //ftime(&EndTime);
  1468. //DEBUG_PRINTF_EVCOMM_DETAIL("duration:%.02lf\n", DiffTimeb(StartTime, EndTime));
  1469. }//while
  1470. }
  1471. /*===========================================================================
  1472. FUNCTION: PP_Detection
  1473. DESCRIPTION:
  1474. 0. SeccComm fork3
  1475. 1. In order to detect CP in efficient response time, we creat an independent
  1476. thead for this procedure.
  1477. 2. The priority of this thread is set as the same as other tasks.
  1478. PRE-CONDITION:
  1479. INPUT:
  1480. OUTPUT:
  1481. GLOBAL VARIABLES:
  1482. =============================================================================*/
  1483. void PP_Detection()
  1484. {
  1485. pid_t tmp = 0;
  1486. // struct timeb StartTime, EndTime;
  1487. unsigned char Statetmp;
  1488. float TotalTmpVolt;
  1489. if(PP_Detection_Pid == 0)
  1490. {
  1491. tmp = fork();
  1492. if(tmp > 0)
  1493. {
  1494. PP_Detection_Pid = tmp;
  1495. #if 0
  1496. unsigned char buf[64];
  1497. memset(buf, 0, sizeof(buf));
  1498. sprintf(buf, "renice -10 -p %d", tmp);
  1499. system(buf);
  1500. #endif
  1501. return;
  1502. }
  1503. }
  1504. TotalTmpVolt = ReadAdcVolt_PP_fork3();
  1505. while(1)
  1506. {
  1507. TotalTmpVolt = ReadAdcVolt_PP_fork3();
  1508. EVCOMM_SYS_INFO.PpVoltage = TotalTmpVolt;
  1509. if (EVCOMM_SYS_INFO.PpVoltage_pre != EVCOMM_SYS_INFO.PpVoltage)
  1510. {
  1511. if ((EVCOMM_SYS_INFO.PpVoltage_pre < 0.5 && EVCOMM_SYS_INFO.PpVoltage >= 1.0) ||
  1512. (EVCOMM_SYS_INFO.PpVoltage_pre >= 1.0 && EVCOMM_SYS_INFO.PpVoltage < 0.5))
  1513. {
  1514. // plug-in : > 1.0
  1515. //unplug : <0.5
  1516. sprintf(buf_log_evcomm_fork3,
  1517. "[fork3]PP(%.2f >> %.2fV)",
  1518. EVCOMM_SYS_INFO.PpVoltage_pre,
  1519. EVCOMM_SYS_INFO.PpVoltage
  1520. );
  1521. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork3);
  1522. EVCOMM_SYS_INFO.PpVoltage_pre = EVCOMM_SYS_INFO.PpVoltage;
  1523. }
  1524. }
  1525. #if 0
  1526. sleep(5);
  1527. printf("V_pp = %.02f\n", TotalTmpVolt);
  1528. #endif
  1529. }//while
  1530. }
  1531. /*===========================================================================
  1532. FUNCTION: Error_Monitor
  1533. DESCRIPTION:
  1534. 1. This function only works in SeccComm fork2.
  1535. PRE-CONDITION:
  1536. INPUT:
  1537. OUTPUT:
  1538. GLOBAL VARIABLES:
  1539. =============================================================================*/
  1540. void Error_Monitor()
  1541. {
  1542. pid_t tmp = 0;
  1543. double time_diff = 0;
  1544. unsigned char status = 0;
  1545. struct ChargingInfoData *ccs;
  1546. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1547. if(Error_Monitor_Pid == 0)
  1548. {
  1549. tmp = fork(); //SeccComm fork2
  1550. if(tmp > 0)
  1551. {
  1552. Error_Monitor_Pid = tmp;
  1553. #if 0
  1554. unsigned char buf[64];
  1555. memset(buf, 0, sizeof(buf));
  1556. sprintf(buf, "renice -20 -p %d", tmp);
  1557. system(buf);
  1558. #endif
  1559. return;
  1560. }
  1561. }
  1562. while(1)
  1563. {
  1564. //Step 0
  1565. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  1566. {
  1567. //If the End_Process is in processing, disable Error_Monitor.
  1568. continue;
  1569. }
  1570. //Step1 1: Check and Response to Plugin Status
  1571. if(CheckConnectorPlugIn() == FALSE)
  1572. {
  1573. status = Check_V2G_Flow_Status();
  1574. if (status > IDLE &&
  1575. status < Performance_Timeout &&
  1576. status != CM_SET_KEY_REQ &&
  1577. status != CM_SET_KEY_CNF &&
  1578. EVCOMM_SYS_INFO.End_Process_inused == FALSE)
  1579. {
  1580. #if (CP_PROTECTION_MECHANISM == ENABLE)
  1581. //SAVE_SYS_LOG_MSG_EVCOMM("[fork2] Emergency Stop (due to Connector is plugged out during communication.)");
  1582. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Plug out Error => End_Process");
  1583. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1584. //CCS_SECC_CP_State_Error (023889)
  1585. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1586. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1587. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1588. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1589. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1590. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1591. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1592. End_Process();
  1593. #else
  1594. //SAVE_SYS_LOG_MSG_EVCOMM("CP_PROTECTION_MECHANISM is disabled. Emergency Stop: skipped" );
  1595. #endif
  1596. }
  1597. }
  1598. //Step 2: Check for V2G_SECC_Sequence_Timeout
  1599. //#if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  1600. #if 1
  1601. status = Check_V2G_Flow_Status();
  1602. if (status >= SupportedAppProtocolRequest &&
  1603. status < SessionStopRequest)
  1604. {
  1605. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_End);
  1606. time_diff = DiffTimeb_fork2_Error_Monitor(EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start, EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_End);
  1607. if(time_diff > V2G_SECC_Sequence_Timeout) //60s
  1608. {
  1609. sprintf(buf_log_evcomm_fork2,
  1610. "[fork2]V2G_SECC_Sequence_Timeout in state %d - (%.02lf of %d ms)\n",
  1611. status,
  1612. time_diff,
  1613. V2G_SECC_Sequence_Timeout);
  1614. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1615. Update_V2G_Flow_Status(Sequence_Timeout);
  1616. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1617. //CCS_SECC_TIMEOUT_V2G_Sequence_Time (023844)
  1618. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1619. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1620. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1621. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1622. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  1623. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  1624. End_Process();
  1625. break;
  1626. }
  1627. else if (time_diff > 4000) //4s
  1628. {
  1629. //Check for CSU command of "Stop by EVSE"
  1630. if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_Shutdown)
  1631. {
  1632. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]EVSE_Shutdown");
  1633. Update_V2G_Flow_Status(Other_Fault);
  1634. }
  1635. else if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_EmergencyShutdown)
  1636. {
  1637. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]EVSE_EmergencyShutdown");
  1638. Update_V2G_Flow_Status(Other_Fault);
  1639. }
  1640. else if (ShmInternalComm->ChargingPermission == FALSE)
  1641. {
  1642. if (status >= ChargeParameterDiscoveryRequest) //&& status < SessionStopRequest
  1643. {
  1644. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]ChargingPermission = FALSE");
  1645. Update_V2G_Flow_Status(Other_Fault);
  1646. }
  1647. }
  1648. else
  1649. {
  1650. //null
  1651. }
  1652. }
  1653. else
  1654. {
  1655. //null
  1656. }
  1657. }
  1658. #endif
  1659. //Step 3: Check and Response to Error V2gFlowStatus
  1660. status = Check_V2G_Flow_Status();
  1661. if (status == Performance_Timeout ||
  1662. status == Sequence_Timeout ||
  1663. status == Other_Fault)
  1664. {
  1665. sprintf(buf_log_evcomm_fork2,
  1666. "[fork2]Timeout or Fault State(%d) => End_Process",
  1667. status);
  1668. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1669. //Normal Stop
  1670. //alarm and duty to 100%
  1671. //OutputCpPwmDuty(100);
  1672. //SwitchCpStateE(ENABLE); //Set CP duty as 100% and set CP state as E (0V).
  1673. //[Joseph/ To-Do] Set State E (0V) via GPIO setting
  1674. End_Process();
  1675. }
  1676. //Step 4: Check and Response to CP State Error
  1677. if(ccs->CpState_err == TRUE)
  1678. {
  1679. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]CP Error => End_Process");
  1680. Update_V2G_Flow_Status(Other_Fault);
  1681. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1682. //CCS_SECC_CP_State_Error (023889)
  1683. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1684. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1685. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1686. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1687. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1688. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1689. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1690. End_Process();
  1691. }
  1692. //Step 5: Check and Response to Shutdown Commnad from CSU
  1693. if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_Shutdown ||
  1694. EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_EmergencyShutdown)
  1695. {
  1696. if (Check_V2G_Flow_Status() <= SLACC_SDP_TCP_Connection)
  1697. {
  1698. sprintf(buf_log_evcomm_fork2,
  1699. "[fork2]EVSE Shutdown(%d) => End_Process",
  1700. EVCOMM_SYS_INFO.DC_EVSEStatus);
  1701. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1702. Update_V2G_Flow_Status(Other_Fault);
  1703. End_Process();
  1704. }
  1705. }
  1706. //Step 6: Check and Response to SessionStop
  1707. status = Check_V2G_Flow_Status();
  1708. if (status == SessionStopResponse)
  1709. {
  1710. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]SessionStopResponse => End_Process");
  1711. End_Process();
  1712. }
  1713. //Step 7: Check for ChargingPermission from TRUE to FALSE before V2G Messages
  1714. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  1715. if ((ShmInternalComm->ChargingPermission == FALSE) &&
  1716. (ShmInternalComm->ChargingPermission_pre >=1) &&
  1717. (ccs->CpState >= 3) && (ccs->CpState <=5))
  1718. {
  1719. if (status >= CM_SLAC_PARM_REQ &&
  1720. status != CM_SET_KEY_REQ &&
  1721. status != CM_SET_KEY_CNF &&
  1722. status <= SLACC_SDP_TCP_Connection)
  1723. {
  1724. sprintf(buf_log_evcomm_fork2,
  1725. "[fork2]Permission OFF before V2G msg(%d) => End_Process",
  1726. ShmInternalComm->ChargingPermission);
  1727. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1728. Update_V2G_Flow_Status(Other_Fault);
  1729. End_Process();
  1730. }
  1731. }
  1732. //Step 8: DC OVP Protection
  1733. if (CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED &&
  1734. status > CableCheckResponse &&
  1735. status <= SessionStopRequest &&
  1736. status != ChargingStatusRequest &&
  1737. status != ChargingStatusResponse &&
  1738. EVCOMM_SYS_INFO.EvBatteryMaxVoltage != 0)
  1739. {
  1740. //Part A: OVP Protection
  1741. #if 0
  1742. if (EVCOMM_SYS_INFO.PresentChargingVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02)) // 2%
  1743. {
  1744. sprintf(buf_log_evcomm_fork2,
  1745. "[fork2][Error]OVP => End_Process (%.02f > %.02f)",
  1746. EVCOMM_SYS_INFO.PresentChargingVoltage,
  1747. (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02));
  1748. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1749. Update_V2G_Flow_Status(Other_Fault);
  1750. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1751. //System CCS output OVP (012219)
  1752. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1753. ShmStatusCodeData->PresentStatusCode[0][1] = 1;
  1754. ShmStatusCodeData->PresentStatusCode[0][2] = 2;
  1755. ShmStatusCodeData->PresentStatusCode[0][3] = 2;
  1756. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  1757. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1758. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1759. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1760. End_Process();
  1761. }
  1762. #endif
  1763. //Part B: Over Voltage Request Protection
  1764. if (EVCOMM_SYS_INFO.EvBatterytargetVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02))
  1765. {
  1766. sprintf(buf_log_evcomm_fork2,
  1767. "[fork2]Over V Req => End_Process (%.02f > %.02f)",
  1768. EVCOMM_SYS_INFO.EvBatterytargetVoltage,
  1769. (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02)
  1770. );
  1771. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm_fork2);
  1772. Update_V2G_Flow_Status(Other_Fault);
  1773. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1774. //System CCS output OVP (012219)
  1775. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1776. ShmStatusCodeData->PresentStatusCode[0][1] = 1;
  1777. ShmStatusCodeData->PresentStatusCode[0][2] = 2;
  1778. ShmStatusCodeData->PresentStatusCode[0][3] = 2;
  1779. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  1780. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1781. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1782. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1783. End_Process();
  1784. }
  1785. }
  1786. //Step 9: Check 60V
  1787. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  1788. if (CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED &&
  1789. ShmInternalComm->ChargingPermission >=1 &&
  1790. status < CableCheckRequest)
  1791. {
  1792. if (EVCOMM_SYS_INFO.PresentChargingVoltage >= 60) //60V
  1793. {
  1794. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]DC Output Voltage is over 60V => End_Process");
  1795. Update_V2G_Flow_Status(Other_Fault);
  1796. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1797. //CCS_SECC_Unexpected_60V_Before_Charing_Error (023890)
  1798. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1799. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1800. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1801. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1802. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  1803. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  1804. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1805. //Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1806. End_Process();
  1807. }
  1808. }
  1809. //Step 10: Check if the connector is unplug from plugin
  1810. if (EVCOMM_SYS_INFO.ConnectorPlugIn_pre == TRUE && EVCOMM_SYS_INFO.ConnectorPlugIn == FALSE)
  1811. {
  1812. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Unplug Reset => End_Process");
  1813. Update_V2G_Flow_Status(Other_Fault);
  1814. End_Process();
  1815. }
  1816. }//while
  1817. }
  1818. /*===========================================================================
  1819. FUNCTION: SendSetKey
  1820. DESCRIPTION:
  1821. PRE-CONDITION:
  1822. INPUT:
  1823. OUTPUT:
  1824. GLOBAL VARIABLES:
  1825. =============================================================================*/
  1826. int SendSetKey()
  1827. {
  1828. int i = 0;
  1829. unsigned char nRandValue = 0x0;
  1830. unsigned char ConstString[16] = "PhihongKey000000";
  1831. memset(&SendMmePacket,0,sizeof(struct MmeHeader));
  1832. memcpy(SendMmePacket.ODA,QcaMac,6);
  1833. memcpy(SendMmePacket.OSA,CsuMac,6);
  1834. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  1835. SendMmePacket.MMV = 0x01;
  1836. SendMmePacket.MMTYPE = MMTYPE_CM_SET_KEY_REQ;
  1837. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  1838. SendMmePacketSize = 0;
  1839. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//Fixed value (0x01) to indicate ��NMK��
  1840. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,4);//My Nonce, Fixed value(0x00000000), encrypted payload not used
  1841. SendMmePacketSize+=4;
  1842. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,4);//Your Nonce, Fixed value(0x00000000), encrypted payload not used
  1843. SendMmePacketSize+=4;
  1844. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x04;//PID, Fixed value (0x04) to indicate ��HLE protocol��
  1845. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,2);//PRN, Fixed value(0x00), encrypted payload not used
  1846. SendMmePacketSize+=2;
  1847. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00;//PMN, Fixed value(0x00) encrypted payload not used
  1848. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//CCo Capablility
  1849. srand(time(NULL));
  1850. for (i = 10; i < 16; i++)
  1851. {
  1852. nRandValue = (rand()%62) + 1;
  1853. if((nRandValue>=0)&&(nRandValue<=9)) // 0 ~ 9
  1854. {
  1855. ConstString[i]= nRandValue + 0x30;
  1856. }
  1857. else if((nRandValue>=10)&&(nRandValue<=35)) // A ~ Z
  1858. {
  1859. ConstString[i]= nRandValue -10 + 0x41;
  1860. }
  1861. else if((nRandValue>=36)&&(nRandValue<=61)) // a ~ z
  1862. {
  1863. ConstString[i]= nRandValue -37 + 0x61;
  1864. }
  1865. else
  1866. {
  1867. ConstString[i]= 0x30;
  1868. }
  1869. }
  1870. memset(NewNmkKey,0,sizeof(NewNmkKey));
  1871. memset(Nid,0,sizeof(Nid));
  1872. HPAVKeyNMK(NewNmkKey, ConstString);
  1873. HPAVKeyNID(Nid,NewNmkKey,DEFAULT_LEVEL);
  1874. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,Nid,sizeof(Nid)); //NID, 54 LSBs contain the NID 2 MSBs = 0b00
  1875. SendMmePacketSize+=sizeof(Nid);
  1876. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x01;//NewEKS,Fixed value (0x01)to indicate ��NMK��
  1877. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,NewNmkKey,sizeof(NewNmkKey));//NewKey
  1878. SendMmePacketSize += sizeof(NewNmkKey);
  1879. SendMmePacketSize += 19; //the size before MMENTRY
  1880. SAVE_SYS_LOG_MSG_EVCOMM("[QCA7K][Tx]CM_SET_KEY_REQ");
  1881. i = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  1882. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  1883. DEBUG_PRINTF_EVCOMM_DETAIL("SendSetKey: send size =%d\n",i);
  1884. }
  1885. /*===========================================================================
  1886. FUNCTION: GetQca7kMac
  1887. DESCRIPTION:
  1888. PRE-CONDITION:
  1889. INPUT:
  1890. OUTPUT:
  1891. GLOBAL VARIABLES:
  1892. =============================================================================*/
  1893. int GetQca7kMac()
  1894. {
  1895. int i = 0;
  1896. struct QcaVendorMmeHeader SendPacket;
  1897. memset(&SendPacket, 0, sizeof(struct QcaVendorMmeHeader));
  1898. memset(SendPacket.ODA, 0xFF, 6); //broadcast
  1899. memcpy(SendPacket.OSA, CsuMac, 6);
  1900. SendPacket.MTYPE = htons(EtherType_HomePlug);
  1901. SendPacket.MMV = 0x00;
  1902. SendPacket.MMTYPE = MMTYPE_VENDOR_VS_NW_INFO;
  1903. SendPacket.OUI[0] = 0x00;
  1904. SendPacket.OUI[1] = 0xB0;
  1905. SendPacket.OUI[2] = 0x52;
  1906. i = sendto(RawSock, &SendPacket, 20, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  1907. DEBUG_PRINTF_EVCOMM_DETAIL("GetQca7kMac: send size =%d\n", i);
  1908. SAVE_SYS_LOG_MSG_EVCOMM("[QCA7K][Tx][VENDOR_VS_NW_INFO]Req for QCA7K MacAddr");
  1909. }
  1910. /*===========================================================================
  1911. FUNCTION: Array_Check_All_Zero
  1912. DESCRIPTION:
  1913. PRE-CONDITION:
  1914. INPUT:
  1915. OUTPUT:
  1916. result:
  1917. (1) TRUE: all zero
  1918. (2) FALSE: not all zero
  1919. GLOBAL VARIABLES:
  1920. =============================================================================*/
  1921. int Array_Check_All_Zero(unsigned char *ptr, int size)
  1922. {
  1923. int result = TRUE;
  1924. int i = 0;
  1925. for (i = 0; i < size; i++)
  1926. {
  1927. if (ptr[i] != 0)
  1928. {
  1929. result = FALSE;
  1930. break;
  1931. }
  1932. }
  1933. return result;
  1934. }
  1935. /*===========================================================================
  1936. FUNCTION: Array_Compare_Identity
  1937. DESCRIPTION:
  1938. PRE-CONDITION:
  1939. INPUT:
  1940. OUTPUT:
  1941. result = FALSE (not identical)
  1942. result = TRUE (identical)
  1943. GLOBAL VARIABLES:
  1944. =============================================================================*/
  1945. int Array_Compare_Identity(unsigned char *ptrA, unsigned char *ptrB, int size)
  1946. {
  1947. int result = TRUE;
  1948. int i = 0;
  1949. for (i = 0; i < size; i++)
  1950. {
  1951. if (ptrA[i] != ptrB[i])
  1952. {
  1953. result = FALSE;
  1954. #if 0
  1955. sprintf(buf_log_evcomm,
  1956. "[Array_Compare_Identity]%02X%02X%02X%02X%02X%02X,%02X%02X%02X%02X%02X%02X(%d)\n",
  1957. ptrA[0], ptrA[1], ptrA[2], ptrA[3], ptrA[4], ptrA[5],
  1958. ptrB[0], ptrB[1], ptrB[2], ptrB[3], ptrB[4], ptrB[5],
  1959. result);
  1960. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  1961. #endif
  1962. break;
  1963. }
  1964. }
  1965. return result;
  1966. }
  1967. /*===========================================================================
  1968. FUNCTION: SLAC_DB_Search_EvMac_idx
  1969. DESCRIPTION:
  1970. PRE-CONDITION:
  1971. INPUT:
  1972. OUTPUT:
  1973. idx = -1 (not found)
  1974. GLOBAL VARIABLES:
  1975. =============================================================================*/
  1976. int SLAC_DB_Search_EvMac_idx(struct EVCC_SLAC_DATA_TYPE *evcc, unsigned char *EvMac_in)
  1977. {
  1978. int idx = -1;
  1979. int i = 0;
  1980. if (evcc->arrayLen == 0)
  1981. {
  1982. //printf("[SLAC_DB_Search_EvMac_idx]arrayLen is empty (%d)\n", evcc->arrayLen);
  1983. //no need to search
  1984. }
  1985. else if (evcc->arrayLen > EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE)
  1986. {
  1987. //error
  1988. sprintf(buf_log_evcomm,
  1989. "[ERROR][SLAC_DB_Search_EvMac_idx]DB length(%d) > %d",
  1990. evcc->arrayLen,
  1991. EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE);
  1992. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  1993. evcc->arrayLen = 0; //reset
  1994. }
  1995. else
  1996. {
  1997. //start searching
  1998. for (i = 0; i < evcc->arrayLen; i++)
  1999. {
  2000. //printf("[SLAC_DB_Search_EvMac_idx]checking DB[%d]...\n", i);
  2001. if (Array_Compare_Identity(evcc->array[i].EvMac, EvMac_in, SLAC_EVMAC_LENGTH) == TRUE)
  2002. {
  2003. //printf("[SLAC_DB_Search_EvMac_idx]identical at DB[%d]...\n", i);
  2004. idx = i;
  2005. break;
  2006. }
  2007. }
  2008. }
  2009. //printf("[SLAC_DB_Search_EvMac_idx]return = %d\n", idx);
  2010. return idx;
  2011. }
  2012. /*===========================================================================
  2013. FUNCTION: SLAC_DB_Check_EvMac_RunID_Matching
  2014. DESCRIPTION:
  2015. PRE-CONDITION:
  2016. INPUT:
  2017. OUTPUT:
  2018. res = FALSE (unmatched)
  2019. res = TRUE (matched)
  2020. GLOBAL VARIABLES:
  2021. =============================================================================*/
  2022. int SLAC_DB_Check_EvMac_RunID_Matching(struct EVCC_SLAC_DATA_TYPE *evcc, unsigned char *EvMac_in, unsigned char *RunID_in)
  2023. {
  2024. int res = FALSE;
  2025. int idx = -1;
  2026. idx = SLAC_DB_Search_EvMac_idx(evcc, EvMac_in);
  2027. if (idx >= 0)
  2028. {
  2029. res = Array_Compare_Identity(evcc->array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2030. }
  2031. else
  2032. {
  2033. //not found the EvMac data in DB
  2034. res = FALSE;
  2035. }
  2036. return res;
  2037. }
  2038. /*===========================================================================
  2039. FUNCTION: SLAC_DB_Add
  2040. DESCRIPTION:
  2041. 1. Saving each CM_SLAC_PARM_REQ data into EVCC database if its
  2042. EvMac and RunID data are different, respectively.
  2043. PRE-CONDITION:
  2044. INPUT:
  2045. OUTPUT:
  2046. idx = saved index (must be a positive value)
  2047. GLOBAL VARIABLES:
  2048. =============================================================================*/
  2049. int SLAC_DB_Add(unsigned char *EvMac_in, unsigned char *RunID_in)
  2050. {
  2051. int idx = -1;
  2052. //Search if this EvMac and RunID already exists
  2053. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2054. if (idx < 0) //not exist, yet.
  2055. {
  2056. if (SLAC_INFO.arrayLen < EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE) //20
  2057. {
  2058. sprintf(buf_log_evcomm,
  2059. "[SLAC_DB_Add]data does not exist => added to %d-th",
  2060. SLAC_INFO.arrayLen);
  2061. DEBUG_PRINTF_EVCOMM_DETAIL(buf_log_evcomm);
  2062. if (SLAC_INFO.arrayLen >= 0)
  2063. {
  2064. memset(&SLAC_INFO.array[SLAC_INFO.arrayLen], 0, sizeof(struct EVCC_SLAC_DATA_ARRAY_TYPE));
  2065. memcpy(SLAC_INFO.array[SLAC_INFO.arrayLen].EvMac, EvMac_in, SLAC_EVMAC_LENGTH);
  2066. memcpy(SLAC_INFO.array[SLAC_INFO.arrayLen].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2067. idx = SLAC_INFO.arrayLen;
  2068. SLAC_INFO.arrayLen++;
  2069. }
  2070. else
  2071. {
  2072. sprintf(buf_log_evcomm,
  2073. "[ERROR][SLAC_DB_Add]arrayLen: unexpected(%d)",
  2074. SLAC_INFO.arrayLen);
  2075. DEBUG_PRINTF_EVCOMM_DETAIL(buf_log_evcomm);
  2076. SLAC_INFO.arrayLen = 0;
  2077. }
  2078. }
  2079. else
  2080. {
  2081. //DB is full
  2082. sprintf(buf_log_evcomm,
  2083. "[SLAC_DB_Add]DB is full(%d) => bypass",
  2084. SLAC_INFO.arrayLen);
  2085. DEBUG_PRINTF_EVCOMM_DETAIL(buf_log_evcomm);
  2086. }
  2087. }
  2088. else
  2089. {
  2090. #if 0
  2091. sprintf(buf_log_evcomm,
  2092. "[SLAC_DB_Add]EvMac: existed (%d)",
  2093. idx);
  2094. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2095. #endif
  2096. //Check RunID
  2097. if (Array_Compare_Identity(SLAC_INFO.array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH) == TRUE)
  2098. {
  2099. //RunID is the same
  2100. //SAVE_SYS_LOG_MSG_EVCOMM("[SLAC_DB_Add]RunID: same");
  2101. }
  2102. else
  2103. {
  2104. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC_DB_Add]RunID: diff");
  2105. }
  2106. //Reset all corresponding parameters
  2107. #if 0
  2108. sprintf(buf_log_evcomm,
  2109. "[SLAC_DB_Add]EvMac: reset para(%d)",
  2110. idx);
  2111. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2112. #endif
  2113. memset(&SLAC_INFO.array[idx], 0, sizeof(struct EVCC_SLAC_DATA_ARRAY_TYPE));
  2114. memcpy(SLAC_INFO.array[idx].EvMac, EvMac_in, SLAC_EVMAC_LENGTH);
  2115. memcpy(SLAC_INFO.array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2116. }
  2117. return idx;
  2118. }
  2119. /*===========================================================================
  2120. FUNCTION: SLAC_DB_Reset
  2121. DESCRIPTION:
  2122. PRE-CONDITION:
  2123. INPUT:
  2124. OUTPUT:
  2125. GLOBAL VARIABLES:
  2126. =============================================================================*/
  2127. int SLAC_DB_Reset()
  2128. {
  2129. memset(&SLAC_INFO, 0, sizeof(struct EVCC_SLAC_DATA_TYPE));
  2130. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC_DB_Reset]DONE");
  2131. }
  2132. /*===========================================================================
  2133. FUNCTION: MmeProcess
  2134. DESCRIPTION:
  2135. PRE-CONDITION:
  2136. INPUT:
  2137. OUTPUT:
  2138. GLOBAL VARIABLES:
  2139. =============================================================================*/
  2140. int MmeProcess(unsigned char *Buffer, int DataLength)
  2141. {
  2142. //struct ethhdr *EthPacket;
  2143. struct MmeHeader *MmePacket;
  2144. static unsigned char counter;
  2145. unsigned char state = 0;
  2146. unsigned char *EvMac_in;
  2147. unsigned char *RunID_in;
  2148. int Rtn = 0;
  2149. int idx = 0;
  2150. MmePacket = (struct MmeHeader *)Buffer;
  2151. state = Check_V2G_Flow_Status();
  2152. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2153. {
  2154. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***********************************\n");
  2155. DEBUG_PRINTF_EVCOMM_DETAIL("***** Received MME Packet *****\n");
  2156. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  2157. DEBUG_PRINTF_EVCOMM_DETAIL("DataLength=%d\n",DataLength);
  2158. DEBUG_PRINTF_EVCOMM_DETAIL("ODA: %02x:%02x:%02x:%02x:%02x:%02x\n", //Destination MAC Address
  2159. MmePacket->ODA[0], MmePacket->ODA[1],
  2160. MmePacket->ODA[2], MmePacket->ODA[3],
  2161. MmePacket->ODA[4], MmePacket->ODA[5]);
  2162. DEBUG_PRINTF_EVCOMM_DETAIL("OSA: %02x:%02x:%02x:%02x:%02x:%02x\n", //Source MAC Address (EV MAC)
  2163. MmePacket->OSA[0], MmePacket->OSA[1],
  2164. MmePacket->OSA[2], MmePacket->OSA[3],
  2165. MmePacket->OSA[4], MmePacket->OSA[5]);
  2166. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(MmePacket->MTYPE));
  2167. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", MmePacket->MMV);
  2168. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", MmePacket->MMTYPE);
  2169. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n",
  2170. MmePacket->FMI[0],MmePacket->FMI[1]);
  2171. }
  2172. #endif
  2173. #if (SLAC_FIRST_RESPONSE_METHOD == SET_NO_PWM_IF_NOT_GET_PERMISSION)
  2174. {
  2175. //Check CP as 5%
  2176. if (EVCOMM_SYS_INFO.CpState != 3 &&
  2177. EVCOMM_SYS_INFO.CpState != 4 &&
  2178. MmePacket->MMTYPE != MMTYPE_CM_SET_KEY_CNF &&
  2179. MmePacket->MMTYPE != MMTYPE_VENDOR_VS_HOST_ACTION &&
  2180. MmePacket->MMTYPE != MMTYPE_VENDOR_ATTEN_CHAR &&
  2181. MmePacket->MMTYPE != MMTYPE_VENDOR_VS_NW_INFO_CNF
  2182. )
  2183. {
  2184. //SAVE_SYS_LOG_MSG_EVCOMM("[SLAC]ignored(wrong CP state)");
  2185. return 0;
  2186. }
  2187. }
  2188. #endif
  2189. //[To-Do] Adding a pre-check filter mechanism for Source and Destination MAC Address
  2190. //check if the destination address is broadcast or EVSE itself, it can be ignore if not belong to itself.
  2191. switch(MmePacket->MMTYPE)
  2192. {
  2193. case MMTYPE_CM_SET_KEY_CNF:
  2194. {
  2195. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SET_KEY_CNF ---\n");
  2196. DEBUG_PRINTF_EVCOMM_DETAIL("Result: 0x%x\n", MmePacket->MMENTRY[0]);
  2197. SAVE_SYS_LOG_MSG_EVCOMM("[QCA7K][Rx]CM_SET_KEY_CNF (SetKey: DONE)");
  2198. Update_V2G_Flow_Status(CM_SET_KEY_CNF);
  2199. break;
  2200. }
  2201. case MMTYPE_CM_SLAC_PARM_REQ:
  2202. {
  2203. //Check QCA7000 status
  2204. if (EVCOMM_SYS_INFO.QCA7K_SetKeyDone == FALSE)
  2205. {
  2206. //SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx]CM_SLAC_PARM_REQ: ignored(QCA7K init...)");
  2207. break;
  2208. }
  2209. //Check error state
  2210. state = Check_V2G_Flow_Status();
  2211. if (state == Performance_Timeout || //253
  2212. state == Sequence_Timeout || //254
  2213. state == Other_Fault) //255
  2214. {
  2215. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx]CM_SLAC_PARM_REQ: ignored(in error state)");
  2216. break;
  2217. }
  2218. //Printing EV MAC Address
  2219. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx]CM_SLAC_PARM_REQ");
  2220. //Avoid Coupled SLAC_PARM_REQ
  2221. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2222. {
  2223. #if 0
  2224. sprintf(buf_log_evcomm,
  2225. "[WARNING][SLAC][Rx]CM_SLAC_PARM_REQ: ignored(coupled SLAC,%d)",
  2226. CheckConnectorPlugIn());
  2227. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2228. #endif
  2229. break;
  2230. }
  2231. //[TC_SECC_VTB_CmSlacParm_003] SECURITY_TYPE needs to be 0x00 (no security)
  2232. if (MmePacket->MMENTRY[1] != 0)
  2233. {
  2234. sprintf(buf_log_evcomm,
  2235. "[WARNING][SLAC][Rx]CM_SLAC_PARM_REQ: ignored(invalid SECURITY_TYPE,%d)", //Source MAC Address (EV MAC)
  2236. MmePacket->MMENTRY[1]);
  2237. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2238. break;
  2239. }
  2240. //=================== Legal CM_SLAC_PARM_REQ Zone =================
  2241. Update_V2G_Flow_Status(CM_SLAC_PARM_REQ);
  2242. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_RX_CM_SLAC_PARM_REQ)
  2243. {
  2244. //Once receiving CM_SLAC_PARM_REQ, set PWM as 5%
  2245. SwitchCpStateE(DISABLE);
  2246. OutputCpPwmDuty(5);
  2247. }
  2248. #endif
  2249. //Checking if this SLAC Req comes before 5% PWM (for 15118)
  2250. if(ShmInternalComm->ChargingPermission == FALSE)
  2251. {
  2252. //Sniffer_Tcpdump(ENABLE);
  2253. sprintf(buf_log_evcomm, "Check Permission: %d (SLAC first => START)", ShmInternalComm->ChargingPermission);
  2254. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2255. }
  2256. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2257. {
  2258. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SLAC_PARM_REQ ---\n");
  2259. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2260. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2261. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2262. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2263. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2264. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2265. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2266. DEBUG_PRINTF_EVCOMM_DETAIL("CipherSuiteSetSize: 0x%x\n", MmePacket->MMENTRY[10]);
  2267. DEBUG_PRINTF_EVCOMM_DETAIL("CipherSuite [1]: 0x%x,0x%x\n",
  2268. MmePacket->MMENTRY[11], MmePacket->MMENTRY[12]);
  2269. }
  2270. #endif
  2271. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2272. {
  2273. //Saving each CM_SLAC_PARM_REQ data into EVCC database
  2274. EvMac_in = &MmePacket->OSA[0];
  2275. RunID_in = &MmePacket->MMENTRY[2];
  2276. idx = SLAC_DB_Add(EvMac_in, RunID_in); //(EvMac, RunID)
  2277. if (idx < 0)
  2278. {
  2279. sprintf(buf_log_evcomm,
  2280. "[WARNING][CM_SLAC_PARM_REQ]DB is full or errors occour(%d) => ignore",
  2281. idx);
  2282. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2283. break;
  2284. }
  2285. //Select the 1st EV MAC address
  2286. if (SLAC_INFO.arrayLen == 1) //1st Req
  2287. {
  2288. #if 1
  2289. sprintf(buf_log_evcomm,
  2290. "[SLAC][Rx]CM_SLAC_PARM_REQ[%d](%02X:%02X:%02X:%02X:%02X:%02X,%02X%02X%02X%02X%02X%02X%02X%02X):selected",
  2291. (idx + 1),
  2292. MmePacket->OSA[0], MmePacket->OSA[1], MmePacket->OSA[2], MmePacket->OSA[3], MmePacket->OSA[4], MmePacket->OSA[5],
  2293. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3], MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2294. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7], MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2295. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2296. #endif
  2297. /*
  2298. sprintf(buf_log_evcomm,
  2299. "[SLAC][EVMAC][%d-th]%02X:%02X:%02X:%02X:%02X:%02X (selected)", //Source MAC Address (EV MAC)
  2300. SLAC_INFO.arrayLen,
  2301. MmePacket->OSA[0], MmePacket->OSA[1],
  2302. MmePacket->OSA[2], MmePacket->OSA[3],
  2303. MmePacket->OSA[4], MmePacket->OSA[5]);
  2304. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2305. sprintf(buf_log_evcomm,
  2306. "[SLAC][RunID][%d-th]%02X%02X%02X%02X%02X%02X%02X%02X (selected)", //RunID (from EVCC)
  2307. SLAC_INFO.arrayLen,
  2308. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2309. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2310. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2311. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2312. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2313. */
  2314. }
  2315. else //2nd Req
  2316. {
  2317. #if 1
  2318. sprintf(buf_log_evcomm,
  2319. "[SLAC][Rx]CM_SLAC_PARM_REQ[%d](%02X:%02X:%02X:%02X:%02X:%02X,%02X%02X%02X%02X%02X%02X%02X%02X):not selected",
  2320. (idx + 1),
  2321. MmePacket->OSA[0], MmePacket->OSA[1], MmePacket->OSA[2], MmePacket->OSA[3], MmePacket->OSA[4], MmePacket->OSA[5],
  2322. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3], MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2323. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7], MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2324. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2325. #endif
  2326. /*
  2327. sprintf(buf_log_evcomm,
  2328. "[SLAC][EVMAC][%d-th]%02X:%02X:%02X:%02X:%02X:%02X (not selected)", //Source MAC Address (EV MAC)
  2329. SLAC_INFO.arrayLen,
  2330. MmePacket->OSA[0], MmePacket->OSA[1],
  2331. MmePacket->OSA[2], MmePacket->OSA[3],
  2332. MmePacket->OSA[4], MmePacket->OSA[5]);
  2333. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2334. sprintf(buf_log_evcomm,
  2335. "[SLAC][RunID][%d-th]%02X%02X%02X%02X%02X%02X%02X%02X (not selected)", //RunID (from EVCC)
  2336. SLAC_INFO.arrayLen,
  2337. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2338. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2339. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2340. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2341. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2342. */
  2343. }
  2344. memcpy(EvMac, MmePacket->OSA, sizeof(EvMac));
  2345. memcpy(DestSocketAddress.sll_addr, MmePacket->OSA, SLAC_EVMAC_LENGTH);
  2346. memcpy(SlacRunId, MmePacket->MMENTRY + 2, SLAC_RUNID_LENGTH);
  2347. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2348. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  2349. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2350. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2351. SendMmePacket.MMV = MmePacket->MMV;
  2352. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_PARM_CNF;
  2353. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2354. SendMmePacketSize = 0;
  2355. memset(SendMmePacket.MMENTRY, 0xFF, 6); //M-SOUND_TARGET(6-byte:0xFFFFFFFFFFFF): Fixed value indicating that M-Sounds to be sent as Ethernet broadcast
  2356. SendMmePacketSize += 6;
  2357. 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
  2358. SendMmePacket.MMENTRY[SendMmePacketSize++] = 6; //Time_Out(0x06): unit = 100ms
  2359. 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
  2360. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SLAC_INFO.array[idx].EvMac, 6); //FORWARDING_STA(MAC Address of the EV HLE)
  2361. SendMmePacketSize += 6;
  2362. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00): 0x00(PEV-EVSE Association), 0x01-0xFF(Reserved)
  2363. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00): 0x00(No Security), 0x01(Public Key Signature), 0x02-0xFF(Reserved)
  2364. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SlacRunId, SLAC_RUNID_LENGTH); //RunID (8-byte)
  2365. SendMmePacketSize += SLAC_RUNID_LENGTH;
  2366. SendMmePacketSize += 19; //the size before MMENTRY
  2367. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2368. {
  2369. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  2370. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2371. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  2372. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2373. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  2374. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  2375. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  2376. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  2377. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  2378. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_PARM_CNF ---\n");
  2379. DEBUG_PRINTF_EVCOMM_DETAIL("M-SOUND_TARGET: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2380. SendMmePacket.MMENTRY[0],SendMmePacket.MMENTRY[1],SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],
  2381. SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5]);
  2382. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", SendMmePacket.MMENTRY[6]);
  2383. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out: 0x%x\n", SendMmePacket.MMENTRY[7]);
  2384. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE: 0x%x\n", SendMmePacket.MMENTRY[8]);
  2385. DEBUG_PRINTF_EVCOMM_DETAIL("M-FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2386. SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],SendMmePacket.MMENTRY[12],
  2387. SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14]);
  2388. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[15]);
  2389. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[16]);
  2390. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2391. SendMmePacket.MMENTRY[17],SendMmePacket.MMENTRY[18],SendMmePacket.MMENTRY[19],SendMmePacket.MMENTRY[20],
  2392. SendMmePacket.MMENTRY[21],SendMmePacket.MMENTRY[22],SendMmePacket.MMENTRY[23],SendMmePacket.MMENTRY[24]);
  2393. }
  2394. #endif
  2395. Update_V2G_Flow_Status(CM_SLAC_PARM_CONF);
  2396. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2397. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  2398. ftime(&SeqStartTime);
  2399. break;
  2400. }
  2401. #else
  2402. {
  2403. memcpy(EvMac, MmePacket->OSA, sizeof(EvMac));
  2404. memcpy(DestSocketAddress.sll_addr, MmePacket->OSA, sizeof(EvMac));
  2405. memcpy(SlacRunId,MmePacket->MMENTRY + 2, sizeof(SlacRunId));
  2406. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2407. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  2408. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2409. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2410. SendMmePacket.MMV = MmePacket->MMV;
  2411. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_PARM_CNF;
  2412. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2413. SendMmePacketSize = 0;
  2414. memset(SendMmePacket.MMENTRY, 0xFF, 6); //M-SOUND_TARGET(6-byte:0xFFFFFFFFFFFF): Fixed value indicating that M-Sounds to be sent as Ethernet broadcast
  2415. SendMmePacketSize += 6;
  2416. 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
  2417. SendMmePacket.MMENTRY[SendMmePacketSize++] = 6; //Time_Out(0x06): unit = 100ms
  2418. 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
  2419. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac, 6); //FORWARDING_STA(MAC Address of the EV HLE)
  2420. SendMmePacketSize += 6;
  2421. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00): 0x00(PEV-EVSE Association), 0x01-0xFF(Reserved)
  2422. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00): 0x00(No Security), 0x01(Public Key Signature), 0x02-0xFF(Reserved)
  2423. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SlacRunId, sizeof(SlacRunId)); //RunID (8-byte)
  2424. SendMmePacketSize += sizeof(SlacRunId);
  2425. SendMmePacketSize += 19; //the size before MMENTRY
  2426. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2427. {
  2428. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  2429. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2430. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  2431. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2432. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  2433. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  2434. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  2435. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  2436. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  2437. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_PARM_CNF ---\n");
  2438. DEBUG_PRINTF_EVCOMM_DETAIL("M-SOUND_TARGET: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2439. SendMmePacket.MMENTRY[0],SendMmePacket.MMENTRY[1],SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],
  2440. SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5]);
  2441. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", SendMmePacket.MMENTRY[6]);
  2442. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out: 0x%x\n", SendMmePacket.MMENTRY[7]);
  2443. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE: 0x%x\n", SendMmePacket.MMENTRY[8]);
  2444. DEBUG_PRINTF_EVCOMM_DETAIL("M-FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2445. SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],SendMmePacket.MMENTRY[12],
  2446. SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14]);
  2447. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[15]);
  2448. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[16]);
  2449. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2450. SendMmePacket.MMENTRY[17],SendMmePacket.MMENTRY[18],SendMmePacket.MMENTRY[19],SendMmePacket.MMENTRY[20],
  2451. SendMmePacket.MMENTRY[21],SendMmePacket.MMENTRY[22],SendMmePacket.MMENTRY[23],SendMmePacket.MMENTRY[24]);
  2452. }
  2453. #endif
  2454. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2455. Update_V2G_Flow_Status(CM_SLAC_PARM_CONF);
  2456. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  2457. ftime(&SeqStartTime);
  2458. counter = 0;
  2459. break;
  2460. }
  2461. #endif
  2462. }
  2463. case MMTYPE_CM_START_ATTEN_CHAR_IND:
  2464. {
  2465. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2466. {
  2467. SAVE_SYS_LOG_MSG_EVCOMM("[WARNING][SLAC][Rx]CM_START_ATTEN_CHAR_IND: ignored(timeup)");
  2468. break;
  2469. }
  2470. //Avoid Coupled CM_START_ATTEN_CHAR_IND
  2471. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2472. {
  2473. sprintf(buf_log_evcomm,
  2474. "[WARNING][SLAC][Rx]CM_START_ATTEN_CHAR_IND: ignored(coupled SLAC,%d)",
  2475. CheckConnectorPlugIn());
  2476. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2477. break;
  2478. }
  2479. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2480. {
  2481. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_START_ATTEN_CHAR_IND (counter : %d/3 ) ---\n",counter + 1);
  2482. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2483. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2484. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", MmePacket->MMENTRY[2]);
  2485. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out 0x%x\n", MmePacket->MMENTRY[3]);
  2486. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE 0x%x\n", MmePacket->MMENTRY[4]); //Fixed value (0x01) indicating other Green PHY station
  2487. DEBUG_PRINTF_EVCOMM_DETAIL("FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2488. MmePacket->MMENTRY[5],MmePacket->MMENTRY[6],MmePacket->MMENTRY[7],MmePacket->MMENTRY[8],
  2489. MmePacket->MMENTRY[9],MmePacket->MMENTRY[10]);
  2490. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2491. MmePacket->MMENTRY[11],MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],MmePacket->MMENTRY[14],
  2492. MmePacket->MMENTRY[15],MmePacket->MMENTRY[16],MmePacket->MMENTRY[17],MmePacket->MMENTRY[18]);
  2493. }
  2494. #endif
  2495. //New SLAC architecture designed by Joseph
  2496. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2497. {
  2498. EvMac_in = &MmePacket->OSA[0];
  2499. RunID_in = &MmePacket->MMENTRY[11];
  2500. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2501. if (idx >= 0)
  2502. {
  2503. Update_V2G_Flow_Status(CM_START_ATTEN_CHAR_IND);
  2504. //[TC_SECC_VTB_AttenuationCharacterization_013]
  2505. if (MmePacket->MMENTRY[0] != 0) //APPLICATION_TYPE must be 0x00(EV-EVSE Matching)
  2506. {
  2507. sprintf(buf_log_evcomm,
  2508. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]APPLICATION_TYPE(%d): invalid => ignore Req",
  2509. MmePacket->MMENTRY[0]);
  2510. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2511. break;
  2512. }
  2513. //[TC_SECC_VTB_AttenuationCharacterization_014]
  2514. if (MmePacket->MMENTRY[1] != 0) //SECURITY_TYPE must be 0x00(No Security)
  2515. {
  2516. sprintf(buf_log_evcomm,
  2517. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]SECURITY_TYPE(%d): invalid => ignore Req",
  2518. MmePacket->MMENTRY[1]);
  2519. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2520. break;
  2521. }
  2522. //[TC_SECC_VTB_AttenuationCharacterization_017]
  2523. if (MmePacket->MMENTRY[4] != 0x01) //RESP_TYPE must be 0x01(Send to another GP STA(EV))
  2524. {
  2525. sprintf(buf_log_evcomm,
  2526. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]RESP_TYPE(%d): invalid => ignore Req",
  2527. MmePacket->MMENTRY[4]);
  2528. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2529. break;
  2530. }
  2531. //[TC_SECC_VTB_AttenuationCharacterization_021]
  2532. //FORWARDING_STA: MAC Address of the EV HLE (station which the measurement results shall be sent to)
  2533. if (Array_Compare_Identity(EvMac_in, &MmePacket->MMENTRY[5], SLAC_EVMAC_LENGTH) == FALSE)
  2534. {
  2535. sprintf(buf_log_evcomm,
  2536. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]FORWARDING_STA(%02X:%02X:%02X:%02X:%02X:%02X): invalid => ignore Req",
  2537. MmePacket->MMENTRY[5], MmePacket->MMENTRY[6],
  2538. MmePacket->MMENTRY[7], MmePacket->MMENTRY[8],
  2539. MmePacket->MMENTRY[9], MmePacket->MMENTRY[10]);
  2540. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2541. SLAC_INFO.array[idx].StartAttenCharErr = TRUE;
  2542. break;
  2543. }
  2544. //Check RunID
  2545. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE)
  2546. {
  2547. SLAC_INFO.array[idx].MnbcSoundNum = MmePacket->MMENTRY[2];
  2548. SLAC_INFO.array[idx].StartAttenCharCnt++;
  2549. #if 0
  2550. sprintf(buf_log_evcomm,
  2551. "[SLAC][Rx]CM_START_ATTEN_CHAR_IND[%d]:%d-th",
  2552. (idx + 1),
  2553. SLAC_INFO.array[idx].StartAttenCharCnt);
  2554. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2555. #endif
  2556. if (SLAC_INFO.array[idx].StartAttenCharCnt == 1)
  2557. {
  2558. memset(SLAC_INFO.array[idx].AAG, 0, sizeof(SLAC_INFO.array[idx].AAG));
  2559. SLAC_INFO.array[idx].AttenProfileCnt = 0;
  2560. ftime(&SeqStartTime); //start TT_EVSE_match_MNBC
  2561. }
  2562. else if (SLAC_INFO.array[idx].StartAttenCharCnt >= 3)
  2563. {
  2564. sprintf(buf_log_evcomm,
  2565. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]counter(%d): unexpected",
  2566. SLAC_INFO.array[idx].StartAttenCharCnt);
  2567. }
  2568. else
  2569. {
  2570. //null
  2571. }
  2572. }
  2573. else
  2574. {
  2575. //This RunID is not matched with this EvMac,
  2576. //or this RunID is not found in DB.
  2577. sprintf(buf_log_evcomm,
  2578. "[WARNING][SLAC][Rx][CM_START_ATTEN_CHAR_IND]EvMac-RunID: unmatched => ignore Req");
  2579. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2580. //Response: ignore
  2581. }
  2582. }
  2583. else
  2584. {
  2585. //this msg source is not in database
  2586. //ignore
  2587. }
  2588. break;
  2589. }
  2590. #else //Old SLAC architecture designed by Vern
  2591. {
  2592. MnbcSoundNum = MmePacket->MMENTRY[2];
  2593. Update_V2G_Flow_Status(CM_START_ATTEN_CHAR_IND);
  2594. counter++;
  2595. if(counter == 1)
  2596. {
  2597. memset(Aag, 0, sizeof(Aag));
  2598. AttenProfileCnt = 0;
  2599. ftime(&SeqStartTime); //start TT_EVSE_match_MNBC
  2600. }
  2601. else if(counter >= 3)
  2602. {
  2603. counter = 0;
  2604. }
  2605. break;
  2606. }
  2607. #endif
  2608. }
  2609. case MMTYPE_CM_MNBC_SOUND_IND:
  2610. {
  2611. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2612. {
  2613. SAVE_SYS_LOG_MSG_EVCOMM("[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND: ignored(timeup)");
  2614. break;
  2615. }
  2616. //Avoid Coupled CM_MNBC_SOUND_IND
  2617. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2618. {
  2619. sprintf(buf_log_evcomm,
  2620. "[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND: ignored(coupled SLAC,%d)",
  2621. CheckConnectorPlugIn());
  2622. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2623. break;
  2624. }
  2625. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == TRUE)
  2626. {
  2627. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_MNBC_SOUND_IND (counter : %d/%d) ---\n",counter + 1 , MnbcSoundNum);
  2628. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2629. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2630. DEBUG_PRINTF_EVCOMM_DETAIL("SenderID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2631. MmePacket->MMENTRY[2],MmePacket->MMENTRY[3],MmePacket->MMENTRY[4],MmePacket->MMENTRY[5],
  2632. MmePacket->MMENTRY[6],MmePacket->MMENTRY[7],MmePacket->MMENTRY[8],MmePacket->MMENTRY[9],
  2633. MmePacket->MMENTRY[10],MmePacket->MMENTRY[11],MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],
  2634. MmePacket->MMENTRY[14],MmePacket->MMENTRY[15],MmePacket->MMENTRY[16],MmePacket->MMENTRY[17],
  2635. MmePacket->MMENTRY[18]);
  2636. DEBUG_PRINTF_EVCOMM_DETAIL("Cnt: 0x%x\n", MmePacket->MMENTRY[19]);
  2637. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2638. MmePacket->MMENTRY[20],MmePacket->MMENTRY[21],MmePacket->MMENTRY[22],MmePacket->MMENTRY[23],
  2639. MmePacket->MMENTRY[24],MmePacket->MMENTRY[25],MmePacket->MMENTRY[26],MmePacket->MMENTRY[27]);
  2640. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2641. MmePacket->MMENTRY[28],MmePacket->MMENTRY[29],MmePacket->MMENTRY[30],MmePacket->MMENTRY[31],
  2642. MmePacket->MMENTRY[32],MmePacket->MMENTRY[33],MmePacket->MMENTRY[34],MmePacket->MMENTRY[35]);
  2643. DEBUG_PRINTF_EVCOMM_DETAIL("Rnd: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2644. MmePacket->MMENTRY[36],MmePacket->MMENTRY[37],MmePacket->MMENTRY[38],MmePacket->MMENTRY[39],
  2645. MmePacket->MMENTRY[40],MmePacket->MMENTRY[41],MmePacket->MMENTRY[42],MmePacket->MMENTRY[43],
  2646. MmePacket->MMENTRY[44],MmePacket->MMENTRY[45],MmePacket->MMENTRY[46],MmePacket->MMENTRY[47],
  2647. MmePacket->MMENTRY[48],MmePacket->MMENTRY[49],MmePacket->MMENTRY[50],MmePacket->MMENTRY[51]);
  2648. }
  2649. #endif
  2650. //New SLAC architecture designed by Joseph
  2651. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2652. {
  2653. EvMac_in = &MmePacket->OSA[0];
  2654. RunID_in = &MmePacket->MMENTRY[20];
  2655. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2656. if (idx >= 0)
  2657. {
  2658. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2659. //Check for RunID
  2660. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE)
  2661. {
  2662. SLAC_INFO.array[idx].MnbcSoundCnt++;
  2663. /*
  2664. sprintf(buf_log_evcomm,
  2665. "[SLAC][Rx]CM_MNBC_SOUND_IND[%d]:%d-th",
  2666. (idx + 1),
  2667. SLAC_INFO.array[idx].MnbcSoundCnt);
  2668. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2669. */
  2670. }
  2671. else
  2672. {
  2673. //RunID is not matched or does not exist.
  2674. sprintf(buf_log_evcomm,
  2675. "[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND]EvMac-RunID: unmatched");
  2676. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2677. }
  2678. }
  2679. else
  2680. {
  2681. //ignore
  2682. sprintf(buf_log_evcomm,
  2683. "[WARNING][SLAC][Rx]CM_MNBC_SOUND_IND]EvMac does not exist");
  2684. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2685. }
  2686. break;
  2687. }
  2688. #else //Old SLAC architecture designed by Vern
  2689. {
  2690. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2691. counter++;
  2692. break;
  2693. }
  2694. #endif
  2695. }
  2696. case MMTYPE_CM_ATTEN_PROFILE_IND:
  2697. {
  2698. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2699. {
  2700. SAVE_SYS_LOG_MSG_EVCOMM("[WARNING][SLAC][Rx]CM_ATTEN_PROFILE_IND: ignore(timeup)");
  2701. break;
  2702. }
  2703. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == TRUE)
  2704. {
  2705. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_ATTEN_PROFILE_IND (counter : %d/%d) ---\n", counter, MnbcSoundNum);
  2706. DEBUG_PRINTF_EVCOMM_DETAIL("EV MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2707. MmePacket->MMENTRY[0], MmePacket->MMENTRY[1], MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2708. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5]);
  2709. DEBUG_PRINTF_EVCOMM_DETAIL("NumGroups: 0x%x\n", MmePacket->MMENTRY[6]); //NumGroups, Number of AAG Groups (ex: 0x3A = 58)
  2710. //NumGroups: Number of OFDM carrier groups used for the SLAC signal characterization.
  2711. //AAG[i]: Average Attenuation of Group i (i = 1 ~ 58)
  2712. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", MmePacket->MMENTRY[7]);
  2713. DEBUG_PRINTF_EVCOMM_DETAIL("AAG: \n");
  2714. for(Rtn = 0; Rtn < MmePacket->MMENTRY[6]; Rtn++)
  2715. {
  2716. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[8 + Rtn]);
  2717. }
  2718. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  2719. }
  2720. #endif
  2721. //New SLAC architecture designed by Joseph
  2722. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2723. {
  2724. EvMac_in = &MmePacket->MMENTRY[0]; //[CAUTION] The EvMac address is not &MmePacket->OSA[0]
  2725. //[CAUTION] There is no RunID information of CM_ATTEN_PROFILE_IND
  2726. // packet, which means SECC cannot use the RunID to
  2727. // distinguish those SLAC request with identical EvMac
  2728. // but with different RunID.
  2729. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2730. /*
  2731. printf("%d, %d, %d, %d\n",
  2732. idx,
  2733. SLAC_INFO.array[idx].AagGroupsNum,
  2734. MmePacket->MMENTRY[6],
  2735. SLAC_INFO.array[idx].AttenProfileCnt);
  2736. */
  2737. if (idx >= 0)
  2738. {
  2739. SLAC_INFO.array[idx].AttenProfileCnt++;
  2740. /*
  2741. sprintf(buf_log_evcomm,
  2742. "[SLAC][Rx]CM_ATTEN_PROFILE_IND[%d]:%d-th",
  2743. (idx + 1),
  2744. SLAC_INFO.array[idx].AttenProfileCnt);
  2745. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2746. */
  2747. //printf("%d, %d\n", SLAC_INFO.array[idx].AagGroupsNum, MmePacket->MMENTRY[6]);
  2748. SLAC_INFO.array[idx].AagGroupsNum = MmePacket->MMENTRY[6];
  2749. ////NumGroups, Number of AAG Groups (ex: 0x3A = 58)
  2750. for(Rtn = 0; Rtn < SLAC_INFO.array[idx].AagGroupsNum; Rtn++) //ex:58
  2751. {
  2752. SLAC_INFO.array[idx].AAG[Rtn] += MmePacket->MMENTRY[8 + Rtn];
  2753. }
  2754. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2755. break;
  2756. }
  2757. else
  2758. {
  2759. //The EvMac is not in the database
  2760. //ignore
  2761. sprintf(buf_log_evcomm,
  2762. "[SLAC][Rx][CM_ATTEN_PROFILE_IND]EvMac(%02X%02X%02X%02X%02X%02X): not exist => ignore",
  2763. EvMac_in[0], EvMac_in[1], EvMac_in[2], EvMac_in[3], EvMac_in[4], EvMac_in[5]);
  2764. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2765. break;
  2766. }
  2767. }
  2768. #else //Old SLAC architecture designed by Vern
  2769. {
  2770. AagGroupsNum = MmePacket->MMENTRY[6];
  2771. for(Rtn = 0; Rtn < MmePacket->MMENTRY[6]; Rtn++)
  2772. {
  2773. Aag[Rtn] += MmePacket->MMENTRY[8 + Rtn];
  2774. }
  2775. AttenProfileCnt++;
  2776. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2777. break;
  2778. }
  2779. #endif
  2780. }
  2781. case MMTYPE_CM_ATTEN_CHAR_RSP:
  2782. {
  2783. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2784. {
  2785. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_ATTEN_CHAR_RSP ---\n");
  2786. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2787. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2788. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2789. MmePacket->MMENTRY[2],MmePacket->MMENTRY[3],MmePacket->MMENTRY[4],MmePacket->MMENTRY[5],
  2790. MmePacket->MMENTRY[6],MmePacket->MMENTRY[7]);
  2791. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2792. MmePacket->MMENTRY[8],MmePacket->MMENTRY[9],MmePacket->MMENTRY[10],MmePacket->MMENTRY[11],
  2793. MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],MmePacket->MMENTRY[14],MmePacket->MMENTRY[15]);
  2794. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: \n");
  2795. for(Rtn = 0; Rtn < 17; Rtn++)
  2796. {
  2797. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[16 + Rtn]);
  2798. }
  2799. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  2800. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: \n");
  2801. for(Rtn = 0; Rtn < 17; Rtn++)
  2802. {
  2803. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[33 + Rtn]);
  2804. }
  2805. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  2806. DEBUG_PRINTF_EVCOMM_DETAIL("Result: 0x%x\n", MmePacket->MMENTRY[50]); //Fixed value of 0x00 indicates a successful SLAC process
  2807. }
  2808. #endif
  2809. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2810. {
  2811. //Check ODA (Destination Address)
  2812. if (Array_Compare_Identity(CsuMac, MmePacket->ODA, SLAC_EVSE_MAC_LENGTH) == FALSE)
  2813. {
  2814. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx][CM_ATTEN_CHAR_RSP]wrong ODA: ignore");
  2815. break;
  2816. }
  2817. EvMac_in = &MmePacket->OSA[0];
  2818. RunID_in = &MmePacket->MMENTRY[8];
  2819. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2820. //Check Parameters
  2821. if ((MmePacket->MMENTRY[0] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_005] applicationType must be 0x00
  2822. (MmePacket->MMENTRY[1] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_006] securityType must be 0x00
  2823. (SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in) < 0) || //[TC_SECC_VTB_AttenuationCharacterization_007] sourceAddress cannot not be all zero
  2824. (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_008] check for invalid runID
  2825. (Array_Check_All_Zero(&MmePacket->MMENTRY[16], 17) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_009] SourceID(17 bytes) must be all zero.
  2826. (Array_Check_All_Zero(&MmePacket->MMENTRY[33], 17) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_009] RESP_ID (17 bytes) must be all zero.
  2827. (MmePacket->MMENTRY[50] != 0) //Result: must be 0x00(Success)
  2828. )
  2829. {
  2830. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry++;
  2831. sprintf(buf_log_evcomm,
  2832. "[WARNING][SLAC][Rx]CM_ATTEN_CHAR_RSP:invalid para(%d,%d,%d,%d,%d) => %d-th retry",
  2833. MmePacket->MMENTRY[0], //applicationType must be 0x00
  2834. MmePacket->MMENTRY[1], //securityType must be 0x00
  2835. SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in),
  2836. SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in),
  2837. MmePacket->MMENTRY[50],
  2838. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry
  2839. );
  2840. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2841. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry <= 2) //limited to 2 retries
  2842. {
  2843. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2844. ftime(&SeqStartTime);
  2845. break;
  2846. }
  2847. else
  2848. {
  2849. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR][SLAC][Rx]CM_ATTEN_CHAR_RSP:invalid para => 2-retry fail => End_Process");
  2850. Update_V2G_Flow_Status(Other_Fault);
  2851. break;
  2852. }
  2853. }
  2854. else
  2855. {
  2856. //The CM_ATTEN_CHAR_IND is legal
  2857. SLAC_INFO.array[idx].AttenCharRspCnt++;
  2858. sprintf(buf_log_evcomm,
  2859. "[SLAC][Rx]CM_ATTEN_CHAR_RSP[%d]:%d-th",
  2860. (idx + 1),
  2861. SLAC_INFO.array[idx].AttenCharRspCnt);
  2862. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2863. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry = 0;
  2864. Update_V2G_Flow_Status(CM_ATTEN_CHAR_RSP);
  2865. ftime(&SeqStartTime);
  2866. break;
  2867. }
  2868. }
  2869. #else
  2870. {
  2871. //Check Parameters
  2872. if ((MmePacket->MMENTRY[0] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_005] applicationType must be 0x00
  2873. (MmePacket->MMENTRY[1] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_006] securityType must be 0x00
  2874. (Array_Compare_Identity(SLAC_INFO.array[0].EvMac, &MmePacket->MMENTRY[2], 6) == TRUE) || //[TC_SECC_VTB_AttenuationCharacterization_007] sourceAddress cannot not be all zero
  2875. (Array_Compare_Identity(SLAC_INFO.array[0].RunID, &MmePacket->MMENTRY[8], 8) == TRUE) //[TC_SECC_VTB_AttenuationCharacterization_008] check for invalid runID
  2876. )
  2877. {
  2878. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry++;
  2879. sprintf(buf_log_evcomm,
  2880. "[WARNING][SLAC][Rx]CM_ATTEN_CHAR_RSP: invalid parameters(%d-th)",
  2881. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  2882. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2883. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry <= 2) //limited to 2 retries
  2884. {
  2885. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2886. ftime(&SeqStartTime);
  2887. break;
  2888. }
  2889. else
  2890. {
  2891. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]CM_ATTEN_CHAR_RSP: invalid parameters => End_Process");
  2892. Update_V2G_Flow_Status(Other_Fault);
  2893. ftime(&SeqStartTime);
  2894. break;
  2895. }
  2896. }
  2897. else
  2898. {
  2899. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry = 0;
  2900. Update_V2G_Flow_Status(CM_ATTEN_CHAR_RSP);
  2901. ftime(&SeqStartTime);
  2902. break;
  2903. }
  2904. }
  2905. #endif
  2906. }
  2907. case MMTYPE_CM_VALIDATE_REQ: //BCB Toggle
  2908. {
  2909. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2910. {
  2911. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_VALIDATE_REQ ---\n");
  2912. DEBUG_PRINTF_EVCOMM_DETAIL("Signal Type: 0x%x\n", MmePacket->MMENTRY[0]); //Fixed value (0x00) to indicate ��PEV S2 toggles on control pilot line��
  2913. 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.
  2914. 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��.
  2915. }
  2916. #endif
  2917. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2918. {
  2919. counter = 0;
  2920. EvMac_in = &MmePacket->OSA[0];
  2921. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2922. if (idx >= 0)
  2923. {
  2924. Update_V2G_Flow_Status(CM_VALIDATE_CNF);
  2925. SLAC_INFO.array[idx].ValidateReqCnt++;
  2926. sprintf(buf_log_evcomm,
  2927. "[SLAC][Rx]CM_VALIDATE_REQ[%d]:%d-th",
  2928. (idx + 1),
  2929. SLAC_INFO.array[idx].ValidateReqCnt);
  2930. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  2931. //[To-Do] Protection
  2932. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2933. memcpy(SendMmePacket.ODA, EvMac_in, SLAC_EVMAC_LENGTH);
  2934. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2935. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2936. SendMmePacket.MMV = 0x01;
  2937. SendMmePacket.MMTYPE = MMTYPE_CM_VALIDATE_CNF;
  2938. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2939. SendMmePacketSize = 0;
  2940. if(counter == 0)
  2941. {
  2942. //The First MMTYPE_CM_VALIDATE_REQ because Unicast
  2943. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SignalType(0x00): Fixed value to indicate "EV S2 toggles on control pilot line"
  2944. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //ToggleNum(0x00): Fixed value. In the first VALIDATE Request-Response exchange, the ToggleNum field shall be set to zero.
  2945. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  2946. SendMmePacket.MMENTRY[SendMmePacketSize++] = 1; //0x01 = Ready
  2947. #else
  2948. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  2949. #endif
  2950. }
  2951. else
  2952. {
  2953. //The Second MMTYPE_CM_VALIDATE_REQ because Broadcast
  2954. unsigned char PreStatus = 3;
  2955. unsigned char ToggleNum = 0;
  2956. ftime(&SeqStartTime);
  2957. while(1)
  2958. {
  2959. if((EVCOMM_SYS_INFO.CpState == 4) && (PreStatus == 3))
  2960. {
  2961. ToggleNum++;
  2962. PreStatus = 4;
  2963. }
  2964. else
  2965. {
  2966. PreStatus = 3;
  2967. }
  2968. ftime(&SeqEndTime);
  2969. if(DiffTimeb(SeqStartTime, SeqEndTime) >= (SendMmePacket.MMENTRY[1]*100 + 100))
  2970. {
  2971. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate "PEV S2 toggles on control pilot line"
  2972. SendMmePacket.MMENTRY[SendMmePacketSize++] = ToggleNum;
  2973. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  2974. SendMmePacket.MMENTRY[SendMmePacketSize++] = 2; //0x02 = Success
  2975. #else
  2976. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  2977. #endif
  2978. break;
  2979. }
  2980. }
  2981. }
  2982. SendMmePacketSize += 19; //the size before MMENTRY
  2983. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2984. ftime(&SeqStartTime);
  2985. }
  2986. else
  2987. {
  2988. //EvMac does not exist.
  2989. //ignore
  2990. }
  2991. break;
  2992. }
  2993. #else
  2994. {
  2995. counter = 0;
  2996. for(Rtn = 0; Rtn < 6; Rtn++)
  2997. {
  2998. if(MmePacket->ODA[Rtn] != CsuMac[Rtn])
  2999. {
  3000. counter = 1;
  3001. break;
  3002. }
  3003. }
  3004. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3005. memcpy(SendMmePacket.ODA, EvMac,6);
  3006. memcpy(SendMmePacket.OSA, CsuMac,6);
  3007. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3008. SendMmePacket.MMV = 0x01;
  3009. SendMmePacket.MMTYPE = MMTYPE_CM_VALIDATE_CNF;
  3010. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3011. SendMmePacketSize = 0;
  3012. if(counter == 0)
  3013. {
  3014. //The First MMTYPE_CM_VALIDATE_REQ because Unicast
  3015. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate PEV S2 toggles on control pilot line
  3016. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value In the first VALIDATE Request-Response exchange, the ToggleNum field shall be set to zero.
  3017. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  3018. SendMmePacket.MMENTRY[SendMmePacketSize++] = 1; //0x01 = Ready
  3019. #else
  3020. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  3021. #endif
  3022. }
  3023. else
  3024. {
  3025. //The Second MMTYPE_CM_VALIDATE_REQ because Broadcast
  3026. unsigned char PreStatus = 3, ToggleNum = 0;
  3027. ftime(&SeqStartTime);
  3028. while(1)
  3029. {
  3030. ftime(&SeqEndTime);
  3031. if((EVCOMM_SYS_INFO.CpState == 4) && (PreStatus == 3))
  3032. {
  3033. ToggleNum++;
  3034. PreStatus = 4;
  3035. }
  3036. else
  3037. {
  3038. PreStatus = 3;
  3039. }
  3040. if(DiffTimeb(SeqStartTime, SeqEndTime) >= (SendMmePacket.MMENTRY[1]*100 + 100))
  3041. {
  3042. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate ��PEV S2 toggles on control pilot line��
  3043. SendMmePacket.MMENTRY[SendMmePacketSize++] = ToggleNum;
  3044. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  3045. SendMmePacket.MMENTRY[SendMmePacketSize++] = 2; //0x02 = Success
  3046. #else
  3047. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  3048. #endif
  3049. break;
  3050. }
  3051. }
  3052. }
  3053. SendMmePacketSize += 19; //the size before MMENTRY
  3054. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3055. Update_V2G_Flow_Status(CM_VALIDATE_CNF);
  3056. ftime(&SeqStartTime);
  3057. break;
  3058. }
  3059. #endif
  3060. }
  3061. case MMTYPE_CM_SLAC_MATCH_REQ:
  3062. {
  3063. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3064. {
  3065. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SLAC_MATCH_REQ ---\n");
  3066. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  3067. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  3068. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", MmePacket->MMENTRY[2],MmePacket->MMENTRY[3]); //Fixed value (0x3E) for matching
  3069. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3070. for(Rtn=0; Rtn<17; Rtn++)
  3071. {
  3072. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[4+Rtn]);
  3073. }
  3074. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3075. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3076. for(Rtn=0; Rtn<6; Rtn++)
  3077. {
  3078. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[21+Rtn]);
  3079. }
  3080. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3081. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3082. for(Rtn=0; Rtn<17; Rtn++)
  3083. {
  3084. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[27+Rtn]);
  3085. }
  3086. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3087. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3088. for(Rtn=0; Rtn<6; Rtn++)
  3089. {
  3090. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[44+Rtn]);
  3091. }
  3092. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3093. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3094. for(Rtn=0; Rtn<8; Rtn++)
  3095. {
  3096. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[50+Rtn]);
  3097. }
  3098. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3099. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3100. for(Rtn=0; Rtn<8; Rtn++)
  3101. {
  3102. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[58+Rtn]);
  3103. }
  3104. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3105. }
  3106. #endif
  3107. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3108. {
  3109. //SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx]CM_SLAC_MATCH_REQ");
  3110. //Check ODA (Destination Address)
  3111. if (Array_Compare_Identity(CsuMac, MmePacket->ODA, SLAC_EVSE_MAC_LENGTH) == FALSE)
  3112. {
  3113. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx][CM_SLAC_MATCH_REQ]wrong ODA: ignore");
  3114. //break; //patch for DEKRA I2SE EVCC (another EVSE MAC Address protection comes as below.)
  3115. }
  3116. EvMac_in = &MmePacket->OSA[0];
  3117. RunID_in = &MmePacket->MMENTRY[50];
  3118. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  3119. if (idx >= 0)
  3120. {
  3121. Update_V2G_Flow_Status(CM_SLAC_MATCH_REQ);
  3122. SLAC_INFO.array[idx].MatchReqNum++;
  3123. sprintf(buf_log_evcomm,
  3124. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:%d-th",
  3125. (idx + 1),
  3126. SLAC_INFO.array[idx].MatchReqNum);
  3127. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3128. //[TC_SECC_VTB_CmSlacMatch_007] APPLICATION_TYPE must be 0x00(EV-EVSE Matching)
  3129. //[TC_SECC_VTB_CmSlacMatch_008]
  3130. if (MmePacket->MMENTRY[0] != 0)
  3131. {
  3132. sprintf(buf_log_evcomm,
  3133. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:wrong APPLICATION_TYPE(%d)",
  3134. (idx + 1),
  3135. MmePacket->MMENTRY[0]);
  3136. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3137. break;
  3138. }
  3139. //[TC_SECC_VTB_CmSlacMatch_009] SECURITY_TYPE must be 0x00(No Security)
  3140. //[TC_SECC_VTB_CmSlacMatch_010]
  3141. if (MmePacket->MMENTRY[1] != 0)
  3142. {
  3143. sprintf(buf_log_evcomm,
  3144. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:wrong SECURITY_TYPE(%d)",
  3145. (idx + 1),
  3146. MmePacket->MMENTRY[1]);
  3147. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3148. break;
  3149. }
  3150. //[TC_SECC_VTB_CmSlacMatch_011] MVFLength must be 0x3E(MatchVarField Length)
  3151. //[TC_SECC_VTB_CmSlacMatch_012]
  3152. if (MmePacket->MMENTRY[2] != 0x3E || MmePacket->MMENTRY[3] != 0x00)
  3153. {
  3154. sprintf(buf_log_evcomm,
  3155. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]:wrong MVFLength(%d,%d)",
  3156. (idx + 1),
  3157. MmePacket->MMENTRY[2],
  3158. MmePacket->MMENTRY[3]);
  3159. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3160. break;
  3161. }
  3162. //[TC_SECC_VTB_CmSlacMatch_013] EV ID (muxt be all zero)
  3163. //[TC_SECC_VTB_CmSlacMatch_014]
  3164. if (Array_Check_All_Zero(&MmePacket->MMENTRY[4], 17) == FALSE)
  3165. {
  3166. sprintf(buf_log_evcomm,
  3167. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EV ID",
  3168. (idx + 1));
  3169. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3170. break;
  3171. }
  3172. //[TC_SECC_VTB_CmSlacMatch_015] EV MAC
  3173. //[TC_SECC_VTB_CmSlacMatch_016]
  3174. if (Array_Compare_Identity(EvMac_in, &MmePacket->MMENTRY[21], SLAC_EVMAC_LENGTH) == FALSE)
  3175. {
  3176. sprintf(buf_log_evcomm,
  3177. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EV MAC(%02X:%02X:%02X:%02X:%02X:%02X)",
  3178. (idx + 1),
  3179. MmePacket->MMENTRY[21], MmePacket->MMENTRY[22], MmePacket->MMENTRY[23],
  3180. MmePacket->MMENTRY[24], MmePacket->MMENTRY[25], MmePacket->MMENTRY[26]);
  3181. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3182. break;
  3183. }
  3184. //[TC_SECC_VTB_CmSlacMatch_017] EVSE ID should be all zero
  3185. //[TC_SECC_VTB_CmSlacMatch_018]
  3186. if (Array_Check_All_Zero(&MmePacket->MMENTRY[27], 17) == FALSE)
  3187. {
  3188. sprintf(buf_log_evcomm,
  3189. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EVSE ID",
  3190. (idx + 1));
  3191. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3192. break;
  3193. }
  3194. //[TC_SECC_VTB_CmSlacMatch_019] EVSE MAC
  3195. //[TC_SECC_VTB_CmSlacMatch_020]
  3196. if (Array_Compare_Identity(CsuMac, &MmePacket->MMENTRY[44], SLAC_EVSE_MAC_LENGTH) == FALSE)
  3197. {
  3198. sprintf(buf_log_evcomm,
  3199. "[SLAC][Rx]CM_SLAC_MATCH_REQ[%d]: wrong EVSE MAC(%02X:%02X:%02X:%02X:%02X:%02X)",
  3200. (idx + 1),
  3201. MmePacket->MMENTRY[44], MmePacket->MMENTRY[45], MmePacket->MMENTRY[46],
  3202. MmePacket->MMENTRY[47], MmePacket->MMENTRY[48], MmePacket->MMENTRY[49]);
  3203. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3204. break;
  3205. }
  3206. //[TC_SECC_VTB_CmSlacMatch_021]runID: Check RunID
  3207. //[TC_SECC_VTB_CmSlacMatch_022]
  3208. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE &&
  3209. (idx == 0)) //only setup a successful link establishment with the first SLAC Req instance
  3210. {
  3211. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3212. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  3213. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3214. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3215. SendMmePacket.MMV = MmePacket->MMV;
  3216. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_MATCH_CNF;
  3217. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3218. SendMmePacketSize = 0;
  3219. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //APPLICATION_TYPE: Fixed value (0x00: EV-EVSE matching)
  3220. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //SECURITY_TYPE: Fixed value (0x00: No Security)
  3221. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x56; //MVFLength: MatchVarField Length (Fixed value: 0x0056)
  3222. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //MVFLength: MatchVarField Length (Fixed value: 0x0056)
  3223. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //EV ID
  3224. SendMmePacketSize += 17;
  3225. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac_in, SLAC_EVMAC_LENGTH); //EV MAC
  3226. SendMmePacketSize += 6;
  3227. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //EVSE ID
  3228. SendMmePacketSize += 17;
  3229. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, CsuMac, 6); //EVSE MAC
  3230. SendMmePacketSize += 6;
  3231. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, RunID_in, SLAC_RUNID_LENGTH);
  3232. SendMmePacketSize += SLAC_RUNID_LENGTH;
  3233. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 8); //RSVD
  3234. SendMmePacketSize += 8;
  3235. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, Nid, sizeof(Nid)); //NID: Network ID given by the CCo(EVSE)
  3236. SendMmePacketSize += sizeof(Nid); //NID caculated from the random NMK that will be set.
  3237. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //RSVD
  3238. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, NewNmkKey, sizeof(NewNmkKey)); //NMK: Random value
  3239. SendMmePacketSize += sizeof(NewNmkKey); //NMK: Private NMK of the EVSE (random value)
  3240. SendMmePacketSize += 19; //the size before MMENTRY
  3241. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3242. {
  3243. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  3244. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3245. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3246. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3247. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3248. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3249. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3250. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3251. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3252. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_MATCH_CNF ---\n");
  3253. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3254. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3255. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3]);
  3256. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3257. for(Rtn=0; Rtn<17; Rtn++)
  3258. {
  3259. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[4+Rtn]);
  3260. }
  3261. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3262. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3263. for(Rtn=0; Rtn<6; Rtn++)
  3264. {
  3265. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[21+Rtn]);
  3266. }
  3267. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3268. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3269. for(Rtn=0; Rtn<17; Rtn++)
  3270. {
  3271. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[27+Rtn]);
  3272. }
  3273. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3274. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3275. for(Rtn=0; Rtn<6; Rtn++)
  3276. {
  3277. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[44+Rtn]);
  3278. }
  3279. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3280. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3281. for(Rtn=0; Rtn<8; Rtn++)
  3282. {
  3283. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[50+Rtn]);
  3284. }
  3285. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3286. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3287. for(Rtn=0; Rtn<8; Rtn++)
  3288. {
  3289. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[58+Rtn]);
  3290. }
  3291. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3292. DEBUG_PRINTF_EVCOMM_DETAIL("NID: \n");
  3293. for(Rtn=0; Rtn<7; Rtn++)
  3294. {
  3295. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[66+Rtn]);
  3296. }
  3297. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3298. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", SendMmePacket.MMENTRY[73]);
  3299. DEBUG_PRINTF_EVCOMM_DETAIL("NMK: \n");
  3300. for(Rtn=0; Rtn<16; Rtn++)
  3301. {
  3302. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[74+Rtn]);
  3303. }
  3304. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3305. }
  3306. #endif
  3307. Update_V2G_Flow_Status(CM_SLAC_MATCH_CNF);
  3308. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3309. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  3310. sprintf(buf_log_evcomm,
  3311. "[SLAC][Tx]CM_SLAC_MATCH_CNF[%d]",
  3312. (idx + 1));
  3313. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3314. ftime(&SeqStartTime);
  3315. }
  3316. else
  3317. {
  3318. //RunID does not match and it's not the first SLAC request
  3319. //Reset the SLAC database to embrace SLAC retry
  3320. SAVE_SYS_LOG_MSG_EVCOMM("[CM_SLAC_MATCH_REQ]No Real MATCH_REQ");
  3321. SLAC_DB_Reset();
  3322. }
  3323. }
  3324. else
  3325. {
  3326. //OSA(EvMac) does not exist
  3327. }
  3328. break;
  3329. }
  3330. #else
  3331. {
  3332. Update_V2G_Flow_Status(CM_SLAC_MATCH_REQ);
  3333. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Rx]CM_SLAC_MATCH_REQ");
  3334. memset(&SendMmePacket,0,sizeof(struct MmeHeader));
  3335. memcpy(SendMmePacket.ODA,MmePacket->OSA,6);
  3336. memcpy(SendMmePacket.OSA,CsuMac,6);
  3337. SendMmePacket.MTYPE=htons(EtherType_HomePlug);
  3338. SendMmePacket.MMV=MmePacket->MMV;
  3339. SendMmePacket.MMTYPE=MMTYPE_CM_SLAC_MATCH_CNF;
  3340. SendMmePacket.FMI[0]=SendMmePacket.FMI[1]=0;
  3341. SendMmePacketSize=0;
  3342. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x00) indicating PEV-EVSE matching
  3343. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x00) indicating No Security
  3344. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x56; //Fixed value (0x0056) for matching
  3345. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x0056) for matching
  3346. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,17); //PEV ID
  3347. SendMmePacketSize+=17;
  3348. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,EvMac,6);
  3349. SendMmePacketSize+=6;
  3350. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,17); //EVSE ID
  3351. SendMmePacketSize+=17;
  3352. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,CsuMac,6);
  3353. SendMmePacketSize+=6;
  3354. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,SlacRunId,sizeof(SlacRunId));
  3355. SendMmePacketSize+=sizeof(SlacRunId);
  3356. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,8); //RSVD
  3357. SendMmePacketSize+=8;
  3358. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,Nid,sizeof(Nid));
  3359. SendMmePacketSize+=sizeof(Nid);
  3360. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //RSVD
  3361. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,NewNmkKey,sizeof(NewNmkKey));
  3362. SendMmePacketSize+=sizeof(NewNmkKey);
  3363. SendMmePacketSize+=19; //the size before MMENTRY
  3364. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3365. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  3366. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3367. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3368. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3369. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3370. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3371. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3372. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3373. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3374. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_MATCH_CNF ---\n");
  3375. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3376. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3377. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3]);
  3378. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3379. for(Rtn=0; Rtn<17; Rtn++)
  3380. {
  3381. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[4+Rtn]);
  3382. }
  3383. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3384. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3385. for(Rtn=0; Rtn<6; Rtn++)
  3386. {
  3387. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[21+Rtn]);
  3388. }
  3389. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3390. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3391. for(Rtn=0; Rtn<17; Rtn++)
  3392. {
  3393. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[27+Rtn]);
  3394. }
  3395. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3396. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3397. for(Rtn=0; Rtn<6; Rtn++)
  3398. {
  3399. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[44+Rtn]);
  3400. }
  3401. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3402. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3403. for(Rtn=0; Rtn<8; Rtn++)
  3404. {
  3405. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[50+Rtn]);
  3406. }
  3407. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3408. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3409. for(Rtn=0; Rtn<8; Rtn++)
  3410. {
  3411. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[58+Rtn]);
  3412. }
  3413. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3414. DEBUG_PRINTF_EVCOMM_DETAIL("NID: \n");
  3415. for(Rtn=0; Rtn<7; Rtn++)
  3416. {
  3417. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[66+Rtn]);
  3418. }
  3419. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3420. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", SendMmePacket.MMENTRY[73]);
  3421. DEBUG_PRINTF_EVCOMM_DETAIL("NMK: \n");
  3422. for(Rtn=0; Rtn<16; Rtn++)
  3423. {
  3424. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[74+Rtn]);
  3425. }
  3426. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3427. #endif
  3428. Update_V2G_Flow_Status(CM_SLAC_MATCH_CNF);
  3429. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3430. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  3431. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][Tx]CM_SLAC_MATCH_CNF");
  3432. ftime(&SeqStartTime);
  3433. break;
  3434. }
  3435. #endif
  3436. }
  3437. case MMTYPE_VENDOR_VS_HOST_ACTION:
  3438. {
  3439. struct QcaVendorMmeHeader *RecvPacket;
  3440. RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
  3441. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_VS_HOST_ACTION ---\n");
  3442. switch (RecvPacket->MBODY[0])
  3443. {
  3444. case 0x00:
  3445. //Loader (Device Softloader or Bootloader) ready
  3446. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Loader Ready\n");
  3447. break;
  3448. case 0x01:
  3449. //Firmware Upgrade Ready
  3450. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Firmware Upgrade Ready\n");
  3451. break;
  3452. case 0x02:
  3453. //PIB Update Ready
  3454. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: PIB Update Ready\n");
  3455. break;
  3456. case 0x03:
  3457. //Firmware Upgrade and PIB Update ready
  3458. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Firmware Upgrade and PIB Update ready\n");
  3459. break;
  3460. case 0x04:
  3461. //Loader (Bootloader) ready to receive SDRAM configuration.
  3462. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Loader ready to receive SDRAM configuration\n");
  3463. break;
  3464. case 0x05:
  3465. //Reset to Factory Defaults.
  3466. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Reset to Factory Defaults\n");
  3467. break;
  3468. default:
  3469. //Reserved
  3470. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Reserved\n");
  3471. break;
  3472. }
  3473. break;
  3474. }
  3475. case MMTYPE_VENDOR_ATTEN_CHAR:
  3476. {
  3477. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_ATTEN_CHAR ---\n");
  3478. break;
  3479. }
  3480. case MMTYPE_VENDOR_VS_NW_INFO_CNF:
  3481. {
  3482. struct QcaVendorMmeHeader *RecvPacket;
  3483. RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
  3484. memcpy(QcaMac, RecvPacket->OSA, 6);
  3485. sprintf(buf_log_evcomm,
  3486. "[QCA7K][Rx][VENDOR_VS_NW_INFO_CNF]Got QCA7K MacAddr:%02X:%02X:%02X:%02X:%02X:%02X (comm:OK)",
  3487. QcaMac[0], QcaMac[1], QcaMac[2], QcaMac[3], QcaMac[4], QcaMac[5]);
  3488. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3489. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_VS_NW_INFO_CNF ---\n");
  3490. DEBUG_PRINTF_EVCOMM_DETAIL("QcaMac: %02x:%02x:%02x:%02x:%02x:%02x\n",
  3491. QcaMac[0],
  3492. QcaMac[1],
  3493. QcaMac[2],
  3494. QcaMac[3],
  3495. QcaMac[4],
  3496. QcaMac[5]);
  3497. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  3498. ftime(&SeqStartTime);
  3499. break;
  3500. }
  3501. case MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF:
  3502. {
  3503. struct QcaVendorMmeHeader *RecvPacket;
  3504. RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
  3505. if(RecvPacket->MBODY[1]==0)
  3506. {
  3507. //PLC disconnected
  3508. sprintf(buf_log_evcomm,
  3509. "[QCA7K][Rx][MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF]Got PLC Link Status:%d",
  3510. RecvPacket->MBODY[1]);
  3511. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3512. Update_V2G_Flow_Status(Other_Fault);
  3513. }
  3514. else
  3515. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  3516. ftime(&SeqStartTime);
  3517. break;
  3518. }
  3519. default:
  3520. {
  3521. break;
  3522. }
  3523. }
  3524. }
  3525. /*===========================================================================
  3526. FUNCTION: SlacComm
  3527. DESCRIPTION:
  3528. PRE-CONDITION:
  3529. INPUT:
  3530. OUTPUT:
  3531. GLOBAL VARIABLES:
  3532. =============================================================================*/
  3533. int SlacComm()
  3534. {
  3535. static unsigned char qca7k_comm_retry = 0;
  3536. unsigned char *EvMac_in;
  3537. unsigned char *RunID_in;
  3538. double t_diff = 0;
  3539. int packet_size = 0;
  3540. int count = 0;
  3541. int idx = 0;
  3542. int i = 0;
  3543. if(RawSock >= 0)
  3544. {
  3545. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  3546. packet_size = recvfrom(RawSock, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, 0, NULL, NULL);
  3547. if(packet_size > 0)
  3548. {
  3549. /*#ifdef Debug
  3550. DEBUG_PRINTF_EVCOMM_DETAIL("Raw Data: ");
  3551. for(count=0;count<packet_size;count++)
  3552. DEBUG_PRINTF_EVCOMM_DETAIL("0x%x, ",V2gtpMsgRxBuf[count]);
  3553. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3554. #endif*/
  3555. MmeProcess(V2gtpMsgRxBuf, packet_size);
  3556. }
  3557. }
  3558. switch(Check_V2G_Flow_Status())
  3559. {
  3560. case IDLE:
  3561. {
  3562. if(RawSock < 0)
  3563. {
  3564. RawSock = socket(PF_PACKET, SOCK_RAW, htons(EtherType_HomePlug));
  3565. sprintf(buf_log_evcomm, "[RawSock]opened(%d)", RawSock);
  3566. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3567. if(RawSock == -1)
  3568. {
  3569. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm:Failed to create socket");
  3570. Update_V2G_Flow_Status(Other_Fault);
  3571. return -1;
  3572. }
  3573. if (setsockopt(RawSock, SOL_SOCKET, SO_BINDTODEVICE, QcaInterface, 4) < 0)
  3574. {
  3575. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm:Set SO_BINDTODEVICE NG");
  3576. Update_V2G_Flow_Status(Other_Fault);
  3577. return -1;
  3578. }
  3579. struct timeval tv;
  3580. tv.tv_sec = 0;
  3581. tv.tv_usec = 100000; //100ms (Rx timeout)
  3582. if (setsockopt(RawSock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  3583. {
  3584. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm:Set SO_RCVTIMEO NG");
  3585. Update_V2G_Flow_Status(Other_Fault);
  3586. return -1;
  3587. }
  3588. tv.tv_usec = 100000; //100ms (Tx timeout)
  3589. if (setsockopt(RawSock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  3590. {
  3591. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm:Set SO_SNDTIMEO NG");
  3592. Update_V2G_Flow_Status(Other_Fault);
  3593. return -1;
  3594. }
  3595. memset(&Req, 0, sizeof(struct ifreq));
  3596. strcpy( (char*)Req.ifr_name, QcaInterface);
  3597. if (ioctl(RawSock, SIOCGIFINDEX, &Req) < 0)
  3598. {
  3599. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: ioctl NG");
  3600. Update_V2G_Flow_Status(Other_Fault);
  3601. return -1;
  3602. }
  3603. memset( &DestSocketAddress, 0, sizeof(struct sockaddr_ll));
  3604. DestSocketAddress.sll_ifindex = Req.ifr_ifindex;
  3605. DestSocketAddress.sll_halen = ETH_ALEN;
  3606. PwmStartTime = 0;
  3607. EVCOMM_SYS_INFO.QCA7K_SetKeyDone = FALSE;
  3608. SAVE_SYS_LOG_MSG_EVCOMM("[QCA7K]connecting...");
  3609. //Get QCA7K MAC address
  3610. GetQca7kMac();
  3611. ftime(&SeqStartTime);
  3612. break;
  3613. }
  3614. else //RawSock: opened
  3615. {
  3616. if(EVCOMM_SYS_INFO.QCA7K_SetKeyDone == FALSE)
  3617. {
  3618. ftime(&SeqEndTime);
  3619. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3620. if (t_diff > V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD) //3 secs
  3621. {
  3622. qca7k_comm_retry++;
  3623. sprintf(buf_log_evcomm,
  3624. "[QCA7K]re-try connecting...(%.02lf/%dms)",
  3625. t_diff,
  3626. V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD);
  3627. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3628. GetQca7kMac(); //re-send req
  3629. ftime(&SeqStartTime);
  3630. break;
  3631. }
  3632. else
  3633. {
  3634. //null
  3635. }
  3636. //Retry by 3 times
  3637. if (qca7k_comm_retry >= 3)
  3638. {
  3639. sprintf(buf_log_evcomm,
  3640. "[QCA7K][Error]comm: fail (retry by %d times)",
  3641. qca7k_comm_retry);
  3642. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3643. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3644. //CCS_SECCC_TIMEOUT_QCA7000_COMM (023892): The firmware code of QCA7000 may not be installed, yet
  3645. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3646. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3647. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3648. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3649. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  3650. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  3651. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3652. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3653. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  3654. Update_V2G_Flow_Status(Sequence_Timeout);
  3655. qca7k_comm_retry = 0;
  3656. break;
  3657. }
  3658. }
  3659. else //RawSock: opened; Set Key: DONE
  3660. {
  3661. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  3662. if((CheckConnectorPlugIn() == TRUE) && (ShmInternalComm->ChargingPermission >=1))
  3663. {
  3664. if(PwmStartTime <= 0)
  3665. {
  3666. //Sniffer_Tcpdump(ENABLE);
  3667. //#if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  3668. //sleep(1); //wait for tcpdump to be ready.
  3669. //#endif
  3670. SwitchCpStateE(DISABLE);
  3671. OutputCpPwmDuty(5);
  3672. PwmStartTime = time(NULL);
  3673. }
  3674. else
  3675. {
  3676. if((time(NULL) - PwmStartTime) > TT_EVSE_SLAC_init)
  3677. {
  3678. sprintf(buf_log_evcomm,
  3679. "SlacComm: Wait CM_SLAC_PARM_REQ Timeout - TT_EVSE_SLAC_init, NowTime(%d)-PwmStartTime(%d)>%d (sec)",
  3680. time(NULL),
  3681. PwmStartTime,
  3682. TT_EVSE_SLAC_init);
  3683. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3684. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3685. //CCS_SECC_TIMEOUT_SLAC_TT_EVSE_SLAC_init (023809)
  3686. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3687. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3688. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3689. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3690. ShmStatusCodeData->PresentStatusCode[0][4] = 0;
  3691. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  3692. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  3693. Update_V2G_Flow_Status(Sequence_Timeout);
  3694. PwmStartTime = 0;
  3695. return -1;
  3696. }
  3697. else
  3698. {
  3699. //waiting for CM_SLAC_PARM_REQ
  3700. }
  3701. }
  3702. }
  3703. else
  3704. {
  3705. PwmStartTime = 0;
  3706. }
  3707. }
  3708. }
  3709. break;
  3710. }
  3711. case CM_SET_KEY_REQ: //13
  3712. {
  3713. //CM_SET_KEY_REQ
  3714. //SAVE_SYS_LOG_MSG_EVCOMM("[QCA7K][Rx]CM_SET_KEY_REQ");
  3715. ftime(&SeqEndTime);
  3716. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3717. if (t_diff > V2G_SECC_QCA7000_COMM_TIMEOUT) //10 seconds
  3718. {
  3719. sprintf(buf_log_evcomm,
  3720. "[QCA7K]Failed on SetKey => End_Process (%.02lf/%dms)",
  3721. t_diff,
  3722. V2G_SECC_QCA7000_COMM_TIMEOUT);
  3723. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3724. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3725. //CCS_SECCC_TIMEOUT_QCA7000_COMM (023892): The firmware code of QCA7000 may not be installed, yet
  3726. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3727. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3728. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3729. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3730. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  3731. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  3732. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3733. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3734. Update_V2G_Flow_Status(Sequence_Timeout);
  3735. }
  3736. else if (t_diff > V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD) //2 seconds
  3737. {
  3738. sprintf(buf_log_evcomm,
  3739. "[QCA7K]SetKey: proceed (%.02lf/%dms)",
  3740. t_diff,
  3741. V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD);
  3742. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3743. SendSetKey();
  3744. ftime(&SeqStartTime);
  3745. }
  3746. else
  3747. {
  3748. //null
  3749. }
  3750. break;
  3751. }
  3752. case CM_SET_KEY_CNF: //14
  3753. {
  3754. sprintf(buf_log_evcomm,
  3755. "[SECCReady]Wait: plugin(%d), matached(%d), permission(%d)...",
  3756. CheckConnectorPlugIn(),
  3757. CSUCOMMDC_TASK_FLAG.matched,
  3758. ShmInternalComm->ChargingPermission
  3759. );
  3760. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3761. EVCOMM_SYS_INFO.QCA7K_SetKeyDone = TRUE;
  3762. PwmStartTime = 0;
  3763. Update_V2G_Flow_Status(IDLE);
  3764. break;
  3765. }
  3766. case CM_SLAC_PARM_CONF:
  3767. {
  3768. ftime(&SeqEndTime);
  3769. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_sequence)
  3770. {
  3771. sprintf(buf_log_evcomm,
  3772. "SlacComm: Wait CM_START_ATTEN_CHAR_IND Timeout - TT_match_sequence (%.02lf of %dms)",
  3773. DiffTimeb(SeqStartTime, SeqEndTime),
  3774. TT_match_sequence);
  3775. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3776. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3777. //CCS_SECC_TIMEOUT_CM_START_ATTEN_CHAR_IND (023811):
  3778. //[Possible Reason] CCS Board image might not be updated properly. The 2nd reboot process is not finished.
  3779. //[Verification Method] By tying reboot command to the terminal and see if it could be executed immediately.
  3780. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3781. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3782. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3783. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3784. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  3785. ShmStatusCodeData->PresentStatusCode[0][5] = 1;
  3786. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3787. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3788. Update_V2G_Flow_Status(Sequence_Timeout);
  3789. return -1;
  3790. }
  3791. break;
  3792. }
  3793. case CM_START_ATTEN_CHAR_IND:
  3794. {
  3795. ftime(&SeqEndTime);
  3796. if(DiffTimeb(SeqStartTime, SeqEndTime) > (TP_EV_batch_msg_interval)) //one more time interval for tolerance
  3797. {
  3798. sprintf(buf_log_evcomm,
  3799. "SlacComm: Wait CM_MNBC_SOUND_IND Timeout - TP_EV_batch_msg_interval (%.02lf of %dms)",
  3800. DiffTimeb(SeqStartTime, SeqEndTime),
  3801. TP_EV_batch_msg_interval);
  3802. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3803. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3804. //CCS_SECC_TIMEOUT_SLAC_CM_MNBC_SOUND_IND (023818):
  3805. //[Possible Reason] CCS Board image might not be updated properly. The 2nd reboot process is not finished.
  3806. //[Verification Method] By tying reboot command to the terminal and see if it could be executed immediately.
  3807. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3808. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3809. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3810. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3811. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  3812. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  3813. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3814. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3815. Update_V2G_Flow_Status(Sequence_Timeout);
  3816. return -1;
  3817. }
  3818. break;
  3819. }
  3820. case CM_MNBC_SOUND_IND:
  3821. {
  3822. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3823. {
  3824. ftime(&SeqEndTime);
  3825. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3826. //printf("time:%.02lf, profilNum:%d\n",DiffTimeb(SeqStartTime, SeqEndTime),AttenProfileCnt); //added by Vern
  3827. if(t_diff > TT_EVSE_match_MNBC ||
  3828. (SLAC_INFO.array[0].AttenProfileCnt >= SLAC_INFO.array[0].MnbcSoundNum) ||
  3829. (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)) //TC_SECC_VTB_AttenuationCharacterization_003
  3830. {
  3831. //Wait for other SLAC Req sets
  3832. if ((SLAC_INFO.arrayLen >= 2) &&
  3833. (t_diff < TT_EVSE_match_MNBC) &&
  3834. (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry == 0)) //not a retry
  3835. {
  3836. break;
  3837. }
  3838. //Check if it is a timeup response
  3839. if (t_diff > TT_EVSE_match_MNBC)
  3840. {
  3841. sprintf(buf_log_evcomm,
  3842. "[WARNING][SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: timeup(%.2f/%dms) => send",
  3843. (i + 1),
  3844. t_diff,
  3845. TT_EVSE_match_MNBC);
  3846. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3847. }
  3848. //Sending all CM_ATTEN_CHAR_IND according to all corresponding SLAC Req sets
  3849. for (i = 0; i < SLAC_INFO.arrayLen; i++)
  3850. {
  3851. if ((SLAC_INFO.array[i].AttenProfileCnt == 0) ||
  3852. (SLAC_INFO.array[i].AagGroupsNum == 0) ||
  3853. (SLAC_INFO.array[i].StartAttenCharCnt == 0) ||
  3854. (SLAC_INFO.array[i].MnbcSoundNum != 10) || //received in CM_START_ATTEN_CHAR_IND
  3855. (SLAC_INFO.array[i].StartAttenCharErr == TRUE)
  3856. )
  3857. {
  3858. //Ignoring those SLAC request sets without sending CM_MNBC_SOUND_IND(CM_ATTEN_PROFILE_IND)
  3859. sprintf(buf_log_evcomm,
  3860. "[WARNING][SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: para err(%d,%d,%d,%d,%d) => canceled",
  3861. (i + 1),
  3862. SLAC_INFO.array[i].AttenProfileCnt,
  3863. SLAC_INFO.array[i].AagGroupsNum,
  3864. SLAC_INFO.array[i].StartAttenCharCnt,
  3865. SLAC_INFO.array[i].MnbcSoundNum,
  3866. SLAC_INFO.array[i].StartAttenCharErr);
  3867. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3868. continue;
  3869. }
  3870. //In CM_ATTEN_CHAR_IND retry process, here only re-send this message according to the 1st coming SLAC request
  3871. if ((EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0) && (i != 0))
  3872. {
  3873. sprintf(buf_log_evcomm,
  3874. "[NOTE][SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: canceled",
  3875. (i + 1));
  3876. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3877. break;
  3878. }
  3879. EvMac_in = SLAC_INFO.array[i].EvMac;
  3880. RunID_in = SLAC_INFO.array[i].RunID;
  3881. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3882. memcpy(SendMmePacket.ODA, EvMac_in, SLAC_EVMAC_LENGTH);
  3883. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3884. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3885. SendMmePacket.MMV = 0x01;
  3886. SendMmePacket.MMTYPE = MMTYPE_CM_ATTEN_CHAR_IND;
  3887. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3888. SendMmePacketSize = 0;
  3889. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00: EV-EVSE Matching)
  3890. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00: No Security)
  3891. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac_in, SLAC_EVMAC_LENGTH); //SOURCE_ADDRESS, MAC address of the EV Host
  3892. SendMmePacketSize += SLAC_EVMAC_LENGTH;
  3893. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, RunID_in, SLAC_RUNID_LENGTH);
  3894. SendMmePacketSize += SLAC_RUNID_LENGTH;
  3895. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //SOURCE_ID(0x00)
  3896. SendMmePacketSize += 17;
  3897. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //RESP_ID(0x00)
  3898. SendMmePacketSize += 17;
  3899. SendMmePacket.MMENTRY[SendMmePacketSize++] = SLAC_INFO.array[i].AttenProfileCnt; //NumSounds: Number of M-Sounds used for generation of the ATTEN_PROFILE
  3900. SendMmePacket.MMENTRY[SendMmePacketSize++] = SLAC_INFO.array[i].AagGroupsNum; //NumGroups
  3901. for(count = 0; count < SLAC_INFO.array[i].AagGroupsNum; count++)
  3902. {
  3903. unsigned char TmpAag;
  3904. TmpAag = ((SLAC_INFO.array[i].AAG[count] / SLAC_INFO.array[i].AttenProfileCnt) & 0xFF);
  3905. SLAC_INFO.array[i].AAG_quality_ori += (float) TmpAag; //original signal quality
  3906. #if (SUDO_PSD_PARAMETER_MECHANISM == ENABLE) //default: ENABLE
  3907. #if 1
  3908. //TC_SECC_VTB_AttenuationCharacterization_019
  3909. TmpAag = TmpAag >> 1; //new method proposed by Joseph (divided by 2)
  3910. #else
  3911. if(TmpAag >= 39) //original method proposed by Vern
  3912. {
  3913. TmpAag = 37;
  3914. }
  3915. #endif
  3916. #endif
  3917. SendMmePacket.MMENTRY[SendMmePacketSize++] = TmpAag;
  3918. SLAC_INFO.array[i].AAG_quality_refined += (float) TmpAag; //refined signal quality
  3919. }
  3920. SendMmePacketSize += 19; //the size before MMENTRY
  3921. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == TRUE)
  3922. {
  3923. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Send MME Packet *****\n");
  3924. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3925. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3926. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3927. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3928. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3929. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3930. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3931. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3932. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_ATTEN_CHAR_IND ---\n");
  3933. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3934. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3935. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  3936. SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5],
  3937. SendMmePacket.MMENTRY[6],SendMmePacket.MMENTRY[7]);
  3938. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  3939. SendMmePacket.MMENTRY[8],SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],
  3940. SendMmePacket.MMENTRY[12],SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14],SendMmePacket.MMENTRY[15]);
  3941. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: \n");
  3942. for(count=0; count<17; count++)
  3943. {
  3944. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[16+count]);
  3945. }
  3946. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3947. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: \n");
  3948. for(count=0; count<17; count++)
  3949. {
  3950. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[33+count]);
  3951. }
  3952. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3953. DEBUG_PRINTF_EVCOMM_DETAIL("NumSounds: 0x%x\n", SendMmePacket.MMENTRY[50]);
  3954. DEBUG_PRINTF_EVCOMM_DETAIL("ATTEN_PROFILE: \n");
  3955. for(count=0; count<AagGroupsNum; count++)
  3956. {
  3957. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[51+count]);
  3958. }
  3959. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3960. }
  3961. #endif
  3962. count = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3963. SLAC_INFO.array[i].AAG_quality_ori /= SLAC_INFO.array[i].AagGroupsNum;
  3964. SLAC_INFO.array[i].AAG_quality_refined /= SLAC_INFO.array[i].AagGroupsNum;
  3965. //Print log if this CM_ATTEN_CHAR_IND belongs to RETRY Tx message.
  3966. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)
  3967. {
  3968. sprintf(buf_log_evcomm,
  3969. "[SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: %d-th resend (Q=%.2f/%.2f)(%d/%d)",
  3970. (i + 1),
  3971. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry,
  3972. SLAC_INFO.array[i].AAG_quality_refined,
  3973. SLAC_INFO.array[i].AAG_quality_ori,
  3974. SLAC_INFO.array[i].AttenProfileCnt,
  3975. SLAC_INFO.array[i].MnbcSoundNum);
  3976. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3977. }
  3978. else if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry == 0)
  3979. {
  3980. sprintf(buf_log_evcomm,
  3981. "[SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: Q=%.2f/%.2f(%d/%d)",
  3982. (i + 1),
  3983. SLAC_INFO.array[i].AAG_quality_refined,
  3984. SLAC_INFO.array[i].AAG_quality_ori,
  3985. SLAC_INFO.array[i].AttenProfileCnt,
  3986. SLAC_INFO.array[i].MnbcSoundNum);
  3987. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3988. }
  3989. else
  3990. {
  3991. sprintf(buf_log_evcomm,
  3992. "[SLAC][Tx]CM_ATTEN_CHAR_IND[%d]: unexpected CM_ATTEN_CHAR_IND_retry(%d))",
  3993. i,
  3994. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  3995. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  3996. }
  3997. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n", SendMmePacketSize,count);
  3998. } //end of for loop
  3999. Update_V2G_Flow_Status(CM_ATTEN_CHAR_IND);
  4000. ftime(&SeqStartTime);
  4001. }
  4002. break;
  4003. }
  4004. #else
  4005. {
  4006. ftime(&SeqEndTime);
  4007. //printf("time:%.02lf, profilNum:%d\n",DiffTimeb(SeqStartTime, SeqEndTime),AttenProfileCnt); //added by Vern
  4008. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_EVSE_match_MNBC || (AttenProfileCnt >= MnbcSoundNum) || (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0))
  4009. {
  4010. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  4011. memcpy(SendMmePacket.ODA, EvMac, 6);
  4012. memcpy(SendMmePacket.OSA, CsuMac, 6);
  4013. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  4014. SendMmePacket.MMV = 0x01;
  4015. SendMmePacket.MMTYPE = MMTYPE_CM_ATTEN_CHAR_IND;
  4016. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  4017. SendMmePacketSize = 0;
  4018. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00: EV-EVSE Matching)
  4019. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00: No Security)
  4020. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac, 6); //SOURCE_ADDRESS, MAC address of the EV Host
  4021. SendMmePacketSize += 6;
  4022. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize, SlacRunId, sizeof(SlacRunId));
  4023. SendMmePacketSize += sizeof(SlacRunId);
  4024. memset(SendMmePacket.MMENTRY+SendMmePacketSize, 0, 17); //SOURCE_ID
  4025. SendMmePacketSize += 17;
  4026. memset(SendMmePacket.MMENTRY+SendMmePacketSize, 0, 17); //RESP_ID
  4027. SendMmePacketSize += 17;
  4028. SendMmePacket.MMENTRY[SendMmePacketSize++] = AttenProfileCnt; //NumSounds
  4029. SendMmePacket.MMENTRY[SendMmePacketSize++] = AagGroupsNum; //NumGroups
  4030. for(count=0; count < AagGroupsNum; count++)
  4031. {
  4032. unsigned char TmpAag;
  4033. TmpAag = ((Aag[count] / AttenProfileCnt) & 0xFF);
  4034. #if (SUDO_PSD_PARAMETER_MECHANISM == ENABLE) //default: ENABLE
  4035. #if 1
  4036. //TC_SECC_VTB_AttenuationCharacterization_019
  4037. TmpAag = TmpAag >> 1; //new method proposed by Joseph (divided by 2)
  4038. #else
  4039. if(TmpAag >= 39) //original method proposed by Vern
  4040. {
  4041. /*
  4042. // [To-do] If this statement is enabled, SLAC will fail due to timeout.
  4043. {
  4044. unsigned char TmpBuf[64];
  4045. memset(TmpBuf,0,sizeof(TmpBuf));
  4046. sprintf(TmpBuf,"SlacComm: bad Aag[%d]=%d",count,TmpAag);
  4047. SAVE_SYS_LOG_MSG_EVCOMM(TmpBuf);
  4048. }
  4049. */
  4050. printf("%d,", TmpAag);
  4051. TmpAag = 37;
  4052. }
  4053. #endif
  4054. #endif
  4055. SendMmePacket.MMENTRY[SendMmePacketSize++] = TmpAag;
  4056. }
  4057. SendMmePacketSize += 19; //the size before MMENTRY
  4058. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == TRUE)
  4059. {
  4060. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Send MME Packet *****\n");
  4061. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  4062. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  4063. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  4064. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  4065. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  4066. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  4067. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  4068. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  4069. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_ATTEN_CHAR_IND ---\n");
  4070. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  4071. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  4072. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  4073. SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5],
  4074. SendMmePacket.MMENTRY[6],SendMmePacket.MMENTRY[7]);
  4075. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  4076. SendMmePacket.MMENTRY[8],SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],
  4077. SendMmePacket.MMENTRY[12],SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14],SendMmePacket.MMENTRY[15]);
  4078. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: \n");
  4079. for(count=0; count<17; count++)
  4080. {
  4081. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[16+count]);
  4082. }
  4083. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  4084. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: \n");
  4085. for(count=0; count<17; count++)
  4086. {
  4087. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[33+count]);
  4088. }
  4089. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  4090. DEBUG_PRINTF_EVCOMM_DETAIL("NumSounds: 0x%x\n", SendMmePacket.MMENTRY[50]);
  4091. DEBUG_PRINTF_EVCOMM_DETAIL("ATTEN_PROFILE: \n");
  4092. for(count=0; count<AagGroupsNum; count++)
  4093. {
  4094. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[51+count]);
  4095. }
  4096. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  4097. }
  4098. #endif
  4099. Update_V2G_Flow_Status(CM_ATTEN_CHAR_IND);
  4100. count = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  4101. //Print log if this CM_ATTEN_CHAR_IND belongs to RETRY Tx message.
  4102. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)
  4103. {
  4104. sprintf(buf_log_evcomm,
  4105. "[SLAC][Tx]CM_ATTEN_CHAR_IND: resend(%d-th)",
  4106. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  4107. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4108. }
  4109. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n", SendMmePacketSize,count);
  4110. ftime(&SeqStartTime);
  4111. }
  4112. break;
  4113. }
  4114. #endif
  4115. }
  4116. case CM_ATTEN_CHAR_IND:
  4117. {
  4118. ftime(&SeqEndTime);
  4119. //if(DiffTimeb(SeqStartTime, SeqEndTime)>TT_match_response)
  4120. 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.
  4121. {
  4122. sprintf(buf_log_evcomm,
  4123. "SlacComm: Wait CM_ATTEN_CHAR_RSP Timeout - TT_match_response (%.02lf of %dms)",
  4124. DiffTimeb(SeqStartTime, SeqEndTime),
  4125. TT_match_response);
  4126. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4127. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4128. //CCS_SECC_TIMEOUT_SLAC_CM_ATTEN_CHAR_RSP (023814):
  4129. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4130. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4131. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4132. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4133. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4134. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4135. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  4136. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4137. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4138. Update_V2G_Flow_Status(Sequence_Timeout);
  4139. return -1;
  4140. }
  4141. break;
  4142. }
  4143. case CM_ATTEN_CHAR_RSP:
  4144. {
  4145. ftime(&SeqEndTime);
  4146. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_EVSE_match_session)
  4147. {
  4148. sprintf(buf_log_evcomm,
  4149. "SlacComm: Wait CM_VALIDATE_REQ_1ST or CM_SLAC_MATCH_REQ Timeout - TT_EVSE_match_session (%.02lf of %dms)",
  4150. DiffTimeb(SeqStartTime, SeqEndTime),
  4151. TT_EVSE_match_session);
  4152. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4153. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4154. //CCS_SECC_TIMEOUT_SLAC_CM_VALIDATE_REQ_1ST__CM_SLAC_MATCH_REQ (023815):
  4155. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4156. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4157. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4158. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4159. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4160. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4161. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  4162. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4163. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4164. Update_V2G_Flow_Status(Sequence_Timeout);
  4165. return -1;
  4166. }
  4167. break;
  4168. }
  4169. case CM_VALIDATE_CNF:
  4170. {
  4171. ftime(&SeqEndTime);
  4172. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_sequence)
  4173. {
  4174. sprintf(buf_log_evcomm,
  4175. "SlacComm: Wait CM_VALIDATE_REQ_2ND or CM_SLAC_MATCH_REQ Timeout - TT_match_sequence (%.02lf of %dms)",
  4176. DiffTimeb(SeqStartTime, SeqEndTime),
  4177. TT_match_sequence);
  4178. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4179. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4180. //CCS_SECC_TIMEOUT_SLAC_CM_VALIDATE_REQ_2ND__CM_SLAC_MATCH_REQ (023819):
  4181. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4182. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4183. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4184. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4185. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4186. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4187. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  4188. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4189. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4190. Update_V2G_Flow_Status(Sequence_Timeout);
  4191. return -1;
  4192. }
  4193. break;
  4194. }
  4195. case CM_SLAC_MATCH_CNF:
  4196. {
  4197. if(UdpSock > 0)
  4198. {
  4199. close(UdpSock);
  4200. UdpSock = -1;
  4201. }
  4202. if(TcpSock > 0)
  4203. {
  4204. close(TcpSock);
  4205. TcpSock = -1;
  4206. }
  4207. ftime(&SeqStartTime);
  4208. V2gTcpConnected();
  4209. Update_V2G_Flow_Status(SLACC_SDP_UDP_Connection);
  4210. SAVE_SYS_LOG_MSG_EVCOMM("SLAAC,SDP,UDP: connecting...");
  4211. break;
  4212. }
  4213. defaudlt:
  4214. {
  4215. break;
  4216. }
  4217. }
  4218. return 0;
  4219. }
  4220. /*===========================================================================
  4221. FUNCTION: V2gMsgDecoder
  4222. DESCRIPTION:
  4223. 1. Decode the V2GTP messages inside "msg" and save the decoded
  4224. messages in ccs_exi_doc_DIN, ccs_exi_doc_ISO1, and ccs_exi_doc_ISO2,
  4225. respectively.
  4226. 2. After decoding, V2gMsg_Process() could then use
  4227. ccs_exi_doc_DIN, ccs_exi_doc_ISO1, or ccs_exi_doc_ISO2
  4228. to deal with the corresponding Response messages, respectively.
  4229. PRE-CONDITION:
  4230. 1. msg_length > 0
  4231. INPUT:
  4232. 1. msg
  4233. 2. msg_length
  4234. OUTPUT:
  4235. 1. ccs_exi_doc_DIN //global variable
  4236. ccs_exi_doc_ISO1
  4237. ccs_exi_doc_ISO2
  4238. 2. v2g_state //Status Flag
  4239. //indicating the V2gMsg_Process_din to proceed
  4240. the next process.
  4241. 3. return value // < 0: ERROR
  4242. // > 0: Message Type
  4243. GLOBAL VARIABLES:
  4244. =============================================================================*/
  4245. int V2gMsgDecoder(unsigned char *msg, unsigned int msg_length, unsigned int v2g_state)
  4246. {
  4247. int errn = 0;
  4248. //Checking the minimum Header size requirement
  4249. if(msg_length < V2GTP_MSG_HEADER_LENGTH) //The minimum requirement should be 8-byte header.
  4250. {
  4251. errn = -1;
  4252. return errn;
  4253. }
  4254. //Decode the 1st V2GMSG: AppProtocol
  4255. if(v2g_state == SupportedAppProtocolRequest) //17
  4256. {
  4257. if (errn = API_V2GMSG_EXI_Decoder_AppProtocol(msg, msg_length, &ccs_handshake) < 0)
  4258. {
  4259. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR = %d (DEC)]V2gMsgDecoder: SupportedAppProtocolRequest()\n", errn);
  4260. }
  4261. else //decoded successfully.
  4262. {
  4263. //PRINT_XML_DOC_supportedAppProtocolReq(&ccs_handshake);
  4264. }
  4265. }
  4266. //Decode the subsequent V2GMSG (DIN 70121, ISO 15118-2, ISO 15118-20)
  4267. else if(v2g_state > SupportedAppProtocolRequest && v2g_state <= SessionStopResponse)
  4268. {
  4269. //Decoding according to its own protocol
  4270. switch (ShmCcsData->CommProtocol)
  4271. {
  4272. case V2GT_MSG_PROTOCOL_DIN70121: //0
  4273. {
  4274. //DIN
  4275. if(errn = API_V2GMSG_EXI_Decoder_DIN(msg, msg_length, &ccs_exi_doc_DIN) < 0)
  4276. {
  4277. sprintf(buf_log_evcomm,
  4278. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_DIN()",
  4279. errn);
  4280. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4281. }
  4282. break;
  4283. }
  4284. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  4285. {
  4286. //ISO1
  4287. if(errn = API_V2GMSG_EXI_Decoder_ISO1(msg, msg_length, &ccs_exi_doc_ISO1) < 0)
  4288. {
  4289. sprintf(buf_log_evcomm,
  4290. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_ISO1()",
  4291. errn);
  4292. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4293. }
  4294. break;
  4295. }
  4296. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  4297. {
  4298. //ISO2
  4299. if(errn = API_V2GMSG_EXI_Decoder_ISO2(msg, msg_length, &ccs_exi_doc_ISO2) < 0)
  4300. {
  4301. sprintf(buf_log_evcomm,
  4302. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_ISO2()",
  4303. errn);
  4304. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4305. }
  4306. break;
  4307. }
  4308. default:
  4309. break;
  4310. }
  4311. }
  4312. else
  4313. {
  4314. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR = %d (DEC)]V2gMsgDecoder: Unexpected v2g_state\n", errn);
  4315. errn = -1;
  4316. }
  4317. return errn;
  4318. }
  4319. /*===========================================================================
  4320. FUNCTION: encode_din_V2GTP_stream
  4321. DESCRIPTION:
  4322. PRE-CONDITION:
  4323. INPUT:
  4324. OUTPUT:
  4325. GLOBAL VARIABLES:
  4326. =============================================================================*/
  4327. int encode_din_V2GTP_stream(bitstream_t *v2g_tx_stream, struct dinEXIDocument *ccs_exi_doc_DIN)
  4328. {
  4329. int errn = 0;
  4330. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4331. errn = encode_dinExiDocument(v2g_tx_stream, ccs_exi_doc_DIN);
  4332. if (errn == 0)
  4333. {
  4334. //successfully encoded
  4335. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4336. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4337. if (errn != 0)
  4338. {
  4339. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_din_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4340. }
  4341. }
  4342. else
  4343. {
  4344. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_din_V2GTP_stream]encode_dinExiDocument(): %d (DEC)\n", errn);
  4345. }
  4346. return errn;
  4347. }
  4348. /*===========================================================================
  4349. FUNCTION: encode_iso1_V2GTP_stream
  4350. DESCRIPTION:
  4351. PRE-CONDITION:
  4352. INPUT:
  4353. OUTPUT:
  4354. GLOBAL VARIABLES:
  4355. =============================================================================*/
  4356. int encode_iso1_V2GTP_stream(bitstream_t *v2g_tx_stream, struct iso1EXIDocument *ccs_exi_doc_ISO1)
  4357. {
  4358. int errn = 0;
  4359. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4360. errn = encode_iso1ExiDocument(v2g_tx_stream, ccs_exi_doc_ISO1);
  4361. if (errn == 0)
  4362. {
  4363. //successfully encoded
  4364. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4365. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4366. if (errn != 0)
  4367. {
  4368. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso1_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4369. }
  4370. }
  4371. else
  4372. {
  4373. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso1_V2GTP_stream]encode_iso1ExiDocument(): %d (DEC)\n", errn);
  4374. }
  4375. return errn;
  4376. }
  4377. /*===========================================================================
  4378. FUNCTION: encode_iso2_V2GTP_stream
  4379. DESCRIPTION:
  4380. PRE-CONDITION:
  4381. INPUT:
  4382. OUTPUT:
  4383. GLOBAL VARIABLES:
  4384. =============================================================================*/
  4385. int encode_iso2_V2GTP_stream(bitstream_t *v2g_tx_stream, struct iso2EXIDocument *ccs_exi_doc_ISO2)
  4386. {
  4387. int errn = 0;
  4388. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4389. errn = encode_iso2ExiDocument(v2g_tx_stream, ccs_exi_doc_ISO2);
  4390. if (errn == 0)
  4391. {
  4392. //successfully encoded
  4393. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4394. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4395. if (errn != 0)
  4396. {
  4397. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso2_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4398. }
  4399. }
  4400. else
  4401. {
  4402. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso2_V2GTP_stream]encode_iso2ExiDocument(): %d (DEC)\n", errn);
  4403. }
  4404. return errn;
  4405. }
  4406. /*===========================================================================
  4407. FUNCTION: send_encoded_din_V2GTP_Stream
  4408. DESCRIPTION:
  4409. PRE-CONDITION:
  4410. INPUT:
  4411. OUTPUT:
  4412. GLOBAL VARIABLES:
  4413. =============================================================================*/
  4414. int send_encoded_din_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct dinEXIDocument *ccs_exi_doc_DIN)
  4415. {
  4416. int errn = 0;
  4417. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4418. errn = encode_din_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_DIN);
  4419. // STEP 2: =========== Send Response Packet ===========
  4420. int rtn = 0;
  4421. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4422. if (rtn == v2g_tx_stream->size)
  4423. {
  4424. /*
  4425. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][send_encoded_din_V2GTP_Stream] Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4426. rtn, v2g_tx_stream->size);
  4427. */
  4428. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4429. }
  4430. else if (rtn >= 0)
  4431. {
  4432. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][send_encoded_din_V2GTP_Stream]Imcomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n",
  4433. rtn, v2g_tx_stream->size);
  4434. }
  4435. else
  4436. {
  4437. errn = rtn;
  4438. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][send_encoded_din_V2GTP_Stream]send(): %d (DEC)\n", errn);
  4439. }
  4440. //STEP 3: ========= Reset V2G MSG Flags ==========
  4441. init_dinBodyType(&ccs_exi_doc_DIN->V2G_Message.Body);
  4442. return errn;
  4443. }
  4444. /*===========================================================================
  4445. FUNCTION: send_encoded_iso1_V2GTP_Stream
  4446. DESCRIPTION:
  4447. PRE-CONDITION:
  4448. INPUT:
  4449. OUTPUT:
  4450. GLOBAL VARIABLES:
  4451. =============================================================================*/
  4452. int send_encoded_iso1_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct iso1EXIDocument *ccs_exi_doc_ISO1)
  4453. {
  4454. int errn = 0;
  4455. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4456. errn = encode_iso1_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_ISO1);
  4457. // STEP 2: =========== Send Response Packet ===========
  4458. int rtn = 0;
  4459. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4460. if (rtn == v2g_tx_stream->size)
  4461. {
  4462. /*
  4463. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][send_encoded_iso1_V2GTP_Stream] Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4464. rtn, v2g_tx_stream->size);
  4465. */
  4466. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4467. }
  4468. else if (rtn >= 0)
  4469. {
  4470. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][send_encoded_iso1_V2GTP_Stream]Imcomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n",
  4471. rtn, v2g_tx_stream->size);
  4472. }
  4473. else
  4474. {
  4475. errn = rtn;
  4476. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][send_encoded_iso1_V2GTP_Stream]send(): %d (DEC)\n", errn);
  4477. }
  4478. //STEP 3: ========= Reset V2G MSG Flags ==========
  4479. init_iso1BodyType(&ccs_exi_doc_ISO1->V2G_Message.Body);
  4480. return errn;
  4481. }
  4482. /*===========================================================================
  4483. FUNCTION: send_encoded_iso2_V2GTP_Stream
  4484. DESCRIPTION:
  4485. PRE-CONDITION:
  4486. INPUT:
  4487. OUTPUT:
  4488. GLOBAL VARIABLES:
  4489. =============================================================================*/
  4490. int send_encoded_iso2_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct iso2EXIDocument *ccs_exi_doc_ISO2)
  4491. {
  4492. int errn = 0;
  4493. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4494. errn = encode_iso2_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_ISO2);
  4495. // STEP 2: =========== Send Response Packet ===========
  4496. int rtn = 0;
  4497. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4498. if (rtn == v2g_tx_stream->size)
  4499. {
  4500. /*
  4501. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][send_encoded_iso2_V2GTP_Stream] Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4502. rtn, v2g_tx_stream->size);
  4503. */
  4504. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4505. }
  4506. else if (rtn >= 0)
  4507. {
  4508. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][send_encoded_iso2_V2GTP_Stream]Imcomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n",
  4509. rtn, v2g_tx_stream->size);
  4510. }
  4511. else
  4512. {
  4513. errn = rtn;
  4514. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][send_encoded_iso2_V2GTP_Stream]send(): %d (DEC)\n", errn);
  4515. }
  4516. //STEP 3: ========= Reset V2G MSG Flags ==========
  4517. init_iso2BodyType(&ccs_exi_doc_ISO2->V2G_Message.Body);
  4518. return errn;
  4519. }
  4520. /*===========================================================================
  4521. FUNCTION: Check_din_V2G_Rx_MSG_SessionID
  4522. DESCRIPTION:
  4523. PRE-CONDITION:
  4524. INPUT:
  4525. OUTPUT:
  4526. GLOBAL VARIABLES:
  4527. =============================================================================*/
  4528. int Check_din_V2G_Rx_MSG_SessionID(struct dinEXIDocument *exi_doc_DIN)
  4529. {
  4530. int i = 0;
  4531. int leng = 0;
  4532. int errn = 0;
  4533. leng = exi_doc_DIN->V2G_Message.Header.SessionID.bytesLen;
  4534. //Step 1: Check SessionID Length
  4535. if (leng != 8) //8-byte
  4536. {
  4537. sprintf(buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4538. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4539. errn = -1;
  4540. }
  4541. else
  4542. {
  4543. //Step 2-1: Check SessionID content
  4544. for (i = 0; i < leng; i++)
  4545. {
  4546. if (exi_doc_DIN->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4547. {
  4548. errn = -2;
  4549. break;
  4550. }
  4551. }
  4552. }
  4553. //Step 2-2: Print Incorrect ID
  4554. if (errn == -2) //incorrect ID
  4555. {
  4556. sprintf(buf_log_evcomm,
  4557. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4558. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[0],
  4559. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[1],
  4560. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[2],
  4561. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[3],
  4562. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[4],
  4563. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[5],
  4564. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[6],
  4565. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[7],
  4566. EVCOMM_SYS_INFO.SessionID[0],
  4567. EVCOMM_SYS_INFO.SessionID[1],
  4568. EVCOMM_SYS_INFO.SessionID[2],
  4569. EVCOMM_SYS_INFO.SessionID[3],
  4570. EVCOMM_SYS_INFO.SessionID[4],
  4571. EVCOMM_SYS_INFO.SessionID[5],
  4572. EVCOMM_SYS_INFO.SessionID[6],
  4573. EVCOMM_SYS_INFO.SessionID[7]
  4574. );
  4575. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4576. }
  4577. //Step 3: Correct SessionID for Res Message
  4578. if (errn != 0)
  4579. {
  4580. exi_doc_DIN->V2G_Message.Header.SessionID.bytesLen = 8;
  4581. memset(exi_doc_DIN->V2G_Message.Header.SessionID.bytes, 0, 8);
  4582. memcpy(exi_doc_DIN->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4583. }
  4584. return errn;
  4585. }
  4586. /*===========================================================================
  4587. FUNCTION: Check_iso1_V2G_Rx_MSG_SessionID
  4588. DESCRIPTION:
  4589. PRE-CONDITION:
  4590. INPUT:
  4591. OUTPUT:
  4592. GLOBAL VARIABLES:
  4593. =============================================================================*/
  4594. int Check_iso1_V2G_Rx_MSG_SessionID(struct iso1EXIDocument *exi_doc_ISO1)
  4595. {
  4596. int i = 0;
  4597. int leng = 0;
  4598. int errn = 0;
  4599. leng = exi_doc_ISO1->V2G_Message.Header.SessionID.bytesLen;
  4600. //Step 1: Check SessionID Length
  4601. if (leng != 8) //8-byte
  4602. {
  4603. sprintf(buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4604. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4605. errn = -1;
  4606. }
  4607. else
  4608. {
  4609. //Step 2-1: Check SessionID content
  4610. for (i = 0; i < leng; i++)
  4611. {
  4612. if (exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4613. {
  4614. errn = -2;
  4615. break;
  4616. }
  4617. }
  4618. }
  4619. //Step 2-2: Print Incorrect ID
  4620. if (errn == -2) //incorrect ID
  4621. {
  4622. sprintf(buf_log_evcomm,
  4623. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4624. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[0],
  4625. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[1],
  4626. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[2],
  4627. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[3],
  4628. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[4],
  4629. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[5],
  4630. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[6],
  4631. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[7],
  4632. EVCOMM_SYS_INFO.SessionID[0],
  4633. EVCOMM_SYS_INFO.SessionID[1],
  4634. EVCOMM_SYS_INFO.SessionID[2],
  4635. EVCOMM_SYS_INFO.SessionID[3],
  4636. EVCOMM_SYS_INFO.SessionID[4],
  4637. EVCOMM_SYS_INFO.SessionID[5],
  4638. EVCOMM_SYS_INFO.SessionID[6],
  4639. EVCOMM_SYS_INFO.SessionID[7]
  4640. );
  4641. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4642. }
  4643. //Step 3: Correct SessionID for Res Message
  4644. if (errn != 0)
  4645. {
  4646. exi_doc_ISO1->V2G_Message.Header.SessionID.bytesLen = 8;
  4647. memset(exi_doc_ISO1->V2G_Message.Header.SessionID.bytes, 0, 8);
  4648. memcpy(exi_doc_ISO1->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4649. }
  4650. return errn;
  4651. }
  4652. /*===========================================================================
  4653. FUNCTION: Check_iso2_V2G_Rx_MSG_SessionID
  4654. DESCRIPTION:
  4655. PRE-CONDITION:
  4656. INPUT:
  4657. OUTPUT:
  4658. GLOBAL VARIABLES:
  4659. =============================================================================*/
  4660. int Check_iso2_V2G_Rx_MSG_SessionID(struct iso2EXIDocument *exi_doc_ISO2)
  4661. {
  4662. int i = 0;
  4663. int leng = 0;
  4664. int errn = 0;
  4665. leng = exi_doc_ISO2->V2G_Message.Header.SessionID.bytesLen;
  4666. //Step 1: Check SessionID Length
  4667. if (leng != 8) //8-byte
  4668. {
  4669. sprintf(buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4670. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4671. errn = -1;
  4672. }
  4673. else
  4674. {
  4675. //Step 2-1: Check SessionID content
  4676. for (i = 0; i < leng; i++)
  4677. {
  4678. if (exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4679. {
  4680. errn = -2;
  4681. break;
  4682. }
  4683. }
  4684. }
  4685. //Step 2-2: Print Incorrect ID
  4686. if (errn == -2) //incorrect ID
  4687. {
  4688. sprintf(buf_log_evcomm,
  4689. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4690. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[0],
  4691. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[1],
  4692. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[2],
  4693. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[3],
  4694. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[4],
  4695. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[5],
  4696. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[6],
  4697. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[7],
  4698. EVCOMM_SYS_INFO.SessionID[0],
  4699. EVCOMM_SYS_INFO.SessionID[1],
  4700. EVCOMM_SYS_INFO.SessionID[2],
  4701. EVCOMM_SYS_INFO.SessionID[3],
  4702. EVCOMM_SYS_INFO.SessionID[4],
  4703. EVCOMM_SYS_INFO.SessionID[5],
  4704. EVCOMM_SYS_INFO.SessionID[6],
  4705. EVCOMM_SYS_INFO.SessionID[7]
  4706. );
  4707. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4708. }
  4709. //Step 3: Correct SessionID for Res Message
  4710. if (errn != 0)
  4711. {
  4712. exi_doc_ISO2->V2G_Message.Header.SessionID.bytesLen = 8;
  4713. memset(exi_doc_ISO2->V2G_Message.Header.SessionID.bytes, 0, 8);
  4714. memcpy(exi_doc_ISO2->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4715. }
  4716. return errn;
  4717. }
  4718. /*===========================================================================
  4719. FUNCTION: GetSchemaID_of_Protocol
  4720. DESCRIPTION:
  4721. 1. Get the SchemaID accroding to the input target
  4722. *V2GT_MSG_PROTOCOL_DIN70121: choose DIN 70121
  4723. *V2GT_MSG_PROTOCOL_ISO15118_2014: choose ISO 15118-2 (ed1)
  4724. *V2GT_MSG_PROTOCOL_ISO15118_2018: choose ISO 15118-20 (ed2)
  4725. *V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY: choose the one with the highest priority
  4726. 2. [To-do] Checking Major and Minor version
  4727. 3. The parsing method will not support those private protocols,
  4728. such as "usr:tesla...," since "tesla" is 5 bytes but "din" and "iso" are 3 bytes.
  4729. 4. [To-do] If the target is selected as DIN," but there is no DIN.
  4730. However, if EV and EVSE all support ISO, how to use ISO instead?
  4731. PRE-CONDITION:
  4732. INPUT:
  4733. 1. target: target protocol
  4734. OUTPUT:
  4735. 1. id: SchemaID of selected protocol by EVSE
  4736. 2. ShmCcsData->CommProtocol (selected protocol)
  4737. 3. SupportedAppProtocol_result
  4738. (1) appHandresponseCodeType_OK_SuccessfulNegotiation = 0,
  4739. (2) appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation = 1,
  4740. (3) appHandresponseCodeType_Failed_NoNegotiation = 2
  4741. GLOBAL VARIABLES:
  4742. 1. ccs_handshake
  4743. 2. ShmCcsData
  4744. =============================================================================*/
  4745. int GetSchemaID_of_Protocol(unsigned char target)
  4746. {
  4747. int i = 0;
  4748. int ii = 0;
  4749. int id = 0;
  4750. unsigned char tmp = 0;
  4751. unsigned char pri = 20; //priority = 1(highest)~20(lowerest)
  4752. char num[10];
  4753. //struct CCS_ProtocolNamespacestructCharacters pro;
  4754. //Choose the 1st protocol as default.
  4755. //id = CCS_HANDSHAKE_PROTOCOLS.array[0].SchemaID;
  4756. id = -1;
  4757. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4758. for(i = 0; i < CCS_HANDSHAKE_PROTOCOLS.arrayLen; i++)
  4759. {
  4760. //Checking for <ProtocolNamespace>urn:din:70121:2012:MsgDef</ProtocolNamespace>
  4761. //[To-Do] Ignoring the priority from EV and force DIN 70121 as our only option. (for temp)
  4762. //[CAUTION] The parsing method will not support those private protocols, such as "usr:tesla..."
  4763. num[0] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[8];
  4764. num[1] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[9];
  4765. num[2] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[10];
  4766. num[3] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[11];
  4767. num[4] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[12];
  4768. num[5] = '\0';
  4769. if (atoi(num) == 70121)
  4770. {
  4771. sprintf(buf_log_evcomm,
  4772. "[GetSchemaID_of_Protocol]supported(%d-th/%d): DIN 70121(%d:v%d.%d;id=%d,pri=%d)",
  4773. (i+1),
  4774. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4775. atoi(num),
  4776. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4777. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4778. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4779. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4780. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4781. if (target == V2GT_MSG_PROTOCOL_DIN70121)
  4782. {
  4783. sprintf(buf_log_evcomm,
  4784. "[GetSchemaID_of_Protocol]selected(%d-th/%d): DIN 70121(%d:v%d.%d;id=%d,pri=%d)",
  4785. (i+1),
  4786. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4787. atoi(num),
  4788. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4789. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4790. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4791. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4792. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4793. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == DIN_SPEC_70121_2012_VersionNumberMajor)
  4794. {
  4795. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == DIN_SPEC_70121_2012_VersionNumberMinor)
  4796. {
  4797. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4798. }
  4799. else
  4800. { //[TC_SECC_VTB_SupportedAppProtocol_005]
  4801. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4802. }
  4803. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4804. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4805. return id;
  4806. }
  4807. else
  4808. {
  4809. //keep looking for the suitable protocol
  4810. }
  4811. }
  4812. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4813. {
  4814. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4815. {
  4816. ii = i;
  4817. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4818. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4819. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4820. }
  4821. else
  4822. {
  4823. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  4824. }
  4825. }
  4826. else
  4827. {
  4828. //null
  4829. }
  4830. }
  4831. else if (atoi(num) == 15118)
  4832. {
  4833. //urn:din:70121:2012:MsgDef
  4834. //urn:iso:15118:2:2013:MsgDef
  4835. memset(num, 0, sizeof(num));
  4836. num[0] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[16];
  4837. num[1] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[17];
  4838. num[2] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[18];
  4839. num[3] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[19];
  4840. num[4] = '\0';
  4841. if (atoi(num) < 2018 && atoi(num) >= 2010)
  4842. {
  4843. sprintf(buf_log_evcomm,
  4844. "[GetSchemaID_of_Protocol]supported(%d-th/%d): ISO 15118-2(ed1,%d:v%d.%d;id=%d,pri=%d)",
  4845. (i+1),
  4846. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4847. atoi(num),
  4848. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4849. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4850. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4851. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4852. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4853. if (target == V2GT_MSG_PROTOCOL_ISO15118_2014)
  4854. {
  4855. sprintf(buf_log_evcomm,
  4856. "[GetSchemaID_of_Protocol]selected(%d-th/%d): ISO 15118-2,ed1(%d:v%d.%d;id=%d,pri=%d)",
  4857. (i+1),
  4858. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4859. atoi(num),
  4860. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4861. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4862. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4863. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4864. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4865. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == ISO1_15118_2013_VersionNumberMajor)
  4866. {
  4867. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == ISO1_15118_2013_VersionNumberMinor)
  4868. {
  4869. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4870. }
  4871. else
  4872. {
  4873. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4874. }
  4875. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4876. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2014;
  4877. return id;
  4878. }
  4879. else
  4880. {
  4881. //keep looking for the suitable protocol
  4882. }
  4883. }
  4884. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4885. {
  4886. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4887. {
  4888. ii = i;
  4889. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4890. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4891. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2014;
  4892. }
  4893. else
  4894. {
  4895. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  4896. }
  4897. }
  4898. else
  4899. {
  4900. //null
  4901. }
  4902. }
  4903. else if (atoi(num) >= 2018 && atoi(num) <= 2100) // >= 2018
  4904. {
  4905. sprintf(buf_log_evcomm,
  4906. "[GetSchemaID_of_Protocol]supported(%d-th/%d): ISO 15118-20(ed2,%d:v%d.%d;id=%d,pri=%d)",
  4907. (i+1),
  4908. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4909. atoi(num),
  4910. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4911. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4912. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4913. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4914. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4915. if (target == V2GT_MSG_PROTOCOL_ISO15118_2018)
  4916. {
  4917. sprintf(buf_log_evcomm,
  4918. "[GetSchemaID_of_Protocol]selected(%d-th/%d): ISO 15118-20,ed2(%d:v%d.%d;id=%d,pri=%d)",
  4919. (i+1),
  4920. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4921. atoi(num),
  4922. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4923. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4924. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4925. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4926. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4927. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == ISO2_15118_2018_VersionNumberMajor)
  4928. {
  4929. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == ISO2_15118_2018_VersionNumberMinor)
  4930. {
  4931. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4932. }
  4933. else
  4934. {
  4935. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4936. }
  4937. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4938. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2018;
  4939. return id;
  4940. }
  4941. else
  4942. {
  4943. //keep looking for the suitable protocol
  4944. }
  4945. }
  4946. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4947. {
  4948. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4949. {
  4950. ii = i;
  4951. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4952. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4953. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2018;
  4954. }
  4955. else
  4956. {
  4957. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  4958. }
  4959. }
  4960. else
  4961. {
  4962. //null
  4963. }
  4964. }
  4965. else
  4966. {
  4967. //Unexpected Year
  4968. sprintf(buf_log_evcomm,
  4969. "[GetSchemaID_of_Protocol]unsupported(%d-th/%d): ISO 15118-X(unexpected year:%d,v%d.%d),id=%d,pri=%d",
  4970. (i+1),
  4971. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4972. atoi(num),
  4973. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4974. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4975. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4976. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4977. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4978. //return -1;
  4979. }
  4980. }
  4981. else
  4982. {
  4983. sprintf(buf_log_evcomm,
  4984. "[GetSchemaID_of_Protocol]unsupported protocol(%d-th/%d)(%d:v%d.%d;id=%d,pri=%d)",
  4985. (i+1),
  4986. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4987. atoi(num),
  4988. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4989. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4990. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4991. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4992. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  4993. //return -1;
  4994. }
  4995. }
  4996. //The final result of highest priority protocol
  4997. sprintf(buf_log_evcomm,
  4998. "[GetSchemaID_of_Protocol]selected(%d-th/%d): pro=%d(0:DIN,1:ISO1,2:ISO2);id=%d,pri=%d",
  4999. (ii+1),
  5000. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  5001. ShmCcsData->CommProtocol,
  5002. id,
  5003. pri);
  5004. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5005. if (id < 0)
  5006. {
  5007. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_Failed_NoNegotiation;
  5008. }
  5009. return id;
  5010. }
  5011. /*===========================================================================
  5012. FUNCTION: Proc_supportedAppProtocolRes
  5013. DESCRIPTION:
  5014. PRE-CONDITION:
  5015. INPUT:
  5016. OUTPUT:
  5017. GLOBAL VARIABLES:
  5018. =============================================================================*/
  5019. int Proc_supportedAppProtocolRes(int AcceptFd)
  5020. {
  5021. int errn = 0;
  5022. bitstream_t v2g_tx_stream;
  5023. static struct ChargingInfoData *sys;
  5024. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5025. //STEP 1: =========== Setting the Response Message ===========
  5026. init_appHandEXIDocument(&ccs_handshake);
  5027. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_OK_SuccessfulNegotiation;
  5028. ccs_handshake.supportedAppProtocolRes_isUsed = 1u;
  5029. //select the 1st one as the default
  5030. ccs_handshake.supportedAppProtocolRes.SchemaID = CCS_HANDSHAKE_PROTOCOLS.array[0].SchemaID;
  5031. ccs_handshake.supportedAppProtocolRes.SchemaID_isUsed = 1u;
  5032. int id = 0;
  5033. /*+++ 20200808, vern, support both DIN and ISO +++*/
  5034. // id = GetSchemaID_of_Protocol(V2GT_MSG_PROTOCOL_PREFERENCE); //output: EVCOMM_SYS_INFO.SupportedAppProtocol_result
  5035. id = GetSchemaID_of_Protocol(V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY); //output: EVCOMM_SYS_INFO.SupportedAppProtocol_result
  5036. /*--- 20200808, vern, support both DIN and ISO ---*/
  5037. ccs_handshake.supportedAppProtocolRes.ResponseCode = EVCOMM_SYS_INFO.SupportedAppProtocol_result; //updating the response code
  5038. if (id < 0)
  5039. {
  5040. sprintf(buf_log_evcomm,
  5041. "[Error]No avalible CCS protocol (id = %d, preference = %d)",
  5042. id,
  5043. V2GT_MSG_PROTOCOL_PREFERENCE);
  5044. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5045. }
  5046. else
  5047. {
  5048. //selected SchemaID
  5049. ccs_handshake.supportedAppProtocolRes.SchemaID = (unsigned char) id;
  5050. }
  5051. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  5052. {
  5053. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_supportedAppProtocolRes]EVSE_Shutdown => End_Process");
  5054. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5055. errn = -1;
  5056. }
  5057. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5058. {
  5059. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_supportedAppProtocolRes]EVSE_EmergencyShutdown => End_Process");
  5060. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5061. errn = -1;
  5062. }
  5063. else
  5064. {
  5065. //null
  5066. }
  5067. //Check for Permission Changing from TRUE to FALSE
  5068. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5069. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  5070. ShmInternalComm->ChargingPermission == FALSE)
  5071. {
  5072. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][supportedAppProtocolRes]Permission OFF");
  5073. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5074. //errn = -1;
  5075. }
  5076. #if (CP_PROTECTION_MECHANISM == ENABLE)
  5077. {
  5078. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  5079. {
  5080. //Detect for CP State should be 9V with 5% PWM or 100%PWM (State B1, B2)
  5081. if (sys->CpState != 2 && sys->CpState != 3) //State B1, B2
  5082. {
  5083. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5084. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5085. Update_V2G_Flow_Status(Other_Fault);
  5086. sprintf(buf_log_evcomm,
  5087. "[Proc_supportedAppProtocolRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  5088. sys->CpState,
  5089. sys->CpVoltage);
  5090. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5091. }
  5092. }
  5093. #else
  5094. {
  5095. //Detect for CP State should be 9V (State B)
  5096. if (sys->CpState != 3) //B2
  5097. {
  5098. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  5099. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5100. Update_V2G_Flow_Status(Other_Fault);
  5101. sprintf(buf_log_evcomm,
  5102. "[Proc_supportedAppProtocolRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  5103. sys->CpState,
  5104. sys->CpVoltage);
  5105. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5106. }
  5107. }
  5108. #endif
  5109. }
  5110. #endif
  5111. //STEP 2: =========== Encode into EXI ===========
  5112. if (errn = API_V2GMSG_EXI_Encoder_AppProtocol(&ccs_handshake, &v2g_tx_stream) !=0)
  5113. {
  5114. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Error]API_V2GMSG_EXI_Encoder_AppProtocol\n");
  5115. return errn;
  5116. }
  5117. //STEP 3: =========== Send Response Packet ===========
  5118. int Rtn = 0;
  5119. Rtn = send(AcceptFd, v2g_tx_stream.data, v2g_tx_stream.size, 0);
  5120. //Rtn = send(6, v2g_tx_stream.data, v2g_tx_stream.size, 0);
  5121. DEBUG_PRINTF_EVCOMM_DETAIL("Send V2GTP Packet Size = %d, Rtn = %d (Bytes, DEC)\n", v2g_tx_stream.size, Rtn);
  5122. if (Rtn < 0)
  5123. {
  5124. return Rtn;
  5125. }
  5126. //STEP 4: =========== Save into Share Memory =========
  5127. //[Joseph, To-Do] Adding a mechanism to choose DIN 70121 as our 1st priority. (for multiple protocols)
  5128. //STEP 5: =========== Updating the Flow State Flag =========
  5129. if (id < 0)
  5130. {
  5131. errn = -1;
  5132. }
  5133. //STEP 6: =========== Reset Flags ============
  5134. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  5135. init_appHandEXIDocument(&ccs_handshake);
  5136. return errn;
  5137. }
  5138. /*===========================================================================
  5139. FUNCTION: Proc_supportedAppProtocolReq
  5140. DESCRIPTION:
  5141. PRE-CONDITION:
  5142. INPUT:
  5143. OUTPUT:
  5144. GLOBAL VARIABLES:
  5145. =============================================================================*/
  5146. int Proc_supportedAppProtocolReq(int AcceptFd)
  5147. {
  5148. //[Joseph, To-Do] analysis on Req message and choose the prefered protocol
  5149. //Default: DIN 70121 (find SchemaID)
  5150. int errn = 0;
  5151. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]supportedAppProtocolReq");
  5152. SHM_Save_din_supportedAppProtocolReq(ShmCcsData, &ccs_handshake, ShmSysConfigAndInfo);
  5153. errn = Proc_supportedAppProtocolRes(AcceptFd);
  5154. if (errn == 0)
  5155. {
  5156. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Tx]supportedAppProtocolRes");
  5157. }
  5158. else
  5159. {
  5160. DEBUG_PRINTF_EVCOMM_DETAIL("[Error]Proc_supportedAppProtocolRes(): %d (DEC)\n", errn);
  5161. }
  5162. return errn;
  5163. }
  5164. /*===========================================================================
  5165. FUNCTION: Proc_din_SessionSetupRes
  5166. DESCRIPTION:
  5167. PRE-CONDITION:
  5168. INPUT:
  5169. OUTPUT:
  5170. GLOBAL VARIABLES:
  5171. =============================================================================*/
  5172. int Proc_din_SessionSetupRes(int AcceptFd)
  5173. {
  5174. int i = 0;
  5175. int errn = 0;
  5176. bitstream_t v2g_tx_stream;
  5177. static struct ChargingInfoData *sys;
  5178. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5179. size_t pos = 0;
  5180. v2g_tx_stream.pos = &pos;
  5181. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5182. v2g_tx_stream.data = V2GTP_Tx_buf;
  5183. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5184. init_dinSessionSetupResType(&ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes);
  5185. // ====== [BODY (1/2) ResponseCode ======
  5186. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5187. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_OK_NewSessionEstablished;
  5188. //[HEADER] Assign Res SessionID
  5189. ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytesLen = 8;
  5190. memset(ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytes, 0, 8);
  5191. memcpy(ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5192. //Check for SequenceError
  5193. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5194. {
  5195. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError;
  5196. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  5197. errn = -1;
  5198. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5199. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5200. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5201. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5202. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5203. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5204. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5205. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5206. }
  5207. //#if PARAMETER_NORMAL_MODE == ENABLE
  5208. //SHM_Read_din_V2GMSG_Header(&ccs_exi_doc_DIN, ShmCcsData);
  5209. //#endif
  5210. //Detect for CP State should be 9V (State B)
  5211. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5212. {
  5213. #if CP_PROTECTION_MECHANISM == ENABLE
  5214. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5215. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5216. Update_V2G_Flow_Status(Other_Fault);
  5217. errn = -1;
  5218. sprintf(buf_log_evcomm,
  5219. "[Proc_din_SessionSetupRes]Emergency Stop by CP Error (%d)\n",
  5220. sys->CpState);
  5221. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5222. #else
  5223. sprintf(buf_log_evcomm,
  5224. "[Proc_din_SessionSetupRes]Emergency Stop by CP Error (%d): ignored\n",
  5225. sys->CpState);
  5226. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5227. #endif
  5228. }
  5229. //Check for shutdown commands from EVSE(DC Main Board)
  5230. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5231. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5232. {
  5233. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5234. sprintf(buf_log_evcomm, "[Proc_din_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5235. EVSE_Shutdown,
  5236. EVSE_EmergencyShutdown,
  5237. sys->DC_EVSEStatus);
  5238. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5239. errn = -1;
  5240. }
  5241. //Check for Permission Changing from TRUE to FALSE
  5242. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5243. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  5244. ShmInternalComm->ChargingPermission == FALSE)
  5245. {
  5246. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][SessionSetupRes]Permission OFF");
  5247. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5248. errn = -1;
  5249. }
  5250. // ====== [BODY (2/3) EVSEID ======
  5251. //EVSEID = all zero
  5252. memset(ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytes, 0, sizeof(ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytes));
  5253. //vern, should be encode by SN
  5254. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytesLen = 1; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5255. // ====== [BODY (3/3) DateTimeNow ======
  5256. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.DateTimeNow_isUsed = 1u;
  5257. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.DateTimeNow = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5258. #if PARAMETER_NORMAL_MODE == ENABLE
  5259. ///////////SHM_Read_din_SessionSetupRes(&ccs_exi_doc_DIN, ShmCcsData);
  5260. #endif
  5261. // ============ Encode and Send Response Message ===========
  5262. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5263. {
  5264. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_SessionSetupRes][Error]Tx encoded msg error");
  5265. errn = -1;
  5266. }
  5267. return errn;
  5268. }
  5269. /*===========================================================================
  5270. FUNCTION: Proc_iso1_SessionSetupRes
  5271. DESCRIPTION:
  5272. PRE-CONDITION:
  5273. INPUT:
  5274. OUTPUT:
  5275. GLOBAL VARIABLES:
  5276. =============================================================================*/
  5277. int Proc_iso1_SessionSetupRes(int AcceptFd)
  5278. {
  5279. int i = 0;
  5280. int errn = 0;
  5281. bitstream_t v2g_tx_stream;
  5282. static struct ChargingInfoData *sys;
  5283. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5284. size_t pos = 0;
  5285. v2g_tx_stream.pos = &pos;
  5286. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5287. v2g_tx_stream.data = V2GTP_Tx_buf;
  5288. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5289. init_iso1SessionSetupResType(&ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes);
  5290. // ====== [BODY (1/2) ResponseCode ======
  5291. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5292. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_OK_NewSessionEstablished;
  5293. //[HEADER] Assign Res SessionID
  5294. ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytesLen = 8;
  5295. memset(ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytes, 0, 8);
  5296. memcpy(ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5297. //Check for SequenceError
  5298. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5299. {
  5300. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5301. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  5302. errn = -1;
  5303. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5304. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5305. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5306. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5307. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5308. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5309. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5310. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5311. }
  5312. //#if PARAMETER_NORMAL_MODE == ENABLE
  5313. //SHM_Read_iso1_V2GMSG_Header(&ccs_exi_doc_ISO1, ShmCcsData);
  5314. //#endif
  5315. //Detect for CP State should be 9V (State B)
  5316. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5317. {
  5318. #if CP_PROTECTION_MECHANISM == ENABLE
  5319. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5320. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5321. Update_V2G_Flow_Status(Other_Fault);
  5322. errn = -1;
  5323. sprintf(buf_log_evcomm,
  5324. "[Proc_iso1_SessionSetupRes]Emergency Stop by CP Error (%d)\n",
  5325. sys->CpState);
  5326. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5327. #else
  5328. sprintf(buf_log_evcomm,
  5329. "[Proc_iso1_SessionSetupRes]Emergency Stop by CP Error (%d): ignored\n",
  5330. sys->CpState);
  5331. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5332. #endif
  5333. }
  5334. //Check for shutdown commands from EVSE(DC Main Board)
  5335. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5336. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5337. {
  5338. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5339. sprintf(buf_log_evcomm, "[Proc_iso1_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5340. EVSE_Shutdown,
  5341. EVSE_EmergencyShutdown,
  5342. sys->DC_EVSEStatus);
  5343. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5344. errn = -1;
  5345. }
  5346. //Check for Permission Changing from TRUE to FALSE
  5347. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  5348. ShmInternalComm->ChargingPermission == FALSE)
  5349. {
  5350. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO1][SessionSetupRes]Permission OFF");
  5351. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5352. errn = -1;
  5353. }
  5354. // ====== [BODY (2/3) EVSEID ======
  5355. //EVSEID = all zero
  5356. memset(ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters, 0, sizeof(ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters));
  5357. /*+++ 20200808, vern, set default EVSEID +++*/
  5358. //vern, should be encoded by SN
  5359. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[0]='Z';
  5360. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[1]='Z';
  5361. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[2]='0';
  5362. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[3]='0';
  5363. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[4]='0';
  5364. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[5]='0';
  5365. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[6]='0';
  5366. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 7; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5367. /*--- 20200808, vern, set default EVSEID ---*/
  5368. // ====== [BODY (3/3) DateTimeNow ======
  5369. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  5370. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSETimeStamp = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5371. #if PARAMETER_NORMAL_MODE == ENABLE
  5372. ///////////SHM_Read_iso1_SessionSetupRes(&ccs_exi_doc_ISO1, ShmCcsData);
  5373. #endif
  5374. // ============ Encode and Send Response Message ===========
  5375. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  5376. {
  5377. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_SessionSetupRes][Error]Tx encoded msg error");
  5378. errn = -1;
  5379. }
  5380. return errn;
  5381. }
  5382. /*===========================================================================
  5383. FUNCTION: Proc_iso2_SessionSetupRes
  5384. DESCRIPTION:
  5385. PRE-CONDITION:
  5386. INPUT:
  5387. OUTPUT:
  5388. GLOBAL VARIABLES:
  5389. =============================================================================*/
  5390. int Proc_iso2_SessionSetupRes(int AcceptFd)
  5391. {
  5392. int i = 0;
  5393. int errn = 0;
  5394. bitstream_t v2g_tx_stream;
  5395. static struct ChargingInfoData *sys;
  5396. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5397. size_t pos = 0;
  5398. v2g_tx_stream.pos = &pos;
  5399. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5400. v2g_tx_stream.data = V2GTP_Tx_buf;
  5401. init_iso2BodyType(&ccs_exi_doc_ISO2.V2G_Message.Body);
  5402. init_iso2SessionSetupResType(&ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes);
  5403. // ====== [BODY (1/2) ResponseCode ======
  5404. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5405. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_OK_NewSessionEstablished;
  5406. //[HEADER] Assign Res SessionID
  5407. ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytesLen = 8;
  5408. memset(ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytes, 0, 8);
  5409. memcpy(ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5410. //Check for SequenceError
  5411. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5412. {
  5413. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5414. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  5415. errn = -1;
  5416. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5417. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5418. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5419. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5420. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5421. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5422. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5423. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5424. }
  5425. //#if PARAMETER_NORMAL_MODE == ENABLE
  5426. //SHM_Read_iso2_V2GMSG_Header(&ccs_exi_doc_ISO2, ShmCcsData);
  5427. //#endif
  5428. //Detect for CP State should be 9V (State B)
  5429. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5430. {
  5431. #if CP_PROTECTION_MECHANISM == ENABLE
  5432. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5433. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5434. Update_V2G_Flow_Status(Other_Fault);
  5435. errn = -1;
  5436. sprintf(buf_log_evcomm,
  5437. "[Proc_iso2_SessionSetupRes]Emergency Stop by CP Error (%d)",
  5438. sys->CpState);
  5439. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5440. #else
  5441. sprintf(buf_log_evcomm,
  5442. "[Proc_iso2_SessionSetupRes]Emergency Stop by CP Error (%d): ignored",
  5443. sys->CpState);
  5444. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5445. #endif
  5446. }
  5447. //Check for shutdown commands from EVSE(DC Main Board)
  5448. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5449. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5450. {
  5451. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5452. sprintf(buf_log_evcomm, "[Proc_iso2_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5453. EVSE_Shutdown,
  5454. EVSE_EmergencyShutdown,
  5455. sys->DC_EVSEStatus);
  5456. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5457. errn = -1;
  5458. }
  5459. //Check for Permission Changing from TRUE to FALSE
  5460. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5461. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  5462. ShmInternalComm->ChargingPermission == FALSE)
  5463. {
  5464. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO2][SessionSetupRes]Permission OFF");
  5465. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5466. errn = -1;
  5467. }
  5468. // ====== [BODY (2/3) EVSEID ======
  5469. //EVSEID = all zero
  5470. memset(ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.characters, 0, sizeof(ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.characters));
  5471. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 15; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5472. // ====== [BODY (3/3) DateTimeNow ======
  5473. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  5474. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSETimeStamp = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5475. #if PARAMETER_NORMAL_MODE == ENABLE
  5476. ///////////SHM_Read_iso2_SessionSetupRes(&ccs_exi_doc_ISO2, ShmCcsData);
  5477. #endif
  5478. // ============ Encode and Send Response Message ===========
  5479. if (send_encoded_iso2_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO2) != 0)
  5480. {
  5481. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso2_SessionSetupRes][Error]Tx encoded msg error");
  5482. errn = -1;
  5483. }
  5484. return errn;
  5485. }
  5486. /*===========================================================================
  5487. FUNCTION: Proc_din_SessionSetupReq
  5488. DESCRIPTION:
  5489. PRE-CONDITION:
  5490. INPUT:
  5491. OUTPUT:
  5492. GLOBAL VARIABLES:
  5493. 2. ccs_exi_doc_DIN
  5494. =============================================================================*/
  5495. int Proc_din_SessionSetupReq(int AcceptFd)
  5496. {
  5497. int errn = 0;
  5498. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Proc_din_SessionSetupReq]Got SessionSetupReq\n");
  5499. //Print the decoded XML Document
  5500. PRINT_XML_DOC_DIN_SessionSetupReq(&ccs_exi_doc_DIN);
  5501. //Save into Share Memory
  5502. SHM_Save_din_SessionSetupReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  5503. errn = Proc_din_SessionSetupRes(AcceptFd);
  5504. if (errn == 0)
  5505. {
  5506. //successfully send response.
  5507. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]SessionSetupRes");
  5508. }
  5509. else
  5510. {
  5511. sprintf(buf_log_evcomm,
  5512. "[Error]Proc_din_SessionSetupRes(): %d (DEC)",
  5513. errn);
  5514. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5515. }
  5516. return errn;
  5517. }
  5518. /*===========================================================================
  5519. FUNCTION: Proc_iso1_SessionSetupReq
  5520. DESCRIPTION:
  5521. PRE-CONDITION:
  5522. INPUT:
  5523. OUTPUT:
  5524. GLOBAL VARIABLES:
  5525. 2. ccs_exi_doc_ISO1
  5526. =============================================================================*/
  5527. int Proc_iso1_SessionSetupReq(int AcceptFd)
  5528. {
  5529. int errn = 0;
  5530. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Proc_iso1_SessionSetupReq]Got SessionSetupReq\n");
  5531. //Print the decoded XML Document
  5532. PRINT_XML_DOC_ISO1_SessionSetupReq(&ccs_exi_doc_ISO1);
  5533. //Save into Share Memory
  5534. SHM_Save_iso1_SessionSetupReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  5535. errn = Proc_iso1_SessionSetupRes(AcceptFd);
  5536. if (errn == 0)
  5537. {
  5538. //successfully send response.
  5539. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]SessionSetupRes");
  5540. }
  5541. else
  5542. {
  5543. sprintf(buf_log_evcomm,
  5544. "[Error]Proc_iso1_SessionSetupRes(): %d (DEC)",
  5545. errn);
  5546. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5547. }
  5548. return errn;
  5549. }
  5550. /*===========================================================================
  5551. FUNCTION: Proc_iso2_SessionSetupReq
  5552. DESCRIPTION:
  5553. PRE-CONDITION:
  5554. INPUT:
  5555. OUTPUT:
  5556. GLOBAL VARIABLES:
  5557. 2. ccs_exi_doc_ISO2
  5558. =============================================================================*/
  5559. int Proc_iso2_SessionSetupReq(int AcceptFd)
  5560. {
  5561. int errn = 0;
  5562. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Proc_iso2_SessionSetupReq]Got SessionSetupReq\n");
  5563. //Print the decoded XML Document
  5564. PRINT_XML_DOC_ISO2_SessionSetupReq(&ccs_exi_doc_ISO2);
  5565. //Save into Share Memory
  5566. SHM_Save_iso2_SessionSetupReq(ShmCcsData, &ccs_exi_doc_ISO2, ShmSysConfigAndInfo);
  5567. errn = Proc_iso2_SessionSetupRes(AcceptFd);
  5568. if (errn == 0)
  5569. {
  5570. //successfully send response.
  5571. SAVE_SYS_LOG_MSG_EVCOMM("[ISO2][V2G][Tx]SessionSetupRes");
  5572. }
  5573. else
  5574. {
  5575. sprintf(buf_log_evcomm,
  5576. "[Error]Proc_iso2_SessionSetupRes(): %d (DEC)",
  5577. errn);
  5578. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5579. }
  5580. return errn;
  5581. }
  5582. /*===========================================================================
  5583. FUNCTION: Proc_din_ServiceDiscoveryRes
  5584. DESCRIPTION:
  5585. PRE-CONDITION:
  5586. INPUT:
  5587. OUTPUT:
  5588. GLOBAL VARIABLES:
  5589. =============================================================================*/
  5590. int Proc_din_ServiceDiscoveryRes(int AcceptFd)
  5591. {
  5592. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5593. //if it is not the same, the packet should be ignored.
  5594. int i = 0;
  5595. int errn = 0;
  5596. bitstream_t v2g_tx_stream;
  5597. struct ChargingInfoData *sys;
  5598. struct ServiceDiscoveryRequest_DIN70121 *req;
  5599. struct ServiceDiscoveryResponse_DIN70121 *res;
  5600. size_t pos = 0;
  5601. v2g_tx_stream.pos = &pos;
  5602. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5603. v2g_tx_stream.data = V2GTP_Tx_buf;
  5604. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5605. req = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryRequest;
  5606. res = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryResponse;
  5607. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5608. init_dinServiceDiscoveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes);
  5609. //[1/4] Response Code
  5610. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
  5611. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_OK;
  5612. //[HEADER] Check Req SessionID
  5613. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  5614. {
  5615. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  5616. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  5617. errn = -1;
  5618. }
  5619. //Check for SequenceError
  5620. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5621. {
  5622. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  5623. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  5624. errn = -1;
  5625. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5626. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5627. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5628. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5629. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5630. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5631. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5632. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5633. }
  5634. //Detect for CP State should be 9V (State B)
  5635. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5636. {
  5637. #if CP_PROTECTION_MECHANISM == ENABLE
  5638. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5639. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5640. Update_V2G_Flow_Status(Other_Fault);
  5641. errn = -1;
  5642. sprintf(buf_log_evcomm,
  5643. "[Proc_din_ServiceDiscoveryRes]Emergency Stop by CP Error (%d)",
  5644. sys->CpState);
  5645. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5646. #else
  5647. sprintf(buf_log_evcomm,
  5648. "[Proc_din_ServiceDiscoveryRes]Emergency Stop by CP Error (%d): ignored",
  5649. sys->CpState);
  5650. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5651. #endif
  5652. }
  5653. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5654. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5655. {
  5656. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5657. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ServiceDiscoveryRes]shutdown by EVSE");
  5658. errn = -1;
  5659. }
  5660. //Check for Permission Changing from TRUE to FALSE
  5661. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5662. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  5663. ShmInternalComm->ChargingPermission == FALSE)
  5664. {
  5665. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][ServiceDiscoveryRes]Permission OFF");
  5666. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5667. errn = -1;
  5668. }
  5669. //[2/4] PaymentOptions
  5670. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.arrayLen = 1u;
  5671. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.array[0] = dinpaymentOptionType_ExternalPayment; //1
  5672. //[3/4] Charge Service
  5673. res->ChargeService_DIN70121.Services.ServiceTag.ServiceID = 1;
  5674. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceID = (unsigned short) res->ChargeService_DIN70121.Services.ServiceTag.ServiceID;
  5675. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceCategory = dinserviceCategoryType_EVCharging;
  5676. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.FreeService = 1; //[Joseph] for test
  5677. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.EnergyTransferType = dinEVSESupportedEnergyTransferType_DC_extended;
  5678. //[4/4] Service List (null, not be uesed for now.)
  5679. //#if PARAMETER_NORMAL_MODE == ENABLE
  5680. ///////////////SHM_Read_din_ServiceDiscoveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  5681. //#endif
  5682. // ============ Encode and Send Response Message ===========
  5683. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5684. {
  5685. errn = -1;
  5686. }
  5687. return errn;
  5688. }
  5689. /*===========================================================================
  5690. FUNCTION: Proc_iso1_ServiceDiscoveryRes
  5691. DESCRIPTION:
  5692. PRE-CONDITION:
  5693. INPUT:
  5694. OUTPUT:
  5695. GLOBAL VARIABLES:
  5696. =============================================================================*/
  5697. int Proc_iso1_ServiceDiscoveryRes(int AcceptFd)
  5698. {
  5699. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5700. //if it is not the same, the packet should be ignored.
  5701. int i = 0;
  5702. int errn = 0;
  5703. bitstream_t v2g_tx_stream;
  5704. struct ChargingInfoData *sys;
  5705. struct ServiceDiscoveryRequest_ISO15118_2014 *req;
  5706. struct ServiceDiscoveryResponse_ISO15118_2014 *res;
  5707. size_t pos = 0;
  5708. v2g_tx_stream.pos = &pos;
  5709. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5710. v2g_tx_stream.data = V2GTP_Tx_buf;
  5711. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5712. req = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryRequest;
  5713. res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryResponse;
  5714. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5715. init_iso1ServiceDiscoveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes);
  5716. //[1/4] Response Code
  5717. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
  5718. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_OK;
  5719. //[HEADER] Check Req SessionID
  5720. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  5721. {
  5722. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  5723. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  5724. errn = -1;
  5725. }
  5726. //Check for SequenceError
  5727. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5728. {
  5729. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5730. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  5731. errn = -1;
  5732. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5733. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5734. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5735. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5736. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5737. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5738. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5739. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5740. }
  5741. //Detect for CP State should be 9V (State B)
  5742. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5743. {
  5744. #if CP_PROTECTION_MECHANISM == ENABLE
  5745. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5746. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5747. Update_V2G_Flow_Status(Other_Fault);
  5748. errn = -1;
  5749. sprintf(buf_log_evcomm,
  5750. "[Proc_iso1_ServiceDiscoveryRes]Emergency Stop by CP Error (%d)",
  5751. sys->CpState);
  5752. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5753. #else
  5754. sprintf(buf_log_evcomm,
  5755. "[Proc_iso1_ServiceDiscoveryRes]Emergency Stop by CP Error (%d): ignored",
  5756. sys->CpState);
  5757. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5758. #endif
  5759. }
  5760. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5761. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5762. {
  5763. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5764. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ServiceDiscoveryRes]shutdown by EVSE");
  5765. errn = -1;
  5766. }
  5767. //Check for Permission Changing from TRUE to FALSE
  5768. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5769. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  5770. ShmInternalComm->ChargingPermission == FALSE)
  5771. {
  5772. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO1][ServiceDiscoveryRes]Permission OFF");
  5773. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5774. errn = -1;
  5775. }
  5776. //[2/4] PaymentOptionList
  5777. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.arrayLen = 1u;
  5778. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.array[0] = iso1paymentOptionType_ExternalPayment; //1
  5779. //[3/4] Charge Service
  5780. res->ChargeService.Services.ServiceID = 1;
  5781. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceID = (unsigned short) res->ChargeService.Services.ServiceID;
  5782. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName_isUsed = 1; //new in ISO1, not be used, yet.
  5783. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName.charactersLen = xxx;
  5784. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName.characters[i] = xxx;
  5785. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceCategory = iso1serviceCategoryType_EVCharging;
  5786. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.FreeService = 1; //[Joseph] for test
  5787. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.arrayLen = 1u; //[ISO1] max = 6
  5788. switch (ShmCcsData->EnergyTransferMode)
  5789. {
  5790. case DC_extended:
  5791. {
  5792. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_DC_extended;
  5793. break;
  5794. }
  5795. case AC_single_phase_core:
  5796. {
  5797. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_AC_single_phase_core;
  5798. break;
  5799. }
  5800. case AC_three_phase_core:
  5801. {
  5802. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_AC_three_phase_core;
  5803. break;
  5804. }
  5805. default:
  5806. {
  5807. sprintf(buf_log_evcomm,
  5808. "[ISO1][ServiceDiscoveryRes][Warning]unexpected EnergyTransferMode(%d)",
  5809. ShmCcsData->EnergyTransferMode);
  5810. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5811. break;
  5812. }
  5813. }
  5814. //[4/4] Service List (null, not be uesed for now.)
  5815. //#if PARAMETER_NORMAL_MODE == ENABLE
  5816. ///////////////SHM_Read_iso1_ServiceDiscoveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  5817. //#endif
  5818. // ============ Encode and Send Response Message ===========
  5819. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  5820. {
  5821. errn = -1;
  5822. }
  5823. return errn;
  5824. }
  5825. /*===========================================================================
  5826. FUNCTION: Proc_din_ServiceDiscoveryReq
  5827. DESCRIPTION:
  5828. PRE-CONDITION:
  5829. INPUT:
  5830. OUTPUT:
  5831. GLOBAL VARIABLES:
  5832. =============================================================================*/
  5833. int Proc_din_ServiceDiscoveryReq(int AcceptFd)
  5834. {
  5835. int errn = 0;
  5836. DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_din_ServiceDiscoveryReq]Got ServiceDiscoveryReq\n");
  5837. //Print the decoded XML Document
  5838. PRINT_XML_DOC_DIN_ServiceDiscoveryReq(&ccs_exi_doc_DIN);
  5839. //Save into Share Memory
  5840. SHM_Save_din_ServiceDiscoveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  5841. errn = Proc_din_ServiceDiscoveryRes(AcceptFd);
  5842. if (errn == 0)
  5843. {
  5844. //send response successfully.
  5845. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]ServiceDiscoveryRes");
  5846. }
  5847. else
  5848. {
  5849. sprintf(buf_log_evcomm,
  5850. "[Error][SeccComm][Proc_din_ServiceDiscoveryReq]Proc_din_ServiceDiscoveryRes(): %d (DEC)",
  5851. errn
  5852. );
  5853. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5854. }
  5855. return errn;
  5856. }
  5857. /*===========================================================================
  5858. FUNCTION: Proc_iso1_ServiceDiscoveryReq
  5859. DESCRIPTION:
  5860. PRE-CONDITION:
  5861. INPUT:
  5862. OUTPUT:
  5863. GLOBAL VARIABLES:
  5864. =============================================================================*/
  5865. int Proc_iso1_ServiceDiscoveryReq(int AcceptFd)
  5866. {
  5867. int errn = 0;
  5868. DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_iso1_ServiceDiscoveryReq]Got ServiceDiscoveryReq\n");
  5869. //Print the decoded XML Document
  5870. PRINT_XML_DOC_ISO1_ServiceDiscoveryReq(&ccs_exi_doc_ISO1);
  5871. //Save into Share Memory
  5872. SHM_Save_iso1_ServiceDiscoveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  5873. errn = Proc_iso1_ServiceDiscoveryRes(AcceptFd);
  5874. if (errn == 0)
  5875. {
  5876. //send response successfully.
  5877. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]ServiceDiscoveryRes");
  5878. }
  5879. else
  5880. {
  5881. sprintf(buf_log_evcomm,
  5882. "[Error][SeccComm][Proc_iso1_ServiceDiscoveryReq]Proc_iso1_ServiceDiscoveryRes(): %d (DEC)",
  5883. errn
  5884. );
  5885. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5886. }
  5887. return errn;
  5888. }
  5889. /*===========================================================================
  5890. FUNCTION: Proc_din_ServiceAndPaymentSelectionRes
  5891. DESCRIPTION:
  5892. PRE-CONDITION:
  5893. INPUT:
  5894. OUTPUT:
  5895. GLOBAL VARIABLES:
  5896. =============================================================================*/
  5897. int Proc_din_ServiceAndPaymentSelectionRes(int AcceptFd)
  5898. {
  5899. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5900. //if it is not the same, the packet should be ignored.
  5901. int i = 0;
  5902. int errn = 0;
  5903. bitstream_t v2g_tx_stream;
  5904. struct ServiceAndPaymentSelectionRequest_DIN70121 *req;
  5905. struct ServiceAndPaymentSelectionResponse_DIN70121 *res;
  5906. struct ServiceDiscoveryResponse_DIN70121 *sd_res;
  5907. struct ChargingInfoData *sys;
  5908. size_t pos = 0;
  5909. v2g_tx_stream.pos = &pos;
  5910. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5911. v2g_tx_stream.data = V2GTP_Tx_buf;
  5912. req = &ShmCcsData->V2GMessage_DIN70121.ServiceAndPaymentSelectionRequest;
  5913. res = &ShmCcsData->V2GMessage_DIN70121.ServiceAndPaymentSelectionResponse;
  5914. sd_res = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryResponse;
  5915. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5916. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5917. init_dinServicePaymentSelectionResType(&ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes);
  5918. //[1/1] Response Code
  5919. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes_isUsed = 1u;
  5920. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_OK;
  5921. //[HEADER] Check Req SessionID
  5922. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  5923. {
  5924. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  5925. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  5926. errn = -1;
  5927. }
  5928. //Check for SequenceError
  5929. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5930. {
  5931. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  5932. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  5933. errn = -1;
  5934. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5935. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5936. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5937. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5938. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5939. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5940. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5941. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5942. }
  5943. //Check for SelectedPaymentOption (TC_SECC_VTB_ServicePaymentSelection_007)
  5944. if (req->SelectedPaymentOption != dinpaymentOptionType_ExternalPayment) //1
  5945. {
  5946. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_PaymentSelectionInvalid;
  5947. sprintf(buf_log_evcomm,
  5948. "[ERROR]unexpected SelectedPaymentOption(%d) => End_Process (EIM only, no PnC, yet.)",
  5949. req->SelectedPaymentOption);
  5950. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5951. errn = -1;
  5952. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5953. //CCS_SECC_ResponseCode_FAILED_Payment SelectionInvalid (023762)
  5954. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5955. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5956. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5957. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5958. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  5959. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  5960. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5961. }
  5962. //Check for ServiceID (TC_SECC_VTB_ServicePaymentSelection_004)
  5963. if (req->SelectedServiceList.SelectedService[0].ServiceID != sd_res->ChargeService_DIN70121.Services.ServiceTag.ServiceID)
  5964. {
  5965. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_ServiceSelectionInvalid; //8
  5966. sprintf(buf_log_evcomm,
  5967. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  5968. req->SelectedServiceList.SelectedService[0].ServiceID);
  5969. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5970. errn = -1;
  5971. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5972. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  5973. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5974. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5975. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5976. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5977. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  5978. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  5979. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5980. }
  5981. //Detect for CP State should be 9V (State B)
  5982. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5983. {
  5984. #if CP_PROTECTION_MECHANISM == ENABLE
  5985. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  5986. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5987. Update_V2G_Flow_Status(Other_Fault);
  5988. errn = -1;
  5989. sprintf(buf_log_evcomm,
  5990. "[Proc_din_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d)",
  5991. sys->CpState);
  5992. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5993. #else
  5994. sprintf(buf_log_evcomm,
  5995. "[Proc_din_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d): ignored due to function is disabled",
  5996. sys->CpState);
  5997. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  5998. #endif
  5999. }
  6000. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  6001. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6002. {
  6003. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ServiceAndPaymentSelectionRes]shutdown by EVSE");
  6004. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  6005. errn = -1;
  6006. }
  6007. //Check for Permission Changing from TRUE to FALSE
  6008. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  6009. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  6010. ShmInternalComm->ChargingPermission == FALSE)
  6011. {
  6012. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][ServicePaymentSelectionRes]Permission OFF");
  6013. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  6014. errn = -1;
  6015. }
  6016. // ============ Encode and Send Response Message ===========
  6017. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  6018. {
  6019. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ServiceAndPaymentSelectionRes]Tx encoded msg error");
  6020. errn = -1;
  6021. }
  6022. return errn;
  6023. }
  6024. /*===========================================================================
  6025. FUNCTION: Proc_iso1_ServiceAndPaymentSelectionRes
  6026. DESCRIPTION:
  6027. PRE-CONDITION:
  6028. INPUT:
  6029. OUTPUT:
  6030. GLOBAL VARIABLES:
  6031. =============================================================================*/
  6032. int Proc_iso1_ServiceAndPaymentSelectionRes(int AcceptFd)
  6033. {
  6034. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6035. //if it is not the same, the packet should be ignored.
  6036. int i = 0;
  6037. int errn = 0;
  6038. bitstream_t v2g_tx_stream;
  6039. struct ServiceAndPaymentSelectionRequest_ISO15118_2014 *req;
  6040. struct ServiceAndPaymentSelectionResponse_ISO15118_2014 *res;
  6041. struct ServiceDiscoveryResponse_ISO15118_2014 *sd_res;
  6042. static struct ChargingInfoData *sys;
  6043. size_t pos = 0;
  6044. v2g_tx_stream.pos = &pos;
  6045. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6046. v2g_tx_stream.data = V2GTP_Tx_buf;
  6047. req = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceAndPaymentSelectionRequest;
  6048. res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceAndPaymentSelectionResponse;
  6049. sd_res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryResponse;
  6050. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6051. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6052. init_iso1PaymentServiceSelectionResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes);
  6053. //[1/1] Response Code
  6054. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes_isUsed = 1u;
  6055. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_OK;
  6056. //[HEADER] Check Req SessionID
  6057. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  6058. {
  6059. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  6060. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  6061. errn = -1;
  6062. }
  6063. //Check for SequenceError
  6064. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6065. {
  6066. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  6067. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  6068. errn = -1;
  6069. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6070. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6071. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6072. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6073. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6074. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6075. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6076. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6077. }
  6078. //Check for SelectedPaymentOption (TC_SECC_VTB_ServicePaymentSelection_007)
  6079. if (req->SelectedPaymentOption != dinpaymentOptionType_ExternalPayment) //1
  6080. {
  6081. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_PaymentSelectionInvalid;
  6082. sprintf(buf_log_evcomm,
  6083. "[ERROR]unexpected SelectedPaymentOption(%d) => End_Process (EIM only, no PnC, yet.)",
  6084. req->SelectedPaymentOption);
  6085. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6086. errn = -1;
  6087. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6088. //CCS_SECC_ResponseCode_FAILED_Payment SelectionInvalid (023762)
  6089. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6090. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6091. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6092. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6093. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6094. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  6095. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6096. }
  6097. //Check for ServiceID (TC_SECC_VTB_ServicePaymentSelection_004)
  6098. if (req->SelectedServiceList.SelectedService[0].ServiceID != sd_res->ChargeService.Services.ServiceID)
  6099. {
  6100. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_ServiceSelectionInvalid; //8
  6101. sprintf(buf_log_evcomm,
  6102. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  6103. req->SelectedServiceList.SelectedService[0].ServiceID);
  6104. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6105. errn = -1;
  6106. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6107. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  6108. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6109. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6110. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6111. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6112. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  6113. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  6114. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6115. }
  6116. //Detect for CP State should be 9V (State B)
  6117. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6118. {
  6119. #if CP_PROTECTION_MECHANISM == ENABLE
  6120. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  6121. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6122. Update_V2G_Flow_Status(Other_Fault);
  6123. errn = -1;
  6124. sprintf(buf_log_evcomm,
  6125. "[Proc_iso1_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d)",
  6126. sys->CpState);
  6127. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6128. #else
  6129. sprintf(buf_log_evcomm,
  6130. "[Proc_iso1_ServiceAndPaymentSelectionRes]Emergency Stop by CP Error (%d): ignored due to function is disabled",
  6131. sys->CpState);
  6132. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6133. #endif
  6134. }
  6135. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  6136. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6137. {
  6138. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ServiceAndPaymentSelectionRes]shutdown by EVSE");
  6139. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  6140. errn = -1;
  6141. }
  6142. //Check for Permission Changing from TRUE to FALSE
  6143. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  6144. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  6145. ShmInternalComm->ChargingPermission == FALSE)
  6146. {
  6147. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO1][PaymentServiceSelectionRes]Permission OFF");
  6148. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  6149. errn = -1;
  6150. }
  6151. // ============ Encode and Send Response Message ===========
  6152. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  6153. {
  6154. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ServiceAndPaymentSelectionRes]Tx encoded msg error");
  6155. errn = -1;
  6156. }
  6157. return errn;
  6158. }
  6159. /*===========================================================================
  6160. FUNCTION: Proc_din_ServiceAndPaymentSelectionReq
  6161. DESCRIPTION:
  6162. PRE-CONDITION:
  6163. INPUT:
  6164. OUTPUT:
  6165. GLOBAL VARIABLES:
  6166. =============================================================================*/
  6167. int Proc_din_ServiceAndPaymentSelectionReq(int AcceptFd)
  6168. {
  6169. int errn = 0;
  6170. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][Proc_din_ServiceAndPaymentSelectionReq]Got ServiceAndPaymentSelectionReq");
  6171. //Print the decoded XML Document
  6172. PRINT_XML_DOC_DIN_ServiceAndPaymentSelectionReq(&ccs_exi_doc_DIN);
  6173. //Save into Share Memory
  6174. SHM_Save_din_ServiceAndPaymentSelectionReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  6175. errn = Proc_din_ServiceAndPaymentSelectionRes(AcceptFd);
  6176. if (errn == 0)
  6177. {
  6178. //send response successfully.
  6179. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]ServiceAndPaymentSelectionRes");
  6180. }
  6181. else
  6182. {
  6183. sprintf(buf_log_evcomm,
  6184. "[Error][Proc_iso1_ServiceAndPaymentSelectionReq]Proc_iso1_ServiceAndPaymentSelectionRes(): %d (DEC)",
  6185. errn);
  6186. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6187. }
  6188. return errn;
  6189. }
  6190. /*===========================================================================
  6191. FUNCTION: Proc_iso1_ServiceAndPaymentSelectionReq
  6192. DESCRIPTION:
  6193. PRE-CONDITION:
  6194. INPUT:
  6195. OUTPUT:
  6196. GLOBAL VARIABLES:
  6197. =============================================================================*/
  6198. int Proc_iso1_ServiceAndPaymentSelectionReq(int AcceptFd)
  6199. {
  6200. int errn = 0;
  6201. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][Proc_iso1_ServiceAndPaymentSelectionReq]Got ServiceAndPaymentSelectionReq");
  6202. //Print the decoded XML Document
  6203. PRINT_XML_DOC_ISO1_ServiceAndPaymentSelectionReq(&ccs_exi_doc_ISO1);
  6204. //Save into Share Memory
  6205. SHM_Save_iso1_ServiceAndPaymentSelectionReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  6206. errn = Proc_iso1_ServiceAndPaymentSelectionRes(AcceptFd);
  6207. if (errn == 0)
  6208. {
  6209. //send response successfully.
  6210. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]ServiceAndPaymentSelectionRes");
  6211. }
  6212. else
  6213. {
  6214. sprintf(buf_log_evcomm,
  6215. "[Error][Proc_iso1_ServiceAndPaymentSelectionReq]Proc_iso1_ServiceAndPaymentSelectionRes(): %d (DEC)",
  6216. errn);
  6217. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6218. }
  6219. return errn;
  6220. }
  6221. /*===========================================================================
  6222. FUNCTION: Proc_din_ContractAuthenticationRes
  6223. DESCRIPTION:
  6224. PRE-CONDITION:
  6225. INPUT:
  6226. OUTPUT:
  6227. GLOBAL VARIABLES:
  6228. =============================================================================*/
  6229. int Proc_din_ContractAuthenticationRes(int AcceptFd)
  6230. {
  6231. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6232. //if it is not the same, the packet should be ignored.
  6233. int i = 0;
  6234. int errn = 0;
  6235. bitstream_t v2g_tx_stream;
  6236. static struct ChargingInfoData *sys;
  6237. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6238. size_t pos = 0;
  6239. v2g_tx_stream.pos = &pos;
  6240. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6241. v2g_tx_stream.data = V2GTP_Tx_buf;
  6242. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  6243. init_dinContractAuthenticationResType(&ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes);
  6244. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes_isUsed = 1u;
  6245. //[BODY (1/2)] ResponseCode
  6246. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_OK;
  6247. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Ongoing; //0
  6248. //[HEADER] Check Req SessionID
  6249. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  6250. {
  6251. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  6252. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  6253. errn = -1;
  6254. }
  6255. //Check for SequenceError
  6256. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6257. {
  6258. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  6259. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  6260. errn = -1;
  6261. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6262. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6263. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6264. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6265. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6266. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6267. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6268. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6269. }
  6270. //Detect for CP State should be 9V (State B)
  6271. #if CP_PROTECTION_MECHANISM == ENABLE
  6272. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6273. {
  6274. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6275. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6276. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6277. Update_V2G_Flow_Status(Other_Fault);
  6278. errn = -1;
  6279. sprintf(buf_log_evcomm,
  6280. "[Proc_din_ContractAuthenticationRes]Emergency Stop by CP Error (%d)",
  6281. sys->CpState);
  6282. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6283. }
  6284. #endif
  6285. //Check for CSU command of "Stop by EVSE"
  6286. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6287. {
  6288. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6289. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6290. errn = -1;
  6291. }
  6292. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6293. {
  6294. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6295. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6296. errn = -1;
  6297. }
  6298. //[BODY (2/2)] EVSEProcessing
  6299. if(ShmInternalComm->ChargingPermission == TRUE)
  6300. {
  6301. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished; //0
  6302. SAVE_SYS_LOG_MSG_EVCOMM("CSU Permission: OK");
  6303. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  6304. {
  6305. //Set PWM as 5% (for SLAC first case)
  6306. SAVE_SYS_LOG_MSG_EVCOMM("Set PWM as 5%%");
  6307. SwitchCpStateE(DISABLE);
  6308. OutputCpPwmDuty(5);
  6309. }
  6310. #endif
  6311. }
  6312. //Check for Permission Changing from TRUE to FALSE
  6313. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  6314. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  6315. ShmInternalComm->ChargingPermission == FALSE)
  6316. {
  6317. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][ContractAuthenticationRes]Permission OFF");
  6318. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6319. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6320. errn = -1;
  6321. }
  6322. #if PARAMETER_NORMAL_MODE == ENABLE
  6323. ////////////SHM_Read_din_ContractAuthenticationRes(&ccs_exi_doc_DIN, ShmCcsData);
  6324. #endif
  6325. // ============ Encode and Send Response Message ===========
  6326. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  6327. {
  6328. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  6329. errn = -1;
  6330. }
  6331. return errn;
  6332. }
  6333. /*===========================================================================
  6334. FUNCTION: Proc_iso1_AuthorizationRes
  6335. DESCRIPTION:
  6336. PRE-CONDITION:
  6337. INPUT:
  6338. OUTPUT:
  6339. GLOBAL VARIABLES:
  6340. =============================================================================*/
  6341. int Proc_iso1_AuthorizationRes(int AcceptFd)
  6342. {
  6343. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6344. //if it is not the same, the packet should be ignored.
  6345. int i = 0;
  6346. int errn = 0;
  6347. bitstream_t v2g_tx_stream;
  6348. static struct ChargingInfoData *sys;
  6349. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6350. size_t pos = 0;
  6351. v2g_tx_stream.pos = &pos;
  6352. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6353. v2g_tx_stream.data = V2GTP_Tx_buf;
  6354. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6355. init_iso1AuthorizationResType(&ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes);
  6356. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes_isUsed = 1u;
  6357. //[BODY (1/2)] ResponseCode
  6358. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_OK;
  6359. /*+++ 20200808, vern, EVSEProcessing should be waiting for Customer during authrization +++*/
  6360. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Ongoing_WaitingForCustomerInteraction; //0
  6361. /*--- 20200808, vern, should be waiting for Customer during authrization ---*/
  6362. //[HEADER] Check Req SessionID
  6363. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  6364. {
  6365. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  6366. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  6367. errn = -1;
  6368. }
  6369. //Check for SequenceError
  6370. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6371. {
  6372. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  6373. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  6374. errn = -1;
  6375. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6376. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6377. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6378. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6379. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6380. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6381. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6382. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6383. }
  6384. //Detect for CP State should be 9V (State B)
  6385. #if CP_PROTECTION_MECHANISM == ENABLE
  6386. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6387. {
  6388. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED;
  6389. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6390. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6391. Update_V2G_Flow_Status(Other_Fault);
  6392. errn = -1;
  6393. sprintf(buf_log_evcomm,
  6394. "[Proc_iso1_AuthorizationRes]Emergency Stop by CP Error (%d)",
  6395. sys->CpState);
  6396. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6397. }
  6398. #endif
  6399. //Check for CSU command of "Stop by EVSE"
  6400. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6401. {
  6402. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6403. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6404. errn = -1;
  6405. }
  6406. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6407. {
  6408. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6409. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6410. errn = -1;
  6411. }
  6412. //[BODY (2/2)] EVSEProcessing
  6413. //Check for Permission from CSU
  6414. if(ShmInternalComm->ChargingPermission == TRUE)
  6415. {
  6416. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  6417. SAVE_SYS_LOG_MSG_EVCOMM("CSU Permission: OK");
  6418. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  6419. {
  6420. //Set PWM as 5% (for SLAC first case)
  6421. SAVE_SYS_LOG_MSG_EVCOMM("Set PWM as 5%%");
  6422. SwitchCpStateE(DISABLE);
  6423. OutputCpPwmDuty(5);
  6424. }
  6425. #endif
  6426. }
  6427. //Check for Permission Changing from TRUE to FALSE
  6428. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  6429. if (ShmInternalComm->ChargingPermission_pre >=1 &&
  6430. ShmInternalComm->ChargingPermission == FALSE)
  6431. {
  6432. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO1][AuthorizationRes]Permission OFF");
  6433. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6434. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6435. errn = -1;
  6436. }
  6437. #if PARAMETER_NORMAL_MODE == ENABLE
  6438. ////////////SHM_Read_iso1_AuthorizationRes(&ccs_exi_doc_ISO1, ShmCcsData);
  6439. #endif
  6440. // ============ Encode and Send Response Message ===========
  6441. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  6442. {
  6443. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  6444. errn = -1;
  6445. }
  6446. return errn;
  6447. }
  6448. /*===========================================================================
  6449. FUNCTION: Proc_din_ContractAuthenticationReq
  6450. DESCRIPTION:
  6451. PRE-CONDITION:
  6452. INPUT:
  6453. OUTPUT:
  6454. GLOBAL VARIABLES:
  6455. =============================================================================*/
  6456. int Proc_din_ContractAuthenticationReq(int AcceptFd)
  6457. {
  6458. int errn = 0;
  6459. DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_din_ContractAuthenticationReq]Got Proc_din_ContractAuthenticationReq\n");
  6460. //Print the decoded XML Document
  6461. PRINT_XML_DOC_DIN_ContractAuthenticationReq(&ccs_exi_doc_DIN);
  6462. //Save into Share Memory
  6463. SHM_Save_din_ContractAuthenticationReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  6464. errn = Proc_din_ContractAuthenticationRes(AcceptFd);
  6465. if (errn == 0)
  6466. {
  6467. //send response successfully.
  6468. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]ContractAuthenticationRes");
  6469. }
  6470. else
  6471. {
  6472. sprintf(buf_log_evcomm,
  6473. "[Error][SeccComm][Proc_din_ContractAuthenticationReq]Proc_iso1_AuthenticationRes(): %d (DEC)",
  6474. errn);
  6475. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6476. }
  6477. return errn;
  6478. }
  6479. /*===========================================================================
  6480. FUNCTION: Proc_iso1_AuthenticationReq
  6481. DESCRIPTION:
  6482. PRE-CONDITION:
  6483. INPUT:
  6484. OUTPUT:
  6485. GLOBAL VARIABLES:
  6486. =============================================================================*/
  6487. int Proc_iso1_AuthenticationReq(int AcceptFd)
  6488. {
  6489. int errn = 0;
  6490. DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_iso1_AuthenticationReq]Got AuthorizationReq\n");
  6491. //Print the decoded XML Document
  6492. PRINT_XML_DOC_ISO1_AuthorizationReq(&ccs_exi_doc_ISO1);
  6493. //Save into Share Memory
  6494. SHM_Save_iso1_AuthorizationReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  6495. errn = Proc_iso1_AuthorizationRes(AcceptFd);
  6496. if (errn == 0)
  6497. {
  6498. //send response successfully.
  6499. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]AuthorizationRes");
  6500. }
  6501. else
  6502. {
  6503. sprintf(buf_log_evcomm,
  6504. "[Error][SeccComm][Proc_iso1_AuthenticationReq]Proc_iso1_AuthenticationRes(): %d (DEC)",
  6505. errn);
  6506. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6507. }
  6508. return errn;
  6509. }
  6510. /*===========================================================================
  6511. FUNCTION: SHM_Init_dinDC_EVSEStatusType
  6512. DESCRIPTION:
  6513. PRE-CONDITION:
  6514. INPUT:
  6515. 1. in
  6516. OUTPUT:
  6517. 2. out
  6518. GLOBAL VARIABLES:
  6519. =============================================================================*/
  6520. void SHM_Init_dinDC_EVSEStatusType(struct DC_EVSEStatusType_DIN70121 *in)
  6521. {
  6522. in->EVSEIsolationStatus = dinisolationLevelType_Valid;
  6523. // dinisolationLevelType_Invalid = 0,
  6524. // dinisolationLevelType_Valid = 1, (default)
  6525. // dinisolationLevelType_Warning = 2,
  6526. // dinisolationLevelType_Fault = 3
  6527. in->EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  6528. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6529. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1, (default)
  6530. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6531. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6532. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6533. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6534. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6535. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  6536. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  6537. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  6538. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  6539. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  6540. in->EVSENotification = dinEVSENotificationType_None;
  6541. // dinEVSENotificationType_None = 0, (default)
  6542. // dinEVSENotificationType_StopCharging = 1,
  6543. // dinEVSENotificationType_ReNegotiation = 2
  6544. }
  6545. /*===========================================================================
  6546. FUNCTION: SHM_Save_dinPhysicalValueType
  6547. DESCRIPTION:
  6548. PRE-CONDITION:
  6549. INPUT:
  6550. OUTPUT:
  6551. GLOBAL VARIABLES:
  6552. =============================================================================*/
  6553. void SHM_Save_dinPhysicalValueType(struct PhysicalValueType_DIN70121 *obj, short value, int multiplier, unsigned char unit)
  6554. {
  6555. obj->Value = value;
  6556. obj->Multiplier = multiplier;
  6557. obj->Unit =unit;
  6558. }
  6559. /*===========================================================================
  6560. FUNCTION: SHM_Init_din_ChargeParameterDiscoveryRes
  6561. DESCRIPTION:
  6562. PRE-CONDITION:
  6563. INPUT:
  6564. 1. shm_ccs
  6565. OUTPUT:
  6566. 2. shm_ccs
  6567. GLOBAL VARIABLES:
  6568. =============================================================================*/
  6569. void SHM_Init_din_ChargeParameterDiscoveryRes(struct CcsData *shm_ccs)
  6570. {
  6571. struct ChargeParameterDiscoveryResponse_DIN70121 *in;
  6572. in = &shm_ccs->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse;
  6573. //----- [BODY (1/5)] ResponseCode -----
  6574. in->ResponseCode = dinresponseCodeType_OK;
  6575. //----- [BODY (2/5)] EVSEProcessing -----
  6576. in->EVSEProcessing = dinEVSEProcessingType_Ongoing; //0
  6577. // dinEVSEProcessingType_Finished = 0,
  6578. // dinEVSEProcessingType_Ongoing = 1
  6579. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6580. //be fixed in another function.
  6581. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6582. //ignore, since DIN doesn't support AC
  6583. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6584. struct DC_EVSEChargeParameterType_DIN70121 *in_para;
  6585. in_para = &in->DC_EVSEChargeParameter;
  6586. //DC_EVSEStatus
  6587. SHM_Init_dinDC_EVSEStatusType(&in_para->DC_EVSEStatus);
  6588. in_para->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  6589. short value = 0; int multiplier = 0; unsigned char unit = 0;
  6590. //EVSEMaximumCurrentLimit
  6591. value = 600; multiplier = -1; unit = A_DIN70121; //60A
  6592. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumCurrentLimit, value, multiplier, unit);
  6593. //EVSEMaximumPowerLimit
  6594. value = 3000; multiplier = 1; unit = W_DIN70121; //30KW
  6595. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumPowerLimit, value, multiplier, unit);
  6596. //EVSEMaximumVoltageLimit
  6597. value = 7500; multiplier = -1; unit = V_DIN70121; //750V
  6598. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumVoltageLimit, value, multiplier, unit);
  6599. //EVSEMinimumVoltageLimit
  6600. value = 1500; multiplier = -1; unit = V_DIN70121; //150V
  6601. SHM_Save_dinPhysicalValueType(&in_para->EVSEMinimumVoltageLimit, value, multiplier, unit);
  6602. //EVSEMinimumCurrentLimit
  6603. value = 10; multiplier = -1; unit = A_DIN70121; //1A
  6604. SHM_Save_dinPhysicalValueType(&in_para->EVSEMinimumCurrentLimit, value, multiplier, unit);
  6605. //EVSECurrentRegulationTolerance
  6606. value = 10; multiplier = -1; unit = A_DIN70121; //1A
  6607. SHM_Save_dinPhysicalValueType(&in_para->EVSECurrentRegulationTolerance, value, multiplier, unit);
  6608. //EVSEPeakCurrentRipple
  6609. value = 2; multiplier = -1; unit = A_DIN70121; //0.2A
  6610. SHM_Save_dinPhysicalValueType(&in_para->EVSEPeakCurrentRipple, value, multiplier, unit);
  6611. //EVSEEnergyToBeDelivered (optional)
  6612. //SHM_Save_dinPhysicalValueType(&out_para->EVSEEnergyToBeDelivered, &in_para->EVSEEnergyToBeDelivered);
  6613. }
  6614. /*===========================================================================
  6615. FUNCTION: Sudo_Parameter_din_ChargeParameterDiscoveryRes
  6616. DESCRIPTION:
  6617. PRE-CONDITION:
  6618. INPUT:
  6619. OUTPUT:
  6620. GLOBAL VARIABLES:
  6621. =============================================================================*/
  6622. void Sudo_Parameter_din_ChargeParameterDiscoveryRes()
  6623. {
  6624. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  6625. init_dinChargeParameterDiscoveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes);
  6626. ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed = 1u;
  6627. //----- [BODY (1/5)] ResponseCode -----
  6628. struct dinChargeParameterDiscoveryResType *res;
  6629. res = &ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes;
  6630. res->ResponseCode = dinresponseCodeType_OK;
  6631. //----- [BODY (2/5)] EVSEProcessing -----
  6632. res->EVSEProcessing = dinEVSEProcessingType_Finished; //0
  6633. // dinEVSEProcessingType_Finished = 0,
  6634. // dinEVSEProcessingType_Ongoing = 1
  6635. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6636. res->SAScheduleList_isUsed = 1u;
  6637. struct dinSAScheduleListType *list;
  6638. list = &res->SAScheduleList;
  6639. //
  6640. list->SAScheduleTuple.arrayLen = 1;
  6641. list->SAScheduleTuple.array[0].SAScheduleTupleID = 0;
  6642. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleID = 0;
  6643. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.arrayLen = 1;
  6644. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval_isUsed = 1u;
  6645. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.start = 0;
  6646. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration = xxx
  6647. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration_isUsed = 1u;
  6648. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval_isUsed = 0u;
  6649. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval.xxx
  6650. //list->SAScheduleTuple.array[0].SalesTariff.xxx
  6651. //list->SAScheduleTuple.array[0].SalesTariff_isUsed = 0u;
  6652. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6653. //ignore, since DIN doesn't support AC
  6654. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6655. res->DC_EVSEChargeParameter_isUsed = 1u;
  6656. struct dinDC_EVSEChargeParameterType *para;
  6657. para = &res->DC_EVSEChargeParameter;
  6658. //DC_EVSEStatus
  6659. para->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  6660. para->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  6661. // dinisolationLevelType_Invalid = 0,
  6662. // dinisolationLevelType_Valid = 1,
  6663. // dinisolationLevelType_Warning = 2,
  6664. // dinisolationLevelType_Fault = 3
  6665. para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  6666. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6667. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  6668. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6669. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6670. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6671. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6672. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6673. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  6674. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  6675. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  6676. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  6677. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  6678. para->DC_EVSEStatus.NotificationMaxDelay = 0u;
  6679. para->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  6680. // dinEVSENotificationType_None = 0,
  6681. // dinEVSENotificationType_StopCharging = 1,
  6682. // dinEVSENotificationType_ReNegotiation = 2
  6683. //EVSEMaximumCurrentLimit
  6684. para->EVSEMaximumCurrentLimit.Value = 2400;
  6685. para->EVSEMaximumCurrentLimit.Multiplier = -1;
  6686. para->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  6687. para->EVSEMaximumCurrentLimit.Unit = dinunitSymbolType_A;
  6688. // dinunitSymbolType_h = 0,
  6689. // dinunitSymbolType_m = 1,
  6690. // dinunitSymbolType_s = 2,
  6691. // dinunitSymbolType_A = 3,
  6692. // dinunitSymbolType_Ah = 4,
  6693. // dinunitSymbolType_V = 5,
  6694. // dinunitSymbolType_VA = 6,
  6695. // dinunitSymbolType_W = 7,
  6696. // dinunitSymbolType_W_s = 8,
  6697. // dinunitSymbolType_Wh = 9
  6698. //EVSEMaximumPowerLimit
  6699. para->EVSEMaximumPowerLimit.Value = 6000;
  6700. para->EVSEMaximumPowerLimit.Multiplier = 1;
  6701. para->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  6702. para->EVSEMaximumPowerLimit.Unit = dinunitSymbolType_W;
  6703. //EVSEMaximumVoltageLimit
  6704. para->EVSEMaximumVoltageLimit.Value = 7500;
  6705. para->EVSEMaximumVoltageLimit.Multiplier = -1;
  6706. para->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  6707. para->EVSEMaximumVoltageLimit.Unit = dinunitSymbolType_V;
  6708. //EVSEMinimumVoltageLimit
  6709. para->EVSEMinimumVoltageLimit.Value = 1500;
  6710. para->EVSEMinimumVoltageLimit.Multiplier = -1;
  6711. para->EVSEMinimumVoltageLimit.Unit_isUsed = 1u;
  6712. para->EVSEMinimumVoltageLimit.Unit = dinunitSymbolType_V;
  6713. //EVSEMinimumCurrentLimit
  6714. para->EVSEMinimumCurrentLimit.Value = 20;
  6715. para->EVSEMinimumCurrentLimit.Multiplier = -1;
  6716. para->EVSEMinimumCurrentLimit.Unit_isUsed = 1u;
  6717. para->EVSEMinimumCurrentLimit.Unit = dinunitSymbolType_A;
  6718. //EVSECurrentRegulationTolerance_isUsed
  6719. para->EVSECurrentRegulationTolerance_isUsed = 1u;
  6720. //EVSECurrentRegulationTolerance
  6721. para->EVSECurrentRegulationTolerance.Value = 10;
  6722. para->EVSECurrentRegulationTolerance.Multiplier = -1;
  6723. para->EVSECurrentRegulationTolerance.Unit_isUsed = 1u;
  6724. para->EVSECurrentRegulationTolerance.Unit = dinunitSymbolType_A;
  6725. //EVSEEnergyToBeDelivered_isUsed
  6726. para->EVSEEnergyToBeDelivered_isUsed = 1u;
  6727. //EVSEPeakCurrentRipple
  6728. para->EVSEPeakCurrentRipple.Value = 2;
  6729. para->EVSEPeakCurrentRipple.Multiplier = -1;
  6730. para->EVSEPeakCurrentRipple.Unit_isUsed = 1u;
  6731. para->EVSEPeakCurrentRipple.Unit = dinunitSymbolType_A;
  6732. //EVSEEnergyToBeDelivered (optional)
  6733. /*
  6734. para->EVSEEnergyToBeDelivered.Value = 360;
  6735. para->EVSEEnergyToBeDelivered.Multiplier = 3;
  6736. para->EVSEEnergyToBeDelivered.Unit_isUsed = 1u;
  6737. para->EVSEEnergyToBeDelivered.Unit = dinunitSymbolType_Wh;
  6738. */
  6739. }
  6740. /*===========================================================================
  6741. FUNCTION: Sudo_Parameter_iso1_ChargeParameterDiscoveryRes
  6742. DESCRIPTION:
  6743. PRE-CONDITION:
  6744. INPUT:
  6745. OUTPUT:
  6746. GLOBAL VARIABLES:
  6747. =============================================================================*/
  6748. void Sudo_Parameter_iso1_ChargeParameterDiscoveryRes()
  6749. {
  6750. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6751. init_iso1ChargeParameterDiscoveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes);
  6752. ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed = 1u;
  6753. //----- [BODY (1/5)] ResponseCode -----
  6754. struct iso1ChargeParameterDiscoveryResType *res;
  6755. res = &ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes;
  6756. res->ResponseCode = iso1responseCodeType_OK;
  6757. //----- [BODY (2/5)] EVSEProcessing -----
  6758. res->EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  6759. // iso1EVSEProcessingType_Finished = 0,
  6760. // iso1EVSEProcessingType_Ongoing = 1
  6761. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6762. res->SAScheduleList_isUsed = 1u;
  6763. struct iso1SAScheduleListType *list;
  6764. list = &res->SAScheduleList;
  6765. //
  6766. list->SAScheduleTuple.arrayLen = 1;
  6767. list->SAScheduleTuple.array[0].SAScheduleTupleID = 0;
  6768. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.arrayLen = 1;
  6769. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval_isUsed = 1u;
  6770. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.start = 0;
  6771. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration = xxx
  6772. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration_isUsed = 1u;
  6773. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval_isUsed = 0u;
  6774. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval.xxx
  6775. //list->SAScheduleTuple.array[0].SalesTariff.xxx
  6776. //list->SAScheduleTuple.array[0].SalesTariff_isUsed = 0u;
  6777. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6778. //ignore, since our ISO1 doesn't support AC, yet
  6779. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6780. res->DC_EVSEChargeParameter_isUsed = 1u;
  6781. struct iso1DC_EVSEChargeParameterType *para;
  6782. para = &res->DC_EVSEChargeParameter;
  6783. //DC_EVSEStatus
  6784. para->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  6785. para->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  6786. // iso1isolationLevelType_Invalid = 0,
  6787. // iso1isolationLevelType_Valid = 1,
  6788. // iso1isolationLevelType_Warning = 2,
  6789. // iso1isolationLevelType_Fault = 3
  6790. para->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  6791. // iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6792. // iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  6793. // iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6794. // iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6795. // iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6796. // iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6797. // iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6798. // iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  6799. // iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  6800. // iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  6801. // iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  6802. // iso1DC_EVSEStatusCodeType_Reserved_C = 11
  6803. para->DC_EVSEStatus.NotificationMaxDelay = 0u;
  6804. para->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  6805. // iso1EVSENotificationType_None = 0,
  6806. // iso1EVSENotificationType_StopCharging = 1,
  6807. // iso1EVSENotificationType_ReNegotiation = 2
  6808. //EVSEMaximumCurrentLimit
  6809. para->EVSEMaximumCurrentLimit.Value = 2400;
  6810. para->EVSEMaximumCurrentLimit.Multiplier = -1;
  6811. //para->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  6812. para->EVSEMaximumCurrentLimit.Unit = iso1unitSymbolType_A;
  6813. //iso1unitSymbolType_h = 0,
  6814. //iso1unitSymbolType_m = 1,
  6815. //iso1unitSymbolType_s = 2,
  6816. //iso1unitSymbolType_A = 3,
  6817. //iso1unitSymbolType_V = 4,
  6818. //iso1unitSymbolType_W = 5,
  6819. //iso1unitSymbolType_Wh = 6
  6820. //EVSEMaximumPowerLimit
  6821. para->EVSEMaximumPowerLimit.Value = 6000;
  6822. para->EVSEMaximumPowerLimit.Multiplier = 1;
  6823. //para->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  6824. para->EVSEMaximumPowerLimit.Unit = iso1unitSymbolType_W;
  6825. //EVSEMaximumVoltageLimit
  6826. para->EVSEMaximumVoltageLimit.Value = 7500;
  6827. para->EVSEMaximumVoltageLimit.Multiplier = -1;
  6828. //para->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  6829. para->EVSEMaximumVoltageLimit.Unit = iso1unitSymbolType_V;
  6830. //EVSEMinimumVoltageLimit
  6831. para->EVSEMinimumVoltageLimit.Value = 1500;
  6832. para->EVSEMinimumVoltageLimit.Multiplier = -1;
  6833. //para->EVSEMinimumVoltageLimit.Unit_isUsed = 1u;
  6834. para->EVSEMinimumVoltageLimit.Unit = iso1unitSymbolType_V;
  6835. //EVSEMinimumCurrentLimit
  6836. para->EVSEMinimumCurrentLimit.Value = 20;
  6837. para->EVSEMinimumCurrentLimit.Multiplier = -1;
  6838. //para->EVSEMinimumCurrentLimit.Unit_isUsed = 1u;
  6839. para->EVSEMinimumCurrentLimit.Unit = iso1unitSymbolType_A;
  6840. //EVSECurrentRegulationTolerance_isUsed
  6841. para->EVSECurrentRegulationTolerance_isUsed = 1u;
  6842. //EVSECurrentRegulationTolerance
  6843. para->EVSECurrentRegulationTolerance.Value = 10;
  6844. para->EVSECurrentRegulationTolerance.Multiplier = -1;
  6845. //para->EVSECurrentRegulationTolerance.Unit_isUsed = 1u;
  6846. para->EVSECurrentRegulationTolerance.Unit = iso1unitSymbolType_A;
  6847. //EVSEEnergyToBeDelivered_isUsed
  6848. para->EVSEEnergyToBeDelivered_isUsed = 1u;
  6849. //EVSEPeakCurrentRipple
  6850. para->EVSEPeakCurrentRipple.Value = 2;
  6851. para->EVSEPeakCurrentRipple.Multiplier = -1;
  6852. //para->EVSEPeakCurrentRipple.Unit_isUsed = 1u;
  6853. para->EVSEPeakCurrentRipple.Unit = iso1unitSymbolType_A;
  6854. //EVSEEnergyToBeDelivered (optional)
  6855. /*
  6856. para->EVSEEnergyToBeDelivered.Value = 360;
  6857. para->EVSEEnergyToBeDelivered.Multiplier = 3;
  6858. para->EVSEEnergyToBeDelivered.Unit_isUsed = 1u;
  6859. para->EVSEEnergyToBeDelivered.Unit = iso1unitSymbolType_Wh;
  6860. */
  6861. }
  6862. /*===========================================================================
  6863. FUNCTION: Proc_din_ChargeParameterDiscoveryRes
  6864. DESCRIPTION:
  6865. PRE-CONDITION:
  6866. INPUT:
  6867. OUTPUT:
  6868. GLOBAL VARIABLES:
  6869. =============================================================================*/
  6870. int Proc_din_ChargeParameterDiscoveryRes(int AcceptFd)
  6871. {
  6872. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6873. //if it is not the same, the packet should be ignored.
  6874. //STEP 1: ============ Initialize ============
  6875. int errn = 0;
  6876. bitstream_t v2g_tx_stream;
  6877. struct ChargeParameterDiscoveryResponse_DIN70121 *res;
  6878. struct ChargeParameterDiscoveryRequest_DIN70121 *req;
  6879. struct DC_EVSEChargeParameterType_DIN70121 *dc_para;
  6880. struct ChargingInfoData *sys;
  6881. size_t pos = 0;
  6882. v2g_tx_stream.pos = &pos;
  6883. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6884. v2g_tx_stream.data = V2GTP_Tx_buf;
  6885. res = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse;
  6886. req = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest;
  6887. dc_para = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse.DC_EVSEChargeParameter;
  6888. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6889. res->ResponseCode = OK_DIN70121;
  6890. res->EVSEProcessing = Ongoing_DIN70121;
  6891. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready; //1
  6892. //[HEADER] Check Req SessionID
  6893. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  6894. {
  6895. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  6896. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  6897. errn = -1;
  6898. }
  6899. //Check for SequenceError
  6900. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6901. {
  6902. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  6903. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  6904. errn = -1;
  6905. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6906. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6907. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6908. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6909. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6910. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6911. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6912. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6913. }
  6914. //[TC_SECC_VTB_ChargeParameterDiscovery_005]
  6915. if ( (sys->EvBatteryMaxCurrent < 0) ||
  6916. (sys->EvBatteryMaxVoltage<150)
  6917. )
  6918. {
  6919. sprintf(buf_log_evcomm,
  6920. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  6921. sys->EvBatteryMaxCurrent);
  6922. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6923. res->ResponseCode = dinresponseCodeType_FAILED_WrongChargeParameter; //16
  6924. res->EVSEProcessing = Finished_DIN70121;
  6925. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6926. errn = -1;
  6927. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6928. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  6929. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6930. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6931. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6932. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6933. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  6934. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  6935. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6936. }
  6937. //STEP 2: ============ Modify Parameters of ShmCcsData ============
  6938. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_DIN70121);
  6939. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_DIN70121);
  6940. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_DIN70121);
  6941. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMinimumVoltageLimit, 1500, V_DIN70121); //150V
  6942. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMinimumCurrentLimit, 10, A_DIN70121); //1A
  6943. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSECurrentRegulationTolerance, 10, A_DIN70121); //1A
  6944. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEPeakCurrentRipple, 2, A_DIN70121); //0.2A
  6945. //SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEEnergyToBeDelivered, 0, WH_DIN70121); //optional
  6946. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  6947. if (sys->EvBatteryMaxVoltage <= 500)
  6948. {
  6949. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumVoltageLimit, (int) (500 * 10), V_DIN70121); //500V
  6950. }
  6951. #endif
  6952. //for test with Tesla Model 3, 10A
  6953. //SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumCurrentLimit, (int) (10 * 10), A_DIN70121); //10A, for testing with Tesla Model 3
  6954. //Check for EnergyTransferMode [TC_SECC_VTB_ChargeParameterDiscovery_004]
  6955. if (req->EVRequestedEnergyTransferType != dinEVSESupportedEnergyTransferType_DC_extended)
  6956. {
  6957. sprintf(buf_log_evcomm,
  6958. "[ERROR]Wrong EVRequestedEnergyTransferType(%d,%d)",
  6959. req->EVRequestedEnergyTransferType,
  6960. dinEVSESupportedEnergyTransferType_DC_extended);
  6961. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  6962. res->ResponseCode = FAILED_WrongEnergyTransferType_DIN70121;
  6963. res->EVSEProcessing = Finished_DIN70121;
  6964. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6965. errn = -1;
  6966. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6967. Update_V2G_Flow_Status(Other_Fault);
  6968. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6969. //CCS_SECC_ResponseCode_FAILED_WrongEnergyTransferMode (023774)
  6970. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6971. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6972. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6973. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6974. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  6975. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  6976. }
  6977. //Check for CSU command of "Stop by EVSE"
  6978. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6979. {
  6980. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes]EVSE_Shutdown");
  6981. res->ResponseCode = FAILED_DIN70121;
  6982. res->EVSEProcessing = Finished_DIN70121;
  6983. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6984. errn = -1;
  6985. }
  6986. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6987. {
  6988. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes]EVSE_EmergencyShutdown");
  6989. res->ResponseCode = FAILED_DIN70121;
  6990. res->EVSEProcessing = Finished_DIN70121;
  6991. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  6992. errn = -1;
  6993. }
  6994. //Detect for CP State should be 9V (State B)
  6995. #if CP_PROTECTION_MECHANISM == ENABLE
  6996. if (sys->CpState != 3) //State B1, B2
  6997. {
  6998. res->ResponseCode = FAILED_DIN70121;
  6999. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7000. res->EVSEProcessing = Finished_DIN70121;
  7001. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7002. Update_V2G_Flow_Status(Other_Fault);
  7003. errn = -1;
  7004. sprintf(buf_log_evcomm,
  7005. "[Proc_din_ChargeParameterDiscoveryRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  7006. sys->CpState,
  7007. sys->CpVoltage);
  7008. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7009. }
  7010. #endif
  7011. //Check for Permission from CSU
  7012. if (ShmInternalComm->ChargingPermission == TRUE)
  7013. {
  7014. res->EVSEProcessing = Finished_DIN70121;
  7015. }
  7016. //Check for Permission Off
  7017. if (ShmInternalComm->ChargingPermission == FALSE)
  7018. {
  7019. SAVE_SYS_LOG_MSG_EVCOMM("[Error][DIN][ChargeParameterDiscoveryRes]Permission OFF");
  7020. res->ResponseCode = FAILED_DIN70121;
  7021. res->EVSEProcessing = Finished_DIN70121;
  7022. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7023. errn = -1;
  7024. }
  7025. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7026. #if PARAMETER_NORMAL_MODE == ENABLE
  7027. SHM_Read_din_ChargeParameterDiscoveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  7028. #else
  7029. Sudo_Parameter_din_ChargeParameterDiscoveryRes();
  7030. #endif
  7031. //STEP 4: ============ Encode and Send Response Message ===========
  7032. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  7033. {
  7034. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  7035. errn = -1;
  7036. }
  7037. //STPE 5: ============ Update Flags ============
  7038. return errn;
  7039. }
  7040. /*===========================================================================
  7041. FUNCTION: Proc_iso1_ChargeParameterDiscoveryRes
  7042. DESCRIPTION:
  7043. PRE-CONDITION:
  7044. INPUT:
  7045. OUTPUT:
  7046. GLOBAL VARIABLES:
  7047. =============================================================================*/
  7048. int Proc_iso1_ChargeParameterDiscoveryRes(int AcceptFd)
  7049. {
  7050. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7051. //if it is not the same, the packet should be ignored.
  7052. //STEP 1: ============ Initialize ============
  7053. int errn = 0;
  7054. bitstream_t v2g_tx_stream;
  7055. struct ChargeParameterDiscoveryResponse_ISO15118_2014 *res;
  7056. struct ChargeParameterDiscoveryRequest_ISO15118_2014 *req;
  7057. struct DC_EVSEChargeParameterType_ISO15118_2014 *dc_para;
  7058. struct AC_EVSEChargeParameterType_ISO15118_2014 *ac_para;
  7059. struct ChargingInfoData *sys;
  7060. size_t pos = 0;
  7061. v2g_tx_stream.pos = &pos;
  7062. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7063. v2g_tx_stream.data = V2GTP_Tx_buf;
  7064. res = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse;
  7065. req = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest;
  7066. dc_para = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse.DC_EVSEChargeParameter;
  7067. ac_para = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse.AC_EVSEChargeParameter;
  7068. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7069. res->ResponseCode = OK_ISO15118_2014;
  7070. /*+++ 20200808, vern, EVSEProcessing should be on-going during ChargeParameterDiscovery +++*/
  7071. res->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  7072. /*--- 20200808, vern, EVSEProcessing should be on-going during ChargeParameterDiscovery ---*/
  7073. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; //1
  7074. ac_para->AC_EVSEStatus.RCD = ShmInternalComm->AC_RcdStatus; //0:no error, 1:error
  7075. ac_para->AC_EVSEStatus.NotificationMaxDelay = 0; //unit: 1s
  7076. ac_para->AC_EVSEStatus.EVSENotification = ShmInternalComm->AC_EVSENotification; //0:none, 1:StopCharging, 2:RenNgotiation
  7077. //[HEADER] Check Req SessionID
  7078. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  7079. {
  7080. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  7081. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  7082. errn = -1;
  7083. }
  7084. //Check for SequenceError
  7085. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7086. {
  7087. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  7088. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  7089. errn = -1;
  7090. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7091. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7092. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7093. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7094. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7095. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7096. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7097. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7098. }
  7099. //[TC_SECC_VTB_ChargeParameterDiscovery_005]
  7100. /*+++ 20200808, vern, should check the voltage and current to see if the range of battery parameter is accepted by charger ---*/
  7101. if ((sys->EvBatteryMaxCurrent < 0) ||(sys->EvBatteryMaxVoltage<150))
  7102. {
  7103. sprintf(buf_log_evcomm,
  7104. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  7105. sys->EvBatteryMaxCurrent);
  7106. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7107. res->ResponseCode = iso1responseCodeType_FAILED_WrongChargeParameter; //16
  7108. res->EVSEProcessing = Finished_ISO15118_2014;
  7109. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7110. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7111. errn = -1;
  7112. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7113. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  7114. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7115. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7116. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7117. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7118. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  7119. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  7120. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7121. }
  7122. //STEP 2: ============ Modify Parameters of ShmCcsData ============
  7123. //DC
  7124. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_ISO15118_2014);
  7125. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  7126. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_ISO15118_2014);
  7127. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMinimumVoltageLimit, 1500, V_ISO15118_2014); //150V
  7128. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMinimumCurrentLimit, 10, A_ISO15118_2014); //1A
  7129. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSECurrentRegulationTolerance, 10, A_ISO15118_2014); //1A
  7130. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEPeakCurrentRipple, 2, A_ISO15118_2014); //0.2A
  7131. //SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEEnergyToBeDelivered, 0, Wh_ISO15118_2014); //optional
  7132. //AC
  7133. SAVE_PhysicalValueType_ISO15118_2014(&ac_para->EVSENominalVoltage, (int) (sys->AC_EVSENominalVoltage * 10), V_ISO15118_2014);
  7134. SAVE_PhysicalValueType_ISO15118_2014(&ac_para->EVSEMaxCurrent, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  7135. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  7136. if (sys->EvBatteryMaxVoltage <= 500)
  7137. {
  7138. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumVoltageLimit, (int) (500 * 10), V_ISO15118_2014); //500V
  7139. }
  7140. #endif
  7141. //for test with Tesla Model 3, 10A
  7142. //SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumCurrentLimit, (int) (10 * 10), A_ISO15118_2014); //10A, for testing with Tesla Model 3
  7143. //Check for EnergyTransferMode
  7144. if (req->RequestedEnergyTransferMode != ShmCcsData->EnergyTransferMode) //[CAUTION] Their table should be kept as the same.
  7145. {
  7146. sprintf(buf_log_evcomm,
  7147. "[ERROR]Unmatched RequestedEnergyTransferMode(%d,%d)",
  7148. req->RequestedEnergyTransferMode,
  7149. ShmCcsData->EnergyTransferMode);
  7150. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7151. res->ResponseCode = FAILED_WrongEnergyTransferMode_ISO15118_2014;
  7152. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7153. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7154. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7155. errn = -1;
  7156. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7157. Update_V2G_Flow_Status(Other_Fault);
  7158. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7159. //CCS_SECC_ResponseCode_FAILED_WrongEnergyTransferMode (023774)
  7160. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7161. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7162. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7163. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7164. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  7165. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  7166. }
  7167. //Check for CSU command of "Stop by EVSE"
  7168. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7169. {
  7170. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryRes]EVSE_Shutdown");
  7171. res->ResponseCode = FAILED_ISO15118_2014;
  7172. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7173. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7174. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7175. errn = -1;
  7176. }
  7177. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7178. {
  7179. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryRes]EVSE_EmergencyShutdown");
  7180. res->ResponseCode = FAILED_ISO15118_2014;
  7181. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7182. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7183. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7184. errn = -1;
  7185. }
  7186. //Detect for CP State should be 9V (State B)
  7187. #if CP_PROTECTION_MECHANISM == ENABLE
  7188. if (sys->CpState != 3) //State B1, B2
  7189. {
  7190. res->ResponseCode = FAILED_ISO15118_2014;
  7191. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7192. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7193. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7194. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7195. Update_V2G_Flow_Status(Other_Fault);
  7196. errn = -1;
  7197. sprintf(buf_log_evcomm,
  7198. "[Proc_iso1_ChargeParameterDiscoveryRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  7199. sys->CpState,
  7200. sys->CpVoltage);
  7201. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7202. }
  7203. #endif
  7204. //Check for Permission from CSU
  7205. if(ShmInternalComm->ChargingPermission == TRUE)
  7206. {
  7207. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7208. }
  7209. //Check for Permission Off
  7210. if (ShmInternalComm->ChargingPermission == FALSE)
  7211. {
  7212. SAVE_SYS_LOG_MSG_EVCOMM("[Error][ISO1][ChargeParameterDiscoveryRes]Permission OFF");
  7213. res->ResponseCode = FAILED_ISO15118_2014;
  7214. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7215. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7216. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7217. errn = -1;
  7218. }
  7219. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7220. #if PARAMETER_NORMAL_MODE == ENABLE
  7221. SHM_Read_iso1_ChargeParameterDiscoveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  7222. #else
  7223. Sudo_Parameter_iso1_ChargeParameterDiscoveryRes();
  7224. #endif
  7225. //STEP 4: ============ Encode and Send Response Message ===========
  7226. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  7227. {
  7228. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryRes][Error]Tx encoded msg error");
  7229. errn = -1;
  7230. }
  7231. //STPE 5: ============ Update Flags ============
  7232. return errn;
  7233. }
  7234. /*===========================================================================
  7235. FUNCTION: Proc_din_ChargeParameterDiscoveryReq
  7236. DESCRIPTION:
  7237. PRE-CONDITION:
  7238. INPUT:
  7239. OUTPUT:
  7240. GLOBAL VARIABLES:
  7241. =============================================================================*/
  7242. int Proc_din_ChargeParameterDiscoveryReq(int AcceptFd)
  7243. {
  7244. int errn = 0;
  7245. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryReq] Got ChargeParameterDiscoveryReq");
  7246. //ftime(&SeqStartTime);
  7247. //Print the decoded XML Document
  7248. PRINT_XML_DOC_DIN_ChargeParameterDiscoveryReq(&ccs_exi_doc_DIN);
  7249. //Save into Share Memory
  7250. SHM_Save_din_ChargeParameterDiscoveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  7251. //Check for EV Error Code
  7252. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.DC_EVStatus.EVErrorCode);
  7253. errn = Proc_din_ChargeParameterDiscoveryRes(AcceptFd);
  7254. //ftime(&SeqEndTime);
  7255. //DEBUG_PRINTF_EVCOMM_DETAIL("\ndelta = %.02lf ms\n", DiffTimeb(SeqStartTime, SeqEndTime));
  7256. if ( errn == 0)
  7257. {
  7258. //send response successfully.
  7259. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]ChargeParameterDiscoveryRes");
  7260. }
  7261. else
  7262. {
  7263. sprintf(buf_log_evcomm,
  7264. "[Error][DIN][ChargeParameterDiscoveryRes]%d (DEC)",
  7265. errn);
  7266. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7267. }
  7268. return errn;
  7269. }
  7270. /*===========================================================================
  7271. FUNCTION: Proc_iso1_ChargeParameterDiscoveryReq
  7272. DESCRIPTION:
  7273. PRE-CONDITION:
  7274. INPUT:
  7275. OUTPUT:
  7276. GLOBAL VARIABLES:
  7277. =============================================================================*/
  7278. int Proc_iso1_ChargeParameterDiscoveryReq(int AcceptFd)
  7279. {
  7280. int errn = 0;
  7281. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargeParameterDiscoveryReq] Got ChargeParameterDiscoveryReq");
  7282. //ftime(&SeqStartTime);
  7283. //Print the decoded XML Document
  7284. PRINT_XML_DOC_ISO1_ChargeParameterDiscoveryReq(&ccs_exi_doc_ISO1);
  7285. //Save into Share Memory
  7286. SHM_Save_iso1_ChargeParameterDiscoveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  7287. //Check for EV Error Code
  7288. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.DC_EVStatus.EVErrorCode);
  7289. errn = Proc_iso1_ChargeParameterDiscoveryRes(AcceptFd);
  7290. //ftime(&SeqEndTime);
  7291. //DEBUG_PRINTF_EVCOMM_DETAIL("\ndelta = %.02lf ms\n", DiffTimeb(SeqStartTime, SeqEndTime));
  7292. if (errn == 0)
  7293. {
  7294. //send response successfully.
  7295. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]ChargeParameterDiscoveryRes");
  7296. }
  7297. else
  7298. {
  7299. sprintf(buf_log_evcomm,
  7300. "[Error][ISO1][ChargeParameterDiscoveryRes]%d (DEC)",
  7301. errn);
  7302. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7303. }
  7304. return errn;
  7305. }
  7306. /*===========================================================================
  7307. FUNCTION: SHM_Init_din_CableCheckRes
  7308. DESCRIPTION:
  7309. PRE-CONDITION:
  7310. INPUT:
  7311. 1. shm_ccs
  7312. OUTPUT:
  7313. 1. shm_ccs
  7314. GLOBAL VARIABLES:
  7315. =============================================================================*/
  7316. void SHM_Init_din_CableCheckRes(struct CcsData *shm_ccs)
  7317. {
  7318. struct CableCheckResponse_DIN70121 *in;
  7319. in = &shm_ccs->V2GMessage_DIN70121.CableCheckResponse;
  7320. //----- [BODY (1/3)] ResponseCode -----
  7321. in->ResponseCode = dinresponseCodeType_OK;
  7322. //----- [BODY (2/3)] EVSEProcessing -----
  7323. //in->EVSEProcessing = dinEVSEProcessingType_Finished; //for test
  7324. in->EVSEProcessing = dinEVSEProcessingType_Ongoing; //default
  7325. // dinEVSEProcessingType_Finished = 0,
  7326. // dinEVSEProcessingType_Ongoing = 1
  7327. //----- [BODY (3/3)] DC_EVSEStatus -----
  7328. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  7329. in->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0 (default)
  7330. // dinisolationLevelType_Invalid = 0,
  7331. // dinisolationLevelType_Valid = 1, (default)
  7332. // dinisolationLevelType_Warning = 2,
  7333. // dinisolationLevelType_Fault = 3
  7334. }
  7335. /*===========================================================================
  7336. FUNCTION: Sudo_Parameter_din_CableCheckRes
  7337. DESCRIPTION:
  7338. PRE-CONDITION:
  7339. INPUT:
  7340. OUTPUT:
  7341. GLOBAL VARIABLES:
  7342. =============================================================================*/
  7343. void Sudo_Parameter_din_CableCheckRes()
  7344. {
  7345. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  7346. init_dinCableCheckResType(&ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes);
  7347. ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes_isUsed = 1u;
  7348. //----- [BODY (1/3)] ResponseCode -----
  7349. struct dinCableCheckResType *res;
  7350. res = &ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes;
  7351. res->ResponseCode = dinresponseCodeType_OK;
  7352. //----- [BODY (2/3)] EVSEProcessing -----
  7353. res->EVSEProcessing = dinEVSEProcessingType_Finished; //0
  7354. // dinEVSEProcessingType_Finished = 0,
  7355. // dinEVSEProcessingType_Ongoing = 1
  7356. //----- [BODY (3/3)] DC_EVSEStatus -----
  7357. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7358. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7359. // dinisolationLevelType_Invalid = 0,
  7360. // dinisolationLevelType_Valid = 1,
  7361. // dinisolationLevelType_Warning = 2,
  7362. // dinisolationLevelType_Fault = 3
  7363. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7364. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7365. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  7366. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7367. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7368. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7369. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7370. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7371. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  7372. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  7373. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  7374. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  7375. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  7376. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7377. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  7378. // dinEVSENotificationType_None = 0,
  7379. // dinEVSENotificationType_StopCharging = 1,
  7380. // dinEVSENotificationType_ReNegotiation = 2
  7381. }
  7382. /*===========================================================================
  7383. FUNCTION: Sudo_Parameter_iso1_CableCheckRes
  7384. DESCRIPTION:
  7385. PRE-CONDITION:
  7386. INPUT:
  7387. OUTPUT:
  7388. GLOBAL VARIABLES:
  7389. =============================================================================*/
  7390. void Sudo_Parameter_iso1_CableCheckRes()
  7391. {
  7392. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  7393. init_iso1CableCheckResType(&ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes);
  7394. ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes_isUsed = 1u;
  7395. //----- [BODY (1/3)] ResponseCode -----
  7396. struct iso1CableCheckResType *res;
  7397. res = &ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes;
  7398. res->ResponseCode = iso1responseCodeType_OK;
  7399. //----- [BODY (2/3)] EVSEProcessing -----
  7400. res->EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  7401. //iso1EVSEProcessingType_Finished = 0,
  7402. //iso1EVSEProcessingType_Ongoing = 1,
  7403. //iso1EVSEProcessingType_Ongoing_WaitingForCustomerInteraction = 2
  7404. //----- [BODY (3/3)] DC_EVSEStatus -----
  7405. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7406. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  7407. //iso1isolationLevelType_Invalid = 0,
  7408. //iso1isolationLevelType_Valid = 1,
  7409. //iso1isolationLevelType_Warning = 2,
  7410. //iso1isolationLevelType_Fault = 3,
  7411. //iso1isolationLevelType_No_IMD = 4
  7412. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  7413. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7414. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  7415. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7416. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7417. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7418. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7419. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7420. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  7421. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  7422. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  7423. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  7424. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  7425. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7426. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  7427. //iso1EVSENotificationType_None = 0,
  7428. //iso1EVSENotificationType_StopCharging = 1,
  7429. //iso1EVSENotificationType_ReNegotiation = 2
  7430. }
  7431. /*===========================================================================
  7432. FUNCTION: Proc_din_CableCheckRes
  7433. DESCRIPTION:
  7434. PRE-CONDITION:
  7435. INPUT:
  7436. OUTPUT:
  7437. GLOBAL VARIABLES:
  7438. =============================================================================*/
  7439. int Proc_din_CableCheckRes(int AcceptFd)
  7440. {
  7441. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7442. //if it is not the same, the packet should be ignored.
  7443. //STEP 1: ============ Initialize ============
  7444. int i = 0;
  7445. int errn = 0;
  7446. bitstream_t v2g_tx_stream;
  7447. static struct CableCheckResponse_DIN70121 *cab;
  7448. static struct ChargingInfoData *sys;
  7449. size_t pos = 0;
  7450. v2g_tx_stream.pos = &pos;
  7451. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7452. v2g_tx_stream.data = V2GTP_Tx_buf;
  7453. cab = &ShmCcsData->V2GMessage_DIN70121.CableCheckResponse;
  7454. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7455. cab->ResponseCode = OK_DIN70121;
  7456. cab->cnt++;
  7457. DEBUG_PRINTF_EVCOMM_DETAIL("CP_State = %d (%.02f V), V_now = %.02f, Isolation Status = %d, EVSEProcessing = %d\n",
  7458. sys->CpState,
  7459. sys->CpVoltage,
  7460. sys->PresentChargingVoltage,
  7461. sys->IsolationStatus,
  7462. cab->EVSEProcessing);
  7463. //[HEADER] Check Req SessionID
  7464. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  7465. {
  7466. cab->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  7467. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  7468. errn = -1;
  7469. }
  7470. //Check for SequenceError
  7471. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7472. {
  7473. cab->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  7474. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  7475. errn = -1;
  7476. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7477. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7478. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7479. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7480. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7481. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7482. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7483. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7484. }
  7485. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  7486. if (sys->IsolationStatus == GFD_Invalid) //0: on going
  7487. {
  7488. //For PSU
  7489. sys->EvBatterytargetVoltage = CABLECHECK_TARGET_VOLTAGE; //500V //[To-Do] this should be modified to auto decision.
  7490. sys->EvBatterytargetCurrent = CABLECHECK_TARGET_CURRENT; //2A(default), unit: 1A
  7491. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7492. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive; //4
  7493. cab->EVSEProcessing = dinEVSEProcessingType_Ongoing;
  7494. }
  7495. else if ((sys->IsolationStatus == GFD_Valid) || (sys->IsolationStatus == GFD_Warning)) //1: valid, 2: warning
  7496. {
  7497. //For PSU
  7498. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7499. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7500. if (sys->PresentChargingVoltage < 60) // < 60V
  7501. {
  7502. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  7503. sprintf(buf_log_evcomm, "[V2G][CableCheck]Pass (V_now = %.02f, Isolated = %d)",
  7504. sys->PresentChargingVoltage,
  7505. sys->IsolationStatus);
  7506. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7507. //IsolationStatus
  7508. if (sys->IsolationStatus == GFD_Valid)
  7509. {
  7510. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7511. }
  7512. else if (sys->IsolationStatus == GFD_Warning)
  7513. {
  7514. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning;
  7515. }
  7516. else
  7517. {
  7518. sprintf(buf_log_evcomm,
  7519. "[WARNING]unexpected IsolationStatus(%d)",
  7520. sys->IsolationStatus);
  7521. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7522. }
  7523. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7524. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7525. }
  7526. else
  7527. {
  7528. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7529. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7530. cab->EVSEProcessing = dinEVSEProcessingType_Ongoing;
  7531. }
  7532. }
  7533. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  7534. {
  7535. //For PSU
  7536. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7537. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7538. cab->ResponseCode = FAILED_DIN70121;
  7539. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7540. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_NotReady;
  7541. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7542. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_CableCheckRes]IsolationStatus = 3 (fault)");
  7543. errn = -1;
  7544. }
  7545. else
  7546. {
  7547. //For PSU
  7548. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7549. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7550. cab->ResponseCode = FAILED_DIN70121;
  7551. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7552. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_NotReady;
  7553. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7554. sprintf(buf_log_evcomm,
  7555. "[Proc_din_CableCheckRes]Undefined Isolation Status(%d)",
  7556. sys->IsolationStatus);
  7557. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7558. }
  7559. //Check for CSU command of "Stop by EVSE"
  7560. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7561. {
  7562. cab->ResponseCode = FAILED_DIN70121;
  7563. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7564. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7565. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7566. errn = -1;
  7567. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_CableCheckRes]EVSE_Shutdown");
  7568. }
  7569. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7570. {
  7571. cab->ResponseCode = FAILED_DIN70121;
  7572. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7573. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7574. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7575. errn = -1;
  7576. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_CableCheckRes]EVSE_EmergencyShutdown");
  7577. }
  7578. else if (ShmInternalComm->ChargingPermission == FALSE)
  7579. {
  7580. cab->ResponseCode = FAILED_DIN70121;
  7581. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7582. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7583. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7584. errn = -1;
  7585. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_CableCheckRes]ChargingPermission = FALSE");
  7586. }
  7587. else
  7588. {
  7589. //null
  7590. }
  7591. //Response to CP Error
  7592. #if CP_PROTECTION_MECHANISM == ENABLE
  7593. //#if 1
  7594. if (sys->CableCheckPreCountDownDone == TRUE) //[To-Do] Here should be modified to 2 seconds
  7595. {
  7596. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  7597. {
  7598. cab->ResponseCode = FAILED_DIN70121;
  7599. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7600. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7601. Update_V2G_Flow_Status(Other_Fault);
  7602. errn = -1;
  7603. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7604. //CCS_SECC_CP_State_Error (023889)
  7605. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7606. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7607. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7608. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  7609. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  7610. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  7611. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  7612. sprintf(buf_log_evcomm,
  7613. "[CableCheck]Emergency Stop by CP Error (%d, %.02f V, %d)\n",
  7614. sys->CpState,
  7615. sys->CpVoltage,
  7616. cab->cnt
  7617. );
  7618. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7619. //cab->cnt = 0;
  7620. }
  7621. }
  7622. #endif
  7623. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7624. #if PARAMETER_NORMAL_MODE == ENABLE
  7625. SHM_Read_din_CableCheckRes(&ccs_exi_doc_DIN, ShmCcsData);
  7626. #else
  7627. Sudo_Parameter_din_CableCheckRes();
  7628. #endif
  7629. //STEP 4: ============ Encode and Send Response Message ===========
  7630. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  7631. {
  7632. errn = -1;
  7633. }
  7634. //STEP 5: ============ Update Flags ===========
  7635. sys->ConnectorLocked = TRUE; //Inicating EVSE that the CCS Connector is Locked.
  7636. return errn;
  7637. }
  7638. /*===========================================================================
  7639. FUNCTION: Proc_iso1_CableCheckRes
  7640. DESCRIPTION:
  7641. PRE-CONDITION:
  7642. INPUT:
  7643. OUTPUT:
  7644. GLOBAL VARIABLES:
  7645. =============================================================================*/
  7646. int Proc_iso1_CableCheckRes(int AcceptFd)
  7647. {
  7648. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7649. //if it is not the same, the packet should be ignored.
  7650. //STEP 1: ============ Initialize ============
  7651. int i = 0;
  7652. int errn = 0;
  7653. bitstream_t v2g_tx_stream;
  7654. static struct CableCheckResponse_ISO15118_2014 *cab;
  7655. static struct ChargingInfoData *sys;
  7656. size_t pos = 0;
  7657. v2g_tx_stream.pos = &pos;
  7658. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7659. v2g_tx_stream.data = V2GTP_Tx_buf;
  7660. cab = &ShmCcsData->V2GMessage_ISO15118_2014.CableCheckResponse;
  7661. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7662. cab->ResponseCode = OK_ISO15118_2014;
  7663. cab->cnt++;
  7664. DEBUG_PRINTF_EVCOMM_DETAIL("CP_State = %d (%.02f V), V_now = %.02f, Isolation Status = %d, EVSEProcessing = %d\n",
  7665. sys->CpState,
  7666. sys->CpVoltage,
  7667. sys->PresentChargingVoltage,
  7668. sys->IsolationStatus,
  7669. cab->EVSEProcessing);
  7670. //[HEADER] Check Req SessionID
  7671. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  7672. {
  7673. cab->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  7674. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  7675. errn = -1;
  7676. }
  7677. //Check for SequenceError
  7678. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7679. {
  7680. cab->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  7681. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  7682. errn = -1;
  7683. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7684. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7685. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7686. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7687. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7688. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7689. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7690. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7691. }
  7692. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  7693. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  7694. {
  7695. //For PSU
  7696. sys->EvBatterytargetVoltage = CABLECHECK_TARGET_VOLTAGE; //500V //[To-Do] this should be modified to auto decision.
  7697. sys->EvBatterytargetCurrent = CABLECHECK_TARGET_CURRENT; //2A(default), unit: 1A
  7698. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  7699. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7700. cab->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  7701. }
  7702. else if ((sys->IsolationStatus == GFD_Valid) || (sys->IsolationStatus == GFD_Warning)) //1: valid, 2:waring
  7703. {
  7704. //For PSU
  7705. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7706. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7707. if (sys->PresentChargingVoltage < 60) // < 60V
  7708. {
  7709. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  7710. sprintf(buf_log_evcomm, "[V2G][CableCheck]Pass (V_now = %.02f, Isolated = %d)",
  7711. sys->PresentChargingVoltage,
  7712. sys->IsolationStatus);
  7713. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7714. //IsolationStatus
  7715. if (sys->IsolationStatus == GFD_Valid)
  7716. {
  7717. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  7718. }
  7719. else if (sys->IsolationStatus == GFD_Warning)
  7720. {
  7721. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning;
  7722. }
  7723. else
  7724. {
  7725. sprintf(buf_log_evcomm,
  7726. "[WARNING]unexpected IsolationStatus(%d)",
  7727. sys->IsolationStatus);
  7728. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7729. }
  7730. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  7731. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7732. }
  7733. else
  7734. {
  7735. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  7736. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7737. cab->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  7738. }
  7739. }
  7740. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  7741. {
  7742. //For PSU
  7743. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7744. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7745. cab->ResponseCode = FAILED_ISO15118_2014;
  7746. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7747. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_NotReady;
  7748. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7749. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CableCheckRes]IsolationStatus = 3 (fault)");
  7750. errn = -1;
  7751. }
  7752. //else if (sys->IsolationStatus == GFD_No_IMD){} //only for ISO15118
  7753. else
  7754. {
  7755. //For PSU
  7756. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7757. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7758. cab->ResponseCode = FAILED_ISO15118_2014;
  7759. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7760. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_NotReady;
  7761. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7762. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CableCheckRes]Undefined Isolation Status.");
  7763. }
  7764. //Check for CSU command of "Stop by EVSE"
  7765. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7766. {
  7767. cab->ResponseCode = FAILED_ISO15118_2014;
  7768. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7769. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7770. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7771. errn = -1;
  7772. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CableCheckRes]EVSE_Shutdown");
  7773. }
  7774. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7775. {
  7776. cab->ResponseCode = FAILED_ISO15118_2014;
  7777. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7778. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7779. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7780. errn = -1;
  7781. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CableCheckRes]EVSE_EmergencyShutdown");
  7782. }
  7783. else if (ShmInternalComm->ChargingPermission == FALSE)
  7784. {
  7785. cab->ResponseCode = FAILED_ISO15118_2014;
  7786. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7787. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7788. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7789. errn = -1;
  7790. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_CableCheckRes]ChargingPermission = FALSE");
  7791. }
  7792. else
  7793. {
  7794. //null
  7795. }
  7796. //Response to CP Error
  7797. #if CP_PROTECTION_MECHANISM == ENABLE
  7798. if (sys->CableCheckPreCountDownDone == TRUE) //[To-Do] Here should be modified to 2 seconds
  7799. {
  7800. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  7801. {
  7802. cab->ResponseCode = FAILED_ISO15118_2014;
  7803. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7804. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7805. Update_V2G_Flow_Status(Other_Fault);
  7806. errn = -1;
  7807. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7808. //CCS_SECC_CP_State_Error (023889)
  7809. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7810. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7811. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7812. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  7813. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  7814. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  7815. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  7816. sprintf(buf_log_evcomm,
  7817. "[CableCheck]Emergency Stop by CP Error (%d, %.02f V, %d)\n",
  7818. sys->CpState,
  7819. sys->CpVoltage,
  7820. cab->cnt
  7821. );
  7822. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7823. //cab->cnt = 0;
  7824. }
  7825. }
  7826. #endif
  7827. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7828. #if PARAMETER_NORMAL_MODE == ENABLE
  7829. SHM_Read_iso1_CableCheckRes(&ccs_exi_doc_ISO1, ShmCcsData);
  7830. #else
  7831. Sudo_Parameter_iso1_CableCheckRes();
  7832. #endif
  7833. //STEP 4: ============ Encode and Send Response Message ===========
  7834. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  7835. {
  7836. errn = -1;
  7837. }
  7838. //STEP 5: ============ Update Flags ===========
  7839. sys->ConnectorLocked = TRUE; //Inicating EVSE that the CCS Connector is Locked.
  7840. return errn;
  7841. }
  7842. /*===========================================================================
  7843. FUNCTION: Proc_din_CableCheckReq
  7844. DESCRIPTION:
  7845. PRE-CONDITION:
  7846. INPUT:
  7847. OUTPUT:
  7848. GLOBAL VARIABLES:
  7849. =============================================================================*/
  7850. int Proc_din_CableCheckReq(int AcceptFd)
  7851. {
  7852. int errn = 0;
  7853. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_CableCheckReq] Got CableCheckReq\n");
  7854. //Print the decoded XML Document
  7855. PRINT_XML_DOC_DIN_CableCheckReq(&ccs_exi_doc_DIN);
  7856. //Save into Share Memory
  7857. SHM_Save_din_CableCheckReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  7858. //Check for EV Error Code
  7859. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.CableCheckRequest.DC_EVStatus.EVErrorCode);
  7860. errn = Proc_din_CableCheckRes(AcceptFd);
  7861. if (errn == 0)
  7862. {
  7863. //send response successfully.
  7864. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]CableCheckRes");
  7865. }
  7866. else
  7867. {
  7868. sprintf(buf_log_evcomm,
  7869. "[Error][SeccComm][Proc_din_CableCheckReq]Proc_iso1_CableCheckRes(): %d (DEC)",
  7870. errn);
  7871. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7872. }
  7873. return errn;
  7874. }
  7875. /*===========================================================================
  7876. FUNCTION: Proc_iso1_CableCheckReq
  7877. DESCRIPTION:
  7878. PRE-CONDITION:
  7879. INPUT:
  7880. OUTPUT:
  7881. GLOBAL VARIABLES:
  7882. =============================================================================*/
  7883. int Proc_iso1_CableCheckReq(int AcceptFd)
  7884. {
  7885. int errn = 0;
  7886. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CableCheckReq] Got CableCheckReq");
  7887. //Print the decoded XML Document
  7888. PRINT_XML_DOC_ISO1_CableCheckReq(&ccs_exi_doc_ISO1);
  7889. //Save into Share Memory
  7890. SHM_Save_iso1_CableCheckReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  7891. //Check for EV Error Code
  7892. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.CableCheckRequest.DC_EVStatus.EVErrorCode);
  7893. errn = Proc_iso1_CableCheckRes(AcceptFd);
  7894. if (errn == 0)
  7895. {
  7896. //send response successfully.
  7897. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]CableCheckRes");
  7898. }
  7899. else
  7900. {
  7901. sprintf(buf_log_evcomm,
  7902. "[Error][SeccComm][Proc_iso1_CableCheckReq]Proc_iso1_CableCheckRes(): %d (DEC)",
  7903. errn);
  7904. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  7905. }
  7906. return errn;
  7907. }
  7908. /*===========================================================================
  7909. FUNCTION: SHM_Init_din_PreChargeRes
  7910. DESCRIPTION:
  7911. PRE-CONDITION:
  7912. INPUT:
  7913. 1. shm_ccs
  7914. OUTPUT:
  7915. 1. shm_ccs
  7916. GLOBAL VARIABLES:
  7917. =============================================================================*/
  7918. void SHM_Init_din_PreChargeRes(struct CcsData *shm_ccs)
  7919. {
  7920. struct PreChargeResponse_DIN70121 *in;
  7921. in = &shm_ccs->V2GMessage_DIN70121.PreChargeResponse;
  7922. //----- [BODY (1/3)] ResponseCode -----
  7923. in->ResponseCode = dinresponseCodeType_OK;
  7924. //----- [BODY (2/3)] EVSEPresentVoltage -----
  7925. short value = 0; int multiplier = 0; unsigned char unit = 0;
  7926. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for Test
  7927. value = 0; multiplier = 0; unit = V_DIN70121; //waiting for CsuComm to update V to fit EV Target
  7928. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  7929. //----- [BODY (3/3)] DC_EVSEStatus -----
  7930. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  7931. }
  7932. /*===========================================================================
  7933. FUNCTION: Sudo_Parameter_din_PreChargeRes
  7934. DESCRIPTION:
  7935. PRE-CONDITION:
  7936. INPUT:
  7937. OUTPUT:
  7938. GLOBAL VARIABLES:
  7939. =============================================================================*/
  7940. void Sudo_Parameter_din_PreChargeRes()
  7941. {
  7942. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  7943. init_dinPreChargeResType(&ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes);
  7944. ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes_isUsed = 1u;
  7945. //----- [BODY (1/3)] ResponseCode -----
  7946. struct dinPreChargeResType *res;
  7947. res = &ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes;
  7948. res->ResponseCode = dinresponseCodeType_OK;
  7949. //----- [BODY (2/3)] EVSEPresentVoltage -----
  7950. res->EVSEPresentVoltage.Value = 3820;
  7951. res->EVSEPresentVoltage.Multiplier = -1;
  7952. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  7953. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  7954. // dinunitSymbolType_h = 0,
  7955. // dinunitSymbolType_m = 1,
  7956. // dinunitSymbolType_s = 2,
  7957. // dinunitSymbolType_A = 3,
  7958. // dinunitSymbolType_Ah = 4,
  7959. // dinunitSymbolType_V = 5,
  7960. // dinunitSymbolType_VA = 6,
  7961. // dinunitSymbolType_W = 7,
  7962. // dinunitSymbolType_W_s = 8,
  7963. // dinunitSymbolType_Wh = 9
  7964. //----- [BODY (3/3)] DC_EVSEStatus -----
  7965. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7966. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7967. // dinisolationLevelType_Invalid = 0,
  7968. // dinisolationLevelType_Valid = 1,
  7969. // dinisolationLevelType_Warning = 2,
  7970. // dinisolationLevelType_Fault = 3
  7971. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7972. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7973. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  7974. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7975. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7976. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7977. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7978. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7979. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  7980. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  7981. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  7982. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  7983. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  7984. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7985. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  7986. // dinEVSENotificationType_None = 0,
  7987. // dinEVSENotificationType_StopCharging = 1,
  7988. // dinEVSENotificationType_ReNegotiation = 2
  7989. }
  7990. /*===========================================================================
  7991. FUNCTION: Sudo_Parameter_iso1_PreChargeRes
  7992. DESCRIPTION:
  7993. PRE-CONDITION:
  7994. INPUT:
  7995. OUTPUT:
  7996. GLOBAL VARIABLES:
  7997. =============================================================================*/
  7998. void Sudo_Parameter_iso1_PreChargeRes()
  7999. {
  8000. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8001. init_iso1PreChargeResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes);
  8002. ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes_isUsed = 1u;
  8003. //----- [BODY (1/3)] ResponseCode -----
  8004. struct iso1PreChargeResType *res;
  8005. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes;
  8006. res->ResponseCode = iso1responseCodeType_OK;
  8007. //----- [BODY (2/3)] EVSEPresentVoltage -----
  8008. res->EVSEPresentVoltage.Value = 3820;
  8009. res->EVSEPresentVoltage.Multiplier = -1;
  8010. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  8011. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  8012. //iso1unitSymbolType_h = 0,
  8013. //iso1unitSymbolType_m = 1,
  8014. //iso1unitSymbolType_s = 2,
  8015. //iso1unitSymbolType_A = 3,
  8016. //iso1unitSymbolType_V = 4,
  8017. //iso1unitSymbolType_W = 5,
  8018. //iso1unitSymbolType_Wh = 6
  8019. //----- [BODY (3/3)] DC_EVSEStatus -----
  8020. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8021. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  8022. //iso1isolationLevelType_Invalid = 0,
  8023. //iso1isolationLevelType_Valid = 1,
  8024. //iso1isolationLevelType_Warning = 2,
  8025. //iso1isolationLevelType_Fault = 3,
  8026. //iso1isolationLevelType_No_IMD = 4
  8027. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8028. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8029. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8030. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8031. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8032. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8033. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8034. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8035. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8036. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8037. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8038. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8039. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8040. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8041. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8042. //iso1EVSENotificationType_None = 0,
  8043. //iso1EVSENotificationType_StopCharging = 1,
  8044. //iso1EVSENotificationType_ReNegotiation = 2
  8045. }
  8046. /*===========================================================================
  8047. FUNCTION: Proc_din_PreChargeRes
  8048. DESCRIPTION:
  8049. PRE-CONDITION:
  8050. INPUT:
  8051. OUTPUT:
  8052. GLOBAL VARIABLES:
  8053. =============================================================================*/
  8054. int Proc_din_PreChargeRes(int AcceptFd)
  8055. {
  8056. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8057. //if it is not the same, the packet should be ignored.
  8058. //STEP 1: ============ Initialize ============
  8059. int i = 0;
  8060. int errn = 0;
  8061. bitstream_t v2g_tx_stream;
  8062. static struct PreChargeResponse_DIN70121 *pre;
  8063. static struct ChargingInfoData *sys;
  8064. size_t pos = 0;
  8065. v2g_tx_stream.pos = &pos;
  8066. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8067. v2g_tx_stream.data = V2GTP_Tx_buf;
  8068. pre = &ShmCcsData->V2GMessage_DIN70121.PreChargeResponse;
  8069. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8070. pre->ResponseCode = OK_DIN70121;
  8071. //EVSE Status Code
  8072. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8073. //[HEADER] Check Req SessionID
  8074. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  8075. {
  8076. pre->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  8077. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  8078. errn = -1;
  8079. }
  8080. //Check for SequenceError
  8081. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8082. {
  8083. pre->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  8084. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  8085. errn = -1;
  8086. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8087. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8088. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8089. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8090. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8091. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8092. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8093. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8094. }
  8095. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8096. SAVE_PhysicalValueType_DIN70121(&pre->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  8097. //Isolation Status
  8098. if (sys->IsolationStatus == GFD_Invalid) //0: invalid
  8099. {
  8100. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  8101. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8102. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8103. Update_V2G_Flow_Status(Other_Fault);
  8104. errn = -1;
  8105. sprintf(buf_log_evcomm, "[Error][Proc_din_PreChargeRes]IsolationStatus = %d", sys->IsolationStatus);
  8106. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8107. }
  8108. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  8109. {
  8110. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  8111. }
  8112. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  8113. {
  8114. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  8115. }
  8116. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  8117. {
  8118. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]GFD_Fault => Emergency Shutdown");
  8119. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  8120. pre->ResponseCode = FAILED_DIN70121;
  8121. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8122. errn = -1;
  8123. }
  8124. else //GFD_No_IMD or other unexpected status
  8125. {
  8126. pre->ResponseCode = FAILED_DIN70121;
  8127. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  8128. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8129. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8130. Update_V2G_Flow_Status(Other_Fault);
  8131. errn = -1;
  8132. sprintf(buf_log_evcomm,
  8133. "[Error][Proc_din_PreChargeRes]IsolationStatus = %d (undefined)",
  8134. sys->IsolationStatus);
  8135. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8136. }
  8137. //Check for CSU command of "Stop by EVSE"
  8138. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8139. {
  8140. //Check for Alarm Code: CCS GFD trip (012235)
  8141. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8142. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8143. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8144. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8145. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8146. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8147. {
  8148. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]CCS GFD trip => EVSE_Shutdown");
  8149. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8150. }
  8151. else
  8152. {
  8153. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]EVSE_Shutdown");
  8154. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8155. }
  8156. pre->ResponseCode = FAILED_DIN70121;
  8157. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8158. errn = -1;
  8159. }
  8160. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8161. {
  8162. //Check for Alarm Code: CCS GFD trip (012235)
  8163. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8164. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8165. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8166. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8167. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8168. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8169. {
  8170. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]CCS GFD trip => EVSE_EmergencyShutdown");
  8171. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8172. }
  8173. else
  8174. {
  8175. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]EVSE_EmergencyShutdown");
  8176. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8177. }
  8178. pre->ResponseCode = FAILED_DIN70121;
  8179. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8180. errn = -1;
  8181. }
  8182. else if (ShmInternalComm->ChargingPermission == FALSE)
  8183. {
  8184. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_PreChargeRes]ChargingPermission = FALSE");
  8185. pre->ResponseCode = FAILED_DIN70121;
  8186. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8187. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8188. errn = -1;
  8189. }
  8190. else
  8191. {
  8192. //null
  8193. }
  8194. //Response to CP Error
  8195. #if CP_PROTECTION_MECHANISM == ENABLE
  8196. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  8197. {
  8198. pre->ResponseCode = FAILED_DIN70121;
  8199. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8200. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8201. Update_V2G_Flow_Status(Other_Fault);
  8202. errn = -1;
  8203. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8204. //CCS_SECC_CP_State_Error (023889)
  8205. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8206. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8207. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8208. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  8209. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  8210. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  8211. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  8212. sprintf(buf_log_evcomm,
  8213. "[Error][Proc_din_PreChargeRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  8214. sys->CpState,
  8215. sys->CpVoltage
  8216. );
  8217. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8218. }
  8219. #endif
  8220. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8221. #if PARAMETER_NORMAL_MODE == ENABLE
  8222. SHM_Read_din_PreChargeRes(&ccs_exi_doc_DIN, ShmCcsData);
  8223. #else
  8224. Sudo_Parameter_din_PreChargeRes();
  8225. #endif
  8226. //STEP 4: ============ Encode and Send Response Message ===========
  8227. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  8228. {
  8229. SAVE_SYS_LOG_MSG_EVCOMM("[Error][send_encoded_din_V2GTP_Stream]:Tx encoded msg error");
  8230. errn = -1;
  8231. }
  8232. //STEP 5: ============ Update Flags ===========
  8233. return errn;
  8234. }
  8235. /*===========================================================================
  8236. FUNCTION: Proc_iso1_PreChargeRes
  8237. DESCRIPTION:
  8238. PRE-CONDITION:
  8239. INPUT:
  8240. OUTPUT:
  8241. GLOBAL VARIABLES:
  8242. =============================================================================*/
  8243. int Proc_iso1_PreChargeRes(int AcceptFd)
  8244. {
  8245. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8246. //if it is not the same, the packet should be ignored.
  8247. //STEP 1: ============ Initialize ============
  8248. int i = 0;
  8249. int errn = 0;
  8250. bitstream_t v2g_tx_stream;
  8251. static struct PreChargeResponse_ISO15118_2014 *pre;
  8252. static struct ChargingInfoData *sys;
  8253. size_t pos = 0;
  8254. v2g_tx_stream.pos = &pos;
  8255. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8256. v2g_tx_stream.data = V2GTP_Tx_buf;
  8257. pre = &ShmCcsData->V2GMessage_ISO15118_2014.PreChargeResponse;
  8258. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8259. pre->ResponseCode = OK_ISO15118_2014;
  8260. //EVSE Status Code
  8261. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8262. //[HEADER] Check Req SessionID
  8263. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  8264. {
  8265. pre->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  8266. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  8267. errn = -1;
  8268. }
  8269. //Check for SequenceError
  8270. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8271. {
  8272. pre->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  8273. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  8274. errn = -1;
  8275. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8276. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8277. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8278. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8279. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8280. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8281. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8282. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8283. }
  8284. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8285. SAVE_PhysicalValueType_ISO15118_2014(&pre->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  8286. //Isolation Status
  8287. if (sys->IsolationStatus == GFD_Invalid) //0: invalid(on going)
  8288. {
  8289. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  8290. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8291. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8292. Update_V2G_Flow_Status(Other_Fault);
  8293. errn = -1;
  8294. sprintf(buf_log_evcomm, "[Error][Proc_iso1_PreChargeRes]IsolationStatus = %d", sys->IsolationStatus);
  8295. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8296. }
  8297. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  8298. {
  8299. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  8300. }
  8301. else if (sys->IsolationStatus == GFD_Warning) //2: waring
  8302. {
  8303. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning; //1
  8304. }
  8305. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  8306. {
  8307. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]GFD_Fault => Emergency Shutdown");
  8308. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  8309. pre->ResponseCode = FAILED_ISO15118_2014;
  8310. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8311. errn = -1;
  8312. }
  8313. else
  8314. {
  8315. pre->ResponseCode = FAILED_ISO15118_2014;
  8316. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  8317. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8318. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8319. Update_V2G_Flow_Status(Other_Fault);
  8320. errn = -1;
  8321. sprintf(buf_log_evcomm,
  8322. "[Error][Proc_iso1_PreChargeRes]IsolationStatus = %d (undefined)",
  8323. sys->IsolationStatus);
  8324. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8325. }
  8326. //Check for CSU command of "Stop by EVSE"
  8327. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8328. {
  8329. //Check for Alarm Code: CCS GFD trip (012235)
  8330. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8331. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8332. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8333. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8334. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8335. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8336. {
  8337. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]CCS GFD trip => EVSE_Shutdown");
  8338. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8339. }
  8340. else
  8341. {
  8342. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]EVSE_Shutdown");
  8343. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8344. }
  8345. pre->ResponseCode = FAILED_ISO15118_2014;
  8346. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8347. errn = -1;
  8348. }
  8349. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8350. {
  8351. //Check for Alarm Code: CCS GFD trip (012235)
  8352. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8353. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8354. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8355. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8356. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8357. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8358. {
  8359. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]CCS GFD trip => EVSE_EmergencyShutdown");
  8360. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8361. }
  8362. else
  8363. {
  8364. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]EVSE_EmergencyShutdown");
  8365. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8366. }
  8367. pre->ResponseCode = FAILED_ISO15118_2014;
  8368. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8369. errn = -1;
  8370. }
  8371. else if (ShmInternalComm->ChargingPermission == FALSE)
  8372. {
  8373. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_PreChargeRes]ChargingPermission = FALSE");
  8374. pre->ResponseCode = FAILED_ISO15118_2014;
  8375. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8376. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8377. errn = -1;
  8378. }
  8379. else
  8380. {
  8381. //null
  8382. }
  8383. //Response to CP Error
  8384. #if CP_PROTECTION_MECHANISM == ENABLE
  8385. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  8386. {
  8387. pre->ResponseCode = FAILED_ISO15118_2014;
  8388. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8389. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8390. Update_V2G_Flow_Status(Other_Fault);
  8391. errn = -1;
  8392. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8393. //CCS_SECC_CP_State_Error (023889)
  8394. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8395. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8396. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8397. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  8398. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  8399. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  8400. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  8401. sprintf(buf_log_evcomm,
  8402. "[Error][Proc_iso1_PreChargeRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  8403. sys->CpState,
  8404. sys->CpVoltage
  8405. );
  8406. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8407. }
  8408. #endif
  8409. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8410. #if PARAMETER_NORMAL_MODE == ENABLE
  8411. SHM_Read_iso1_PreChargeRes(&ccs_exi_doc_ISO1, ShmCcsData);
  8412. #else
  8413. Sudo_Parameter_iso1_PreChargeRes();
  8414. #endif
  8415. //STEP 4: ============ Encode and Send Response Message ===========
  8416. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  8417. {
  8418. SAVE_SYS_LOG_MSG_EVCOMM("[Error][send_encoded_iso1_V2GTP_Stream]:Tx encoded msg error");
  8419. errn = -1;
  8420. }
  8421. //STEP 5: ============ Update Flags ===========
  8422. return errn;
  8423. }
  8424. /*===========================================================================
  8425. FUNCTION: Proc_din_PreChargeReq
  8426. DESCRIPTION:
  8427. PRE-CONDITION:
  8428. INPUT:
  8429. OUTPUT:
  8430. GLOBAL VARIABLES:
  8431. =============================================================================*/
  8432. int Proc_din_PreChargeReq(int AcceptFd)
  8433. {
  8434. int errn = 0;
  8435. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_PreChargeReq] Got PreChargeReq");
  8436. //Print the decoded XML Document
  8437. PRINT_XML_DOC_DIN_PreChargeReq(&ccs_exi_doc_DIN);
  8438. //Save into Share Memory
  8439. SHM_Save_din_PreChargeReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  8440. //Check for EV Error Code
  8441. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PreChargeRequest.DC_EVStatus.EVErrorCode);
  8442. errn = Proc_din_PreChargeRes(AcceptFd);
  8443. if (errn == 0)
  8444. {
  8445. //send response successfully.
  8446. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]PreChargeRes");
  8447. }
  8448. else
  8449. {
  8450. sprintf(buf_log_evcomm,
  8451. "[Error][SeccComm][Proc_din_PreChargeReq]Proc_iso1_PreChargeRes(): %d (DEC)",
  8452. errn);
  8453. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8454. }
  8455. return errn;
  8456. }
  8457. /*===========================================================================
  8458. FUNCTION: Proc_iso1_PreChargeReq
  8459. DESCRIPTION:
  8460. PRE-CONDITION:
  8461. INPUT:
  8462. OUTPUT:
  8463. GLOBAL VARIABLES:
  8464. =============================================================================*/
  8465. int Proc_iso1_PreChargeReq(int AcceptFd)
  8466. {
  8467. int errn = 0;
  8468. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_PreChargeReq] Got PreChargeReq");
  8469. //Print the decoded XML Document
  8470. PRINT_XML_DOC_ISO1_PreChargeReq(&ccs_exi_doc_ISO1);
  8471. //Save into Share Memory
  8472. SHM_Save_iso1_PreChargeReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  8473. //Check for EV Error Code
  8474. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PreChargeRequest.DC_EVStatus.EVErrorCode);
  8475. errn = Proc_iso1_PreChargeRes(AcceptFd);
  8476. if (errn == 0)
  8477. {
  8478. //send response successfully.
  8479. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]PreChargeRes");
  8480. }
  8481. else
  8482. {
  8483. sprintf(buf_log_evcomm,
  8484. "[Error][SeccComm][Proc_iso1_PreChargeReq]Proc_iso1_PreChargeRes(): %d (DEC)",
  8485. errn);
  8486. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8487. }
  8488. return errn;
  8489. }
  8490. /*===========================================================================
  8491. FUNCTION: SHM_Init_din_PowerDeliveryRes
  8492. DESCRIPTION:
  8493. PRE-CONDITION:
  8494. INPUT:
  8495. 1. shm_ccs
  8496. OUTPUT:
  8497. 1. shm_ccs
  8498. GLOBAL VARIABLES:
  8499. =============================================================================*/
  8500. void SHM_Init_din_PowerDeliveryRes(struct CcsData *shm_ccs)
  8501. {
  8502. struct PowerDeliveryResponse_DIN70121 *in;
  8503. in = &shm_ccs->V2GMessage_DIN70121.PowerDeliveryResponse;
  8504. //----- [BODY (1/3)] ResponseCode -----
  8505. in->ResponseCode = dinresponseCodeType_OK;
  8506. //----- [BODY (2/3)] AC_EVSEStatus -----
  8507. //ignore, since DIN 70121 doesn't support AC, yet.
  8508. //----- [BODY (2/3)] DC_EVSEStatus -----
  8509. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  8510. }
  8511. /*===========================================================================
  8512. FUNCTION: Sudo_Parameter_din_PowerDeliveryRes
  8513. DESCRIPTION:
  8514. PRE-CONDITION:
  8515. INPUT:
  8516. OUTPUT:
  8517. GLOBAL VARIABLES:
  8518. =============================================================================*/
  8519. void Sudo_Parameter_din_PowerDeliveryRes()
  8520. {
  8521. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  8522. init_dinPowerDeliveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes);
  8523. ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  8524. //----- [BODY (1/3)] ResponseCode -----
  8525. struct dinPowerDeliveryResType *res;
  8526. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  8527. res->ResponseCode = dinresponseCodeType_OK;
  8528. //----- [BODY (2/3)] AC_EVSEStatus -----
  8529. //ignore, since DIN 70121 doesn't support AC, yet.
  8530. //----- [BODY (2/3)] DC_EVSEStatus -----
  8531. res->DC_EVSEStatus_isUsed = 1u;
  8532. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8533. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  8534. // dinisolationLevelType_Invalid = 0,
  8535. // dinisolationLevelType_Valid = 1,
  8536. // dinisolationLevelType_Warning = 2,
  8537. // dinisolationLevelType_Fault = 3
  8538. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8539. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8540. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  8541. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8542. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8543. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8544. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8545. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8546. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  8547. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  8548. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  8549. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  8550. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  8551. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8552. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  8553. // dinEVSENotificationType_None = 0,
  8554. // dinEVSENotificationType_StopCharging = 1,
  8555. // dinEVSENotificationType_ReNegotiation = 2
  8556. }
  8557. /*===========================================================================
  8558. FUNCTION: Sudo_Parameter_iso1_PowerDeliveryRes
  8559. DESCRIPTION:
  8560. PRE-CONDITION:
  8561. INPUT:
  8562. OUTPUT:
  8563. GLOBAL VARIABLES:
  8564. =============================================================================*/
  8565. void Sudo_Parameter_iso1_PowerDeliveryRes()
  8566. {
  8567. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8568. init_iso1PowerDeliveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes);
  8569. ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  8570. //----- [BODY (1/3)] ResponseCode -----
  8571. struct iso1PowerDeliveryResType *res;
  8572. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  8573. res->ResponseCode = iso1responseCodeType_OK;
  8574. //----- [BODY (2/3)] AC_EVSEStatus -----
  8575. //ignore, since our ISO1 70121 doesn't support AC, yet.
  8576. //----- [BODY (2/3)] DC_EVSEStatus -----
  8577. res->DC_EVSEStatus_isUsed = 1u;
  8578. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8579. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  8580. //iso1isolationLevelType_Invalid = 0,
  8581. //iso1isolationLevelType_Valid = 1,
  8582. //iso1isolationLevelType_Warning = 2,
  8583. //iso1isolationLevelType_Fault = 3,
  8584. //iso1isolationLevelType_No_IMD = 4
  8585. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8586. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8587. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8588. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8589. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8590. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8591. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8592. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8593. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8594. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8595. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8596. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8597. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8598. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8599. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8600. //iso1EVSENotificationType_None = 0,
  8601. //iso1EVSENotificationType_StopCharging = 1,
  8602. //iso1EVSENotificationType_ReNegotiation = 2
  8603. }
  8604. /*===========================================================================
  8605. FUNCTION: Proc_din_PowerDeliveryStartRes
  8606. DESCRIPTION:
  8607. PRE-CONDITION:
  8608. INPUT:
  8609. OUTPUT:
  8610. GLOBAL VARIABLES:
  8611. =============================================================================*/
  8612. int Proc_din_PowerDeliveryStartRes(int AcceptFd)
  8613. {
  8614. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8615. //if it is not the same, the packet should be ignored.
  8616. //STEP 1: ============ Initialize ============
  8617. int i = 0;
  8618. int errn = 0;
  8619. bitstream_t v2g_tx_stream;
  8620. struct dinPowerDeliveryResType *res;
  8621. struct ChargingInfoData *sys;
  8622. size_t pos = 0;
  8623. v2g_tx_stream.pos = &pos;
  8624. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8625. v2g_tx_stream.data = V2GTP_Tx_buf;
  8626. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  8627. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8628. res->ResponseCode = OK_DIN70121;
  8629. //[HEADER] Check Req SessionID
  8630. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  8631. {
  8632. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  8633. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  8634. errn = -1;
  8635. }
  8636. //Check for SequenceError
  8637. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8638. {
  8639. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  8640. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  8641. errn = -1;
  8642. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8643. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8644. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8645. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8646. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8647. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8648. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8649. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8650. }
  8651. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8652. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8653. #if PARAMETER_NORMAL_MODE == ENABLE
  8654. SHM_Read_din_PowerDeliveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  8655. #else
  8656. Sudo_Parameter_din_PowerDeliveryRes();
  8657. #endif
  8658. //EVSE Status Code
  8659. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  8660. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8661. //Check for CSU command of "Stop by EVSE"
  8662. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8663. {
  8664. //res->ResponseCode = FAILED_DIN70121;
  8665. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8666. }
  8667. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8668. {
  8669. //res->ResponseCode = FAILED_DIN70121;
  8670. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8671. }
  8672. else if (ShmInternalComm->ChargingPermission == FALSE)
  8673. {
  8674. //res->ResponseCode = FAILED_DIN70121;
  8675. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8676. }
  8677. //STEP 4: ============ Encode and Send Response Message ===========
  8678. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  8679. {
  8680. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_PowerDeliveryStartRes][Error]Tx encoded msg error");
  8681. errn = -1;
  8682. }
  8683. //STEP 5: ============ Update Flags ===========
  8684. return errn;
  8685. }
  8686. /*===========================================================================
  8687. FUNCTION: Proc_iso1_PowerDeliveryStartRes
  8688. DESCRIPTION:
  8689. PRE-CONDITION:
  8690. INPUT:
  8691. OUTPUT:
  8692. GLOBAL VARIABLES:
  8693. =============================================================================*/
  8694. int Proc_iso1_PowerDeliveryStartRes(int AcceptFd)
  8695. {
  8696. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8697. //if it is not the same, the packet should be ignored.
  8698. //STEP 1: ============ Initialize ============
  8699. int i = 0;
  8700. int errn = 0;
  8701. bitstream_t v2g_tx_stream;
  8702. struct iso1PowerDeliveryResType *res;
  8703. struct ChargingInfoData *sys;
  8704. size_t pos = 0;
  8705. v2g_tx_stream.pos = &pos;
  8706. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8707. v2g_tx_stream.data = V2GTP_Tx_buf;
  8708. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  8709. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8710. res->ResponseCode = OK_ISO15118_2014;
  8711. //[HEADER] Check Req SessionID
  8712. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  8713. {
  8714. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  8715. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  8716. errn = -1;
  8717. }
  8718. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8719. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8720. #if PARAMETER_NORMAL_MODE == ENABLE
  8721. SHM_Read_iso1_PowerDeliveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  8722. #else
  8723. Sudo_Parameter_iso1_PowerDeliveryRes();
  8724. #endif
  8725. //EVSE Status Code
  8726. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  8727. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8728. //Check for CSU command of "Stop by EVSE"
  8729. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8730. {
  8731. //res->ResponseCode = FAILED_ISO15118_2014;
  8732. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8733. }
  8734. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8735. {
  8736. //res->ResponseCode = FAILED_ISO15118_2014;
  8737. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8738. }
  8739. else if (ShmInternalComm->ChargingPermission == FALSE)
  8740. {
  8741. //res->ResponseCode = FAILED_ISO15118_2014;
  8742. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8743. }
  8744. //STEP 4: ============ Encode and Send Response Message ===========
  8745. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  8746. {
  8747. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_PowerDeliveryStartRes][Error]Tx encoded msg error");
  8748. errn = -1;
  8749. }
  8750. //STEP 5: ============ Update Flags ===========
  8751. return errn;
  8752. }
  8753. /*===========================================================================
  8754. FUNCTION: Proc_din_PowerDeliveryStartReq
  8755. DESCRIPTION:
  8756. PRE-CONDITION:
  8757. INPUT:
  8758. OUTPUT:
  8759. GLOBAL VARIABLES:
  8760. =============================================================================*/
  8761. int Proc_din_PowerDeliveryStartReq(int AcceptFd)
  8762. {
  8763. int errn = 0;
  8764. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PowerDeliveryStartReq");
  8765. //Print the decoded XML Document
  8766. PRINT_XML_DOC_DIN_PowerDeliveryReq(&ccs_exi_doc_DIN);
  8767. //Save into Share Memory
  8768. SHM_Save_din_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  8769. //Check for EV Error Code
  8770. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  8771. errn = Proc_din_PowerDeliveryStartRes(AcceptFd);
  8772. if (errn == 0)
  8773. {
  8774. //send response successfully.
  8775. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]PowerDeliveryStartRes");
  8776. }
  8777. else
  8778. {
  8779. sprintf(buf_log_evcomm,
  8780. "[Error][Proc_din_PowerDeliveryStartReq]Proc_iso1_PowerDeliveryStartRes(): %d (DEC)",
  8781. errn);
  8782. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8783. }
  8784. return errn;
  8785. }
  8786. /*===========================================================================
  8787. FUNCTION: Proc_iso1_PowerDeliveryStartReq
  8788. DESCRIPTION:
  8789. PRE-CONDITION:
  8790. INPUT:
  8791. OUTPUT:
  8792. GLOBAL VARIABLES:
  8793. =============================================================================*/
  8794. int Proc_iso1_PowerDeliveryStartReq(int AcceptFd)
  8795. {
  8796. int errn = 0;
  8797. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PowerDeliveryStartReq");
  8798. //Print the decoded XML Document
  8799. PRINT_XML_DOC_ISO1_PowerDeliveryReq(&ccs_exi_doc_ISO1);
  8800. //Save into Share Memory
  8801. SHM_Save_iso1_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  8802. //Check for EV Error Code
  8803. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  8804. errn = Proc_iso1_PowerDeliveryStartRes(AcceptFd);
  8805. if (errn == 0)
  8806. {
  8807. //send response successfully.
  8808. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]PowerDeliveryStartRes");
  8809. }
  8810. else
  8811. {
  8812. sprintf(buf_log_evcomm,
  8813. "[Error][Proc_iso1_PowerDeliveryStartReq]Proc_iso1_PowerDeliveryStartRes(): %d (DEC)",
  8814. errn);
  8815. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  8816. }
  8817. return errn;
  8818. }
  8819. /*===========================================================================
  8820. FUNCTION: SHM_Init_din_CurrentDemandRes
  8821. DESCRIPTION:
  8822. PRE-CONDITION:
  8823. INPUT:
  8824. 1. shm_ccs
  8825. OUTPUT:
  8826. 1. shm_ccs
  8827. GLOBAL VARIABLES:
  8828. =============================================================================*/
  8829. void SHM_Init_din_CurrentDemandRes(struct CcsData *shm_ccs)
  8830. {
  8831. struct CurrentDemandResponse_DIN70121 *in;
  8832. in = &shm_ccs->V2GMessage_DIN70121.CurrentDemandResponse;
  8833. //----- [BODY (1/10)] ResponseCode -----
  8834. in->ResponseCode = dinresponseCodeType_OK;
  8835. //----- [BODY (2/10)] DC_EVSEStatus -----
  8836. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  8837. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8838. short value = 0; int multiplier = 0; unsigned char unit = 0;
  8839. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for test only.
  8840. value = 0; multiplier = 0; unit = V_DIN70121;
  8841. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  8842. //----- [BODY (4/10)] EVSEPresentCurrent -----
  8843. //value = 600; multiplier = -1; unit = A_DIN70121; //60A, for test only.
  8844. value = 0; multiplier = 0; unit = A_DIN70121;
  8845. SHM_Save_dinPhysicalValueType(&in->EVSEPresentCurrent, value, multiplier, unit);
  8846. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  8847. in->EVSECurrentLimitAchieved = FALSE;
  8848. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  8849. in->EVSEVoltageLimitAchieved = FALSE;
  8850. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  8851. in->EVSEPowerLimitAchieved = FALSE;
  8852. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  8853. //value = 7500; multiplier = -1; unit = V_DIN70121; //750V
  8854. value = 5000; multiplier = -1; unit = V_DIN70121; //500V
  8855. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumVoltageLimit, value, multiplier, unit);
  8856. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  8857. value = 600; multiplier = -1; unit = A_DIN70121; //60A
  8858. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumCurrentLimit, value, multiplier, unit);
  8859. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  8860. value = 3000; multiplier = 1; unit = W_DIN70121; //30KW
  8861. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumPowerLimit, value, multiplier, unit);
  8862. }
  8863. /*===========================================================================
  8864. FUNCTION: Sudo_Parameter_din_CurrentDemandRes
  8865. DESCRIPTION:
  8866. PRE-CONDITION:
  8867. INPUT:
  8868. OUTPUT:
  8869. GLOBAL VARIABLES:
  8870. =============================================================================*/
  8871. void Sudo_Parameter_din_CurrentDemandRes()
  8872. {
  8873. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  8874. init_dinCurrentDemandResType(&ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes);
  8875. ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes_isUsed = 1u;
  8876. //----- [BODY (1/10)] ResponseCode -----
  8877. struct dinCurrentDemandResType *res;
  8878. res = &ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes;
  8879. res->ResponseCode = dinresponseCodeType_OK;
  8880. //----- [BODY (2/10)] DC_EVSEStatus -----
  8881. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8882. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  8883. // dinisolationLevelType_Invalid = 0,
  8884. // dinisolationLevelType_Valid = 1,
  8885. // dinisolationLevelType_Warning = 2,
  8886. // dinisolationLevelType_Fault = 3
  8887. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8888. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8889. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  8890. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8891. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8892. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8893. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8894. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8895. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  8896. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  8897. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  8898. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  8899. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  8900. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8901. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  8902. // dinEVSENotificationType_None = 0,
  8903. // dinEVSENotificationType_StopCharging = 1,
  8904. // dinEVSENotificationType_ReNegotiation = 2
  8905. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8906. res->EVSEPresentVoltage.Value = 3820;
  8907. res->EVSEPresentVoltage.Multiplier = -1;
  8908. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  8909. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  8910. //----- [BODY (4/10)] EVSEPresentCurrent -----
  8911. res->EVSEPresentCurrent.Value = 1200;
  8912. res->EVSEPresentCurrent.Multiplier = -1;
  8913. res->EVSEPresentCurrent.Unit_isUsed = 1u;
  8914. res->EVSEPresentCurrent.Unit = dinunitSymbolType_A;
  8915. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  8916. res->EVSECurrentLimitAchieved = 0;
  8917. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  8918. res->EVSEVoltageLimitAchieved = 0;
  8919. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  8920. res->EVSEPowerLimitAchieved = 0;
  8921. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  8922. res->EVSEMaximumVoltageLimit_isUsed = 1u;
  8923. res->EVSEMaximumVoltageLimit.Value = 7500;
  8924. res->EVSEMaximumVoltageLimit.Multiplier = -1;
  8925. res->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  8926. res->EVSEMaximumVoltageLimit.Unit = dinunitSymbolType_V;
  8927. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  8928. res->EVSEMaximumCurrentLimit_isUsed = 1u;
  8929. res->EVSEMaximumCurrentLimit.Value = 1200;
  8930. res->EVSEMaximumCurrentLimit.Multiplier = -1;
  8931. res->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  8932. res->EVSEMaximumCurrentLimit.Unit = dinunitSymbolType_A;
  8933. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  8934. res->EVSEMaximumPowerLimit_isUsed = 1u;
  8935. res->EVSEMaximumPowerLimit.Value = 6000;
  8936. res->EVSEMaximumPowerLimit.Multiplier = 1;
  8937. res->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  8938. res->EVSEMaximumPowerLimit.Unit = dinunitSymbolType_W;
  8939. }
  8940. /*===========================================================================
  8941. FUNCTION: Sudo_Parameter_iso1_CurrentDemandRes
  8942. DESCRIPTION:
  8943. PRE-CONDITION:
  8944. INPUT:
  8945. OUTPUT:
  8946. GLOBAL VARIABLES:
  8947. =============================================================================*/
  8948. void Sudo_Parameter_iso1_CurrentDemandRes()
  8949. {
  8950. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8951. init_iso1CurrentDemandResType(&ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes);
  8952. ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes_isUsed = 1u;
  8953. //----- [BODY (1/10)] ResponseCode -----
  8954. struct iso1CurrentDemandResType *res;
  8955. res = &ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes;
  8956. res->ResponseCode = iso1responseCodeType_OK;
  8957. //----- [BODY (2/10)] DC_EVSEStatus -----
  8958. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8959. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  8960. //iso1isolationLevelType_Invalid = 0,
  8961. //iso1isolationLevelType_Valid = 1,
  8962. //iso1isolationLevelType_Warning = 2,
  8963. //iso1isolationLevelType_Fault = 3,
  8964. //iso1isolationLevelType_No_IMD = 4
  8965. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8966. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8967. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8968. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8969. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8970. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8971. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8972. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8973. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8974. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8975. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8976. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8977. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8978. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8979. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8980. //iso1EVSENotificationType_None = 0,
  8981. //iso1EVSENotificationType_StopCharging = 1,
  8982. //iso1EVSENotificationType_ReNegotiation = 2
  8983. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8984. res->EVSEPresentVoltage.Value = 3820;
  8985. res->EVSEPresentVoltage.Multiplier = -1;
  8986. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  8987. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  8988. //----- [BODY (4/10)] EVSEPresentCurrent -----
  8989. res->EVSEPresentCurrent.Value = 1200;
  8990. res->EVSEPresentCurrent.Multiplier = -1;
  8991. //res->EVSEPresentCurrent.Unit_isUsed = 1u;
  8992. res->EVSEPresentCurrent.Unit = iso1unitSymbolType_A;
  8993. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  8994. res->EVSECurrentLimitAchieved = 0;
  8995. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  8996. res->EVSEVoltageLimitAchieved = 0;
  8997. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  8998. res->EVSEPowerLimitAchieved = 0;
  8999. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  9000. res->EVSEMaximumVoltageLimit_isUsed = 1u;
  9001. res->EVSEMaximumVoltageLimit.Value = 7500;
  9002. res->EVSEMaximumVoltageLimit.Multiplier = -1;
  9003. //res->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  9004. res->EVSEMaximumVoltageLimit.Unit = iso1unitSymbolType_V;
  9005. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  9006. res->EVSEMaximumCurrentLimit_isUsed = 1u;
  9007. res->EVSEMaximumCurrentLimit.Value = 1200;
  9008. res->EVSEMaximumCurrentLimit.Multiplier = -1;
  9009. //res->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  9010. res->EVSEMaximumCurrentLimit.Unit = iso1unitSymbolType_A;
  9011. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  9012. res->EVSEMaximumPowerLimit_isUsed = 1u;
  9013. res->EVSEMaximumPowerLimit.Value = 6000;
  9014. res->EVSEMaximumPowerLimit.Multiplier = 1;
  9015. //res->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  9016. res->EVSEMaximumPowerLimit.Unit = iso1unitSymbolType_W;
  9017. }
  9018. /*===========================================================================
  9019. FUNCTION: Sudo_Parameter_iso1_ChargingStatusRes
  9020. DESCRIPTION:
  9021. PRE-CONDITION:
  9022. INPUT:
  9023. OUTPUT:
  9024. GLOBAL VARIABLES:
  9025. =============================================================================*/
  9026. void Sudo_Parameter_iso1_ChargingStatusRes()
  9027. {
  9028. int i = 0;
  9029. struct iso1ChargingStatusResType *res;
  9030. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  9031. init_iso1ChargingStatusResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes);
  9032. res = &ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes;
  9033. ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes_isUsed = 1u;
  9034. //----- [BODY (1/10)] ResponseCode -----
  9035. res->ResponseCode = OK_ISO15118_2014;
  9036. //----- [BODY (2/10)] AC_EVSEStatus -----
  9037. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  9038. res->AC_EVSEStatus.NotificationMaxDelay = 0;
  9039. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9040. // iso1EVSENotificationType_None = 0,
  9041. // iso1EVSENotificationType_StopCharging = 1,
  9042. // iso1EVSENotificationType_ReNegotiation = 2
  9043. //----- [BODY (3/10)] EVSEMaxCurrent -----
  9044. res->EVSEMaxCurrent_isUsed = 1u;
  9045. res->EVSEMaxCurrent.Value = 32;
  9046. res->EVSEMaxCurrent.Multiplier = 0;
  9047. res->EVSEMaxCurrent.Unit = iso1unitSymbolType_A;
  9048. //----- [BODY (4/10)] SAScheduleTupleID -----
  9049. res->SAScheduleTupleID = 0;
  9050. //----- [BODY (5/10)] EVSEID -----
  9051. res->EVSEID.charactersLen = 37;
  9052. memset(res->EVSEID.characters, 0, sizeof(res->EVSEID.characters));
  9053. //sprintf(res->EVSEID.characters, CCS_AC_EVSEID);
  9054. //----- [BODY (6/10)] MeterInfo -----
  9055. res->MeterInfo_isUsed = 1u;
  9056. memset(res->MeterInfo.MeterID.characters, 0, sizeof(res->MeterInfo.MeterID.characters));
  9057. memset(res->MeterInfo.SigMeterReading.bytes, 0, sizeof(res->MeterInfo.SigMeterReading.bytes));
  9058. //[MeterInfo][1/5] MeterID
  9059. //sprintf(res->MeterInfo.MeterID , CCS_AC_METER_ID);
  9060. //[MeterInfo][2/5] SigMeterReading (optional)
  9061. //sprintf(res->MeterInfo.SigMeterReading , CCS_AC_SIG_METER_READING);
  9062. //[MeterInfo][3/5] MeterStatus (optional)
  9063. res->MeterInfo.MeterStatus = 0;
  9064. //[MeterInfo][4/5] MeterReading (optional)
  9065. res->MeterInfo.MeterReading = 12345;
  9066. //[MeterInfo][5/5] TMeter (optional)
  9067. res->MeterInfo.TMeter = 1586243587; //Unix Time Stamp format
  9068. //----- [BODY (7/10)] ReceiptRequired -----
  9069. res->ReceiptRequired_isUsed = 1u;
  9070. res->ReceiptRequired = FALSE; //optional
  9071. }
  9072. /*===========================================================================
  9073. FUNCTION: Check_EVErrorCode
  9074. DESCRIPTION:
  9075. PRE-CONDITION:
  9076. INPUT:
  9077. OUTPUT:
  9078. GLOBAL VARIABLES:
  9079. =============================================================================*/
  9080. void Check_EVErrorCode(int code)
  9081. {
  9082. if (code != NO_ERROR) //NO_ERROR = 0
  9083. {
  9084. //Asking CSU to Stop
  9085. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9086. //Update_V2G_Flow_Status(Other_Fault);
  9087. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  9088. sprintf(buf_log_evcomm,
  9089. "Stop by EV (EVErrorCode = %d (DEC))",
  9090. code);
  9091. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9092. }
  9093. }
  9094. /*===========================================================================
  9095. FUNCTION: Proc_din_CurrentDemandRes
  9096. DESCRIPTION:
  9097. PRE-CONDITION:
  9098. INPUT:
  9099. OUTPUT:
  9100. GLOBAL VARIABLES:
  9101. =============================================================================*/
  9102. int Proc_din_CurrentDemandRes(int AcceptFd)
  9103. {
  9104. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9105. //if it is not the same, the packet should be ignored.
  9106. //STEP 1: ============ Initialize ============
  9107. int i = 0;
  9108. int errn = 0;
  9109. bitstream_t v2g_tx_stream;
  9110. static struct CurrentDemandResponse_DIN70121 *cur;
  9111. static struct ChargingInfoData *sys;
  9112. static int EVSE_max_current;
  9113. int tmp = 0;
  9114. size_t pos = 0;
  9115. v2g_tx_stream.pos = &pos;
  9116. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9117. v2g_tx_stream.data = V2GTP_Tx_buf;
  9118. cur = &ShmCcsData->V2GMessage_DIN70121.CurrentDemandResponse;
  9119. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9120. cur->ResponseCode = OK_DIN70121;
  9121. //EVSE Status Code
  9122. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  9123. //[HEADER] Check Req SessionID
  9124. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  9125. {
  9126. cur->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  9127. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  9128. errn = -1;
  9129. }
  9130. //Check for SequenceError
  9131. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9132. {
  9133. cur->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  9134. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  9135. errn = -1;
  9136. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9137. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9138. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9139. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9140. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9141. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9142. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9143. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9144. }
  9145. //Check for negative EvBatteryMaxCurrent
  9146. if (sys->EvBatteryMaxCurrent < 0)
  9147. {
  9148. sprintf(buf_log_evcomm,
  9149. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  9150. sys->EvBatteryMaxCurrent);
  9151. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9152. cur->DC_EVSEStatus.EVSEStatusCode = dinresponseCodeType_FAILED_WrongChargeParameter; //16
  9153. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9154. errn = -1;
  9155. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9156. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  9157. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9158. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9159. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9160. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9161. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  9162. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  9163. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9164. }
  9165. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9166. SAVE_PhysicalValueType_DIN70121(&cur->EVSEPresentCurrent, (int) (sys->PresentChargingCurrent * 10), A_DIN70121);
  9167. SAVE_PhysicalValueType_DIN70121(&cur->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  9168. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == DISABLE
  9169. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_DIN70121);
  9170. #endif
  9171. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_DIN70121);
  9172. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_DIN70121);
  9173. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  9174. if (sys->EvBatteryMaxVoltage <= 500)
  9175. {
  9176. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumVoltageLimit, (int) (500 * 10), V_DIN70121); //500V
  9177. }
  9178. #endif
  9179. //Limit the EVTargetCurrent should be under EVSEMaximumCurrentLimit
  9180. if (sys->EvBatterytargetCurrent > sys->AvailableChargingCurrent)
  9181. {
  9182. sys->EvBatterytargetCurrent = sys->AvailableChargingCurrent;
  9183. //[To-Do] Limit is achieved flag
  9184. }
  9185. //Isolation Status
  9186. if (sys->IsolationStatus == GFD_Invalid) //0:invalid (on going)
  9187. {
  9188. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  9189. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9190. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9191. sprintf(buf_log_evcomm, "[Error][Proc_din_CurrentDemandRes]IsolationStatus = %d", sys->IsolationStatus);
  9192. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9193. Update_V2G_Flow_Status(Other_Fault);
  9194. errn = -1;
  9195. }
  9196. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  9197. {
  9198. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  9199. }
  9200. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  9201. {
  9202. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  9203. }
  9204. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  9205. {
  9206. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  9207. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9208. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9209. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_CurrentDemandRes]GFD_Fault => Emergency Shutdown");
  9210. Update_V2G_Flow_Status(Other_Fault);
  9211. errn = -1;
  9212. }
  9213. else //GFD_No_IMD or other unexpected status
  9214. {
  9215. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  9216. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9217. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9218. sprintf(buf_log_evcomm, "[Error][Proc_din_CurrentDemandRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9219. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9220. Update_V2G_Flow_Status(Other_Fault);
  9221. errn = -1;
  9222. }
  9223. //For testing with Tesla Model 3
  9224. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == ENABLE
  9225. //[CAUTION][To-Do] Decresement of Current is not implemented.
  9226. //SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumCurrentLimit, 10, A_DIN70121);
  9227. if (sys->EvBatterytargetCurrent <= 0)
  9228. {
  9229. EVSE_max_current = 50; //10A
  9230. cur->EVSEMaximumCurrentLimit.Value = 50; //10A
  9231. /*
  9232. DEBUG_PRINTF_EVCOMM_DETAIL("1PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9233. sys->PresentChargingCurrent,
  9234. sys->EvBatterytargetCurrent,
  9235. EVSE_max_current,
  9236. cur->EVSEMaximumCurrentLimit.Value
  9237. );
  9238. */
  9239. }
  9240. else //1A
  9241. {
  9242. /*
  9243. DEBUG_PRINTF_EVCOMM_DETAIL("2PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9244. sys->PresentChargingCurrent,
  9245. sys->EvBatterytargetCurrent,
  9246. EVSE_max_current,
  9247. cur->EVSEMaximumCurrentLimit.Value
  9248. );
  9249. */
  9250. if ((abs((int)sys->PresentChargingCurrent - (int)sys->EvBatterytargetCurrent) < 3)&&(abs((int)(EVSE_max_current/10) - (int)sys->EvBatterytargetCurrent) < 3))
  9251. {
  9252. tmp = EVSE_max_current + 50; //10A
  9253. if (tmp <= (int)(sys->AvailableChargingCurrent * 10))
  9254. {
  9255. cur->EVSEMaximumCurrentLimit.Value = (int)tmp;
  9256. EVSE_max_current = tmp;
  9257. }
  9258. else
  9259. {
  9260. cur->EVSEMaximumCurrentLimit.Value = (int) (sys->AvailableChargingCurrent * 10); //max is set to 40A
  9261. EVSE_max_current = (int) (sys->AvailableChargingCurrent * 10);
  9262. }
  9263. }
  9264. }
  9265. #endif
  9266. //Check for CSU command of "Stop by EVSE"
  9267. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9268. {
  9269. //Check for Alarm Code: CCS GFD trip (012235)
  9270. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9271. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9272. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9273. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9274. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9275. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9276. {
  9277. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][Error][CurrentDemandRes]CCS GFD trip => EVSE_Shutdown");
  9278. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  9279. }
  9280. else
  9281. {
  9282. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][Error][CurrentDemandRes]EVSE_Shutdown");
  9283. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9284. }
  9285. //cur->ResponseCode = FAILED_DIN70121;
  9286. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9287. //errn = -1;
  9288. }
  9289. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9290. {
  9291. //Check for Alarm Code: CCS GFD trip (012235)
  9292. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9293. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9294. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9295. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9296. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9297. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9298. {
  9299. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][Error][CurrentDemandRes]CCS GFD trip => EVSE_EmergencyShutdown");
  9300. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  9301. }
  9302. else
  9303. {
  9304. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][Error][CurrentDemandRes]EVSE_EmergencyShutdown");
  9305. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9306. }
  9307. //cur->ResponseCode = FAILED_DIN70121;
  9308. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9309. //errn = -1;
  9310. }
  9311. else if (ShmInternalComm->ChargingPermission == FALSE)
  9312. {
  9313. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][Error][CurrentDemandRes]Permission OFF");
  9314. //cur->ResponseCode = FAILED_DIN70121;
  9315. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9316. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9317. //errn = -1;
  9318. }
  9319. else
  9320. {
  9321. //null
  9322. }
  9323. //Response to CP Error
  9324. #if CP_PROTECTION_MECHANISM == ENABLE
  9325. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9326. {
  9327. cur->ResponseCode = FAILED_DIN70121;
  9328. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9329. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9330. Update_V2G_Flow_Status(Other_Fault);
  9331. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9332. //CCS_SECC_CP_State_Error (023889)
  9333. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9334. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9335. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9336. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9337. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9338. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9339. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9340. sprintf(buf_log_evcomm,
  9341. "[CurrentDemand]Emergency Stop by CP Error (%d, %.02f V)",
  9342. sys->CpState,
  9343. sys->CpVoltage);
  9344. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9345. }
  9346. #endif
  9347. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9348. #if PARAMETER_NORMAL_MODE == ENABLE
  9349. SHM_Read_din_CurrentDemandRes(&ccs_exi_doc_DIN, ShmCcsData);
  9350. #else
  9351. Sudo_Parameter_din_CurrentDemandRes();
  9352. #endif
  9353. //STEP 4: ============ Encode and Send Response Message ===========
  9354. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  9355. {
  9356. errn = -1;
  9357. }
  9358. //STEP 5: ============ Update Flags ===========
  9359. return errn;
  9360. }
  9361. /*===========================================================================
  9362. FUNCTION: Proc_iso1_CurrentDemandRes
  9363. DESCRIPTION:
  9364. PRE-CONDITION:
  9365. INPUT:
  9366. OUTPUT:
  9367. GLOBAL VARIABLES:
  9368. =============================================================================*/
  9369. int Proc_iso1_CurrentDemandRes(int AcceptFd)
  9370. {
  9371. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9372. //if it is not the same, the packet should be ignored.
  9373. //STEP 1: ============ Initialize ============
  9374. int i = 0;
  9375. int errn = 0;
  9376. bitstream_t v2g_tx_stream;
  9377. static struct CurrentDemandResponse_ISO15118_2014 *cur;
  9378. static struct ChargingInfoData *sys;
  9379. static int EVSE_max_current;
  9380. int tmp = 0;
  9381. size_t pos = 0;
  9382. v2g_tx_stream.pos = &pos;
  9383. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9384. v2g_tx_stream.data = V2GTP_Tx_buf;
  9385. cur = &ShmCcsData->V2GMessage_ISO15118_2014.CurrentDemandResponse;
  9386. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9387. cur->ResponseCode = OK_ISO15118_2014;
  9388. //EVSE Status Code
  9389. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  9390. //[HEADER] Check Req SessionID
  9391. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9392. {
  9393. cur->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9394. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  9395. errn = -1;
  9396. }
  9397. //Check for SequenceError
  9398. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9399. {
  9400. cur->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  9401. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  9402. errn = -1;
  9403. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9404. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9405. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9406. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9407. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9408. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9409. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9410. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9411. }
  9412. //Check for negative EvBatteryMaxCurrent
  9413. if (sys->EvBatteryMaxCurrent < 0)
  9414. {
  9415. sprintf(buf_log_evcomm,
  9416. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  9417. sys->EvBatteryMaxCurrent);
  9418. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9419. cur->ResponseCode = iso1responseCodeType_FAILED_WrongChargeParameter; //16
  9420. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9421. errn = -1;
  9422. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9423. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  9424. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9425. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9426. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9427. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9428. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  9429. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  9430. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9431. }
  9432. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9433. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEPresentCurrent, (int) (sys->PresentChargingCurrent * 10), A_ISO15118_2014);
  9434. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  9435. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == DISABLE
  9436. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  9437. #endif
  9438. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_ISO15118_2014);
  9439. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_ISO15118_2014);
  9440. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  9441. if (sys->EvBatteryMaxVoltage <= 500)
  9442. {
  9443. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumVoltageLimit, (int) (500 * 10), V_ISO15118_2014); //500V
  9444. }
  9445. #endif
  9446. //Limit the EVTargetCurrent should be under EVSEMaximumCurrentLimit
  9447. if (sys->EvBatterytargetCurrent > sys->AvailableChargingCurrent)
  9448. {
  9449. sys->EvBatterytargetCurrent = sys->AvailableChargingCurrent;
  9450. //[To-Do] Limit is achieved flag
  9451. }
  9452. //Isolation Status
  9453. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  9454. {
  9455. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  9456. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9457. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9458. sprintf(buf_log_evcomm, "[Error][Proc_iso1_CurrentDemandRes]IsolationStatus = %d", sys->IsolationStatus);
  9459. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9460. Update_V2G_Flow_Status(Other_Fault);
  9461. errn = -1;
  9462. }
  9463. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  9464. {
  9465. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  9466. }
  9467. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  9468. {
  9469. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning; //2
  9470. }
  9471. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  9472. {
  9473. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  9474. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9475. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9476. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_CurrentDemandRes]GFD_Fault => EmergencyShutdown");
  9477. Update_V2G_Flow_Status(Other_Fault);
  9478. errn = -1;
  9479. }
  9480. else
  9481. {
  9482. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  9483. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9484. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9485. sprintf(buf_log_evcomm, "[Error][Proc_iso1_CurrentDemandRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9486. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9487. Update_V2G_Flow_Status(Other_Fault);
  9488. errn = -1;
  9489. }
  9490. //For testing with Tesla Model 3
  9491. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == ENABLE
  9492. //[CAUTION][To-Do] Decresement of Current is not implemented.
  9493. //SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumCurrentLimit, 10, A_ISO15118_2014);
  9494. if (sys->EvBatterytargetCurrent <= 0)
  9495. {
  9496. EVSE_max_current = 50; //10A
  9497. cur->EVSEMaximumCurrentLimit.Value = 50; //10A
  9498. /*
  9499. DEBUG_PRINTF_EVCOMM_DETAIL("1PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9500. sys->PresentChargingCurrent,
  9501. sys->EvBatterytargetCurrent,
  9502. EVSE_max_current,
  9503. cur->EVSEMaximumCurrentLimit.Value
  9504. );
  9505. */
  9506. }
  9507. else //1A
  9508. {
  9509. /*
  9510. DEBUG_PRINTF_EVCOMM_DETAIL("2PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9511. sys->PresentChargingCurrent,
  9512. sys->EvBatterytargetCurrent,
  9513. EVSE_max_current,
  9514. cur->EVSEMaximumCurrentLimit.Value
  9515. );
  9516. */
  9517. if ((abs((int)sys->PresentChargingCurrent - (int)sys->EvBatterytargetCurrent) < 3)&&(abs((int)(EVSE_max_current/10) - (int)sys->EvBatterytargetCurrent) < 3))
  9518. {
  9519. tmp = EVSE_max_current + 50; //10A
  9520. if (tmp <= (int)(sys->AvailableChargingCurrent * 10))
  9521. {
  9522. cur->EVSEMaximumCurrentLimit.Value = (int)tmp;
  9523. EVSE_max_current = tmp;
  9524. }
  9525. else
  9526. {
  9527. cur->EVSEMaximumCurrentLimit.Value = (int) (sys->AvailableChargingCurrent * 10); //max is set to 40A
  9528. EVSE_max_current = (int) (sys->AvailableChargingCurrent * 10);
  9529. }
  9530. }
  9531. }
  9532. #endif
  9533. //Check for CSU command of "Stop by EVSE"
  9534. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9535. {
  9536. //Check for Alarm Code: CCS GFD trip (012235)
  9537. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9538. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9539. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9540. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9541. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9542. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9543. {
  9544. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][Error][CurrentDemandRes]CCS GFD trip => EVSE_Shutdown");
  9545. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  9546. }
  9547. else
  9548. {
  9549. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][Error][CurrentDemandRes]EVSE_Shutdown");
  9550. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9551. }
  9552. //cur->ResponseCode = FAILED_ISO15118_2014;
  9553. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9554. //errn = -1;
  9555. }
  9556. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9557. {
  9558. //Check for Alarm Code: CCS GFD trip (012235)
  9559. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9560. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9561. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9562. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9563. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9564. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9565. {
  9566. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][Error][CurrentDemandRes]CCS GFD trip => EVSE_EmergencyShutdown");
  9567. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  9568. }
  9569. else
  9570. {
  9571. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][Error][CurrentDemandRes]EVSE_EmergencyShutdown");
  9572. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9573. }
  9574. //cur->ResponseCode = FAILED_ISO15118_2014;
  9575. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9576. //errn = -1;
  9577. }
  9578. else if (ShmInternalComm->ChargingPermission == FALSE)
  9579. {
  9580. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][Error][CurrentDemandRes]Permission OFF");
  9581. //cur->ResponseCode = FAILED_ISO15118_2014;
  9582. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9583. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9584. //errn = -1;
  9585. }
  9586. else
  9587. {
  9588. //null
  9589. }
  9590. //Response to CP Error
  9591. #if CP_PROTECTION_MECHANISM == ENABLE
  9592. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9593. {
  9594. cur->ResponseCode = FAILED_ISO15118_2014;
  9595. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9596. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9597. Update_V2G_Flow_Status(Other_Fault);
  9598. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9599. //CCS_SECC_CP_State_Error (023889)
  9600. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9601. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9602. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9603. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9604. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9605. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9606. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9607. sprintf(buf_log_evcomm,
  9608. "[CurrentDemand]Emergency Stop by CP Error (%d, %.02f V)",
  9609. sys->CpState,
  9610. sys->CpVoltage);
  9611. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9612. }
  9613. #endif
  9614. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9615. #if PARAMETER_NORMAL_MODE == ENABLE
  9616. SHM_Read_iso1_CurrentDemandRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9617. #else
  9618. Sudo_Parameter_iso1_CurrentDemandRes();
  9619. #endif
  9620. //STEP 4: ============ Encode and Send Response Message ===========
  9621. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9622. {
  9623. errn = -1;
  9624. }
  9625. //STEP 5: ============ Update Flags ===========
  9626. return errn;
  9627. }
  9628. /*===========================================================================
  9629. FUNCTION: Proc_iso1_ChargingStatusRes
  9630. DESCRIPTION:
  9631. PRE-CONDITION:
  9632. INPUT:
  9633. OUTPUT:
  9634. GLOBAL VARIABLES:
  9635. =============================================================================*/
  9636. int Proc_iso1_ChargingStatusRes(int AcceptFd)
  9637. {
  9638. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9639. //if it is not the same, the packet should be ignored.
  9640. //STEP 1: ============ Initialize ============
  9641. int i = 0;
  9642. int errn = 0;
  9643. bitstream_t v2g_tx_stream;
  9644. static struct ChargingStatusResponse_ISO15118_2014 *res;
  9645. static struct ChargingInfoData *sys;
  9646. size_t pos = 0;
  9647. v2g_tx_stream.pos = &pos;
  9648. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9649. v2g_tx_stream.data = V2GTP_Tx_buf;
  9650. res = &ShmCcsData->V2GMessage_ISO15118_2014.ChargingStatusResponse;
  9651. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9652. //Init
  9653. res->ResponseCode = OK_ISO15118_2014;
  9654. res->ReceiptRequired = FALSE; //optional
  9655. res->SAScheduleTupleID = 0;
  9656. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  9657. res->AC_EVSEStatus.NotificationMaxDelay = 0;
  9658. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9659. // iso1EVSENotificationType_None = 0,
  9660. // iso1EVSENotificationType_StopCharging = 1,
  9661. // iso1EVSENotificationType_ReNegotiation = 2
  9662. //[HEADER] Check Req SessionID
  9663. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9664. {
  9665. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9666. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  9667. errn = -1;
  9668. }
  9669. //Check for SequenceError
  9670. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9671. {
  9672. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  9673. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  9674. errn = -1;
  9675. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9676. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9677. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9678. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9679. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9680. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9681. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9682. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9683. }
  9684. //EVSE ID
  9685. memset(res->EVSEID, 0, sizeof(res->EVSEID));
  9686. //sprintf(res->EVSEID, CCS_AC_EVSEID);
  9687. //[MeterInfo][0/5] init
  9688. //memset(res->MeterInfo.MeterID.characters, 0, sizeof(res->MeterInfo.MeterID.characters));
  9689. //memset(res->MeterInfo.SigMeterReading.bytes, 0, sizeof(res->MeterInfo.SigMeterReading.bytes));
  9690. //[MeterInfo][1/5] MeterID
  9691. //sprintf(res->MeterInfo.MeterID , CCS_AC_METER_ID);
  9692. //[MeterInfo][2/5] SigMeterReading (optional)
  9693. //sprintf(res->MeterInfo.SigMeterReading , CCS_AC_SIG_METER_READING);
  9694. //[MeterInfo][3/5] MeterStatus (optional)
  9695. res->MeterInfo.MeterStatus = 0;
  9696. //[MeterInfo][4/5] MeterReading (optional)
  9697. res->MeterInfo.MeterReading = 12345;
  9698. //[MeterInfo][5/5] TMeter (optional)
  9699. res->MeterInfo.TMeter = 1586243587; //Unix Time Stamp format
  9700. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9701. SAVE_PhysicalValueType_ISO15118_2014(&res->EVSEMaxCurrent, (int)(sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  9702. //Isolation Status (RCD)
  9703. if (sys->IsolationStatus == 0) //Isolation is invalid
  9704. {
  9705. res->AC_EVSEStatus.RCD = TRUE; //FALSE(no error), TRUE(error is detected)
  9706. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9707. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9708. sprintf(buf_log_evcomm, "[ISO1][Error][ChargingStatusRes]IsolationStatus = %d", sys->IsolationStatus);
  9709. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9710. Update_V2G_Flow_Status(Other_Fault);
  9711. errn = -1;
  9712. }
  9713. else if (sys->IsolationStatus == 1) //Isolation is valid
  9714. {
  9715. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  9716. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9717. }
  9718. else
  9719. {
  9720. res->AC_EVSEStatus.RCD = TRUE; //FALSE(no error), TRUE(error is detected)
  9721. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9722. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9723. sprintf(buf_log_evcomm, "[ISO1][Error][ChargingStatusRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9724. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9725. Update_V2G_Flow_Status(Other_Fault);
  9726. errn = -1;
  9727. }
  9728. //Check for CSU command of "Stop by EVSE"
  9729. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9730. {
  9731. //res->ResponseCode = FAILED_ISO15118_2014;
  9732. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9733. //errn = -1;
  9734. }
  9735. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9736. {
  9737. //res->ResponseCode = FAILED_ISO15118_2014;
  9738. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9739. //errn = -1;
  9740. }
  9741. else if (ShmInternalComm->ChargingPermission == FALSE)
  9742. {
  9743. //res->ResponseCode = FAILED_ISO15118_2014;
  9744. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9745. //errn = -1;
  9746. }
  9747. //Response to CP Error
  9748. #if CP_PROTECTION_MECHANISM == ENABLE
  9749. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9750. {
  9751. res->ResponseCode = FAILED_ISO15118_2014;
  9752. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9753. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9754. Update_V2G_Flow_Status(Other_Fault);
  9755. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9756. //CCS_SECC_CP_State_Error (023889)
  9757. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9758. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9759. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9760. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9761. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9762. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9763. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9764. sprintf(buf_log_evcomm,
  9765. "[ChargingStatus]Emergency Stop by CP Error (%d, %.02f V)",
  9766. sys->CpState,
  9767. sys->CpVoltage);
  9768. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9769. }
  9770. #endif
  9771. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9772. #if PARAMETER_NORMAL_MODE == ENABLE
  9773. SHM_Read_iso1_ChargingStatusRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9774. #else
  9775. Sudo_Parameter_iso1_ChargingStatusRes();
  9776. #endif
  9777. //STEP 4: ============ Encode and Send Response Message ===========
  9778. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9779. {
  9780. errn = -1;
  9781. }
  9782. //STEP 5: ============ Update Flags ===========
  9783. return errn;
  9784. }
  9785. /*===========================================================================
  9786. FUNCTION: Proc_din_CurrentDemandReq
  9787. DESCRIPTION:
  9788. PRE-CONDITION:
  9789. INPUT:
  9790. OUTPUT:
  9791. GLOBAL VARIABLES:
  9792. =============================================================================*/
  9793. int Proc_din_CurrentDemandReq(int AcceptFd)
  9794. {
  9795. int errn = 0;
  9796. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_CurrentDemandReq] Got CurrentDemandReq\n");
  9797. //Print the decoded XML Document
  9798. PRINT_XML_DOC_DIN_CurrentDemandReq(&ccs_exi_doc_DIN);
  9799. //Save into Share Memory
  9800. SHM_Save_din_CurrentDemandReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  9801. //Check for EV Error Code
  9802. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.CurrentDemandRequest.DC_EVStatus.EVErrorCode);
  9803. errn = Proc_din_CurrentDemandRes(AcceptFd);
  9804. if (errn == 0)
  9805. {
  9806. //Response is sent successfully.
  9807. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]CurrentDemandRes");
  9808. }
  9809. else
  9810. {
  9811. sprintf(buf_log_evcomm,
  9812. "[DIN][Error][CurrentDemandReq]CurrentDemandRes: fail(%d,DEC)",
  9813. errn);
  9814. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9815. }
  9816. return errn;
  9817. }
  9818. /*===========================================================================
  9819. FUNCTION: Proc_iso1_CurrentDemandReq
  9820. DESCRIPTION:
  9821. PRE-CONDITION:
  9822. INPUT:
  9823. OUTPUT:
  9824. GLOBAL VARIABLES:
  9825. =============================================================================*/
  9826. int Proc_iso1_CurrentDemandReq(int AcceptFd)
  9827. {
  9828. int errn = 0;
  9829. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_CurrentDemandReq] Got CurrentDemandReq\n");
  9830. //Print the decoded XML Document
  9831. PRINT_XML_DOC_ISO1_CurrentDemandReq(&ccs_exi_doc_ISO1);
  9832. //Save into Share Memory
  9833. SHM_Save_iso1_CurrentDemandReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9834. //Check for EV Error Code
  9835. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.CurrentDemandRequest.DC_EVStatus.EVErrorCode);
  9836. errn = Proc_iso1_CurrentDemandRes(AcceptFd);
  9837. if (errn == 0)
  9838. {
  9839. //Response is sent successfully.
  9840. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]CurrentDemandRes");
  9841. }
  9842. else
  9843. {
  9844. sprintf(buf_log_evcomm,
  9845. "[ISO1][Error][CurrentDemandReq]CurrentDemandRes: fail(%d,DEC)",
  9846. errn);
  9847. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9848. }
  9849. return errn;
  9850. }
  9851. /*===========================================================================
  9852. FUNCTION: Proc_iso1_ChargingStatusReq
  9853. DESCRIPTION:
  9854. PRE-CONDITION:
  9855. INPUT:
  9856. OUTPUT:
  9857. GLOBAL VARIABLES:
  9858. =============================================================================*/
  9859. int Proc_iso1_ChargingStatusReq(int AcceptFd)
  9860. {
  9861. int errn = 0;
  9862. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ChargingStatusReq] Got ChargingStatusReq\n");
  9863. //Print the decoded XML Document
  9864. PRINT_XML_DOC_ISO1_ChargingStatusReq(&ccs_exi_doc_ISO1);
  9865. //Save into Share Memory
  9866. SHM_Save_iso1_ChargingStatusReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9867. //Check for EV Error Code
  9868. //no content in ISO1
  9869. errn = Proc_iso1_ChargingStatusRes(AcceptFd);
  9870. if (errn == 0)
  9871. {
  9872. //Response is sent successfully.
  9873. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]ChargingStatusRes");
  9874. }
  9875. else
  9876. {
  9877. sprintf(buf_log_evcomm,
  9878. "[ISO1][Error][ChargingStatusReq]ChargingStatusRes: fail(%d,DEC)",
  9879. errn);
  9880. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  9881. }
  9882. return errn;
  9883. }
  9884. /*===========================================================================
  9885. FUNCTION: Proc_din_PowerDeliveryStopRes
  9886. DESCRIPTION:
  9887. PRE-CONDITION:
  9888. INPUT:
  9889. OUTPUT:
  9890. GLOBAL VARIABLES:
  9891. =============================================================================*/
  9892. int Proc_din_PowerDeliveryStopRes(int AcceptFd)
  9893. {
  9894. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9895. //if it is not the same, the packet should be ignored.
  9896. //STEP 1: ============ Initialize ============
  9897. int i = 0;
  9898. int errn = 0;
  9899. bitstream_t v2g_tx_stream;
  9900. struct dinPowerDeliveryResType *res;
  9901. struct ChargingInfoData *sys;
  9902. size_t pos = 0;
  9903. v2g_tx_stream.pos = &pos;
  9904. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9905. v2g_tx_stream.data = V2GTP_Tx_buf;
  9906. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  9907. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9908. res->ResponseCode = OK_DIN70121;
  9909. //[HEADER] Check Req SessionID
  9910. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  9911. {
  9912. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  9913. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  9914. errn = -1;
  9915. }
  9916. //Check for SequenceError
  9917. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9918. {
  9919. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  9920. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  9921. errn = -1;
  9922. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9923. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9924. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9925. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9926. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9927. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9928. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9929. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9930. }
  9931. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9932. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9933. #if PARAMETER_NORMAL_MODE == ENABLE
  9934. ShmCcsData->V2GMessage_DIN70121.PowerDeliveryResponse.DC_EVSEStatus.EVSEStatusCode = EVSE_NotReady;
  9935. SHM_Read_din_PowerDeliveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  9936. #else
  9937. Sudo_Parameter_din_PreChargeRes();
  9938. #endif
  9939. //EVSE Status Code
  9940. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  9941. //Check for CSU command of "Stop by EVSE"
  9942. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9943. {
  9944. //res->ResponseCode = FAILED_DIN70121;
  9945. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9946. }
  9947. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9948. {
  9949. //res->ResponseCode = FAILED_DIN70121;
  9950. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9951. }
  9952. else if (ShmInternalComm->ChargingPermission == FALSE)
  9953. {
  9954. //res->ResponseCode = FAILED_DIN70121;
  9955. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9956. }
  9957. //STEP 4: ============ Encode and Send Response Message ===========
  9958. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  9959. {
  9960. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_PowerDeliveryStopRes][Error]Tx encoded msg error");
  9961. errn = -1;
  9962. }
  9963. //STEP 5: ============ Update Flags ===========
  9964. return errn;
  9965. }
  9966. /*===========================================================================
  9967. FUNCTION: Proc_iso1_PowerDeliveryStopRes
  9968. DESCRIPTION:
  9969. PRE-CONDITION:
  9970. INPUT:
  9971. OUTPUT:
  9972. GLOBAL VARIABLES:
  9973. =============================================================================*/
  9974. int Proc_iso1_PowerDeliveryStopRes(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. struct iso1PowerDeliveryResType *res;
  9983. struct ChargingInfoData *sys;
  9984. size_t pos = 0;
  9985. v2g_tx_stream.pos = &pos;
  9986. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9987. v2g_tx_stream.data = V2GTP_Tx_buf;
  9988. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  9989. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9990. res->ResponseCode = OK_ISO15118_2014;
  9991. //[HEADER] Check Req SessionID
  9992. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9993. {
  9994. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9995. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  9996. errn = -1;
  9997. }
  9998. //Check for SequenceError
  9999. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10000. {
  10001. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10002. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  10003. errn = -1;
  10004. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10005. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10006. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10007. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10008. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10009. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10010. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10011. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10012. }
  10013. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10014. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10015. #if PARAMETER_NORMAL_MODE == ENABLE
  10016. ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryResponse.DC_EVSEStatus.DC_EVSEStatusCode = EVSE_NotReady;
  10017. SHM_Read_iso1_PowerDeliveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10018. #else
  10019. Sudo_Parameter_iso1_PreChargeRes();
  10020. #endif
  10021. //EVSE Status Code
  10022. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10023. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1 /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  10024. //Check for CSU command of "Stop by EVSE"
  10025. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10026. {
  10027. //res->ResponseCode = FAILED_ISO15118_2014;
  10028. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  10029. }
  10030. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10031. {
  10032. //res->ResponseCode = FAILED_ISO15118_2014;
  10033. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10034. }
  10035. else if (ShmInternalComm->ChargingPermission == FALSE)
  10036. {
  10037. //res->ResponseCode = FAILED_ISO15118_2014;
  10038. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  10039. }
  10040. //STEP 4: ============ Encode and Send Response Message ===========
  10041. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10042. {
  10043. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_PowerDeliveryStopRes][Error]Tx encoded msg error");
  10044. errn = -1;
  10045. }
  10046. //STEP 5: ============ Update Flags ===========
  10047. return errn;
  10048. }
  10049. /*===========================================================================
  10050. FUNCTION: Proc_din_PowerDeliveryStopReq
  10051. DESCRIPTION:
  10052. PRE-CONDITION:
  10053. INPUT:
  10054. OUTPUT:
  10055. GLOBAL VARIABLES:
  10056. =============================================================================*/
  10057. int Proc_din_PowerDeliveryStopReq(int AcceptFd)
  10058. {
  10059. int errn = 0;
  10060. //Request CSU to STOP
  10061. //This should be reponsed as soon as possible once this message is received.
  10062. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10063. EVCOMM_SYS_INFO.EvBatterytargetVoltage = 0;
  10064. EVCOMM_SYS_INFO.EvBatterytargetCurrent = 0;
  10065. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PowerDeliveryReq (2nd)\n");
  10066. //Print the decoded XML Document
  10067. PRINT_XML_DOC_DIN_PowerDeliveryReq(&ccs_exi_doc_DIN);
  10068. //Save into Share Memory
  10069. SHM_Save_din_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10070. //Check for EV Error Code
  10071. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  10072. //[To-Do] Sending response after the EVSE output voltage decreases to under 60V
  10073. usleep(1500000); //1.5 seconds
  10074. //sleep(1); //1 second
  10075. errn = Proc_din_PowerDeliveryStopRes(AcceptFd);
  10076. if (errn == 0)
  10077. {
  10078. //send response successfully.
  10079. SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]PowerDeliveryRes (2nd)\n");
  10080. }
  10081. else
  10082. {
  10083. sprintf(buf_log_evcomm,
  10084. "[Error][SeccComm][Proc_din_PowerDeliveryStopReq]Proc_iso1_PowerDeliveryStopRes(): %d (DEC)",
  10085. errn);
  10086. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10087. }
  10088. return errn;
  10089. }
  10090. /*===========================================================================
  10091. FUNCTION: Proc_iso1_PowerDeliveryStopReq
  10092. DESCRIPTION:
  10093. PRE-CONDITION:
  10094. INPUT:
  10095. OUTPUT:
  10096. GLOBAL VARIABLES:
  10097. =============================================================================*/
  10098. int Proc_iso1_PowerDeliveryStopReq(int AcceptFd)
  10099. {
  10100. int errn = 0;
  10101. //Request CSU to STOP
  10102. //This should be reponsed as soon as possible once this message is received.
  10103. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10104. EVCOMM_SYS_INFO.EvBatterytargetVoltage = 0;
  10105. EVCOMM_SYS_INFO.EvBatterytargetCurrent = 0;
  10106. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PowerDeliveryReq (2nd)\n");
  10107. //Print the decoded XML Document
  10108. PRINT_XML_DOC_ISO1_PowerDeliveryReq(&ccs_exi_doc_ISO1);
  10109. //Save into Share Memory
  10110. SHM_Save_iso1_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10111. //Check for EV Error Code
  10112. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  10113. //[To-Do] Sending response after the EVSE output voltage decreases to under 60V
  10114. usleep(1500000); //1.5 seconds
  10115. //sleep(1); //1 second
  10116. errn = Proc_iso1_PowerDeliveryStopRes(AcceptFd);
  10117. if (errn == 0)
  10118. {
  10119. //send response successfully.
  10120. SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]PowerDeliveryRes (2nd)");
  10121. }
  10122. else
  10123. {
  10124. sprintf(buf_log_evcomm,
  10125. "[Error][SeccComm][Proc_iso1_PowerDeliveryStopReq]Proc_iso1_PowerDeliveryStopRes(): %d (DEC)",
  10126. errn);
  10127. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10128. }
  10129. return errn;
  10130. }
  10131. /*===========================================================================
  10132. FUNCTION: SHM_Init_din_WeldingDetectionRes
  10133. DESCRIPTION:
  10134. PRE-CONDITION:
  10135. INPUT:
  10136. 1. shm_ccs
  10137. OUTPUT:
  10138. 1. shm_ccs
  10139. GLOBAL VARIABLES:
  10140. =============================================================================*/
  10141. void SHM_Init_din_WeldingDetectionRes(struct CcsData *shm_ccs)
  10142. {
  10143. struct WeldingDetectionResponse_DIN70121 *in;
  10144. in = &shm_ccs->V2GMessage_DIN70121.WeldingDetectionResponse;
  10145. //----- [BODY (1/3)] ResponseCode -----
  10146. in->ResponseCode = dinresponseCodeType_OK;
  10147. //----- [BODY (2/3)] EVSEPresentVoltage -----
  10148. short value = 0; int multiplier = 0; unsigned char unit = 0;
  10149. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for test only.
  10150. value = 0; multiplier = 0; unit = V_DIN70121;
  10151. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  10152. //----- [BODY (3/3)] DC_EVSEStatus -----
  10153. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  10154. }
  10155. /*===========================================================================
  10156. FUNCTION: Sudo_Parameter_din_WeldingDetectionRes
  10157. DESCRIPTION:
  10158. PRE-CONDITION:
  10159. INPUT:
  10160. OUTPUT:
  10161. GLOBAL VARIABLES:
  10162. =============================================================================*/
  10163. void Sudo_Parameter_din_WeldingDetectionRes()
  10164. {
  10165. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  10166. init_dinWeldingDetectionResType(&ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes);
  10167. ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes_isUsed = 1u;
  10168. //----- [BODY (1/3)] ResponseCode -----
  10169. struct dinWeldingDetectionResType *res;
  10170. res = &ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes;
  10171. res->ResponseCode = dinresponseCodeType_OK;
  10172. //----- [BODY (2/3)] EVSEPresentVoltage -----
  10173. res->EVSEPresentVoltage.Value = 3820;
  10174. res->EVSEPresentVoltage.Multiplier = -1;
  10175. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  10176. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  10177. // dinunitSymbolType_h = 0,
  10178. // dinunitSymbolType_m = 1,
  10179. // dinunitSymbolType_s = 2,
  10180. // dinunitSymbolType_A = 3,
  10181. // dinunitSymbolType_Ah = 4,
  10182. // dinunitSymbolType_V = 5,
  10183. // dinunitSymbolType_VA = 6,
  10184. // dinunitSymbolType_W = 7,
  10185. // dinunitSymbolType_W_s = 8,
  10186. // dinunitSymbolType_Wh = 9
  10187. //----- [BODY (3/3)] DC_EVSEStatus -----
  10188. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  10189. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  10190. // dinisolationLevelType_Invalid = 0,
  10191. // dinisolationLevelType_Valid = 1,
  10192. // dinisolationLevelType_Warning = 2,
  10193. // dinisolationLevelType_Fault = 3
  10194. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  10195. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  10196. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  10197. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  10198. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  10199. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  10200. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  10201. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  10202. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  10203. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  10204. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  10205. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  10206. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  10207. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  10208. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  10209. // dinEVSENotificationType_None = 0,
  10210. // dinEVSENotificationType_StopCharging = 1,
  10211. // dinEVSENotificationType_ReNegotiation = 2
  10212. }
  10213. /*===========================================================================
  10214. FUNCTION: Sudo_Parameter_iso1_WeldingDetectionRes
  10215. DESCRIPTION:
  10216. PRE-CONDITION:
  10217. INPUT:
  10218. OUTPUT:
  10219. GLOBAL VARIABLES:
  10220. =============================================================================*/
  10221. void Sudo_Parameter_iso1_WeldingDetectionRes()
  10222. {
  10223. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  10224. init_iso1WeldingDetectionResType(&ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes);
  10225. ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes_isUsed = 1u;
  10226. //----- [BODY (1/3)] ResponseCode -----
  10227. struct iso1WeldingDetectionResType *res;
  10228. res = &ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes;
  10229. res->ResponseCode = iso1responseCodeType_OK;
  10230. //----- [BODY (2/3)] EVSEPresentVoltage -----
  10231. res->EVSEPresentVoltage.Value = 3820;
  10232. res->EVSEPresentVoltage.Multiplier = -1;
  10233. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  10234. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  10235. //iso1unitSymbolType_h = 0,
  10236. //iso1unitSymbolType_m = 1,
  10237. //iso1unitSymbolType_s = 2,
  10238. //iso1unitSymbolType_A = 3,
  10239. //iso1unitSymbolType_V = 4,
  10240. //iso1unitSymbolType_W = 5,
  10241. //iso1unitSymbolType_Wh = 6
  10242. //----- [BODY (3/3)] DC_EVSEStatus -----
  10243. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  10244. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  10245. //iso1isolationLevelType_Invalid = 0,
  10246. //iso1isolationLevelType_Valid = 1,
  10247. //iso1isolationLevelType_Warning = 2,
  10248. //iso1isolationLevelType_Fault = 3,
  10249. //iso1isolationLevelType_No_IMD = 4
  10250. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10251. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  10252. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  10253. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  10254. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  10255. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  10256. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  10257. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  10258. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  10259. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  10260. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  10261. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  10262. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  10263. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  10264. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  10265. //iso1EVSENotificationType_None = 0,
  10266. //iso1EVSENotificationType_StopCharging = 1,
  10267. //iso1EVSENotificationType_ReNegotiation = 2
  10268. }
  10269. /*===========================================================================
  10270. FUNCTION: Proc_din_WeldingDetectionRes
  10271. DESCRIPTION:
  10272. PRE-CONDITION:
  10273. INPUT:
  10274. OUTPUT:
  10275. GLOBAL VARIABLES:
  10276. =============================================================================*/
  10277. int Proc_din_WeldingDetectionRes(int AcceptFd)
  10278. {
  10279. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10280. //if it is not the same, the packet should be ignored.
  10281. //STEP 1: ============ Initialize ============
  10282. int i = 0;
  10283. int errn = 0;
  10284. bitstream_t v2g_tx_stream;
  10285. static struct WeldingDetectionResponse_DIN70121 *wel;
  10286. static struct ChargingInfoData *sys;
  10287. size_t pos = 0;
  10288. v2g_tx_stream.pos = &pos;
  10289. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10290. v2g_tx_stream.data = V2GTP_Tx_buf;
  10291. wel = &ShmCcsData->V2GMessage_DIN70121.WeldingDetectionResponse;
  10292. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10293. wel->ResponseCode = OK_DIN70121;
  10294. //[HEADER] Check Req SessionID
  10295. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  10296. {
  10297. wel->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  10298. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  10299. errn = -1;
  10300. }
  10301. //Check for SequenceError
  10302. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10303. {
  10304. wel->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  10305. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  10306. errn = -1;
  10307. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10308. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10309. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10310. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10311. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10312. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10313. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10314. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10315. }
  10316. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10317. SAVE_PhysicalValueType_DIN70121(&wel->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  10318. //EVSE Status Code
  10319. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  10320. //Check for CSU command of "Stop by EVSE"
  10321. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10322. {
  10323. //wel->ResponseCode = FAILED_DIN70121;
  10324. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10325. }
  10326. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10327. {
  10328. //wel->ResponseCode = FAILED_DIN70121;
  10329. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10330. }
  10331. else if (ShmInternalComm->ChargingPermission == FALSE)
  10332. {
  10333. //wel->ResponseCode = FAILED_DIN70121;
  10334. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10335. }
  10336. //Isolation Status
  10337. if (sys->IsolationStatus == GFD_Invalid) //0:invalid (on going)
  10338. {
  10339. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  10340. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10341. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10342. sprintf(buf_log_evcomm, "[Error][Proc_din_WeldingDetectionRes]IsolationStatus = %d", sys->IsolationStatus);
  10343. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10344. Update_V2G_Flow_Status(Other_Fault);
  10345. errn = -1;
  10346. }
  10347. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  10348. {
  10349. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  10350. }
  10351. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  10352. {
  10353. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  10354. }
  10355. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  10356. {
  10357. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  10358. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10359. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10360. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_din_WeldingDetectionRes]GFD_Fault => Emergency Shutdown");
  10361. Update_V2G_Flow_Status(Other_Fault);
  10362. errn = -1;
  10363. }
  10364. else //GFD_No_IMD or other unexpected status
  10365. {
  10366. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  10367. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10368. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10369. sprintf(buf_log_evcomm, "[Error][Proc_din_WeldingDetectionRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  10370. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10371. Update_V2G_Flow_Status(Other_Fault);
  10372. errn = -1;
  10373. }
  10374. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10375. #if PARAMETER_NORMAL_MODE == ENABLE
  10376. SHM_Read_din_WeldingDetectionRes(&ccs_exi_doc_DIN, ShmCcsData);
  10377. #else
  10378. Sudo_Parameter_din_WeldingDetectionRes();
  10379. #endif
  10380. //STEP 4: ============ Encode and Send Response Message ===========
  10381. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  10382. {
  10383. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_WeldingDetectionRes][Error]Tx encoded msg error");
  10384. errn = -1;
  10385. }
  10386. //STEP 5: ============ Update Flags ===========
  10387. return errn;
  10388. }
  10389. /*===========================================================================
  10390. FUNCTION: Proc_iso1_WeldingDetectionRes
  10391. DESCRIPTION:
  10392. PRE-CONDITION:
  10393. INPUT:
  10394. OUTPUT:
  10395. GLOBAL VARIABLES:
  10396. =============================================================================*/
  10397. int Proc_iso1_WeldingDetectionRes(int AcceptFd)
  10398. {
  10399. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10400. //if it is not the same, the packet should be ignored.
  10401. //STEP 1: ============ Initialize ============
  10402. int i = 0;
  10403. int errn = 0;
  10404. bitstream_t v2g_tx_stream;
  10405. static struct WeldingDetectionResponse_ISO15118_2014 *wel;
  10406. static struct ChargingInfoData *sys;
  10407. size_t pos = 0;
  10408. v2g_tx_stream.pos = &pos;
  10409. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10410. v2g_tx_stream.data = V2GTP_Tx_buf;
  10411. wel = &ShmCcsData->V2GMessage_ISO15118_2014.WeldingDetectionResponse;
  10412. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10413. wel->ResponseCode = OK_ISO15118_2014;
  10414. //[HEADER] Check Req SessionID
  10415. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10416. {
  10417. wel->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10418. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  10419. errn = -1;
  10420. }
  10421. //Check for SequenceError
  10422. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10423. {
  10424. wel->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10425. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  10426. errn = -1;
  10427. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10428. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10429. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10430. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10431. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10432. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10433. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10434. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10435. }
  10436. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10437. SAVE_PhysicalValueType_ISO15118_2014(&wel->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  10438. //EVSE Status Code
  10439. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10440. //Check for CSU command of "Stop by EVSE"
  10441. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10442. {
  10443. //wel->ResponseCode = FAILED_ISO15118_2014;
  10444. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10445. }
  10446. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10447. {
  10448. //wel->ResponseCode = FAILED_ISO15118_2014;
  10449. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10450. }
  10451. else if (ShmInternalComm->ChargingPermission == FALSE)
  10452. {
  10453. //wel->ResponseCode = FAILED_ISO15118_2014;
  10454. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10455. }
  10456. //Isolation Status
  10457. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  10458. {
  10459. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  10460. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10461. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10462. sprintf(buf_log_evcomm, "[Error][Proc_iso1_WeldingDetectionRes]IsolationStatus = %d", sys->IsolationStatus);
  10463. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10464. Update_V2G_Flow_Status(Other_Fault);
  10465. errn = -1;
  10466. }
  10467. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  10468. {
  10469. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  10470. }
  10471. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  10472. {
  10473. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  10474. }
  10475. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  10476. {
  10477. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  10478. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10479. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10480. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_WeldingDetectionRes]GFD_Fault => EmergencyShutdown");
  10481. Update_V2G_Flow_Status(Other_Fault);
  10482. errn = -1;
  10483. }
  10484. else
  10485. {
  10486. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  10487. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10488. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10489. sprintf(buf_log_evcomm, "[Error][Proc_iso1_WeldingDetectionRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  10490. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10491. Update_V2G_Flow_Status(Other_Fault);
  10492. errn = -1;
  10493. }
  10494. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10495. #if PARAMETER_NORMAL_MODE == ENABLE
  10496. SHM_Read_iso1_WeldingDetectionRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10497. #else
  10498. Sudo_Parameter_iso1_WeldingDetectionRes();
  10499. #endif
  10500. //STEP 4: ============ Encode and Send Response Message ===========
  10501. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10502. {
  10503. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_WeldingDetectionRes][Error]Tx encoded msg error");
  10504. errn = -1;
  10505. }
  10506. //STEP 5: ============ Update Flags ===========
  10507. return errn;
  10508. }
  10509. /*===========================================================================
  10510. FUNCTION: Proc_din_WeldingDetectionReq
  10511. DESCRIPTION:
  10512. PRE-CONDITION:
  10513. INPUT:
  10514. OUTPUT:
  10515. GLOBAL VARIABLES:
  10516. =============================================================================*/
  10517. int Proc_din_WeldingDetectionReq(int AcceptFd)
  10518. {
  10519. int errn = 0;
  10520. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_WeldingDetectionReq] Got WeldingDetectionReq\n");
  10521. //Print the decoded XML Document
  10522. PRINT_XML_DOC_DIN_WeldingDetectionReq(&ccs_exi_doc_DIN);
  10523. //Save into Share Memory
  10524. SHM_Save_din_WeldingDetectionReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10525. //Check for EV Error Code
  10526. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.WeldingDetectionRequest.DC_EVStatus.EVErrorCode);
  10527. errn = Proc_din_WeldingDetectionRes(AcceptFd);
  10528. if (errn == 0)
  10529. {
  10530. //send response successfully.
  10531. //SAVE_SYS_LOG_MSG_EVCOMM("[DIN][V2G][Tx]WeldingDetectionRes");
  10532. }
  10533. else
  10534. {
  10535. sprintf(buf_log_evcomm,
  10536. "[Error][SeccComm][Proc_din_WeldingDetectionReq]Proc_din_WeldingDetectionRes(): %d (DEC)",
  10537. errn);
  10538. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10539. }
  10540. return errn;
  10541. }
  10542. /*===========================================================================
  10543. FUNCTION: Proc_iso1_WeldingDetectionReq
  10544. DESCRIPTION:
  10545. PRE-CONDITION:
  10546. INPUT:
  10547. OUTPUT:
  10548. GLOBAL VARIABLES:
  10549. =============================================================================*/
  10550. int Proc_iso1_WeldingDetectionReq(int AcceptFd)
  10551. {
  10552. int errn = 0;
  10553. //SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_WeldingDetectionReq] Got WeldingDetectionReq\n");
  10554. //Print the decoded XML Document
  10555. PRINT_XML_DOC_ISO1_WeldingDetectionReq(&ccs_exi_doc_ISO1);
  10556. //Save into Share Memory
  10557. SHM_Save_iso1_WeldingDetectionReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10558. //Check for EV Error Code
  10559. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.WeldingDetectionRequest.DC_EVStatus.EVErrorCode);
  10560. errn = Proc_iso1_WeldingDetectionRes(AcceptFd);
  10561. if (errn == 0)
  10562. {
  10563. //send response successfully.
  10564. //SAVE_SYS_LOG_MSG_EVCOMM("[ISO1][V2G][Tx]WeldingDetectionRes");
  10565. }
  10566. else
  10567. {
  10568. sprintf(buf_log_evcomm,
  10569. "[Error][SeccComm][Proc_iso1_WeldingDetectionReq]Proc_iso1_WeldingDetectionRes(): %d (DEC)",
  10570. errn);
  10571. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10572. }
  10573. return errn;
  10574. }
  10575. /*===========================================================================
  10576. FUNCTION: SHM_Init_din_SessionStopRes
  10577. DESCRIPTION:
  10578. PRE-CONDITION:
  10579. INPUT:
  10580. 1. shm_ccs
  10581. OUTPUT:
  10582. 1. shm_ccs
  10583. GLOBAL VARIABLES:
  10584. =============================================================================*/
  10585. void SHM_Init_din_SessionStopRes(struct CcsData *shm_ccs)
  10586. {
  10587. struct SessionStopResponse_DIN70121 *in;
  10588. in = &shm_ccs->V2GMessage_DIN70121.SessionStopResponse;
  10589. //----- [BODY (1/3)] ResponseCode -----
  10590. in->ResponseCode = dinresponseCodeType_OK;
  10591. }
  10592. /*===========================================================================
  10593. FUNCTION: Sudo_Parameter_din_SessionStopRes
  10594. DESCRIPTION:
  10595. PRE-CONDITION:
  10596. INPUT:
  10597. OUTPUT:
  10598. GLOBAL VARIABLES:
  10599. =============================================================================*/
  10600. void Sudo_Parameter_din_SessionStopRes()
  10601. {
  10602. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  10603. init_dinSessionStopResType(&ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes);
  10604. ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes_isUsed = 1u;
  10605. //----- [BODY (1/3)] ResponseCode -----
  10606. struct dinSessionStopResType *res;
  10607. res = &ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes;
  10608. res->ResponseCode = dinresponseCodeType_OK;
  10609. }
  10610. /*===========================================================================
  10611. FUNCTION: Sudo_Parameter_iso1_SessionStopRes
  10612. DESCRIPTION:
  10613. PRE-CONDITION:
  10614. INPUT:
  10615. OUTPUT:
  10616. GLOBAL VARIABLES:
  10617. =============================================================================*/
  10618. void Sudo_Parameter_iso1_SessionStopRes()
  10619. {
  10620. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  10621. init_iso1SessionStopResType(&ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes);
  10622. ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes_isUsed = 1u;
  10623. //----- [BODY (1/3)] ResponseCode -----
  10624. struct iso1SessionStopResType *res;
  10625. res = &ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes;
  10626. res->ResponseCode = iso1responseCodeType_OK;
  10627. }
  10628. /*===========================================================================
  10629. FUNCTION: Proc_din_SessionStopRes
  10630. DESCRIPTION:
  10631. PRE-CONDITION:
  10632. INPUT:
  10633. OUTPUT:
  10634. GLOBAL VARIABLES:
  10635. =============================================================================*/
  10636. int Proc_din_SessionStopRes(int AcceptFd)
  10637. {
  10638. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10639. //if it is not the same, the packet should be ignored.
  10640. //STEP 1: ============ Initialize ============
  10641. int i = 0;
  10642. int errn = 0;
  10643. bitstream_t v2g_tx_stream;
  10644. struct SessionStopResponse_DIN70121 *stp;
  10645. struct ChargingInfoData *sys;
  10646. size_t pos = 0;
  10647. v2g_tx_stream.pos = &pos;
  10648. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10649. v2g_tx_stream.data = V2GTP_Tx_buf;
  10650. stp = &ShmCcsData->V2GMessage_DIN70121.SessionStopResponse;
  10651. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10652. stp->ResponseCode = OK_DIN70121;
  10653. //[HEADER] Check Req SessionID
  10654. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  10655. {
  10656. stp->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  10657. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  10658. errn = -1;
  10659. }
  10660. //Check for SequenceError
  10661. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10662. {
  10663. stp->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  10664. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  10665. errn = -1;
  10666. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10667. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10668. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10669. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10670. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10671. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10672. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10673. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10674. }
  10675. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10676. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10677. #if PARAMETER_NORMAL_MODE == ENABLE
  10678. SHM_Read_din_SessionStopRes(&ccs_exi_doc_DIN, ShmCcsData);
  10679. #else
  10680. Sudo_Parameter_din_SessionStopRes();
  10681. #endif
  10682. //STEP 4: ============ Encode and Send Response Message ===========
  10683. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  10684. {
  10685. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Tx]SessionStopRes: fail");
  10686. errn = -1;
  10687. }
  10688. else
  10689. {
  10690. //send response successfully.
  10691. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Tx]SessionStopRes");
  10692. }
  10693. //STEP 5: ============ Update Flags ===========
  10694. EVCOMM_SYS_INFO.ConnectorLocked = FALSE; //Indicating CSU that the Connector is unlocked.
  10695. //Once this is set, the CSU should
  10696. // =========== Annouce to CSU [To-Be Implemented]=============
  10697. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE; //This should be also added to EV Error events.
  10698. // =========== Re-initialized [To-Be Implemented]=============
  10699. //Keep 5% PWM for 2 seconds
  10700. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 2");
  10701. sleep(1);
  10702. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 1");
  10703. sleep(1);
  10704. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 0");
  10705. OutputCpPwmDuty(100);
  10706. //[To-Do] Reset All Share memory
  10707. //[To-Do] CCS Module enter "idle" mode and CSU should check for this state.
  10708. //system("reboot -f");
  10709. //sleep(5);
  10710. //system("reboot -f");
  10711. return errn;
  10712. }
  10713. /*===========================================================================
  10714. FUNCTION: Proc_iso1_SessionStopRes
  10715. DESCRIPTION:
  10716. PRE-CONDITION:
  10717. INPUT:
  10718. OUTPUT:
  10719. GLOBAL VARIABLES:
  10720. =============================================================================*/
  10721. int Proc_iso1_SessionStopRes(int AcceptFd)
  10722. {
  10723. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10724. //if it is not the same, the packet should be ignored.
  10725. //STEP 1: ============ Initialize ============
  10726. int i = 0;
  10727. int errn = 0;
  10728. bitstream_t v2g_tx_stream;
  10729. struct SessionStopResponse_ISO15118_2014 *stp;
  10730. struct ChargingInfoData *sys;
  10731. size_t pos = 0;
  10732. v2g_tx_stream.pos = &pos;
  10733. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10734. v2g_tx_stream.data = V2GTP_Tx_buf;
  10735. stp = &ShmCcsData->V2GMessage_ISO15118_2014.SessionStopResponse;
  10736. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10737. stp->ResponseCode = OK_ISO15118_2014;
  10738. //[HEADER] Check Req SessionID
  10739. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10740. {
  10741. stp->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10742. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process");
  10743. errn = -1;
  10744. }
  10745. //Check for SequenceError
  10746. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10747. {
  10748. stp->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10749. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process");
  10750. errn = -1;
  10751. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10752. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10753. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10754. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10755. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10756. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10757. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10758. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10759. }
  10760. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10761. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10762. #if PARAMETER_NORMAL_MODE == ENABLE
  10763. SHM_Read_iso1_SessionStopRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10764. #else
  10765. Sudo_Parameter_iso1_SessionStopRes();
  10766. #endif
  10767. //STEP 4: ============ Encode and Send Response Message ===========
  10768. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10769. {
  10770. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Tx]SessionStopRes: fail");
  10771. errn = -1;
  10772. }
  10773. else
  10774. {
  10775. //send response successfully.
  10776. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Tx]SessionStopRes");
  10777. }
  10778. //STEP 5: ============ Update Flags ===========
  10779. EVCOMM_SYS_INFO.ConnectorLocked = FALSE; //Indicating CSU that the Connector is unlocked.
  10780. //Once this is set, the CSU should
  10781. // =========== Annouce to CSU [To-Be Implemented]=============
  10782. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE; //This should be also added to EV Error events.
  10783. // =========== Re-initialized [To-Be Implemented]=============
  10784. //Keep 5% PWM for 2 seconds
  10785. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 2");
  10786. sleep(1);
  10787. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 1");
  10788. sleep(1);
  10789. SAVE_SYS_LOG_MSG_EVCOMM("PWM 5\% countdown: 0");
  10790. OutputCpPwmDuty(100);
  10791. //[To-Do] Reset All Share memory
  10792. //[To-Do] CCS Module enter "idle" mode and CSU should check for this state.
  10793. //system("reboot -f");
  10794. //sleep(5);
  10795. //system("reboot -f");
  10796. return errn;
  10797. }
  10798. /*===========================================================================
  10799. FUNCTION: Proc_din_SessionStopReq
  10800. DESCRIPTION:
  10801. PRE-CONDITION:
  10802. INPUT:
  10803. OUTPUT:
  10804. GLOBAL VARIABLES:
  10805. =============================================================================*/
  10806. int Proc_din_SessionStopReq(int AcceptFd)
  10807. {
  10808. int errn = 0;
  10809. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]SessionStopReq");
  10810. //Print the decoded XML Document
  10811. PRINT_XML_DOC_DIN_SessionStopReq(&ccs_exi_doc_DIN);
  10812. //Save into Share Memory
  10813. SHM_Save_din_SessionStopReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10814. errn = Proc_din_SessionStopRes(AcceptFd);
  10815. if (errn == 0)
  10816. {
  10817. //send response successfully.
  10818. }
  10819. else
  10820. {
  10821. sprintf(buf_log_evcomm,
  10822. "[Error][SeccComm][Proc_din_SessionStopReq]Proc_iso1_SessionStopRes(): %d (DEC)",
  10823. errn);
  10824. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10825. }
  10826. return errn;
  10827. }
  10828. /*===========================================================================
  10829. FUNCTION: Proc_iso1_SessionStopReq
  10830. DESCRIPTION:
  10831. PRE-CONDITION:
  10832. INPUT:
  10833. OUTPUT:
  10834. GLOBAL VARIABLES:
  10835. =============================================================================*/
  10836. int Proc_iso1_SessionStopReq(int AcceptFd)
  10837. {
  10838. int errn = 0;
  10839. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]SessionStopReq");
  10840. //Print the decoded XML Document
  10841. PRINT_XML_DOC_ISO1_SessionStopReq(&ccs_exi_doc_ISO1);
  10842. //Save into Share Memory
  10843. SHM_Save_iso1_SessionStopReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10844. errn = Proc_iso1_SessionStopRes(AcceptFd);
  10845. if (errn == 0)
  10846. {
  10847. //send response successfully.
  10848. }
  10849. else
  10850. {
  10851. sprintf(buf_log_evcomm,
  10852. "[Error][SeccComm][Proc_iso1_SessionStopReq]Proc_iso1_SessionStopRes(): %d (DEC)",
  10853. errn);
  10854. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  10855. }
  10856. return errn;
  10857. }
  10858. /*===========================================================================
  10859. FUNCTION: V2gMsg_Process_din
  10860. DESCRIPTION:
  10861. PRE-CONDITION:
  10862. INPUT:
  10863. 1. V2gFlowStatus
  10864. OUTPUT:
  10865. GLOBAL VARIABLES:
  10866. 1. V2gFlowStatus
  10867. =============================================================================*/
  10868. int V2gMsg_Process_din(int AcceptFd)
  10869. {
  10870. unsigned char req_is_responsed = FALSE;
  10871. while (req_is_responsed == FALSE)
  10872. {
  10873. //Check if it is in End_Process
  10874. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  10875. {
  10876. break;
  10877. }
  10878. switch(V2gFlowStatus)
  10879. {
  10880. //-------------------------------------------
  10881. case SupportedAppProtocolRequest:
  10882. {
  10883. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  10884. {
  10885. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  10886. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  10887. {
  10888. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10889. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  10890. }
  10891. else
  10892. {
  10893. SAVE_SYS_LOG_MSG_EVCOMM("[Error]supportedAppProtocolResReq: fail");
  10894. Update_V2G_Flow_Status(Other_Fault);
  10895. }
  10896. }
  10897. req_is_responsed = TRUE;
  10898. break;
  10899. }
  10900. case SupportedAppProtocolResponse:
  10901. {
  10902. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  10903. {
  10904. Update_V2G_Flow_Status(SessionSetupRequest);
  10905. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10906. }
  10907. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10908. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10909. {
  10910. sprintf(buf_log_evcomm,
  10911. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10912. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10913. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10914. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10915. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10916. }
  10917. else
  10918. {
  10919. break;
  10920. }
  10921. }
  10922. //-------------------------------------------
  10923. case SessionSetupRequest: //19
  10924. {
  10925. if (Proc_din_SessionSetupReq(AcceptFd) == 0)
  10926. {
  10927. Update_V2G_Flow_Status(SessionSetupResponse);
  10928. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10929. }
  10930. else
  10931. {
  10932. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionSetupReqRes: fail");
  10933. Update_V2G_Flow_Status(Other_Fault);
  10934. }
  10935. req_is_responsed = TRUE;
  10936. break;
  10937. }
  10938. case SessionSetupResponse: //20
  10939. {
  10940. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  10941. {
  10942. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  10943. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10944. }
  10945. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10946. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10947. {
  10948. sprintf(buf_log_evcomm,
  10949. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10950. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10951. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10952. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10953. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10954. }
  10955. else
  10956. {
  10957. break;
  10958. }
  10959. }
  10960. //-------------------------------------------
  10961. case ServiceDiscoveryRequest: //21
  10962. {
  10963. if (Proc_din_ServiceDiscoveryReq(AcceptFd) == 0)
  10964. {
  10965. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  10966. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10967. }
  10968. else
  10969. {
  10970. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceDiscoveryReqRes: fail");
  10971. Update_V2G_Flow_Status(Other_Fault);
  10972. }
  10973. req_is_responsed = TRUE;
  10974. break;
  10975. }
  10976. case ServiceDiscoveryResponse: //22
  10977. {
  10978. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  10979. {
  10980. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  10981. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10982. }
  10983. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10984. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10985. {
  10986. sprintf(buf_log_evcomm,
  10987. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10988. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10989. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10990. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10991. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10992. }
  10993. else
  10994. {
  10995. break;
  10996. }
  10997. }
  10998. //-------------------------------------------
  10999. case ServiceAndPaymentSelectionRequest: //25
  11000. {
  11001. if (Proc_din_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  11002. {
  11003. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  11004. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11005. }
  11006. else
  11007. {
  11008. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceAndPaymentSelectionReqRes: fail");
  11009. Update_V2G_Flow_Status(Other_Fault);
  11010. }
  11011. req_is_responsed = TRUE;
  11012. break;
  11013. }
  11014. case ServiceAndPaymentSelectionResponse: //26
  11015. {
  11016. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11017. {
  11018. Update_V2G_Flow_Status(AuthorizationRequest);
  11019. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11020. }
  11021. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11022. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11023. {
  11024. sprintf(buf_log_evcomm,
  11025. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11026. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11027. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11028. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11029. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11030. }
  11031. else
  11032. {
  11033. break;
  11034. }
  11035. }
  11036. //-------------------------------------------
  11037. //case ContractAuthenticationReq:
  11038. case AuthorizationRequest: //29
  11039. {
  11040. if (Proc_din_ContractAuthenticationReq(AcceptFd) == 0)
  11041. {
  11042. Update_V2G_Flow_Status(AuthorizationResponse);
  11043. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11044. }
  11045. else
  11046. {
  11047. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  11048. Update_V2G_Flow_Status(Other_Fault);
  11049. }
  11050. req_is_responsed = TRUE;
  11051. break;
  11052. }
  11053. case AuthorizationResponse: //30
  11054. {
  11055. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11056. {
  11057. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11058. if (Proc_din_ContractAuthenticationReq(AcceptFd) == 0)
  11059. {
  11060. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11061. }
  11062. else
  11063. {
  11064. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  11065. Update_V2G_Flow_Status(Other_Fault);
  11066. }
  11067. req_is_responsed = TRUE;
  11068. break;
  11069. }
  11070. //Check for ChargeParameterDiscoveryReq
  11071. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11072. {
  11073. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11074. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  11075. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  11076. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11077. ftime(&SeqStartTime);
  11078. #endif
  11079. }
  11080. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11081. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11082. {
  11083. sprintf(buf_log_evcomm,
  11084. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11085. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11086. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11087. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11088. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11089. }
  11090. else
  11091. {
  11092. break;
  11093. }
  11094. }
  11095. //-------------------------------------------
  11096. case ChargeParameterDiscoveryRequest: //35
  11097. {
  11098. if (Proc_din_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11099. {
  11100. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  11101. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11102. }
  11103. else
  11104. {
  11105. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  11106. Update_V2G_Flow_Status(Other_Fault);
  11107. }
  11108. req_is_responsed = TRUE;
  11109. break;
  11110. }
  11111. case ChargeParameterDiscoveryResponse:
  11112. {
  11113. //STEP 1: Check for Process Timeout
  11114. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11115. ftime(&SeqEndTime);
  11116. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  11117. {
  11118. sprintf(buf_log_evcomm,
  11119. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  11120. DiffTimeb(SeqStartTime, SeqEndTime),
  11121. V2G_SECC_ChargingParameter_Performance_Time);
  11122. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11123. Update_V2G_Flow_Status(Sequence_Timeout);
  11124. break;
  11125. }
  11126. #endif
  11127. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11128. {
  11129. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11130. if (Proc_din_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11131. {
  11132. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11133. }
  11134. else
  11135. {
  11136. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  11137. Update_V2G_Flow_Status(Other_Fault);
  11138. }
  11139. req_is_responsed = TRUE;
  11140. break;
  11141. }
  11142. //STEP 2: Check for CableCheckReq message
  11143. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11144. {
  11145. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11146. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CableCheckReqReq: isolated?");
  11147. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  11148. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11149. Update_V2G_Flow_Status(CableCheckRequest);
  11150. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11151. ftime(&SeqStartTime);
  11152. #endif
  11153. }
  11154. //STEP 3: Wait for PowerDeliveryReq Message
  11155. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11156. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11157. {
  11158. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11159. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11160. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11161. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11162. ftime(&SeqStartTime);
  11163. #endif
  11164. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  11165. {
  11166. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11167. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11168. }
  11169. else
  11170. {
  11171. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  11172. Update_V2G_Flow_Status(Other_Fault);
  11173. }
  11174. break;
  11175. }
  11176. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11177. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11178. {
  11179. sprintf(buf_log_evcomm,
  11180. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11181. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11182. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11183. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11184. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11185. }
  11186. else
  11187. {
  11188. break;
  11189. }
  11190. }
  11191. //-------------------------------------------
  11192. case CableCheckRequest: //37
  11193. {
  11194. //STEP 3: Execute Cable Check Process
  11195. if (Proc_din_CableCheckReq(AcceptFd) == 0)
  11196. {
  11197. Update_V2G_Flow_Status(CableCheckResponse);
  11198. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11199. }
  11200. else
  11201. {
  11202. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  11203. Update_V2G_Flow_Status(Other_Fault);
  11204. }
  11205. req_is_responsed = TRUE;
  11206. break;
  11207. }
  11208. case CableCheckResponse: //38
  11209. {
  11210. //STEP 1: Check for Process Timeout
  11211. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11212. ftime(&SeqEndTime);
  11213. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  11214. {
  11215. //SAVE_SYS_LOG_MSG_EVCOMM("[CableCheck] end counting...");
  11216. sprintf(buf_log_evcomm,
  11217. "CableCheck Timeout - (%.02lf of %d ms)\n",
  11218. DiffTimeb(SeqStartTime, SeqEndTime),
  11219. V2G_SECC_CableCheck_Performance_Time);
  11220. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11221. Update_V2G_Flow_Status(Sequence_Timeout);
  11222. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11223. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  11224. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11225. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11226. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11227. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11228. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  11229. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  11230. break;
  11231. }
  11232. #endif
  11233. //STEP 2: Check for CableCheckReq message
  11234. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11235. {
  11236. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11237. //STEP 3: Execute Cable Check Process
  11238. if (Proc_din_CableCheckReq(AcceptFd) == 0)
  11239. {
  11240. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11241. }
  11242. else
  11243. {
  11244. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  11245. Update_V2G_Flow_Status(Other_Fault);
  11246. }
  11247. req_is_responsed = TRUE;
  11248. break;
  11249. }
  11250. //STEP 3: Check for PreChargeReq message
  11251. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11252. {
  11253. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11254. Update_V2G_Flow_Status(PreChargeRequest);
  11255. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PreChargeReqReq: waiting for precharge voltage...");
  11256. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11257. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  11258. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11259. ftime(&SeqStartTime);
  11260. #endif
  11261. }
  11262. //STEP 3: Wait for PowerDeliveryReq Message
  11263. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11264. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11265. {
  11266. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11267. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11268. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11269. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11270. ftime(&SeqStartTime);
  11271. #endif
  11272. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  11273. {
  11274. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11275. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11276. }
  11277. else
  11278. {
  11279. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  11280. Update_V2G_Flow_Status(Other_Fault);
  11281. }
  11282. break;
  11283. }
  11284. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11285. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11286. {
  11287. sprintf(buf_log_evcomm,
  11288. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11289. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11290. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11291. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11292. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11293. }
  11294. else
  11295. {
  11296. break;
  11297. }
  11298. }
  11299. //-------------------------------------------
  11300. case PreChargeRequest: //39
  11301. {
  11302. if (Proc_din_PreChargeReq(AcceptFd) == 0)
  11303. {
  11304. Update_V2G_Flow_Status(PreChargeResponse);
  11305. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11306. }
  11307. else
  11308. {
  11309. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  11310. Update_V2G_Flow_Status(Other_Fault);
  11311. }
  11312. req_is_responsed = TRUE;
  11313. break;
  11314. }
  11315. case PreChargeResponse: //40
  11316. {
  11317. //STEP 1: Check for Process Timeout
  11318. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11319. ftime(&SeqEndTime);
  11320. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  11321. {
  11322. sprintf(buf_log_evcomm,
  11323. "Precharge Timeout - (%.02lf of %d ms)\n",
  11324. DiffTimeb(SeqStartTime, SeqEndTime),
  11325. V2G_SECC_PreCharge_Performance_Time);
  11326. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11327. Update_V2G_Flow_Status(Sequence_Timeout);
  11328. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11329. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  11330. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11331. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11332. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11333. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11334. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  11335. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  11336. break;
  11337. }
  11338. #endif
  11339. //STEP 2: Check for PreChargeReq message
  11340. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11341. {
  11342. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11343. if (Proc_din_PreChargeReq(AcceptFd) == 0)
  11344. {
  11345. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11346. }
  11347. else
  11348. {
  11349. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  11350. Update_V2G_Flow_Status(Other_Fault);
  11351. }
  11352. req_is_responsed = TRUE;
  11353. break;
  11354. }
  11355. //STEP 3: Check for PowerDeliveryReq message
  11356. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11357. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11358. {
  11359. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11360. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  11361. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  11362. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11363. ftime(&SeqStartTime);
  11364. #endif
  11365. }
  11366. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11367. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11368. {
  11369. sprintf(buf_log_evcomm,
  11370. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11371. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11372. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11373. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11374. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11375. }
  11376. else
  11377. {
  11378. break;
  11379. }
  11380. }
  11381. //-------------------------------------------
  11382. case PowerDeliveryRequestStart: //41
  11383. {
  11384. if (Proc_din_PowerDeliveryStartReq(AcceptFd) == 0)
  11385. {
  11386. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  11387. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11388. }
  11389. else
  11390. {
  11391. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStartReqRes: fail");
  11392. Update_V2G_Flow_Status(Other_Fault);
  11393. }
  11394. req_is_responsed = TRUE;
  11395. break;
  11396. }
  11397. case PowerDeliveryResponsetStart: //42
  11398. {
  11399. //STEP 1: Check for Process Timeout
  11400. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11401. if (ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  11402. {
  11403. ftime(&SeqEndTime);
  11404. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  11405. {
  11406. sprintf(buf_log_evcomm,
  11407. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  11408. DiffTimeb(SeqStartTime, SeqEndTime),
  11409. 2000);
  11410. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11411. Update_V2G_Flow_Status(Sequence_Timeout);
  11412. }
  11413. break;
  11414. }
  11415. #endif
  11416. //STEP 2: Wait for CurrentDemandReq Message
  11417. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  11418. {
  11419. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11420. Update_V2G_Flow_Status(CurrentDemandRequest);
  11421. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CurrentDemandReqReq: energy transfering...");
  11422. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  11423. }
  11424. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11425. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11426. {
  11427. sprintf(buf_log_evcomm,
  11428. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11429. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11430. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11431. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11432. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11433. }
  11434. else
  11435. {
  11436. break;
  11437. }
  11438. }
  11439. //-------------------------------------------
  11440. case CurrentDemandRequest: //45,
  11441. {
  11442. if (Proc_din_CurrentDemandReq(AcceptFd) == 0)
  11443. {
  11444. Update_V2G_Flow_Status(CurrentDemandResponse);
  11445. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11446. }
  11447. else
  11448. {
  11449. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  11450. Update_V2G_Flow_Status(Other_Fault);
  11451. }
  11452. req_is_responsed = TRUE;
  11453. break;
  11454. }
  11455. case CurrentDemandResponse: //46,
  11456. {
  11457. //STEP 1: Wait for CurrentDemandReq Message
  11458. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  11459. {
  11460. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11461. if (Proc_din_CurrentDemandReq(AcceptFd) == 0)
  11462. {
  11463. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11464. }
  11465. else
  11466. {
  11467. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  11468. Update_V2G_Flow_Status(Other_Fault);
  11469. }
  11470. req_is_responsed = TRUE;
  11471. break;
  11472. }
  11473. //STEP 2: Wait for PowerDeliveryReq Message
  11474. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11475. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11476. {
  11477. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11478. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11479. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  11480. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11481. ftime(&SeqStartTime);
  11482. #endif
  11483. }
  11484. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11485. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11486. {
  11487. sprintf(buf_log_evcomm,
  11488. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11489. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11490. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11491. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11492. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11493. }
  11494. else
  11495. {
  11496. break;
  11497. }
  11498. }
  11499. //-------------------------------------------
  11500. case PowerDeliveryRequestStop: //49,
  11501. {
  11502. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  11503. {
  11504. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11505. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11506. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11507. ftime(&SeqStartTime);
  11508. #endif
  11509. }
  11510. else
  11511. {
  11512. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  11513. Update_V2G_Flow_Status(Other_Fault);
  11514. }
  11515. req_is_responsed = TRUE;
  11516. break;
  11517. }
  11518. case PowerDeliveryResponseStop: //50,
  11519. {
  11520. //STEP 1: Check for Process Timeout
  11521. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11522. ftime(&SeqEndTime);
  11523. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  11524. {
  11525. sprintf(buf_log_evcomm,
  11526. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  11527. DiffTimeb(SeqStartTime, SeqEndTime),
  11528. 2000);
  11529. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11530. Update_V2G_Flow_Status(Sequence_Timeout);
  11531. break;
  11532. }
  11533. #endif
  11534. //STEP 2: Check for WeldingDetectionReq Message
  11535. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  11536. {
  11537. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11538. Update_V2G_Flow_Status(WeldingDetectionRequest);
  11539. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]WeldingDetectionReq: ongoing...");
  11540. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  11541. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11542. ftime(&SeqStartTime);
  11543. #endif
  11544. }
  11545. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  11546. {
  11547. Update_V2G_Flow_Status(SessionStopRequest);
  11548. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11549. if (Proc_din_SessionStopReq(AcceptFd) == 0)
  11550. {
  11551. Update_V2G_Flow_Status(SessionStopResponse);
  11552. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11553. }
  11554. else
  11555. {
  11556. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  11557. Update_V2G_Flow_Status(Other_Fault);
  11558. }
  11559. break;
  11560. }
  11561. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11562. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11563. {
  11564. sprintf(buf_log_evcomm,
  11565. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11566. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11567. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11568. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11569. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11570. }
  11571. else
  11572. {
  11573. break;
  11574. }
  11575. }
  11576. //-------------------------------------------
  11577. case WeldingDetectionRequest: //51,
  11578. {
  11579. if (Proc_din_WeldingDetectionReq(AcceptFd) == 0)
  11580. {
  11581. Update_V2G_Flow_Status(WeldingDetectionResponse);
  11582. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11583. }
  11584. else
  11585. {
  11586. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  11587. Update_V2G_Flow_Status(Other_Fault);
  11588. }
  11589. req_is_responsed = TRUE;
  11590. break;
  11591. }
  11592. case WeldingDetectionResponse: //52,
  11593. {
  11594. //STEP 1: Check for Process Timeout
  11595. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11596. ftime(&SeqEndTime);
  11597. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  11598. {
  11599. sprintf(buf_log_evcomm,
  11600. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  11601. DiffTimeb(SeqStartTime, SeqEndTime),
  11602. V2G_SECC_WeldingDetection_Performance_Time);
  11603. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11604. Update_V2G_Flow_Status(Sequence_Timeout);
  11605. break;
  11606. }
  11607. #endif
  11608. //STEP 2: Check for WeldingDetectionReq Message
  11609. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  11610. {
  11611. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11612. if (Proc_din_WeldingDetectionReq(AcceptFd) == 0)
  11613. {
  11614. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11615. }
  11616. else
  11617. {
  11618. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  11619. Update_V2G_Flow_Status(Other_Fault);
  11620. }
  11621. req_is_responsed = TRUE;
  11622. break;
  11623. }
  11624. //STEP 3: Check for SessionStopReq Message
  11625. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  11626. {
  11627. Update_V2G_Flow_Status(SessionStopRequest);
  11628. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11629. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  11630. }
  11631. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11632. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11633. {
  11634. sprintf(buf_log_evcomm,
  11635. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11636. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11637. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11638. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11639. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11640. }
  11641. else
  11642. {
  11643. break;
  11644. }
  11645. }
  11646. //-------------------------------------------
  11647. case SessionStopRequest: //53,
  11648. {
  11649. if (Proc_din_SessionStopReq(AcceptFd) == 0)
  11650. {
  11651. Update_V2G_Flow_Status(SessionStopResponse);
  11652. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11653. }
  11654. else
  11655. {
  11656. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  11657. Update_V2G_Flow_Status(Other_Fault);
  11658. }
  11659. req_is_responsed = TRUE;
  11660. //break;
  11661. }
  11662. case SessionStopResponse: //54,
  11663. {
  11664. break;
  11665. }
  11666. //-------------------------------------------
  11667. default:
  11668. {
  11669. break;
  11670. }
  11671. }
  11672. }
  11673. }
  11674. /*===========================================================================
  11675. FUNCTION: V2gMsg_Process_iso1_DC
  11676. DESCRIPTION:
  11677. PRE-CONDITION:
  11678. INPUT:
  11679. 1. V2gFlowStatus
  11680. OUTPUT:
  11681. GLOBAL VARIABLES:
  11682. 1. V2gFlowStatus
  11683. =============================================================================*/
  11684. int V2gMsg_Process_iso1_DC(int AcceptFd)
  11685. {
  11686. unsigned char req_is_responsed = FALSE;
  11687. while (req_is_responsed == FALSE)
  11688. {
  11689. //Check if it is in End_Process
  11690. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  11691. {
  11692. break;
  11693. }
  11694. switch(V2gFlowStatus)
  11695. {
  11696. //-------------------------------------------
  11697. case SupportedAppProtocolRequest:
  11698. {
  11699. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  11700. {
  11701. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  11702. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  11703. {
  11704. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11705. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  11706. }
  11707. else
  11708. {
  11709. SAVE_SYS_LOG_MSG_EVCOMM("[Error]supportedAppProtocolResReq: fail");
  11710. Update_V2G_Flow_Status(Other_Fault);
  11711. }
  11712. }
  11713. req_is_responsed = TRUE;
  11714. break;
  11715. }
  11716. case SupportedAppProtocolResponse:
  11717. {
  11718. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  11719. {
  11720. Update_V2G_Flow_Status(SessionSetupRequest);
  11721. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11722. }
  11723. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11724. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11725. {
  11726. sprintf(buf_log_evcomm,
  11727. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11728. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11729. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11730. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11731. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11732. }
  11733. else
  11734. {
  11735. break;
  11736. }
  11737. }
  11738. //-------------------------------------------
  11739. case SessionSetupRequest: //19
  11740. {
  11741. if (Proc_iso1_SessionSetupReq(AcceptFd) == 0)
  11742. {
  11743. Update_V2G_Flow_Status(SessionSetupResponse);
  11744. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11745. }
  11746. else
  11747. {
  11748. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionSetupReqRes: fail");
  11749. Update_V2G_Flow_Status(Other_Fault);
  11750. }
  11751. req_is_responsed = TRUE;
  11752. break;
  11753. }
  11754. case SessionSetupResponse: //20
  11755. {
  11756. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  11757. {
  11758. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  11759. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11760. }
  11761. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11762. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11763. {
  11764. sprintf(buf_log_evcomm,
  11765. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11766. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11767. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11768. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11769. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11770. }
  11771. else
  11772. {
  11773. break;
  11774. }
  11775. }
  11776. //-------------------------------------------
  11777. case ServiceDiscoveryRequest: //21
  11778. {
  11779. if (Proc_iso1_ServiceDiscoveryReq(AcceptFd) == 0)
  11780. {
  11781. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  11782. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11783. }
  11784. else
  11785. {
  11786. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceDiscoveryReqRes: fail");
  11787. Update_V2G_Flow_Status(Other_Fault);
  11788. }
  11789. req_is_responsed = TRUE;
  11790. break;
  11791. }
  11792. case ServiceDiscoveryResponse: //22
  11793. {
  11794. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  11795. {
  11796. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  11797. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11798. }
  11799. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11800. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11801. {
  11802. sprintf(buf_log_evcomm,
  11803. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11804. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11805. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11806. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11807. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11808. }
  11809. else
  11810. {
  11811. break;
  11812. }
  11813. }
  11814. //-------------------------------------------
  11815. case ServiceAndPaymentSelectionRequest: //25
  11816. {
  11817. if (Proc_iso1_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  11818. {
  11819. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  11820. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11821. }
  11822. else
  11823. {
  11824. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceAndPaymentSelectionReqRes: fail");
  11825. Update_V2G_Flow_Status(Other_Fault);
  11826. }
  11827. req_is_responsed = TRUE;
  11828. break;
  11829. }
  11830. case ServiceAndPaymentSelectionResponse: //26
  11831. {
  11832. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11833. {
  11834. Update_V2G_Flow_Status(AuthorizationRequest);
  11835. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11836. }
  11837. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11838. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11839. {
  11840. sprintf(buf_log_evcomm,
  11841. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11842. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11843. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11844. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11845. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11846. }
  11847. else
  11848. {
  11849. break;
  11850. }
  11851. }
  11852. //-------------------------------------------
  11853. //case ContractAuthenticationReq:
  11854. case AuthorizationRequest: //29
  11855. {
  11856. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  11857. {
  11858. Update_V2G_Flow_Status(AuthorizationResponse);
  11859. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11860. }
  11861. else
  11862. {
  11863. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  11864. Update_V2G_Flow_Status(Other_Fault);
  11865. }
  11866. req_is_responsed = TRUE;
  11867. break;
  11868. }
  11869. case AuthorizationResponse: //30
  11870. {
  11871. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11872. {
  11873. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11874. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  11875. {
  11876. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11877. }
  11878. else
  11879. {
  11880. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  11881. Update_V2G_Flow_Status(Other_Fault);
  11882. }
  11883. req_is_responsed = TRUE;
  11884. break;
  11885. }
  11886. //Check for ChargeParameterDiscoveryReq
  11887. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11888. {
  11889. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11890. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  11891. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  11892. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11893. ftime(&SeqStartTime);
  11894. #endif
  11895. }
  11896. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11897. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11898. {
  11899. sprintf(buf_log_evcomm,
  11900. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11901. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11902. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11903. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11904. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11905. }
  11906. else
  11907. {
  11908. break;
  11909. }
  11910. }
  11911. //-------------------------------------------
  11912. case ChargeParameterDiscoveryRequest: //35
  11913. {
  11914. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11915. {
  11916. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  11917. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11918. }
  11919. else
  11920. {
  11921. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  11922. Update_V2G_Flow_Status(Other_Fault);
  11923. }
  11924. req_is_responsed = TRUE;
  11925. break;
  11926. }
  11927. case ChargeParameterDiscoveryResponse:
  11928. {
  11929. //STEP 1: Check for Process Timeout
  11930. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11931. ftime(&SeqEndTime);
  11932. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  11933. {
  11934. sprintf(buf_log_evcomm,
  11935. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  11936. DiffTimeb(SeqStartTime, SeqEndTime),
  11937. V2G_SECC_ChargingParameter_Performance_Time);
  11938. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  11939. Update_V2G_Flow_Status(Sequence_Timeout);
  11940. break;
  11941. }
  11942. #endif
  11943. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11944. {
  11945. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11946. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11947. {
  11948. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11949. }
  11950. else
  11951. {
  11952. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  11953. Update_V2G_Flow_Status(Other_Fault);
  11954. }
  11955. req_is_responsed = TRUE;
  11956. break;
  11957. }
  11958. //STEP 2: Check for CableCheckReq message
  11959. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11960. {
  11961. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11962. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CableCheckReqReq: isolated?");
  11963. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  11964. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11965. Update_V2G_Flow_Status(CableCheckRequest);
  11966. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11967. ftime(&SeqStartTime);
  11968. #endif
  11969. }
  11970. //STEP 3: Wait for PowerDeliveryReq Message
  11971. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11972. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11973. {
  11974. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11975. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11976. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11977. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11978. ftime(&SeqStartTime);
  11979. #endif
  11980. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  11981. {
  11982. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11983. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11984. }
  11985. else
  11986. {
  11987. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  11988. Update_V2G_Flow_Status(Other_Fault);
  11989. }
  11990. break;
  11991. }
  11992. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11993. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11994. {
  11995. sprintf(buf_log_evcomm,
  11996. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11997. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11998. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11999. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12000. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12001. }
  12002. else
  12003. {
  12004. break;
  12005. }
  12006. }
  12007. //-------------------------------------------
  12008. case CableCheckRequest: //37
  12009. {
  12010. //STEP 3: Execute Cable Check Process
  12011. if (Proc_iso1_CableCheckReq(AcceptFd) == 0)
  12012. {
  12013. Update_V2G_Flow_Status(CableCheckResponse);
  12014. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12015. }
  12016. else
  12017. {
  12018. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  12019. Update_V2G_Flow_Status(Other_Fault);
  12020. }
  12021. req_is_responsed = TRUE;
  12022. break;
  12023. }
  12024. case CableCheckResponse: //38
  12025. {
  12026. //STEP 1: Check for Process Timeout
  12027. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12028. ftime(&SeqEndTime);
  12029. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  12030. {
  12031. //SAVE_SYS_LOG_MSG_EVCOMM("[CableCheck] end counting...");
  12032. sprintf(buf_log_evcomm,
  12033. "CableCheck Timeout - (%.02lf of %d ms)\n",
  12034. DiffTimeb(SeqStartTime, SeqEndTime),
  12035. V2G_SECC_CableCheck_Performance_Time);
  12036. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12037. Update_V2G_Flow_Status(Sequence_Timeout);
  12038. //Update_ShmStatusCode(); //[To-Do] to be implemented
  12039. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  12040. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12041. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12042. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12043. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  12044. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  12045. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  12046. break;
  12047. }
  12048. #endif
  12049. //STEP 2: Check for CableCheckReq message
  12050. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  12051. {
  12052. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12053. //STEP 3: Execute Cable Check Process
  12054. if (Proc_iso1_CableCheckReq(AcceptFd) == 0)
  12055. {
  12056. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12057. }
  12058. else
  12059. {
  12060. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  12061. Update_V2G_Flow_Status(Other_Fault);
  12062. }
  12063. req_is_responsed = TRUE;
  12064. break;
  12065. }
  12066. //STEP 3: Check for PreChargeReq message
  12067. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  12068. {
  12069. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12070. Update_V2G_Flow_Status(PreChargeRequest);
  12071. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PreChargeReqReq: waiting for precharge voltage...");
  12072. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  12073. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  12074. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12075. ftime(&SeqStartTime);
  12076. #endif
  12077. }
  12078. //STEP 3: Wait for PowerDeliveryReq Message
  12079. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12080. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12081. {
  12082. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12083. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12084. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  12085. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12086. ftime(&SeqStartTime);
  12087. #endif
  12088. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12089. {
  12090. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12091. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12092. }
  12093. else
  12094. {
  12095. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  12096. Update_V2G_Flow_Status(Other_Fault);
  12097. }
  12098. break;
  12099. }
  12100. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12101. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12102. {
  12103. sprintf(buf_log_evcomm,
  12104. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12105. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12106. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12107. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12108. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12109. }
  12110. else
  12111. {
  12112. break;
  12113. }
  12114. }
  12115. //-------------------------------------------
  12116. case PreChargeRequest: //39
  12117. {
  12118. if (Proc_iso1_PreChargeReq(AcceptFd) == 0)
  12119. {
  12120. Update_V2G_Flow_Status(PreChargeResponse);
  12121. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12122. }
  12123. else
  12124. {
  12125. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  12126. Update_V2G_Flow_Status(Other_Fault);
  12127. }
  12128. req_is_responsed = TRUE;
  12129. break;
  12130. }
  12131. case PreChargeResponse: //40
  12132. {
  12133. //STEP 1: Check for Process Timeout
  12134. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12135. ftime(&SeqEndTime);
  12136. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  12137. {
  12138. sprintf(buf_log_evcomm,
  12139. "Precharge Timeout - (%.02lf of %d ms)\n",
  12140. DiffTimeb(SeqStartTime, SeqEndTime),
  12141. V2G_SECC_PreCharge_Performance_Time);
  12142. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12143. Update_V2G_Flow_Status(Sequence_Timeout);
  12144. //Update_ShmStatusCode(); //[To-Do] to be implemented
  12145. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  12146. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  12147. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  12148. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  12149. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  12150. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  12151. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  12152. break;
  12153. }
  12154. #endif
  12155. //STEP 2: Check for PreChargeReq message
  12156. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  12157. {
  12158. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12159. if (Proc_iso1_PreChargeReq(AcceptFd) == 0)
  12160. {
  12161. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12162. }
  12163. else
  12164. {
  12165. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  12166. Update_V2G_Flow_Status(Other_Fault);
  12167. }
  12168. req_is_responsed = TRUE;
  12169. break;
  12170. }
  12171. //STEP 3: Check for PowerDeliveryReq message
  12172. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12173. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12174. {
  12175. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12176. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  12177. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  12178. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12179. ftime(&SeqStartTime);
  12180. #endif
  12181. }
  12182. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12183. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  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
  12193. {
  12194. break;
  12195. }
  12196. }
  12197. //-------------------------------------------
  12198. case PowerDeliveryRequestStart: //41
  12199. {
  12200. if (Proc_iso1_PowerDeliveryStartReq(AcceptFd) == 0)
  12201. {
  12202. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  12203. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12204. }
  12205. else
  12206. {
  12207. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStartReqRes: fail");
  12208. Update_V2G_Flow_Status(Other_Fault);
  12209. }
  12210. req_is_responsed = TRUE;
  12211. break;
  12212. }
  12213. case PowerDeliveryResponsetStart: //42
  12214. {
  12215. //STEP 1: Check for Process Timeout
  12216. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12217. if (ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  12218. {
  12219. ftime(&SeqEndTime);
  12220. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  12221. {
  12222. sprintf(buf_log_evcomm,
  12223. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  12224. DiffTimeb(SeqStartTime, SeqEndTime),
  12225. 2000);
  12226. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12227. Update_V2G_Flow_Status(Sequence_Timeout);
  12228. }
  12229. break;
  12230. }
  12231. #endif
  12232. //STEP 2: Wait for CurrentDemandReq Message
  12233. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  12234. {
  12235. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12236. Update_V2G_Flow_Status(CurrentDemandRequest);
  12237. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CurrentDemandReqReq: energy transfering...");
  12238. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  12239. }
  12240. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12241. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12242. {
  12243. sprintf(buf_log_evcomm,
  12244. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12245. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12246. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12247. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12248. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12249. }
  12250. else
  12251. {
  12252. break;
  12253. }
  12254. }
  12255. //-------------------------------------------
  12256. case CurrentDemandRequest: //45,
  12257. {
  12258. if (Proc_iso1_CurrentDemandReq(AcceptFd) == 0)
  12259. {
  12260. Update_V2G_Flow_Status(CurrentDemandResponse);
  12261. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12262. }
  12263. else
  12264. {
  12265. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  12266. Update_V2G_Flow_Status(Other_Fault);
  12267. }
  12268. req_is_responsed = TRUE;
  12269. break;
  12270. }
  12271. case CurrentDemandResponse: //46,
  12272. {
  12273. //STEP 1: Wait for CurrentDemandReq Message
  12274. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  12275. {
  12276. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12277. if (Proc_iso1_CurrentDemandReq(AcceptFd) == 0)
  12278. {
  12279. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12280. }
  12281. else
  12282. {
  12283. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  12284. Update_V2G_Flow_Status(Other_Fault);
  12285. }
  12286. req_is_responsed = TRUE;
  12287. break;
  12288. }
  12289. //STEP 2: 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_CurrentDemand_Timer_End);
  12296. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12297. ftime(&SeqStartTime);
  12298. #endif
  12299. }
  12300. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12301. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12302. {
  12303. sprintf(buf_log_evcomm,
  12304. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12305. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12306. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12307. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12308. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12309. }
  12310. else
  12311. {
  12312. break;
  12313. }
  12314. }
  12315. //-------------------------------------------
  12316. case PowerDeliveryRequestStop: //49,
  12317. {
  12318. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12319. {
  12320. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12321. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12322. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12323. ftime(&SeqStartTime);
  12324. #endif
  12325. }
  12326. else
  12327. {
  12328. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  12329. Update_V2G_Flow_Status(Other_Fault);
  12330. }
  12331. req_is_responsed = TRUE;
  12332. break;
  12333. }
  12334. case PowerDeliveryResponseStop: //50,
  12335. {
  12336. //STEP 1: Check for Process Timeout
  12337. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12338. ftime(&SeqEndTime);
  12339. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  12340. {
  12341. sprintf(buf_log_evcomm,
  12342. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12343. DiffTimeb(SeqStartTime, SeqEndTime),
  12344. 2000);
  12345. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12346. Update_V2G_Flow_Status(Sequence_Timeout);
  12347. break;
  12348. }
  12349. #endif
  12350. //STEP 2: Check for WeldingDetectionReq Message
  12351. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  12352. {
  12353. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12354. Update_V2G_Flow_Status(WeldingDetectionRequest);
  12355. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]WeldingDetectionReq: ongoing...");
  12356. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  12357. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12358. ftime(&SeqStartTime);
  12359. #endif
  12360. }
  12361. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12362. {
  12363. Update_V2G_Flow_Status(SessionStopRequest);
  12364. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12365. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12366. {
  12367. Update_V2G_Flow_Status(SessionStopResponse);
  12368. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12369. }
  12370. else
  12371. {
  12372. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  12373. Update_V2G_Flow_Status(Other_Fault);
  12374. }
  12375. break;
  12376. }
  12377. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12378. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12379. {
  12380. sprintf(buf_log_evcomm,
  12381. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12382. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12383. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12384. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12385. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12386. }
  12387. else
  12388. {
  12389. break;
  12390. }
  12391. }
  12392. //-------------------------------------------
  12393. case WeldingDetectionRequest: //51,
  12394. {
  12395. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  12396. {
  12397. Update_V2G_Flow_Status(WeldingDetectionResponse);
  12398. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12399. }
  12400. else
  12401. {
  12402. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  12403. Update_V2G_Flow_Status(Other_Fault);
  12404. }
  12405. req_is_responsed = TRUE;
  12406. break;
  12407. }
  12408. case WeldingDetectionResponse: //52,
  12409. {
  12410. //STEP 1: Check for Process Timeout
  12411. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12412. ftime(&SeqEndTime);
  12413. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  12414. {
  12415. sprintf(buf_log_evcomm,
  12416. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12417. DiffTimeb(SeqStartTime, SeqEndTime),
  12418. V2G_SECC_WeldingDetection_Performance_Time);
  12419. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12420. Update_V2G_Flow_Status(Sequence_Timeout);
  12421. break;
  12422. }
  12423. #endif
  12424. //STEP 2: Check for WeldingDetectionReq Message
  12425. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  12426. {
  12427. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12428. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  12429. {
  12430. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12431. }
  12432. else
  12433. {
  12434. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  12435. Update_V2G_Flow_Status(Other_Fault);
  12436. }
  12437. req_is_responsed = TRUE;
  12438. break;
  12439. }
  12440. //STEP 3: Check for SessionStopReq Message
  12441. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12442. {
  12443. Update_V2G_Flow_Status(SessionStopRequest);
  12444. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12445. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  12446. }
  12447. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12448. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12449. {
  12450. sprintf(buf_log_evcomm,
  12451. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12452. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12453. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12454. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12455. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12456. }
  12457. else
  12458. {
  12459. break;
  12460. }
  12461. }
  12462. //-------------------------------------------
  12463. case SessionStopRequest: //53,
  12464. {
  12465. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12466. {
  12467. Update_V2G_Flow_Status(SessionStopResponse);
  12468. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12469. }
  12470. else
  12471. {
  12472. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  12473. Update_V2G_Flow_Status(Other_Fault);
  12474. }
  12475. req_is_responsed = TRUE;
  12476. //break;
  12477. }
  12478. case SessionStopResponse: //54,
  12479. {
  12480. break;
  12481. }
  12482. //-------------------------------------------
  12483. default:
  12484. {
  12485. break;
  12486. }
  12487. }
  12488. }
  12489. }
  12490. /*===========================================================================
  12491. FUNCTION: V2gMsg_Process_iso1_AC
  12492. DESCRIPTION:
  12493. PRE-CONDITION:
  12494. INPUT:
  12495. 1. V2gFlowStatus
  12496. OUTPUT:
  12497. GLOBAL VARIABLES:
  12498. 1. V2gFlowStatus
  12499. =============================================================================*/
  12500. int V2gMsg_Process_iso1_AC(int AcceptFd)
  12501. {
  12502. unsigned char req_is_responsed = FALSE;
  12503. while (req_is_responsed == FALSE)
  12504. {
  12505. //Check if it is in End_Process
  12506. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  12507. {
  12508. break;
  12509. }
  12510. switch(V2gFlowStatus)
  12511. {
  12512. //-------------------------------------------
  12513. case SupportedAppProtocolRequest: //17
  12514. {
  12515. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  12516. {
  12517. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  12518. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  12519. {
  12520. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12521. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  12522. }
  12523. else
  12524. {
  12525. SAVE_SYS_LOG_MSG_EVCOMM("[Error]supportedAppProtocolResReq: fail");
  12526. Update_V2G_Flow_Status(Other_Fault);
  12527. }
  12528. }
  12529. req_is_responsed = TRUE;
  12530. break;
  12531. }
  12532. case SupportedAppProtocolResponse: //18
  12533. {
  12534. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  12535. {
  12536. Update_V2G_Flow_Status(SessionSetupRequest);
  12537. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12538. }
  12539. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12540. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12541. {
  12542. sprintf(buf_log_evcomm,
  12543. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12544. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12545. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12546. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12547. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12548. }
  12549. else
  12550. {
  12551. break;
  12552. }
  12553. }
  12554. //-------------------------------------------
  12555. case SessionSetupRequest: //19
  12556. {
  12557. if (Proc_iso1_SessionSetupReq(AcceptFd) == 0)
  12558. {
  12559. Update_V2G_Flow_Status(SessionSetupResponse);
  12560. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12561. }
  12562. else
  12563. {
  12564. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionSetupReqRes: fail");
  12565. Update_V2G_Flow_Status(Other_Fault);
  12566. }
  12567. req_is_responsed = TRUE;
  12568. break;
  12569. }
  12570. case SessionSetupResponse: //20
  12571. {
  12572. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  12573. {
  12574. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  12575. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12576. }
  12577. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12578. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12579. {
  12580. sprintf(buf_log_evcomm,
  12581. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12582. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12583. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12584. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12585. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12586. }
  12587. else
  12588. {
  12589. break;
  12590. }
  12591. }
  12592. //-------------------------------------------
  12593. case ServiceDiscoveryRequest: //21
  12594. {
  12595. if (Proc_iso1_ServiceDiscoveryReq(AcceptFd) == 0)
  12596. {
  12597. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  12598. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12599. }
  12600. else
  12601. {
  12602. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceDiscoveryReqRes: fail");
  12603. Update_V2G_Flow_Status(Other_Fault);
  12604. }
  12605. req_is_responsed = TRUE;
  12606. break;
  12607. }
  12608. case ServiceDiscoveryResponse: //22
  12609. {
  12610. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  12611. {
  12612. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  12613. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12614. }
  12615. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12616. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12617. {
  12618. sprintf(buf_log_evcomm,
  12619. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12620. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12621. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12622. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12623. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12624. }
  12625. else
  12626. {
  12627. break;
  12628. }
  12629. }
  12630. //-------------------------------------------
  12631. case ServiceAndPaymentSelectionRequest: //25
  12632. {
  12633. if (Proc_iso1_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  12634. {
  12635. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  12636. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12637. }
  12638. else
  12639. {
  12640. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceAndPaymentSelectionReqRes: fail");
  12641. Update_V2G_Flow_Status(Other_Fault);
  12642. }
  12643. req_is_responsed = TRUE;
  12644. break;
  12645. }
  12646. case ServiceAndPaymentSelectionResponse://26
  12647. {
  12648. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  12649. {
  12650. Update_V2G_Flow_Status(AuthorizationRequest);
  12651. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12652. }
  12653. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12654. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12655. {
  12656. sprintf(buf_log_evcomm,
  12657. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12658. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12659. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12660. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12661. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12662. }
  12663. else
  12664. {
  12665. break;
  12666. }
  12667. }
  12668. //-------------------------------------------
  12669. //case ContractAuthenticationReq:
  12670. case AuthorizationRequest: //29
  12671. {
  12672. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  12673. {
  12674. Update_V2G_Flow_Status(AuthorizationResponse);
  12675. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12676. }
  12677. else
  12678. {
  12679. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  12680. Update_V2G_Flow_Status(Other_Fault);
  12681. }
  12682. break;
  12683. }
  12684. case AuthorizationResponse: //30
  12685. {
  12686. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  12687. {
  12688. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12689. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  12690. {
  12691. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12692. }
  12693. else
  12694. {
  12695. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  12696. Update_V2G_Flow_Status(Other_Fault);
  12697. }
  12698. req_is_responsed = TRUE;
  12699. break;
  12700. }
  12701. //Check for ChargeParameterDiscoveryReq
  12702. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  12703. {
  12704. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12705. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  12706. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  12707. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12708. ftime(&SeqStartTime);
  12709. #endif
  12710. }
  12711. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12712. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12713. {
  12714. sprintf(buf_log_evcomm,
  12715. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12716. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12717. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12718. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12719. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12720. }
  12721. else
  12722. {
  12723. break;
  12724. }
  12725. }
  12726. //-------------------------------------------
  12727. case ChargeParameterDiscoveryRequest: //35
  12728. {
  12729. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  12730. {
  12731. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  12732. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12733. }
  12734. else
  12735. {
  12736. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  12737. Update_V2G_Flow_Status(Other_Fault);
  12738. }
  12739. req_is_responsed = TRUE;
  12740. break;
  12741. }
  12742. case ChargeParameterDiscoveryResponse: //36
  12743. {
  12744. //STEP 1: Check for Process Timeout
  12745. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12746. ftime(&SeqEndTime);
  12747. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  12748. {
  12749. sprintf(buf_log_evcomm,
  12750. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  12751. DiffTimeb(SeqStartTime, SeqEndTime),
  12752. V2G_SECC_ChargingParameter_Performance_Time);
  12753. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12754. Update_V2G_Flow_Status(Sequence_Timeout);
  12755. break;
  12756. }
  12757. #endif
  12758. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  12759. {
  12760. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12761. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  12762. {
  12763. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12764. }
  12765. else
  12766. {
  12767. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  12768. Update_V2G_Flow_Status(Other_Fault);
  12769. }
  12770. req_is_responsed = TRUE;
  12771. break;
  12772. }
  12773. //STEP 3: Wait for PowerDeliveryReq Message
  12774. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12775. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12776. {
  12777. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  12778. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12779. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  12780. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12781. ftime(&SeqStartTime);
  12782. #endif
  12783. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12784. {
  12785. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12786. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12787. }
  12788. else
  12789. {
  12790. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  12791. Update_V2G_Flow_Status(Other_Fault);
  12792. }
  12793. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12794. ftime(&SeqStartTime);
  12795. #endif
  12796. break;
  12797. }
  12798. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12799. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12800. {
  12801. sprintf(buf_log_evcomm,
  12802. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12803. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12804. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12805. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12806. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12807. }
  12808. else
  12809. {
  12810. break;
  12811. }
  12812. }
  12813. //-------------------------------------------
  12814. case PowerDeliveryRequestStart: //41
  12815. {
  12816. if (Proc_iso1_PowerDeliveryStartReq(AcceptFd) == 0)
  12817. {
  12818. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  12819. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12820. }
  12821. else
  12822. {
  12823. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStartReqRes: fail");
  12824. Update_V2G_Flow_Status(Other_Fault);
  12825. }
  12826. req_is_responsed = TRUE;
  12827. break;
  12828. }
  12829. case PowerDeliveryResponsetStart: //42
  12830. {
  12831. //STEP 1: Check for Process Timeout
  12832. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12833. if (ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  12834. {
  12835. ftime(&SeqEndTime);
  12836. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  12837. {
  12838. sprintf(buf_log_evcomm,
  12839. "Wait for ChargingStatusReq Timeout - (%.02lf of %d ms)\n",
  12840. DiffTimeb(SeqStartTime, SeqEndTime),
  12841. 2000);
  12842. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12843. Update_V2G_Flow_Status(Sequence_Timeout);
  12844. }
  12845. break;
  12846. }
  12847. #endif
  12848. //STEP 2: Wait for ChargingStatusReq Message
  12849. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargingStatusRequest)
  12850. {
  12851. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12852. Update_V2G_Flow_Status(ChargingStatusRequest);
  12853. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]ChargingStatusReq: energy transfering...");
  12854. ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_Start);
  12855. }
  12856. else
  12857. {
  12858. break;
  12859. }
  12860. }
  12861. //-------------------------------------------
  12862. case ChargingStatusRequest: //43
  12863. {
  12864. if (Proc_iso1_ChargingStatusReq(AcceptFd) == 0)
  12865. {
  12866. Update_V2G_Flow_Status(ChargingStatusResponse);
  12867. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12868. }
  12869. else
  12870. {
  12871. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingStatusRes: fail");
  12872. Update_V2G_Flow_Status(Other_Fault);
  12873. }
  12874. req_is_responsed = TRUE;
  12875. break;
  12876. }
  12877. case ChargingStatusResponse: //44
  12878. {
  12879. //STEP 1: Wait for ChargingStatusReq Message
  12880. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargingStatusRequest)
  12881. {
  12882. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12883. if (Proc_iso1_ChargingStatusReq(AcceptFd) == 0)
  12884. {
  12885. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12886. }
  12887. else
  12888. {
  12889. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingStatusRes: fail");
  12890. Update_V2G_Flow_Status(Other_Fault);
  12891. }
  12892. req_is_responsed = TRUE;
  12893. break;
  12894. }
  12895. //STEP 2: Wait for PowerDeliveryReq Message
  12896. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12897. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12898. {
  12899. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12900. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12901. ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_End);
  12902. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12903. ftime(&SeqStartTime);
  12904. #endif
  12905. }
  12906. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12907. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  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
  12917. {
  12918. break;
  12919. }
  12920. }
  12921. //-------------------------------------------
  12922. case PowerDeliveryRequestStop: //49
  12923. {
  12924. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12925. {
  12926. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12927. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12928. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12929. ftime(&SeqStartTime);
  12930. #endif
  12931. }
  12932. else
  12933. {
  12934. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  12935. Update_V2G_Flow_Status(Other_Fault);
  12936. }
  12937. req_is_responsed = TRUE;
  12938. break;
  12939. }
  12940. case PowerDeliveryResponseStop: //50
  12941. {
  12942. //STEP 1: Check for Process Timeout
  12943. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12944. ftime(&SeqEndTime);
  12945. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  12946. {
  12947. sprintf(buf_log_evcomm,
  12948. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12949. DiffTimeb(SeqStartTime, SeqEndTime),
  12950. 2000);
  12951. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  12952. Update_V2G_Flow_Status(Sequence_Timeout);
  12953. break;
  12954. }
  12955. #endif
  12956. //STEP 3: Check for SessionStopReq Message
  12957. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12958. {
  12959. Update_V2G_Flow_Status(SessionStopRequest);
  12960. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12961. }
  12962. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12963. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12964. {
  12965. sprintf(buf_log_evcomm,
  12966. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12967. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12968. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12969. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12970. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12971. }
  12972. else
  12973. {
  12974. break;
  12975. }
  12976. }
  12977. //-------------------------------------------
  12978. case SessionStopRequest: //53
  12979. {
  12980. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12981. {
  12982. Update_V2G_Flow_Status(SessionStopResponse);
  12983. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12984. }
  12985. else
  12986. {
  12987. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  12988. Update_V2G_Flow_Status(Other_Fault);
  12989. }
  12990. req_is_responsed = TRUE;
  12991. //break;
  12992. }
  12993. case SessionStopResponse: //54
  12994. {
  12995. break;
  12996. }
  12997. //-------------------------------------------
  12998. default:
  12999. {
  13000. break;
  13001. }
  13002. }
  13003. }
  13004. }
  13005. /*===========================================================================
  13006. FUNCTION: V2gMsg_Process_iso1
  13007. DESCRIPTION:
  13008. 1. EnergyTransferMode:
  13009. AC_single_phase_core = 0,
  13010. AC_three_phase_core = 1,
  13011. DC_core = 2,
  13012. DC_extended = 3,
  13013. DC_combo_core = 4,
  13014. DC_unique = 5
  13015. iso1EnergyTransferModeType_AC_single_phase_core = 0,
  13016. iso1EnergyTransferModeType_AC_three_phase_core = 1,
  13017. iso1EnergyTransferModeType_DC_core = 2,
  13018. iso1EnergyTransferModeType_DC_extended = 3,
  13019. iso1EnergyTransferModeType_DC_combo_core = 4,
  13020. iso1EnergyTransferModeType_DC_unique = 5
  13021. PRE-CONDITION:
  13022. INPUT:
  13023. 1. V2gFlowStatus
  13024. OUTPUT:
  13025. GLOBAL VARIABLES:
  13026. 1. V2gFlowStatus
  13027. =============================================================================*/
  13028. int V2gMsg_Process_iso1(int AcceptFd, unsigned char EnergyTransferMode)
  13029. {
  13030. switch (EnergyTransferMode)
  13031. {
  13032. case DC_extended:
  13033. {
  13034. V2gMsg_Process_iso1_DC(AcceptFd);
  13035. break;
  13036. }
  13037. case AC_single_phase_core:
  13038. case AC_three_phase_core:
  13039. {
  13040. V2gMsg_Process_iso1_AC(AcceptFd);
  13041. break;
  13042. }
  13043. default:
  13044. {
  13045. sprintf(buf_log_evcomm,
  13046. "[ISO1][Warning]Unexpected EnergyTransferMode(%d)",
  13047. EnergyTransferMode);
  13048. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13049. break;
  13050. }
  13051. }
  13052. }
  13053. /*===========================================================================
  13054. FUNCTION: V2gMsg_Process_iso2_DC
  13055. DESCRIPTION:
  13056. PRE-CONDITION:
  13057. INPUT:
  13058. 1. V2gFlowStatus
  13059. OUTPUT:
  13060. GLOBAL VARIABLES:
  13061. 1. V2gFlowStatus
  13062. =============================================================================*/
  13063. int V2gMsg_Process_iso2_DC(int AcceptFd)
  13064. {
  13065. unsigned char req_is_responsed = FALSE;
  13066. while (req_is_responsed == FALSE)
  13067. {
  13068. //Check if it is in End_Process
  13069. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  13070. {
  13071. break;
  13072. }
  13073. switch(V2gFlowStatus)
  13074. {
  13075. //-------------------------------------------
  13076. case SupportedAppProtocolRequest:
  13077. {
  13078. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  13079. {
  13080. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  13081. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  13082. {
  13083. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13084. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  13085. }
  13086. else
  13087. {
  13088. SAVE_SYS_LOG_MSG_EVCOMM("[Error]supportedAppProtocolResReq: fail");
  13089. Update_V2G_Flow_Status(Other_Fault);
  13090. }
  13091. }
  13092. req_is_responsed = TRUE;
  13093. break;
  13094. }
  13095. case SupportedAppProtocolResponse:
  13096. {
  13097. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  13098. {
  13099. Update_V2G_Flow_Status(SessionSetupRequest);
  13100. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13101. }
  13102. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13103. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13104. {
  13105. sprintf(buf_log_evcomm,
  13106. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13107. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13108. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13109. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13110. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13111. }
  13112. else
  13113. {
  13114. break;
  13115. }
  13116. }
  13117. //-------------------------------------------
  13118. case SessionSetupRequest: //19
  13119. {
  13120. if (Proc_iso2_SessionSetupReq(AcceptFd) == 0)
  13121. {
  13122. Update_V2G_Flow_Status(SessionSetupResponse);
  13123. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13124. }
  13125. else
  13126. {
  13127. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionSetupReqRes: fail");
  13128. Update_V2G_Flow_Status(Other_Fault);
  13129. }
  13130. req_is_responsed = TRUE;
  13131. break;
  13132. }
  13133. case SessionSetupResponse: //20
  13134. {
  13135. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  13136. {
  13137. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  13138. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13139. }
  13140. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13141. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13142. {
  13143. sprintf(buf_log_evcomm,
  13144. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13145. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13146. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13147. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13148. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13149. }
  13150. else
  13151. {
  13152. break;
  13153. }
  13154. }
  13155. #if 0
  13156. //-------------------------------------------
  13157. case ServiceDiscoveryRequest: //21
  13158. {
  13159. if (Proc_iso2_ServiceDiscoveryReq(AcceptFd) == 0)
  13160. {
  13161. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  13162. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13163. }
  13164. else
  13165. {
  13166. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceDiscoveryReqRes: fail");
  13167. Update_V2G_Flow_Status(Other_Fault);
  13168. }
  13169. req_is_responsed = TRUE;
  13170. break;
  13171. }
  13172. case ServiceDiscoveryResponse: //22
  13173. {
  13174. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  13175. {
  13176. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  13177. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13178. }
  13179. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13180. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13181. {
  13182. sprintf(buf_log_evcomm,
  13183. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13184. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13185. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13186. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13187. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13188. }
  13189. else
  13190. {
  13191. break;
  13192. }
  13193. }
  13194. //-------------------------------------------
  13195. case ServiceAndPaymentSelectionRequest: //25
  13196. {
  13197. if (Proc_iso2_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  13198. {
  13199. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  13200. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13201. }
  13202. else
  13203. {
  13204. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceAndPaymentSelectionReqRes: fail");
  13205. Update_V2G_Flow_Status(Other_Fault);
  13206. }
  13207. req_is_responsed = TRUE;
  13208. break;
  13209. }
  13210. case ServiceAndPaymentSelectionResponse: //26
  13211. {
  13212. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  13213. {
  13214. Update_V2G_Flow_Status(AuthorizationRequest);
  13215. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13216. }
  13217. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13218. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13219. {
  13220. sprintf(buf_log_evcomm,
  13221. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13222. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13223. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13224. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13225. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13226. }
  13227. else
  13228. {
  13229. break;
  13230. }
  13231. }
  13232. //-------------------------------------------
  13233. //case ContractAuthenticationReq:
  13234. case AuthorizationRequest: //29
  13235. {
  13236. if (Proc_iso2_AuthenticationReq(AcceptFd) == 0)
  13237. {
  13238. Update_V2G_Flow_Status(AuthorizationResponse);
  13239. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13240. }
  13241. else
  13242. {
  13243. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  13244. Update_V2G_Flow_Status(Other_Fault);
  13245. }
  13246. req_is_responsed = TRUE;
  13247. break;
  13248. }
  13249. case AuthorizationResponse: //30
  13250. {
  13251. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  13252. {
  13253. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13254. if (Proc_iso2_AuthenticationReq(AcceptFd) == 0)
  13255. {
  13256. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13257. }
  13258. else
  13259. {
  13260. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail");
  13261. Update_V2G_Flow_Status(Other_Fault);
  13262. }
  13263. req_is_responsed = TRUE;
  13264. break;
  13265. }
  13266. //Check for ChargeParameterDiscoveryReq
  13267. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  13268. {
  13269. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13270. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  13271. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]ChargeParameterDiscoveryReq: CSU Permission?");
  13272. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13273. ftime(&SeqStartTime);
  13274. #endif
  13275. }
  13276. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13277. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13278. {
  13279. sprintf(buf_log_evcomm,
  13280. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13281. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13282. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13283. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13284. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13285. }
  13286. else
  13287. {
  13288. break;
  13289. }
  13290. }
  13291. //-------------------------------------------
  13292. case ChargeParameterDiscoveryRequest: //35
  13293. {
  13294. if (Proc_iso2_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  13295. {
  13296. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  13297. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13298. }
  13299. else
  13300. {
  13301. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  13302. Update_V2G_Flow_Status(Other_Fault);
  13303. }
  13304. req_is_responsed = TRUE;
  13305. break;
  13306. }
  13307. case ChargeParameterDiscoveryResponse:
  13308. {
  13309. //STEP 1: Check for Process Timeout
  13310. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13311. ftime(&SeqEndTime);
  13312. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  13313. {
  13314. sprintf(buf_log_evcomm,
  13315. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  13316. DiffTimeb(SeqStartTime, SeqEndTime),
  13317. V2G_SECC_ChargingParameter_Performance_Time);
  13318. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13319. Update_V2G_Flow_Status(Sequence_Timeout);
  13320. break;
  13321. }
  13322. #endif
  13323. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  13324. {
  13325. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13326. if (Proc_iso2_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  13327. {
  13328. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13329. }
  13330. else
  13331. {
  13332. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail");
  13333. Update_V2G_Flow_Status(Other_Fault);
  13334. }
  13335. req_is_responsed = TRUE;
  13336. break;
  13337. }
  13338. //STEP 2: Check for CableCheckReq message
  13339. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  13340. {
  13341. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13342. Update_V2G_Flow_Status(CableCheckRequest);
  13343. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CableCheckReqReq: isolated?");
  13344. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  13345. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  13346. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13347. ftime(&SeqStartTime);
  13348. #endif
  13349. }
  13350. //STEP 3: Wait for PowerDeliveryReq Message
  13351. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13352. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13353. {
  13354. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13355. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13356. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  13357. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13358. ftime(&SeqStartTime);
  13359. #endif
  13360. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13361. {
  13362. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13363. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13364. }
  13365. else
  13366. {
  13367. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  13368. Update_V2G_Flow_Status(Other_Fault);
  13369. }
  13370. break;
  13371. }
  13372. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13373. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13374. {
  13375. sprintf(buf_log_evcomm,
  13376. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13377. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13378. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13379. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13380. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13381. }
  13382. else
  13383. {
  13384. break;
  13385. }
  13386. }
  13387. //-------------------------------------------
  13388. case CableCheckRequest: //37
  13389. {
  13390. //STEP 3: Execute Cable Check Process
  13391. if (Proc_iso2_CableCheckReq(AcceptFd) == 0)
  13392. {
  13393. Update_V2G_Flow_Status(CableCheckResponse);
  13394. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13395. }
  13396. else
  13397. {
  13398. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  13399. Update_V2G_Flow_Status(Other_Fault);
  13400. }
  13401. req_is_responsed = TRUE;
  13402. break;
  13403. }
  13404. case CableCheckResponse: //38
  13405. {
  13406. //STEP 1: Check for Process Timeout
  13407. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13408. ftime(&SeqEndTime);
  13409. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  13410. {
  13411. //SAVE_SYS_LOG_MSG_EVCOMM("[CableCheck] end counting...");
  13412. sprintf(buf_log_evcomm,
  13413. "CableCheck Timeout - (%.02lf of %d ms)\n",
  13414. DiffTimeb(SeqStartTime, SeqEndTime),
  13415. V2G_SECC_CableCheck_Performance_Time);
  13416. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13417. Update_V2G_Flow_Status(Sequence_Timeout);
  13418. //Update_ShmStatusCode(); //[To-Do] to be implemented
  13419. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  13420. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13421. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13422. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13423. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  13424. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  13425. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  13426. break;
  13427. }
  13428. #endif
  13429. //STEP 2: Check for CableCheckReq message
  13430. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  13431. {
  13432. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13433. //STEP 3: Execute Cable Check Process
  13434. if (Proc_iso2_CableCheckReq(AcceptFd) == 0)
  13435. {
  13436. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13437. }
  13438. else
  13439. {
  13440. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CableCheckReqRes: fail");
  13441. Update_V2G_Flow_Status(Other_Fault);
  13442. }
  13443. req_is_responsed = TRUE;
  13444. break;
  13445. }
  13446. //STEP 3: Check for PreChargeReq message
  13447. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  13448. {
  13449. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13450. Update_V2G_Flow_Status(PreChargeRequest);
  13451. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]PreChargeReqReq: waiting for precharge voltage...");
  13452. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  13453. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  13454. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13455. ftime(&SeqStartTime);
  13456. #endif
  13457. }
  13458. //STEP 3: Wait for PowerDeliveryReq Message
  13459. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13460. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13461. {
  13462. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13463. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13464. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  13465. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13466. ftime(&SeqStartTime);
  13467. #endif
  13468. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13469. {
  13470. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13471. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13472. }
  13473. else
  13474. {
  13475. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  13476. Update_V2G_Flow_Status(Other_Fault);
  13477. }
  13478. break;
  13479. }
  13480. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13481. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13482. {
  13483. sprintf(buf_log_evcomm,
  13484. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13485. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13486. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13487. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13488. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13489. }
  13490. else
  13491. {
  13492. break;
  13493. }
  13494. }
  13495. //-------------------------------------------
  13496. case PreChargeRequest: //39
  13497. {
  13498. if (Proc_iso2_PreChargeReq(AcceptFd) == 0)
  13499. {
  13500. Update_V2G_Flow_Status(PreChargeResponse);
  13501. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13502. }
  13503. else
  13504. {
  13505. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  13506. Update_V2G_Flow_Status(Other_Fault);
  13507. }
  13508. req_is_responsed = TRUE;
  13509. break;
  13510. }
  13511. case PreChargeResponse: //40
  13512. {
  13513. //STEP 1: Check for Process Timeout
  13514. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13515. ftime(&SeqEndTime);
  13516. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  13517. {
  13518. sprintf(buf_log_evcomm,
  13519. "Precharge Timeout - (%.02lf of %d ms)\n",
  13520. DiffTimeb(SeqStartTime, SeqEndTime),
  13521. V2G_SECC_PreCharge_Performance_Time);
  13522. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13523. Update_V2G_Flow_Status(Sequence_Timeout);
  13524. //Update_ShmStatusCode(); //[To-Do] to be implemented
  13525. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  13526. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13527. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13528. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13529. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  13530. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  13531. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  13532. break;
  13533. }
  13534. #endif
  13535. //STEP 2: Check for PreChargeReq message
  13536. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  13537. {
  13538. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13539. if (Proc_iso2_PreChargeReq(AcceptFd) == 0)
  13540. {
  13541. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13542. }
  13543. else
  13544. {
  13545. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PreChargeReqRes: fail");
  13546. Update_V2G_Flow_Status(Other_Fault);
  13547. }
  13548. req_is_responsed = TRUE;
  13549. break;
  13550. }
  13551. //STEP 3: Check for PowerDeliveryReq message
  13552. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13553. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13554. {
  13555. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13556. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  13557. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  13558. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13559. ftime(&SeqStartTime);
  13560. #endif
  13561. }
  13562. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13563. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13564. {
  13565. sprintf(buf_log_evcomm,
  13566. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13567. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13568. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13569. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13570. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13571. }
  13572. else
  13573. {
  13574. break;
  13575. }
  13576. }
  13577. //-------------------------------------------
  13578. case PowerDeliveryRequestStart: //41
  13579. {
  13580. if (Proc_iso2_PowerDeliveryStartReq(AcceptFd) == 0)
  13581. {
  13582. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  13583. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13584. }
  13585. else
  13586. {
  13587. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStartReqRes: fail");
  13588. Update_V2G_Flow_Status(Other_Fault);
  13589. }
  13590. req_is_responsed = TRUE;
  13591. break;
  13592. }
  13593. case PowerDeliveryResponsetStart: //42
  13594. {
  13595. //STEP 1: Check for Process Timeout
  13596. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13597. if (ccs_exi_doc_ISO2.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  13598. {
  13599. ftime(&SeqEndTime);
  13600. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  13601. {
  13602. sprintf(buf_log_evcomm,
  13603. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  13604. DiffTimeb(SeqStartTime, SeqEndTime),
  13605. 2000);
  13606. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13607. Update_V2G_Flow_Status(Sequence_Timeout);
  13608. }
  13609. break;
  13610. }
  13611. #endif
  13612. //STEP 2: Wait for CurrentDemandReq Message
  13613. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  13614. {
  13615. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13616. Update_V2G_Flow_Status(CurrentDemandRequest);
  13617. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]CurrentDemandReqReq: energy transfering...");
  13618. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  13619. }
  13620. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13621. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13622. {
  13623. sprintf(buf_log_evcomm,
  13624. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13625. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13626. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13627. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13628. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13629. }
  13630. else
  13631. {
  13632. break;
  13633. }
  13634. }
  13635. //-------------------------------------------
  13636. case CurrentDemandRequest: //45,
  13637. {
  13638. if (Proc_iso2_CurrentDemandReq(AcceptFd) == 0)
  13639. {
  13640. Update_V2G_Flow_Status(CurrentDemandResponse);
  13641. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13642. }
  13643. else
  13644. {
  13645. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  13646. Update_V2G_Flow_Status(Other_Fault);
  13647. }
  13648. req_is_responsed = TRUE;
  13649. break;
  13650. }
  13651. case CurrentDemandResponse: //46,
  13652. {
  13653. //STEP 1: Wait for CurrentDemandReq Message
  13654. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  13655. {
  13656. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13657. if (Proc_iso2_CurrentDemandReq(AcceptFd) == 0)
  13658. {
  13659. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13660. }
  13661. else
  13662. {
  13663. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CurrentDemandReqRes: fail");
  13664. Update_V2G_Flow_Status(Other_Fault);
  13665. }
  13666. req_is_responsed = TRUE;
  13667. break;
  13668. }
  13669. //STEP 2: Wait for PowerDeliveryReq Message
  13670. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13671. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13672. {
  13673. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13674. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13675. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  13676. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13677. ftime(&SeqStartTime);
  13678. #endif
  13679. }
  13680. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13681. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13682. {
  13683. sprintf(buf_log_evcomm,
  13684. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13685. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13686. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13687. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13688. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13689. }
  13690. else
  13691. {
  13692. break;
  13693. }
  13694. }
  13695. //-------------------------------------------
  13696. case PowerDeliveryRequestStop: //49,
  13697. {
  13698. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13699. {
  13700. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13701. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13702. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13703. ftime(&SeqStartTime);
  13704. #endif
  13705. }
  13706. else
  13707. {
  13708. SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail");
  13709. Update_V2G_Flow_Status(Other_Fault);
  13710. }
  13711. req_is_responsed = TRUE;
  13712. break;
  13713. }
  13714. case PowerDeliveryResponseStop: //50,
  13715. {
  13716. //STEP 1: Check for Process Timeout
  13717. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13718. ftime(&SeqEndTime);
  13719. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  13720. {
  13721. sprintf(buf_log_evcomm,
  13722. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  13723. DiffTimeb(SeqStartTime, SeqEndTime),
  13724. 2000);
  13725. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13726. Update_V2G_Flow_Status(Sequence_Timeout);
  13727. break;
  13728. }
  13729. #endif
  13730. //STEP 2: Check for WeldingDetectionReq Message
  13731. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  13732. {
  13733. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13734. Update_V2G_Flow_Status(WeldingDetectionRequest);
  13735. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][Rx]WeldingDetectionReq: ongoing...");
  13736. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  13737. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13738. ftime(&SeqStartTime);
  13739. #endif
  13740. }
  13741. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  13742. {
  13743. Update_V2G_Flow_Status(SessionStopRequest);
  13744. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13745. if (Proc_iso2_SessionStopReq(AcceptFd) == 0)
  13746. {
  13747. Update_V2G_Flow_Status(SessionStopResponse);
  13748. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13749. }
  13750. else
  13751. {
  13752. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  13753. Update_V2G_Flow_Status(Other_Fault);
  13754. }
  13755. break;
  13756. }
  13757. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13758. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13759. {
  13760. sprintf(buf_log_evcomm,
  13761. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13762. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13763. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13764. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13765. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13766. }
  13767. else
  13768. {
  13769. break;
  13770. }
  13771. }
  13772. //-------------------------------------------
  13773. case WeldingDetectionRequest: //51,
  13774. {
  13775. if (Proc_iso2_WeldingDetectionReq(AcceptFd) == 0)
  13776. {
  13777. Update_V2G_Flow_Status(WeldingDetectionResponse);
  13778. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13779. }
  13780. else
  13781. {
  13782. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  13783. Update_V2G_Flow_Status(Other_Fault);
  13784. }
  13785. req_is_responsed = TRUE;
  13786. break;
  13787. }
  13788. case WeldingDetectionResponse: //52,
  13789. {
  13790. //STEP 1: Check for Process Timeout
  13791. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13792. ftime(&SeqEndTime);
  13793. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  13794. {
  13795. sprintf(buf_log_evcomm,
  13796. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  13797. DiffTimeb(SeqStartTime, SeqEndTime),
  13798. V2G_SECC_WeldingDetection_Performance_Time);
  13799. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13800. Update_V2G_Flow_Status(Sequence_Timeout);
  13801. break;
  13802. }
  13803. #endif
  13804. //STEP 2: Check for WeldingDetectionReq Message
  13805. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  13806. {
  13807. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13808. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  13809. {
  13810. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13811. }
  13812. else
  13813. {
  13814. SAVE_SYS_LOG_MSG_EVCOMM("[Error]WeldingDetectionReqRes: fail");
  13815. Update_V2G_Flow_Status(Other_Fault);
  13816. }
  13817. req_is_responsed = TRUE;
  13818. break;
  13819. }
  13820. //STEP 3: Check for SessionStopReq Message
  13821. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  13822. {
  13823. Update_V2G_Flow_Status(SessionStopRequest);
  13824. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13825. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  13826. }
  13827. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13828. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13829. {
  13830. sprintf(buf_log_evcomm,
  13831. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13832. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13833. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13834. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13835. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13836. }
  13837. else
  13838. {
  13839. break;
  13840. }
  13841. }
  13842. //-------------------------------------------
  13843. case SessionStopRequest: //53,
  13844. {
  13845. if (Proc_iso2_SessionStopReq(AcceptFd) == 0)
  13846. {
  13847. Update_V2G_Flow_Status(SessionStopResponse);
  13848. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13849. }
  13850. else
  13851. {
  13852. SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail");
  13853. Update_V2G_Flow_Status(Other_Fault);
  13854. }
  13855. req_is_responsed = TRUE;
  13856. //break;
  13857. }
  13858. case SessionStopResponse: //54,
  13859. {
  13860. break;
  13861. }
  13862. #endif
  13863. //-------------------------------------------
  13864. default:
  13865. {
  13866. break;
  13867. }
  13868. }
  13869. }
  13870. }
  13871. /*===========================================================================
  13872. FUNCTION: V2gMsg_Process_iso2_AC
  13873. DESCRIPTION:
  13874. PRE-CONDITION:
  13875. INPUT:
  13876. 1. V2gFlowStatus
  13877. OUTPUT:
  13878. GLOBAL VARIABLES:
  13879. 1. V2gFlowStatus
  13880. =============================================================================*/
  13881. int V2gMsg_Process_iso2_AC(int AcceptFd)
  13882. {
  13883. }
  13884. /*===========================================================================
  13885. FUNCTION: V2gMsg_Process_iso2
  13886. DESCRIPTION:
  13887. PRE-CONDITION:
  13888. INPUT:
  13889. 1. V2gFlowStatus
  13890. OUTPUT:
  13891. GLOBAL VARIABLES:
  13892. 1. V2gFlowStatus
  13893. =============================================================================*/
  13894. int V2gMsg_Process_iso2(int AcceptFd, unsigned char EnergyTransferMode)
  13895. {
  13896. switch (EnergyTransferMode)
  13897. {
  13898. case DC_extended:
  13899. {
  13900. V2gMsg_Process_iso2_DC(AcceptFd);
  13901. break;
  13902. }
  13903. case AC_single_phase_core:
  13904. case AC_three_phase_core:
  13905. {
  13906. V2gMsg_Process_iso2_AC(AcceptFd);
  13907. break;
  13908. }
  13909. default:
  13910. {
  13911. sprintf(buf_log_evcomm,
  13912. "[ISO2][Warning]Unexpected EnergyTransferMode(%d)",
  13913. EnergyTransferMode);
  13914. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13915. break;
  13916. }
  13917. }
  13918. }
  13919. /*===========================================================================
  13920. FUNCTION: V2gMsg_Process
  13921. DESCRIPTION:
  13922. PRE-CONDITION:
  13923. INPUT:
  13924. OUTPUT:
  13925. GLOBAL VARIABLES:
  13926. =============================================================================*/
  13927. int V2gMsg_Process(int AcceptFd)
  13928. {
  13929. int errn = 0;
  13930. switch (ShmCcsData->CommProtocol)
  13931. {
  13932. case V2GT_MSG_PROTOCOL_DIN70121: //0
  13933. {
  13934. V2gMsg_Process_din(AcceptFd);
  13935. break;
  13936. }
  13937. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  13938. {
  13939. V2gMsg_Process_iso1(AcceptFd, ShmCcsData->EnergyTransferMode);
  13940. break;
  13941. }
  13942. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  13943. {
  13944. V2gMsg_Process_iso2(AcceptFd, ShmCcsData->EnergyTransferMode);
  13945. break;
  13946. }
  13947. default:
  13948. {
  13949. sprintf(buf_log_evcomm,
  13950. "[Warning]Unexpected CommProtocol(%d)",
  13951. ShmCcsData->CommProtocol);
  13952. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13953. break;
  13954. }
  13955. }
  13956. return errn;
  13957. }
  13958. /*===========================================================================
  13959. FUNCTION: V2gMsg_Rx
  13960. DESCRIPTION:
  13961. PRE-CONDITION:
  13962. INPUT:
  13963. OUTPUT:
  13964. GLOBAL VARIABLES:
  13965. =============================================================================*/
  13966. int V2gMsg_Rx(int AcceptFd)
  13967. {
  13968. int errn = 0;
  13969. unsigned int packet_size = 0;
  13970. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  13971. packet_size = recv(AcceptFd, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, 0);
  13972. //[CAUTION] Everytime recv() is called, it will take a default time to wait for TCP packets.
  13973. //The more time you call recv(), the more time you will waste here.
  13974. //Here it is suggested that response immediatedly once you receive any packets.
  13975. //For configuring the Rx waiting time, please use setsockopt().
  13976. if(packet_size > 0) //[Joseph] If there is no data, ignore. (TBD)
  13977. {
  13978. //DEBUG_PRINTF_EVCOMM_DETAIL("\n\n Got TCP V2GTP Message: size = %d Bytes\n", packet_size);
  13979. errn = V2gMsgDecoder(V2gtpMsgRxBuf, packet_size, V2gFlowStatus);
  13980. if (errn < 0)
  13981. {
  13982. sprintf(buf_log_evcomm, "[ERROR]V2gMsgDecoder", errn);
  13983. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  13984. }
  13985. }
  13986. return errn;
  13987. }
  13988. /*===========================================================================
  13989. FUNCTION: V2gComm
  13990. DESCRIPTION:
  13991. PRE-CONDITION:
  13992. 1. TCP socket is connected.
  13993. INPUT:
  13994. 1. AcceptFd //TCP Connection ID
  13995. 2. V2gtpMsgRxBuf[] //V2GTP Messages (Header + Payload)
  13996. 3. V2GTP_MSG_RX_BUFFER_SIZE //64*1024 = 65,536 = 65.5K (Bytes)
  13997. OUTPUT:
  13998. GLOBAL VARIABLES:
  13999. 1. V2gtpMsgRxBuf[]
  14000. =============================================================================*/
  14001. int V2gComm(int AcceptFd)
  14002. {
  14003. int errn = 0;
  14004. if (V2gMsg_Rx(AcceptFd) < 0)
  14005. {
  14006. Update_V2G_Flow_Status(Other_Fault);
  14007. errn = -1;
  14008. }
  14009. //following are the response message handling according to status flag
  14010. if (V2gMsg_Process(AcceptFd) < 0)
  14011. {
  14012. errn = -1;
  14013. }
  14014. //Error Check
  14015. //V2G_Error_Monitor();
  14016. return errn;
  14017. }
  14018. /*===========================================================================
  14019. FUNCTION: SdpUdpConnected
  14020. DESCRIPTION:
  14021. PRE-CONDITION:
  14022. INPUT:
  14023. OUTPUT:
  14024. GLOBAL VARIABLES:
  14025. =============================================================================*/
  14026. int SdpUdpConnected()
  14027. {
  14028. int packet_size,Rtn;
  14029. struct sockaddr_in6 ServerAddr,ClientAddr;
  14030. struct V2gtpHeader *header;
  14031. unsigned char *payload;
  14032. if(UdpSock <= 0)
  14033. {
  14034. if ((UdpSock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
  14035. {
  14036. SAVE_SYS_LOG_MSG_EVCOMM("SdpUdpConnected: Fail to open UdpSock");
  14037. return 0;
  14038. }
  14039. memset(&ServerAddr,0, sizeof(struct sockaddr_in));
  14040. ServerAddr.sin6_family = AF_INET6;
  14041. ServerAddr.sin6_addr = in6addr_any;
  14042. ServerAddr.sin6_port = htons(SdpUdpServerPort);
  14043. if(bind(UdpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) <0)
  14044. {
  14045. sprintf(buf_log_evcomm,
  14046. "SdpUdpConnected: Fail to bind UdpSock(%d)",
  14047. UdpSock);
  14048. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14049. close(UdpSock);
  14050. UdpSock = -1;
  14051. return 0;
  14052. }
  14053. sprintf(buf_log_evcomm, "[UdpSock]opend:%d", UdpSock);
  14054. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14055. sprintf(buf_log_evcomm, "[SDP]Req from EVCC: waiting...(%d)", UdpSock);
  14056. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14057. }
  14058. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  14059. memset(&ClientAddr, 0, sizeof(struct sockaddr_in));
  14060. Rtn = sizeof(struct sockaddr_in6);
  14061. packet_size = recvfrom(UdpSock, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *)&ClientAddr, &Rtn);
  14062. if(packet_size > 0)
  14063. {
  14064. header = (struct V2gtpHeader *) V2gtpMsgRxBuf;
  14065. payload = V2gtpMsgRxBuf+sizeof(struct V2gtpHeader);
  14066. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  14067. {
  14068. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n Got UDP packet_size = %d (Bytes)\n", packet_size);
  14069. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***********************************\n");
  14070. DEBUG_PRINTF_EVCOMM_DETAIL("***** Received SDP Packet *****\n");
  14071. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  14072. DEBUG_PRINTF_EVCOMM_DETAIL("ClientAddress=");
  14073. for(Rtn = 0; Rtn < 16; Rtn += 2)
  14074. {
  14075. DEBUG_PRINTF_EVCOMM_DETAIL("%02x%02x:",ClientAddr.sin6_addr.s6_addr[Rtn],ClientAddr.sin6_addr.s6_addr[Rtn+1]);
  14076. }
  14077. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  14078. DEBUG_PRINTF_EVCOMM_DETAIL("ClientPort=%d\n",ClientAddr.sin6_port);
  14079. DEBUG_PRINTF_EVCOMM_DETAIL("ProtocolVersion=%d\n",header->ProtocolVersion);
  14080. DEBUG_PRINTF_EVCOMM_DETAIL("InverseProtocolVersion=0x%x\n",header->InverseProtocolVersion);
  14081. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadType=0x%x\n",htons(header->PayloadType));
  14082. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadLength=0x%x\n",htonl(header->PayloadLength));
  14083. DEBUG_PRINTF_EVCOMM_DETAIL("htons(header->PayloadType)=0x%x\n",htons(header->PayloadType));
  14084. }
  14085. #endif
  14086. if( (header->ProtocolVersion == 0x01) &&
  14087. (header->InverseProtocolVersion == 0xFE) &&
  14088. (htons(header->PayloadType) == V2GTP_PAYLOAD_TYPE_SDP_REQUEST))
  14089. {
  14090. sprintf(buf_log_evcomm, "[SDP][Rx]Req from EVCC: GOT(%d)", UdpSock);
  14091. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14092. DEBUG_PRINTF_EVCOMM_DETAIL("Security=0x%x\n", *(payload + 0));
  14093. DEBUG_PRINTF_EVCOMM_DETAIL("TransportProtocol=0x%x\n", *(payload + 1));
  14094. header->PayloadType = htons(V2GTP_PAYLOAD_TYPE_SDP_RESPONSE);
  14095. header->PayloadLength = htonl(20); //Fixed Length=20
  14096. memset(payload, 0, 20);
  14097. // MAC address[0:2] + FFFE + MAC address[3:5]
  14098. payload[0] = (IPV6_LINK_LOCAL_PREFIX>>8) & 0xFF;
  14099. payload[1] = IPV6_LINK_LOCAL_PREFIX & 0xFF;
  14100. payload[8 ]= CsuMac[0];
  14101. payload[8] ^= 0x02;// bit 1 should complemented.
  14102. payload[9] = CsuMac[1];
  14103. payload[10] = CsuMac[2];
  14104. payload[11] = 0xFF;
  14105. payload[12] = 0xFE;
  14106. payload[13] = CsuMac[3];
  14107. payload[14] = CsuMac[4];
  14108. payload[15] = CsuMac[5];
  14109. //TCP port
  14110. payload[16] = (EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active>>8) & 0xFF;
  14111. payload[17] = EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active & 0xFF;
  14112. payload[18] = SDP_PAYLOAD_SECURITY_NONE; //Security
  14113. payload[19] = SDP_PAYLOAD_TRANS_PROTOCOL_TCP; //Transport protocol
  14114. //[To-Do] Setup the TCP in advance to receive the coming TCP handshke messages after SDP response.
  14115. Rtn = sendto(UdpSock, V2gtpMsgRxBuf, sizeof(struct V2gtpHeader) + htonl(header->PayloadLength), 0, (struct sockaddr *)&ClientAddr, sizeof(struct sockaddr_in6));
  14116. sprintf(buf_log_evcomm, "[SDP][Tx]Res from SECC");
  14117. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14118. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  14119. {
  14120. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response SDP Packet *****\n");
  14121. DEBUG_PRINTF_EVCOMM_DETAIL("Send size=%d\n",Rtn);
  14122. DEBUG_PRINTF_EVCOMM_DETAIL("Destination Address=");
  14123. for(Rtn = 0; Rtn < 16; Rtn++)
  14124. {
  14125. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ", ClientAddr.sin6_addr.s6_addr[Rtn]);
  14126. }
  14127. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  14128. DEBUG_PRINTF_EVCOMM_DETAIL("Destination Port=%d\n", ClientAddr.sin6_port);
  14129. DEBUG_PRINTF_EVCOMM_DETAIL("ProtocolVersion=%d\n", header->ProtocolVersion);
  14130. DEBUG_PRINTF_EVCOMM_DETAIL("InverseProtocolVersion=0x%x\n", header->InverseProtocolVersion);
  14131. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadType=0x%x\n", htons(header->PayloadType));
  14132. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadLength=0x%x\n", htonl(header->PayloadLength));
  14133. DEBUG_PRINTF_EVCOMM_DETAIL("SECC Ipv6 Address=");
  14134. for(Rtn = 0; Rtn < 16; Rtn++)
  14135. {
  14136. DEBUG_PRINTF_EVCOMM_DETAIL("%02x:",payload[Rtn]);
  14137. }
  14138. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  14139. DEBUG_PRINTF_EVCOMM_DETAIL("SECC Port=%d\n", (payload[16]<<8 | payload[17]));
  14140. DEBUG_PRINTF_EVCOMM_DETAIL("Security=0x%x\n", payload[19]);
  14141. DEBUG_PRINTF_EVCOMM_DETAIL("TransportProtocol=0x%x\n", payload[20]);
  14142. }
  14143. #endif
  14144. if(Rtn > 0)
  14145. {
  14146. return 1;
  14147. }
  14148. }
  14149. }
  14150. return 0;
  14151. }
  14152. /*===========================================================================
  14153. FUNCTION: V2gTcpConnected
  14154. DESCRIPTION:
  14155. PRE-CONDITION:
  14156. INPUT:
  14157. OUTPUT:
  14158. GLOBAL VARIABLES:
  14159. =============================================================================*/
  14160. int V2gTcpConnected()
  14161. {
  14162. int packet_size,Rtn,AcceptFd;
  14163. struct sockaddr_in6 ServerAddr,ClientAddr;
  14164. if(TcpSock <= 0)
  14165. {
  14166. if ((TcpSock = socket(PF_INET6, SOCK_STREAM, 0)) < 0)
  14167. {
  14168. sprintf(buf_log_evcomm,
  14169. "V2gTcpConnected: Fail to open TcpSock (%s)",
  14170. strerror(errno));
  14171. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14172. usleep(100000); //100ms
  14173. return 0;
  14174. }
  14175. fcntl(TcpSock, F_SETFL, O_NONBLOCK); //set to O_NONBLOCK
  14176. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]socket set: DONE");
  14177. memset(&ServerAddr,0, sizeof(struct sockaddr_in));
  14178. ServerAddr.sin6_family = PF_INET6;
  14179. ServerAddr.sin6_addr = in6addr_any;
  14180. ServerAddr.sin6_port = htons(EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  14181. //ServerAddr.sin6_port = htons(SdpTcpServerPort + (rand() % 10) + 1);
  14182. //printf("SdpTcpServerPort = %d(DEC)\n", htons(ServerAddr.sin6_port));
  14183. if(bind(TcpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) < 0)
  14184. {
  14185. sprintf(buf_log_evcomm,
  14186. "V2gTcpConnected: Fail to bind TcpSock (%s), SdpTcpServerPort = %d",
  14187. strerror(errno),
  14188. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active
  14189. );
  14190. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14191. //Change to another TCP port
  14192. /*
  14193. memset(&ServerAddr, 0, sizeof(struct sockaddr_in));
  14194. ServerAddr.sin6_family = PF_INET6;
  14195. ServerAddr.sin6_addr = in6addr_any;
  14196. //ServerAddr.sin6_port = htons(SdpTcpServerPort + (rand() % 1000) + 1);
  14197. ServerAddr.sin6_port = htons(EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  14198. */
  14199. if(bind(TcpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) < 0)
  14200. {
  14201. sprintf(buf_log_evcomm,
  14202. "V2gTcpConnected: Fail to bind TcpSock (%s), SdpTcpServerPort = %d",
  14203. strerror(errno),
  14204. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active
  14205. );
  14206. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14207. usleep(100000); //100ms
  14208. close(TcpSock);
  14209. TcpSock = -1;
  14210. return 0;
  14211. }
  14212. }
  14213. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]blid: DONE");
  14214. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]listen: START");
  14215. if(listen(TcpSock, 1) == -1) //only accept one connection
  14216. {
  14217. sprintf(buf_log_evcomm,
  14218. "V2gTcpConnected: Fail to listen TcpSock (%s)",
  14219. strerror(errno));
  14220. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14221. usleep(100000); //100ms
  14222. close(TcpSock);
  14223. TcpSock = -1;
  14224. return 0;
  14225. }
  14226. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]listen: DONE");
  14227. sprintf(buf_log_evcomm, "[TCP]TcpSock: opened(%d), port=%d", TcpSock, htons(ServerAddr.sin6_port));
  14228. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14229. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]accept: START");
  14230. }
  14231. Rtn = sizeof(struct sockaddr_in6);
  14232. if((AcceptFd = accept(TcpSock, (struct sockaddr *)&ClientAddr, &Rtn)) == -1)
  14233. {
  14234. static BOOL tmp = 0;
  14235. if (tmp = 0)
  14236. {
  14237. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]Wait TCP connection...");
  14238. tmp = 1;
  14239. }
  14240. else
  14241. {
  14242. //DEBUG_PRINTF_EVCOMM_DETAIL(".");
  14243. }
  14244. return 0;
  14245. }
  14246. SAVE_SYS_LOG_MSG_EVCOMM("[TCP]accept: DONE\n");
  14247. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  14248. {
  14249. DEBUG_PRINTF_EVCOMM_DETAIL("\n\nAccept one TCP connection:\n");
  14250. DEBUG_PRINTF_EVCOMM_DETAIL("AcceptFd=%d\n",AcceptFd);
  14251. DEBUG_PRINTF_EVCOMM_DETAIL("ClientAddress=");
  14252. for(Rtn = 0; Rtn < 16; Rtn += 2)
  14253. {
  14254. DEBUG_PRINTF_EVCOMM_DETAIL("%02x%02x:", ClientAddr.sin6_addr.s6_addr[Rtn], ClientAddr.sin6_addr.s6_addr[Rtn+1]);
  14255. }
  14256. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  14257. DEBUG_PRINTF_EVCOMM_DETAIL("ClientPort=%d\n", ClientAddr.sin6_port);
  14258. }
  14259. #endif
  14260. return AcceptFd;
  14261. }
  14262. /*===========================================================================
  14263. FUNCTION: End_Process
  14264. DESCRIPTION:
  14265. PRE-CONDITION:
  14266. 1. <CAUTION> This function could only be used in SeccComm fork2.
  14267. INPUT:
  14268. OUTPUT:
  14269. GLOBAL VARIABLES:
  14270. =============================================================================*/
  14271. int End_Process()
  14272. {
  14273. if(EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  14274. {
  14275. SAVE_SYS_LOG_MSG_EVCOMM("End_Process has been triggered by another event.");
  14276. return -1;
  14277. }
  14278. SAVE_SYS_LOG_MSG_EVCOMM("[End_Process]entering...");
  14279. //STEP 1: Ask CSU to Stop
  14280. EVCOMM_SYS_INFO.End_Process_inused = TRUE;
  14281. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  14282. EVCOMM_SYS_INFO.ConnectorLocked = FALSE;
  14283. ShmInternalComm->ChargingPermission = FALSE;
  14284. //Step 2: Close sockets
  14285. SAVE_SYS_LOG_MSG_EVCOMM("[End_Process]close sockets...");
  14286. if(RawSock > 0)
  14287. {
  14288. close(RawSock);
  14289. }
  14290. if(UdpSock > 0)
  14291. {
  14292. close(UdpSock);
  14293. }
  14294. if(TcpSock > 0)
  14295. {
  14296. close(TcpSock);
  14297. close(TcpAcceptFd);
  14298. }
  14299. RawSock = UdpSock = TcpSock = TcpAcceptFd = -1;
  14300. //STEP 3: Switch to State E
  14301. //SwitchCpStateE(ENABLE);
  14302. //STEP 4: Close tcpdump
  14303. Sniffer_Tcpdump(DISABLE);
  14304. //STEP 5: Keep 100% PWM for 5 seconds
  14305. OutputCpPwmDuty(100);
  14306. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 5");
  14307. sleep(1);
  14308. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 4");
  14309. sleep(1);
  14310. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 3");
  14311. sleep(1);
  14312. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 2");
  14313. sleep(1);
  14314. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 1");
  14315. sleep(1);
  14316. SAVE_SYS_LOG_MSG_EVCOMM("PWM 100\% countdown: 0");
  14317. AttenProfileCnt = 0;
  14318. init_appHandEXIDocument(&ccs_handshake);
  14319. // Qca7kPowerReset(); //reset QCA7000 /* +++ 20200808, vern, should disconnected PLC connection after session stop ---*/
  14320. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  14321. {
  14322. SAVE_SYS_LOG_MSG_EVCOMM("[End_Process]1st sync...");
  14323. system("sync");
  14324. }
  14325. #endif
  14326. //STEP 4: Switch to State E
  14327. //Keep State E for 5 seconds
  14328. #if 0
  14329. SwitchCpStateE(ENABLE); //Set PWM Duty as 0 and set State as E (0V)
  14330. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 5");
  14331. sleep(1);
  14332. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 4");
  14333. sleep(1);
  14334. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 3");
  14335. sleep(1);
  14336. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 2");
  14337. sleep(1);
  14338. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 1");
  14339. sleep(1);
  14340. SAVE_SYS_LOG_MSG_EVCOMM("State E countdown: 0");
  14341. #endif
  14342. //Reset Memory
  14343. unsigned char SlaveAddress_backup;
  14344. unsigned int matched_backup;
  14345. //unsigned char state_backup;
  14346. SAVE_SYS_LOG_MSG_EVCOMM("[CCS Board]soft reset (closing SeccComm)...");
  14347. SAVE_SYS_LOG_MSG_EVCOMM("---------------------------------------------");
  14348. SAVE_SYS_LOG_MSG_EVCOMM("-- EVCOMM: END --");
  14349. SAVE_SYS_LOG_MSG_EVCOMM("---------------------------------------------\n");
  14350. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  14351. {
  14352. SAVE_SYS_LOG_MSG_EVCOMM("[End_Process]2nd sync...");
  14353. system("sync");
  14354. }
  14355. #endif
  14356. system("sleep 1");
  14357. //Backup CsuComm flags
  14358. SlaveAddress_backup = ShmInternalComm->SlaveAddress;
  14359. matched_backup = CSUCOMMDC_TASK_FLAG.matched;
  14360. //state_backup = Check_V2G_Flow_Status();
  14361. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  14362. memset(V2gtpMsgTxBuf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14363. memset(&ccs_handshake, 0, sizeof(struct appHandEXIDocument));
  14364. memset(&ccs_exi_doc_DIN, 0, sizeof(struct dinEXIDocument));
  14365. memset(V2GTP_Tx_buf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14366. memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  14367. memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
  14368. memset(ShmInternalComm, 0, sizeof(struct InternalComm));
  14369. memset(ShmCcsData, 0, sizeof(struct CcsData));
  14370. //Resume CsuComm flags
  14371. ShmInternalComm->SlaveAddress = SlaveAddress_backup;
  14372. CSUCOMMDC_TASK_FLAG.matched = matched_backup;
  14373. Sniffer_Candump(DISABLE);
  14374. Sniffer_Candump(ENABLE);
  14375. //memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo)); //EVCOMM_SYS_INFO.End_Process_inused = FALSE;
  14376. //EVCOMM_SYS_INFO.End_Process_inused = TRUE;
  14377. //Update_V2G_Flow_Status(state_backup);
  14378. //CP_Detection_Pid = 0;
  14379. //PP_Detection_Pid = 0;
  14380. //Error_Monitor_Pid = 0;
  14381. /* while(CheckConnectorPlugIn() != TRUE)
  14382. {
  14383. sleep(1);
  14384. }*/
  14385. free(V2gtpMsgRxBuf);
  14386. free(V2gtpMsgTxBuf);
  14387. //DetachShareMemory();
  14388. system("cd /root;./reset_soft.sh");
  14389. while(1)
  14390. {
  14391. //wait for CSU configrm
  14392. }
  14393. }
  14394. /*===========================================================================
  14395. FUNCTION: Parameters_Init
  14396. DESCRIPTION:
  14397. PRE-CONDITION:
  14398. INPUT:
  14399. OUTPUT:
  14400. GLOBAL VARIABLES:
  14401. =============================================================================*/
  14402. int Parameters_Init()
  14403. {
  14404. //Step 0: Generate random number
  14405. unsigned int value_random;
  14406. struct timeb time_seed;
  14407. ftime(&time_seed);
  14408. srand(time_seed.millitm);
  14409. //Step 1: Init SDP TCP Port
  14410. value_random = rand();
  14411. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active = (unsigned short)(SdpTcpServerPort + (value_random % 10000) + 1);
  14412. sprintf(buf_log_evcomm,
  14413. "[Init]TCP Port:OK(%d)",
  14414. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  14415. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14416. //Step 2: Init SessionID
  14417. value_random = rand();
  14418. memcpy(&EVCOMM_SYS_INFO.SessionID[0], &value_random, 4);
  14419. value_random = rand();
  14420. memcpy(&EVCOMM_SYS_INFO.SessionID[4], &value_random, 4);
  14421. sprintf(buf_log_evcomm,
  14422. "[Init]SessionID:OK(%02X%02X%02X%02X%02X%02X%02X%02X)",
  14423. EVCOMM_SYS_INFO.SessionID[0],
  14424. EVCOMM_SYS_INFO.SessionID[1],
  14425. EVCOMM_SYS_INFO.SessionID[2],
  14426. EVCOMM_SYS_INFO.SessionID[3],
  14427. EVCOMM_SYS_INFO.SessionID[4],
  14428. EVCOMM_SYS_INFO.SessionID[5],
  14429. EVCOMM_SYS_INFO.SessionID[6],
  14430. EVCOMM_SYS_INFO.SessionID[7]);
  14431. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14432. }
  14433. /*===========================================================================
  14434. FUNCTION: main
  14435. DESCRIPTION:
  14436. PRE-CONDITION:
  14437. INPUT:
  14438. OUTPUT:
  14439. GLOBAL VARIABLES:
  14440. =============================================================================*/
  14441. int main(int argc, char *argv[])
  14442. {
  14443. unsigned char Rtn;
  14444. //Initialization
  14445. if(ShareMemory_Init()==0)
  14446. {
  14447. system("reboot -f");
  14448. sleep(5);
  14449. system("reboot -f");
  14450. }
  14451. memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
  14452. if(RawSock > 0)
  14453. {
  14454. close(RawSock);
  14455. }
  14456. if(UdpSock > 0)
  14457. {
  14458. close(UdpSock);
  14459. }
  14460. if(TcpSock > 0)
  14461. {
  14462. close(TcpSock);
  14463. }
  14464. RawSock = UdpSock = TcpSock = -1;
  14465. Update_V2G_Flow_Status(IDLE);
  14466. SAVE_SYS_LOG_MSG_EVCOMM("---------------------------------------------");
  14467. SAVE_SYS_LOG_MSG_EVCOMM("-- EVCOMM: START --");
  14468. SAVE_SYS_LOG_MSG_EVCOMM("---------------------------------------------\n");
  14469. //Print Linux Kernel Version
  14470. sprintf(buf_log_evcomm, "\nLinux Image SHA1: %s\n", LINUX_IMAGE_VERSION);
  14471. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14472. //Print Hardware Version
  14473. sprintf(buf_log_evcomm, "HW: %s\n", HARDWARE_VERSION);
  14474. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14475. //Print Firmware Version
  14476. sprintf(buf_log_evcomm, "FW: %s\n", FIRMWARE_VERSION);
  14477. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14478. SAVE_SYS_LOG_MSG_EVCOMM("init...");
  14479. //Init V2G TCP/IPv6 packets buffer
  14480. V2gtpMsgRxBuf = (unsigned char *)malloc(V2GTP_MSG_RX_BUFFER_SIZE);
  14481. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  14482. V2gtpMsgTxBuf = (unsigned char *)malloc(V2GTP_MSG_TX_BUFFER_SIZE);
  14483. memset(V2gtpMsgTxBuf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14484. //Release State E Control
  14485. SwitchCpStateE(DISABLE);
  14486. OutputCpPwmDuty(100);
  14487. //start to detect CP pilot state
  14488. CP_Detection_Pid = 0;
  14489. CP_Detection(); //fork1
  14490. SAVE_SYS_LOG_MSG_EVCOMM("[fork1]CP Detection: ON");
  14491. //start to detect errors
  14492. Error_Monitor(); //fork2
  14493. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Error Monitor: ON");
  14494. //start to detect PP
  14495. PP_Detection_Pid = 0;
  14496. #if (PP_PROTECTION_MECHANISM == ENABLE)
  14497. PP_Detection();
  14498. SAVE_SYS_LOG_MSG_EVCOMM("[fork3]PP Detection: ON");
  14499. #else
  14500. SAVE_SYS_LOG_MSG_EVCOMM("[fork3]PP Detection: OFF");
  14501. #endif
  14502. //Init communication parameters
  14503. GetEthMac(QcaInterface, CsuMac);
  14504. AttenProfileCnt = 0;
  14505. init_appHandEXIDocument(&ccs_handshake);
  14506. //Init Energy transfer mode
  14507. //[To-Do] Parsing Model Name
  14508. ShmCcsData->EnergyTransferMode = CCS_ENERGY_TRANSFER_MODE;
  14509. struct ChargingInfoData *ccs;
  14510. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  14511. Parameters_Init();
  14512. Sniffer_Tcpdump(ENABLE);
  14513. #if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  14514. sleep(1); //wait for tcpdump getting ready
  14515. #endif
  14516. SAVE_SYS_LOG_MSG_EVCOMM("[Init]DONE");
  14517. while(1)
  14518. {
  14519. //DEBUG_PRINTF_EVCOMM_DETAIL("\nV2gFlowStatus = %d\n", V2gFlowStatus);
  14520. //if((ShmInternalComm->ChargingPermission == 0x01) && (CheckConnectorPlugIn() == 1))
  14521. //if((CheckConnectorPlugIn() == TRUE) && (ShmInternalComm->ChargingPermission == TRUE))
  14522. //if(ShmInternalComm->ChargingPermission == 0x01)
  14523. //if(CheckConnectorPlugIn() == TRUE)
  14524. if (EVCOMM_SYS_INFO.End_Process_inused == FALSE)
  14525. {
  14526. if(V2gFlowStatus < SLACC_SDP_UDP_Connection)
  14527. {
  14528. SlacComm();
  14529. }
  14530. else if(V2gFlowStatus == SLACC_SDP_UDP_Connection)
  14531. {
  14532. if(SdpUdpConnected() == 1)
  14533. {
  14534. Update_V2G_Flow_Status(SLACC_SDP_TCP_Connection);
  14535. continue;
  14536. }
  14537. SlacComm(); //TC_SECC_VTB_CmSlacMatch_004
  14538. ftime(&SeqEndTime);
  14539. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_join)
  14540. {
  14541. sprintf(buf_log_evcomm,
  14542. "Wait SLACC_SDP_UDP_Connection Timeout - TT_match_join (%.02lf of %d ms)\n",
  14543. DiffTimeb(SeqStartTime, SeqEndTime),
  14544. TT_match_join);
  14545. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14546. Update_V2G_Flow_Status(Sequence_Timeout);
  14547. //Update_ShmStatusCode(); //[To-Do] to be implemented
  14548. //CCS_SECC_TIMEOUT_SLACC_SDP_UDP_TT_match_join (023823)
  14549. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  14550. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  14551. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  14552. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  14553. ShmStatusCodeData->PresentStatusCode[0][4] = 2;
  14554. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  14555. //CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  14556. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  14557. }
  14558. }
  14559. else if(V2gFlowStatus == SLACC_SDP_TCP_Connection)
  14560. {
  14561. if((TcpAcceptFd = V2gTcpConnected()) > 0)
  14562. {
  14563. Update_V2G_Flow_Status(SupportedAppProtocolRequest);
  14564. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14565. continue;
  14566. }
  14567. SlacComm();
  14568. ftime(&SeqEndTime);
  14569. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_join)
  14570. {
  14571. sprintf(buf_log_evcomm,
  14572. "Wait SLACC_SDP_TCP_Connection Timeout - TT_match_join (%.02lf / %d ms)",
  14573. DiffTimeb(SeqStartTime, SeqEndTime),
  14574. TT_match_join);
  14575. SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
  14576. Update_V2G_Flow_Status(Sequence_Timeout);
  14577. //Update_ShmStatusCode(); //[To-Do] to be implemented
  14578. //CCS_SECC_TIMEOUT_SLACC_SDP_TCP_TT_match_join (023824)
  14579. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  14580. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  14581. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  14582. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  14583. ShmStatusCodeData->PresentStatusCode[0][4] = 2;
  14584. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  14585. //CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  14586. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  14587. }
  14588. }
  14589. else if(V2gFlowStatus <= SessionStopResponse)
  14590. {
  14591. if (V2gComm(TcpAcceptFd) < 0)
  14592. {
  14593. //error occours
  14594. }
  14595. }
  14596. else if (V2gFlowStatus >= Performance_Timeout)
  14597. {
  14598. //End_Process
  14599. }
  14600. else
  14601. {
  14602. //null
  14603. }
  14604. }
  14605. } //while
  14606. }//main while