main.c 208 KB

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