1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682 |
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <stdint.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #include "../../define.h"
- #include "Config.h"
- #include <stdbool.h>
- #include <dirent.h>
- #include "timeout.h"
- #if defined DD360 ||defined DD360Audi || defined DD360ComBox
- #include "AudiCust.h"
- #endif //defined DD360Audi
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
- #define PASS 1
- #define FAIL -1
- #define MODELNAME_FAIL 0
- #define BUFFER_SIZE 128
- #define YES 1
- #define NO 0
- #define NORMAL 0
- #define ABNORMAL 1
- #define EQUAL 0
- #define BTN_RELEASE 0
- #define BTN_PRESS 1
- #define MAX_BUF 64
- #define MtdBlockSize 0x600000
- #define SYSFS_GPIO_DIR "/sys/class/gpio"
- #define UPGRADE_FAN 0x02
- #if defined DD360 ||defined DD360Audi || defined DD360ComBox
- #define UPGRADE_RB 0x09 //0x09 for DD360 dispenser
- #else
- #define UPGRADE_RB 0x03 //other module use
- #endif //defined DD360 || defined DD360Audi
- #define UPGRADE_PRI 0x04
- #define UPGRADE_AC 0x05
- #define UPGRADE_LED 0x06
- #define SYSTEM_MIN_VOL 80 //150
- #define MIN_OUTPUT_CUR 0
- #define AC_OUTPUT_VOL 220
- #define NO_DEFINE 255
- #define DEFAULT_AC_INDEX 2
- #define PSU_MIN_CUR 100
- #define DB_FILE "/Storage/ChargeLog/localCgargingRecord.db"
- #define uSEC_VAL 1000000
- #define SELFTEST_TIMEOUT 60//45
- #define AUTHORIZE_TIMEOUT 15//30
- #define AUTHORIZE_COMP_TIMEOUT 3
- #define AUTHORIZE_FAIL_TIMEOUT 3
- #define AUTHORIZE_STOP_TIMEOUT 30
- #define RETURN_TO_CHARGING_PAGE 30
- #define GUN_PREPARE_TIMEOUT 30
- #define GUN_EV_WAIT_TIMEOUT 120
- #define GUN_EVSE_WAIT_TIMEOUT 60
- #define GUN_COMP_WAIT_TIMEOUT 10
- #define GUN_PRECHARGING_TIMEOUT 60
- typedef struct StLedConfig {
- //OutputDrvValue[0]
- uint8_t LeftButtonLed: 1; //bit 0, H: ON, L:OFF
- uint8_t RightButtonLed: 1; //bit 1, H: ON, L:OFF
- uint8_t GreenLED: 1; //bit 2, H: ON, L:OFF
- uint8_t YellowLED: 1; //bit 3, H: ON, L:OFF
- uint8_t RedLED: 1; //bit 4, H: ON, L:OFF
- uint8_t SystemLed4: 1; //bit 5, H: ON, L:OFF
- uint8_t AcContactor: 1; //bit 6, H: ON, L:OFF
- uint8_t Reserved: 1; //bit 7 reserved
- } LedConfig;
- char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
- unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
- int whileLoopTime = 10000; // 10 ms
- int wtdFd = -1;
- byte _authorizeIndex = NO_DEFINE;
- #if defined METER_ENABLE
- bool relayWeldingCheck = false;
- bool relayDrivingCheck = false;
- #endif //defined METER_ENABLE
- bool IsAuthorizingMode();
- void ClearAuthorizedFlag();
- bool isDetectPlugin();
- void ClearDetectPluginFlag();
- int mystrcmp(unsigned char *p1, unsigned char *p2);
- long long DiffTimebWithNow(struct timeb ST);
- unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
- void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
- void ChargingTerminalProcess(byte gunIndex);
- void ChkPrimaryStatus();
- void StartSystemTimeoutDet(unsigned char flag);
- void StopSystemTimeoutDet();
- void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag);
- void StopGunInfoTimeoutDet(unsigned char gunIndex);
- int StoreLogMsg_1(const char *fmt, ...);
- unsigned long GetTimeoutValue(struct timeval _sour_time);
- void gpio_set_value(unsigned int gpio, unsigned int value);
- void PRINTF_FUNC(char *string, ...);
- void ChangeGunSelectByIndex(byte sel);
- void InformOcppErrOccur(byte codeType);
- void RecordAlarmCode(byte gunIndex, char *code);
- void RecordWarningCode(byte gunIndex, char *code);
- void ReleaseWarningCodeByString(byte gunIndex, char *code);
- void ReleaseAlarmCode(byte gunIndex);
- int DB_Open(sqlite3 *db);
- int DB_Insert_Record(sqlite3 *db, int gun_index);
- int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable);
- int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index);
- #define log_info(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- #define log_warn(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- #define log_error(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct PsuData *ShmPsuData;
- struct CHAdeMOData *ShmCHAdeMOData;
- struct GBTData *ShmGBTData;
- struct CcsData *ShmCcsData;
- struct PrimaryMcuData *ShmPrimaryMcuData;
- struct FanModuleData *ShmFanModuleData;
- struct RelayModuleData *ShmRelayModuleData;
- struct LedModuleData *ShmLedModuleData;
- struct OCPP16Data *ShmOCPP16Data;
- struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
- struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- #if defined METER_ENABLE
- struct MeterInformation *ShmCsuMeterData;
- struct DcCommonInformation *ShmDcCommonData;
- #endif //defined METER_ENABLE
- #if defined DD360 ||defined DD360Audi || defined DD360ComBox
- static AudiCustInfo *gAudiCustInfo = NULL; //Jerry add
- #endif //defined DD360Audi
- // for initial index to check EV board type is correct
- byte _gunIndex = 0;
- byte _acgunIndex = 0;
- byte _chademoIndex = 0;
- byte _ccsIndex = 0;
- byte _gb_Index = 0;
- byte _ac_Index = 0;
- byte bd0_1_status = 0;
- byte bd0_2_status = 0;
- byte bd1_1_status = 0;
- byte bd1_2_status = 0;
- static uint8_t restartFlag = 0;
- bool isCardScan = false;
- bool isModelNameMatch = true;
- int rfidFd = -1;
- char *rfidPortName = "/dev/ttyS2";
- char *fwVersion = "V1.07.00.0000.00"; // "V0.16.00.0000.00";
- sqlite3 *localDb;
- bool isDb_ready;
- #if defined DD360Audi
- //------------------------------------------------------------------------------
- //--- share memory value ---
- //------------------------------------------------------------------------------
- static void changeLcmPage(uint8_t index)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = index;
- }
- static uint8_t getCurLcmPage(void)
- {
- return ShmSysConfigAndInfo->SysInfo.SystemPage;
- }
- //------------------------------------------------------------------------------
- static void destroySelGun(uint8_t curGun)
- {
- uint8_t i = 0;
- uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
- //for status timeout
- if (curGun == DESTROY_ALL_SEL) {
- gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
- gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
- log_info("destroy all gun = %d, %d\r\n",
- gAudiCustInfo->SelGunInfo.LeftGun,
- gAudiCustInfo->SelGunInfo.RightGun);
- for (i = 0; i < totalGun; i++) {
- StopGunInfoTimeoutDet(i);
- memset(&gAudiCustInfo->PricesInfo[i], 0, sizeof(PricesInfo));
- }
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- //changeLcmPage(_LCM_SELECT_GUN);
- return;
- }
- //for charging timeout or complete
- if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
- if (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
- gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
- changeLcmPage(_LCM_SELECT_GUN);
- }
- gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
- StopGunInfoTimeoutDet(LEFT_GUN_NUM);
- if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
- ClearAuthorizedFlag();
- }
- log_info("destroy left gun, cur page = %d\r\n", getCurLcmPage());
- if (getCurLcmPage() == ShmSysConfigAndInfo->SysInfo.SystemPage) {
- log_info("clear left balance\r\n");
- memset(&gAudiCustInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
- gAudiCustInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
- }
- }
- if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
- if (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
- gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
- changeLcmPage(_LCM_SELECT_GUN);
- }
- gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
- StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
- if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
- ClearAuthorizedFlag();
- }
- log_info("destroy right gun, cur page = %d\r\n", getCurLcmPage());
- if (getCurLcmPage() == ShmSysConfigAndInfo->SysInfo.SystemPage) {
- log_info("clear right balance\r\n");
- memset(&gAudiCustInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
- gAudiCustInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
- }
- }
- }
- static int waitRightGunPlugIt(uint8_t curGun)
- {
- if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
- return PASS;
- }
- return FAIL;
- }
- static int waitLeftGunPlugIt(uint8_t curGun)
- {
- if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
- return PASS;
- }
- return FAIL;
- }
- static void setSelGunWaitToAuthor(uint8_t curSel)
- {
- if (curSel == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
- gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
- //printf("setSelGunWaitToAuthor left\r\n");
- StopGunInfoTimeoutDet(curSel);
- } else if (curSel == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
- gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
- //printf("setSelGunWaitToAuthor right\r\n");
- StopGunInfoTimeoutDet(curSel);
- }
- }
- static int getConfirmSelectedGun(uint8_t curSel)
- {
- if (((curSel == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
- ((curSel == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
- return PASS;
- }
- return FAIL;
- }
- static void confirmSelGun(uint8_t selGun)
- {
- if (selGun == LEFT_GUN_NUM) {
- gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
- StopGunInfoTimeoutDet(selGun);
- //printf("confirmSelGun left\r\n");
- } else if (selGun == RIGHT_GUN_NUM) {
- gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
- StopGunInfoTimeoutDet(selGun);
- //printf("confirmSelGun right\r\n");
- }
- changeLcmPage(_LCM_IDLE);
- StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
- }
- #endif // defined DD360Audi
- static void startPrimaryLedIndicatorCtrlFork(void)
- {
- pid_t pid = fork();
- if (pid == 0) {
- uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
- uint8_t gunIndex = 0;
- int isContinue = 1;
- LedConfig *pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
- while (isContinue) {
- for (gunIndex = 0; gunIndex < totalGun; gunIndex++) {
- //printf("led indicator status = %d\r\n", chargingInfo[gunIndex]->SystemStatus);
- //printf("level = %d\r\n", ShmSysConfigAndInfo->SysWarningInfo.Level);
- switch (chargingInfo[gunIndex]->SystemStatus) {
- case S_BOOTING:
- if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE) {
- //DoComm tcp disconnect
- if (pLedConfig->RedLED == YES ||
- pLedConfig->YellowLED == YES ||
- pLedConfig->GreenLED == YES) {
- pLedConfig->RedLED = NO;
- pLedConfig->YellowLED = NO;
- pLedConfig->GreenLED = NO;
- } else {
- pLedConfig->RedLED = YES;
- pLedConfig->YellowLED = YES;
- pLedConfig->GreenLED = YES;
- }
- break;
- }
- pLedConfig->RedLED = YES;
- pLedConfig->YellowLED = YES;
- pLedConfig->GreenLED = YES;
- break;
- case S_IDLE:
- //DoComm connected and system idle
- pLedConfig->RedLED = NO;
- pLedConfig->YellowLED = NO;
- pLedConfig->GreenLED = YES;
- break;
- case S_RESERVATION:
- case S_AUTHORIZING:
- case S_REASSIGN_CHECK:
- case S_REASSIGN:
- case S_PREPARNING:
- case S_PREPARING_FOR_EV:
- case S_PREPARING_FOR_EVSE:
- case S_CCS_PRECHARGE_ST0:
- case S_CCS_PRECHARGE_ST1:
- //precharging status
- if (pLedConfig->GreenLED == YES) {
- pLedConfig->GreenLED = NO;
- } else {
- pLedConfig->GreenLED = YES;
- }
- break;
- case S_CHARGING:
- pLedConfig->RedLED = NO;
- if (pLedConfig->YellowLED == YES) {
- pLedConfig->YellowLED = NO;
- } else {
- pLedConfig->YellowLED = YES;
- }
- pLedConfig->GreenLED = NO;
- break;
- case S_ALARM:
- case S_TERMINATING:
- case S_COMPLETE:
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
- pLedConfig->YellowLED = NO;
- pLedConfig->GreenLED = NO;
- if (pLedConfig->RedLED == YES) {
- pLedConfig->RedLED = NO;
- } else {
- pLedConfig->RedLED = YES;
- }
- } else {
- pLedConfig->RedLED = NO;
- pLedConfig->YellowLED = YES;
- pLedConfig->GreenLED = NO;
- }
- break;
- case S_MAINTAIN:
- case S_FAULT:
- pLedConfig->YellowLED = NO;
- pLedConfig->GreenLED = NO;
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
- if (pLedConfig->RedLED == YES) {
- pLedConfig->RedLED = NO;
- } else {
- pLedConfig->RedLED = YES;
- }
- }
- break;
- case S_BOOKING:
- case S_DEBUG:
- case S_UPDATE:
- case S_NONE:
- break;
- }
- usleep(500000);
- }//switch
- }//for
- }//while
- }
- //================================================
- // initial can-bus
- //================================================
- int InitCanBus()
- {
- int s0, nbytes;
- struct timeval tv;
- struct ifreq ifr0;
- struct sockaddr_can addr0;
- system("/sbin/ip link set can0 down");
- system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
- system("/sbin/ip link set can0 up");
- s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
- tv.tv_sec = 0;
- tv.tv_usec = 10000;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) {
- #ifdef SystemLogMessage
- log_error("Set SO_RCVTIMEO NG");
- #endif
- }
- nbytes = 40960;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0) {
- #ifdef SystemLogMessage
- log_error("Set SO_RCVBUF NG");
- #endif
- }
- nbytes = 40960;
- if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) {
- #ifdef SystemLogMessage
- log_error("Set SO_SNDBUF NG");
- #endif
- }
- strcpy(ifr0.ifr_name, "can0" );
- ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
- addr0.can_family = AF_CAN;
- addr0.can_ifindex = ifr0.ifr_ifindex;
- bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
- return s0;
- }
- //================================================
- // initial uart port
- //================================================
- char *_priPortName = "/dev/ttyS1";
- char *_485PortName = "/dev/ttyS5";
- int InitComPort(byte target)
- {
- int fd;
- struct termios tios;
- if (target == UPGRADE_PRI) {
- fd = open(_priPortName, O_RDWR);
- } else if (target == UPGRADE_FAN || target == UPGRADE_RB || target == UPGRADE_AC || target == UPGRADE_LED) {
- fd = open(_485PortName, O_RDWR);
- }
- if (fd <= 0) {
- #ifdef SystemLogMessage
- log_error("open 407 Communication port NG \n");
- #endif
- return -1;
- }
- ioctl (fd, TCGETS, &tios);
- tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN] = 0;
- tios.c_cc[VTIME] = (unsigned char)1;
- tios.c_lflag = 0;
- tcflush(fd, TCIFLUSH);
- ioctl (fd, TCSETS, &tios);
- return fd;
- }
- //=================================
- // Common routine
- //=================================
- void substr(char *dest, const char *src, unsigned int start, unsigned int cnt)
- {
- strncpy(dest, src + start, cnt);
- dest[cnt] = 0;
- }
- int InitWatchDog()
- {
- int fd;
- system("/usr/bin/fuser -k /dev/watchdog");
- sleep(1);
- system("echo V > /dev/watchdog");
- sleep(1);
- fd = open("/dev/watchdog", O_RDWR);
- if (fd <= 0) {
- log_error("System watch dog initial fail.\r\n");
- }
- return fd;
- }
- int StoreLogMsg_1(const char *fmt, ...)
- {
- char Buf[4096 + 256];
- char buffer[4096];
- va_list args;
- struct timeb SeqEndTime;
- struct tm *tm;
- va_start(args, fmt);
- int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
- va_end(args);
- memset(Buf, 0, sizeof(Buf));
- ftime(&SeqEndTime);
- SeqEndTime.time = time(NULL);
- tm = localtime(&SeqEndTime.time);
- if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
- sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
- tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
- printf("%s \n", Buf);
- } else {
- sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
- buffer,
- tm->tm_year + 1900, tm->tm_mon + 1);
- system(Buf);
- }
- return rc;
- }
- unsigned long GetTimeoutValue(struct timeval _sour_time)
- {
- struct timeval _end_time;
- gettimeofday(&_end_time, NULL);
- return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
- }
- int mystrcmp(unsigned char *p1, unsigned char *p2)
- {
- while (*p1 == *p2) {
- if (*p1 == '\0' || *p2 == '\0') {
- break;
- }
- p1++;
- p2++;
- }
- if (*p1 == '\0' && *p2 == '\0') {
- return (PASS);
- } else {
- return (FAIL);
- }
- }
- int DiffTimeb(struct timeb ST, struct timeb ET)
- {
- //return milli-second
- unsigned int StartTime, StopTime;
- StartTime = (unsigned int)ST.time;
- StopTime = (unsigned int)ET.time;
- //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
- return (StopTime - StartTime);
- }
- bool CheckTimeOut(struct timeb ST)
- {
- struct timeb ET;
- unsigned int StartTime, StopTime;
- ftime(&ET);
- StartTime = (unsigned int) ST.time;
- StopTime = (unsigned int) ET.time;
- return (StopTime > StartTime) ? YES : NO;
- }
- void setChargerMode(byte gun_index, byte mode)
- {
- chargingInfo[gun_index]->SystemStatus = mode;
- }
- void PRINTF_FUNC(char *string, ...)
- {
- va_list args;
- char buffer[4096];
- va_start(args, string);
- vsnprintf(buffer, sizeof(buffer), string, args);
- va_end(args);
- log_info("%s \n", buffer);
- }
- long long DiffTimebWithNow(struct timeb ST)
- {
- //return milli-second
- struct timeb ET;
- long long StartTime, StopTime;
- ftime(&ET);
- StartTime = (long long)ST.time;
- StopTime = (long long)ET.time;
- return ((StopTime - StartTime) * 1000) + (ET.millitm - ST.millitm);
- }
- //==========================================
- // Log
- //==========================================
- void CheckFwSlotStatusLog()
- {
- if (bd0_1_status == 0 && bd0_2_status == 1) {
- PRINTF_FUNC("Connector 1 : Chademo");
- } else if (bd0_1_status == 1 && bd0_2_status == 0) {
- PRINTF_FUNC("Connector 1 : CCS");
- } else if (bd0_1_status == 1 && bd0_2_status == 1) {
- PRINTF_FUNC("Connector 1 : GB");
- }
- if (bd1_1_status == 0 && bd1_2_status == 1) {
- PRINTF_FUNC("Connector 2 : Chademo");
- } else if (bd1_1_status == 1 && bd1_2_status == 0) {
- PRINTF_FUNC("Connector 2 : CCS");
- } else if (bd1_1_status == 1 && bd1_2_status == 1) {
- PRINTF_FUNC("Connector 2 : GB");
- }
- }
- void CheckHwSlotStatusLog(byte index)
- {
- if (chargingInfo[index]->Type == _Type_Chademo) {
- PRINTF_FUNC("Hw check : Connector %d, Type : Chademo, Evboard_id = %d \n",
- index, chargingInfo[index]->Evboard_id);
- } else if (chargingInfo[index]->Type == _Type_CCS_2) {
- PRINTF_FUNC("Hw check : Connector %d, Type : CCS, Evboard_id = %d \n",
- index, chargingInfo[index]->Evboard_id);
- } else if (chargingInfo[index]->Type == _Type_GB) {
- PRINTF_FUNC("Hw check : Connector %d, Type : GB, Evboard_id = %d \n",
- index, chargingInfo[index]->Evboard_id);
- }
- }
- //==========================================
- // Check interface status
- //==========================================
- int isInterfaceUp(const char *interface)
- {
- int result = FAIL;
- FILE *fp;
- char cmd[256];
- char buf[512];
- strcpy(cmd, "ifconfig");
- fp = popen(cmd, "r");
- if (fp != NULL) {
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- if (strstr(buf, interface) > 0) {
- result = PASS;
- }
- }
- }
- pclose(fp);
- return result;
- }
- //=================================
- // Create all share memory
- //=================================
- int CreateShareMemory()
- {
- int MeterSMId = FAIL;
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
- //creat ShmPsuData
- if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmPsuData, 0, sizeof(struct PsuData));
- if (CHAdeMO_QUANTITY > 0) {
- if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
- }
- if (GB_QUANTITY > 0) {
- if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmGBTData, 0, sizeof(struct GBTData));
- }
- //creat ShmCcsData
- if (CCS_QUANTITY > 0) {
- if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmCcsData, 0, sizeof(struct CcsData));
- }
- //creat ShmPrimaryMcuData
- if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
- //creat ShmFanModuleData
- if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
- //creat ShmRelayModuleData
- if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
- if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
- //creat ShmOCPP16Data
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- // memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
- #if defined METER_ENABLE
- if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmCsuMeterData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmCsuMeterData, 0, sizeof(struct MeterInformation));
- if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(ShmDcCommonData, 0, sizeof(struct DcCommonInformation));
- #endif //defined METER_ENABLE
- #if defined DD360 ||defined DD360Audi || defined DD360ComBox
- //creat Audi customization info
- if ((MeterSMId = shmget(ShmAudiCustInfoKey, sizeof(AudiCustInfo), IPC_CREAT | 0777)) < 0) {
- return FAIL;
- } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- return FAIL;
- }
- memset(gAudiCustInfo, 0, sizeof(AudiCustInfo));
- #endif //defined DD360Audi
- return PASS;
- }
- //=================================
- // LCM Page
- //=================================
- void ChangeLcmByIndex(byte page_index)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
- page_index == _LCM_COMPLETE || page_index == _LCM_FIX) {
- ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
- }
- }
- //======================================================
- // Peripheral initial
- //======================================================
- void InitGPIO()
- {
- /*****************0~3, 4 bank, bank x 32+ num*********************/
- /***************************************************************/
- /*************** GPIO 0 ***************************************/
- /***************************************************************/
- /* GPMC_AD8 => GPIO0_22 *//*ID BD1_1*/
- system("echo 22 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio22/direction");
- /* GPMC_AD9 => GPIO0_23 *//*ID BD1_2*/
- system("echo 23 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio23/direction");
- /* GPMC_AD10 => GPIO0_26 *//*IO BD1_1*/
- system("echo 26 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio26/direction");
- system("echo 1 > /sys/class/gpio/gpio26/value");
- /* GPMC_AD11 => GPIO0_27 *//*IO BD1_2*/
- system("echo 27 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio27/direction");
- /* RMII1_REF_CLK => GPIO0_29 *//*USB 0 OCP detection*/
- system("echo 29 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio29/direction");
- /*XDMA_EVENT_INTR0 => GPIO0_19 *//*AM_RFID_RST*/
- system("echo 19 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio19/direction");
- system("echo 1 > /sys/class/gpio/gpio19/value");
- /*XDMA_EVENT_INTR1 => GPIO0_20 *//*AM_RFID_ICC*/
- system("echo 20 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio20/direction");
- /***************************************************************/
- /*************** GPIO 1 ***************************************/
- /***************************************************************/
- /* GPMC_AD12 => GPIO1_12 *//*ID BD2_1*/
- system("echo 44 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio44/direction");
- /* GPMC_AD13 => GPIO1_13 *//*ID BD2_2*/
- system("echo 45 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio45/direction");
- /* GPMC_AD14 => GPIO1_14 *//*IO BD2_1*/
- system("echo 46 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio46/direction");
- system("echo 0 > /sys/class/gpio/gpio46/value");
- /* GPMC_AD15 => GPIO1_15 *//*IO BD2_2*/
- system("echo 47 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio47/direction");
- /***************************************************************/
- /*************** GPIO 2 ***************************************/
- /***************************************************************/
- /*LCD_AC_BIAS_EN => GPIO2_25*//*RS-485 for module DE control*/
- system("echo 89 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio89/direction");
- system("echo 1 > /sys/class/gpio/gpio89/value");
- /*LCD_HSYNC => GPIO2_23*//*RS-485 for module RE control*/
- system("echo 87 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio87/direction");
- system("echo 0 > /sys/class/gpio/gpio87/value");
- /*LCD_PCLK => GPIO2_24*//*CCS communication board 1 proximity*/
- system("echo 88 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio88/direction");
- /*LCD_VSYNC => GPIO2_22*//*CCS communication board 2 proximity*/
- system("echo 86 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio86/direction");
- /***************************************************************/
- /*************** GPIO 3 ***************************************/
- /***************************************************************/
- /*MCASP0_FSX => GPIO3_15*//*Emergency Stop button detect*/
- system("echo 111 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio111/direction");
- /*MCASP0_ACLKR => GPIO3_18*//*USB1 OCP detect*/
- system("echo 114 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio114/direction");
- /*MCASP0_AHCLKR => GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
- system("echo 113 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio113/direction");
- /*MCASP0_ACLKX => GPIO3_14*//*Ethernet PHY reset*/
- system("echo 110 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio110/direction");
- system("echo 0 > /sys/class/gpio/gpio110/value");
- /* MCASP0_FSR => GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
- system("echo 115 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio115/direction");
- system("echo 0 > /sys/class/gpio/gpio115/value");
- /* MCASP0_AXR0 => GPIO3_16 *//*CSU board function OK indicator.*/
- system("echo 112 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio112/direction");
- system("echo 1 > /sys/class/gpio/gpio112/value");
- /* MCASP0_AXR1 => GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
- system("echo 116 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio116/direction");
- system("echo 0 > /sys/class/gpio/gpio116/value");
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- /* (C14) EMU0.gpio3[7] */ /*CP open/short feature enable/disable, pull low for default enable*/
- system("echo 103 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio103/direction");
- system("echo 0 > /sys/class/gpio/gpio103/value");
- /* (B14) EMU1.gpio3[8] */ /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
- system("echo 104 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio104/direction");
- system("echo 0 > /sys/class/gpio/gpio104/value");
- #endif //!defined DD360 && !defined DD360Audi
- log_info("Initial GPIO OK");
- }
- int LoadSysConfigAndInfo(struct SysConfigData *ptr)
- {
- int fd, wrd;
- unsigned char *buf;
- unsigned int ChkSum, ChkSumOrg;
- if ((buf = malloc(MtdBlockSize)) == NULL) {
- log_error("malloc buffer NG,rebooting..\r\n");
- if (ShmStatusCodeData != NULL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- //================================================
- // Load configuration from mtdblock10
- //================================================
- fd = open("/dev/mtdblock10", O_RDWR);
- if (fd < 0) {
- free(buf);
- log_error("open mtdblock10 NG,rebooting..\r\n");
- if (ShmStatusCodeData != NULL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if (wrd < MtdBlockSize) {
- free(buf);
- log_error("read SysConfigData data NG,rebooting..\r\n");
- if (ShmStatusCodeData != NULL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
- //================================================
- // Load configuration from mtdblock11
- //================================================
- if (ChkSum != ChkSumOrg) {
- log_error("Primary SysConfigData checksum NG, read backup\r\n");
- fd = open("/dev/mtdblock11", O_RDWR);
- if (fd < 0) {
- free(buf);
- log_error("open mtdblock11 (backup) NG,rebooting..\r\n");
- if (ShmStatusCodeData != NULL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if (wrd < MtdBlockSize) {
- free(buf);
- log_error("read backup SysConfigData data NG,rebooting..\r\n");
- if (ShmStatusCodeData != NULL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
- //================================================
- // Load configuration from mtdblock12 (Factory default)
- //================================================
- if (ChkSum != ChkSumOrg) {
- log_error("backup SysConfigData checksum NG, read Factory default\r\n");
- fd = open("/dev/mtdblock12", O_RDWR);
- if (fd < 0) {
- free(buf);
- log_error("open mtdblock12 (Factory default) NG,rebooting..\r\n");
- if (ShmStatusCodeData != NULL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if (wrd < MtdBlockSize) {
- free(buf);
- log_error("read factory default SysConfigData data NG,rebooting..\r\n");
- if (ShmStatusCodeData != NULL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
- if (ChkSum != ChkSumOrg) {
- log_error("factory default SysConfigData checksum NG, restore factory default\r\n");
- free(buf);
- system("cd /root;./FactoryConfig -m");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- return FAIL;
- }
- }
- }
- //load OK
- memcpy((struct SysConfigData *)ptr, buf, sizeof(struct SysConfigData));
- free(buf);
- //log_info("Load SysConfigData OK\n");
- return PASS;
- }
- int isRouteFail()
- {
- int result = YES;
- FILE *fp;
- char buf[512];
- fp = popen("route -n", "r");
- if (fp != NULL) {
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- if (strstr(buf, "eth0") != NULL) {
- result = NO;
- }
- }
- }
- pclose(fp);
- return result;
- }
- int isReachableInternet()
- {
- int result = FAIL;
- FILE *fp;
- char cmd[256];
- char buf[512];
- char tmp[512];
- strcpy(cmd, "ifconfig eth0");
- fp = popen(cmd, "r");
- if (fp != NULL) {
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- if (strstr(buf, "inet addr:") > 0) {
- sscanf(buf, "%*s%s", tmp);
- substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf) - strspn(tmp, "addr:"));
- if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != EQUAL) {
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
- }
- }
- }
- }
- pclose(fp);
- #if defined DD360 ||defined DD360Audi || defined DD360ComBox
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == NORMAL) {
- result = FAIL;
- } else {
- result = PASS;
- }
- #else
- memset(buf, 0x00, sizeof(buf));
- for (int idx = 0; idx < ARRAY_SIZE(valid_Internet); idx++) {
- sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
- fp = popen(cmd, "r");
- if (fp != NULL) {
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- if (strstr(buf, "transmitted") > 0) {
- //sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
- if (strstr(buf, "100%") != NULL) {
- } else {
- result = PASS;
- }
- //DEBUG_INFO("%s",buf);
- //DEBUG_INFO("%s\n",tmp);
- }
- }
- }
- pclose(fp);
- }
- #endif //defined DD360 || defined DD360Audi
- return result;
- }
- void InitEthernet()
- {
- char tmpbuf[256];
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- bool ethResult = false;
- uint8_t cnt_pingDNS_Fail = 0;
- #endif //!defined DD360 && !defined DD360Audi
- system("ifconfig eth0 down");// eth0 down
- system("ifconfig eth1 down");// eth1 down
- sleep(2);
- // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
- system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
- sleep(2);
- //Init Eth0 for internet
- memset(tmpbuf, 0, 256);
- sprintf(tmpbuf, "/sbin/ifconfig eth0 %s netmask %s up",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
- //sprintf(tmpbuf,"/sbin/ifconfig eth0 192.168.100.10 netmask 255.255.255.0 up");
- system(tmpbuf);
- memset(tmpbuf, 0, 256);
- sprintf(tmpbuf, "route add default gw %s eth0 ",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
- //sprintf(tmpbuf,"route add default gw 192.168.100.1 eth0 ");
- system(tmpbuf);
- //system("ifconfig lo up");
- // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
- //Init Eth1 for administrator tool
- memset(tmpbuf, 0, 256);
- sprintf(tmpbuf, "/sbin/ifconfig eth1 %s netmask %s up",
- ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
- system(tmpbuf);
- //Run DHCP client if enabled
- system("killall udhcpc");
- system("rm -rf /etc/resolv.conf");
- system("echo nameserver 8.8.8.8 > /etc/resolv.conf"); //Google DNS server
- system("echo nameserver 180.76.76.76 > /etc/resolv.conf"); //Baidu DNS server
- //system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
- if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
- sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- //Upgrade system id to /etc/hostname
- sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- pid_t pid = fork();
- if (pid == 0) {
- log_info("InitEthernet = %d\r\n", pid);
- for (;;) {
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- if (isRouteFail()) {
- //PRINTF_FUNC("eth0 not in route, restart eht0. \n");
- system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
- if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
- InitialDHCP();
- }
- }
- if (isReachableInternet() == PASS) {
- ShmSysConfigAndInfo->SysInfo.ethInternetConn = YES;
- cnt_pingDNS_Fail = 0;
- } else {
- if (++cnt_pingDNS_Fail > 3) {
- ShmSysConfigAndInfo->SysInfo.ethInternetConn = NO;
- }
- }
- ethResult = ShmSysConfigAndInfo->SysInfo.ethInternetConn;
- if (ethResult == YES) {
- system("/sbin/ifmetric eth0 0");
- if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
- system("/sbin/ifmetric mlan0 1");
- }
- if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
- system("/sbin/ifmetric ppp0 2");
- }
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
- //ethResult = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn;
- ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? NO : YES;
- if (ethResult) {
- if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
- system("/sbin/ifmetric eth0 1");
- system("/sbin/ifmetric mlan0 0");
- }
- if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
- system("/sbin/ifmetric ppp0 2");
- }
- }
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
- //ethResult = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn;
- ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == YES ? NO : YES;
- if (ethResult) {
- if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
- system("/sbin/ifmetric mlan0 2");
- }
- if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
- system("/sbin/ifmetric eth0 1");
- system("/sbin/ifmetric ppp0 0");
- }
- }
- }
- ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
- #else
- isReachableInternet();
- #endif //!defined DD360 && !defined DD360
- sleep(5);
- }
- }
- log_info("Initial Ethernet OK\r\n");
- }
- int InitialRfidPort()
- {
- int uartO2 = open(rfidPortName, O_RDWR);
- struct termios tios;
- if (uartO2 != FAIL) {
- ioctl (uartO2, TCGETS, &tios);
- tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN] = 0;
- tios.c_cc[VTIME] = (unsigned char) 1;
- tios.c_lflag = 0;
- tcflush(uartO2, TCIFLUSH);
- ioctl(uartO2, TCSETS, &tios);
- }
- if (uartO2 < 0) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
- }
- return uartO2;
- }
- void GetMacAddress()
- {
- for (byte index = 0; index < 2; index++) {
- int fd;
- struct ifreq ifr;
- char tarEth[5];
- char Mac[18];
- sprintf(tarEth, "eth%d", index);
- fd = socket(AF_INET, SOCK_DGRAM, 0);
- ifr.ifr_addr.sa_family = AF_INET;
- strncpy(ifr.ifr_name, tarEth, IFNAMSIZ - 1);
- ioctl(fd, SIOCGIFHWADDR, &ifr);
- close(fd);
- sprintf(Mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
- ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2],
- ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
- if (index == 0) {
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, Mac);
- } else {
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthMacAddress, Mac);
- }
- }
- }
- void GetFirmwareVersion()
- {
- // Get CSU root file system version
- sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
- byte count = 0, chademo = 0, ccs = 0, gb = 0;
- for (uint8_t idx = 0; idx < 3; idx++) {
- if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'J') {
- chademo++;
- count++;
- } else if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'G') {
- gb++;
- count++;
- } else if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'U' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'V' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'E') {
- ccs++;
- count++;
- }
- }
- if (count == 1) {
- if (chademo > 0) {
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '1';
- } else if (ccs > 0) {
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '2';
- } else if (gb > 0) {
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '3';
- }
- } else {
- if (chademo > 0 && ccs > 0) {
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
- } else if (chademo > 0 && gb > 0) {
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
- } else if (ccs > 0 && gb > 0) {
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
- }
- }
- // Get network option from model name
- switch (ShmSysConfigAndInfo->SysConfig.ModelName[10]) {
- case 'B':
- case 'U':
- //Blue tooth
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
- break;
- case 'W':
- // WIFI
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
- break;
- case 'T':
- // 3G/4G
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
- break;
- case 'D': //DS60-120 add
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '5';
- break;
- default:
- // LAN
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
- break;
- }
- // Get rating power from model name
- memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
- // Get IEC or UL
- char _buf[3] = {0};
- memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[2], 2);
- if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL) {
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
- log_info("IEC model");
- } else if (strcmp(_buf, "WU") == EQUAL) {
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
- log_info("UL model");
- }
- }
- //DS60-120 add
- void InitialGunIndexToUnUse()
- {
- for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
- ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index = NO_DEFINE;
- }
- for (byte index = 0; index < CCS_QUANTITY; index++) {
- ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index = NO_DEFINE;
- }
- for (byte index = 0; index < GB_QUANTITY; index++) {
- ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index = NO_DEFINE;
- }
- for (byte index = 0; index < AC_QUANTITY; index++) {
- ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index = NO_DEFINE;
- }
- }
- void InitialShareMemoryInfo()
- {
- FILE *fp;
- char cmd[512];
- char buf[512];
- sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
- sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
- sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = 0;
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount = 0;
- ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
- ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
- ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
- sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
- memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
- sprintf(cmd, "/bin/uname -r");
- fp = popen(cmd, "r");
- if (fp == NULL) {
- sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
- } else {
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- strcpy((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
- }
- }
- // 雙槍 CCS + Chademo
- GetFirmwareVersion();
- //sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
- ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
- ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
- ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
- ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
- ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
- ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = NO; //DS60-120 Add
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail = NO; //DS60-120 Add
- ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = NO; //DS60-120 add
- memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
- memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
- ShmPrimaryMcuData->SelfTest_Comp = NO;
- ShmRelayModuleData->SelfTest_Comp = NO;
- ShmFanModuleData->SelfTest_Comp = NO;
- ShmLedModuleData->SelfTest_Comp = NO;
- #if defined DD360Audi
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
- #else
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- #endif //defined DD360Audi
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOTTING; //DS60-120 add
- ShmFanModuleData->TestFanSpeed = 0;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- //--- DS60-120 remove -----
- /*char EvsePower[2];
- EvsePower[2] = '\0';
- unsigned short buf_pow = 0;
- if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6) {
- strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
- if (strcmp(EvsePower, "15") == EQUAL) {
- buf_pow = 150;
- } else if (strcmp(EvsePower, "30") == EQUAL) {
- buf_pow = 30;
- } else if (strcmp(EvsePower, "60") == EQUAL) {
- buf_pow = 60;
- } else if (strcmp(EvsePower, "12") == EQUAL) {
- buf_pow = 120;
- } else if (strcmp(EvsePower, "18") == EQUAL) {
- buf_pow = 180;
- } else if (strcmp(EvsePower, "36") == EQUAL) {
- buf_pow = 360;
- }
- ShmSysConfigAndInfo->SysConfig.RatingCurrent = (buf_pow / 30) * PSU_MIN_CUR;
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingPower == 0 ||
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower > buf_pow) {
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower = buf_pow;
- }
- }
- */
- //--------------------------------------------------------------------------
- InitialGunIndexToUnUse();//DS60-120 add
- ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
- ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
- #if defined METER_ENABLE
- ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V015S0; //DS60-120
- #endif //defined METER_ENABLE
- log_info("3InitialShareMemoryInfo done...\r\n");
- }
- int Initialization()
- {
- // 初始化卡號驗證的 Flag
- ClearAuthorizedFlag();
- // 初始化插槍驗證的 Flag
- ClearDetectPluginFlag();
- // UART 2 for Rfid
- rfidFd = InitialRfidPort();
- int pinOut[2] = { 116, 115 };
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
- chargingInfo[count]->RemoteStartFlag = NO;
- if (chargingInfo[count]->Type == _Type_Chademo) {
- gpio_set_value(pinOut[count], 0x00);
- ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
- } else if (chargingInfo[count]->Type == _Type_GB) {
- gpio_set_value(pinOut[count], 0x00);
- ShmGBTData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
- } else if (chargingInfo[count]->Type == _Type_CCS_2) {
- //if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) { //DS60-120 remove
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
- gpio_set_value(pinOut[1], 0x01);
- } else {
- gpio_set_value(pinOut[count], 0x01);
- }
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
- //}
- }
- strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
- }
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++) {
- ac_chargingInfo[count]->RemoteStartFlag = NO;
- if (ac_chargingInfo[count]->Type == _Type_AC) {
- ac_chargingInfo[count]->SelfTest_Comp = NO;
- strcpy((char *)ShmOCPP16Data->StatusNotification[count + ShmSysConfigAndInfo->SysConfig.TotalConnectorCount].ErrorCode, "NoError");
- }
- }
- //PRINTF_FUNC("Initialization OK \n");
- return PASS;
- }
- bool InitialSystemDefaultConfig()
- {
- bool result = true;
- LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
- InitGPIO();
- InitEthernet();
- GetMacAddress();
- // system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
- // sleep(3);
- // system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
- // sleep(1);
- // system("/sbin/ifconfig eth1 192.168.0.10 netmask 255.255.255.0 up");
- return result;
- }
- bool DisplaySelfTestFailReason()
- {
- bool result = false;
- // RB、FB、407、EV 小板中有些板子無回應
- if (ShmRelayModuleData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = true; }
- if (ShmFanModuleData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = true; }
- if (ShmPrimaryMcuData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = true; }
- if (ShmLedModuleData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = true; }
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
- if (chargingInfo[index]->Type == _Type_Chademo) {
- if (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = true; }
- } else if (chargingInfo[index]->Type == _Type_GB) {
- if (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtboardStestFail = true; }
- } else if (chargingInfo[index]->Type == _Type_CCS_2) {
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
- if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = true; }
- }
- }
- }
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++) {
- // 先借 GBT 顯示
- if (ac_chargingInfo[index]->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcConnectorStestFail = true; }
- }
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO) {
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- // AC Contact 未搭上
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = true;
- result = true;
- #endif //!defined DD360 && !defined DD360Audi
- }
- #if 0
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES) { //DS60-120 add
- result = true;
- }
- #endif //0
- else if (ShmPsuData->SystemAvailablePower <= 0 && ShmPsuData->SystemAvailableCurrent <= 0) {
- // PSU 通訊問題
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = true;
- result = true;
- }
- return result;
- }
- void SelfTestRun()
- {
- bool evInitFlag = false;
- StartSystemTimeoutDet(Timeout_SelftestChk);
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
- while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE //||
- //GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL <= 20 //DS60-120 add
- ) {
- if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE) {
- return;
- }
- ChkPrimaryStatus();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 //||
- //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES //DS60-120 add
- ) {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
- return;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) {
- if (ShmPsuData->Work_Step == _NO_WORKING ||
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL) {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
- return;
- }
- switch (ShmSysConfigAndInfo->SysInfo.SelfTestSeq) {
- case _STEST_VERSION: {
- if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev) != 0 ||
- ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0] != '\0')
- && (ShmRelayModuleData->SelfTest_Comp != YES)
- ) {
- log_info("Relay Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
- ShmRelayModuleData->SelfTest_Comp = YES;
- }
- #if !defined NO_FAN_BOARD && !defined DD360ComBox
- if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
- ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
- && (ShmFanModuleData->SelfTest_Comp != YES)
- ) {
- log_info("Fan Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
- ShmFanModuleData->SelfTest_Comp = YES;
- }
- #else
- ShmFanModuleData->SelfTest_Comp = YES;
- #endif //NO_FAN_BOARD
- if ((strlen((char *)ShmPrimaryMcuData->version) != 0 ||
- ShmPrimaryMcuData->version[0] != '\0')
- && (ShmPrimaryMcuData->SelfTest_Comp != YES)
- ) {
- log_info("Primary FW Rev = %s", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
- ShmPrimaryMcuData->SelfTest_Comp = YES;
- }
- #if 0 //DS60-120 remove
- if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev) != 0 ||
- ShmSysConfigAndInfo->SysInfo.LedModuleFwRev[0] != '\0')
- && (ShmLedModuleData->SelfTest_Comp != YES)
- ) {
- log_info("LED Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
- ShmLedModuleData->SelfTest_Comp = YES;
- }
- #endif //0
- // EV 小板
- if (!evInitFlag) {
- evInitFlag = YES;
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
- //log_info("index = %d, charging index = %d, type = %d\r\n",
- // index,
- // chargingInfo[index]->type_index,
- // chargingInfo[index]->Type);
- if (chargingInfo[index]->Type == _Type_Chademo) {
- if ((strlen((char *)ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version) != 0 ||
- ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version[0] != '\0')
- //&& (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp != YES)
- ) {
- log_info("CHAdeMO[%d] FW Rev = %s", chargingInfo[index]->type_index, ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
- ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
- } else {
- //PRINTF_FUNC("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
- evInitFlag = NO;
- }
- } else if (chargingInfo[index]->Type == _Type_GB) {
- if ((strlen((char *)ShmGBTData->evse[chargingInfo[index]->type_index].version) != 0 ||
- ShmGBTData->evse[chargingInfo[index]->type_index].version[0] != '\0')
- //&& (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp != YES)
- ) {
- log_info("GBT[%d] FW Rev = %s", chargingInfo[index]->type_index, ShmGBTData->evse[chargingInfo[index]->type_index].version);
- ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
- } else {
- //PRINTF_FUNC("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
- evInitFlag = NO;
- }
- } else if (chargingInfo[index]->Type == _Type_CCS_2) {
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
- if ((strlen((char *)ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version) != 0 ||
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version[0] != '\0')
- /*&&(ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp != YES)*/
- ) {
- log_info("CCS[%d] FW Rev = %s",
- chargingInfo[index]->type_index,
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp = YES;
- } else {
- //log_info("CCS[%d] ccs fw lose...... %s \n",
- // chargingInfo[index]->type_index,
- // ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
- evInitFlag = NO;
- }
- }
- }
- }
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++) {
- if (ac_chargingInfo[index]->Type == _Type_AC) {
- if ((strlen((char *)ac_chargingInfo[index]->version) != 0 || ac_chargingInfo[index]->version[0] != '\0')
- && (ac_chargingInfo[index]->SelfTest_Comp != YES)
- ) {
- log_info("AC connector[%d] FW Rev = %s", index, ac_chargingInfo[index]->version);
- ac_chargingInfo[index]->SelfTest_Comp = YES;
- } else {
- evInitFlag = NO;
- }
- }
- }
- }
- if ( ShmFanModuleData->SelfTest_Comp &&
- ShmRelayModuleData->SelfTest_Comp &&
- ShmPrimaryMcuData->SelfTest_Comp &&
- //ShmLedModuleData->SelfTest_Comp &&
- evInitFlag
- ) {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_AC_CONTACTOR;
- }
- }
- break;
- case _STEST_AC_CONTACTOR: {
- //ShmPsuData->Work_Step = _TEST_COMPLETE;
- // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES) {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
- log_info("AC contactor self test OK");
- }
- #else
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
- log_info("Waiting for DO communication");
- #endif //!defined DD360 && !defined DD360Audi
- }
- break;
- case _STEST_PSU_DETECT: {
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
- }
- #else
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
- #endif //defined DD360 && !defined DD360Audi
- }
- break;
- case _STEST_PSU_CAP: {
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- // 此測試是要確認當前總輸出能力
- // 如果沒有 PSU 模組請 bypass
- if (ShmPsuData->Work_Step == BOOTING_COMPLETE) {
- sleep(1);
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
- ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
- }
- #else
- //check the power limit from DO
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
- ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
- log_info("Successful Self Test");
- #endif //defined DD360 && !defined DD360Audi
- }
- break;
- }
- } else {
- break;
- }
- usleep(100000);
- }
- }
- int SpawnTask()
- {
- sleep(2);
- system("/root/Module_EventLogging &");
- system("/root/Module_PrimaryComm &");
- system("/root/Module_EvComm &");
- system("/root/Module_LcmControl &");
- system("/root/Module_InternalComm &");
- system("/root/Module_ProduceUtils &");
- #if defined DD360 ||defined DD360Audi || defined DD360ComBox
- system("/root/DoComm &");
- #else
- system("/root/Module_PsuComm &");
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL) {
- system("/root/OcppBackend &");
- }
- if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') {
- system("/root/Module_4g &");
- }
- if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') {
- system("/root/Module_Wifi &");
- }
- if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D') {
- system("/root/Module_4g &");
- system("/root/Module_Wifi &");
- }
- #endif //defined DD360 || defined DD360Audi
- return PASS;
- }
- int StoreUsrConfigData(struct SysConfigData *UsrData)
- {
- int result = PASS;
- int fd, wrd;
- unsigned int i, Chk;
- unsigned char *ptr, *BufTmp;
- Chk = 0;
- ptr = (unsigned char *)UsrData;
- if ((BufTmp = malloc(MtdBlockSize)) != NULL) {
- memset(BufTmp, 0, MtdBlockSize);
- memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
- for (i = 0; i < MtdBlockSize - 4; i++) {
- Chk += *(ptr + i);
- }
- memcpy(BufTmp + MtdBlockSize - 4, &Chk, 4);
- fd = open("/dev/mtdblock10", O_RDWR);
- if (fd > 0) {
- wrd = write(fd, BufTmp, MtdBlockSize);
- close(fd);
- if (wrd >= MtdBlockSize) {
- fd = open("/dev/mtdblock11", O_RDWR);
- if (fd > 0) {
- wrd = write(fd, BufTmp, MtdBlockSize);
- close(fd);
- if (wrd < MtdBlockSize) {
- log_error("write /dev/mtdblock11(backup) NG\r\n");
- result = FAIL;
- }
- } else {
- log_error("open /dev/mtdblock11(backup) NG\r\n");
- result = FAIL;
- }
- } else {
- log_error("write /dev/mtdblock10 NG\r\n");
- result = FAIL;
- }
- } else {
- log_error("open /dev/mtdblock10 NG\r\n");
- result = FAIL;
- }
- } else {
- log_error("alloc BlockSize NG\r\n");
- result = FAIL;
- }
- if (BufTmp != NULL) {
- free(BufTmp);
- }
- return result;
- }
- //===============================================
- // Common Detect Chk - Stop Charging ?
- //===============================================
- int isEvBoardStopChargeFlag(byte gunIndex)
- {
- //printf("StopChargeFlag = %d\r\n", chargingInfo[gunIndex]->StopChargeFlag);
- return chargingInfo[gunIndex]->StopChargeFlag;
- }
- bool isEvBoardNormalStopChargeFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->NormalStopChargeFlag;
- }
- //===============================================
- // 掃描插槍狀況
- //===============================================
- void ClearDetectPluginFlag()
- {
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
- //DS60-120 add
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
- if (chargingInfo[gun_index]->RemoteStartFlag == YES) {
- chargingInfo[gun_index]->RemoteStartFlag = NO;
- }
- }
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE) {
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- }
- }
- void DetectPluginStart()
- {
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
- }
- bool isDetectPlugin()
- {
- if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) {
- return YES;
- }
- return NO;
- }
- //===============================================
- // Common Detect Chk - Chademo
- //===============================================
- bool isEvGunLocked_chademo(byte gunIndex)
- {
- return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
- }
- bool isEvContactorWelding_chademo(byte gunIndex)
- {
- return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
- }
- bool isEvStopReq_chademo(byte gunIndex)
- {
- return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
- }
- bool isEvStopCharging_chademo(byte gunIndex)
- {
- if (isEvGunLocked_chademo(gunIndex) == NO) {
- // 無鎖槍 = 停止
- PRINTF_FUNC("gun locked none (%d) \n", gunIndex);
- return YES;
- }
- return NO;
- }
- byte isPrechargeStatus_chademo(byte gunIndex)
- {
- byte result = 0x00;
- result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
- return result;
- }
- //===============================================
- // Common Detect Chk - GB
- //===============================================
- bool isEvGunLocked_gb(byte gunIndex)
- {
- return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
- }
- bool isEvStopCharging_gb(byte gunIndex)
- {
- if (isEvGunLocked_gb(gunIndex) == NO) {
- // 無鎖槍 = 停止
- PRINTF_FUNC("gun locked none. \n");
- return YES;
- }
- return NO;
- }
- byte isPrechargeStatus_gb(byte gunIndex)
- {
- byte result = 0x00;
- result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
- return result;
- }
- //===============================================
- // Common Detect Chk - CCS
- //===============================================
- bool isEvGunLocked_ccs(byte gunIndex)
- {
- return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
- }
- byte isPrechargeStatus_ccs(byte gunIndex)
- {
- byte result = 0x00;
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
- result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
- }
- return result;
- }
- bool isEvStopCharging_ccs(byte gunIndex)
- {
- if (isEvGunLocked_ccs(gunIndex) == NO) {
- // 無鎖槍 = 停止
- PRINTF_FUNC("gun locked none. \n");
- return YES;
- }
- return NO;
- }
- //===============================================
- // Callback
- //===============================================
- void DisplayChargingInfo()
- {
- PRINTF_FUNC("*********** DisplayChargingInfo *********** \n");
- for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
- if (chargingInfo[i]->SystemStatus != S_IDLE &&
- chargingInfo[i]->SystemStatus != S_RESERVATION) {
- ChangeGunSelectByIndex(i);
- return;
- }
- }
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
- ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE) {
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
- }
- usleep(50000);
- #if defined DD360Audi
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
- #else
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- #endif //defined DD360Audi
- }
- void _AutoReturnTimeout()
- {
- PRINTF_FUNC("*********** _AutoReturnTimeout %d*********** \n", ShmSysConfigAndInfo->SysInfo.PageIndex);
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG) {
- ClearDetectPluginFlag();
- } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP) {
- DetectPluginStart();
- }
- usleep(50000);
- #if defined DD360Audi
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
- #else
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- #endif //defined DD360Audi
- }
- void _SelfTestTimeout()
- {
- if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE) {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
- setChargerMode(gun_index, MODE_ALARM);
- }
- }
- ShmPsuData->Work_Step = _NO_WORKING;
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
- PRINTF_FUNC("Self test timeout. \n");
- }
- void _AuthorizedTimeout()
- {
- if (IsAuthorizingMode()) {
- PRINTF_FUNC("*********** _AuthorizedTimeout *********** \n");
- isCardScan = false;
- //gAudiCustInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance = 0.0; //Jerry add
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
- //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearAuthorizedFlag();
- }
- }
- void _DetectPlugInTimeout()
- {
- PRINTF_FUNC("*********** _DetectPlugInTimeout *********** \n");
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearDetectPluginFlag();
- //usleep(50000);
- sleep(1); //Jerry add
- #if defined DD360Audi
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
- #else
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- #endif //defined DD360Audi
- }
- void _DetectEvChargingEnableTimeout(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
- if (!isEvGunLocked_chademo(gunIndex)) {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
- }
- } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
- if (!isEvGunLocked_ccs(gunIndex)) {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
- }
- } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
- if (!isEvGunLocked_ccs(gunIndex)) {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
- }
- }
- ChargingTerminalProcess(gunIndex);
- _AutoReturnTimeout();
- }
- void _DetectEvseChargingEnableTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
- //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
- {
- setChargerMode(gunIndex, MODE_IDLE);
- _AutoReturnTimeout();
- }
- }
- void _PrepareTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _PrepareTimeout ***********\n");
- setChargerMode(gunIndex, MODE_IDLE);
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
- _AutoReturnTimeout();
- }
- void _CcsPrechargeTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _CcsPrechargeTimeout ***********\n");
- setChargerMode(gunIndex, MODE_IDLE);
- }
- //===============================================
- // 取得卡號與卡號驗證
- //===============================================
- bool canStartCharging()
- {
- char buf2[16] = "";
- memset(buf2, 0, ARRAY_SIZE(buf2));
- for (byte index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) {
- sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
- }
- sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
- // 因為無法得知實際的長度,所以只能用搜尋的方式
- if (strcmp(buf2, "Accepted") == EQUAL) {
- return true;
- } else {
- }
- return false;
- }
- void AuthorizingStart()
- {
- ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
- ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
- }
- void ClearAuthorizedFlag()
- {
- ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
- ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
- }
- bool isAuthorizedComplete()
- {
- if (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == YES) {
- return false;
- }
- return true;
- }
- bool IsAuthorizingMode()
- {
- if (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO) {
- return false;
- }
- return true;
- }
- //===============================================
- // 紀錄 Alarm Code
- //===============================================
- void RecordAlarmCode(byte gunIndex, char *code)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, code, 6);
- if (strcmp(code, "012234") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES; }
- if (strcmp(code, "012235") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES; }
- if (strcmp(code, "012236") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES; }
- if (strcmp(code, "012288") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES; }
- if (strcmp(code, "012289") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES; }
- if (strcmp(code, "012290") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES; }
- }
- void RecordWarningCode(byte gunIndex, char *code)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, code, 6);
- if (strcmp(code, "012296") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES; }
- if (strcmp(code, "012297") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES; }
- if (strcmp(code, "012298") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES; }
- }
- void ReleaseAlarmCode(byte gunIndex)
- {
- bool isCleanCheck = false;
- char code[7];
- if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES) {
- memcpy(code, "012234", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail == YES) {
- memcpy(code, "012289", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES) {
- ReleaseWarningCodeByString(gunIndex, "012296");
- }
- } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES) {
- memcpy(code, "012236", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail == YES) {
- memcpy(code, "012290", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES) {
- ReleaseWarningCodeByString(gunIndex, "012298");
- }
- } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES) {
- memcpy(code, "012235", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail == YES) {
- memcpy(code, "012288", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES) {
- ReleaseWarningCodeByString(gunIndex, "012297");
- }
- }
- if (isCleanCheck) {
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
- if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, code, 6) != EQUAL) {
- if (strncmp(code, "012234", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO; }
- if (strncmp(code, "012289", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO; }
- if (strncmp(code, "012236", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO; }
- if (strncmp(code, "012290", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO; }
- if (strncmp(code, "012235", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO; }
- if (strncmp(code, "012288", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO; }
- }
- }
- }
- }
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012238", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012304", 6) == EQUAL
- ) {
- memset(chargingInfo[gunIndex]->ConnectorAlarmCode, 0, sizeof(chargingInfo[gunIndex]->ConnectorAlarmCode));
- }
- }
- void ReleaseWarningCodeByString(byte gunIndex, char *code)
- {
- bool isCleanCheck = false;
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES) {
- memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
- isCleanCheck = true;
- } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES) {
- memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
- isCleanCheck = true;
- } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES) {
- memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
- isCleanCheck = true;
- }
- if (isCleanCheck) {
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
- if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
- if (strncmp((char *)chargingInfo[index]->ConnectorWarningCode, code, 6) != EQUAL) {
- if (strncmp(code, "012296", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO; }
- if (strncmp(code, "012297", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO; }
- if (strncmp(code, "012298", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO; }
- }
- }
- }
- }
- }
- //===============================================
- // EmergencyStop and Charging Stop
- //===============================================
- void ChargingTerminalProcess(byte gunIndex)
- {
- setChargerMode(gunIndex, MODE_TERMINATING);
- }
- void ChargingAlarmProcess(byte gunIndex)
- {
- setChargerMode(gunIndex, MODE_ALARM);
- }
- void AcChargingTerminalProcess()
- {
- ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
- }
- void StopChargingProcessByString(byte level)
- {
- if (level > ShmSysConfigAndInfo->SysWarningInfo.Level) {
- ShmSysConfigAndInfo->SysWarningInfo.Level = level;
- }
- }
- void ReleaseChargingProcessByString(byte level)
- {
- if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level) {
- ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
- }
- }
- // 一般錯誤停止充電處理函式
- void BoardErrOccurByString(byte index, char *code)
- {
- byte level = 1;
- if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
- (chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- if (strncmp(code, "023730", 6) == EQUAL && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO) {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
- }
- ChargingTerminalProcess(index);
- }
- StopChargingProcessByString(level);
- }
- // 急停狀況的停止充電處理函式
- void EmcOccureByString(char *code)
- {
- byte level = 2;
- // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
- // 其錯誤等級為 2
- #if defined DD360 ||defined DD360Audi || defined DD360ComBox
- //DS60-120 remove
- if (strncmp(code, "012251", 6) == EQUAL ||
- strncmp(code, "012252", 6) == EQUAL ||
- strncmp(code, "012238", 6) == EQUAL ||
- strncmp(code, "042251", 6) == EQUAL ||
- strncmp(code, "042252", 6) == EQUAL ||
- strncmp(code, "012304", 6) == EQUAL ||
- strncmp(code, "042200", 6) == EQUAL ||
- strncmp(code, "042201", 6) == EQUAL ||
- strncmp(code, "042202", 6) == EQUAL ||
- strncmp(code, "042267", 6) == EQUAL)
- #endif //defined DD360 || defined DD360Audi
- {
- for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++) {
- //strncpy((char *)ShmOCPP16Data->StatusNotification[gun].VendorErrorCode, code, 6);
- if ((chargingInfo[gun]->SystemStatus > S_IDLE &&
- chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
- (chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- //ChargingTerminalProcess(gun);
- ChargingAlarmProcess(gun);
- }
- }
- #if defined DD360 ||defined DD360Audi || defined DD360ComBox
- StopChargingProcessByString(level);
- InformOcppErrOccur(4);
- #endif //defined DD360 || defined DD360Audi
- }
- }
- void ReleaseBoardErrOccurByString(byte index, char *code)
- {
- bool isTrigger = false;
- byte level = 1;
- if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
- isTrigger = true;
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
- }
- if (isTrigger) {
- ReleaseChargingProcessByString(level);
- }
- }
- void ReleaseEmsOccureByString(byte index, char *code)
- {
- bool isTrigger = false;
- byte level = 2;
- if (strncmp(code, "042251", 6) == 0 ) {
- isTrigger = true;
- } else if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES) {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
- } else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES) {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
- } else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES) {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- } else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES) {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- if (isTrigger) {
- ReleaseChargingProcessByString(level);
- InformOcppErrOccur(6);
- }
- }
- //===============================================
- // 確認硬體 (按鈕) 狀態
- //===============================================
- bool leftBtnPush = false;
- bool rightBtnPush = false;
- void ChkPrimaryStatus()
- {
- unsigned char Rtn;
- if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
- Rtn = 0;
- for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
- if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042251", 6) == 0) {
- EmcOccureByString("042251");
- Rtn = 1;
- } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042252", 6) == 0) {
- EmcOccureByString("042252");
- Rtn = 1;
- } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042200", 6) == 0) {
- EmcOccureByString("042200");
- Rtn = 1;
- } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042201", 6) == 0) {
- EmcOccureByString("042201");
- Rtn = 1;
- } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042202", 6) == 0) {
- EmcOccureByString("042202");
- Rtn = 1;
- } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == 0) {
- EmcOccureByString("012304");
- Rtn = 1;
- }
- }
- if (Rtn == 0) {
- ReleaseEmsOccureByString(0, "042251");
- ReleaseEmsOccureByString(0, "042252");
- ReleaseEmsOccureByString(0, "042200");
- ReleaseEmsOccureByString(0, "042201");
- ReleaseEmsOccureByString(0, "042202");
- ReleaseEmsOccureByString(0, "012304");
- }
- } else {
- ReleaseEmsOccureByString(0, "042251");
- ReleaseEmsOccureByString(0, "042252");
- ReleaseEmsOccureByString(0, "042200");
- ReleaseEmsOccureByString(0, "042201");
- ReleaseEmsOccureByString(0, "042202");
- ReleaseEmsOccureByString(0, "012304");
- }
- if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
- EmcOccureByString("012251");
- } else {
- ReleaseEmsOccureByString(0, "012251");
- }
- if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
- EmcOccureByString("012238");
- } else {
- ReleaseEmsOccureByString(0, "012238");
- }
- if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
- } else {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- }
- if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
- EmcOccureByString("012252");
- } else {
- ReleaseEmsOccureByString(0, "012252");
- }
- //DS60-120 add
- //if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
- // ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS) {
- // ShmSysConfigAndInfo->SysConfig.ShowInformation = YES;
- //} else {
- // ShmSysConfigAndInfo->SysConfig.ShowInformation = NO;
- //}
- if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
- !leftBtnPush
- #if defined DD360Audi
- &&
- getCurLcmPage() != _LCM_AUTHORIZING &&
- getCurLcmPage() != _LCM_AUTHORIZ_COMP &&
- getCurLcmPage() != _LCM_AUTHORIZ_FAIL
- #endif //defined DD360Audi
- ) {
- if (!leftBtnPush) {
- leftBtnPush = true;
- PRINTF_FUNC("left btn down...............................%x\n",
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus);
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
- switch (ac_chargingInfo[0]->SystemStatus) {
- case S_IDLE: {
- if (isDetectPlugin()) {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- }
- }
- break;
- case S_REASSIGN_CHECK:
- case S_REASSIGN:
- case S_PREPARNING:
- case S_PREPARING_FOR_EV:
- case S_PREPARING_FOR_EVSE:
- case S_CCS_PRECHARGE_ST0:
- case S_CCS_PRECHARGE_ST1: {
- // 取消充電
- AcChargingTerminalProcess();
- }
- break;
- case S_CHARGING: {
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
- // 停止充電
- AcChargingTerminalProcess();
- }
- }
- break;
- case S_COMPLETE:
- {}
- break;
- }
- }
- switch (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
- case S_IDLE: {
- if (isDetectPlugin()) {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- #if defined DD360Audi
- destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- #endif //defined DD360Audi
- }
- #if defined DD360Audi
- else {
- if (getConfirmSelectedGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected) == PASS) {
- //printf("destroy gun = %d\r\n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- } else {
- confirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- PRINTF_FUNC("confirm select gun ............................... %d \n",
- ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- }
- #endif //defined DD360Audi
- }
- break;
- case S_REASSIGN_CHECK:
- case S_REASSIGN:
- case S_PREPARNING:
- case S_PREPARING_FOR_EV:
- case S_PREPARING_FOR_EVSE:
- case S_CCS_PRECHARGE_ST0:
- case S_CCS_PRECHARGE_ST1: {
- // 取消充電
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
- AcChargingTerminalProcess();
- } else {
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- }
- break;
- case S_CHARGING: {
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
- // 停止充電
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- }
- break;
- case S_COMPLETE: {
- // 回 IDLE
- //PRINTF_FUNC("right btn down.................S_COMPLETE \n");
- //chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_IDLE;
- }
- break;
- }
- }
- } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
- if (leftBtnPush) {
- leftBtnPush = false;
- //PRINTF_FUNC("left btn up............................... \n");
- }
- }
- if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS &&
- !rightBtnPush
- #if defined DD360Audi
- &&
- getCurLcmPage() != _LCM_IDLE &&
- getCurLcmPage() != _LCM_AUTHORIZING &&
- getCurLcmPage() != _LCM_AUTHORIZ_COMP &&
- getCurLcmPage() != _LCM_AUTHORIZ_FAIL &&
- getCurLcmPage() != _LCM_WAIT_FOR_PLUG
- #endif //defined DD360Audi
- ) {
- if (!rightBtnPush) {
- rightBtnPush = true;
- //PRINTF_FUNC("right btn down............................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO) {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected++;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- } else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE) {
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
- } else if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
- if (chargingInfo[_index]->SystemStatus != S_BOOTING &&
- chargingInfo[_index]->SystemStatus != S_IDLE &&
- chargingInfo[_index]->SystemStatus != S_RESERVATION) {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- return;
- }
- }
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- } else {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- }
- PRINTF_FUNC("current select gun ............................... %d \n",
- ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
- if (rightBtnPush) {
- rightBtnPush = false;
- //PRINTF_FUNC("right btn up............................... \n");
- }
- }
- }
- //===============================================
- // 確認各小板偵測的錯誤狀況
- //===============================================
- void CheckErrorOccurStatus(byte index)
- {
- // 小板
- if (chargingInfo[index]->Type == _Type_Chademo) {
- if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
- BoardErrOccurByString(index, "011012");
- }
- // else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
- // BoardErrOccurByString(index, "012234");
- } else if (chargingInfo[index]->Type == _Type_GB) {
- if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES) {
- BoardErrOccurByString(index, "011016");
- }
- // else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES)
- // BoardErrOccurByString(index, "012236");
- } else if (chargingInfo[index]->Type == _Type_CCS_2) {
- if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
- BoardErrOccurByString(index, "011014");
- }
- // else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
- // BoardErrOccurByString(index, "012235");
- }
- // RB
- if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES) {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
- StopChargingProcessByString(2);
- InformOcppErrOccur(13);
- }
- //DS60-120 add -----
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012203", 6);
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012204", 6);
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012205", 6);
- }
- }
- //log_info("1 CheckErrorOccurStatus\r\n");
- chargingInfo[index]->StopChargeFlag = YES;
- //------------------------------------------------------------------
- } else {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- InformOcppErrOccur(6);
- }
- }
- } else {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- InformOcppErrOccur(6);
- }
- }
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES) {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
- StopChargingProcessByString(2);
- InformOcppErrOccur(14);
- }
- //DS60-120 -----
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012200", 6);
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012201", 6);
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012202", 6);
- }
- }
- //log_info("2 CheckErrorOccurStatus\r\n");
- chargingInfo[index]->StopChargeFlag = YES;
- //----------------------------------------------------------------------
- } else {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP) {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- InformOcppErrOccur(6);
- }
- }
- //DS60-120 ----
- if (chargingInfo[index]->Type == _Type_Chademo) {
- if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "011011", 6);
- } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "011012", 6);
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012217", 6);
- }
- } else if (chargingInfo[index]->Type == _Type_GB) {
- if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "011015", 6);
- } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "011016", 6);
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012221", 6);
- }
- } else if (chargingInfo[index]->Type == _Type_CCS_2) {
- if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "011013", 6);
- } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "011014", 6);
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012219", 6);
- }
- }
- //--------------------------------------------------------------------------
- if (strlen(chargingInfo[index]->ConnectorAlarmCode) == 0) {
- //Primary
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012251", 6);
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012252", 6);
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012238", 6);
- } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == YES) {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "012304", 6);
- }
- }
- }
- //===============================================
- // 確認 GPIO 狀態
- //===============================================
- void gpio_set_value(unsigned int gpio, unsigned int value)
- {
- int fd;
- char buf[MAX_BUF];
- snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
- fd = open(buf, O_WRONLY);
- if (fd < 0) {
- perror("gpio/set-value");
- return;
- }
- if (value) {
- write(fd, "1", 2);
- } else {
- write(fd, "0", 2);
- }
- close(fd);
- }
- int gpio_get_value(unsigned int gpio, unsigned int *value)
- {
- int fd;
- char buf[MAX_BUF];
- char ch;
- snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
- fd = open(buf, O_RDONLY);
- if (fd < 0) {
- perror("gpio/get-value");
- return fd;
- }
- read(fd, &ch, 1);
- if (ch != '0') {
- *value = 1;
- } else {
- *value = 0;
- }
- close(fd);
- return 0;
- }
- void CheckGunTypeFromHw()
- {
- uint8_t i = 0;
- int pinIn[4] = {22, 23, 44, 45};
- unsigned int gpioValue = 0;
- unsigned char tmp[2] = {0};
- log_info("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
- for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
- gpio_get_value(pinIn[i], &gpioValue);
- switch (pinIn[i]) {
- //right slot
- case 22:
- bd1_1_status = gpioValue;
- break;
- case 23:
- bd1_2_status = gpioValue;
- break;
- //left slot
- case 44:
- bd0_1_status = gpioValue;
- break;
- case 45:
- bd0_2_status = gpioValue;
- break;
- }
- }
- #if 1 //DS60-120 remove
- //BD1(Left-CCS-CND1-SMR2-左槍), BD2(Right-CHADEMO-CND2-SMR1-右槍), CCS: 10 , CHAdeMO: 01 , GBT: 11
- //CcsChargingData [0至1] 分別為 Right至Left
- //model name 槍順序左至右分別為Right至Left
- tmp[1] = (bd0_1_status << 4 | bd0_2_status);
- tmp[0] = (bd1_1_status << 4 | bd1_2_status);
- for (i = 0; i < 2; i++) {
- switch (tmp[i]) {
- case 0x01:
- log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CHAdeMO");
- break;
- case 0x10:
- log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CCS");
- break;
- case 0x11:
- log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "GBT");
- break;
- case 0x00:
- log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "None");
- break;
- }
- }
- #endif //0
- }
- void CheckGpioInStatus()
- {
- int pinIn[2] = { 27, 47 };//{IO BD1_2, IO BD2_2}
- unsigned int gpioValue = 0;
- for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
- gpio_get_value(pinIn[i], &gpioValue);
- if (gpioValue == 0x01) {
- switch (pinIn[i]) {
- // 小板緊急停止
- case 47: {
- for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
- if (chargingInfo[i]->slotsIndex == 1) {
- if (chargingInfo[i]->Type == _Type_Chademo) {
- BoardErrOccurByString(i, "023730");
- } else if (chargingInfo[i]->Type == _Type_CCS_2) {
- BoardErrOccurByString(i, "013627");
- }
- break;
- }
- }
- }
- break;
- case 27: {
- for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
- if (chargingInfo[i]->slotsIndex == 3) {
- if (chargingInfo[i]->Type == _Type_Chademo) {
- BoardErrOccurByString(i, "023730");
- } else if (chargingInfo[i]->Type == _Type_CCS_2) {
- BoardErrOccurByString(i, "013627");
- }
- break;
- }
- }
- }
- break;
- }
- } else {
- switch (pinIn[i]) {
- // 小板解除緊急停止
- case 47: {
- for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
- if (chargingInfo[i]->slotsIndex == 1) {
- if (chargingInfo[i]->Type == _Type_Chademo) {
- ReleaseBoardErrOccurByString(i, "023730");
- } else if (chargingInfo[i]->Type == _Type_CCS_2) {
- ReleaseBoardErrOccurByString(i, "013627");
- }
- break;
- }
- }
- }
- break;
- case 27: {
- for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
- if (chargingInfo[i]->slotsIndex == 3) {
- if (chargingInfo[i]->Type == _Type_Chademo) {
- ReleaseBoardErrOccurByString(i, "023730");
- } else if (chargingInfo[i]->Type == _Type_CCS_2) {
- ReleaseBoardErrOccurByString(i, "013627");
- }
- break;
- }
- }
- }
- break;
- }
- }
- }
- }
- //===============================================
- // Main process
- //===============================================
- // 檢查 Byte 中某個 Bit 的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
- {
- return ( _byte & mask_table[_bit] ) != 0x00;
- }
- // 設定 Byte 中某個 Bit的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- // value : 修改的值為 0 or 1
- void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
- {
- if (value == 1) {
- *_byte |= (1 << _bit);
- } else if (value == 0) {
- *_byte ^= (1 << _bit);
- }
- }
- void UserScanFunction()
- {
- bool idleReq = false;
- unsigned char stopReq = 255;
- // 當前非驗證的狀態
- if (!IsAuthorizingMode()) {
- #if defined DD360Audi
- //當前沒有選槍
- if (getConfirmSelectedGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected) == FAIL) { //Jerry add
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- return;
- }
- #endif //defined DD360Audi
- // 先判斷現在是否可以提供刷卡
- // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
- // 2. 停止充電
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- return;
- }
- for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
- if (chargingInfo[i]->SystemStatus == S_CHARGING) {
- stopReq = i;
- }
- if ((chargingInfo[i]->SystemStatus == S_IDLE && chargingInfo[i]->IsAvailable) == YES ||
- (_acgunIndex > 0 && ac_chargingInfo[0]->SystemStatus == S_IDLE && ac_chargingInfo[0]->IsAvailable)) {
- idleReq = true;
- }
- }
- if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
- ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
- stopReq = DEFAULT_AC_INDEX;
- }
- if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0) {
- if (_acgunIndex > 0 && stopReq == DEFAULT_AC_INDEX && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) {
- char value[32];
- PRINTF_FUNC("ac stop charging \n");
- PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
- ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
- memcpy(value, (unsigned char *)ac_chargingInfo[0]->StartUserId,
- ARRAY_SIZE(ac_chargingInfo[0]->StartUserId));
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL) {
- AcChargingTerminalProcess();
- }
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- } else if (stopReq < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING &&
- (_acgunIndex <= 0 || (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE))) {
- char value[32];
- PRINTF_FUNC("stop charging \n");
- PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected,
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
- memcpy(value, (unsigned char *)chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
- ARRAY_SIZE(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId));
- // 同一張卡直接停掉
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL) {
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- } else {
- // 進驗證
- if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) {
- _authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
- } else {
- _authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
- }
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- StartSystemTimeoutDet(Timeout_AuthorizingForStop);
- AuthorizingStart();
- #else
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- #endif //!defined DD360 && !defined DD360Audi
- }
- } else if (idleReq) {
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 &&
- stopReq != 255 &&
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
- idleReq = false;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- } else if ((_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE) {
- PRINTF_FUNC("// LCM => Authorizing \n");
- #if defined DD360Audi
- setSelGunWaitToAuthor(ShmSysConfigAndInfo->SysInfo.CurGunSelected); //Jerry add
- #endif //defined DD360Audi
- // LCM => Authorizing
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
- // 進入確認卡號狀態
- AuthorizingStart();
- } else {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- } else {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- }
- } else {
- // 透過後臺停止充電的判斷
- if (isAuthorizedComplete()
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
- #endif //!defined DD360 && !defined DD360Audi
- ) {
- // 判斷後台回覆狀態
- if (canStartCharging()
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
- #endif //!defined DD360 && !defined DD360Audi
- ) {
- if (_authorizeIndex != NO_DEFINE) {
- // 先找 AC
- if (_authorizeIndex == DEFAULT_AC_INDEX) {
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
- strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL) {
- AcChargingTerminalProcess();
- }
- } else {
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
- strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL) {
- ChargingTerminalProcess(_authorizeIndex);
- }
- }
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- _authorizeIndex = NO_DEFINE;
- }
- } else {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- ClearAuthorizedFlag();
- } else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
- // 白名單驗證
- for (int i = 0; i < 10; i++) {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL) {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL) {
- ChargingTerminalProcess(_authorizeIndex);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearAuthorizedFlag();
- break;
- }
- }
- }
- }
- }
- }
- unsigned char isModeChange(unsigned char gun_index)
- {
- unsigned char result = NO;
- if (chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus) {
- result = YES;
- chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
- }
- return result;
- }
- void ScannerCardProcess()
- {
- if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level != 2 &&
- ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
- isCardScan = true;
- // 處理刷卡及驗證卡號的動作
- UserScanFunction();
- }
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING) {
- StartSystemTimeoutDet(Timeout_Authorizing);
- // 確認驗證卡號完成沒
- if (isAuthorizedComplete()
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
- #endif //!defined DD360 && !defined DD360Audi
- ) {
- StopSystemTimeoutDet();
- // 判斷後台回覆狀態
- if (canStartCharging()
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
- #endif //!defined DD360 && !defined DD360Audi
- ) {
- // LCM => Authorize complete
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
- } else {
- // LCM => Authorize fail
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- ClearAuthorizedFlag();
- } else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
- // 白名單驗證
- for (int i = 0; i < 10; i++) {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL) {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL) {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
- ClearAuthorizedFlag();
- break;
- }
- }
- }
- }
- } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL) {
- StartSystemTimeoutDet(Timeout_VerifyFail);
- isCardScan = false;
- } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP) {
- StartSystemTimeoutDet(Timeout_VerifyComp);
- } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG) {
- StartSystemTimeoutDet(Timeout_WaitPlug);
- } else {
- isCardScan = false;
- }
- }
- bool AddGunInfoByConnector(byte typeValue, byte slots)
- {
- bool result = true;
- switch (typeValue) {
- case '0': // none
- break;
- case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
- break;
- case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
- break;
- case '3': // IEC 62196-2 Type 2 Plug
- case '4': // IEC 62196-2 Type 2 Socket
- if (AC_QUANTITY > _ac_Index) {
- ac_chargingInfo[_acgunIndex] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[_ac_Index];
- // AC 固定 index
- ac_chargingInfo[_acgunIndex]->Index = 0;
- ac_chargingInfo[_acgunIndex]->ReservationId = -1;
- ac_chargingInfo[_acgunIndex]->SystemStatus = S_IDLE;
- ac_chargingInfo[_acgunIndex]->Type = _Type_AC;
- ac_chargingInfo[_acgunIndex]->IsAvailable = YES;
- ac_chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO; //DS60-120 add
- ac_chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
- _ac_Index++;
- _acgunIndex++;
- } else {
- result = false;
- }
- break;
- case '5': // GB/T AC Plug
- break;
- case '6': // GB/T AC Socket
- break;
- case 'J':
- case 'K': { // CHAdeMO
- if (CHAdeMO_QUANTITY > _chademoIndex) {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = -1;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_Chademo;
- chargingInfo[_gunIndex]->type_index = _chademoIndex;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO; //DS60-120 add
- chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
- _chademoIndex++;
- _gunIndex++;
- } else {
- result = false;
- }
- }
- break;
- case 'T': //Rema CCS1
- case 'D': //Rema CCS2
- case 'U': // CCS1 combo
- case 'E': // CCS2 combo
- case 'V': // Liquid CCS1 combo
- case 'F': { // Liquid CCS2 combo
- if (CCS_QUANTITY > _ccsIndex) {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = -1;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_CCS_2;
- chargingInfo[_gunIndex]->type_index = _ccsIndex;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;//DS60-120 add
- chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
- // 現階段預設為走 DIN70121
- ShmCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
- _ccsIndex++;
- _gunIndex++;
- } else {
- result = false;
- }
- }
- break;
- case 'G': { // GBT DC
- if (GB_QUANTITY > _gb_Index) {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[_gb_Index];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = -1;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_GB;
- chargingInfo[_gunIndex]->type_index = _gb_Index;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;//DS60-120 add
- chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
- _gb_Index++;
- _gunIndex++;
- } else {
- result = false;
- }
- }
- break;
- //case 'D': // GBT DC x 2
- // break;
- }
- return result;
- }
- bool CheckConnectorTypeStatus()
- {
- bool result = true;
- //PRINTF_FUNC("bd0_1_status = %d, bd0_2_status = %d, bd1_1_status = %d, bd1_2_status = %d \n",
- // bd0_1_status,
- // bd0_2_status,
- // bd1_1_status,
- // bd1_2_status);
- if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9) {
- //printf("1 CheckConnectorTypeStatus\r\n");
- byte slots = 1;
- for (byte typeIndex = 7; typeIndex <= 9; typeIndex++) {
- if (!AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots)) {
- return false;
- }
- slots++;
- }
- // AC index 接在 DC 後面
- //if (AC_QUANTITY > 0) {
- if (_ac_Index > 0) { //DS60-120 add
- ac_chargingInfo[0]->Index += _gunIndex;
- }
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = _gunIndex;
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount = _acgunIndex;
- log_info("DC connector Quality = %d, AC connector Quality = %d",
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount);
- log_info("Type 0~3 = CHAdeMO, CCS, GB, AC");
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0 &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0) {
- result = false;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
- //DS60-120 add
- bool isFind = false;
- if (chargingInfo[0]->Type == _Type_Chademo) {
- if ((bd0_1_status == 0 && bd0_2_status == 1) ||
- (bd1_1_status == 0 && bd1_2_status == 1)) {
- isFind = true;
- }
- } else if (chargingInfo[0]->Type == _Type_CCS_2) {
- if ((bd0_1_status == 1 && bd0_2_status == 0) ||
- (bd1_1_status == 1 && bd1_2_status == 0)) {
- isFind = true;
- }
- } else if (chargingInfo[0]->Type == _Type_GB) {
- if ((bd0_1_status == 1 && bd0_2_status == 1) ||
- (bd1_1_status == 1 && bd1_2_status == 1)) {
- isFind = true;
- }
- }
- if (isFind) {
- if (bd0_1_status == 1 || bd0_2_status == 1) {
- chargingInfo[0]->Evboard_id = 0x01;
- }
- if (bd1_1_status == 1 || bd1_2_status == 1) {
- chargingInfo[0]->Evboard_id = 0x02;
- }
- CheckHwSlotStatusLog(0);
- } else {
- result = false;
- }
- //chargingInfo[0]->Evboard_id = 0x01;
- log_info("index = %d, Type = %d, Evboard_id = %d", 0, chargingInfo[0]->Type, chargingInfo[0]->Evboard_id);
- } else {
- char type = NO_DEFINE; //DS60-120 add
- // 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
- for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++) {
- if (gunIndex == 0 && bd0_1_status == 0 && bd0_2_status == 1) {
- // 與硬體相同 type : Chademo
- if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- } else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 0) {
- // 與硬體相同 type : CCS
- if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- } else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 1) {
- // 與硬體相同 type : GB
- if (chargingInfo[gunIndex]->Type == _Type_GB) {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- }
- if (gunIndex == 1 && bd1_1_status == 0 && bd1_2_status == 1) {
- // 與硬體相同 type : Chademo
- if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
- chargingInfo[gunIndex]->Evboard_id = 0x02;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- } else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 0) {
- // 與硬體相同 type : CCS
- if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
- chargingInfo[gunIndex]->Evboard_id = 0x02;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- } else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 1) {
- // 與硬體相同 type : GB
- if (chargingInfo[gunIndex]->Type == _Type_GB) {
- chargingInfo[gunIndex]->Evboard_id = 0x02;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- }
- log_info("index = %d, Type = %d, Evboard_id = %d",
- gunIndex,
- chargingInfo[gunIndex]->Type,
- chargingInfo[gunIndex]->Evboard_id);
- CheckHwSlotStatusLog(gunIndex);
- if (type == NO_DEFINE) {
- type = chargingInfo[gunIndex]->Type;
- }
- #if defined METER_ENABLE
- else {
- // 雙槍都是同一個 type
- if (type == chargingInfo[gunIndex]->Type) {
- ShmDcCommonData->SysGunAreSameType = YES;
- }
- }
- #endif //METER_ENABLE
- if (chargingInfo[gunIndex]->Evboard_id == 0x00) {
- result = false;
- }
- }
- }
- } else {
- // Module Name 不正確 - 告警
- result = false;
- }
- return result;
- }
- void KillTask()
- {
- ChangeLcmByIndex(_LCM_FIX);
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_LcmControl");
- system("killall Module_InternalComm");
- //system("killall DoComm");
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- system("killall Module_PsuComm");
- system("killall OcppBackend &");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- #endif //!defined DD360 && !defined DD360Audi
- }
- void KillTaskExceptPrimary()
- {
- ChangeLcmByIndex(_LCM_FIX);
- system("killall Module_EvComm");
- system("killall Module_InternalComm");
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- system("killall Module_PsuComm");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- #endif //!defined DD360 && !defined DD360Audi
- }
- void KillAllTask()
- {
- ChangeLcmByIndex(_LCM_FIX);
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_LcmControl");
- system("killall Module_InternalComm");
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- system("killall Module_PsuComm");
- system("killall OcppBackend &");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- #else
- system("killall DoComm");
- #endif //!defined DD360 && !defined DD360Audi
- }
- int CheckUpdateProcess(void)
- {
- //bool isPass = true;
- uint8_t retSucc = 0;
- uint8_t retFail = 0;
- byte index = 0;
- byte target = 0;
- char *new_str = NULL;
- unsigned char *ptr = NULL;
- int fd = 0;
- int CanFd = 0;
- int uartFd = 0;
- unsigned int Type = 0;
- long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
- DIR *d;
- struct dirent *dir;
- d = opendir("/mnt/");
- if (d) {
- while ((dir = readdir(d)) != NULL) {
- if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
- continue;
- }
- new_str = calloc(strlen("/mnt/") + strlen(dir->d_name) + 1, sizeof(char));
- //new_str[0] = '\0';
- strcat(new_str, "/mnt/");
- strcat(new_str, dir->d_name);
- log_info("%s%s\r\n", "/mnt/", dir->d_name);
- fd = open(new_str, O_RDONLY);
- if (fd < 0) {
- return FAIL;
- }
- ptr = calloc(MaxLen, sizeof(char)); //-48 is take out the header
- //memset(ptr, 0xFF, MaxLen); //-48 is take out the header
- //get the image length
- ImageLen = read(fd, ptr, MaxLen);
- for (byte i = 0; i < 16; i++) {
- if (ShmSysConfigAndInfo->SysConfig.ModelName[i] != ptr[i]) {
- return FAIL;
- }
- }
- PRINTF_FUNC("model name check pass. \n");
- if (ImageLen > 20) {
- Type = (((unsigned int)ptr[16]) << 24 |
- ((unsigned int)ptr[17]) << 16 |
- ((unsigned int)ptr[18]) << 8 |
- ((unsigned int)ptr[19]));
- PRINTF_FUNC("Typed...%x \r\n", Type);
- switch (Type) {
- case 0x10000001:
- case 0x10000002:
- case 0x10000003:
- case 0x10000004:
- case 0x10000005:
- if (Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
- //return PASS;
- retSucc++;
- } else {
- PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
- //return FAIL;
- retFail++;
- }
- break;
- case 0x10000007:
- case 0x10000008:
- case 0x10000009:
- case 0x1000000A:
- //isPass = true;
- CanFd = InitCanBus();
- if (CanFd > 0) {
- for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
- //if (!isPass) {
- // break;
- //}
- if (chargingInfo[index]->Type == _Type_CCS_2) {
- if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL) {
- //isPass = false;
- PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
- retFail++;
- }
- }
- }
- } else {
- log_error("Upgrade CCS open CAN FD fail.\n");
- //isPass = false;
- return FAIL;
- }
- if (retFail != 0) {
- break;
- } else {
- retSucc++;
- }
- //return isPass;
- break;
- case 0x10000006:
- case 0x1000000D:
- case 0x1000000E:
- case 0x20000002:
- case 0x10000014:
- // CSU_PRIMARY_CONTROLLER : 0x10000006
- target = 0x00;
- if (Type == 0x10000006) {
- target = UPGRADE_PRI;
- } else if (Type == 0x1000000D) {
- target = UPGRADE_RB;
- } else if (Type == 0x1000000E) {
- target = UPGRADE_FAN;
- } else if (Type == 0x20000002) {
- target = UPGRADE_AC;
- } else if (Type == 0x10000014) {
- target = UPGRADE_LED;
- }
- uartFd = InitComPort(target);
- if (Upgrade_UART(uartFd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
- //return PASS;
- retSucc++;
- } else {
- PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
- //return FAIL;
- return FAIL;
- }
- if (uartFd > 0) {
- close(uartFd);
- }
- break;
- case 0x1000000B:
- case 0x1000000C:
- // CHAdeMO_BOARD : 0x1000000B, GBT : 0x1000000C
- //bool isPass = true;
- CanFd = InitCanBus();
- if (CanFd > 0) {
- for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
- //if (!isPass) {
- // break;
- //}
- if ((Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo) ||
- (Type == 0x1000000C && chargingInfo[index]->Type == _Type_GB)) {
- if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
- //isPass = PASS;
- retSucc++;
- } else {
- PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
- //isPass = FAIL;
- retFail++;
- }
- }
- }
- } else {
- PRINTF_FUNC("Upgrad FD fail. \n");
- //isPass = false;
- return FAIL;
- }
- //return isPass;
- break;
- }
- }
- free(new_str);
- free(ptr);
- }
- }
- free(dir);
- closedir(d);
- if (retFail != 0) {
- return FAIL;
- }
- return PASS;
- }
- void CreateRfidFork()
- {
- pid_t rfidRecPid;
- rfidRecPid = fork();
- log_info("CreateRfidFork = %d\r\n", rfidRecPid);
- if (rfidRecPid == 0) {
- while (true) {
- // 刷卡判斷
- RFID rfid;
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
- !ShmSysConfigAndInfo->SysConfig.isRFID)
- {}
- else if (getRequestCardSN(rfidFd, 0, &rfid)) {
- //log_info("Get Card..-%s- \n", ShmSysConfigAndInfo->SysConfig.UserId);
- if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0) {
- if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
- switch (rfid.snType) {
- case RFID_SN_TYPE_6BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3],
- rfid.currentCard[4], rfid.currentCard[5]);
- break;
- case RFID_SN_TYPE_7BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3],
- rfid.currentCard[4], rfid.currentCard[5],
- rfid.currentCard[6]);
- break;
- case RFID_SN_TYPE_10BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3],
- rfid.currentCard[4], rfid.currentCard[5],
- rfid.currentCard[6], rfid.currentCard[7],
- rfid.currentCard[8], rfid.currentCard[9]);
- break;
- case RFID_SN_TYPE_4BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3]);
- break;
- }
- } else if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_BIG) {
- switch (rfid.snType) {
- case RFID_SN_TYPE_6BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[5], rfid.currentCard[4],
- rfid.currentCard[3], rfid.currentCard[2],
- rfid.currentCard[1], rfid.currentCard[0]);
- break;
- case RFID_SN_TYPE_7BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[6], rfid.currentCard[5],
- rfid.currentCard[4], rfid.currentCard[3],
- rfid.currentCard[2], rfid.currentCard[1],
- rfid.currentCard[0]);
- break;
- case RFID_SN_TYPE_10BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[9], rfid.currentCard[8],
- rfid.currentCard[7], rfid.currentCard[6],
- rfid.currentCard[5], rfid.currentCard[4],
- rfid.currentCard[3], rfid.currentCard[2],
- rfid.currentCard[1], rfid.currentCard[0]);
- break;
- case RFID_SN_TYPE_4BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X",
- rfid.currentCard[3], rfid.currentCard[2],
- rfid.currentCard[1], rfid.currentCard[0]);
- break;
- }
- }
- log_info("card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
- }
- }
- usleep(500000);
- }
- }
- }
- void StartSystemTimeoutDet(unsigned char flag)
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag) {
- gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
- }
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
- }
- void StopSystemTimeoutDet()
- {
- gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
- }
- void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
- {
- if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
- if (chargingInfo[gunIndex]->TimeoutFlag != flag) {
- gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
- }
- chargingInfo[gunIndex]->TimeoutFlag = flag;
- }
- }
- void StopGunInfoTimeoutDet(unsigned char gunIndex)
- {
- if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
- chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
- }
- }
- void CheckConnectionTimeout()
- {
- if (gAudiCustInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
- _connectionTimeout = gAudiCustInfo->RemoteSetup.ConnectionTimeout;
- } else {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- #if 0
- if (system("pidof -s OcppBackend > /dev/null") != 0) {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- } else {
- if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0) {
- _connectionTimeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
- if (_connectionTimeout <= 0) {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- } else {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- }
- #endif //0
- }
- void CreateTimeoutFork()
- {
- pid_t timeoutPid;
- timeoutPid = fork();
- log_info("CreateTimeoutFork = %d\r\n", timeoutPid);
- if (timeoutPid == 0) {
- gettimeofday(&_cmdSubPriority_time, NULL);
- CheckConnectionTimeout();
- while (1) {
- if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000) {
- CheckConnectionTimeout();
- gettimeofday(&_cmdSubPriority_time, NULL);
- }
- //printf("Timeout ***********SystemTimeoutFlag = %d, ********\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag);
- // 系統
- switch (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag) {
- case Timeout_SelftestChk:
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
- _SelfTestTimeout();
- StopSystemTimeoutDet();
- #if defined DD360Audi
- destroySelGun(DESTROY_ALL_SEL); //jerry add
- #endif //defined DD360Audi
- }
- break;
- case Timeout_Authorizing:
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
- _AuthorizedTimeout();
- StopSystemTimeoutDet();
- #if defined DD360Audi
- destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- #endif //defined DD360Audi
- }
- break;
- case Timeout_VerifyFail:
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
- _AutoReturnTimeout();
- StopSystemTimeoutDet();
- #if defined DD360Audi
- destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- #endif //defined DD360Audi
- }
- break;
- case Timeout_VerifyComp:
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
- _AutoReturnTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_WaitPlug:
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- #if defined DD360Audi
- destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- #endif //defined DD360Audi
- }
- break;
- case Timeout_ReturnToChargingGunDet: {
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
- #if defined DD360Audi
- if (getCurLcmPage() != _LCM_PRE_CHARGE &&
- getCurLcmPage() != _LCM_CHARGING &&
- getCurLcmPage() != _LCM_COMPLETE) {
- destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected); //jerry add
- }
- #endif //defined DD360Audi
- DisplayChargingInfo();
- StopSystemTimeoutDet();
- }
- }
- break;
- case Timeout_AuthorizingForStop: {
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearAuthorizedFlag();
- StopSystemTimeoutDet();
- }
- }
- break;
- }
- // 各槍
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
- //printf("Timeout ***********TimeoutFlag = %d, ********\n", chargingInfo[gun_index]->TimeoutFlag);
- switch (chargingInfo[gun_index]->TimeoutFlag) {
- case Timeout_Preparing: {
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
- _PrepareTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- #if defined DD360Audi
- destroySelGun(gun_index); //jerry add
- #endif //defined DD360Audi
- }
- }
- break;
- case Timeout_EvChargingDet: {
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
- _DetectEvChargingEnableTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- #if defined DD360Audi
- destroySelGun(gun_index); //jerry add
- #endif //defined DD360Audi
- }
- }
- break;
- case Timeout_EvseChargingDet: {
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
- _DetectEvseChargingEnableTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- #if defined DD360Audi
- destroySelGun(gun_index); //jerry add
- #endif //defined DD360Audi
- }
- }
- break;
- case Timeout_EvseCompleteDet: {
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
- StopGunInfoTimeoutDet(gun_index);
- #if defined DD360Audi
- destroySelGun(gun_index); //jerry add
- #endif //defined DD360Audi
- }
- }
- break;
- case Timeout_ForCcsPrechargeDet: {
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
- _CcsPrechargeTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- #if defined DD360Audi
- destroySelGun(gun_index); //jerry add
- #endif //defined DD360Audi
- }
- }
- break;
- #if defined DD360Audi
- case Timeout_SelectGun: //Jerry add
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
- log_info("Timeout_SelectGun\r\n");
- StopGunInfoTimeoutDet(gun_index);
- destroySelGun(gun_index); //jerry add
- }
- break;
- #endif //defined DD360Audi
- }
- }
- sleep(1);
- }
- }
- }
- void GetSystemTime()
- {
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
- tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- tmCSU->tm_sec);
- // byte date[14];
- //
- //
- // //sprintf(&date, "%d", );
- //
- // date[0] = '0' + ((tmCSU->tm_year + 1900) / 1000 % 10);
- // date[0] = (tmCSU->tm_year + 1900) / 1000 % 10;
- // date[1] = (tmCSU->tm_year + 1900) / 100 % 10;
- // date[2] = (tmCSU->tm_year + 1900) / 10 % 10;
- // date[3] = (tmCSU->tm_year + 1900) / 1 % 10;
- //
- // date[4] = (tmCSU->tm_mon + 1) / 10 % 10;
- // date[5] = (tmCSU->tm_mon + 1) / 1 % 10;
- //
- // date[6] = (tmCSU->tm_mday) / 10 % 10;
- // date[7] = (tmCSU->tm_mday) / 1 % 10;
- //
- // date[8] = (tmCSU->tm_hour) / 10 % 10;
- // date[9] = (tmCSU->tm_hour) / 1 % 10;
- //
- // date[10] = (tmCSU->tm_min) / 10 % 10;
- // date[11] = (tmCSU->tm_min) / 1 % 10;
- //
- // date[12] = (tmCSU->tm_sec) / 10 % 10;
- // date[13] = (tmCSU->tm_sec) / 1 % 10;
- // PRINTF_FUNC("%x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x \n", date[0], date[1], date[2], date[3],
- // date[4], date[5], date[6], date[7],
- // date[8], date[9], date[10], date[11],
- // date[12], date[13]);
- }
- void CheckFactoryConfigFunction()
- {
- char Buf[256] = {0};
- if (ShmSysConfigAndInfo->SysInfo.FactoryConfiguration) {
- sprintf(Buf, "cd /root;./FactoryConfig -m %s %s",
- ShmSysConfigAndInfo->SysConfig.ModelName,
- ShmSysConfigAndInfo->SysConfig.SerialNumber);
- system(Buf);
- system("rm -f /Storage/OCPP/OCPPConfiguration");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- }
- void CheckFwUpdateFunction()
- {
- //PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
- if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
- log_info("ftp : update start. \n");
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
- setChargerMode(gun_index, MODE_UPDATE);
- }
- byte updateResult = CheckUpdateProcess();
- if (updateResult == PASS) {
- log_info("ftp : update complete. \n");
- } else if (updateResult == MODELNAME_FAIL) {
- log_info("ftp : model name is none match. \n");
- KillAllTask();
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
- sleep(5);
- system("/usr/bin/run_evse_restart.sh");
- return;
- } else {
- log_info("ftp : update fail. \n");
- }
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
- sleep(5);
- system("reboot -f");
- } else if (ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES) {
- ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
- if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
- log_info("Backend : update start. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- KillTask();
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
- setChargerMode(_index, MODE_UPDATE);
- }
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++) {
- ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
- }
- byte updateResult = CheckUpdateProcess();
- if (updateResult == PASS) {
- log_info("Backend : update complete. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
- } else if (updateResult == MODELNAME_FAIL) {
- log_info("Backend : model name is none match. \n");
- KillAllTask();
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- system("/usr/bin/run_evse_restart.sh");
- return;
- } else {
- log_info("Backend : update fail. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
- }
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- system("reboot -f");
- }
- }
- }
- //===============================================
- // Check reservation date is expired
- //===============================================
- int isReservationExpired(unsigned char gun_index)
- {
- int result = NO;
- struct tm expiredDate;
- struct timeb expiredTime;
- if (sscanf((char *) ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,
- "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
- &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
- &expiredDate.tm_min, &expiredDate.tm_sec) == 6) {
- expiredDate.tm_year -= 1900;
- expiredDate.tm_mon -= 1;
- expiredTime.time = mktime(&expiredDate);
- if (!CheckTimeOut(expiredTime)) {
- result = YES;
- }
- }
- return result;
- }
- //===============================================
- // OCPP
- //===============================================
- void CheckOcppStatus()
- {
- if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
- ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
- }
- if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES) {
- bool canReset = true;
- bool canHardReset = true; //DS60-120 add
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
- if (chargingInfo[_index]->SystemStatus != S_IDLE &&
- chargingInfo[_index]->SystemStatus != S_RESERVATION &&
- chargingInfo[_index]->SystemStatus != S_MAINTAIN) {
- canReset = false;
- if (chargingInfo[_index]->SystemStatus >= S_REASSIGN &&
- chargingInfo[_index]->SystemStatus < S_TERMINATING) {
- canHardReset = false;
- ChargingTerminalProcess(_index);
- restartFlag = 1;
- }
- }
- }
- }
- if (canReset) {
- ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
- sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
- if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL) {
- log_error("****** Hard Reboot ****** \n");
- ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- system("reboot -f");
- } else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL) {
- log_error("****** Soft Reboot ****** \n");
- ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- system("killall OcppBackend &");
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- }
- }
- void OcppStartTransation(byte gunIndex)
- {
- byte _OcppGunIndex = gunIndex;
- // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
- _OcppGunIndex = 2;
- }
- if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
- } else {
- strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
- }
- PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
- ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
- }
- void OcppStopTransation(byte gunIndex)
- {
- byte _OcppGunIndex = gunIndex;
- // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
- _OcppGunIndex = 2;
- }
- if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
- } else {
- strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
- }
- PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
- ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
- }
- bool OcppRemoteStop(byte gunIndex)
- {
- byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- // 有 AC 槍的話
- if (acDirIndex > 0 && gunIndex > 0) {
- gunIndex += acDirIndex;
- }
- bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
- if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
- ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
- }
- return result;
- }
- bool WifiScheduleStop(byte gunIndex)
- {
- bool result = false;
- result = chargingInfo[gunIndex]->schedule.isTriggerStop;
- chargingInfo[gunIndex]->schedule.isTriggerStop = NO;
- return result;
- }
- void OcppRemoteStartChk()
- {
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
- {}
- else if (!isDetectPlugin()) {
- // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
- byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- for (byte ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++) {
- if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
- if (ac_chargingInfo[ac_index]->SystemStatus == S_IDLE ||
- ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION) {
- ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
- ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
- ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
- DetectPluginStart();
- return;
- }
- ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
- }
- }
- byte threeGunIndex = 0;
- byte dcIndex = 0;
- bool isGunUsingStatus = false;
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
- // 如果有 AC 槍,且 DC 槍也有兩把
- if (acDirIndex == 1 && _index == 1) {
- threeGunIndex = 1;
- }
- if (ShmOCPP16Data->CsMsg.bits[_index + threeGunIndex].RemoteStartTransactionReq == YES) {
- dcIndex = _index;
- }
- if (chargingInfo[_index]->SystemStatus != S_IDLE) {
- isGunUsingStatus = true;
- }
- }
- // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
- if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
- if (dcIndex == 0) {
- threeGunIndex = 0;
- }
- ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
- return;
- }
- if (dcIndex == 0) {
- threeGunIndex = 0;
- }
- if (ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq == YES) {
- if (chargingInfo[dcIndex]->SystemStatus == S_IDLE ||
- chargingInfo[dcIndex]->SystemStatus == S_RESERVATION) {
- chargingInfo[dcIndex]->RemoteStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
- ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
- DetectPluginStart();
- #if defined DD360Audi
- setSelGunWaitToAuthor(dcIndex); //Jerry add
- #endif //defined DD360Audi
- }
- ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
- }
- }
- }
- void ChkOcppStatus(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
- if (isReservationExpired(gunIndex)) {
- PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- log_error("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
- chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
- }
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
- }
- if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
- if (isReservationExpired(gunIndex)) {
- PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
- log_error("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
- chargingInfo[gunIndex]->ReservationId = 0;
- chargingInfo[gunIndex]->SystemStatus = S_IDLE;
- }
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
- }
- if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
- PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- log_error("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
- if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL) {
- if (isDb_ready) {
- DB_Update_Operactive(localDb, gunIndex, true);
- }
- chargingInfo[gunIndex]->IsAvailable = YES;
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
- setChargerMode(gunIndex, MODE_IDLE);
- }
- } else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL) {
- if (isDb_ready) {
- DB_Update_Operactive(localDb, gunIndex, false);
- }
- chargingInfo[gunIndex]->IsAvailable = NO;
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
- setChargerMode(gunIndex, MODE_MAINTAIN);
- }
- }
- }
- if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
- ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
- if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK && // DS60-120 add ||
- chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) {
- // 充電中,需停止充電
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
- ChargingTerminalProcess(gunIndex);
- }
- strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
- ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
- }
- }
- bool CheckBackendChargingTimeout(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) {
- if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60)) {
- result = true;
- }
- }
- } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
- // 隨插即充電的要看 offline
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0) {
- if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60)) {
- result = true;
- }
- }
- }
- return result;
- }
- bool CheckBackendChargingEnergy(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) {
- if (chargingInfo[gunIndex]->PresentChargedEnergy > ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy) {
- result = true;
- }
- }
- } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
- // 隨插即充電的要看 offline
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0) {
- if (chargingInfo[gunIndex]->PresentChargedEnergy > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy)) {
- result = true;
- }
- }
- }
- return result;
- }
- void InformOcppErrOccur(byte codeType)
- {
- char _error[25];
- switch (codeType) {
- case 4: strcpy(_error, "InternalError"); break;
- case 6: strcpy(_error, "NoError"); break;
- case 7: strcpy(_error, "OtherError"); break;
- case 13: strcpy(_error, "UnderVoltage"); break;
- case 14: strcpy(_error, "OverVoltage"); break;
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, _error);
- }
- }
- //===============================================
- // SQLite3 related routine
- //===============================================
- int DB_Open(sqlite3 *db)
- {
- int result = PASS;
- char *errMsg = NULL;
- char *createRecordSql = "CREATE TABLE IF NOT EXISTS charging_record("
- "idx integer primary key AUTOINCREMENT, "
- "reservationId text, "
- "transactionId text, "
- "startMethod text, "
- "userId text, "
- "dateTimeStart text, "
- "dateTimeStop text,"
- "socStart text, "
- "socStop text, "
- "chargeEnergy text, "
- "stopReason text"
- ");";
- /*char *createCfgSql = "CREATE TABLE IF NOT EXISTS `config` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`IsAvailable` TEXT NOT NULL, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(IsAvailable,connector) on conflict replace);";
- */
- //DS60-120 add
- char *createCfgSql = "CREATE TABLE IF NOT EXISTS `config` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`item` TEXT NOT NULL, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(item,connector) on conflict replace);";
- char *createrecordSql = "CREATE TABLE IF NOT EXISTS `event_record` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`occurDatetime` TEXT NOT NULL, "
- "`statusCode` TEXT NOT NULL, unique(occurDatetime,statusCode) on conflict replace);";
- char *createrebootSql = "CREATE TABLE IF NOT EXISTS `reboot_record` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`rebootDatetime` TEXT NOT NULL, unique(rebootDatetime) on conflict replace);";
- if (sqlite3_open(DB_FILE, &db)) {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- } else {
- PRINTF_FUNC( "Local charging record database open successfully.\r\n");
- if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
- result = FAIL;
- PRINTF_FUNC( "Create local charging record table error message: %s\n", errMsg);
- } else {
- PRINTF_FUNC( "Opened local charging record table successfully\n");
- }
- if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK) {
- result = FAIL;
- PRINTF_FUNC( "Create local config table error message: %s\n", errMsg);
- } else {
- PRINTF_FUNC( "Opened local config table successfully\n");
- }
- //DS60-120
- if (sqlite3_exec(db, createrecordSql, 0, 0, &errMsg) != SQLITE_OK) {
- result = FAIL;
- PRINTF_FUNC( "Create local record table error message: %s\n", errMsg);
- } else {
- PRINTF_FUNC( "Opened local record table successfully\n");
- }
- if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK) {
- result = FAIL;
- PRINTF_FUNC( "Create reboot record table error message: %s\n", errMsg);
- } else {
- PRINTF_FUNC( "Opened reboot record table successfully\n");
- }
- //-----
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Insert_Record(sqlite3 *db, int gun_index)
- {
- int result = PASS;
- char *errMsg = NULL;
- char insertSql[1024];
- sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
- "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
- chargingInfo[gun_index]->ReservationId, //DS60-120 add
- ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
- chargingInfo[gun_index]->StartMethod,
- chargingInfo[gun_index]->StartUserId,
- chargingInfo[gun_index]->StartDateTime,
- chargingInfo[gun_index]->StopDateTime,
- chargingInfo[gun_index]->EvBatteryStartSoc,
- chargingInfo[gun_index]->EvBatterySoc,
- chargingInfo[gun_index]->PresentChargedEnergy,
- //DS60-120 remove
- //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
- //ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
- //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
- //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
- //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
- //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
- //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
- //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
- //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
- ShmOCPP16Data->StopTransaction[gun_index].StopReason);
- //if (sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db)) {
- if (sqlite3_open(DB_FILE, &db)) { //DS60-120 add
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- } else {
- PRINTF_FUNC( "Local charging record database open successfully.\r\n");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
- result = FAIL;
- PRINTF_FUNC( "Insert local charging record error message: %s\n", errMsg);
- } else {
- PRINTF_FUNC( "Insert local charging record successfully\n");
- }
- //DS60-120 add
- sprintf(insertSql, "delete from charging_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
- result = FAIL;
- PRINTF_FUNC( "delete local charging error message: %s\n", errMsg);
- } else {
- PRINTF_FUNC( "delete local charging record successfully\n");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable)
- {
- uint8_t result = false;
- char *errMsg = NULL;
- char sqlStr[1024];
- srand(time(NULL));
- if (sqlite3_open(DB_FILE, &db)) {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- } else {
- PRINTF_FUNC( "Local charging record database open successfully (%d).\r\n", IsAvailable);
- //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
- sprintf(sqlStr, "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable); //DS60-120 add
- PRINTF_FUNC("sqlStr= %s\r\n", sqlStr);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
- result = FAIL;
- PRINTF_FUNC( "update config error message: %s\n", errMsg);
- } else {
- PRINTF_FUNC("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
- {
- uint8_t result = true;
- char *errMsg = NULL;
- char sqlStr[1024];
- char **rs;
- int rows, cols;
- //sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gun_index);
- sprintf(sqlStr, "select * from config where item='IsAvailable' and connector=%d;", gun_index); //DS60-120 add
- //DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
- if (sqlite3_open(DB_FILE, &db)) {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- } else {
- PRINTF_FUNC( "Local config query database open successfully.\r\n");
- sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
- if (rows > 0) {
- for (int idxRow = 1; idxRow <= rows; idxRow++) {
- if (strcmp(rs[(idxRow * cols) + 3], "0") == 0) {
- result = false;
- }
- PRINTF_FUNC("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow * cols) + 3]);
- }
- } else {
- PRINTF_FUNC("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Reboot_Record(sqlite3 *db)
- {
- int result = PASS;
- char *errMsg = NULL;
- char insertSql[256];
- sprintf(insertSql, "insert into reboot_record(rebootDatetime) values(CURRENT_TIMESTAMP);");
- if (sqlite3_open(DB_FILE, &db)) {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- } else {
- PRINTF_FUNC( "Local charging record database open successfully.\n");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
- result = FAIL;
- PRINTF_FUNC( "Insert reboot record error message: %s\n", errMsg);
- } else {
- PRINTF_FUNC( "Insert reboot record successfully\n");
- }
- sprintf(insertSql, "delete from reboot_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
- result = FAIL;
- PRINTF_FUNC( "delete reboot record error message: %s\n", errMsg);
- } else {
- PRINTF_FUNC( "delete reboot record successfully\n");
- }
- sqlite3_close(db);
- }
- return result;
- }
- //===============================================
- // Config process
- //===============================================
- void AddPlugInTimes(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
- ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
- } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
- ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
- } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
- ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
- }
- }
- void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
- {
- char cmdBuf[32];
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
- tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- tmCSU->tm_sec);
- if (isStart) {
- strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
- } else {
- strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
- }
- }
- void zipLogFiles()
- {
- const char *logPath = "/Storage/SystemLog";
- // 獲取目錄
- DIR *pDir = opendir(logPath);
- if (pDir != NULL) {
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- // PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
- // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- // tmCSU->tm_sec);
- // Read items inside the folder
- struct dirent *pEntry = NULL;
- while ((pEntry = readdir(pDir)) != NULL) {
- if (strcmp(pEntry->d_name, ".") != 0 &&
- strcmp(pEntry->d_name, "..") != 0 &&
- strncmp(pEntry->d_name, "[", 1) == 0 &&
- strstr(pEntry->d_name, "tar") < 0) {
- char yearC[5];
- unsigned short year = 0;
- char monthC[3];
- unsigned short month = 0;
- yearC[4] = '\0';
- strncpy(yearC, pEntry->d_name + 1, 4);
- monthC[2] = '\0';
- strncpy(monthC, pEntry->d_name + 6, 2);
- year = atoi(yearC);
- month = atoi(monthC);
- if (year != 0) {
- if (year < tmCSU->tm_year + 1900 ||
- (year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1)) {
- log_info("tar file name : %s \n", pEntry->d_name);
- char file[256];
- memset(file, 0x00, sizeof(file));
- strcat(file, "tar zcvf ");
- strcat(file, logPath);
- strncat(file, "/", 1);
- strcat(file, pEntry->d_name);
- strcat(file, ".tar");
- strncat(file, " ", 1);
- strcat(file, logPath);
- strncat(file, "/", 1);
- strcat(file, pEntry->d_name);
- PRINTF_FUNC("zip = %s \n", file);
- system(file);
- }
- }
- }
- }
- }
- // Close folder
- closedir(pDir);
- }
- void ChangeGunSelectByIndex(byte sel)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = sel;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- }
- void CheckIsAlternatvieByModelName()
- {
- // 黑白機 ?
- /*if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWWU301J0UT1PH") == EQUAL ||
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYE301J0ET1PH") == EQUAL ||
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DSYE301J3EW2PH") == EQUAL ||
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYC301J0UW1PH") == EQUAL) {
- */
- if (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W') { //DS60-120
- // 壁掛
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = YES;
- } else {
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = NO;
- }
- }
- void StopProcessingLoop()
- {
- for (;;) {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
- ChkPrimaryStatus();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 0) {
- PRINTF_FUNC("Soft reboot for retry self-tets (Primary). \n");
- KillAllTask();
- sleep(3);
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- }
- sleep(1);
- }
- }
- void CreateWatchdog()
- {
- if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO) {
- wtdFd = InitWatchDog();
- if (wtdFd < 0) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- }
- }
- bool IsConnectorWholeIdle()
- {
- bool result = true;
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
- if (chargingInfo[count]->SystemStatus != S_IDLE &&
- chargingInfo[count]->SystemStatus != S_RESERVATION) {
- result = false;
- break;
- }
- }
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++) {
- if (ac_chargingInfo[count]->SystemStatus != S_IDLE &&
- ac_chargingInfo[count]->IsErrorOccur == NO) {
- result = false;
- break;
- }
- }
- return result;
- }
- void ClearAlarmCodeWhenAcOff()
- {
- if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- }
- }
- //==========================================
- // Check task processing
- //==========================================
- void CheckTask()
- {
- /*+++ 20200908, vern, disable it for DD360 +++*/
- #if 0
- if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') {
- if (system("pidof -s Module_4g > /dev/null") != 0) {
- log_error("Module_4g not running, restart it.\r\n");
- system("/root/Module_4g &");
- }
- } else if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') {
- if (system("pidof -s Module_Wifi > /dev/null") != 0) {
- log_error("Module_Wifi not running, restart it.\r\n");
- system("/root/Module_Wifi &");
- }
- }
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL) {
- if (system("pidof -s OcppBackend > /dev/null") != 0) {
- log_error("OcppBackend not running, restart it.\r\n");
- system("/root/OcppBackend &");
- }
- }
- #endif
- /*--- 20200908, vern, disable it for DD360 ---*/
- if (system("pidof -s Module_ProduceUtils > /dev/null") != 0) {
- log_error("Module_ProduceUtils not running, restart it.\r\n");
- system ("/root/Module_ProduceUtils &");
- }
- }
- void InitialDHCP()
- {
- char tmpbuf[256] = {0};
- system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
- sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
- ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- //==========================================
- // Check Smart Charging Profile
- //==========================================
- int GetStartScheduleTime(unsigned char *time)
- {
- int result = -1;
- struct tm tmScheduleStart;
- struct timeb tbScheduleStart;
- if ((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6)) {
- tmScheduleStart.tm_year -= 1900;
- tmScheduleStart.tm_mon -= 1;
- tbScheduleStart.time = mktime(&tmScheduleStart);
- tbScheduleStart.millitm = 0;
- result = DiffTimebWithNow(tbScheduleStart) / 1000;
- }
- return result;
- }
- void CheckSmartChargeProfile(byte _index)
- {
- if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
- // Get Charging Profile
- ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
- if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
- ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES //DS60-120 add
- ) {
- int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
- byte _startCount = NO_DEFINE;
- byte _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
- for (byte _count = 0; _count < _maxCount; _count++) {
- // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
- if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod) {
- if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
- ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR) {
- _startCount = _count;
- }
- }
- }
- PRINTF_FUNC("_startCount = %d \n", _startCount);
- if (_startCount < _maxCount) {
- //DS60-120 add
- PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
- chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
- if (chargingInfo[_index]->EvBatterytargetVoltage > 0 && chargingInfo[_index]->PresentChargingVoltage > 0) {
- chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
- } else {
- chargingInfo[_index]->ChargingProfileCurrent = 0;
- }
- //DS60-120 remove
- //PRINTF_FUNC("*********Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
- //chargingInfo[_index]->ChargingProfileCurrent = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * 10;
- //chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * chargingInfo[_index]->EvBatterytargetVoltage / 100;
- //chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
- // if ((chargingInfo[_index]->EvBatterytargetVoltage * 10) > 0)
- // {
- // chargingInfo[_index]->ChargingProfileCurrent = chargingInfo[_index]->ChargingProfilePower / (chargingInfo[_index]->EvBatterytargetVoltage * 10);
- // }
- } else {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- } else {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- PRINTF_FUNC("ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
- PRINTF_FUNC("ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
- }
- //
- // printf("-------------Schedule------------\n");
- // printf("index = %d \n", _index);
- // printf("StartSchedule = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
- // printf("ChargingRateUnit = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
- // printf("----------SchedulePeriod---------\n");
- // for (int v = 0; v < 10; v++)
- // {
- // printf("StartPeriod = %d \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
- // printf("Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
- // }
- // printf("---------------------------------\n");
- }
- void ChargingProfileFlat(byte _index)
- {
- if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO) {
- if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO) {
- ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
- }
- }
- }
- void CheckReturnToChargingConn()
- {
- if ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ShmSysConfigAndInfo->SysConfig.AcConnectorCount) > 1 &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZING &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_FAIL &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_COMP &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_WAIT_FOR_PLUG) {
- bool isReturnTimeout = false;
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
- // 如果選的 DC 槍在充電~ 則 DC 槍不改變
- if (count == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
- if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
- (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- isReturnTimeout = false;
- break;
- }
- } else if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
- if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
- (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- }
- // AC 槍
- if (!isReturnTimeout && ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0) {
- // 沒有選中 AC,且 AC 在充電中
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
- (ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE)) {
- // 當前 DC 充電槍在 idle 狀態
- if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE ||
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_RESERVATION) {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- } else if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
- ((chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_COMPLETE) ||
- (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_CCS_PRECHARGE_ST1))) {
- // 當前 DC 充電槍在 idle 狀態
- if (ac_chargingInfo[0]->SystemStatus == S_IDLE ||
- ac_chargingInfo[0]->SystemStatus == S_RESERVATION) {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- }
- if (!isReturnTimeout) {
- StopSystemTimeoutDet();
- }
- }
- }
- bool GetStartChargingByAlterMode(byte _gun)
- {
- bool result = true;
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2 &&
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
- for (byte _select = 0; _select < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _select++) {
- if (_select != _gun) {
- if (chargingInfo[_select]->SystemStatus != S_IDLE &&
- chargingInfo[_select]->SystemStatus != S_RESERVATION) {
- result = false;
- break;
- }
- }
- }
- }
- return result;
- }
- void TheEndCharging(byte gun_index)
- {
- ftime(&endChargingTime[gun_index]);
- if (chargingInfo[gun_index]->PresentChargedDuration != 0) {
- chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
- }
- chargingInfo[gun_index]->isRemoteStart = NO;
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
- ChangeStartOrStopDateTime(NO, gun_index);
- DB_Insert_Record(localDb, gun_index);
- }
- void UpdateErrorCodeToOcpp(byte index)
- {
- uint8_t i = 0;
- //if ((strcmp((char *)chargingInfo[index]->ConnectorAlarmCode, "") == EQUAL) &&
- // (strcmp((char *)chargingInfo[index]->EvConnAlarmCode, "") == EQUAL)
- // ) {
- // for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
- // if (strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012251", 6) == EQUAL ||
- // strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012252", 6) == EQUAL ||
- // strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012238", 6) == EQUAL ||
- // strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042251", 6) == EQUAL ||
- // strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042252", 6) == EQUAL ||
- // strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == EQUAL ||
- // strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042200", 6) == EQUAL ||
- // strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042201", 6) == EQUAL ||
- // strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042202", 6) == EQUAL ||
- // strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042267", 6) == EQUAL) {
- // strncpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 6);
- // //log_info("1 %d = VendorErrorCode = %s\r\n", index, (char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
- // break;
- // }
- // }
- //}
- //log_info("%d = ConnectorAlarmCode = %s\r\n", index, (char *)chargingInfo[index]->ConnectorAlarmCode);
- //log_info("%d = EvConnAlarmCode = %s\r\n", index, (char *)chargingInfo[index]->EvConnAlarmCode);
- if (strcmp((char *)chargingInfo[index]->ConnectorAlarmCode, "") != EQUAL) {
- strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "InternalError");
- strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)chargingInfo[index]->ConnectorAlarmCode);
- } else if (strcmp((char *)chargingInfo[index]->EvConnAlarmCode, "") != EQUAL) {
- strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "OtherError");
- strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)chargingInfo[index]->EvConnAlarmCode);
- }
- //log_info("2 %d = VendorErrorCode = %s\r\n", index, (char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
- }
- void AdjustChargerCurrent()
- {
- ShmSysConfigAndInfo->SysConfig.RatingCurrent = ShmPsuData->SystemAvailableCurrent / 10;
- // 設定的電流~ 如超過可輸出的電流,則 bypass
- if (ShmSysConfigAndInfo->SysConfig.RatingCurrent < ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent ||
- ShmSysConfigAndInfo->SysConfig.RatingCurrent == 0) {
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = 0;
- }
- PRINTF_FUNC ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
- ShmPsuData->SystemAvailablePower / 10,
- ShmPsuData->SystemAvailableCurrent / 10
- );
- PRINTF_FUNC ("Config : ChargingPower = %d, ChargingCurrent = %d",
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent
- );
- }
- #if METER_ENABLE
- void CheckStatusOfMeter()
- {
- // 橋接如果搭上~ 則兩個電表都是使用狀態
- // 如橋接沒有搭上~ 則視該火線 relay 狀態為電表使用狀態
- if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES) {
- for (byte mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++) {
- ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
- }
- } else {
- for (byte mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++) {
- if (chargingInfo[mIndex]->RelayKPK2Status == YES || chargingInfo[mIndex]->RelayK1K2Status) {
- ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
- } else {
- ShmCsuMeterData->_meter[mIndex].isCalculation = NO;
- }
- }
- }
- }
- void CheckRelayWeldingOrDrivingFault(byte gun_index)
- {
- // relay welding fault then stop the charging process.
- byte faultCode = RELAY_STATUS_ERROR_NONE;
- if (gun_index == 0) {
- if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
- faultCode = RELAY_STATUS_ERROR_WELDING;
- } else if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
- faultCode = RELAY_STATUS_ERROR_DRIVING;
- }
- } else if (gun_index == 1) {
- if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
- faultCode = RELAY_STATUS_ERROR_WELDING;
- } else if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
- faultCode = RELAY_STATUS_ERROR_DRIVING;
- }
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2 &&
- !ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
- // 橋接
- if (ShmDcCommonData->RelayCheckStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
- faultCode = RELAY_STATUS_ERROR_WELDING;
- } else if (ShmDcCommonData->RelayCheckStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
- faultCode = RELAY_STATUS_ERROR_DRIVING;
- }
- }
- if (faultCode == RELAY_STATUS_ERROR_WELDING) {
- // welding
- if (chargingInfo[gun_index]->Type == _Type_Chademo) {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
- } else if (chargingInfo[gun_index]->Type == _Type_GB) {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
- } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
- }
- ShmDcCommonData->GunRelayWeldingOccur[gun_index] = YES;
- EmcOccureByString("");
- } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
- // driving
- if (chargingInfo[gun_index]->Type == _Type_Chademo) {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
- } else if (chargingInfo[gun_index]->Type == _Type_GB) {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
- } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
- }
- ShmDcCommonData->GunRelayDrivingOccur[gun_index] = YES;
- EmcOccureByString("");
- } else {
- ShmDcCommonData->GunRelayWeldingOccur[gun_index] = NO;
- ShmDcCommonData->GunRelayDrivingOccur[gun_index] = NO;
- bool isClear = false;
- if (!relayDrivingCheck) {
- if (chargingInfo[gun_index]->Type == _Type_Chademo &&
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
- isClear = true;
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
- } else if (chargingInfo[gun_index]->Type == _Type_GB &&
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES) {
- isClear = true;
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = NO;
- } else if (chargingInfo[gun_index]->Type == _Type_CCS_2 &&
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
- isClear = true;
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
- }
- }
- if (!relayWeldingCheck) {
- if (chargingInfo[gun_index]->Type == _Type_Chademo &&
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding == YES) {
- isClear = true;
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = NO;
- } else if (chargingInfo[gun_index]->Type == _Type_GB &&
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding == YES) {
- isClear = true;
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = NO;
- } else if (chargingInfo[gun_index]->Type == _Type_CCS_2 &&
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding == YES) {
- isClear = true;
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = NO;
- }
- }
- if (!relayDrivingCheck && !relayWeldingCheck && isClear) {
- ReleaseChargingProcessByString(2);
- }
- }
- }
- bool PrecheckIsPass(byte gun_index)
- {
- bool result = true;
- // relay welding or driving 是反向
- if (result) {
- result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
- }
- return result;
- }
- #endif //METER_ENABLE
- void ResetDetAlarmStatus(byte gun)
- {
- if (chargingInfo[gun]->Type == _Type_Chademo) {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
- }
- } else if (chargingInfo[gun]->Type == _Type_GB) {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
- }
- } else if (chargingInfo[gun]->Type == _Type_CCS_2) {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
- }
- }
- }
- static void powerCabinetPsuAlarmStatus(void)
- {
- uint8_t i = 0;
- for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
- if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042267", 6) == 0) {
- EmcOccureByString("042267");
- }
- }
- }
- static void autoStartChargingForComBox(uint8_t gunIndex)
- {
- #if defined DD360ComBox
- if ((chargingInfo[gunIndex]->ConnectorPlugIn == YES) &&
- (chargingInfo[gunIndex]->SystemStatus == S_IDLE)
- ) {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = gunIndex;
- strcpy((char *)&ShmSysConfigAndInfo->SysConfig.UserId, "AutoStartCharging");
- }
- #else
- return;
- #endif //DD360ComBox
- }
- int main(void)
- {
- uint8_t evBoardStopState = 0;
- if (CreateShareMemory() == 0) {
- log_error("CreatShareMemory NG\r\n");
- if (ShmStatusCodeData != NULL) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- log_info(" **************** FileSystem Boot up ***************\n");
- if (!InitialSystemDefaultConfig()) {
- log_error("InitialSystemDefaultConfig NG \n");
- //StopProcessingLoop();
- sleep(5);
- system("reboot -f");
- }
- CheckGunTypeFromHw();
- CheckIsAlternatvieByModelName();
- InitialShareMemoryInfo();
- ChangeLcmByIndex(_LCM_INIT);
- if (!CheckConnectorTypeStatus()) {
- isModelNameMatch = false;
- }
- Initialization();
- SpawnTask();
- log_info("Spawned all Task");
- if (!isModelNameMatch) {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
- ChangeLcmByIndex(_LCM_FIX);
- // Module Name 與硬體對應不正確
- log_error("Module Name & HW info none match. \n");
- sleep(3);
- KillAllTask();
- StopProcessingLoop();
- }
- CreateTimeoutFork();
- log_info("Start self test... \n");
- startPrimaryLedIndicatorCtrlFork();
- SelfTestRun();
- StopSystemTimeoutDet();
- log_info("Self test finished : SelfTestSeq = %d, Work_Step = %d ",
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq,
- ShmPsuData->Work_Step);
- if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
- ShmPsuData->Work_Step == _NO_WORKING ||
- ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES //DS60-120 add
- ) {
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
- if (!DisplaySelfTestFailReason()) { //DS60-120 add
- PRINTF_FUNC("Soft reboot for retry self-tets. \n");
- sleep(3);
- system("killall OcppBackend &");
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
- setChargerMode(gun_index, MODE_ALARM);
- }
- //ChangeLcmByIndex(_LCM_FIX);
- sleep(3);
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) { //DS60-120 add
- KillTaskExceptPrimary();
- } else {
- KillTask();
- }
- StopProcessingLoop();
- } else {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- // Local DB
- if (DB_Open(localDb) != PASS) {
- PRINTF_FUNC("DB_Open fail. \n");
- isDb_ready = false;
- } else {
- isDb_ready = true;
- for (int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
- chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
- }
- DB_Reboot_Record(localDb);
- }
- PRINTF_FUNC("===== Create DB End ===== \n");
- #if defined DD360Audi
- ChangeLcmByIndex(_LCM_SELECT_GUN);
- #else
- ChangeLcmByIndex(_LCM_IDLE);
- #endif //defined DD360Audi
- sleep(1);
- //***** 須新增的偵測 *****//
- // 1. Thernal - 控制風扇轉速
- // 2. ouput fuse - 控制風扇轉速
- CreateRfidFork();
- // Create Watchdog
- //CreateWatchdog();
- // Main loop
- PRINTF_FUNC("===== Charger info ===== ");
- PRINTF_FUNC("SW Version = %s", fwVersion);
- PRINTF_FUNC("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
- CheckFwSlotStatusLog();
- AdjustChargerCurrent();
- gettimeofday(&_cmdMainPriority_time, NULL);
- for (;;) {
- CheckOcppStatus();
- ChkPrimaryStatus();
- if ((IsConnectorWholeIdle() || ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) &&
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_ReturnToChargingGunDet) {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- }
- // OCPP 邏輯
- OcppRemoteStartChk();
- // 讀卡邏輯
- ScannerCardProcess();
- // 當 AC 沒有搭上時,清除一些錯誤碼
- ClearAlarmCodeWhenAcOff();
- // 確認是否要回到充電中的槍畫面邏輯判斷
- CheckReturnToChargingConn();
- #if defined DD360 ||defined DD360Audi || defined DD360ComBox
- //確認Power cabinet PSU Status
- powerCabinetPsuAlarmStatus();
- #endif // defined DD360 || defined DD360Audi
- if (_acgunIndex > 0 && isDetectPlugin() && !isCardScan) {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
- CheckTask();
- #if defined METER_ENABLE
- relayWeldingCheck = false;
- relayDrivingCheck = false;
- #endif //defined METER_ENABLE
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
- //if (chargingInfo[_index]->SystemStatus == S_CHARGING) {
- // CheckSmartChargeProfile(_index);
- //}
- if ((chargingInfo[_index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
- chargingInfo[_index]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- chargingInfo[_index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- if (chargingInfo[_index]->SystemStatus == S_CHARGING &&
- _ocppProfileChkFlag == 12) {
- ChargingProfileFlat(_index);
- _ocppProfileChkFlag = 0;
- } else if (chargingInfo[_index]->SystemStatus != S_CHARGING) {
- ChargingProfileFlat(_index);
- _ocppProfileChkFlag = 0;
- } else {
- _ocppProfileChkFlag++;
- }
- }
- #if defined METER_ENABLE
- if (ShmDcCommonData->SysGunAreSameType == YES) {
- if (ShmDcCommonData->GunRelayWeldingOccur[_index] == YES) {
- relayWeldingCheck = true;
- }
- if (ShmDcCommonData->GunRelayDrivingOccur[_index] == YES) {
- relayDrivingCheck = true;
- }
- }
- #endif //defined METER_ENABLE
- }
- gettimeofday(&_cmdMainPriority_time, NULL);
- }
- #if defined METER_ENABLE
- if (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'L') {
- CheckStatusOfMeter();
- }
- #endif //defined METER_ENABLE
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
- autoStartChargingForComBox(gun_index); //for DD360ComBox
- CheckGpioInStatus();
- CheckErrorOccurStatus(gun_index);
- ChkOcppStatus(gun_index);
- #if defined METER_ENABLE
- CheckRelayWeldingOrDrivingFault(gun_index);
- #endif //defined METER_ENABLE
- if ((chargingInfo[gun_index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
- chargingInfo[gun_index]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[gun_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- chargingInfo[gun_index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- CheckSmartChargeProfile(gun_index);
- }
- //PRINTF_FUNC("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
- switch (chargingInfo[gun_index]->SystemStatus) {
- case S_IDLE:
- ReleaseAlarmCode(gun_index);
- if (isModeChange(gun_index)) {
- log_info("S_IDLE================================== %x \n", gun_index);
- chargingInfo[gun_index]->PresentChargedDuration = 0;
- chargingInfo[gun_index]->RemainChargingDuration = 0;
- chargingInfo[gun_index]->PresentChargingVoltage = 0;//DS60-120 add
- chargingInfo[gun_index]->PresentChargingCurrent = 0;//DS60-120 add
- strcpy((char *)chargingInfo[gun_index]->StartDateTime, "");
- strcpy((char *)chargingInfo[gun_index]->StopDateTime, "");
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
- //Jerry add
- memset(&gAudiCustInfo->PricesInfo[gun_index], 0, sizeof(PricesInfo));
- gAudiCustInfo->PricesInfo[gun_index].Balance = FAIL_BALANCE_PRICES;
- #if defined DD360Audi
- destroySelGun(gun_index);
- #endif //defined DD360Audi
- ResetDetAlarmStatus(gun_index); //recovery OVP status code
- //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "");
- }
- case S_RESERVATION:
- if (isModeChange(gun_index)) {
- log_info("S_RESERVATION....................%x \n", gun_index);
- ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
- }
- if (chargingInfo[gun_index]->IsAvailable == NO) {
- setChargerMode(gun_index, MODE_MAINTAIN);
- }
- case S_MAINTAIN:
- case S_FAULT: {
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
- if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
- } else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_IDLE &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_RESERVATION &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_MAINTAIN &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_FAULT) {
- if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING) {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_COMPLETE;
- } else {
- #if defined DD360Audi
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
- #else
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- #endif //defined DD360Audi
- }
- }
- ClearDetectPluginFlag();
- //#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- UpdateErrorCodeToOcpp(gun_index);
- //#endif //!defined DD360 && !defined DD360Audi
- setChargerMode(gun_index, MODE_FAULT);
- } else {
- #if 1
- if (chargingInfo[gun_index]->SystemStatus == S_FAULT) {
- #if defined DD360Audi
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
- #else
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- #endif //defined DD360Audi
- setChargerMode(gun_index, MODE_IDLE);
- }
- //if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_FIX) {
- // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;//_LCM_NONE; //Jerry add
- // //for (byte g_index = 0; g_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; g_index++) {
- // setChargerMode(gun_index, MODE_IDLE);
- // //}
- //}
- #endif //0
- if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
- #else
- if (1)
- #endif //!defined DD360 && !defined DD360Audi
- {
- // 均充 -> 最大充
- if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO) {
- if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE) {
- log_info("=============Smart Charging============= Step 11 \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
- }
- } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING) {
- log_info("=============Smart Charging============= Step 14 \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
- } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP) {
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- } else {
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- } else {
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- #if defined METER_ENABLE
- if (PrecheckIsPass(gun_index)) {
- if (chargingInfo[gun_index]->SystemStatus == S_FAULT) {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- setChargerMode(gun_index, MODE_IDLE);
- }
- #endif //defined METER_ENABLE
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- #if defined DD360Audi
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
- #else
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
- #endif //
- }
- } else {
- // Idle 正常程序起點
- // 判斷是否有啟用檢查插槍
- if (isDetectPlugin()) {
- // 卡號驗證成功後,等待充電槍插入充電車
- if (chargingInfo[gun_index]->RemoteStartFlag == YES) {
- if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
- chargingInfo[gun_index]->IsAvailable) {
- PRINTF_FUNC("-----------------1----------------- %d \n", gun_index);
- chargingInfo[gun_index]->RemoteStartFlag = NO;
- chargingInfo[gun_index]->isRemoteStart = YES; //DS60-120
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
- ClearDetectPluginFlag();
- continue;
- }
- } else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE) {
- if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
- chargingInfo[gun_index]->IsAvailable &&
- chargingInfo[gun_index]->SystemStatus == S_IDLE
- #if defined DD360Audi
- && (waitRightGunPlugIt(gun_index) == PASS ||
- waitLeftGunPlugIt(gun_index) == PASS)
- #endif //defined DD360Audi
- ) {
- PRINTF_FUNC("-----------------2----------------- \n");
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
- PRINTF_FUNC("index = %d, CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- // 當前操作的槍號,進入 Preparing
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- ClearDetectPluginFlag();
- continue;
- }
- }
- if (!isCardScan) {
- // LCM => Waiting for plugging
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- } else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION) {
- if (!isReservationExpired(gun_index)) {
- chargingInfo[gun_index]->SystemStatus = S_IDLE;
- }
- } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
- (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable)) {
- PRINTF_FUNC("-----------------3----------------- \n");
- bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
- if (isCanStartChargingFlag) {
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- ClearDetectPluginFlag();
- continue;
- }
- } else {
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- #if defined DD360Audi
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
- #else
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
- #endif // defined DD360Audi
- }
- }
- } // Idle 正常程序終點
- #if defined METER_ENABLE
- } else {
- setChargerMode(gun_index, MODE_FAULT);
- if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
- }
- }
- #endif //defined METER_ENABLE
- }
- }
- break;
- case S_REASSIGN_CHECK: {
- if (isModeChange(gun_index)) {
- log_info("S_REASSIGN_CHECK================================== %x \n", gun_index);
- #if defined DD360Audi
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
- #else
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- #endif //defined DD360Audi
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE) {
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- }
- StopSystemTimeoutDet();
- }
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- bool isRessign = false;
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO) {
- if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
- // 有其他槍已經分配好 psu 模塊
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index &&
- chargingInfo[index]->SystemStatus >= S_PREPARNING &&
- chargingInfo[index]->SystemStatus != S_MAINTAIN) {
- log_info("=============Smart Charging============= Step 1 \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
- isRessign = true;
- break;
- }
- }
- } else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE) {
- // 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
- if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES) {
- if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING) {
- log_info("=============Smart Charging============= Step 14 \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
- } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP) {
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- continue;
- }
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- continue;
- }
- }
- #endif // !defined DD360 && !defined DD360Audi
- if (0) { // if (isRessign)
- #if defined DD360 ||defined DD360Audi || defined DD360ComBox
- setChargerMode(gun_index, MODE_PRECHARGE);
- #else
- setChargerMode(gun_index, MODE_REASSIGN);
- #endif //defined DD360 || defined DD360Audi
- } else {
- setChargerMode(gun_index, MODE_PRECHARGE);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- }
- break;
- case S_REASSIGN: {
- if (isModeChange(gun_index)) {
- PRINTF_FUNC("S_REASSIGN================================== %x \n", gun_index);
- gettimeofday(&_toAverage_time, NULL);
- }
- // 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
- // 此狀態下~ 控制權在於 PSU 及 EV小板 Process
- if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE ||
- ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
- if (ShmSysConfigAndInfo->SysInfo.CanAverageCharging) {
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;//DS60-120 add
- setChargerMode(gun_index, MODE_PRECHARGE);
- } else {
- setChargerMode(gun_index, MODE_IDLE);
- }
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 add
- } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
- ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO) {
- PRINTF_FUNC("=============Smart Charging : _REASSIGNED_COMP============= Step 6 \n");
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
- //ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 remove
- ShmSysConfigAndInfo->SysInfo.CanAverageCharging = true; //DS60-120 add
- }
- //PRINTF_FUNC("CurGunSelected = %d, gun_index = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected, gun_index);
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_PREPARNING: {
- if (isModeChange(gun_index)) {
- PRINTF_FUNC("S_PREPARNING================================== %x \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
- }
- if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
- ShmPsuData->SystemAvailablePower > 10 &&
- GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 5000000) {
- //if ((chargingInfo[gun_index]->MaximumChargingVoltage > 0) && //DS60-120 remove
- // (chargingInfo[gun_index]->AvailableChargingCurrent > 0) &&
- // (chargingInfo[gun_index]->AvailableChargingPower > 0)) {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
- //}
- }
- //DS60-120 add
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2) {
- bool oughtAver = true;
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
- // 共同進入充電邏輯
- if (chargingInfo[index]->SystemStatus != S_PREPARNING) {
- oughtAver = false;
- break;
- }
- }
- if (oughtAver) {
- PRINTF_FUNC("********* Automatically change to aver mode ********** \n");
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- }
- if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
- // 板端要求停止 (錯誤)
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
- }
- if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
- ChargingAlarmProcess(gun_index);
- } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
- ChargingTerminalProcess(gun_index);
- }
- } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
- // 板端要求停止 (正常)
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
- }
- ChargingTerminalProcess(gun_index);
- } else if (OcppRemoteStop(gun_index) == YES ||
- WifiScheduleStop(gun_index)) {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_PREPARING_FOR_EV: { // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
- if (isModeChange(gun_index)) {
- log_info("S_PREPARING_FOR_EV================================== %x \n", gun_index);
- //strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
- }
- if (chargingInfo[gun_index]->Type == _Type_Chademo) {
- // 檢查車端的槍鎖是否為鎖上
- if (isEvGunLocked_chademo(gun_index) == YES) {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- } else if (chargingInfo[gun_index]->Type == _Type_GB) {
- // 檢查車端的 charging enable 是否為 1
- if (isEvGunLocked_gb(gun_index) == YES) {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
- // 檢查車端的 charging enable 是否為 1
- if (isEvGunLocked_ccs(gun_index) == YES) {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- }
- if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
- // 板端要求停止 (錯誤)
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
- }
- if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
- ChargingAlarmProcess(gun_index);
- } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
- ChargingTerminalProcess(gun_index);
- }
- } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
- // 板端要求停止 (正常)
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
- }
- ChargingTerminalProcess(gun_index);
- } else if (OcppRemoteStop(gun_index) == YES ||
- WifiScheduleStop(gun_index)) {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // LCM => Pre-charging
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_PREPARING_FOR_EVSE: { // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
- if (isModeChange(gun_index)) {
- log_info("S_PREPARING_FOR_EVSE================================== %x \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
- }
- if (chargingInfo[gun_index]->Type == _Type_Chademo) {
- // 檢查樁端的 GFD 結果
- if (isPrechargeStatus_chademo(gun_index) > 5 && isPrechargeStatus_chademo(gun_index) < 8) {
- // 當前操作的槍號,進入 Charging
- setChargerMode(gun_index, MODE_CHARGING);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012234");
- } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- RecordWarningCode(gun_index, "012296");
- }
- } else if (chargingInfo[gun_index]->Type == _Type_GB) {
- // 檢查樁端的 GFD 結果
- if (isPrechargeStatus_gb(gun_index) > 5 && isPrechargeStatus_gb(gun_index) < 9) {
- setChargerMode(gun_index, MODE_CHARGING);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012236");
- } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- RecordWarningCode(gun_index, "012298");
- }
- } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
- // 檢查樁端的 GFD 結果
- if ((chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS ||
- chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)) {
- setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- RecordWarningCode(gun_index, "012297");
- }
- }
- if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
- // 板端要求停止 (錯誤)
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
- }
- if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
- ChargingAlarmProcess(gun_index);
- } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
- ChargingTerminalProcess(gun_index);
- }
- } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
- // 板端要求停止 (正常)
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
- }
- ChargingTerminalProcess(gun_index);
- } else if (OcppRemoteStop(gun_index) == YES ||
- WifiScheduleStop(gun_index)) {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // LCM => Pre-charging
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_CHARGING: { // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
- if (isModeChange(gun_index)) {
- log_info("S_CHARGING================================== %x \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- ftime(&startChargingTime[gun_index]);
- strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, ""); //DS60-120 add
- ChangeStartOrStopDateTime(YES, gun_index);
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- OcppStartTransation(gun_index);
- #endif //!defined DD360 && !defined DD360Audi
- }
- if (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf) {
- ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
- }
- ftime(&endChargingTime[gun_index]);
- chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
- if (chargingInfo[gun_index]->Type == _Type_Chademo) {
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012234");
- }
- //else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
- // (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)) {
- // // UVP
- // RecordAlarmCode(gun_index, "012289");
- // ChargingTerminalProcess(gun_index);
- //}
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- RecordWarningCode(gun_index, "012296");
- }
- } else if (chargingInfo[gun_index]->Type == _Type_GB) {
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012236");
- }
- //else if (isPrechargeStatus_gb(gun_index) == 10 &&
- // (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
- // (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))) {
- // // UVP
- // RecordAlarmCode(gun_index, "012290");
- // ChargingTerminalProcess(gun_index);
- //}
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- RecordWarningCode(gun_index, "012298");
- }
- } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- //else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
- // (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)) {
- // // UVP
- // RecordAlarmCode(gun_index, "012288");
- // ChargingTerminalProcess(gun_index);
- //}
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- RecordWarningCode(gun_index, "012297");
- }
- }
- if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
- // 板端要求停止 (錯誤)
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
- }
- //printf("%d evBoardStopState = %d\r\n", gun_index, evBoardStopState);
- if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
- ChargingAlarmProcess(gun_index);
- } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
- ChargingTerminalProcess(gun_index);
- }
- } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
- // 板端要求停止 (正常)
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
- }
- ChargingTerminalProcess(gun_index);
- } else if (OcppRemoteStop(gun_index) == YES ||
- WifiScheduleStop(gun_index) ||
- CheckBackendChargingTimeout(gun_index) ||
- CheckBackendChargingEnergy(gun_index) ||
- strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // LCM => Charging
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
- // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_ALARM:
- case S_TERMINATING: {
- if (isModeChange(gun_index)) {
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
- }
- if (chargingInfo[gun_index]->SystemStatus == S_ALARM) {
- PRINTF_FUNC("================== S_ALARM (%x) ================ \n", gun_index);
- UpdateErrorCodeToOcpp(gun_index);
- if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
- OcppStopTransation(gun_index);
- }
- TheEndCharging(gun_index);
- } else {
- PRINTF_FUNC("================== S_TERMINATING (%x) ================ \n", gun_index);
- }
- //log_info ("terminating......................... %x \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- if (chargingInfo[gun_index]->Type == _Type_Chademo) {
- // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
- //if (isEvStopCharging_chademo(gun_index) == YES) {
- // /*+++ 20200908, vern, disable it for DD360 +++*/
- // /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
- // strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
- // /*--- 20200908, vern, disable it for DD360 ---*/
- //}
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012234");
- } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- RecordWarningCode(gun_index, "012296");
- }
- //if (isEvStopCharging_chademo(gun_index) == YES ||
- // isPrechargeStatus_chademo(gun_index) <= 0) {
- // setChargerMode(gun_index, MODE_COMPLETE);
- //}
- } else if (chargingInfo[gun_index]->Type == _Type_GB) {
- log_info("************ GB lock Status = %d, status = %d \n", isEvStopCharging_gb(gun_index), isPrechargeStatus_gb(gun_index));
- // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
- //if (isEvStopCharging_chademo(gun_index) == YES) {
- // /*+++ 20200908, vern, disable it for DD360 +++*/
- // /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
- // strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
- // /*--- 20200908, vern, disable it for DD360 ---*/
- //}
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012236");
- } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- RecordWarningCode(gun_index, "012298");
- }
- //if (isEvStopCharging_gb(gun_index) == YES ||
- // isPrechargeStatus_gb(gun_index) <= 0) {
- // setChargerMode(gun_index, MODE_COMPLETE);
- //}
- } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
- // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
- //if (isEvStopCharging_chademo(gun_index) == YES) {
- // /*+++ 20200908, vern, disable it for DD360 +++*/
- // /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
- // strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
- // /*--- 20200908, vern, disable it for DD360 ---*/
- //}
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- RecordWarningCode(gun_index, "012297");
- }
- //if (isEvStopCharging_ccs(gun_index) == YES &&
- // (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
- // isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14)) {
- // setChargerMode(gun_index, MODE_COMPLETE);
- //}
- }
- if (chargingInfo[gun_index]->SystemStatus == S_ALARM) {
- if (chargingInfo[gun_index]->ConnectorPlugIn == NO &&
- GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000) {
- setChargerMode(gun_index, MODE_IDLE);
- }
- } else {
- if (chargingInfo[gun_index]->Type == _Type_Chademo) {
- if (isEvStopCharging_chademo(gun_index) == YES ||
- isPrechargeStatus_chademo(gun_index) <= 0) {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- } else if (chargingInfo[gun_index]->Type == _Type_GB) {
- if (isEvStopCharging_gb(gun_index) == YES ||
- isPrechargeStatus_gb(gun_index) <= 0) {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
- if (isEvStopCharging_ccs(gun_index) == YES &&
- (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
- isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14)) {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- }
- }
- // 車端的停止
- //if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
- // strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
- //}
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
- // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_COMPLETE: {
- if (isModeChange(gun_index)) {
- PRINTF_FUNC ("complete......................... %x \n", gun_index);
- if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
- OcppStopTransation(gun_index);
- }
- TheEndCharging(gun_index);
- //ftime(&endChargingTime[gun_index]);
- //if (chargingInfo[gun_index]->PresentChargedDuration != 0) {
- // chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
- //}
- //StopGunInfoTimeoutDet(gun_index);
- //StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
- //ChangeStartOrStopDateTime(NO, gun_index);
- }
- //if (((chargingInfo[gun_index]->ConnectorPlugIn == NO) ||
- // (restartFlag == 1)) &&
- // (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)) {
- // setChargerMode(gun_index, MODE_IDLE);
- // destroySelGun(gun_index); //Jerry add
- //}
- if (chargingInfo[gun_index]->ConnectorPlugIn == NO &&
- GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000) {
- setChargerMode(gun_index, MODE_IDLE);
- #if defined DD360Audi
- destroySelGun(gun_index); //Jerry add
- #endif //defined DD360Audi
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
- // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_CCS_PRECHARGE_ST0: {
- if (isModeChange(gun_index)) {
- PRINTF_FUNC("CCS Precharge Processing 1....................%x \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
- // 板端要求停止 (錯誤)
- if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
- ChargingAlarmProcess(gun_index);
- } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
- ChargingTerminalProcess(gun_index);
- }
- } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
- // 板端要求停止 (正常)
- ChargingTerminalProcess(gun_index);
- } else if (OcppRemoteStop(gun_index) == YES ||
- WifiScheduleStop(gun_index)) {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // 等待 EV 小板 (CCS) 通知可以開始 Precharge
- // 切換 D+ Relay to Precharge Relay
- if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40) {
- if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
- //if (chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
- {
- //PRINTF_FUNC("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
- if (isPrechargeStatus_ccs(gun_index) == 39) {
- PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
- } else if (isPrechargeStatus_ccs(gun_index) == 40) {
- PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PowerDeliveryRequest start (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
- }
- chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
- }
- } else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46) {
- setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP1);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- break;
- }
- case S_CCS_PRECHARGE_ST1: {
- if (isModeChange(gun_index)) {
- log_info("CCS Precharge Processing 2....................%x \n", gun_index);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
- // 板端要求停止 (錯誤)
- if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
- ChargingAlarmProcess(gun_index);
- } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
- ChargingTerminalProcess(gun_index);
- }
- } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
- // 板端要求停止 (正常)
- ChargingTerminalProcess(gun_index);
- } else if (OcppRemoteStop(gun_index) == YES ||
- WifiScheduleStop(gun_index)) {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // 等待小板通知進入充電
- // 切換 D+ Relay to Precharge Relay
- if (chargingInfo[gun_index]->RelayK1K2Status == YES) {
- chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
- setChargerMode(gun_index, MODE_CHARGING);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- break;
- }
- }
- }
- #if defined DD360Audi
- if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_SELECT_GUN) {
- #else
- if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE) {
- #endif //defined DD360Audi
- ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
- } else {
- bool dcPageRun = false;
- if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
- if (ac_chargingInfo[0]->SystemStatus == S_IDLE) {
- ChangeLcmByIndex(_LCM_IDLE);
- } else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING) {
- ChangeLcmByIndex(_LCM_PRE_CHARGE);
- } else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
- ChangeLcmByIndex(_LCM_CHARGING);
- } else if (ac_chargingInfo[0]->SystemStatus == S_TERMINATING ||
- ac_chargingInfo[0]->SystemStatus == S_COMPLETE) {
- ChangeLcmByIndex(_LCM_COMPLETE);
- } else {
- dcPageRun = true;
- }
- } else {
- dcPageRun = true;
- }
- if (dcPageRun) {
- ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
- }
- }
- write(wtdFd, "a", 1);
- usleep(whileLoopTime);
- }
- return FAIL;
- }
|