main.c 210 KB

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