main.c 197 KB

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