main.c 208 KB

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