ReadCmdline.c 182 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444
  1. /*
  2. * Main.c
  3. *
  4. * Created on: 2019年8月6日
  5. * Author: 7564
  6. */
  7. #include <sys/time.h>
  8. #include <sys/timeb.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <sys/types.h>
  12. #include <sys/ioctl.h>
  13. #include <sys/socket.h>
  14. #include <sys/ipc.h>
  15. #include <sys/shm.h>
  16. #include <sys/shm.h>
  17. #include <sys/mman.h>
  18. #include <linux/wireless.h>
  19. #include <arpa/inet.h>
  20. #include <netinet/in.h>
  21. #include <unistd.h>
  22. #include <stdarg.h>
  23. #include <stdio.h> /*標準輸入輸出定義*/
  24. #include <stdlib.h> /*標準函數庫定義*/
  25. #include <unistd.h> /*Unix 標準函數定義*/
  26. #include <fcntl.h> /*檔控制定義*/
  27. #include <termios.h> /*PPSIX 終端控制定義*/
  28. #include <errno.h> /*錯誤號定義*/
  29. #include <errno.h>
  30. #include <string.h>
  31. #include <time.h>
  32. #include <ctype.h>
  33. #include <ifaddrs.h>
  34. #include <math.h>
  35. #include <stdbool.h>
  36. #include "../../define.h"
  37. #include "Config.h"
  38. #include "Module_EvComm.h"
  39. #include "Common.h"
  40. typedef unsigned char byte;
  41. #define NO_DEFINE 255
  42. #define OPTION_CNT 3
  43. #define STR_OPTION '-'
  44. #define OPTION_REFLASH 0x00000001
  45. #define OPTION_LOOP 0x00000002
  46. #define OPTION_TIME 0x00000004
  47. #define MAX_SUB_CMD_QUANTITY 16
  48. #define MAX_SUB_CMD_LENGTH 128
  49. #define STR_OPT_REFLASH 'f'
  50. #define STR_OPT_LOOP 'l'
  51. #define STR_OPT_TIME 't'
  52. #define TTY_PATH "/dev/tty"
  53. #define STTY_US "stty raw -echo -F "
  54. #define STTY_DEF "stty -raw echo -F "
  55. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  56. struct StatusCodeData *ShmStatusCodeData;
  57. struct PrimaryMcuData *ShmPrimaryMcuData;
  58. struct CHAdeMOData *ShmCHAdeMOData;
  59. struct CcsData *ShmCcsData;
  60. struct GBTData *ShmGBTData;
  61. struct FanModuleData *ShmFanModuleData;
  62. struct RelayModuleData *ShmRelayModuleData;
  63. struct LedModuleData *ShmLedModuleData;
  64. struct PsuData *ShmPsuData;
  65. ChargerInfoData *ShmChargerInfo;
  66. PsuPositionInfoData *ShmPsuPosition;
  67. PsuGroupingInfoData *ShmPsuGrouping;
  68. struct OCPP16Data *ShmOCPP16Data;
  69. struct OCPP20Data *ShmOCPP20Data;
  70. struct ChargingInfoData *_chargingData[CONNECTOR_QUANTITY];
  71. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  72. char MultiSubCmd[MAX_SUB_CMD_QUANTITY][MAX_SUB_CMD_LENGTH];
  73. int totalSubCnt = 0;
  74. char *msg = "state : get gun state (index) \n"
  75. "card : scanning card (x) : \n"
  76. "gun : get gun plugit state (index) \n"
  77. "lock : get gun locked state (index) \n"
  78. "self : self test state (x) \n"
  79. "ver : ver of board (407 or index or rb or fan) \n"
  80. "ac : get ac relay state (x) \n"
  81. "gunchg: set gun start charging \n"
  82. "gunstp: set gun stop charging \n"
  83. "gunext: extend gun capability \n";
  84. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  85. {
  86. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  87. {
  88. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  89. {
  90. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  91. return true;
  92. }
  93. }
  94. for (byte index = 0; index < CCS_QUANTITY; index++)
  95. {
  96. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  97. {
  98. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  99. return true;
  100. }
  101. }
  102. for (byte index = 0; index < GB_QUANTITY; index++)
  103. {
  104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  105. {
  106. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  107. return true;
  108. }
  109. }
  110. if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
  111. {
  112. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
  113. return true;
  114. }
  115. return false;
  116. }
  117. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  118. {
  119. if (target < AC_QUANTITY)
  120. {
  121. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  122. return true;
  123. }
  124. return false;
  125. }
  126. int InitShareMemory()
  127. {
  128. int result = PASS;
  129. int MeterSMId;
  130. //initial ShmSysConfigAndInfo
  131. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  132. {
  133. result = FAIL;
  134. }
  135. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  136. {
  137. result = FAIL;
  138. }
  139. else
  140. {}
  141. //initial ShmStatusCodeData
  142. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  143. {
  144. result = FAIL;
  145. }
  146. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  147. {
  148. result = FAIL;
  149. }
  150. else
  151. {}
  152. if (CHAdeMO_QUANTITY > 0) {
  153. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  154. IPC_CREAT | 0777)) < 0) {
  155. result = FAIL;
  156. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  157. == (void *) -1) {
  158. result = FAIL;
  159. } else {
  160. }
  161. }
  162. if (CCS_QUANTITY > 0) {
  163. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  164. IPC_CREAT | 0777)) < 0) {
  165. result = FAIL;
  166. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  167. result = FAIL;
  168. } else {
  169. }
  170. }
  171. if (GB_QUANTITY > 0) {
  172. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  173. IPC_CREAT | 0777)) < 0) {
  174. return 0;
  175. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  176. return 0;
  177. }
  178. memset(ShmGBTData, 0, sizeof(struct GBTData));
  179. }
  180. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  181. {
  182. result = FAIL;
  183. }
  184. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  185. {
  186. result = FAIL;
  187. }
  188. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  189. {
  190. result = FAIL;
  191. }
  192. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  193. {
  194. result = FAIL;
  195. }
  196. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  197. {
  198. result = FAIL;
  199. }
  200. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  201. {
  202. result = FAIL;
  203. }
  204. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  205. {
  206. result = FAIL;
  207. }
  208. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  209. {
  210. result = FAIL;
  211. }
  212. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  213. {
  214. result = FAIL;
  215. }
  216. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  217. {
  218. result = FAIL;
  219. }
  220. if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
  221. {
  222. result = FAIL;
  223. }
  224. else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  225. {
  226. result = FAIL;
  227. }
  228. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  229. {
  230. result = FAIL;
  231. }
  232. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  233. {
  234. result = FAIL;
  235. }
  236. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  237. {
  238. result = FAIL;
  239. }
  240. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  241. {
  242. result = FAIL;
  243. }
  244. if(result == PASS)
  245. {
  246. ShmPsuPosition = &ShmChargerInfo->PsuPosition;
  247. ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
  248. }
  249. return result;
  250. }
  251. void Get_Ocpp_TransactionId(int gun_index, char *transactionId)
  252. {
  253. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  254. {
  255. sprintf(transactionId, "%d", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  256. return;
  257. }
  258. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  259. {
  260. strcpy(transactionId, (char *)&ShmOCPP20Data->TransactionEvent [gun_index].transactionInfo.transactionId[0]);
  261. return;
  262. }
  263. sprintf(transactionId, "%d", 0);
  264. }
  265. static void get_char(char *word)
  266. {
  267. fd_set rfds;
  268. struct timeval tv;
  269. FD_ZERO(&rfds);
  270. FD_SET(0, &rfds);
  271. tv.tv_sec = 0;
  272. tv.tv_usec = 10; //wait input timout time
  273. //if input
  274. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  275. {
  276. fgets(word, 128, stdin);
  277. }
  278. }
  279. // return command length
  280. int ParsingCmd(char *inputString, char *outputString)
  281. {
  282. bool valid = false, done = false;
  283. int len = 0, start = 0;
  284. for(int i = 0; i < strlen(inputString); i++)
  285. {
  286. if(!valid)
  287. {
  288. if(inputString[i] != ' ' && inputString[i] != '\0' && inputString[i] != '\r' && inputString[i] != '\n')
  289. {
  290. valid = true;
  291. start = i;
  292. }
  293. }
  294. else
  295. {
  296. if(inputString[i] == ' ' || inputString[i] == '\0' || inputString[i] == '\r' || inputString[i] == '\n' || len >= MAX_SUB_CMD_LENGTH)
  297. {
  298. done = true;
  299. break;
  300. }
  301. }
  302. len = (valid && !done) ? len + 1 : len;
  303. }
  304. if(valid)
  305. {
  306. memcpy(outputString, &inputString[start], len);
  307. outputString[len] = '\0';
  308. }
  309. return len;
  310. }
  311. bool IsOption(char *strCmd, unsigned int *opt)
  312. {
  313. int len = 0;
  314. char str_opt[OPTION_CNT] = {STR_OPT_REFLASH, STR_OPT_LOOP, STR_OPT_TIME};
  315. unsigned int opt_value[OPTION_CNT] = {OPTION_REFLASH, OPTION_LOOP, OPTION_TIME};
  316. len = strlen(strCmd);
  317. if(len == 2)
  318. {
  319. if(strCmd[0] == STR_OPTION)
  320. {
  321. for(int i = 0; i < OPTION_CNT; i++)
  322. {
  323. if(strCmd[1] == str_opt[i])
  324. {
  325. *opt |= opt_value[i];
  326. return true;
  327. }
  328. }
  329. }
  330. }
  331. return false;
  332. }
  333. // inputCmdString: console input string
  334. // outputCmdString: input string parsed
  335. // return command quantity
  336. int InputStringNormalize(char *inputCmdString, char *outputCmdString, unsigned int *opt)
  337. {
  338. int len = 0, cnt = 0, start = 0;
  339. int cmdLen = 0, totalLen = 0;
  340. len = strlen(inputCmdString);
  341. *opt = 0;
  342. if(len > 0)
  343. {
  344. while(start < len)
  345. {
  346. if(inputCmdString[start] != ' ' && inputCmdString[start] != '\0' &&
  347. inputCmdString[start] != '\r' && inputCmdString[start] != '\n')
  348. {
  349. cmdLen = ParsingCmd(&inputCmdString[start], &outputCmdString[totalLen]);
  350. if(cmdLen > 0)
  351. {
  352. //printf("Find %d Cmd: %s\r\n", cnt + 1, &outputCmdString[totalLen]);
  353. if(!IsOption(&outputCmdString[totalLen], opt))
  354. {
  355. outputCmdString[totalLen + cmdLen] = ' ';
  356. cnt++;
  357. totalLen += cmdLen + 1;
  358. }
  359. start += cmdLen;
  360. }
  361. }
  362. else
  363. {
  364. start++;
  365. }
  366. }
  367. outputCmdString[totalLen - 1] = '\0';
  368. }
  369. return cnt;
  370. }
  371. int MainAndSubCommandParsing(char *normalCmd, char *mainCmd, char *subCmd)
  372. {
  373. int len = 0, totalLen = 0;
  374. int quantity = 0;
  375. strcpy(mainCmd, "");
  376. strcpy(subCmd, "");
  377. totalLen = strlen(normalCmd);
  378. if(totalLen > 0)
  379. {
  380. len = ParsingCmd(normalCmd, mainCmd);
  381. //printf("Find MainCmd: %s\r\n", mainCmd);
  382. quantity = len > 0 ? (quantity + 1) : quantity;
  383. if(len > 0 && totalLen > len)
  384. {
  385. strcpy(subCmd, &normalCmd[len + 1]);
  386. //printf("Find SubCmd: %s\r\n", subCmd);
  387. len = strlen(subCmd);
  388. quantity = len > 0 ? (quantity + 1) : quantity;
  389. }
  390. }
  391. return quantity;
  392. }
  393. int GetCommandSring(char *outputCmdString)
  394. {
  395. int len = 0, cnt = 0;
  396. int cmdLen = 0, totalLen = 0;
  397. char word[128];
  398. memset(word, 0x00, sizeof(word));
  399. get_char(word);
  400. len = strlen(word);
  401. if(len == 0)
  402. {
  403. return -1;
  404. }
  405. int start = 0;
  406. while(start < len - 1)
  407. {
  408. if(word[start] != ' ' && word[start] != '\0')
  409. {
  410. cmdLen = ParsingCmd(&word[start], &outputCmdString[totalLen]);
  411. char newCmd[MAX_SUB_CMD_LENGTH];
  412. memset(newCmd, 0x00, MAX_SUB_CMD_LENGTH);
  413. memcpy(newCmd, &outputCmdString[totalLen], cmdLen);
  414. cnt = cmdLen > 0 ? cnt + 1 : cnt;
  415. totalLen += cmdLen + 1;
  416. start += cmdLen;
  417. }
  418. else
  419. {
  420. start++;
  421. }
  422. }
  423. return cnt;
  424. }
  425. bool IsLoopStopCmd(void)
  426. {
  427. bool stop = false;
  428. int cnt = 0;
  429. char cmd[256];
  430. char totalCmd[256];
  431. memset(cmd, 0x00, 256);
  432. memset(totalCmd, 0x00, 256);
  433. cnt = GetCommandSring(totalCmd);
  434. if(cnt > 0)
  435. {
  436. strcpy(&cmd[0], totalCmd);
  437. if(strcmp(&cmd[0], "c") == 0)
  438. {
  439. stop = true;
  440. }
  441. }
  442. return stop;
  443. }
  444. void ConsoleReflash(int groupCnt, int lineCnt)
  445. {
  446. for(int i = 0; i < groupCnt; i++)
  447. {
  448. for(int i = 0; i < lineCnt; i++)
  449. {
  450. printf("\033[1A");
  451. printf("\033[K");
  452. }
  453. }
  454. printf("\r");
  455. }
  456. int GetSubCommand(char *inputCmd)
  457. {
  458. unsigned int paraOpt = 0;
  459. int loopLimit = 0;
  460. char normalString[128];
  461. totalSubCnt = InputStringNormalize(inputCmd, normalString, &paraOpt);
  462. if(totalSubCnt > MAX_SUB_CMD_QUANTITY)
  463. {
  464. totalSubCnt = MAX_SUB_CMD_QUANTITY;
  465. }
  466. if(totalSubCnt > 0)
  467. {
  468. loopLimit = totalSubCnt > 1 ? totalSubCnt - 1 : 1;
  469. for(int i = 0; i < loopLimit; i++)
  470. {
  471. memset(&MultiSubCmd[i][0], 0x00, MAX_SUB_CMD_LENGTH);
  472. memset(&MultiSubCmd[i + 1][0], 0x00, MAX_SUB_CMD_LENGTH);
  473. MainAndSubCommandParsing(normalString, &MultiSubCmd[i][0], &MultiSubCmd[i + 1][0]);
  474. strcpy(normalString, &MultiSubCmd[i + 1][0]);
  475. }
  476. }
  477. return totalSubCnt;
  478. }
  479. void RunStatusProc(char *v1, char *v2)
  480. {
  481. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  482. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  483. if (strcmp(v1, "ac") == 0)
  484. {
  485. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  486. {
  487. printf("FindChargingInfoData (AC) false \n");
  488. }
  489. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  490. return;
  491. }
  492. int _index = atoi(v1);
  493. if (_index <= 3)
  494. {
  495. if (!FindChargingInfoData(_index, &_chargingData[0]))
  496. {
  497. printf ("FindChargingInfoData error\n");
  498. return;
  499. }
  500. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  501. {
  502. // get
  503. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  504. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  505. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  506. printf("ConnectorAlarmCode = %s \n", _chargingData[_index]->ConnectorAlarmCode);
  507. printf("EvConnAlarmCode = %s \n", _chargingData[_index]->EvConnAlarmCode);
  508. printf("RemotenAlarmCode = %s \n", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].RemotenAlarmCode);
  509. }
  510. else
  511. {
  512. // set
  513. _chargingData[_index]->SystemStatus = atoi(v2);
  514. }
  515. }
  516. else
  517. {
  518. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  519. {
  520. printf("FindChargingInfoData (AC) false \n");
  521. }
  522. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  523. {
  524. // get
  525. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  526. }
  527. else
  528. {
  529. // set
  530. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  531. }
  532. }
  533. }
  534. void RunCardProc(char *v1, char *v2)
  535. {
  536. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  537. {
  538. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  539. {
  540. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  541. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  542. }
  543. else
  544. {
  545. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  546. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  547. }
  548. }
  549. else
  550. {
  551. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  552. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  553. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  554. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  555. }
  556. }
  557. void RunGunPlugitProc(char *v1, char *v2)
  558. {
  559. if (strcmp(v1, "ac") == 0)
  560. {
  561. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  562. {
  563. printf("FindChargingInfoData (AC) false \n");
  564. }
  565. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  566. {
  567. // get
  568. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  569. }
  570. else
  571. {
  572. // set
  573. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  574. }
  575. return;
  576. }
  577. int _index = atoi(v1);
  578. if (!FindChargingInfoData(_index, &_chargingData[0]))
  579. {
  580. printf("FindChargingInfoData error\n");
  581. return;
  582. }
  583. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  584. {
  585. // get
  586. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  587. }
  588. else
  589. {
  590. // set
  591. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  592. }
  593. }
  594. void GetGunLockStatusProc(char *v1, char *v2)
  595. {
  596. int _index = atoi(v1);
  597. if (!FindChargingInfoData(_index, &_chargingData[0]))
  598. {
  599. printf("FindChargingInfoData error\n");
  600. return;
  601. }
  602. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  603. {
  604. _chargingData[_index]->GunLocked = atoi(v2);
  605. }
  606. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  607. }
  608. void SetSystemIDProc()
  609. {
  610. char *systemId = "Alston_Test";
  611. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  612. }
  613. void RunSelfProc()
  614. {
  615. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  616. }
  617. void ShowFwVer(void)
  618. {
  619. printf("\r\nPower Cabinet, Model Name: %s, SN: %s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  620. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
  621. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev);
  622. printf("\r\n Csu Kernel: ");
  623. for(int i = 0; i < strlen((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev); i++)
  624. {
  625. if(ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\r' && ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\n')
  626. {
  627. printf("%c", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i]);
  628. }
  629. }
  630. printf("\r\n Csu Root Fs: %s [%s]", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, ShmChargerInfo->SysMisc.SubVersion);
  631. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
  632. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  633. printf("\r\n Relay1 Module: %s", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  634. printf("\r\n Relay2 Module: %s", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  635. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  636. {
  637. printf("\r\n\r\nDispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  638. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  639. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  640. {
  641. printf(", Model Name: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName);
  642. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuBootLoadFwRev);
  643. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev);
  644. printf("\r\n Csu Kernel: ");
  645. for(int j = 0; j < strlen((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev); j++)
  646. {
  647. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\r' &&
  648. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\n')
  649. {
  650. printf("%c", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j]);
  651. }
  652. }
  653. printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuRootFsFwRev);
  654. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuPrimFwRev);
  655. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].FanModuleFwRev);
  656. printf("\r\n Relay Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].RelayModuleFwRev);
  657. printf("\r\n Connector 1: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector1FwRev);
  658. printf("\r\n Connector 2: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector2FwRev);
  659. printf("\r\n Led Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LedModuleFwRev);
  660. }
  661. }
  662. printf("\r\n\r\n");
  663. }
  664. void GetFwVerProc(char *v1)
  665. {
  666. if (strcmp(v1, "407") == 0)
  667. {
  668. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  669. }
  670. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0 || strcmp(v1, "2") == 0 || strcmp(v1, "3") == 0)
  671. {
  672. int _index = atoi(v1);
  673. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Enable)
  674. {
  675. int dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].ParentDispensetIndex;
  676. int ParentIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].GeneralChargingData.Index;
  677. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  678. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  679. {
  680. if(ParentIndex == 0)
  681. {
  682. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  683. }
  684. else
  685. {
  686. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  687. }
  688. }
  689. }
  690. else
  691. {
  692. printf("Gun %d is disable\r\n", _index);
  693. }
  694. }
  695. else if (strcmp(v1, "rb") == 0)
  696. {
  697. printf("RB1 Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  698. printf("RB2 Version = %s \n", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  699. }
  700. else if (strcmp(v1, "fan") == 0)
  701. {
  702. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  703. }
  704. else if (strcmp(v1, "dc") == 0)
  705. {
  706. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  707. }
  708. else if (strcmp(v1, "led") == 0)
  709. {
  710. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  711. }
  712. }
  713. void CreateOneError(char *v1)
  714. {
  715. int value = atoi(v1);
  716. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
  717. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  718. }
  719. void GetAuthorizeFlag(char *v1)
  720. {
  721. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  722. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  723. else
  724. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  725. }
  726. void GetOrClearId(char *v1)
  727. {
  728. int _index = atoi(v1);
  729. if (!FindChargingInfoData(_index, &_chargingData[0]))
  730. {
  731. printf("FindChargingInfoData error\n");
  732. return;
  733. }
  734. printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
  735. }
  736. void FwUpdateFlagProc()
  737. {
  738. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  739. }
  740. void CheckAcStatus(char *v1)
  741. {
  742. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  743. {
  744. printf(" AC Contactor Ctrl: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactor);
  745. printf(" AC Off By Psu : %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu);
  746. printf(" AC Off ByEmergency: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency);
  747. printf("AC Contactor Status: %d\r\n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  748. }
  749. else
  750. {
  751. if(system("pidof -s main > /dev/null") != 0)
  752. {
  753. if(strcmp(v1, "0") == 0)
  754. {
  755. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = false;
  756. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  757. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  758. printf("Set AC Contactor Off\r\n");
  759. }
  760. else
  761. {
  762. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = true;
  763. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  764. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  765. printf("Set AC Contactor On\r\n");
  766. }
  767. }
  768. else
  769. {
  770. printf("main task is running\r\n");
  771. }
  772. }
  773. }
  774. void SetCableChkStatus(char *v1, char *v2)
  775. {
  776. int _index = atoi(v1);
  777. if (!FindChargingInfoData(_index, &_chargingData[0]))
  778. {
  779. printf ("FindChargingInfoData error\n");
  780. return;
  781. }
  782. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  783. }
  784. void SetPowerValue(char *v1, char *v2)
  785. {
  786. int _index = atoi(v1);
  787. float _Current = atof(v2);
  788. // 盲沖的時候才允許使用~
  789. if (_chargingData[_index]->Type != 9)
  790. return;
  791. if (!FindChargingInfoData(_index, &_chargingData[0]))
  792. {
  793. printf ("FindChargingInfoData error\n");
  794. return;
  795. }
  796. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  797. }
  798. void GetSystemInfo(void)
  799. {
  800. printf ("Power Cabinet\r\n");
  801. printf (" -System ID: [%s]\r\n", (char *)&ShmSysConfigAndInfo->SysConfig.SystemId);
  802. printf (" -ModelName: [%s], SerialNumber: [%s]\r\n",
  803. (char *)&ShmSysConfigAndInfo->SysConfig.ModelName,
  804. (char *)&ShmSysConfigAndInfo->SysConfig.SerialNumber);
  805. printf (" -CSURootFs: %s [%s]\r\n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, ShmChargerInfo->SysMisc.SubVersion);
  806. }
  807. bool SetModelName(char *modelName);
  808. void ModelNameCmd(char *inputCmd, unsigned int opt)
  809. {
  810. int totalCnt = 0, maxPara = 0;
  811. maxPara = 2;
  812. totalCnt = GetSubCommand(inputCmd);
  813. printf("\r\n");
  814. if(totalCnt == 0)
  815. {
  816. GetSystemInfo();
  817. printf("\r\n");
  818. return;
  819. }
  820. if(totalCnt != maxPara || strcmp(&MultiSubCmd[0][0], "set") != EQUAL)
  821. {
  822. printf("Input cmd fail ------ model [set] [model name]\r\n\r\n");
  823. return;
  824. }
  825. if(SetModelName(&MultiSubCmd[0][0]))
  826. {
  827. printf("\r\n");
  828. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  829. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  830. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashAndReset = true;
  831. }
  832. }
  833. bool SetSerialNumber(char *serialNumber);
  834. void SerialNumberCmd(char *inputCmd, unsigned int opt)
  835. {
  836. int totalCnt = 0, maxPara = 0;
  837. maxPara = 2;
  838. totalCnt = GetSubCommand(inputCmd);
  839. printf("\r\n");
  840. if(totalCnt != maxPara)
  841. {
  842. printf("Input cmd fail ------ model [set] [serial number]\r\n\r\n");
  843. return;
  844. }
  845. if(SetSerialNumber(&MultiSubCmd[1][0]))
  846. {
  847. printf("\r\n");
  848. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  849. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  850. }
  851. }
  852. void SetFanSpeed(char *v1)
  853. {
  854. int speed = atoi(v1);
  855. ShmFanModuleData->TestFanSpeed = speed;
  856. }
  857. void GetFanSpeed()
  858. {
  859. printf("Target Speed = %d \n", ShmFanModuleData->TestFanSpeed);
  860. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  861. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  862. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  863. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  864. }
  865. void SetDebugMode(char *v1)
  866. {
  867. int mode = atoi(v1);
  868. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  869. }
  870. void SetGFDMode(char *v1)
  871. {
  872. int mode = atoi(v1);
  873. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  874. }
  875. // PSU 0 PSU 1 PSU 2 ...
  876. // Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb
  877. // 1 XXX XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX
  878. void GetTemperature(char *inputCmd, unsigned int opt)
  879. {
  880. bool keepRun = false;
  881. bool reflash = false;
  882. int time = 0;
  883. struct timespec _Loop_time;
  884. char strGunTemp[16], strChillerTemp[16];
  885. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  886. {
  887. keepRun = true;
  888. }
  889. printf("\r\n");
  890. printf(" PSU 0 PSU 1 PSU 2 .....\r\n");
  891. printf(" Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb\r\n");
  892. do
  893. {
  894. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  895. if(time >= 1000)
  896. {
  897. if(reflash)
  898. {
  899. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  900. }
  901. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  902. {
  903. sprintf(strGunTemp, "N/A");
  904. sprintf(strChillerTemp, "N/A");
  905. if(_chargingData[i]->ConnectorTemp != 0 && _chargingData[i]->ConnectorTemp != 0xFF)
  906. {
  907. sprintf(strGunTemp, "%3d", _chargingData[i]->ConnectorTemp - 60);
  908. }
  909. if(_chargingData[i]->ChillerTemp != 0 && _chargingData[i]->ChillerTemp != 0xFF)
  910. {
  911. sprintf(strChillerTemp, "%3d", _chargingData[i]->ChillerTemp - 60);
  912. }
  913. printf(" %d %s %s ", i + 1, strGunTemp, strChillerTemp);
  914. for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  915. {
  916. printf(" %3d/%3d/%3d",
  917. ShmPsuData->PsuGroup[i].PsuModule[j].ExletTemp,
  918. ShmPsuData->PsuGroup[i].PsuModule[j].InletTemp,
  919. ShmPsuData->PsuGroup[i].PsuModule[j].CriticalTemp1);
  920. }
  921. printf("\r\n");
  922. }
  923. GetClockTime(&_Loop_time);
  924. if((opt & OPTION_REFLASH) > 0)
  925. {
  926. reflash = true;
  927. }
  928. }
  929. if(keepRun)
  930. {
  931. keepRun = IsLoopStopCmd() ? false : true;
  932. usleep(10000);
  933. }
  934. }while(keepRun);
  935. printf("\r\n");
  936. }
  937. void GetInputVol(char *inputCmd, unsigned int opt)
  938. {
  939. bool keepRun = false;
  940. bool reflash = false;
  941. int time = 0;
  942. struct timespec _Loop_time;
  943. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  944. {
  945. keepRun = true;
  946. }
  947. printf("\r\n");
  948. do
  949. {
  950. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  951. if(time >= 1000)
  952. {
  953. if(reflash)
  954. {
  955. ConsoleReflash(1, 1);
  956. }
  957. printf("L1N_L12 = %4.1f V, L2N_L23 = %4.1f V, L3N_L31 = %4.1f V, DC Input: %4.1f V\r\n",
  958. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  959. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  960. ShmSysConfigAndInfo->SysInfo.InputVoltageT,
  961. ShmSysConfigAndInfo->SysInfo.InputVoltageDc);
  962. GetClockTime(&_Loop_time);
  963. if((opt & OPTION_REFLASH) > 0)
  964. {
  965. reflash = true;
  966. }
  967. }
  968. if(keepRun)
  969. {
  970. keepRun = IsLoopStopCmd() ? false : true;
  971. usleep(10000);
  972. }
  973. }while(keepRun);
  974. printf("\r\n");
  975. }
  976. void GetPsuInformation(char *v1, char *v2, char *v3)
  977. {
  978. printf("**********************AC Contact needed*************************\n");
  979. if(strcmp(v1, "count") == 0)
  980. {
  981. for (int i = 0; i < 4; i++)
  982. {
  983. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  984. }
  985. }
  986. else if(strcmp(v1, "ver") == 0)
  987. {
  988. for (int i = 0; i < ShmPsuData->SystemInitialPsuQuantity; i++)
  989. {
  990. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  991. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  992. }
  993. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  994. {
  995. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  996. {
  997. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  998. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  999. }
  1000. }
  1001. }
  1002. else if(strcmp(v1, "cap") == 0)
  1003. {
  1004. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  1005. {
  1006. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  1007. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  1008. }
  1009. }
  1010. else if(strcmp(v1, "input") == 0)
  1011. {
  1012. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  1013. {
  1014. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  1015. {
  1016. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  1017. i, count,
  1018. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  1019. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  1020. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  1021. }
  1022. }
  1023. }
  1024. else if (strcmp(v1, "output") == 0)
  1025. {
  1026. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  1027. {
  1028. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  1029. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  1030. }
  1031. }
  1032. else if (strcmp(v1, "test") == 0)
  1033. {
  1034. int mode = atoi(v2);
  1035. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  1036. {
  1037. ShmPsuData->Work_Step = mode;
  1038. }
  1039. }
  1040. else if (strcmp(v1, "out") == 0)
  1041. {
  1042. float vol = atof(v2);
  1043. float cur = atof(v3);
  1044. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  1045. {
  1046. if (!FindChargingInfoData(0, &_chargingData[0]))
  1047. {
  1048. printf ("FindChargingInfoData error\n");
  1049. return;
  1050. }
  1051. _chargingData[0]->EvBatterytargetVoltage = vol;
  1052. _chargingData[0]->EvBatterytargetCurrent = cur;
  1053. }
  1054. }
  1055. printf("*************************************************\n");
  1056. }
  1057. void GetConnectorCapInfo(char *v1)
  1058. {
  1059. int _GunIndex = atoi(v1);
  1060. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  1061. {
  1062. printf ("FindChargingInfoData error\n");
  1063. return;
  1064. }
  1065. printf ("Charger Max Current = %d, Max Power = %d \n",
  1066. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  1067. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  1068. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  1069. _GunIndex,
  1070. _chargingData[_GunIndex]->RealMaxPower,
  1071. _chargingData[_GunIndex]->RealMaxVoltage,
  1072. _chargingData[_GunIndex]->RealMaxCurrent);
  1073. }
  1074. void SetWiringInfo(char *v1, char *v2)
  1075. {
  1076. int dispenser = atoi(v1);
  1077. int connector = atoi(v2);
  1078. if(dispenser > 0 && dispenser <= GENERAL_GUN_QUANTITY && connector >= 0 && connector <= GENERAL_GUN_QUANTITY)
  1079. {
  1080. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence == (dispenser - 1))
  1081. {
  1082. printf("\r\n");
  1083. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1084. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1085. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = dispenser;
  1086. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += connector;
  1087. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1088. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1089. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1090. }
  1091. else if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > (dispenser - 1))
  1092. {
  1093. printf("\r\n");
  1094. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1095. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1096. int quantity = 0;
  1097. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1098. {
  1099. quantity += ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
  1100. }
  1101. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity = quantity;
  1102. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1103. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1104. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1105. }
  1106. }
  1107. }
  1108. void ShowWiringInfo(void)
  1109. {
  1110. printf("\r\n");
  1111. printf("********** Wiring Info **********\r\n");
  1112. printf("Dispenser = %d, Connector = %d\r\n",
  1113. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
  1114. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
  1115. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > 0)
  1116. {
  1117. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1118. {
  1119. printf("Dispenser[%d] <=> %d\r\n", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
  1120. }
  1121. }
  1122. printf("\r\n");
  1123. }
  1124. void CleanWiringInfo(void)
  1125. {
  1126. printf("\r\n");
  1127. printf("******* Clean Wiring Info *******\r\n");
  1128. memset((char *)&ShmSysConfigAndInfo->SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
  1129. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1130. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  1131. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashAndReset = true;
  1132. printf("\r\n");
  1133. }
  1134. void SetSystemSoftRest(void)
  1135. {
  1136. printf("\r\n");
  1137. printf("********* Set Soft Reset ********\r\n\r\n");
  1138. ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
  1139. }
  1140. void SetSystemHardReboot(void)
  1141. {
  1142. printf("\r\n");
  1143. printf("******** Set Hard Reboot ********\r\n\r\n");
  1144. ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
  1145. }
  1146. void SetGroupRole(byte group, byte role)
  1147. {
  1148. if(group < GENERAL_GUN_QUANTITY)
  1149. {
  1150. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != role)
  1151. {
  1152. //printf("\r\nSet Group %d Role = %d", group, role);
  1153. }
  1154. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role = role;
  1155. }
  1156. }
  1157. void SetGroupToIdle(byte group)
  1158. {
  1159. if(group < GENERAL_GUN_QUANTITY)
  1160. {
  1161. SetGroupRole(group, _GROLE_IDLE);
  1162. ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity = 0;
  1163. memset(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1164. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = 0;
  1165. //printf("\r\n Reset Group %02X To Idle", group);
  1166. }
  1167. }
  1168. void SetGroupToMaster(byte group)
  1169. {
  1170. if(group < GENERAL_GUN_QUANTITY)
  1171. {
  1172. SetGroupRole(group, _GROLE_MASTER);
  1173. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = group + 1;
  1174. //printf("\r\n Set Group %02X As Master", group);
  1175. }
  1176. }
  1177. void SetGroupToSlave(byte group, byte target)
  1178. {
  1179. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1180. {
  1181. SetGroupRole(group, _GROLE_SLAVE);
  1182. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = target + 1;
  1183. //printf("\r\n Set Group %02X As Slave", group);
  1184. }
  1185. }
  1186. // group: group index, target: target index
  1187. // add group to target's member
  1188. void AddGroupCollection(byte group, byte target)
  1189. {
  1190. int ParallelConfig = 0;
  1191. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1192. {
  1193. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role != _GROLE_MASTER)
  1194. {
  1195. return;
  1196. }
  1197. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE &&
  1198. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_WAIT_IDLE &&
  1199. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_PRECHARGE_READY)
  1200. {
  1201. return;
  1202. }
  1203. SetGroupToSlave(group, target);
  1204. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity++] = group;
  1205. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1206. if(ParallelConfig != 0)
  1207. {
  1208. ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
  1209. }
  1210. //printf("\r\n Add Group %02X To Gun %d (Quantity %d), Set Parallel Relay %d On", group, target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ParallelConfig);
  1211. }
  1212. }
  1213. // group: group index, target: target index
  1214. // remove group out of target's member
  1215. void RemoveGroupCollection(byte group, byte target)
  1216. {
  1217. int location = 0, slave = 0;
  1218. bool find = false;
  1219. int ParallelConfig = 0;
  1220. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1221. {
  1222. for(int i = 0; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1223. {
  1224. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i])
  1225. {
  1226. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1227. location = i;
  1228. find = true;
  1229. break;
  1230. }
  1231. }
  1232. if(find)
  1233. {
  1234. for(int i = location + 1; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1235. {
  1236. slave = ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i];
  1237. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1238. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i - 1] = slave;
  1239. }
  1240. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity--;
  1241. SetGroupToIdle(group);
  1242. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1243. if(ParallelConfig != 0)
  1244. {
  1245. ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
  1246. }
  1247. //printf("\r\n Remove Group %02X From Gun %d (Quantity %d), Clean Parallel Relay %d Off", group, target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ParallelConfig);
  1248. }
  1249. }
  1250. }
  1251. // Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay
  1252. // 1 (00) 00 3 00 [00] [00] [00] 0000 V 0000 A 0000 kW 0000 A 0000 A 00 XX
  1253. void ShowGroupingInfo(void)
  1254. {
  1255. byte target = 0;
  1256. printf("\r\n Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay");
  1257. for(int i = 0; i < 4; i++)
  1258. {
  1259. target = ShmPsuGrouping->Layout[i];
  1260. printf("\r\n %d (%2d) %2d %d %02X ",
  1261. target + 1, _chargingData[target]->SystemStatus, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role,
  1262. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup);
  1263. for(int j = 0; j < 3; j++)
  1264. {
  1265. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role == 1 && j < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity)
  1266. {
  1267. printf("[%02X] ", ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[j]);
  1268. }
  1269. else
  1270. {
  1271. printf(" ");
  1272. }
  1273. }
  1274. printf(" %4d V %4d A %4d kW %4d A %4d A ",
  1275. (int)_chargingData[target]->PresentChargingVoltage, (int)_chargingData[target]->PresentChargingCurrent,
  1276. (int)(_chargingData[target]->AvailableChargingPower / 10), (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1277. (int)(_chargingData[target]->DeratingChargingCurrent / 10));
  1278. printf("%02X %02X",ShmPsuGrouping->OutputRelayConfig[target].CtrlValue, ShmPsuGrouping->ParallelRelayConfig.CtrlValue);
  1279. }
  1280. printf("\r\n\r\nSystem Capability Current = %4d.%01d A, Power = %3d.%01d kW",
  1281. (ShmPsuData->SystemAvailableCurrent / 10), (ShmPsuData->SystemAvailableCurrent % 10),
  1282. (ShmPsuData->SystemAvailablePower / 10), (ShmPsuData->SystemAvailablePower % 10));
  1283. printf("\r\n\r\n");
  1284. }
  1285. void PsuGroupSwitchToIdle(byte group)
  1286. {
  1287. int master = 0, quantity = 0, location = 0, total = 0;
  1288. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_SLAVE)
  1289. {
  1290. return;
  1291. }
  1292. master = ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup - 1;
  1293. quantity = ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Quantity;
  1294. //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
  1295. for(int i = 0; i < quantity; i++)
  1296. {
  1297. if(total == 0)
  1298. {
  1299. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i])
  1300. {
  1301. location = i;
  1302. total++;
  1303. //printf("\r\n Find Group %02X At Member Index = %d", group, location);
  1304. }
  1305. }
  1306. else
  1307. {
  1308. // find other group in the same direction
  1309. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
  1310. {
  1311. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
  1312. {
  1313. total++;
  1314. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1315. }
  1316. }
  1317. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
  1318. {
  1319. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
  1320. {
  1321. total++;
  1322. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1323. }
  1324. }
  1325. }
  1326. }
  1327. if(total > 0)
  1328. {
  1329. unsigned char collection[GENERAL_GUN_QUANTITY];
  1330. //printf("\r\n There are %d Group Need To Switch Idle:", total);
  1331. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member));
  1332. for(int i = 0; i < total; i++)
  1333. {
  1334. //printf(" %02X", collection[i + location]);
  1335. }
  1336. for(int i = 0; i < total; i++)
  1337. {
  1338. RemoveGroupCollection(collection[i + location], master);
  1339. }
  1340. }
  1341. }
  1342. void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
  1343. {
  1344. int slave = 0, location = 0;
  1345. PsuGroupPartner partner;
  1346. memset(&partner, 0x00, sizeof(PsuGroupPartner));
  1347. // search from left
  1348. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location - 1;
  1349. for(int i = location; i >= 0; i--)
  1350. {
  1351. if(partner.Quantity >= quantity)
  1352. {
  1353. break;
  1354. }
  1355. slave = ShmPsuGrouping->Layout[i];
  1356. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1357. {
  1358. //printf("\r\n Find Group %02X From Left", slave);
  1359. partner.Member[partner.Quantity++] = slave;
  1360. }
  1361. else
  1362. {
  1363. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1364. {
  1365. continue;
  1366. }
  1367. break;
  1368. }
  1369. }
  1370. // search from right
  1371. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location + 1;
  1372. for(int i = location; i < 4; i++)
  1373. {
  1374. if(partner.Quantity >= quantity)
  1375. {
  1376. break;
  1377. }
  1378. slave = ShmPsuGrouping->Layout[i];
  1379. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1380. {
  1381. //printf("\r\n Find Group %02X From Right", slave);
  1382. partner.Member[partner.Quantity++] = slave;
  1383. }
  1384. else
  1385. {
  1386. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1387. {
  1388. continue;
  1389. }
  1390. break;
  1391. }
  1392. }
  1393. memcpy(tPartner, &partner, sizeof(PsuGroupPartner));
  1394. }
  1395. int GetPsuGroupAvailable(byte group)
  1396. {
  1397. //int slave = 0, location = 0, available = 0;
  1398. PsuGroupPartner partner;
  1399. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1400. //printf("\r\n Gun %d Available Quantity = %d", group + 1, partner.Quantity);
  1401. return partner.Quantity;
  1402. #if 0
  1403. // search from left
  1404. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1405. for(int i = location; i >= 0; i--)
  1406. {
  1407. slave = ShmPsuGrouping->Layout[i];
  1408. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1409. {
  1410. available++;
  1411. }
  1412. else
  1413. {
  1414. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1415. {
  1416. continue;
  1417. }
  1418. break;
  1419. }
  1420. }
  1421. // search from right
  1422. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1423. for(int i = location; i < 4; i++)
  1424. {
  1425. slave = ShmPsuGrouping->Layout[i];
  1426. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1427. {
  1428. available++;
  1429. }
  1430. else
  1431. {
  1432. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1433. {
  1434. continue;
  1435. }
  1436. break;
  1437. }
  1438. }
  1439. return available;
  1440. #endif
  1441. }
  1442. void PsuGroupShareCheck(byte group)
  1443. {
  1444. int slave = 0, target = 0, location = 0, share = 0, total = 0;
  1445. total = GetPsuGroupAvailable(group) + 1;
  1446. //printf("\r\n Gun %d Total Group = %d", group + 1, total);
  1447. // search from left
  1448. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1449. for(int i = location; i >= 0; i--)
  1450. {
  1451. slave = ShmPsuGrouping->Layout[i];
  1452. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1453. {
  1454. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1455. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1456. {
  1457. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1458. }
  1459. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1460. break;
  1461. }
  1462. else
  1463. {
  1464. break;
  1465. }
  1466. }
  1467. if(share == 0)
  1468. {
  1469. // search from right
  1470. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1471. for(int i = location; i < 4; i++)
  1472. {
  1473. slave = ShmPsuGrouping->Layout[i];
  1474. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1475. {
  1476. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1477. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1478. {
  1479. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1480. }
  1481. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1482. break;
  1483. }
  1484. else
  1485. {
  1486. break;
  1487. }
  1488. }
  1489. }
  1490. if(share > 0)
  1491. {
  1492. //printf("\r\n Grab %02X", slave);
  1493. PsuGroupSwitchToIdle(slave);
  1494. }
  1495. else
  1496. {
  1497. //printf("\r\n No Need To Grab");
  1498. }
  1499. }
  1500. void SimplePsuGroupStartCharging(byte group)
  1501. {
  1502. //int slave = 0, location = 0;
  1503. int available = 0;
  1504. PsuGroupPartner partner;
  1505. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1506. {
  1507. return;
  1508. }
  1509. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE && ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1510. {
  1511. return;
  1512. }
  1513. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_IDLE)
  1514. {
  1515. SetGroupToMaster(group);
  1516. PsuGroupShareCheck(group);
  1517. }
  1518. else
  1519. {
  1520. available = GetPsuGroupAvailable(group);
  1521. //printf("\r\nGun %d is already master, there are %d available group", group + 1, available);
  1522. if(available == 0)
  1523. {
  1524. return;
  1525. }
  1526. }
  1527. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1528. for(int i = 0; i < partner.Quantity; i++)
  1529. {
  1530. AddGroupCollection(partner.Member[i], group);
  1531. }
  1532. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = true;
  1533. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = true;
  1534. #if 0
  1535. // search from left
  1536. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1537. for(int i = location; i >= 0; i--)
  1538. {
  1539. slave = ShmPsuGrouping->Layout[i];
  1540. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1541. {
  1542. //printf("\r\n Find %02X From Left", slave);
  1543. AddGroupCollection(slave, group);
  1544. }
  1545. else
  1546. {
  1547. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1548. {
  1549. continue;
  1550. }
  1551. break;
  1552. }
  1553. }
  1554. // search from right
  1555. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1556. for(int i = location; i < 4; i++)
  1557. {
  1558. slave = ShmPsuGrouping->Layout[i];
  1559. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1560. {
  1561. //printf("\r\n Find %02X From Right", slave);
  1562. AddGroupCollection(slave, group);
  1563. }
  1564. else
  1565. {
  1566. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1567. {
  1568. continue;
  1569. }
  1570. break;
  1571. }
  1572. }
  1573. #endif
  1574. }
  1575. void PsuGroupStopCharging(byte group)
  1576. {
  1577. int total = 0;
  1578. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1579. {
  1580. return;
  1581. }
  1582. total = ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity;
  1583. if(total > 0)
  1584. {
  1585. unsigned char collection[GENERAL_GUN_QUANTITY];
  1586. //printf("\r\n There are %d Group Need To Stop:", ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity);
  1587. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1588. for(int i = 0; i < total; i++)
  1589. {
  1590. //printf(" %02X", collection[i]);
  1591. }
  1592. for(int i = 0; i < total; i++)
  1593. {
  1594. RemoveGroupCollection(collection[i], group);
  1595. }
  1596. }
  1597. SetGroupToIdle(group);
  1598. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = false;
  1599. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = false;
  1600. }
  1601. void RunSimplePsuGrouping(char *v1, char *v2)
  1602. {
  1603. int group = 0, charging = 0;
  1604. group = atoi(v1);
  1605. charging = atoi(v2);
  1606. group -= 1;
  1607. if(group >= 0 && group < 4)
  1608. {
  1609. if(charging > 0)
  1610. {
  1611. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1612. {
  1613. //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
  1614. PsuGroupSwitchToIdle(group);
  1615. }
  1616. SimplePsuGroupStartCharging(group);
  1617. }
  1618. if(charging == 0)
  1619. {
  1620. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_MASTER)
  1621. {
  1622. PsuGroupStopCharging(group);
  1623. }
  1624. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1625. {
  1626. PsuGroupSwitchToIdle(group);
  1627. }
  1628. }
  1629. ShowGroupingInfo();
  1630. }
  1631. }
  1632. void ConnectionInfo(void)
  1633. {
  1634. int address = 0;
  1635. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  1636. {
  1637. address = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
  1638. printf(" Connection[%d] Status: %d, DispenserIndex: %d, IP: %d.%d.%d.%d\r\n", i,
  1639. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status,
  1640. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex,
  1641. ((address >> 0) & 0xFF), ((address >> 8) & 0xFF), ((address >> 16) & 0xFF), ((address >> 24) & 0xFF));
  1642. }
  1643. }
  1644. void GunEnableInfo(int gunIndex)
  1645. {
  1646. printf(" Gun %d Index: %2X, Status = %2d , %7s, MeterValue: %10.4f, Local: : %10.4f, Gun: : %10.4f\r\n", gunIndex + 1, _chargingData[gunIndex]->Index, _chargingData[gunIndex]->SystemStatus,
  1647. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Enable ? "Enable" : "Disable",
  1648. _chargingData[gunIndex]->PowerConsumption,
  1649. ShmChargerInfo->MeterValue[gunIndex].LocalConsumption,
  1650. ShmChargerInfo->MeterValue[gunIndex].GunConsumption);
  1651. }
  1652. int FindDispenserIpAddress(int dispenser)
  1653. {
  1654. int address = 0;
  1655. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  1656. {
  1657. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched &&
  1658. dispenser == ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex)
  1659. {
  1660. address = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
  1661. }
  1662. }
  1663. return address;
  1664. }
  1665. int DispenserInfo(int dispenser)
  1666. {
  1667. int ipAddress = 0;
  1668. int gunCnt = 0;
  1669. printf(" Dispenser %d Status: %d", dispenser + 1, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus);
  1670. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  1671. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  1672. {
  1673. ipAddress = FindDispenserIpAddress(dispenser);
  1674. gunCnt = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ConnectorQuantity;
  1675. printf(", ModelName: %s, IP: %d.%d.%d.%d\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ModelName,
  1676. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  1677. for(int i = 0; i < gunCnt; i++)
  1678. {
  1679. unsigned char gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ConnectorID[i];
  1680. printf(" - Connector[%d] Gun %d, %s\r\n", i, gun, _chargingData[gun - 1]->ConnectorPlugIn ? "Plugged" : "Unplugged");
  1681. }
  1682. }
  1683. else
  1684. {
  1685. printf(", No Information\r\n");
  1686. }
  1687. return gunCnt;
  1688. }
  1689. void ShowCabinetInfo(char *inputCmd, unsigned int opt)
  1690. {
  1691. bool keepRun = false;
  1692. bool reflash = false;
  1693. int time = 0;
  1694. int dispenserLine = 0;
  1695. struct timespec _Loop_time;
  1696. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  1697. {
  1698. keepRun = true;
  1699. }
  1700. printf("\r\n");
  1701. printf("Power Cabinet & Dispenser Info\r\n");
  1702. do
  1703. {
  1704. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  1705. if(time >= 1000)
  1706. {
  1707. if(reflash)
  1708. {
  1709. ConsoleReflash(1, 2);
  1710. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  1711. dispenserLine = dispenserLine > 0 ? (dispenserLine + 1) : dispenserLine;
  1712. ConsoleReflash(1, dispenserLine);
  1713. dispenserLine = 0;
  1714. }
  1715. printf(" Dispenser: %d / %d, Connector: %d / %d\r\n",
  1716. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
  1717. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
  1718. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
  1719. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
  1720. printf("\r\n");
  1721. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  1722. {
  1723. GunEnableInfo(i);
  1724. }
  1725. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity > 0)
  1726. {
  1727. printf("\r\n");
  1728. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  1729. {
  1730. dispenserLine += DispenserInfo(i) + 1;
  1731. }
  1732. }
  1733. GetClockTime(&_Loop_time);
  1734. if((opt & OPTION_REFLASH) > 0)
  1735. {
  1736. reflash = true;
  1737. }
  1738. }
  1739. if(keepRun)
  1740. {
  1741. keepRun = IsLoopStopCmd() ? false : true;
  1742. usleep(10000);
  1743. }
  1744. }while(keepRun);
  1745. printf("\r\n");
  1746. }
  1747. void SetTestControl(char *v1, char *v2)
  1748. {
  1749. int testItem = 0;
  1750. int testItemLen = 5;
  1751. int enable = 0;
  1752. char strTest[32][32] = {"tbl", "tfsb", "chgsm", "fcre", "ubill"};
  1753. char strItem[32][32] = {"Balance", "Fast Standby Time", "Charging Simulation", "FCharging Release Extend", "Undisposed Bill"};
  1754. enable = atoi(v2);
  1755. if(enable < 0)
  1756. {
  1757. return;
  1758. }
  1759. for(int i = 0; i < testItemLen; i++)
  1760. {
  1761. if(strcmp((char *)&strTest[i][0], v1) == 0)
  1762. {
  1763. testItem = i + 1;
  1764. break;
  1765. }
  1766. }
  1767. if(testItem != 0)
  1768. {
  1769. if(enable)
  1770. {
  1771. ShmChargerInfo->Control.TestCtrl.CtrlValue |= (1 << (testItem - 1));
  1772. }
  1773. else
  1774. {
  1775. ShmChargerInfo->Control.TestCtrl.CtrlValue &= ~(1 << (testItem - 1));
  1776. }
  1777. printf("%s %s Test Item, Test Control Value = %08X\n",
  1778. enable ? "Enable" : "Disable", strItem[testItem - 1], ShmChargerInfo->Control.TestCtrl.CtrlValue);
  1779. }
  1780. else
  1781. {
  1782. printf("Test Item %s Not Found\n", v1);
  1783. for(int i = 0; i < testItemLen; i++)
  1784. {
  1785. printf(" [%s] -> %s Test\n", strTest[i], strItem[i]);
  1786. }
  1787. }
  1788. printf("\r\n");
  1789. }
  1790. // Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading DiffP_Ava DiffP_Cap DiffP_Lim
  1791. // 1 00 00 0 0000 V 000.0 A 0000 A XXX.XX XXX.XX XXX kw XXX kW XXX kW
  1792. void ShowGroupingDemand(void)
  1793. {
  1794. byte target = 0;
  1795. unsigned char k1k2 = 0;
  1796. printf("\r\n Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading DiffP_Ava DiffP_Cap DiffP_Lim");
  1797. for(int i = 0; i < 4; i++)
  1798. {
  1799. target = ShmPsuGrouping->Layout[i];
  1800. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup != 0)
  1801. {
  1802. k1k2 = _chargingData[ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
  1803. }
  1804. else
  1805. {
  1806. k1k2 = _chargingData[target]->RelayK1K2Status;
  1807. }
  1808. printf("\r\n %d %2d %02X %d %4d V %3d.%d A %4d A %3d.%02d",
  1809. target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup, k1k2,
  1810. (ShmPsuGrouping->GroupOutput[target].GTargetVoltage / 10),
  1811. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent / 10),
  1812. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent % 10),
  1813. (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1814. (ShmPsuGrouping->GroupOutput[target].OutputLoading / 100),
  1815. (ShmPsuGrouping->GroupOutput[target].OutputLoading % 100));
  1816. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup == target + 1)
  1817. {
  1818. printf(" %3d.%02d", (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading / 100), (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading % 100));
  1819. printf(" %3d kW %3d kW %3d kW",
  1820. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_Available,
  1821. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_Capability,
  1822. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_PhysicalLimit);
  1823. }
  1824. }
  1825. printf("\r\n\r\n");
  1826. }
  1827. // v1: gun
  1828. // v2: voltage
  1829. // v3: current
  1830. void SetGunStartCharging(char *inputCmd, unsigned int opt, unsigned char isWeb)
  1831. {
  1832. int totalCnt = 0, maxPara = 0;
  1833. maxPara = 3;
  1834. totalCnt = GetSubCommand(inputCmd);
  1835. if(totalCnt != maxPara)
  1836. {
  1837. printf("Input cmd fail ------ gunchg [gun 1-4] [voltage 0-1000] [current 0-100]\r\n\r\n");
  1838. return;
  1839. }
  1840. int gun = 0;
  1841. float _voltage = 0, _current = 0;
  1842. gun = atoi(&MultiSubCmd[0][0]);
  1843. _voltage = atof(&MultiSubCmd[1][0]);
  1844. _current = atof(&MultiSubCmd[2][0]);
  1845. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY || _voltage < 0 || _voltage > 1000 || _current < 0 || _current > 1200)
  1846. {
  1847. printf("\r\n");
  1848. printf("Gun Start Charging Input parameter %d, %.1f, %.1f out of range\r\n", gun, _voltage, _current);
  1849. printf("\r\n");
  1850. return;
  1851. }
  1852. bool wait = true;
  1853. int time = 0;
  1854. struct timespec _Wait_time;
  1855. unsigned char PreviousSystemStatus = 0xFF;
  1856. unsigned short _targetVoltage = 0, _targetCurrent = 0;
  1857. printf("\r\n");
  1858. while(wait)
  1859. {
  1860. switch(_chargingData[gun - 1]->SystemStatus)
  1861. {
  1862. case S_IDLE:
  1863. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1864. {
  1865. printf("Gun %d S_IDLE\r\n", gun);
  1866. printf("Set Gun %d Start Charging > Voltage: %4d, Current: %d\r\n", gun, (int)_voltage, (int)_current);
  1867. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  1868. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  1869. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  1870. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  1871. if(isWeb)
  1872. {
  1873. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.WebApiTrigger = true;
  1874. }
  1875. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1876. }
  1877. break;
  1878. case S_REASSIGN_CHECK:
  1879. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1880. {
  1881. printf("Gun %d S_REASSIGN_CHECK, Wait For Request Charging\r\n", gun);
  1882. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1883. }
  1884. break;
  1885. case S_REASSIGN:
  1886. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1887. {
  1888. printf("Gun %d S_REASSIGN, Wait For Grouping\r\n", gun);
  1889. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1890. }
  1891. break;
  1892. case S_PREPARNING:
  1893. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1894. {
  1895. printf("Gun %d S_PREPARNING\r\n", gun);
  1896. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1897. }
  1898. break;
  1899. case S_PREPARING_FOR_EV:
  1900. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1901. {
  1902. printf("Gun %d S_PREPARING_FOR_EV\r\n", gun);
  1903. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1904. }
  1905. break;
  1906. case S_PREPARING_FOR_EVSE:
  1907. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1908. {
  1909. printf("Gun %d S_PREPARING_FOR_EVSE, Wait For EVSE\r\n", gun);
  1910. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1911. }
  1912. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  1913. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  1914. {
  1915. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  1916. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  1917. printf("Gun %d Set Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  1918. }
  1919. break;
  1920. case S_CHARGING:
  1921. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1922. {
  1923. printf("Gun %d S_CHARGING\r\n", gun);
  1924. if(PreviousSystemStatus == 0xFF)
  1925. {
  1926. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  1927. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  1928. printf("Gun %d Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  1929. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  1930. {
  1931. printf("Set Gun %d Force Charging > Voltage: %4d, Current: %d\r\n", gun, (int)_voltage, (int)_current);
  1932. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  1933. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  1934. }
  1935. }
  1936. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1937. GetClockTime(&_Wait_time);
  1938. }
  1939. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  1940. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  1941. {
  1942. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  1943. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  1944. printf("Gun %d Set Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  1945. }
  1946. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  1947. if(time >= 1)
  1948. {
  1949. wait = false;
  1950. printf("Done\r\n");
  1951. }
  1952. break;
  1953. case S_TERMINATING:
  1954. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1955. {
  1956. printf("Gun %d S_TERMINATING\r\n", gun);
  1957. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1958. }
  1959. wait = false;
  1960. break;
  1961. case S_COMPLETE:
  1962. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1963. {
  1964. printf("Gun %d S_COMPLETE\r\n", gun);
  1965. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1966. }
  1967. wait = false;
  1968. break;
  1969. case S_ALARM:
  1970. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1971. {
  1972. printf("Gun %d S_ALARM\r\n", gun);
  1973. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1974. }
  1975. wait = false;
  1976. break;
  1977. default:
  1978. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1979. {
  1980. printf("Gun SystemStatus %d Unknown(%d)\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  1981. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1982. }
  1983. printf("Gun %d SystemStatus(%d) Is Not Available\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  1984. wait = false;
  1985. break;
  1986. }
  1987. char word[128];
  1988. char newString[7][10];
  1989. int i,j,ctr;
  1990. memset(word, 0x00, sizeof(word));
  1991. get_char(word);
  1992. if (strlen(word) == 0)
  1993. {
  1994. continue;
  1995. }
  1996. j=0; ctr=0;
  1997. strcpy(newString[1], "-1");
  1998. strcpy(newString[2], "-1");
  1999. for (i = 0; i <= (strlen(word)); i++)
  2000. {
  2001. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2002. {
  2003. newString[ctr][j] = '\0';
  2004. ctr++;
  2005. j = 0;
  2006. }
  2007. else
  2008. {
  2009. newString[ctr][j] = word[i];
  2010. j++;
  2011. }
  2012. }
  2013. if(strcmp(newString[0], "c") == 0)
  2014. {
  2015. printf("Stop\r\n");
  2016. wait = false;
  2017. }
  2018. usleep(100000);
  2019. }
  2020. printf("\r\n");
  2021. }
  2022. void GenerateManualStop(int gunIndex, bool isAlarm, char *alarmCode)
  2023. {
  2024. if(isAlarm)
  2025. {
  2026. if(!_chargingData[gunIndex]->ChargingStopFlag.bits.AlarmStop)
  2027. {
  2028. if(strncmp((char *)_chargingData[gunIndex]->ConnectorAlarmCode, "", 6) == EQUAL)
  2029. {
  2030. memcpy((char *)_chargingData[gunIndex]->ConnectorAlarmCode, alarmCode, 6);
  2031. }
  2032. _chargingData[gunIndex]->ChargingStopFlag.bits.AlarmStop = true;
  2033. printf("Set Gun %d Stop Charging(ManualAlarm)\r\n", gunIndex + 1);
  2034. }
  2035. }
  2036. else
  2037. {
  2038. if(!_chargingData[gunIndex]->ChargingStopFlag.bits.ManualStop)
  2039. {
  2040. _chargingData[gunIndex]->ChargingStopFlag.bits.ManualStop = true;
  2041. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gunIndex + 1);
  2042. }
  2043. }
  2044. }
  2045. // v1: gun
  2046. void SetGunStopCharging(char *inputCmd, unsigned int opt)
  2047. {
  2048. int totalCnt = 0, maxPara = 0;
  2049. maxPara = 2;
  2050. totalCnt = GetSubCommand(inputCmd);
  2051. if(totalCnt > maxPara || totalCnt == 0)
  2052. {
  2053. printf("Input cmd fail ------ gunstp [gun 1-4] [status code]\r\n\r\n");
  2054. return;
  2055. }
  2056. int gun = 0;
  2057. gun = atoi(&MultiSubCmd[0][0]);
  2058. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
  2059. {
  2060. printf("\r\n");
  2061. printf("Gun Stop Charging Input parameter %d over range\r\n", gun);
  2062. printf("\r\n");
  2063. return;
  2064. }
  2065. bool isAlarmStop = false;
  2066. char manualAlarm[7];
  2067. if(totalCnt == 2)
  2068. {
  2069. if((strlen(&MultiSubCmd[1][0]) == 6) && atoi(&MultiSubCmd[1][0]) != 0)
  2070. {
  2071. memset(manualAlarm, 0x00, sizeof(manualAlarm));
  2072. memcpy(manualAlarm, &MultiSubCmd[1][0], 6);
  2073. isAlarmStop = true;
  2074. }
  2075. }
  2076. bool wait = true;
  2077. int time = 0;
  2078. struct timespec _Wait_time;
  2079. unsigned char PreviousSystemStatus = 0xFF;
  2080. printf("\r\n");
  2081. while(wait)
  2082. {
  2083. switch(_chargingData[gun - 1]->SystemStatus)
  2084. {
  2085. case S_IDLE:
  2086. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2087. {
  2088. printf("Gun %d S_IDLE\r\n", gun);
  2089. if(PreviousSystemStatus == 0xFF)
  2090. {
  2091. if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2092. {
  2093. printf("Set Group [%02X] Stop\r\n", gun - 1);
  2094. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2095. }
  2096. }
  2097. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2098. GetClockTime(&_Wait_time);
  2099. }
  2100. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2101. if(time >= 1)
  2102. {
  2103. wait = false;
  2104. printf("Done\r\n");
  2105. }
  2106. break;
  2107. case S_REASSIGN_CHECK:
  2108. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2109. {
  2110. printf("Gun %d S_REASSIGN_CHECK, Wait For Request Charging\r\n", gun);
  2111. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2112. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2113. }
  2114. break;
  2115. case S_REASSIGN:
  2116. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2117. {
  2118. printf("Gun %d S_REASSIGN, Wait For Grouping\r\n", gun);
  2119. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2120. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2121. }
  2122. break;
  2123. case S_PREPARNING:
  2124. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2125. {
  2126. printf("Gun %d S_PREPARNING\r\n", gun);
  2127. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2128. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2129. }
  2130. break;
  2131. case S_PREPARING_FOR_EV:
  2132. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2133. {
  2134. printf("Gun %d S_PREPARING_FOR_EV\r\n", gun);
  2135. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2136. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2137. }
  2138. break;
  2139. case S_PREPARING_FOR_EVSE:
  2140. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2141. {
  2142. printf("Gun %d S_PREPARING_FOR_EVSE, Wait For EVSE\r\n", gun);
  2143. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2144. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2145. }
  2146. break;
  2147. case S_CHARGING:
  2148. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2149. {
  2150. printf("Gun %d S_CHARGING\r\n", gun);
  2151. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2152. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2153. }
  2154. break;
  2155. case S_TERMINATING:
  2156. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2157. {
  2158. printf("Gun %d S_TERMINATING\r\n", gun);
  2159. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2160. }
  2161. break;
  2162. case S_COMPLETE:
  2163. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2164. {
  2165. printf("Gun %d S_COMPLETE\r\n", gun);
  2166. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2167. }
  2168. break;
  2169. case S_ALARM:
  2170. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2171. {
  2172. printf("Gun %d S_ALARM\r\n", gun);
  2173. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2174. }
  2175. break;
  2176. default:
  2177. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2178. {
  2179. printf("Gun SystemStatus %d Unknown(%d)\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2180. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2181. }
  2182. printf("Gun %d SystemStatus(%d) Is Not Available\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2183. wait = false;
  2184. break;
  2185. }
  2186. char word[128];
  2187. char newString[7][10];
  2188. int i,j,ctr;
  2189. memset(word, 0x00, sizeof(word));
  2190. get_char(word);
  2191. if (strlen(word) == 0)
  2192. {
  2193. continue;
  2194. }
  2195. j=0; ctr=0;
  2196. strcpy(newString[1], "-1");
  2197. strcpy(newString[2], "-1");
  2198. for (i = 0; i <= (strlen(word)); i++)
  2199. {
  2200. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2201. {
  2202. newString[ctr][j] = '\0';
  2203. ctr++;
  2204. j = 0;
  2205. }
  2206. else
  2207. {
  2208. newString[ctr][j] = word[i];
  2209. j++;
  2210. }
  2211. }
  2212. if(strcmp(newString[0], "c") == 0)
  2213. {
  2214. printf("Stop\r\n");
  2215. wait = false;
  2216. }
  2217. usleep(100000);
  2218. }
  2219. printf("\r\n");
  2220. }
  2221. void SetGunExtend(char *v1)
  2222. {
  2223. int gun = 0;
  2224. gun = atoi(v1);
  2225. if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
  2226. {
  2227. printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
  2228. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
  2229. }
  2230. else
  2231. {
  2232. printf("\r\nGun %d Extend Capability Is Not Available, SystemStatus(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2233. }
  2234. printf("\r\n\r\n");
  2235. }
  2236. // Gun TargetV TargetC GTargetV GTargetC OutputV OutputC G_Psu_V G_Psu_C Psu 0_V Psu 0_C Psu 1_V Psu 1_C Psu 2_V Psu 2_C ...
  2237. // X XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A
  2238. void ShowGunOutput(void)
  2239. {
  2240. byte target = 0;
  2241. unsigned short voltage = 0, current = 0;
  2242. printf("\r\n Gun TargetV TargetC GTargetV GTargetC OutputV OutputC G_Psu_V G_Psu_C Psu 0_V Psu 0_C Psu 1_V Psu 1_C Psu 2_V Psu 2_C ...");
  2243. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2244. {
  2245. target = ShmPsuGrouping->Layout[i];
  2246. // "\r\n %d %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A"
  2247. voltage = (unsigned short)(_chargingData[target]->EvBatterytargetVoltage * 10);
  2248. current = (unsigned short)(_chargingData[target]->EvBatterytargetCurrent * 10);
  2249. printf("\r\n %d %4d.%d V %3d.%d A", target + 1, (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2250. voltage = ShmPsuGrouping->GroupOutput[target].GTargetVoltage;
  2251. current = ShmPsuGrouping->GroupOutput[target].GTargetCurrent;
  2252. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2253. voltage = (unsigned short)(_chargingData[target]->PresentChargingVoltage * 10);
  2254. current = (unsigned short)(_chargingData[target]->PresentChargingCurrent * 10);
  2255. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2256. voltage = ShmPsuData->PsuGroup[target].GroupPresentOutputVoltage;
  2257. current = ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent;
  2258. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2259. /*
  2260. for(int j = 0; j < ShmPsuData->PsuGroup[target].GroupPresentPsuQuantity; j++)
  2261. {
  2262. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2263. }
  2264. */
  2265. }
  2266. printf("\r\n\r\n");
  2267. }
  2268. void SetGpio(char *v1, char *v2)
  2269. {
  2270. int testItem = 0;
  2271. int testItemLen = 1;
  2272. int ioOutput = 0;
  2273. char strTest[32][32] = {"4g"};
  2274. char strItem[32][32] = {"4G Reset"};
  2275. ioOutput = atoi(v2);
  2276. if(ioOutput < 0)
  2277. {
  2278. return;
  2279. }
  2280. for(int i = 0; i < testItemLen; i++)
  2281. {
  2282. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2283. {
  2284. testItem = i + 1;
  2285. break;
  2286. }
  2287. }
  2288. if(testItem != 0)
  2289. {
  2290. if(ioOutput)
  2291. {
  2292. system("echo 1 > /sys/class/gpio/gpio104/value");
  2293. }
  2294. else
  2295. {
  2296. system("echo 0 > /sys/class/gpio/gpio104/value");
  2297. }
  2298. printf("Set %s %s\n",
  2299. strItem[testItem - 1], ioOutput > 0 ? "High" : "Low");
  2300. }
  2301. else
  2302. {
  2303. printf("Gpio Item %s Not Found\n", v1);
  2304. }
  2305. printf("\r\n");
  2306. }
  2307. void ShowStatus(void)
  2308. {
  2309. char *str_cabinet_role[] = {STR_CABINET_ROLE_NONE, STR_CABINET_ROLE_MASTER, STR_CABINET_ROLE_SLAVE};
  2310. for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
  2311. {
  2312. printf("\r\nGun %d Status = %d, IsAvailable = %d, GunEnable = %d",
  2313. i + 1,
  2314. _chargingData[i]->SystemStatus,
  2315. _chargingData[i]->IsAvailable,
  2316. ShmChargerInfo->Control.GunAvailable[i]);
  2317. printf("\r\nAlarmCode");
  2318. printf("\r\n Connector = %6s, EvConn = %6s, Remote = %6s, Vendor = %6s",
  2319. strncmp((char *)_chargingData[i]->ConnectorAlarmCode, "", 6) != 0 ?
  2320. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2321. strncmp((char *)_chargingData[i]->EvConnAlarmCode, "", 6) != 0 ?
  2322. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2323. strncmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode, "", 6) != 0 ?
  2324. (char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode : "No Err",
  2325. strncmp((char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode, "", 6) != 0 ?
  2326. (char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode : "No Err");
  2327. }
  2328. printf("\r\n");
  2329. printf("\r\nPower Cabinet Role: %s, Switch Value: %d, ",
  2330. ShmChargerInfo->Control.CabinetSwitch <= _CROLE_SLAVE ? str_cabinet_role[ShmChargerInfo->Control.CabinetSwitch] : "Unknown",
  2331. ShmChargerInfo->Control.CabinetSwitch);
  2332. printf("\r\nStatus Code Len = %d", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
  2333. if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
  2334. {
  2335. printf("\r\n WarningCode:");
  2336. for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  2337. {
  2338. printf(" %s", (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  2339. }
  2340. }
  2341. printf("\r\n\r\n");
  2342. }
  2343. void ShowWhiteCardList(void)
  2344. {
  2345. printf("\r\nWhite Card List");
  2346. for(int i = 0; i < 10; i++)
  2347. {
  2348. printf("\r\n White Card [%2d]: %s", i + 1, (char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i]);
  2349. }
  2350. printf("\r\n\r\n");
  2351. }
  2352. void WriteWhiteCard(char *v1, char *v2)
  2353. {
  2354. int cardIndex = 0;
  2355. cardIndex = atoi(v1);
  2356. if(cardIndex < 1 || cardIndex > 10)
  2357. {
  2358. printf("\r\n White Card Index Fail\r\n\r\n");
  2359. return;
  2360. }
  2361. if(strlen(v2) == 0 || strlen(v2) > 31)
  2362. {
  2363. printf("\r\n White Card Fail\r\n\r\n");
  2364. return;
  2365. }
  2366. printf("\r\n Str Len = %d = %s", strlen(v2), v2);
  2367. printf("\r\n Set White Card Index %d = %s", cardIndex, v2);
  2368. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], v2, strlen(v2));
  2369. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  2370. printf("\r\n\r\n");
  2371. }
  2372. void EraseWhiteCard(char *v1)
  2373. {
  2374. int cardIndex = 0;
  2375. cardIndex = atoi(v1);
  2376. if(cardIndex < 1 || cardIndex > 10)
  2377. {
  2378. printf("\r\n White Card Index Fail\r\n\r\n");
  2379. return;
  2380. }
  2381. printf("\r\n Erase White Card Index = %d", cardIndex);
  2382. memset((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], 0x00, 32);
  2383. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  2384. printf("\r\n\r\n");
  2385. }
  2386. // MaxChargingProfile: %s
  2387. // Offline MaxPower: %s
  2388. // Max Total Power: XXXX kW, Total Current: XXXX A, MaxSoc: XXX %
  2389. // Total Energy: XXXX kWh, Duration: XXXX Minute(s)
  2390. void ShowMaxLimit(void)
  2391. {
  2392. char tempString[64];
  2393. //************************************************************************************************
  2394. memset(tempString, 0x00, sizeof(tempString));
  2395. if(ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1)
  2396. {
  2397. sprintf(tempString, " %s", "Unlimited");
  2398. }
  2399. else
  2400. {
  2401. sprintf(tempString, " %4d kW", (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000);
  2402. }
  2403. printf(" MaxChargingProfile: %s\r\n", tempString);
  2404. //************************************************************************************************
  2405. memset(tempString, 0x00, sizeof(tempString));
  2406. if(ShmChargerInfo->OutputLimit.Offline_MaxChargingPower <= 0)
  2407. {
  2408. sprintf(tempString, " %s", "Unlimited");
  2409. }
  2410. else
  2411. {
  2412. sprintf(tempString, " %4d kW", ShmChargerInfo->OutputLimit.Offline_MaxChargingPower / 1000);
  2413. }
  2414. printf(" Offline MaxPower: %s\r\n", tempString);
  2415. //************************************************************************************************
  2416. printf(" Max Total Power: %4d kW, Total Current: %4d A, MaxSoc: %3d %%\r\n",
  2417. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  2418. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent,
  2419. ShmSysConfigAndInfo->SysConfig.MaxChargingSoc);
  2420. //************************************************************************************************
  2421. printf(" Total Energy: %4d kWh, Duration: %4d Minute(s)\r\n",
  2422. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy, ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2423. }
  2424. void ShowGunLimit(int gun_index)
  2425. {
  2426. char *str_gun_type[] = {STR_GUN_TYPE_CHADEMO, STR_GUN_TYPE_CCS, STR_GUN_TYPE_GBT};
  2427. // Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur
  2428. // 1 0 CHAdeMO 00 0000 V 0000 A 0000 / 0000 / 0000 kW 0000 / 0000 A
  2429. // Gun 1 Enable, Type: CCS, Psu Cnt: 00, Max Physical Vol: 0000 V, Cur: 0000 A, Max Config Pow: 0000 kW, Cur: 0000 A
  2430. printf(" %d %d ", gun_index + 1, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable);
  2431. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable)
  2432. {
  2433. printf(" %7s %2d",
  2434. _chargingData[gun_index]->Type <= _Type_GB ? str_gun_type[_chargingData[gun_index]->Type] : "???",
  2435. ShmChargerInfo->PsuGrouping.GroupCollection[gun_index].GunPsuQuantity);
  2436. printf(" %4d V %4d A",
  2437. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteMaxPhysicalVoltage / 10),
  2438. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteMaxPhysicalCurrent / 10));
  2439. printf(" %4d / %4d / %4d kW",
  2440. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower / 10),
  2441. _chargingData[gun_index]->ChargingProfilePower == -1 ? (int)_chargingData[gun_index]->ChargingProfilePower : ((int)_chargingData[gun_index]->ChargingProfilePower / 1000),
  2442. ShmChargerInfo->OutputLimit.GunMaxProfilePower[gun_index] == 0 ? (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : (ShmChargerInfo->OutputLimit.GunMaxProfilePower[gun_index] / 1000));
  2443. printf(" %4d / %4d A",
  2444. ((int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent / 10),
  2445. _chargingData[gun_index]->ChargingProfileCurrent == -1 ? (int)_chargingData[gun_index]->ChargingProfileCurrent : ((int)_chargingData[gun_index]->ChargingProfileCurrent / 10));
  2446. }
  2447. printf("\r\n");
  2448. }
  2449. void ShowChargerLimit(char *inputCmd, unsigned int opt)
  2450. {
  2451. bool keepRun = false;
  2452. bool reflash = false;
  2453. int time = 0;
  2454. struct timespec _Loop_time;
  2455. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  2456. {
  2457. keepRun = true;
  2458. }
  2459. printf("\r\n");
  2460. printf("Charger Limit\r\n");
  2461. do
  2462. {
  2463. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  2464. if(time >= 1000)
  2465. {
  2466. if(reflash)
  2467. {
  2468. ConsoleReflash(1, 6);
  2469. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  2470. }
  2471. ShowMaxLimit();
  2472. printf("\r\n");
  2473. printf(" Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur\r\n");
  2474. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2475. {
  2476. ShowGunLimit(i);
  2477. }
  2478. GetClockTime(&_Loop_time);
  2479. if((opt & OPTION_REFLASH) > 0)
  2480. {
  2481. reflash = true;
  2482. }
  2483. }
  2484. if(keepRun)
  2485. {
  2486. keepRun = IsLoopStopCmd() ? false : true;
  2487. usleep(10000);
  2488. }
  2489. }while(keepRun);
  2490. printf("\r\n");
  2491. }
  2492. void SetPsuCommand(char *inputCmd, unsigned int opt)
  2493. {
  2494. }
  2495. void SetGunCommand(char *v1, char *v2, char *v3)
  2496. {
  2497. int cmdItem = 0;
  2498. int cmdItemLen = 2;
  2499. int gunID = 0;
  2500. int enable = 0;
  2501. char strGunCmd[32][32] = {"enable", "operative"};
  2502. char strDescription[32][32] = {"Available", "Operative"};
  2503. gunID = atoi(v2);
  2504. enable = atoi(v3);
  2505. if(gunID <= 0 || gunID > CONNECTOR_QUANTITY || enable < 0)
  2506. {
  2507. return;
  2508. }
  2509. for(int i = 0; i < cmdItemLen; i++)
  2510. {
  2511. if(strcmp((char *)&strGunCmd[i][0], v1) == 0)
  2512. {
  2513. cmdItem = i + 1;
  2514. break;
  2515. }
  2516. }
  2517. if(cmdItem != 0)
  2518. {
  2519. switch(cmdItem)
  2520. {
  2521. case 1:
  2522. ShmChargerInfo->Control.GunAvailable[gunID - 1] = enable > 0 ? YES : NO;
  2523. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2524. break;
  2525. case 2:
  2526. _chargingData[gunID - 1]->IsAvailable = enable > 0 ? YES : NO;
  2527. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2528. break;
  2529. }
  2530. printf("Gun cmd [%s] [%s]\n", strDescription[cmdItem - 1], enable ? "Enable" : "Disable");
  2531. }
  2532. else
  2533. {
  2534. printf("Gun cmd %s not found\n", v1);
  2535. for(int i = 0; i < cmdItemLen; i++)
  2536. {
  2537. printf(" [%s] -> %s Test\n", strGunCmd[i], strDescription[i]);
  2538. }
  2539. }
  2540. printf("\r\n");
  2541. }
  2542. void ShowWebSystemInfo(void)
  2543. {
  2544. char *str_led_intensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  2545. char *str_qr_code_made[] = {STR_QR_DEFAULT, STR_QR_CUSTOMIZED, STR_QR_CHARGEBOXID};
  2546. char *str_rfid_endian[] = {STR_LITTLE_ENDIAN, STR_BIG_ENDIAN};
  2547. printf("\r\n");
  2548. printf("Web [System]\r\n");
  2549. printf(" *System ID: %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
  2550. printf(" *AuthorisationMode[%7s]\r\n",
  2551. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE ? "Enable" : "Disable");
  2552. printf(" - APP [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAPP > 0 ? "Enable" : "Disable");
  2553. printf(" - QRCode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isQRCode > 0 ? "Enable" : "Disable");
  2554. printf(" - RFID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isRFID > 0 ? "Enable" : "Disable");
  2555. printf(" - EVCCID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID > 0 ? "Enable" : "Disable");
  2556. if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian <= RFID_ENDIAN_BIG)
  2557. {
  2558. printf(" *RfidCardNumEndian [%s]\r\n", str_rfid_endian[ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian]);
  2559. }
  2560. else
  2561. {
  2562. printf(" *RfidCardNumEndian: %d\r\n", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
  2563. }
  2564. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode <= _QR_MODE_Customized)
  2565. {
  2566. printf(" *QR Code Made [%s]\r\n", str_qr_code_made[ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode]);
  2567. }
  2568. else
  2569. {
  2570. printf(" *QR Code Made: %d\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode);
  2571. }
  2572. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == _QR_MODE_Customized)
  2573. {
  2574. printf(" - QR Code Content: %s\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  2575. }
  2576. if(ShmChargerInfo->AuthInfo.QRCodeMode <= _QR_MODE_ChargeBoxId)
  2577. {
  2578. printf(" *QR Code Mode [%s]\r\n", str_qr_code_made[ShmChargerInfo->AuthInfo.QRCodeMode]);
  2579. }
  2580. else
  2581. {
  2582. printf(" *QR Code Mode: %d\r\n", ShmChargerInfo->AuthInfo.QRCodeMode);
  2583. }
  2584. if(ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity <= _LED_INTENSITY_BRIGHTEST)
  2585. {
  2586. printf(" *LED Intensity[%s]\r\n", str_led_intensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
  2587. }
  2588. else
  2589. {
  2590. printf(" *LED Intensity[%d]\r\n", ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity);
  2591. }
  2592. }
  2593. void ShowWebChargingInfo(void)
  2594. {
  2595. printf("\r\n");
  2596. printf("Web [Charging]\r\n");
  2597. printf(" *Max Charging Energy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy);
  2598. printf(" *Max Charging Power : %4d kW\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingPower);
  2599. printf(" *Max Charging Current : %4d A\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  2600. printf(" *Max Charging Duration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2601. printf(" *Max Charging Soc : %4d %%\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingSoc);
  2602. printf(" *StopCharging By Button[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton > 0 ? "Enable" : "Disable");
  2603. printf(" *Billing[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.isBilling > 0 ? "Enable" : "Disable");
  2604. printf(" - Currency[%2d]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
  2605. }
  2606. // *DHCP Client [Enable]
  2607. // - MAC Add [%s]
  2608. // - IP Add [%s]
  2609. // - Submask [%s]
  2610. // - Gateway [%s]
  2611. void ShowEthernetInfo(void)
  2612. {
  2613. printf(" *DHCP Client [%s]\r\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0 ? "Enable" : "Disable");
  2614. printf(" - MAC Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress : "NULL");
  2615. printf(" - IP Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress : "NULL");
  2616. printf(" - SubMask [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress : "NULL");
  2617. printf(" - Gateway [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress : "NULL");
  2618. }
  2619. // *WiFi Mode [Station]
  2620. // - SSID [%s]
  2621. // - PWD [%s]
  2622. // - TargetMac [%s]
  2623. // - RSSI [%s]
  2624. // - DHCP [%s]
  2625. // - MAC Add [%s]
  2626. // - IP Add [%s]
  2627. // - Submask [%s]
  2628. // - Gateway [%s]
  2629. // - ConnStatus [Connected]
  2630. void ShowWiFiInfo(void)
  2631. {
  2632. char *str_wifi_mode[] = {"Disable", "Station", "AP Mode"};
  2633. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode <= _SYS_WIFI_MODE_AP)
  2634. {
  2635. printf(" *WiFi Mode [%s]\r\n", str_wifi_mode[ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode]);
  2636. }
  2637. else
  2638. {
  2639. printf(" *WiFi Mode [%d]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
  2640. }
  2641. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_STATION)
  2642. {
  2643. printf(" - SSID [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid : "NULL");
  2644. printf(" - PWD [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword : "NULL");
  2645. printf(" - TargetMac [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac : "NULL");
  2646. printf(" - RSSI [%d dBm]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi);
  2647. printf(" - DHCP [%s]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient == 0 ? "Enable" : "Disable");
  2648. printf(" - MAC Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress : "NULL");
  2649. printf(" - IP Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress : "NULL");
  2650. printf(" - SubMask [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress : "NULL");
  2651. printf(" - Gateway [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress : "NULL");
  2652. printf(" - ConnStatus [%s]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ? "Connected" : "Disconnected");
  2653. }
  2654. }
  2655. // *3G/4G Mode [%s]
  2656. // - APN [%s]
  2657. // - NetworkType[%s]
  2658. // - RSSI [%d dBm]
  2659. // - ChapPapId [%s]
  2660. // - ChapPapPwd [%s]
  2661. // - Modem IMEI [%s]
  2662. // - SIM IMSI [%s]
  2663. // - SIM ICCID [%s]
  2664. // - SIM Status [%s]
  2665. // - Modem Mode [%s]
  2666. // - IP Add [%s]
  2667. // - ConnStatus [%s]
  2668. void Show3G4GInfo(void)
  2669. {
  2670. char *strNetworkType[] = {"Auto", "CDMA", "WCDMA", "LTE", "TD-SCDMA", "UMTS", "CDMA", "HDR", "CDMA/HDR"};
  2671. char *strSimStatus[] = {"No SIM Card", "Valid SIM Card", "Invalid SIM Card"};
  2672. char *strModemMode[] = {"No Services", "CDMA", "GSM/GPRS", "WCDMA", "GSM/WCDMA", "TD_SCDMA", "HSPA", "LTE", "Mode 8", "Unknown"};
  2673. printf(" *3G/4G Mode [%s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES ? "Enable" : "Disable");
  2674. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
  2675. {
  2676. printf(" - APN [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn : "NULL");
  2677. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkType <= 8)
  2678. {
  2679. printf(" - NetworkType[%s]\r\n", strNetworkType[ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkType]);
  2680. }
  2681. else
  2682. {
  2683. printf(" - NetworkType[%d]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkType);
  2684. }
  2685. printf(" - RSSI [%d dBm]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
  2686. printf(" - ChapPapId [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId : "NULL");
  2687. printf(" - ChapPapPwd [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd : "NULL");
  2688. printf(" - Modem IMEI [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei : "NULL");
  2689. printf(" - SIM IMSI [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi : "NULL");
  2690. printf(" - SIM ICCID [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid : "NULL");
  2691. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus <= 2)
  2692. {
  2693. printf(" - SIM Status [%s]\r\n", strSimStatus[ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus]);
  2694. }
  2695. else
  2696. {
  2697. printf(" - SIM Status [%d]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus);
  2698. }
  2699. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode <= 9)
  2700. {
  2701. printf(" - Modem Mode [%s]\r\n", strModemMode[ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode]);
  2702. }
  2703. else
  2704. {
  2705. printf(" - Modem Mode [%d]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode);
  2706. }
  2707. printf(" - IP Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress : "NULL");
  2708. printf(" - ConnStatus [%s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ? "Connected" : "Disconnected");
  2709. }
  2710. }
  2711. void ShowWebNetworkInfo(void)
  2712. {
  2713. printf("\r\n");
  2714. printf("Web [Network]\r\n");
  2715. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2716. ShowEthernetInfo();
  2717. ShowWiFiInfo();
  2718. Show3G4GInfo();
  2719. }
  2720. void ShowWebEthernetOnly(void)
  2721. {
  2722. printf("\r\n");
  2723. printf("Web [Network]\r\n");
  2724. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2725. ShowEthernetInfo();
  2726. }
  2727. void ShowWebWiFiOnly(void)
  2728. {
  2729. printf("\r\n");
  2730. printf("Web [Network]\r\n");
  2731. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2732. ShowWiFiInfo();
  2733. }
  2734. void ShowWeb3G4GOnly(void)
  2735. {
  2736. printf("\r\n");
  2737. printf("Web [Network]\r\n");
  2738. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2739. Show3G4GInfo();
  2740. }
  2741. void ShowWebBackendInfo(void)
  2742. {
  2743. char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
  2744. char *str_security_profile[] = {
  2745. "None security",
  2746. "Unsecured Transport with Basic Atuentication",
  2747. "TLS with Basic Authentication",
  2748. "TLS with Client Side Certificates"
  2749. };
  2750. printf("\r\n");
  2751. printf("Web [Backend]\r\n");
  2752. printf(" *Common\r\n");
  2753. printf(" - Backend Timeout : %d s\r\n", ShmSysConfigAndInfo->SysConfig.BackendConnTimeout);
  2754. if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy <= _OFFLINE_POLICY_NO_CHARGING)
  2755. {
  2756. printf(" - Offline Policy : %s\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
  2757. }
  2758. else
  2759. {
  2760. printf(" - Offline Policy : %d\r\n", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
  2761. }
  2762. printf(" - OfflineMaxEnergy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy);
  2763. printf(" - OfflineMaxDuration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration);
  2764. printf(" *OCPP\r\n");
  2765. printf(" - OcppStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES ? "Connected" : "Disconnected");
  2766. printf(" - OcppURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  2767. printf(" - ChargeBoxId: %s\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2768. printf(" - Vendor : %s\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2769. if(ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile <= 3)
  2770. {
  2771. printf(" - Security : %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile]);
  2772. }
  2773. else
  2774. {
  2775. printf(" - Security : %d\r\n", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2776. }
  2777. printf(" - MaintainStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus == YES ? "Connected" : "Disconnected");
  2778. printf(" - MaintainURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  2779. if(ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile <= 3)
  2780. {
  2781. printf(" - MaintainSecurity: %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile]);
  2782. }
  2783. else
  2784. {
  2785. printf(" - MaintainSecurity: %d\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile);
  2786. }
  2787. printf(" *TTIA[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES ? "Enable" : "Disable");
  2788. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES)
  2789. {
  2790. printf(" - ServerAddress: %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  2791. printf(" - ServerPort : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  2792. printf(" - BusVenderId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  2793. printf(" - Provider : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  2794. printf(" - CompanyNo : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  2795. printf(" - ChargeBoxId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  2796. printf(" - EVSEStation : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  2797. }
  2798. }
  2799. void ShowWebAllInfo(void)
  2800. {
  2801. ShowWebSystemInfo();
  2802. ShowWebChargingInfo();
  2803. ShowWebNetworkInfo();
  2804. ShowWebBackendInfo();
  2805. }
  2806. void ShowWebInfo(char *inputCmd, unsigned int opt)
  2807. {
  2808. int totalCnt = 0, maxPara = 0;
  2809. maxPara = 1;
  2810. totalCnt = GetSubCommand(inputCmd);
  2811. if(totalCnt > maxPara)
  2812. {
  2813. printf("Input cmd fail ------ web [cmd]\r\n\r\n");
  2814. return;
  2815. }
  2816. bool find = false;
  2817. int showItem = 0;
  2818. int itemLen = 8;
  2819. char strItem[32][32] = {"system", "charging", "network", "backend", "all", "eth", "wifi", "4g"};
  2820. void *actionList[32] = {
  2821. &ShowWebSystemInfo, &ShowWebChargingInfo, &ShowWebNetworkInfo, &ShowWebBackendInfo,
  2822. &ShowWebAllInfo, &ShowWebEthernetOnly, &ShowWebWiFiOnly, &ShowWeb3G4GOnly};
  2823. void (*ItemAction)();
  2824. for(showItem = 0; showItem < itemLen; showItem++)
  2825. {
  2826. if(strcmp((char *)&strItem[showItem][0], &MultiSubCmd[0][0]) == 0)
  2827. {
  2828. find = true;
  2829. break;
  2830. }
  2831. }
  2832. if(find)
  2833. {
  2834. ItemAction = actionList[showItem];
  2835. ItemAction();
  2836. }
  2837. else
  2838. {
  2839. printf("\r\n");
  2840. printf ("Input cmd fail ------ web [cmd]\r\n");
  2841. for(int i = 0; i < itemLen; i++)
  2842. {
  2843. printf(" [cmd] %s\r\n", (char *)&strItem[i][0]);
  2844. }
  2845. }
  2846. printf("\r\n");
  2847. }
  2848. // Gun 1 ( CCS ) Soc: XXX %, Energy: XXXXXXX.XXX kWh, IdTag: [XXXXXXXXXX]
  2849. // (XX) (X) Target: XXXX V, XXXX A, Cap: XXXX A, XXXX kW, TxId: [XXXXXXXXXX]
  2850. // PSU: XXXX V, XXXX A, Limit: XXXX A, XXXX kW, Local: XXXXXXX.XXX kWh
  2851. // Start: [0000-00-00 00:00:00] PSU: XXXX V, XXXX A, Limit: XXXX A, XXXX kW, Local: XXXXXXX.XXX kWh
  2852. // Gun: XXXX V, XXXX A, Remote: XXXXXXX.XXX kWh, Meter: XXXXXXX.XXX kWh
  2853. // Stop: [0000-00-00 00:00:00] Gun: XXXX V, XXXX A, Remote: XXXXXXX.XXX kWh, Meter: XXXXXXX.XXX kWh
  2854. // Gun 1 ( CCS ) Soc: XXX %, Energy: XXXXXXX.XXX kWh, IdTag: [XXXXXXXXXX]
  2855. // (XX) (X) Target: XXXX V, XXXX A, Cap: XXXX A, XXXX kW, TxId: [XXXXXXXXXX]
  2856. // Start: [0000-00-00 00:00:00] PSU: XXXX V, XXXX A, Limit: XXXX A, XXXX kW, Ratio: X.XX %
  2857. // Stop: [0000-00-00 00:00:00] Gun: XXXX V, XXXX A, Power: XXXX.X kW, FireV: XXXX.X V
  2858. // Remote: XXXXXXX.XXX kWh, Local: XXXXXXX.XXX kWh, Meter: XXXXXXX.XXX kWh
  2859. void ShowGunInfo(int gun)
  2860. {
  2861. char *str_gun_type[] = {"CHAdeMO", " CCS ", " GBT "};
  2862. #if 0
  2863. printf(" Gun %d (%s) Soc: %3d %s, Energy: %10.3f kWh, IdTag [%20s] Transaction [%d], TotalCost: %.2f\r\n",
  2864. gun + 1,
  2865. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
  2866. _chargingData[gun]->EvBatterySoc, "%",
  2867. _chargingData[gun]->PresentChargedEnergy,
  2868. _chargingData[gun]->StartUserId,
  2869. ShmChargerInfo->UserTransaction[gun].TransactionId,
  2870. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost);
  2871. #endif
  2872. //************************************************************************************************
  2873. printf(" Gun %d (%s) Soc: %3d %s, Energy: %11.3f kWh",
  2874. gun + 1,
  2875. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
  2876. _chargingData[gun]->EvBatterySoc, "%",
  2877. _chargingData[gun]->PresentChargedEnergy);
  2878. if(strlen((char *)_chargingData[gun]->StartUserId) > 0)
  2879. {
  2880. printf(", IdTag: [%s]", _chargingData[gun]->StartUserId);
  2881. }
  2882. printf("\r\n");
  2883. //************************************************************************************************
  2884. printf(" (%2d) (%s) Target: %4d V, %4d A, Cap: %4d A, %4d kW",
  2885. _chargingData[gun]->SystemStatus,
  2886. _chargingData[gun]->ConnectorPlugIn ? "O" : "X",
  2887. (int)_chargingData[gun]->EvBatterytargetVoltage,
  2888. (int)_chargingData[gun]->EvBatterytargetCurrent,
  2889. (int)(_chargingData[gun]->AvailableChargingCurrent / 10),
  2890. (int)(_chargingData[gun]->AvailableChargingPower / 10));
  2891. if(ShmChargerInfo->UserTransaction[gun].TransactionId > 0)
  2892. {
  2893. printf(", TxId: [%d]", ShmChargerInfo->UserTransaction[gun].TransactionId);
  2894. }
  2895. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost > 0)
  2896. {
  2897. printf(", $: %.2f", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost);
  2898. }
  2899. printf("\r\n");
  2900. //************************************************************************************************
  2901. if(strlen(ShmChargerInfo->Timestamp[gun].StartCharging) > 0)
  2902. {
  2903. printf(" Start: [%s] ", ShmChargerInfo->Timestamp[gun].StartCharging);
  2904. }
  2905. else
  2906. {
  2907. printf(" ");
  2908. }
  2909. printf("PSU: %4d V, %4d A, Limit: %4d A, %4d kW, Ratio: %4.2f %%\r\n",
  2910. (int)(_chargingData[gun]->PresentChargingVoltage),
  2911. (int)(_chargingData[gun]->PresentChargingCurrent),
  2912. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityCurrent / 10),
  2913. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityPower / 10),
  2914. ShmPsuGrouping->GroupCollection[gun].MaxOutputRatio);
  2915. //************************************************************************************************
  2916. if(strlen(ShmChargerInfo->Timestamp[gun].StopCharging) > 0)
  2917. {
  2918. printf(" Stop: [%s] ", ShmChargerInfo->Timestamp[gun].StopCharging);
  2919. }
  2920. else
  2921. {
  2922. printf(" ");
  2923. }
  2924. printf("Gun: %4d V, %4d A, Power: %6.1f kW, FireV: %6.1f V\r\n",
  2925. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingVoltage / 10),
  2926. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingCurrent / 10),
  2927. _chargingData[gun]->PresentChargingPower,
  2928. (_chargingData[gun]->FireChargingVoltage / 10));
  2929. //************************************************************************************************
  2930. printf(" Remote: %11.3f kWh, Local: %11.3f kWh, Meter: %11.3f kWh\r\n",
  2931. ShmChargerInfo->MeterValue[gun].GunConsumption,
  2932. ShmChargerInfo->MeterValue[gun].LocalConsumption,
  2933. _chargingData[gun]->PowerConsumption);
  2934. }
  2935. void ShowInfo(char *inputCmd, unsigned int opt)
  2936. {
  2937. bool keepRun = false;
  2938. bool reflash = false;
  2939. int time = 0;
  2940. struct timespec _Loop_time;
  2941. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  2942. {
  2943. keepRun = true;
  2944. }
  2945. do
  2946. {
  2947. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  2948. if(time >= 1000)
  2949. {
  2950. if(reflash)
  2951. {
  2952. ConsoleReflash(CONNECTOR_QUANTITY, 6);
  2953. }
  2954. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2955. {
  2956. printf("\r\n");
  2957. ShowGunInfo(i);
  2958. }
  2959. GetClockTime(&_Loop_time);
  2960. if((opt & OPTION_REFLASH) > 0)
  2961. {
  2962. reflash = true;
  2963. }
  2964. }
  2965. if(keepRun)
  2966. {
  2967. keepRun = IsLoopStopCmd() ? false : true;
  2968. usleep(10000);
  2969. }
  2970. }while(keepRun);
  2971. printf("\r\n");
  2972. }
  2973. void RtcSyncCmd(char *inputCmd, unsigned int opt)
  2974. {
  2975. int totalCnt = 0, maxPara = 0;
  2976. char hostAdd[32];
  2977. int dispenser = 0, offset = 0;
  2978. memset(hostAdd, 0x00, sizeof(hostAdd));
  2979. maxPara = 2;
  2980. totalCnt = GetSubCommand(inputCmd);
  2981. if(totalCnt != maxPara)
  2982. {
  2983. printf("Input cmd fail ------ rtc [dispenser 1-4] [offset minute]\r\n\r\n");
  2984. return;
  2985. }
  2986. printf("\r\n");
  2987. dispenser = atoi(&MultiSubCmd[0][0]);
  2988. offset = atoi(&MultiSubCmd[1][0]);
  2989. if(dispenser <= 0 || dispenser > CONNECTOR_QUANTITY)
  2990. {
  2991. printf("dispenser %d over range\r\n\r\n", dispenser);
  2992. return;
  2993. }
  2994. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser - 1].LocalStatus == _DS_None ||
  2995. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser - 1].LocalStatus == _DS_Timeout)
  2996. {
  2997. printf("dispenser %d is not available\r\n\r\n", dispenser);
  2998. return;
  2999. }
  3000. // find dispenser ip address
  3001. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  3002. {
  3003. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched)
  3004. {
  3005. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex == (dispenser - 1))
  3006. {
  3007. sprintf(hostAdd, "%d.%d.%d.%d",
  3008. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 0) &0xFF),
  3009. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 8) &0xFF),
  3010. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 16) &0xFF),
  3011. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 24) &0xFF));
  3012. }
  3013. }
  3014. }
  3015. if(strlen(hostAdd) == 0)
  3016. {
  3017. printf("dispenser %d ip is not available\r\n\r\n", dispenser);
  3018. return;
  3019. }
  3020. printf("try sycn dispenser %d [%s] rtc, offset: %d minutes\r\n", dispenser, hostAdd, offset);
  3021. // get current time and create offset time
  3022. time_t timep;
  3023. struct tm *tm;
  3024. time(&timep);
  3025. tm = localtime(&timep);
  3026. printf(" NowTime: %d/%02d/%02d %02d:%02d:%02d\r\n",
  3027. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3028. if(offset != 0)
  3029. {
  3030. timep += (offset * 60);
  3031. tm = localtime(&timep);
  3032. printf("OffsetTime: %d/%02d/%02d %02d:%02d:%02d\r\n\r\n",
  3033. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3034. }
  3035. // create send socket
  3036. int rtcfd = 0;
  3037. struct sockaddr_in serverInfo;
  3038. struct timeval tv;
  3039. char rtcTxBuffer[64];
  3040. char rtcRxBuffer[64];
  3041. int txLen = 0, rxLen = 0;
  3042. unsigned char chksum = 0x00;
  3043. rtcfd = socket(AF_INET, SOCK_STREAM, 0);
  3044. if (rtcfd < 0)
  3045. {
  3046. printf("create rtc socket fail\r\n\r\n");
  3047. return;
  3048. }
  3049. memset(rtcTxBuffer, 0x00, sizeof(rtcTxBuffer));
  3050. memset(rtcRxBuffer, 0x00, sizeof(rtcRxBuffer));
  3051. tv.tv_sec = 3;
  3052. tv.tv_usec = 0;
  3053. setsockopt(rtcfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)); //設定等待3s
  3054. setsockopt(rtcfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval)); //設定傳送3s
  3055. bzero(&serverInfo,sizeof(serverInfo));
  3056. serverInfo.sin_family = AF_INET;
  3057. serverInfo.sin_addr.s_addr = inet_addr(hostAdd);
  3058. serverInfo.sin_port = htons(8234);
  3059. if(connect(rtcfd, (struct sockaddr *)&serverInfo, sizeof(serverInfo)) < 0)
  3060. {
  3061. printf("connect to host: %s fail\r\n\r\n", hostAdd);
  3062. close(rtcfd);
  3063. return;
  3064. }
  3065. // set tx header & data
  3066. rtcTxBuffer[0] = 0xAA; // Frame ID
  3067. rtcTxBuffer[1] = 0x00; // Master address
  3068. rtcTxBuffer[2] = 0xFF; // Slave address
  3069. rtcTxBuffer[3] = 0x87; // 0x87
  3070. rtcTxBuffer[4] = 0x0E; // Length_Low
  3071. rtcTxBuffer[5] = 0x00; // Length_High
  3072. sprintf(&rtcTxBuffer[6], "%04d%02d%02d%02d%02d%02d",
  3073. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3074. txLen = rtcTxBuffer[4] + (rtcTxBuffer[5] << 8);
  3075. chksum = 0;
  3076. for(int i = 0; i < txLen; i++)
  3077. {
  3078. chksum ^= rtcTxBuffer[6 + i];
  3079. }
  3080. rtcTxBuffer[6 + txLen] = chksum;
  3081. send(rtcfd, rtcTxBuffer, txLen + 7, MSG_NOSIGNAL);
  3082. // receive
  3083. if(recv(rtcfd, &rtcRxBuffer[0], 6, MSG_WAITALL) < 0)
  3084. {
  3085. printf("read head fail\r\n\r\n");
  3086. close(rtcfd);
  3087. return;
  3088. }
  3089. rxLen = rtcRxBuffer[4] + (rtcRxBuffer[5] << 8);
  3090. if(recv(rtcfd, &rtcRxBuffer[6], rxLen + 1, MSG_WAITALL) < 0)
  3091. {
  3092. printf("read data fail\r\n\r\n");
  3093. close(rtcfd);
  3094. return;
  3095. }
  3096. chksum = 0;
  3097. for(int i = 0; i < rxLen; i++)
  3098. {
  3099. chksum ^= rtcRxBuffer[6 + i];
  3100. }
  3101. if(chksum == rtcRxBuffer[6 + rxLen])
  3102. {
  3103. printf("set %s rtc: ", hostAdd);
  3104. for(int i = 0; i < txLen; i++)
  3105. {
  3106. printf("%c", rtcTxBuffer[6 + i]);
  3107. }
  3108. printf(" %s\r\n\r\n", rtcRxBuffer[6] == 0x01 ? "success" : "fail");
  3109. }
  3110. else
  3111. {
  3112. printf("receive rtc checksum fail\r\n\r\n");
  3113. }
  3114. close(rtcfd);
  3115. }
  3116. void ParsingModelName(char *modelName)
  3117. {
  3118. ParsingRatedCur parsingRatedCur = {0};
  3119. RateCurInfo *pRatedCurInfo = NULL;
  3120. if(RatedCurrentParsing(modelName, &parsingRatedCur) != PASS)
  3121. {
  3122. printf("Parsing [%s] failed\r\n", modelName);
  3123. return;
  3124. }
  3125. printf("Model Name: [%s]\r\n", modelName);
  3126. for(int i = 0; i < 2; i++)
  3127. {
  3128. pRatedCurInfo = (RateCurInfo *)&parsingRatedCur.ParsingInfo[i];
  3129. printf(" Gun %d Type %d, MaxVol: %d, MaxCur: %d\r\n",
  3130. i + 1, pRatedCurInfo->GunType, pRatedCurInfo->Voltage, pRatedCurInfo->Current);
  3131. }
  3132. }
  3133. void ParsingModelNameCmd(char *inputCmd, unsigned int opt)
  3134. {
  3135. int totalCnt = 0, maxPara = 0;
  3136. maxPara = 1;
  3137. totalCnt = GetSubCommand(inputCmd);
  3138. if(totalCnt > maxPara)
  3139. {
  3140. printf("Input cmd fail ------ pmodel [model_name]\r\n\r\n");
  3141. return;
  3142. }
  3143. printf("\r\n");
  3144. if(totalCnt != 0)
  3145. {
  3146. ParsingModelName(&MultiSubCmd[0][0]);
  3147. }
  3148. else
  3149. {
  3150. printf("Cabinet\r\n");
  3151. ParsingModelName((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  3152. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  3153. {
  3154. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  3155. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  3156. {
  3157. printf("\r\n");
  3158. printf("Dispenser %d\r\n", i + 1);
  3159. ParsingModelName((char *)&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName[0]);
  3160. }
  3161. }
  3162. }
  3163. printf("\r\n");
  3164. }
  3165. void CustomerPriceTest(char *inputCmd, unsigned int opt)
  3166. {
  3167. #if 0
  3168. char priceString[512];
  3169. float price = 0;
  3170. printf("\r\n");
  3171. // running cost
  3172. printf("Running Cost\r\n");
  3173. strcpy(priceString, "Connection Fee: $0 NTD; Session Fee: $15.96 NTD; Occupancy Fee: $0 NTD; Total Cost: $15.96 NTD; Account Balance: $37693 NTD");
  3174. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3175. printf("Connection Fee: %.2f\r\n", price);
  3176. price = PriceParsing((char *)priceString, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
  3177. printf("Session Fee: %.2f\r\n", price);
  3178. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3179. printf("Occupancy Fee: %.2f\r\n", price);
  3180. price = PriceParsing((char *)priceString, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
  3181. printf("Total Cost: %.2f\r\n", price);
  3182. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3183. printf("Account Balance: %.2f\r\n", price);
  3184. // final cost
  3185. printf("Final Cost\r\n");
  3186. strcpy(priceString, "Connection Fee: $0 NTD; Session Fee: $283.68 NTD; Occupancy Fee: $0 NTD; Total Cost: $283.68 NTD; Account Balance: $37410 NTD");
  3187. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3188. printf("Connection Fee: %.2f\r\n", price);
  3189. price = PriceParsing((char *)priceString, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
  3190. printf("Session Fee: %.2f\r\n", price);
  3191. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3192. printf("Occupancy Fee: %.2f\r\n", price);
  3193. price = PriceParsing((char *)priceString, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
  3194. printf("Total Cost: %.2f\r\n", price);
  3195. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3196. printf("Account Balance: %.2f\r\n", price);
  3197. // user price
  3198. printf("User Price\r\n");
  3199. strcpy(priceString, "Connection Fee: $0 NTD/time; Current Rate: $12 NTD/kWh; Occupancy Fee: $0 NTD/hr; Account Balance: $17553 NTD");
  3200. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3201. printf("Connection Fee: %.2f\r\n", price);
  3202. price = PriceParsing((char *)priceString, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
  3203. printf("Current Rate: %.2f\r\n", price);
  3204. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3205. printf("Occupancy Fee: %.2f\r\n", price);
  3206. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3207. printf("Account Balance: %.2f\r\n", price);
  3208. // default price
  3209. printf("Default Price\r\n");
  3210. strcpy(priceString, "Connection Fee: $0 NTD/time; Current Rate: $12 NTD/kWh; Occupancy Fee: $0 NTD/hr");
  3211. price = PriceParsing(priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3212. printf("Connection Fee: %.2f\r\n", price);
  3213. price = PriceParsing(priceString, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
  3214. printf("Current Rate: %.2f\r\n", price);
  3215. price = PriceParsing(priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3216. printf("Occupancy Fee: %.2f\r\n", price);
  3217. printf("\r\n");
  3218. printf("TCC Default Price\r\n");
  3219. strcpy(priceString, "$ 12/kWh");
  3220. price = PriceParsing(priceString, "", "");
  3221. printf("Default: %.2f\r\n", price);
  3222. printf("\r\n");
  3223. char userPrice[512];
  3224. printf("Shell Default Price\r\n");
  3225. strcpy(priceString, "100.0 kW\nPrice\nTransaction Fee: $0.6165/Flat\nIdle Fee: $0.5/Flat\n\n100.0 kW\nPrice\nTransaction Fee: $0.6165/Flat\nIdle Fee: $0.5/Flat\n\n");
  3226. ShellPriceParsing(priceString, userPrice);
  3227. printf("DefaultPrice: %s\r\n", userPrice);
  3228. printf("\r\n");
  3229. printf("Shell User Price\r\n");
  3230. ShellPriceParsing(priceString, userPrice);
  3231. printf("UserPrice: %s\r\n", userPrice);
  3232. printf("\r\n");
  3233. strcpy(priceString, "Current Period Price:$0.35/kWh\nCurrent Idle Fee: $5.0/hr\nCurrent Total: 2.70kWh $2.53 ConnectorId: 1\nLast update: 2021-06-28T11:22:31");
  3234. price = ShellRunningCostParsing(priceString);
  3235. printf("Shell Running Cost\r\n");
  3236. printf("Cost: %.2f\r\n", price);
  3237. printf("\r\n");
  3238. strcpy(priceString, "2022-01-18 07:00:00-2022-01-18 08:15:30\n07:00 AM $1.00/kWh 4.30kWh Cost: $4.300\n07:30 AM $2.00/kWh 0.00kWh Cost: $4.300\n07:46 AM $0.00/Flat 10m Cost: $0.000\n07:56 AM $0.50/Flat 19m Cost: $0.500\nTotal\nSale: $4.80\nTax: $0.00\nTransaction Fee: $0.62\nDiscount: $0.00\nCost: $5.42\nEnergy: 4.3000kWh\nTime: 1 Hrs 15 Mins\nPayment: RFID\nReceipt: https://qa.qa.greenlotstest-qa.com/greenlots/receipt.jsf?session5658739 | Call 1 800 Greenlots or check app for more detailed receipt\nEV_DISCONNECTED");
  3239. printf("Shell Final Cost\r\n");
  3240. int urlLen = 0;
  3241. char url[512];
  3242. price = ShellFinalCostParsing(priceString);
  3243. urlLen = GetShellReceiptInfo(priceString, url);
  3244. printf("Cost: %.2f\r\n", price);
  3245. if(urlLen > 0)
  3246. {
  3247. printf("Receipt: [%s]\r\n", url);
  3248. }
  3249. #endif
  3250. }
  3251. void EvCommMsgDebug(char *inputCmd, unsigned int opt)
  3252. {
  3253. int totalCnt = 0, maxPara = 0;
  3254. maxPara = 2;
  3255. totalCnt = GetSubCommand(inputCmd);
  3256. printf("\r\n");
  3257. if(totalCnt == 1)
  3258. {
  3259. if(strcmp(&MultiSubCmd[0][0], "clean") == 0)
  3260. {
  3261. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0] = 0;
  3262. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1] = 0;
  3263. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2] = 0;
  3264. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3] = 0;
  3265. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = false;
  3266. printf("Clean All EvComm Msg Flag\r\n");
  3267. printf("Disable MsgEvComm Flag Debug\r\n\r\n");
  3268. return;
  3269. }
  3270. }
  3271. if(totalCnt != maxPara)
  3272. {
  3273. printf("Input cmd fail ------ evmsg [reg] [enable 0-1]\r\n\r\n");
  3274. return;
  3275. }
  3276. bool find = false;
  3277. int reg = 0, enable = 0;
  3278. reg = atoi(&MultiSubCmd[0][0]);
  3279. enable = atoi(&MultiSubCmd[1][0]);
  3280. if(enable > 1 || enable < 0)
  3281. {
  3282. printf("enable(%d) out of range\r\n\r\n", enable);
  3283. return;
  3284. }
  3285. if(reg >= _Reg_Dispenser_Model_Name && reg < _Reg_None)
  3286. {
  3287. find = true;
  3288. if(enable)
  3289. {
  3290. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[reg / 32] |= (1 << (reg % 32));
  3291. printf("Set EvComm Msg Flag: 0x%02X\r\n", reg);
  3292. }
  3293. else
  3294. {
  3295. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[reg / 32] &= ~(1 << (reg % 32));
  3296. printf("Clean EvComm Msg Flag: 0x%02X\r\n", reg);
  3297. }
  3298. }
  3299. else
  3300. {
  3301. if(strcmp(&MultiSubCmd[0][0], "all") == 0)
  3302. {
  3303. find = true;
  3304. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.bits.RegDbg_All = enable;
  3305. printf("%s EvComm All Msg Flag\r\n", enable ? "Enable" : "Disable");
  3306. }
  3307. }
  3308. if(find)
  3309. {
  3310. printf("EvCommMsg[0]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0]);
  3311. printf("EvCommMsg[1]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1]);
  3312. printf("EvCommMsg[2]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2]);
  3313. printf("EvCommMsg[3]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3]);
  3314. printf("\r\n");
  3315. if(ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0] ||
  3316. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1] ||
  3317. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2] ||
  3318. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3])
  3319. {
  3320. if(!ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm)
  3321. {
  3322. printf("Enable MsgEvComm Flag Debug\r\n\r\n");
  3323. }
  3324. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = true;
  3325. }
  3326. else
  3327. {
  3328. if(ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm)
  3329. {
  3330. printf("Disable MsgEvComm Flag Debug\r\n\r\n");
  3331. }
  3332. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = false;
  3333. }
  3334. }
  3335. else
  3336. {
  3337. printf("reg: 0x%02X out of range\r\n", reg);
  3338. printf("\r\n");
  3339. }
  3340. }
  3341. void EvCommIdDebug(char *inputCmd, unsigned int opt)
  3342. {
  3343. int totalCnt = 0, maxPara = 0;
  3344. maxPara = 2;
  3345. totalCnt = GetSubCommand(inputCmd);
  3346. printf("\r\n");
  3347. if(totalCnt != maxPara)
  3348. {
  3349. printf("Input cmd fail ------ evid [id] [enable 0-1]\r\n\r\n");
  3350. return;
  3351. }
  3352. int id = 0, enable = 0;
  3353. id = atoi(&MultiSubCmd[0][0]);
  3354. enable = atoi(&MultiSubCmd[1][0]);
  3355. if(enable > 1 || enable < 0)
  3356. {
  3357. printf("enable(%d) out of range\r\n\r\n", enable);
  3358. return;
  3359. }
  3360. if(id > 0 && id <= CONNECTOR_QUANTITY)
  3361. {
  3362. if(enable)
  3363. {
  3364. ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal |= (1 << id);
  3365. printf("Set EvComm ID %d Enable\r\n", id);
  3366. }
  3367. else
  3368. {
  3369. ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal &= ~(1 << id);
  3370. printf("Clean EvComm ID %d\r\n", id);
  3371. }
  3372. printf("EvComm ID: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal);
  3373. printf("\r\n");
  3374. }
  3375. else
  3376. {
  3377. printf("id(%d) out of range\r\n\r\n", id);
  3378. }
  3379. }
  3380. bool SetModelName(char *modelName)
  3381. {
  3382. if(!IsCabinetModelNameLegal(modelName))
  3383. {
  3384. printf("Model Name: [%s] is Illegal\r\n", modelName);
  3385. return false;
  3386. }
  3387. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.ModelName, modelName, MODELNAME_LENGTH);
  3388. printf("Set Model Name: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.ModelName);
  3389. return true;
  3390. }
  3391. bool SetSerialNumber(char *serialNumber)
  3392. {
  3393. if(!IsSerialNumberLegal(serialNumber))
  3394. {
  3395. printf("Serial Number: [%s] is Illegal\r\n", serialNumber);
  3396. return false;
  3397. }
  3398. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.SerialNumber, serialNumber, SERIAL_NUMBER_LENGTH);
  3399. printf("Set Serial Number: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3400. return true;
  3401. }
  3402. bool SetSystemID(char *systemId)
  3403. {
  3404. if(!IsSystemIdLegal(systemId))
  3405. {
  3406. printf("System ID: [%s] is Illegal\r\n", systemId);
  3407. return false;
  3408. }
  3409. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  3410. printf("Set System ID: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
  3411. return true;
  3412. }
  3413. bool CleanSystemID(void)
  3414. {
  3415. memset((char *)&ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.SystemId));
  3416. printf("Clean System ID OK\r\n");
  3417. return true;
  3418. }
  3419. bool SetAuthorisationMode(char *mode)
  3420. {
  3421. bool disable = false;
  3422. if(strcmp(mode, "disable") == EQUAL)
  3423. {
  3424. disable = true;
  3425. }
  3426. else
  3427. {
  3428. if(strcmp(mode, "enable") != EQUAL)
  3429. {
  3430. printf("Authorisation Mode: [%s] is Illegal\r\n", mode);
  3431. printf(" [value] enable | disable\r\n");
  3432. return false;
  3433. }
  3434. }
  3435. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = disable;
  3436. printf("Set Authorisation Mode: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.AuthorisationMode == 0 ? "Enable" : "Disable");
  3437. if(disable && ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID)
  3438. {
  3439. printf("AuthorisationMode Is Disable, AuthrizeByEVCCID Need To Set Disable\r\n");
  3440. ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID = false;
  3441. }
  3442. return true;
  3443. }
  3444. bool SetAuthrizeByEVCCID(char *isEVCCID)
  3445. {
  3446. bool enable = false;
  3447. if(strcmp(isEVCCID, "enable") == EQUAL)
  3448. {
  3449. enable = true;
  3450. }
  3451. else
  3452. {
  3453. if(strcmp(isEVCCID, "disable") != EQUAL)
  3454. {
  3455. printf("Authrize By EVCCID: [%s] is Illegal\r\n", isEVCCID);
  3456. printf(" [value] enable | disable\r\n");
  3457. return false;
  3458. }
  3459. }
  3460. if(enable && ShmSysConfigAndInfo->SysConfig.AuthorisationMode == 1)
  3461. {
  3462. printf("AuthorisationMode Is Disable, Reset AuthrizeByEVCCID To Disable\r\n");
  3463. enable = false;
  3464. }
  3465. ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID = enable;
  3466. printf("Set AuthrizeByEVCCID: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID ? "Enable" : "Disable");
  3467. return true;
  3468. }
  3469. bool SetQRCodeMadeMode(char *qrCodeMode)
  3470. {
  3471. bool customized = false;
  3472. if(strcmp(qrCodeMode, "customized") == EQUAL)
  3473. {
  3474. customized = true;
  3475. }
  3476. else
  3477. {
  3478. if(strcmp(qrCodeMode, "default") != EQUAL)
  3479. {
  3480. printf("QR Code Made Mode: [%s] is Illegal\r\n", qrCodeMode);
  3481. printf(" [value] default | customized\r\n");
  3482. return false;
  3483. }
  3484. }
  3485. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = customized;
  3486. printf("Set QRCodeMadeMode: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode ? "Customized" : "Default");
  3487. return true;
  3488. }
  3489. bool SetQRCodeContent(char *content)
  3490. {
  3491. if(strlen(content) >= sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent))
  3492. {
  3493. printf("QR Code Content: [%s] is Out Of Length\r\n", content);
  3494. return false;
  3495. }
  3496. memset((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent));
  3497. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, content, strlen(content));
  3498. printf("Set QRCodeContent: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  3499. return true;
  3500. }
  3501. bool CleanQRCodeContent(void)
  3502. {
  3503. memset((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent));
  3504. printf("Clean QRCode Content OK\r\n");
  3505. return true;
  3506. }
  3507. bool SetLEDIntensity(char *intensity)
  3508. {
  3509. int ledIntensity = _LED_INTENSITY_DARKEST;
  3510. char *strIntensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  3511. if(strcmp(intensity, "brightest") == EQUAL)
  3512. {
  3513. ledIntensity = _LED_INTENSITY_BRIGHTEST;
  3514. }
  3515. else if(strcmp(intensity, "medium") == EQUAL)
  3516. {
  3517. ledIntensity = _LED_INTENSITY_MEDIUM;
  3518. }
  3519. else if(strcmp(intensity, "darkest") != EQUAL)
  3520. {
  3521. printf("LED Intensity: [%s] is Illegal\r\n", intensity);
  3522. printf(" [value] darkest | medium | brightest\r\n");
  3523. return false;
  3524. }
  3525. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = ledIntensity;
  3526. printf("Set LED Intensity: [%s] OK\r\n", strIntensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
  3527. return true;
  3528. }
  3529. bool SetMaxChargingEnergy(char *energy)
  3530. {
  3531. int _energy = 0;
  3532. _energy = atoi(energy);
  3533. if(_energy < 0)
  3534. {
  3535. printf("MaxChargingEnergy: [%s] is Illegal\r\n", energy);
  3536. printf(" [value] > 0\r\n");
  3537. return false;
  3538. }
  3539. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = _energy;
  3540. printf("Set MaxChargingEnergy: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy);
  3541. return true;
  3542. }
  3543. bool SetMaxChargingPower(char *power)
  3544. {
  3545. int _power = 0;
  3546. _power = atoi(power);
  3547. if(_power < 0)
  3548. {
  3549. printf("MaxChargingEnergy: [%s] is Illegal\r\n", power);
  3550. printf(" [value] > 0\r\n");
  3551. return false;
  3552. }
  3553. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = _power;
  3554. printf("Set MaxChargingPower: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingPower);
  3555. return true;
  3556. }
  3557. bool SetMaxChargingCurrent(char *current)
  3558. {
  3559. int _current = 0;
  3560. _current = atoi(current);
  3561. if(_current < 0)
  3562. {
  3563. printf("MaxChargingEnergy: [%s] is Illegal\r\n", current);
  3564. printf(" [value] > 0\r\n");
  3565. return false;
  3566. }
  3567. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = _current;
  3568. printf("Set MaxChargingCurrent: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  3569. return true;
  3570. }
  3571. bool SetMaxChargingDuration(char *duration)
  3572. {
  3573. int _duration = 0;
  3574. _duration = atoi(duration);
  3575. if(_duration < 0)
  3576. {
  3577. printf("MaxChargingDuration: [%s] is Illegal\r\n", duration);
  3578. printf(" [value] > 0\r\n");
  3579. return false;
  3580. }
  3581. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = _duration;
  3582. printf("Set MaxChargingDuration: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  3583. return true;
  3584. }
  3585. bool SetMaxChargingSoc(char *soc)
  3586. {
  3587. int _soc = 0;
  3588. _soc = atoi(soc);
  3589. if(_soc < 0 || _soc > 100)
  3590. {
  3591. printf("MaxChargingSoc: [%s] is Illegal\r\n", soc);
  3592. printf(" [value] 0 ~ 100\r\n");
  3593. return false;
  3594. }
  3595. ShmSysConfigAndInfo->SysConfig.MaxChargingSoc = _soc;
  3596. printf("Set MaxChargingSoc: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingSoc);
  3597. return true;
  3598. }
  3599. bool SetStopChargingByButton(char *btn)
  3600. {
  3601. bool enable = false;
  3602. if(strcmp(btn, "enable") == EQUAL)
  3603. {
  3604. enable = true;
  3605. }
  3606. else
  3607. {
  3608. if(strcmp(btn, "disable") != EQUAL)
  3609. {
  3610. printf("Stop Charging By Button: [%s] is Illegal\r\n", btn);
  3611. printf(" [value] enable | disable\r\n");
  3612. return false;
  3613. }
  3614. }
  3615. ShmSysConfigAndInfo->SysConfig.StopChargingByButton = enable;
  3616. printf("Set Stop Charging By Button: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton ? "Enable" : "Disable");
  3617. return true;
  3618. }
  3619. bool SetOfflinePolicy(char *policy)
  3620. {
  3621. int offlinePolicy = _OFFLINE_POLICY_LOCAL_LIST;
  3622. char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
  3623. if(strcmp(policy, "free") == EQUAL)
  3624. {
  3625. offlinePolicy = _OFFLINE_POLICY_FREE_CHARGING;
  3626. }
  3627. else if(strcmp(policy, "nocharging") == EQUAL)
  3628. {
  3629. offlinePolicy = _OFFLINE_POLICY_NO_CHARGING;
  3630. }
  3631. else if(strcmp(policy, "local") != EQUAL)
  3632. {
  3633. printf("Offline Policy: [%s] is Illegal\r\n", policy);
  3634. printf(" [value] local | rfid | free | nocharging\r\n");
  3635. return false;
  3636. }
  3637. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = offlinePolicy;
  3638. printf("Set Offline Policy: [%s] OK\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
  3639. return true;
  3640. }
  3641. bool SetOcppServerURL(char *url)
  3642. {
  3643. if(strlen(url) >= sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL))
  3644. {
  3645. printf("Ocpp Server URL: [%s] is Out Of Length\r\n", url);
  3646. return false;
  3647. }
  3648. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  3649. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, url);
  3650. printf("Set Ocpp Server URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  3651. return true;
  3652. }
  3653. bool CleanOcppServerURL(void)
  3654. {
  3655. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  3656. printf("Clean Ocpp Server URL OK\r\n");
  3657. return true;
  3658. }
  3659. bool SetChargeBoxId(char *boxId)
  3660. {
  3661. if(strlen(boxId) >= sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId))
  3662. {
  3663. printf("Charge Box Id: [%s] is Out Of Length\r\n", boxId);
  3664. return false;
  3665. }
  3666. memset((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
  3667. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, boxId);
  3668. printf("Set Charge Box Id: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  3669. return true;
  3670. }
  3671. bool CleanChargeBoxId(void)
  3672. {
  3673. memset((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
  3674. printf("Clean Charge Box Id OK\r\n");
  3675. return true;
  3676. }
  3677. bool SetChargePointVendor(char *vendor)
  3678. {
  3679. if(strlen(vendor) >= sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor))
  3680. {
  3681. printf("Charge Point Vendor: [%s] is Out Of Length\r\n", vendor);
  3682. return false;
  3683. }
  3684. memset((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  3685. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, vendor);
  3686. printf("Set Charge Point Vendor: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3687. return true;
  3688. }
  3689. bool CleanChargePointVendor(void)
  3690. {
  3691. memset((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  3692. printf("Clean Charge Point Vendor OK\r\n");
  3693. return true;
  3694. }
  3695. bool SetOcppReceiptrURL(char *receipt)
  3696. {
  3697. if(strlen(receipt) >= sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL))
  3698. {
  3699. printf("Ocpp Receiptr URL: [%s] is Out Of Length\r\n", receipt);
  3700. return false;
  3701. }
  3702. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL));
  3703. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, receipt);
  3704. printf("Set Ocpp Receiptr URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL);
  3705. return true;
  3706. }
  3707. bool CleanOcppReceiptrURL(void)
  3708. {
  3709. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL));
  3710. printf("Clean Ocpp Receiptr URL OK\r\n");
  3711. return true;
  3712. }
  3713. bool SetMaintainServerURL(char *url)
  3714. {
  3715. if(strlen(url) >= sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL))
  3716. {
  3717. printf("Maintain Server URL: [%s] is Out Of Length\r\n", url);
  3718. return false;
  3719. }
  3720. memset((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  3721. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, url);
  3722. printf("Set Maintain Server URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  3723. return true;
  3724. }
  3725. bool CleanMaintainServerURL(void)
  3726. {
  3727. memset((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  3728. printf("Clean Maintain Server URL OK\r\n");
  3729. return true;
  3730. }
  3731. void FlashSetCmd(char *inputCmd, unsigned int opt)
  3732. {
  3733. char subMain[MAX_SUB_CMD_LENGTH];
  3734. char subSub[MAX_SUB_CMD_LENGTH];
  3735. memset(subMain, 0x00, sizeof(subMain));
  3736. memset(subSub, 0x00, sizeof(subSub));
  3737. bool find = false;
  3738. int actIndex = 0;
  3739. int maxLen = 20;
  3740. char strWriteItem[32][32] = {
  3741. "model", "sn", "sysid", "auth", "evccid", "qrmode", "qrcode", "led",
  3742. "energy", "power", "current", "time", "soc", "stopbtn", "policy", "backend",
  3743. "boxid", "vendor", "receipt", "maintain"};
  3744. bool (*writeFlashList[32])(char *) = {
  3745. &SetModelName, &SetSerialNumber, &SetSystemID, &SetAuthorisationMode,
  3746. &SetAuthrizeByEVCCID, &SetQRCodeMadeMode, &SetQRCodeContent, &SetLEDIntensity,
  3747. &SetMaxChargingEnergy, &SetMaxChargingPower, &SetMaxChargingCurrent, &SetMaxChargingDuration,
  3748. &SetMaxChargingSoc, &SetStopChargingByButton, &SetOfflinePolicy, &SetOcppServerURL,
  3749. &SetChargeBoxId, &SetChargePointVendor, &SetOcppReceiptrURL, &SetMaintainServerURL};
  3750. bool (*WriteFlashAct)(char *);
  3751. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3752. {
  3753. for(actIndex = 0; actIndex < maxLen; actIndex++)
  3754. {
  3755. if(strcmp((char *)&strWriteItem[actIndex][0], subMain) == 0)
  3756. {
  3757. find = true;
  3758. break;
  3759. }
  3760. }
  3761. if(find)
  3762. {
  3763. printf("\r\n");
  3764. WriteFlashAct = writeFlashList[actIndex];
  3765. WriteFlashAct(subSub);
  3766. printf("\r\n");
  3767. return;
  3768. }
  3769. }
  3770. printf("\r\n");
  3771. printf("Input cmd fail ------ model [set] [cmd] [value]\r\n");
  3772. printf(" [cmd]");
  3773. for(actIndex = 0; actIndex < maxLen; actIndex++)
  3774. {
  3775. printf("%s%s", actIndex == 0 ? " " : " | ", &strWriteItem[actIndex][0]);
  3776. }
  3777. printf("\r\n\r\n");
  3778. }
  3779. void FlashCleanCmd(char *inputCmd, unsigned int opt)
  3780. {
  3781. char subMain[MAX_SUB_CMD_LENGTH];
  3782. char subSub[MAX_SUB_CMD_LENGTH];
  3783. memset(subMain, 0x00, sizeof(subMain));
  3784. memset(subSub, 0x00, sizeof(subSub));
  3785. bool find = false;
  3786. int actIndex = 0;
  3787. int maxLen = 7;
  3788. char strCleanItem[32][32] = {
  3789. "sysid", "qrcode", "backend", "boxid", "vendor", "receipt", "maintain"};
  3790. bool (*cleanFlashList[32])() = {
  3791. &CleanSystemID, &CleanQRCodeContent, &CleanOcppServerURL, &CleanChargeBoxId,
  3792. &CleanChargePointVendor, &CleanOcppReceiptrURL, &CleanMaintainServerURL};
  3793. bool (*CleanFlashAct)();
  3794. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  3795. {
  3796. for(actIndex = 0; actIndex < maxLen; actIndex++)
  3797. {
  3798. if(strcmp((char *)&strCleanItem[actIndex][0], subMain) == 0)
  3799. {
  3800. find = true;
  3801. break;
  3802. }
  3803. }
  3804. if(find)
  3805. {
  3806. printf("\r\n");
  3807. CleanFlashAct = cleanFlashList[actIndex];
  3808. CleanFlashAct();
  3809. printf("\r\n");
  3810. return;
  3811. }
  3812. }
  3813. printf("\r\n");
  3814. printf("Input cmd fail ------ model [clean] [cmd]\r\n");
  3815. printf(" [cmd]");
  3816. for(actIndex = 0; actIndex < maxLen; actIndex++)
  3817. {
  3818. printf("%s%s", actIndex == 0 ? " " : " | ", &strCleanItem[actIndex][0]);
  3819. }
  3820. printf("\r\n\r\n");
  3821. }
  3822. void FlashWriteCmd(char *inputCmd, unsigned int opt)
  3823. {
  3824. if(strcmp(inputCmd, "now") == EQUAL)
  3825. {
  3826. printf("\r\n");
  3827. printf("Write Flash Immediately\r\n\r\n");
  3828. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  3829. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  3830. }
  3831. else
  3832. {
  3833. printf("\r\n");
  3834. printf("Write Flash Command Not Available\r\n\r\n");
  3835. }
  3836. }
  3837. void FlashCmd(char *inputCmd, unsigned int opt)
  3838. {
  3839. char subMain[MAX_SUB_CMD_LENGTH];
  3840. char subSub[MAX_SUB_CMD_LENGTH];
  3841. memset(subMain, 0x00, sizeof(subMain));
  3842. memset(subSub, 0x00, sizeof(subSub));
  3843. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3844. {
  3845. if(strcmp(subMain, "set") == EQUAL)
  3846. {
  3847. FlashSetCmd(subSub, opt);
  3848. return;
  3849. }
  3850. if(strcmp(subMain, "write") == EQUAL)
  3851. {
  3852. FlashWriteCmd(subSub, opt);
  3853. return;
  3854. }
  3855. if(strcmp(subMain, "clean") == EQUAL)
  3856. {
  3857. FlashCleanCmd(subSub, opt);
  3858. return;
  3859. }
  3860. }
  3861. printf("\r\n");
  3862. printf("Input cmd fail ------ flash [set | write | clean] [cmd] [...]\r\n\r\n");
  3863. }
  3864. void EnableAbnormalRelay(void)
  3865. {
  3866. ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay = true;
  3867. printf("\r\n");
  3868. printf("Enable Abnormal Relay Cmd\r\n\r\n");
  3869. }
  3870. void DisableAbnormalRelay(void)
  3871. {
  3872. ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay = NO;
  3873. printf("\r\n");
  3874. printf("Disable Abnormal Relay Cmd\r\n\r\n");
  3875. }
  3876. void RelayWriteOutputCmd(char *inputCmd)
  3877. {
  3878. char subMain[MAX_SUB_CMD_LENGTH];
  3879. char subSub[MAX_SUB_CMD_LENGTH];
  3880. memset(subMain, 0x00, sizeof(subMain));
  3881. memset(subSub, 0x00, sizeof(subSub));
  3882. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3883. {
  3884. int value = 0;
  3885. value = atoi(&subMain[0]);
  3886. if(value > 0 && value <= MAX_GUN_QUANTITY && (strcmp(subSub, "on") == 0 || strcmp(subSub, "off") == 0))
  3887. {
  3888. int OnOff = 0;
  3889. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  3890. {
  3891. EnableAbnormalRelay();
  3892. }
  3893. OnOff = strcmp(subSub, "on") == 0 ? YES : NO;
  3894. ShmChargerInfo->PsuGrouping.OutputRelayConfig[value - 1].bits.Output_N = OnOff;
  3895. ShmChargerInfo->PsuGrouping.OutputRelayConfig[value - 1].bits.Output_P = OnOff;
  3896. printf("\r\n");
  3897. printf("Write Gun %d OutputRelay %s\r\n\r\n", value, subSub);
  3898. return;
  3899. }
  3900. }
  3901. printf("\r\n");
  3902. printf("Input cmd fail ------ relay [write] [output] [value 1-4] [on | off]\r\n\r\n");
  3903. }
  3904. void RelayWriteParallelCmd(char *inputCmd)
  3905. {
  3906. char subMain[MAX_SUB_CMD_LENGTH];
  3907. char subSub[MAX_SUB_CMD_LENGTH];
  3908. memset(subMain, 0x00, sizeof(subMain));
  3909. memset(subSub, 0x00, sizeof(subSub));
  3910. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3911. {
  3912. int value = 0;
  3913. value = atoi(&subMain[0]);
  3914. if(value > 0 && value <= PARALLEL_RELAY_COUNT && (strcmp(subSub, "on") == 0 || strcmp(subSub, "off") == 0))
  3915. {
  3916. int OnOff = 0;
  3917. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  3918. {
  3919. EnableAbnormalRelay();
  3920. }
  3921. OnOff = strcmp(subSub, "on") == 0 ? YES : NO;
  3922. if(OnOff)
  3923. {
  3924. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue |= 1 << (value - 1);
  3925. }
  3926. else
  3927. {
  3928. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue &= ~(1 << (value - 1));
  3929. }
  3930. printf("\r\n");
  3931. printf("Write ParallelRelay %d %s\r\n\r\n", value, subSub);
  3932. return;
  3933. }
  3934. }
  3935. printf("\r\n");
  3936. printf("Input cmd fail ------ relay [write] [parallel] [value 1-6] [on | off]\r\n\r\n");
  3937. }
  3938. void AbnormalRelayCmd(char *inputCmd, unsigned int opt)
  3939. {
  3940. char subMain[MAX_SUB_CMD_LENGTH];
  3941. char subSub[MAX_SUB_CMD_LENGTH];
  3942. memset(subMain, 0x00, sizeof(subMain));
  3943. memset(subSub, 0x00, sizeof(subSub));
  3944. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  3945. {
  3946. if(strcmp(subMain, "enable") == 0)
  3947. {
  3948. EnableAbnormalRelay();
  3949. return;
  3950. }
  3951. if(strcmp(subMain, "disable") == 0)
  3952. {
  3953. DisableAbnormalRelay();
  3954. return;
  3955. }
  3956. }
  3957. printf("\r\n");
  3958. printf("Input cmd fail ------ relay [abnormal] [enable | disable]\r\n\r\n");
  3959. }
  3960. void RelayWriteCmd(char *inputCmd, unsigned int opt)
  3961. {
  3962. char subMain[MAX_SUB_CMD_LENGTH];
  3963. char subSub[MAX_SUB_CMD_LENGTH];
  3964. memset(subMain, 0x00, sizeof(subMain));
  3965. memset(subSub, 0x00, sizeof(subSub));
  3966. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3967. {
  3968. if(strcmp(subMain, "output") == 0)
  3969. {
  3970. RelayWriteOutputCmd(subSub);
  3971. return;
  3972. }
  3973. if(strcmp(subMain, "parallel") == 0)
  3974. {
  3975. RelayWriteParallelCmd(subSub);
  3976. return;
  3977. }
  3978. }
  3979. printf("\r\n");
  3980. printf("Input cmd fail ------ relay [write] [output | parallel] [value] [on | off]\r\n\r\n");
  3981. }
  3982. void RelayReadCmd(char *inputCmd, unsigned int opt)
  3983. {
  3984. }
  3985. void RelayStatusCmd(char *inputCmd, unsigned int opt)
  3986. {
  3987. }
  3988. void OutputRelayAutoTest(void)
  3989. {
  3990. int MaxGunCount = 0;
  3991. struct timespec _Loop_time;
  3992. int time = 0;
  3993. MaxGunCount = ShmChargerInfo->Control.MaxConnector;
  3994. for(int i = 0; i < MaxGunCount; i++)
  3995. {
  3996. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = YES;
  3997. GetClockTime(&_Loop_time);
  3998. while(1)
  3999. {
  4000. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4001. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_N)
  4002. {
  4003. printf("Gun %d Output Relay N Driving Check OK\r\n", i + 1);
  4004. break;
  4005. }
  4006. if(time >= 3000)
  4007. {
  4008. printf("Gun %d Output Relay N Driving Check Fault\r\n", i + 1);
  4009. break;
  4010. }
  4011. usleep(10000);
  4012. }
  4013. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = YES;
  4014. GetClockTime(&_Loop_time);
  4015. while(1)
  4016. {
  4017. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4018. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_P)
  4019. {
  4020. printf("Gun %d Output Relay P Driving Check OK\r\n", i + 1);
  4021. break;
  4022. }
  4023. if(time >= 3000)
  4024. {
  4025. printf("Gun %d Output Relay P Driving Check Fault\r\n", i + 1);
  4026. break;
  4027. }
  4028. usleep(10000);
  4029. }
  4030. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = NO;
  4031. GetClockTime(&_Loop_time);
  4032. while(1)
  4033. {
  4034. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4035. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_N)
  4036. {
  4037. printf("Gun %d Output Relay N Welding Check OK\r\n", i + 1);
  4038. break;
  4039. }
  4040. if(time >= 3000)
  4041. {
  4042. printf("Gun %d Output Relay N Welding Check Fault\r\n", i + 1);
  4043. break;
  4044. }
  4045. usleep(10000);
  4046. }
  4047. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = NO;
  4048. GetClockTime(&_Loop_time);
  4049. while(1)
  4050. {
  4051. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4052. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_P)
  4053. {
  4054. printf("Gun %d Output Relay P Welding Check OK\r\n", i + 1);
  4055. break;
  4056. }
  4057. if(time >= 3000)
  4058. {
  4059. printf("Gun %d Output Relay P Welding Check Fault\r\n", i + 1);
  4060. break;
  4061. }
  4062. usleep(10000);
  4063. }
  4064. }
  4065. }
  4066. void ParallelRelayAutoTest(void)
  4067. {
  4068. int ParallelRelayCount = 0;
  4069. struct timespec _Loop_time;
  4070. int time = 0;
  4071. if(ShmChargerInfo->Control.MaxConnector == GENERAL_GUN_QUANTITY)
  4072. {
  4073. ParallelRelayCount = ShmChargerInfo->Control.SysCtrl.bits.Enable6ParallelRelay == 1 ? PARALLEL_RELAY_COUNT : 3;
  4074. }
  4075. else
  4076. {
  4077. ParallelRelayCount = 1;
  4078. }
  4079. for(int i = 0; i < ParallelRelayCount; i++)
  4080. {
  4081. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue |= 1 << i;
  4082. GetClockTime(&_Loop_time);
  4083. while(1)
  4084. {
  4085. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4086. if(ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue == ShmChargerInfo->PsuGrouping.ParallelRelayConfirmed.CtrlValue)
  4087. {
  4088. printf("Location %d Parallel Relay Driving Check OK\r\n", i + 1);
  4089. break;
  4090. }
  4091. if(time >= 3000)
  4092. {
  4093. printf("Location %d Parallel Relay Driving Check Fault\r\n", i + 1);
  4094. break;
  4095. }
  4096. usleep(10000);
  4097. }
  4098. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue &= ~(1 << i);
  4099. GetClockTime(&_Loop_time);
  4100. while(1)
  4101. {
  4102. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4103. if(ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue == ShmChargerInfo->PsuGrouping.ParallelRelayConfirmed.CtrlValue)
  4104. {
  4105. printf("Location %d Parallel Relay Welding Check OK\r\n", i + 1);
  4106. break;
  4107. }
  4108. if(time >= 3000)
  4109. {
  4110. printf("Location %d Parallel Relay Welding Check Fault\r\n", i + 1);
  4111. break;
  4112. }
  4113. usleep(10000);
  4114. }
  4115. }
  4116. }
  4117. void RelayAutoTest(char *inputCmd)
  4118. {
  4119. if(strcmp(inputCmd, "now") != EQUAL)
  4120. {
  4121. printf("\r\n");
  4122. printf("Input cmd fail ------ relay [autotest] [now]\r\n\r\n");
  4123. return;
  4124. }
  4125. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  4126. {
  4127. EnableAbnormalRelay();
  4128. }
  4129. OutputRelayAutoTest();
  4130. ParallelRelayAutoTest();
  4131. printf("Relay Auto Test Completed\r\n");
  4132. DisableAbnormalRelay();
  4133. }
  4134. void RelayAllOn(void)
  4135. {
  4136. int MaxGunCount = 0;
  4137. MaxGunCount = ShmChargerInfo->Control.MaxConnector;
  4138. for(int i = 0; i < MaxGunCount; i++)
  4139. {
  4140. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = YES;
  4141. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = YES;
  4142. }
  4143. int ParallelRelayCount = 0;
  4144. if(ShmChargerInfo->Control.MaxConnector == GENERAL_GUN_QUANTITY)
  4145. {
  4146. ParallelRelayCount = ShmChargerInfo->Control.SysCtrl.bits.Enable6ParallelRelay == 1 ? PARALLEL_RELAY_COUNT : 3;
  4147. }
  4148. else
  4149. {
  4150. ParallelRelayCount = 1;
  4151. }
  4152. for(int i = 0; i < ParallelRelayCount; i++)
  4153. {
  4154. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue |= 1 << i;
  4155. }
  4156. }
  4157. void RelayAllOff(void)
  4158. {
  4159. int MaxGunCount = 0;
  4160. MaxGunCount = ShmChargerInfo->Control.MaxConnector;
  4161. for(int i = 0; i < MaxGunCount; i++)
  4162. {
  4163. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = NO;
  4164. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = NO;
  4165. }
  4166. int ParallelRelayCount = 0;
  4167. if(ShmChargerInfo->Control.MaxConnector == GENERAL_GUN_QUANTITY)
  4168. {
  4169. ParallelRelayCount = ShmChargerInfo->Control.SysCtrl.bits.Enable6ParallelRelay == 1 ? PARALLEL_RELAY_COUNT : 3;
  4170. }
  4171. else
  4172. {
  4173. ParallelRelayCount = 1;
  4174. }
  4175. for(int i = 0; i < ParallelRelayCount; i++)
  4176. {
  4177. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue &= ~(1 << i);
  4178. }
  4179. }
  4180. void RelayLongTimeTest(char *inputCmd)
  4181. {
  4182. int time = 0;
  4183. struct timespec _Loop_time;
  4184. bool keepRun = true;
  4185. bool _relayOn = false;
  4186. if(strcmp(inputCmd, "now") != EQUAL)
  4187. {
  4188. printf("\r\n");
  4189. printf("Input cmd fail ------ relay [timetest] [now]\r\n\r\n");
  4190. return;
  4191. }
  4192. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  4193. {
  4194. EnableAbnormalRelay();
  4195. }
  4196. printf("Relay Long Time Test Start\r\n");
  4197. do
  4198. {
  4199. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4200. if(time >= 10000)
  4201. {
  4202. if(!_relayOn)
  4203. {
  4204. printf("Set Relay All On\r\n");
  4205. RelayAllOn();
  4206. _relayOn = true;
  4207. }
  4208. else
  4209. {
  4210. printf("Set Relay All Off\r\n");
  4211. RelayAllOff();
  4212. _relayOn = false;
  4213. }
  4214. GetClockTime(&_Loop_time);
  4215. }
  4216. if(keepRun)
  4217. {
  4218. keepRun = IsLoopStopCmd() ? false : true;
  4219. usleep(10000);
  4220. }
  4221. }while(keepRun);
  4222. printf("\r\n");
  4223. DisableAbnormalRelay();
  4224. }
  4225. void RelayCmd(char *inputCmd, unsigned int opt)
  4226. {
  4227. char subMain[MAX_SUB_CMD_LENGTH];
  4228. char subSub[MAX_SUB_CMD_LENGTH];
  4229. memset(subMain, 0x00, sizeof(subMain));
  4230. memset(subSub, 0x00, sizeof(subSub));
  4231. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) >= 2)
  4232. {
  4233. if(strcmp(subMain, "abnormal") == EQUAL)
  4234. {
  4235. AbnormalRelayCmd(subSub, opt);
  4236. return;
  4237. }
  4238. if(strcmp(subMain, "write") == EQUAL)
  4239. {
  4240. RelayWriteCmd(subSub, opt);
  4241. return;
  4242. }
  4243. if(strcmp(subMain, "read") == EQUAL)
  4244. {
  4245. RelayReadCmd(subSub, opt);
  4246. return;
  4247. }
  4248. if(strcmp(subMain, "status") == EQUAL)
  4249. {
  4250. RelayStatusCmd(subSub, opt);
  4251. return;
  4252. }
  4253. if(strcmp(subMain, "autotest") == EQUAL)
  4254. {
  4255. RelayAutoTest(subSub);
  4256. return;
  4257. }
  4258. if(strcmp(subMain, "longtime") == EQUAL)
  4259. {
  4260. RelayLongTimeTest(subSub);
  4261. return;
  4262. }
  4263. }
  4264. printf("\r\n");
  4265. printf("Input cmd fail ------ relay [abnormal | write | read | autotest] [...]\r\n\r\n");
  4266. }
  4267. // Sys CurrentRate: [XX.XX]
  4268. // TimeOfDayPrice: [00-01: XX.XX] [01-02: XX.XX] [02-03: XX.XX] [03-04: XX.XX] [04-05: XX.XX] [05-06: XX.XX]
  4269. // : [06-07: XX.XX] [07-08: XX.XX] [08-09: XX.XX] [09-10: XX.XX] [10-11: XX.XX] [11-12: XX.XX]
  4270. // : [12-13: XX.XX] [13-14: XX.XX] [14-15: XX.XX] [15-16: XX.XX] [16-17: XX.XX] [17-18: XX.XX]
  4271. // : [18-19: XX.XX] [19-20: XX.XX] [20-21: XX.XX] [21-22: XX.XX] [22-23: XX.XX] [23-24: XX.XX]
  4272. int ShowSysPriceInfo(void)
  4273. {
  4274. int showLine = 1;
  4275. char priceString[1024];
  4276. //************************************************************************************************
  4277. printf(" Sys CurrentRate: [%5.2f]\r\n", ShmChargerInfo->PriceAndReceiptInfo.CurrentRate);
  4278. if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
  4279. {
  4280. //************************************************************************************************
  4281. memset(priceString, 0x00, sizeof(priceString));
  4282. for(int i = 0; i < 6; i++)
  4283. {
  4284. char strTemp[64];
  4285. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4286. strcat(priceString, strTemp);
  4287. }
  4288. printf(" TimeOfDayPrice:%s\r\n", priceString);
  4289. //************************************************************************************************
  4290. memset(priceString, 0x00, sizeof(priceString));
  4291. for(int i = 6; i < 12; i++)
  4292. {
  4293. char strTemp[64];
  4294. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4295. strcat(priceString, strTemp);
  4296. }
  4297. printf(" :%s\r\n", priceString);
  4298. //************************************************************************************************
  4299. memset(priceString, 0x00, sizeof(priceString));
  4300. for(int i = 12; i < 18; i++)
  4301. {
  4302. char strTemp[64];
  4303. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4304. strcat(priceString, strTemp);
  4305. }
  4306. printf(" :%s\r\n", priceString);
  4307. //************************************************************************************************
  4308. memset(priceString, 0x00, sizeof(priceString));
  4309. for(int i = 18; i < 24; i++)
  4310. {
  4311. char strTemp[64];
  4312. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4313. strcat(priceString, strTemp);
  4314. }
  4315. printf(" :%s\r\n", priceString);
  4316. showLine += 4;
  4317. }
  4318. return showLine;
  4319. }
  4320. // Gun X UserPrice: [%s]
  4321. // Receipt: [%s]
  4322. int ShowGunPriceInfo(int gun)
  4323. {
  4324. int showLine = 2;
  4325. char priceString[1024];
  4326. //************************************************************************************************
  4327. memset(priceString, 0x00, sizeof(priceString));
  4328. if(strlen(&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gun][0]) > 0)
  4329. {
  4330. strcpy(priceString, &ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gun][0]);
  4331. }
  4332. else
  4333. {
  4334. strcpy(priceString, "NULL");
  4335. }
  4336. printf(" Gun %d UserPrice: [%s]\r\n", gun + 1, priceString);
  4337. //************************************************************************************************
  4338. memset(priceString, 0x00, sizeof(priceString));
  4339. if(strlen(&ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gun][0]) > 0)
  4340. {
  4341. strcpy(priceString, &ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gun][0]);
  4342. }
  4343. else
  4344. {
  4345. strcpy(priceString, "NULL");
  4346. }
  4347. printf(" Receipt: [%s]\r\n", priceString);
  4348. return showLine;
  4349. }
  4350. void ShowPrice(char *inputCmd, unsigned int opt)
  4351. {
  4352. int totalLine = 0;
  4353. bool keepRun = false;
  4354. bool reflash = false;
  4355. int time = 0;
  4356. struct timespec _Loop_time;
  4357. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  4358. {
  4359. keepRun = true;
  4360. }
  4361. do
  4362. {
  4363. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4364. if(time >= 1000)
  4365. {
  4366. if(reflash)
  4367. {
  4368. ConsoleReflash(1, totalLine);
  4369. }
  4370. totalLine = 0;
  4371. printf("\r\n");
  4372. totalLine += ShowSysPriceInfo() + 1;
  4373. printf("\r\n");
  4374. totalLine += 1;
  4375. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  4376. {
  4377. totalLine += ShowGunPriceInfo(i);
  4378. }
  4379. GetClockTime(&_Loop_time);
  4380. if((opt & OPTION_REFLASH) > 0)
  4381. {
  4382. reflash = true;
  4383. }
  4384. }
  4385. if(keepRun)
  4386. {
  4387. keepRun = IsLoopStopCmd() ? false : true;
  4388. usleep(10000);
  4389. }
  4390. }while(keepRun);
  4391. printf("\r\n");
  4392. }
  4393. int main(void)
  4394. {
  4395. char newString[32][MAX_SUB_CMD_LENGTH];
  4396. char inputString[MAX_SUB_CMD_LENGTH], normalCmd[MAX_SUB_CMD_LENGTH];
  4397. char mainCmd[MAX_SUB_CMD_LENGTH], subCmd[MAX_SUB_CMD_LENGTH], multiCmd[MAX_SUB_CMD_LENGTH];
  4398. int cmdCnt = 0, parseCnt = 0;
  4399. unsigned int option = 0;
  4400. if(InitShareMemory() == FAIL)
  4401. {
  4402. printf ("InitShareMemory = FAIL \n");
  4403. if(ShmStatusCodeData != NULL)
  4404. {
  4405. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4406. }
  4407. sleep(5);
  4408. return 0;
  4409. }
  4410. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  4411. {
  4412. if (!FindChargingInfoData(i, &_chargingData[0]))
  4413. {
  4414. return 0;
  4415. }
  4416. }
  4417. // clean command
  4418. memset(mainCmd, 0x00, sizeof(mainCmd));
  4419. memset(subCmd, 0x00, sizeof(subCmd));
  4420. for(int i = 0; i < 32; i++)
  4421. {
  4422. memset(&newString[i], 0x00, 32);
  4423. }
  4424. for(;;)
  4425. {
  4426. memset(inputString, 0x00, sizeof(inputString));
  4427. memset(normalCmd, 0x00, sizeof(normalCmd));
  4428. get_char(inputString);
  4429. cmdCnt = InputStringNormalize(inputString, normalCmd, &option);
  4430. if(cmdCnt > 0)
  4431. {
  4432. // clean command
  4433. memset(mainCmd, 0x00, sizeof(mainCmd));
  4434. memset(subCmd, 0x00, sizeof(subCmd));
  4435. for(int i = 0; i < 32; i++)
  4436. {
  4437. memset(&newString[i], 0x00, MAX_SUB_CMD_LENGTH);
  4438. }
  4439. //printf("CmdCnt: %d\r\n", cmdCnt);
  4440. //printf("Input: %s", inputString);
  4441. //printf("Normalize: %s\r\n", normalCmd);
  4442. //printf("option: %08X\r\n", option);
  4443. MainAndSubCommandParsing(normalCmd, mainCmd, subCmd);
  4444. //printf("MainCmd: %s\r\n", mainCmd);
  4445. //printf("SubCmd: %s\r\n", subCmd);
  4446. parseCnt = 0;
  4447. strcpy(multiCmd, normalCmd);
  4448. do
  4449. {
  4450. MainAndSubCommandParsing(multiCmd, &newString[parseCnt][0], &newString[parseCnt + 1][0]);
  4451. strcpy(multiCmd, &newString[parseCnt + 1][0]);
  4452. //printf("MultiCmd Parse %d\r\n", parseCnt + 1);
  4453. //printf("MainCmd: %s\r\n", &newString[parseCnt][0]);
  4454. //printf("SubCmd: %s\r\n", &newString[parseCnt + 1][0]);
  4455. parseCnt++;
  4456. }while(parseCnt < cmdCnt - 1);
  4457. //printf("\r\n");
  4458. //for(int i = 0; i < cmdCnt; i++)
  4459. //{
  4460. // printf("MultiCmd %d: [%s]\r\n", i + 1, &newString[i][0]);
  4461. //}
  4462. }
  4463. else
  4464. {
  4465. usleep(100000);
  4466. continue;
  4467. }
  4468. if(strcmp(newString[0], "state") == 0)
  4469. {
  4470. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4471. continue;
  4472. // 槍狀態
  4473. RunStatusProc(newString[1], newString[2]);
  4474. }
  4475. else if(strcmp(newString[0], "card") == 0)
  4476. {
  4477. // 刷卡狀態
  4478. RunCardProc(newString[1], newString[2]);
  4479. }
  4480. else if(strcmp(newString[0], "gun") == 0)
  4481. {
  4482. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4483. continue;
  4484. // 插槍狀態
  4485. RunGunPlugitProc(newString[1], newString[2]);
  4486. }
  4487. else if(strcmp(newString[0], "lock") == 0)
  4488. {
  4489. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4490. continue;
  4491. // 插槍狀態
  4492. GetGunLockStatusProc(newString[1], newString[2]);
  4493. }
  4494. else if(strcmp(newString[0], "sysid") == 0)
  4495. {
  4496. // 測試 sys id
  4497. SetSystemIDProc();
  4498. }
  4499. else if(strcmp(newString[0], "self") == 0)
  4500. {
  4501. // CSU 自我檢測狀態
  4502. RunSelfProc(newString[1]);
  4503. }
  4504. else if(strcmp(newString[0], "ver") == 0)
  4505. {
  4506. //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4507. // continue;
  4508. // 取 FW 版號
  4509. //GetFwVerProc(newString[1]);
  4510. ShowFwVer();
  4511. }
  4512. else if (strcmp(newString[0], "update") == 0)
  4513. {
  4514. // 更新
  4515. FwUpdateFlagProc(newString[1]);
  4516. }
  4517. else if (strcmp(newString[0], "ac") == 0)
  4518. {
  4519. // AC contactor 狀態
  4520. CheckAcStatus(newString[1]);
  4521. }
  4522. else if (strcmp(newString[0], "cable") == 0)
  4523. {
  4524. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4525. continue;
  4526. // cable check pass
  4527. SetCableChkStatus(newString[1], newString[2]);
  4528. }
  4529. else if (strcmp(newString[0], "pow") == 0)
  4530. {
  4531. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4532. continue;
  4533. // cable check pass
  4534. SetPowerValue(newString[1], newString[2]);
  4535. }
  4536. else if(strcmp(mainCmd, "model") == 0)
  4537. {
  4538. ModelNameCmd(subCmd, option);
  4539. }
  4540. else if(strcmp(mainCmd, "sn") == 0)
  4541. {
  4542. SerialNumberCmd(subCmd, option);
  4543. }
  4544. else if(strcmp(newString[0], "fan") == 0)
  4545. {
  4546. // 設定風扇速度
  4547. SetFanSpeed(newString[1]);
  4548. }
  4549. else if(strcmp(newString[0], "speed") == 0)
  4550. {
  4551. // 取得風扇速度
  4552. GetFanSpeed();
  4553. }
  4554. else if(strcmp(newString[0], "debug") == 0)
  4555. {
  4556. // 設定 debug mode
  4557. SetDebugMode(newString[1]);
  4558. }
  4559. else if (strcmp(newString[0], "gfd") == 0)
  4560. {
  4561. // 設定盲沖使用 GFD 功能
  4562. SetGFDMode(newString[1]);
  4563. }
  4564. else if(strcmp(mainCmd, "temp") == 0)
  4565. {
  4566. // 取得溫度
  4567. GetTemperature(subCmd, option);
  4568. }
  4569. else if(strcmp(mainCmd, "acin") == 0 || strcmp(mainCmd, "input") == 0)
  4570. {
  4571. // 取得三向輸入電壓
  4572. GetInputVol(subCmd, option);
  4573. }
  4574. else if(strcmp(newString[0], "psu") == 0)
  4575. {
  4576. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  4577. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4578. {
  4579. printf ("PSU : Param fail..Please retry again......\n");
  4580. continue;
  4581. }
  4582. // 取得 PSU 資訊
  4583. GetPsuInformation(newString[1], newString[2], newString[3]);
  4584. }
  4585. else if (strcmp(newString[0], "cap") == 0)
  4586. {
  4587. GetConnectorCapInfo(newString[1]);
  4588. }
  4589. else if(strcmp(newString[0], "error") == 0)
  4590. {
  4591. CreateOneError(newString[1]);
  4592. }
  4593. else if (strcmp(newString[0], "auth") == 0)
  4594. {
  4595. GetAuthorizeFlag(newString[1]);
  4596. }
  4597. else if (strcmp(newString[0], "id") == 0)
  4598. {
  4599. GetOrClearId(newString[1]);
  4600. }
  4601. else if(strcmp(newString[0], "wiring") == 0)
  4602. {
  4603. if(strcmp(newString[1], "-1") != 0 && strcmp(newString[1], "") != 0 &&
  4604. strcmp(newString[2], "-1") != 0 && strcmp(newString[2], "") != 0)
  4605. {
  4606. SetWiringInfo(newString[1], newString[2]);
  4607. }
  4608. ShowWiringInfo();
  4609. }
  4610. else if(strcmp(newString[0], "cwiring") == 0)
  4611. {
  4612. CleanWiringInfo();
  4613. }
  4614. else if(strcmp(newString[0], "reset") == 0)
  4615. {
  4616. SetSystemSoftRest();
  4617. }
  4618. else if(strcmp(newString[0], "reboot") == 0)
  4619. {
  4620. SetSystemHardReboot();
  4621. }
  4622. else if(strcmp(newString[0], "sgroup") == 0)
  4623. {
  4624. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4625. {
  4626. ShowGroupingInfo();
  4627. continue;
  4628. }
  4629. RunSimplePsuGrouping(newString[1], newString[2]);
  4630. }
  4631. else if(strcmp(mainCmd, "cabinet") == 0)
  4632. {
  4633. ShowCabinetInfo(subCmd, option);
  4634. }
  4635. else if(strcmp(newString[0], "tctl") == 0)
  4636. {
  4637. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4638. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  4639. {
  4640. printf("Test Control Value = %08X\n",ShmChargerInfo->Control.TestCtrl.CtrlValue);
  4641. printf ("Input cmd fail ------ tctl [tcmd] [value]\n\n");
  4642. continue;
  4643. }
  4644. SetTestControl(newString[1], newString[2]);
  4645. }
  4646. else if(strcmp(newString[0], "group") == 0)
  4647. {
  4648. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4649. {
  4650. ShowGroupingInfo();
  4651. continue;
  4652. }
  4653. }
  4654. else if(strcmp(newString[0], "gdmd") == 0)
  4655. {
  4656. ShowGroupingDemand();
  4657. }
  4658. else if(strcmp(mainCmd, "gunchg") == 0)
  4659. {
  4660. SetGunStartCharging(subCmd, option, NO);
  4661. }
  4662. else if(strcmp(mainCmd, "webchg") == 0)
  4663. {
  4664. SetGunStartCharging(subCmd, option, YES);
  4665. }
  4666. else if(strcmp(mainCmd, "gunstp") == 0)
  4667. {
  4668. SetGunStopCharging(subCmd, option);
  4669. }
  4670. else if(strcmp(newString[0], "gunext") == 0)
  4671. {
  4672. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4673. {
  4674. printf ("Input cmd fail ------ gunext [gun 1-4]\n\n");
  4675. continue;
  4676. }
  4677. SetGunExtend(newString[1]);
  4678. }
  4679. else if(strcmp(newString[0], "output") == 0)
  4680. {
  4681. ShowGunOutput();
  4682. }
  4683. else if(strcmp(newString[0], "gio") == 0)
  4684. {
  4685. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4686. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  4687. {
  4688. printf ("Input cmd fail ------ gio [io] [on-off 0-1]\n\n");
  4689. continue;
  4690. }
  4691. SetGpio(newString[1], newString[2]);
  4692. }
  4693. else if(strcmp(newString[0], "status") == 0)
  4694. {
  4695. ShowStatus();
  4696. }
  4697. else if(strcmp(newString[0], "whiteR") == 0)
  4698. {
  4699. ShowWhiteCardList();
  4700. }
  4701. else if(strcmp(newString[0], "whiteW") == 0)
  4702. {
  4703. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4704. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  4705. {
  4706. printf ("Input cmd fail ------ whiteW [index 1-10] [card id]\n\n");
  4707. continue;
  4708. }
  4709. WriteWhiteCard(newString[1], newString[2]);
  4710. }
  4711. else if(strcmp(newString[0], "whiteE") == 0)
  4712. {
  4713. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4714. {
  4715. printf ("Input cmd fail ------ whiteE [index 1-10]\n\n");
  4716. continue;
  4717. }
  4718. EraseWhiteCard(newString[1]);
  4719. }
  4720. else if(strcmp(mainCmd, "limit") == 0)
  4721. {
  4722. ShowChargerLimit(subCmd, option);
  4723. }
  4724. else if(strcmp(mainCmd, "pcmd") == 0)
  4725. {
  4726. SetPsuCommand(subCmd, option);
  4727. }
  4728. else if(strcmp(newString[0], "gcmd") == 0)
  4729. {
  4730. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4731. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  4732. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  4733. {
  4734. printf ("Input cmd fail ------ gcmd [cmd] [gun] [value]\n\n");
  4735. continue;
  4736. }
  4737. SetGunCommand(newString[1], newString[2], newString[3]);
  4738. }
  4739. else if(strcmp(mainCmd, "web") == 0)
  4740. {
  4741. ShowWebInfo(subCmd, option);
  4742. }
  4743. else if(strcmp(mainCmd, "info") == 0)
  4744. {
  4745. ShowInfo(subCmd, option);
  4746. }
  4747. else if(strcmp(mainCmd, "rtcsync") == 0)
  4748. {
  4749. RtcSyncCmd(subCmd, option);
  4750. }
  4751. else if(strcmp(mainCmd, "pmodel") == 0)
  4752. {
  4753. ParsingModelNameCmd(subCmd, option);
  4754. }
  4755. else if(strcmp(mainCmd, "pt") == 0)
  4756. {
  4757. CustomerPriceTest(subCmd, option);
  4758. }
  4759. else if(strcmp(mainCmd, "evmsg") == 0)
  4760. {
  4761. EvCommMsgDebug(subCmd, option);
  4762. }
  4763. else if(strcmp(mainCmd, "evid") == 0)
  4764. {
  4765. EvCommIdDebug(subCmd, option);
  4766. }
  4767. else if(strcmp(mainCmd, "flash") == 0)
  4768. {
  4769. FlashCmd(subCmd, option);
  4770. }
  4771. else if(strcmp(mainCmd, "relay") == 0)
  4772. {
  4773. RelayCmd(subCmd, option);
  4774. }
  4775. else if(strcmp(mainCmd, "price") == 0)
  4776. {
  4777. ShowPrice(subCmd, option);
  4778. }
  4779. else
  4780. {
  4781. printf ("%s\n", msg);
  4782. }
  4783. usleep(100000);
  4784. }
  4785. return 0;
  4786. }