1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795 |
- #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 <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <string.h>
- #include <stdint.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #include <stdbool.h>
- #include <dirent.h>
- #include "../../define.h"
- #include "CheckSystemTask.h"
- #include "Config.h"
- #include "timeout.h"
- #define DEBUG_ALSTON 0
- #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 0x300000
- #define SYSFS_GPIO_DIR "/sys/class/gpio"
- #define UPGRADE_FAN 0x02
- #define UPGRADE_RB 0x03
- #define UPGRADE_PRI 0x04
- #define UPGRADE_AC 0x05
- #define UPGRADE_LED 0x06
- #define SYSTEM_MIN_VOL 80
- #define MIN_OUTPUT_CUR 0
- #define AC_OUTPUT_VOL 220
- #define NO_RESERVE -1
- #define NO_DEFINE 255
- #define DEFAULT_AC_INDEX 2
- #define PSU_MIN_CUR 100
- #define DB_FILE "/Storage/ChargeLog/localCgargingRecord.db"
- #define NETWORK_DB_FILE "/Storage/EventLog/Eventlog.db"
- #define GUN_OTP_VALUE 150
- #define GUN_OTP_RECOVERY 140
- #define UNDEFINED_TEMP 255
- #define uSEC_VAL 1000000
- #define SELFTEST_TIMEOUT 60
- #define AUTHORIZE_TIMEOUT 15
- #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 3
- #define GUN_PRECHARGING_TIMEOUT 60
- #define TPC_PLUG_DETECT_TIMEOUT 60
- #define TIMEOUT_SPEC_HANDSHAKING 180000
- #define CERT_PNC_DIR_FILE "/Storage/OCPP/certPnCAuth.pem"
- #define CERT_PNC_CCS_DIR_FILE "/mnt/P-256_Tier1_Valid_EVSE_Cert-privkey.pem"
- 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;
- int wtdFd = -1;
- byte _authorizeIndex = NO_DEFINE;
- bool IsAuthorizingMode();
- void ClearAuthorizedFlag();
- bool isDetectPlugin();
- void ClearDetectPluginFlag();
- int mystrcmp(unsigned char *p1, unsigned char *p2);
- void CheckTask();
- 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, ...);
- int GetTimeoutValue(struct timespec *startTime);
- void gpio_set_value(unsigned int gpio, unsigned int value);
- void PRINTF_FUNC(char *string, ...);
- void ChangeGunSelectByIndex(byte sel);
- void ChargingAlarmProcess(byte gunIndex);
- void CheckSystemErrorFunction(byte index);
- int opcc_chk_reserve_expired(byte gunIndex);
- void ocpp_process_start();
- void ocpp_auto_response_BootNotification();
- void ocpp_auto_response_StartTransationConf(byte gunIndex);
- void ocpp_auto_response_StopTransationConf(byte gunIndex);
- bool ocpp_chk_authrization_cmd();
- void ocpp_chk_reset_cmd(byte isforce);
- void ocpp_chk_reserved_cmd(byte gunIndex);
- void ocpp_chk_availability_cmd(byte gunIndex);
- void ocpp_chk_unlock_cmd(byte gunIndex);
- bool ocpp_chk_remoteStop_cmd(byte gunIndex);
- void ocpp_chk_remoteStart_cmd();
- void ocpp_chk_update_cmd();
- bool ocpp_chk_invalid_id_cmd(byte gunIndex);
- void ocpp_set_startTransation_cmd(byte gunIndex);
- void ocpp_set_stopTransation_cmd(byte gunIndex);
- void ocpp_set_noErrorCode_cmd(byte gunIndex, char *errString);
- void ocpp_set_stopReason_by_cmd(byte gunIndex, char *reason);
- void ocpp_set_authorizeReq_cmd(byte value);
- void ocpp_set_authorizeConf_cmd(byte value);
- void ocpp_set_errCode_cmd(byte gunIndex);
- void ocpp_clear_errorCode_cmd(byte gunIndex);
- void ocpp_clear_idTag_cmd(byte gun_index);
- void ocpp_clear_stopReason(byte gun_index);
- bool ocpp_get_authorize_conf();
- unsigned short _ocpp_get_connect_timeout();
- void ocpp_chargingProfile_process(byte gun_index);
- void ocpp_set_startTransationPH_cmd(byte gunIndex);
- void ocpp_auto_response_StartTransationConfPH(byte gunIndex);
- void ocpp_set_stopTransationPH_cmd(byte gunIndex);
- void ocpp_auto_response_StopTransationConfPH(byte gunIndex);
- void ocpp_copy_stopReason2maintainServer(byte gunIndex);
- void ocpp_sub_set_remote_start_transaction_req(byte gunIndex, bool result);
- void RecordAlarmCode(byte gunIndex, char *code);
- void ReleaseSysAlarmCode(byte gunIndex);
- void ReviewCriticalAlarm();
- 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);
- void InitialDHCP();
- int GetStartScheduleTime(unsigned char *time);
- void KillAllTask();
- void CheckSystemTaskAlive();
- void CheckConnectorOTP(byte _index);
- void _DetectTpcPlugInTimeout();
- int ElapsedTime(uint8_t *start);
- bool CheckTheParentId(byte gun_index);
- #define DEBUG_INFO_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- #define DEBUG_WARN_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- #define DEBUG_ERROR_MSG(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 OCPP20Data *ShmOCPP20Data;
- struct OCPP16Data *ShmOCPP16DataPH;
- struct MeterInformation *ShmCsuMeterData;
- struct DcCommonInformation *ShmDcCommonData;
- struct SmartBoxData *ShmSmartBoxData;
- 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];
- int _presentChargingTimeBuf[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timespec _startTransation_time[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- float _ChargingProfilePwBuffer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- float _ChargingMaxProfilePwBuffer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- float _AcChargingProfileCurBuffer;
- bool _isSendStartTransaction[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- GunErr errCollect;
- struct timespec _autoRuntestTime;
- byte _isTestRun = NO;
- 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;
- bool isCardScan = false;
- bool isModelNameMatch = true;
- byte _chargingCount;
- int rfidFd = -1;
- char* rfidPortName = "/dev/ttyS2";
- char* fwVersion = "V3.02.00.0000.00";
- sqlite3 *localDb;
- bool isDb_ready;
- sqlite3 *networkDb;
- char MyDefaultPriceString[501];
- byte reset4gStep = RESET_4G_STEP_NONE;
- byte gunTempAllowCount[2] = {0, 0};
- byte _verifyMechanism = VERIFY_MECHANISM_RFID;
- bool isPaymentBusy = false;
- byte _isUsingWifi;
- byte _isUsing4G;
- 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
- DEBUG_ERROR_MSG("Set SO_RCVTIMEO NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("Set SO_RCVBUF NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("Set SO_SNDBUF NG");
- #endif
- }
- strcpy(ifr0.ifr_name, "can0" );
- ioctl(s0, SIOCGIFINDEX, &ifr0);
- addr0.can_family = AF_CAN;
- addr0.can_ifindex = ifr0.ifr_ifindex;
- bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
- return s0;
- }
- 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
- DEBUG_ERROR_MSG("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)5;
- tios.c_lflag=0;
- tcflush(fd, TCIFLUSH);
- ioctl (fd, TCSETS, &tios);
- return fd;
- }
- 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;
- int timeout = 180;
- 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)
- {
- DEBUG_ERROR_MSG("System watch dog initial fail.\r\n");
- }
- ioctl(fd, _IOWR('W', 6, int), &timeout);
- return fd;
- }
- void CreateWatchdog()
- {
- if (!DEBUG_ALSTON && wtdFd == -1)
- {
- PRINTF_FUNC("===== Create crazy dog ===== \n");
- if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO)
- {
- wtdFd = InitWatchDog();
- if (wtdFd < 0)
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- }
- }
- void CloseWatchDog()
- {
- if (wtdFd > 0)
- {
- close(wtdFd);
- sleep(1);
- system("/usr/bin/fuser -k /dev/watchdog");
- sleep(1);
- system("echo V > /dev/watchdog");
- sleep(1);
- wtdFd = -1;
- }
- }
- 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 ||
- DEBUG_ALSTON)
- {
- 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_%s_Log",
- 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,
- ShmSysConfigAndInfo->SysConfig.SerialNumber);
- system(Buf);
- }
- return rc;
- }
- int GetTimeoutValue(struct timespec *startTime)
- {
- struct timespec endTime;
- clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
- return endTime.tv_sec - startTime->tv_sec;
- }
- void GetTimespecFunc(struct timespec *time)
- {
- clock_gettime(CLOCK_MONOTONIC_COARSE, time);
- }
- 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)
- {
-
- unsigned int StartTime,StopTime;
- StartTime=(unsigned int)ST.time;
- StopTime=(unsigned int)ET.time;
-
- return (StopTime-StartTime);
- }
- int DiffTimebWithNowSec(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);
- }
- int CheckTimeOut(uint8_t *start)
- {
- int result = YES;
- struct ParsingResult
- {
- int result;
- int scanedElement;
- int year;
- int month;
- int mday;
- int hour;
- int min;
- int sec;
- int tz_hour;
- int tz_min;
- float minSec;
- }parsingResult;
- struct tm tmStart;
- struct timeb tbStart;
- memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
- if(strstr((char*)start, ".") != NULL)
- {
-
- if(strstr((char*)start, "Z") != NULL)
- {
-
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec,
- &parsingResult.minSec);
- }
- else
- {
-
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec,
- &parsingResult.minSec,
- &parsingResult.tz_hour,
- &parsingResult.tz_min);
- }
- }
- else
- {
-
- if(strstr((char*)start, "Z") != NULL)
- {
-
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec);
- }
- else
- {
-
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec,
- &parsingResult.tz_hour,
- &parsingResult.tz_min);
- }
- }
- if(parsingResult.scanedElement >= 6)
- {
- tmStart.tm_year = parsingResult.year - 1900;
- tmStart.tm_mon = parsingResult.month - 1;
- tmStart.tm_mday = parsingResult.mday;
- tmStart.tm_hour = parsingResult.hour;
- tmStart.tm_min = parsingResult.min;
- tmStart.tm_sec = parsingResult.sec;
- tmStart.tm_gmtoff = 0;
- tbStart.time = mktime(&tmStart);
- tbStart.timezone = 0;
- tbStart.millitm = 0;
- tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
- if(DiffTimebWithNowSec(tbStart) <= 0)
- result = NO;
- else
- result = YES;
- }
- else
- {
- PRINTF_FUNC("Start date parsing error.\n");
- }
- return result;
- }
- 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);
- DEBUG_INFO_MSG("%s ", buffer);
- }
- long long DiffTimebWithNow(struct timeb ST)
- {
-
- 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);
- }
- bool CheckWebConfigChargingTimeout(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60))
- result = true;
- }
-
- if (!result && ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO)
- {
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60))
- result = true;
- }
- }
- return result;
- }
- bool CheckWebConfigChargingEnergy(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedEnergy >= ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)
- result = true;
- }
-
- if (!result && ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO)
- {
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedEnergy >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy))
- result = true;
- }
- }
- return result;
- }
- bool CheckWebConfigChargingSOC(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingSoc > 0)
- {
- if (chargingInfo[gunIndex]->EvBatterySoc >= ShmSysConfigAndInfo->SysConfig.MaxChargingSoc)
- result = true;
- }
- return result;
- }
- bool CheckOcppChargingTimeout(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->SessionTarget[gunIndex].targetDuration > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedDuration >= (ShmOCPP16Data->SessionTarget[gunIndex].targetDuration * 60))
- {
- PRINTF_FUNC("CheckOcppChargingTimeout. G_(%d) - (%d) \n", gunIndex,
- chargingInfo[gunIndex]->PresentChargedDuration);
- result = true;
- }
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->SessionTarget[gunIndex].targetDuration > 0)
- {
- if (chargingInfo [gunIndex]->PresentChargedDuration >= (ShmOCPP20Data->SessionTarget[gunIndex].targetDuration * 60))
- {
- PRINTF_FUNC ( "CheckOcppChargingTimeout. G_(%d) - (%d) \n", gunIndex,
- chargingInfo [gunIndex]->PresentChargedDuration );
- result = true;
- }
- }
- }
- return result;
- }
- bool CheckOcppChargingEnergy(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->SessionTarget[gunIndex].targetEnergy > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedEnergy >= ShmOCPP16Data->SessionTarget[gunIndex].targetEnergy)
- {
- PRINTF_FUNC ( "CheckOcppChargingEnergy. G_(%d) - (%f) \n", gunIndex,
- chargingInfo[gunIndex]->PresentChargedEnergy );
- result = true;
- }
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->SessionTarget[gunIndex].targetEnergy > 0)
- {
- if (chargingInfo [gunIndex]->PresentChargedEnergy >= ShmOCPP20Data->SessionTarget[gunIndex].targetEnergy)
- {
- PRINTF_FUNC ( "CheckOcppChargingEnergy. G_(%d) - (%f) \n", gunIndex,
- chargingInfo [gunIndex]->PresentChargedEnergy );
- result = true;
- }
- }
- }
- return result;
- }
- bool CheckOcppChargingSOC(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->SessionTarget[gunIndex].targetSoc > 0)
- {
- if (chargingInfo [gunIndex]->EvBatterySoc >= (ShmOCPP16Data->SessionTarget[gunIndex].targetSoc))
- {
- PRINTF_FUNC ( "CheckOcppChargingSOC. G_(%d) - (%d) \n", gunIndex,
- chargingInfo [gunIndex]->PresentChargedDuration );
- result = true;
- }
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->SessionTarget[gunIndex].targetSoc > 0)
- {
- if (chargingInfo [gunIndex]->EvBatterySoc >= (ShmOCPP20Data->SessionTarget[gunIndex].targetSoc))
- {
- PRINTF_FUNC ( "CheckOcppChargingSOC. G_(%d) - (%d) \n", gunIndex,
- chargingInfo [gunIndex]->PresentChargedDuration );
- result = true;
- }
- }
- }
- return result;
- }
- bool IsGunUsing(byte dcGunIndex)
- {
- bool result = false;
- if((chargingInfo[dcGunIndex]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
- chargingInfo[dcGunIndex]->SystemStatus <= SYS_MODE_ALARM) ||
- (chargingInfo[dcGunIndex]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 &&
- chargingInfo[dcGunIndex]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
- {
- result = true;
- }
- return result;
- }
- void InfoFwSlotStatusLog()
- {
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- {
- if ((bd0_1_status == 0 && bd0_2_status == 1) || (bd1_1_status == 0 && bd1_2_status == 1))
- PRINTF_FUNC("Connector 1 : Chademo [Ver. = %s]", ShmCHAdeMOData->evse[chargingInfo[0]->type_index].version);
- else if ((bd0_1_status == 1 && bd0_2_status == 0) || (bd1_1_status == 1 && bd1_2_status == 0))
- PRINTF_FUNC("Connector 1 : CCS [Ver. = %s]", ShmCcsData->V2GMessage_DIN70121[chargingInfo[0]->type_index].version);
- else if ((bd0_1_status == 1 && bd0_2_status == 1) || (bd1_1_status == 1 && bd1_2_status == 1))
- PRINTF_FUNC("Connector 1 : GB [Ver. = %s]", ShmGBTData->evse[chargingInfo[0]->type_index].version);
- }
- else
- {
- if (bd0_1_status == 0 && bd0_2_status == 1)
- PRINTF_FUNC("Connector 1 : Chademo [Ver. = %s]", ShmCHAdeMOData->evse[chargingInfo[0]->type_index].version);
- else if (bd0_1_status == 1 && bd0_2_status == 0)
- PRINTF_FUNC("Connector 1 : CCS [Ver. = %s]", ShmCcsData->V2GMessage_DIN70121[chargingInfo[0]->type_index].version);
- else if (bd0_1_status == 1 && bd0_2_status == 1)
- PRINTF_FUNC("Connector 1 : GB [Ver. = %s]", ShmGBTData->evse[chargingInfo[0]->type_index].version);
- if (bd1_1_status == 0 && bd1_2_status == 1)
- PRINTF_FUNC("Connector 2 : Chademo [Ver. = %s]", ShmCHAdeMOData->evse[chargingInfo[1]->type_index].version);
- else if (bd1_1_status == 1 && bd1_2_status == 0)
- PRINTF_FUNC("Connector 2 : CCS [Ver. = %s]", ShmCcsData->V2GMessage_DIN70121[chargingInfo[1]->type_index].version);
- else if (bd1_1_status == 1 && bd1_2_status == 1)
- PRINTF_FUNC("Connector 2 : GB [Ver. = %s]", ShmGBTData->evse[chargingInfo[1]->type_index].version);
- }
- }
- void InfoSystemType()
- {
- if (ShmDcCommonData->systemType == _SYSTEM_TYPE_SIMPLE)
- PRINTF_FUNC("DW or DM Serial.");
- else if (ShmDcCommonData->systemType == _SYSTEM_TYPE_STANDARD)
- PRINTF_FUNC("DS Serial - Standard");
- else if (ShmDcCommonData->systemType == _SYSTEM_TYPE_SMART)
- PRINTF_FUNC("DS Serial - Dynamic");
- }
- void InfoLcmVersion()
- {
- PRINTF_FUNC("LCM Version = V.%03d ", ShmDcCommonData->LcmFwVersion);
- }
- 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)
- {
- 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);
- }
- }
- 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;
- }
- int CreateShareMemory()
- {
- int MeterSMId;
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n");
- return 0;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n");
- return 0;
- }
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmStatusCodeData NG \n");
- return 0;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmStatusCodeData NG \n");
- return 0;
- }
- memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
-
- if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPsuData NG \n");
- return 0;
- }
- else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPsuData NG \n");
- return 0;
- }
- memset(ShmPsuData, 0, sizeof(struct PsuData));
- if(CHAdeMO_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCHAdeMOData NG \n");
- return 0;
- }
- else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCHAdeMOData NG \n");
- return 0;
- }
- memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
- }
- if(GB_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmGBTData NG \n");
- return 0;
- }
- else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmGBTData NG \n");
- return 0;
- }
- memset(ShmGBTData, 0, sizeof(struct GBTData));
- }
-
- if(CCS_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCcsData NG \n");
- return 0;
- }
- else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCcsData NG \n");
- return 0;
- }
- memset(ShmCcsData, 0, sizeof(struct CcsData));
- }
-
- if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPrimaryMcuData NG \n");
- return 0;
- }
- else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG \n");
- return 0;
- }
- memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
-
- if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmFanModuleData NG \n");
- return 0;
- }
- else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmFanModuleData NG \n");
- return 0;
- }
- memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
-
- if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmRelayModuleData NG \n");
- return 0;
- }
- else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmRelayModuleData NG \n");
- return 0;
- }
- memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
- if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmLedModuleData NG \n");
- return 0;
- }
- else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmLedModuleData NG \n");
- return 0;
- }
- memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
-
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmOCPP16Data NG \n");
- return 0;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmOCPP16Data NG \n");
- return 0;
- }
- memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
- if ((MeterSMId = shmget ( ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777 )) < 0)
- {
- DEBUG_ERROR_MSG( "[main]CreatShareMemory:shmget ShmOCPP16DataPH NG \n" );
- return 0;
- }
- else if ((ShmOCPP16DataPH = shmat ( MeterSMId, NULL, 0 )) == (void *) - 1)
- {
- DEBUG_ERROR_MSG( "[main]CreatShareMemory:shmat ShmOCPP16DataPH NG \n" );
- return 0;
- }
- memset ( ShmOCPP16DataPH , 0, sizeof(struct OCPP16Data) );
- if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget OCPP20Data NG\n");
- return 0;
- }
- else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat OCPP20Data NG\n");
- return 0;
- }
- memset(ShmOCPP20Data,0,sizeof(struct OCPP20Data));
- if ((MeterSMId = shmget ( ShmSmartBoxKey, sizeof(struct SmartBoxData), IPC_CREAT | 0777 )) < 0)
- {
- DEBUG_ERROR_MSG( "[main]CreatShareMemory:shmget ShmSmartBoxKey NG \n" );
- return 0;
- }
- else if ((ShmSmartBoxData = shmat ( MeterSMId, NULL, 0 )) == (void *) - 1)
- {
- DEBUG_ERROR_MSG( "[main]CreatShareMemory:shmat ShmSmartBoxData NG \n" );
- return 0;
- }
- memset ( ShmSmartBoxData, 0, sizeof(struct SmartBoxData) );
- if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCsuMeterKey NG \n");
- return 0;
- }
- else if ((ShmCsuMeterData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCsuMeterData NG \n");
- return 0;
- }
- memset(ShmCsuMeterData, 0, sizeof(struct MeterInformation));
- if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCommonKey NG \n");
- return 0;
- }
- else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCommonKey NG \n");
- return 0;
- }
- byte buf = 0;
- if (ShmDcCommonData->rebootCount == 1)
- buf = ShmDcCommonData->rebootCount;
- memset(ShmDcCommonData, 0, sizeof(struct DcCommonInformation));
- ShmDcCommonData->rebootCount = buf;
- return 1;
- }
- void SetupRebootCount(byte value)
- {
- int MeterSMId;
- if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]RecordRebootCount:shmget ShmCommonKey NG \n");
- }
- else
- {
- ShmDcCommonData->rebootCount = value;
- shmctl(MeterSMId, IPC_SET, 0);
- }
- }
- void ChangeLcmByIndex(byte page_index)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != _ALARM_LEVEL_CRITICAL ||
- page_index == _LCM_COMPLETE || page_index == _LCM_FIX || page_index == _LCM_EMC)
- {
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0 &&
- (page_index == _LCM_FIX || page_index == _LCM_EMC))
- {
- bool isUpdate = false;
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus == SYS_MODE_UPDATE)
- {
- isUpdate = true;
- break;
- }
- }
- if (!isUpdate &&
- ShmDcCommonData->LcmFwVersion > 0 &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
- ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_EMC;
- else
- ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_FIX;
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
- }
- }
- }
- void InitGPIO()
- {
-
-
-
-
-
- system("echo 22 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio22/direction");
-
- system("echo 23 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio23/direction");
-
- system("echo 26 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio26/direction");
- system("echo 1 > /sys/class/gpio/gpio26/value");
-
- system("echo 27 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio27/direction");
-
- system("echo 29 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio29/direction");
-
- system("echo 19 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio19/direction");
- system("echo 1 > /sys/class/gpio/gpio19/value");
-
- system("echo 20 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio20/direction");
-
-
-
-
- system("echo 44 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio44/direction");
-
- system("echo 45 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio45/direction");
-
- system("echo 46 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio46/direction");
- system("echo 0 > /sys/class/gpio/gpio46/value");
-
- system("echo 47 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio47/direction");
-
-
-
-
- system("echo 89 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio89/direction");
- system("echo 1 > /sys/class/gpio/gpio89/value");
-
- system("echo 87 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio87/direction");
- system("echo 0 > /sys/class/gpio/gpio87/value");
-
- system("echo 88 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio88/direction");
-
- system("echo 86 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio86/direction");
-
-
-
-
- system("echo 111 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio111/direction");
-
- system("echo 114 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio114/direction");
-
- system("echo 113 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio113/direction");
-
- system("echo 110 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio110/direction");
- system("echo 0 > /sys/class/gpio/gpio110/value");
-
- system("echo 115 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio115/direction");
- system("echo 0 > /sys/class/gpio/gpio115/value");
-
- system("echo 112 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio112/direction");
- system("echo 1 > /sys/class/gpio/gpio112/value");
-
- system("echo 116 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio116/direction");
- system("echo 0 > /sys/class/gpio/gpio116/value");
-
- system("echo 103 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio103/direction");
- system("echo 0 > /sys/class/gpio/gpio103/value");
-
- system("echo 104 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio104/direction");
- system("echo 0 > /sys/class/gpio/gpio104/value");
- #ifdef SystemLogMessage
- DEBUG_INFO_MSG("[main]InitGPIO: Initial GPIO OK \n");
- #endif
- }
- int LoadSysConfigAndInfo(struct SysConfigData *ptr)
- {
- int fd,wrd;
- unsigned char *buf;
- unsigned int ChkSum,ChkSumOrg;
- if((buf=malloc(MtdBlockSize))==NULL)
- {
- DEBUG_ERROR_MSG("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);
-
-
-
- system("nanddump /dev/mtd10 -f /mnt/EvseConfig.bin");
-
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if (fd < 0)
- {
- free(buf);
- DEBUG_ERROR_MSG("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);
- DEBUG_ERROR_MSG("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=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
- {
- ChkSum+=buf[wrd];
- }
- memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
- memcpy(&ptr->ModelName,buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)),ARRAY_SIZE(ptr->ModelName));
- memcpy(&ptr->SerialNumber,buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)+ARRAY_SIZE(ptr->ModelName)+ARRAY_SIZE(ptr->AcModelName)),ARRAY_SIZE(ptr->SerialNumber));
-
-
-
- if(ChkSum!=ChkSumOrg)
- {
- DEBUG_ERROR_MSG("Primary SysConfigData checksum NG, read backup\r\n");
- system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
-
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if (fd < 0)
- {
- free(buf);
- DEBUG_ERROR_MSG("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);
- DEBUG_ERROR_MSG("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=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
- {
- ChkSum+=buf[wrd];
- }
- memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
-
-
-
- if(ChkSum!=ChkSumOrg)
- {
- DEBUG_ERROR_MSG("backup SysConfigData checksum NG, read Factory default\r\n");
- system("nanddump /dev/mtd12 -f /mnt/EvseConfig.bin");
-
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if (fd < 0)
- {
- free(buf);
- DEBUG_ERROR_MSG("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);
- DEBUG_ERROR_MSG("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=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
- {
- ChkSum+=buf[wrd];
- }
- memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
- memcpy(buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)), &ptr->ModelName, ARRAY_SIZE(ptr->ModelName));
- memcpy(buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)+ARRAY_SIZE(ptr->ModelName)+ARRAY_SIZE(ptr->AcModelName)), &ptr->SerialNumber, ARRAY_SIZE(ptr->SerialNumber));
- if(ChkSum!=ChkSumOrg)
- {
- DEBUG_ERROR_MSG("factory default SysConfigData checksum NG, restore factory default\r\n");
- free(buf);
-
- sleep(5);
- char facBuf[256];
- sprintf(facBuf, "cd /root;./FactoryConfig -m %s %s",
- ShmSysConfigAndInfo->SysConfig.ModelName,
- ShmSysConfigAndInfo->SysConfig.SerialNumber);
- system(facBuf);
- system("rm -f /Storage/OCPP/OCPPConfiguration");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- return FAIL;
- }
- }
- }
-
- memcpy((struct SysConfigData *)ptr,buf,sizeof(struct SysConfigData));
- free(buf);
- system("rm -f /mnt/EvseConfig.bin");
-
- if((strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName)) ||
- (strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber)) ||
- (strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId)) ||
- (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff))
- {
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName))
- {
- PRINTF_FUNC("Model name over length.\n");
- memset(ShmSysConfigAndInfo->SysConfig.ModelName, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
- }
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber))
- {
- PRINTF_FUNC("Model serial number over length.\n");
- memset(ShmSysConfigAndInfo->SysConfig.SerialNumber, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
- }
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId))
- {
- PRINTF_FUNC("System id over length.\n");
- memset(ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId));
- }
- if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff)
- {
- PRINTF_FUNC("Ethernet dhcp config is null.\n");
- }
- system("cd /root;./FactoryConfig -m");
- sleep(3);
- system("/usr/bin/run_evse_restart.sh");
- }
- PRINTF_FUNC("*********************************************************** \n");
- DEBUG_INFO_MSG("Load SysConfigData OK\r\n");
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memcpy((char*)ShmOCPP16Data->ChargeBoxId,
- (char*)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,
- ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- memcpy((char*)ShmOCPP20Data->ChargeBoxId,
- (char*)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,
- ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
- }
- 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((char*)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- tmp, strspn(tmp, "addr:"), strlen(tmp)-strspn(tmp, "addr:"));
- sscanf(buf, "%*s%*s%*s%s", tmp);
- substr((char*)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
- tmp, strspn(tmp, "Mask:"), strlen(tmp)-strspn(tmp, "Mask:"));
- }
- }
- }
- pclose(fp);
- 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)
- {
-
- if(strstr(buf,"100%") != NULL)
- {
- }
- else
- {
- result = PASS;
- }
-
-
- }
- }
- }
- pclose(fp);
- }
- }
- return result;
- }
- void InitEthernet()
- {
- system("ifconfig eth0 down");
- system("ifconfig eth1 down");
- sleep(2);
- char tmpbuf[256];
-
- system("echo 1 > /sys/class/gpio/gpio110/value");
- sleep(2);
-
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
- system(tmpbuf);
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"route add default gw %s eth0 ",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
- system(tmpbuf);
-
-
-
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up",
- ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
- system(tmpbuf);
-
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"ifconfig lo up");
- system(tmpbuf);
-
- system("killall udhcpc");
- system("rm -rf /etc/resolv.conf");
- system("echo nameserver 8.8.8.8 > /etc/resolv.conf");
- system("echo nameserver 180.76.76.76 >> /etc/resolv.conf");
-
- 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);
- }
-
- sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- pid_t pid = fork();
- uint8_t cnt_pingDNS_Fail;
- if(pid == 0)
- {
- for(;;)
- {
- if (isRouteFail())
- {
-
- system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
- if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
- {
- InitialDHCP();
- }
- else
- {
- system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up &",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
- system(tmpbuf);
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"route add default gw %s eth0 &",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
- system(tmpbuf);
- }
- }
- if(isReachableInternet() == PASS)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet = NO;
- cnt_pingDNS_Fail = 0;
- }
- else
- {
- if(++cnt_pingDNS_Fail > 3)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet = YES;
- if((ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient==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);
- }
- else
- {
- system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up &",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
- system(tmpbuf);
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"route add default gw %s eth0 &",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
- system(tmpbuf);
- }
- cnt_pingDNS_Fail = 0;
- }
- }
- bool ethResult = !ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet;
- ShmSysConfigAndInfo->SysInfo.ethInternetConn = !ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet;
- if(ethResult == YES)
- {
- system("/sbin/ifmetric eth0 0");
- if(_isUsingWifi)
- system("/sbin/ifmetric mlan0 1");
- if(_isUsing4G)
- system("/sbin/ifmetric ppp0 2");
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- _isUsingWifi)
- {
- ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? NO : YES;
- if (ethResult)
- {
- system("/sbin/ifmetric eth0 1");
- if(_isUsingWifi)
- system("/sbin/ifmetric mlan0 0");
- if(_isUsing4G)
- system("/sbin/ifmetric ppp0 2");
- }
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
- _isUsing4G)
- {
- ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == YES ? NO : YES;
- if (ethResult)
- {
- system("/sbin/ifmetric eth0 1");
- if(_isUsingWifi)
- system("/sbin/ifmetric mlan0 2");
- if(_isUsing4G)
- system("/sbin/ifmetric ppp0 0");
- }
- }
- ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
- sleep(5);
- }
- }
- #ifdef SystemLogMessage
- DEBUG_INFO_MSG("[main]InitEthernet: Initial Ethernet OK. \n");
- #endif
- }
- 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()
- {
-
- 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' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'K' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'L' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'S' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'W')
- {
- 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] == 'E' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'T' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'D' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'M' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'N' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'R' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'V' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'F' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'Y' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'Z' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'I' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'Q')
- {
- 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 == 1 && ccs == 1)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
- else if (chademo == 1 && gb == 1)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
- else if (ccs == 1 && gb == 1)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
- else if (chademo == 2)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '7';
- else if (ccs == 2)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '8';
- else if (gb == 2)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '9';
- }
-
- if (_isUsingWifi && _isUsing4G)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '5';
- else if (_isUsingWifi)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
- else if (_isUsing4G)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
- else
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
-
- memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
-
- char _buf[3] = {0};
- memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[3], 1);
- if (strcmp(_buf, "E") == EQUAL || strcmp(_buf, "G") == EQUAL || strcmp(_buf, "C") == EQUAL ||
- strcmp(_buf, "T") == EQUAL || strcmp(_buf, "K") == EQUAL || strcmp(_buf, "Z") == EQUAL ||
- strcmp(_buf, "M") == EQUAL || strcmp(_buf, "P") == EQUAL || strcmp(_buf, "I") == EQUAL ||
- strcmp(_buf, "F") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
- else if (strcmp(_buf, "U") == EQUAL || strcmp(_buf, "B") == EQUAL || strcmp(_buf, "L") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
- else if (strcmp(_buf, "J") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_JARI;
- memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[12], 2);
- memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[14], &ShmSysConfigAndInfo->SysConfig.ModelName[12], 2);
- if (strcmp(_buf, "PN") == EQUAL ||
- strcmp(_buf, "N7") == EQUAL ||
- strcmp(_buf, "NX") == EQUAL ||
- strcmp(_buf, "OL") == EQUAL ||
- strcmp(_buf, "DE") == EQUAL)
- ShmDcCommonData->ShowLogoFlag = NO;
- else
- ShmDcCommonData->ShowLogoFlag = YES;
- if (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'G')
- ShmDcCommonData->chargerType = CHARGER_TYPE_SIMPLE;
- else
- ShmDcCommonData->chargerType = CHARGER_TYPE_STANDARD;
- }
- 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 ParsingModelNameForDeviceEnable()
- {
-
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == '1')
- {
- _verifyMechanism = VERIFY_MECHANISM_ENEGATE;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == '2')
- {
- _verifyMechanism = VERIFY_MECHANISM_BAZEL8;
- }
-
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == '1' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == '2' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == '3' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == '4' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == '7' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == '8' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'A' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'K' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'L' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
- _isUsingWifi = YES;
- else
- _isUsingWifi = NO;
-
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == '1' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == '2' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == '3' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == '4' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == '7' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == '8' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'A' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'L' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
- _isUsing4G = YES;
- else
- _isUsing4G = NO;
- }
- void InitialShareMemoryInfo()
- {
- FILE *fp;
- char cmd[512];
- char buf[512];
- 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);
- }
- }
- GetFirmwareVersion();
-
- 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 = NO;
- ShmSysConfigAndInfo->SysInfo.OcppConnStatus = NO;
- 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;
- 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;
- 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;
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_NORMAL;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOTTING;
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- ShmFanModuleData->TestFanSpeed = 0;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- InitialGunIndexToUnUse();
- ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
- ShmDcCommonData->systemType = _SYSTEM_TYPE_SIMPLE;
- ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V015S0;
- ShmDcCommonData->psuKeepCommunication = NO;
- ShmDcCommonData->acContactSwitch = NO;
- ShmDcCommonData->ConnectErrList[0].GunErrMessage = 0;
- ShmDcCommonData->ConnectErrList[1].GunErrMessage = 0;
- ShmDcCommonData->LcmFwVersion = 0;
- ShmDcCommonData->minOutputCur = 0;
- ShmDcCommonData->evBoardResetFlag = NO;
- ShmDcCommonData->enObtainAuthorizbyCCID = NO;
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
- ShmDcCommonData->_psuProtocol = _PSU_PROTOCOL_INFY;
- ShmDcCommonData->_offlinePower = 0;
- ShmDcCommonData->_tpcPlugDetectState = _TPC_PLUG_DETECT_STATUS_NONE;
- ShmDcCommonData->TpcDetectFunction = NO;
- ShmDcCommonData->_isPsuErrorOccur = NO;
- ShmDcCommonData->stopSessionIndex = NO_DEFINE;
- ParsingModelNameForDeviceEnable();
- ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
- }
- int Initialization()
- {
-
- ClearAuthorizedFlag();
-
- ClearDetectPluginFlag();
-
- if (_verifyMechanism == VERIFY_MECHANISM_RFID)
- rfidFd = InitialRfidPort();
- int pinOut[2] = { 116, 115 };
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- chargingInfo[count]->RemoteStartFlag = NO;
- chargingInfo[count]->ReservedStartFlag = 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)
- {
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- gpio_set_value(pinOut[1], 0x00);
- else
- gpio_set_value(pinOut[count], 0x00);
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
- }
- strcpy((char *)ShmDcCommonData->_reserved_UserId[count], "");
- }
- byte acDirIndex = 0;
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- if (count == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- ocpp_set_noErrorCode_cmd(count + acDirIndex, "NoError");
- }
- byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
- 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;
- ocpp_set_noErrorCode_cmd(count + hasDc, "NoError");
- }
- }
- PRINTF_FUNC("Information check done \n");
- return PASS;
- }
- bool InitialSystemDefaultConfig()
- {
- bool result = true;
- LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
- PRINTF_FUNC("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
- InitGPIO();
- InitEthernet();
- GetMacAddress();
- return result;
- }
- bool DisplaySelfTestFailReason()
- {
- bool result = false;
-
- if (ShmRelayModuleData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = YES; result = true; }
- if (ShmFanModuleData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = YES; result = true; }
- if (ShmPrimaryMcuData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = YES; result = true; }
- if (ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
- { result = 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 = YES; result = true; }
- }
- else if (chargingInfo[index]->Type == _Type_GB)
- {
- if (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtboardStestFail = YES; result = true; }
- }
- else if (chargingInfo[index]->Type == _Type_CCS)
- {
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
- {
- if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = YES; result = true; }
- }
- }
- }
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++)
- {
-
- if (ac_chargingInfo[index]->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcConnectorStestFail = YES; result = true; }
- }
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
- {
-
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = YES;
- result = true;
- }
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES)
- {
- result = true;
- }
- else if (ShmPsuData->SystemAvailablePower <= 0 && ShmPsuData->SystemAvailableCurrent <= 0)
- {
-
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = YES;
- 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) <= 20)
- {
- ReviewCriticalAlarm();
- ChkPrimaryStatus();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_CRITICAL ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES)
- {
- 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;
- }
- if (strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
- ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
- {
-
- ShmFanModuleData->SelfTest_Comp = YES;
- }
- if (strlen((char *)ShmPrimaryMcuData->version) != 0 ||
- ShmPrimaryMcuData->version[0] != '\0')
- {
-
- ShmPrimaryMcuData->SelfTest_Comp = YES;
- }
-
- if (!evInitFlag)
- {
- evInitFlag = YES;
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- 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;
- }
- else
- {
-
- 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;
- }
- else
- {
-
- evInitFlag = NO;
- }
- }
- else if (chargingInfo[index]->Type == _Type_CCS)
- {
- 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;
- }
- else
- {
-
- 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;
- }
- else
- {
- evInitFlag = NO;
- }
- }
- }
- }
- if (ShmFanModuleData->SelfTest_Comp &&
- ShmRelayModuleData->SelfTest_Comp &&
- ShmPrimaryMcuData->SelfTest_Comp &&
- evInitFlag)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_AC_CONTACTOR;
- }
- }
- break;
- case _STEST_AC_CONTACTOR:
- {
-
-
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
- PRINTF_FUNC("Communication board pass. \n");
- }
- }
- break;
- case _STEST_PSU_DETECT:
- {
- if (ShmPsuData->Work_Step >= GET_SYS_CAP)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
- }
- }
- break;
- case _STEST_PSU_CAP:
- {
-
-
- if (ShmPsuData->Work_Step == BOOTING_COMPLETE)
- {
- sleep(1);
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
- ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
- }
- }
- 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_PsuComm &");
- system("/root/Module_SmartBox &");
- system("/root/Module_ProduceUtils &");
- if (_verifyMechanism == VERIFY_MECHANISM_BAZEL8)
- system("/root/Module_Payment_Bazel8 &");
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- system("/root/OcppBackend &");
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- system("/root/OcppBackend20 &");
- if(_isUsing4G)
- {
- system("/root/Module_4g &");
- }
- if(_isUsingWifi)
- {
- system("/root/Module_Wifi &");
- }
- 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)
- {
- DEBUG_ERROR_MSG("write /dev/mtdblock11(backup) NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("open /dev/mtdblock11(backup) NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("write /dev/mtdblock10 NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("open /dev/mtdblock10 NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("alloc BlockSize NG\r\n");
- result = FAIL;
- }
- if(BufTmp != NULL)
- free(BufTmp);
- return result;
- }
- bool isEvBoardStopChargeFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->StopChargeFlag;
- }
- bool isEvBoardNormalStopChargeFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->NormalStopChargeFlag;
- }
- void ClearDetectPluginFlag()
- {
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- ocpp_sub_set_remote_start_transaction_req(gun_index, NO);
- if (chargingInfo[gun_index]->RemoteStartFlag == YES)
- chargingInfo[gun_index]->RemoteStartFlag = NO;
- if (chargingInfo[gun_index]->ReservedStartFlag == YES)
- chargingInfo[gun_index]->ReservedStartFlag = 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;
- }
- bool isEvGunLocked(byte gunIndex)
- {
- return chargingInfo[gunIndex]->GunLocked;
- }
- 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);
- }
- byte isPrechargeStatus_chademo(byte gunIndex)
- {
- byte result = 0x00;
- result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
- return result;
- }
- byte isPrechargeStatus_gb(byte gunIndex)
- {
- byte result = 0x00;
- result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
- return result;
- }
- 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;
- }
- void DisplayChargingInfo()
- {
- PRINTF_FUNC("*********** DisplayChargingInfo *********** \n");
- for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->SystemStatus != SYS_MODE_IDLE &&
- chargingInfo[i]->SystemStatus != SYS_MODE_RESERVATION)
- {
- ChangeGunSelectByIndex(i);
- usleep(50000);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- return;
- }
- }
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
- ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING && ac_chargingInfo[0]->SystemStatus <= SYS_MODE_COMPLETE)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
- }
- usleep(50000);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- 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)
- {
- if (ShmDcCommonData->stopSessionIndex != NO_DEFINE &&
- ShmDcCommonData->stopSessionIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
- {
- PRINTF_FUNC("NormalStop (%d) \n", ShmDcCommonData->stopSessionIndex);
- ChargingTerminalProcess(ShmDcCommonData->stopSessionIndex);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ShmDcCommonData->stopSessionIndex = NO_DEFINE;
- }
- else
- {
- bool needPluginDet = true;
- if (ShmDcCommonData->enObtainAuthorizbyCCID)
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- if (ShmDcCommonData->_authWithCcidFlag [gun_index] == _CCID_CHECK)
- {
- needPluginDet = false;
- break;
- }
- }
- }
- if (needPluginDet)
- DetectPluginStart();
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_AUTHCOMP;
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL)
- {
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_AUTHFAIL;
- }
- usleep(50000);
- stopChargingChkByCard = false;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- void _SelfTestTimeout()
- {
- if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- ChargingAlarmProcess(gun_index);
- }
- }
- ShmPsuData->Work_Step = _NO_WORKING;
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
- PRINTF_FUNC("Self test timeout. \n");
- }
- void _AuthorizedTimeout()
- {
- PRINTF_FUNC("*********** _AuthorizedTimeout *********** \n");
- isCardScan = false;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_AUTHFAIL;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearAuthorizedFlag();
-
- }
- void _DetectPlugInTimeout()
- {
- PRINTF_FUNC("*********** _DetectPlugInTimeout (%d)*********** \n", _connectionTimeout);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearDetectPluginFlag();
- usleep(50000);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- void _DetectTpcPlugInTimeout()
- {
- PRINTF_FUNC("// _Detect CHAdeMO_TPC PlugInTimeout(60 sec) // \n");
- ShmDcCommonData->_tpcPlugDetectState = _TPC_PLUG_DETECT_STATUS_NONE;
- }
- void _DetectEvChargingEnableTimeout(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- {
- if(!isEvGunLocked(gunIndex))
- {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- if(!isEvGunLocked(gunIndex))
- {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_CCS)
- {
- if(!isEvGunLocked(gunIndex))
- {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
- }
- }
- ChargingTerminalProcess(gunIndex);
- _AutoReturnTimeout();
- }
- void _DetectEvseChargingEnableTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
-
- {
- SetChargerMode(gunIndex, SYS_MODE_IDLE);
- _AutoReturnTimeout();
- }
- }
- void _PrepareTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _PrepareTimeout ***********\n");
- SetChargerMode(gunIndex, SYS_MODE_IDLE);
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
- _AutoReturnTimeout();
- }
- void _CcsPrechargeTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _CcsPrechargeTimeout ***********\n");
- SetChargerMode(gunIndex, SYS_MODE_IDLE);
- }
- void AuthorizingStart()
- {
- ocpp_set_authorizeReq_cmd(YES);
- ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
- }
- void ClearAuthorizedFlag()
- {
- ocpp_set_authorizeConf_cmd(NO);
- ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
- }
- bool isAuthorizedComplete()
- {
- return ocpp_get_authorize_conf();
- }
- bool IsAuthorizingMode()
- {
- if(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO)
- return false;
- return true;
- }
- void RecordAlarmCode(byte gunIndex, char *code)
- {
- if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES; return; }
- else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES; return; }
- else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES; return; }
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) == EQUAL)
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, code, 6);
- if (strcmp(code, "012234") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES;
- else if (strcmp(code, "012235") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
- else if (strcmp(code, "012236") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES;
- else if (strcmp(code, "012288") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = YES;
- else if (strcmp(code, "012289") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = YES;
- else if (strcmp(code, "012290") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = YES;
- else if (strcmp(code, "012229") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES;
- else if (strcmp(code, "012230") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES;
- else if (strcmp(code, "012231") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES;
- else if (strcmp(code, "012296") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES;
- else if (strcmp(code, "012297") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES;
- else if (strcmp(code, "012298") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES;
- else if (strcmp(code, "011011") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES;
- else if (strcmp(code, "011013") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES;
- else if (strcmp(code, "011015") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES;
- else if (strcmp(code, "011012") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES;
- else if (strcmp(code, "011014") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES;
- else if (strcmp(code, "011016") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES;
- else if (strcmp(code, "012320") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectUCP = YES;
- else if (strcmp(code, "012321") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectUCP = YES;
- else if (strcmp(code, "012322") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectUCP = YES;
- else if (strcmp(code, "011039") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ParallelRelayWeldingFault = YES;
- else if (strcmp(code, "011040") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ParallelRelayDrivingFault = YES;
- else if (strcmp(code, "023984") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.StopByEvseCondition = YES;
- }
- void ResetChargerAlarmCode(byte gunIndex, char *code)
- {
- if (strcmp(code, "012229") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
- else if (strcmp(code, "012230") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
- else if (strcmp(code, "012231") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
- else if (strcmp(code, "011011") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
- else if (strcmp(code, "011013") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
- else if (strcmp(code, "011015") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
- else if (strcmp(code, "011012") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
- else if (strcmp(code, "011014") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
- else if (strcmp(code, "011016") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
- else if (strcmp(code, "011018") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
- else if (strcmp(code, "011019") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO;
- else if (strcmp(code, "011020") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO;
- else if (strcmp(code, "012320") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectUCP)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectUCP = NO;
- else if (strcmp(code, "012321") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectUCP)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectUCP = NO;
- else if (strcmp(code, "012322") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectUCP)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectUCP = NO;
- else if (strcmp(code, "011039") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ParallelRelayWeldingFault)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ParallelRelayWeldingFault = NO;
- else if (strcmp(code, "011040") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ParallelRelayDrivingFault)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ParallelRelayDrivingFault = NO;
- else if (strcmp(code, "023984") == EQUAL && ShmDcCommonData->ConnectErrList[gunIndex].GunBits.StopByEvseCondition)
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.StopByEvseCondition = NO;
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, code, 6) == EQUAL)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- }
- }
- void ReleaseSysAlarmCode(byte gunIndex)
- {
-
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012324", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012325", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012267", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012346", 6) == EQUAL)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- }
- }
- if (gunIndex == 0)
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AbnormalVoltageOnOutputLine_1 = NO;
- else if (gunIndex == 1)
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AbnormalVoltageOnOutputLine_2 = NO;
- ResetChargerAlarmCode(gunIndex, "023984");
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectUCP = NO;
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012217", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012296", 6) == EQUAL)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- }
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_CCS)
- {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectUCP = NO;
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012219", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012297", 6) == EQUAL)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- }
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectUCP = NO;
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012221", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012298", 6) == EQUAL)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- }
- }
- }
- ocpp_clear_errorCode_cmd(gunIndex);
- }
- void NormalStop(byte gunIndex)
- {
- PRINTF_FUNC("NormalStop (%d) \n", gunIndex);
- }
- void ChargingTerminalProcess(byte gunIndex)
- {
- SetChargerMode(gunIndex, SYS_MODE_TERMINATING);
- }
- void ChargingAlarmProcess(byte gunIndex)
- {
- CheckSystemErrorFunction(gunIndex);
- ocpp_set_errCode_cmd(gunIndex);
- SetChargerMode(gunIndex, SYS_MODE_ALARM);
- }
- void AcChargingTerminalProcess()
- {
- ac_chargingInfo[0]->SystemStatus = SYS_MODE_TERMINATING;
- }
- void BoardErrOccurByString(byte index, char *code)
- {
-
- if ((chargingInfo[index]->SystemStatus > SYS_MODE_IDLE && chargingInfo[index]->SystemStatus < SYS_MODE_TERMINATING) ||
- (chargingInfo[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
- {
- PRINTF_FUNC("BoardErrOccurByString (%d) - (%s) \n", index, code);
- if (strncmp(code, "023730", 6) == EQUAL &&
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
- }
- ChargingAlarmProcess(index);
- }
-
- }
- void EmcOccurThenStopCharging()
- {
-
-
-
- for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++)
- {
- if ((chargingInfo[gun]->SystemStatus > SYS_MODE_IDLE && chargingInfo[gun]->SystemStatus < SYS_MODE_TERMINATING) ||
- (chargingInfo[gun]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[gun]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
- {
- ChargingAlarmProcess(gun);
- }
- }
-
- }
- void ReleaseBoardErrOccurByString(byte index, char *code)
- {
- if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
- }
- }
- void ReleaseEmsOccureByString(byte index, char *code)
- {
- if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
- }
- else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
- }
- else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- }
- else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- }
- bool leftBtnPush = false;
- bool rightBtnPush = false;
- byte _delayDetectSingleBtnCnt = 0;
- bool twoBtnPress = 0;
- bool btnDelayFlag = 0;
- void ButtonTriggerEvent()
- {
- if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
- ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS)
- {
- ShmSysConfigAndInfo->SysConfig.ShowInformation = YES;
- twoBtnPress = TRUE;
- }
- else
- {
- ShmSysConfigAndInfo->SysConfig.ShowInformation = NO;
-
- if (twoBtnPress == TRUE && _delayDetectSingleBtnCnt < 100)
- _delayDetectSingleBtnCnt++;
- else
- {
- if (twoBtnPress == TRUE)
- twoBtnPress = FALSE;
- _delayDetectSingleBtnCnt = 0;
- }
- }
- if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush)
- {
- if(leftBtnPush == BTN_RELEASE)
- {
- leftBtnPush = BTN_PRESS;
- PRINTF_FUNC("left btn down............................... \n");
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
- {
- switch(ac_chargingInfo[0]->SystemStatus)
- {
- case SYS_MODE_IDLE:
- case SYS_MODE_MAINTAIN:
- case SYS_MODE_RESERVATION:
- {
- if(isDetectPlugin())
- {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- }
- }
- break;
- case SYS_MODE_MODE_REASSIGN_CHECK:
- case SYS_MODE_REASSIGN:
- case SYS_MODE_PREPARING:
- case SYS_MODE_PREPARE_FOR_EV:
- case SYS_MODE_PREPARE_FOR_EVSE:
- case SYS_MODE_CCS_PRECHARGE_STEP0:
- case SYS_MODE_CCS_PRECHARGE_STEP1:
- {
-
- AcChargingTerminalProcess();
- }
- break;
- case SYS_MODE_CHARGING:
- {
- if (ShmSysConfigAndInfo->SysConfig.StopChargingByButton == YES)
- {
-
- AcChargingTerminalProcess();
- }
- }
- break;
- case SYS_MODE_COMPLETE:
- {}
- break;
- }
- }
- else
- {
- switch(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- case SYS_MODE_IDLE:
- case SYS_MODE_MAINTAIN:
- case SYS_MODE_RESERVATION:
- {
- if(isDetectPlugin())
- {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- btnDelayFlag = TRUE;
- }
- else
- {
-
- if (ShmDcCommonData->TpcDetectFunction == YES
- && ShmSysConfigAndInfo->SysConfig.ShowInformation == NO && twoBtnPress == FALSE
- && btnDelayFlag == FALSE)
- {
- if (ShmDcCommonData->_tpcPlugDetectState != _TPC_PLUG_DETECT_STATUS_WAIT)
- {
- PRINTF_FUNC("// Start Detect Plug in // \n");
- ShmDcCommonData->_tpcPlugDetectState = _TPC_PLUG_DETECT_STATUS_WAIT;
- GetTimespecFunc(&_tcpDetectStatus_time);
- }
- else
- {
- PRINTF_FUNC("// Stop Detect PlugIn for TPC. // \n");
- ShmDcCommonData->_tpcPlugDetectState = _TPC_PLUG_DETECT_STATUS_NONE;
- StopGunInfoTimeoutDet(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- }
- }
- }
- break;
- case SYS_MODE_MODE_REASSIGN_CHECK:
- case SYS_MODE_REASSIGN:
- case SYS_MODE_PREPARING:
- case SYS_MODE_PREPARE_FOR_EV:
- case SYS_MODE_PREPARE_FOR_EVSE:
- case SYS_MODE_CCS_PRECHARGE_STEP0:
- case SYS_MODE_CCS_PRECHARGE_STEP1:
- {
-
-
-
-
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- break;
- case SYS_MODE_CHARGING:
- {
- if (ShmSysConfigAndInfo->SysConfig.StopChargingByButton == YES)
- {
-
- NormalStop(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- }
- break;
- case SYS_MODE_COMPLETE:
- {
-
-
-
- }
- break;
- }
- }
- }
- }
- else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE)
- {
- if(leftBtnPush == BTN_PRESS)
- {
- leftBtnPush = BTN_RELEASE;
- PRINTF_FUNC("left btn up............................... \n");
-
- switch (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- case SYS_MODE_IDLE:
- btnDelayFlag = FALSE;
- break;
- }
- }
- }
- if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush)
- {
- if(rightBtnPush == BTN_RELEASE)
- {
- rightBtnPush = BTN_PRESS;
- PRINTF_FUNC("right btn down .................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- if (ShmSysConfigAndInfo->SysInfo.PageIndex >= _LCM_AUTHORIZING &&
- ShmSysConfigAndInfo->SysInfo.PageIndex <= _LCM_AUTHORIZ_FAIL)
- return;
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 == ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected++;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- else if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
- {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus != SYS_MODE_BOOTING &&
- chargingInfo[_index]->SystemStatus != SYS_MODE_IDLE &&
- chargingInfo[_index]->SystemStatus != SYS_MODE_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);
- }
- }
- }
- else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE)
- {
- if(rightBtnPush == BTN_PRESS)
- {
- rightBtnPush = BTN_RELEASE;
- PRINTF_FUNC("right btn up............................... \n");
- }
- }
- }
- void ChkPrimaryStatus()
- {
- if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
- EmcOccurThenStopCharging();
- }
- else
- ReleaseEmsOccureByString(0, "012251");
- if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
- EmcOccurThenStopCharging();
- }
- 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 &&
- ShmDcCommonData->_tiltSensorStep == _TILT_SENSOR_STEP_NONE)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
- EmcOccurThenStopCharging();
- }
- else
- ReleaseEmsOccureByString(0, "012252");
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- {
- EmcOccurThenStopCharging();
- }
- else
- ReleaseEmsOccureByString(0, "012267");
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU)
- {
- EmcOccurThenStopCharging ();
- }
- else
- ReleaseEmsOccureByString (0,"012346");
- }
- void CheckSystemErrorFunction(byte index)
- {
-
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip)
- RecordAlarmCode(index, "012251");
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip)
- RecordAlarmCode(index, "012238");
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen &&
- ShmDcCommonData->_tiltSensorStep == _TILT_SENSOR_STEP_NONE)
- RecordAlarmCode(index, "012252");
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- RecordAlarmCode(index, "012267");
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU)
- RecordAlarmCode(index, "012346");
- 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;
- }
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES)
- RecordAlarmCode(index, "012203");
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES)
- RecordAlarmCode(index, "012204");
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
- RecordAlarmCode(index, "012205");
- chargingInfo[index]->StopChargeFlag = YES;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- }
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- }
- }
- 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;
- }
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES)
- RecordAlarmCode(index, "012200");
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES)
- RecordAlarmCode(index, "012201");
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
- RecordAlarmCode(index, "012202");
- chargingInfo[index]->StopChargeFlag = YES;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- }
- }
- }
- 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()
- {
- int pinIn[4] = { 22, 23, 44, 45 };
- unsigned int gpioValue = 0;
- for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
- gpio_get_value(pinIn[i], &gpioValue);
- {
- switch (pinIn[i])
- {
- case 22:
- bd1_1_status = gpioValue;
- break;
- case 23:
- bd1_2_status = gpioValue;
- break;
- case 44:
- bd0_1_status = gpioValue;
- break;
- case 45:
- bd0_2_status = gpioValue;
- break;
- }
- }
- }
- }
- void CheckGpioInStatus()
- {
- int pinIn[2] = { 27, 47 };
- 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)
- {
- break;
- }
- }
- }
- break;
- case 27:
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->slotsIndex == 3)
- {
- 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");
- 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");
- break;
- }
- }
- }
- break;
- }
- }
- }
- }
- bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
- {
- for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
- {
- if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
- {
- chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
- return true;
- }
- }
- for (byte index = 0; index < CCS_QUANTITY; index++)
- {
- if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
- {
- chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
- return true;
- }
- }
- for (byte index = 0; index < GB_QUANTITY; index++)
- {
- if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
- {
- chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
- return true;
- }
- }
- return false;
- }
- unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
- {
- return ( _byte & mask_table[_bit] ) != 0x00;
- }
- 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 GetCcidAuthPossible(bool *idleReq, byte *idleIndex)
- {
- for (byte gun_index = 0;
- gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
- gun_index ++)
- {
-
- if (((chargingInfo [gun_index]->SystemStatus == SYS_MODE_PREPARE_FOR_EV && chargingInfo[gun_index]->Type == _Type_CCS)
- || (chargingInfo [gun_index]->SystemStatus == SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[gun_index]->Type == _Type_GB))
- && ShmDcCommonData->_authWithCcidFlag [gun_index] == _CCID_CHECK)
- {
- *idleIndex = gun_index;
- *idleReq = true;
- break;
- }
- }
- }
- void UserScanFunction()
- {
- bool idleReq = false;
- unsigned char idleIndex = 255;
-
- bool hasGunUsing = false;
- bool isReservedCard = false;
-
- if(!IsAuthorizingMode())
- {
-
-
-
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX ||
- ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_EMC)
- {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- return;
- }
- if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0)
- {
- if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
- ac_chargingInfo[0]->SystemStatus != SYS_MODE_ALARM)
- {
-
- if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
- ac_chargingInfo[0]->SystemStatus < SYS_MODE_ALARM)
- {
- if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_CHARGING)
- {
- 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 (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE ||
- ac_chargingInfo[0]->SystemStatus == SYS_MODE_RESERVATION)
- {
- idleReq = true;
- }
- }
- else
- {
- if (IsGunUsing(ShmSysConfigAndInfo->SysInfo.CurGunSelected))
- {
- if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == SYS_MODE_CHARGING)
- {
- 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)
- {
- NormalStop(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- else
- {
- if (ShmDcCommonData->enObtainAuthorizbyCCID)
- {
- GetCcidAuthPossible(&idleReq, &idleIndex);
- }
- if (!idleReq)
- {
- PRINTF_FUNC("Remote check for stop session = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
- stopChargingChkByCard = true;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
- ShmDcCommonData->stopSessionIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
-
- AuthorizingStart();
- return;
- }
- }
- }
- else
- {
- if (ShmDcCommonData->enObtainAuthorizbyCCID)
- {
- GetCcidAuthPossible(&idleReq, &idleIndex);
- }
- }
- }
- else
- {
- if (ShmDcCommonData->enObtainAuthorizbyCCID &&
- (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_AUTHORIZ_COMP ||
- ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_AUTHORIZ_FAIL))
- return;
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_IDLE)
- {
- idleIndex = gun_index;
- idleReq = true;
- }
- else if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_RESERVATION)
- {
- idleReq = true;
- }
- else
- {
- hasGunUsing = IsGunUsing(gun_index);
- }
- }
-
- if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES &&
- hasGunUsing)
- {
- PRINTF_FUNC("DW Serial not support dual charging. \n");
- idleReq = false;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- }
- }
- if (idleReq)
- {
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; gun_index++)
- {
- if (ac_chargingInfo[gun_index]->SystemStatus == SYS_MODE_RESERVATION)
- {
- if (strcmp ( (char *) ShmSysConfigAndInfo->SysConfig.UserId,
- (char *) ShmDcCommonData->_reserved_ac_UserId [gun_index] ) == EQUAL)
- {
- isReservedCard = true;
-
- ac_chargingInfo[gun_index]->ReservedStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- strcpy ( (char *) ShmSysConfigAndInfo->SysConfig.UserId, "" );
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
- break;
- }
- }
- }
- if (!isReservedCard)
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_RESERVATION)
- {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId,
- (char *)ShmDcCommonData->_reserved_UserId[gun_index]) == EQUAL)
- {
- isReservedCard = true;
-
- chargingInfo[gun_index]->ReservedStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
- break;
- }
- }
- }
- }
- if (!isReservedCard &&
- ((_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
- (idleIndex != 255 && (chargingInfo[idleIndex]->SystemStatus == SYS_MODE_IDLE ||
- chargingInfo[idleIndex]->SystemStatus == SYS_MODE_PREPARE_FOR_EV ||
- chargingInfo[idleIndex]->SystemStatus == SYS_MODE_PREPARE_FOR_EVSE))))
- {
-
- if (ShmDcCommonData->_CcidAuthProcessStep != _CCID_AUTH)
- {
- PRINTF_FUNC("Start Authorizing...UserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
-
- if (ShmDcCommonData->enObtainAuthorizbyCCID &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != DEFAULT_AC_INDEX)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = idleIndex;
- }
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_AUTH;
-
- AuthorizingStart();
- }
- }
- else
- {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- }
- }
- else
- {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- }
- }
- }
- 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 != _ALARM_LEVEL_CRITICAL &&
- ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
- {
- isCardScan = true;
-
- UserScanFunction();
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING)
- {
- StartSystemTimeoutDet(Timeout_Authorizing);
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
- ShmDcCommonData->stopSessionIndex == NO_DEFINE)
- {
-
- 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)
- {
- PRINTF_FUNC("White Card Pass (%s)... \n", ShmSysConfigAndInfo->SysConfig.UserId);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
- ClearAuthorizedFlag();
- break;
- }
- }
- }
- }
-
- if (isAuthorizedComplete() || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
- {
- StopSystemTimeoutDet();
-
- if(ocpp_chk_authrization_cmd() || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
- {
- if (ShmDcCommonData->stopSessionIndex != NO_DEFINE &&
- ShmDcCommonData->stopSessionIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
- {
- if (CheckTheParentId(ShmDcCommonData->stopSessionIndex))
- {
-
- PRINTF_FUNC ( "_LCM_AUTHORIZ_COMP (stop) \n" );
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
- }
- else
- {
-
- PRINTF_FUNC ( "_LCM_AUTHORIZ_FAIL (stop) \n" );
- ShmDcCommonData->stopSessionIndex = NO_DEFINE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
- strcpy ( (char *) ShmSysConfigAndInfo->SysConfig.UserId, "" );
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
- }
- }
- else
- {
-
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if ((chargingInfo[_index]->SystemStatus == SYS_MODE_IDLE || chargingInfo[_index]->SystemStatus == SYS_MODE_RESERVATION) &&
- ShmDcCommonData->remoteStartAuthFlag[_index])
- {
- chargingInfo[_index]->RemoteStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- }
- }
-
- PRINTF_FUNC("_LCM_AUTHORIZ_COMP \n");
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
- }
- }
- else
- {
-
- PRINTF_FUNC("_LCM_AUTHORIZ_FAIL \n");
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
- }
- ClearAuthorizedFlag();
- }
- }
- 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->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE &&
- 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':
- break;
- case '1':
- break;
- case '2':
- break;
- case '3':
- case '4':
- if (AC_QUANTITY > _ac_Index)
- {
- ac_chargingInfo[_acgunIndex] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[_ac_Index];
-
- ac_chargingInfo[_acgunIndex]->Index = DEFAULT_AC_INDEX;
- ac_chargingInfo[_acgunIndex]->ReservationId = NO_RESERVE;
- ac_chargingInfo[_acgunIndex]->SystemStatus = SYS_MODE_BOOTING;
- ac_chargingInfo[_acgunIndex]->Type = _Type_AC;
- ac_chargingInfo[_acgunIndex]->IsAvailable = YES;
- ac_chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
- ac_chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
- _ac_Index++;
- _acgunIndex++;
- }
- else
- result = false;
- break;
- case '5':
- break;
- case '6':
- break;
- case 'J':
- case 'K':
- case 'L':
- case 'S':
- case 'W':
- {
- if (CHAdeMO_QUANTITY > _chademoIndex)
- {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = NO_RESERVE;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = SYS_MODE_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_Chademo;
- chargingInfo[_gunIndex]->type_index = _chademoIndex;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
- chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
- chargingInfo[_gunIndex]->ModelType = typeValue;
- ShmDcCommonData->TpcDetectFunction = YES;
- _chademoIndex++;
- _gunIndex++;
- }
- else
- result = false;
- }
- break;
- case 'U':
- case 'E':
- case 'T':
- case 'D':
- case 'M':
- case 'N':
- case 'R':
- case 'V' :
- case 'F' :
- case 'Y' :
- case 'Z' :
- case 'I' :
- case 'Q' :
- {
- if (CCS_QUANTITY > _ccsIndex)
- {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = NO_RESERVE;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = SYS_MODE_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_CCS;
- chargingInfo[_gunIndex]->type_index = _ccsIndex;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
- chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
- chargingInfo[_gunIndex]->ModelType = typeValue;
-
- ShmCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
- if (typeValue == 'U' || typeValue == 'T' ||
- typeValue == 'N' || typeValue == 'V' ||
- typeValue == 'Y' || typeValue == 'I')
- ShmDcCommonData->CcsTypeSaved[_gunIndex] = _CCS_TYPE_CCS1;
- else if (typeValue == 'E' || typeValue == 'D' ||
- typeValue == 'M' || typeValue == 'R' ||
- typeValue == 'F' || typeValue == 'Z' ||
- typeValue == 'Q')
- ShmDcCommonData->CcsTypeSaved[_gunIndex] = _CCS_TYPE_CCS2;
- _ccsIndex++;
- _gunIndex++;
- }
- else
- result = false;
- }
- break;
- case 'G':
- case 'B':
- {
- if (GB_QUANTITY > _gb_Index)
- {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[_gb_Index];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = NO_RESERVE;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = SYS_MODE_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_GB;
- chargingInfo[_gunIndex]->type_index = _gb_Index;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
- chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
- chargingInfo[_gunIndex]->ModelType = typeValue;
- _gb_Index++;
- _gunIndex++;
- }
- else
- result = false;
- }
- break;
- }
- return result;
- }
- bool CheckConnectorTypeStatus()
- {
- bool result = true;
-
-
- if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9)
- {
- byte slots = 1;
- for (byte typeIndex = 7; typeIndex <= 9; typeIndex++)
- {
- if(!AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots))
- {
- return false;
- }
- slots++;
- }
-
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = _gunIndex;
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount = _acgunIndex;
- PRINTF_FUNC("Charger Count => DC-Count = %d, AC-Count = %d \n",
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount);
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0 &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0)
- result = false;
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- {
- 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)
- {
- 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)
- {
- chargingInfo[0]->Evboard_id = 0x01;
- CheckHwSlotStatusLog(0);
- }
- else
- {
- PRINTF_FUNC("HW Conn, Flag1 = %d, Flag2 = %d \n", bd0_1_status, bd0_2_status);
- PRINTF_FUNC("HW Conn, Flag1 = %d, Flag2 = %d \n", bd1_1_status, bd1_2_status);
- result = false;
- }
- }
- else
- {
- char type = NO_DEFINE;
-
- for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
- {
- if (gunIndex == 0 && bd0_1_status == 0 && bd0_2_status == 1)
- {
- PRINTF_FUNC("HW Conn %d (Chademo) \n", gunIndex);
-
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- }
- else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 0)
- {
- PRINTF_FUNC("HW Conn %d (CCS) \n", gunIndex);
-
- if (chargingInfo[gunIndex]->Type == _Type_CCS)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- }
- else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 1)
- {
- PRINTF_FUNC("HW Conn %d (GB) \n", gunIndex);
-
- if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- }
- else if (gunIndex == 0)
- {
- PRINTF_FUNC("HW Conn fail, Gun_%d, Flag1 = %d, Flag2 = %d \n",
- gunIndex, bd0_1_status, bd0_2_status);
- }
- if (gunIndex == 1 && bd1_1_status == 0 && bd1_2_status == 1)
- {
- PRINTF_FUNC("HW Conn %d (Chademo) \n", gunIndex);
-
- 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)
- {
- PRINTF_FUNC("HW Conn %d (CCS) \n", gunIndex);
-
- if (chargingInfo[gunIndex]->Type == _Type_CCS)
- {
- 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)
- {
- PRINTF_FUNC("HW Conn %d (GB) \n", gunIndex);
-
- if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x02;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- else if (gunIndex == 1)
- {
- PRINTF_FUNC("HW Conn fail, Gun_%d, Flag1 = %d, Flag2 = %d \n",
- gunIndex, bd1_1_status, bd1_2_status);
- }
- CheckHwSlotStatusLog(gunIndex);
- if (type == NO_DEFINE)
- type = chargingInfo[gunIndex]->Type;
- else
- {
-
- if (type == chargingInfo[gunIndex]->Type)
- ShmDcCommonData->SysGunAreSameType = YES;
- }
- if (chargingInfo[gunIndex]->Evboard_id == 0x00)
- result = false;
- }
- }
- }
- else
- {
-
- result = false;
- }
- return result;
- }
- void KillTask()
- {
- ChangeLcmByIndex(_LCM_FIX);
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_InternalComm");
- system("killall Module_PsuComm");
- system("killall Module_Module_SmartBox");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- system("killall Module_Payment_Bazel8 &");
- }
- void KillTaskExceptDetectTask()
- {
- ChangeLcmByIndex(_LCM_FIX);
- sleep(3);
- system("killall Module_EvComm");
-
- system("killall Module_PsuComm");
- system("killall Module_Module_SmartBox");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- system("killall Module_Payment_Bazel8 &");
- }
- 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");
- system("killall Module_PsuComm");
- system("killall Module_Module_SmartBox");
- system("killall OcppBackend &");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- system("killall Module_DcMeter &");
- system("killall Module_Payment_Bazel8 &");
- }
- bool CreateBufferForLcmFile(char *file)
- {
- bool result = FAIL;
- unsigned char *ptr = NULL;
- long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
- int fd, fd_lcm;
- int wrd_lcm;
- char Buf_lcm[128] = "/mnt/BUFFER.zip";
- fd = open ( file, O_RDONLY );
- if (fd < 0)
- {
- close ( fd );
- return result;
- }
- ptr = malloc(MaxLen);
- ImageLen = read(fd, ptr, MaxLen);
- fd_lcm = open ( Buf_lcm, O_RDWR | O_CREAT | O_EXCL );
- if (fd_lcm < 0)
- {
- PRINTF_FUNC ( "Can not create %s \n", Buf_lcm );
- }
- else
- {
- PRINTF_FUNC ( "Writing data to %s file.... \n", Buf_lcm );
- wrd_lcm = write ( fd_lcm, ptr + 48, ImageLen - 48 );
- close ( fd_lcm );
- PRINTF_FUNC ( ">> %s Written length : 0x%x \n", Buf_lcm, wrd_lcm );
- if (wrd_lcm != (ImageLen - 48))
- {
- result = FAIL;
- }
- else
- {
- result = PASS;
- }
- close(fd);
- free(ptr);
- }
- return result;
- }
- void LogUpgradeType(unsigned int type)
- {
- switch (type)
- {
- case _UPDATE_TYPE_CSU_UBOOT: PRINTF_FUNC("CSU bootloader (uboot) \n"); break;
- case _UPDATE_TYPE_CSU_DTB: PRINTF_FUNC("CSU kernel configuration (dtb) \n"); break;
- case _UPDATE_TYPE_CSU_ZIMAGE: PRINTF_FUNC("CSU kernel image (zImage) \n"); break;
- case _UPDATE_TYPE_CSU_RFILES: PRINTF_FUNC("CSU root file system (ramdisk.gz) \n"); break;
- case _UPDATE_TYPE_CSU_CONFIG: PRINTF_FUNC("CSU user configuration (bin) \n"); break;
- case _UPDATE_TYPE_CCS_UBOOT: PRINTF_FUNC("CCS board bootloader (uboot) \n"); break;
- case _UPDATE_TYPE_CCS_DTB: PRINTF_FUNC("CCS board kernel configuration (dtb) \n"); break;
- case _UPDATE_TYPE_CCS_ZIMAGE: PRINTF_FUNC("CCS board kernel image (zImage) \n"); break;
- case _UPDATE_TYPE_CCS_RFILES: PRINTF_FUNC("CCS board file system (ramdisk.gz) \n"); break;
- case _UPDATE_TYPE_DCM_ST407: PRINTF_FUNC("DCM 407 primary controller \n"); break;
- case _UPDATE_TYPE_RELAY_CTR: PRINTF_FUNC("Relay control board \n"); break;
- case _UPDATE_TYPE_FAN_CTR: PRINTF_FUNC("Fan control board \n"); break;
- case _UPDATE_TYPE_AC_WLMOUNT_CTR: PRINTF_FUNC("AC wall-mount (low-end) controller \n"); break;
- case _UPDATE_TYPE_LED_CTR: PRINTF_FUNC("LED control board \n"); break;
- case _UPDATE_TYPE_CHADEMO: PRINTF_FUNC("CAHdeMO board \n"); break;
- case _UPDATE_TYPE_GBT: PRINTF_FUNC("GBT board \n"); break;
- case _UPDATE_TYPE_DWIN_LCM: PRINTF_FUNC("LCM Module \n"); break;
- }
- }
- int CheckUpdateProcess(void)
- {
-
- uint8_t retSucc = 0;
- uint8_t retFail = 0;
- byte index = 0;
- byte target = 0;
- char new_str[256];
- 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;
- byte result = PASS;
- char Buf[256];
- d = opendir("/mnt/");
- if (d)
- {
- while ((dir = readdir(d)) != NULL)
- {
- if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0)
- {
- continue;
- }
- memset(new_str, 0x00, sizeof(new_str));
- strcat(new_str, "/mnt/");
- strcat(new_str, dir->d_name);
- PRINTF_FUNC("%s \n", new_str);
- fd = open(new_str, O_RDONLY);
- if (fd < 0)
- {
- close(fd);
- result = FAIL;
- sleep(1);
- continue;
- }
- ptr = malloc(MaxLen);
-
-
- ImageLen = read(fd, ptr, MaxLen);
- bool isModelNameFail = false;
-
- if((ShmSysConfigAndInfo->SysConfig.ModelName[0] != ptr[0]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[1] != ptr[1]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[7] != ptr[7]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[8] != ptr[8]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[9] != ptr[9]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[11] != ptr[11]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[12] != ptr[12]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[13] != ptr[13]))
- {
- result = MODELNAME_FAIL;
- isModelNameFail = true;
- }
- if (isModelNameFail)
- {
- close(fd);
- continue;
- }
- 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]));
- LogUpgradeType(Type);
- PRINTF_FUNC("Upgrade Status : PASS : %d, FAIL : %d \n", retSucc, retFail);
- free(ptr);
- switch (Type)
- {
- case _UPDATE_TYPE_CSU_UBOOT:
- case _UPDATE_TYPE_CSU_DTB:
- case _UPDATE_TYPE_CSU_ZIMAGE:
- case _UPDATE_TYPE_CSU_RFILES:
- case _UPDATE_TYPE_CSU_CONFIG:
- {
- system("echo 3 > /proc/sys/vm/drop_caches");
- sleep(2);
- if (Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
- retSucc++;
- else
- {
- PRINTF_FUNC("Upgrade CSU Failed (%d) \n", Type);
- retFail++;
- }
- memset(Buf, 0, sizeof(Buf));
- sprintf(Buf, "rm -rvf /mnt/%s", new_str);
- system(Buf);
- }
- break;
- case _UPDATE_TYPE_CCS_UBOOT:
- case _UPDATE_TYPE_CCS_DTB:
- case _UPDATE_TYPE_CCS_ZIMAGE:
- case _UPDATE_TYPE_CCS_RFILES:
- {
- CanFd = InitCanBus();
- if (CanFd > 0)
- {
- for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if (chargingInfo[index]->Type == _Type_CCS)
- {
- byte targetID = chargingInfo[index]->Evboard_id;
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1 &&
- ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
- {
- targetID += 1;
- }
- system("echo 3 > /proc/sys/vm/drop_caches");
- sleep(2);
- PRINTF_FUNC("Upgrade CCS Processing..target id = %d \n", targetID);
- if (Upgrade_CCS(CanFd, Type, targetID, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL)
- {
- PRINTF_FUNC("Upgrade CCS Failed \n");
- retFail++;
- }
- else
- retSucc++;
- }
- }
- close(CanFd);
- }
- memset(Buf, 0, sizeof(Buf));
- sprintf(Buf, "rm -rvf /mnt/%s", new_str);
- system(Buf);
- }
- break;
- case _UPDATE_TYPE_DCM_ST407:
- case _UPDATE_TYPE_RELAY_CTR:
- case _UPDATE_TYPE_FAN_CTR:
- case _UPDATE_TYPE_AC_WLMOUNT_CTR:
- case _UPDATE_TYPE_LED_CTR:
- {
- target = 0x00;
- if (Type == _UPDATE_TYPE_DCM_ST407) {
- target = UPGRADE_PRI;
- } else if (Type == _UPDATE_TYPE_RELAY_CTR) {
- target = UPGRADE_RB;
- } else if (Type == _UPDATE_TYPE_FAN_CTR) {
- target = UPGRADE_FAN;
- } else if (Type == _UPDATE_TYPE_AC_WLMOUNT_CTR) {
- target = UPGRADE_AC;
- } else if (Type == _UPDATE_TYPE_LED_CTR) {
- target = UPGRADE_LED;
- }
- uartFd = InitComPort(target);
- if (Upgrade_UART(uartFd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
- {
- retSucc++;
- }
- else
- {
- PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
- retFail++;
- }
- if (uartFd > 0)
- {
- close(uartFd);
- }
- memset(Buf, 0, sizeof(Buf));
- sprintf(Buf, "rm -rvf /mnt/%s", new_str);
- system(Buf);
- }
- break;
- case _UPDATE_TYPE_CHADEMO:
- case _UPDATE_TYPE_GBT:
- {
- CanFd = InitCanBus();
- if (CanFd > 0)
- {
- for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if ((Type == _UPDATE_TYPE_CHADEMO && chargingInfo[index]->Type == _Type_Chademo) ||
- (Type == _UPDATE_TYPE_GBT && chargingInfo[index]->Type == _Type_GB))
- {
- PRINTF_FUNC("Upgrade GBT / Chademo Processing..target id = %d \n", chargingInfo[index]->Evboard_id);
- if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
- retSucc++;
- else
- {
- if (chargingInfo[index]->Type == _Type_Chademo)
- PRINTF_FUNC("Upgrade Chademo Failed \n");
- else
- PRINTF_FUNC("Upgrade GBT Failed \n");
- retFail++;
- }
- }
- }
- close(CanFd);
- }
- memset(Buf, 0, sizeof(Buf));
- sprintf(Buf, "rm -rvf /mnt/%s", new_str);
- system(Buf);
- }
- break;
- case _UPDATE_TYPE_DWIN_LCM:
- {
- if (CreateBufferForLcmFile(new_str))
- {
- runShellCmd ( "mkdir -p /mnt/lcd" );
- runShellCmd ( "unzip /mnt/BUFFER.zip -d /mnt/lcd" );
- PRINTF_FUNC ( "Start upgrade LCM files. \n" );
- ShmDcCommonData->_upgrade_lcm_flag = YES;
- while (ShmDcCommonData->_upgrade_lcm_result == _LCM_UPGRADE_RESULT_WAIT)
- {
- sleep (5);
- }
- if (ShmDcCommonData->_upgrade_lcm_result == _LCM_UPGRADE_RESULT_PASS)
- retSucc ++;
- else
- retFail ++;
- }
- }
- break;
- }
- }
- close(fd);
- }
- }
- closedir(d);
- PRINTF_FUNC("Upgrade Result : PASS : %d, FAIL : %d \n", retSucc, retFail);
- sleep(1);
- system("rm -rvf /mnt/* ");
- if (retFail != 0)
- {
- result = FAIL;
- }
- return result;
- }
- void CreateRfidFork()
- {
- pid_t rfidRecPid;
- rfidRecPid = fork();
- if (rfidRecPid == 0)
- {
- int module_type = MODULE_EWT;
- while(true)
- {
-
- RFID rfid;
- if (!ShmSysConfigAndInfo->SysConfig.isRFID ||
- _verifyMechanism != VERIFY_MECHANISM_RFID)
- {}
- else if(getRequestCardSN(rfidFd, module_type, &rfid))
- {
-
- if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0)
- {
- 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[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_8BYTE :
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%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]);
- 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_LITTLE)
- {
- 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_8BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X%02X",
- 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_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;
- }
- }
- PRINTF_FUNC("RFID : Get card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
- }
- if (rfid.cardType == ISO14443A)
- sethaltCard ( rfidFd, module_type);
- else if (rfid.cardType == IS014443B)
- { }
- else if (rfid.cardType == FELICA)
- { }
- }
- sleep(1);
- }
- }
- }
- void CreateCheckSystemTaskFork()
- {
- pid_t taskPid;
- taskPid = fork();
- if (taskPid == 0)
- {
- bool stopToDet = false;
- while(true)
- {
- if (!stopToDet)
- {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus == SYS_MODE_UPDATE ||
- chargingInfo[_index]->Type == 0x09)
- {
- stopToDet = true;
- continue;
- }
- }
- if (!stopToDet)
- CheckSystemTaskAlive();
- }
- sleep(5);
- }
- }
- }
- void StartSystemTimeoutDet(unsigned char flag)
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag)
- {
- GetTimespecFunc(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer);
- }
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
- }
- void StopSystemTimeoutDet()
- {
- GetTimespecFunc(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer);
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
- }
- void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
- {
- if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
- {
- if (chargingInfo[gunIndex]->TimeoutFlag != flag)
- {
- GetTimespecFunc(&chargingInfo[gunIndex]->ConnectorTimeout);
- }
- chargingInfo[gunIndex]->TimeoutFlag = flag;
- }
- }
- void StopGunInfoTimeoutDet(unsigned char gunIndex)
- {
- if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
- {
- chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
- }
- }
- void CheckConnectionTimeout()
- {
- if(system("pidof -s OcppBackend > /dev/null") != 0)
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- else
- {
- _connectionTimeout = _ocpp_get_connect_timeout();
- if(_connectionTimeout <= 0)
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- }
- }
- void GetOfflinePowerValue()
- {
- int value = atoi((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
- if (ShmDcCommonData->_offlinePower != value)
- {
- ShmDcCommonData->_offlinePower = value;
- PRINTF_FUNC("OCPP offline .. Read OfflinePower = %d \n", ShmDcCommonData->_offlinePower);
- }
- }
- void CreateTimeoutFork()
- {
- pid_t timeoutPid;
- timeoutPid = fork();
- if (timeoutPid > 0)
- {
- GetTimespecFunc(&_cmdSubPriority_time);
- CheckConnectionTimeout();
- int _timebuf = 0;
- while(true)
- {
- _timebuf = GetTimeoutValue(&_cmdSubPriority_time);
- if (_timebuf < 0)
- {
- GetTimespecFunc(&_cmdSubPriority_time);
- }
- else
- {
- if (_timebuf >= 5)
- {
- CheckConnectionTimeout();
-
- GetOfflinePowerValue();
- GetTimespecFunc(&_cmdSubPriority_time);
- }
- }
-
-
- if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_None)
- {
- _timebuf = GetTimeoutValue(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer);
- if (_timebuf < 0)
- {
- GetTimespecFunc(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer);
- }
- else
- {
- switch(ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag)
- {
- case Timeout_SelftestChk:
- if (_timebuf >= SELFTEST_TIMEOUT)
- {
- _SelfTestTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_Authorizing:
- if (_timebuf >= AUTHORIZE_TIMEOUT)
- {
- _AuthorizedTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_VerifyFail:
- if (_timebuf >= AUTHORIZE_FAIL_TIMEOUT)
- {
- _AutoReturnTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_VerifyComp:
- if (_timebuf >= AUTHORIZE_COMP_TIMEOUT)
- {
- _AutoReturnTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_WaitPlug:
- if (_timebuf >= _connectionTimeout)
- {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_ReturnToChargingGunDet:
- {
- if (_timebuf >= RETURN_TO_CHARGING_PAGE)
- {
- DisplayChargingInfo();
- StopSystemTimeoutDet();
- }
- }
- break;
-
-
-
-
-
-
-
-
-
-
- }
- }
- }
-
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- if (chargingInfo[gun_index]->TimeoutFlag != Timeout_None)
- {
- _timebuf = GetTimeoutValue(&chargingInfo[gun_index]->ConnectorTimeout);
- if (_timebuf < 0)
- {
- GetTimespecFunc(&chargingInfo[gun_index]->ConnectorTimeout);
- }
- else
- {
-
- switch(chargingInfo[gun_index]->TimeoutFlag)
- {
- case Timeout_Preparing:
- {
- if (_timebuf >= GUN_PREPARE_TIMEOUT)
- {
- _PrepareTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- case Timeout_EvChargingDet:
- {
- if (_timebuf >= GUN_EV_WAIT_TIMEOUT)
- {
- _DetectEvChargingEnableTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- case Timeout_EvseChargingDet:
- {
- if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- if (_timebuf >= GUN_EVSE_WAIT_TIMEOUT * 3)
- {
- _DetectEvseChargingEnableTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- else
- {
- if (_timebuf >= GUN_EVSE_WAIT_TIMEOUT)
- {
- _DetectEvseChargingEnableTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- }
- break;
- case Timeout_EvseCompleteDet:
- {
- if (_timebuf >= GUN_COMP_WAIT_TIMEOUT)
- {
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- case Timeout_ForCcsPrechargeDet:
- {
- if (_timebuf >= GUN_PRECHARGING_TIMEOUT)
- {
- _CcsPrechargeTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- }
- }
- }
- }
- 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);
- }
- void CheckFactoryConfigFunction()
- {
- if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
- {
- char Buf[256];
- sleep(5);
- 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()
- {
-
- if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
- {
- DEBUG_INFO_MSG("ftp : update start. \n");
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- SetChargerMode(gun_index, SYS_MODE_UPDATE);
- }
- CloseWatchDog();
- sleep(2);
- KillTask();
- byte updateResult = CheckUpdateProcess();
- if (updateResult == PASS)
- DEBUG_INFO_MSG("ftp : update complete. \n");
- else if (updateResult == MODELNAME_FAIL)
- {
- DEBUG_INFO_MSG("ftp : model name is none match. \n");
- KillAllTask();
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
- sleep(5);
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- else
- DEBUG_INFO_MSG("ftp : update fail. \n");
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
- sleep(5);
- system("reboot -f");
- }
- else
- {
- ocpp_chk_update_cmd();
- }
- }
- int TariffParsing(char *StringItem, char *TariffCode)
- {
- char *ptrSave, *ptrToken;
- char strSource[128];
- int fee = 0;
- memcpy(strSource, StringItem, 128);
- ptrToken = strtok_r(strSource, ";", &ptrSave);
- while(ptrToken != NULL)
- {
- char *strTariff = strstr(ptrToken, TariffCode);
- if(strTariff != NULL)
- {
- char *strFee = strstr(strTariff, "$");
- if(strFee != NULL)
- {
- strFee++;
- float fFee = atof(strFee);
- fee = (int)(fFee * 100);
- break;
- }
- }
- ptrToken = strtok_r(NULL, ";", &ptrSave);
- }
- return fee;
- }
- void DefaultPriceHandlerOcpp16(char *StrDefaultPrice)
- {
- if (strstr(StrDefaultPrice, "Connection Fee") != NULL)
- {
- ShmDcCommonData->_useVersion = _CDFA_VERSION_NOODOE;
-
- unsigned int connectionFee = 0, currentRate = 0, occupancyFee = 0;
- connectionFee = TariffParsing(StrDefaultPrice, "Connection Fee");
- currentRate = TariffParsing(StrDefaultPrice, "Current Rate");
- occupancyFee = TariffParsing(StrDefaultPrice, "Occupancy Fee");
- PRINTF_FUNC("*** Connection Fee: %d.%02d ***", (connectionFee / 100), (connectionFee % 100));
- PRINTF_FUNC("*** Current Rate: %d.%02d ***", (currentRate / 100), (currentRate % 100));
- PRINTF_FUNC("*** Occupancy Fee: %d.%02d ***", (occupancyFee / 100), (occupancyFee % 100));
- ShmDcCommonData->balanceInfo.defaultPrice_Noodoe = currentRate;
- }
- else
- {
-
- ShmDcCommonData->_useVersion = _CDFA_VERSION_10;
- PRINTF_FUNC("*********DefaultPriceHandlerOcpp16**************** - %s \n", StrDefaultPrice);
- sprintf(ShmDcCommonData->balanceInfo.defaultPrice, "%s", StrDefaultPrice);
- }
- }
- void UserPriceHandlerOcpp16(char *UserId, char *UserPrice)
- {
- unsigned int connectionFee = 0, currentRate = 0, occupancyFee = 0;
- int accountBalance = 0;
- byte acGunIndex = 0;
- for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
- {
- if((chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
- chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CHARGING) &&
- strcmp((char *)chargingInfo[gunIndex]->StartUserId, UserId) == EQUAL)
- {
- if (strstr(UserPrice, "Connection Fee") != NULL)
- {
-
- connectionFee = TariffParsing(UserPrice, "Connection Fee");
- currentRate = TariffParsing(UserPrice, "Current Rate");
- occupancyFee = TariffParsing(UserPrice, "Occupancy Fee");
- accountBalance = TariffParsing(UserPrice, "Account Balance");
- if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex].UserPrice != currentRate ||
- ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex].AccountBalance != accountBalance)
- {
- PRINTF_FUNC("*** Connection Fee: %d.%02d ***", (connectionFee / 100), (connectionFee % 100));
- PRINTF_FUNC("*** Current Rate: %d.%02d ***", (currentRate / 100), (currentRate % 100));
- PRINTF_FUNC("*** Occupancy Fee: %d.%02d ***", (occupancyFee / 100), (occupancyFee % 100));
- PRINTF_FUNC("*** Account Balance: %d.%02d ***", (accountBalance / 100), (accountBalance % 100));
- PRINTF_FUNC("*** Connector Id %d User Price %d.%02d, Account Balance %d.%02d ***",
- (gunIndex), (currentRate / 100), (currentRate % 100), (accountBalance / 100), (accountBalance % 100));
- }
- ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex].UserPrice = currentRate;
- ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex].AccountBalance = accountBalance;
- }
- else
- {
-
-
- }
- }
- }
- for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; gunIndex++)
- {
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0)
- acGunIndex = 1;
- else
- acGunIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- acGunIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(strcmp((char *)ac_chargingInfo[gunIndex]->StartUserId, UserId) == EQUAL)
- {
- if (strstr(UserPrice, "Connection Fee") != NULL)
- {
- if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[acGunIndex].UserPrice != currentRate ||
- ShmDcCommonData->balanceInfo.connectorBalanceInfo[acGunIndex].AccountBalance != accountBalance)
- {
- PRINTF_FUNC("*** AC Connector User Price %d.%02d, Account Balance %d.%02d ***",
- (currentRate / 100), (currentRate % 100), (accountBalance / 100), (accountBalance % 100));
- }
- ShmDcCommonData->balanceInfo.connectorBalanceInfo[acGunIndex].UserPrice = currentRate;
- ShmDcCommonData->balanceInfo.connectorBalanceInfo[acGunIndex].AccountBalance = accountBalance;
- }
- }
- }
- }
- void ExtractNoodoeInfor(byte gunIndex, byte connectionFee, byte sessionFee, byte occupancyFee, byte totalCost, int accountBalance)
- {
- PRINTF_FUNC("*** Connection Fee: %d.%02d *** \n", (connectionFee / 100), (connectionFee % 100));
- PRINTF_FUNC("*** Session Fee: %d.%02d *** \n", (sessionFee / 100), (sessionFee % 100));
- PRINTF_FUNC("*** Occupancy Fee: %d.%02d *** \n", (occupancyFee / 100), (occupancyFee % 100));
- PRINTF_FUNC("*** Total Cost: %d.%02d *** \n", (totalCost / 100), (totalCost % 100));
- PRINTF_FUNC("*** Account Balance: %d.%02d *** \n", (accountBalance / 100), (accountBalance % 100));
- if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex].TotalCost != totalCost ||
- ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex].AccountBalance != accountBalance)
- {
- PRINTF_FUNC("*** Connector Id %d Total Cost %d.%02d, Account Balance %d.%02d *** \n",
- (gunIndex), (totalCost / 100), (totalCost % 100), (accountBalance / 100), (accountBalance % 100));
- }
- ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex].TotalCost = totalCost;
- ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex].AccountBalance = accountBalance;
- }
- void ExtractCtep10Infor(byte gunIndex, json_object **jsonDescription)
- {
- if (json_object_object_get ( *jsonDescription, "chargingFee" ) != NULL)
- {
- ShmDcCommonData->cdfaInfor[gunIndex]._ctepEnergyCost = json_object_get_double
- (json_object_object_get ( *jsonDescription, "chargingFee" ) );
- }
- if (json_object_object_get ( *jsonDescription, "parkingFee" ) != NULL)
- {
- ShmDcCommonData->cdfaInfor[gunIndex]._ctepParkingFee = json_object_get_double
- (json_object_object_get ( *jsonDescription, "parkingFee" ) );
- }
- if ((ShmDcCommonData->cdfaInfor[gunIndex]._ctepEnergyCost + ShmDcCommonData->cdfaInfor[gunIndex]._ctepParkingFee) > 0)
- ShmDcCommonData->cdfaInfor[gunIndex]._ctepTotalCost = ShmDcCommonData->cdfaInfor[gunIndex]._ctepEnergyCost + ShmDcCommonData->cdfaInfor[gunIndex]._ctepParkingFee;
- else
- ShmDcCommonData->cdfaInfor[gunIndex]._ctepTotalCost = 0;
- PRINTF_FUNC("Energy Cost = %f \n", ShmDcCommonData->cdfaInfor[gunIndex]._ctepEnergyCost);
- PRINTF_FUNC("Parking Fee = %f \n", ShmDcCommonData->cdfaInfor[gunIndex]._ctepParkingFee);
- PRINTF_FUNC("Total Cost = %f \n", ShmDcCommonData->cdfaInfor[gunIndex]._ctepTotalCost);
- }
- void ExtractCtep20Infor(byte gunIndex)
- {
-
- ShmDcCommonData->cdfaInfor[gunIndex]._ctepEnergyCost = ShmDcCommonData->cdfaInfor[gunIndex]._preEnergyCost +
- ((chargingInfo[gunIndex]->PresentChargedEnergy - ShmDcCommonData->cdfaInfor[gunIndex]._preOutputEnergy) * ShmDcCommonData->cdfaInfor[gunIndex]._prekWhPrice);
-
-
- float elapsedTime = (float)ElapsedTime(ShmDcCommonData->cdfaInfor[gunIndex]._preTimestamp) / 3600;
- ShmDcCommonData->cdfaInfor[gunIndex]._ctepParkingFee = ShmDcCommonData->cdfaInfor[gunIndex]._preParkingFee +
- (elapsedTime * ShmDcCommonData->cdfaInfor[gunIndex]._prehourPrice);
-
- ShmDcCommonData->cdfaInfor[gunIndex]._ctepTotalCost =
- ShmDcCommonData->cdfaInfor[gunIndex]._ctepEnergyCost +
- ShmDcCommonData->cdfaInfor[gunIndex]._ctepParkingFee +
- ShmOCPP16Data->Cost.RunningCost[gunIndex].chargingPrice.flatFee;
- }
- void RunningFinalCostHandlerOcpp16()
- {
- unsigned int connectionFee = 0, sessionFee = 0, occupancyFee = 0, totalCost = 0;
- int accountBalance = 0;
- byte acGunIndex = 0;
- json_object *jsonDescription;
- bool isFind;
- for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
- {
- isFind = false;
- if (gunIndex == 1)
- acGunIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- else
- acGunIndex = 0;
- if (chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE &&
- chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_ALARM)
- {
- if(ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].txId != 0 &&
- ShmOCPP16Data->StartTransaction[gunIndex + acGunIndex].ResponseTransactionId == ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].txId)
- {
- if(strlen((char *)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].description) > 0)
- {
- if (strstr((char *)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].description, "Connection Fee") != NULL)
- {
- ShmDcCommonData->_useVersion = _CDFA_VERSION_NOODOE;
- connectionFee = TariffParsing ((char *) ShmOCPP16Data->Cost.RunningCost [gunIndex + acGunIndex].description, "Connection Fee" );
- sessionFee = TariffParsing ((char *) ShmOCPP16Data->Cost.RunningCost [gunIndex + acGunIndex].description, "Session Fee" );
- occupancyFee = TariffParsing ((char *) ShmOCPP16Data->Cost.RunningCost [gunIndex + acGunIndex].description, "Occupancy Fee" );
- totalCost = TariffParsing ((char *) ShmOCPP16Data->Cost.RunningCost [gunIndex + acGunIndex].description, "Total Cost" );
- accountBalance = TariffParsing ((char *) ShmOCPP16Data->Cost.RunningCost [gunIndex + acGunIndex].description, "Account Balance" );
- PRINTF_FUNC ( "*** Connector Id: %d Running Cost *** \n", gunIndex );
- memset (&ShmOCPP16Data->Cost.RunningCost [gunIndex + acGunIndex], 0x00, sizeof(struct StrcutRunningCost) );
- isFind = true;
- }
- else
- {
-
-
-
- ShmDcCommonData->_useVersion = _CDFA_VERSION_10;
- PRINTF_FUNC("*** (CDFA 1.0) Connector Id: %d Running Cost *** \n", gunIndex + acGunIndex);
- jsonDescription = json_tokener_parse(
- (char*)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].description);
- isFind = true;
- }
- }
- else
- {
-
-
-
- ShmDcCommonData->_useVersion = _CDFA_VERSION_20;
- if (strcmp((char*)ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preTimestamp,
- (char*)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].timestamp) != EQUAL &&
- strcmp((char*)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].timestamp, "") != EQUAL)
- {
-
- if ((float)ElapsedTime(ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].timestamp) > 0)
- {
-
- strcpy((char*)ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preTimestamp, (char*)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].timestamp);
- ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preOutputEnergy = chargingInfo[gunIndex]->PresentChargedEnergy;
- ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._prekWhPrice = ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].chargingPrice.kWhPrice;
- ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._prehourPrice = ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].chargingPrice.hourPrice;
- ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preEnergyCost = ShmDcCommonData->cdfaInfor[gunIndex]._ctepEnergyCost;
- ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preParkingFee = ShmDcCommonData->cdfaInfor[gunIndex]._ctepParkingFee;
- PRINTF_FUNC("***************** (CDFA 2.0) RunningCost**************** \n");
- PRINTF_FUNC("cost = %f \n", ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].cost);
- PRINTF_FUNC("flatFee = %f \n", ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].chargingPrice.flatFee);
- PRINTF_FUNC("_ctepEnergyCost = %f \n", ShmDcCommonData->cdfaInfor[gunIndex]._ctepEnergyCost);
- PRINTF_FUNC("******************************************** \n");
- if (ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].cost > ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].chargingPrice.flatFee)
- {
- if ((ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].cost - ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].chargingPrice.flatFee) >=
- ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._ctepEnergyCost)
- {
- ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preParkingFee = ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].cost -
- ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].chargingPrice.flatFee - ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._ctepEnergyCost;
- }
- }
- }
- isFind = true;
- }
- else if (strcmp((char*)ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preTimestamp, "") != EQUAL)
- { isFind = true; }
- }
- }
- if((chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_TERMINATING && chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_ALARM) &&
- ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].txId != 0 &&
- ShmOCPP16Data->StartTransaction[gunIndex + acGunIndex].ResponseTransactionId == ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].txId)
- {
- if(strlen((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description) > 0)
- {
- if (strstr((char *)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].description, "Connection Fee") != NULL)
- {
- ShmDcCommonData->_useVersion = _CDFA_VERSION_NOODOE;
- connectionFee = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description, "Connection Fee");
- sessionFee = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description, "Session Fee");
- occupancyFee = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description, "Occupancy Fee");
- totalCost = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description, "Total Cost");
- accountBalance = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description, "Account Balance");
- PRINTF_FUNC("********** Connector Id: %d Final Cost ********** \n", gunIndex);
- memset(&ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex], 0x00, sizeof(struct StrcutFinalCost));
- isFind = true;
- }
- else
- {
-
-
-
- ShmDcCommonData->_useVersion = _CDFA_VERSION_10;
- PRINTF_FUNC("********** (CDFA 1.0) Connector Id: %d Final Cost ********** \n", gunIndex);
- jsonDescription = json_tokener_parse(
- (char*)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description);
- isFind = true;
- }
- }
- else
- {
-
-
-
- if (strcmp((char*)ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preQrCodeText, "") == EQUAL &&
- strcmp((char*)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].priceText, "") != EQUAL &&
- strcmp((char*)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].qrCodeText, "") != EQUAL)
- {
- PRINTF_FUNC("***************** (CDFA 2.0) FinalCost**************** \n");
- ShmDcCommonData->_useVersion = _CDFA_VERSION_20;
- strcpy((char*)ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preQrCodeText,
- (char*)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].qrCodeText);
- ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._ctepTotalCost = ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].cost;
- if ((ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].cost - ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._ctepEnergyCost) >= 0)
- {
- ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preParkingFee = ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].cost - ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._ctepEnergyCost;
- }
- else
- {
- ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._ctepEnergyCost = ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._ctepTotalCost;
- ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preParkingFee = 0;
- }
- }
- }
- }
- if (isFind)
- {
- if (ShmDcCommonData->_useVersion == _CDFA_VERSION_NOODOE)
- {
- ExtractNoodoeInfor(gunIndex + acGunIndex, connectionFee, sessionFee, occupancyFee, totalCost, accountBalance);
- }
- else if (ShmDcCommonData->_useVersion == _CDFA_VERSION_10)
- {
- ExtractCtep10Infor(gunIndex + acGunIndex, &jsonDescription);
- json_object_put (jsonDescription);
- }
- else if (ShmDcCommonData->_useVersion == _CDFA_VERSION_20)
- {
- if (strcmp((char*)ShmDcCommonData->cdfaInfor[gunIndex + acGunIndex]._preTimestamp, "") != EQUAL)
- ExtractCtep20Infor(gunIndex + acGunIndex);
- }
- }
- }
- }
- }
- bool ocpp_authorizeRemoteTxReqChk_key()
- {
- bool result = false;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE"))
- result = true;
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return result;
- }
- int opcc_chk_reserve_expired(byte gun_index)
- {
- int result = NO;
- byte acDirIndex = 0;
- if (gun_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(chargingInfo[gun_index]->SystemStatus != SYS_MODE_RESERVATION)
- PRINTF_FUNC("%s \n", ShmOCPP16Data->ReserveNow[gun_index + acDirIndex].ExpiryDate);
- if (CheckTimeOut(ShmOCPP16Data->ReserveNow[gun_index + acDirIndex].ExpiryDate))
- result = YES;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(chargingInfo[gun_index]->SystemStatus != SYS_MODE_RESERVATION)
- PRINTF_FUNC("%s \n", ShmOCPP20Data->ReserveNow[gun_index + acDirIndex].expiryDateTime);
- if (CheckTimeOut(ShmOCPP20Data->ReserveNow[gun_index + acDirIndex].expiryDateTime))
- result = YES;
- }
- return result;
- }
- void ocpp_ac_chk_availability_cmd()
- {
- byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
- byte type = 0;
-
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CsMsg.bits[hasDc].ChangeAvailabilityReq == YES)
- {
- PRINTF_FUNC("***************ChkOcppStatus : AC OcppChangeAvailability******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : AC OcppChangeAvailability******************** \n");
- ShmOCPP16Data->CsMsg.bits[hasDc].ChangeAvailabilityReq = NO;
- if(strcmp((char *)ShmOCPP16Data->ChangeAvailability[hasDc].Type, "Operative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, hasDc, true);
- type = 1;
- }
- else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[hasDc].Type, "Inoperative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, hasDc, false);
- type = 2;
- }
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CsMsg.bits[hasDc].ChangeAvailabilityReq == YES)
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- ShmOCPP20Data->CsMsg.bits[hasDc].ChangeAvailabilityReq = NO;
- if(strcmp((char *)ShmOCPP20Data->ChangeAvailability[hasDc].operationalStatus, "Operative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, hasDc, true);
- type = 1;
- }
- else if (strcmp((char *)ShmOCPP20Data->ChangeAvailability[hasDc].operationalStatus, "Inoperative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, hasDc, false);
- type = 2;
- }
- }
- }
- if (type == 1)
- {
- ac_chargingInfo[0]->IsAvailable = YES;
- }
- else if (type == 2)
- {
- ac_chargingInfo[0]->IsAvailable = NO;
- }
- }
- void ocpp_ac_chk_unlock_cmd()
- {
- byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
-
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CsMsg.bits[hasDc].UnlockConnectorReq == YES)
- {
- ShmOCPP16Data->CsMsg.bits[hasDc].UnlockConnectorReq = NO;
- if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
- ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING)
- {
-
- strcpy((char *)ShmOCPP16Data->StopTransaction[hasDc].StopReason, "UnlockCommand");
- ac_chargingInfo[0]->StopChargeFlag = YES;
- }
- strcpy((char *)ShmOCPP16Data->UnlockConnector[hasDc].ResponseStatus, "Unlocked");
- ShmOCPP16Data->CsMsg.bits[hasDc].UnlockConnectorConf = YES;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CsMsg.bits[hasDc].UnlockConnectorReq == YES)
- {
- ShmOCPP20Data->CsMsg.bits[hasDc].UnlockConnectorReq = NO;
- if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
- ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING)
- {
-
- strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].transactionInfo.stoppedReason, "UnlockCommand");
- ac_chargingInfo[0]->StopChargeFlag = YES;
- }
- strcpy((char*)ShmOCPP20Data->UnlockConnector[hasDc].Response_status, "Unlocked");
- ShmOCPP20Data->CsMsg.bits[hasDc].UnlockConnectorConf = YES;
- }
- }
- }
- void ocpp_ac_chk_profileConf_cmd()
- {
- byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CSUMsg.bits[hasDc].ChargingProfileConf == YES)
- {
- ShmOCPP16Data->CSUMsg.bits[hasDc].ChargingProfileConf = NO;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CSUMsg.bits[hasDc].ChargingProfileConf == YES)
- {
- ShmOCPP20Data->CSUMsg.bits[hasDc].ChargingProfileConf = NO;
- }
- }
- }
- void ocpp_ac_chargingProfile_process()
- {
- int _time = 0;
- int _startCount = NO_DEFINE;
- int _maxCount = 0;
- byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingProfileKind, "Absolute") == EQUAL &&
- ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingProfileId == YES)
- {
- _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.StartSchedule);
- if (_time > -1)
- {
- _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod);
- _startCount = NO_DEFINE;
- for (byte _count = 0; _count < _maxCount; _count++)
- {
-
- if (_time >= ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod)
- {
- if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
- ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
- {
- _startCount = _count;
- }
- }
- }
- if (_startCount < _maxCount)
- {
-
-
- if (ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit >= 1 &&
- ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit <= 5)
- {
- ac_chargingInfo[0]->ChargingProfileCurrent = AC_MINIMUM_DUTY;
- }
- else if (ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit == 0)
- {
- ac_chargingInfo[0]->ChargingProfileCurrent = AC_STOP_DUTY;
- }
- else
- {
- ac_chargingInfo[0]->ChargingProfileCurrent = ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit;
- }
- }
- else
- {
- ac_chargingInfo[0]->ChargingProfilePower = -1;
- ac_chargingInfo[0]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- ac_chargingInfo[0]->ChargingProfilePower = -1;
- ac_chargingInfo[0]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- ac_chargingInfo[0]->ChargingProfilePower = -1;
- ac_chargingInfo[0]->ChargingProfileCurrent = -1;
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (strcmp((char *)ShmOCPP20Data->SmartChargingProfile[hasDc].chargingProfileKind, "Absolute") == EQUAL &&
- ShmOCPP20Data->SmartChargingProfile[hasDc].id == YES)
- {
- _time = GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].startSchedule);
- _maxCount = ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod);
- _startCount = NO_DEFINE;
- for (byte _count = 0; _count < _maxCount; _count++)
- {
-
- if (_time >= ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_count].startPeriod)
- {
- if ((_count == 0 && ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_count].limit >= MIN_OUTPUT_CUR) ||
- ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_count].limit > MIN_OUTPUT_CUR)
- {
- _startCount = _count;
- }
- }
- }
- if (_startCount < _maxCount)
- {
-
-
- if (ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit >= 1 &&
- ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit <= 5)
- {
- ac_chargingInfo [0]->ChargingProfileCurrent = AC_MINIMUM_DUTY;
- }
- else if (ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit == 0)
- {
- ac_chargingInfo [0]->ChargingProfileCurrent = AC_STOP_DUTY;
- }
- else
- {
- ac_chargingInfo [0]->ChargingProfileCurrent = ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit;
- }
- }
- else
- {
- ac_chargingInfo[0]->ChargingProfilePower = -1;
- ac_chargingInfo[0]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- ac_chargingInfo[0]->ChargingProfilePower = -1;
- ac_chargingInfo[0]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- ac_chargingInfo[0]->ChargingProfilePower = -1;
- ac_chargingInfo[0]->ChargingProfileCurrent = -1;
- }
- if (ac_chargingInfo[0]->ChargingProfileCurrent >= 0 &&
- _AcChargingProfileCurBuffer != ac_chargingInfo[0]->ChargingProfileCurrent)
- {
- _AcChargingProfileCurBuffer = ac_chargingInfo[0]->ChargingProfileCurrent;
- PRINTF_FUNC ( "AC Profile (duty) : ChargingProfileCurrent = %.2f \n", ac_chargingInfo[0]->ChargingProfileCurrent);
- }
- }
- void ocpp_ac_lift_profileReq_cmd(byte gunIndex)
- {
- byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CSUMsg.bits[hasDc].ChargingProfileConf == NO)
- {
- if (ShmOCPP16Data->CSUMsg.bits[hasDc].ChargingProfileReq == NO)
- ShmOCPP16Data->CSUMsg.bits[hasDc].ChargingProfileReq = YES;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CSUMsg.bits[hasDc].ChargingProfileConf == NO)
- {
- if (ShmOCPP20Data->CSUMsg.bits[hasDc].ChargingProfileReq == NO)
- ShmOCPP20Data->CSUMsg.bits[hasDc].ChargingProfileReq = YES;
- }
- }
- }
- int opcc_ac_chk_reserve_expired()
- {
- int result = NO;
- byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(ac_chargingInfo [0]->SystemStatus != SYS_MODE_RESERVATION)
- PRINTF_FUNC("%s \n", ShmOCPP16Data->ReserveNow[hasDc].ExpiryDate);
- if (CheckTimeOut(ShmOCPP16Data->ReserveNow[hasDc].ExpiryDate))
- result = YES;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(ac_chargingInfo [0]->SystemStatus != SYS_MODE_RESERVATION)
- PRINTF_FUNC("%s \n", ShmOCPP20Data->ReserveNow[hasDc].expiryDateTime);
- if (CheckTimeOut(ShmOCPP20Data->ReserveNow[hasDc].expiryDateTime))
- result = YES;
- }
- return result;
- }
- void ocpp_ac_chk_reserved_cmd()
- {
- byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
- if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ac_chargingInfo [0]->SystemStatus == SYS_MODE_IDLE &&
- ShmOCPP16Data->CsMsg.bits [hasDc].ReserveNowReq == YES)
- {
- PRINTF_FUNC ( "***************ChkOcppStatus : (AC) OcppReservedStatus******************** \n" );
- ShmOCPP16Data->CsMsg.bits [hasDc].ReserveNowReq = NO;
- if ( ! opcc_ac_chk_reserve_expired ())
- {
- PRINTF_FUNC ( "ReservationId = %d \n", ShmOCPP16Data->ReserveNow [hasDc].ReservationId );
- PRINTF_FUNC ( "IdTag = %s \n", ShmOCPP16Data->ReserveNow [hasDc].IdTag );
- PRINTF_FUNC ( "*************ChkOcppStatus : (AC) OcppReservedStatus End****************** \n" );
- ac_chargingInfo [0]->ReservationId = ShmOCPP16Data->ReserveNow [hasDc].ReservationId;
- ac_chargingInfo [0]->SystemStatus = SYS_MODE_RESERVATION;
- strcpy ( (char *) ShmDcCommonData->_reserved_ac_UserId[0],
- (char *) ShmOCPP16Data->ReserveNow [hasDc].IdTag );
- }
- ShmOCPP16Data->CsMsg.bits [hasDc].ReserveNowConf = YES;
- }
- if (ac_chargingInfo [0]->SystemStatus == SYS_MODE_RESERVATION &&
- ShmOCPP16Data->CsMsg.bits [hasDc].CancelReservationReq == YES)
- {
- ShmOCPP16Data->CsMsg.bits [hasDc].CancelReservationReq = NO;
- if (ShmOCPP16Data->ReserveNow [hasDc].ReservationId == ac_chargingInfo [0]->ReservationId)
- {
- PRINTF_FUNC ( "***************ChkOcppStatus : (AC) OcppReservedStatus******************** \n" );
- PRINTF_FUNC ( "ReservationId = %d \n", ShmOCPP16Data->ReserveNow [hasDc].ReservationId );
- PRINTF_FUNC ( "***********ChkOcppStatus : (AC) Cancel OcppReservedStatus End**************** \n" );
- ac_chargingInfo [0]->ReservationId = NO_RESERVE;
- ac_chargingInfo [0]->SystemStatus = SYS_MODE_IDLE;
- strcpy ( (char *) ShmDcCommonData->_reserved_ac_UserId[0], "" );
- ShmOCPP16Data->CsMsg.bits [hasDc].CancelReservationConf = YES;
- }
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ac_chargingInfo [0]->SystemStatus == SYS_MODE_IDLE &&
- ShmOCPP20Data->CsMsg.bits [hasDc].ReserveNowReq == YES)
- {
- PRINTF_FUNC ( "***************ChkOcppStatus : (AC) OcppReservedStatus******************** \n" );
- ShmOCPP20Data->CsMsg.bits [hasDc].ReserveNowReq = NO;
- if ( ! opcc_ac_chk_reserve_expired ())
- {
- PRINTF_FUNC ( "id = %d \n", ShmOCPP20Data->ReserveNow [hasDc].id );
- PRINTF_FUNC ( "idToken = %s \n", ShmOCPP20Data->ReserveNow [hasDc].idToken.idToken );
- PRINTF_FUNC ( "*************ChkOcppStatus : (AC) OcppReservedStatus End****************** \n" );
- ac_chargingInfo [0]->ReservationId = ShmOCPP20Data->ReserveNow [hasDc].id;
- ac_chargingInfo [0]->SystemStatus = SYS_MODE_RESERVATION;
- strncpy ( (char *) ShmDcCommonData->_reserved_UserId,
- (char *) ShmOCPP20Data->ReserveNow [hasDc].idToken.idToken, 30 );
- }
- ShmOCPP20Data->CsMsg.bits [hasDc].ReserveNowConf = YES;
- }
- if (ac_chargingInfo [0]->SystemStatus == SYS_MODE_RESERVATION &&
- ShmOCPP20Data->CsMsg.bits [hasDc].CancelReservationReq == YES)
- {
- ShmOCPP20Data->CsMsg.bits [hasDc].CancelReservationReq = NO;
- if (ShmOCPP20Data->ReserveNow [hasDc].id == ac_chargingInfo [0]->ReservationId)
- {
- PRINTF_FUNC ( "***************ChkOcppStatus : (AC) OcppReservedStatus******************** \n" );
- PRINTF_FUNC ( "ReservationId = %d \n", ShmOCPP20Data->ReserveNow [hasDc].id );
- PRINTF_FUNC ( "***********ChkOcppStatus : (AC) Cancel OcppReservedStatus End**************** \n" );
- ac_chargingInfo [0]->ReservationId = NO_RESERVE;
- ac_chargingInfo [0]->SystemStatus = SYS_MODE_IDLE;
- strcpy ( (char *) ShmDcCommonData->_reserved_UserId, "" );
- ShmOCPP20Data->CsMsg.bits [hasDc].CancelReservationConf = YES;
- }
- }
- }
- }
- void ocpp_process_start()
- {
- if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
- {
- if(system("pidof -s OcppBackend > /dev/null") != 0 &&
- system("pidof -s OcppBackend20 > /dev/null") != 0)
- {
- if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE)
- CloseWatchDog();
- DEBUG_ERROR_MSG("OcppBackend not running, restart it.\r\n");
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- system("/root/OcppBackend &");
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- system("/root/OcppBackend20 &");
- if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE)
- CreateWatchdog();
- }
- else
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if((time((time_t*)NULL) - ShmOCPP16Data->procDogTime) > 180)
- {
- DEBUG_ERROR_MSG("OcppBackend watch dog timeout task restart.\n");
- ShmOCPP16Data->procDogTime = time((time_t*)NULL);
- system("pkill OcppBackend");
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if((time((time_t*)NULL) - ShmOCPP20Data->procDogTime) > 180)
- {
- DEBUG_ERROR_MSG("OcppBackend20 watch dog timeout task restart.\n");
- ShmOCPP16Data->procDogTime = time((time_t*)NULL);
- system("pkill OcppBackend20");
- }
- }
- }
- }
- if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- if(system("pidof -s OcppBackendPH > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("OcppBackendPH not running, restart it.\r\n");
- system("/root/OcppBackendPH &");
- }
- }
- }
- void ocpp_auto_response_BootNotification()
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES)
- ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->SpMsg.bits.BootNotificationConf == YES)
- ShmOCPP20Data->SpMsg.bits.BootNotificationConf = NO;
- }
- }
- bool ocpp_is_resPass_StartTransactionConf(byte gun_index)
- {
- bool result = false;
- byte acDirIndex = 0;
-
- if (gun_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- result = ShmOCPP16Data->CpMsg.bits[gun_index + acDirIndex].StartTransactionConf;
- ShmDcCommonData->startTransactionID[gun_index] = ShmOCPP16Data->StartTransaction[gun_index + acDirIndex].ResponseTransactionId;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- result = ShmOCPP20Data->CpMsg.bits[gun_index + acDirIndex].TransactionEventConf;
- }
- return result;
- }
- void ocpp_auto_response_StartTransationConf(byte gun_index)
- {
- byte acDirIndex = 0;
-
- if (gun_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CpMsg.bits[gun_index + acDirIndex].StartTransactionConf)
- ShmOCPP16Data->CpMsg.bits[gun_index + acDirIndex].StartTransactionConf = NO;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CpMsg.bits[gun_index + acDirIndex].TransactionEventConf)
- ShmOCPP20Data->CpMsg.bits[gun_index + acDirIndex].TransactionEventConf = NO;
- }
- }
- void ocpp_auto_response_StopTransationConf(byte gun_index)
- {
- byte acDirIndex = 0;
-
- if (gun_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(ShmOCPP16Data->CpMsg.bits[gun_index + acDirIndex].StopTransactionConf)
- ShmOCPP16Data->CpMsg.bits[gun_index + acDirIndex].StopTransactionConf = NO;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void ocpp_auto_response_StopTransationConfPH(byte gun_index)
- {
- byte acDirIndex = 0;
-
- if (gun_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(ShmOCPP16DataPH->CpMsg.bits[gun_index + acDirIndex].StopTransactionConf)
- ShmOCPP16DataPH->CpMsg.bits[gun_index + acDirIndex].StopTransactionConf = NO;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- }
- void ocpp_copy_stopReason2maintainServer(byte gun_index)
- {
- byte acDirIndex = 0;
-
- if (gun_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0)
- {
- memcpy(ShmOCPP16DataPH->StopTransaction[gun_index + acDirIndex].StopReason, ShmOCPP16Data->StopTransaction[gun_index + acDirIndex].StopReason, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index + acDirIndex].StopReason));
- memcpy(ShmOCPP16DataPH->StopTransaction[gun_index + acDirIndex].IdTag, ShmOCPP16Data->StopTransaction[gun_index + acDirIndex].IdTag, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index + acDirIndex].IdTag));
- }
- }
- void ocpp_auto_response_StartTransationConfPH(byte gun_index)
- {
- byte acDirIndex = 0;
-
- if (gun_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16DataPH->CpMsg.bits[gun_index + acDirIndex].StartTransactionConf)
- ShmOCPP16DataPH->CpMsg.bits[gun_index + acDirIndex].StartTransactionConf = NO;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- }
- void ocpp_auto_response_ReserveConf(byte gun_index)
- {
- byte acDirIndex = 0;
-
- if (gun_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- ShmOCPP16Data->CsMsg.bits[gun_index + acDirIndex].ReserveNowConf = YES;
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- ShmOCPP20Data->CsMsg.bits[gun_index + acDirIndex].ReserveNowConf = YES;
- }
- bool ocpp_chk_authrization_cmd()
- {
- char buf2[16] = "";
- memset(buf2, 0, ARRAY_SIZE(buf2));
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- sprintf(buf2, "%s", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
-
- if(strcmp(buf2, "Accepted") == EQUAL)
- {
- return true;
- }
- return false;
- }
- bool opcc_sub_get_reset_req()
- {
- bool result = false;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- result = ShmOCPP16Data->MsMsg.bits.ResetReq;
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- result = ShmOCPP20Data->MsMsg.bits.ResetReq;
- return result;
- }
- void ocpp_sub_run_reset(bool canReset)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL)
- {
- DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
- sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
- ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
- ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- system("reboot -f");
- }
- else if (canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL)
- {
- DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
- sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
- ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
- ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- KillAllTask();
- CloseWatchDog();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "Immediate") == EQUAL)
- {
- DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
- sprintf((char*)ShmOCPP20Data->Reset.Response_status, "Accepted");
- ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
- ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- system("reboot -f");
- }
- else if (canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "OnIdle") == EQUAL)
- {
- DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
- sprintf((char*)ShmOCPP20Data->Reset.Response_status, "Accepted");
- ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
- ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- KillAllTask();
- CloseWatchDog();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- }
- void ocpp_chk_reset_cmd(byte isforce)
- {
- if (opcc_sub_get_reset_req())
- {
- bool canReset = true;
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != _ALARM_LEVEL_CRITICAL)
- {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
- {
- if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
- ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING)
- {
-
- ac_chargingInfo[0]->StopChargeFlag = YES;
- GetTimespecFunc(&_resetChkTime);
- }
- }
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus >= SYS_MODE_REASSIGN &&
- chargingInfo[_index]->SystemStatus <= SYS_MODE_TERMINATING)
- {
- canReset = false;
-
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL)
- ocpp_set_stopReason_by_cmd(_index, "HardReset");
- else
- ocpp_set_stopReason_by_cmd(_index, "SoftReset");
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)ShmOCPP20Data->Reset.type, "Immediate") == EQUAL)
- ocpp_set_stopReason_by_cmd(_index, "HardReset");
- else
- ocpp_set_stopReason_by_cmd(_index, "SoftReset");
- }
- ChargingTerminalProcess(_index);
- GetTimespecFunc(&_resetChkTime);
- }
- }
- }
- if (canReset)
- {
- if (GetTimeoutValue(&_resetChkTime) < 0)
- GetTimespecFunc(&_resetChkTime);
- if (GetTimeoutValue(&_resetChkTime) >= 5)
- {
- ShmDcCommonData->evBoardResetFlag = YES;
-
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- SetChargerMode(_index, SYS_MODE_MAINTAIN);
- }
- ChangeLcmByIndex(_LCM_FIX);
- }
- else
- canReset = false;
- }
- else
- GetTimespecFunc(&_resetChkTime);
- if (isforce == YES)
- canReset = true;
- ocpp_sub_run_reset(canReset);
- }
- }
- void ocpp_chk_reserved_cmd(byte gunIndex)
- {
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_IDLE &&
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowReq == YES)
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowReq = NO;
- if (!opcc_chk_reserve_expired(gunIndex))
- {
- PRINTF_FUNC("ReservationId = %d \n", ShmOCPP16Data->ReserveNow[gunIndex + acDirIndex].ReservationId);
- PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->ReserveNow[gunIndex + acDirIndex].IdTag);
- PRINTF_FUNC("*************ChkOcppStatus : OcppReservedStatus End****************** \n");
- chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
-
- strcpy((char *)ShmDcCommonData->_reserved_UserId[gunIndex],
- (char *)ShmOCPP16Data->ReserveNow[gunIndex + acDirIndex].IdTag);
- }
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowConf = YES;
- }
- if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_RESERVATION &&
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationReq == YES)
- {
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationReq = NO;
- if (ShmOCPP16Data->ReserveNow[gunIndex + acDirIndex].ReservationId == chargingInfo[gunIndex]->ReservationId)
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- PRINTF_FUNC("ReservationId = %d \n", ShmOCPP16Data->ReserveNow[gunIndex + acDirIndex].ReservationId);
- PRINTF_FUNC("***********ChkOcppStatus : Cancel OcppReservedStatus End**************** \n");
- chargingInfo[gunIndex]->ReservationId = NO_RESERVE;
- chargingInfo[gunIndex]->SystemStatus = SYS_MODE_IDLE;
- strcpy((char *)ShmDcCommonData->_reserved_UserId[gunIndex], "");
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationConf = YES;
- }
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_IDLE &&
- ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowReq == YES)
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowReq = NO;
- if (!opcc_chk_reserve_expired(gunIndex))
- {
- PRINTF_FUNC("id = %d \n", ShmOCPP20Data->ReserveNow[gunIndex + acDirIndex].id);
- PRINTF_FUNC("idToken = %s \n", ShmOCPP20Data->ReserveNow[gunIndex + acDirIndex].idToken.idToken);
- PRINTF_FUNC("*************ChkOcppStatus : OcppReservedStatus End****************** \n");
- chargingInfo[gunIndex]->ReservationId = ShmOCPP20Data->ReserveNow[gunIndex].id;
- chargingInfo[gunIndex]->SystemStatus = SYS_MODE_RESERVATION;
- strncpy((char *)ShmDcCommonData->_reserved_UserId[gunIndex],
- (char *)ShmOCPP20Data->ReserveNow[gunIndex + acDirIndex].idToken.idToken, 30);
- }
- ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowConf = YES;
- }
- if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_RESERVATION &&
- ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationReq == YES)
- {
- ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationReq = NO;
- if (ShmOCPP20Data->ReserveNow[gunIndex + acDirIndex].id == chargingInfo[gunIndex]->ReservationId)
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- PRINTF_FUNC("ReservationId = %d \n", ShmOCPP20Data->ReserveNow[gunIndex + acDirIndex].id);
- PRINTF_FUNC("***********ChkOcppStatus : Cancel OcppReservedStatus End**************** \n");
- chargingInfo[gunIndex]->ReservationId = NO_RESERVE;
- chargingInfo[gunIndex]->SystemStatus = SYS_MODE_IDLE;
- strcpy((char *)ShmDcCommonData->_reserved_UserId[gunIndex], "");
- ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationConf = YES;
- }
- }
- }
- }
- void ocpp_chk_availability_cmd(byte gunIndex)
- {
- byte type = 0;
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].ChangeAvailabilityReq == YES)
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].ChangeAvailabilityReq = NO;
- if(strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex + acDirIndex].Type, "Operative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex + acDirIndex, true);
- type = 1;
- }
- else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex + acDirIndex].Type, "Inoperative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex + acDirIndex, false);
- type = 2;
- }
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].ChangeAvailabilityReq == YES)
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].ChangeAvailabilityReq = NO;
- if(strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex + acDirIndex].operationalStatus, "Operative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex + acDirIndex, true);
- type = 1;
- }
- else if (strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex + acDirIndex].operationalStatus, "Inoperative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex + acDirIndex, false);
- type = 2;
- }
- }
- }
- if (type == 1)
- {
- chargingInfo[gunIndex]->IsAvailable = YES;
- if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == SYS_MODE_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == SYS_MODE_MAINTAIN)
- {
- SetChargerMode(gunIndex, SYS_MODE_IDLE);
- }
- }
- else if (type == 2)
- {
- chargingInfo[gunIndex]->IsAvailable = NO;
- if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == SYS_MODE_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == SYS_MODE_MAINTAIN)
- {
- SetChargerMode(gunIndex, SYS_MODE_MAINTAIN);
- }
- }
- }
- void ocpp_chk_unlock_cmd(byte gunIndex)
- {
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorReq == YES)
- {
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorReq = NO;
- if ((chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
- chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CHARGING) ||
- (chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 &&
- chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
- {
-
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex + acDirIndex].StopReason, "UnlockCommand");
- ChargingTerminalProcess(gunIndex);
- }
- if (chargingInfo[gunIndex]->Type == _Type_Chademo ||
- chargingInfo[gunIndex]->Type == _Type_GB)
- strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex + acDirIndex].ResponseStatus, "Unlocked");
- else
- strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex + acDirIndex].ResponseStatus, "Unlocked");
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorConf = YES;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorReq == YES)
- {
- ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorReq = NO;
- if ((chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
- chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CHARGING) ||
- (chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 &&
- chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
- {
-
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].transactionInfo.stoppedReason, "UnlockCommand");
- ChargingTerminalProcess(gunIndex);
- }
- if (chargingInfo[gunIndex]->Type == _Type_Chademo ||
- chargingInfo[gunIndex]->Type == _Type_GB)
- strcpy((char*)ShmOCPP20Data->UnlockConnector[gunIndex + acDirIndex].Response_status, "Unlocked");
- else
- strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex + acDirIndex].ResponseStatus, "Unlocked");
- ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorConf = YES;
- }
- }
- }
- bool ocpp_chk_remoteStop_cmd(byte gunIndex)
- {
- bool result = false;
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- result = ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].RemoteStopTransactionReq;
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- result = ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].RequestStopTransactionReq;
- if (result)
- {
- DEBUG_INFO_MSG("Remote Stop by OCPP (%d) \n", gunIndex + acDirIndex);
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex + acDirIndex].StopReason, "Remote");
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].RemoteStopTransactionReq = NO;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].transactionInfo.stoppedReason, "Remote");
- ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].RequestStopTransactionReq = NO;
- }
- }
- return result;
- }
- bool ocpp_sub_get_remote_start_transaction_req(byte gun_index)
- {
- bool result = false;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- result = ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- result = ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq;
- }
- if (result && ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,
- (char *)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag,
- ARRAY_SIZE(ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag));
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- memcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken,
- (char *)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken,
- ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken));
- }
- return result;
- }
- void ocpp_sub_set_remote_start_transaction_req(byte gunIndex, bool result)
- {
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].RemoteStartTransactionReq = result;
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].RequestStartTransactionReq = result;
- }
- void ocpp_chk_remoteStart_cmd()
- {
- if(!isDetectPlugin())
- {
-
- byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- for (byte ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++)
- {
- if (ocpp_sub_get_remote_start_transaction_req(acDirIndex))
- {
- if (ac_chargingInfo[ac_index]->SystemStatus == SYS_MODE_IDLE ||
- ac_chargingInfo[ac_index]->SystemStatus == SYS_MODE_RESERVATION)
- {
- ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
-
-
- DetectPluginStart();
- return;
- }
-
- }
- }
- byte threeGunIndex = 0;
- byte dcIndex = 0;
- bool isGunUsingStatus = false;
- byte scheduleIndex = 0;
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
-
- if (acDirIndex == 1 && _index == 1)
- threeGunIndex = 1;
- if (ocpp_sub_get_remote_start_transaction_req(_index + threeGunIndex))
- dcIndex = _index;
- if (chargingInfo[_index]->SystemStatus != SYS_MODE_IDLE)
- {
- isGunUsingStatus = true;
- }
- if (chargingInfo[_index]->schedule.isTriggerStart)
- scheduleIndex = _index;
- }
-
- if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
- {
- if (dcIndex == 0)
- threeGunIndex = 0;
-
- return;
- }
- if (dcIndex == 0)
- threeGunIndex = 0;
- if (ocpp_sub_get_remote_start_transaction_req(dcIndex + threeGunIndex))
- {
- if (chargingInfo[dcIndex]->SystemStatus == SYS_MODE_IDLE ||
- chargingInfo[dcIndex]->SystemStatus == SYS_MODE_RESERVATION)
- {
- if (ocpp_authorizeRemoteTxReqChk_key())
- {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId,
- (char *)ShmOCPP16Data->RemoteStartTransaction[dcIndex + threeGunIndex].IdTag);
- ShmDcCommonData->remoteStartAuthFlag[dcIndex] = YES;
- }
- else
- {
- chargingInfo[dcIndex]->RemoteStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- ChangeGunSelectByIndex(dcIndex);
-
- DetectPluginStart();
- }
- }
-
- }
- else if (chargingInfo[scheduleIndex]->schedule.isTriggerStart)
- {
- if (chargingInfo[scheduleIndex]->SystemStatus == SYS_MODE_IDLE ||
- chargingInfo[scheduleIndex]->SystemStatus == SYS_MODE_RESERVATION)
- {
- chargingInfo[scheduleIndex]->RemoteStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- DetectPluginStart();
- }
- chargingInfo[scheduleIndex]->schedule.isTriggerStart = NO;
- }
- }
- }
- bool ocpp_remote_start_wait_cmd()
- {
- bool result = false;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- result = ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- result = ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq;
- }
- return result;
- }
- void ocpp_chk_update_cmd()
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES)
- {
- ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
- if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL)
- {
- DEBUG_INFO_MSG("Backend : update start. \n");
- sleep(2);
- memcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing", sizeof("Installing"));
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- SetChargerMode(_index, SYS_MODE_UPDATE);
- }
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
- {
- ac_chargingInfo[_index]->SystemStatus = SYS_MODE_UPDATE;
- }
- CloseWatchDog();
- sleep(2);
- KillTask();
- byte updateResult = CheckUpdateProcess();
- if (updateResult == PASS)
- {
- DEBUG_INFO_MSG("Backend : update complete. \n");
- memcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed", sizeof("Installed"));
- }
- else if (updateResult == MODELNAME_FAIL)
- {
- DEBUG_INFO_MSG("Backend : model name is none match. \n");
- memcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed", sizeof("InstallationFailed"));
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- else
- {
- DEBUG_INFO_MSG("Backend : update fail. \n");
- memcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed", sizeof("InstallationFailed"));
- }
- memcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed", sizeof("Installed"));
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- system("reboot -f");
- }
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq == YES)
- {
- ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = NO;
- if (strcmp((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Downloaded") == EQUAL)
- {
- DEBUG_INFO_MSG("Backend : update start. \n");
- sleep(2);
- memcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installing", sizeof("Installing"));
- ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- SetChargerMode(_index, SYS_MODE_UPDATE);
- }
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
- {
- ac_chargingInfo[_index]->SystemStatus = SYS_MODE_UPDATE;
- }
- CloseWatchDog();
- sleep(2);
- KillTask();
- byte updateResult = CheckUpdateProcess();
- if (updateResult == PASS)
- {
- DEBUG_INFO_MSG("Backend : update complete. \n");
- memcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed", sizeof("Installed"));
- }
- else if (updateResult == MODELNAME_FAIL)
- {
- DEBUG_INFO_MSG("Backend : model name is none match. \n");
- memcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed", sizeof("InstallationFailed"));
- ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- else
- {
- DEBUG_INFO_MSG("Backend : update fail. \n");
- memcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed", sizeof("InstallationFailed"));
- }
- memcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed", sizeof("Installed"));
- ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- system("reboot -f");
- }
- }
- }
- }
- bool ocpp_chk_invalid_id_cmd(byte gunIndex)
- {
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE"))
- {
- if (strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex + acDirIndex].ResponseIdTagInfo.Status, "Blocked") == EQUAL ||
- strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex + acDirIndex].ResponseIdTagInfo.Status, "Expired") == EQUAL ||
- strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex + acDirIndex].ResponseIdTagInfo.Status, "Invalid") == EQUAL)
- return true;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (strstr((char *) ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE"))
- {
- if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "Blocked") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "Expired") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "Invalid") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "NoCredit") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "NotAllowedTypeEVSE") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "NotAtThisLocation") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "NotAtThisTime") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "Unknown") == EQUAL)
- return true;
- }
- }
- return false;
- }
- bool ocpp_chk_profileConf_cmd(byte gunIndex)
- {
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf == YES)
- {
- ShmOCPP16Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf = NO;
- return true;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf == YES)
- {
- ShmOCPP20Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf = NO;
- return true;
- }
- }
- return false;
- }
- void ocpp_chk_notificationMessage_cmd(byte gunIndex)
- {
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].TriggerMessageReq == YES)
- {
- if (chargingInfo[gunIndex]->Type == _Type_Chademo &&
- (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_IDLE ||
- chargingInfo[gunIndex]->SystemStatus ==SYS_MODE_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus ==SYS_MODE_MAINTAIN))
- {
- if (ShmDcCommonData->_cha_try_communication[gunIndex].try2CommunicationFlag == NO)
- {
- PRINTF_FUNC("Trigger msg (StatusNotification) = %d (chademo) \n", gunIndex);
- ShmDcCommonData->_cha_try_communication[gunIndex].elapsedTime = 0;
- GetTimespecFunc(&ShmDcCommonData->_cha_try_communication[gunIndex].detectTimer);
- ShmDcCommonData->_cha_try_communication[gunIndex].try2CommunicationFlag = YES;
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_CCS ||
- chargingInfo[gunIndex]->Type == _Type_GB ||
- chargingInfo[gunIndex]->Type == _Type_AC)
- {
- PRINTF_FUNC("Trigger msg (StatusNotification) = %d (ccs) \n", gunIndex);
- }
- ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].TriggerMessageReq = NO;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- if (ShmDcCommonData->_cha_try_communication[gunIndex].try2CommunicationFlag)
- {
- int _timeBuf = GetTimeoutValue(&ShmDcCommonData->_cha_try_communication[gunIndex].detectTimer);
- if (_timeBuf < 0)
- {
- ShmDcCommonData->_cha_try_communication[gunIndex].elapsedTime = 0;
- GetTimespecFunc(&ShmDcCommonData->_cha_try_communication[gunIndex].detectTimer);
- }
- if (_timeBuf > 30 ||
- (_timeBuf > 2 &&
- chargingInfo[gunIndex]->ConnectorPlugIn))
- {
- PRINTF_FUNC("Trigger msg - timeout or Plugin. \n");
- ShmDcCommonData->_cha_try_communication[gunIndex].try2CommunicationFlag = NO;
- }
- else
- ShmDcCommonData->_cha_try_communication[gunIndex].elapsedTime = (_timeBuf / uSEC_VAL);
- }
- }
- void ocpp_lift_profileReq_cmd(byte gunIndex)
- {
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf == NO)
- {
- if (ShmOCPP16Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileReq == NO)
- ShmOCPP16Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileReq = YES;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf == NO)
- {
- if (ShmOCPP20Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileReq == NO)
- ShmOCPP20Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileReq = YES;
- }
- }
- }
- void ocpp_set_startTransation_cmd(byte gunIndex)
- {
- byte _OcppGunIndex = gunIndex;
-
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
- _OcppGunIndex = 2;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
- strcpy((char *)chargingInfo[gunIndex]->StartUserId, (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
- else
- strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
- if (strcmp((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, "") == EQUAL)
- strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
- ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
- PRINTF_FUNC("Gun = %d, IdTag = %s \n", _OcppGunIndex, chargingInfo[gunIndex]->StartUserId);
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
- strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
- else
- strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
- ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
- PRINTF_FUNC("Gun = %d, IdTag = %s \n", _OcppGunIndex, ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
- }
- }
- void ocpp_set_startTransationPH_cmd(byte gunIndex)
- {
- byte _OcppGunIndex = gunIndex;
-
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
- _OcppGunIndex = 2;
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp((char *)ShmOCPP16DataPH->StartTransaction[_OcppGunIndex].IdTag, "") == EQUAL)
- strcpy((char *)ShmOCPP16DataPH->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
- ShmOCPP16DataPH->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- }
- void ocpp_set_stopTransation_cmd(byte gunIndex)
- {
- byte _OcppGunIndex = gunIndex;
-
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
- _OcppGunIndex = 2;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- 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;
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
- strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
- else
- strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
- PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
- ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
- }
- if (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'P')
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gunIndex].ActionCmd = _DC_METER_TRANSACTION_ACTION_STOP;
- }
- void ocpp_set_stopTransationPH_cmd(byte gunIndex)
- {
- byte _OcppGunIndex = gunIndex;
-
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
- _OcppGunIndex = 2;
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
- strcpy((char *)ShmOCPP16DataPH->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16DataPH->StopTransaction[_OcppGunIndex].IdTag);
- else
- strcpy((char *)ShmOCPP16DataPH->StopTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
- ShmOCPP16DataPH->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- }
- void ocpp_set_noErrorCode_cmd(byte gunIndex, char *errString)
- {
-
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, errString);
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void ocpp_set_stopReason_by_cmd(byte gunIndex, char *reason)
- {
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex + acDirIndex].StopReason, "") == EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex + acDirIndex].StopReason, reason);
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].transactionInfo.stoppedReason, "") == EQUAL)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].transactionInfo.stoppedReason, reason);
- }
- }
- }
- void ocpp_set_authorizeReq_cmd(byte value)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- ShmOCPP16Data->SpMsg.bits.AuthorizeReq = value;
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- sprintf((char*)ShmOCPP20Data->Authorize.idToken.type, "ISO14443");
- ShmOCPP20Data->SpMsg.bits.AuthorizeReq = value;
- }
- }
- void ocpp_set_authorizeConf_cmd(byte value)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- ShmOCPP16Data->SpMsg.bits.AuthorizeConf = value;
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- ShmOCPP20Data->SpMsg.bits.AuthorizeConf = value;
- }
- void ocpp_set_errCode_cmd(byte gunIndex)
- {
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "") != EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].ErrorCode, "InternalError");
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->ConnectorAlarmCode);
- }
- else if (strcmp((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "") != EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].ErrorCode, "OtherError");
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->EvConnAlarmCode);
- }
- else
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].ErrorCode, "NoError");
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].VendorErrorCode, "");
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void ocpp_clear_errorCode_cmd(byte gunIndex)
- {
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].ErrorCode, "NoError") != EQUAL)
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].ErrorCode, "NoError");
- if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].VendorErrorCode, "") != EQUAL)
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].VendorErrorCode, "");
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void ocpp_default_errorCode_cmd(byte gunIndex)
- {
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp ( (char *) ShmOCPP16Data->StatusNotification [gunIndex + acDirIndex].ErrorCode, "" ) == EQUAL)
- strcpy ( (char *) ShmOCPP16Data->StatusNotification [gunIndex + acDirIndex].ErrorCode, "NoError" );
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void ocpp_clear_idTag_cmd(byte gun_index)
- {
- byte acDirIndex = 0;
-
- if (gun_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index + acDirIndex].ResponseIdTagInfo.Status, "");
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index + acDirIndex].Response_idTokenInfo.status, "");
- }
- void ocpp_clear_stopReason(byte gun_index)
- {
- byte acDirIndex = 0;
-
- if (gun_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index + acDirIndex].StopReason, "");
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index + acDirIndex].transactionInfo.stoppedReason, "");
- }
- void ocpp_clear_stopTansaction_Idtag(byte gun_index)
- {
- byte acDirIndex = 0;
-
- if (gun_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index + acDirIndex].IdTag, "");
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index + acDirIndex].idToken.idToken, "");
- }
- unsigned short _ocpp_get_connect_timeout()
- {
- uint16_t result = (TIMEOUT_SPEC_HANDSHAKING / 1000);
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData,"") != 0)
- result = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value,"") != 0)
- result = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
- }
- return result;
- }
- bool ocpp_get_authorize_conf()
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- return ShmOCPP16Data->SpMsg.bits.AuthorizeConf;
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- return ShmOCPP20Data->SpMsg.bits.AuthorizeConf;
- return false;
- }
- bool ocpp_get_startTransation_req(byte gunIndex)
- {
- bool result = false;
- byte acDirIndex = 0;
-
- if (gunIndex == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
-
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- result = ShmOCPP16Data->CpMsg.bits[gunIndex + acDirIndex].StartTransactionReq;
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- result = ShmOCPP20Data->CpMsg.bits[gunIndex + acDirIndex].TransactionEventReq;
- }
- return result;
- }
- void ocpp_get_freeVendor(byte gunIndex)
- {
- byte _OcppGunIndex = gunIndex;
-
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
- _OcppGunIndex = 2;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, "");
- strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag,
- (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (strlen((char *)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].value) > 0)
- {
- }
- else
- {
- }
- }
- }
- void ocpp_parsing_DT_defaultPrice_cmd()
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp(MyDefaultPriceString, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData) != EQUAL)
- {
- DefaultPriceHandlerOcpp16((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
- memcpy(MyDefaultPriceString, ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, sizeof(MyDefaultPriceString));
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
-
- }
- }
- void ocpp_parsing_DT_userPrice_cmd()
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strlen((char *)ShmOCPP16Data->Cost.SetUserPrice.idToken) > 0 &&
- strlen((char *)ShmOCPP16Data->Cost.SetUserPrice.price) > 0)
- {
-
- UserPriceHandlerOcpp16((char *)ShmOCPP16Data->Cost.SetUserPrice.idToken,
- (char *)ShmOCPP16Data->Cost.SetUserPrice.price);
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
-
- }
- }
- void ocpp_parsing_DT_running_final_cmd()
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- RunningFinalCostHandlerOcpp16();
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
-
- }
- }
- void ocpp_chargingProfile_process(byte _index)
- {
- int _time = 0;
- int _startCount = NO_DEFINE;
- int _maxCount = 0;
- byte acDirIndex = 0;
-
- if (_index == 1)
- acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingProfileKind, "Absolute") == EQUAL &&
- ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingProfileId == YES)
- {
- _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.StartSchedule);
- if (_time > -1)
- {
- _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod);
- _startCount = NO_DEFINE;
- for (byte _count = 0; _count < _maxCount; _count++)
- {
-
- if (_time >= ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod)
- {
- if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
- ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
- {
- _startCount = _count;
- }
- }
- }
- if (_startCount < _maxCount)
- {
- if (ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit >= (ShmPsuData->SystemAvailableCurrent / 10))
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- else
- {
-
- chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL * ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod[_startCount].NumberPhases;
- if (chargingInfo[_index]->EvBatterytargetVoltage > 0 && chargingInfo[_index]->PresentChargingVoltage > 0)
- chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
- else
- chargingInfo[_index]->ChargingProfileCurrent = 0;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- if (strcmp((char *)ShmOCPP16Data->MaxChargingProfile.ChargingProfileKind, "Absolute") == EQUAL &&
- ShmOCPP16Data->MaxChargingProfile.ChargingProfileId == YES)
- {
- _time = GetStartScheduleTime(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.StartSchedule);
- if (_time > -1)
- {
- _maxCount = ARRAY_SIZE(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod);
- _startCount = NO_DEFINE;
- for (byte _count = 0; _count < _maxCount; _count++)
- {
- if (_time >= ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod)
- {
- if ((_count == 0 && ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
- ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
- {
- _startCount = _count;
- }
- }
- }
-
- if (_startCount < _maxCount)
- {
- if (ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit >= (ShmPsuData->SystemAvailableCurrent / 10))
- {
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- }
- else
- {
- float maxChargingProfilePow = ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL * ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_startCount].NumberPhases;
- if (_chargingCount > 0)
- maxChargingProfilePow /= _chargingCount;
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = maxChargingProfilePow;
- }
- }
- else
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- }
- }
- else
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (strcmp((char *)ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingProfileKind, "Absolute") == EQUAL &&
- ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].id == YES)
- {
- _time = GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].startSchedule);
- _maxCount = ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].chargingSchedulePeriod);
- _startCount = NO_DEFINE;
- for (byte _count = 0; _count < _maxCount; _count++)
- {
-
- if (_time >= ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].chargingSchedulePeriod[_count].startPeriod)
- {
- if ((_count == 0 && ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].chargingSchedulePeriod[_count].limit >= MIN_OUTPUT_CUR) ||
- ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].chargingSchedulePeriod[_count].limit > MIN_OUTPUT_CUR)
- {
- _startCount = _count;
- }
- }
- }
- if (_startCount < _maxCount)
- {
- if (ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit >= (ShmPsuData->SystemAvailableCurrent / 10))
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- else
- {
-
-
- chargingInfo[_index]->ChargingProfilePower = ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].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;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- if (ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower != -1)
- {
- chargingInfo[_index]->ChargingProfilePower = ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
- if (_ChargingMaxProfilePwBuffer[_index] != ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower)
- {
- _ChargingMaxProfilePwBuffer[_index] = ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
- PRINTF_FUNC("Profile : MaxChargingProfilePower = %.2f \n", ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower);
- }
- }
- if (chargingInfo[_index]->ChargingProfilePower >= 0 &&
- _ChargingProfilePwBuffer[_index] != chargingInfo[_index]->ChargingProfilePower)
- {
- _ChargingProfilePwBuffer[_index] = chargingInfo[_index]->ChargingProfilePower;
- PRINTF_FUNC("Profile : ChargingProfilePower = %.2f \n", chargingInfo[_index]->ChargingProfilePower);
- PRINTF_FUNC("Profile : ChargingProfileCurrent = %.2f \n", chargingInfo[_index]->ChargingProfileCurrent);
- }
- }
- void ocpp_ocmf_information(byte _index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memcpy((char *)ShmOCPP16Data->OcmfData[_index].DataString,
- (char *)ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[_index].transactionOCMF,
- sizeof(ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[_index].transactionOCMF));
- memcpy((char *)ShmOCPP16Data->OcmfData[_index].PublicKey,
- (char *)ShmSysConfigAndInfo->SysInfo.DcMeterStatusInfo[_index].publicKeyOcmf,
- sizeof(ShmSysConfigAndInfo->SysInfo.DcMeterStatusInfo[_index].publicKeyOcmf));
- ShmOCPP16Data->OcmfData[_index].SendOcmfDataReq = YES;
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void CheckOcppProfileConfirm(byte gun_index)
- {
- if ((chargingInfo [gun_index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo [gun_index]->SystemStatus <= SYS_MODE_CHARGING) ||
- (chargingInfo [gun_index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo [gun_index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
- {
- ocpp_chk_profileConf_cmd ( gun_index );
- }
- }
- void CheckAcOcppProfileConfirm()
- {
- if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING &&
- ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING)
- {
- ocpp_ac_chk_profileConf_cmd();
- }
- }
- bool WifiScheduleStop(byte gunIndex)
- {
- bool result = false;
- result = chargingInfo[gunIndex]->schedule.isTriggerStop;
- chargingInfo[gunIndex]->schedule.isTriggerStop = NO;
- return result;
- }
- int NetworkDB_Open(sqlite3 *db)
- {
- int result = PASS;
- char* errMsg = NULL;
- char* createNerRecordSql="CREATE TABLE IF NOT EXISTS network_record("
- "idx integer primary key AUTOINCREMENT, "
- "occurDatetime text NOT NULL, "
- "isInternet text NOT NULL, "
- "isOcppConnected text NOT NULL, "
- "isEth0Internet text NOT NULL, "
- "isMlan0Internet text NOT NULL, "
- "isPpp0Internet text NOT NULL, "
- "rssiMlan0 text NOT NULL, "
- "rssiPpp0 text NOT NULL"
- ");";
-
- if(sqlite3_open(NETWORK_DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database (Net) : %s\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- PRINTF_FUNC( "Local network status record database open successfully.\n");
- if (sqlite3_exec(db, createNerRecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Create local network status record table error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Opened local network status record table successfully\n");
- }
- sqlite3_close(db);
- }
- return result;
- }
- 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,"
- "vincode text"
- ");";
- 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* creatererrecordSql="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);";
- char * createconsumptionSql = "CREATE TABLE IF NOT EXISTS `power_consumption` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(connector) on conflict replace);";
- char* createDcMeterSql="CREATE TABLE IF NOT EXISTS ocmf_record("
- "idx integer primary key AUTOINCREMENT, "
- "transactionId text, "
- "status INTEGER NOT NULL, "
- "connector INTEGER NOT NULL, "
- "publicKey text, "
- "ocmfInfo text"
- ");";
- 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");
- }
- if (sqlite3_exec(db, creatererrecordSql, 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");
- }
- if (sqlite3_exec(db, createconsumptionSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Create power consumption record table error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Opened power consumption record table successfully\n");
- }
- if (sqlite3_exec(db, createDcMeterSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Create OCMF record table error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Opened OCMF 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];
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, vincode) "
- "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%s');",
- chargingInfo[gun_index]->ReservationId,
- 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,
- ShmOCPP16Data->StopTransaction[gun_index].StopReason,
- chargingInfo[gun_index]->EVCCID);
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
- "values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
- chargingInfo[gun_index]->ReservationId,
- ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId,
- 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,
- ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason);
- }
- 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 local charging record error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Insert local charging record successfully\n");
- }
- 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 (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
- 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 item='IsAvailable' and connector=%d;", gun_index);
-
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
-
- 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;
- }
- void DB_Update_PowerConsumption(sqlite3 *db, uint8_t gun_index, float value)
- {
- char* errMsg = NULL;
- char sqlStr[1024];
- srand(time(NULL));
- if(sqlite3_open(DB_FILE, &db))
- {
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sprintf(sqlStr, "insert or replace into power_consumption (connector, val) values(%d, %f);", gun_index, value);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
- {
- PRINTF_FUNC( "update power_consumption error message: %s\n", errMsg);
- }
- else
- {
-
- }
- sqlite3_close(db);
- }
- }
- float DB_Get_PowerConsumption(sqlite3 *db, uint8_t gun_index)
- {
- float result = 0;
- char* errMsg = NULL;
- char sqlStr[1024];
- char **rs;
- int rows, cols;
- sprintf(sqlStr, "select * from power_consumption where connector=%d;", gun_index);
- if (sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC("Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
-
- sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
- if (rows > 0)
- {
- for (int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atof(rs[(idxRow * cols) + 2]);
- }
- }
- else
- {
- PRINTF_FUNC( "Query connector-%d fail, set default value to consumption.\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 reboot_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;
- }
- int DB_Insert_ocmf(sqlite3 *db, uint8_t gun_index)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[2048];
- memset(insertSql, 0, sizeof(insertSql));
- sprintf(insertSql, "insert into ocmf_record (transactionId, status, connector) values('%d', 0, '%d');",
- ShmDcCommonData->startTransactionID[gun_index],
- gun_index);
- if (sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC("Can't open database: %s\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- if (sqlite3_exec(db, insertSql, 0, 0, & errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC("Insert ocmf error message : %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC("Insert ocmf successfully\n");
- }
- sqlite3_close(db);
- }
- return result;
- }
- void DB_Update_ocmf(sqlite3 *db, uint8_t gun_index)
- {
- char* errMsg = NULL;
- char insertSql[4096];
- memset(insertSql, 0, sizeof(insertSql));
- sprintf(insertSql, "update ocmf_record set status=1, publicKey='%s', ocmfInfo='%s' where status=0 and transactionId=%d and connector=%d;",
- ShmSysConfigAndInfo->SysInfo.DcMeterStatusInfo[gun_index].publicKeyOcmf,
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].transactionOCMF,
- ShmDcCommonData->startTransactionID[gun_index],
- gun_index);
- if (sqlite3_open(DB_FILE, &db))
- {
- PRINTF_FUNC("Can't open database: %s\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- if (sqlite3_exec(db, insertSql, 0, 0, & errMsg) != SQLITE_OK)
- {
- PRINTF_FUNC("Update ocmf error message : %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC("Update ocmf successfully \n");
- }
- sqlite3_close(db);
- }
- }
- void DB_Update_ocmf_Record(sqlite3 *db, uint8_t gun_index, int _trid, bool isGet)
- {
- char* errMsg = NULL;
- char insertSql[4096];
- memset(insertSql, 0, sizeof(insertSql));
- if (isGet)
- {
- sprintf(insertSql, "update ocmf_record set status=1, ocmfInfo='%s' where status=0 and transactionId=%d and connector=%d;",
- ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].transactionOCMF,
- _trid,
- gun_index);
- }
- else
- {
- sprintf(insertSql, "update ocmf_record set status=2 where status=0 and transactionId=%d and connector=%d;",
- _trid,
- gun_index);
- }
- if (sqlite3_open(DB_FILE, &db))
- {
- PRINTF_FUNC("Can't open database: %s\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- if (sqlite3_exec(db, insertSql, 0, 0, & errMsg) != SQLITE_OK)
- {
- PRINTF_FUNC("Update ocmf error message : %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC("Update ocmf_Record successfully \n");
- }
- sqlite3_close(db);
- }
- }
- int DB_Get_OcmfTrid(sqlite3 *db, uint8_t gun_index)
- {
- int result = 0;
- char* errMsg = NULL;
- char sqlStr[2048];
- char **rs;
- int rows, cols;
- memset(sqlStr, 0, sizeof(sqlStr));
- sprintf(sqlStr, "select * from ocmf_record where status=0 and connector=%d and transactionId!=0;", gun_index);
- if (sqlite3_open(DB_FILE, &db))
- {
- PRINTF_FUNC("Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
-
- sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
- if (rows > 0)
- {
- for (int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atoi(rs[(idxRow * cols) + 1]);
- break;
- }
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Insert_test_Record(sqlite3 *db, uint8_t gun_index, char *textID)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[1024];
- sprintf(insertSql, "insert into for_test (connector, testID, checkStatus) values(%d, %s, 0);",
- gun_index, textID);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Insert sdlu test error message : %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Insert sdlu test successfully\n");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_delete_test_Record(sqlite3 *db, uint8_t gun_index, char *textID)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[1024];
- sprintf(insertSql, "delete from for_test where testID = %s", textID);
- if (sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC("Can't open database: %s\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Test message 2: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Test message 2 successfully\n");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_sql_test(sqlite3 *db, uint8_t gun_index)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[1024];
- char valueStr[128];
- char **rs;
- int rows, cols;
- sprintf(insertSql, "select testID from for_test where checkStatus=0;");
- 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 for_test query database open successfully.\r\n");
- sqlite3_get_table(db, insertSql, &rs, &rows, &cols, &errMsg);
- if (rows > 0)
- {
- for (int idxRow = 1; idxRow <= rows; idxRow++)
- {
- strcpy(valueStr, rs[(idxRow * cols)]);
- printf("valueStr = %s \n", valueStr);
- }
- }
- else
- {
- PRINTF_FUNC("select testID from for_test fail \r\n");
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- void AddPlugInTimes(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
- else if(chargingInfo[gunIndex]->Type == _Type_CCS)
- 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
- {
- if (strcmp((char *)chargingInfo[gunIndex]->StartDateTime, "00:00:00") != EQUAL)
- 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);
-
- 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))
- {
- DEBUG_INFO_MSG("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);
- }
- }
- }
- }
- }
-
- closedir(pDir);
- }
- void ChangeGunSelectByIndex(byte sel)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = sel;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- }
- void CheckIsAlternatvieByModelName()
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W')
- {
-
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = YES;
- }
- else
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = NO;
- }
- void StopProcessingLoop()
- {
- for (;;)
- {
- CheckTask();
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- ocpp_chk_reset_cmd(YES);
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_CRITICAL)
- {
-
- ChkPrimaryStatus();
- ButtonTriggerEvent();
- ReviewCriticalAlarm();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_NORMAL &&
- ShmDcCommonData->rebootCount < 1)
- {
- PRINTF_FUNC("Soft reboot for retry self-test (Primary). \n");
- SetupRebootCount(1);
- KillAllTask();
- sleep(3);
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- }
- sleep(1);
- }
- }
- bool IsConnectorWholeIdle()
- {
- bool result = true;
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- if (chargingInfo[count]->SystemStatus != SYS_MODE_IDLE &&
- chargingInfo[count]->SystemStatus != SYS_MODE_RESERVATION)
- {
- result = false;
- break;
- }
- }
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++)
- {
- if (ac_chargingInfo[count]->SystemStatus != SYS_MODE_IDLE &&
- ac_chargingInfo[count]->IsErrorOccur == NO)
- {
- result = false;
- break;
- }
- }
- return result;
- }
- void ClearAlarmCodeWhenAcOff()
- {
- if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- }
- }
- void CheckTask()
- {
- if(reset4gStep == RESET_4G_STEP_NONE && _isUsing4G)
- {
- if(system("pidof -s Module_4g > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("Module_4g not running, restart it.\r\n");
- system("/root/Module_4g &");
- }
- }
- if(reset4gStep == RESET_4G_STEP_NONE && _isUsingWifi)
- {
- if(system("pidof -s Module_Wifi > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("Module_Wifi not running, restart it.\r\n");
- system("/root/Module_Wifi &");
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'P')
- {
- if(system("pidof -s Module_DcMeter > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("Module_DcMeter not running, restart it.\r\n");
- system("/root/Module_DcMeter &");
- }
- }
- if (_verifyMechanism == VERIFY_MECHANISM_BAZEL8)
- {
- if(system("pidof -s Module_Payment_Bazel8 > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("Module_Payment_Bazel8 not running, restart it.\r\n");
- system("/root/Module_Payment_Bazel8 &");
- }
- }
- ocpp_process_start();
- if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("Module_ProduceUtils not running, restart it.\r\n");
- system ("/root/Module_ProduceUtils &");
- }
- }
- void Check267Alarm()
- {
- bool canRun = true;
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if((chargingInfo[_index]->SystemStatus > SYS_MODE_IDLE && chargingInfo[_index]->SystemStatus < SYS_MODE_TERMINATING) ||
- (chargingInfo[_index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[_index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
- {
- canRun = false;
- break;
- }
- }
- if (canRun)
- {
- if ( ! ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
- }
- }
- }
- void CheckPaymentID()
- {
- if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0 &&
- !isPaymentBusy)
- {
- isPaymentBusy = true;
- ShmSysConfigAndInfo->SysInfo.bazel8.cmdPreAuth.isReq = true;
- }
- else if (ShmSysConfigAndInfo->SysInfo.bazel8.cmdPreAuth.isRes)
- {
- ShmSysConfigAndInfo->SysInfo.bazel8.cmdPreAuth.isRes = false;
- if (ShmSysConfigAndInfo->SysInfo.bazel8.cmdPreAuth.isResultPass)
- {
- isPaymentBusy = false;
- PRINTF_FUNC ( "txnId = %s \n", ShmSysConfigAndInfo->SysInfo.bazel8.txResp.txnId );
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- ShmSysConfigAndInfo->SysInfo.bazel8.txResp.txnId);
- }
- else
- isPaymentBusy = false;
- PRINTF_FUNC ( "isWaitRes = %d \n", ShmSysConfigAndInfo->SysInfo.bazel8.cmdPreAuth.isWaitRes );
- }
- }
- void CheckSystemTaskAlive()
- {
- unsigned char lostId = CheckSystemTask(ShmSysConfigAndInfo->SysInfo.SystemPage);
- if (lostId != 0)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost == NO)
- {
- EmcOccurThenStopCharging();
- sleep(2);
- if (lostId == _SYSTEM_TASK_LOST_ITEM_MAIN) PRINTF_FUNC ( "System task lost (CSU). \n" );
- else if (lostId == _SYSTEM_TASK_LOST_ITEM_EVCOMM)
- {
- PRINTF_FUNC ( "System task lost (EVComm). \n" );
- for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun ++)
- {
- chargingInfo [gun]->ConnectorPlugIn = NO;
- }
- }
- else if (lostId == _SYSTEM_TASK_LOST_ITEM_PSUCOMM) PRINTF_FUNC ( "System task lost (PSU Task). \n" );
- else if (lostId == _SYSTEM_TASK_LOST_ITEM_SMARTBOX) PRINTF_FUNC ( "System task lost (SmartBox Task). \n" );
- else if (lostId == _SYSTEM_TASK_LOST_ITEM_EVENTLOG) PRINTF_FUNC ( "System task lost (Event log). \n" );
- else if (lostId == _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM) PRINTF_FUNC ( "System task lost (Primary). \n" );
- else if (lostId == _SYSTEM_TASK_LOST_ITEM_LCMCONTROL) PRINTF_FUNC ( "System task lost (LCM Comm). \n" );
- else if (lostId == _SYSTEM_TASK_LOST_ITEM_INTERCOMM) PRINTF_FUNC("System task lost (Internal Comm). \n");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost = YES;
- }
- }
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost = NO;
- }
- void InitialDHCP()
- {
- char tmpbuf[256];
- memset(tmpbuf,0,256);
- 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);
- }
- void Run4gResetProc()
- {
- if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == _SYS_4G_MODE_ENABLE ||
- ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_STATION)
- {
- if (!ShmSysConfigAndInfo->SysInfo.OcppConnStatus &&
- !ShmSysConfigAndInfo->SysInfo.InternetConn)
- {
- if (reset4gStep == RESET_4G_STEP_NONE)
- {
- if (_4gResetChkFlag >= 300)
- {
- PRINTF_FUNC("Reset 4G/Wifi module. \n");
- reset4gStep = RESET_4G_STEP_DELETE_TASK;
- }
- else
- _4gResetChkFlag++;
- }
- }
- else
- _4gResetChkFlag = 0;
- switch(reset4gStep)
- {
- case RESET_4G_STEP_DELETE_TASK:
- {
- PRINTF_FUNC("Killall 4G / Wifi task. \n");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- reset4gStep = RESET_4G_STEP_GPIO_HIGH;
- }
- break;
- case RESET_4G_STEP_GPIO_HIGH:
- {
- PRINTF_FUNC("Disable 4G/Wifi. GPIO-104 -> High. \n");
- system("echo 1 > /sys/class/gpio/gpio104/value");
- reset4gStep = RESET_4G_STEP_GPIO_LOW_COMP;
- }
- break;
- case RESET_4G_STEP_GPIO_LOW_COMP:
- {
- PRINTF_FUNC("Enable 4G/Wifi. GPIO-104 -> Low. \n");
- system("echo 0 > /sys/class/gpio/gpio104/value");
- reset4gStep = RESET_4G_STEP_NONE;
- _4gResetChkFlag = 0;
- }
- break;
- }
- }
- else
- {
- if (reset4gStep != RESET_4G_STEP_NONE)
- system("echo 0 > /sys/class/gpio/gpio104/value");
- reset4gStep = RESET_4G_STEP_NONE;
- _4gResetChkFlag = 0;
- }
- }
- 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 ConfigOcmfInfo(byte gun_index)
- {
- strncpy((char *)ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].head.evseId,
- (char *)ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
- char trId[32];
- sprintf(trId, "%d", ShmDcCommonData->startTransactionID[gun_index]);
- memcpy((char *)ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].head.transactionId, trId,
- sizeof(trId));
- char clientId[32] = "DC_Charger";
- memcpy((char *)ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].head.clientId, clientId,
- sizeof(clientId));
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].head.tariffId = 0;
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].head.cableId = 0;
- memcpy((char *)ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].head.userData,
- (char *)chargingInfo[gun_index]->StartUserId,
- sizeof(chargingInfo[gun_index]->StartUserId));
- }
- void ConfigOcmfInfo_Record(int _trID, byte gun_index)
- {
- strncpy((char *)ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].head.evseId,
- (char *)ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
- char trId[32];
- sprintf(trId, "%d", _trID);
- strcpy((char *)ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].head.transactionId, trId);
- strcpy((char *)ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].head.clientId, "DC_Charger");
- ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].head.tariffId = 0;
- ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].head.cableId = 0;
- strcpy((char *)ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].head.userData, "Record");
- }
- void ChkOcmfRecord(byte gun_index)
- {
- int trid = DB_Get_OcmfTrid(localDb, gun_index);
- if (trid != 0 &&
- trid != ShmDcCommonData->ocmfTridRecord[gun_index] &&
- trid != ShmDcCommonData->startTransactionID[gun_index])
- {
- PRINTF_FUNC("OCMF Record Send : trid = %d\n", trid);
- ShmDcCommonData->ocmfTridRecord[gun_index] = trid;
- ConfigOcmfInfo_Record(ShmDcCommonData->ocmfTridRecord[gun_index], gun_index);
- ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].ActionCmd = _DC_METER_TRANSACTION_ACTION_START;
- }
- if (ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].OcmfInfoReady == _OCMF_INFO_READY_YES)
- {
- PRINTF_FUNC("OCMF Record - Reture Pass \n");
- ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].OcmfInfoReady = _OCMF_INFO_READY_NO;
- ocpp_ocmf_information(gun_index);
- DB_Update_ocmf_Record(localDb, gun_index, ShmDcCommonData->ocmfTridRecord[gun_index], true);
- ShmDcCommonData->ocmfTridRecord[gun_index] = 0;
- }
- else if (ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].OcmfInfoReady == _OCMF_INFO_READY_FAIL)
- {
- PRINTF_FUNC("OCMF Record - Reture Fail \n");
- ShmSysConfigAndInfo->SysInfo.DcMeterReadTransactionRecord[gun_index].OcmfInfoReady = _OCMF_INFO_READY_NO;
- DB_Update_ocmf_Record(localDb, gun_index, ShmDcCommonData->ocmfTridRecord[gun_index], false);
- ShmDcCommonData->ocmfTridRecord[gun_index] = 0;
- }
- }
- 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++)
- {
-
- if (count == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
- {
- if ((chargingInfo[count]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= SYS_MODE_COMPLETE) ||
- (chargingInfo[count]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[count]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
- {
- isReturnTimeout = false;
- break;
- }
- }
- else if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected)
- {
- if ((chargingInfo[count]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= SYS_MODE_COMPLETE) ||
- (chargingInfo[count]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[count]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
- {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- }
-
- if (!isReturnTimeout && ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
-
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
- (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING && ac_chargingInfo[0]->SystemStatus <= SYS_MODE_COMPLETE))
- {
-
- if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == SYS_MODE_IDLE ||
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == SYS_MODE_RESERVATION)
- {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
- ((chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= SYS_MODE_COMPLETE) ||
- (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1)))
- {
-
- if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE ||
- ac_chargingInfo[0]->SystemStatus == SYS_MODE_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 != SYS_MODE_IDLE &&
- chargingInfo[_select]->SystemStatus != SYS_MODE_RESERVATION)
- {
- result = false;
- break;
- }
- }
- }
- }
- return result;
- }
- void TheEndCharging(byte 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 AdjustChargerCurrent()
- {
- ShmSysConfigAndInfo->SysConfig.RatingCurrent = ShmPsuData->SystemAvailableCurrent / 10;
-
- if (ShmSysConfigAndInfo->SysConfig.RatingCurrent < ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent ||
- ShmSysConfigAndInfo->SysConfig.RatingCurrent == 0)
- {
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = 0;
- }
- PRINTF_FUNC ("System : MaxChargingPower = %d (KW), MaxChargingCurrent = %d (A)",
- ShmPsuData->SystemAvailablePower / 10,
- ShmPsuData->SystemAvailableCurrent / 10
- );
- PRINTF_FUNC ("Web Config : ChargingPower = %d (KW), ChargingCurrent = %d (A)",
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent
- );
- }
- bool CheckTheSystemType()
- {
- bool result = false;
- char EvsePower[2];
- EvsePower[2] = '\0';
- strncpy ( EvsePower, (char *) (ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2 );
- ShmDcCommonData->halfGroupCount = 1;
- if (strcmp ( EvsePower, "30" ) == EQUAL)
- ShmDcCommonData->systemType = _SYSTEM_TYPE_SIMPLE;
- else
- {
-
- if (ShmPsuData->PsuGroup[2].GroupPresentPsuQuantity == 0 &&
- ShmPsuData->PsuGroup[3].GroupPresentPsuQuantity == 0)
- ShmDcCommonData->systemType = _SYSTEM_TYPE_STANDARD;
- else
- {
- ShmDcCommonData->halfGroupCount = 2;
- ShmDcCommonData->systemType = _SYSTEM_TYPE_SMART;
- }
- if ((ShmPsuData->PsuGroup[2].GroupPresentPsuQuantity != 0 && ShmPsuData->PsuGroup[3].GroupPresentPsuQuantity == 0) ||
- (ShmPsuData->PsuGroup[2].GroupPresentPsuQuantity == 0 && ShmPsuData->PsuGroup[3].GroupPresentPsuQuantity != 0))
- {
- result = true;
- }
- }
- return result;
- }
- void CheckStatusOfMeter()
- {
-
-
- 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 ReviewCriticalAlarm()
- {
- if (ShmDcCommonData->GunRelayDrivingOccur[0] == YES ||
- ShmDcCommonData->GunRelayDrivingOccur[1] == YES ||
- ShmDcCommonData->GunRelayWeldingOccur[0] == YES ||
- ShmDcCommonData->GunRelayWeldingOccur[1] == YES ||
- ShmDcCommonData->ParaRelayWeldingOccur == YES ||
- ShmDcCommonData->ParaRelayDrivingOccur == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip ||
- (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen && ShmDcCommonData->_tiltSensorStep == _TILT_SENSOR_STEP_NONE) ||
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost)
- {
- ShmSysConfigAndInfo->SysWarningInfo.Level = _ALARM_LEVEL_CRITICAL;
- }
- else
- ShmSysConfigAndInfo->SysWarningInfo.Level = _ALARM_LEVEL_NORMAL;
- }
- void CheckRelayWeldingOrDrivingFault(byte gun_index)
- {
-
- 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 ||
- ShmDcCommonData->RelayCheckStatus[RELAY_PRE_STATUS] == RELAY_STATUS_ERROR_WELDING)
- {
- faultCode = RELAY_STATUS_ERROR_PARA_WELDING;
- }
- else if (ShmDcCommonData->RelayCheckStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_PRE_STATUS] == RELAY_STATUS_ERROR_DRIVING)
- {
- faultCode = RELAY_STATUS_ERROR_PARA_DRIVING;
- }
- }
- if (faultCode == RELAY_STATUS_ERROR_WELDING)
- {
-
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- RecordAlarmCode(gun_index, "011011");
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- RecordAlarmCode(gun_index, "011015");
- else if (chargingInfo[gun_index]->Type == _Type_CCS)
- RecordAlarmCode(gun_index, "011013");
- ShmDcCommonData->GunRelayWeldingOccur[gun_index] = YES;
- EmcOccurThenStopCharging();
- }
- else if (faultCode == RELAY_STATUS_ERROR_DRIVING)
- {
-
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- RecordAlarmCode(gun_index, "011012");
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- RecordAlarmCode(gun_index, "011016");
- else if (chargingInfo[gun_index]->Type == _Type_CCS)
- RecordAlarmCode(gun_index, "011014");
- ShmDcCommonData->GunRelayDrivingOccur[gun_index] = YES;
- EmcOccurThenStopCharging();
- }
- else
- {
- if (chargingInfo[gun_index]->SystemStatus <= SYS_MODE_TERMINATING ||
- chargingInfo[gun_index]->SystemStatus >= SYS_MODE_ALARM)
- {
- ShmDcCommonData->GunRelayWeldingOccur[gun_index] = NO;
- ShmDcCommonData->GunRelayDrivingOccur[gun_index] = NO;
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- ResetChargerAlarmCode(gun_index, "011012");
- ResetChargerAlarmCode(gun_index, "011011");
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS)
- {
- ResetChargerAlarmCode(gun_index, "011014");
- ResetChargerAlarmCode(gun_index, "011013");
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- ResetChargerAlarmCode(gun_index, "011016");
- ResetChargerAlarmCode(gun_index, "011015");
- }
- }
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2)
- {
- if ((chargingInfo[0]->SystemStatus <= SYS_MODE_TERMINATING ||
- chargingInfo[0]->SystemStatus >= SYS_MODE_ALARM) &&
- (chargingInfo[1]->SystemStatus <= SYS_MODE_TERMINATING ||
- chargingInfo[1]->SystemStatus >= SYS_MODE_ALARM))
- {
- if (faultCode == RELAY_STATUS_ERROR_PARA_WELDING)
- {
-
- RecordAlarmCode ( gun_index, "011039" );
- ShmDcCommonData->ParaRelayWeldingOccur = YES;
- EmcOccurThenStopCharging ();
- }
- else if (faultCode == RELAY_STATUS_ERROR_PARA_DRIVING)
- {
-
- RecordAlarmCode ( gun_index, "011040" );
- ShmDcCommonData->ParaRelayDrivingOccur = YES;
- EmcOccurThenStopCharging ();
- }
- else
- {
- ShmDcCommonData->ParaRelayWeldingOccur = NO;
- ShmDcCommonData->ParaRelayDrivingOccur = NO;
- ResetChargerAlarmCode ( gun_index, "011039" );
- ResetChargerAlarmCode ( gun_index, "011040" );
- }
- }
- }
- }
- void KillOcppTask()
- {
- system ("pkill OcppBackend");
- system ("pkill OcppBackend20");
- }
- bool PrecheckIsPass(byte gun_index)
- {
- bool result = true;
-
- if (result)
- result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
- if (result)
- result = !ShmDcCommonData->ParaRelayWeldingOccur;
- return result;
- }
- void CollectError(byte gun_index)
- {
- errCollect.GunErrMessage |= ShmDcCommonData->ConnectErrList[gun_index].GunErrMessage;
- }
- void AlarmCheck(byte type)
- {
-
- if (type == _Type_Chademo)
- {
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 0))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 1))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 2))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 3))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 4))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 5))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 6))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 7))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 0))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputUCP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputUCP = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 3))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayWelding = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayWelding = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 4))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayDriving = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayDriving = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 5))
- ShmStatusCodeData->InfoCode.InfoEvents.bits.Stop_by_EVSE_condition = YES;
- else
- ShmStatusCodeData->InfoCode.InfoEvents.bits.Stop_by_EVSE_condition = NO;
- }
- else if (type == _Type_CCS)
- {
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 0))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 1))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 2))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 3))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 4))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 5))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 6))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 7))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 1))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCCSOutputUCP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCCSOutputUCP = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 3))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayWelding = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayWelding = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 4))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayDriving = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayDriving = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 5))
- ShmStatusCodeData->InfoCode.InfoEvents.bits.Stop_by_EVSE_condition = YES;
- else
- ShmStatusCodeData->InfoCode.InfoEvents.bits.Stop_by_EVSE_condition = NO;
- }
- else if (type == _Type_GB)
- {
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 0))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 1))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 2))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 3))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 4))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 5))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 6))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 7))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 2))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGBTOutputUCP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGBTOutputUCP = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 3))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayWelding = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayWelding = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 4))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayDriving = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayDriving = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 5))
- ShmStatusCodeData->InfoCode.InfoEvents.bits.Stop_by_EVSE_condition = YES;
- else
- ShmStatusCodeData->InfoCode.InfoEvents.bits.Stop_by_EVSE_condition = NO;
- }
- }
- void SystemAlarmCheck()
- {
- byte system = 3;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * system), 3))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayWelding = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayWelding = NO;
-
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * system), 4))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayDriving = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayDriving = NO;
- }
- void SavePresentChargedDuration(byte gun_index)
- {
- int _diffTime = 0;
- ftime(&endChargingTime[gun_index]);
- _diffTime = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
-
- if (_diffTime < 0 ||
- _diffTime > chargingInfo[gun_index]->PresentChargedDuration + 5)
- {
- _presentChargingTimeBuf[gun_index] = chargingInfo[gun_index]->PresentChargedDuration;
- ftime(&startChargingTime[gun_index]);
- PRINTF_FUNC("TimeZone changed (%d) \n", gun_index);
- }
- else
- chargingInfo[gun_index]->PresentChargedDuration = _presentChargingTimeBuf[gun_index] + _diffTime;
- }
- void ClearEnergyTimePeriod(byte gun_index)
- {
- for (int i = 0; i < 24; i++)
- {
- ShmDcCommonData->energy_time_period[gun_index][i] = 0;
- }
- }
- void CheckOcppCostAndPrice()
- {
- if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
- {
-
- ocpp_parsing_DT_defaultPrice_cmd();
- ocpp_parsing_DT_userPrice_cmd();
- ocpp_parsing_DT_running_final_cmd();
- }
- }
- void CheckAuthrizeByEvccid()
- {
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE &&
- ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID)
- ShmDcCommonData->enObtainAuthorizbyCCID = YES;
- else
- ShmDcCommonData->enObtainAuthorizbyCCID = NO;
- }
- void ConnectorOTP(byte _index)
- {
- bool isOTP = false;
- if (chargingInfo[_index]->Type == _Type_Chademo)
- {
- if (ShmDcCommonData->ConnectErrList[_index].GunBits.ChaConnectOTP)
- isOTP = true;
- }
- else if (chargingInfo[_index]->Type == _Type_CCS)
- {
- if (ShmDcCommonData->ConnectErrList[_index].GunBits.CCSConnectOTP)
- isOTP = true;
- }
- else if (chargingInfo[_index]->Type == _Type_GB)
- {
- if (ShmDcCommonData->ConnectErrList[_index].GunBits.GBTConnectOTP)
- isOTP = true;
- }
- if (isOTP)
- {
- if (gunTempAllowCount[_index] >= 1)
- chargingInfo[_index]->StopChargeFlag = YES;
- else
- gunTempAllowCount[_index] += 1;
- }
- }
- void CheckConnectorOTP(byte _index)
- {
- if (chargingInfo[_index]->Type == _Type_Chademo &&
- (chargingInfo[_index]->ModelType == 'K' ||
- chargingInfo[_index]->ModelType == 'S' ||
- chargingInfo[_index]->ModelType == 'W'))
- {
- if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
- {
- ResetChargerAlarmCode(_index, "011018");
- if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
- RecordAlarmCode(_index, "012229");
- else if (chargingInfo[_index]->ConnectorTemp != 0 &&
- chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
- ResetChargerAlarmCode(_index, "012229");
- }
- else
- {
-
- RecordAlarmCode(_index, "011018");
- ResetChargerAlarmCode(_index, "012229");
- }
- }
- else if (chargingInfo[_index]->Type == _Type_CCS)
- {
-
- if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
- {
- ResetChargerAlarmCode(_index, "011019");
- if(chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
- RecordAlarmCode(_index, "012230");
- else if (chargingInfo[_index]->ConnectorTemp != 0 &&
- chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
- ResetChargerAlarmCode(_index, "012230");
- }
- else
- {
-
- RecordAlarmCode(_index, "011019");
- ResetChargerAlarmCode(_index, "012230");
- }
- }
- else if (chargingInfo[_index]->Type == _Type_GB &&
- chargingInfo[_index]->ModelType == 'B')
- {
- if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
- {
- ResetChargerAlarmCode(_index, "011020");
- if(chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
- RecordAlarmCode(_index, "012231");
- else if (chargingInfo[_index]->ConnectorTemp != 0 &&
- chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
- ResetChargerAlarmCode(_index, "012231");
- }
- else
- {
-
- RecordAlarmCode(_index, "011020");
- ResetChargerAlarmCode(_index, "012231");
- }
- }
- ConnectorOTP(_index);
- }
- void ChkConnectorBoardStop(byte index)
- {
- if (isEvBoardStopChargeFlag(index) == YES)
- {
-
- ocpp_set_stopReason_by_cmd(index, "EVDisconnected");
- ChargingAlarmProcess(index);
- }
- else if (isEvBoardNormalStopChargeFlag(index) == YES)
- {
-
- ocpp_set_stopReason_by_cmd(index, "EVDisconnected");
- ChargingTerminalProcess(index);
- }
- }
- void ChkNoCharging(byte index)
- {
- if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
- {
- PRINTF_FUNC("Offline Policy : No Charing... \n");
- ocpp_set_stopReason_by_cmd(index, "Other");
- ChargingTerminalProcess(index);
- }
- }
- void ChkPsuErrorStop(byte index)
- {
- if (ShmPsuData->PsuGroup[index].GroupErrorFlag.bits.PsuFailure == YES ||
- (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf && ShmPsuData->PsuGroup[0].GroupErrorFlag.bits.PsuFailure))
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- if (chargingInfo[gun_index]->PresentChargingCurrent <= 5 &&
- ((chargingInfo[gun_index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[gun_index]->SystemStatus <= SYS_MODE_CHARGING) ||
- (chargingInfo[gun_index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[gun_index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1)))
- {
- ocpp_set_stopReason_by_cmd(gun_index, "Other");
- ChargingAlarmProcess(gun_index);
- }
- }
- }
- }
- void ChkBackendStop(byte index)
- {
- if (ocpp_chk_invalid_id_cmd(index))
- {
-
- ocpp_set_stopReason_by_cmd(index, "DeAuthorized");
- ChargingTerminalProcess(index);
- }
- else if (ocpp_chk_remoteStop_cmd(index) == YES ||
- WifiScheduleStop(index))
- {
-
- ChargingTerminalProcess(index);
- }
- }
- void ChkConfigurationStop(byte index)
- {
- if (CheckWebConfigChargingTimeout(index) ||
- CheckWebConfigChargingEnergy(index) ||
- CheckWebConfigChargingSOC(index))
- {
-
- PRINTF_FUNC("CheckBackendCharging stop charging (%d) \n", index);
- RecordAlarmCode(index, "023984");
- ChargingTerminalProcess(index);
- return;
- }
- if (CheckOcppChargingTimeout(index) ||
- CheckOcppChargingEnergy(index) ||
- CheckOcppChargingSOC(index))
- {
-
- PRINTF_FUNC("CheckOcppCharging stop charging (%d) \n", index);
- RecordAlarmCode(index, "023984");
- ChargingTerminalProcess(index);
- }
- }
- void RecordGfdResult(byte index)
- {
- if (chargingInfo[index]->Type == _Type_Chademo)
- {
- if (chargingInfo[index]->GroundFaultStatus == GFD_FAIL)
- {
-
- RecordAlarmCode(index, "012234");
- ocpp_set_stopReason_by_cmd(index, "Other");
- ChargingAlarmProcess(index);
- }
- else if (chargingInfo[index]->GroundFaultStatus == GFD_WARNING)
- {
-
- RecordAlarmCode(index, "012296");
- }
- }
- else if (chargingInfo[index]->Type == _Type_GB)
- {
- if (chargingInfo[index]->GroundFaultStatus == GFD_FAIL)
- {
-
- RecordAlarmCode(index, "012236");
- ocpp_set_stopReason_by_cmd ( index, "Other" );
- ChargingAlarmProcess ( index );
- }
- else if (chargingInfo[index]->GroundFaultStatus == GFD_WARNING)
- {
-
- RecordAlarmCode(index, "012298");
- }
- }
- else if (chargingInfo[index]->Type == _Type_CCS)
- {
- if (chargingInfo[index]->GroundFaultStatus == GFD_FAIL)
- {
-
- RecordAlarmCode(index, "012235");
- ocpp_set_stopReason_by_cmd(index, "Other");
- ChargingAlarmProcess ( index );
- }
- else if (chargingInfo[index]->GroundFaultStatus == GFD_WARNING)
- {
-
- RecordAlarmCode(index, "012297");
- }
- }
- }
- void CcidAuthorizationProcessing(byte gun_index)
- {
-
- if ((chargingInfo [gun_index]->Type == _Type_CCS || chargingInfo [gun_index]->Type == _Type_GB) &&
- chargingInfo [gun_index]->IsAvailable &&
- ShmDcCommonData->enObtainAuthorizbyCCID &&
- chargingInfo[gun_index]->ConnectorPlugIn &&
- strcmp ((char *)ShmSysConfigAndInfo->SysConfig.UserId, "") == EQUAL)
- {
- AddPlugInTimes(gun_index);
- PRINTF_FUNC("CcidAuthorizationProcessing. \n");
- ChangeGunSelectByIndex(gun_index);
- SetChargerMode(gun_index, SYS_MODE_MODE_REASSIGN_CHECK);
- }
- }
- void CheckCcidAuthorizationFunction(byte gun_index)
- {
-
- {
- if (ShmDcCommonData->_authWithCcidFlag [gun_index] == _CCID_GET &&
- ShmDcCommonData->_CcidAuthProcessStep == _CCID_NONE &&
- strcmp ( (char *) ShmSysConfigAndInfo->SysConfig.UserId, "" ) == EQUAL)
- {
- PRINTF_FUNC ( "index = %d, Get for CCID (main). \n", gun_index );
- ShmDcCommonData->_authWithCcidFlag [gun_index] = _CCID_CHECK;
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_CHECK;
-
- if(strcmp((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "") != EQUAL)
- {
- strcpy((char*)ShmSysConfigAndInfo->SysConfig.UserId, (char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
- strcat((char*)ShmSysConfigAndInfo->SysConfig.UserId, (char*)chargingInfo [gun_index]->EVCCID);
- PRINTF_FUNC ( "Prfix CCID:%s\n", ShmSysConfigAndInfo->SysConfig.UserId);
- }
- else
- strcpy((char*)ShmSysConfigAndInfo->SysConfig.UserId, (char*)chargingInfo[gun_index]->EVCCID);
- }
- else if (ShmDcCommonData->_authWithCcidFlag [gun_index] == _CCID_CHECK)
- {
- if (ShmDcCommonData->_CcidAuthProcessStep == _CCID_AUTHFAIL)
- {
- PRINTF_FUNC ( "index = %d, _CCID_AUTHFAIL. \n", gun_index );
- ShmDcCommonData->_authWithCcidFlag [gun_index] = ShmDcCommonData->_CcidAuthProcessStep;
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
- }
- else if (ShmDcCommonData->_CcidAuthProcessStep == _CCID_AUTHCOMP)
- {
- PRINTF_FUNC ( "index = %d, _CCID_AUTHCOMP. \n", gun_index );
- ShmDcCommonData->_authWithCcidFlag [gun_index] = ShmDcCommonData->_CcidAuthProcessStep;
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
- }
- }
- }
- }
- byte TransactionResponseStatus(byte _index)
- {
- byte _checkResult = NO_DEFINE;
- _checkResult = ocpp_is_resPass_StartTransactionConf(_index);
- if (_checkResult == START_TRANSATION_STATUS_PASS)
- {
- if (ocpp_chk_invalid_id_cmd(_index))
- _checkResult = START_TRANSATION_STATUS_FAIL;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO)
- {
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING ||
- ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- !ocpp_get_startTransation_req(_index) ||
- strcmp((char *) chargingInfo[_index]->StartUserId, "") != EQUAL || _isTestRun)
- {
- _checkResult = START_TRANSATION_STATUS_PASS;
- }
- }
- }
- return _checkResult;
- }
- void SendStartTransactionReq(byte _index)
- {
- _isSendStartTransaction[_index] = true;
- ocpp_set_startTransation_cmd(_index);
- ocpp_set_startTransationPH_cmd(_index);
- GetTimespecFunc(&_startTransation_time[_index]);
- }
- bool isStartTransactionResponsedFail(byte _index)
- {
- bool result = NO;
-
-
- if ((_isSendStartTransaction[_index] && ShmDcCommonData->startTransactionFlag[_index] == START_TRANSATION_STATUS_FAIL)
- || (_isSendStartTransaction[_index] && ShmDcCommonData->startTransactionFlag[_index] == START_TRANSATION_STATUS_WAIT
- && GetTimeoutValue(&_startTransation_time[_index]) > 45))
- {
- result = YES;
- }
- return result;
- }
- bool isCcidEnterToCharging(byte gun_index)
- {
- bool result = false;
- if (ShmDcCommonData->enObtainAuthorizbyCCID)
- {
- if (ShmDcCommonData->_CcidAuthProcessStep == _CCID_AUTHCOMP)
- {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo [_index]->Type == _Type_CCS &&
- chargingInfo [_index]->IsAvailable &&
- ShmDcCommonData->_authWithCcidFlag [_index] == _CCID_CHECK)
- {
- if (_index != gun_index)
- result = true;
- break;
- }
- }
- if (!result)
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
- }
- }
- return result;
- }
- bool IsNoneSelectAcModule()
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0 ||
- (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE))
- {
- result = true;
- }
- return result;
- }
- bool IsSelectAcModule()
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0)
- return result;
- else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
- {
- result = true;
- }
- return result;
- }
- void DisplayPageChkByAcModule()
- {
- if (IsSelectAcModule())
- {
- if (ac_chargingInfo [0]->ConnectorPlugIn == AC_SYS_A)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- }
- void GetSystemDate()
- {
- time_t timep;
- struct tm *p;
- time ( & timep );
- p = gmtime ( & timep );
- sprintf ( (char *) ShmDcCommonData->_sys_date, "%d/%.2d/%.2d",
- (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday );
- if (p->tm_hour >= 12)
- {
- sprintf ( (char *) ShmDcCommonData->_sys_period, "p.m" );
- sprintf ( (char *) ShmDcCommonData->_sys_time, "%.2d:%.2d", p->tm_hour - 12, p->tm_min);
- }
- else
- {
- sprintf ( (char *) ShmDcCommonData->_sys_period, "a.m" );
- sprintf ( (char *) ShmDcCommonData->_sys_time, "%.2d:%.2d", p->tm_hour, p->tm_min);
- }
- }
- void UpdateDcMeterPowerConsumption(byte _index)
- {
- if (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'P')
- {
- if (chargingInfo[_index]->PowerConsumption != ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeImportEnergy)
- chargingInfo[_index]->PowerConsumption = ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeImportEnergy;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'L')
- {
- if(chargingInfo[_index]->PowerConsumption != ShmCsuMeterData->_meter[_index]._curTotalCharging / 100)
- chargingInfo[_index]->PowerConsumption = ShmCsuMeterData->_meter[_index]._curTotalCharging / 100;
- }
- }
- int PresentChargedAcEnergyClear(unsigned char gun_index)
- {
- int result = FAIL;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
- memset(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].presentChargedEnergyPeriod, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].presentChargedEnergyPeriod)*sizeof(float));
- result = PASS;
- return result;
- }
- void CheckTpcTimeout()
- {
- int _tpcTimebuf = 0;
- _tpcTimebuf = GetTimeoutValue(&_tcpDetectStatus_time);
- if (_tpcTimebuf < 0)
- GetTimespecFunc(&_tcpDetectStatus_time);
- else
- {
- if (_tpcTimebuf >= TPC_PLUG_DETECT_TIMEOUT)
- {
- _DetectTpcPlugInTimeout();
- }
- }
- }
- int ElapsedTime(uint8_t *start)
- {
- int time = 0;
- struct ParsingResult
- {
- int result;
- int scanedElement;
- int year;
- int month;
- int mday;
- int hour;
- int min;
- int sec;
- int tz_hour;
- int tz_min;
- float minSec;
- }parsingResult;
- struct tm tmStart;
- struct timeb tbStart;
- memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
- if(strstr((char*)start, ".") != NULL)
- {
-
- if(strstr((char*)start, "Z") != NULL)
- {
-
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
- &parsingResult.year, &parsingResult.month, &parsingResult.mday,
- &parsingResult.hour, &parsingResult.min, &parsingResult.sec, &parsingResult.minSec);
- }
- else
- {
-
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
- &parsingResult.year, &parsingResult.month, &parsingResult.mday, &parsingResult.hour,
- &parsingResult.min, &parsingResult.sec, &parsingResult.minSec, &parsingResult.tz_hour,
- &parsingResult.tz_min);
- }
- }
- else
- {
-
- if(strstr((char*)start, "Z") != NULL)
- {
-
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
- &parsingResult.year, &parsingResult.month, &parsingResult.mday,
- &parsingResult.hour, &parsingResult.min, &parsingResult.sec);
- }
- else
- {
-
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
- &parsingResult.year, &parsingResult.month, &parsingResult.mday, &parsingResult.hour,
- &parsingResult.min, &parsingResult.sec, &parsingResult.tz_hour, &parsingResult.tz_min);
- }
- }
- if(parsingResult.scanedElement >= 6)
- {
- tmStart.tm_year = parsingResult.year - 1900;
- tmStart.tm_mon = parsingResult.month - 1;
- tmStart.tm_mday = parsingResult.mday;
- tmStart.tm_hour = parsingResult.hour;
- tmStart.tm_min = parsingResult.min;
- tmStart.tm_sec = parsingResult.sec;
- tmStart.tm_gmtoff = 0;
- tbStart.time = mktime(&tmStart);
- tbStart.timezone = 0;
- tbStart.millitm = 0;
- tbStart.time -= (parsingResult.tz_hour * 3600) + (parsingResult.tz_min * 60 * (parsingResult.tz_hour >= 0 ? 1 : -1));
- if(DiffTimebWithNowSec(tbStart) <= 0)
- time = 0;
- else
- time = DiffTimebWithNowSec(tbStart);
- }
- else
- {
- PRINTF_FUNC("OCMF - Start date parsing error.\n");
- }
- return time;
- }
- void SaveTheParentId(byte gun_index)
- {
-
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memcpy(chargingInfo[gun_index]->ParentIdTag,
- ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag,
- ARRAY_SIZE(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool CheckTheParentId(byte gun_index)
- {
- bool result = false;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp((char *)chargingInfo[gun_index]->ParentIdTag, "") != EQUAL)
- {
- PRINTF_FUNC("IdTag = %s\n", ShmOCPP16Data->Authorize.IdTag);
- PRINTF_FUNC("ParentIdTag = %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
- if (strcmp((char *)chargingInfo[gun_index]->ParentIdTag, (char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == EQUAL &&
- strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) > 0)
- {
- memcpy(chargingInfo[gun_index]->StartUserId, ShmOCPP16Data->Authorize.IdTag,
- sizeof(ShmOCPP16Data->Authorize.IdTag));
- result = true;
- }
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return result;
- }
- int main(void)
- {
- if(CreateShareMemory() == 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("CreatShareMemory NG \n");
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- PRINTF_FUNC("===== Boot and Initialization start ===== \n");
- if (!InitialSystemDefaultConfig())
- {
- DEBUG_ERROR_MSG("InitialSystemDefaultConfig NG \n");
- StopProcessingLoop();
- }
- PRINTF_FUNC("CheckConnectorTypeStatus and CheckIsAlternatvie \n");
- CheckGunTypeFromHw();
- CheckIsAlternatvieByModelName();
- InitialShareMemoryInfo();
- PRINTF_FUNC("InitialShareMemoryInfo OK. \n");
- if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
- PRINTF_FUNC("ChargerType (IEC or UL) = IEC \n");
- else
- PRINTF_FUNC("ChargerType (IEC or UL) = UL \n");
- ChangeLcmByIndex(_LCM_INIT);
- if (!CheckConnectorTypeStatus() && !DEBUG_ALSTON)
- isModelNameMatch = false;
- Initialization();
- PRINTF_FUNC("===== Initial Complete ===== \n");
- PRINTF_FUNC("===== Spawn all Task and self test start ===== \n");
- SpawnTask();
- if (!isModelNameMatch)
- {
-
- PRINTF_FUNC("*** Module Name & HW info none match : Please check if the Model name and HW are matched. ***\n");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
- ChangeLcmByIndex(_LCM_FIX);
- sleep(3);
- KillTask();
- StopProcessingLoop();
- }
- PRINTF_FUNC("Module Name & HW info correct. \n");
- CreateTimeoutFork();
- if (!DEBUG_ALSTON)
- {
- PRINTF_FUNC("Self test run..\n");
- SelfTestRun();
- }
- else
- {
- sleep(3);
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
- }
- StopSystemTimeoutDet();
- if (!DEBUG_ALSTON &&
- (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
- ShmPsuData->Work_Step == _NO_WORKING ||
- ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES ||
- strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == EQUAL))
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != _ALARM_LEVEL_CRITICAL)
- {
- if (!DisplaySelfTestFailReason() &&
- ShmDcCommonData->rebootCount < 1)
- {
- PRINTF_FUNC("=======Soft reboot for retry self-test======= \n");
- SetupRebootCount(1);
- sleep(3);
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- else if (ShmDcCommonData->rebootCount < 1)
- {
- PRINTF_FUNC("=======Soft reboot for retry self-test (Normal)======= \n");
- SetupRebootCount(1);
- sleep(3);
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- else
- SetupRebootCount(0);
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- ChargingAlarmProcess(gun_index);
- }
- sleep(3);
- KillTaskExceptDetectTask();
- StopProcessingLoop();
- }
- else
- {
- SetupRebootCount(0);
- }
- PRINTF_FUNC("===== Self Test Complete ===== \n");
- PRINTF_FUNC("===== Finally Create DB ===== \n");
-
- if(DB_Open(localDb) != PASS)
- {
- PRINTF_FUNC("DB_Open fail. \n");
- isDb_ready = false;
- }
- else
- {
- isDb_ready = true;
- for (int _acIndex = 0; _acIndex < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _acIndex++)
- {
- byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
- ac_chargingInfo[0]->IsAvailable = DB_Get_Operactive(localDb, _acIndex + hasDc);
- }
- for(int _index=0; _index< ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;_index++)
- {
- chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
- chargingInfo[_index]->PowerConsumption = DB_Get_PowerConsumption(localDb, _index);
- }
- DB_Reboot_Record(localDb);
- }
-
- for (int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index ++)
- {
- if (chargingInfo [_index]->IsAvailable == NO)
- SetChargerMode ( _index, SYS_MODE_MAINTAIN );
- else
- SetChargerMode ( _index, SYS_MODE_IDLE );
- }
- if (NetworkDB_Open(networkDb) != PASS)
- {
- PRINTF_FUNC("NetworkDB_Open fail. \n");
- }
- ChangeLcmByIndex(_LCM_IDLE);
- sleep(1);
- CreateRfidFork();
- sleep(1);
- if (!DEBUG_ALSTON)
- {
- PRINTF_FUNC("===== Create chk system Task ===== \n");
- CreateCheckSystemTaskFork();
- }
- PRINTF_FUNC("===== Create DB End ===== \n");
- if (CheckTheSystemType())
- {
- PRINTF_FUNC("Can't confirm the system type. (reboot) \n");
- sleep(3);
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- PRINTF_FUNC("===== Charger info ===== ");
- PRINTF_FUNC("SW Version = %s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
- PRINTF_FUNC("Bootloader = %s", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
- PRINTF_FUNC("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
- InfoSystemType();
- InfoLcmVersion();
- InfoFwSlotStatusLog();
- AdjustChargerCurrent();
- PRINTF_FUNC("===== Charger info End ===== ");
- GetTimespecFunc(&_cmdMainPriority_time);
- _ocppProfileChkFlag_1 = 0;
- _ocppProfileChkFlag_2 = 0;
- KillOcppTask();
- int _mainTimebuf = 0;
- for (;;)
- {
- if (ShmDcCommonData->_isAutoRunTest != _isTestRun)
- {
- if (ShmDcCommonData->_isAutoRunTest == YES)
- {
- GetTimespecFunc(&_autoRuntestTime);
- }
- _isTestRun = ShmDcCommonData->_isAutoRunTest;
- }
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- ocpp_ac_chk_availability_cmd();
- ocpp_ac_chk_unlock_cmd();
- }
- ocpp_auto_response_BootNotification();
- ocpp_chk_reset_cmd(NO);
- ButtonTriggerEvent();
- if (!DEBUG_ALSTON)
- ChkPrimaryStatus();
- if ((IsConnectorWholeIdle() ||
- ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX))
- {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0)
- {
- sleep(1);
- continue;
- }
-
- ocpp_chk_remoteStart_cmd();
-
- ScannerCardProcess();
-
- ClearAlarmCodeWhenAcOff();
-
- CheckReturnToChargingConn();
- if ((_acgunIndex > 0 && isDetectPlugin() && !isCardScan))
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- _mainTimebuf = GetTimeoutValue(&_cmdMainPriority_time);
- if (ShmDcCommonData->_tpcPlugDetectState == _TPC_PLUG_DETECT_STATUS_WAIT)
- CheckTpcTimeout();
- if (_mainTimebuf < 0)
- GetTimespecFunc(&_cmdMainPriority_time);
- if (_mainTimebuf >= 5)
- {
- if (ShmPsuData->PsuStopChargeFlag)
- Check267Alarm();
- CheckTask();
- Run4gResetProc();
- GetSystemDate();
- bool isBothCharging = true;
- byte chargingCount = 0;
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (_verifyMechanism == VERIFY_MECHANISM_BAZEL8)
- {
- if ((chargingInfo[_index]->SystemStatus == SYS_MODE_IDLE ||
- chargingInfo[_index]->SystemStatus == SYS_MODE_RESERVATION ||
- chargingInfo[_index]->SystemStatus == SYS_MODE_MAINTAIN) &&
- chargingInfo[_index]->ConnectorPlugIn)
- {
- CheckPaymentID();
- }
- }
- UpdateDcMeterPowerConsumption(_index);
- if ((chargingInfo[_index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[_index]->SystemStatus <= SYS_MODE_CHARGING) ||
- (chargingInfo[_index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[_index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
- {
- ocpp_chargingProfile_process(_index);
- if (chargingInfo[_index]->SystemStatus == SYS_MODE_CHARGING)
- {
- if (_index == 0 && _ocppProfileChkFlag_1 >= 12)
- {
- ocpp_lift_profileReq_cmd ( _index );
- _ocppProfileChkFlag_1 = 0;
- }
- else if (_index == 1 && _ocppProfileChkFlag_2 >= 12)
- {
- ocpp_lift_profileReq_cmd ( _index );
- _ocppProfileChkFlag_2 = 0;
- }
- }
- else if (chargingInfo[_index]->SystemStatus != SYS_MODE_CHARGING)
- {
- if (_index == 0)
- {
- ocpp_lift_profileReq_cmd ( _index );
- _ocppProfileChkFlag_1 = 0;
- }
- else if (_index == 1)
- {
- ocpp_lift_profileReq_cmd ( _index );
- _ocppProfileChkFlag_2 = 0;
- }
- }
- else
- {
- if (_index == 0)
- _ocppProfileChkFlag_1++;
- else if (_index == 1)
- _ocppProfileChkFlag_2++;
- }
- if (chargingInfo[_index]->SystemStatus >= SYS_MODE_CHARGING &&
- chargingInfo[_index]->SystemStatus <= SYS_MODE_ALARM)
- {
- DB_Update_PowerConsumption(localDb, _index, chargingInfo[_index]->PowerConsumption);
- }
- chargingCount++;
- }
-
- CheckConnectorOTP(_index);
- if (ShmSmartBoxData->ConnectorStatus[_index].ConnectorStaus != _CONNECTOR_STATUS_USING)
- isBothCharging = false;
-
- ChkOcmfRecord(_index);
-
- if (chargingInfo[_index]->ReservationId != NO_RESERVE)
- chargingInfo[_index]->SystemStatus = SYS_MODE_RESERVATION;
- if (chargingInfo[_index]->SystemStatus == SYS_MODE_RESERVATION)
- {
- if (opcc_chk_reserve_expired(_index))
- {
- chargingInfo[_index]->SystemStatus = SYS_MODE_IDLE;
- }
- }
- }
- _chargingCount = chargingCount;
- if (isBothCharging)
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_BOTH;
- else
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_NORMAL;
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
- {
- if ((ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING) ||
- (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
- {
- ocpp_ac_chargingProfile_process();
- }
- if ((ac_chargingInfo[_index]->SystemStatus >= SYS_MODE_PREPARING &&
- ac_chargingInfo[_index]->SystemStatus <= SYS_MODE_CHARGING))
- {
- if (ac_chargingInfo[_index]->SystemStatus == SYS_MODE_CHARGING &&
- _ac_ocppProfileChkFlag == 12)
- {
- ocpp_ac_lift_profileReq_cmd(_index);
- _ac_ocppProfileChkFlag = 0;
- }
- else if (ac_chargingInfo[_index]->SystemStatus != SYS_MODE_CHARGING)
- {
- ocpp_ac_lift_profileReq_cmd(_index);
- _ac_ocppProfileChkFlag = 0;
- }
- else
- _ac_ocppProfileChkFlag++;
- }
- }
- CheckOcppCostAndPrice();
- CheckAuthrizeByEvccid();
- GetTimespecFunc(&_cmdMainPriority_time);
- CreateWatchdog();
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'L')
- CheckStatusOfMeter();
-
- ReviewCriticalAlarm();
- errCollect.GunErrMessage = 0;
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- CheckAcOcppProfileConfirm();
- ocpp_ac_chk_reserved_cmd();
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
-
-
- CheckSystemErrorFunction(gun_index);
-
- CheckRelayWeldingOrDrivingFault(gun_index);
-
- CollectError(gun_index);
- ocpp_chk_reserved_cmd(gun_index);
- ocpp_chk_availability_cmd(gun_index);
- ocpp_chk_unlock_cmd(gun_index);
- ocpp_default_errorCode_cmd(gun_index);
-
- CheckOcppProfileConfirm(gun_index);
-
- switch(chargingInfo[gun_index]->SystemStatus)
- {
- case SYS_MODE_IDLE:
- case SYS_MODE_RESERVATION:
- case SYS_MODE_MAINTAIN:
- case SYS_MODE_FAULT:
- {
- if (isModeChange(gun_index))
- {
- if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_IDLE)
- {
- PRINTF_FUNC("================= SYS_MODE_IDLE (%x) ================ \n", gun_index);
- chargingInfo[gun_index]->ReservationId = NO_RESERVE;
- }
- else if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_RESERVATION)
- {
- PRINTF_FUNC("================= SYS_MODE_RESERVATION (%x) ================ \n", gun_index);
- PRINTF_FUNC("================= Id : %s ================ \n", ShmDcCommonData->_reserved_UserId[gun_index]);
- }
- else if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_MAINTAIN)
- {
- PRINTF_FUNC("================= SYS_MODE_MAINTAIN (%x) ================ \n", gun_index);
- }
- chargingInfo[gun_index]->PresentChargedDuration = 0;
- chargingInfo[gun_index]->RemainChargingDuration = 0;
- chargingInfo[gun_index]->PresentChargingVoltage = 0;
- chargingInfo[gun_index]->PresentChargingCurrent = 0;
- strcpy((char *)chargingInfo[gun_index]->StartDateTime, "00:00:00");
- strcpy((char *)chargingInfo[gun_index]->StopDateTime, "00:00:00");
- memset((char *)chargingInfo[gun_index]->StartUserId, 0, sizeof(chargingInfo[gun_index]->StartUserId));
- memset((char *)chargingInfo[gun_index]->EVCCID, 0, sizeof(chargingInfo[gun_index]->EVCCID));
- _isSendStartTransaction[gun_index] = false;
- ocpp_auto_response_StopTransationConf(gun_index);
- ocpp_auto_response_StopTransationConfPH(gun_index);
- ClearEnergyTimePeriod(gun_index);
- ocpp_clear_stopReason(gun_index);
- ocpp_clear_stopTansaction_Idtag(gun_index);
- ocpp_auto_response_StartTransationConf(gun_index);
- ocpp_auto_response_StartTransationConfPH(gun_index);
- ShmDcCommonData->startTransactionFlag[gun_index] = START_TRANSATION_STATUS_WAIT;
- ShmDcCommonData->_authWithCcidFlag[gun_index] = _CCID_NONE;
- ShmDcCommonData->startTransactionID[gun_index] = 0;
- ShmDcCommonData->_useVersion = _CDFA_VERSION_NONE;
- ShmDcCommonData->cdfaInfor[gun_index]._ctepEnergyCost = 0;
- ShmDcCommonData->cdfaInfor[gun_index]._ctepParkingFee = 0;
- ShmDcCommonData->cdfaInfor[gun_index]._ctepTotalCost = 0;
- ShmDcCommonData->cdfaInfor[gun_index]._prekWhPrice = 0;
- ShmDcCommonData->cdfaInfor[gun_index]._prehourPrice = 0;
- ShmDcCommonData->cdfaInfor[gun_index]._preEnergyCost = 0;
- ShmDcCommonData->cdfaInfor[gun_index]._preParkingFee = 0;
- ShmDcCommonData->remoteStartAuthFlag[gun_index] = NO;
- memset((char *)ShmDcCommonData->cdfaInfor[gun_index]._preTimestamp, 0, sizeof(ShmDcCommonData->cdfaInfor[gun_index]._preTimestamp));
- memset((char *)ShmDcCommonData->cdfaInfor[gun_index]._preQrCodeText, 0, sizeof(ShmDcCommonData->cdfaInfor[gun_index]._preQrCodeText));
- _ChargingProfilePwBuffer[gun_index] = 0;
- _ChargingMaxProfilePwBuffer[gun_index] = 0;
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].ActionCmd = _DC_METER_TRANSACTION_ACTION_NONE;
- PresentChargedAcEnergyClear(gun_index);
- for(byte _vCount = 0; _vCount < VOLTAGE_SAMPLE_COUNT; _vCount++)
- {
- ShmDcCommonData->_outputVoltageSapmle[gun_index][_vCount] = 0;
- }
- }
- if (chargingInfo[gun_index]->deratingByConnOtp.deratingIndex != 0)
- chargingInfo[gun_index]->deratingByConnOtp.deratingIndex = 0;
-
- if (chargingInfo [gun_index]->IsAvailable == NO &&
- chargingInfo[gun_index]->SystemStatus != SYS_MODE_MAINTAIN)
- {
- SetChargerMode(gun_index, SYS_MODE_MAINTAIN);
- }
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_CRITICAL)
- {
- if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
- else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != SYS_MODE_IDLE &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != SYS_MODE_RESERVATION &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != SYS_MODE_MAINTAIN &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != SYS_MODE_FAULT)
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- ClearDetectPluginFlag();
- ocpp_set_errCode_cmd(gun_index);
- SetChargerMode(gun_index, SYS_MODE_FAULT);
- }
- else
- {
- if (PrecheckIsPass(gun_index))
- {
- if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_FAULT)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- SetChargerMode(gun_index, SYS_MODE_IDLE);
- }
- if (chargingInfo[gun_index]->ReservationId == NO_RESERVE)
- CcidAuthorizationProcessing(gun_index);
-
- {
-
-
- if(isDetectPlugin())
- {
-
- if (chargingInfo[gun_index]->RemoteStartFlag == YES)
- {
- if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
- chargingInfo[gun_index]->IsAvailable)
- {
- PRINTF_FUNC("Conn %d Start Charging : Remote \n", gun_index);
- chargingInfo[gun_index]->RemoteStartFlag = NO;
- chargingInfo[gun_index]->isRemoteStart = YES;
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- SetChargerMode(gun_index, SYS_MODE_MODE_REASSIGN_CHECK);
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
- ClearDetectPluginFlag();
- continue;
- }
- }
- else if (chargingInfo[gun_index]->ReservedStartFlag == YES)
- {
- if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
- chargingInfo[gun_index]->IsAvailable)
- {
- chargingInfo[gun_index]->ReservedStartFlag = NO;
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmDcCommonData->_reserved_UserId[gun_index]);
- PRINTF_FUNC("Conn %d Start Charging : Reserved CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- strcpy((char *)ShmDcCommonData->_reserved_UserId[gun_index], "");
-
- SetChargerMode(gun_index, SYS_MODE_MODE_REASSIGN_CHECK);
- ClearDetectPluginFlag();
- continue;
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE)
- {
- if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
- chargingInfo[gun_index]->IsAvailable &&
- chargingInfo[gun_index]->SystemStatus == SYS_MODE_IDLE)
- {
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
- SaveTheParentId(gun_index);
- PRINTF_FUNC("Conn %d Start Charging : RFID CardNumber = %s, ParentId = %s \n",
- gun_index, chargingInfo[gun_index]->StartUserId,
- chargingInfo[gun_index]->ParentIdTag);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-
- SetChargerMode(gun_index, SYS_MODE_MODE_REASSIGN_CHECK);
- ClearDetectPluginFlag();
- continue;
- }
- }
- if (!isCardScan &&
- (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected ||
- (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)))
- {
-
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
- (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable))
- {
- PRINTF_FUNC("Conn %d Start Charging : Plug and charing \n", gun_index);
- bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
- if (isCanStartChargingFlag)
- {
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- SetChargerMode(gun_index, SYS_MODE_MODE_REASSIGN_CHECK);
- ClearDetectPluginFlag();
- ocpp_get_freeVendor(gun_index);
- continue;
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- ocpp_remote_start_wait_cmd()))
- {
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
- {
- if (ac_chargingInfo[0]->ConnectorPlugIn == AC_SYS_A)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE &&
- ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_WAIT_FOR_PLUG)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
- }
- }
- }
- }
- else
- {
- SetChargerMode(gun_index, SYS_MODE_FAULT);
- if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
- }
- ReleaseSysAlarmCode(gun_index);
- }
- }
- break;
- case SYS_MODE_MODE_REASSIGN_CHECK:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================= SYS_MODE_MODE_REASSIGN_CHECK (%x) ================ \n", gun_index);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- StopSystemTimeoutDet();
- ShmDcCommonData->_tpcPlugDetectState = _TPC_PLUG_DETECT_STATUS_NONE;
- chargingInfo[gun_index]->ReservationId = NO_RESERVE;
- ocpp_sub_set_remote_start_transaction_req(gun_index, NO);
- }
- ocpp_clear_errorCode_cmd(gun_index);
- if (ShmSmartBoxData->ConnectorStatus[gun_index].ConnectorStaus == _CONNECTOR_STATUS_WAIT)
- {
- PRINTF_FUNC("Conn_%d wait for Psu Module. \n", gun_index);
- SetChargerMode(gun_index, SYS_MODE_REASSIGN);
- }
- else if (ShmSmartBoxData->ConnectorStatus[gun_index].ConnectorStaus == _CONNECTOR_STATUS_USING)
- {
- PRINTF_FUNC("Conn_%d start charging with Psu Module. \n", gun_index);
- SetChargerMode(gun_index, SYS_MODE_PREPARING);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- if (IsNoneSelectAcModule())
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- else
- {
- if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- ocpp_remote_start_wait_cmd ()))
- {
- DisplayPageChkByAcModule();
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case SYS_MODE_REASSIGN:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== SYS_MODE_REASSIGN (%x) ================ \n", gun_index);
- }
- ocpp_clear_errorCode_cmd(gun_index);
- if (ShmSmartBoxData->ConnectorStatus[gun_index].ConnectorStaus == _CONNECTOR_STATUS_USING)
- SetChargerMode(gun_index, SYS_MODE_PREPARING);
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- if (IsNoneSelectAcModule())
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- else
- {
- if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- ocpp_remote_start_wait_cmd ()))
- {
- DisplayPageChkByAcModule();
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case SYS_MODE_PREPARING:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("=================== SYS_MODE_PREPARING (%x) =============== \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
- }
- ocpp_clear_errorCode_cmd(gun_index);
- if (chargingInfo[gun_index]->AvailableChargingPower > 0 &&
- ShmPsuData->Work_Step == _WORK_CHARGING)
- {
- SetChargerMode(gun_index, SYS_MODE_PREPARE_FOR_EV);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- if (IsNoneSelectAcModule())
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- else
- {
- if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- ocpp_remote_start_wait_cmd ()))
- {
- DisplayPageChkByAcModule();
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case SYS_MODE_PREPARE_FOR_EV:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== SYS_MODE_PREPARE_FOR_EV (%x) ================ \n", gun_index);
- _presentChargingTimeBuf[gun_index] = 0;
-
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
- ShmDcCommonData->startTransactionFlag[gun_index] = START_TRANSATION_STATUS_WAIT;
-
- PRINTF_FUNC("StartUserId = %s \n", chargingInfo[gun_index]->StartUserId);
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- strcmp((char *)chargingInfo[gun_index]->StartUserId, "") != EQUAL ||
- chargingInfo[gun_index]->isRemoteStart == YES)
- {
- SendStartTransactionReq(gun_index);
- }
- ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
- }
- ocpp_clear_errorCode_cmd(gun_index);
-
- if(chargingInfo [gun_index]->Type == _Type_CCS
- && ShmDcCommonData->enObtainAuthorizbyCCID)
- {
- CheckCcidAuthorizationFunction(gun_index);
- if (!_isSendStartTransaction[gun_index])
- {
- if (ShmDcCommonData->_authWithCcidFlag[gun_index] == _CCID_AUTHCOMP)
- {
- PRINTF_FUNC("_CCID_AUTHCOMP \n");
- SendStartTransactionReq(gun_index);
- }
- else if (ShmDcCommonData->_authWithCcidFlag[gun_index] == _CCID_AUTHFAIL)
- {
- PRINTF_FUNC("_CCID_AUTHFAIL \n");
- ChargingTerminalProcess(gun_index);
- }
- }
- }
-
- ShmDcCommonData->startTransactionFlag[gun_index] = TransactionResponseStatus(gun_index);
-
- ChkNoCharging(gun_index);
-
- ChkConnectorBoardStop(gun_index);
-
- ChkPsuErrorStop(gun_index);
- if (ocpp_chk_remoteStop_cmd(gun_index) == YES ||
- WifiScheduleStop(gun_index) || isStartTransactionResponsedFail(gun_index) == YES)
- {
-
- ChargingTerminalProcess(gun_index);
- if (ShmDcCommonData->startTransactionFlag[gun_index] == START_TRANSATION_STATUS_FAIL)
- PRINTF_FUNC("StartTransaction req fail. (%d) \n", gun_index);
- else if (ShmDcCommonData->startTransactionFlag[gun_index] == START_TRANSATION_STATUS_WAIT)
- PRINTF_FUNC("StartTransaction req timeout. (%d) \n", gun_index);
- }
-
- if (isEvGunLocked(gun_index) == YES)
- {
- if (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'P')
- {
- ConfigOcmfInfo(gun_index);
- DB_Insert_ocmf(localDb, gun_index);
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].ActionCmd = _DC_METER_TRANSACTION_ACTION_START;
- }
- SetChargerMode(gun_index, SYS_MODE_PREPARE_FOR_EVSE);
- }
-
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- if (IsNoneSelectAcModule())
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZ_FAIL)
- { }
- else
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- else
- {
- if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- ocpp_remote_start_wait_cmd ()))
- {
- DisplayPageChkByAcModule();
- }
- }
- if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_NONE)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZ_FAIL)
- {}
- else
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- }
- break;
- case SYS_MODE_PREPARE_FOR_EVSE:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== SYS_MODE_PREPARE_FOR_EVSE (%x) ================ \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
- }
-
-
- if(chargingInfo [gun_index]->Type == _Type_GB
- && ShmDcCommonData->enObtainAuthorizbyCCID)
- {
- CheckCcidAuthorizationFunction(gun_index);
-
- if (!_isSendStartTransaction[gun_index])
- {
- if (ShmDcCommonData->_authWithCcidFlag[gun_index] == _CCID_AUTHCOMP)
- {
- PRINTF_FUNC("_CCID_AUTHCOMP \n");
- SendStartTransactionReq(gun_index);
- }
- else if (ShmDcCommonData->_authWithCcidFlag[gun_index] == _CCID_AUTHFAIL)
- {
- PRINTF_FUNC("_CCID_AUTHFAIL \n");
- ChargingTerminalProcess(gun_index);
- }
- }
-
- if(isStartTransactionResponsedFail(gun_index) == YES)
- ChargingTerminalProcess(gun_index);
- ShmDcCommonData->startTransactionFlag[gun_index] = TransactionResponseStatus(gun_index);
- }
- ocpp_clear_errorCode_cmd(gun_index);
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
-
- if (isPrechargeStatus_chademo(gun_index) >= 6)
- {
-
- SetChargerMode(gun_index, SYS_MODE_CHARGING);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
-
-
-
- if (isPrechargeStatus_gb(gun_index) >= 10 &&
- ShmDcCommonData->startTransactionFlag[gun_index] == START_TRANSATION_STATUS_PASS)
- {
- SetChargerMode(gun_index, SYS_MODE_CHARGING);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS)
- {
-
- if ((chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS ||
- chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING))
- {
- SetChargerMode(gun_index, SYS_MODE_CCS_PRECHARGE_STEP0);
- }
- }
- RecordGfdResult(gun_index);
-
- ChkNoCharging ( gun_index );
-
- ChkConnectorBoardStop(gun_index);
-
- ChkPsuErrorStop(gun_index);
-
- ChkBackendStop(gun_index);
-
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- if (IsNoneSelectAcModule())
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- else
- {
- if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- ocpp_remote_start_wait_cmd ()))
- {
- DisplayPageChkByAcModule();
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-
- if(ShmDcCommonData->_authWithCcidFlag [gun_index] != _CCID_CHECK)
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-
- }
- }
- break;
- case SYS_MODE_CHARGING:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== SYS_MODE_CHARGING (%x) ================ \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- ftime(&startChargingTime[gun_index]);
- ocpp_clear_idTag_cmd(gun_index);
- ChangeStartOrStopDateTime(YES, gun_index);
- if (_isTestRun == YES)
- {
- GetTimespecFunc(&_autoRuntestTime);
- }
- chargingInfo[gun_index]->EvBatteryStartSoc = chargingInfo[gun_index]->EvBatterySoc;
- }
- ocpp_clear_errorCode_cmd(gun_index);
- if (_isTestRun == YES)
- {
- if (GetTimeoutValue(&_autoRuntestTime) > 60)
- {
- ChargingTerminalProcess(gun_index);
- }
- }
- SavePresentChargedDuration(gun_index);
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- if (ShmDcCommonData->minOutputCur != 0 &&
- chargingInfo[gun_index]->PresentChargedDuration >= 10 &&
- chargingInfo[gun_index]->PresentChargingCurrent < ShmDcCommonData->minOutputCur)
- {
-
- RecordAlarmCode(gun_index, "012320");
- ChargingTerminalProcess(gun_index);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- if (ShmDcCommonData->minOutputCur != 0 &&
- chargingInfo[gun_index]->PresentChargedDuration >= 10 &&
- chargingInfo[gun_index]->PresentChargingCurrent < ShmDcCommonData->minOutputCur)
- {
-
- RecordAlarmCode(gun_index, "012322");
- ChargingTerminalProcess(gun_index);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS)
- {
- if (ShmDcCommonData->minOutputCur != 0 &&
- chargingInfo[gun_index]->PresentChargedDuration >= 10 &&
- chargingInfo[gun_index]->PresentChargingCurrent < ShmDcCommonData->minOutputCur)
- {
-
- RecordAlarmCode(gun_index, "012321");
- ChargingTerminalProcess(gun_index);
- }
- }
- RecordGfdResult(gun_index);
-
- ChkNoCharging(gun_index);
-
- ChkConnectorBoardStop(gun_index);
-
- ChkPsuErrorStop(gun_index);
-
- ChkBackendStop(gun_index);
-
- ChkConfigurationStop(gun_index);
-
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- if (IsNoneSelectAcModule() || !stopChargingChkByCard)
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZ_FAIL)
- { }
- else
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- else
- {
- if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- ocpp_remote_start_wait_cmd ()))
- {
- DisplayPageChkByAcModule();
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
- if (!stopChargingChkByCard)
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case SYS_MODE_ALARM:
- case SYS_MODE_TERMINATING:
- {
- if (isModeChange(gun_index))
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip ||
- (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen && ShmDcCommonData->_tiltSensorStep == _TILT_SENSOR_STEP_NONE))
- ocpp_set_stopReason_by_cmd(gun_index, "EmergencyStop");
- else
- ocpp_set_stopReason_by_cmd(gun_index, "Local");
- ocpp_copy_stopReason2maintainServer(gun_index);
- if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_ALARM)
- {
- PRINTF_FUNC("================== SYS_MODE_ALARM (%x) ================ \n", gun_index);
- if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL)
- {
- ocpp_auto_response_StartTransationConf(gun_index);
- ocpp_auto_response_StartTransationConfPH(gun_index);
- if (_isSendStartTransaction[gun_index])
- {
- ocpp_set_stopTransation_cmd(gun_index);
- ocpp_set_stopTransationPH_cmd(gun_index);
- }
- }
- TheEndCharging(gun_index);
- }
- else
- {
- PRINTF_FUNC("================== SYS_MODE_TERMINATING (%x) ================ \n", gun_index);
- }
- ShmDcCommonData->_returnIdleHoldFlag[gun_index] = NO;
- StopGunInfoTimeoutDet(gun_index);
- }
- if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_ALARM)
- {
- ocpp_set_errCode_cmd(gun_index);
- }
- if (chargingInfo[gun_index]->Type == _Type_Chademo) { }
- else if (chargingInfo[gun_index]->Type == _Type_GB) { }
- else if (chargingInfo[gun_index]->Type == _Type_CCS) { }
- if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_ALARM)
- {
- if (chargingInfo [gun_index]->ConnectorPlugIn == NO)
- {
- if (ShmDcCommonData->_returnIdleHoldFlag [gun_index] == NO &&
- GetTimeoutValue ( & chargingInfo [gun_index]->ConnectorTimeout ) >= 10)
- {
- ShmDcCommonData->_returnIdleHoldFlag [gun_index] = YES;
- StopGunInfoTimeoutDet ( gun_index );
- StartGunInfoTimeoutDet ( gun_index, Timeout_EvseCompleteDet );
- }
- else if (ShmDcCommonData->_returnIdleHoldFlag [gun_index] == YES &&
- GetTimeoutValue ( & chargingInfo [gun_index]->ConnectorTimeout ) >= 2)
- {
- SetChargerMode ( gun_index, SYS_MODE_IDLE );
- }
- }
- if (_isTestRun == YES &&
- GetTimeoutValue(&chargingInfo[gun_index]->ConnectorTimeout) >= 10)
- {
- SetChargerMode(gun_index, SYS_MODE_IDLE);
- }
- }
- else
- {
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- if (isEvGunLocked(gun_index) == NO ||
- isPrechargeStatus_chademo(gun_index) <= 0)
- {
- SetChargerMode(gun_index, SYS_MODE_COMPLETE);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- if (isEvGunLocked(gun_index) == NO ||
- isPrechargeStatus_gb(gun_index) <= 0)
- {
- SetChargerMode(gun_index, SYS_MODE_COMPLETE);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS)
- {
- if (isEvGunLocked(gun_index) == NO &&
- (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
- isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14))
- {
- SetChargerMode(gun_index, SYS_MODE_COMPLETE);
- }
- }
- }
- if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_ALARM &&
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].OcmfInfoReady)
- {
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].OcmfInfoReady = NO;
- ocpp_ocmf_information(gun_index);
- DB_Update_ocmf(localDb, gun_index);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- if (IsNoneSelectAcModule())
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- else
- {
- if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- ocpp_remote_start_wait_cmd ()))
- {
- DisplayPageChkByAcModule();
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case SYS_MODE_COMPLETE:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== SYS_MODE_COMPLETE (%x) ================ \n", gun_index);
- if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL)
- {
- ocpp_set_errCode_cmd(gun_index);
- ocpp_auto_response_StartTransationConf(gun_index);
- ocpp_auto_response_StartTransationConfPH(gun_index);
- if (_isSendStartTransaction[gun_index])
- {
- ocpp_set_stopTransation_cmd(gun_index);
- ocpp_set_stopTransationPH_cmd(gun_index);
- }
- }
- TheEndCharging(gun_index);
- ShmDcCommonData->_returnIdleHoldFlag[gun_index] = NO;
- }
- ocpp_clear_errorCode_cmd(gun_index);
- if (chargingInfo[gun_index]->ConnectorPlugIn == NO)
- {
- if (ShmDcCommonData->_returnIdleHoldFlag[gun_index] == NO &&
- GetTimeoutValue(&chargingInfo[gun_index]->ConnectorTimeout) >= 10)
- {
- ShmDcCommonData->_returnIdleHoldFlag[gun_index] = YES;
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
- }
- else if (ShmDcCommonData->_returnIdleHoldFlag[gun_index] == YES &&
- GetTimeoutValue(&chargingInfo[gun_index]->ConnectorTimeout) >= 2)
- {
- SetChargerMode(gun_index, SYS_MODE_IDLE);
- }
- }
- if (_isTestRun == YES &&
- GetTimeoutValue(&chargingInfo[gun_index]->ConnectorTimeout) >= 10)
- {
- SetChargerMode(gun_index, SYS_MODE_IDLE);
- }
- if (ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[gun_index].OcmfInfoReady)
- {
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction [gun_index].OcmfInfoReady = NO;
- ocpp_ocmf_information(gun_index);
- DB_Update_ocmf(localDb, gun_index);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- if (IsNoneSelectAcModule())
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- else
- {
- if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- ocpp_remote_start_wait_cmd ()))
- {
- DisplayPageChkByAcModule();
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case SYS_MODE_CCS_PRECHARGE_STEP0:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== SYS_MODE_CCS_PRECHARGE_STEP0 (%x) ================ \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
- }
- ocpp_clear_errorCode_cmd(gun_index);
- RecordGfdResult(gun_index);
-
- ChkNoCharging(gun_index);
-
- ChkConnectorBoardStop(gun_index);
-
- ChkPsuErrorStop(gun_index);
-
- ChkBackendStop(gun_index);
-
-
- if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40)
- {
- if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
-
- {
- 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, SYS_MODE_CCS_PRECHARGE_STEP1);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- if (IsNoneSelectAcModule())
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- else
- {
- if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- ocpp_remote_start_wait_cmd ()))
- {
- DisplayPageChkByAcModule();
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- break;
- }
- case SYS_MODE_CCS_PRECHARGE_STEP1:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== SYS_MODE_CCS_PRECHARGE_STEP1 (%x) ================ \n", gun_index);
- }
- ocpp_clear_errorCode_cmd(gun_index);
- RecordGfdResult(gun_index);
-
- ChkNoCharging(gun_index);
-
- ChkConnectorBoardStop(gun_index);
-
- ChkPsuErrorStop(gun_index);
-
- ChkBackendStop(gun_index);
-
-
- if (chargingInfo[gun_index]->RelayK1K2Status == YES)
- {
- chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
- SetChargerMode(gun_index, SYS_MODE_CHARGING);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- if (IsNoneSelectAcModule())
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
- ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- else
- {
- if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- ocpp_remote_start_wait_cmd ()))
- {
- DisplayPageChkByAcModule();
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- break;
- }
- }
- if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_IDLE ||
- chargingInfo[gun_index]->SystemStatus == SYS_MODE_RESERVATION ||
- chargingInfo[gun_index]->SystemStatus == SYS_MODE_MAINTAIN ||
- chargingInfo[gun_index]->SystemStatus == SYS_MODE_FAULT)
- {
- ocpp_chk_notificationMessage_cmd(gun_index);
- }
- }
- if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE)
- {
- ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
- }
- else
- {
- bool dcPageRun = false;
- if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
- {
- if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE)
- ChangeLcmByIndex(_LCM_IDLE);
- else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_PREPARING)
- ChangeLcmByIndex(_LCM_PRE_CHARGE);
- else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_CHARGING)
- ChangeLcmByIndex(_LCM_CHARGING);
- else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_TERMINATING ||
- ac_chargingInfo[0]->SystemStatus == SYS_MODE_COMPLETE)
- ChangeLcmByIndex(_LCM_COMPLETE);
- else
- dcPageRun = true;
- }
- else
- dcPageRun = true;
- if (dcPageRun)
- ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
- }
- bool isCharging = false;
- SystemAlarmCheck();
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- AlarmCheck(chargingInfo[gun_index]->Type);
- if (_isTestRun == YES)
- {
- if (IsGunUsing(gun_index))
- {
- isCharging = true;
- if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_COMPLETE ||
- chargingInfo[gun_index]->SystemStatus == SYS_MODE_ALARM)
- {
- GetTimespecFunc(&_autoRuntestTime);
- }
- }
- }
- }
- if (_isTestRun == YES)
- {
- if (!isCharging)
- {
- if (GetTimeoutValue(&_autoRuntestTime) >= 60)
- {
- DetectPluginStart();
- GetTimespecFunc(&_autoRuntestTime);
- }
- }
- else
- {
- ClearDetectPluginFlag();
- }
- }
- write(wtdFd, "a", 1);
- usleep(whileLoopTime);
- }
- return FAIL;
- }
|