main.c 179 KB

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