main.c 208 KB

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