main.c 200 KB

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