main.c 202 KB

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