main.c 180 KB

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