main.c 184 KB

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