main.c 206 KB

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