main.c 209 KB

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