main.c 206 KB

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