main.c 179 KB

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