main.c 203 KB

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