main.c 196 KB

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