1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619 |
- /*
- * main.c
- *
- * Created on: 2020年9月10日
- * Author: Wendell
- */
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <stdint.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #include "../../define.h"
- #include "Config.h"
- #include <stdbool.h>
- #include <dirent.h>
- #include "timeout.h"
- #include "Module_EvComm.h"
- #include "Module_CabinetParallel.h"
- #include "Common.h"
- #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 UPGRADE_DORC1 0x07
- #define UPGRADE_DORC2 0x08
- #define UPGRADE_DDRB 0x09
- #define SYSTEM_MIN_VOL 150
- #define MIN_OUTPUT_CUR 0
- #define AC_OUTPUT_VOL 220
- #define NO_DEFINE 255
- #define DEFAULT_AC_INDEX 2
- #define PSU_MIN_CUR 100
- #define MAIN_PRIORITY_INTERVAL 5
- #define CABINET_ROLE_TIMEOUT 3 // unit: 1s
- #define GUN_PREPARE_TIMEOUT 30
- #define GUN_EV_WAIT_TIMEOUT (120 + 10)
- #define GUN_EVSE_WAIT_TIMEOUT (60 + 10)
- #define GUN_COMP_WAIT_TIMEOUT 10
- #define GUN_PRECHARGING_TIMEOUT 60
- #define REBOOT_TIMEOUT 10
- #define RESET_TIMEOUT 10
- #define OCPP_COST_REQ_INTERVAL 1
- #define DISPENSER_RECONNECTE_TIME 30
- #define DISPENSER_AUTH_COMP_TIME 3
- #define FORCE_BALANCE_TIME 5
- #define DISPENSER_UPGRADE_TIME 600
- #define AC_CONTACTOR_REOPEN_TIME 60
- #define PSU_FAILURE_RESUME_TIME 180
- #define MAX_AC_CONTACTOR_COUNT 3
- #define STANDBY_TIME 600
- #define FAST_STANDBY_TIME 30
- #define WIRING_INFO_DELAY 30
- #define WAIT_REASSIGN_TIME 30 // unit: second
- #define MAX_REQUEST_CHARGING_TIME 15 // unit: second
- #define MIN_WAIT_PREPARNING_TIME 1 // unit: second
- #define FORCE_CHARGING_WAIT_EVSE 10 // unit: second
- #define TRY_RESET_4G_WIFI_TIME 300 // unit: second
- #define FAST_RESET_4G_WIFI_TIME 60 // unit: second
- #define ENERAGY_INTERVAL 1 // unit: second
- #define FAULT_RELEASE_TIME 1 // unit: second
- #define MAINTAIN_RECOVERY_TIME 1 // unit: second
- #define PARALLEL_WAIT_TIME 3 // unit: second
- #define START_UPGRADE_TIME 60 // unit: second
- #define PCABINET_UPGRADE_TIME 300 // unit: second
- #define MCABINET_UPGRADE_TIME 60 // unit: second
- #define CONNECTION_TIME_OFFSET 5 // unit: second
- #define AUTO_START_CHARGING "AutoStartCharging"
- #define CONTACTOR_AUTO_ON_OFF 0
- #define CONTACTOR_AUTO_ON_TIME 60
- #define CONTACTOR_AUTO_OFF_TIME 300
- char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
- unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
- int whileLoopTime = 10000; // 10 ms
- int wtdFd = -1;
- byte _authorizeIndex = NO_DEFINE;
- BOOL _UpgradeNeedReboot = FALSE;
- const byte Group_to_Location_2_Gun[GENERAL_GUN_QUANTITY] = {0, 1, 0, 0};
- const byte Location_to_Group_2_Gun[GENERAL_GUN_QUANTITY] = {0, 1, 0, 0};
- const byte GroupParallelRelay_2_Gun[GENERAL_GUN_QUANTITY][GENERAL_GUN_QUANTITY] =
- {
- {0, 1, 0, 0},
- {1, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0}
- };
- //Location: 1 2 3 4
- // Gun: 1 3 4 2
- //Parallel: 1 2 3
- //const byte Group_to_Location_4_Gun[GENERAL_GUN_QUANTITY] = {0, 3, 1, 2};
- //const byte Location_to_Group_4_Gun[GENERAL_GUN_QUANTITY] = {0, 2, 3, 1};
- //const byte GroupParallelRelay_4_Gun[GENERAL_GUN_QUANTITY][GENERAL_GUN_QUANTITY] =
- //{
- // {0, 3, 1, 2}, // group 0
- // {1, 0, 2, 3}, // group 1
- // {1, 3, 0, 2}, // group 2
- // {1, 3, 2, 0} // group 3
- //};
- //Location: 1 2 3 4
- // Gun: 1 4 3 2
- //Parallel: 1 2 3
- const byte Group_to_Location_4_Gun[GENERAL_GUN_QUANTITY] = {0, 3, 2, 1};
- const byte Location_to_Group_4_Gun[GENERAL_GUN_QUANTITY] = {0, 3, 2, 1};
- const byte GroupParallelRelay_4_Gun[GENERAL_GUN_QUANTITY][GENERAL_GUN_QUANTITY] =
- {
- {0, 3, 2, 1}, // group 0
- {1, 0, 3, 2}, // group 1
- {1, 3, 0, 2}, // group 2
- {1, 3, 2, 0} // group 3
- };
- 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 ChargingAlarmProcess(byte gunIndex);
- void InformOcppErrOccur(byte codeType);
- void SetOcppErrorCode(unsigned char _index, char *errCode);
- void SetOcppVendorErrorCode(unsigned char _index, char *vendorCode);
- void ReleaseAlarmCode(byte gunIndex);
- int DB_Open(sqlite3 *db);
- int DB_Insert_Record(sqlite3 *db, int gun_index);
- int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable);
- int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index);
- void DB_Update_PowerConsumption(sqlite3 *db, uint8_t gun_index, float value);
- float DB_Get_PowerConsumption(sqlite3 *db, uint8_t gun_index);
- int DB_Reboot_Record(sqlite3 *db);
- void InitialDHCP();
- void InitialDispenserDhcpServerConfig(void);
- void StartDispenserDhcpServer(void);
- int GetStartScheduleTime(unsigned char *time);
- void CheckConnectionTimeout(void);
- bool IsParallelCabinetIdle(void);
- bool IsStandbyEnable(void);
- bool IsConnectorWholeIdle(void);
- void SetAcContactor(unsigned char OnOff);
- void UpdateErrorCodeToOcpp(byte index);
- bool CheckConnectorTypeStatus(void);
- void CreateWatchdog(void);
- void TryCloseWatchdog(void);
- void TryFeedWatchdog(void);
- bool IsReadyParalleling(void);
- void SetParallelingStart(void);
- void SetParallelingDone(void);
- void SetPCabinetOutputRelay(unsigned char index, unsigned char OnOff);
- void SetParallelCabinetAcContactor(unsigned char OnOff);
- unsigned short GetTotalParallelCabinetPower(void);
- void MCabinetParallelingProcess(void);
- void SCabinetControllProcess(void);
- bool Get_Ocpp_ConnectionStatus(void);
- void Run_Ocpp_Service(void);
- bool Is_Ocpp_Task_Alive(void);
- void Kill_Ocpp_Service(void);
- void Run_MaintainOcpp_Service(void);
- bool Is_MaintainOcpp_Task_Alive(void);
- void Kill_MaintainOcpp_Service(void);
- unsigned int Get_Ocpp_procDogTime(void);
- void Clean_Ocpp_procDogTime(void);
- bool Is_Ocpp_BootNotification(void);
- void Clean_Ocpp_BootNotification(void);
- bool Is_Ocpp_ResetReq(void);
- bool Chk_Ocpp_Reset_Type(char *type);
- void Clean_Ocpp_ResetReq(void);
- void Set_Ocpp_AuthorizeReq(void);
- bool Is_Ocpp_AuthorizeConf(void);
- bool Is_Ocpp_Authorize_Status(char *status);
- bool Is_Ocpp_UpdateFirmwareReq(void);
- void Clean_Ocpp_UpdateFirmwareReq(void);
- bool Is_Ocpp_UpdateFirmwareStatus(char *status);
- void Set_Ocpp_UpdateFirmwareStatus(char *status);
- void Clean_Ocpp_UpdateFirmwareStatus(char *status);
- void Set_Ocpp_FirmwareStatusNotificationReq(void);
- bool Is_Ocpp_StopOnInvalidId_Enable(void);
- bool Is_Ocpp_AuthorizeRemoteTxRequests(void);
- int Get_Ocpp_ConnectionTimeOut(void);
- void Get_Ocpp_DefaultPrice(char *defaultPrice);
- void Get_Ocpp_UserPrice(char * userId, char *userPrice);
- void Clean_Ocpp_UserPrice(void);
- void Get_Ocpp_RunningCost(int gun_index, char *cost);
- void Clean_Ocpp_RunningCost(int gun_index);
- void Get_Ocpp_FinalCost(int gun_index, char *cost);
- void Clean_Ocpp_FinalCost(int gun_index);
- void Get_Ocpp_TimeOffset(char *timeOffset);
- void Get_Ocpp_Refunding(char *Refunding);
- void Clean_Ocpp_Refunding(void);
- bool Is_Ocpp_LcdOverideReq(int *gun, int *page);
- void Clean_Ocpp_LcdOverideReq(void);
- void Get_Ocpp_ChargerStationInfo(int *station_id, char *name);
- bool Is_Ocpp_ChargerStationReq(void);
- void Clean_Ocpp_ChargerStationReq(void);
- void Get_Ocpp_WeatherInfo(int *weatherID, float *temperature);
- bool Is_Ocpp_WeatherReq(void);
- void Clean_Ocpp_WeatherReq(void);
- void Set_Ocpp_DeductTransaction(int transaction);
- void Set_Ocpp_DeductCreditNo(char *userId);
- void Set_Ocpp_DeductVemData(char *vemData);
- void Set_Ocpp_DeductAmount(double value);
- void Set_Ocpp_DeductResult(unsigned char result);
- void Set_Ocpp_DonateInvoice(unsigned char donate);
- bool Is_Ocpp_ReportCreditDeductReq(void);
- void Set_Ocpp_ReportCreditDeductReq(void);
- void Clean_Ocpp_TcciSerialNo(int gun_index);
- bool Set_Ocpp_TcciReaderStatus(int gun_index, DeductResultInfoData *ReaderStatus);
- void Set_Ocpp_TcciReaderStatusReq(int gun_index);
- bool Is_Ocpp_TcciReaderStatusReq(int gun_index);
- void Set_Ocpp_StartTransactionId(int gun_index, char *id);
- void Set_Ocpp_StartTransactionReq(int gun_index);
- bool Is_Ocpp_StartTransactionConf(int gun_index);
- void Clean_Ocpp_StartTransactionConf(int gun_index);
- bool Is_Ocpp_StartTransaction_Status(int gun_index, char *status);
- bool Is_Ocpp_StartTransaction_Accepted(int gun_index);
- void Get_Ocpp_StartTransaction_Status(int gun_index, char *status);
- void Get_Ocpp_TransactionId(int gun_index, char *transactionId);
- bool Is_Invalid_StartTransactionId(int gun_index);
- void Set_Ocpp_StopTransactionId(int gun_index, char *id);
- void Set_Ocpp_StopTransactionReq(int gun_index);
- void Chk_Ocpp_Backup_ErrorCode(int gun_index);
- bool Is_Ocpp_ReserveNowReq(int gun_index);
- void Clean_Ocpp_ReserveNowReq(int gun_index);
- int Get_Ocpp_ReserveNowId(int gun_index);
- void Set_Ocpp_ReserveNowConf(int gun_index);
- void Get_Ocpp_ReserveNowExpiryDate(int gun_index, char *date);
- bool Is_Ocpp_ReserveNowExpired(int gun_index);
- void Get_Ocpp_ReserveNowIdTag(int gun_index, char *idTag);
- bool Is_Ocpp_ReserveNowIdTag(uint8_t gun_index, char *authIdTag);
- bool Is_Ocpp_CancelReservationReq(int gun_index);
- void Clean_Ocpp_CancelReservationReq(int gun_index);
- void Set_Ocpp_CancelReservationConf(int gun_index);
- bool Is_Ocpp_ChangeAvailabilityReq(int gun_index);
- void Clean_Ocpp_ChangeAvailabilityReq(int gun_index);
- bool Chk_Ocpp_Availability_Type(int gun_index, char *type);
- bool Is_Ocpp_UnlockConnectorReq(int gun_index);
- void Clean_Ocpp_UnlockConnectorReq(int gun_index);
- void Set_Ocpp_UnlockConnectorConf(int gun_index);
- bool Is_Ocpp_RemoteStartReq(int gun_index);
- void Clean_Ocpp_RemoteStartReq(int gun_index);
- void Get_Ocpp_RemoteStartIdTag(int gun_index, char *idTag);
- bool Is_Ocpp_RemoteStopReq(int gun_index);
- void Clean_Ocpp_RemoteStopReq(int gun_index);
- void Set_Ocpp_StopReason(int gun_index, char *reason);
- void Get_Ocpp_StopReason(int gun_index, char *reason);
- void Clean_Ocpp_StopReason(int gun_index);
- void Set_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode);
- bool Is_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode);
- void Set_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode);
- bool Is_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode);
- bool Is_Ocpp_ChargingProfileConf(int gun_index);
- void Clean_Ocpp_ChargingProfileConf(int gun_index);
- bool Is_Ocpp_ChargingProfileReq(int gun_index);
- void Set_Ocpp_ChargingProfileReq(int gun_index);
- bool Is_Ocpp_ChargingProfileKind(int gun_index, char *kind);
- bool Is_Ocpp_ChargingProfileId(int gun_index);
- int Get_Ocpp_ChargingProfileStartTime(int gun_index);
- int Get_Ocpp_ChargingProfileScheduleCount(int gun_index);
- int Get_Ocpp_ChargingProfileScheduleTime(int gun_index, int schedule_index);
- float Get_Ocpp_ChargingProfileScheduleLimit(int gun_index, int schedule_index);
- int Get_Ocpp_ChargingProfileScheduleNumberPhases(int gun_index, int schedule_index);
- int Get_Ocpp_ChargingProfileStartIndex(int gun_index);
- bool Is_Ocpp_MaxChargingProfileKind(char *kind);
- bool Is_Ocpp_MaxChargingProfileId(void);
- int Get_Ocpp_MaxProfileStartTime(void);
- int Get_Ocpp_MaxProfileScheduleCount(void);
- int Get_Ocpp_MaxProfileScheduleTime(int schedule_index);
- float Get_Ocpp_MaxProfileScheduleLimit(int schedule_index);
- int Get_Ocpp_MaxProfileScheduleNumberPhases(int schedule_index);
- int Get_Ocpp_MaxProfileStartIndex(void);
- int Is_Ocpp_RemoteStartWaitReq(void);
- void Set_Deduct_UserId(int gunIndex, char *userId);
- void Set_Deduct_TransactionId(int gunIndex, int transaction);
- void Clean_DeductInfo(int gunIndex);
- bool Is_DeductResultReq(int gunIndex);
- bool Is_ReaderStatusReq(int gunIndex);
- void Clean_ReaderStatusInfo(int gunIndex);
- void Set_UserTransactionId(int gunIndex, int transaction);
- void Set_UserPrice(int gunIndex, float price);
- void Set_UserTotalCost(int gunIndex, float cost);
- void Set_UserAccountBalance(int gunIndex, float balance);
- void Set_UserDiscount(int gunIndex, float discount);
- void Clean_UserTransaction(int gunIndex);
- 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[2];
- struct LedModuleData *ShmLedModuleData;
- struct OCPP16Data *ShmOCPP16Data;
- struct OCPP20Data *ShmOCPP20Data;
- struct MeterInformation *ShmCsuMeterData;
- ChargerInfoData *ShmChargerInfo;
- PsuPositionInfoData *ShmPsuPosition;
- PsuGroupingInfoData *ShmPsuGrouping;
- struct ChargingInfoData *chargingInfo[CONNECTOR_QUANTITY];
- struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
- struct timespec _cmdMainPriority_time;
- struct timespec _cmdSubPriority_time;
- struct timespec _ConnectorAuthorizing_Time[CONNECTOR_QUANTITY];
- struct timespec _ConnectorAuthorizeFail_Time[CONNECTOR_QUANTITY];
- struct timespec _DispenserAuthorizing_Time[CONNECTOR_QUANTITY];
- struct timespec _DispenserUpgrade_time;
- struct timespec _Standby_time;
- struct timespec _SystemStatus_Time[CONNECTOR_QUANTITY];
- struct timespec _Parallel_Time;
- struct timespec _RemoteStartNoId_Time;
- float gunOutputVol[CONNECTOR_QUANTITY];
- unsigned char _ocppProfileChkFlag[CONNECTOR_QUANTITY];
- float _lastProfilePower[CONNECTOR_QUANTITY];
- float _lastProfileCurrent[CONNECTOR_QUANTITY];
- float _lastMaxProfilePower;
- struct StructStatusNotification _BackupStatusNotification[CONNECTOR_QUANTITY];
- bool _NeedReset4gWifi;
- struct timespec _4gWifiReset_time;
- // for initial index to check EV board type is correct
- byte _gunIndex = 0;
- byte _acgunIndex = 0;
- byte _chademoIndex = 0;
- byte _ccsIndex = 0;
- byte _gb_Index = 0;
- byte _ac_Index = 0;
- bool _isStandbyEnable = true;
- bool isModelNameMatch = true;
- //int rfidFd = -1;
- //char* rfidPortName = "/dev/ttyS2";
- #if ENABLE_PCBA_TEST == 0
- char* fwVersion = "V1.10.00.0000.00";
- char* subVersion = "06";
- #else
- char* fwVersion = "PCBA.00.04";
- char* subVersion = "00";
- #endif
- sqlite3 *localDb;
- bool isDb_ready;
- sqlite3 *networkDb;
- //================================================
- // initial can-bus
- //================================================
- int InitCanBus()
- {
- int s0,nbytes;
- struct timeval tv;
- struct ifreq ifr0;
- struct sockaddr_can addr0;
- system("/sbin/ip link set can0 down");
- system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
- system("/sbin/ip link set can0 up");
- s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
- tv.tv_sec = 0;
- tv.tv_usec = 10000;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("Set SO_RCVTIMEO NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("Set SO_RCVBUF NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("Set SO_SNDBUF NG");
- #endif
- }
- strcpy(ifr0.ifr_name, "can0" );
- ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
- addr0.can_family = AF_CAN;
- addr0.can_ifindex = ifr0.ifr_ifindex;
- bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
- return s0;
- }
- //================================================
- // initial uart port
- //================================================
- char *_priPortName = "/dev/ttyS1";
- char *_485PortName = "/dev/ttyS5";
- int InitComPort(byte target)
- {
- int fd;
- struct termios tios;
- if(target == UPGRADE_PRI)
- fd = open(_priPortName, O_RDWR);
- else if (target == UPGRADE_FAN || target == UPGRADE_RB || target == UPGRADE_AC || target == UPGRADE_LED)
- fd = open(_485PortName, O_RDWR);
- if(fd<=0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("open 407 Communication port NG");
- #endif
- return -1;
- }
- ioctl (fd, TCGETS, &tios);
- tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN]=0;
- tios.c_cc[VTIME]=(unsigned char)1;
- tios.c_lflag=0;
- tcflush(fd, TCIFLUSH);
- ioctl (fd, TCSETS, &tios);
- return fd;
- }
- //=================================
- // Common routine
- //=================================
- void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
- {
- strncpy(dest, src + start, cnt);
- dest[cnt] = 0;
- }
- int InitWatchDog()
- {
- int fd;
- 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)
- {
- LOG_ERROR("System watch dog initial fail.\r\n");
- }
- ioctl(fd, _IOWR('W', 6, int), &timeout);
- return fd;
- }
- void setChargerMode(byte gun_index, byte mode)
- {
- chargingInfo[gun_index]->SystemStatus = mode;
- }
- long long DiffTimebWithNow(struct timeb ST)
- {
- //return milli-second
- struct timeb ET;
- long long StartTime,StopTime;
- ftime(&ET);
- StartTime=(long long)ST.time;
- StopTime=(long long)ET.time;
- return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
- }
- //=================================
- // Create all share memory
- //=================================
- int CreateShareMemory()
- {
- int MeterSMId;
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG");
- #endif
- return 0;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG");
- #endif
- return 0;
- }
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmStatusCodeData NG");
- #endif
- return 0;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmStatusCodeData NG");
- #endif
- return 0;
- }
- memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
- //creat ShmPsuData
- if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmPsuData NG");
- #endif
- return 0;
- }
- else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmPsuData NG");
- #endif
- return 0;
- }
- memset(ShmPsuData, 0, sizeof(struct PsuData));
- /*
- if(CHAdeMO_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmCHAdeMOData NG");
- #endif
- return 0;
- }
- else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmCHAdeMOData NG");
- #endif
- return 0;
- }
- memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
- }
- if(GB_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmGBTData NG");
- #endif
- return 0;
- }
- else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmGBTData NG");
- #endif
- return 0;
- }
- memset(ShmGBTData, 0, sizeof(struct GBTData));
- }
- //creat ShmCcsData
- if(CCS_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmCcsData NG");
- #endif
- return 0;
- }
- else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmCcsData NG");
- #endif
- return 0;
- }
- memset(ShmCcsData, 0, sizeof(struct CcsData));
- }
- */
- //creat ShmPrimaryMcuData
- if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmPrimaryMcuData NGn");
- #endif
- return 0;
- }
- else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG");
- #endif
- return 0;
- }
- memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
- //creat ShmFanModuleData
- if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmFanModuleData NG");
- #endif
- return 0;
- }
- else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmFanModuleData NG");
- #endif
- return 0;
- }
- memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
- //creat ShmRelayModuleData
- if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmRelayModuleData[0] NG");
- #endif
- return 0;
- }
- else if ((ShmRelayModuleData[0] = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmRelayModuleData[0] NG");
- #endif
- return 0;
- }
- memset(ShmRelayModuleData[0], 0, sizeof(struct RelayModuleData));
- // DO360 RC2
- if ((MeterSMId = shmget(ShmRelay2BdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmRelayModuleData[1] NG");
- #endif
- return 0;
- }
- else if ((ShmRelayModuleData[1] = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmRelayModuleData[1] NG");
- #endif
- return 0;
- }
- memset(ShmRelayModuleData[1], 0, sizeof(struct RelayModuleData));
- if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmLedModuleData NG");
- #endif
- return 0;
- }
- else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmLedModuleData NG");
- #endif
- return 0;
- }
- memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
- //creat ShmOCPP16Data
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmOCPP16Data NG");
- #endif
- return 0;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmOCPP16Data NG");
- #endif
- return 0;
- }
- memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
- if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0)
- {
- LOG_ERROR("[main]CreatShareMemory:shmget OCPP20Data NG\n");
- return 0;
- }
- else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- LOG_ERROR("[main]CreatShareMemory:shmat OCPP20Data NG\n");
- return 0;
- }
- memset(ShmOCPP20Data,0,sizeof(struct OCPP20Data));
- if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ChargerInfoData NG");
- #endif
- return 0;
- }
- else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ChargerInfoData NG");
- #endif
- return 0;
- }
- memset(ShmChargerInfo, 0, sizeof(ChargerInfoData));
- ShmPsuPosition = &ShmChargerInfo->PsuPosition;
- ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
- return 1;
- }
- //======================================================
- // Peripheral initial
- //======================================================
- void InitGPIO()
- {
- /*****************0~3, 4 bank, bank x 32+ num*********************/
- /***************************************************************/
- /*************** GPIO 0 ***************************************/
- /***************************************************************/
- /* GPMC_AD8 => GPIO0_22 *//*ID BD1_1*/ // no use
- system("echo 22 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio22/direction");
- /* GPMC_AD9 => GPIO0_23 *//*ID BD1_2*/ // no use
- system("echo 23 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio23/direction");
- /* GPMC_AD10 => GPIO0_26 *//*IO BD1_1*/ // no use
- system("echo 26 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio26/direction");
- system("echo 1 > /sys/class/gpio/gpio26/value");
- /* GPMC_AD11 => GPIO0_27 *//*IO BD1_2*/ // no use
- system("echo 27 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio27/direction");
- /* RMII1_REF_CLK => GPIO0_29 *//*USB 0 OCP detection*/
- system("echo 29 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio29/direction");
- /*XDMA_EVENT_INTR0 => GPIO0_19 *//*AM_RFID_RST*/ // no use
- system("echo 19 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio19/direction");
- system("echo 1 > /sys/class/gpio/gpio19/value");
- /*XDMA_EVENT_INTR1 => GPIO0_20 *//*AM_RFID_ICC*/ // no use
- system("echo 20 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio20/direction");
- /***************************************************************/
- /*************** GPIO 1 ***************************************/
- /***************************************************************/
- /* GPMC_AD12 => GPIO1_12 *//*ID BD2_1*/ // no use
- system("echo 44 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio44/direction");
- /* GPMC_AD13 => GPIO1_13 *//*ID BD2_2*/ // no use
- system("echo 45 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio45/direction");
- /* GPMC_AD14 => GPIO1_14 *//*IO BD2_1*/ // no use
- system("echo 46 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio46/direction");
- system("echo 0 > /sys/class/gpio/gpio46/value");
- /* GPMC_AD15 => GPIO1_15 *//*IO BD2_2*/ // no use
- system("echo 47 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio47/direction");
- /***************************************************************/
- /*************** GPIO 2 ***************************************/
- /***************************************************************/
- /*LCD_AC_BIAS_EN => GPIO2_25*//*RS-485 for module DE control*/
- system("echo 89 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio89/direction");
- system("echo 1 > /sys/class/gpio/gpio89/value");
- /*LCD_HSYNC => GPIO2_23*//*RS-485 for module RE control*/
- system("echo 87 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio87/direction");
- system("echo 0 > /sys/class/gpio/gpio87/value");
- /*LCD_PCLK => GPIO2_24*//*CCS communication board 1 proximity*/ // no use
- system("echo 88 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio88/direction");
- /*LCD_VSYNC => GPIO2_22*//*CCS communication board 2 proximity*/ // no use
- system("echo 86 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio86/direction");
- /***************************************************************/
- /*************** GPIO 3 ***************************************/
- /***************************************************************/
- /*MCASP0_FSX => GPIO3_15*//*Emergency Stop button detect*/
- system("echo 111 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio111/direction");
- /*MCASP0_ACLKR => GPIO3_18*//*USB1 OCP detect*/
- system("echo 114 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio114/direction");
- /*MCASP0_AHCLKR => GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
- system("echo 113 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio113/direction");
- /*MCASP0_ACLKX => GPIO3_14*//*Ethernet PHY reset*/
- system("echo 110 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio110/direction");
- system("echo 0 > /sys/class/gpio/gpio110/value");
- /* MCASP0_FSR => GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/ // no use
- system("echo 115 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio115/direction");
- system("echo 0 > /sys/class/gpio/gpio115/value");
- /* MCASP0_AXR0 => GPIO3_16 *//*CSU board function OK indicator.*/
- system("echo 112 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio112/direction");
- system("echo 1 > /sys/class/gpio/gpio112/value");
- /* MCASP0_AXR1 => GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/ // no use
- system("echo 116 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio116/direction");
- system("echo 0 > /sys/class/gpio/gpio116/value");
- /* (C14) EMU0.gpio3[7] */ /*CP open/short feature enable/disable, pull low for default enable*/
- system("echo 103 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio103/direction");
- system("echo 0 > /sys/class/gpio/gpio103/value");
- /* (B14) EMU1.gpio3[8] */ /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
- system("echo 104 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio104/direction");
- system("echo 0 > /sys/class/gpio/gpio104/value");
- LOG_INFO("[main]InitGPIO: Initial GPIO OK");
- }
- int LoadSysConfigAndInfo(struct SysConfigData *ptr)
- {
- int fd, wrd;
- unsigned char *buf;
- unsigned int ChkSum, ChkSumOrg;
- if((buf = malloc(MtdBlockSize)) == NULL)
- {
- LOG_ERROR("malloc buffer NG, rebooting..\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- //================================================
- // Load configuration from mtdblock10
- //================================================
- system("nanddump /dev/mtd10 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- LOG_ERROR("open mtdblock10 NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if(wrd < MtdBlockSize)
- {
- free(buf);
- LOG_ERROR("read SysConfigData data NG, rebooting..\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));
- //================================================
- // Load configuration from mtdblock11
- //================================================
- if(ChkSum != ChkSumOrg)
- {
- LOG_ERROR("Primary SysConfigData checksum NG, read backup\n");
- system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- LOG_ERROR("open mtdblock11 (backup) NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if(wrd < MtdBlockSize)
- {
- free(buf);
- LOG_ERROR("read backup SysConfigData data NG, rebooting..\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));
- //================================================
- // Load configuration from mtdblock12 (Factory default)
- //================================================
- if(ChkSum != ChkSumOrg)
- {
- LOG_ERROR("backup SysConfigData checksum NG, read Factory default\n");
- system("nanddump /dev/mtd12 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- LOG_ERROR("open mtdblock12 (Factory default) NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if(wrd < MtdBlockSize)
- {
- free(buf);
- LOG_ERROR("read factory default SysConfigData data NG, rebooting..\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)
- {
- LOG_ERROR("factory default SysConfigData checksum NG, restore factory default\n");
- free(buf);
- system("cd /root;./FactoryConfig -m");
- system("rm -f /Storage/OCPP/OCPPConfiguration");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- return FAIL;
- }
- }
- }
- //load OK
- memcpy((struct SysConfigData *)ptr, buf, sizeof(struct SysConfigData));
- free(buf);
- system("rm -f /mnt/EvseConfig.bin");
- // SysConfig in flash is empty (0xffffffff)
- 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))
- {
- LOG_INFO("Model name over length.");
- memset(ShmSysConfigAndInfo->SysConfig.ModelName, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
- }
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber))
- {
- LOG_INFO("Model serial number over length.");
- memset(ShmSysConfigAndInfo->SysConfig.SerialNumber, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
- }
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId))
- {
- LOG_INFO("System id over length.");
- memset(ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId));
- }
- if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff)
- {
- LOG_INFO("Ethernet dhcp config is null.");
- }
- system("cd /root;./Module_FactoryConfig -m");
- sleep(3);
- system("/usr/bin/run_evse_restart.sh");
- }
- LOG_INFO("Load SysConfigData OK");
- return PASS;
- }
- int isEthernetCablePlugIn(int ethernet)
- {
- int fd, PlugInStatus = 0;
- char ch[2];
- char buffer[64];
- snprintf(buffer, sizeof(buffer), "/sys/class/net/eth%d/carrier", ethernet);
- fd = open(buffer, O_RDONLY);
- if(fd < 0)
- {
- return -1;
- }
- if(read(fd, ch, 1) < 0)
- {
- return -1;
- }
- PlugInStatus = atoi(ch);
- close(fd);
- return PlugInStatus;
- }
- 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];
- // if (ShmOCPP16Data->OcppConnStatus == PASS)
- // {
- // result = PASS;
- // }
- // else
- {
- strcpy(cmd, "ifconfig eth0");
- fp = popen(cmd, "r");
- if (fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if (strstr(buf, "inet addr:") > 0)
- {
- sscanf(buf, "%*s%s", tmp);
- substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:"));
- if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != EQUAL)
- {
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
- }
- }
- }
- }
- pclose(fp);
- memset(buf, 0x00, sizeof(buf));
- for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
- {
- sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if(strstr(buf, "transmitted") > 0)
- {
- //sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
- if(strstr(buf,"100%") != NULL)
- {
- }
- else
- {
- result = PASS;
- }
- //DEBUG_INFO("%s",buf);
- //DEBUG_INFO("%s\n",tmp);
- }
- }
- }
- pclose(fp);
- }
- }
- return result;
- }
- bool Is_Dispenser_MiscCommand(int dispenser, int misc_cmd)
- {
- return (ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue & misc_cmd) > 0 ? true : false;
- }
- void Set_Dispenser_MiscCommand(int dispenser, int misc_cmd)
- {
- ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue |= misc_cmd;
- }
- void Clean_Dispenser_MiscCommand(int dispenser, int misc_cmd)
- {
- ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue &= ~misc_cmd;
- }
- bool Is_Connector_MiscCommand(int connector, int misc_cmd)
- {
- return (ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue & misc_cmd) > 0 ? true : false;
- }
- void Set_Connector_MiscCommand(int connector, int misc_cmd)
- {
- ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue |= misc_cmd;
- }
- void Clean_Connector_MiscCommand(int connector, int misc_cmd)
- {
- ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue &= ~misc_cmd;
- }
- void AnnounceEthernetStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_ETHERNET_STATUS);
- }
- }
- }
- void AnnounceWiFiStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_WIFI_STATUS);
- }
- }
- }
- void AnnounceTelcomModemStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_TELCOM_MODEM_STATUS);
- }
- }
- }
- void AnnounceBackendStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_BACKEND_STATUS);
- }
- }
- }
- void AnnounceBillingStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_BILLING_STATUS);
- }
- }
- }
- void AnnounceStopChargingButtonStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_STOP_BUTTON_STATUS);
- }
- }
- }
- void AnnounceAuthModeConfig(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_AUTH_MODE_CONFIG);
- }
- }
- }
- void AnnounceEVCCIDConfig(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_EVCCID_CONFIG);
- }
- }
- }
- void AnnounceLEDIntensity(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_LED_INTENSITY);
- }
- }
- }
- void AnnounceCurrency(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_CURRENCY);
- }
- }
- }
- void AnnounceRemoteStartNoID(void)
- {
- for(int index = 0; index < CONNECTOR_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorID[i] - 1;
- if(chargingInfo[gun]->SystemStatus == S_IDLE)
- {
- ShmChargerInfo->ConnectorPageReq[gun].bits.RemoteStartNoID = true;
- break;
- }
- }
- }
- }
- }
- void AnnounceLineStatusCode(int gun, int status)
- {
- int dispenser = 0;
- dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].ParentDispensetIndex;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
- {
- ShmChargerInfo->LineApi.StatusCode[gun] = status;
- Set_Connector_MiscCommand(gun, MISC_CONN_LINE_STATUS);
- }
- }
- void AnnounceStationInfo(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_STATION_INFO);
- }
- }
- }
- void UpdateConfigAndIcon(void)
- {
- unsigned char status = _Connnection_Disable;
- // update ethernet connection status
- status = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet == YES ? _Connnection_Disconnected : _Connnection_Connected;
- if(ShmChargerInfo->CabinetMiscValue.EthernetStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.EthernetStatus = status;
- AnnounceEthernetStatus();
- }
- // update wifi connection status
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- status = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? _Connnection_Disconnected : _Connnection_Connected;
- }
- else
- {
- status = _Connnection_Disable;
- }
- if(ShmChargerInfo->CabinetMiscValue.WiFiStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.WiFiStatus = status;
- AnnounceWiFiStatus();
- }
- // update 4g connection status
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- status = (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == NO &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES) ? _Connnection_Connected : _Connnection_Disconnected;
- }
- else
- {
- status = _Connnection_Disable;
- }
- if(ShmChargerInfo->CabinetMiscValue.TelcomModemStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.TelcomModemStatus = status;
- AnnounceTelcomModemStatus();
- }
- // update backend connection status
- status = ShmStatusCodeData->InfoCode.InfoEvents.bits.BackendDisconnectedViaEthernet == YES ? _Connnection_Disconnected : _Connnection_Connected;
- if(ShmChargerInfo->CabinetMiscValue.BackendStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.BackendStatus = status;
- AnnounceBackendStatus();
- }
- // update billing status
- status = ShmSysConfigAndInfo->SysConfig.BillingData.isBilling;
- if(ShmChargerInfo->CabinetMiscValue.BillingStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.BillingStatus = status;
- AnnounceBillingStatus();
- }
- // update stop charging button
- status = ShmSysConfigAndInfo->SysConfig.StopChargingByButton;
- if(ShmChargerInfo->CabinetMiscValue.StopChargingButton != status)
- {
- ShmChargerInfo->CabinetMiscValue.StopChargingButton = status;
- AnnounceStopChargingButtonStatus();
- }
- // update AuthMode config
- status = ShmSysConfigAndInfo->SysConfig.AuthorisationMode;
- if(ShmChargerInfo->CabinetMiscValue.AuthModeConfig != status)
- {
- ShmChargerInfo->CabinetMiscValue.AuthModeConfig = status;
- AnnounceAuthModeConfig();
- AnnounceEVCCIDConfig();
- }
- // update EVCCID config
- status = ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID;
- if(ShmChargerInfo->CabinetMiscValue.EVCCIDConfig != status)
- {
- ShmChargerInfo->CabinetMiscValue.EVCCIDConfig = status;
- AnnounceEVCCIDConfig();
- }
- // update LED Intensity
- status = ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity;
- if(ShmChargerInfo->CabinetMiscValue.LEDIntensity != status)
- {
- ShmChargerInfo->CabinetMiscValue.LEDIntensity = status;
- AnnounceLEDIntensity();
- }
- // update currency
- status = ShmSysConfigAndInfo->SysConfig.BillingData.Currency;
- if(ShmChargerInfo->CabinetMiscValue.Currency != status)
- {
- ShmChargerInfo->CabinetMiscValue.Currency = status;
- AnnounceCurrency();
- }
- }
- void Check4gWifiReset(void)
- {
- int timeDelay = 0;
- if(ShmChargerInfo->Control.SysCtrl.bits.BackendEnable)
- {
- if((!ShmSysConfigAndInfo->SysInfo.InternetConn && !ShmSysConfigAndInfo->SysInfo.OcppConnStatus &&
- (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE ||
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)) ||
- ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken == YES)
- {
- if(!_NeedReset4gWifi)
- {
- GetClockTime(&_4gWifiReset_time);
- LOG_INFO("Backend Enable But Internet Not Available!");
- }
- _NeedReset4gWifi = true;
- }
- else
- {
- _NeedReset4gWifi = false;
- }
- if(_NeedReset4gWifi)
- {
- timeDelay = ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken == YES ?
- FAST_RESET_4G_WIFI_TIME : TRY_RESET_4G_WIFI_TIME;
- if(GetTimeoutValue(_4gWifiReset_time) / uSEC_VAL >= timeDelay)
- {
- ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable = true;
- usleep(100000);
- // before reset 4g io, kill Module_4g & Module_Wifi task
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- system("killall Module_4g &");
- }
- usleep(100000);
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- system("killall Module_Wifi &");
- }
- LOG_INFO("Reset 4g_Wifi Module");
- system("echo 1 > /sys/class/gpio/gpio104/value");
- sleep(1);
- system("echo 0 > /sys/class/gpio/gpio104/value");
- _NeedReset4gWifi = false;
- ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable = false;
- }
- }
- }
- else
- {
- _NeedReset4gWifi = false;
- }
- }
- void MasterCabinetDhcpClientConfig(void)
- {
- char tmpbuf[256];
- //Run DHCP client if enabled
- system("killall udhcpc");
- system("rm -rf /etc/resolv.conf");
- system("echo nameserver 8.8.8.8 > /etc/resolv.conf"); //Google DNS server
- system("echo nameserver 180.76.76.76 >> /etc/resolv.conf"); //Baidu DNS server
- //system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
- if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
- {
- sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- //Upgrade system id to /etc/hostname
- sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- void InitMasterCabinetEthernet(void)
- {
- char tmpbuf[256];
- //Init Eth0 for internet
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
- system(tmpbuf);
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"route add default gw %s eth0 ",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
- system(tmpbuf);
- //system("ifconfig lo up");
- // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
- //Init Eth1 for administrator tool
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up", "192.168.100.1", "255.255.255.0");
- system(tmpbuf);
- }
- void InitSlaveCabinetEthernet(void)
- {
- char tmpbuf[256];
- system("/sbin/ifconfig eth0 down");
- system("/sbin/ifconfig eth1 down");
- system("killall udhcpc");
- system("rm -rf /etc/resolv.conf");
- system("pgrep -f \"udhcpd /etc/udhcpd_eth1.conf\" | xargs kill");
- //Init Eth0 for internet
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 192.168.100.3%d netmask %s up",
- (ShmChargerInfo->Control.CabinetSwitch - 1),
- "255.255.255.0");
- system(tmpbuf);
- system("/sbin/route add default gw 192.168.100.1 eth0");
- //Init Eth1 for internet
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up", SLAVE_ETH1_IP, SLAVE_ETH1_SUBMASK);
- system(tmpbuf);
- }
- void InitEthernet(void)
- {
- system("ifconfig eth0 down");
- system("ifconfig eth1 down");
- sleep(2);
- char tmpbuf[256];
- // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
- system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
- sleep(2);
- InitMasterCabinetEthernet();
- MasterCabinetDhcpClientConfig();
- // DO360 DHCP Server
- InitialDispenserDhcpServerConfig();
- StartDispenserDhcpServer();
- pid_t pid = fork();
- uint8_t cnt_pingDNS_Fail;
- if(pid == 0)
- {
- ShmChargerInfo->CabinetMiscValue.BackendStatus = _Connnection_Disconnected;
- ShmChargerInfo->CabinetMiscValue.EthernetStatus = _Connnection_Disconnected;
- ShmChargerInfo->CabinetMiscValue.WiFiStatus = _Connnection_Disable;
- ShmChargerInfo->CabinetMiscValue.TelcomModemStatus = _Connnection_Disable;
- LOG_INFO("Internet Fork PID = %d", getpid());
- for(;;)
- {
- if(isEthernetCablePlugIn(0) == YES)
- {
- if(isRouteFail())
- {
- LOG_INFO("eth0 not in route, restart eht0.");
- 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)
- {
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet != NO)
- {
- LOG_INFO("Internet is Reachable");
- }
- ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet = NO;
- ShmSysConfigAndInfo->SysInfo.ethInternetConn = YES;
- cnt_pingDNS_Fail = 0;
- }
- else
- {
- if(++cnt_pingDNS_Fail > 3)
- {
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet != YES)
- {
- LOG_INFO("Internet is Disconnect Via Ethernet");
- }
- ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet = YES;
- ShmSysConfigAndInfo->SysInfo.ethInternetConn = NO;
- }
- }
- bool ethResult = ShmSysConfigAndInfo->SysInfo.ethInternetConn;
- if(ethResult == YES)
- {
- system("/sbin/ifmetric eth0 0");
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')))
- {
- system("/sbin/ifmetric mlan0 1");
- }
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')))
- {
- system("/sbin/ifmetric ppp0 2");
- }
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? NO : YES;
- if (ethResult)
- {
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- system("/sbin/ifmetric eth0 1");
- system("/sbin/ifmetric mlan0 0");
- }
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')))
- {
- system("/sbin/ifmetric ppp0 2");
- }
- }
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- ethResult = (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == NO &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES) ? YES : NO;
- if (ethResult)
- {
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')))
- {
- system("/sbin/ifmetric mlan0 2");
- }
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- system("/sbin/ifmetric eth0 1");
- system("/sbin/ifmetric ppp0 0");
- }
- }
- }
- if(!Is_Ocpp_Task_Alive())
- {
- ShmSysConfigAndInfo->SysInfo.OcppConnStatus = false;
- }
- ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
- ShmStatusCodeData->InfoCode.InfoEvents.bits.WiFiDisable = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == false ? true : false;
- ShmStatusCodeData->InfoCode.InfoEvents.bits.Telocom4GModuleDisable = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == false ? true : false;
- ShmStatusCodeData->InfoCode.InfoEvents.bits.BackendDisconnectedViaEthernet = ShmSysConfigAndInfo->SysInfo.OcppConnStatus == false ? true : false;
- UpdateConfigAndIcon();
- Check4gWifiReset();
- sleep(5);
- }
- }
- #ifdef SystemLogMessage
- LOG_INFO("[main]InitEthernet: Initial Ethernet OK.");
- #endif
- }
- void GetMacAddress()
- {
- for (byte index = 0; index < 2; index++)
- {
- int fd;
- struct ifreq ifr;
- char tarEth[5];
- char Mac[18];
- sprintf(tarEth,"eth%d",index);
- fd = socket(AF_INET, SOCK_DGRAM, 0);
- ifr.ifr_addr.sa_family = AF_INET;
- strncpy(ifr.ifr_name, tarEth, IFNAMSIZ - 1);
- ioctl(fd, SIOCGIFHWADDR, &ifr);
- close(fd);
- sprintf(Mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
- ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2],
- ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
- if (index == 0)
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, Mac);
- else
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthMacAddress, Mac);
- }
- }
- void GetFirmwareVersion()
- {
- // Get CSU root file system version
- sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
- #if ENABLE_PCBA_TEST == 0
- byte count = 0, chademo = 0, ccs = 0, gb = 0;
- for(uint8_t idx=0;idx<3;idx++)
- {
- if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'J')
- {
- chademo++;
- count++;
- }
- else if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'G')
- {
- gb++;
- count++;
- }
- else if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'U' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'E')
- {
- ccs++;
- count++;
- }
- }
- if (count == 1)
- {
- if (chademo > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '1';
- else if (ccs > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '2';
- else if (gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '3';
- }
- else
- {
- if (chademo > 0 && ccs > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
- else if (chademo > 0 && gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
- else if (ccs > 0 && gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
- }
- // Get network option from model name
- switch(ShmSysConfigAndInfo->SysConfig.ModelName[10])
- {
- case 'B':
- case 'U':
- //Blue tooth
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
- break;
- case 'W':
- // WIFI
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
- break;
- case 'T':
- // 3G/4G
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
- break;
- case 'D':
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '5';
- break;
- default:
- // LAN
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
- break;
- }
- // Get rating power from model name
- memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
- // Get IEC or UL
- char _buf[3] = {0};
- memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[2], 2);
- if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
- else if (strcmp(_buf, "WU") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
- #endif
- }
- void InitialShareMemoryInfo()
- {
- FILE *fp;
- char cmd[512];
- char buf[512];
- _UpgradeNeedReboot = FALSE;
- //sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
- //sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
- //sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = 0;
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount = 0;
- ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
- ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
- ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
- sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
- memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
- sprintf(cmd, "/bin/uname -r");
- fp = popen(cmd, "r");
- if(fp == NULL)
- sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
- else
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
- }
- }
- // 雙槍 CCS + Chademo
- GetFirmwareVersion();
- //sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.Relay2ModuleHwRev, " "); //DO360 RC2
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, " "); //DO360 RC2
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LedModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.Connector1FwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.Connector2FwRev, " ");
- ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
- ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
- ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
- ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
- ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
- ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- 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.ChademoboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
- memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
- memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
- memset(ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev)); //DO360 RC2
- ShmPrimaryMcuData->SelfTest_Comp = NO;
- ShmRelayModuleData[0]->SelfTest_Comp = NO;
- ShmRelayModuleData[1]->SelfTest_Comp = NO;
- ShmFanModuleData->SelfTest_Comp = NO;
- ShmLedModuleData->SelfTest_Comp = NO;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- ShmFanModuleData->TestFanSpeed = 0;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
- ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
- LOG_INFO("DispenserSequence = %d, MaxConnectorQuantity = %d",
- ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
- ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
- {
- LOG_INFO("Dispenser[%d] <=> %d", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- memset((char *)&_BackupStatusNotification[i], 0, sizeof(struct StructStatusNotification));
- }
- }
- int Initialization(void)
- {
- // int pinOut[2] = { 116, 115 };
- for (byte count = 0; count < CONNECTOR_QUANTITY; count++)
- {
- chargingInfo[count]->RemoteStartFlag = NO;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[count].Parameter.bits.RemoteStartConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[count].Parameter.bits.RemoteStopConfirm = false;
- SetOcppErrorCode(count, "NoError");
- }
- LOG_INFO("Initialization OK");
- return PASS;
- }
- void InitialPsuGroupingAndLocation(void)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
- {
- memcpy(ShmPsuGrouping->Location, Group_to_Location_4_Gun, sizeof(ShmPsuGrouping->Location));
- memcpy(ShmPsuGrouping->Layout, Location_to_Group_4_Gun, sizeof(ShmPsuGrouping->Layout));
- }
- else
- {
- memcpy(ShmPsuGrouping->Location, Group_to_Location_2_Gun, sizeof(ShmPsuGrouping->Location));
- memcpy(ShmPsuGrouping->Layout, Location_to_Group_2_Gun, sizeof(ShmPsuGrouping->Layout));
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- ShmPsuGrouping->GroupCollection[i].Index = i;
- ShmPsuGrouping->GroupCollection[i].Location = ShmPsuGrouping->Location[i];
- if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
- {
- memcpy(&ShmPsuGrouping->GroupCollection[i].ParallelConfig[0], &GroupParallelRelay_4_Gun[i][0], GENERAL_GUN_QUANTITY);
- }
- else
- {
- memcpy(&ShmPsuGrouping->GroupCollection[i].ParallelConfig[0], &GroupParallelRelay_2_Gun[i][0], GENERAL_GUN_QUANTITY);
- }
- ShmChargerInfo->Control.GunAvailable[i] = NO;
- }
- }
- void InitialCustomerCode(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'A' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'D')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_Audi;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'E' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == '4')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_E4U;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'U' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'U')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_UCar;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'T' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'C')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_TCC;
- }
- else
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_Phihong;
- }
- }
- void InitialMaxDispenserConnectorQuantity(void)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable == false)
- {
- ShmChargerInfo->Control.MaxDispenser = 2;
- ShmChargerInfo->Control.MaxConnector = 2;
- }
- else
- {
- ShmChargerInfo->Control.MaxDispenser = GENERAL_GUN_QUANTITY;
- ShmChargerInfo->Control.MaxConnector = GENERAL_GUN_QUANTITY;
- }
- }
- void InitialAuthMode(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'K')
- {
- ShmChargerInfo->AuthInfo.AuthMode.bits.AutoStartEnable = true;
- }
- }
- void InitialQRCodeMode(void)
- {
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi ||
- ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
- {
- ShmChargerInfo->AuthInfo.QRCodeMode = _QR_MODE_ChargeBoxId;
- }
- else
- {
- // customized
- if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode)
- {
- ShmChargerInfo->AuthInfo.QRCodeMode = _QR_MODE_Customized;
- }
- else
- {
- ShmChargerInfo->AuthInfo.QRCodeMode = _QR_MODE_Default;
- }
- }
- }
- void InitialPowerCabinetSetting(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'A' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'D')
- {
- ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = true;
- }
- ShmChargerInfo->CabinetMiscValue.BillingStatus = ShmSysConfigAndInfo->SysConfig.BillingData.isBilling;
- ShmChargerInfo->CabinetMiscValue.StopChargingButton = ShmSysConfigAndInfo->SysConfig.StopChargingByButton;
- ShmChargerInfo->CabinetMiscValue.AuthModeConfig = ShmSysConfigAndInfo->SysConfig.AuthorisationMode;
- ShmChargerInfo->CabinetMiscValue.EVCCIDConfig = ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID;
- }
- bool InitialChargerSetting(void)
- {
- bool result = true;
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'O')
- {
- ShmChargerInfo->Control.PrimaryCtrl.bits.AcContactorReverse = true;
- ShmChargerInfo->Control.PrimaryCtrl.bits.DoorSensorReverse = true;
- ShmChargerInfo->Control.SysCtrl.bits.LedBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable = true;
- ShmChargerInfo->Control.SysCtrl.bits.DOLedIndication = true;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'K')
- {
- if(!(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'P' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'K'))
- {
- ShmChargerInfo->Control.SysCtrl.bits.FanBoardDisable = true;
- }
- ShmChargerInfo->Control.SysCtrl.bits.LedBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.DKLedIndication = true;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'B')
- {
- //ShmChargerInfo->Control.SysCtrl.bits.FanBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.LedBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.DOLedIndication = true;
- //ShmChargerInfo->Control.SysCtrl.bits.DKLedIndication = true;
- ShmChargerInfo->Control.RelayCtrl.bits.AcInputDisable = true;
- ShmChargerInfo->Control.RelayCtrl.bits.DcInputEnable = true;
- }
- else
- {
- result = false;
- }
- InitialCustomerCode();
- InitialMaxDispenserConnectorQuantity();
- InitialAuthMode();
- InitialQRCodeMode();
- InitialPsuGroupingAndLocation();
- InitialPowerCabinetSetting();
- if(!CheckConnectorTypeStatus())
- {
- result = false;
- }
- return result;
- }
- bool InitialSystemDefaultConfig()
- {
- bool result = true;
- LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
- InitGPIO();
- InitEthernet();
- GetMacAddress();
- return result;
- }
- void SelfTestRun(void)
- {
- LOG_INFO("Self test.");
- system("/root/Module_ChargerSelfTest &");
- }
- void SpawnNormalService(void)
- {
- 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_ProduceUtils &");
- system("/root/Module_CabinetParallel &");
- system("/root/Module_LedIndication &");
- system("/root/Module_Authorize &");
- }
- void SpawnOcppService(void)
- {
- if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
- {
- Run_Ocpp_Service();
- }
- }
- void SpawnMaintainOcppService(void)
- {
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- Run_MaintainOcpp_Service();
- }
- }
- void SpawnInternetService(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
- {
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- system("/root/Module_4g &");
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
- {
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- system("/root/Module_Wifi &");
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- system("/root/Module_4g &");
- }
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- system("/root/Module_Wifi &");
- }
- }
- }
- int SpawnTask(void)
- {
- sleep(2);
- SpawnNormalService();
- SpawnInternetService();
- return PASS;
- }
- int runFlashShellCmd(const char *cmd)
- {
- int result = FAIL;
- char buf[256];
- FILE *fp;
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- LOG_INFO("%s\n", buf);
- }
- result = PASS;
- }
- pclose(fp);
- return result;
- }
- 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 = ARRAY_SIZE(UsrData->CsuBootLoadFwRev); i < MtdBlockSize - 4; i++)
- {
- Chk += *(BufTmp+i);
- }
- memcpy(BufTmp + MtdBlockSize - 4, &Chk, 4);
- // Output configuration to file.
- fd = open("/mnt/EvseTempConfig.bin", O_RDWR | O_CREAT | O_TRUNC);
- if(fd < 0)
- {
- LOG_ERROR("open /mnt/EvseTempConfig.bin NG");
- free(BufTmp);
- return 0;
- }
- wrd = write(fd, BufTmp, MtdBlockSize);
- close(fd);
- if(wrd < MtdBlockSize)
- {
- LOG_ERROR("write /mnt/EvseTempConfig.bin NG");
- free(BufTmp);
- return 0;
- }
- LOG_INFO("EvseTempConfig write to file in /mnt OK.");
- LOG_INFO("Erase /dev/mtd10.");
- runFlashShellCmd("flash_erase /dev/mtd10 0 0");
- LOG_INFO("Write /dev/mtd10.");
- runFlashShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseTempConfig.bin");
- LOG_INFO("Erase /dev/mtd11.");
- runFlashShellCmd("flash_erase /dev/mtd11 0 0");
- LOG_INFO("Write /dev/mtd11.");
- runFlashShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseTempConfig.bin");
- system("rm -f /mnt/EvseTempConfig.bin");
- LOG_INFO("EvseTempConfig write to flash OK");
- }
- else
- {
- LOG_ERROR("alloc BlockSize NG");
- result = FAIL;
- }
- if(BufTmp != NULL)
- {
- free(BufTmp);
- }
- return result;
- }
- //===============================================
- // Common Detect Chk - Stop Charging ?
- //===============================================
- bool isEvBoardStopChargeFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->ChargingStopFlag.bits.AlarmStop;
- }
- bool isNormalStopChargeFlag(byte gunIndex)
- {
- return (chargingInfo[gunIndex]->ChargingStopFlag.bits.NormalStop || chargingInfo[gunIndex]->ChargingStopFlag.bits.ManualStop);
- }
- bool isResetStopChargeFlag(byte gunIndex)
- {
- return (chargingInfo[gunIndex]->ChargingStopFlag.bits.HardResetStop || chargingInfo[gunIndex]->ChargingStopFlag.bits.SoftResetStop);
- }
- bool isInvalidIdStopFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->ChargingStopFlag.bits.InvalidIdStop;
- }
- void ReleaseAlarmCode(byte gunIndex)
- {
- if(!Is_Ocpp_StatusNotificationErrorCode(gunIndex, "NoError"))
- {
- SetOcppErrorCode(gunIndex, "NoError");
- }
- if(!Is_Ocpp_StatusNotificationVendorCode(gunIndex, ""))
- {
- SetOcppVendorErrorCode(gunIndex, "");
- }
- if (strcmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "") != EQUAL)
- {
- strcpy((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "");
- }
- if (strcmp((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "") != EQUAL)
- {
- strcpy((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "");
- }
- if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemotenAlarmCode, "") != EQUAL)
- {
- strcpy((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemotenAlarmCode, "");
- }
- }
- //===============================================
- // EmergencyStop and Charging Stop
- //===============================================
- void ChargingTerminalProcess(byte gunIndex)
- {
- setChargerMode(gunIndex, MODE_TERMINATING);
- }
- void ChargingAlarmProcess(byte gunIndex)
- {
- UpdateErrorCodeToOcpp(gunIndex);
- setChargerMode(gunIndex, MODE_ALARM);
- }
- void AcChargingTerminalProcess()
- {
- ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
- }
- void StopChargingProcessByString(byte level)
- {
- if (level > ShmSysConfigAndInfo->SysWarningInfo.Level)
- {
- ShmSysConfigAndInfo->SysWarningInfo.Level = level;
- }
- }
- void ReleaseChargingProcessByString(byte level)
- {
- if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level)
- ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
- }
- // 一般錯誤停止充電處理函式
- void BoardErrOccurByString(byte index, char *code)
- {
- byte level = 1;
- if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
- (chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (strncmp(code, "023730", 6) == EQUAL && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
- }
- ChargingTerminalProcess(index);
- }
- StopChargingProcessByString(level);
- }
- // 急停狀況的停止充電處理函式
- void EmcOccureByString(char *code)
- {
- byte level = 2;
- if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
- {
- return;
- }
- // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
- // 其錯誤等級為 2
- if (strncmp(code, "042251", 6) == EQUAL || strncmp(code, "042252", 6) == EQUAL ||
- strncmp(code, "042238", 6) == EQUAL || strncmp(code, "042267", 6) == EQUAL ||
- strncmp(code, "042328", 6) == EQUAL)
- {
- for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++)
- {
- if ((chargingInfo[gun]->SystemStatus > S_IDLE && chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
- (chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (strncmp((char *)chargingInfo[gun]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun]->ConnectorAlarmCode, code, 6);
- }
- InformOcppErrOccur(4);
- ChargingAlarmProcess(gun);
- }
- }
- StopChargingProcessByString(level);
- }
- }
- void ReleaseEmsOccureByString(byte index, char *code)
- {
- bool isTrigger = false;
- byte level = 2;
- if (strncmp(code, "042251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
- }
- else if (strncmp(code, "042252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
- }
- else if (strncmp(code, "042237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- }
- else if (strncmp(code, "042238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- else if (strncmp(code, "042267", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = NO;
- }
- if (isTrigger)
- {
- ReleaseChargingProcessByString(level);
- }
- }
- //===============================================
- // 確認硬體 (按鈕) 狀態
- //===============================================
- void ChkPrimaryStatus()
- {
- if(ShmChargerInfo->Control.TestCtrl.bits.ChargingSimulation)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = NO;
- return;
- }
- if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = YES;
- EmcOccureByString("042251");
- }
- else
- {
- ReleaseEmsOccureByString(0, "042251");
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = NO;
- }
- if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
- //EmcOccureByString("042238");
- }
- else
- {
- //ReleaseEmsOccureByString(0, "042238");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
- }
- else
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- }
- if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
- EmcOccureByString("042252");
- }
- else
- {
- ReleaseEmsOccureByString(0, "042252");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == YES)
- {
- EmcOccureByString("042328");
- SetAcContactor(OFF);
- }
- }
- struct timespec _AcContactReOpen_Time;
- void ChkPsuStatus(void)
- {
- if(!ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- {
- for(int psuGroup = 0; psuGroup < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; psuGroup++)
- {
- if(ShmPsuData->PsuGroup[psuGroup].GroupErrorFlag.PsuGroupErrorValue != 0)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
- }
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- {
- EmcOccureByString("042267");
- }
- }
- else
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactor &&
- ShmChargerInfo->Control.PsuCtrl.bits.FailureResume == NO)
- {
- bool allFaultStatus = true;
- for(int gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
- {
- if(chargingInfo[gunIndex]->SystemStatus != S_FAULT && chargingInfo[gunIndex]->SystemStatus != S_MAINTAIN)
- {
- allFaultStatus = false;
- }
- }
- if(allFaultStatus)
- {
- LOG_INFO("PSU Failure, Need Resume");
- ShmChargerInfo->Control.PsuCtrl.bits.FailureResume = YES;
- }
- }
- }
- }
- int AcContactorReOpenCount = 0;
- void PsuFailureResume(void)
- {
- if(ShmChargerInfo->Control.PsuCtrl.bits.FailureResume)
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu == NO)
- {
- LOG_INFO("Ac Contactor Off By Psu Failure");
- // update _AcContactReOpen_Time
- GetClockTime(&_AcContactReOpen_Time);
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = YES;
- AcContactorReOpenCount++;
- }
- else
- {
- if(AcContactorReOpenCount < MAX_AC_CONTACTOR_COUNT)
- {
- if(GetTimeoutValue(_AcContactReOpen_Time) / uSEC_VAL >= AC_CONTACTOR_REOPEN_TIME)
- {
- ReleaseEmsOccureByString(0, "042267");
- // update _AcContactReOpen_Time
- GetClockTime(&_AcContactReOpen_Time);
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = NO;
- ShmChargerInfo->Control.PsuCtrl.bits.FailureResume = NO;
- LOG_INFO("Psu Failure Resume");
- }
- }
- }
- }
- else
- {
- if(AcContactorReOpenCount > 0)
- {
- if(GetTimeoutValue(_AcContactReOpen_Time) / uSEC_VAL >= PSU_FAILURE_RESUME_TIME)
- {
- AcContactorReOpenCount = 0;
- }
- }
- }
- }
- void SetAcContactor(unsigned char OnOff)
- {
- OnOff = OnOff ? ON : OFF;
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactor != OnOff)
- {
- if(OnOff)
- {
- ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown = NO;
- }
- LOG_INFO("Set Ac Contactor %s", OnOff == ON ? "On" : "Off");
- }
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = OnOff == ON ? ON : OFF;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER && ShmChargerInfo->ParallelCabinet.ParallelStatus == _Parallel_None)
- {
- SetParallelCabinetAcContactor(OnOff);
- }
- }
- int GetStandbyTime(void)
- {
- int time = STANDBY_TIME;
- if(ShmChargerInfo->Control.TestCtrl.bits.FastStandbyTime)
- {
- time = FAST_STANDBY_TIME;
- }
- return time;
- }
- void StandbyCheck(void)
- {
- bool enable = IsStandbyEnable();
- if(IsConnectorWholeIdle() && IsParallelCabinetIdle())
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown)
- {
- int time = GetStandbyTime();
- #if CONTACTOR_AUTO_ON_OFF == 1
- time = CONTACTOR_AUTO_ON_TIME;
- #endif
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactor)
- {
- if(GetSecTimeoutValue(_Standby_time) >= time && enable)
- {
- SetAcContactor(OFF);
- }
- }
- #if CONTACTOR_AUTO_ON_OFF == 1
- time = CONTACTOR_AUTO_ON_TIME + CONTACTOR_AUTO_OFF_TIME;
- if((GetTimeoutValue(_Standby_time) / uSEC_VAL) >= time)
- {
- SetAcContactor(ON);
- }
- #endif
- }
- else
- {
- ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown = YES;
- GetClockTime(&_Standby_time);
- }
- }
- else
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown)
- {
- ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown = NO;
- }
- }
- }
- void CheckDisconnectionStatusRecovery(void)
- {
- bool recovery = true;
- // check all connector
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.Disconnection)
- {
- recovery = false;
- }
- }
- if(recovery)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = false;
- }
- }
- //===============================================
- // 確認各小板偵測的錯誤狀況
- //===============================================
- void CheckErrorOccurStatus(byte index)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.NormalStopRequest)
- {
- chargingInfo[index]->ChargingStopFlag.bits.NormalStop = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AlarmStopRequest)
- {
- if(strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].RemotenAlarmCode, 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d Error Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.TimeoutStopRequest)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.TimeoutStopRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.Disconnection = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = true;
- if(chargingInfo[index]->SystemStatus == S_AUTHORIZING ||
- chargingInfo[index]->SystemStatus == S_PREPARNING ||
- chargingInfo[index]->SystemStatus == S_PREPARING_FOR_EV ||
- chargingInfo[index]->SystemStatus == S_PREPARING_FOR_EVSE ||
- chargingInfo[index]->SystemStatus == S_CHARGING)
- {
- if(strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042304", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d Disconnect Alarm Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else if(chargingInfo[index]->SystemStatus == S_REASSIGN_CHECK ||
- chargingInfo[index]->SystemStatus == S_REASSIGN)
- {
- setChargerMode(index, MODE_IDLE);
- }
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo)
- {
- CheckDisconnectionStatusRecovery();
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_PRIMARY;
- StopChargingProcessByString(2);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042251", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042252", 6);
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_PRIMARY)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- // RB
- if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
- StopChargingProcessByString(2);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042203", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042204", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042205", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d RC Board Input UVP Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcInputDisable == NO)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
- StopChargingProcessByString(2);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042200", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042201", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042202", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d RC Board Input OVP Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- }
- else
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
- StopChargingProcessByString(2);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042327", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042328", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Gun %d DC Input OVP/UVP Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- }
- }
- int DiffTimebWithNowSec(struct timeb ST)
- {
- //return milli-second
- struct timeb ET;
- unsigned int StartTime,StopTime;
- ftime(&ET);
- StartTime=(unsigned int)ST.time;
- StopTime=(unsigned int)ET.time;
- return (StopTime-StartTime);
- }
- int CheckTimeOut(char *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)
- {
- // Original data with mini second
- if(strstr((char*)start, "Z") != NULL)
- {
- // Original data with Z
- 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
- {
- // Original data without Z
- 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
- {
- // Original data without mini second
- if(strstr((char*)start, "Z") != NULL)
- {
- // Original data with Z
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec);
- }
- else
- {
- // Original data without Z
- 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
- {
- LOG_INFO("Start date parsing error");
- }
- return result;
- }
- //===============================================
- // Ocpp_Service
- //===============================================
- void Run_Ocpp_Service(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- system("/root/OcppBackend &");
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- system("/root/OcppBackend20 &");
- return;
- }
- }
- bool Is_Ocpp_Task_Alive(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(system("pidof -s OcppBackend > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(system("pidof -s OcppBackend20 > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- return false;
- }
- void Kill_Ocpp_Service(void)
- {
- system("killall OcppBackend");
- system("killall OcppBackend20");
- }
- //===============================================
- // Maintain Ocpp_Service
- //===============================================
- void Run_MaintainOcpp_Service(void)
- {
- system("/root/OcppBackendPH &");
- }
- bool Is_MaintainOcpp_Task_Alive(void)
- {
- if(system("pidof -s OcppBackendPH > /dev/null") != 0)
- {
- return false;
- }
- return false;
- }
- void Kill_MaintainOcpp_Service(void)
- {
- system("killall OcppBackendPH");
- }
- //===============================================
- // Ocpp OcppConnStatus
- //===============================================
- bool Get_Ocpp_ConnectionStatus(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->OcppConnStatus > 0 ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->OcppConnStatus > 0 ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp procDogTime
- //===============================================
- unsigned int Get_Ocpp_procDogTime(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->procDogTime;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->procDogTime;
- }
- return 0;
- }
- void Clean_Ocpp_procDogTime(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->procDogTime = time((time_t*)NULL);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->procDogTime = time((time_t*)NULL);
- return;
- }
- }
- //===============================================
- // Ocpp Boot Notification
- //===============================================
- bool Is_Ocpp_BootNotification(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SpMsg.bits.BootNotificationConf == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_BootNotification(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->SpMsg.bits.BootNotificationConf = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->SpMsg.bits.BootNotificationConf = false;
- return;
- }
- }
- //===============================================
- // Ocpp Rest
- //===============================================
- bool Is_Ocpp_ResetReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MsMsg.bits.ResetReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MsMsg.bits.ResetReq == YES ? true : false;
- }
- return false;
- }
- bool Chk_Ocpp_Reset_Type(char *type)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->Reset.Type, type) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->Reset.type, type) == EQUAL ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ResetReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
- ShmOCPP16Data->MsMsg.bits.ResetReq = false;
- ShmOCPP16Data->MsMsg.bits.ResetConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- sprintf ( (char*) ShmOCPP20Data->Reset.Response_status, "Accepted" );
- ShmOCPP20Data->MsMsg.bits.ResetReq = false;
- ShmOCPP20Data->MsMsg.bits.ResetConf = true;
- return;
- }
- }
- //===============================================
- // Ocpp AuthorizeReq
- //===============================================
- void Set_Ocpp_AuthorizeReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->SpMsg.bits.AuthorizeConf = false;
- ShmOCPP16Data->SpMsg.bits.AuthorizeReq = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->SpMsg.bits.AuthorizeConf = false;
- ShmOCPP20Data->SpMsg.bits.AuthorizeReq = true;
- return;
- }
- }
- bool Is_Ocpp_AuthorizeConf(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SpMsg.bits.AuthorizeConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SpMsg.bits.AuthorizeConf == YES ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_Authorize_Status(char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, status) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, status) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp UpdateFirmwareReq
- //===============================================
- bool Is_Ocpp_UpdateFirmwareReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_UpdateFirmwareReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = false;
- return;
- }
- }
- bool Is_Ocpp_UpdateFirmwareStatus(char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, status) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->FirmwareStatusNotification.status, status) == EQUAL ? true : false;
- }
- return false;
- }
- void Set_Ocpp_UpdateFirmwareStatus(char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, status);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, status);
- return;
- }
- }
- void Clean_Ocpp_UpdateFirmwareStatus(char *status)
- {
- Set_Ocpp_UpdateFirmwareStatus("");
- }
- void Set_Ocpp_FirmwareStatusNotificationReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- return;
- }
- }
- //===============================================
- // Ocpp StopTransactionOnInvalidId
- //===============================================
- bool Is_Ocpp_StopOnInvalidId_Enable(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE") > 0 ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strstr((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE") > 0 ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp AuthorizeRemoteTxRequests
- //===============================================
- bool Is_Ocpp_AuthorizeRemoteTxRequests(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") > 0 ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strstr((char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "TRUE") > 0 ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp ConnectionTimeOut
- //===============================================
- int Get_Ocpp_ConnectionTimeOut(void)
- {
- int timeout = 0;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0)
- {
- timeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "" ) != 0)
- {
- timeout = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
- }
- }
- return timeout > 0 ? timeout : 0;
- }
- //===============================================
- // Ocpp DefaultPrice
- //===============================================
- void Get_Ocpp_DefaultPrice(char *defaultPrice)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(defaultPrice, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(defaultPrice, "");
- return;
- }
- strcpy(defaultPrice, "");
- }
- //===============================================
- // Ocpp UserPrice
- //===============================================
- void Get_Ocpp_UserPrice(char *userId, char *userPrice)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(userId, (char *)ShmOCPP16Data->Cost.SetUserPrice.idToken);
- strcpy(userPrice, (char *)ShmOCPP16Data->Cost.SetUserPrice.price);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(userId, "");
- strcpy(userPrice, "");
- return;
- }
- strcpy(userId, "");
- strcpy(userPrice, "");
- }
- void Clean_Ocpp_UserPrice(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- //===============================================
- // Ocpp RunningCost
- //===============================================
- void Get_Ocpp_RunningCost(int gun_index, char *cost)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(cost, (char *)ShmOCPP16Data->Cost.RunningCost[gun_index].description);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(cost, (char *)"");
- return;
- }
- }
- void Clean_Ocpp_RunningCost(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(&ShmOCPP16Data->Cost.RunningCost[gun_index], 0x00, sizeof(struct StrcutRunningCost));
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- //===============================================
- // Ocpp FinalCost
- //===============================================
- void Get_Ocpp_FinalCost(int gun_index, char *cost)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(cost, (char *)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(cost, (char *)"");
- return;
- }
- }
- void Clean_Ocpp_FinalCost(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(&ShmOCPP16Data->Cost.FinalCost[gun_index], 0x00, sizeof(struct StrcutFinalCost));
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- //===============================================
- // Ocpp TimeOffset
- //===============================================
- void Get_Ocpp_TimeOffset(char *timeOffset)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(timeOffset, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(timeOffset, "");
- return;
- }
- strcpy(timeOffset, "");
- }
- //===============================================
- // Ocpp Refunding
- //===============================================
- void Get_Ocpp_Refunding(char *Refunding)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- void Clean_Ocpp_Refunding(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- //===============================================
- // Ocpp LcdOveride
- //===============================================
- bool Is_Ocpp_LcdOverideReq(int *gun, int *page)
- {
- *gun = ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId;
- *page = ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index;
- return ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq ? true : false;
- }
- void Clean_Ocpp_LcdOverideReq(void)
- {
- ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = false;
- }
- //===============================================
- // Ocpp StationInfo
- //===============================================
- void Get_Ocpp_ChargerStationInfo(int *station_id, char *name)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(name, (char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Is_Ocpp_ChargerStationReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.ChargerInfoReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Clean_Ocpp_ChargerStationReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.ChargerInfoReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp WeatherInfo
- //===============================================
- void Get_Ocpp_WeatherInfo(int *weatherID, float *temperature)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- *weatherID = ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId;
- *temperature = ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Is_Ocpp_WeatherReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.WeatherInfoReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Clean_Ocpp_WeatherReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.WeatherInfoReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp DeductInfo
- //===============================================
- void Set_Ocpp_DeductTransaction(int transaction)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.txId = transaction;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductCreditNo(char *userId)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo, userId, strlen(userId));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductVemData(char *vemData)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.vemData, vemData);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductAmount(double value)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.amount = value;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductResult(unsigned char result)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult = result;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DonateInvoice(unsigned char donate)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice = donate ? YES : NO;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Set_Ocpp_DeductInfo(DeductResultInfoData *deductInfo)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.txId = deductInfo->TransactionId;
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo, (char *)deductInfo->creditNo, sizeof(deductInfo->creditNo));
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.vemData, deductInfo->VemData, sizeof(deductInfo->VemData));
- ShmOCPP16Data->TcciCustomData.DeductInfo.amount = ((double)deductInfo->DeductAmount / 100);
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo, deductInfo->ApprovalNumber, sizeof(deductInfo->ApprovalNumber));
- ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult = deductInfo->DeductResult;
- ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice = deductInfo->IsDonateInvoice ? YES : NO;
- return true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- bool Is_Ocpp_ReportCreditDeductReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Set_Ocpp_ReportCreditDeductReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = YES;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Tcci SerialNo
- //===============================================
- void Clean_Ocpp_TcciSerialNo(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset((char *)&ShmOCPP16Data->TcciCustomData.SerialNo[gun_index], 0x00, sizeof(37));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Tcci ReaderStatus
- //===============================================
- bool Set_Ocpp_TcciReaderStatus(int gun_index, DeductResultInfoData *ReaderStatus)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(ReaderStatus->DeductResult == _Deduct_Cancel || ReaderStatus->DeductResult == _Deduct_PreAuth || ReaderStatus->DeductResult == _Deduct_Pass)
- {
- switch(ReaderStatus->DeductResult)
- {
- case _Deduct_Pass:
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus = 1;
- break;
- case _Deduct_Cancel:
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus = 2;
- break;
- case _Deduct_PreAuth:
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus = 0;
- break;
- }
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo, ReaderStatus->creditNo, sizeof(ReaderStatus->creditNo));
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.VEMData[gun_index], ReaderStatus->VemData, sizeof(ReaderStatus->VemData));
- return true;
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- void Set_Ocpp_TcciReaderStatusReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Is_Ocpp_TcciReaderStatusReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- //===============================================
- // Ocpp Start Transaction
- //===============================================
- void Set_Ocpp_StartTransactionId(int gun_index, char *id)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, id);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent [gun_index].idToken.idToken, id);
- return;
- }
- }
- void Set_Ocpp_StartTransactionReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CpMsg.bits [gun_index].TransactionEventReq = true;
- return;
- }
- }
- bool Is_Ocpp_StartTransactionConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_StartTransactionConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = false;
- return;
- }
- }
- bool Is_Ocpp_StartTransaction_Status(int gun_index, char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, status) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, status) == EQUAL ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_StartTransaction_Accepted(int gun_index)
- {
- return Is_Ocpp_StartTransaction_Status(gun_index, "Accepted");
- }
- void Get_Ocpp_StartTransaction_Status(int gun_index, char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(status, (char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(status, (char *)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status);
- }
- }
- void Get_Ocpp_TransactionId(int gun_index, char *transactionId)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- sprintf(transactionId, "%d", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(transactionId, (char *)&ShmOCPP20Data->TransactionEvent [gun_index].transactionInfo.transactionId[0]);
- return;
- }
- sprintf(transactionId, "%d", 0);
- }
- bool Is_Invalid_StartTransactionId(int gun_index)
- {
- if(Is_Ocpp_StartTransaction_Status(gun_index, "Blocked") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "Expired") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "Invalid") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NoCredit") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NotAllowedTypeEVSE") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NotAtThisLocation") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NotAtThisTime") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "Unknown"))
- {
- return true;
- }
- return false;
- }
- //===============================================
- // Ocpp Stop Transaction
- //===============================================
- void Set_Ocpp_StopTransactionId(int gun_index, char *id)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, id);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent [gun_index].idToken.idToken, id);
- return;
- }
- }
- void Set_Ocpp_StopTransactionReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CpMsg.bits [gun_index].TransactionEventReq = true;
- return;
- }
- }
- //===============================================
- // Ocpp Check Backup Error Code
- //===============================================
- void Chk_Ocpp_Backup_ErrorCode(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "") == EQUAL)
- {
- if(strcmp((char *)_BackupStatusNotification[gun_index].ErrorCode, "") != EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, (char *)_BackupStatusNotification[gun_index].ErrorCode);
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, (char *)_BackupStatusNotification[gun_index].VendorErrorCode);
- }
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Reserve Now
- //===============================================
- bool Is_Ocpp_ReserveNowReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ReserveNowReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowReq = false;
- return;
- }
- }
- int Get_Ocpp_ReserveNowId(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->ReserveNow[gun_index].ReservationId;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->ReserveNow[gun_index].id;
- }
- return 0;
- }
- void Set_Ocpp_ReserveNowConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits [gun_index].ReserveNowConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits [gun_index].ReserveNowConf = true;
- return;
- }
- }
- void Get_Ocpp_ReserveNowExpiryDate(int gun_index, char *date)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(date, (char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(date, (char *)ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime);
- return;
- }
- strcpy(date, "");
- return;
- }
- bool Is_Ocpp_ReserveNowExpired(int gun_index)
- {
- bool _expired = true;
- char _expiryDate[128];
- Get_Ocpp_ReserveNowExpiryDate(gun_index, _expiryDate);
- _expired = CheckTimeOut(_expiryDate);
- return _expired;
- }
- void Get_Ocpp_ReserveNowIdTag(int gun_index, char *idTag)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(idTag, (char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(idTag, (char *)ShmOCPP20Data->ReserveNow[gun_index].idToken.idToken);
- return;
- }
- strcpy(idTag, "");
- return;
- }
- bool Is_Ocpp_ReserveNowIdTag(uint8_t gun_index, char *authIdTag)
- {
- char ReserveIdTag[32];
- Get_Ocpp_ReserveNowIdTag(gun_index, ReserveIdTag);
- return strcmp(ReserveIdTag, authIdTag) == EQUAL ? true : false;
- }
- //===============================================
- // Ocpp Cancel Reservation
- //===============================================
- bool Is_Ocpp_CancelReservationReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_CancelReservationReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationReq = false;
- return;
- }
- }
- void Set_Ocpp_CancelReservationConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits [gun_index].CancelReservationConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits [gun_index].CancelReservationConf = true;
- return;
- }
- }
- //===============================================
- // Ocpp Change Availability
- //===============================================
- bool Is_Ocpp_ChangeAvailabilityReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ChangeAvailabilityReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = false;
- return;
- }
- }
- bool Chk_Ocpp_Availability_Type(int gun_index, char *type)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->ChangeAvailability[gun_index].Type, type) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->ChangeAvailability[gun_index].operationalStatus, type) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp Unlock Connector
- //===============================================
- bool Is_Ocpp_UnlockConnectorReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_UnlockConnectorReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorReq = false;
- return;
- }
- }
- void Set_Ocpp_UnlockConnectorConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus, "Unlocked");
- ShmOCPP16Data->CsMsg.bits [gun_index].UnlockConnectorConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->UnlockConnector[gun_index].Response_status, "Unlocked");
- ShmOCPP20Data->CsMsg.bits [gun_index].UnlockConnectorConf = true;
- return;
- }
- }
- //===============================================
- // Ocpp Remote Start
- //===============================================
- bool Is_Ocpp_RemoteStartReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_RemoteStartReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq = false;
- return;
- }
- }
- void Get_Ocpp_RemoteStartIdTag(int gun_index, char *idTag)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(idTag, (char *)&ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag[0]);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(idTag, (char *)&ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken[0]);
- return;
- }
- strcpy(idTag, "");
- }
- //===============================================
- // Ocpp Remote Stop
- //===============================================
- bool Is_Ocpp_RemoteStopReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].RequestStopTransactionReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_RemoteStopReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].RequestStopTransactionReq = false;
- return;
- }
- }
- //===============================================
- // Ocpp StopReason
- //===============================================
- void Set_Ocpp_StopReason(int gun_index, char *reason)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, reason);
- return;
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "" ) == EQUAL)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, reason);
- return;
- }
- }
- }
- void Get_Ocpp_StopReason(int gun_index, char *reason)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(reason, (char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(reason, (char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason);
- return;
- }
- strcpy(reason, "");
- }
- void Clean_Ocpp_StopReason(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "");
- return;
- }
- }
- //===============================================
- // Ocpp StatusNotification ErrorCode
- //===============================================
- void Set_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, errCode);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- bool Is_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, errCode) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)_BackupStatusNotification[gun_index].ErrorCode, errCode) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp StatusNotification VendorErrorCode
- //===============================================
- void Set_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, vendorCode);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- bool Is_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, vendorCode) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)_BackupStatusNotification[gun_index].VendorErrorCode, vendorCode) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp ChargingProfileConf
- //===============================================
- bool Is_Ocpp_ChargingProfileConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileConf == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ChargingProfileConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = NO;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileConf = NO;
- return;
- }
- }
- //===============================================
- // Ocpp ChargingProfileReq
- //===============================================
- bool Is_Ocpp_ChargingProfileReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == YES ? true : false;
- }
- return false;
- }
- void Set_Ocpp_ChargingProfileReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = YES;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = YES;
- return;
- }
- }
- //===============================================
- // Ocpp SmartChargingProfile ChargingProfileKind
- //===============================================
- bool Is_Ocpp_ChargingProfileKind(int gun_index, char *kind)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileKind, kind) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->SmartChargingProfile [gun_index].chargingProfileKind, kind) == EQUAL ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_ChargingProfileId(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].id == YES ? true : false;
- }
- return false;
- }
- int Get_Ocpp_ChargingProfileStartTime(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.StartSchedule);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].startSchedule);
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileScheduleCount(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod);
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileScheduleTime(int gun_index, int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[schedule_index].StartPeriod;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[schedule_index].startPeriod;
- }
- return 0;
- }
- float Get_Ocpp_ChargingProfileScheduleLimit(int gun_index, int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[schedule_index].Limit;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[schedule_index].limit;
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileScheduleNumberPhases(int gun_index, int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[schedule_index].NumberPhases;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[schedule_index].numberPhases;
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileStartIndex(int gun_index)
- {
- int _time = 0, _scheduleTime = 0;
- int _maxCount = 0;
- float _limit = 0;
- int _startCount = NO_DEFINE;
- _time = Get_Ocpp_ChargingProfileStartTime(gun_index);
- _maxCount = Get_Ocpp_ChargingProfileScheduleCount(gun_index);
- for(int i = 0; i < _maxCount; i++)
- {
- _scheduleTime = Get_Ocpp_ChargingProfileScheduleTime(gun_index, i);
- if(_time >= _scheduleTime)
- {
- _limit = Get_Ocpp_ChargingProfileScheduleLimit(gun_index, i);
- if((i == 0 && _limit >= MIN_OUTPUT_CUR) || _limit > MIN_OUTPUT_CUR)
- {
- _startCount = i;
- }
- }
- }
- return _startCount;
- }
- //===============================================
- // Ocpp MaxChargingProfile ChargingProfileKind
- //===============================================
- bool Is_Ocpp_MaxChargingProfileKind(char *kind)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->MaxChargingProfile.ChargingProfileKind, kind) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->MaxChargingProfile.chargingProfileKind, kind) == EQUAL ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_MaxChargingProfileId(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingProfileId == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.id == YES ? true : false;
- }
- return false;
- }
- int Get_Ocpp_MaxProfileStartTime(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return GetStartScheduleTime(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.StartSchedule);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return GetStartScheduleTime(ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].startSchedule);
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileScheduleCount(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ARRAY_SIZE(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ARRAY_SIZE(ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod);
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileScheduleTime(int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[schedule_index].StartPeriod;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[schedule_index].startPeriod;
- }
- return 0;
- }
- float Get_Ocpp_MaxProfileScheduleLimit(int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[schedule_index].Limit;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[schedule_index].limit;
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileScheduleNumberPhases(int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[schedule_index].NumberPhases;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[schedule_index].limit;
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileStartIndex(void)
- {
- int _time = 0, _scheduleTime = 0;
- int _maxCount = 0;
- float _limit = 0;
- int _startCount = NO_DEFINE;
- _time = Get_Ocpp_MaxProfileStartTime();
- _maxCount = Get_Ocpp_MaxProfileScheduleCount();
- for(int i = 0; i < _maxCount; i++)
- {
- _scheduleTime = Get_Ocpp_MaxProfileScheduleTime(i);
- if(_time >= _scheduleTime)
- {
- _limit = Get_Ocpp_MaxProfileScheduleLimit(i);
- if((i == 0 && _limit >= MIN_OUTPUT_CUR) || _limit > MIN_OUTPUT_CUR)
- {
- _startCount = i;
- }
- }
- }
- return _startCount;
- }
- //===============================================
- // Ocpp isRemoteStartWaitReq
- //===============================================
- int Is_Ocpp_RemoteStartWaitReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq;
- }
- return 0;
- }
- //===============================================
- // DeductResult
- //===============================================
- void Set_Deduct_UserId(int gunIndex, char *userId)
- {
- memcpy((char *)&ShmChargerInfo->DeductResultReq[gunIndex].creditNo, userId, strlen(userId));
- }
- void Set_Deduct_TransactionId(int gunIndex, int transaction)
- {
- ShmChargerInfo->DeductResultReq[gunIndex].TransactionId = transaction;
- }
- void Clean_DeductInfo(int gunIndex)
- {
- memset(&ShmChargerInfo->DeductResultReq[gunIndex], 0x00, sizeof(DeductResultInfoData));
- }
- bool Is_DeductResultReq(int gunIndex)
- {
- return ShmChargerInfo->DeductResultReq[gunIndex].DeductReq ? true : false;
- }
- //===============================================
- // ReaderStatus
- //===============================================
- bool Is_ReaderStatusReq(int gunIndex)
- {
- return ShmChargerInfo->ReaderStatus[gunIndex].ReaderStatusReq ? true : false;
- }
- void Clean_ReaderStatusInfo(int gunIndex)
- {
- memset(&ShmChargerInfo->ReaderStatus[gunIndex], 0x00, sizeof(DeductResultInfoData));
- }
- //===============================================
- // TransactionInfoData
- //===============================================
- void Set_UserTransactionId(int gunIndex, int transaction)
- {
- ShmChargerInfo->UserTransaction[gunIndex].TransactionId = transaction;
- }
- void Set_UserPrice(int gunIndex, float price)
- {
- ShmChargerInfo->UserTransaction[gunIndex].UserPrice = price;
- }
- void Set_UserTotalCost(int gunIndex, float cost)
- {
- ShmChargerInfo->UserTransaction[gunIndex].TotalCost = cost;
- }
- void Set_UserAccountBalance(int gunIndex, float balance)
- {
- ShmChargerInfo->UserTransaction[gunIndex].AccountBalance = balance;
- }
- void Set_UserDiscount(int gunIndex, float discount)
- {
- ShmChargerInfo->UserTransaction[gunIndex].CostDiscount = discount;
- }
- void Clean_UserTransaction(int gunIndex)
- {
- memset(&ShmChargerInfo->UserTransaction[gunIndex], 0x00, sizeof(TransactionInfoData));
- ShmChargerInfo->UserTransaction[gunIndex].AccountBalance = -65535;
- }
- //===============================================
- // Main process
- //===============================================
- // 檢查 Byte 中某個 Bit 的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
- {
- return ( _byte & mask_table[_bit] ) != 0x00;
- }
- // 設定 Byte 中某個 Bit的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- // value : 修改的值為 0 or 1
- void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
- {
- if(value == 1)
- *_byte |= (1 << _bit);
- else if (value == 0)
- *_byte ^= (1 << _bit);
- }
- void UserScanFunction()
- {
- }
- 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 AnnounceAccountBalance(unsigned char index, float balance)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance = true;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AccountBalance = balance;
- if(!ShmChargerInfo->Control.TestCtrl.bits.DisableBalance)
- {
- Set_Connector_MiscCommand(index, MISC_CONN_ACCOUNT_BALANCE);
- }
- LOG_INFO("%sAnnounce Account Balance %4.2f To Connector %d",
- ShmChargerInfo->Control.TestCtrl.bits.DisableBalance ? "Do Not " : "", balance, index + 1);
- }
- void FouceAnnounceAccountBalance(unsigned char index)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance)
- {
- AnnounceAccountBalance(index, 0);
- }
- }
- void CleanConnectorUserIdAndPrice(unsigned char index)
- {
- if(chargingInfo[index]->SystemStatus == S_IDLE)
- {
- LOG_INFO("*********** Connector %d Clean UserId & UserPrice ***********", index + 1);
- memset(chargingInfo[index]->StartUserId, 0x00, 32);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].UserPrice = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AccountBalance = -65535;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance = false;
- }
- }
- void DispenserAuthInitial(unsigned char dispenser)
- {
- LOG_INFO("*********** Dispenser %d Authorizing Initial ***********", dispenser + 1);
- memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- }
- void GunAuthInitial(unsigned char connector)
- {
- LOG_INFO("*********** Gun %d Authorizing Initial ***********", connector + 1);
- memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- }
- unsigned char _preGunAuthResult[GENERAL_GUN_QUANTITY];
- unsigned char _preDispenserAuthResult[GENERAL_GUN_QUANTITY];
- struct timespec _GunAuth_Time[GENERAL_GUN_QUANTITY];
- struct timespec _DispenserAuth_Time[GENERAL_GUN_QUANTITY];
- void AuthorizeTimeoutProcess(void)
- {
- int CompletedTime = 0;
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult != _AuthResult_None)
- {
- if(_preGunAuthResult[index] != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult)
- {
- GetClockTime(&_GunAuth_Time[index]);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult == _AuthResult_Invalid)
- {
- FouceAnnounceAccountBalance(index);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult == _AuthResult_Invalid)
- {
- if(GetTimeoutValue(_GunAuth_Time[index]) / uSEC_VAL >= AUTHORIZE_COMPLETED_TIME)
- {
- LOG_INFO("*********** Gun %d Authorizing Initial ***********", index + 1);
- memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- CleanConnectorUserIdAndPrice(index);
- }
- }
- }
- _preGunAuthResult[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult;
- }
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult != _AuthResult_None)
- {
- if(_preDispenserAuthResult[index] != ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult)
- {
- GetClockTime(&_DispenserAuth_Time[index]);
- }
- CompletedTime = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult == _AuthResult_Valid ?
- ShmChargerInfo->CabinetMiscValue.ConnectionTimeout : AUTHORIZE_COMPLETED_TIME;
- if(GetTimeoutValue(_DispenserAuth_Time[index]) / uSEC_VAL >= CompletedTime)
- {
- LOG_INFO("*********** Dispenser %d Authorizing Initial ***********", index + 1);
- memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- }
- }
- _preDispenserAuthResult[index] = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult;
- }
- }
- BOOL IsConnectorAuthorizeSuccess(unsigned char connector)
- {
- BOOL success = false;
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].AuthInfo.AuthResult == _AuthResult_Valid)
- {
- success = true;
- }
- return success;
- }
- BOOL IsAutoGunSelectionAuthorizeSuccess(unsigned char connector)
- {
- BOOL success = false;
- unsigned char dispenser = 0;
- dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].ParentDispensetIndex;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].AuthInfo.AuthResult == _AuthResult_Valid)
- {
- success = true;
- }
- return success;
- }
- unsigned short ParsingRatingPower(char *modelname)
- {
- char strVal[3], strExp[2];
- unsigned short value = 0, exponent = 0;
- memset(strVal, 0x00, sizeof(strVal));
- memset(strExp, 0x00, sizeof(strExp));
- memcpy(strVal, &modelname[4], 2);
- memcpy(strExp, &modelname[6], 1);
- value = atoi(strVal);
- exponent = atoi(strExp);
- if(value < 0 || exponent < 0)
- {
- return 0;
- }
- for(int i = 0; i < exponent; i++)
- {
- value *= 10;
- }
- return value;
- }
- bool CheckConnectorTypeStatus(void)
- {
- bool result = true;
- if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 14)
- {
- // DO360 for Audi, two gun only
- _gunIndex = ShmChargerInfo->Control.MaxConnector;
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = _gunIndex;
- ShmChargerInfo->Control.ChargerRatingPower = ParsingRatingPower((char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- LOG_INFO("DC Gun Count = %d, RatingPower = %d.%d kW",
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
- (ShmChargerInfo->Control.ChargerRatingPower / 10),
- (ShmChargerInfo->Control.ChargerRatingPower % 10));
- if(ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0)
- {
- result = false;
- }
- //DO360 charging info default setting
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- chargingInfo[i] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData;
- chargingInfo[i]->Index = (i < ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity || i == 0) ? i : 0xFF;
- chargingInfo[i]->Evboard_id = 0x00;
- chargingInfo[i]->ReservationId = -1;
- chargingInfo[i]->slotsIndex = 0;
- chargingInfo[i]->SystemStatus = S_BOOTING;
- chargingInfo[i]->Type = _Type_Unknown;
- chargingInfo[i]->type_index = 0;
- chargingInfo[i]->IsAvailable = YES;
- }
- }
- else
- {
- // Module Name 不正確 - 告警
- result = false;
- }
- return result;
- }
- void KillTaskExceptPrimary()
- {
- system("killall Module_Authorize");
- system("killall Module_CabinetParallel");
- system("killall Module_ChargerSelfTest");
- system("killall Module_LedIndication");
- system("killall Module_EvComm");
- system("killall Module_InternalComm");
- system("killall Module_PsuComm");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- }
- void KillAllTask()
- {
- system("killall Module_Authorize");
- system("killall Module_CabinetParallel");
- system("killall Module_ChargerSelfTest");
- system("killall Module_LedIndication");
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_LcmControl");
- system("killall Module_InternalComm");
- system("killall Module_PsuComm");
- Kill_Ocpp_Service();
- Kill_MaintainOcpp_Service();
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- }
- int TransferImageViaFTP(char *IpAddress, char *SourcePath)
- {
- int isPass = PASS;
- unsigned char ftpcmdbuf[256];
- LOG_INFO("Transfer image(%s) to ip: %s ", SourcePath, IpAddress);
- //Using ftpput command to transfer upgrade image,
- //User name : root
- //User password : y42j/4cj84
- //Destination : as same as source path
- sprintf((char*)ftpcmdbuf,"ftpput -u root -p y42j/4cj84 %s %s %s", IpAddress, SourcePath, SourcePath);
- if(system((char*)ftpcmdbuf) != 0)
- {
- isPass = FAIL;
- LOG_INFO("Transfer Image NG - FTP put upgrade image to fail");
- }
- else
- {
- LOG_INFO("FTP put Image OK");
- }
- return isPass;
- }
- void TriggerDispenserUpgrade(unsigned char index, char *FileName)
- {
- memset(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].FwFileName, 0x00, 128);
- memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].FwFileName, FileName, strlen(FileName));
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].Setting.bits.FirmwareUpdateRequest = true;
- LOG_INFO("Trigger dispenser %d to update image [%s]", index + 1, FileName);
- }
- BOOL PutImageToAllDispenser(char *SourcePath, char *FileName)
- {
- int isPass = FAIL;
- BOOL transferred = FALSE;
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched)
- {
- char DispenserIpAddress[16];
- memset((char*)DispenserIpAddress, 0x00, 16);
- sprintf((char*)DispenserIpAddress, "%d.%d.%d.%d",
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 0) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 8) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 16) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 24) & 0xFF));
- isPass = TransferImageViaFTP(DispenserIpAddress, SourcePath);
- if(isPass == PASS)
- {
- TriggerDispenserUpgrade(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex, FileName);
- }
- transferred = true;
- }
- }
- return transferred;
- }
- BOOL WaitAllDispenserUpgradeCompleted(void)
- {
- BOOL completed = TRUE;
- GetClockTime(&_DispenserUpgrade_time);
- do
- {
- completed = TRUE;
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateRequest ||
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateConfirm)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateCompleted)
- {
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateRequest = false;
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateConfirm = false;
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateCompleted = false;
- LOG_INFO("Dispenser %d Upgrade Success", i + 1);
- }
- else
- {
- completed = FALSE;
- }
- }
- }
- if(GetTimeoutValue(_DispenserUpgrade_time) / uSEC_VAL >= DISPENSER_UPGRADE_TIME)
- {
- LOG_INFO("Wait Upgrade Timeout");
- completed = FALSE;
- break;
- }
- if(completed == FALSE)
- {
- sleep(1);
- }
- }while(!completed);
- return completed;
- }
- void UpgradePrepare(void)
- {
- int count = 0;
- SetAcContactor(OFF);
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- count++;
- }
- }
- }
- if(count > 0)
- {
- sleep(3);
- }
- else
- {
- sleep(1);
- }
- }
- void TriggerPCabinetUpgrade(unsigned char index, char *FileName)
- {
- memset(ShmChargerInfo->ParallelCabinet.PCabinet[index].FwFileName, 0x00, 128);
- memcpy(ShmChargerInfo->ParallelCabinet.PCabinet[index].FwFileName, FileName, strlen(FileName));
- ShmChargerInfo->ParallelCabinet.PCabinet[index].UpdateRequest = YES;
- LOG_INFO("Trigger PCabinet %d to update image [%s]", index + 1, FileName);
- }
- BOOL PutImageToAllParallelCabinet(char *SourcePath, char *FileName)
- {
- int isPass = FAIL;
- BOOL transferred = FALSE;
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- int channel = ShmChargerInfo->ParallelCabinet.PCabinet[i].SocketChannel;
- if(ShmChargerInfo->CabinetConnInfo[channel].Status == _SCONN_MATCHED &&
- ShmChargerInfo->ParallelCabinet.PCUpdateState[i] == Not_Update)
- {
- char PCabinetIpAddress[16];
- memset((char*)PCabinetIpAddress, 0x00, 16);
- sprintf((char*)PCabinetIpAddress, "%d.%d.%d.%d",
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 0) & 0xFF),
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 8) & 0xFF),
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 16) & 0xFF),
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 24) & 0xFF));
- isPass = TransferImageViaFTP(PCabinetIpAddress, SourcePath);
- if(isPass == PASS)
- {
- TriggerPCabinetUpgrade(i, FileName);
- }
- transferred = true;
- }
- }
- }
- return transferred;
- }
- BOOL WaitAllPCabinetStartUpgrade(void)
- {
- BOOL isStart = true;
- int count = 0;
- struct timespec _waitStart;
- GetClockTime(&_waitStart);
- do
- {
- isStart = true;
- count = 0;
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- count++;
- if(ShmChargerInfo->ParallelCabinet.PCUpdateState[i] != Updating)
- {
- isStart = false;
- }
- }
- }
- if((GetTimeoutValue(_waitStart) / uSEC_VAL) >= START_UPGRADE_TIME)
- {
- isStart = false;
- break;
- }
- usleep(10000);
- }while(!isStart);
- if(isStart && count > 0)
- {
- LOG_INFO("Total %d PCabinet upgrade start...", count);
- }
- else
- {
- if(count > 0)
- {
- LOG_INFO("Wait PCabinet upgrade timeout");
- }
- else
- {
- LOG_INFO("No PCabinet need to upgrade");
- }
- }
- return isStart;
- }
- BOOL WaitAllPCabinetUpgradeCompleted(void)
- {
- BOOL completed = true;
- int count = 0;
- struct timespec _waitCompleted;
- GetClockTime(&_waitCompleted);
- do
- {
- completed = true;
- count = 0;
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- count++;
- if(ShmChargerInfo->ParallelCabinet.PCUpdateState[i] != Updated)
- {
- completed = false;
- }
- }
- }
- if((GetTimeoutValue(_waitCompleted) / uSEC_VAL) >= PCABINET_UPGRADE_TIME)
- {
- completed = false;
- break;
- }
- usleep(10000);
- }while(!completed);
- if(completed && count > 0)
- {
- LOG_INFO("Total %d PCabinet upgrade completed!", count);
- }
- else
- {
- if(count > 0)
- {
- LOG_INFO("Wait PCabinet upgrade completed timeout");
- }
- else
- {
- LOG_INFO("Need not to wait PCabinet completed");
- }
- }
- return completed;
- }
- BOOL WaitMCabinetUpgradeCompleted(void)
- {
- BOOL completed = true;
- struct timespec _waitCompleted;
- GetClockTime(&_waitCompleted);
- do
- {
- completed = false;
- if(ShmChargerInfo->SCabinetControl.NeedUpgrade == _R_NoUpgrade)
- {
- completed = true;
- }
- if(ShmChargerInfo->SCabinetControl.SCabinetStatus != _DeviceStatus_Idle &&
- ShmChargerInfo->SCabinetControl.SCabinetStatus != _DeviceStatus_Alarm &&
- ShmChargerInfo->SCabinetControl.SCabinetStatus != _DeviceStatus_Charging)
- {
- completed = false;
- break;
- }
- if((GetTimeoutValue(_waitCompleted) / uSEC_VAL) >= MCABINET_UPGRADE_TIME)
- {
- completed = false;
- break;
- }
- usleep(10000);
- }while(!completed);
- if(completed)
- {
- LOG_INFO("MCabinet upgrade completed!");
- }
- else
- {
- LOG_INFO("Wait MCabinet upgrade timeout or disconnected...");
- }
- return completed;
- }
- bool IsModelNameMatch(char *model)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == model[0] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[1] == model[1] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[7] == model[7] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[8] == model[8] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[9] == model[9] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[11] == model[11] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[12] == model[12] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[13] == model[13])
- {
- return true;
- }
- return false;
- }
- char CheckUpdateProcess()
- {
- char model[32];
- bool support = false;
- bool OneImageOnly = false;
- int isPass = true;
- uint8_t retSucc = 0;
- uint8_t retFail = 0;
- byte target = 0;
- char *new_str = NULL;
- unsigned char *ptr = NULL;
- int fd = 0;
- int uartFd = 0;
- unsigned int Type = 0;
- long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
- DIR *d;
- struct dirent *dir;
- char cmdBuf[128];
- d = opendir("/mnt/");
- if(d)
- {
- while((dir = readdir(d)) != NULL && !OneImageOnly)
- {
- if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
- continue;
- }
- new_str = calloc(strlen("/mnt/") + strlen(dir->d_name) + 1, sizeof(char));
- strcat(new_str, "/mnt/");
- strcat(new_str, dir->d_name);
- fd = open(new_str, O_RDONLY);
- if(fd < 0)
- {
- close(fd);
- free(new_str);
- continue;
- }
- LOG_INFO("%s\n", new_str);
- ptr = calloc(MaxLen, sizeof(char)); //-48 is take out the header
- memset(ptr, 0xFF, MaxLen); //-48 is take out the header
- //get the image length
- ImageLen = read(fd, ptr, MaxLen);
- if (ImageLen > 20)
- {
- support = false;
- memcpy(model, ptr, 16);
- LOG_INFO("Model: %s", model);
- Type = (((unsigned int)ptr[16]) << 24 | ((unsigned int)ptr[17]) << 16 | ((unsigned int)ptr[18]) << 8 | ((unsigned int)ptr[19]));
- LOG_INFO("Typed...%x", Type);
- //if(strcmp(model, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == EQUAL)
- if(IsModelNameMatch(model))
- {
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- PutImageToAllParallelCabinet(new_str, dir->d_name);
- WaitAllPCabinetStartUpgrade();
- }
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE && ShmChargerInfo->SCabinetControl.NeedUpgrade)
- {
- ShmChargerInfo->SCabinetControl.UpgradeState = Updating;
- sleep(1);
- }
- switch (Type)
- {
- case 0x10000001:
- case 0x10000002:
- case 0x10000003:
- case 0x10000004:
- case 0x10000005:
- support = true;
- _UpgradeNeedReboot = TRUE;
- isPass = Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- break;
- case 0x10000006: // primary mcu
- case 0x1000000D: // relay board
- case 0x1000000E: // fan board
- case 0x10000014: // led board
- support = true;
- target = 0x00;
- if (Type == 0x10000006)
- {
- target = UPGRADE_PRI;
- }
- else if (Type == 0x1000000D)
- {
- target = UPGRADE_RB;
- }
- else if (Type == 0x1000000E)
- {
- target = UPGRADE_FAN;
- }
- else if (Type == 0x10000014)
- {
- target = UPGRADE_LED;
- }
- uartFd = InitComPort(target);
- if(target == UPGRADE_RB)
- {
- isPass = Upgrade_UART(uartFd, Type, UPGRADE_DORC1, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- if(isPass == PASS)
- {
- retSucc++;
- }
- else
- {
- retFail++;
- }
- LOG_INFO("Upgrade %s", isPass == PASS ? "Success" : "Fail");
- sleep(3);
- isPass = Upgrade_UART(uartFd, Type, UPGRADE_DORC2, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- }
- else
- {
- isPass = Upgrade_UART(uartFd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- }
- close(uartFd);
- break;
- }
- if(support)
- {
- if(isPass == PASS)
- {
- retSucc++;
- }
- else
- {
- retFail++;
- }
- LOG_INFO("Upgrade %s", isPass == PASS ? "Success" : "Fail");
- }
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- LOG_INFO("MCabinet upgrade completed");
- WaitAllPCabinetUpgradeCompleted();
- }
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE && ShmChargerInfo->SCabinetControl.UpgradeState == Updating)
- {
- ShmChargerInfo->SCabinetControl.UpgradeState = Updated;
- LOG_INFO("SCabinet upgrade completed");
- WaitMCabinetUpgradeCompleted();
- }
- }
- else
- {
- if(model[0] == 'D' && (model[1] == 'D' || model[1] == 'X'))
- {
- OneImageOnly = true;
- _UpgradeNeedReboot = TRUE;
- LOG_INFO("Start Put Image To All Dispenser");
- PutImageToAllDispenser(new_str, dir->d_name);
- WaitAllDispenserUpgradeCompleted();
- LOG_INFO("All Dispenser Upgrade Completed");
- }
- }
- }
- sprintf(cmdBuf, "rm -f %s", new_str);
- system(cmdBuf);
- close(fd);
- free(new_str);
- free(ptr);
- }
- }
- free(dir);
- closedir(d);
- if(retFail != 0)
- {
- return FAIL;
- }
- return PASS;
- }
- void TriggerDispenserConnectionTimeoutSetting(void)
- {
- BOOL trigger = FALSE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0 &&
- !Is_Dispenser_MiscCommand(i, MISC_DISP_CONNECTION_TIMEOUT))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_CONNECTION_TIMEOUT);
- }
- }
- if(trigger)
- {
- LOG_INFO("********** Trigger Dispenser Connector Timeout Value: %d **********", ShmChargerInfo->CabinetMiscValue.ConnectionTimeout);
- }
- }
- void CheckConnectionTimeout(void)
- {
- if(!Is_Ocpp_Task_Alive())
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- else
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _connectionTimeout = Get_Ocpp_ConnectionTimeOut();
- if(_connectionTimeout <= 0)
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- }
- else
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- }
- if(_connectionTimeout != ShmChargerInfo->CabinetMiscValue.ConnectionTimeout)
- {
- ShmChargerInfo->CabinetMiscValue.ConnectionTimeout = _connectionTimeout;
- TriggerDispenserConnectionTimeoutSetting();
- }
- }
- void CreateTimeoutFork()
- {
- pid_t timeoutPid;
- timeoutPid = fork();
- if (timeoutPid == 0)
- {
- GetClockTime(&_cmdSubPriority_time);
- CheckConnectionTimeout();
- LOG_INFO("Timeout Fork PID = %d", getpid());
- while(true)
- {
- if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000)
- {
- CheckConnectionTimeout();
- GetClockTime(&_cmdSubPriority_time);
- }
- sleep(1);
- }
- }
- }
- void CheckFactoryConfigFunction(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
- {
- char Buf[256];
- sprintf(Buf, "cd /root;./FactoryConfig -m");
- system(Buf);
- system("rm -f /Storage/OCPP/OCPPConfiguration");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- }
- void CheckFwUpdateFunction(void)
- {
- char UpdateResult = PASS;
- if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedSelfTest = false;
- UpgradePrepare();
- ShmChargerInfo->Control.PrimaryCtrl.bits.Paused = true;
- ShmChargerInfo->Control.RelayCtrl.bits.Paused = true;
- ShmChargerInfo->Control.FanCtrl.bits.Paused = true;
- LOG_INFO("ftp : update start.");
- TryCloseWatchdog();
- //KillTask();
- system("killall Module_PrimaryComm");
- system("killall Module_InternalComm");
- UpdateResult = CheckUpdateProcess();
- if (UpdateResult == PASS)
- {
- LOG_INFO("ftp : update complete.");
- }
- else
- {
- LOG_INFO("ftp : update fail.");
- }
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
- sleep(10);
- if(_UpgradeNeedReboot)
- {
- system("reboot -f");
- }
- else
- {
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- else if(Is_Ocpp_UpdateFirmwareReq())
- {
- Clean_Ocpp_UpdateFirmwareReq();
- ShmChargerInfo->Control.SysCtrl.bits.NeedSelfTest = false;
- UpgradePrepare();
- ShmChargerInfo->Control.PrimaryCtrl.bits.Paused = true;
- ShmChargerInfo->Control.RelayCtrl.bits.Paused = true;
- ShmChargerInfo->Control.FanCtrl.bits.Paused = true;
- if(Is_Ocpp_UpdateFirmwareStatus("Downloaded"))
- {
- LOG_INFO("Backend : update start.");
- TryCloseWatchdog();
- Set_Ocpp_UpdateFirmwareStatus("Installing");
- Set_Ocpp_FirmwareStatusNotificationReq();
- //KillTask();
- system("killall Module_PrimaryComm");
- system("killall Module_InternalComm");
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- setChargerMode(_index, MODE_UPDATE);
- }
- UpdateResult = CheckUpdateProcess();
- if (UpdateResult == PASS)
- {
- LOG_INFO("Backend : update complete.");
- Set_Ocpp_UpdateFirmwareStatus("Installed");
- }
- else
- {
- LOG_INFO("Backend : update fail.");
- Set_Ocpp_UpdateFirmwareStatus("InstallationFailed");
- }
- Set_Ocpp_FirmwareStatusNotificationReq();
- sleep(10);
- if(_UpgradeNeedReboot)
- {
- system("reboot -f");
- }
- else
- {
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- }
- }
- void ExecuteWriteWiringInfo(void)
- {
- struct SysConfigData config;
- memcpy(&config, &ShmSysConfigAndInfo->SysConfig, sizeof(struct SysConfigData));
- config.SwitchDebugFlag = NO;
- strcpy((char *) config.UserId, "");
- int result = StoreUsrConfigData(&config);
- if(result != 1)
- {
- LOG_INFO("Store User Config NG");
- }
- else
- {
- LOG_INFO("Store User Config OK");
- }
- }
- struct timespec _WiringInfo_time;
- int CheckWiringInfoUpdate(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged)
- {
- ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = false;
- LOG_INFO("Flash Config Changed");
- GetClockTime(&_WiringInfo_time);
- ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.EnableWriteFlash = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.EnableWriteFlash)
- {
- // 30s for reboot request timeout
- if((GetTimeoutValue(_WiringInfo_time) / uSEC_VAL) >= WIRING_INFO_DELAY ||
- ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.CleanWiringInfo)
- {
- ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.EnableWriteFlash = false;
- LOG_INFO("Start Write To Flash");
- pid_t writePid = fork();
- if(writePid == 0)
- {
- ExecuteWriteWiringInfo();
- if(ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.CleanWiringInfo)
- {
- ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.CleanWiringInfo = false;
- ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
- LOG_INFO("Clean Wiring Info And Need Soft Reset");
- }
- return NO;
- }
- LOG_INFO("Clean Write Flahs Flag");
- }
- }
- return YES;
- }
- void CheckSoftHardReset(void)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset)
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = false;
- LOG_INFO("********** Need Soft Reset **********");
- sleep(5);
- Kill_Ocpp_Service();
- KillAllTask();
- TryCloseWatchdog();
- system("/usr/bin/run_evse_restart.sh");
- }
- if(ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset)
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = false;
- LOG_INFO("********** Need Hard Reset **********");
- sleep(5);
- system("reboot -f");
- }
- }
- struct timespec _Reboot_time;
- void TriggerDispenserHardwareReboot(void)
- {
- BOOL trigger = FALSE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.HardwareRebootConfirm == 0 &&
- !Is_Dispenser_MiscCommand(i, MISC_DISP_SOFTWARE_RESET))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_HARDWARE_REBOOT);
- }
- }
- }
- if(trigger)
- {
- GetClockTime(&_Reboot_time);
- LOG_INFO("********** Trigger Dispenser Hardware Reboot **********");
- }
- }
- BOOL IsDispenserHardwareRebootResponsed(void)
- {
- BOOL response_ok = TRUE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.HardwareRebootConfirm)
- {
- response_ok = FALSE;
- // 10s for reboot request timeout
- if((GetTimeoutValue(_Reboot_time) / uSEC_VAL) >= REBOOT_TIMEOUT)
- {
- response_ok = TRUE;
- LOG_INFO("Reboot request timeout");
- }
- }
- }
- }
- return response_ok;
- }
- struct timespec _Reset_time;
- void TriggerDispenserSoftwareReset(void)
- {
- BOOL trigger = FALSE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.SoftwareResetConfirm == 0 &&
- !Is_Dispenser_MiscCommand(i, MISC_DISP_SOFTWARE_RESET))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_SOFTWARE_RESET);
- }
- }
- }
- if(trigger)
- {
- GetClockTime(&_Reset_time);
- LOG_INFO("********** Trigger Dispenser Software Reset **********");
- }
- }
- BOOL IsDispenserSoftwareResetResponsed(void)
- {
- BOOL response_ok = TRUE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.SoftwareResetConfirm)
- {
- response_ok = FALSE;
- // 10s for reset request timeout
- if((GetTimeoutValue(_Reset_time) / uSEC_VAL) >= RESET_TIMEOUT)
- {
- response_ok = TRUE;
- LOG_INFO("Reset request timeout");
- }
- }
- }
- }
- return response_ok;
- }
- float TariffParsing(char *StringItem, char *TariffCode)
- {
- char *ptrSave, *ptrToken;
- char strSource[128];
- float 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++;
- fee = atof(strFee);
- break;
- }
- }
- ptrToken = strtok_r(NULL, ";", &ptrSave);
- }
- return fee;
- }
- float PhTariffParsing(char *StringItem, char *TariffCode)
- {
- char *ptrSave, *ptrToken;
- char strSource[128];
- float 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++;
- fee = atof(strFee);
- break;
- }
- }
- ptrToken = strtok_r(NULL, ",", &ptrSave);
- }
- return fee;
- }
- // the unit of return value: 0.01 dollar
- float DefaultPriceParsing(char *StringItem)
- {
- char *ptrSave, *ptrToken;
- char strSource[128];
- float fee = 0;
- memcpy(strSource, StringItem, 128);
- ptrToken = strtok_r(strSource, ",", &ptrSave);
- while(ptrToken != NULL)
- {
- char *strFee = strstr(ptrToken, "$");
- if(strFee != NULL)
- {
- strFee++;
- fee = atof(strFee);
- break;
- }
- else
- {
- fee = atof(ptrToken);
- break;
- }
- ptrToken = strtok_r(NULL, ",", &ptrSave);
- }
- return fee;
- }
- // return time offset
- int TimeOffsetKeyParsing(char *StringItem)
- {
- int offset = 0;
- int hour = 0, minute = 0, sign = 1;
- char *ptrSave, *ptrToken;
- char strSource[501];
- memset(strSource, 0x00, sizeof(strSource));
- strcpy(strSource, StringItem);
- if(strSource[0] != '+' && strSource[0] != '-')
- {
- return offset;
- }
- sign = strSource[0] == '+' ? (1) : (-1);
- ptrToken = strtok_r(&strSource[1], ":", &ptrSave);
- if(ptrToken != NULL)
- {
- hour = atoi(ptrToken);
- ptrToken = strtok_r(NULL, ":", &ptrSave);
- if(ptrToken != NULL)
- {
- minute = atoi(ptrToken);
- offset = ((hour * 60) + minute) * sign;
- }
- }
- return offset;
- }
- char MyDefaultPriceString[501];
- void DefaultPriceHandler(void)
- {
- char price[501];
- Get_Ocpp_DefaultPrice((char *)price);
- if(strcmp(MyDefaultPriceString, (char *)price) != EQUAL)
- {
- BOOL trigger = FALSE;
- float ConnectionFee = 0, CurrentRate = 0, OccupancyFee = 0;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- ConnectionFee = TariffParsing(price, "Connection Fee");
- CurrentRate = TariffParsing(price, "Current Rate");
- OccupancyFee = TariffParsing(price, "Occupancy Fee");
- }
- else
- {
- CurrentRate = DefaultPriceParsing(price);
- }
- LOG_INFO("********** Default Price: %s", price);
- LOG_INFO("********** Connection Fee: %4.2f **********", ConnectionFee);
- LOG_INFO("********** Current Rate: %4.2f **********", CurrentRate);
- LOG_INFO("********** Occupancy Fee: %4.2f **********", OccupancyFee);
- ShmChargerInfo->CabinetMiscValue.DefaultPrice = CurrentRate;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!Is_Dispenser_MiscCommand(i, MISC_DISP_DEFAULT_PRICE))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_DEFAULT_PRICE);
- }
- if(!Is_Dispenser_MiscCommand(i, MISC_DISP_CURRENCY))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_CURRENCY);
- }
- }
- }
- if(trigger)
- {
- LOG_INFO("********** Trigger Dispenser Default Price **********");
- }
- strcpy(MyDefaultPriceString, price);
- }
- }
- void UserPriceHandler(void)
- {
- char UserId[32];
- char preice[500];
- Get_Ocpp_UserPrice(UserId, preice);
- if(strlen((char *)UserId) > 0 && strlen((char *)preice) > 0)
- {
- float ConnectionFee = 0, CurrentRate = 0, OccupancyFee = 0;
- float AccountBalance = 0;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- ConnectionFee = TariffParsing((char *)preice, "Connection Fee");
- CurrentRate = TariffParsing((char *)preice, "Current Rate");
- OccupancyFee = TariffParsing((char *)preice, "Occupancy Fee");
- AccountBalance = TariffParsing((char *)preice, "Account Balance");
- }
- else
- {
- CurrentRate = PhTariffParsing((char *)preice, "chargineFee");
- OccupancyFee = PhTariffParsing((char *)preice, "parkingFee");
- }
- LOG_INFO("********** User Id: %s **********", UserId);
- LOG_INFO("********** User Price: %s", preice);
- LOG_INFO("********** Connection Fee: %7.2f **********", ConnectionFee);
- LOG_INFO("********** Current Rate: %7.2f **********", CurrentRate);
- LOG_INFO("********** Occupancy Fee: %7.2f **********", OccupancyFee);
- LOG_INFO("********** Account Balance: %7.2f **********", AccountBalance);
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.StartUserId, UserId) == EQUAL)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].UserPrice != CurrentRate ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].AccountBalance != AccountBalance)
- {
- LOG_INFO("********** Connector Id %d User Price %4.2f, Account Balance %7.2f **********",
- (i + 1), CurrentRate, AccountBalance);
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].UserPrice = CurrentRate;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].AccountBalance = AccountBalance;
- if(chargingInfo[i]->SystemStatus == S_AUTHORIZING)
- {
- AnnounceAccountBalance(i, AccountBalance);
- }
- }
- }
- Clean_Ocpp_UserPrice();
- }
- }
- void RunningFinalCostHandler(void)
- {
- char strCost[256];
- float ConnectionFee = 0, SessionFee = 0, OccupancyFee = 0, TotalCost = 0, CostDiscount = 0;
- float AccountBalance = 0;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.SystemStatus >= S_REASSIGN_CHECK &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.SystemStatus <= S_ALARM)
- {
- Get_Ocpp_RunningCost(i, strCost);
- if(strlen((char *)strCost) > 0)
- {
- ConnectionFee = 0;
- SessionFee = 0;
- OccupancyFee = 0;
- TotalCost = 0;
- AccountBalance = 0;
- CostDiscount = 0;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- ConnectionFee = TariffParsing((char *)strCost, "Connection Fee");
- SessionFee = TariffParsing((char *)strCost, "Session Fee");
- OccupancyFee = TariffParsing((char *)strCost, "Occupancy Fee");
- TotalCost = TariffParsing((char *)strCost, "Total Cost");
- AccountBalance = TariffParsing((char *)strCost, "Account Balance");
- }
- else
- {
- TotalCost = PhTariffParsing((char *)strCost, "chargingFee");
- OccupancyFee = PhTariffParsing((char *)strCost, "parkingFee");
- }
- #if 0
- LOG_INFO("********** Connector Id: %d Running Cost **********", (i + 1));
- LOG_INFO("********** Connection Fee: %7.2f **********", ConnectionFee);
- LOG_INFO("********** Session Fee: %7.2f **********", SessionFee);
- LOG_INFO("********** Occupancy Fee: %7.2f **********", OccupancyFee);
- LOG_INFO("********** Total Cost: %7.2f **********", TotalCost);
- LOG_INFO("********** Account Balance: %7.2f **********", AccountBalance);
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].TotalCost != TotalCost ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].AccountBalance != AccountBalance)
- {
- LOG_INFO("********** Connector Id %d Total Cost %.2f, Account Balance %7.2f **********",
- (i + 1), TotalCost, AccountBalance);
- }
- #endif
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].TotalCost = TotalCost;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].AccountBalance = AccountBalance;
- Clean_Ocpp_RunningCost(i);
- }
- Get_Ocpp_FinalCost(i, strCost);
- if(strlen((char *)strCost) > 0)
- {
- ConnectionFee = 0;
- SessionFee = 0;
- OccupancyFee = 0;
- TotalCost = 0;
- AccountBalance = 0;
- CostDiscount = 0;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- ConnectionFee = TariffParsing((char *)strCost, "Connection Fee");
- SessionFee = TariffParsing((char *)strCost, "Session Fee");
- OccupancyFee = TariffParsing((char *)strCost, "Occupancy Fee");
- TotalCost = TariffParsing((char *)strCost, "Total Cost");
- AccountBalance = TariffParsing((char *)strCost, "Account Balance");
- }
- else
- {
- TotalCost = PhTariffParsing((char *)strCost, "chargingFee");
- OccupancyFee = PhTariffParsing((char *)strCost, "parkingFee");
- AccountBalance = PhTariffParsing((char *)strCost, "accountBalance");
- CostDiscount = PhTariffParsing((char *)strCost, "couponPoint");
- }
- LOG_INFO("********** Connector Id: %d Final Cost **********", (i + 1));
- LOG_INFO("********** Connection Fee: %7.2f **********", ConnectionFee);
- LOG_INFO("********** Session Fee: %7.2f **********", SessionFee);
- LOG_INFO("********** Occupancy Fee: %7.2f **********", OccupancyFee);
- LOG_INFO("********** Total Cost: %7.2f **********", TotalCost);
- LOG_INFO("********** Account Balance: %7.2f **********", AccountBalance);
- #if 0
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].TotalCost != TotalCost ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].AccountBalance != AccountBalance ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].CostDiscount != CostDiscount)
- {
- LOG_INFO("********** Connector Id %d Total Cost %.2f, Account Balance: %7.2f, Discount: %d.%02d **********",
- (i + 1), TotalCost, AccountBalance, (CostDiscount / 100), (CostDiscount % 100));
- }
- #endif
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].TotalCost = TotalCost;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].AccountBalance = AccountBalance;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].CostDiscount = CostDiscount;
- Set_Connector_MiscCommand(i, MISC_CONN_FINAL_COST);
- Clean_Ocpp_FinalCost(i);
- }
- }
- }
- }
- char MyTimeOffsetString[501];
- void TimeOffsetHandler(void)
- {
- char timeOffset[501];
- Get_Ocpp_TimeOffset((char *)timeOffset);
- if(strcmp(MyTimeOffsetString, (char *)timeOffset) != EQUAL)
- {
- BOOL trigger = FALSE;
- int offset = 0;
- offset = TimeOffsetKeyParsing(timeOffset);
- LOG_INFO("********** Time Offset String [%s] -> Value [%d] -> Time [%s%02d:%02d]",
- timeOffset, offset, offset >= 0 ? "+" : "-", (abs(offset) / 60), (abs(offset) % 60));
- ShmChargerInfo->CabinetMiscValue.TimeOffset = offset;
- #if 0
- time_t timep;
- struct tm *tm;
- time(&timep);
- tm = localtime(&timep);
- LOG_INFO(" NowTime: %d/%02d/%02d %02d:%02d:%02d",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
- timep += (offset * 60);
- tm = localtime(&timep);
- LOG_INFO("OffsetTime: %d/%02d/%02d %02d:%02d:%02d",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
- #endif
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!Is_Dispenser_MiscCommand(i, MISC_DISP_TIME_OFFSET))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_TIME_OFFSET);
- }
- }
- }
- if(trigger)
- {
- LOG_INFO("********** Trigger Dispenser Time Offset **********");
- }
- strcpy(MyTimeOffsetString, timeOffset);
- }
- }
- struct timespec _Cost_Price_time;
- void CheckOcppCostAndPrice(void)
- {
- // 5s for reboot request timeout
- if((GetTimeoutValue(_Cost_Price_time) / uSEC_VAL) >= OCPP_COST_REQ_INTERVAL)
- {
- GetClockTime(&_Cost_Price_time);
- DefaultPriceHandler();
- UserPriceHandler();
- RunningFinalCostHandler();
- TimeOffsetHandler();
- }
- }
- void CheckRemoteStartNoIdRequest(void)
- {
- if(Is_Ocpp_RemoteStartWaitReq())
- {
- if(!ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId)
- {
- LOG_INFO("Ocpp remote start without connector id is trigger");
- ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId = true;
- AnnounceRemoteStartNoID();
- GetClockTime(&_RemoteStartNoId_Time);
- }
- if(ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId)
- {
- // to avoid keep RemoteStartNoId state when ocpp is disconnected
- if((GetTimeoutValue(_RemoteStartNoId_Time) / uSEC_VAL) >= (ShmChargerInfo->CabinetMiscValue.ConnectionTimeout + CONNECTION_TIME_OFFSET))
- {
- ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId = false;
- }
- }
- }
- else
- {
- if(ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId)
- {
- LOG_INFO("Ocpp remote start without connector id is expired");
- }
- ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId = false;
- }
- }
- void CheckOcppPageChangeRequest(void)
- {
- int gunId = 0, pageIndex = 0;
- if(Is_Ocpp_LcdOverideReq(&gunId, &pageIndex))
- {
- Clean_Ocpp_LcdOverideReq();
- switch(pageIndex)
- {
- case _OCPP_Page_LineStatus_1:
- case _OCPP_Page_LineStatus_2:
- case _OCPP_Page_LineStatus_3:
- case _OCPP_Page_LineStatus_4:
- LOG_INFO("Gun %d Ocpp Line Status [%d] is trigger", gunId, pageIndex);
- AnnounceLineStatusCode(gunId - 1, pageIndex);
- break;
- default:
- LOG_INFO("Gun %d Ocpp page change [Unknown][%d]", gunId, pageIndex);
- break;
- }
- }
- }
- void CheckLcmPageChangeRequest(void)
- {
- bool isTrigger = false;
- CheckRemoteStartNoIdRequest();
- CheckOcppPageChangeRequest();
- for(int index = 0; index < CONNECTOR_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- isTrigger = false;
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorID[i] - 1;
- if(ShmChargerInfo->ConnectorPageReq[gun].CtrlValue != 0)
- {
- isTrigger = true;
- break;
- }
- }
- if(isTrigger)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_CHANGE_LCM_INFO);
- }
- else
- {
- Clean_Dispenser_MiscCommand(index, MISC_DISP_CHANGE_LCM_INFO);
- }
- }
- }
- }
- void CheckStationInfo(void)
- {
- int station_id = 0;
- char station_name[64];
- if(Is_Ocpp_ChargerStationReq())
- {
- memset(station_name, 0x00, sizeof(station_name));
- Get_Ocpp_ChargerStationInfo(&station_id, station_name);
- if(strcmp(station_name, ShmChargerInfo->StationInfo.StationName) != EQUAL ||
- ShmChargerInfo->StationInfo.StationID != station_id)
- {
- strcpy(ShmChargerInfo->StationInfo.StationName, station_name);
- ShmChargerInfo->StationInfo.StationID = station_id;
- LOG_INFO("Station ID: %d, Name: %s", ShmChargerInfo->StationInfo.StationID, ShmChargerInfo->StationInfo.StationName);
- AnnounceStationInfo();
- }
- Clean_Ocpp_ChargerStationReq();
- }
- }
- void CheckWeatherInfo(void)
- {
- int weatherID = 0;
- float temperature = 0;
- char strWeather[16];
- char *str_weather_type[] = {STR_WEATHER_NONE, STR_WEATHER_SUNNY, STR_WEATHER_CLOUDY, STR_WEATHER_RAIN, STR_WEATHER_THUNDERSTORM, STR_WEATHER_SNOW, STR_WEATHER_MIST};
- if(Is_Ocpp_WeatherReq())
- {
- Get_Ocpp_WeatherInfo(&weatherID, &temperature);
- if(weatherID != ShmChargerInfo->StationInfo.WeatherID ||
- temperature != ShmChargerInfo->StationInfo.Temperature)
- {
- ShmChargerInfo->StationInfo.WeatherID = weatherID;
- ShmChargerInfo->StationInfo.Temperature = temperature;
- if(ShmChargerInfo->StationInfo.WeatherID <= _WEATHER_Mist)
- {
- strcpy(strWeather, str_weather_type[ShmChargerInfo->StationInfo.WeatherID]);
- }
- else
- {
- sprintf(strWeather, "%d", ShmChargerInfo->StationInfo.WeatherID);
- }
- LOG_INFO("Weather: [%s][%d], Temperature: %4.1f", strWeather, ShmChargerInfo->StationInfo.WeatherID, ShmChargerInfo->StationInfo.Temperature);
- AnnounceStationInfo();
- }
- Clean_Ocpp_WeatherReq();
- }
- }
- bool _WriteDeductBusy[CONNECTOR_QUANTITY] = {0};
- void CheckDeductResultRequest(void)
- {
- char *str_ReaderStatus[] = {STR_DEDUCT_FAIL, STR_DEDUCT_PASS, STR_DEDUCT_CANCEL, STR_DEDUCT_PREAUTH};
- char cardNo[21];
- char appNo[10];
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(Is_DeductResultReq(i))
- {
- if(!_WriteDeductBusy[i])
- {
- if(!Is_Ocpp_ReportCreditDeductReq() && ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _WriteDeductBusy[i] = true;
- //Set_Ocpp_DeductTransaction(_BackupDeductResult[i].TransactionId);
- //Set_Ocpp_DeductCreditNo((char *)&_BackupDeductResult[i].creditNo);
- //Set_Ocpp_DeductVemData("");
- //Set_Ocpp_DeductAmount(((double)_BackupDeductResult[i].DeductAmount / 100));
- //Set_Ocpp_DeductResult(_BackupDeductResult[i].DeductResult);
- //Set_Ocpp_DonateInvoice(_BackupDeductResult[i].IsDonateInvoice);
- if(Set_Ocpp_DeductInfo(&ShmChargerInfo->DeductResultReq[i]))
- {
- memset(cardNo, 0x00, sizeof(cardNo));
- memcpy(cardNo, (char *)&ShmChargerInfo->DeductResultReq[i].creditNo[0], sizeof(ShmChargerInfo->DeductResultReq[i].creditNo));
- memset(appNo, 0x00, sizeof(appNo));
- memcpy(appNo, (char *)&ShmChargerInfo->DeductResultReq[i].ApprovalNumber[0], sizeof(ShmChargerInfo->DeductResultReq[i].ApprovalNumber));
- Set_Ocpp_ReportCreditDeductReq();
- LOG_INFO("DeductReport Gun %d TxId: %d, UserId: %s, ApprovalNo: [%s], Amount: %d.%02d, [%s], Donate: %s",
- i + 1,
- ShmChargerInfo->DeductResultReq[i].TransactionId,
- cardNo,
- appNo,
- (ShmChargerInfo->DeductResultReq[i].DeductAmount / 100),
- (ShmChargerInfo->DeductResultReq[i].DeductAmount % 100),
- str_ReaderStatus[ShmChargerInfo->DeductResultReq[i].DeductResult],
- ShmChargerInfo->DeductResultReq[i].IsDonateInvoice ? "Yes" : "No");
- if(ShmChargerInfo->DeductResultReq[i].DeductResult == _Deduct_Pass)
- {
- memcpy(&ShmChargerInfo->ReaderStatus[i], &ShmChargerInfo->DeductResultReq[i], sizeof(DeductResultInfoData));
- ShmChargerInfo->ReaderStatus[i].ReaderStatusReq = YES;
- }
- }
- }
- }
- else
- {
- if(!Is_Ocpp_ReportCreditDeductReq())
- {
- Clean_DeductInfo(i);
- _WriteDeductBusy[i] = false;
- }
- }
- }
- else
- {
- _WriteDeductBusy[i] = false;
- }
- }
- }
- bool _WriteReDeductBusy = false;
- void CheckReDeductRequest(void)
- {
- char *str_ReaderStatus[] = {STR_DEDUCT_FAIL, STR_DEDUCT_PASS, STR_DEDUCT_CANCEL, STR_DEDUCT_PREAUTH};
- char cardNo[21];
- char appNo[10];
- if(ShmChargerInfo->ReDeductReq.DeductReq)
- {
- if(!_WriteReDeductBusy)
- {
- if(!Is_Ocpp_ReportCreditDeductReq() && ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _WriteReDeductBusy = true;
- if(Set_Ocpp_DeductInfo(&ShmChargerInfo->ReDeductReq))
- {
- memset(cardNo, 0x00, sizeof(cardNo));
- memcpy(cardNo, (char *)&ShmChargerInfo->ReDeductReq.creditNo[0], sizeof(ShmChargerInfo->ReDeductReq.creditNo));
- memset(appNo, 0x00, sizeof(appNo));
- memcpy(appNo, (char *)&ShmChargerInfo->ReDeductReq.ApprovalNumber[0], sizeof(ShmChargerInfo->ReDeductReq.ApprovalNumber));
- Set_Ocpp_ReportCreditDeductReq();
- LOG_INFO("ReDeductReport TxId: %d, UserId: %s, ApprovalNo: [%s], Amount: %d.%02d, [%s], Donate: %s",
- ShmChargerInfo->ReDeductReq.TransactionId,
- cardNo,
- appNo,
- (ShmChargerInfo->ReDeductReq.DeductAmount / 100),
- (ShmChargerInfo->ReDeductReq.DeductAmount % 100),
- str_ReaderStatus[ShmChargerInfo->ReDeductReq.DeductResult],
- ShmChargerInfo->ReDeductReq.IsDonateInvoice ? "Yes" : "No");
- if(ShmChargerInfo->ReDeductReq.DeductResult == _Deduct_Pass && ShmChargerInfo->ReDeductReq.ConnectorId != 0xFF)
- {
- int gunIndex = ShmChargerInfo->ReDeductReq.ConnectorId - 1;
- memcpy(&ShmChargerInfo->ReaderStatus[gunIndex], &ShmChargerInfo->ReDeductReq, sizeof(DeductResultInfoData));
- ShmChargerInfo->ReaderStatus[gunIndex].ReaderStatusReq = YES;
- }
- }
- }
- }
- else
- {
- if(!Is_Ocpp_ReportCreditDeductReq())
- {
- memset(&ShmChargerInfo->ReDeductReq, 0x00, sizeof(DeductResultInfoData));
- _WriteReDeductBusy = false;
- }
- }
- }
- else
- {
- _WriteReDeductBusy = false;
- }
- }
- bool _WriteReaderStatusBusy[CONNECTOR_QUANTITY] = {0};
- void CheckReaderStatusRequest(void)
- {
- char *str_ReaderStatus[] = {STR_DEDUCT_FAIL, STR_DEDUCT_PASS, STR_DEDUCT_CANCEL, STR_DEDUCT_PREAUTH};
- char cardNo[21];
- char appNo[10];
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(Is_ReaderStatusReq(i))
- {
- if(!_WriteReaderStatusBusy[i])
- {
- if(!Is_Ocpp_TcciReaderStatusReq(i) && ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _WriteReaderStatusBusy[i] = true;
- if(Set_Ocpp_TcciReaderStatus(i, &ShmChargerInfo->ReaderStatus[i]))
- {
- memset(cardNo, 0x00, sizeof(cardNo));
- memcpy(cardNo, (char *)&ShmChargerInfo->ReaderStatus[i].creditNo[0], sizeof(ShmChargerInfo->ReaderStatus[i].creditNo));
- memset(appNo, 0x00, sizeof(appNo));
- memcpy(appNo, (char *)&ShmChargerInfo->ReaderStatus[i].ApprovalNumber[0], sizeof(ShmChargerInfo->ReaderStatus[i].ApprovalNumber));
- Set_Ocpp_TcciReaderStatusReq(i);
- LOG_INFO("StatusReport Gun %d: [%s], CreditNo: [%s], ApprovalNo: [%s]",
- i + 1, str_ReaderStatus[ShmChargerInfo->ReaderStatus[i].DeductResult], cardNo, appNo);
- }
- }
- }
- else
- {
- if(!Is_Ocpp_TcciReaderStatusReq(i))
- {
- Clean_ReaderStatusInfo(i);
- _WriteReaderStatusBusy[i] = false;
- }
- }
- }
- else
- {
- _WriteReaderStatusBusy[i] = false;
- }
- }
- }
- //===============================================
- // OCPP
- //===============================================
- void CheckOcppStatus()
- {
- if (Is_Ocpp_BootNotification())
- {
- Clean_Ocpp_BootNotification();
- LOG_INFO("*********************OCPP Boot Notification****************************");
- }
- if (Is_Ocpp_ResetReq())
- {
- bool canReset = true;
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2)
- {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus != S_IDLE &&
- chargingInfo[_index]->SystemStatus != S_RESERVATION &&
- chargingInfo[_index]->SystemStatus != S_MAINTAIN)
- {
- canReset = false;
- //if (chargingInfo[_index]->SystemStatus >= S_REASSIGN && chargingInfo[_index]->SystemStatus < S_TERMINATING)
- //{
- // ChargingTerminalProcess(_index);
- //}
- if(Chk_Ocpp_Reset_Type("Hard") || Chk_Ocpp_Reset_Type("Immediate"))
- {
- chargingInfo[_index]->ChargingStopFlag.bits.HardResetStop = true;
- }
- if(Chk_Ocpp_Reset_Type("Soft") || Chk_Ocpp_Reset_Type("OnIdle"))
- {
- chargingInfo[_index]->ChargingStopFlag.bits.SoftResetStop = true;
- }
- }
- }
- }
- if(canReset)
- {
- if(Chk_Ocpp_Reset_Type("Hard") || Chk_Ocpp_Reset_Type("Immediate"))
- {
- //trigger dispenser to hardware reboot
- TriggerDispenserHardwareReboot();
- if(IsDispenserHardwareRebootResponsed())
- {
- Clean_Ocpp_ResetReq();
- LOG_INFO("****** Hard Reboot ******");
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- setChargerMode(i, MODE_MAINTAIN);
- }
- sleep(3);
- system("reboot -f");
- }
- }
- if(Chk_Ocpp_Reset_Type("Soft") || Chk_Ocpp_Reset_Type("OnIdle"))
- {
- //trigger dispenser to software reset
- TriggerDispenserSoftwareReset();
- if(IsDispenserSoftwareResetResponsed())
- {
- Clean_Ocpp_ResetReq();
- LOG_INFO("****** Soft Reboot ******");
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- setChargerMode(i, MODE_MAINTAIN);
- }
- sleep(3);
- Kill_Ocpp_Service();
- KillAllTask();
- TryCloseWatchdog();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- }
- }
- CheckOcppCostAndPrice();
- CheckLcmPageChangeRequest();
- CheckStationInfo();
- CheckWeatherInfo();
- CheckDeductResultRequest();
- CheckReDeductRequest();
- CheckReaderStatusRequest();
- }
- void CheckoutStartChargingSoc(byte gunIndex, bool force)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Parameter.bits.GetStartChargingSoc)
- {
- if(chargingInfo[gunIndex]->EvBatterySoc > 0 || force)
- {
- chargingInfo[gunIndex]->EvBatteryStartSoc = chargingInfo[gunIndex]->EvBatterySoc;
- LOG_INFO("Gun %d StartSoc = %d", chargingInfo[gunIndex]->Index + 1, chargingInfo[gunIndex]->EvBatteryStartSoc);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Parameter.bits.GetStartChargingSoc = true;
- }
- }
- }
- void OcppStartTransaction(byte gunIndex)
- {
- // clean deduct info
- Clean_DeductInfo(gunIndex);
- // set deduct user id
- //Set_Deduct_UserId(gunIndex, (char *)&chargingInfo[gunIndex]->StartUserId);
- // initial start & stop datetime
- strcpy((char *)chargingInfo[gunIndex]->StartDateTime, "00:00:00");
- strcpy((char *)chargingInfo[gunIndex]->StopDateTime, "00:00:00");
- Set_Ocpp_StartTransactionId(gunIndex, (char *)chargingInfo[gunIndex]->StartUserId);
- LOG_INFO("Gun %d Start Transaction IdTag = %s", chargingInfo[gunIndex]->Index + 1, chargingInfo[gunIndex]->StartUserId);
- Clean_Ocpp_StartTransactionConf(gunIndex);
- Set_Ocpp_StartTransactionReq(gunIndex);
- }
- void OcppStopTransaction(byte gunIndex)
- {
- Set_Ocpp_StopTransactionId(gunIndex, (char *)chargingInfo[gunIndex]->StartUserId);
- LOG_INFO("Gun %d Stop Transaction IdTag = %s, StopSoc = %d",
- chargingInfo[gunIndex]->Index + 1, chargingInfo[gunIndex]->StartUserId, chargingInfo[gunIndex]->EvBatterySoc);
- Set_Ocpp_StopTransactionReq(gunIndex);
- }
- void ChkOcppStatus(byte gunIndex)
- {
- Chk_Ocpp_Backup_ErrorCode(gunIndex);
- if(Is_Ocpp_ReserveNowReq(gunIndex))
- {
- Clean_Ocpp_ReserveNowReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_IDLE && !Is_Ocpp_ReserveNowExpired(gunIndex))
- {
- LOG_INFO("***************ChkOcppStatus: Gun %d OcppReservedStatus********************", gunIndex + 1);
- chargingInfo[gunIndex]->ReservationId = Get_Ocpp_ReserveNowId(gunIndex);
- setChargerMode(gunIndex, MODE_RESERVATION);
- }
- Set_Ocpp_ReserveNowConf(gunIndex);
- }
- if(Is_Ocpp_CancelReservationReq(gunIndex))
- {
- Clean_Ocpp_CancelReservationReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_RESERVATION)
- {
- LOG_INFO("***************ChkOcppStatus: Gun %d Cancel OcppReservedStatus********************", gunIndex + 1);
- chargingInfo[gunIndex]->ReservationId = -1;
- setChargerMode(gunIndex, MODE_IDLE);
- }
- Set_Ocpp_CancelReservationConf(gunIndex);
- }
- if (Is_Ocpp_ChangeAvailabilityReq(gunIndex) == YES)
- {
- LOG_INFO("***************ChkOcppStatus: Gun %d OcppChangeAvailability********************", gunIndex + 1);
- Clean_Ocpp_ChangeAvailabilityReq(gunIndex);
- if(Chk_Ocpp_Availability_Type(gunIndex, "Operative"))
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, true);
- chargingInfo[gunIndex]->IsAvailable = YES;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_AVAILABILITY);
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
- {
- setChargerMode(gunIndex, MODE_IDLE);
- }
- }
- else if(Chk_Ocpp_Availability_Type(gunIndex, "Inoperative"))
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, false);
- chargingInfo[gunIndex]->IsAvailable = NO;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_AVAILABILITY);
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
- {
- setChargerMode(gunIndex, MODE_MAINTAIN);
- }
- }
- }
- if (Is_Ocpp_UnlockConnectorReq(gunIndex))
- {
- Clean_Ocpp_UnlockConnectorReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_PREPARNING ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EV ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EVSE ||
- chargingInfo[gunIndex]->SystemStatus == S_CHARGING)
- {
- // 充電中,需停止充電
- Set_Ocpp_StopReason(gunIndex, "UnlockCommand");
- //Set_Connector_MiscCommand(gunIndex, MISC_CONN_UNLOCK);
- chargingInfo[gunIndex]->ChargingStopFlag.bits.UnlockStop = true;
- LOG_INFO("********** OcppUnlockStop Gun %d **********", gunIndex + 1);
- }
- Set_Ocpp_UnlockConnectorConf(gunIndex);
- }
- if (Is_Ocpp_RemoteStopReq(gunIndex))
- {
- Clean_Ocpp_RemoteStopReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_PREPARNING ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EV ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EVSE ||
- chargingInfo[gunIndex]->SystemStatus == S_CHARGING)
- {
- Set_Ocpp_StopReason(gunIndex, "Remote");
- //Set_Connector_MiscCommand(gunIndex, MISC_CONN_REMOTE_STOP);
- chargingInfo[gunIndex]->ChargingStopFlag.bits.RemoteStop = true;
- LOG_INFO("********** OcppRemoteStop Gun %d **********", gunIndex + 1);
- }
- }
- if(Is_Ocpp_StartTransactionConf(gunIndex))
- {
- char acceptId[128] = {0};
- char status[32] = {0};
- Get_Ocpp_StartTransaction_Status(gunIndex, status);
- Get_Ocpp_TransactionId(gunIndex, acceptId);
- Set_Deduct_TransactionId(gunIndex, atoi(acceptId));
- Set_UserTransactionId(gunIndex, atoi(acceptId));
- LOG_INFO("Gun %d OCPP Start Transaction %s, TransactionId [%s]", gunIndex + 1, status, acceptId);
- if(!Is_Ocpp_StartTransaction_Accepted(gunIndex))
- {
- if(Is_Ocpp_StopOnInvalidId_Enable())
- {
- if(Is_Invalid_StartTransactionId(gunIndex))
- {
- chargingInfo[gunIndex]->ChargingStopFlag.bits.InvalidIdStop = true;
- LOG_INFO("Gun %d OCPP StopOnInvalidId", gunIndex + 1);
- }
- }
- LOG_INFO("Gun %d OCPP Start Transaction Accepted, TransactionId [%s]", gunIndex + 1, acceptId);
- }
- Clean_Ocpp_StartTransactionConf(gunIndex);
- }
- }
- bool CheckBackendChargingTimeout(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
- {
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60))
- result = true;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- {
- // 隨插即充電的要看 offline
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60))
- result = true;
- }
- }
- return result;
- }
- bool CheckBackendChargingEnergy(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
- {
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedEnergy > ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)
- result = true;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- {
- // 隨插即充電的要看 offline
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedEnergy > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy))
- result = true;
- }
- }
- return result;
- }
- void InformOcppErrOccur(byte codeType)
- {
- char _error[25];
- switch(codeType)
- {
- case 4: strcpy(_error, "InternalError"); break;
- case 6: strcpy(_error, "NoError"); break;
- case 7: strcpy(_error, "OtherError"); break;
- case 13: strcpy(_error, "UnderVoltage"); break;
- case 14: strcpy(_error, "OverVoltage"); break;
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- SetOcppErrorCode(gun_index, _error);
- }
- }
- void SetOcppErrorCode(unsigned char _index, char *errCode)
- {
- Set_Ocpp_StatusNotificationErrorCode(_index, errCode);
- strcpy((char *)_BackupStatusNotification[_index].ErrorCode, errCode);
- }
- void SetOcppVendorErrorCode(unsigned char _index, char *vendorCode)
- {
- Set_Ocpp_StatusNotificationVendorCode(_index, vendorCode);
- strcpy((char *)_BackupStatusNotification[_index].VendorErrorCode, vendorCode);
- }
- //===============================================
- // SQLite3 related routine
- //===============================================
- 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"
- ");";
- //sqlite3_config(SQLITE_CONFIG_URI, 1);
- if(sqlite3_open(NETWORK_DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database (Net) : %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO("Local network status record database open successfully.");
- if (sqlite3_exec(db, createNerRecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Create local network status record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("Opened local network status record table successfully");
- }
- 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"
- ");";
- char* createCfgSql="CREATE TABLE IF NOT EXISTS `config` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`IsAvailable` TEXT NOT NULL, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(IsAvailable,connector) on conflict replace);";
- 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);";
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR( "Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO( "Local charging record database open successfully.");
- if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create local charging record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened local charging record table successfully");
- }
- if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create local config table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened local config table successfully");
- }
- if (sqlite3_exec(db, creatererrecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create local record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened local record table successfully");
- }
- if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create reboot record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened reboot record table successfully");
- }
- if (sqlite3_exec(db, createconsumptionSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create power consumption record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened power consumption record table successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Insert_Record(sqlite3 *db, int gun_index)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[1024];
- char transactionId[128];
- char reason[32];
- Get_Ocpp_TransactionId(gun_index, transactionId);
- Get_Ocpp_StopReason(gun_index, reason);
- 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,
- 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,
- reason);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO( "Local charging record database open successfully.");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Insert local charging record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("Insert local charging record successfully");
- }
- 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;
- LOG_ERROR("delete local charging error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("delete local charging record successfully");
- }
- 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;
- LOG_ERROR( "Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO( "Local charging record database open successfully (%d).", IsAvailable);
- sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
- LOG_INFO("sqlStr= %s", sqlStr);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_INFO( "update config error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("update connector-%d config item isOperactive to %d", gun_index, IsAvailable);
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
- {
- uint8_t result = true;
- char* errMsg = NULL;
- char sqlStr[1024];
- char **rs;
- int rows, cols;
- sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gun_index);
- //DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR( "Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO( "Local config query database open successfully.");
- 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;
- }
- LOG_INFO("Query connector-%d isOperactive: %s", gun_index, rs[(idxRow*cols)+3]);
- }
- }
- else
- {
- LOG_INFO("Query connector-%d fail, set default value to operactive.", 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))
- {
- LOG_ERROR("Can't open database: %s", 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)
- {
- LOG_ERROR("update power_consumption error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("update connector-%d power_consumption item consumption to %f \r\n", gun_index, value);
- }
- 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;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO("Local config query database open successfully.");
- 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
- {
- LOG_INFO("Query connector-%d fail, set default value to consumption.", 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;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO("Local charging record database open successfully.");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Insert reboot record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("Insert reboot record successfully");
- }
- sprintf(insertSql, "delete from reboot_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("delete reboot record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("delete reboot record successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- //===============================================
- // Config process
- //===============================================
- void AddPlugInTimes(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
- else if(chargingInfo[gunIndex]->Type == _Type_CCS_2)
- ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
- else if(chargingInfo[gunIndex]->Type == _Type_GB)
- ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
- }
- void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
- {
- char cmdBuf[32];
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
- tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- tmCSU->tm_sec);
- if (isStart)
- strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
- else
- strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
- }
- void zipLogFiles()
- {
- const char* logPath = "/Storage/SystemLog";
- // 獲取目錄
- DIR* pDir = opendir(logPath);
- if (pDir != NULL)
- {
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- // LOG_INFO("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
- // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- // tmCSU->tm_sec);
- // Read items inside the folder
- struct dirent* pEntry = NULL;
- while ((pEntry = readdir(pDir)) != NULL)
- {
- if (strcmp(pEntry->d_name, ".") != 0 &&
- strcmp(pEntry->d_name, "..") != 0 &&
- strncmp(pEntry->d_name, "[", 1) == 0 &&
- strstr(pEntry->d_name, "tar") < 0)
- {
- char yearC[5];
- unsigned short year = 0;
- char monthC[3];
- unsigned short month = 0;
- yearC[4] = '\0';
- strncpy(yearC, pEntry->d_name + 1, 4);
- monthC[2] = '\0';
- strncpy(monthC, pEntry->d_name + 6, 2);
- year = atoi(yearC);
- month = atoi(monthC);
- if (year != 0)
- {
- if (year < tmCSU->tm_year + 1900 ||
- (year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1))
- {
- LOG_INFO("tar file name : %s", 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);
- LOG_INFO("zip = %s \n", file);
- system(file);
- }
- }
- }
- }
- }
- // Close folder
- closedir(pDir);
- }
- void StopProcessingLoop()
- {
- for (;;)
- {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
- {
- ChkPrimaryStatus();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 0)
- {
- LOG_INFO("Soft reboot for retry self-tets (Primary).");
- KillAllTask();
- sleep(3);
- TryCloseWatchdog();
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- }
- if(Is_Ocpp_ResetReq())
- {
- if(Chk_Ocpp_Reset_Type("Hard") || Chk_Ocpp_Reset_Type("Immediate"))
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
- }
- if(Chk_Ocpp_Reset_Type("Soft") || Chk_Ocpp_Reset_Type("OnIdle"))
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
- }
- }
- CheckSoftHardReset();
- sleep(1);
- }
- }
- void CreateWatchdog(void)
- {
- wtdFd = InitWatchDog();
- if(wtdFd < 0)
- {
- LOG_INFO("Watchdog Initial Fail");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- else
- {
- LOG_INFO("Watchdog Initial Success");
- }
- }
- void TryCloseWatchdog(void)
- {
- if(wtdFd > 0)
- {
- write(wtdFd, "V", 1);
- close(wtdFd);
- }
- }
- void TryFeedWatchdog(void)
- {
- if(wtdFd > 0)
- {
- write(wtdFd, "a", 1);
- }
- }
- bool IsParallelCabinetIdle(void)
- {
- bool result = true;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- result = false;
- }
- return result;
- }
- bool IsStandbyEnable(void)
- {
- bool result = true;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
- {
- time_t timep;
- struct tm *tm;
- time(&timep);
- timep += (ShmChargerInfo->CabinetMiscValue.TimeOffset * 60);
- tm = localtime(&timep);
- if(tm->tm_hour >= 0 && tm->tm_hour < 8)
- {
- if(!_isStandbyEnable)
- {
- LOG_INFO("[TCC]Customer Enable Standby Function This Time[%02d:%02d:%02d], Offset[%d]",
- tm->tm_hour, tm->tm_min, tm->tm_sec, ShmChargerInfo->CabinetMiscValue.TimeOffset);
- }
- _isStandbyEnable = true;
- result = true;
- }
- else
- {
- if(_isStandbyEnable)
- {
- LOG_INFO("[TCC]Customer Disable Standby Function This Time[%02d:%02d:%02d], Offset[%d]",
- tm->tm_hour, tm->tm_min, tm->tm_sec, ShmChargerInfo->CabinetMiscValue.TimeOffset);
- }
- _isStandbyEnable = false;
- result = false;
- }
- }
- return result;
- }
- bool IsConnectorWholeIdle(void)
- {
- bool result = true;
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- if (chargingInfo[count]->SystemStatus != S_IDLE &&
- chargingInfo[count]->SystemStatus != S_RESERVATION &&
- chargingInfo[count]->SystemStatus != S_FAULT &&
- chargingInfo[count]->SystemStatus != S_MAINTAIN)
- {
- result = false;
- break;
- }
- }
- return result;
- }
- void ClearAlarmCodeWhenAcOff()
- {
- if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- }
- }
- //==========================================
- // Check task processing
- //==========================================
- void CheckTask()
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- if(system("pidof -s Module_4g > /dev/null") != 0 && ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable == false)
- {
- LOG_ERROR("Module_4g not running, restart it.");
- system("/root/Module_4g &");
- }
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- if(system("pidof -s Module_Wifi > /dev/null") != 0 && ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable == false)
- {
- LOG_ERROR("Module_Wifi not running, restart it.");
- system("/root/Module_Wifi &");
- }
- }
- }
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
- {
- ShmChargerInfo->Control.SysCtrl.bits.BackendEnable = true;
- if((time((time_t*)NULL) - Get_Ocpp_procDogTime()) > 180)
- {
- LOG_ERROR("OcppBackend watch dog timeout task restart.");
- Clean_Ocpp_procDogTime();
- Kill_Ocpp_Service();
- }
- if(!Is_Ocpp_Task_Alive())
- {
- LOG_ERROR("OcppBackend not running, restart it.");
- Run_Ocpp_Service();
- }
- }
- else
- {
- ShmChargerInfo->Control.SysCtrl.bits.BackendEnable = false;
- }
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- if(!Is_MaintainOcpp_Task_Alive())
- {
- LOG_ERROR("Maintain Backend not running, restart it.");
- Run_MaintainOcpp_Service();
- }
- }
- if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
- {
- LOG_ERROR("Module_ProduceUtils not running, restart it.");
- system ("/root/Module_ProduceUtils &");
- }
- if(system("pidof -s Module_EvComm > /dev/null") != 0)
- {
- LOG_ERROR("Module_EvComm not running, restart it.");
- system ("/root/Module_EvComm &");
- }
- if(system("pidof -s Module_InternalComm > /dev/null") != 0)
- {
- LOG_ERROR("Module_InternalComm not running, restart it.");
- system ("/root/Module_InternalComm &");
- //ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
- }
- }
- 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 InitialDispenserDhcpServerConfig(void)
- {
- system("echo 'start 192.168.100.10' > /etc/udhcpd_eth1.conf");
- system("echo 'end 192.168.100.20' >> /etc/udhcpd_eth1.conf");
- system("echo 'interface eth1' >> /etc/udhcpd_eth1.conf");
- system("echo 'opt dns 8.8.8.8' >> /etc/udhcpd_eth1.conf");
- system("echo 'option subnet 255.255.255.0' >> /etc/udhcpd_eth1.conf");
- system("echo 'opt router 192.168.100.1' >> /etc/udhcpd_eth1.conf");
- system("echo 'option domain local' >> /etc/udhcpd_eth1.conf");
- system("echo 'option lease 86400' >> /etc/udhcpd_eth1.conf");
- usleep(1000);
- }
- void StartDispenserDhcpServer(void)
- {
- system("pgrep -f \"udhcpd /etc/udhcpd_eth1.conf\" | xargs kill");
- system("/usr/sbin/udhcpd /etc/udhcpd_eth1.conf > /dev/null &");
- }
- //==========================================
- // Check Smart Charging Profile
- //==========================================
- void Ocpp_ProfileReq_Cmd(byte gunIndex)
- {
- if(!Is_Ocpp_ChargingProfileConf(gunIndex))
- {
- if(!Is_Ocpp_ChargingProfileReq(gunIndex))
- {
- Set_Ocpp_ChargingProfileReq(gunIndex);
- }
- }
- }
- 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 Ocpp_ChargingProfile_Process(byte _index)
- {
- int _startCount = NO_DEFINE;
- int _maxCount = 0;
- float _limit = 0;
- int _numberPhases = 0;
- if(Is_Ocpp_ChargingProfileKind(_index, "Absolute") && Is_Ocpp_ChargingProfileId(_index))
- {
- _maxCount = Get_Ocpp_ChargingProfileScheduleCount(_index);
- _startCount = Get_Ocpp_ChargingProfileStartIndex(_index);
- if(_startCount < _maxCount)
- {
- _limit = Get_Ocpp_ChargingProfileScheduleLimit(_index, _startCount);
- _numberPhases = Get_Ocpp_ChargingProfileScheduleNumberPhases(_index, _startCount);
- chargingInfo[_index]->ChargingProfilePower = _limit * AC_OUTPUT_VOL * _numberPhases;
- if(chargingInfo[_index]->EvBatterytargetVoltage > 0 &&
- (int)chargingInfo[_index]->PresentChargingVoltage > 0)
- {
- chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
- }
- else
- {
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- if((int)_lastProfilePower[_index] != (int)chargingInfo[_index]->ChargingProfilePower ||
- (int)_lastProfileCurrent[_index] != (int)chargingInfo[_index]->ChargingProfileCurrent)
- {
- _limit = Get_Ocpp_ChargingProfileScheduleLimit(_index, _startCount);
- LOG_INFO("Gun %d Get Profile - Index = %d, Limit = %f",
- _index + 1, _startCount, _limit);
- LOG_INFO("Max: %d kW, Gun %d ChargingProfile Power = %d, Current = %d",
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1 ? (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : ((int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000),
- _index + 1, (int)chargingInfo[_index]->ChargingProfilePower, (int)chargingInfo[_index]->ChargingProfileCurrent);
- }
- _lastProfilePower[_index] = chargingInfo[_index]->ChargingProfilePower;
- _lastProfileCurrent[_index] = chargingInfo[_index]->ChargingProfileCurrent;
- }
- void Ocpp_MaxChargingProfile_Process(void)
- {
- int _startCount = NO_DEFINE;
- int _maxCount = 0;
- float _limit = 0;
- int _numberPhases = 0;
- if(Is_Ocpp_MaxChargingProfileKind("Absolute") && Is_Ocpp_MaxChargingProfileId())
- {
- _maxCount = Get_Ocpp_MaxProfileScheduleCount();
- _startCount = Get_Ocpp_MaxProfileStartIndex();
- if(_startCount < _maxCount)
- {
- _limit = Get_Ocpp_MaxProfileScheduleLimit(_startCount);
- _numberPhases = Get_Ocpp_MaxProfileScheduleNumberPhases(_startCount);
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = _limit * AC_OUTPUT_VOL * _numberPhases;
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- }
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- }
- if((int)_lastMaxProfilePower != (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower)
- {
- _limit = Get_Ocpp_MaxProfileScheduleLimit(_startCount);
- LOG_INFO("Charger Get Max Profile - Index = %d, Limit = %f",
- _startCount, _limit);
- LOG_INFO("Charger Max Profile Power = %d", (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower);
- }
- _lastMaxProfilePower = ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
- }
- void CheckSmartChargeProfile(byte _index)
- {
- if(Is_Ocpp_ChargingProfileConf(_index))
- {
- Clean_Ocpp_ChargingProfileConf(_index);
- Ocpp_MaxChargingProfile_Process();
- Ocpp_ChargingProfile_Process(_index);
- }
- }
- 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 UpdateErrorCodeToOcpp(byte index)
- {
- //printf("ConnectorAlarmCode = %s \n", chargingInfo[index]->ConnectorAlarmCode);
- if (strcmp((char *)chargingInfo[index]->ConnectorAlarmCode, "") != EQUAL)
- {
- SetOcppErrorCode(index, "InternalError");
- SetOcppVendorErrorCode(index, (char *)chargingInfo[index]->ConnectorAlarmCode);
- }
- else if (strcmp((char *)chargingInfo[index]->EvConnAlarmCode, "") != EQUAL)
- {
- SetOcppErrorCode(index, "OtherError");
- SetOcppVendorErrorCode(index, (char *)chargingInfo[index]->EvConnAlarmCode);
- }
- }
- void CheckMiscCommandRequirement(void)
- {
- BOOL NeedAnnouncement = FALSE;
- unsigned char connector = 0;
- if(ShmSysConfigAndInfo->SysInfo.FirmwareUpdate != YES)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- NeedAnnouncement = FALSE;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
- {
- if(ShmChargerInfo->DispenserMiscReq[i].CtrlValue != 0)
- {
- NeedAnnouncement = TRUE;
- }
- for(int j = 0; j < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity; j++)
- {
- connector = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorID[j] - 1;
- if(ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue != 0)
- {
- NeedAnnouncement = TRUE;
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.MiscNeedAnnouncement != NeedAnnouncement)
- {
- if(NeedAnnouncement)
- {
- //LOG_INFO("********** Dispenser %d Misc Command Need Announcement **********", i + 1);
- }
- else
- {
- //LOG_INFO("********** Dispenser %d Misc Command Announced **********", i + 1);
- }
- }
- }
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.MiscNeedAnnouncement = NeedAnnouncement;
- }
- }
- }
- void CheckDispenserVersionUpdateRequirement(void)
- {
- }
- bool IsReadyParalleling(void)
- {
- bool ready = true;
- for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
- {
- if(chargingInfo[i]->SystemStatus != S_IDLE && chargingInfo[i]->SystemStatus != S_MAINTAIN)
- {
- ready = false;
- break;
- }
- }
- return ready;
- }
- void SetParallelingStart(void)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(chargingInfo[i]->SystemStatus == S_IDLE)
- {
- setChargerMode(i, MODE_MAINTAIN);
- }
- }
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_Wait;
- }
- void SetParallelingDone(void)
- {
- unsigned short totalPow = 0;
- totalPow = GetTotalParallelCabinetPower();
- if(totalPow != ShmChargerInfo->ParallelCabinet.TotalParallelPower)
- {
- LOG_INFO("Total Parallel Cabinet Power: %d.%d kW", (totalPow / 10), (totalPow % 10));
- }
- ShmChargerInfo->ParallelCabinet.TotalParallelPower = totalPow;
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_None;
- }
- void SetPCabinetOutputRelay(unsigned char index, unsigned char OnOff)
- {
- unsigned char relay = 0;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle &&
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelConfirm)
- {
- relay = OnOff == YES ? YES : NO;
- if(ShmChargerInfo->ParallelCabinet.PCabinet[index].OutputRelaySetting[index] != relay)
- {
- LOG_INFO("Set Parallel Cabinet Gun %d Output Relay %s", index + 1, relay == YES ? "ON" : "OFF");
- }
- ShmChargerInfo->ParallelCabinet.PCabinet[i].OutputRelaySetting[index] = relay;
- }
- }
- }
- }
- void SetParallelCabinetAcContactor(unsigned char OnOff)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle &&
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelConfirm)
- {
- ShmChargerInfo->ParallelCabinet.PCabinet[i].AcContactorSetting = OnOff == YES ? YES : NO;
- }
- }
- }
- unsigned short GetTotalParallelCabinetPower(void)
- {
- unsigned short power = 0, slavePow = 0;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- slavePow = ParsingRatingPower((char *)ShmChargerInfo->ParallelCabinet.PCabinet[i].ModelName);
- power += slavePow;
- }
- }
- }
- return power;
- }
- unsigned char preParallelStatus = 0;
- void MCabinetParallelingProcess(void)
- {
- bool PsuReInitial = false;
- unsigned char status = 0;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- if(IsReadyParalleling())
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelRequest)
- {
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelRequest = false;
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelConfirm = true;
- PsuReInitial = true;
- }
- }
- if(PsuReInitial)
- {
- SetParallelingStart();
- }
- }
- status = ShmChargerInfo->ParallelCabinet.ParallelStatus;
- switch(status)
- {
- case _Parallel_None:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [None]");
- GetClockTime(&_Parallel_Time);
- }
- unsigned short totalPow = 0;
- totalPow = GetTotalParallelCabinetPower();
- if(totalPow != ShmChargerInfo->ParallelCabinet.TotalParallelPower)
- {
- LOG_INFO("Total Parallel Cabinet Power: %d.%d kW", (totalPow / 10), (totalPow % 10));
- }
- ShmChargerInfo->ParallelCabinet.TotalParallelPower = totalPow;
- break;
- case _Parallel_Wait:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [Wait]");
- SetAcContactor(OFF);
- SetParallelCabinetAcContactor(OFF);
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- SetPCabinetOutputRelay(i, OFF);
- }
- GetClockTime(&_Parallel_Time);
- }
- if((GetTimeoutValue(_Parallel_Time) / uSEC_VAL) >= PARALLEL_WAIT_TIME)
- {
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_Working;
- }
- break;
- case _Parallel_Working:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [Working]");
- SetAcContactor(ON);
- SetParallelCabinetAcContactor(ON);
- GetClockTime(&_Parallel_Time);
- }
- if(ShmPsuData->Work_Step == _WORK_CHARGING)
- {
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_Done;
- }
- break;
- case _Parallel_Done:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [Done]");
- GetClockTime(&_Parallel_Time);
- }
- if((GetTimeoutValue(_Parallel_Time) / uSEC_VAL) >= PARALLEL_WAIT_TIME)
- {
- SetParallelingDone();
- }
- break;
- }
- preParallelStatus = status;
- }
- }
- void SCabinetControllProcess(void)
- {
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- if(ShmChargerInfo->SCabinetControl.SAcContactor)
- {
- SetAcContactor(ON);
- }
- else
- {
- SetAcContactor(OFF);
- }
- unsigned short _parallelRelay = 0;
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- _parallelRelay = ShmChargerInfo->SCabinetControl.SParallelRelay[i] > 0 ? (1 < i) : 0;
- }
- if(_parallelRelay != ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue)
- {
- LOG_INFO("SCabinet Set Parallel Relay %X -> %X", ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue, _parallelRelay);
- }
- ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue = _parallelRelay;
- }
- }
- void CheckConnectorDisconnectionRecovery(unsigned char connector)
- {
- unsigned char dispenser = 0;
- dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].ParentDispensetIndex;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
- {
- LOG_INFO("Connector %d Disconnection Recovery", connector + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].Parameter.bits.Disconnection = false;
- }
- }
- bool ConnectorRequestToCharging(unsigned char connector)
- {
- unsigned char role = 0;
- bool done = false;
- role = ShmPsuGrouping->GroupCollection[connector].Role;
- switch(role)
- {
- case _GROLE_IDLE:
- if(!ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.ChargingRequest)
- {
- LOG_INFO("Request Gun %d To Start Charging", connector + 1);
- }
- ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.ChargingRequest = true;
- break;
- case _GROLE_MASTER:
- done = true;
- break;
- case _GROLE_SLAVE:
- if(!ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.SlaveChargingRequest)
- {
- LOG_INFO("Gun %d Wait For Re-Grouping", connector + 1);
- }
- ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.SlaveChargingRequest = true;
- break;
- case _GROLE_REQUEST_TO_CHARGING:
- done = true;
- break;
- default:
- break;
- }
- return done;
- }
- bool IsConnectorGroupingCompleted(unsigned char connector)
- {
- unsigned char role = 0;
- bool completed = false;
- role = ShmPsuGrouping->GroupCollection[connector].Role;
- switch(role)
- {
- case _GROLE_MASTER:
- completed = true;
- break;
- default:
- break;
- }
- return completed;
- }
- void SelfTestFailReason(void)
- {
- char reason[50];
- memset(reason, 0x00, sizeof(reason));
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip)
- {
- StatusCodeCompose(reason, "042251");
- }
- else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail)
- {
- StatusCodeCompose(reason, "042280");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail)
- {
- StatusCodeCompose(reason, "042281");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail)
- {
- StatusCodeCompose(reason, "042282");
- }
- }
- else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail)
- {
- StatusCodeCompose(reason, "042285");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail)
- {
- StatusCodeCompose(reason, "042286");
- }
- }
- else
- {
- StatusCodeCompose(reason, "Self Test Fail");
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- SetOcppErrorCode(gun_index, "InternalError");
- SetOcppVendorErrorCode(gun_index, reason);
- setChargerMode(gun_index, MODE_MAINTAIN);
- }
- }
- bool IsAvailableBackToIdle(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Idle ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable == false ||
- (!chargingInfo[gun_index]->ConnectorPlugIn && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm) ||
- isResetStopChargeFlag(gun_index) == YES)
- {
- return true;
- }
- return false;
- }
- void CheckGunAvailable(void)
- {
- if(!ShmChargerInfo->Control.SysCtrl.bits.PsuInit)
- {
- if(ShmChargerInfo->Control.PsuCtrl.bits.SelfTestOK)
- {
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- if(ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity > 0)
- {
- ShmChargerInfo->Control.GunAvailable[i] = YES;
- }
- }
- ShmChargerInfo->Control.SysCtrl.bits.PsuInit = true;
- }
- }
- }
- int presentChargedEnergyClear(unsigned char gun_index)
- {
- int result = FAIL;
- chargingInfo[gun_index]->PresentChargedEnergy = 0;
- memset(chargingInfo[gun_index]->presentChargedEnergyPeriod, 0x00, ARRAY_SIZE(chargingInfo[gun_index]->presentChargedEnergyPeriod) * sizeof(float));
- result = PASS;
- return result;
- }
- float presentChargedEnergyTotal(unsigned char gun_index)
- {
- float result = 0.0f;
- for(int idx = 0; idx < ARRAY_SIZE(chargingInfo[gun_index]->presentChargedEnergyPeriod); idx++)
- {
- result += chargingInfo[gun_index]->presentChargedEnergyPeriod[idx];
- }
- return result;
- }
- int presentChargedEnergyUpdate(unsigned char gun_index, float kwh)
- {
- int result = FAIL;
- time_t CurrentTime;
- struct tm *tm;
- CurrentTime = time(NULL);
- tm=localtime(&CurrentTime);
- chargingInfo[gun_index]->presentChargedEnergyPeriod[tm->tm_hour] += kwh;
- return result;
- }
- void ChkConnectorAction(void)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ConnectorActReq[i].Flag.bits.ChargingCancel)
- {
- Clean_Ocpp_TcciSerialNo(i);
- LOG_INFO("Gun %d Charging Canceled", i + 1);
- ShmChargerInfo->ConnectorActReq[i].Flag.bits.ChargingCancel = false;
- }
- }
- }
- int main(void)
- {
- unsigned long time = 0;
- int _dispenser = 0;
- _isStandbyEnable = true;
- if(CreateShareMemory() == 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("CreatShareMemory NG");
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- LOG_INFO("\n");
- LOG_INFO("===== Boot and Initialization start =====");
- LOG_INFO("Main Fork PID = %d", getpid());
- if (!InitialSystemDefaultConfig())
- {
- LOG_INFO("InitialSystemDefaultConfig NG");
- StopProcessingLoop();
- }
- LOG_INFO("ModelName: [%s], SN: [%s], SW Version: [%s][%s]",
- ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, fwVersion, subVersion);
- LOG_INFO("InitialShareMemoryInfo");
- InitialShareMemoryInfo();
- LOG_INFO("ChargerType (IEC or UL) = %d", ShmSysConfigAndInfo->SysInfo.ChargerType);
- if(!InitialChargerSetting())
- {
- isModelNameMatch = false;
- }
- Initialization();
- LOG_INFO("Spawn all Task.");
- SpawnTask();
- if (!isModelNameMatch)
- {
- LOG_INFO("Module Name & HW info none match.");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
- // Module Name 與硬體對應不正確
- LOG_ERROR("Module Name & HW info none match.");
- sleep(3);
- KillAllTask();
- StopProcessingLoop();
- }
- LOG_INFO("Module Name & HW info correct. Initialize.......");
- CreateTimeoutFork();
- SelfTestRun();
- while(ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
- {
- sleep(1);
- }
- if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
- {
- sleep(1);
- SelfTestFailReason();
- }
- else
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- setChargerMode(gun_index, MODE_IDLE);
- if(ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity > 0 ||
- !ShmChargerInfo->Control.PsuCtrl.bits.SelfTestOK)
- {
- ShmChargerInfo->Control.GunAvailable[gun_index] = YES;
- }
- }
- }
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE)
- {
- SetAcContactor(ON);
- SpawnOcppService();
- SpawnMaintainOcppService();
- }
- else
- {
- InitSlaveCabinetEthernet();
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- setChargerMode(gun_index, MODE_MAINTAIN);
- }
- }
- // Local DB
- if(DB_Open(localDb) != PASS)
- {
- LOG_INFO("DB_Open fail.");
- isDb_ready = false;
- }
- else
- {
- isDb_ready = true;
- for(int _index=0; _index< ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;_index++)
- {
- chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
- LOG_INFO("Gun %d IsAvailable Initial: [%s]", _index + 1, chargingInfo[_index]->IsAvailable == YES ? "Enable" : "Disable");
- }
- for(int _index=0; _index< ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;_index++)
- {
- chargingInfo[_index]->PowerConsumption = DB_Get_PowerConsumption(localDb, _index);
- LOG_INFO("Gun %d Consumption Initial: [%.1f kWh]", _index + 1, chargingInfo[_index]->PowerConsumption);
- }
- DB_Reboot_Record(localDb);
- }
- if (NetworkDB_Open(networkDb) != PASS)
- {
- LOG_ERROR("NetworkDB_Open fail.");
- }
- sleep(1);
- CreateWatchdog();
- // Main loop
- LOG_INFO("%s \n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE ?
- "****************************Main Loop**********************************" :
- "********************** SelfTest Fail **********************");
- GetClockTime(&_cmdMainPriority_time);
- for (;;)
- {
- CheckGunAvailable();
- CheckOcppStatus();
- ChkPrimaryStatus();
- ChkPsuStatus();
- PsuFailureResume();
- ChkConnectorAction();
- if (IsConnectorWholeIdle())
- {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- }
- if(CheckWiringInfoUpdate() != YES)
- {
- // return fork process
- return 0;
- }
- CheckSoftHardReset();
- StandbyCheck();
- // 讀卡邏輯
- //ScannerCardProcess();
- AuthorizeTimeoutProcess();
- // 當 AC 沒有搭上時,清除一些錯誤碼
- ClearAlarmCodeWhenAcOff();
- if ((GetTimeoutValue(_cmdMainPriority_time) / uSEC_VAL) > MAIN_PRIORITY_INTERVAL)
- {
- CheckTask();
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if((chargingInfo[_index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[_index]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[_index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (chargingInfo[_index]->SystemStatus == S_CHARGING && _ocppProfileChkFlag[_index] == 12)
- {
- Ocpp_ProfileReq_Cmd(_index);
- gunOutputVol[_index] = chargingInfo[_index]->PresentChargingVoltage;
- _ocppProfileChkFlag[_index] = 0;
- }
- else if (chargingInfo[_index]->SystemStatus != S_CHARGING)
- {
- Ocpp_ProfileReq_Cmd(_index);
- _ocppProfileChkFlag[_index] = 0;
- }
- else
- {
- _ocppProfileChkFlag[_index]++;
- }
- }
- if (chargingInfo[_index]->SystemStatus >= SYS_MODE_CHARGING &&
- chargingInfo[_index]->SystemStatus <= SYS_MODE_ALARM)
- {
- DB_Update_PowerConsumption(localDb, _index, chargingInfo[_index]->PowerConsumption);
- }
- }
- GetClockTime(&_cmdMainPriority_time);
- }
- CheckMiscCommandRequirement();
- CheckDispenserVersionUpdateRequirement();
- MCabinetParallelingProcess();
- SCabinetControllProcess();
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- //CheckGpioInStatus();
- CheckErrorOccurStatus(gun_index);
- ChkOcppStatus(gun_index);
- if((chargingInfo[gun_index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[gun_index]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[gun_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun_index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if(chargingInfo[gun_index]->SystemStatus == S_CHARGING)
- {
- // 進充電後,如果輸出電壓落差大於 10V 則直接繼續看 ChargingProfile
- if (chargingInfo[gun_index]->PresentChargingVoltage >= gunOutputVol[gun_index] + 10 ||
- chargingInfo[gun_index]->PresentChargingVoltage <= gunOutputVol[gun_index] - 10)
- {
- _ocppProfileChkFlag[gun_index] = 12;
- gunOutputVol[gun_index] = chargingInfo[gun_index]->PresentChargingVoltage;
- }
- }
- }
- CheckSmartChargeProfile(gun_index);
- //LOG_INFO("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
- switch(chargingInfo[gun_index]->SystemStatus)
- {
- case S_MAINTAIN:
- if(isModeChange(gun_index))
- {
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- LOG_INFO("================== Slave Cabinet %d ==================", ShmChargerInfo->Control.CabinetSwitch - 1);
- }
- LOG_INFO("================== S_MAINTAIN (%x) ================== \n", gun_index + 1);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_AVAILABILITY);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetSecTimeoutValue(_SystemStatus_Time[gun_index]);
- if(ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE ||
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE ||
- ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- break;
- }
- if(chargingInfo[gun_index]->IsAvailable == YES &&
- ShmChargerInfo->Control.GunAvailable[gun_index] == YES &&
- ShmChargerInfo->ParallelCabinet.ParallelStatus == _Parallel_None)
- {
- if(time >= MAINTAIN_RECOVERY_TIME)
- {
- Set_Connector_MiscCommand(gun_index, MISC_CONN_AVAILABILITY);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_RESERVATION:
- if(isModeChange(gun_index))
- {
- LOG_INFO("================== S_RESERVATION (%x) ================== \n", gun_index + 1);
- Get_Ocpp_ReserveNowIdTag(gun_index, &ShmChargerInfo->Control.ResevedIdTag[gun_index][0]);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_RESERVATION);
- LOG_INFO("****** Reservation IdTag: [%s] ******", &ShmChargerInfo->Control.ResevedIdTag[gun_index][0]);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Alarm ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- UpdateErrorCodeToOcpp(gun_index);
- setChargerMode(gun_index, MODE_FAULT);
- continue;
- }
- if(Is_Ocpp_ReserveNowExpired(gun_index))
- {
- chargingInfo[gun_index]->ReservationId = -1;
- LOG_INFO("Gun %d reservation time's up...", gun_index + 1);
- setChargerMode(gun_index, MODE_IDLE);
- }
- else
- {
- if(IsConnectorAuthorizeSuccess(gun_index))
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RemoteStart)
- {
- LOG_INFO("Gun %d remote start reserve charging", gun_index + 1);
- }
- else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RFID)
- {
- LOG_INFO("Gun %d swipe rfid start reserve charging", gun_index + 1);
- }
- setChargerMode(gun_index, MODE_AUTHORIZING);
- }
- else if(IsAutoGunSelectionAuthorizeSuccess(gun_index))
- {
- SetAcContactor(ON);
- if(chargingInfo[gun_index]->ConnectorPlugIn &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Preparing)
- {
- _dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex;
- if(Is_Ocpp_ReserveNowIdTag(gun_index, (char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[_dispenser].AuthInfo.AuthId))
- {
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[_dispenser].AuthInfo.AuthId);
- LOG_INFO("Gun %d reserve Auto Selection, CardNumber = %s", gun_index + 1, chargingInfo[gun_index]->StartUserId);
- DispenserAuthInitial(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- }
- }
- }
- }
- break;
- case S_IDLE:
- case S_FAULT:
- {
- // clean PermissionRequest flag
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PermissionRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = true;
- if(isModeChange(gun_index))
- {
- if (chargingInfo[gun_index]->SystemStatus == S_IDLE)
- {
- LOG_INFO("================== S_IDLE (%x) ================== \n", gun_index + 1);
- chargingInfo[gun_index]->PresentChargedDuration = 0;
- chargingInfo[gun_index]->RemainChargingDuration = 0;
- strcpy((char *)chargingInfo[gun_index]->StartDateTime, "");
- strcpy((char *)chargingInfo[gun_index]->StopDateTime, "");
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
- Clean_Ocpp_StopReason(gun_index);
- ReleaseAlarmCode(gun_index);
- // clean connector information
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingVoltage = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingCurrent = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteRemainChargingDuration = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteSoc = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].UserPrice = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].TotalCost = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AccountBalance = -65535;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.AnnounceBalance = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.GetStartChargingSoc = false;
- memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.StartWaitPlug = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.OutputLimitEnable = false;
- chargingInfo[gun_index]->EvBatterytargetVoltage = 0;
- chargingInfo[gun_index]->EvBatterytargetCurrent = 0;
- chargingInfo[gun_index]->EvBatteryMaxVoltage = 0;
- chargingInfo[gun_index]->EvBatterySoc = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteTargetVoltage = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteTargetCurrent = 0;
- // clean RemoteStart & RemoteStop flag
- Clean_Connector_MiscCommand(gun_index, MISC_CONN_REMOTE_START);
- Clean_Connector_MiscCommand(gun_index, MISC_CONN_REMOTE_STOP);
- Clean_Connector_MiscCommand(gun_index, MISC_CONN_UNLOCK);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStartConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStopConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.UnlockStopConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NormalStopRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.AlarmStopRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest = false;
- memset(chargingInfo[gun_index]->ConnectorAlarmCode, 0x00, sizeof(chargingInfo[gun_index]->ConnectorAlarmCode));
- Clean_Ocpp_RunningCost(gun_index);
- Clean_Ocpp_FinalCost(gun_index);
- Clean_DeductInfo(gun_index);
- Clean_Ocpp_TcciSerialNo(gun_index);
- Clean_UserTransaction(gun_index);
- presentChargedEnergyClear(gun_index);
- chargingInfo[gun_index]->PresentChargingPower = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent = 0;
- chargingInfo[gun_index]->ChargingProfilePower = -1;
- chargingInfo[gun_index]->ChargingProfileCurrent = -1;
- // clean force charging info
- memset(&ShmChargerInfo->Control.FCharging[gun_index], 0x00, sizeof(ForceCharging));
- if(chargingInfo[gun_index]->ReservationId != -1)
- {
- setChargerMode(gun_index, MODE_RESERVATION);
- continue;
- }
- }
- else if (chargingInfo[gun_index]->SystemStatus == S_FAULT)
- {
- LOG_INFO("================== S_FAULT (%x) ================== \n", gun_index + 1);
- }
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- if (chargingInfo[gun_index]->IsAvailable == NO ||
- ShmChargerInfo->Control.GunAvailable[gun_index] == NO)
- {
- setChargerMode(gun_index, MODE_MAINTAIN);
- continue;
- }
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Alarm ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest)
- {
- if(strncmp((char *)chargingInfo[gun_index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun_index]->ConnectorAlarmCode, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemotenAlarmCode, 6);
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest = false;
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- if(strncmp((char *)chargingInfo[gun_index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun_index]->ConnectorAlarmCode, "042304", 6);
- LOG_INFO("Connector %d Disconnect Occur", gun_index + 1);
- }
- }
- if(chargingInfo[gun_index]->SystemStatus != S_FAULT)
- {
- UpdateErrorCodeToOcpp(gun_index);
- setChargerMode(gun_index, MODE_FAULT);
- }
- else
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- CheckConnectorDisconnectionRecovery(gun_index);
- }
- }
- }
- else
- {
- if (chargingInfo[gun_index]->SystemStatus == S_FAULT)
- {
- time = GetSecTimeoutValue(_SystemStatus_Time[gun_index]);
- if(time >= FAULT_RELEASE_TIME)
- {
- ReleaseAlarmCode(gun_index);
- setChargerMode(gun_index, MODE_IDLE);
- }
- break;
- }
- // clean stop charge flag
- chargingInfo[gun_index]->StopChargeFlag = false;
- chargingInfo[gun_index]->ChargingStopFlag.ChargingStopValue = 0;
- { // Idle 正常程序起點
- // 判斷是否有啟用檢查插槍
- if(IsConnectorAuthorizeSuccess(gun_index))
- {
- if(chargingInfo[gun_index]->IsAvailable &&
- chargingInfo[gun_index]->SystemStatus == S_IDLE)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RemoteStart)
- {
- LOG_INFO("Gun %d remote start charging", gun_index + 1);
- }
- else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RFID)
- {
- LOG_INFO("Gun %d swipe rfid start charging", gun_index + 1);
- }
- setChargerMode(gun_index, MODE_AUTHORIZING);
- continue;
- }
- }
- else if(IsAutoGunSelectionAuthorizeSuccess(gun_index))
- {
- SetAcContactor(ON);
- if(chargingInfo[gun_index]->IsAvailable &&
- chargingInfo[gun_index]->SystemStatus == S_IDLE &&
- chargingInfo[gun_index]->ConnectorPlugIn &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Preparing)
- {
- _dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex;
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[_dispenser].AuthInfo.AuthId);
- LOG_INFO("Gun %d Auto Selection, CardNumber = %s", gun_index + 1, chargingInfo[gun_index]->StartUserId);
- DispenserAuthInitial(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- continue;
- }
- }
- // only for test & debug purpose
- else if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging &&
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.StartForceCharging)
- {
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.StartForceCharging = false;
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "ChargingTest");
- LOG_INFO("Gun %d Start Force Charging", gun_index + 1);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- continue;
- }
- else
- {
- }
- } // Idle 正常程序終點
- }
- }
- break;
- case S_AUTHORIZING:
- if(isModeChange(gun_index))
- {
- LOG_INFO("================== S_AUTHORIZING (%x) ================== \n", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- //StopSystemTimeoutDet();
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = false;
- SetAcContactor(ON);
- GetClockTime(&_ConnectorAuthorizing_Time[gun_index]);
- }
- if(GetTimeoutValue(_ConnectorAuthorizing_Time[gun_index]) / uSEC_VAL >= FORCE_BALANCE_TIME)
- {
- FouceAnnounceAccountBalance(gun_index);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStartConfirm)
- {
- // sync with dispenser
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStartConfirm = false;
- GetClockTime(&_ConnectorAuthorizing_Time[gun_index]);
- LOG_INFO("Sync with Gun %d through remote start", gun_index + 1);
- FouceAnnounceAccountBalance(gun_index);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.SwipeRfidConfirm)
- {
- // sync with dispenser
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.SwipeRfidConfirm = false;
- GetClockTime(&_ConnectorAuthorizing_Time[gun_index]);
- LOG_INFO("Sync with Connector %d through swipe rfid", gun_index + 1);
- }
- if(GetTimeoutValue(_ConnectorAuthorizing_Time[gun_index]) / uSEC_VAL >= ShmChargerInfo->CabinetMiscValue.ConnectionTimeout)
- {
- if(!chargingInfo[gun_index]->ConnectorPlugIn)
- {
- LOG_INFO("*********** Gun %d Plug In Timeout ***********", gun_index + 1);
- }
- else
- {
- LOG_INFO("*********** Gun %d Preparing State Timeout ***********", gun_index + 1);
- }
- setChargerMode(gun_index, MODE_IDLE);
- }
- else
- {
- if(chargingInfo[gun_index]->ConnectorPlugIn &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Preparing)
- {
- AddPlugInTimes(gun_index);
- LOG_INFO("Gun %d CardNumber = [%s]", gun_index + 1, chargingInfo[gun_index]->StartUserId);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- GunAuthInitial(gun_index);
- }
- else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.StartWaitPlug = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo = false;
- LOG_INFO("*********** Gun %d User Stop Plug In ***********", gun_index + 1);
- setChargerMode(gun_index, MODE_IDLE);
- }
- else if(isEvBoardStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Alarm Stop (S_AUTHORIZING) **********", gun_index + 1);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_REASSIGN_CHECK:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_REASSIGN_CHECK (%x) ================== \n", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- //StopSystemTimeoutDet();
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputEnergy = ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputDuration = ShmSysConfigAndInfo->SysConfig.MaxChargingDuration;
- LOG_INFO("Max Total Current %d A, Max Total Power %d kW, Total Energy %d kWh, Total Duration %d",
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent,
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputEnergy,
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputDuration);
- SetAcContactor(ON);
- SetPCabinetOutputRelay(gun_index, ON);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if(ConnectorRequestToCharging(gun_index))
- {
- setChargerMode(gun_index, MODE_REASSIGN);
- }
- else if(time >= WAIT_REASSIGN_TIME)
- {
- if(ShmPsuData->Work_Step != _WORK_CHARGING)
- {
- LOG_INFO("Gun %d Wait PSU Work Step Timeout", gun_index + 1);
- }
- else
- {
- LOG_INFO("Gun %d Request Charging Timeout", gun_index + 1);
- }
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_REASSIGN:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_REASSIGN (%x) ================== \n", gun_index + 1);
- //gettimeofday(&_toAverage_time, NULL);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if(IsConnectorGroupingCompleted(gun_index))
- {
- setChargerMode(gun_index, MODE_PRECHARGE);
- }
- else if(time >= MAX_REQUEST_CHARGING_TIME)
- {
- LOG_INFO("Gun %d Grouping Timeout", gun_index + 1);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_PREPARNING:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_PREPARNING (%x) ================== \n", gun_index + 1);
- //StopGunInfoTimeoutDet(gun_index);
- //StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
- SetAcContactor(ON);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if ((chargingInfo[gun_index]->AvailableChargingPower > 10) && time >= MIN_WAIT_PREPARNING_TIME)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
- break;;
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端或後臺要求停止
- LOG_INFO("********** Gun %d Alarm Stop (S_PREPARNING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_PREPARNING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_PREPARNING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- if(time > GUN_PREPARE_TIMEOUT)
- {
- LOG_INFO("********** Gun %d PrepareTimeout **********", gun_index + 1);
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
- if(strncmp((char *)chargingInfo[gun_index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun_index]->ConnectorAlarmCode, "012279", 6);
- LOG_INFO("Gun %d No Psu Resource", gun_index + 1);
- }
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- }
- }
- break;
- case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_PREPARING_FOR_EV (%x) ================== \n", gun_index + 1);
- //strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- //StopGunInfoTimeoutDet(gun_index);
- //StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PermissionRequest)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- // only for test & debug purpose
- else if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- LOG_INFO("Gun %d [Force Charging] S_PREPARING_FOR_EV OK", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PermissionRequest = true;
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端或後臺要求停止
- LOG_INFO("********** Gun %d Alarm Stop (S_PREPARING_FOR_EV) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_PREPARING_FOR_EV) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_PREPARING_FOR_EV) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- if(time >= GUN_EV_WAIT_TIMEOUT)
- {
- LOG_INFO("********** Gun %d Wait Dispenser Timeout **********", gun_index + 1);
- ChargingTerminalProcess(gun_index);
- }
- }
- break;
- case S_PREPARING_FOR_EVSE: // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_PREPARING_FOR_EVSE (%x) ================== \n", gun_index + 1);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- #ifdef STARTTRANSATION_IMMEDIATELY
- OcppStartTransaction(gun_index);
- #endif
- }
- CheckoutStartChargingSoc(gun_index, NO);
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- // only for test & debug purpose
- if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- float voltage = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetVoltage / 10;
- float current = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetCurrent / 10;
- if(chargingInfo[gun_index]->EvBatterytargetVoltage != voltage || chargingInfo[gun_index]->EvBatterytargetCurrent != current)
- {
- LOG_INFO("Gun %d Set Force Charging Voltage %4d V, Current: %4d A", gun_index + 1, (int)voltage, (int)current);
- }
- chargingInfo[gun_index]->EvBatterytargetVoltage = voltage;
- chargingInfo[gun_index]->EvBatterytargetCurrent = current;
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Charging)
- {
- setChargerMode(gun_index, MODE_CHARGING);
- }
- // only for test & debug purpose
- else if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- if(time >= FORCE_CHARGING_WAIT_EVSE)
- {
- LOG_INFO("Gun %d [Charging Simulation] S_PREPARING_FOR_EVSE OK", gun_index + 1);
- setChargerMode(gun_index, MODE_CHARGING);
- }
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端或後臺要求停止
- LOG_INFO("********** Gun %d Alarm Stop (S_PREPARING_FOR_EVSE) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_PREPARING_FOR_EVSE) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_PREPARING_FOR_EVSE) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- else if(isInvalidIdStopFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d InvalidId Stop (S_PREPARING_FOR_EVSE) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "DeAuthorized");
- ChargingTerminalProcess(gun_index);
- }
- if(time >= GUN_EV_WAIT_TIMEOUT)
- {
- LOG_INFO("********** Gun %d GFD timeout **********", gun_index + 1);
- ChargingTerminalProcess(gun_index);
- }
- }
- break;
- case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_CHARGING (%x) ================== \n", gun_index + 1);
- //StopGunInfoTimeoutDet(gun_index);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- CheckoutStartChargingSoc(gun_index, YES);
- chargingInfo[gun_index]->PresentChargedDuration = 0;
- ChangeStartOrStopDateTime(YES, gun_index);
- #ifndef STARTTRANSATION_IMMEDIATELY
- OcppStartTransaction(gun_index);
- #endif
- }
- // only for test & debug purpose
- if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- float voltage = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetVoltage / 10;
- float current = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetCurrent / 10;
- if(chargingInfo[gun_index]->EvBatterytargetVoltage != voltage || chargingInfo[gun_index]->EvBatterytargetCurrent != current)
- {
- LOG_INFO("Gun %d Set Force Charging Voltage %4d V, Current: %4d A", gun_index + 1, (int)voltage, (int)current);
- }
- chargingInfo[gun_index]->EvBatterytargetVoltage = voltage;
- chargingInfo[gun_index]->EvBatterytargetCurrent = current;
- }
- time = GetSecTimeoutValue(_SystemStatus_Time[gun_index]);
- // 計算 Power
- //chargingInfo[gun_index]->PresentChargingPower = ((float)((chargingInfo[gun_index]->PresentChargingVoltage) * (chargingInfo[gun_index]->PresentChargingCurrent)) / 1000);
- chargingInfo[gun_index]->PresentChargingPower = (((float)((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingVoltage) * (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingCurrent))) / 1000 / 100);
- if(time >= (chargingInfo[gun_index]->PresentChargedDuration + ENERAGY_INTERVAL))
- {
- chargingInfo[gun_index]->PresentChargedDuration++;
- float changingPow = (chargingInfo[gun_index]->PresentChargingPower) / 3600;
- if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
- {
- chargingInfo[gun_index]->ChargingFee += changingPow * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
- }
- presentChargedEnergyUpdate(gun_index, changingPow);
- chargingInfo[gun_index]->PresentChargedEnergy += changingPow;
- chargingInfo[gun_index]->PowerConsumption += changingPow;
- }
- if (isEvBoardStopChargeFlag(gun_index))
- {
- LOG_INFO("********** Gun %d Alarm Stop (S_CHARGING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_CHARGING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_CHARGING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- else if(isInvalidIdStopFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d InvalidId Stop (S_CHARGING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "DeAuthorized");
- ChargingTerminalProcess(gun_index);
- }
- else if(CheckBackendChargingTimeout(gun_index) ||
- CheckBackendChargingEnergy(gun_index))
- {
- LOG_INFO("********** Gun %d Backend Stop (S_CHARGING) **********", gun_index + 1);
- // 板端或後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- }
- break;
- case S_ALARM:
- case S_TERMINATING:
- {
- if (isModeChange(gun_index))
- {
- Set_Ocpp_StopReason(gun_index, "Other");
- if (chargingInfo[gun_index]->SystemStatus == S_ALARM)
- {
- LOG_INFO("================== S_ALARM (%x) ================== \n", gun_index + 1);
- UpdateErrorCodeToOcpp(gun_index);
- if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL)
- {
- OcppStopTransaction(gun_index);
- }
- TheEndCharging(gun_index);
- }
- else
- {
- LOG_INFO("================== S_TERMINATING (%x) ================== \n", gun_index + 1);
- }
- //StopGunInfoTimeoutDet(gun_index);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if (chargingInfo[gun_index]->SystemStatus == S_ALARM)
- {
- if(time >= GUN_COMP_WAIT_TIMEOUT)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- LOG_INFO ("********** Gun %d psu is releasable **********\n", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = true;
- }
- }
- if(IsAvailableBackToIdle(gun_index) == YES &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- ReleaseAlarmCode(gun_index);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- else
- {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- }
- break;
- case S_COMPLETE:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_COMPLETE (%x) ================== \n", gun_index + 1);
- if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL)
- {
- OcppStopTransaction(gun_index);
- }
- TheEndCharging(gun_index);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if(time >= GUN_COMP_WAIT_TIMEOUT)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- LOG_INFO ("********** Gun %d psu is releasable **********", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = true;
- }
- }
- if(IsAvailableBackToIdle(gun_index) == YES &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_CCS_PRECHARGE_ST0:
- if (isModeChange(gun_index))
- {
- LOG_INFO("CCS Precharge Processing 1....................%x \n", gun_index);
- //StopGunInfoTimeoutDet(gun_index);
- //StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
- }
- break;
- case S_CCS_PRECHARGE_ST1:
- if (isModeChange(gun_index))
- {
- LOG_INFO("CCS Precharge Processing 2....................%x \n", gun_index);
- }
- break;
- }
- }
- TryFeedWatchdog();
- usleep(whileLoopTime);
- }
- return FAIL;
- }
|