main.c 209 KB

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