main.c 186 KB

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