main.c 186 KB

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