main.c 205 KB

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