main.c 221 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <sys/time.h>
  4. #include <sys/timeb.h>
  5. #include <sys/types.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/socket.h>
  8. #include <sys/ipc.h>
  9. #include <sys/shm.h>
  10. #include <sys/mman.h>
  11. #include <linux/wireless.h>
  12. #include <arpa/inet.h>
  13. #include <netinet/in.h>
  14. #include <unistd.h>
  15. #include <stdarg.h>
  16. #include <stdio.h> /*標準輸入輸出定義*/
  17. #include <stdlib.h> /*標準函數庫定義*/
  18. #include <unistd.h> /*Unix 標準函數定義*/
  19. #include <fcntl.h> /*檔控制定義*/
  20. #include <termios.h> /*PPSIX 終端控制定義*/
  21. #include <errno.h> /*錯誤號定義*/
  22. #include <errno.h>
  23. #include <string.h>
  24. #include <stdint.h>
  25. #include <time.h>
  26. #include <ctype.h>
  27. #include <ifaddrs.h>
  28. #include <math.h>
  29. #include <stdbool.h>
  30. #include <dirent.h>
  31. #include <signal.h>
  32. #include "../Config.h"
  33. #include "main.h"
  34. #include "../common.h"
  35. #include "../timeout.h"
  36. #include "../Log/log.h"
  37. #include "../DataBase/DataBase.h"
  38. #include "../Define/define.h"
  39. #include "../ShareMemory/shmMem.h"
  40. #include "../SelectGun/SelectGun.h"
  41. //------------------------------------------------------------------------------
  42. static struct SysInfoData *pSysInfo = NULL;
  43. static struct SysConfigData *pSysConfig = NULL;
  44. static struct WARNING_CODE_INFO *pSysWarning = NULL;
  45. static struct AlarmCodeData *pAlarmCode = NULL;
  46. static struct FaultCodeData *pFaultCode = NULL;
  47. static struct InfoCodeData *pInfoCode = NULL;
  48. static struct PsuData *ShmPsuData = NULL;
  49. static struct CHAdeMOData *ShmCHAdeMOData = NULL;
  50. static struct GBTData *ShmGBTData = NULL;
  51. static struct CcsData *ShmCcsData = NULL;
  52. static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
  53. static struct FanModuleData *ShmFanModuleData = NULL;
  54. static struct RelayModuleData *ShmRelayModuleData = NULL;
  55. static struct LedModuleData *ShmLedModuleData = NULL;
  56. static struct OCPP16Data *ShmOCPP16Data = NULL;
  57. static struct OCPP20Data* ShmOCPP20Data = NULL;
  58. static DcCommonInfo *ShmDcCommonData = NULL;
  59. static struct ChargingInfoData *pDcChargingInfo = NULL;
  60. static struct ChargingInfoData *pAcChargingInfo = NULL;
  61. static struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  62. static struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  63. static SelectGunInfo *ShmSelectGunInfo = NULL; //Jerry add
  64. static EvBoardErrMsg gEvBoardErr = {0};
  65. static ChillerTempErr gChillerTempErr = {0};
  66. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  67. struct StatusCodeData *ShmStatusCodeData;
  68. #define DERATING_TARGET_LEVEL 5
  69. // for initial index to check EV board type is correct
  70. uint8_t bd0_1_status = 0;
  71. uint8_t bd0_2_status = 0;
  72. uint8_t bd1_1_status = 0;
  73. uint8_t bd1_2_status = 0;
  74. char *fwVersion = "V1.24.01.0000.00";
  75. char* DebugVersion = "V1.24.1";
  76. //sqlite3 *localDb;
  77. bool isDb_ready;
  78. //------------------------------------------------------------------------------
  79. void ClearDetectPluginFlag(int gunIndex);
  80. long long DiffTimebWithNow(struct timeb ST);
  81. uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
  82. void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value);
  83. unsigned long GetTimeoutValue(struct timeval _sour_time);
  84. void GetClockTime(struct timespec *_now_time, void *null);
  85. unsigned long GetClockTimeoutValue(struct timespec _start_time);
  86. void gpio_set_value(unsigned int gpio, unsigned int value);
  87. void InformOcppErrOccur(uint8_t codeType);
  88. void RecordAlarmCode(uint8_t gunIndex, char *code);
  89. void ReleaseAlarmCode(uint8_t gunIndex);
  90. void ResetChargerAlarmCode(uint8_t gunIndex, char *code);
  91. void AdjustChargerCurrent(void);
  92. void UpdateErrorCodeToOcpp(uint8_t index);
  93. //------------------------------------------------------------------------------
  94. //Primary.c
  95. extern void PrimaryLedIndicatorCtrlFork(void);
  96. extern void ChkPrimaryStatus(void);
  97. //RFID.c
  98. extern void CreateRfidFork(void);
  99. extern void ScannerCardProcess(void);
  100. extern bool GetIsCardScan(void);
  101. extern void SetIsCardScan(bool value);
  102. //SelfTest.c
  103. extern void SelfTestRun(void);
  104. //UpgradeFW.c
  105. /*extern void CheckFwUpdateFunction(void);*/
  106. //Ethernet.c
  107. extern void InitEthernet(void);
  108. extern void GetMacAddress(void);
  109. //WatchDog.c
  110. extern void CreateWatchdog(void);
  111. extern void TryCloseWatchdog(void);
  112. extern void TryFeedWatchdog(void);
  113. //ZipFile.c
  114. extern void zipLogFiles(void);
  115. //------------------------------------------------------------------------------
  116. //--- share memory value ---
  117. //------------------------------------------------------------------------------
  118. static void changeLcmPage(uint8_t index)
  119. {
  120. pSysInfo->SystemPage = index;
  121. }
  122. static uint8_t getCurLcmPage(void)
  123. {
  124. return pSysInfo->SystemPage;
  125. }
  126. static void systemPageRestoreInit(void)
  127. {
  128. #if defined DD360Audi
  129. pSysInfo->SystemPage = _LCM_SELECT_GUN;
  130. return;
  131. #endif //defined DD360Audi
  132. pSysInfo->SystemPage = _LCM_NONE;
  133. }
  134. static void connectorPageRestoreIdle(void)
  135. {
  136. #if defined DD360Audi
  137. pSysInfo->ConnectorPage = _LCM_SELECT_GUN;
  138. return;
  139. #endif //defined DD360Audi
  140. pSysInfo->ConnectorPage = _LCM_IDLE;
  141. }
  142. //------------------------------------------------------------------------------
  143. void destroySelGun(uint8_t curGun)
  144. {
  145. uint8_t i = 0;
  146. uint8_t totalGun = pSysConfig->TotalConnectorCount;
  147. #if !defined DD360Audi
  148. return;
  149. #endif //!defined DD360Audi
  150. //for status timeout
  151. if (curGun == DESTROY_ALL_SEL) {
  152. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
  153. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
  154. log_info("destroy all gun = %d, %d",
  155. ShmSelectGunInfo->SelGunInfo.LeftGun,
  156. ShmSelectGunInfo->SelGunInfo.RightGun);
  157. for (i = 0; i < totalGun; i++) {
  158. StopGunInfoTimeoutDet(i);
  159. memset(&ShmSelectGunInfo->PricesInfo[i], 0, sizeof(PricesInfo));
  160. }
  161. pSysInfo->CurGunSelected = 0;
  162. strcpy((char *)pSysConfig->UserId, "");
  163. //changeLcmPage(_LCM_SELECT_GUN);
  164. return;
  165. }
  166. //for charging timeout or complete
  167. if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
  168. if (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
  169. ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
  170. #ifdef DD360Audi
  171. changeLcmPage(_LCM_SELECT_GUN);
  172. #endif
  173. }
  174. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
  175. StopGunInfoTimeoutDet(LEFT_GUN_NUM);
  176. if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
  177. ClearAuthorizedFlag();
  178. }
  179. log_info("destroy left gun, cur page = %d", getCurLcmPage());
  180. if (getCurLcmPage() == pSysInfo->SystemPage) {
  181. log_info("clear left balance");
  182. memset(&ShmSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
  183. ShmSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
  184. }
  185. }
  186. if ((curGun == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
  187. if (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
  188. ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
  189. #ifdef DD360Audi
  190. changeLcmPage(_LCM_SELECT_GUN);
  191. #endif
  192. }
  193. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
  194. StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
  195. if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
  196. ClearAuthorizedFlag();
  197. }
  198. log_info("destroy right gun, cur page = %d", getCurLcmPage());
  199. if (getCurLcmPage() == pSysInfo->SystemPage) {
  200. log_info("clear right balance");
  201. memset(&ShmSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
  202. ShmSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
  203. }
  204. }
  205. }
  206. static int waitRightGunPlugIt(uint8_t curGun)
  207. {
  208. #if !defined DD360Audi
  209. return PASS;
  210. #endif //!defined DD360Audi
  211. if ((curGun == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
  212. return PASS;
  213. }
  214. return FAIL;
  215. }
  216. static int waitLeftGunPlugIt(uint8_t curGun)
  217. {
  218. #if !defined DD360Audi
  219. return PASS;
  220. #endif //!defined DD360Audi
  221. if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
  222. return PASS;
  223. }
  224. return FAIL;
  225. }
  226. void setSelGunWaitToAuthor(uint8_t curSel)
  227. {
  228. #if !defined DD360Audi
  229. return;
  230. #endif //!defined DD360Audi
  231. if (curSel == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
  232. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
  233. //printf("setSelGunWaitToAuthor left");
  234. StopGunInfoTimeoutDet(curSel);
  235. } else if (curSel == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
  236. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
  237. //printf("setSelGunWaitToAuthor right");
  238. StopGunInfoTimeoutDet(curSel);
  239. }
  240. }
  241. int getConfirmSelectedGun(uint8_t curSel)
  242. {
  243. #if !defined DD360Audi
  244. return PASS;
  245. #endif //!defined DD360Audi
  246. if (((curSel == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
  247. ((curSel == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
  248. return PASS;
  249. }
  250. return FAIL;
  251. }
  252. void confirmSelGun(uint8_t selGun)
  253. {
  254. #if !defined DD360Audi
  255. return;
  256. #endif //!defined DD360Audi
  257. if (selGun == LEFT_GUN_NUM) {
  258. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
  259. StopGunInfoTimeoutDet(selGun);
  260. //printf("confirmSelGun left");
  261. } else if (selGun == RIGHT_GUN_NUM) {
  262. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
  263. StopGunInfoTimeoutDet(selGun);
  264. //printf("confirmSelGun right");
  265. }
  266. // AUDI_LCM_CHANGE
  267. changeLcmPage(_LCM_IDLE);
  268. StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
  269. }
  270. static void GetFirmwareVersion(void)
  271. {
  272. // Get CSU root file system version
  273. sprintf((char *)pSysInfo->CsuRootFsFwRev, fwVersion);
  274. sprintf((char *)ShmDcCommonData->DebugVersion, DebugVersion);
  275. uint8_t count = 0, chademo = 0, ccs = 0, gb = 0;
  276. for (uint8_t idx = 0; idx < 3; idx++) {
  277. if (pSysConfig->ModelName[7 + idx] == 'J') {
  278. chademo++;
  279. count++;
  280. } else if (pSysConfig->ModelName[7 + idx] == 'G') {
  281. gb++;
  282. count++;
  283. } else if (pSysConfig->ModelName[7 + idx] == 'U' ||
  284. pSysConfig->ModelName[7 + idx] == 'V' ||
  285. pSysConfig->ModelName[7 + idx] == 'E') {
  286. ccs++;
  287. count++;
  288. }
  289. }
  290. if (count == 1) {
  291. if (chademo > 0) {
  292. pSysInfo->CsuRootFsFwRev[7] = '1';
  293. } else if (ccs > 0) {
  294. pSysInfo->CsuRootFsFwRev[7] = '2';
  295. } else if (gb > 0) {
  296. pSysInfo->CsuRootFsFwRev[7] = '3';
  297. }
  298. } else {
  299. if (chademo > 0 && ccs > 0) {
  300. pSysInfo->CsuRootFsFwRev[7] = '4';
  301. } else if (chademo > 0 && gb > 0) {
  302. pSysInfo->CsuRootFsFwRev[7] = '5';
  303. } else if (ccs > 0 && gb > 0) {
  304. pSysInfo->CsuRootFsFwRev[7] = '6';
  305. }
  306. }
  307. // Get network option from model name
  308. switch (pSysConfig->ModelName[10]) {
  309. case 'B':
  310. case 'U':
  311. //Blue tooth
  312. pSysInfo->CsuRootFsFwRev[9] = '3';
  313. break;
  314. case 'W':
  315. // WIFI
  316. pSysInfo->CsuRootFsFwRev[9] = '1';
  317. break;
  318. case 'T':
  319. // 3G/4G
  320. pSysInfo->CsuRootFsFwRev[9] = '2';
  321. break;
  322. case 'D': //DS60-120 add
  323. pSysInfo->CsuRootFsFwRev[9] = '5';
  324. break;
  325. default:
  326. // LAN
  327. pSysInfo->CsuRootFsFwRev[9] = '0';
  328. break;
  329. }
  330. // Get rating power from model name
  331. memcpy(&pSysInfo->CsuRootFsFwRev[10], &pSysConfig->ModelName[4], 0x03);
  332. // Get IEC or UL
  333. char _buf[3] = {0};
  334. memcpy(_buf, &pSysConfig->ModelName[2], 2);
  335. if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL) {
  336. pSysInfo->ChargerType = _CHARGER_TYPE_IEC;
  337. log_info("IEC model");
  338. } else if (strcmp(_buf, "WU") == EQUAL) {
  339. pSysInfo->ChargerType = _CHARGER_TYPE_UL;
  340. log_info("UL model");
  341. }
  342. }
  343. bool isCharging(uint8_t status)
  344. {
  345. if ((status >= S_REASSIGN_CHECK && status <= S_CHARGING) ||
  346. status == S_CCS_PRECHARGE_ST0 || status == S_CCS_PRECHARGE_ST1 ) {
  347. return TRUE;
  348. }
  349. return FALSE;
  350. }
  351. static void checkGunOTPState(uint8_t gunIndex)
  352. {
  353. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  354. //log_info("OTP:%d OTPR%d",pSysInfo->OTPTemp,pSysInfo->OTPTempR);
  355. //水冷機溫度檢測
  356. if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
  357. if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
  358. // 單水冷機
  359. // Chiller OTP
  360. if (pDcChargingInfo->ChillerTemp == UNDEFINED_TEMP) {
  361. // 溫度為255時判斷Sensor fail
  362. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  363. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  364. } else {
  365. //判斷OTP
  366. if ((ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[0] != UNDEFINED_TEMP) ||
  367. (ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[1] != UNDEFINED_TEMP)) {
  368. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
  369. RecordAlarmCode(gunIndex, "012323");
  370. } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR &&
  371. ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
  372. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  373. }
  374. //判斷Tube OTP
  375. if ((ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[2] != UNDEFINED_TEMP)||
  376. (ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[3] != UNDEFINED_TEMP)) {
  377. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
  378. RecordAlarmCode(gunIndex, "012332");
  379. } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR &&
  380. ShmDcCommonData->SystemTemp[3] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
  381. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
  382. }
  383. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  384. }
  385. } else {
  386. // 雙水冷機
  387. if (pDcChargingInfo->ChillerTemp == UNDEFINED_TEMP) {
  388. // 溫度為255時判斷Sensor fail
  389. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  390. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  391. } else {
  392. //判斷OTP
  393. if (ShmDcCommonData->SystemTemp[gunIndex*2] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[gunIndex*2] != UNDEFINED_TEMP) {
  394. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
  395. RecordAlarmCode(gunIndex, "012323");
  396. } else if (ShmDcCommonData->SystemTemp[gunIndex*2] != 0 && ShmDcCommonData->SystemTemp[gunIndex*2] < pSysInfo->OTPTempR) {
  397. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  398. }
  399. if (ShmDcCommonData->SystemTemp[gunIndex*2+1] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[gunIndex*2+1] != UNDEFINED_TEMP) {
  400. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
  401. RecordAlarmCode(gunIndex, "012332");
  402. } else if (ShmDcCommonData->SystemTemp[gunIndex*2+1] != 0 && ShmDcCommonData->SystemTemp[gunIndex*2+1] < pSysInfo->OTPTempR) {
  403. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
  404. }
  405. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  406. }
  407. }
  408. if (pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES) {
  409. RecordAlarmCode(gunIndex, "011037");
  410. }
  411. }
  412. switch (pDcChargingInfo->Type) {
  413. case _Type_Chademo:
  414. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  415. if (pDcChargingInfo->ConnectorTemp >= pSysInfo->OTPTemp) {
  416. RecordAlarmCode(gunIndex, "012229");
  417. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES;
  418. } else if (pDcChargingInfo->ConnectorTemp != 0 &&
  419. pDcChargingInfo->ConnectorTemp < pSysInfo->OTPTempR) {
  420. //ResetChargerAlarmCode(gunIndex, "012229");
  421. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  422. }
  423. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  424. } else {
  425. // 沒接上 Sensor or 異常
  426. //RecordAlarmCode(gunIndex, "011018");
  427. //ResetChargerAlarmCode(gunIndex, "012229");
  428. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  429. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES;
  430. if ((gunIndex == 0) &&
  431. (strncmp((char *)&pSysConfig->ModelName[7], "J", 1) == 0)) {
  432. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  433. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  434. } else if ((gunIndex == 1) &&
  435. ((strncmp((char *)&pSysConfig->ModelName[9], "J", 1) == 0) )) {
  436. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  437. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  438. }
  439. }
  440. break;
  441. case _Type_CCS_2:
  442. // CCS 不管甚麼輸出都會有槍溫偵測!!~
  443. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  444. //ResetChargerAlarmCode(gunIndex, "011019");
  445. if (pDcChargingInfo->ConnectorTemp >= pSysInfo->OTPTemp) {
  446. RecordAlarmCode(gunIndex, "012230");
  447. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES;
  448. } else if (pDcChargingInfo->ConnectorTemp != 0 &&
  449. pDcChargingInfo->ConnectorTemp < pSysInfo->OTPTempR) {
  450. //ResetChargerAlarmCode(gunIndex, "012230");
  451. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
  452. }
  453. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO;
  454. //ResetChargerAlarmCode(gunIndex, "011019");
  455. } else {
  456. // 沒接上 Sensor or 異常
  457. //RecordAlarmCode(gunIndex, "011019");
  458. //ResetChargerAlarmCode(gunIndex, "012230");
  459. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
  460. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES;
  461. }
  462. break;
  463. case _Type_GB:
  464. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  465. if (pDcChargingInfo->ConnectorTemp >= pSysInfo->OTPTemp) {
  466. RecordAlarmCode(gunIndex, "012231");
  467. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES;
  468. } else if (pDcChargingInfo->ConnectorTemp != 0 &&
  469. pDcChargingInfo->ConnectorTemp < pSysInfo->OTPTempR) {
  470. //ResetChargerAlarmCode(gunIndex, "012231");
  471. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
  472. }
  473. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO;
  474. } else {
  475. // 沒接上 Sensor or 異常
  476. //RecordAlarmCode(gunIndex, "011020");
  477. //ResetChargerAlarmCode(gunIndex, "012231");
  478. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
  479. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES;
  480. }
  481. break;
  482. }
  483. }
  484. static void collectError(uint8_t gunIndex)
  485. {
  486. gEvBoardErr.GunErrMessage |= ShmDcCommonData->ConnectErrList[gunIndex].GunErrMessage;
  487. gChillerTempErr.TempErrMsg |= ShmDcCommonData->ChillerTempErr[gunIndex].TempErrMsg;
  488. }
  489. static void checkGBTAlarmState(uint8_t gunType)
  490. {
  491. // GFD Trip
  492. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  493. pAlarmCode->AlarmEvents.bits.GbGfdTrip = YES;
  494. } else {
  495. pAlarmCode->AlarmEvents.bits.GbGfdTrip = NO;
  496. }
  497. // UVP
  498. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  499. pAlarmCode->AlarmEvents.bits.GbtOutputUVPFail = YES;
  500. } else {
  501. pAlarmCode->AlarmEvents.bits.GbtOutputUVPFail = NO;
  502. }
  503. // OTP
  504. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  505. pAlarmCode->AlarmEvents.bits.GbConnectorOTP = YES;
  506. } else {
  507. pAlarmCode->AlarmEvents.bits.GbConnectorOTP = NO;
  508. }
  509. // OVP
  510. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  511. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES;
  512. } else {
  513. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = NO;
  514. }
  515. // GFD Warning
  516. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  517. pAlarmCode->AlarmEvents.bits.GbGroundfaultWarning = YES;
  518. } else {
  519. pAlarmCode->AlarmEvents.bits.GbGroundfaultWarning = NO;
  520. }
  521. // Relay Welding
  522. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  523. pFaultCode->FaultEvents.bits.GbOutputRelayWelding = YES;
  524. } else {
  525. pFaultCode->FaultEvents.bits.GbOutputRelayWelding = NO;
  526. }
  527. // Relay Driving
  528. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  529. pFaultCode->FaultEvents.bits.GbOutputRelayDrivingFault = YES;
  530. } else {
  531. pFaultCode->FaultEvents.bits.GbOutputRelayDrivingFault = NO;
  532. }
  533. // Connect temp Sensor broken
  534. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  535. pFaultCode->FaultEvents.bits.GbConnectorTempSensorBroken = YES;
  536. } else {
  537. pFaultCode->FaultEvents.bits.GbConnectorTempSensorBroken = NO;
  538. }
  539. }
  540. static void checkCCSAlarmState(uint8_t gunType)
  541. {
  542. // GFD Trip
  543. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  544. pAlarmCode->AlarmEvents.bits.CcsGfdTrip = YES;
  545. } else {
  546. pAlarmCode->AlarmEvents.bits.CcsGfdTrip = NO;
  547. }
  548. // UVP
  549. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  550. pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = YES;
  551. } else {
  552. pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = NO;
  553. }
  554. // OTP
  555. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  556. pAlarmCode->AlarmEvents.bits.CcsConnectorOTP = YES;
  557. } else {
  558. pAlarmCode->AlarmEvents.bits.CcsConnectorOTP = NO;
  559. }
  560. // OVP
  561. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  562. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES;
  563. } else {
  564. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO;
  565. }
  566. // GFD Warning
  567. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  568. pAlarmCode->AlarmEvents.bits.CcsGroundfaultWarning = YES;
  569. } else {
  570. pAlarmCode->AlarmEvents.bits.CcsGroundfaultWarning = NO;
  571. }
  572. // Relay Welding
  573. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  574. pFaultCode->FaultEvents.bits.CcsOutputRelayWelding = YES;
  575. } else {
  576. pFaultCode->FaultEvents.bits.CcsOutputRelayWelding = NO;
  577. }
  578. // Relay Driving
  579. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  580. pFaultCode->FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
  581. } else {
  582. pFaultCode->FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
  583. }
  584. // Connect temp Sensor broken
  585. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  586. pFaultCode->FaultEvents.bits.CcsConnectorTempSensorBroken = YES;
  587. } else {
  588. pFaultCode->FaultEvents.bits.CcsConnectorTempSensorBroken = NO;
  589. }
  590. }
  591. static void checkChaDeMoAlarmState(uint8_t gunType)
  592. {
  593. // GFD Trip
  594. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  595. pAlarmCode->AlarmEvents.bits.ChademoGfdTrip = YES;
  596. } else {
  597. pAlarmCode->AlarmEvents.bits.ChademoGfdTrip = NO;
  598. }
  599. // UVP
  600. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  601. pAlarmCode->AlarmEvents.bits.ChademoOutputUVPFail = YES;
  602. } else {
  603. pAlarmCode->AlarmEvents.bits.ChademoOutputUVPFail = NO;
  604. }
  605. // OTP
  606. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  607. pAlarmCode->AlarmEvents.bits.ChademoConnectorOTP = YES;
  608. } else {
  609. pAlarmCode->AlarmEvents.bits.ChademoConnectorOTP = NO;
  610. }
  611. // OVP
  612. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  613. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES;
  614. } else {
  615. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = NO;
  616. }
  617. // GFD Warning
  618. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  619. pAlarmCode->AlarmEvents.bits.ChademoGroundWarning = YES;
  620. } else {
  621. pAlarmCode->AlarmEvents.bits.ChademoGroundWarning = NO;
  622. }
  623. // Relay Welding
  624. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  625. pFaultCode->FaultEvents.bits.ChademoOutputRelayWelding = YES;
  626. } else {
  627. pFaultCode->FaultEvents.bits.ChademoOutputRelayWelding = NO;
  628. }
  629. // Relay Driving
  630. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  631. pFaultCode->FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
  632. } else {
  633. pFaultCode->FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
  634. }
  635. // Connect temp Sensor broken
  636. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  637. pFaultCode->FaultEvents.bits.ChademoConnectorTempSensorBroken = YES;
  638. } else {
  639. pFaultCode->FaultEvents.bits.ChademoConnectorTempSensorBroken = NO;
  640. }
  641. }
  642. static void checkChillerAlarmState(void)
  643. {
  644. if (DetectBitValue(gChillerTempErr.TempErrMsg, 0)) {
  645. pAlarmCode->AlarmEvents.bits.SystemChillerOTP = YES;
  646. } else {
  647. pAlarmCode->AlarmEvents.bits.SystemChillerOTP = NO;
  648. }
  649. if (DetectBitValue(gChillerTempErr.TempErrMsg, 1)) {
  650. pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = YES;
  651. } else {
  652. pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = NO;
  653. }
  654. #if 0
  655. //uint8_t gunIndex = 0;
  656. //for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  657. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  658. if (ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP == YES) {
  659. pAlarmCode->AlarmEvents.bits.SystemChillerOTP = YES;
  660. //log_info("SystemChillerOTP = %d", pAlarmCode->AlarmEvents.bits.SystemChillerOTP);
  661. return ABNORMAL;
  662. } else {
  663. pAlarmCode->AlarmEvents.bits.SystemChillerOTP = NO;
  664. }
  665. if (ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail == YES) {
  666. pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = YES;
  667. return ABNORMAL;
  668. } else {
  669. pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = NO;
  670. }
  671. //}
  672. //
  673. return NORMAL;
  674. #endif //0
  675. }
  676. static void checkEvBoardAlarmState(uint8_t gunType)
  677. {
  678. switch (gunType) {
  679. case _Type_Chademo:
  680. checkChaDeMoAlarmState(gunType);
  681. break;
  682. case _Type_CCS_2:
  683. checkCCSAlarmState(gunType);
  684. break;
  685. case _Type_GB:
  686. checkGBTAlarmState(gunType);
  687. break;
  688. }
  689. }
  690. unsigned long GetTimeoutValue(struct timeval _sour_time)
  691. {
  692. struct timeval _end_time;
  693. gettimeofday(&_end_time, NULL);
  694. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  695. }
  696. void GetClockTime(struct timespec *_now_time, void *null)
  697. {
  698. clock_gettime(CLOCK_MONOTONIC, _now_time);
  699. }
  700. // return value unit: 1us
  701. unsigned long GetClockTimeoutValue(struct timespec _start_time)
  702. {
  703. struct timespec ts_end;
  704. unsigned long ret = 0;
  705. clock_gettime(CLOCK_MONOTONIC, &ts_end);
  706. ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec/ 1000)));
  707. return ret;
  708. }
  709. int DiffTimeb(struct timeb ST, struct timeb ET)
  710. {
  711. //return milli-second
  712. unsigned int StartTime, StopTime;
  713. StartTime = (unsigned int)ST.time;
  714. StopTime = (unsigned int)ET.time;
  715. //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  716. return (StopTime - StartTime);
  717. }
  718. bool CheckTimeOut(struct timeb ST)
  719. {
  720. struct timeb ET;
  721. unsigned int StartTime, StopTime;
  722. ftime(&ET);
  723. StartTime = (unsigned int) ST.time;
  724. StopTime = (unsigned int) ET.time;
  725. return (StopTime > StartTime) ? YES : NO;
  726. }
  727. void setChargerMode(uint8_t gunIndex, uint8_t mode)
  728. {
  729. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  730. pDcChargingInfo->SystemStatus = mode;
  731. }
  732. long long DiffTimebWithNow(struct timeb ST)
  733. {
  734. //return milli-second
  735. struct timeb ET;
  736. long long StartTime, StopTime;
  737. ftime(&ET);
  738. StartTime = (long long)ST.time;
  739. StopTime = (long long)ET.time;
  740. return ((StopTime - StartTime) * 1000) + (ET.millitm - ST.millitm);
  741. }
  742. //==========================================
  743. // Log
  744. //==========================================
  745. void CheckFwSlotStatusLog(void)
  746. {
  747. if (bd0_1_status == 0 && bd0_2_status == 1) {
  748. log_info("Connector 1 : Chademo");
  749. } else if (bd0_1_status == 1 && bd0_2_status == 0) {
  750. log_info("Connector 1 : CCS");
  751. } else if (bd0_1_status == 1 && bd0_2_status == 1) {
  752. log_info("Connector 1 : GB");
  753. }
  754. if (bd1_1_status == 0 && bd1_2_status == 1) {
  755. log_info("Connector 2 : Chademo");
  756. } else if (bd1_1_status == 1 && bd1_2_status == 0) {
  757. log_info("Connector 2 : CCS");
  758. } else if (bd1_1_status == 1 && bd1_2_status == 1) {
  759. log_info("Connector 2 : GB");
  760. }
  761. }
  762. void CheckHwSlotStatusLog(uint8_t index)
  763. {
  764. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  765. if (pDcChargingInfo->Type == _Type_Chademo) {
  766. log_info("Hw check : Connector %d, Type : Chademo, Evboard_id = %d ",
  767. index, pDcChargingInfo->Evboard_id);
  768. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  769. log_info("Hw check : Connector %d, Type : CCS, Evboard_id = %d ",
  770. index, pDcChargingInfo->Evboard_id);
  771. } else if (pDcChargingInfo->Type == _Type_GB) {
  772. log_info("Hw check : Connector %d, Type : GB, Evboard_id = %d ",
  773. index, pDcChargingInfo->Evboard_id);
  774. }
  775. }
  776. //=================================
  777. // LCM Page
  778. //=================================
  779. void ChangeLcmByIndex(uint8_t page_index)
  780. {
  781. if (pSysWarning->Level != WARN_LV_ER ||
  782. page_index == _LCM_COMPLETE ||
  783. page_index == _LCM_FIX
  784. ) {
  785. pSysInfo->PageIndex = page_index;
  786. }
  787. }
  788. //======================================================
  789. // Peripheral initial
  790. //======================================================
  791. void InitGPIO()
  792. {
  793. /*****************0~3, 4 bank, bank x 32+ num*********************/
  794. /***************************************************************/
  795. /*************** GPIO 0 ***************************************/
  796. /***************************************************************/
  797. /* GPMC_AD8 => GPIO0_22 *//*ID BD1_1*/
  798. system("echo 22 > /sys/class/gpio/export");
  799. system("echo \"in\" > /sys/class/gpio/gpio22/direction");
  800. /* GPMC_AD9 => GPIO0_23 *//*ID BD1_2*/
  801. system("echo 23 > /sys/class/gpio/export");
  802. system("echo \"in\" > /sys/class/gpio/gpio23/direction");
  803. /* GPMC_AD10 => GPIO0_26 *//*IO BD1_1*/
  804. system("echo 26 > /sys/class/gpio/export");
  805. system("echo \"out\" > /sys/class/gpio/gpio26/direction");
  806. system("echo 1 > /sys/class/gpio/gpio26/value");
  807. /* GPMC_AD11 => GPIO0_27 *//*IO BD1_2*/
  808. system("echo 27 > /sys/class/gpio/export");
  809. system("echo \"in\" > /sys/class/gpio/gpio27/direction");
  810. /* RMII1_REF_CLK => GPIO0_29 *//*USB 0 OCP detection*/
  811. system("echo 29 > /sys/class/gpio/export");
  812. system("echo \"in\" > /sys/class/gpio/gpio29/direction");
  813. /*XDMA_EVENT_INTR0 => GPIO0_19 *//*AM_RFID_RST*/
  814. system("echo 19 > /sys/class/gpio/export");
  815. system("echo \"out\" > /sys/class/gpio/gpio19/direction");
  816. system("echo 1 > /sys/class/gpio/gpio19/value");
  817. /*XDMA_EVENT_INTR1 => GPIO0_20 *//*AM_RFID_ICC*/
  818. system("echo 20 > /sys/class/gpio/export");
  819. system("echo \"in\" > /sys/class/gpio/gpio20/direction");
  820. /***************************************************************/
  821. /*************** GPIO 1 ***************************************/
  822. /***************************************************************/
  823. /* GPMC_AD12 => GPIO1_12 *//*ID BD2_1*/
  824. system("echo 44 > /sys/class/gpio/export");
  825. system("echo \"in\" > /sys/class/gpio/gpio44/direction");
  826. /* GPMC_AD13 => GPIO1_13 *//*ID BD2_2*/
  827. system("echo 45 > /sys/class/gpio/export");
  828. system("echo \"in\" > /sys/class/gpio/gpio45/direction");
  829. /* GPMC_AD14 => GPIO1_14 *//*IO BD2_1*/
  830. system("echo 46 > /sys/class/gpio/export");
  831. system("echo \"out\" > /sys/class/gpio/gpio46/direction");
  832. system("echo 0 > /sys/class/gpio/gpio46/value");
  833. /* GPMC_AD15 => GPIO1_15 *//*IO BD2_2*/
  834. system("echo 47 > /sys/class/gpio/export");
  835. system("echo \"in\" > /sys/class/gpio/gpio47/direction");
  836. /***************************************************************/
  837. /*************** GPIO 2 ***************************************/
  838. /***************************************************************/
  839. /*LCD_AC_BIAS_EN => GPIO2_25*//*RS-485 for module DE control*/
  840. system("echo 89 > /sys/class/gpio/export");
  841. system("echo \"out\" > /sys/class/gpio/gpio89/direction");
  842. system("echo 1 > /sys/class/gpio/gpio89/value");
  843. /*LCD_HSYNC => GPIO2_23*//*RS-485 for module RE control*/
  844. system("echo 87 > /sys/class/gpio/export");
  845. system("echo \"out\" > /sys/class/gpio/gpio87/direction");
  846. system("echo 0 > /sys/class/gpio/gpio87/value");
  847. /*LCD_PCLK => GPIO2_24*//*CCS communication board 1 proximity*/
  848. system("echo 88 > /sys/class/gpio/export");
  849. system("echo \"in\" > /sys/class/gpio/gpio88/direction");
  850. /*LCD_VSYNC => GPIO2_22*//*CCS communication board 2 proximity*/
  851. system("echo 86 > /sys/class/gpio/export");
  852. system("echo \"in\" > /sys/class/gpio/gpio86/direction");
  853. /***************************************************************/
  854. /*************** GPIO 3 ***************************************/
  855. /***************************************************************/
  856. /*MCASP0_FSX => GPIO3_15*//*Emergency Stop button detect*/
  857. system("echo 111 > /sys/class/gpio/export");
  858. system("echo \"in\" > /sys/class/gpio/gpio111/direction");
  859. /*MCASP0_ACLKR => GPIO3_18*//*USB1 OCP detect*/
  860. system("echo 114 > /sys/class/gpio/export");
  861. system("echo \"in\" > /sys/class/gpio/gpio114/direction");
  862. /*MCASP0_AHCLKR => GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
  863. system("echo 113 > /sys/class/gpio/export");
  864. system("echo \"in\" > /sys/class/gpio/gpio113/direction");
  865. /*MCASP0_ACLKX => GPIO3_14*//*Ethernet PHY reset*/
  866. system("echo 110 > /sys/class/gpio/export");
  867. system("echo \"out\" > /sys/class/gpio/gpio110/direction");
  868. system("echo 0 > /sys/class/gpio/gpio110/value");
  869. /* MCASP0_FSR => GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
  870. system("echo 115 > /sys/class/gpio/export");
  871. system("echo \"out\" > /sys/class/gpio/gpio115/direction");
  872. system("echo 0 > /sys/class/gpio/gpio115/value");
  873. /* MCASP0_AXR0 => GPIO3_16 *//*CSU board function OK indicator.*/
  874. system("echo 112 > /sys/class/gpio/export");
  875. system("echo \"out\" > /sys/class/gpio/gpio112/direction");
  876. system("echo 1 > /sys/class/gpio/gpio112/value");
  877. /* MCASP0_AXR1 => GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
  878. system("echo 116 > /sys/class/gpio/export");
  879. system("echo \"out\" > /sys/class/gpio/gpio116/direction");
  880. system("echo 0 > /sys/class/gpio/gpio116/value");
  881. log_info("Initial GPIO OK");
  882. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  883. return ;
  884. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  885. /* (C14) EMU0.gpio3[7] */ /*CP open/short feature enable/disable, pull low for default enable*/
  886. system("echo 103 > /sys/class/gpio/export");
  887. system("echo \"out\" > /sys/class/gpio/gpio103/direction");
  888. system("echo 0 > /sys/class/gpio/gpio103/value");
  889. /* (B14) EMU1.gpio3[8] */ /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
  890. system("echo 104 > /sys/class/gpio/export");
  891. system("echo \"out\" > /sys/class/gpio/gpio104/direction");
  892. system("echo 0 > /sys/class/gpio/gpio104/value");
  893. }
  894. int LoadSysConfigAndInfo()
  895. {
  896. int fd, wrd;
  897. unsigned char *buf;
  898. unsigned int ChkSum, ChkSumOrg;
  899. if ((buf = malloc(MtdBlockSize)) == NULL) {
  900. log_error("malloc buffer NG,rebooting..");
  901. if (pAlarmCode != NULL) {
  902. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  903. }
  904. sleep(5);
  905. system("reboot -f");
  906. sleep(5);
  907. system("reboot -f");
  908. }
  909. memset(buf, 0, MtdBlockSize);
  910. //================================================
  911. // Load configuration from mtdblock10
  912. //================================================
  913. system("nanddump /dev/mtd10 -f /mnt/EvseConfig.bin");
  914. fd = open("/mnt/EvseConfig.bin", O_RDWR);
  915. if (fd < 0) {
  916. free(buf);
  917. log_error("open mtdblock10 NG,rebooting..");
  918. if (pAlarmCode != NULL) {
  919. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  920. }
  921. sleep(5);
  922. system("reboot -f");
  923. sleep(5);
  924. system("reboot -f");
  925. }
  926. wrd = read(fd, buf, MtdBlockSize);
  927. close(fd);
  928. if (wrd < MtdBlockSize) {
  929. free(buf);
  930. log_error("read SysConfigData data NG,rebooting..");
  931. if (pAlarmCode != NULL) {
  932. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  933. }
  934. sleep(5);
  935. system("reboot -f");
  936. sleep(5);
  937. system("reboot -f");
  938. }
  939. ChkSum = 0;
  940. for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
  941. ChkSum += buf[wrd];
  942. }
  943. memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
  944. memcpy(&pSysConfig->ModelName, buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev)), ARRAY_SIZE(pSysConfig->ModelName));
  945. memcpy(&pSysConfig->SerialNumber, buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev) + ARRAY_SIZE(pSysConfig->ModelName) + ARRAY_SIZE(pSysConfig->AcModelName)), ARRAY_SIZE(pSysConfig->SerialNumber));
  946. //================================================
  947. // Load configuration from mtdblock11
  948. //================================================
  949. if (ChkSum != ChkSumOrg) {
  950. log_error("Primary SysConfigData checksum NG, read backup");
  951. system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
  952. fd = open("/mnt/EvseConfig.bin", O_RDWR);
  953. if (fd < 0) {
  954. free(buf);
  955. log_error("open mtdblock11 (backup) NG,rebooting..");
  956. if (pAlarmCode != NULL) {
  957. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  958. }
  959. sleep(5);
  960. system("reboot -f");
  961. sleep(5);
  962. system("reboot -f");
  963. }
  964. memset(buf, 0, MtdBlockSize);
  965. wrd = read(fd, buf, MtdBlockSize);
  966. close(fd);
  967. if (wrd < MtdBlockSize) {
  968. free(buf);
  969. log_error("read backup SysConfigData data NG,rebooting..");
  970. if (pAlarmCode != NULL) {
  971. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  972. }
  973. sleep(5);
  974. system("reboot -f");
  975. sleep(5);
  976. system("reboot -f");
  977. }
  978. ChkSum = 0;
  979. for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
  980. ChkSum += buf[wrd];
  981. }
  982. memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
  983. //================================================
  984. // Load configuration from mtdblock12 (Factory default)
  985. //================================================
  986. if (ChkSum != ChkSumOrg) {
  987. log_warn("backup SysConfigData checksum NG, read Factory default");
  988. system("nanddump /dev/mtd12 -f /mnt/EvseConfig.bin");
  989. fd = open("/mnt/EvseConfig.bin", O_RDWR);
  990. if (fd < 0) {
  991. log_error("open mtdblock12 (Factory default) NG,rebooting..");
  992. free(buf);
  993. if (pAlarmCode != NULL) {
  994. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  995. }
  996. sleep(5);
  997. system("reboot -f");
  998. sleep(5);
  999. system("reboot -f");
  1000. }
  1001. memset(buf, 0, MtdBlockSize);
  1002. wrd = read(fd, buf, MtdBlockSize);
  1003. close(fd);
  1004. if (wrd < MtdBlockSize) {
  1005. log_error("read factory default SysConfigData data NG,rebooting..");
  1006. free(buf);
  1007. if (pAlarmCode != NULL) {
  1008. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  1009. }
  1010. sleep(5);
  1011. system("reboot -f");
  1012. sleep(5);
  1013. system("reboot -f");
  1014. }
  1015. ChkSum = 0;
  1016. for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
  1017. ChkSum += buf[wrd];
  1018. }
  1019. memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
  1020. memcpy(buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev)), &pSysConfig->ModelName, ARRAY_SIZE(pSysConfig->ModelName));
  1021. memcpy(buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev) + ARRAY_SIZE(pSysConfig->ModelName) + ARRAY_SIZE(pSysConfig->AcModelName)), &pSysConfig->SerialNumber, ARRAY_SIZE(pSysConfig->SerialNumber));
  1022. if (ChkSum != ChkSumOrg) {
  1023. log_warn("factory default SysConfigData checksum NG, restore factory default");
  1024. free(buf);
  1025. system("cd /root;./FactoryConfig -m");
  1026. system("rm -f /Storage/OCPP/OCPPConfiguration");
  1027. system("sync");
  1028. sleep(5);
  1029. system("reboot -f");
  1030. sleep(5);
  1031. system("reboot -f");
  1032. return FAIL;
  1033. }
  1034. }
  1035. }
  1036. //load OK
  1037. memcpy(pSysConfig, buf, sizeof(struct SysConfigData));
  1038. free(buf);
  1039. system("rm -f /mnt/EvseConfig.bin");
  1040. // SysConfig in flash is empty (0xffffffff)
  1041. if ((strlen((char *)pSysConfig->ModelName) > ARRAY_SIZE(pSysConfig->ModelName)) ||
  1042. (strlen((char *)pSysConfig->SerialNumber) > ARRAY_SIZE(pSysConfig->SerialNumber)) ||
  1043. (strlen((char *)pSysConfig->SystemId) > ARRAY_SIZE(pSysConfig->SystemId)) ||
  1044. (pSysConfig->Eth0Interface.EthDhcpClient == 0xff)) {
  1045. if (strlen((char *)pSysConfig->ModelName) > ARRAY_SIZE(pSysConfig->ModelName)) {
  1046. memset(pSysConfig->ModelName, 0x00, ARRAY_SIZE(pSysConfig->ModelName));
  1047. }
  1048. if (strlen((char *)pSysConfig->SerialNumber) > ARRAY_SIZE(pSysConfig->SerialNumber)) {
  1049. memset(pSysConfig->SerialNumber, 0x00, ARRAY_SIZE(pSysConfig->SerialNumber));
  1050. }
  1051. if (strlen((char *)pSysConfig->SystemId) > ARRAY_SIZE(pSysConfig->SystemId)) {
  1052. memset(pSysConfig->SystemId, 0x00, ARRAY_SIZE(pSysConfig->SystemId));
  1053. }
  1054. if (pSysConfig->Eth0Interface.EthDhcpClient == 0xff) {
  1055. log_info("Ethernet dhcp config is null.");
  1056. }
  1057. if (strlen((char *)pSysConfig->ModelName) == 0x00) {
  1058. log_info("Model name over length.");
  1059. }
  1060. if (strlen((char *)pSysConfig->SerialNumber) == 0x00) {
  1061. log_info("Model serial number over length.");
  1062. }
  1063. if (strlen((char *)pSysConfig->SystemId) == 0x00) {
  1064. log_info("SystemId over length.");
  1065. }
  1066. system("cd /root;./FactoryConfig -m");
  1067. sleep(3);
  1068. system("/usr/bin/run_evse_restart.sh");
  1069. }
  1070. log_info("Load SysConfigData OK");
  1071. return PASS;
  1072. }
  1073. int Initialization(void)
  1074. {
  1075. uint8_t count = 0;
  1076. uint8_t pinOut[2] = {116, 115};
  1077. // 初始化卡號驗證的 Flag
  1078. ClearAuthorizedFlag();
  1079. for (count = 0; count < pSysConfig->TotalConnectorCount; count++) {
  1080. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
  1081. // 初始化插槍驗證的 Flag
  1082. ClearDetectPluginFlag(count);
  1083. pDcChargingInfo->RemoteStartFlag = NO;
  1084. if (pDcChargingInfo->Type == _Type_Chademo) {
  1085. gpio_set_value(pinOut[count], 0x00);
  1086. ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = NO;
  1087. } else if (pDcChargingInfo->Type == _Type_GB) {
  1088. gpio_set_value(pinOut[count], 0x00);
  1089. ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = NO;
  1090. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1091. //if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) { //DS60-120 remove
  1092. if (pSysConfig->TotalConnectorCount == 1) {
  1093. gpio_set_value(pinOut[1], 0x01);
  1094. } else {
  1095. gpio_set_value(pinOut[count], 0x01);
  1096. }
  1097. ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = NO;
  1098. //}
  1099. }
  1100. strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
  1101. }
  1102. for (count = 0; count < pSysConfig->AcConnectorCount; count++) {
  1103. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(count);
  1104. pAcChargingInfo->RemoteStartFlag = NO;
  1105. if (pAcChargingInfo->Type == _Type_AC) {
  1106. pAcChargingInfo->SelfTest_Comp = NO;
  1107. strcpy((char *)ShmOCPP16Data->StatusNotification[count + pSysConfig->TotalConnectorCount].ErrorCode, "NoError");
  1108. }
  1109. }
  1110. return PASS;
  1111. }
  1112. bool InitialSystemDefaultConfig()
  1113. {
  1114. bool result = true;
  1115. LoadSysConfigAndInfo();
  1116. InitGPIO();
  1117. InitEthernet();
  1118. GetMacAddress();
  1119. // system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
  1120. // sleep(3);
  1121. // system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
  1122. // sleep(1);
  1123. // system("/sbin/ifconfig eth1 192.168.0.10 netmask 255.255.255.0 up");
  1124. return result;
  1125. }
  1126. //顯示自檢錯誤原因,觸發對應的flag
  1127. bool DisplaySelfTestFailReason()
  1128. {
  1129. bool result = false;
  1130. uint8_t index = 0;
  1131. // RB、FB、407、EV 小板中有些板子無回應
  1132. if (ShmRelayModuleData->SelfTest_Comp == NO) {
  1133. pAlarmCode->AlarmEvents.bits.RelayboardStestFail = true;
  1134. }
  1135. if (ShmFanModuleData->SelfTest_Comp == NO) {
  1136. pAlarmCode->AlarmEvents.bits.FanboardStestFail = true;
  1137. }
  1138. if (ShmPrimaryMcuData->SelfTest_Comp == NO) {
  1139. pAlarmCode->AlarmEvents.bits.PrimaryStestFail = true;
  1140. }
  1141. if (ShmLedModuleData->SelfTest_Comp == NO) {
  1142. pAlarmCode->AlarmEvents.bits.LedboardStestFail = true;
  1143. }
  1144. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  1145. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  1146. if (pDcChargingInfo->Type == _Type_Chademo) {
  1147. if (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
  1148. pAlarmCode->AlarmEvents.bits.ChademoboardStestFail = true;
  1149. }
  1150. } else if (pDcChargingInfo->Type == _Type_GB) {
  1151. if (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
  1152. pAlarmCode->AlarmEvents.bits.GbtboardStestFail = true;
  1153. }
  1154. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1155. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  1156. if (ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
  1157. pAlarmCode->AlarmEvents.bits.CCSboardStestFail = true;
  1158. }
  1159. }
  1160. }
  1161. }
  1162. for (index = 0; index < pSysConfig->AcConnectorCount; index++) {
  1163. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(index);
  1164. // 先借 GBT 顯示
  1165. if (pAcChargingInfo->SelfTest_Comp == NO) {
  1166. pAlarmCode->AlarmEvents.bits.AcConnectorStestFail = true;
  1167. }
  1168. }
  1169. if (pSysInfo->AcContactorStatus == NO) {
  1170. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1171. // AC Contact 未搭上
  1172. pAlarmCode->AlarmEvents.bits.AcContactStestFail = true;
  1173. result = true;
  1174. #endif // !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1175. } else if (ShmPsuData->SystemAvailablePower <= 0 &&
  1176. ShmPsuData->SystemAvailableCurrent <= 0) {
  1177. // PSU 通訊問題
  1178. pAlarmCode->AlarmEvents.bits.PsuModuleStestFail = true;
  1179. result = true;
  1180. }
  1181. return result;
  1182. }
  1183. #if 0 //not use
  1184. int StoreUsrConfigData(struct SysConfigData *UsrData)
  1185. {
  1186. int result = PASS;
  1187. int fd, wrd;
  1188. unsigned int i, Chk;
  1189. uint8_t *ptr, *BufTmp;
  1190. Chk = 0;
  1191. ptr = (uint8_t *)UsrData;
  1192. if ((BufTmp = malloc(MtdBlockSize)) != NULL) {
  1193. memset(BufTmp, 0, MtdBlockSize);
  1194. memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
  1195. for (i = 0; i < MtdBlockSize - 4; i++) {
  1196. Chk += *(ptr + i);
  1197. }
  1198. memcpy(BufTmp + MtdBlockSize - 4, &Chk, 4);
  1199. fd = open("/dev/mtdblock10", O_RDWR);
  1200. if (fd > 0) {
  1201. wrd = write(fd, BufTmp, MtdBlockSize);
  1202. close(fd);
  1203. if (wrd >= MtdBlockSize) {
  1204. fd = open("/dev/mtdblock11", O_RDWR);
  1205. if (fd > 0) {
  1206. wrd = write(fd, BufTmp, MtdBlockSize);
  1207. close(fd);
  1208. if (wrd < MtdBlockSize) {
  1209. log_error("write /dev/mtdblock11(backup) NG");
  1210. result = FAIL;
  1211. }
  1212. } else {
  1213. log_error("open /dev/mtdblock11(backup) NG");
  1214. result = FAIL;
  1215. }
  1216. } else {
  1217. log_error("write /dev/mtdblock10 NG");
  1218. result = FAIL;
  1219. }
  1220. } else {
  1221. log_error("open /dev/mtdblock10 NG");
  1222. result = FAIL;
  1223. }
  1224. } else {
  1225. log_error("alloc BlockSize NG");
  1226. result = FAIL;
  1227. }
  1228. if (BufTmp != NULL) {
  1229. free(BufTmp);
  1230. }
  1231. return result;
  1232. }
  1233. #endif //0
  1234. //===============================================
  1235. // Common Detect Chk - Stop Charging ?
  1236. //===============================================
  1237. int isEvBoardStopChargeFlag(uint8_t gunIndex)
  1238. {
  1239. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1240. //printf("StopChargeFlag = %d", chargingInfo[gunIndex]->StopChargeFlag);
  1241. return pDcChargingInfo->StopChargeFlag;
  1242. }
  1243. bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
  1244. {
  1245. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1246. return pDcChargingInfo->NormalStopChargeFlag;
  1247. }
  1248. //===============================================
  1249. // 掃描插槍狀況
  1250. //===============================================
  1251. void ClearDetectPluginFlag(int gunIndex)
  1252. {
  1253. if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
  1254. return;
  1255. ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
  1256. //DS60-120 add
  1257. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1258. if (pDcChargingInfo->RemoteStartFlag == YES) {
  1259. pDcChargingInfo->RemoteStartFlag = NO;
  1260. }
  1261. if (pSysInfo->OrderCharging != NO_DEFINE) {
  1262. pSysInfo->OrderCharging = NO_DEFINE;
  1263. }
  1264. }
  1265. void DetectPluginStart(int gunIndex)
  1266. {
  1267. //pSysInfo->WaitForPlugit = YES;
  1268. if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
  1269. return;
  1270. ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = YES;
  1271. log_info("Gun%d start detect plug in",gunIndex);
  1272. }
  1273. bool isDetectPlugin(int gunIndex)
  1274. {
  1275. if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
  1276. return false;
  1277. if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
  1278. return true;
  1279. }
  1280. /*
  1281. if (pSysInfo->WaitForPlugit == YES) {
  1282. return true;
  1283. }
  1284. */
  1285. return false;
  1286. }
  1287. //===============================================
  1288. // Common Detect Chk - Chademo
  1289. //===============================================
  1290. bool isEvGunLocked_chademo(uint8_t gunIndex)
  1291. {
  1292. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1293. return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
  1294. }
  1295. bool isEvContactorWelding_chademo(uint8_t gunIndex)
  1296. {
  1297. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1298. return DetectBitValue(ShmCHAdeMOData->ev[pDcChargingInfo->type_index].EvDetection, 3);
  1299. }
  1300. bool isEvStopReq_chademo(uint8_t gunIndex)
  1301. {
  1302. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1303. return DetectBitValue(ShmCHAdeMOData->ev[pDcChargingInfo->type_index].EvDetection, 4);
  1304. }
  1305. bool isEvStopCharging_chademo(uint8_t gunIndex)
  1306. {
  1307. if (isEvGunLocked_chademo(gunIndex) == NO) {
  1308. // 無鎖槍 = 停止
  1309. //log_info("gun locked none (%d) ", gunIndex);
  1310. return YES;
  1311. }
  1312. return NO;
  1313. }
  1314. uint8_t isPrechargeStatus_chademo(uint8_t gunIndex)
  1315. {
  1316. uint8_t result = 0x00;
  1317. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1318. result = ShmCHAdeMOData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus;
  1319. return result;
  1320. }
  1321. //===============================================
  1322. // Common Detect Chk - GB
  1323. //===============================================
  1324. bool isEvGunLocked_gb(uint8_t gunIndex)
  1325. {
  1326. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1327. return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
  1328. }
  1329. bool isEvStopCharging_gb(uint8_t gunIndex)
  1330. {
  1331. if (isEvGunLocked_gb(gunIndex) == NO) {
  1332. // 無鎖槍 = 停止
  1333. //log_info("gun locked none. ");
  1334. return YES;
  1335. }
  1336. return NO;
  1337. }
  1338. uint8_t isPrechargeStatus_gb(uint8_t gunIndex)
  1339. {
  1340. uint8_t result = 0x00;
  1341. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1342. result = ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus;
  1343. return result;
  1344. }
  1345. //===============================================
  1346. // Common Detect Chk - CCS
  1347. //===============================================
  1348. bool isEvGunLocked_ccs(uint8_t gunIndex)
  1349. {
  1350. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1351. return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
  1352. }
  1353. uint8_t isPrechargeStatus_ccs(uint8_t gunIndex)
  1354. {
  1355. uint8_t result = 0x00;
  1356. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1357. return ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;;
  1358. }
  1359. bool isEvStopCharging_ccs(uint8_t gunIndex)
  1360. {
  1361. if (isEvGunLocked_ccs(gunIndex) == NO) {
  1362. // 無鎖槍 = 停止
  1363. //log_info("gun locked none. ");
  1364. return YES;
  1365. }
  1366. return NO;
  1367. }
  1368. //===============================================
  1369. // Callback
  1370. //===============================================
  1371. void DisplayChargingInfo()
  1372. {
  1373. uint8_t i = 0;
  1374. log_info("*********** DisplayChargingInfo *********** ");
  1375. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1376. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1377. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  1378. pDcChargingInfo->SystemStatus != S_RESERVATION) {
  1379. ChangeGunSelectByIndex(i);
  1380. return;
  1381. }
  1382. }
  1383. if (pSysConfig->AcConnectorCount > 0 &&
  1384. pSysInfo->CurGunSelectedByAc == NO_DEFINE)
  1385. {
  1386. pAcChargingInfo = (struct ChargingInfoData*)GetAcChargingInfoData(0);
  1387. if (pAcChargingInfo->SystemStatus >= S_PREPARNING &&
  1388. pAcChargingInfo->SystemStatus <= S_COMPLETE)
  1389. {
  1390. pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
  1391. }
  1392. }
  1393. usleep(50000);
  1394. systemPageRestoreInit();
  1395. }
  1396. void _AutoReturnTimeout(int gunIndex)
  1397. {
  1398. log_info("*********** _AutoReturnTimeout(%d) *********** ", pSysInfo->PageIndex);
  1399. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
  1400. if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
  1401. if (pDcChargingInfo->RemoteStartFlag) {
  1402. ClearDetectPluginFlag(gunIndex);
  1403. } else {
  1404. ClearDetectPluginFlag(0);
  1405. ClearDetectPluginFlag(1);
  1406. }
  1407. } else if (pSysInfo->PageIndex == _LCM_AUTHORIZ_COMP) {
  1408. if (pDcChargingInfo->RemoteStartFlag) {
  1409. DetectPluginStart(gunIndex);
  1410. } else {
  1411. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(LEFT_GUN_NUM);
  1412. if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
  1413. DetectPluginStart(LEFT_GUN_NUM);
  1414. if (pSysConfig->TotalConnectorCount > 1) {
  1415. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
  1416. if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
  1417. DetectPluginStart(RIGHT_GUN_NUM);
  1418. }
  1419. }
  1420. }
  1421. usleep(50000);
  1422. systemPageRestoreInit();
  1423. }
  1424. void _SelfTestTimeout(void)
  1425. {
  1426. if (pSysInfo->BootingStatus != BOOT_COMPLETE) {
  1427. for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  1428. setChargerMode(gunIndex, MODE_ALARM);
  1429. }
  1430. }
  1431. ShmPsuData->Work_Step = _NO_WORKING;
  1432. pSysInfo->SelfTestSeq = _STEST_FAIL;
  1433. log_info("Self test timeout. ");
  1434. sleep(3);
  1435. system("/usr/bin/run_evse_restart.sh");
  1436. }
  1437. void _AuthorizedTimeout(void)
  1438. {
  1439. if (IsAuthorizingMode()) {
  1440. log_info("*********** _AuthorizedTimeout *********** ");
  1441. //isCardScan = false;
  1442. SetIsCardScan(false);
  1443. pSysInfo->SystemPage = _LCM_AUTHORIZ_FAIL;
  1444. //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
  1445. strcpy((char *)pSysConfig->UserId, "");
  1446. ClearAuthorizedFlag();
  1447. }
  1448. }
  1449. void _DetectPlugInTimeout(int gunIndex)
  1450. {
  1451. strcpy((char *)pSysConfig->UserId, "");
  1452. uint8_t is_remote = NO;
  1453. for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1454. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
  1455. if (pDcChargingInfo->RemoteStartFlag) {
  1456. //此停止為remote start停止
  1457. is_remote = YES;
  1458. break;
  1459. }
  1460. }
  1461. if (is_remote) {
  1462. // Remote start進入充電
  1463. log_info("Clear Gun%d Remote start detect plugin flag",gunIndex);
  1464. StopGunInfoTimeoutDet(gunIndex);
  1465. ClearDetectPluginFlag(gunIndex);
  1466. } else {
  1467. log_info("Clear Gun%d RFID detect plugin flag", gunIndex);
  1468. // 刷卡進入充電
  1469. ClearDetectPluginFlag(LEFT_GUN_NUM);
  1470. ClearDetectPluginFlag(RIGHT_GUN_NUM);
  1471. StopGunInfoTimeoutDet(LEFT_GUN_NUM);
  1472. StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
  1473. }
  1474. sleep(1); //等待DoComm回報插槍訊號給主櫃
  1475. #if defined DD360Audi
  1476. //pSysInfo->SystemPage = _LCM_COMPLETE;
  1477. setChargerMode(gunIndex, S_TERMINATING);
  1478. #elif DD360 || DD360Combox
  1479. setChargerMode(gunIndex, S_IDLE);
  1480. #endif
  1481. systemPageRestoreInit();
  1482. }
  1483. void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
  1484. {
  1485. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1486. if (pDcChargingInfo->Type == _Type_Chademo) {
  1487. if (!isEvGunLocked_chademo(gunIndex)) {
  1488. log_info("*********** _DetectEvChargingEnableTimeout (chademo) ***********");
  1489. }
  1490. } else if (pDcChargingInfo->Type == _Type_GB) {
  1491. if (!isEvGunLocked_ccs(gunIndex)) {
  1492. log_info("*********** _DetectEvChargingEnableTimeout (gb) ***********");
  1493. }
  1494. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1495. if (!isEvGunLocked_ccs(gunIndex)) {
  1496. log_info("*********** _DetectEvChargingEnableTimeout (ccs) ***********");
  1497. }
  1498. }
  1499. ChargingTerminalProcess(gunIndex);
  1500. _AutoReturnTimeout(gunIndex);
  1501. }
  1502. void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
  1503. {
  1504. log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********");
  1505. //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
  1506. {
  1507. #if defined DD360Audi
  1508. //pSysInfo->SystemPage = _LCM_COMPLETE;
  1509. setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
  1510. #elif DD360 || DD360Combox
  1511. setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
  1512. #endif
  1513. _AutoReturnTimeout(gunIndex);
  1514. }
  1515. }
  1516. void _PrepareTimeout(uint8_t gunIndex)
  1517. {
  1518. log_info("*********** _PrepareTimeout ***********");
  1519. #if defined DD360Audi
  1520. //pSysInfo->SystemPage = _LCM_COMPLETE;
  1521. setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
  1522. #elif DD360 || DD360Combox
  1523. setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
  1524. #endif
  1525. pAlarmCode->AlarmEvents.bits.PsuNoResource = YES;
  1526. _AutoReturnTimeout(gunIndex);
  1527. }
  1528. void _CcsPrechargeTimeout(uint8_t gunIndex)
  1529. {
  1530. log_info("*********** _CcsPrechargeTimeout ***********");
  1531. #if defined DD360Audi
  1532. //pSysInfo->SystemPage = _LCM_COMPLETE;
  1533. setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
  1534. #elif DD360 || DD360Combox
  1535. setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
  1536. pSysInfo->SystemPage = _LCM_COMPLETE;
  1537. return;
  1538. #endif
  1539. }
  1540. //===============================================
  1541. // 取得卡號與卡號驗證
  1542. //===============================================
  1543. void AuthorizingStart(void)
  1544. {
  1545. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
  1546. pSysInfo->AuthorizeFlag = YES;
  1547. }
  1548. void ClearAuthorizedFlag(void)
  1549. {
  1550. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
  1551. pSysInfo->AuthorizeFlag = NO;
  1552. }
  1553. bool isAuthorizedComplete(void)
  1554. {
  1555. if (pSysInfo->AuthorizeFlag == YES) {
  1556. return false;
  1557. }
  1558. return true;
  1559. }
  1560. bool IsAuthorizingMode()
  1561. {
  1562. if (pSysInfo->AuthorizeFlag == NO) {
  1563. return false;
  1564. }
  1565. return true;
  1566. }
  1567. //===============================================
  1568. // 紀錄 Alarm Code
  1569. //===============================================
  1570. void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
  1571. {
  1572. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1573. if (strcmp(code, "012234") == EQUAL) {
  1574. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  1575. } else if (strcmp(code, "012235") == EQUAL) {
  1576. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  1577. } else if (strcmp(code, "012236") == EQUAL) {
  1578. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  1579. } else if (strcmp(code, "012288") == EQUAL) {
  1580. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
  1581. } else if (strcmp(code, "012289") == EQUAL) {
  1582. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
  1583. } else if (strcmp(code, "012290") == EQUAL) {
  1584. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
  1585. } else if (strcmp(code, "012229") == EQUAL) {
  1586. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  1587. } else if (strcmp(code, "012230") == EQUAL) {
  1588. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
  1589. } else if (strcmp(code, "012231") == EQUAL) {
  1590. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
  1591. } else if (strcmp(code, "011011") == EQUAL) {
  1592. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
  1593. } else if (strcmp(code, "011013") == EQUAL) {
  1594. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
  1595. } else if (strcmp(code, "011015") == EQUAL) {
  1596. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
  1597. } else if (strcmp(code, "011012") == EQUAL) {
  1598. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
  1599. } else if (strcmp(code, "011014") == EQUAL) {
  1600. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
  1601. } else if (strcmp(code, "011016") == EQUAL) {
  1602. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
  1603. } else if (strcmp(code, "011018") == EQUAL) {
  1604. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  1605. } else if (strcmp(code, "011019") == EQUAL) {
  1606. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO;
  1607. } else if (strcmp(code, "011020") == EQUAL) {
  1608. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO;
  1609. } else if (strcmp(code, "012323") == EQUAL) {
  1610. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  1611. } else if (strcmp(code, "011038") == EQUAL) {
  1612. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  1613. }
  1614. //if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) != EQUAL) {
  1615. // if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip == NO &&
  1616. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip == NO &&
  1617. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip == NO &&
  1618. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail == NO &&
  1619. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail == NO &&
  1620. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail == NO &&
  1621. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP == NO &&
  1622. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP == NO &&
  1623. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP == NO &&
  1624. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault == NO &&
  1625. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault == NO &&
  1626. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault == NO &&
  1627. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault == NO &&
  1628. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault == NO &&
  1629. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault == NO &&
  1630. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail == NO &&
  1631. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail == NO &&
  1632. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail == NO &&
  1633. // ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP == NO &&
  1634. // ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail == NO
  1635. // ) {
  1636. // strncpy((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1637. // }
  1638. //}
  1639. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012229", 6) == EQUAL ||
  1640. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012230", 6) == EQUAL ||
  1641. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012231", 6) == EQUAL ||
  1642. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011011", 6) == EQUAL ||
  1643. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011013", 6) == EQUAL ||
  1644. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011015", 6) == EQUAL ||
  1645. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011012", 6) == EQUAL ||
  1646. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011014", 6) == EQUAL ||
  1647. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011016", 6) == EQUAL ||
  1648. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011018", 6) == EQUAL ||
  1649. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011019", 6) == EQUAL ||
  1650. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011020", 6) == EQUAL ||
  1651. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012323", 6) == EQUAL ||
  1652. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011038", 6) == EQUAL) {
  1653. strncpy((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1654. }
  1655. }
  1656. void RecordAlarmCode(uint8_t gunIndex, char *code)
  1657. {
  1658. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1659. if((pDcChargingInfo->SystemStatus > S_IDLE && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  1660. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
  1661. {
  1662. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1663. memcpy(pDcChargingInfo->ConnectorAlarmCode, code, 6);
  1664. }
  1665. if (pDcChargingInfo->StopChargeFlag == NO)
  1666. {
  1667. pDcChargingInfo->StopChargeFlag = YES;
  1668. }
  1669. }
  1670. #if 0
  1671. if (strcmp(code, "012234") == EQUAL) {
  1672. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES;
  1673. } else if (strcmp(code, "012235") == EQUAL) {
  1674. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
  1675. } else if (strcmp(code, "012236") == EQUAL) {
  1676. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES;
  1677. } else if (strcmp(code, "012288") == EQUAL) {
  1678. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = YES;
  1679. } else if (strcmp(code, "012289") == EQUAL) {
  1680. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = YES;
  1681. } else if (strcmp(code, "012290") == EQUAL) {
  1682. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = YES;
  1683. } else if (strcmp(code, "012229") == EQUAL) {
  1684. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES;
  1685. } else if (strcmp(code, "012230") == EQUAL) {
  1686. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES;
  1687. } else if (strcmp(code, "012231") == EQUAL) {
  1688. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES;
  1689. } else if (strcmp(code, "012296") == EQUAL) {
  1690. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES;
  1691. } else if (strcmp(code, "012297") == EQUAL) {
  1692. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES;
  1693. } else if (strcmp(code, "012298") == EQUAL) {
  1694. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES;
  1695. } else if (strcmp(code, "011011") == EQUAL) {
  1696. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES;
  1697. } else if (strcmp(code, "011013") == EQUAL) {
  1698. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES;
  1699. } else if (strcmp(code, "011015") == EQUAL) {
  1700. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES;
  1701. } else if (strcmp(code, "011012") == EQUAL) {
  1702. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES;
  1703. } else if (strcmp(code, "011014") == EQUAL) {
  1704. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES;
  1705. } else if (strcmp(code, "011016") == EQUAL) {
  1706. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES;
  1707. } else if (strcmp(code, "011018") == EQUAL) {
  1708. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES;
  1709. } else if (strcmp(code, "011019") == EQUAL) {
  1710. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES;
  1711. } else if (strcmp(code, "011020") == EQUAL) {
  1712. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES;
  1713. } else if (strcmp(code, "012323") == EQUAL) {
  1714. if ((gunIndex == 0) &&
  1715. ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
  1716. (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
  1717. ) {
  1718. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
  1719. } else if ((gunIndex == 1) &&
  1720. ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
  1721. (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
  1722. ) {
  1723. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
  1724. }
  1725. } else if (strcmp(code, "011038") == EQUAL) {
  1726. if ((gunIndex == 0) &&
  1727. ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
  1728. (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
  1729. ) {
  1730. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  1731. } else if ((gunIndex == 1) &&
  1732. ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
  1733. (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
  1734. ) {
  1735. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  1736. }
  1737. }
  1738. #endif
  1739. }
  1740. void ReleaseAlarmCode(uint8_t gunIndex)
  1741. {
  1742. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1743. //if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1744. // return;
  1745. //}
  1746. #if 0
  1747. // 回 idle 後主要清除 GFD Trip、UVP、OVP、GFD Warning
  1748. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012251", 6) == EQUAL ||
  1749. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012252", 6) == EQUAL) {
  1750. memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1751. }
  1752. #endif
  1753. switch (pDcChargingInfo->Type) {
  1754. case _Type_Chademo:
  1755. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  1756. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
  1757. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
  1758. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
  1759. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
  1760. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
  1761. #if 0
  1762. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012234", 6) == EQUAL ||
  1763. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012289", 6) == EQUAL ||
  1764. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012217", 6) == EQUAL ||
  1765. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012296", 6) == EQUAL) {
  1766. memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1767. }
  1768. #endif
  1769. break;
  1770. case _Type_CCS_2:
  1771. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  1772. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
  1773. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
  1774. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
  1775. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
  1776. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
  1777. #if 0
  1778. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012235", 6) == EQUAL ||
  1779. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012288", 6) == EQUAL ||
  1780. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012219", 6) == EQUAL ||
  1781. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012297", 6) == EQUAL) {
  1782. memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1783. }
  1784. #endif
  1785. break;
  1786. case _Type_GB:
  1787. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  1788. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
  1789. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
  1790. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
  1791. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
  1792. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
  1793. #if 0
  1794. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012236", 6) == EQUAL ||
  1795. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012290", 6) == EQUAL ||
  1796. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012221", 6) == EQUAL ||
  1797. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012298", 6) == EQUAL) {
  1798. memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1799. }
  1800. #endif
  1801. break;
  1802. }
  1803. #if 0
  1804. //system alarm
  1805. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012251", 6) == EQUAL ||
  1806. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012252", 6) == EQUAL ||
  1807. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012238", 6) == EQUAL ||
  1808. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012304", 6) == EQUAL ||
  1809. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012323", 6) == EQUAL ||
  1810. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011038", 6) == EQUAL
  1811. ) {
  1812. memset(pDcChargingInfo->ConnectorAlarmCode, 0, sizeof(pDcChargingInfo->ConnectorAlarmCode));
  1813. }
  1814. #endif
  1815. memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1816. }
  1817. //===============================================
  1818. // EmergencyStop and Charging Stop
  1819. //===============================================
  1820. void ChargingTerminalProcess(uint8_t gunIndex)
  1821. {
  1822. setChargerMode(gunIndex, MODE_TERMINATING);
  1823. }
  1824. void ChargingAlarmProcess(uint8_t gunIndex)
  1825. {
  1826. UpdateErrorCodeToOcpp(gunIndex);
  1827. setChargerMode(gunIndex, MODE_ALARM);
  1828. }
  1829. void AcChargingTerminalProcess(void)
  1830. {
  1831. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  1832. pAcChargingInfo->SystemStatus = MODE_TERMINATING;
  1833. }
  1834. void StopChargingProcessByString(uint8_t level)
  1835. {
  1836. if (level > pSysWarning->Level) {
  1837. pSysWarning->Level = level;
  1838. }
  1839. }
  1840. void ReleaseChargingProcessByString(uint8_t level)
  1841. {
  1842. if (level >= pSysWarning->Level) {
  1843. pSysWarning->Level = WARN_LV_NL;
  1844. }
  1845. }
  1846. // 一般錯誤停止充電處理函式
  1847. void BoardErrOccurByString(uint8_t index, char *code)
  1848. {
  1849. uint8_t level = 1;
  1850. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  1851. if ((pDcChargingInfo->SystemStatus > S_IDLE &&
  1852. pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  1853. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1854. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1855. if (strncmp(code, "023730", 6) == EQUAL &&
  1856. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop == NO
  1857. ) {
  1858. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
  1859. }
  1860. ChargingTerminalProcess(index);
  1861. }
  1862. StopChargingProcessByString(level);
  1863. }
  1864. void ReleaseBoardErrOccurByString(uint8_t index, char *code)
  1865. {
  1866. bool isTrigger = false;
  1867. uint8_t level = 1;
  1868. if (strncmp(code, "023730", 6) == 0 &&
  1869. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
  1870. isTrigger = true;
  1871. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
  1872. }
  1873. if (isTrigger) {
  1874. ReleaseChargingProcessByString(level);
  1875. }
  1876. }
  1877. // 急停狀況的停止充電處理函式
  1878. void EmcOccureByString(char *code)
  1879. {
  1880. uint8_t level = 2;
  1881. // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
  1882. // 其錯誤等級為 2
  1883. #if defined DD360 ||defined DD360Audi || defined DD360ComBox
  1884. //DS60-120 remove
  1885. if (strncmp(code, "012251", 6) == EQUAL ||
  1886. strncmp(code, "012252", 6) == EQUAL ||
  1887. strncmp(code, "012238", 6) == EQUAL ||
  1888. strncmp(code, "042251", 6) == EQUAL ||
  1889. strncmp(code, "042252", 6) == EQUAL ||
  1890. strncmp(code, "012304", 6) == EQUAL ||
  1891. strncmp(code, "042200", 6) == EQUAL ||
  1892. strncmp(code, "042201", 6) == EQUAL ||
  1893. strncmp(code, "042202", 6) == EQUAL ||
  1894. strncmp(code, "042267", 6) == EQUAL)
  1895. #endif //defined DD360 || defined DD360Audi
  1896. {
  1897. for (uint8_t gun = 0; gun < pSysConfig->TotalConnectorCount; gun++) {
  1898. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
  1899. //strncpy((char *)ShmOCPP16Data->StatusNotification[gun].VendorErrorCode, code, 6);
  1900. if ((pDcChargingInfo->SystemStatus > S_IDLE &&
  1901. pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  1902. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1903. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1904. //ChargingTerminalProcess(gun);
  1905. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1906. memcpy(pDcChargingInfo->ConnectorAlarmCode, code, 6);
  1907. }
  1908. ChargingAlarmProcess(gun);
  1909. }
  1910. }
  1911. #if defined DD360 ||defined DD360Audi || defined DD360ComBox
  1912. StopChargingProcessByString(level);
  1913. InformOcppErrOccur(4);
  1914. #endif //defined DD360 || defined DD360Audi
  1915. }
  1916. }
  1917. void ReleaseEmsOccureByString(uint8_t index, char *code)
  1918. {
  1919. bool isTrigger = false;
  1920. uint8_t level = 2;
  1921. if (strncmp(code, "042251", 6) == 0 ) {
  1922. isTrigger = true;
  1923. } else if (strncmp(code, "012251", 6) == 0 &&
  1924. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
  1925. isTrigger = true;
  1926. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = NO;
  1927. } else if (strncmp(code, "012252", 6) == 0 &&
  1928. pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
  1929. isTrigger = true;
  1930. pAlarmCode->AlarmEvents.bits.DoorOpen = NO;
  1931. } else if (strncmp(code, "012237", 6) == 0 &&
  1932. pAlarmCode->AlarmEvents.bits.SpdTrip == YES) {
  1933. isTrigger = true;
  1934. pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
  1935. } else if (strncmp(code, "012238", 6) == 0 &&
  1936. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
  1937. isTrigger = true;
  1938. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = NO;
  1939. } else if (strncmp(code, "012348", 6) == 0 &&
  1940. pAlarmCode->AlarmEvents.bits.ChillerAlarmFail == YES) {
  1941. isTrigger = true;
  1942. pAlarmCode->AlarmEvents.bits.ChillerAlarmFail = NO;
  1943. }
  1944. if (isTrigger) {
  1945. ReleaseChargingProcessByString(level);
  1946. InformOcppErrOccur(6);
  1947. }
  1948. }
  1949. static void checkOvpState(uint8_t gunIndex, uint8_t gunType)
  1950. {
  1951. switch(gunType)
  1952. {
  1953. case _Type_Chademo:
  1954. if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP == YES)
  1955. {
  1956. RecordAlarmCode(gunIndex, "012217");
  1957. }
  1958. break;
  1959. case _Type_CCS_2:
  1960. if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP == YES)
  1961. {
  1962. RecordAlarmCode(gunIndex, "012219");
  1963. }
  1964. break;
  1965. case _Type_GB:
  1966. if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP == YES)
  1967. {
  1968. RecordAlarmCode(gunIndex, "012221");
  1969. }
  1970. break;
  1971. }
  1972. }
  1973. //===============================================
  1974. // 確認各小板偵測的錯誤狀況
  1975. //===============================================
  1976. void CheckErrorOccurStatus(uint8_t index)
  1977. {
  1978. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  1979. // RB
  1980. if (pSysConfig->PhaseLossPolicy == YES) {
  1981. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == YES ||
  1982. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == YES ||
  1983. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == YES) {
  1984. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
  1985. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
  1986. StopChargingProcessByString(2);
  1987. InformOcppErrOccur(13);
  1988. }
  1989. //DS60-120 add -----
  1990. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1991. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == YES) {
  1992. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012203", 6);
  1993. } else if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == YES) {
  1994. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012204", 6);
  1995. } else if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == YES) {
  1996. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012205", 6);
  1997. }
  1998. }
  1999. //log_info("1 CheckErrorOccurStatus");
  2000. pDcChargingInfo->StopChargeFlag = YES;
  2001. //------------------------------------------------------------------
  2002. } else {
  2003. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
  2004. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  2005. ReleaseChargingProcessByString(2);
  2006. InformOcppErrOccur(6);
  2007. }
  2008. }
  2009. } else {
  2010. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
  2011. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  2012. ReleaseChargingProcessByString(2);
  2013. InformOcppErrOccur(6);
  2014. }
  2015. }
  2016. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES ||
  2017. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES ||
  2018. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == YES) {
  2019. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
  2020. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
  2021. StopChargingProcessByString(2);
  2022. InformOcppErrOccur(14);
  2023. }
  2024. //DS60-120 -----
  2025. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  2026. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES) {
  2027. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012200", 6);
  2028. } else if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES) {
  2029. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012201", 6);
  2030. } else if (pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == YES) {
  2031. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012202", 6);
  2032. }
  2033. }
  2034. //log_info("2 CheckErrorOccurStatus");
  2035. pDcChargingInfo->StopChargeFlag = YES;
  2036. //----------------------------------------------------------------------
  2037. } else {
  2038. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP) {
  2039. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  2040. ReleaseChargingProcessByString(2);
  2041. InformOcppErrOccur(6);
  2042. }
  2043. }
  2044. checkOvpState(index, pDcChargingInfo->Type);
  2045. //--------------------------------------------------------------------------
  2046. if (strlen((char *)pDcChargingInfo->ConnectorAlarmCode) == 0) {
  2047. //Primary
  2048. if (pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
  2049. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012251", 6);
  2050. } else if (pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
  2051. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012252", 6);
  2052. } else if (pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
  2053. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012238", 6);
  2054. } else if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES) {
  2055. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012304", 6);
  2056. }
  2057. //Chiller temperature
  2058. //else if (pAlarmCode->AlarmEvents.bits.SystemChillerOTP == YES) {
  2059. // memcpy(pDcChargingInfo->ConnectorAlarmCode, "012323", 6);
  2060. //} else if (pFaultCode->FaultEvents.bits.ChillerTempSensorBroken == YES) {
  2061. // memcpy(pDcChargingInfo->ConnectorAlarmCode, "011038", 6);
  2062. //}
  2063. }
  2064. }
  2065. //===============================================
  2066. // 確認 GPIO 狀態
  2067. //===============================================
  2068. void gpio_set_value(unsigned int gpio, unsigned int value)
  2069. {
  2070. int fd;
  2071. char buf[MAX_BUF];
  2072. snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
  2073. fd = open(buf, O_WRONLY);
  2074. if (fd < 0) {
  2075. perror("gpio/set-value");
  2076. return;
  2077. }
  2078. if (value) {
  2079. write(fd, "1", 2);
  2080. } else {
  2081. write(fd, "0", 2);
  2082. }
  2083. close(fd);
  2084. }
  2085. int gpio_get_value(unsigned int gpio, unsigned int *value)
  2086. {
  2087. int fd;
  2088. char buf[MAX_BUF];
  2089. char ch;
  2090. snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
  2091. fd = open(buf, O_RDONLY);
  2092. if (fd < 0) {
  2093. perror("gpio/get-value");
  2094. return fd;
  2095. }
  2096. read(fd, &ch, 1);
  2097. if (ch != '0') {
  2098. *value = 1;
  2099. } else {
  2100. *value = 0;
  2101. }
  2102. close(fd);
  2103. return 0;
  2104. }
  2105. void CheckGunTypeFromHw()
  2106. {
  2107. uint8_t i = 0;
  2108. int pinIn[4] = {22, 23, 44, 45};
  2109. unsigned int gpioValue = 0;
  2110. uint8_t tmp[2] = {0};
  2111. log_info("ModelName = %s", pSysConfig->ModelName);
  2112. for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
  2113. gpio_get_value(pinIn[i], &gpioValue);
  2114. switch (pinIn[i]) {
  2115. //right slot
  2116. case 22:
  2117. bd1_1_status = gpioValue;
  2118. break;
  2119. case 23:
  2120. bd1_2_status = gpioValue;
  2121. break;
  2122. //left slot
  2123. case 44:
  2124. bd0_1_status = gpioValue;
  2125. break;
  2126. case 45:
  2127. bd0_2_status = gpioValue;
  2128. break;
  2129. }
  2130. }
  2131. //BD1(Left-CCS-CND1-SMR2-左槍), BD2(Right-CHADEMO-CND2-SMR1-右槍), CCS: 10 , CHAdeMO: 01 , GBT: 11
  2132. //CcsChargingData [0至1] 分別為 Right至Left
  2133. //model name 槍順序左至右分別為Right至Left
  2134. tmp[1] = (bd0_1_status << 4 | bd0_2_status);
  2135. tmp[0] = (bd1_1_status << 4 | bd1_2_status);
  2136. for (i = 0; i < 2; i++) {
  2137. switch (tmp[i]) {
  2138. case 0x01:
  2139. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CHAdeMO");
  2140. break;
  2141. case 0x10:
  2142. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CCS");
  2143. break;
  2144. case 0x11:
  2145. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "GBT");
  2146. break;
  2147. case 0x00:
  2148. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "None");
  2149. break;
  2150. }
  2151. }
  2152. }
  2153. void CheckGpioInStatus()
  2154. {
  2155. int i = 0;
  2156. int pinIn[2] = { 27, 47 };//{IO BD1_2, IO BD2_2}
  2157. unsigned int gpioValue = 0;
  2158. for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
  2159. gpio_get_value(pinIn[i], &gpioValue);
  2160. if (gpioValue == 0x01) {
  2161. switch (pinIn[i]) {
  2162. // 小板緊急停止
  2163. case 47:
  2164. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  2165. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  2166. if (pDcChargingInfo->slotsIndex == 1) {
  2167. if (pDcChargingInfo->Type == _Type_Chademo) {
  2168. BoardErrOccurByString(i, "023730");
  2169. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  2170. BoardErrOccurByString(i, "013627");
  2171. }
  2172. break;
  2173. }
  2174. }
  2175. break;
  2176. case 27:
  2177. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  2178. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  2179. if (pDcChargingInfo->slotsIndex == 3) {
  2180. if (pDcChargingInfo->Type == _Type_Chademo) {
  2181. BoardErrOccurByString(i, "023730");
  2182. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  2183. BoardErrOccurByString(i, "013627");
  2184. }
  2185. break;
  2186. }
  2187. }
  2188. break;
  2189. }
  2190. } else {
  2191. switch (pinIn[i]) {
  2192. // 小板解除緊急停止
  2193. case 47:
  2194. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  2195. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  2196. if (pDcChargingInfo->slotsIndex == 1) {
  2197. if (pDcChargingInfo->Type == _Type_Chademo) {
  2198. ReleaseBoardErrOccurByString(i, "023730");
  2199. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  2200. ReleaseBoardErrOccurByString(i, "013627");
  2201. }
  2202. break;
  2203. }
  2204. }
  2205. break;
  2206. case 27:
  2207. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  2208. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  2209. if (pDcChargingInfo->slotsIndex == 3) {
  2210. if (pDcChargingInfo->Type == _Type_Chademo) {
  2211. ReleaseBoardErrOccurByString(i, "023730");
  2212. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  2213. ReleaseBoardErrOccurByString(i, "013627");
  2214. }
  2215. break;
  2216. }
  2217. }
  2218. break;
  2219. }
  2220. }
  2221. }
  2222. }
  2223. //===============================================
  2224. // Main process
  2225. //===============================================
  2226. // 檢查 uint8_t 中某個 Bit 的值
  2227. // _byte : 欲改變的 byte
  2228. // _bit : 該 byte 的第幾個 bit
  2229. uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit)
  2230. {
  2231. uint8_t mask_table[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
  2232. return ( _byte & mask_table[_bit] ) != 0x00;
  2233. }
  2234. // 設定 Byte 中某個 Bit的值
  2235. // _byte : 欲改變的 byte
  2236. // _bit : 該 byte 的第幾個 bit
  2237. // value : 修改的值為 0 or 1
  2238. void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value)
  2239. {
  2240. if (value == 1) {
  2241. *_byte |= (1 << _bit);
  2242. } else if (value == 0) {
  2243. *_byte ^= (1 << _bit);
  2244. }
  2245. }
  2246. uint8_t isModeChange(uint8_t gunIndex)
  2247. {
  2248. uint8_t result = NO;
  2249. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2250. if (pDcChargingInfo->SystemStatus == pDcChargingInfo->PreviousSystemStatus) {
  2251. return result;
  2252. }
  2253. pDcChargingInfo->PreviousSystemStatus = pDcChargingInfo->SystemStatus;
  2254. ShmDcCommonData->SystemModeChange[gunIndex] = YES; //for Module_EvRxComm print temperature message
  2255. return YES;
  2256. }
  2257. static int checkSlotGpioMappingGunType(uint8_t gunIndex, uint8_t gunType)
  2258. {
  2259. uint8_t slot1 = 0, slot2 = 0;
  2260. if (gunIndex == 0) {
  2261. slot1 = bd0_1_status;
  2262. slot2 = bd0_2_status;
  2263. } else if (gunIndex == 1) {
  2264. slot1 = bd1_1_status;
  2265. slot2 = bd1_2_status;
  2266. }
  2267. log_info("slot %d gpio1 = %d, gpio2 = %d, type = %d",
  2268. gunIndex,
  2269. slot1,
  2270. slot2,
  2271. gunType);
  2272. switch (gunType) {
  2273. case _Type_Chademo:
  2274. if (slot1 != NO && slot2 != YES) {
  2275. return FAIL;
  2276. }
  2277. break;
  2278. case _Type_CCS_2:
  2279. if (slot1 != YES && slot2 != NO) {
  2280. return FAIL;
  2281. }
  2282. break;
  2283. case _Type_GB:
  2284. if (slot1 != YES && slot2 != YES) {
  2285. return FAIL;
  2286. }
  2287. break;
  2288. }
  2289. return PASS;
  2290. }
  2291. bool CheckConnectorTypeStatus(void)
  2292. {
  2293. bool result = true;
  2294. uint8_t gunIndex = 0;
  2295. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  2296. struct ChargingInfoData *pDcChargingInfo = NULL;
  2297. if (!MappingGunChargingInfo("CSU Task")) {
  2298. log_error("CheckConnectorTypeStatus MappingGunChargingInfo failed");
  2299. return false;
  2300. }
  2301. // 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
  2302. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  2303. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2304. if (checkSlotGpioMappingGunType(gunIndex, pDcChargingInfo->Type) == FAIL) {
  2305. return false;
  2306. }
  2307. pDcChargingInfo->SystemStatus = S_BOOTING;
  2308. switch (gunIndex) {
  2309. case 0:
  2310. if (pSysConfig->TotalConnectorCount == 1) {
  2311. if ((bd0_1_status == YES || bd0_2_status == YES) &&
  2312. (bd1_1_status == NO && bd1_2_status == NO)) {
  2313. pDcChargingInfo->Evboard_id = 0x01;
  2314. }
  2315. if ((bd0_1_status == NO && bd0_2_status == NO) &&
  2316. (bd1_1_status == YES || bd1_2_status == YES)
  2317. ) {
  2318. pDcChargingInfo->Evboard_id = 0x02;
  2319. }
  2320. break;
  2321. }
  2322. pDcChargingInfo->Evboard_id = 0x01;
  2323. break;
  2324. case 1:
  2325. pDcChargingInfo->Evboard_id = 0x02;
  2326. break;
  2327. }
  2328. CheckHwSlotStatusLog(gunIndex);
  2329. if (pDcChargingInfo->Evboard_id == 0x00) {
  2330. return false;
  2331. }
  2332. }
  2333. AdjustChargerCurrent();
  2334. return result;
  2335. }
  2336. int SpawnTask(void)
  2337. {
  2338. if(SIMULATION)
  2339. system("/root/simulation &");
  2340. sleep(2);
  2341. system("/root/Module_EventLogging &");
  2342. system("/root/Module_PrimaryComm &");
  2343. system("/root/Module_EvComm &");
  2344. system("/root/Module_LcmControl &");
  2345. system("/root/Module_InternalComm &");
  2346. system("/root/Module_ProduceUtils &");
  2347. system("/root/Module_UpdateFW &");
  2348. if (pSysConfig->ModelName[3] == 'P')
  2349. system("/root/Module_DcMeter &");
  2350. system("/root/Module_DoComm &");
  2351. return PASS;
  2352. }
  2353. void KillTask(void)
  2354. {
  2355. ChangeLcmByIndex(_LCM_FIX);
  2356. system("killall Module_EventLogging");
  2357. system("killall Module_PrimaryComm");
  2358. system("killall Module_EvComm");
  2359. system("killall Module_LcmControl");
  2360. system("killall Module_InternalComm");
  2361. system("killall Module_UpdateFW");
  2362. system("killall Module_ChkSysTask");
  2363. if (pSysConfig->ModelName[3] == 'P')
  2364. system("killall Module_DcMeter");
  2365. //system("killall Module_DoComm");
  2366. return ;
  2367. }
  2368. void KillTaskExceptPrimary(void)
  2369. {
  2370. ChangeLcmByIndex(_LCM_FIX);
  2371. system("killall Module_EvComm");
  2372. system("killall Module_InternalComm");
  2373. if (pSysConfig->ModelName[3] == 'P')
  2374. system("killall Module_DcMeter");
  2375. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  2376. return;
  2377. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  2378. system("killall Module_PsuComm");
  2379. system("killall Module_4g &");
  2380. system("killall Module_Wifi &");
  2381. }
  2382. void KillAllTask(void)
  2383. {
  2384. ChangeLcmByIndex(_LCM_FIX);
  2385. system("killall Module_EventLogging");
  2386. system("killall Module_PrimaryComm");
  2387. system("killall Module_EvComm");
  2388. system("killall Module_LcmControl");
  2389. system("killall Module_InternalComm");
  2390. system("killall Module_UpdateFW");
  2391. system("killall Module_ChkSysTask");
  2392. if (pSysConfig->ModelName[3] == 'P')
  2393. system("killall Module_DcMeter");
  2394. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  2395. system("killall Module_DoComm");
  2396. return ;
  2397. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  2398. system("killall Module_PsuComm");
  2399. system("killall OcppBackend &");
  2400. system("killall Module_4g &");
  2401. system("killall Module_Wifi &");
  2402. }
  2403. void StartSystemTimeoutDet(uint8_t flag)
  2404. {
  2405. if (pSysInfo->SystemTimeoutFlag != flag) {
  2406. GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
  2407. //log_info("Start System Timeout: %d",flag);
  2408. }
  2409. pSysInfo->SystemTimeoutFlag = flag;
  2410. }
  2411. void StopSystemTimeoutDet(void)
  2412. {
  2413. GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
  2414. pSysInfo->SystemTimeoutFlag = Timeout_None;
  2415. }
  2416. void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
  2417. {
  2418. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2419. if (gunIndex < pSysConfig->TotalConnectorCount) {
  2420. if (pDcChargingInfo->TimeoutFlag != flag) {
  2421. gettimeofday(&pDcChargingInfo->TimeoutTimer, NULL);
  2422. //log_info("Start Gun%d Info timeout: %d",gunIndex,flag);
  2423. }
  2424. pDcChargingInfo->TimeoutFlag = flag;
  2425. }
  2426. }
  2427. void checkLanguagePageTimeout(void)
  2428. {
  2429. int is_idle = TRUE;
  2430. for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  2431. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
  2432. if (pDcChargingInfo->SystemStatus != S_IDLE)
  2433. is_idle = FALSE;
  2434. }
  2435. if (is_idle)
  2436. pSysInfo->SystemPage = _PAGE_VIEW;
  2437. else
  2438. pSysInfo->SystemPage = _PAGE_SELECT_PAY;
  2439. }
  2440. void StopGunInfoTimeoutDet(uint8_t gunIndex)
  2441. {
  2442. if (gunIndex < pSysConfig->TotalConnectorCount) {
  2443. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2444. pDcChargingInfo->TimeoutFlag = Timeout_None;
  2445. }
  2446. }
  2447. void CheckConnectionTimeout(void)
  2448. {
  2449. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  2450. if (ShmSelectGunInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
  2451. _connectionTimeout = ShmSelectGunInfo->RemoteSetup.ConnectionTimeout;
  2452. } else {
  2453. _connectionTimeout = CONN_PLUG_TIME_OUT;
  2454. }
  2455. return;
  2456. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  2457. if (system("pidof -s OcppBackend > /dev/null") != 0) {
  2458. _connectionTimeout = CONN_PLUG_TIME_OUT;
  2459. } else {
  2460. if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0) {
  2461. _connectionTimeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  2462. if (_connectionTimeout <= 0) {
  2463. _connectionTimeout = CONN_PLUG_TIME_OUT;
  2464. }
  2465. } else {
  2466. _connectionTimeout = CONN_PLUG_TIME_OUT;
  2467. }
  2468. }
  2469. }
  2470. void _evccidlinktimeout(uint8_t gunIndex)
  2471. {
  2472. log_info("Getting EVCCID Timeout");
  2473. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2474. pDcChargingInfo->isEVCCIDVerify = true;
  2475. StopGunInfoTimeoutDet(gunIndex);
  2476. destroySelGun(pSysInfo->CurGunSelected);
  2477. connectorPageRestoreIdle();
  2478. }
  2479. void CreateTimeoutFork(void)
  2480. {
  2481. pid_t timeoutPid;
  2482. timeoutPid = fork();
  2483. if (timeoutPid == 0) {
  2484. gettimeofday(&_cmdSubPriority_time, NULL);
  2485. CheckConnectionTimeout();
  2486. log_info("Timeout Fork Child's PID is %d", getpid());
  2487. while (1) {
  2488. if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000) {
  2489. CheckConnectionTimeout();
  2490. gettimeofday(&_cmdSubPriority_time, NULL);
  2491. }
  2492. //log_info("Timeout ***********SystemTimeoutFlag = %d(%d) ********",pSysInfo->SystemTimeoutFlag,
  2493. // GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL);
  2494. // 系統
  2495. switch (pSysInfo->SystemTimeoutFlag) {
  2496. case Timeout_SelftestChk:
  2497. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
  2498. _SelfTestTimeout();
  2499. StopSystemTimeoutDet();
  2500. destroySelGun(DESTROY_ALL_SEL); //jerry add
  2501. }
  2502. break;
  2503. case Timeout_ReturnViewPage:
  2504. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_VIEWPAGE_TIMEOUT) {
  2505. log_error("Timeout_ReturnViewPage");
  2506. StopSystemTimeoutDet();
  2507. pSysInfo->SystemPage = _PAGE_VIEW;
  2508. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  2509. if (pDcChargingInfo->SystemStatus == S_AUTHORIZING || pDcChargingInfo->SystemStatus == S_COMPLETE ||
  2510. pDcChargingInfo->SystemStatus == S_ALARM) {
  2511. setChargerMode(pSysInfo->CurGunSelected, MODE_IDLE);
  2512. }
  2513. }
  2514. break;
  2515. case Timeout_helpPage:
  2516. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= HELP_PAGE_TIMEOUT) {
  2517. StopSystemTimeoutDet();
  2518. pSysInfo->SystemPage = ShmDcCommonData->previousPage;
  2519. }
  2520. break;
  2521. case Timeout_LanguagePage:
  2522. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= LANGUAGE_PAGE_TIMEOUT) {
  2523. StopSystemTimeoutDet();
  2524. checkLanguagePageTimeout();
  2525. }
  2526. break;
  2527. case Timeout_Authorizing:
  2528. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
  2529. log_error("Authorizing Timeout");
  2530. _AuthorizedTimeout();
  2531. StopSystemTimeoutDet();
  2532. destroySelGun(pSysInfo->CurGunSelected);
  2533. if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
  2534. ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
  2535. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  2536. log_error("Author timeout restart DoComm");
  2537. system("killall Module_DoComm");
  2538. //sleep(1);
  2539. //system("/root/Module_DoComm &");
  2540. }
  2541. }
  2542. break;
  2543. case Timeout_WaitBalance:
  2544. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= BALANCE_TIMEOUT) {
  2545. log_error("Wait Balance timeout");
  2546. _AuthorizedTimeout();
  2547. StopSystemTimeoutDet();
  2548. destroySelGun(pSysInfo->CurGunSelected);
  2549. if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
  2550. ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
  2551. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  2552. log_error("Author timeout restart DoComm");
  2553. system("killall Module_DoComm");
  2554. }
  2555. }
  2556. break;
  2557. case Timeout_VerifyFail:
  2558. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
  2559. _AutoReturnTimeout(pSysInfo->CurGunSelected);
  2560. StopSystemTimeoutDet();
  2561. destroySelGun(pSysInfo->CurGunSelected);
  2562. if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
  2563. ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
  2564. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  2565. log_error("Author timeout restart DoComm");
  2566. system("killall Module_DoComm");
  2567. //sleep(1);
  2568. //system("/root/Module_DoComm &");
  2569. }
  2570. }
  2571. break;
  2572. case Timeout_VerifyComp:
  2573. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
  2574. _AutoReturnTimeout(pSysInfo->CurGunSelected);
  2575. StopSystemTimeoutDet();
  2576. }
  2577. break;
  2578. case Timeout_ReturnToChargingGunDet:
  2579. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
  2580. #if defined DD360Audi
  2581. if (getCurLcmPage() != _LCM_PRE_CHARGE &&
  2582. getCurLcmPage() != _LCM_CHARGING &&
  2583. getCurLcmPage() != _LCM_COMPLETE) {
  2584. destroySelGun(pSysInfo->CurGunSelected); //jerry add
  2585. }
  2586. #endif //defined DD360Audi
  2587. DisplayChargingInfo();
  2588. StopSystemTimeoutDet();
  2589. }
  2590. break;
  2591. case Timeout_AuthorizingForStop:
  2592. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
  2593. strcpy((char *)pSysConfig->UserId, "");
  2594. ClearAuthorizedFlag();
  2595. StopSystemTimeoutDet();
  2596. }
  2597. break;
  2598. }
  2599. // 各槍
  2600. for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  2601. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2602. //log_info("Timeout ***********Gun %d TimeoutFlag = %d(%d) ********",gunIndex,pDcChargingInfo->TimeoutFlag,
  2603. // GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL);
  2604. switch (pDcChargingInfo->TimeoutFlag) {
  2605. case Timeout_EVCCID_Link:
  2606. if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= EVCCID_LINK_TIMEOUT) {
  2607. _evccidlinktimeout(gunIndex);
  2608. }
  2609. break;
  2610. case Timeout_WaitPlug:
  2611. if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
  2612. log_info("*********** Gun%d _DetectPlugInTimeout *********** ", gunIndex);
  2613. _DetectPlugInTimeout(gunIndex);
  2614. StopGunInfoTimeoutDet(gunIndex);
  2615. destroySelGun(gunIndex);
  2616. }
  2617. break;
  2618. case Timeout_Preparing:
  2619. if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
  2620. _PrepareTimeout(gunIndex);
  2621. StopGunInfoTimeoutDet(gunIndex);
  2622. destroySelGun(gunIndex); //jerry add
  2623. }
  2624. break;
  2625. case Timeout_EvChargingDet:
  2626. if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
  2627. _DetectEvChargingEnableTimeout(gunIndex);
  2628. StopGunInfoTimeoutDet(gunIndex);
  2629. destroySelGun(gunIndex); //jerry add
  2630. }
  2631. break;
  2632. case Timeout_EvseChargingDet:
  2633. if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
  2634. _DetectEvseChargingEnableTimeout(gunIndex);
  2635. StopGunInfoTimeoutDet(gunIndex);
  2636. destroySelGun(gunIndex); //jerry add
  2637. }
  2638. break;
  2639. case Timeout_EvseCompleteDet:
  2640. if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
  2641. StopGunInfoTimeoutDet(gunIndex);
  2642. destroySelGun(gunIndex); //jerry add
  2643. }
  2644. break;
  2645. case Timeout_ForCcsPrechargeDet:
  2646. if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
  2647. _CcsPrechargeTimeout(gunIndex);
  2648. StopGunInfoTimeoutDet(gunIndex);
  2649. destroySelGun(gunIndex); //jerry add
  2650. }
  2651. break;
  2652. case Timeout_SelectGun: //Jerry add
  2653. if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
  2654. log_info("Timeout_SelectGun");
  2655. StopGunInfoTimeoutDet(gunIndex);
  2656. destroySelGun(gunIndex); //jerry add
  2657. }
  2658. break;
  2659. }
  2660. }
  2661. sleep(1);
  2662. }
  2663. }
  2664. }
  2665. void CheckFactoryConfigFunction(void)
  2666. {
  2667. char Buf[256] = {0};
  2668. if (pSysInfo->FactoryConfiguration) {
  2669. sprintf(Buf, "cd /root;./FactoryConfig -m %s %s",
  2670. pSysConfig->ModelName,
  2671. pSysConfig->SerialNumber);
  2672. system(Buf);
  2673. system("rm -f /Storage/OCPP/OCPPConfiguration");
  2674. system("sync");
  2675. sleep(5);
  2676. system("reboot -f");
  2677. sleep(5);
  2678. system("reboot -f");
  2679. }
  2680. }
  2681. //===============================================
  2682. // Check reservation date is expired
  2683. //===============================================
  2684. int isReservationExpired(uint8_t gunIndex)
  2685. {
  2686. int result = NO;
  2687. struct tm expiredDate;
  2688. struct timeb expiredTime;
  2689. if (sscanf((char *) ShmOCPP16Data->ReserveNow[gunIndex].ExpiryDate,
  2690. "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
  2691. &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
  2692. &expiredDate.tm_min, &expiredDate.tm_sec) == 6) {
  2693. expiredDate.tm_year -= 1900;
  2694. expiredDate.tm_mon -= 1;
  2695. expiredTime.time = mktime(&expiredDate);
  2696. if (!CheckTimeOut(expiredTime)) {
  2697. result = YES;
  2698. }
  2699. }
  2700. return result;
  2701. }
  2702. //===============================================
  2703. // OCPP
  2704. //===============================================
  2705. void CheckOcppStatus(void)
  2706. {
  2707. bool canReset = true;
  2708. //bool canHardReset = true; //DS60-120 add
  2709. if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
  2710. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
  2711. }
  2712. if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES) {
  2713. if (pSysWarning->Level != WARN_LV_ER) {
  2714. for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  2715. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  2716. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  2717. pDcChargingInfo->SystemStatus != S_RESERVATION &&
  2718. pDcChargingInfo->SystemStatus != S_MAINTAIN) {
  2719. canReset = false;
  2720. if (pDcChargingInfo->SystemStatus >= S_REASSIGN &&
  2721. pDcChargingInfo->SystemStatus < S_TERMINATING) {
  2722. //canHardReset = false;
  2723. ChargingTerminalProcess(_index);
  2724. //restartFlag = 1;
  2725. }
  2726. }
  2727. }
  2728. }
  2729. if (canReset) {
  2730. ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
  2731. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
  2732. if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL) {
  2733. log_error("****** Hard Reboot ****** ");
  2734. ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
  2735. sleep(3);
  2736. system("reboot -f");
  2737. } else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL) {
  2738. log_error("****** Soft Reboot ****** ");
  2739. ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
  2740. sleep(3);
  2741. system("killall OcppBackend &");
  2742. KillAllTask();
  2743. TryCloseWatchdog();
  2744. system("/usr/bin/run_evse_restart.sh");
  2745. }
  2746. }
  2747. }
  2748. }
  2749. void OcppStartTransation(uint8_t gunIndex)
  2750. {
  2751. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  2752. return;
  2753. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  2754. uint8_t _OcppGunIndex = gunIndex;
  2755. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2756. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  2757. if (pSysConfig->AcConnectorCount == 1 && gunIndex == 1) {
  2758. _OcppGunIndex = 2;
  2759. }
  2760. if (strcmp((char *)pDcChargingInfo->StartUserId, "") == EQUAL) {
  2761. strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag,
  2762. (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
  2763. } else {
  2764. strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag,
  2765. (char *)pDcChargingInfo->StartUserId);
  2766. }
  2767. log_info("IdTag = %s ", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
  2768. ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
  2769. }
  2770. void OcppStopTransation(uint8_t gunIndex)
  2771. {
  2772. uint8_t _OcppGunIndex = gunIndex;
  2773. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2774. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  2775. if (pSysConfig->AcConnectorCount == 1 && gunIndex == 1) {
  2776. _OcppGunIndex = 2;
  2777. }
  2778. if (strcmp((char *)pDcChargingInfo->StartUserId, "") == EQUAL) {
  2779. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  2780. } else {
  2781. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)pDcChargingInfo->StartUserId);
  2782. }
  2783. log_info("IdTag = %s ", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  2784. ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
  2785. }
  2786. bool OcppRemoteStop(uint8_t gunIndex)
  2787. {
  2788. uint8_t acDirIndex = pSysConfig->AcConnectorCount;
  2789. // 有 AC 槍的話
  2790. if (acDirIndex > 0 && gunIndex > 0) {
  2791. gunIndex += acDirIndex;
  2792. }
  2793. bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
  2794. if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES) {
  2795. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
  2796. ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
  2797. }
  2798. return result;
  2799. }
  2800. bool WifiScheduleStop(uint8_t gunIndex)
  2801. {
  2802. bool result = false;
  2803. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2804. result = pDcChargingInfo->schedule.isTriggerStop;
  2805. pDcChargingInfo->schedule.isTriggerStop = NO;
  2806. return result;
  2807. }
  2808. void OcppRemoteStartChk()
  2809. {
  2810. if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
  2811. } else{
  2812. // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
  2813. uint8_t acDirIndex = pSysConfig->AcConnectorCount;
  2814. for (uint8_t ac_index = 0; ac_index < pSysConfig->AcConnectorCount; ac_index++) {
  2815. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(ac_index);
  2816. if (!isDetectPlugin(acDirIndex)) {
  2817. if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
  2818. if (pAcChargingInfo->SystemStatus == S_IDLE ||
  2819. pAcChargingInfo->SystemStatus == S_RESERVATION) {
  2820. ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
  2821. pAcChargingInfo->RemoteStartFlag = YES;
  2822. pSysInfo->OrderCharging = YES;
  2823. //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
  2824. ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
  2825. DetectPluginStart(acDirIndex);
  2826. return;
  2827. }
  2828. ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
  2829. }
  2830. }
  2831. }
  2832. uint8_t threeGunIndex = 0;
  2833. uint8_t dcIndex = 0;
  2834. bool isGunUsingStatus = false;
  2835. for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  2836. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
  2837. /*
  2838. // 如果有 AC 槍,且 DC 槍也有兩把
  2839. if (acDirIndex == 1 && _index == 1) {
  2840. threeGunIndex = 1;
  2841. }
  2842. if (ShmOCPP16Data->CsMsg.bits[_index + threeGunIndex].RemoteStartTransactionReq == YES) {
  2843. dcIndex = _index;
  2844. }
  2845. if (pDcChargingInfo->SystemStatus != S_IDLE) {
  2846. isGunUsingStatus = true;
  2847. }
  2848. }
  2849. // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
  2850. if (isGunUsingStatus && pSysInfo->IsAlternatvieConf) {
  2851. if (dcIndex == 0) {
  2852. threeGunIndex = 0;
  2853. }
  2854. ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
  2855. return;
  2856. }
  2857. if (dcIndex == 0) {
  2858. threeGunIndex = 0;
  2859. }
  2860. */
  2861. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
  2862. if (ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq == YES) {
  2863. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2864. pDcChargingInfo->SystemStatus == S_RESERVATION) {
  2865. pDcChargingInfo->RemoteStartFlag = YES;
  2866. pSysInfo->OrderCharging = YES;
  2867. //pSysInfo->OrderCharging = gunIndex;
  2868. ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
  2869. DetectPluginStart(_index);
  2870. #if defined DD360Audi
  2871. setSelGunWaitToAuthor(_index); //Jerry add
  2872. #endif //defined DD360Audi
  2873. }
  2874. ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
  2875. }
  2876. }
  2877. }
  2878. }
  2879. void ChkOcppStatus(uint8_t gunIndex)
  2880. {
  2881. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2882. if (pDcChargingInfo->SystemStatus == S_IDLE &&
  2883. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
  2884. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
  2885. if (isReservationExpired(gunIndex)) {
  2886. log_info("***************ChkOcppStatus : OcppReservedStatus******************** ");
  2887. pDcChargingInfo->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
  2888. pDcChargingInfo->SystemStatus = S_RESERVATION;
  2889. }
  2890. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
  2891. }
  2892. if (pDcChargingInfo->SystemStatus == S_RESERVATION &&
  2893. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
  2894. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
  2895. if (isReservationExpired(gunIndex)) {
  2896. log_info("***************ChkOcppStatus : Cancel OcppReservedStatus******************** ");
  2897. pDcChargingInfo->ReservationId = 0;
  2898. pDcChargingInfo->SystemStatus = S_IDLE;
  2899. }
  2900. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
  2901. }
  2902. if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
  2903. log_info("***************ChkOcppStatus : OcppChangeAvailability******************** ");
  2904. ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
  2905. if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL) {
  2906. if (isDb_ready) {
  2907. DB_Update_Operactive(gunIndex, true);
  2908. }
  2909. pDcChargingInfo->IsAvailable = YES;
  2910. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2911. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  2912. pDcChargingInfo->SystemStatus == S_MAINTAIN) {
  2913. setChargerMode(gunIndex, MODE_IDLE);
  2914. }
  2915. } else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL) {
  2916. if (isDb_ready) {
  2917. DB_Update_Operactive(gunIndex, false);
  2918. }
  2919. pDcChargingInfo->IsAvailable = NO;
  2920. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2921. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  2922. pDcChargingInfo->SystemStatus == S_MAINTAIN ) {
  2923. setChargerMode(gunIndex, MODE_MAINTAIN);
  2924. }
  2925. }
  2926. }
  2927. if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
  2928. ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
  2929. if (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK && // DS60-120 add ||
  2930. pDcChargingInfo->SystemStatus <= S_CHARGING) {
  2931. // 充電中,需停止充電
  2932. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
  2933. ChargingTerminalProcess(gunIndex);
  2934. }
  2935. strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
  2936. ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
  2937. }
  2938. }
  2939. bool CheckBackendChargingTimeout(uint8_t gunIndex)
  2940. {
  2941. bool result = false;
  2942. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2943. if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
  2944. if (pSysConfig->MaxChargingDuration > 0) {
  2945. if (pDcChargingInfo->PresentChargedDuration > (pSysConfig->MaxChargingDuration * 60)) {
  2946. result = true;
  2947. }
  2948. }
  2949. } /*else if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
  2950. // 隨插即充電的要看 offline
  2951. if (pSysConfig->OfflineMaxChargeDuration > 0) {
  2952. if (pDcChargingInfo->PresentChargedDuration > (pSysConfig->OfflineMaxChargeDuration * 60)) {
  2953. result = true;
  2954. }
  2955. }
  2956. }*/
  2957. return result;
  2958. }
  2959. bool CheckBackendChargingEnergy(uint8_t gunIndex)
  2960. {
  2961. bool result = false;
  2962. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2963. if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
  2964. if (pSysConfig->MaxChargingEnergy > 0) {
  2965. if (pDcChargingInfo->PresentChargedEnergy > pSysConfig->MaxChargingEnergy) {
  2966. result = true;
  2967. }
  2968. }
  2969. }/* else if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
  2970. // 隨插即充電的要看 offline
  2971. if (pSysConfig->OfflineMaxChargeEnergy > 0) {
  2972. if (pDcChargingInfo->PresentChargedEnergy > (pSysConfig->OfflineMaxChargeEnergy)) {
  2973. result = true;
  2974. }
  2975. }
  2976. }*/
  2977. return result;
  2978. }
  2979. void InformOcppErrOccur(uint8_t codeType)
  2980. {
  2981. char _error[25];
  2982. switch (codeType) {
  2983. case 4:
  2984. strcpy(_error, "InternalError");
  2985. break;
  2986. case 6:
  2987. strcpy(_error, "NoError");
  2988. break;
  2989. case 7:
  2990. strcpy(_error, "OtherError");
  2991. break;
  2992. case 13:
  2993. strcpy(_error, "UnderVoltage");
  2994. break;
  2995. case 14:
  2996. strcpy(_error, "OverVoltage");
  2997. break;
  2998. }
  2999. for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  3000. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, _error);
  3001. }
  3002. }
  3003. //===============================================
  3004. // Config process
  3005. //===============================================
  3006. void AddPlugInTimes(uint8_t gunIndex)
  3007. {
  3008. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3009. if (pDcChargingInfo->Type == _Type_Chademo) {
  3010. pSysConfig->ChademoPlugInTimes += 1;
  3011. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3012. pSysConfig->Ccs2PlugInTimes += 1;
  3013. } else if (pDcChargingInfo->Type == _Type_GB) {
  3014. pSysConfig->GbPlugInTimes += 1;
  3015. }
  3016. }
  3017. void ChangeStartOrStopDateTime(uint8_t isStart, uint8_t gunIndex)
  3018. {
  3019. char cmdBuf[32];
  3020. struct timeb csuTime;
  3021. struct tm *tmCSU;
  3022. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3023. ftime(&csuTime);
  3024. tmCSU = localtime(&csuTime.time);
  3025. sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
  3026. tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  3027. tmCSU->tm_sec);
  3028. if (isStart) {
  3029. strcpy((char *)pDcChargingInfo->StartDateTime, cmdBuf);
  3030. } else {
  3031. strcpy((char *)pDcChargingInfo->StopDateTime, cmdBuf);
  3032. }
  3033. }
  3034. void ChangeGunSelectByIndex(uint8_t sel)
  3035. {
  3036. pSysInfo->CurGunSelected = sel;
  3037. pSysInfo->CurGunSelectedByAc = NO_DEFINE;
  3038. }
  3039. void CheckIsAlternatvieByModelName()
  3040. {
  3041. // 黑白機 ?
  3042. /*if (strcmp((char *)pSysConfig->ModelName, "DWWU301J0UT1PH") == EQUAL ||
  3043. strcmp((char *)pSysConfig->ModelName, "DWYE301J0ET1PH") == EQUAL ||
  3044. strcmp((char *)pSysConfig->ModelName, "DSYE301J3EW2PH") == EQUAL ||
  3045. strcmp((char *)pSysConfig->ModelName, "DWYC301J0UW1PH") == EQUAL) {
  3046. */
  3047. if (pSysConfig->ModelName[1] == 'W') { //DS60-120
  3048. // 壁掛
  3049. pSysInfo->IsAlternatvieConf = YES;
  3050. } else {
  3051. pSysInfo->IsAlternatvieConf = NO;
  3052. }
  3053. }
  3054. void StopProcessingLoop()
  3055. {
  3056. for (;;) {
  3057. CheckFactoryConfigFunction();
  3058. //CheckFwUpdateFunction();
  3059. if (pSysWarning->Level == WARN_LV_ER) {
  3060. ChkPrimaryStatus();
  3061. if (pSysWarning->Level == WARN_LV_NL) {
  3062. log_info("Soft reboot for retry self-tets (Primary). ");
  3063. KillAllTask();
  3064. sleep(3);
  3065. TryCloseWatchdog();
  3066. system("/usr/bin/run_evse_restart.sh");
  3067. return;
  3068. }
  3069. }
  3070. sleep(1);
  3071. TryFeedWatchdog();
  3072. }
  3073. }
  3074. bool IsConnectorWholeIdle()
  3075. {
  3076. bool result = true;
  3077. for (uint8_t count = 0; count < pSysConfig->TotalConnectorCount; count++) {
  3078. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
  3079. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  3080. pDcChargingInfo->SystemStatus != S_RESERVATION) {
  3081. result = false;
  3082. break;
  3083. }
  3084. }
  3085. for (uint8_t count = 0; count < pSysConfig->AcConnectorCount; count++) {
  3086. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(count);
  3087. if (pAcChargingInfo->SystemStatus != S_IDLE &&
  3088. pAcChargingInfo->IsErrorOccur == NO) {
  3089. result = false;
  3090. break;
  3091. }
  3092. }
  3093. return result;
  3094. }
  3095. void ClearAlarmCodeWhenAcOff()
  3096. {
  3097. if (!pSysInfo->AcContactorStatus) {
  3098. pAlarmCode->AlarmEvents.bits.PsuNoResource = NO;
  3099. }
  3100. }
  3101. //==========================================
  3102. // Check task processing
  3103. //==========================================
  3104. void CheckTask()
  3105. {
  3106. /*+++ 20200908, vern, disable it for DD360 +++*/
  3107. #if 0
  3108. if (pSysConfig->ModelName[10] == 'T') {
  3109. if (system("pidof -s Module_4g > /dev/null") != 0) {
  3110. log_error("Module_4g not running, restart it.");
  3111. system("/root/Module_4g &");
  3112. }
  3113. } else if (pSysConfig->ModelName[10] == 'W') {
  3114. if (system("pidof -s Module_Wifi > /dev/null") != 0) {
  3115. log_error("Module_Wifi not running, restart it.");
  3116. system("/root/Module_Wifi &");
  3117. }
  3118. }
  3119. if (strcmp((char *)pSysConfig->OcppServerURL, "") != EQUAL &&
  3120. strcmp((char *)pSysConfig->ChargeBoxId, "") != EQUAL) {
  3121. if (system("pidof -s OcppBackend > /dev/null") != 0) {
  3122. log_error("OcppBackend not running, restart it.");
  3123. system("/root/OcppBackend &");
  3124. }
  3125. }
  3126. #endif //0
  3127. /*--- 20200908, vern, disable it for DD360 ---*/
  3128. /*
  3129. if (system("pidof -s Module_ProduceUtils > /dev/null") != 0) {
  3130. log_error("Module_ProduceUtils not running, restart it.");
  3131. system ("/root/Module_ProduceUtils &");
  3132. }*/
  3133. }
  3134. //==========================================
  3135. // Check Smart Charging Profile
  3136. //==========================================
  3137. int GetStartScheduleTime(uint8_t *time)
  3138. {
  3139. int result = -1;
  3140. struct tm tmScheduleStart;
  3141. struct timeb tbScheduleStart;
  3142. 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)) {
  3143. tmScheduleStart.tm_year -= 1900;
  3144. tmScheduleStart.tm_mon -= 1;
  3145. tbScheduleStart.time = mktime(&tmScheduleStart);
  3146. tbScheduleStart.millitm = 0;
  3147. result = DiffTimebWithNow(tbScheduleStart) / 1000;
  3148. }
  3149. return result;
  3150. }
  3151. void CheckSmartChargeProfile(uint8_t _index)
  3152. {
  3153. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  3154. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
  3155. // Get Charging Profile
  3156. ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
  3157. if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
  3158. ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES //DS60-120 add
  3159. ) {
  3160. int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
  3161. uint8_t _startCount = NO_DEFINE;
  3162. uint8_t _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
  3163. for (uint8_t _count = 0; _count < _maxCount; _count++) {
  3164. // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
  3165. if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod) {
  3166. if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
  3167. ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR) {
  3168. _startCount = _count;
  3169. }
  3170. }
  3171. }
  3172. log_info("_startCount = %d ", _startCount);
  3173. if (_startCount < _maxCount) {
  3174. //DS60-120 add
  3175. log_info("Profile Limit = %f ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
  3176. pDcChargingInfo->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
  3177. if (pDcChargingInfo->EvBatterytargetVoltage > 0 && pDcChargingInfo->PresentChargingVoltage > 0) {
  3178. pDcChargingInfo->ChargingProfileCurrent = (pDcChargingInfo->ChargingProfilePower / pDcChargingInfo->PresentChargingVoltage) * 10;
  3179. } else {
  3180. pDcChargingInfo->ChargingProfileCurrent = 0;
  3181. }
  3182. //DS60-120 remove
  3183. //log_info("*********Limit = %f ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
  3184. //pDcChargingInfo->ChargingProfileCurrent = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * 10;
  3185. //pDcChargingInfo->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * pDcChargingInfo->EvBatterytargetVoltage / 100;
  3186. //pDcChargingInfo->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
  3187. // if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0)
  3188. // {
  3189. // pDcChargingInfo->ChargingProfileCurrent = pDcChargingInfo->ChargingProfilePower / (pDcChargingInfo->EvBatterytargetVoltage * 10);
  3190. // }
  3191. } else {
  3192. pDcChargingInfo->ChargingProfilePower = -1;
  3193. pDcChargingInfo->ChargingProfileCurrent = -1;
  3194. }
  3195. } else {
  3196. pDcChargingInfo->ChargingProfilePower = -1;
  3197. pDcChargingInfo->ChargingProfileCurrent = -1;
  3198. }
  3199. log_info("ChargingProfilePower = %f ", pDcChargingInfo->ChargingProfilePower);
  3200. log_info("ChargingProfileCurrent = %f ", pDcChargingInfo->ChargingProfileCurrent);
  3201. }
  3202. //
  3203. // printf("-------------Schedule------------");
  3204. // printf("index = %d ", _index);
  3205. // printf("StartSchedule = %s ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
  3206. // printf("ChargingRateUnit = %s ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
  3207. // printf("----------SchedulePeriod---------");
  3208. // for (int v = 0; v < 10; v++)
  3209. // {
  3210. // printf("StartPeriod = %d ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
  3211. // printf("Limit = %f ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
  3212. // }
  3213. // printf("---------------------------------");
  3214. }
  3215. void ChargingProfileFlat(uint8_t _index)
  3216. {
  3217. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO) {
  3218. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO) {
  3219. ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
  3220. }
  3221. }
  3222. }
  3223. void CheckReturnToChargingConn()
  3224. {
  3225. if ((pSysConfig->TotalConnectorCount + pSysConfig->AcConnectorCount) > 1 &&
  3226. pSysInfo->PageIndex != _LCM_AUTHORIZING &&
  3227. pSysInfo->PageIndex != _LCM_AUTHORIZ_FAIL &&
  3228. pSysInfo->PageIndex != _LCM_AUTHORIZ_COMP &&
  3229. pSysInfo->PageIndex != _LCM_WAIT_FOR_PLUG) {
  3230. bool isReturnTimeout = false;
  3231. for (uint8_t count = 0; count < pSysConfig->TotalConnectorCount; count++) {
  3232. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
  3233. // 如果選的 DC 槍在充電~ 則 DC 槍不改變
  3234. if (count == pSysInfo->CurGunSelected) {
  3235. if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  3236. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  3237. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  3238. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  3239. ) {
  3240. isReturnTimeout = false;
  3241. break;
  3242. }
  3243. } else if (count != pSysInfo->CurGunSelected) {
  3244. if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  3245. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  3246. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  3247. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  3248. ) {
  3249. isReturnTimeout = true;
  3250. StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
  3251. }
  3252. }
  3253. }
  3254. // AC 槍
  3255. if (!isReturnTimeout && pSysConfig->AcConnectorCount > 0) {
  3256. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  3257. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  3258. // 沒有選中 AC,且 AC 在充電中
  3259. if (pSysInfo->CurGunSelectedByAc == NO_DEFINE &&
  3260. (pAcChargingInfo->SystemStatus >= S_PREPARNING &&
  3261. pAcChargingInfo->SystemStatus <= S_COMPLETE)) {
  3262. // 當前 DC 充電槍在 idle 狀態
  3263. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  3264. pDcChargingInfo->SystemStatus == S_RESERVATION) {
  3265. isReturnTimeout = true;
  3266. StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
  3267. }
  3268. } else if (pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX &&
  3269. ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  3270. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  3271. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  3272. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))) {
  3273. // 當前 DC 充電槍在 idle 狀態
  3274. if (pAcChargingInfo->SystemStatus == S_IDLE ||
  3275. pAcChargingInfo->SystemStatus == S_RESERVATION) {
  3276. isReturnTimeout = true;
  3277. StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
  3278. }
  3279. }
  3280. }
  3281. if (!isReturnTimeout) {
  3282. StopSystemTimeoutDet();
  3283. }
  3284. }
  3285. }
  3286. bool GetStartChargingByAlterMode(uint8_t _gun)
  3287. {
  3288. bool result = true;
  3289. if (pSysConfig->TotalConnectorCount == 2 &&
  3290. pSysInfo->IsAlternatvieConf == YES) {
  3291. for (uint8_t _select = 0; _select < pSysConfig->TotalConnectorCount; _select++) {
  3292. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_select);
  3293. if (_select != _gun) {
  3294. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  3295. pDcChargingInfo->SystemStatus != S_RESERVATION) {
  3296. result = false;
  3297. break;
  3298. }
  3299. }
  3300. }
  3301. }
  3302. return result;
  3303. }
  3304. void TheEndCharging(uint8_t gunIndex)
  3305. {
  3306. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3307. ftime(&endChargingTime[gunIndex]);
  3308. if (pDcChargingInfo->PresentChargedDuration != 0) {
  3309. pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
  3310. }
  3311. pDcChargingInfo->isRemoteStart = NO;
  3312. StopGunInfoTimeoutDet(gunIndex);
  3313. StartGunInfoTimeoutDet(gunIndex, Timeout_EvseCompleteDet);
  3314. ChangeStartOrStopDateTime(NO, gunIndex);
  3315. DB_Insert_Record(gunIndex);
  3316. }
  3317. void UpdateErrorCodeToOcpp(uint8_t index)
  3318. {
  3319. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  3320. //log_info("%d = ConnectorAlarmCode = %s", index, pDcChargingInfo->ConnectorAlarmCode);
  3321. //log_info("%d = EvConnAlarmCode = %s", index, pDcChargingInfo->EvConnAlarmCode);
  3322. if (strcmp((char *)pDcChargingInfo->ConnectorAlarmCode, "") != EQUAL) {
  3323. //if (strlen((char *)pDcChargingInfo->ConnectorAlarmCode) == EQUAL) {
  3324. strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "InternalError");
  3325. strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)pDcChargingInfo->ConnectorAlarmCode);
  3326. } else if (strcmp((char *)pDcChargingInfo->EvConnAlarmCode, "") != EQUAL) {
  3327. //} else if (strlen((char *)pDcChargingInfo->EvConnAlarmCode) == EQUAL) {
  3328. strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "OtherError");
  3329. strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)pDcChargingInfo->EvConnAlarmCode);
  3330. }
  3331. //log_info("Gun %d = VendorErrorCode = %s", index, (char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
  3332. }
  3333. void AdjustChargerCurrent()
  3334. {
  3335. pSysConfig->RatingCurrent = ShmPsuData->SystemAvailableCurrent / 10;
  3336. // 設定的電流~ 如超過可輸出的電流,則 bypass
  3337. if (pSysConfig->RatingCurrent < pSysConfig->MaxChargingCurrent ||
  3338. pSysConfig->RatingCurrent == 0) {
  3339. pSysConfig->MaxChargingCurrent = 0;
  3340. }
  3341. log_info("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
  3342. ShmPsuData->SystemAvailablePower / 10,
  3343. ShmPsuData->SystemAvailableCurrent / 10
  3344. );
  3345. log_info("Config : ChargingPower = %d, ChargingCurrent = %d",
  3346. pSysConfig->MaxChargingPower,
  3347. pSysConfig->MaxChargingCurrent
  3348. );
  3349. }
  3350. void ResetDetAlarmStatus(uint8_t gun)
  3351. {
  3352. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
  3353. if (pDcChargingInfo->Type == _Type_Chademo) {
  3354. if (pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP == YES) {
  3355. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = NO;
  3356. }
  3357. } else if (pDcChargingInfo->Type == _Type_GB) {
  3358. if (pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP == YES) {
  3359. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = NO;
  3360. }
  3361. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3362. if (pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP == YES) {
  3363. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO;
  3364. }
  3365. }
  3366. }
  3367. char OldUseId[32] = {0};
  3368. static void autoStartCharging(uint8_t gunIndex)
  3369. {
  3370. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3371. if ( (pSysInfo->SystemPage >= _LCM_AUTHORIZING && pSysInfo->SystemPage <= _LCM_AUTHORIZ_FAIL) ||
  3372. pDcChargingInfo->isEVCCIDVerify || (strcmp( (char *)pSysConfig->UserId , "" ) != EQUAL)) {
  3373. return;
  3374. }
  3375. if ((pDcChargingInfo->ConnectorPlugIn == YES) &&
  3376. (pDcChargingInfo->SystemStatus == S_IDLE )
  3377. ) {
  3378. if(!pSysConfig->AuthorisationMode) {
  3379. if (pSysConfig->isAuthrizeByEVCCID && !pDcChargingInfo->isEVCCIDVerify &&
  3380. pDcChargingInfo->Type == _Type_CCS_2) {
  3381. #ifdef DD360Audi
  3382. // LCM show linking pic. & timeout 2 min
  3383. if( pSysInfo->CurGunSelected == gunIndex ) {
  3384. systemPageRestoreInit();
  3385. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  3386. }
  3387. StartGunInfoTimeoutDet(gunIndex,Timeout_EVCCID_Link);
  3388. #endif
  3389. // Getting EVCCID
  3390. if( strcmp( (char *)pDcChargingInfo->EVCCID, "" ) != EQUAL ) {
  3391. log_info("Authorizing EVCCID");
  3392. StopSystemTimeoutDet();
  3393. strcpy((char *)pSysConfig->UserId, (char *)pDcChargingInfo->EVCCID);
  3394. pSysInfo->CurGunSelected = gunIndex;
  3395. ChangeGunSelectByIndex(gunIndex);
  3396. confirmSelGun(gunIndex);
  3397. pDcChargingInfo->isEVCCIDVerify = true;
  3398. ShmDcCommonData->AuthroizeType = IdTokenType_MacAddress;
  3399. pSysInfo->SystemPage = _LCM_AUTHORIZING;
  3400. }
  3401. } else
  3402. return;
  3403. } else {
  3404. strcpy((char *)&pSysConfig->UserId, "AutoStartCharging");
  3405. pSysInfo->CurGunSelected = gunIndex;
  3406. ChangeGunSelectByIndex(gunIndex);
  3407. confirmSelGun(gunIndex);
  3408. pSysInfo->SystemPage = _LCM_AUTHORIZING;
  3409. ShmDcCommonData->AuthroizeType = IdTokenType_NoAuthorization;
  3410. pDcChargingInfo->StartMethod = _CHARGING_START_AUTOSTART;
  3411. }
  3412. if (strcmp( (char *)pSysConfig->UserId , OldUseId ) != EQUAL) {
  3413. strcpy((char *)OldUseId, (char *)pSysConfig->UserId);
  3414. log_info("Get User(%d) ID:%s",gunIndex,pSysConfig->UserId);
  3415. }
  3416. }else if (pDcChargingInfo->ConnectorPlugIn == NO && pDcChargingInfo->Type == _Type_CCS_2) {
  3417. strcpy((char *)OldUseId, "");
  3418. }
  3419. }
  3420. static bool PrecheckIsPass(uint8_t gunIndex)
  3421. {
  3422. bool result = true;
  3423. // relay welding or driving 是反向
  3424. result = !ShmDcCommonData->GunRelayWeldingOccur[gunIndex];
  3425. return result;
  3426. }
  3427. static void ReviewCriticalAlarm(void)
  3428. {
  3429. if (//ShmDcCommonData->GunRelayDrivingOccur[0] == YES ||
  3430. //ShmDcCommonData->GunRelayDrivingOccur[1] == YES ||
  3431. //ShmDcCommonData->GunRelayWeldingOccur[0] == YES ||
  3432. //ShmDcCommonData->GunRelayWeldingOccur[1] == YES ||
  3433. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES ||
  3434. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES ||
  3435. pAlarmCode->AlarmEvents.bits.DoorOpen == YES ||
  3436. pSysWarning->ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
  3437. pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == YES ||
  3438. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES ||
  3439. //Power cabinet alarm status
  3440. ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop == YES ||
  3441. ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen == YES ||
  3442. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputOVP == YES ||
  3443. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputUVP == YES ||
  3444. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP == YES ||
  3445. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP == YES ||
  3446. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP == YES ||
  3447. ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure == YES
  3448. ) {
  3449. pSysWarning->Level = WARN_LV_ER;
  3450. } else {
  3451. pSysWarning->Level = WARN_LV_NL;
  3452. }
  3453. }
  3454. static void CheckRelayWeldingOrDrivingFault(uint8_t gunIndex)
  3455. {
  3456. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3457. // relay welding fault then stop the charging process.
  3458. uint8_t faultCode = RELAY_STATUS_ERROR_NONE;
  3459. //static uint8_t drivingCount = 0;
  3460. if (gunIndex == 0) {
  3461. if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
  3462. ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
  3463. faultCode = RELAY_STATUS_ERROR_WELDING;
  3464. } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
  3465. ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
  3466. faultCode = RELAY_STATUS_ERROR_DRIVING;
  3467. }
  3468. } else if (gunIndex == 1) {
  3469. if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
  3470. ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
  3471. faultCode = RELAY_STATUS_ERROR_WELDING;
  3472. } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
  3473. ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
  3474. faultCode = RELAY_STATUS_ERROR_DRIVING;
  3475. }
  3476. }
  3477. if (pSysConfig->TotalConnectorCount >= 2 &&
  3478. !pSysInfo->IsAlternatvieConf) {
  3479. // 橋接
  3480. if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
  3481. ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
  3482. faultCode = RELAY_STATUS_ERROR_WELDING;
  3483. } else if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
  3484. ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
  3485. faultCode = RELAY_STATUS_ERROR_DRIVING;
  3486. }
  3487. }
  3488. if (faultCode == RELAY_STATUS_ERROR_WELDING) {
  3489. // welding
  3490. if (pDcChargingInfo->Type == _Type_Chademo) {
  3491. RecordAlarmCode(gunIndex, "011011");
  3492. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES;
  3493. } else if (pDcChargingInfo->Type == _Type_GB) {
  3494. RecordAlarmCode(gunIndex, "011015");
  3495. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES;
  3496. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3497. RecordAlarmCode(gunIndex, "011013");
  3498. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES;
  3499. }
  3500. ShmDcCommonData->GunRelayWeldingOccur[gunIndex] = YES;
  3501. //EmcOccureByString("");
  3502. } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
  3503. //if (drivingCount++ != 2) {
  3504. // return;
  3505. //}
  3506. // driving
  3507. if (pDcChargingInfo->Type == _Type_Chademo) {
  3508. RecordAlarmCode(gunIndex, "011012");
  3509. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES;
  3510. } else if (pDcChargingInfo->Type == _Type_GB) {
  3511. RecordAlarmCode(gunIndex, "011016");
  3512. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES;
  3513. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3514. RecordAlarmCode(gunIndex, "011014");
  3515. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES;
  3516. }
  3517. ShmDcCommonData->GunRelayDrivingOccur[gunIndex] = YES;
  3518. //EmcOccureByString("");
  3519. } else {
  3520. ShmDcCommonData->GunRelayWeldingOccur[gunIndex] = NO;
  3521. ShmDcCommonData->GunRelayDrivingOccur[gunIndex] = NO;
  3522. //drivingCount = 0;
  3523. #if 0
  3524. if (pDcChargingInfo->Type == _Type_Chademo) {
  3525. //ResetChargerAlarmCode(gunIndex, "011012");
  3526. //ResetChargerAlarmCode(gunIndex, "011011");
  3527. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
  3528. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
  3529. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3530. //ResetChargerAlarmCode(gunIndex, "011014");
  3531. //ResetChargerAlarmCode(gunIndex, "011013");
  3532. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
  3533. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
  3534. } else if (pDcChargingInfo->Type == _Type_GB) {
  3535. //ResetChargerAlarmCode(gunIndex, "011016");
  3536. //ResetChargerAlarmCode(gunIndex, "011015");
  3537. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
  3538. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
  3539. }
  3540. #endif
  3541. }
  3542. }
  3543. static void isChargingAverageState(void)
  3544. {
  3545. if (pSysInfo->MainChargingMode != _MAIN_CHARGING_MODE_AVER) {
  3546. pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
  3547. return;
  3548. }
  3549. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  3550. if (pSysInfo->AcContactorStatus != YES) {
  3551. pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
  3552. pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
  3553. }
  3554. #endif //!defined DD360 && !defined DD360Audi
  3555. // 均充 -> 最大充
  3556. if (pSysInfo->BridgeRelayStatus == NO) {
  3557. if (pSysInfo->ReAssignedFlag == _REASSIGNED_NONE) {
  3558. log_info("=============Smart Charging============= Step 11 ");
  3559. pSysInfo->ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
  3560. }
  3561. } else if (pSysInfo->ReAssignedFlag != _REASSIGNED_COMP &&
  3562. pSysInfo->ReAssignedFlag != _REASSIGNED_WAITING) {
  3563. log_info("=============Smart Charging============= Step 14 ");
  3564. pSysInfo->ReAssignedFlag = _REASSIGNED_WAITING;
  3565. } else if (pSysInfo->ReAssignedFlag == _REASSIGNED_COMP) {
  3566. pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
  3567. pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
  3568. }
  3569. }
  3570. static uint8_t distributionPsuModule(uint8_t *isRessign, uint8_t gunIndex)
  3571. {
  3572. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  3573. return NO;
  3574. #endif // defined DD360 || defined DD360Audi || defined DD360ComBox
  3575. uint8_t index = 0;
  3576. struct ChargingInfoData *pDcChargingInfo = NULL;
  3577. if (pSysConfig->TotalConnectorCount <= 1 &&
  3578. pSysInfo->IsAlternatvieConf != NO) {
  3579. return NO;
  3580. }
  3581. if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
  3582. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  3583. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  3584. // 有其他槍已經分配好 psu 模塊
  3585. if (pSysInfo->CurGunSelected != index &&
  3586. pDcChargingInfo->SystemStatus >= S_PREPARNING &&
  3587. pDcChargingInfo->SystemStatus != S_MAINTAIN) {
  3588. log_info("=============Smart Charging============= Step 1 ");
  3589. pSysInfo->ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
  3590. *(isRessign) = YES;
  3591. break;
  3592. }
  3593. }
  3594. } else if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
  3595. pSysInfo->ReAssignedFlag != _REASSIGNED_NONE) {
  3596. // 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
  3597. if (pSysInfo->BridgeRelayStatus == YES) {
  3598. if (pSysInfo->ReAssignedFlag != _REASSIGNED_COMP &&
  3599. pSysInfo->ReAssignedFlag != _REASSIGNED_WAITING) {
  3600. log_info("=============Smart Charging============= Step 14 ");
  3601. pSysInfo->ReAssignedFlag = _REASSIGNED_WAITING;
  3602. } else if (pSysInfo->ReAssignedFlag == _REASSIGNED_COMP) {
  3603. pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
  3604. pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
  3605. return YES;
  3606. }
  3607. }
  3608. if (pSysInfo->CurGunSelected == gunIndex) {
  3609. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  3610. }
  3611. return YES;
  3612. }
  3613. return NO;
  3614. }
  3615. bool Taskconutstring(char *src, char *taskname)
  3616. {
  3617. bool result = false;
  3618. if (src == NULL || strlen(src) == 0)
  3619. return result;
  3620. if (strstr(src, taskname) != NULL &&
  3621. strstr(src, "grep") == NULL &&
  3622. strstr(src, "[") == NULL)
  3623. {
  3624. result = true;
  3625. }
  3626. return result;
  3627. }
  3628. int GetProcessCount(char *procName)
  3629. {
  3630. int result = 0;
  3631. FILE *fp;
  3632. char cmd[256];
  3633. char buf[256];
  3634. sprintf(cmd, "ps -ef |grep %s", procName);
  3635. fp = popen(cmd, "r");
  3636. if(fp != NULL)
  3637. {
  3638. while(fgets(buf, sizeof(buf), fp) != NULL)
  3639. {
  3640. if (Taskconutstring(buf, procName))
  3641. result++;
  3642. }
  3643. }
  3644. pclose(fp);
  3645. return result;
  3646. }
  3647. void CheckTaskAlive()
  3648. {
  3649. pid_t Pid = fork();
  3650. if ( Pid == 0 ) {
  3651. while(1) {
  3652. sleep(3);
  3653. unsigned char count = GetProcessCount("Module_ChkSysTask");
  3654. if( count != 1 ) {
  3655. system("pkill Module_ChkSysTask");
  3656. sleep(10);
  3657. system("/root/Module_ChkSysTask &");
  3658. }
  3659. }
  3660. return;
  3661. }
  3662. log_info("Create Check Systam fork:%d",Pid);
  3663. return;
  3664. }
  3665. /**
  3666. * [checkPileEndGfdResult 確認充電樁GFD狀態]
  3667. * @Author Jerry
  3668. * @DateTime 2021-07-01
  3669. * @param gunIndex [當前的槍]
  3670. * @param gunType [槍的類型]
  3671. * @param sysStatus [槍的系統狀態]
  3672. */
  3673. static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sysStatus)
  3674. {
  3675. switch (gunType) {
  3676. case _Type_Chademo:
  3677. // 檢查樁端的 GFD 結果
  3678. if (sysStatus == S_PREPARING_FOR_EVSE &&
  3679. isPrechargeStatus_chademo(gunIndex) >= 6) {
  3680. // 當前操作的槍號,進入 Charging
  3681. setChargerMode(gunIndex, MODE_CHARGING);
  3682. }
  3683. // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
  3684. //if ((sysStatus == S_ALARM ||
  3685. // sysStatus == S_TERMINATING) &&
  3686. // isEvStopCharging_chademo(gunIndex) == YES) {
  3687. // /*+++ 20200908, vern, disable it for DD360 +++*/
  3688. // if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  3689. // strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
  3690. // /*--- 20200908, vern, disable it for DD360 ---*/
  3691. // }
  3692. //}
  3693. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  3694. // GFD 錯誤停止
  3695. RecordAlarmCode(gunIndex, "012234");
  3696. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES;
  3697. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
  3698. } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  3699. // GFD 警告
  3700. //RecordAlarmCode(gunIndex, "012296");
  3701. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  3702. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES;
  3703. }
  3704. else
  3705. {
  3706. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  3707. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
  3708. }
  3709. //else if (sysStatus == S_CHARGING &&
  3710. // ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
  3711. // pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
  3712. // (pDcChargingInfo->PresentChargedDuration >= 10 &&
  3713. // pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL)
  3714. // ) {
  3715. // // UVP
  3716. // RecordAlarmCode(gunIndex, "012289");
  3717. // ChargingTerminalProcess(gunIndex);
  3718. //}
  3719. break;
  3720. case _Type_GB:
  3721. // 檢查樁端的 GFD 結果
  3722. //if (isPrechargeStatus_gb(gunIndex) > 5 && isPrechargeStatus_gb(gunIndex) < 9) {
  3723. if (sysStatus == S_PREPARING_FOR_EVSE && isPrechargeStatus_gb(gunIndex) >= 6) {
  3724. setChargerMode(gunIndex, MODE_CHARGING);
  3725. }
  3726. // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
  3727. //if (isEvStopCharging_chademo(gunIndex) == YES) {
  3728. // /*+++ 20200908, vern, disable it for DD360 +++*/
  3729. // if ((sysStatus == S_ALARM ||
  3730. // sysStatus == S_TERMINATING) &&
  3731. // strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL
  3732. // ) {
  3733. // strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
  3734. // }
  3735. // /*--- 20200908, vern, disable it for DD360 ---*/
  3736. //}
  3737. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  3738. // GFD 錯誤停止
  3739. RecordAlarmCode(gunIndex, "012236");
  3740. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES;
  3741. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
  3742. } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  3743. // GFD 警告
  3744. //RecordAlarmCode(gunIndex, "012298");
  3745. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  3746. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES;
  3747. }
  3748. else
  3749. {
  3750. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  3751. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
  3752. }
  3753. //else if (sysStatus == S_CHARGING &&
  3754. // isPrechargeStatus_gb(gunIndex) == 10 &&
  3755. // (((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
  3756. // pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
  3757. // (pDcChargingInfo->PresentChargedDuration >= 10 &&
  3758. // pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL))
  3759. // ) {
  3760. // // UVP
  3761. // RecordAlarmCode(gunIndex, "012290");
  3762. // ChargingTerminalProcess(gunIndex);
  3763. //}
  3764. break;
  3765. case _Type_CCS_2:
  3766. // 檢查樁端的 GFD 結果
  3767. if (sysStatus == S_PREPARING_FOR_EVSE &&
  3768. (pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
  3769. pDcChargingInfo->GroundFaultStatus == GFD_WARNING)
  3770. ) {
  3771. setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP0);
  3772. }
  3773. // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
  3774. //if (isEvStopCharging_chademo(gunIndex) == YES) {
  3775. // /*+++ 20200908, vern, disable it for DD360 +++*/
  3776. // if ((sysStatus == S_ALARM ||
  3777. // sysStatus == S_TERMINATING) &&
  3778. // (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
  3779. // ) {
  3780. // strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
  3781. // }
  3782. // /*--- 20200908, vern, disable it for DD360 ---*/
  3783. //}
  3784. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  3785. // GFD 錯誤停止
  3786. RecordAlarmCode(gunIndex, "012235");
  3787. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
  3788. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
  3789. } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  3790. // GFD 警告
  3791. //RecordAlarmCode(gunIndex, "012297");
  3792. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  3793. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES;
  3794. }
  3795. else
  3796. {
  3797. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  3798. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
  3799. }
  3800. //else if (sysStatus == S_CHARGING &&
  3801. // ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
  3802. // pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
  3803. // (pDcChargingInfo->PresentChargedDuration >= 10 &&
  3804. // pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL)
  3805. // ) {
  3806. // // UVP
  3807. // RecordAlarmCode(gunIndex, "012288");
  3808. // ChargingTerminalProcess(gunIndex);
  3809. //}
  3810. break;
  3811. }
  3812. }
  3813. static void checkEvBoardReqStop(uint8_t sysStatus, uint8_t gunIndex)
  3814. {
  3815. uint8_t evBoardStopState = 0;
  3816. if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
  3817. // 板端要求停止 (錯誤)
  3818. if (sysStatus != S_CCS_PRECHARGE_ST0 &&
  3819. sysStatus != S_CCS_PRECHARGE_ST1) {
  3820. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  3821. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
  3822. }
  3823. }
  3824. if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
  3825. ChargingAlarmProcess(gunIndex);
  3826. } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
  3827. ChargingTerminalProcess(gunIndex);
  3828. }
  3829. } else if (isEvBoardNormalStopChargeFlag(gunIndex) == YES) {
  3830. // 板端要求停止 (正常)
  3831. if (sysStatus != S_CCS_PRECHARGE_ST0 &&
  3832. sysStatus != S_CCS_PRECHARGE_ST1) {
  3833. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  3834. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
  3835. }
  3836. }
  3837. ChargingTerminalProcess(gunIndex);
  3838. } else if (OcppRemoteStop(gunIndex) == YES ||
  3839. WifiScheduleStop(gunIndex)) {
  3840. // 後臺要求停止
  3841. ChargingTerminalProcess(gunIndex);
  3842. }
  3843. }
  3844. void showversion()
  3845. {
  3846. uint8_t index = 0;
  3847. log_info("\t========= Charger info ========= ");
  3848. log_info("\tSW Version = %s", fwVersion);
  3849. log_info("\tDebug Version = %s",DebugVersion);
  3850. log_info("\tModelName = %s", pSysConfig->ModelName);
  3851. log_info("\tRelay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
  3852. log_info("\tFan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
  3853. log_info("\tPrimary FW Rev = %s", pSysInfo->CsuPrimFwRev);
  3854. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  3855. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  3856. if (pDcChargingInfo->Type == _Type_Chademo) {
  3857. log_info("\tCHAdeMO[%d] FW Rev = %s",
  3858. pDcChargingInfo->type_index,
  3859. ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
  3860. } else if (pDcChargingInfo->Type == _Type_GB) {
  3861. log_info("\tGBT[%d] FW Rev = %s",
  3862. pDcChargingInfo->type_index,
  3863. ShmGBTData->evse[pDcChargingInfo->type_index].version);
  3864. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3865. log_info("\tCCS[%d] FW Rev = %s",
  3866. pDcChargingInfo->type_index,
  3867. ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
  3868. }
  3869. }
  3870. log_info("\t================================ ");
  3871. }
  3872. void SetNatural300AGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
  3873. {
  3874. deratingByConnOtp->isNeedDerating = YES;
  3875. deratingByConnOtp->deratingTargetCurrent[0] = 5000;
  3876. deratingByConnOtp->deratingTargetCurrent[1] = 3000;
  3877. deratingByConnOtp->deratingTargetCurrent[2] = 1000;
  3878. deratingByConnOtp->deratingTargetCurrent[3] = 0;
  3879. deratingByConnOtp->deratingTargetCurrent[4] = 0;
  3880. }
  3881. void SetLiquidCoolGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
  3882. {
  3883. deratingByConnOtp->isNeedDerating = YES;
  3884. deratingByConnOtp->deratingTargetCurrent[0] = 5000;
  3885. deratingByConnOtp->deratingTargetCurrent[1] = 4000;
  3886. deratingByConnOtp->deratingTargetCurrent[2] = 3000;
  3887. deratingByConnOtp->deratingTargetCurrent[3] = 0;
  3888. deratingByConnOtp->deratingTargetCurrent[4] = 0;
  3889. }
  3890. void SetCHAdeMoTypeKOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
  3891. {
  3892. deratingByConnOtp->isNeedDerating = YES;
  3893. deratingByConnOtp->deratingTargetRate[0] = 1;
  3894. deratingByConnOtp->deratingTargetRate[1] = 0.8;
  3895. deratingByConnOtp->deratingTargetRate[2] = 0.8;
  3896. deratingByConnOtp->deratingTargetRate[3] = 0;
  3897. deratingByConnOtp->deratingTargetRate[4] = 0;
  3898. memset(&deratingByConnOtp->deratingTargetCurrent[0], 0, sizeof(deratingByConnOtp->deratingTargetCurrent));
  3899. }
  3900. void SetCHAdeMoTypeSJOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
  3901. {
  3902. deratingByConnOtp->isNeedDerating = YES;
  3903. deratingByConnOtp->deratingTargetCurrent[0] = 2000;
  3904. deratingByConnOtp->deratingTargetCurrent[1] = 1250;
  3905. deratingByConnOtp->deratingTargetCurrent[2] = 1250;
  3906. deratingByConnOtp->deratingTargetCurrent[3] = 0;
  3907. deratingByConnOtp->deratingTargetCurrent[4] = 0;
  3908. }
  3909. void SetCHAdeMoTypeOOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
  3910. {
  3911. deratingByConnOtp->isNeedDerating = YES;
  3912. deratingByConnOtp->deratingTargetCurrent[0] = 3500;
  3913. deratingByConnOtp->deratingTargetCurrent[1] = 2000;
  3914. deratingByConnOtp->deratingTargetCurrent[2] = 2000;
  3915. deratingByConnOtp->deratingTargetCurrent[3] = 0;
  3916. deratingByConnOtp->deratingTargetCurrent[4] = 0;
  3917. }
  3918. static void SetGunTypeOTPValue(void)
  3919. {
  3920. //struct ChargingInfoData* chargingData_2 = NULL;
  3921. uint8_t Gun1Type = 0;
  3922. uint8_t Gun2Type = 0;
  3923. uint8_t Type;
  3924. int i,cnt;
  3925. if (pSysConfig->TotalConnectorCount == 1) {
  3926. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(0);
  3927. Gun1Type = pSysConfig->ModelName[7];
  3928. Gun2Type = pSysConfig->ModelName[7];
  3929. switch (Gun1Type) {
  3930. case 'K':
  3931. SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3932. break;
  3933. case 'S':
  3934. SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3935. break;
  3936. case 'I':
  3937. case 'Q':
  3938. SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3939. break;
  3940. case 'O':
  3941. SetCHAdeMoTypeOOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3942. break;
  3943. // 水冷
  3944. case 'V':
  3945. case 'F':
  3946. SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3947. break;
  3948. default:
  3949. pDcChargingInfo->deratingByConnOtp.isNeedDerating = NO;
  3950. }
  3951. if (pDcChargingInfo->deratingByConnOtp.isNeedDerating) {
  3952. log_info("------------ Gun0 - Type:%c Derating info (OTP)-----------", Gun1Type);
  3953. if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[0] != 0) {
  3954. for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
  3955. if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt] != 0) {
  3956. log_info(" (Pwr) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt]);
  3957. }
  3958. }
  3959. } else if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[0] != 0) {
  3960. for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
  3961. if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt] != 0) {
  3962. log_info(" (Cur) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt]);
  3963. }
  3964. }
  3965. }
  3966. }
  3967. } else if (pSysConfig->TotalConnectorCount == 2) {
  3968. Gun1Type = pSysConfig->ModelName[7];
  3969. Gun2Type = pSysConfig->ModelName[9];
  3970. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  3971. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
  3972. switch (i == 0 ? Gun1Type : Gun2Type) {
  3973. case 'K':
  3974. SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3975. break;
  3976. case 'S':
  3977. SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3978. break;
  3979. // 風冷300A
  3980. case 'I':
  3981. case 'Q':
  3982. SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3983. break;
  3984. case 'O':
  3985. SetCHAdeMoTypeOOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3986. break;
  3987. // 水冷
  3988. case 'V':
  3989. case 'F':
  3990. SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3991. break;
  3992. default:
  3993. pDcChargingInfo->deratingByConnOtp.isNeedDerating = NO;
  3994. }
  3995. if (pDcChargingInfo->deratingByConnOtp.isNeedDerating) {
  3996. log_info("------------ Gun%d - Type:%c Derating info (OTP)-----------",i, i == 0 ? Gun1Type : Gun2Type);
  3997. if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[0] != 0) {
  3998. for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
  3999. if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt] != 0) {
  4000. log_info(" (Pwr) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt]);
  4001. }
  4002. }
  4003. } else if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[0] != 0) {
  4004. for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
  4005. if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt] != 0) {
  4006. log_info(" (Cur) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt]);
  4007. }
  4008. }
  4009. }
  4010. }
  4011. }
  4012. }
  4013. }
  4014. bool checkGunTempFail(uint8_t gunIndex)
  4015. {
  4016. #ifndef DD360
  4017. return FALSE;
  4018. #endif
  4019. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  4020. switch (pDcChargingInfo->Type) {
  4021. case _Type_Chademo:
  4022. if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail) {
  4023. if (isCharging(pDcChargingInfo->SystemStatus)) {
  4024. RecordAlarmCode(gunIndex,"011018");
  4025. } else {
  4026. setChargerMode(gunIndex,S_FAULT);
  4027. }
  4028. return TRUE;
  4029. }
  4030. break;
  4031. case _Type_CCS_2:
  4032. if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail) {
  4033. if (isCharging(pDcChargingInfo->SystemStatus)) {
  4034. RecordAlarmCode(gunIndex,"011019");
  4035. } else {
  4036. setChargerMode(gunIndex,S_FAULT);
  4037. }
  4038. return TRUE;
  4039. }
  4040. break;
  4041. case _Type_GB:
  4042. if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail) {
  4043. if (isCharging(pDcChargingInfo->SystemStatus)) {
  4044. RecordAlarmCode(gunIndex,"011020");
  4045. } else {
  4046. setChargerMode(gunIndex,S_FAULT);
  4047. }
  4048. return TRUE;
  4049. }
  4050. break;
  4051. }
  4052. return FALSE;
  4053. }
  4054. //==========================================
  4055. // Ocmf
  4056. //==========================================
  4057. void ConfigOcmfInfo(uint8_t gun_index)
  4058. {
  4059. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
  4060. strncpy((char *)pSysInfo->DcMeterTransactionAction[gun_index].head.evseId,
  4061. (char *)pSysConfig->SerialNumber, ARRAY_SIZE(pSysConfig->SerialNumber));
  4062. char trId[32];
  4063. sprintf(trId, "%d", ShmSelectGunInfo->PricesInfo[gun_index].TransactionId);
  4064. memcpy((char *)pSysInfo->DcMeterTransactionAction[gun_index].head.transactionId, trId,
  4065. sizeof(trId));
  4066. char clientId[32] = "DC_Charger";
  4067. memcpy((char *)pSysInfo->DcMeterTransactionAction[gun_index].head.clientId, clientId,
  4068. sizeof(clientId));
  4069. pSysInfo->DcMeterTransactionAction[gun_index].head.tariffId = 0;
  4070. pSysInfo->DcMeterTransactionAction[gun_index].head.cableId = 2;
  4071. memcpy((char *)pSysInfo->DcMeterTransactionAction[gun_index].head.userData,
  4072. (char *)pDcChargingInfo->StartUserId,
  4073. sizeof(pDcChargingInfo->StartUserId));
  4074. }
  4075. void ConfigOcmfInfo_Record(int _trID, uint8_t gun_index)
  4076. {
  4077. strncpy((char *)pSysInfo->DcMeterReadTransactionRecord[gun_index].head.evseId,
  4078. (char *)pSysConfig->SerialNumber, ARRAY_SIZE(pSysConfig->SerialNumber));
  4079. char trId[32];
  4080. sprintf(trId, "%d", _trID);
  4081. strcpy((char *)pSysInfo->DcMeterReadTransactionRecord[gun_index].head.transactionId, trId);
  4082. strcpy((char *)pSysInfo->DcMeterReadTransactionRecord[gun_index].head.clientId, "DC_Charger");
  4083. pSysInfo->DcMeterReadTransactionRecord[gun_index].head.tariffId = 0;
  4084. pSysInfo->DcMeterReadTransactionRecord[gun_index].head.cableId = 2;
  4085. strcpy((char *)pSysInfo->DcMeterReadTransactionRecord[gun_index].head.userData, "Record");
  4086. }
  4087. void StoreOcmfFile(uint8_t gun_index,int trid,int isRecord)
  4088. {
  4089. if (ShmDcCommonData->pGunInfo[gun_index].ConnectorID <= 0 || ShmDcCommonData->pGunInfo[gun_index].ConnectorID > 4) {
  4090. log_info("Gun%d ConnectorID:%d",gun_index,ShmDcCommonData->pGunInfo[gun_index].ConnectorID);
  4091. return;
  4092. }
  4093. FILE *pfile;
  4094. char cmd[500];
  4095. sprintf((char*)ShmDcCommonData->pGunInfo[gun_index].OcmfFileName,"/mnt/Gun_%d_%d_OCMF",
  4096. ShmDcCommonData->pGunInfo[gun_index].ConnectorID,trid);
  4097. log_info("OCMF File:%s",ShmDcCommonData->pGunInfo[gun_index].OcmfFileName);
  4098. pfile = fopen(ShmDcCommonData->pGunInfo[gun_index].OcmfFileName,"w+");
  4099. if (isRecord)
  4100. fprintf(pfile,"%s",pSysInfo->DcMeterReadTransactionRecord[gun_index].transactionOCMF);
  4101. else
  4102. fprintf(pfile,"%s",pSysInfo->DcMeterTransactionAction[gun_index].transactionOCMF);
  4103. fclose(pfile);
  4104. sprintf(cmd,"ftpput -u root -p y42j/4cj84 192.168.100.1 %s",ShmDcCommonData->pGunInfo[gun_index].OcmfFileName);
  4105. if (system(cmd) != 0 ) {
  4106. log_info("Put OCMF File to Cabinet Fail");
  4107. sprintf(cmd,"rm -f %s",ShmDcCommonData->pGunInfo[gun_index].OcmfFileName);
  4108. system(cmd);
  4109. } else {
  4110. log_info("Put OCMF File to Cabinet OK");
  4111. ShmDcCommonData->pGunInfo[gun_index].SendOcmfDataReq = TRUE;
  4112. }
  4113. }
  4114. void ChkOcmfRecord(uint8_t gun_index)
  4115. {
  4116. if (pAlarmCode->AlarmEvents.bits.Meter1CommTimeout) {
  4117. return;
  4118. }
  4119. int trid = DB_Get_OcmfTrid(gun_index);
  4120. if (trid != 0 &&
  4121. trid != ShmDcCommonData->ocmfTridRecord[gun_index] &&
  4122. trid != ShmSelectGunInfo->PricesInfo[gun_index].TransactionId)
  4123. {
  4124. ShmDcCommonData->ocmfTridRecord[gun_index] = trid;
  4125. ConfigOcmfInfo_Record(ShmDcCommonData->ocmfTridRecord[gun_index], gun_index);
  4126. pSysInfo->DcMeterReadTransactionRecord[gun_index].ActionCmd = _DC_METER_TRANSACTION_ACTION_START;
  4127. }
  4128. if (pSysInfo->DcMeterReadTransactionRecord[gun_index].OcmfInfoReady == _OCMF_INFO_READY_YES &&
  4129. ShmDcCommonData->pGunInfo[gun_index].SendOcmfDataReq == FALSE)
  4130. {
  4131. log_info("OCMF Record - Reture Pass \n");
  4132. pSysInfo->DcMeterReadTransactionRecord[gun_index].OcmfInfoReady = _OCMF_INFO_READY_NO;
  4133. //ocpp_ocmf_information(gun_index);
  4134. DB_Update_ocmf_Record(gun_index, ShmDcCommonData->ocmfTridRecord[gun_index], true);
  4135. StoreOcmfFile(gun_index,trid,TRUE);
  4136. //ShmDcCommonData->ocmfTridRecord[gun_index] = 0;
  4137. }
  4138. else if (pSysInfo->DcMeterReadTransactionRecord[gun_index].OcmfInfoReady == _OCMF_INFO_READY_FAIL)
  4139. {
  4140. log_info("OCMF Record - Reture Fail \n");
  4141. pSysInfo->DcMeterReadTransactionRecord[gun_index].OcmfInfoReady = _OCMF_INFO_READY_NO;
  4142. DB_Update_ocmf_Record(gun_index, ShmDcCommonData->ocmfTridRecord[gun_index], false);
  4143. //ShmDcCommonData->ocmfTridRecord[gun_index] = 0;
  4144. }
  4145. }
  4146. void SetGunMeterCableLoss()
  4147. {
  4148. if (pSysConfig->TotalConnectorCount >= 2) {
  4149. if (pSysConfig->ModelName[7] == 'V' || pSysConfig->ModelName[7] == 'F') {
  4150. pSysInfo->DcMeterTransactionAction[LEFT_GUN_NUM].head.cableId = 3;
  4151. }
  4152. if (pSysConfig->ModelName[9] == 'V' || pSysConfig->ModelName[9] == 'F') {
  4153. pSysInfo->DcMeterTransactionAction[RIGHT_GUN_NUM].head.cableId = 3;
  4154. }
  4155. } else if (pSysConfig->TotalConnectorCount == 1){
  4156. if (pSysConfig->ModelName[7] == 'V' || pSysConfig->ModelName[7] == 'F' ||
  4157. pSysConfig->ModelName[9] == 'V' || pSysConfig->ModelName[9] == 'F') {
  4158. pSysInfo->DcMeterTransactionAction[LEFT_GUN_NUM].head.cableId = 3;
  4159. }
  4160. }
  4161. }
  4162. int main(void)
  4163. {
  4164. bool isModelNameMatch = true;
  4165. uint8_t isRessign = 0;
  4166. uint8_t evBoardStopState = 0;
  4167. uint8_t _ocppProfileChkFlag;
  4168. uint8_t gunIndex = 0;
  4169. uint8_t _isStop[2] = {0};
  4170. float powerconsumption;
  4171. uint8_t ConnectID[2];
  4172. uint8_t SendOcmfDataReq[2];
  4173. if (CreateAllCsuShareMemory() == FAIL) {
  4174. log_error("create share memory error");
  4175. return FAIL;
  4176. }
  4177. ClearAllShmMemParameter();
  4178. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  4179. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  4180. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  4181. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  4182. pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
  4183. pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
  4184. ShmPsuData = (struct PsuData *)GetShmPsuData();
  4185. ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  4186. ShmGBTData = (struct GBTData *)GetShmGBTData();
  4187. ShmCcsData = (struct CcsData *)GetShmCcsData();
  4188. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  4189. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  4190. ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  4191. ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
  4192. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  4193. ShmOCPP20Data = (struct OCPP20Data*)GetShmOCPP20Data();
  4194. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  4195. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  4196. ShmSysConfigAndInfo = (struct SysConfigAndInfo *)GetShmSysConfigAndInfo();
  4197. ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();
  4198. log_info(" ********************************************************");
  4199. log_info(" ****************** FileSystem Boot up *****************");
  4200. log_info(" ********************************************************");
  4201. #if defined DD360
  4202. log_info(" ****************** Project:DD360 *********************");
  4203. #elif defined DD360Audi
  4204. log_info(" ****************** Project:DD360Audi *****************");
  4205. #elif defined DD360ComBox
  4206. log_info(" ****************** Project:DD360ComBox ***************");
  4207. #endif
  4208. log_info(" ********************************************************");
  4209. if (!InitialSystemDefaultConfig()) {
  4210. log_error("InitialSystemDefaultConfig NG ");
  4211. //StopProcessingLoop();
  4212. sleep(5);
  4213. system("reboot -f");
  4214. }
  4215. CheckGunTypeFromHw();
  4216. CheckIsAlternatvieByModelName();
  4217. InitialShareMemoryInfo();
  4218. GetFirmwareVersion();
  4219. ChangeLcmByIndex(_LCM_INIT);
  4220. if (!CheckConnectorTypeStatus()) {
  4221. isModelNameMatch = false;
  4222. }
  4223. Initialization();
  4224. SpawnTask();
  4225. log_info("Spawned all Task");
  4226. if (!isModelNameMatch) {
  4227. pAlarmCode->AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
  4228. ChangeLcmByIndex(_LCM_FIX);
  4229. // Module Name 與硬體對應不正確
  4230. log_error("Module Name & HW info none match. ");
  4231. sleep(3);
  4232. KillAllTask();
  4233. StopProcessingLoop();
  4234. }
  4235. CreateTimeoutFork();
  4236. log_info("Start self test... ");
  4237. PrimaryLedIndicatorCtrlFork();
  4238. ChangeLcmByIndex(_LCM_FIX);
  4239. SelfTestRun();
  4240. StopSystemTimeoutDet();
  4241. log_info("Self test finished : SelfTestSeq = %d, Work_Step = %d ",
  4242. pSysInfo->SelfTestSeq,
  4243. ShmPsuData->Work_Step);
  4244. if (pSysInfo->SelfTestSeq == _STEST_FAIL ||
  4245. ShmPsuData->Work_Step == _NO_WORKING ||
  4246. pInfoCode->InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES //DS60-120 add
  4247. ) {
  4248. /*
  4249. if (pSysWarning->Level != WARN_LV_ER) {
  4250. if (!DisplaySelfTestFailReason()) { //DS60-120 add
  4251. log_info("Soft reboot for retry self-tets. ");
  4252. sleep(3);
  4253. system("killall OcppBackend &");
  4254. KillAllTask();
  4255. system("/usr/bin/run_evse_restart.sh");
  4256. }
  4257. }
  4258. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4259. setChargerMode(gunIndex, MODE_ALARM);
  4260. }
  4261. //ChangeLcmByIndex(_LCM_FIX);
  4262. sleep(3);
  4263. if (pSysWarning->Level == WARN_LV_ER) { //DS60-120 add
  4264. KillTaskExceptPrimary();
  4265. } else {
  4266. KillTask();
  4267. }
  4268. StopProcessingLoop();
  4269. */
  4270. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4271. setChargerMode(gunIndex, MODE_MAINTAIN);
  4272. }
  4273. ChangeLcmByIndex(_LCM_FIX);
  4274. } else {
  4275. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4276. setChargerMode(gunIndex, MODE_IDLE);
  4277. }
  4278. }
  4279. // Local DB
  4280. if (DB_Open() != PASS) {
  4281. log_info("DB_Open fail. ");
  4282. isDb_ready = false;
  4283. } else {
  4284. isDb_ready = true;
  4285. for (int _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  4286. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  4287. pDcChargingInfo->IsAvailable = DB_Get_Operactive(_index);
  4288. if (!DB_Get_PowerConsumption(_index)) {
  4289. DB_Insert_PowerConsumption(_index, 0);
  4290. }
  4291. }
  4292. DB_Reboot_Record();
  4293. }
  4294. log_info("===== Create DB End ===== ");
  4295. #if defined DD360Audi
  4296. ChangeLcmByIndex(_LCM_SELECT_GUN);
  4297. #else
  4298. ChangeLcmByIndex(_LCM_IDLE);
  4299. #endif //defined DD360Audi
  4300. sleep(1);
  4301. //***** 須新增的偵測 *****//
  4302. // 1. Thernal - 控制風扇轉速
  4303. // 2. ouput fuse - 控制風扇轉速
  4304. CreateRfidFork();
  4305. // Main loop
  4306. showversion();
  4307. CheckFwSlotStatusLog();
  4308. //AdjustChargerCurrent();
  4309. gettimeofday(&_cmdMainPriority_time, NULL);
  4310. GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
  4311. CheckTaskAlive();
  4312. CreateWatchdog();
  4313. pSysInfo->OTPTemp = GUN_OTP_VALUE;
  4314. pSysInfo->OTPTempR = GUN_OTP_RECOVERY;
  4315. time_t ShowEVStatusTimer[2] = { 0 };
  4316. SetGunTypeOTPValue();
  4317. SetGunMeterCableLoss();
  4318. for (;;) {
  4319. CheckOcppStatus();
  4320. ChkPrimaryStatus();
  4321. if ((IsConnectorWholeIdle() ||
  4322. (pSysInfo->PageIndex == _LCM_FIX)) &&
  4323. (pSysInfo->SystemTimeoutFlag != Timeout_ReturnToChargingGunDet)
  4324. ) {
  4325. CheckFactoryConfigFunction();
  4326. //CheckFwUpdateFunction();
  4327. }
  4328. // OCPP 邏輯
  4329. OcppRemoteStartChk();
  4330. // 讀卡邏輯
  4331. ScannerCardProcess();
  4332. // 當 AC 沒有搭上時,清除一些錯誤碼
  4333. ClearAlarmCodeWhenAcOff();
  4334. // 確認是否要回到充電中的槍畫面邏輯判斷
  4335. CheckReturnToChargingConn();
  4336. //確認Power cabinet PSU Status
  4337. //powerCabinetPsuAlarmStatus();
  4338. if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
  4339. //CheckTask();
  4340. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4341. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  4342. if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
  4343. pDcChargingInfo->SystemStatus <= S_CHARGING) ||
  4344. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  4345. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  4346. if (pDcChargingInfo->SystemStatus == S_CHARGING &&
  4347. _ocppProfileChkFlag == 12) {
  4348. ChargingProfileFlat(gunIndex);
  4349. _ocppProfileChkFlag = 0;
  4350. } else if (pDcChargingInfo->SystemStatus != S_CHARGING) {
  4351. ChargingProfileFlat(gunIndex);
  4352. _ocppProfileChkFlag = 0;
  4353. } else {
  4354. _ocppProfileChkFlag++;
  4355. }
  4356. }
  4357. checkGunOTPState(gunIndex); //check gun OTP
  4358. // OCMF
  4359. ChkOcmfRecord(gunIndex);
  4360. }
  4361. gettimeofday(&_cmdMainPriority_time, NULL);
  4362. }
  4363. // 確認當前錯誤 Level = 2 ?
  4364. ReviewCriticalAlarm();
  4365. gEvBoardErr.GunErrMessage = 0; //清除系統執行中的錯誤訊息
  4366. gChillerTempErr.TempErrMsg = 0;//清除系統執行中的錯誤訊息
  4367. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4368. // 重新收集各槍的錯誤狀態
  4369. collectError(gunIndex);
  4370. }
  4371. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4372. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  4373. // convert common status code to alarm event
  4374. checkEvBoardAlarmState(pDcChargingInfo->Type);
  4375. }
  4376. checkChillerAlarmState();
  4377. //log_info("MeterCommTimeout:%d",pAlarmCode->AlarmEvents.bits.MeterCommTimeout);
  4378. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4379. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  4380. autoStartCharging(gunIndex);
  4381. CheckGpioInStatus();
  4382. CheckErrorOccurStatus(gunIndex);
  4383. // 確認 Relay Welding or Driving Fault
  4384. CheckRelayWeldingOrDrivingFault(gunIndex);
  4385. ChkOcppStatus(gunIndex);
  4386. if (pGunIndexInfo->AcGunIndex > 0 &&
  4387. isDetectPlugin(gunIndex) &&
  4388. !GetIsCardScan() &&
  4389. gunIndex == pSysInfo->CurGunSelected) {
  4390. // AUDI_LCM_CHANGE
  4391. pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
  4392. }
  4393. if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
  4394. pDcChargingInfo->SystemStatus <= S_CHARGING) ||
  4395. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  4396. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  4397. CheckSmartChargeProfile(gunIndex);
  4398. }
  4399. checkGunTempFail(gunIndex);
  4400. if (pSysInfo->SelfTestSeq == _STEST_FAIL ) {
  4401. setChargerMode(gunIndex, MODE_MAINTAIN);
  4402. ChangeLcmByIndex(_LCM_FIX);
  4403. }
  4404. switch (pDcChargingInfo->SystemStatus) {
  4405. case S_IDLE:
  4406. case S_RESERVATION:
  4407. if (isModeChange(gunIndex)) {
  4408. if (pDcChargingInfo->SystemStatus == S_IDLE)
  4409. log_info("============================= S_IDLE(%x) ============================= ", gunIndex);
  4410. else if (pDcChargingInfo->SystemStatus == S_RESERVATION) {
  4411. log_info("============================= S_RESERVATION(%x) ============================= ", gunIndex);
  4412. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
  4413. }
  4414. pDcChargingInfo->PresentChargedDuration = 0;
  4415. pDcChargingInfo->RemainChargingDuration = 0;
  4416. pDcChargingInfo->PresentChargingVoltage = 0;//DS60-120 add
  4417. pDcChargingInfo->PresentChargingCurrent = 0;//DS60-120 add
  4418. strcpy((char *)pDcChargingInfo->StartDateTime, "");
  4419. strcpy((char *)pDcChargingInfo->StopDateTime, "");
  4420. strcpy((char *)pDcChargingInfo->StartUserId, "");
  4421. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "");
  4422. if (pDcChargingInfo->deratingByConnOtp.deratingIndex != 0) {
  4423. pDcChargingInfo->deratingByConnOtp.deratingIndex = 0;
  4424. }
  4425. ShmDcCommonData->ocmfTridRecord[gunIndex] = 0 ;
  4426. _isStop[gunIndex] = 0;
  4427. //Jerry add
  4428. memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
  4429. powerconsumption = ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption;
  4430. ConnectID[gunIndex] = ShmDcCommonData->pGunInfo[gunIndex].ConnectorID;
  4431. SendOcmfDataReq[gunIndex] = ShmDcCommonData->pGunInfo[gunIndex].SendOcmfDataReq;
  4432. memset(&ShmDcCommonData->pGunInfo[gunIndex], 0, sizeof(GunInfo));
  4433. ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption = powerconsumption;
  4434. ShmDcCommonData->pGunInfo[gunIndex].ConnectorID = ConnectID[gunIndex];
  4435. ShmDcCommonData->pGunInfo[gunIndex].SendOcmfDataReq = SendOcmfDataReq[gunIndex];
  4436. ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
  4437. destroySelGun(gunIndex);
  4438. ResetDetAlarmStatus(gunIndex); //recovery OVP status code
  4439. if (ShmSelectGunInfo->AuthorStateFromCabinet[gunIndex] == YES) {
  4440. ShmSelectGunInfo->AuthorStateFromCabinet[gunIndex] = NO;
  4441. }
  4442. //strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "");
  4443. ReleaseAlarmCode(gunIndex);
  4444. }
  4445. if (pDcChargingInfo->IsAvailable == NO) {
  4446. setChargerMode(gunIndex, MODE_MAINTAIN);
  4447. }
  4448. case S_FAULT:
  4449. if (isModeChange(gunIndex)) {
  4450. log_info("============================= S_FAULT(%x) ============================= ", gunIndex);
  4451. }
  4452. if (pSysWarning->Level == WARN_LV_ER) {
  4453. struct ChargingInfoData *pSelectedDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  4454. if (gunIndex == pSysInfo->CurGunSelected) {
  4455. pSysInfo->SystemPage = _LCM_FIX;
  4456. } else if (pSelectedDcChargingInfo->SystemStatus != S_IDLE &&
  4457. pSelectedDcChargingInfo->SystemStatus != S_RESERVATION &&
  4458. pSelectedDcChargingInfo->SystemStatus != S_MAINTAIN &&
  4459. pSelectedDcChargingInfo->SystemStatus != S_FAULT) {
  4460. if (pSelectedDcChargingInfo->SystemStatus == S_CHARGING) {
  4461. pSysInfo->SystemPage = _LCM_COMPLETE;
  4462. } else {
  4463. systemPageRestoreInit();
  4464. }
  4465. }
  4466. ClearDetectPluginFlag(gunIndex);
  4467. if (pDcChargingInfo->SystemStatus != S_FAULT)
  4468. {
  4469. UpdateErrorCodeToOcpp(gunIndex);
  4470. setChargerMode(gunIndex, MODE_FAULT);
  4471. }
  4472. continue;
  4473. }
  4474. if (checkGunTempFail(gunIndex)) {
  4475. continue;
  4476. }
  4477. if (pDcChargingInfo->SystemStatus == S_FAULT) {
  4478. systemPageRestoreInit();
  4479. setChargerMode(gunIndex, MODE_IDLE);
  4480. }
  4481. isChargingAverageState();
  4482. if (PrecheckIsPass(gunIndex) == false) {
  4483. log_error("Relay welding");
  4484. setChargerMode(gunIndex, MODE_FAULT);
  4485. if (gunIndex == pSysInfo->CurGunSelected) {
  4486. pSysInfo->SystemPage = _LCM_FIX;
  4487. }
  4488. continue;
  4489. }
  4490. if (pDcChargingInfo->SystemStatus == S_FAULT) {
  4491. pSysInfo->SystemPage = _LCM_NONE;
  4492. setChargerMode(gunIndex, MODE_IDLE);
  4493. }
  4494. if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
  4495. if (pSysInfo->CurGunSelected == gunIndex) {
  4496. connectorPageRestoreIdle();
  4497. }
  4498. continue;
  4499. }
  4500. // Idle 正常程序起點
  4501. // 判斷是否有啟用檢查插槍
  4502. if (isDetectPlugin(gunIndex)) {
  4503. StartGunInfoTimeoutDet(gunIndex, Timeout_WaitPlug);
  4504. // 卡號驗證成功後,等待充電槍插入充電車
  4505. if (pDcChargingInfo->RemoteStartFlag == YES) {
  4506. if (pDcChargingInfo->ConnectorPlugIn == YES &&
  4507. pDcChargingInfo->IsAvailable) {
  4508. log_info("-----------------1----------------- %d ", gunIndex);
  4509. pDcChargingInfo->RemoteStartFlag = NO;
  4510. pDcChargingInfo->isRemoteStart = YES; //DS60-120
  4511. ChangeGunSelectByIndex(gunIndex);
  4512. AddPlugInTimes(gunIndex);
  4513. setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
  4514. strcpy((char *)pDcChargingInfo->StartUserId, "");
  4515. ClearDetectPluginFlag(gunIndex);
  4516. StopGunInfoTimeoutDet(gunIndex);
  4517. pDcChargingInfo->StartMethod = _CHARGING_START_REMOTESTART;
  4518. continue;
  4519. }
  4520. } else if (pSysInfo->OrderCharging == NO_DEFINE) {
  4521. if (pDcChargingInfo->ConnectorPlugIn == YES &&
  4522. pDcChargingInfo->IsAvailable &&
  4523. (pDcChargingInfo->SystemStatus == S_IDLE ||
  4524. pDcChargingInfo->SystemStatus == S_RESERVATION) &&
  4525. //waitSelectGunPlugIt(gunIndex)
  4526. (waitRightGunPlugIt(gunIndex) == PASS ||
  4527. waitLeftGunPlugIt(gunIndex) == PASS) ) {
  4528. if (pDcChargingInfo->SystemStatus == S_RESERVATION) {
  4529. if (strcmp((char*)pSysConfig->UserId, (char*)ShmDcCommonData->pGunInfo[gunIndex].ReservationID) != EQUAL) {
  4530. //log_info("Not Resercation ID");
  4531. continue;
  4532. }
  4533. }
  4534. log_info("-----------------2----------------- ");
  4535. ChangeGunSelectByIndex(gunIndex);
  4536. AddPlugInTimes(gunIndex);
  4537. strcpy((char *)pDcChargingInfo->StartUserId, (char *)pSysConfig->UserId);
  4538. log_info("index = %d, CardNumber = %s ",
  4539. gunIndex,
  4540. pDcChargingInfo->StartUserId);
  4541. strcpy((char *)pSysConfig->UserId, "");
  4542. ShmDcCommonData->AuthroizeType = IdTokenType_Central;
  4543. // 當前操作的槍號,進入 Preparing
  4544. setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
  4545. ClearDetectPluginFlag(LEFT_GUN_NUM);
  4546. ClearDetectPluginFlag(RIGHT_GUN_NUM);
  4547. StopGunInfoTimeoutDet(LEFT_GUN_NUM);
  4548. StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
  4549. if (pDcChargingInfo->StartMethod != _CHARGING_START_AUTOSTART)
  4550. pDcChargingInfo->StartMethod = _CHARGING_START_RFID;
  4551. continue;
  4552. }
  4553. }
  4554. if (isDetectPlugin(gunIndex) && pSysInfo->CurGunSelected == gunIndex) {
  4555. // LCM => Waiting for plugging
  4556. // AUDI_LCM_CHANGE
  4557. pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
  4558. }
  4559. } else if (pSysConfig->isAuthrizeByEVCCID && pDcChargingInfo->ConnectorPlugIn &&
  4560. pSysInfo->CurGunSelected == gunIndex && !pDcChargingInfo->isEVCCIDVerify) {
  4561. systemPageRestoreInit();
  4562. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4563. continue;
  4564. } else {
  4565. if (pSysInfo->CurGunSelected == gunIndex) {
  4566. connectorPageRestoreIdle();
  4567. }
  4568. }
  4569. break;
  4570. case S_REASSIGN_CHECK: {
  4571. if (isModeChange(gunIndex)) {
  4572. log_info("============================= S_REASSIGN_CHECK(%x) ============================= ", gunIndex);
  4573. systemPageRestoreInit();
  4574. if (pSysInfo->OrderCharging != NO_DEFINE) {
  4575. pSysInfo->OrderCharging = NO_DEFINE;
  4576. }
  4577. StopSystemTimeoutDet();
  4578. gettimeofday(&pDcChargingInfo->PreChargeTimer, NULL);
  4579. }
  4580. setChargerMode(gunIndex, S_PREPARNING);
  4581. if (pSysInfo->CurGunSelected == gunIndex) {
  4582. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4583. }
  4584. #ifdef DD360Audi
  4585. pDcChargingInfo->Replug_flag = true;
  4586. #endif
  4587. }
  4588. break;
  4589. case S_PREPARNING:
  4590. if (isModeChange(gunIndex)) {
  4591. log_info("============================= S_PREPARNING(%x) ============================= ", gunIndex);
  4592. StopGunInfoTimeoutDet(gunIndex);
  4593. StartGunInfoTimeoutDet(gunIndex, Timeout_Preparing);
  4594. }
  4595. if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
  4596. ShmPsuData->SystemAvailablePower > 10 &&
  4597. GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 3000000) {
  4598. setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
  4599. }
  4600. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  4601. if (pSysInfo->CurGunSelected == gunIndex) {
  4602. systemPageRestoreInit();
  4603. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4604. }
  4605. break;
  4606. case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
  4607. if (isModeChange(gunIndex)) {
  4608. log_info("============================= S_PREPARING_FOR_EV(%x) ============================= ", gunIndex);
  4609. //strcpy((char *)pSysConfig->UserId, "");
  4610. StopGunInfoTimeoutDet(gunIndex);
  4611. StartGunInfoTimeoutDet(gunIndex, Timeout_EvChargingDet);
  4612. }
  4613. if (pDcChargingInfo->Type == _Type_Chademo) {
  4614. // 檢查車端的槍鎖是否為鎖上
  4615. if (isEvGunLocked_chademo(gunIndex) == YES) {
  4616. if (pSysConfig->ModelName[3] == 'P')
  4617. {
  4618. ConfigOcmfInfo(gunIndex);
  4619. DB_Insert_ocmf(gunIndex);
  4620. //pSysInfo->DcMeterTransactionAction[gunIndex].head.cableId = 3;
  4621. pSysInfo->DcMeterTransactionAction[gunIndex].ActionCmd = _DC_METER_TRANSACTION_ACTION_START;
  4622. }
  4623. setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
  4624. }
  4625. } else if (pDcChargingInfo->Type == _Type_GB) {
  4626. // 檢查車端的 charging enable 是否為 1
  4627. if (isEvGunLocked_gb(gunIndex) == YES) {
  4628. if (pSysConfig->ModelName[3] == 'P')
  4629. {
  4630. ConfigOcmfInfo(gunIndex);
  4631. DB_Insert_ocmf(gunIndex);
  4632. //pSysInfo->DcMeterTransactionAction[gunIndex].head.cableId = 3;
  4633. pSysInfo->DcMeterTransactionAction[gunIndex].ActionCmd = _DC_METER_TRANSACTION_ACTION_START;
  4634. }
  4635. setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
  4636. }
  4637. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  4638. // 檢查車端的 charging enable 是否為 1
  4639. if (isEvGunLocked_ccs(gunIndex) == YES) {
  4640. if (pSysConfig->ModelName[3] == 'P')
  4641. {
  4642. ConfigOcmfInfo(gunIndex);
  4643. DB_Insert_ocmf(gunIndex);
  4644. //pSysInfo->DcMeterTransactionAction[gunIndex].head.cableId = 3;
  4645. pSysInfo->DcMeterTransactionAction[gunIndex].ActionCmd = _DC_METER_TRANSACTION_ACTION_START;
  4646. }
  4647. setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
  4648. }
  4649. }
  4650. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  4651. // LCM => Pre-charging
  4652. if (pSysInfo->CurGunSelected == gunIndex) {
  4653. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4654. }
  4655. break;
  4656. case S_PREPARING_FOR_EVSE: // Ground fault test, 等待 Relay Board 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
  4657. if (isModeChange(gunIndex)) {
  4658. log_info("============================= S_PREPARING_FOR_EVSE(%x) ============================= ", gunIndex);
  4659. StopGunInfoTimeoutDet(gunIndex);
  4660. StartGunInfoTimeoutDet(gunIndex, Timeout_EvseChargingDet);
  4661. if (pSysConfig->ModelName[3] == 'P') {
  4662. ShmDcCommonData->pGunInfo[gunIndex].isMeterStart = TRUE;
  4663. ShmDcCommonData->ocmfTridRecord[gunIndex] = ShmSelectGunInfo->PricesInfo[gunIndex].TransactionId;
  4664. }
  4665. }
  4666. checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
  4667. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  4668. // LCM => Pre-charging
  4669. if (pSysInfo->CurGunSelected == gunIndex) {
  4670. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4671. }
  4672. break;
  4673. case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
  4674. if (isModeChange(gunIndex)) {
  4675. log_info("============================= S_CHARGING(%x) ============================= ", gunIndex);
  4676. StopGunInfoTimeoutDet(gunIndex);
  4677. ftime(&startChargingTime[gunIndex]);
  4678. strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, ""); //DS60-120 add
  4679. ChangeStartOrStopDateTime(YES, gunIndex);
  4680. OcppStartTransation(gunIndex);
  4681. }
  4682. if (ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf) {
  4683. ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf = NO;
  4684. }
  4685. ftime(&endChargingTime[gunIndex]);
  4686. pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
  4687. checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
  4688. if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime) >= 5) {
  4689. ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime = time((time_t*)NULL);
  4690. if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
  4691. DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
  4692. }
  4693. if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
  4694. // 板端要求停止 (錯誤)
  4695. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  4696. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
  4697. }
  4698. //printf("%d evBoardStopState = %d", gunIndex, evBoardStopState);
  4699. if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
  4700. ChargingAlarmProcess(gunIndex);
  4701. } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
  4702. ChargingTerminalProcess(gunIndex);
  4703. }
  4704. } else if (isEvBoardNormalStopChargeFlag(gunIndex) == YES) {
  4705. // 板端要求停止 (正常)
  4706. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  4707. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
  4708. }
  4709. ChargingTerminalProcess(gunIndex);
  4710. } else if (OcppRemoteStop(gunIndex) == YES ||
  4711. WifiScheduleStop(gunIndex) ||
  4712. CheckBackendChargingTimeout(gunIndex) ||
  4713. CheckBackendChargingEnergy(gunIndex) ||
  4714. strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
  4715. // 後臺要求停止
  4716. ChargingTerminalProcess(gunIndex);
  4717. }
  4718. // LCM => Charging
  4719. if (pSysInfo->CurGunSelected == gunIndex) {
  4720. pSysInfo->ConnectorPage = _LCM_CHARGING;
  4721. }
  4722. #ifdef DD360Audi
  4723. pDcChargingInfo->Replug_flag = false;
  4724. #endif
  4725. break;
  4726. case S_ALARM:
  4727. case S_TERMINATING:
  4728. if (isModeChange(gunIndex)) {
  4729. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  4730. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
  4731. }
  4732. if (pDcChargingInfo->SystemStatus == S_ALARM) {
  4733. log_info("============================= S_ALARM(%x) ============================= ", gunIndex);
  4734. UpdateErrorCodeToOcpp(gunIndex);
  4735. if (strcmp((char *)pDcChargingInfo->StartDateTime, "") != EQUAL) {
  4736. OcppStopTransation(gunIndex);
  4737. }
  4738. TheEndCharging(gunIndex);
  4739. } else {
  4740. log_info("============================= S_TERMINATING(%x) ============================= ", gunIndex);
  4741. }
  4742. //log_info ("terminating......................... %x ", gunIndex);
  4743. StopGunInfoTimeoutDet(gunIndex);
  4744. ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime = time((time_t*)NULL);
  4745. if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
  4746. DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
  4747. }
  4748. //checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
  4749. if (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'P' && ShmDcCommonData->pGunInfo[gunIndex].isMeterStart &&
  4750. pDcChargingInfo->RelayK1K2Status == NO && !_isStop[gunIndex]) {
  4751. pSysInfo->DcMeterTransactionAction[gunIndex].ActionCmd = _DC_METER_TRANSACTION_ACTION_STOP;
  4752. log_info("Gun%d Stop Dc Meter Transcation",gunIndex);
  4753. _isStop[gunIndex] = TRUE;
  4754. }
  4755. if (pDcChargingInfo->SystemStatus == S_ALARM) {
  4756. if (pDcChargingInfo->ConnectorPlugIn == NO &&
  4757. GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 10000000) {
  4758. if (ShmDcCommonData->pGunInfo[gunIndex].ReservationStatus) {
  4759. setChargerMode(gunIndex, MODE_RESERVATION);
  4760. } else {
  4761. setChargerMode(gunIndex, MODE_IDLE);
  4762. }
  4763. }
  4764. } else {
  4765. if (pDcChargingInfo->Type == _Type_Chademo) {
  4766. if (isEvStopCharging_chademo(gunIndex) == YES ||
  4767. isPrechargeStatus_chademo(gunIndex) <= 0) {
  4768. setChargerMode(gunIndex, MODE_COMPLETE);
  4769. }
  4770. } else if (pDcChargingInfo->Type == _Type_GB) {
  4771. if (isEvStopCharging_gb(gunIndex) == YES ||
  4772. isPrechargeStatus_gb(gunIndex) <= 0) {
  4773. setChargerMode(gunIndex, MODE_COMPLETE);
  4774. }
  4775. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  4776. if (isEvStopCharging_ccs(gunIndex) == YES &&
  4777. (isPrechargeStatus_ccs(gunIndex) >= 53 ||
  4778. isPrechargeStatus_ccs(gunIndex) == 0 ||
  4779. isPrechargeStatus_ccs(gunIndex) == 13 ||
  4780. isPrechargeStatus_ccs(gunIndex) == 14)
  4781. ) {
  4782. setChargerMode(gunIndex, MODE_COMPLETE);
  4783. }
  4784. }
  4785. }
  4786. if (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'P') {
  4787. if (pDcChargingInfo->SystemStatus == S_ALARM && ShmDcCommonData->pGunInfo[gunIndex].isMeterStop &&
  4788. pSysInfo->DcMeterTransactionAction[gunIndex].OcmfInfoReady)
  4789. {
  4790. pSysInfo->DcMeterTransactionAction[gunIndex].OcmfInfoReady = NO;
  4791. DB_Update_ocmf(gunIndex);
  4792. StoreOcmfFile(gunIndex,ShmSelectGunInfo->PricesInfo[gunIndex].TransactionId,FALSE);
  4793. DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
  4794. }
  4795. }
  4796. if (pSysInfo->CurGunSelected == gunIndex) {
  4797. pSysInfo->ConnectorPage = _LCM_COMPLETE;
  4798. }
  4799. break;
  4800. case S_COMPLETE:
  4801. if (isModeChange(gunIndex)) {
  4802. log_info ("============================= S_COMPLETE(%x) ============================= ", gunIndex);
  4803. if (strcmp((char *)pDcChargingInfo->StartDateTime, "") != EQUAL) {
  4804. OcppStopTransation(gunIndex);
  4805. }
  4806. TheEndCharging(gunIndex);
  4807. }
  4808. if (pSysInfo->DcMeterTransactionAction[gunIndex].OcmfInfoReady && ShmDcCommonData->pGunInfo[gunIndex].isMeterStop) {
  4809. pSysInfo->DcMeterTransactionAction[gunIndex].OcmfInfoReady = NO;
  4810. DB_Update_ocmf(gunIndex);
  4811. StoreOcmfFile(gunIndex,ShmSelectGunInfo->PricesInfo[gunIndex].TransactionId,FALSE);
  4812. DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
  4813. }
  4814. if (pDcChargingInfo->ConnectorPlugIn == NO &&
  4815. GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 10000000) {
  4816. if (ShmDcCommonData->pGunInfo[gunIndex].ReservationStatus) {
  4817. setChargerMode(gunIndex, MODE_RESERVATION);
  4818. } else {
  4819. setChargerMode(gunIndex, MODE_IDLE);
  4820. }
  4821. destroySelGun(gunIndex); //Jerry add
  4822. #if defined DD360 || defined DD3660ComBox
  4823. //pSysInfo->SystemPage = _LCM_IDLE;
  4824. connectorPageRestoreIdle();
  4825. #endif
  4826. }
  4827. if (pSysInfo->CurGunSelected == gunIndex) {
  4828. pSysInfo->ConnectorPage = _LCM_COMPLETE;
  4829. }
  4830. break;
  4831. case S_CCS_PRECHARGE_ST0:
  4832. if (isModeChange(gunIndex)) {
  4833. log_info("============================= CCS Precharge Processing 1(%x) ============================= ", gunIndex);
  4834. StopGunInfoTimeoutDet(gunIndex);
  4835. StartGunInfoTimeoutDet(gunIndex, Timeout_ForCcsPrechargeDet);
  4836. }
  4837. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  4838. // GFD 錯誤停止
  4839. RecordAlarmCode(gunIndex, "012235");
  4840. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
  4841. }
  4842. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  4843. // 等待 EV 小板 (CCS) 通知可以開始 Precharge
  4844. // 切換 D+ Relay to Precharge Relay
  4845. if (isPrechargeStatus_ccs(gunIndex) == 39 ||
  4846. isPrechargeStatus_ccs(gunIndex) == 40) {
  4847. if ((pDcChargingInfo->RelayKPK2Status == YES || pDcChargingInfo->PantographFlag == YES) &&
  4848. pDcChargingInfo->PrechargeStatus != PRECHARGE_READY)
  4849. //if (pDcChargingInfo->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
  4850. {
  4851. //log_info("Send precharge ready 1..........%x, status = %d ",
  4852. // gunIndex,
  4853. // isPrechargeStatus_ccs(gunIndex));
  4854. if (isPrechargeStatus_ccs(gunIndex) == 39) {
  4855. log_info("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) ",
  4856. gunIndex,
  4857. isPrechargeStatus_ccs(gunIndex));
  4858. } else if (isPrechargeStatus_ccs(gunIndex) == 40) {
  4859. log_info("Conn %x, Precharge ready, CCS status = PowerDeliveryRequest start (%d) ",
  4860. gunIndex,
  4861. isPrechargeStatus_ccs(gunIndex));
  4862. }
  4863. pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
  4864. }
  4865. } else if (isPrechargeStatus_ccs(gunIndex) == 45 ||
  4866. isPrechargeStatus_ccs(gunIndex) == 46
  4867. ) {
  4868. setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP1);
  4869. }
  4870. if (pSysInfo->CurGunSelected == gunIndex) {
  4871. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4872. }
  4873. break;
  4874. case S_CCS_PRECHARGE_ST1:
  4875. if (isModeChange(gunIndex)) {
  4876. log_info("============================= CCS Precharge Processing 2(%x) ============================= ", gunIndex);
  4877. }
  4878. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  4879. // GFD 錯誤停止
  4880. RecordAlarmCode(gunIndex, "012235");
  4881. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
  4882. }
  4883. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  4884. // 等待小板通知進入充電
  4885. // 切換 D+ Relay to Precharge Relay
  4886. if (pDcChargingInfo->RelayK1K2Status == YES || pDcChargingInfo->PantographFlag == YES) {
  4887. pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
  4888. setChargerMode(gunIndex, MODE_CHARGING);
  4889. }
  4890. if (pSysInfo->CurGunSelected == gunIndex) {
  4891. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4892. }
  4893. break;
  4894. case S_MAINTAIN:
  4895. if (isModeChange(gunIndex)) {
  4896. log_info("============================= S_MAINTAIN(%x) ============================= ", gunIndex);
  4897. //pSysInfo->SystemPage = _PAGE_MAINTAIN;
  4898. if (pSysInfo->FirmwareUpdate == YES) {
  4899. pSysInfo->SystemPage = _PAGE_MAINTAIN;
  4900. continue;
  4901. }
  4902. if (pDcChargingInfo->IsAvailable == NO) {
  4903. log_info("Gun%d is not availbale");
  4904. break;
  4905. }
  4906. if (pSysWarning->Level != WARN_LV_ER) {
  4907. if (!DisplaySelfTestFailReason()) { //DS60-120 add
  4908. log_info("Soft reboot for retry self-tets. ");
  4909. sleep(3);
  4910. KillAllTask();
  4911. system("/usr/bin/run_evse_restart.sh");
  4912. }
  4913. }
  4914. if (pSysWarning->Level == WARN_LV_ER) { //DS60-120 add
  4915. KillTaskExceptPrimary();
  4916. } else {
  4917. KillTask();
  4918. }
  4919. /*
  4920. if (pSysInfo->SelfTestSeq == _STEST_FAIL)
  4921. StopProcessingLoop();
  4922. */
  4923. }
  4924. if (pSysInfo->SelfTestSeq == _STEST_FAIL && pSysInfo->SystemTimeoutFlag != Timeout_SelftestChk) {
  4925. SelfTestRun();
  4926. StopSystemTimeoutDet();
  4927. sleep(3);
  4928. break;
  4929. }
  4930. if (pDcChargingInfo->IsAvailable && pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
  4931. if (pSysWarning->Level == WARN_LV_ER)
  4932. setChargerMode(gunIndex, MODE_FAULT);
  4933. else
  4934. setChargerMode(gunIndex, MODE_IDLE);
  4935. }
  4936. #ifndef DD360Audi
  4937. if (pSysInfo->CurGunSelected == gunIndex) {
  4938. pSysInfo->SystemPage = _PAGE_MAINTAIN;
  4939. }
  4940. #endif
  4941. break;
  4942. }//switch
  4943. TryFeedWatchdog();
  4944. }//for
  4945. #if defined DD360Audi
  4946. if (pSysInfo->SystemPage != _LCM_SELECT_GUN) {
  4947. #else
  4948. if (pSysInfo->SystemPage != _LCM_NONE) {
  4949. #endif //defined DD360Audi
  4950. ChangeLcmByIndex(pSysInfo->SystemPage);
  4951. } else {
  4952. bool dcPageRun = false;
  4953. if (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
  4954. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  4955. if (pAcChargingInfo->SystemStatus == S_IDLE) {
  4956. ChangeLcmByIndex(_LCM_IDLE);
  4957. } else if (pAcChargingInfo->SystemStatus == S_PREPARNING) {
  4958. ChangeLcmByIndex(_LCM_PRE_CHARGE);
  4959. } else if (pAcChargingInfo->SystemStatus == S_CHARGING) {
  4960. ChangeLcmByIndex(_LCM_CHARGING);
  4961. } else if (pAcChargingInfo->SystemStatus == S_TERMINATING ||
  4962. pAcChargingInfo->SystemStatus == S_COMPLETE) {
  4963. ChangeLcmByIndex(_LCM_COMPLETE);
  4964. } else {
  4965. dcPageRun = true;
  4966. }
  4967. } else {
  4968. dcPageRun = true;
  4969. }
  4970. if (dcPageRun) {
  4971. ChangeLcmByIndex(pSysInfo->ConnectorPage);
  4972. }
  4973. }
  4974. //for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4975. // pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  4976. // checkEvBoardAlarmState(pDcChargingInfo->Type);
  4977. // checkChillerAlarmState();
  4978. // //if (checkChillerAlarmState(gunIndex) == ABNORMAL) {
  4979. // // break;
  4980. // //}
  4981. //}
  4982. TryFeedWatchdog();
  4983. usleep(WHILE_LOOP_TIME);
  4984. }
  4985. return FAIL;
  4986. }