main.c 207 KB

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