main.c 201 KB

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