main.c 185 KB

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