ReadCmdline.c 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914
  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 STR_OPT_REFLASH 'f'
  48. #define STR_OPT_LOOP 'l'
  49. #define STR_OPT_TIME 't'
  50. #define TTY_PATH "/dev/tty"
  51. #define STTY_US "stty raw -echo -F "
  52. #define STTY_DEF "stty -raw echo -F "
  53. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  54. struct StatusCodeData *ShmStatusCodeData;
  55. struct PrimaryMcuData *ShmPrimaryMcuData;
  56. struct CHAdeMOData *ShmCHAdeMOData;
  57. struct CcsData *ShmCcsData;
  58. struct GBTData *ShmGBTData;
  59. struct FanModuleData *ShmFanModuleData;
  60. struct RelayModuleData *ShmRelayModuleData;
  61. struct LedModuleData *ShmLedModuleData;
  62. struct PsuData *ShmPsuData;
  63. ChargerInfoData *ShmChargerInfo;
  64. PsuPositionInfoData *ShmPsuPosition;
  65. PsuGroupingInfoData *ShmPsuGrouping;
  66. struct OCPP16Data *ShmOCPP16Data;
  67. struct OCPP20Data *ShmOCPP20Data;
  68. struct ChargingInfoData *_chargingData[CONNECTOR_QUANTITY];
  69. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  70. char *msg = "state : get gun state (index) \n"
  71. "card : scanning card (x) : \n"
  72. "gun : get gun plugit state (index) \n"
  73. "lock : get gun locked state (index) \n"
  74. "self : self test state (x) \n"
  75. "ver : ver of board (407 or index or rb or fan) \n"
  76. "ac : get ac relay state (x) \n"
  77. "gunchg: set gun start charging \n"
  78. "gunstp: set gun stop charging \n"
  79. "gunext: extend gun capability \n";
  80. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  81. {
  82. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  83. {
  84. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  85. {
  86. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  87. return true;
  88. }
  89. }
  90. for (byte index = 0; index < CCS_QUANTITY; index++)
  91. {
  92. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  93. {
  94. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  95. return true;
  96. }
  97. }
  98. for (byte index = 0; index < GB_QUANTITY; index++)
  99. {
  100. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  101. {
  102. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  103. return true;
  104. }
  105. }
  106. if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
  107. {
  108. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
  109. return true;
  110. }
  111. return false;
  112. }
  113. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  114. {
  115. if (target < AC_QUANTITY)
  116. {
  117. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  118. return true;
  119. }
  120. return false;
  121. }
  122. int InitShareMemory()
  123. {
  124. int result = PASS;
  125. int MeterSMId;
  126. //initial ShmSysConfigAndInfo
  127. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  128. {
  129. result = FAIL;
  130. }
  131. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  132. {
  133. result = FAIL;
  134. }
  135. else
  136. {}
  137. //initial ShmStatusCodeData
  138. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  139. {
  140. result = FAIL;
  141. }
  142. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  143. {
  144. result = FAIL;
  145. }
  146. else
  147. {}
  148. if (CHAdeMO_QUANTITY > 0) {
  149. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  150. IPC_CREAT | 0777)) < 0) {
  151. result = FAIL;
  152. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  153. == (void *) -1) {
  154. result = FAIL;
  155. } else {
  156. }
  157. }
  158. if (CCS_QUANTITY > 0) {
  159. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  160. IPC_CREAT | 0777)) < 0) {
  161. result = FAIL;
  162. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  163. result = FAIL;
  164. } else {
  165. }
  166. }
  167. if (GB_QUANTITY > 0) {
  168. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  169. IPC_CREAT | 0777)) < 0) {
  170. return 0;
  171. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  172. return 0;
  173. }
  174. memset(ShmGBTData, 0, sizeof(struct GBTData));
  175. }
  176. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  177. {
  178. result = FAIL;
  179. }
  180. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  181. {
  182. result = FAIL;
  183. }
  184. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  185. {
  186. result = FAIL;
  187. }
  188. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  189. {
  190. result = FAIL;
  191. }
  192. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  193. {
  194. result = FAIL;
  195. }
  196. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  197. {
  198. result = FAIL;
  199. }
  200. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  201. {
  202. result = FAIL;
  203. }
  204. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  205. {
  206. result = FAIL;
  207. }
  208. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  209. {
  210. result = FAIL;
  211. }
  212. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  213. {
  214. result = FAIL;
  215. }
  216. if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
  217. {
  218. result = FAIL;
  219. }
  220. else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  221. {
  222. result = FAIL;
  223. }
  224. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  225. {
  226. result = FAIL;
  227. }
  228. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  229. {
  230. result = FAIL;
  231. }
  232. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  233. {
  234. result = FAIL;
  235. }
  236. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  237. {
  238. result = FAIL;
  239. }
  240. if(result == PASS)
  241. {
  242. ShmPsuPosition = &ShmChargerInfo->PsuPosition;
  243. ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
  244. }
  245. return result;
  246. }
  247. void Get_Ocpp_TransactionId(int gun_index, char *transactionId)
  248. {
  249. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  250. {
  251. sprintf(transactionId, "%d", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  252. return;
  253. }
  254. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  255. {
  256. strcpy(transactionId, (char *)&ShmOCPP20Data->TransactionEvent [gun_index].transactionInfo.transactionId[0]);
  257. return;
  258. }
  259. sprintf(transactionId, "%d", 0);
  260. }
  261. static void get_char(char *word)
  262. {
  263. fd_set rfds;
  264. struct timeval tv;
  265. FD_ZERO(&rfds);
  266. FD_SET(0, &rfds);
  267. tv.tv_sec = 0;
  268. tv.tv_usec = 10; //wait input timout time
  269. //if input
  270. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  271. {
  272. fgets(word, 128, stdin);
  273. }
  274. }
  275. // return command length
  276. int ParsingCmd(char *inputString, char *outputString)
  277. {
  278. bool valid = false, done = false;
  279. int len = 0, start = 0;
  280. for(int i = 0; i < strlen(inputString); i++)
  281. {
  282. if(!valid)
  283. {
  284. if(inputString[i] != ' ' && inputString[i] != '\0' && inputString[i] != '\r' && inputString[i] != '\n')
  285. {
  286. valid = true;
  287. start = i;
  288. }
  289. }
  290. else
  291. {
  292. if(inputString[i] == ' ' || inputString[i] == '\0' || inputString[i] == '\r' || inputString[i] == '\n' || len >= 32)
  293. {
  294. done = true;
  295. break;
  296. }
  297. }
  298. len = (valid && !done) ? len + 1 : len;
  299. }
  300. if(valid)
  301. {
  302. memcpy(outputString, &inputString[start], len);
  303. outputString[len] = '\0';
  304. }
  305. return len;
  306. }
  307. bool IsOption(char *strCmd, unsigned int *opt)
  308. {
  309. int len = 0;
  310. char str_opt[OPTION_CNT] = {STR_OPT_REFLASH, STR_OPT_LOOP, STR_OPT_TIME};
  311. unsigned int opt_value[OPTION_CNT] = {OPTION_REFLASH, OPTION_LOOP, OPTION_TIME};
  312. len = strlen(strCmd);
  313. if(len == 2)
  314. {
  315. if(strCmd[0] == STR_OPTION)
  316. {
  317. for(int i = 0; i < OPTION_CNT; i++)
  318. {
  319. if(strCmd[1] == str_opt[i])
  320. {
  321. *opt |= opt_value[i];
  322. return true;
  323. }
  324. }
  325. }
  326. }
  327. return false;
  328. }
  329. // inputCmdString: console input string
  330. // outputCmdString: input string parsed
  331. // return command quantity
  332. int InputStringNormalize(char *inputCmdString, char *outputCmdString, unsigned int *opt)
  333. {
  334. int len = 0, cnt = 0, start = 0;
  335. int cmdLen = 0, totalLen = 0;
  336. len = strlen(inputCmdString);
  337. *opt = 0;
  338. if(len > 0)
  339. {
  340. while(start < len - 1)
  341. {
  342. if(inputCmdString[start] != ' ' && inputCmdString[start] != '\0')
  343. {
  344. cmdLen = ParsingCmd(&inputCmdString[start], &outputCmdString[totalLen]);
  345. if(cmdLen > 0)
  346. {
  347. //printf("Find %d Cmd: %s\r\n", cnt + 1, &outputCmdString[totalLen]);
  348. if(!IsOption(&outputCmdString[totalLen], opt))
  349. {
  350. outputCmdString[totalLen + cmdLen] = ' ';
  351. cnt++;
  352. totalLen += cmdLen + 1;
  353. }
  354. start += cmdLen;
  355. }
  356. }
  357. else
  358. {
  359. start++;
  360. }
  361. }
  362. outputCmdString[totalLen - 1] = '\0';
  363. }
  364. return cnt;
  365. }
  366. int MainAndSubCommandParsing(char *normalCmd, char *mainCmd, char *subCmd)
  367. {
  368. int len = 0, totalLen = 0;
  369. strcpy(mainCmd, "");
  370. strcpy(subCmd, "");
  371. totalLen = strlen(normalCmd);
  372. if(totalLen > 0)
  373. {
  374. len = ParsingCmd(normalCmd, mainCmd);
  375. //printf("Find MainCmd: %s\r\n", mainCmd);
  376. if(len > 0 && totalLen > len)
  377. {
  378. strcpy(subCmd, &normalCmd[len + 1]);
  379. //printf("Find SubCmd: %s\r\n", subCmd);
  380. }
  381. }
  382. return 0;
  383. }
  384. int GetCommandSring(char *outputCmdString)
  385. {
  386. int len = 0, cnt = 0;
  387. int cmdLen = 0, totalLen = 0;
  388. char word[128];
  389. memset(word, 0x00, sizeof(word));
  390. get_char(word);
  391. len = strlen(word);
  392. if(len == 0)
  393. {
  394. return -1;
  395. }
  396. int start = 0;
  397. while(start < len - 1)
  398. {
  399. if(word[start] != ' ' && word[start] != '\0')
  400. {
  401. cmdLen = ParsingCmd(&word[start], &outputCmdString[totalLen]);
  402. char newCmd[32];
  403. memset(newCmd, 0x00, 32);
  404. memcpy(newCmd, &outputCmdString[totalLen], cmdLen);
  405. cnt = cmdLen > 0 ? cnt + 1 : cnt;
  406. totalLen += cmdLen + 1;
  407. start += cmdLen;
  408. }
  409. else
  410. {
  411. start++;
  412. }
  413. }
  414. return cnt;
  415. }
  416. bool IsLoopStopCmd(void)
  417. {
  418. bool stop = false;
  419. int cnt = 0;
  420. char cmd[256];
  421. char totalCmd[256];
  422. memset(cmd, 0x00, 256);
  423. memset(totalCmd, 0x00, 256);
  424. cnt = GetCommandSring(totalCmd);
  425. if(cnt > 0)
  426. {
  427. strcpy(&cmd[0], totalCmd);
  428. if(strcmp(&cmd[0], "c") == 0)
  429. {
  430. stop = true;
  431. }
  432. }
  433. return stop;
  434. }
  435. void ConsoleReflash(int groupCnt, int lineCnt)
  436. {
  437. for(int i = 0; i < groupCnt; i++)
  438. {
  439. for(int i = 0; i < lineCnt; i++)
  440. {
  441. printf("\033[1A");
  442. printf("\033[K");
  443. }
  444. }
  445. printf("\r");
  446. }
  447. void RunStatusProc(char *v1, char *v2)
  448. {
  449. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  450. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  451. if (strcmp(v1, "ac") == 0)
  452. {
  453. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  454. {
  455. printf("FindChargingInfoData (AC) false \n");
  456. }
  457. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  458. return;
  459. }
  460. int _index = atoi(v1);
  461. if (_index <= 1)
  462. {
  463. if (!FindChargingInfoData(_index, &_chargingData[0]))
  464. {
  465. printf ("FindChargingInfoData error\n");
  466. return;
  467. }
  468. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  469. {
  470. // get
  471. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  472. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  473. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  474. printf("ConnectorAlarmCode = %s \n", _chargingData[_index]->ConnectorAlarmCode);
  475. printf("EvConnAlarmCode = %s \n", _chargingData[_index]->EvConnAlarmCode);
  476. printf("RemotenAlarmCode = %s \n", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].RemotenAlarmCode);
  477. }
  478. else
  479. {
  480. // set
  481. _chargingData[_index]->SystemStatus = atoi(v2);
  482. }
  483. }
  484. else
  485. {
  486. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  487. {
  488. printf("FindChargingInfoData (AC) false \n");
  489. }
  490. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  491. {
  492. // get
  493. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  494. }
  495. else
  496. {
  497. // set
  498. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  499. }
  500. }
  501. }
  502. void RunCardProc(char *v1, char *v2)
  503. {
  504. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  505. {
  506. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  507. {
  508. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  509. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  510. }
  511. else
  512. {
  513. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  514. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  515. }
  516. }
  517. else
  518. {
  519. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  520. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  521. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  522. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  523. }
  524. }
  525. void RunGunPlugitProc(char *v1, char *v2)
  526. {
  527. if (strcmp(v1, "ac") == 0)
  528. {
  529. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  530. {
  531. printf("FindChargingInfoData (AC) false \n");
  532. }
  533. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  534. {
  535. // get
  536. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  537. }
  538. else
  539. {
  540. // set
  541. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  542. }
  543. return;
  544. }
  545. int _index = atoi(v1);
  546. if (!FindChargingInfoData(_index, &_chargingData[0]))
  547. {
  548. printf("FindChargingInfoData error\n");
  549. return;
  550. }
  551. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  552. {
  553. // get
  554. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  555. }
  556. else
  557. {
  558. // set
  559. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  560. }
  561. }
  562. void GetGunLockStatusProc(char *v1, char *v2)
  563. {
  564. int _index = atoi(v1);
  565. if (!FindChargingInfoData(_index, &_chargingData[0]))
  566. {
  567. printf("FindChargingInfoData error\n");
  568. return;
  569. }
  570. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  571. {
  572. _chargingData[_index]->GunLocked = atoi(v2);
  573. }
  574. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  575. }
  576. void SetSystemIDProc()
  577. {
  578. char *systemId = "Alston_Test";
  579. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  580. }
  581. void RunSelfProc()
  582. {
  583. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  584. }
  585. void ShowFwVer(void)
  586. {
  587. printf("\r\nPower Cabinet, Model Name: %s, SN: %s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  588. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
  589. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev);
  590. printf("\r\n Csu Kernel: ");
  591. for(int i = 0; i < strlen((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev); i++)
  592. {
  593. if(ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\r' && ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\n')
  594. {
  595. printf("%c", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i]);
  596. }
  597. }
  598. printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  599. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
  600. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  601. printf("\r\n Relay1 Module: %s", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  602. printf("\r\n Relay2 Module: %s", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  603. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  604. {
  605. printf("\r\n\r\nDispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  606. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  607. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  608. {
  609. printf(", Model Name: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName);
  610. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuBootLoadFwRev);
  611. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev);
  612. printf("\r\n Csu Kernel: ");
  613. for(int j = 0; j < strlen((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev); j++)
  614. {
  615. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\r' &&
  616. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\n')
  617. {
  618. printf("%c", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j]);
  619. }
  620. }
  621. printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuRootFsFwRev);
  622. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuPrimFwRev);
  623. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].FanModuleFwRev);
  624. printf("\r\n Relay Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].RelayModuleFwRev);
  625. printf("\r\n Connector 1: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector1FwRev);
  626. printf("\r\n Connector 2: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector2FwRev);
  627. printf("\r\n Led Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LedModuleFwRev);
  628. }
  629. }
  630. printf("\r\n\r\n");
  631. }
  632. void GetFwVerProc(char *v1)
  633. {
  634. if (strcmp(v1, "407") == 0)
  635. {
  636. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  637. }
  638. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0 || strcmp(v1, "2") == 0 || strcmp(v1, "3") == 0)
  639. {
  640. int _index = atoi(v1);
  641. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Enable)
  642. {
  643. int dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].ParentDispensetIndex;
  644. int ParentIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].GeneralChargingData.Index;
  645. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  646. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  647. {
  648. if(ParentIndex == 0)
  649. {
  650. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  651. }
  652. else
  653. {
  654. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  655. }
  656. }
  657. }
  658. else
  659. {
  660. printf("Gun %d is disable\r\n", _index);
  661. }
  662. }
  663. else if (strcmp(v1, "rb") == 0)
  664. {
  665. printf("RB1 Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  666. printf("RB2 Version = %s \n", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  667. }
  668. else if (strcmp(v1, "fan") == 0)
  669. {
  670. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  671. }
  672. else if (strcmp(v1, "dc") == 0)
  673. {
  674. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  675. }
  676. else if (strcmp(v1, "led") == 0)
  677. {
  678. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  679. }
  680. }
  681. void CreateOneError(char *v1)
  682. {
  683. int value = atoi(v1);
  684. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
  685. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  686. }
  687. void GetAuthorizeFlag(char *v1)
  688. {
  689. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  690. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  691. else
  692. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  693. }
  694. void GetOrClearId(char *v1)
  695. {
  696. int _index = atoi(v1);
  697. if (!FindChargingInfoData(_index, &_chargingData[0]))
  698. {
  699. printf("FindChargingInfoData error\n");
  700. return;
  701. }
  702. printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
  703. }
  704. void FwUpdateFlagProc()
  705. {
  706. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  707. }
  708. void CheckAcStatus(char *v1)
  709. {
  710. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  711. {
  712. printf(" AC Contactor Ctrl: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactor);
  713. printf(" AC Off By Psu : %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu);
  714. printf(" AC Off ByEmergency: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency);
  715. printf("AC Contactor Status: %d\r\n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  716. }
  717. else
  718. {
  719. if(system("pidof -s main > /dev/null") != 0)
  720. {
  721. if(strcmp(v1, "0") == 0)
  722. {
  723. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = false;
  724. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  725. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  726. printf("Set AC Contactor Off\r\n");
  727. }
  728. else
  729. {
  730. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = true;
  731. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  732. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  733. printf("Set AC Contactor On\r\n");
  734. }
  735. }
  736. else
  737. {
  738. printf("main task is running\r\n");
  739. }
  740. }
  741. }
  742. void SetCableChkStatus(char *v1, char *v2)
  743. {
  744. int _index = atoi(v1);
  745. if (!FindChargingInfoData(_index, &_chargingData[0]))
  746. {
  747. printf ("FindChargingInfoData error\n");
  748. return;
  749. }
  750. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  751. }
  752. void SetPowerValue(char *v1, char *v2)
  753. {
  754. int _index = atoi(v1);
  755. float _Current = atof(v2);
  756. // 盲沖的時候才允許使用~
  757. if (_chargingData[_index]->Type != 9)
  758. return;
  759. if (!FindChargingInfoData(_index, &_chargingData[0]))
  760. {
  761. printf ("FindChargingInfoData error\n");
  762. return;
  763. }
  764. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  765. }
  766. void GetSystemInfo()
  767. {
  768. printf ("\r\n ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
  769. printf ("\r\nSerialNumber = %s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  770. printf ("\r\nInternetConn = %d", ShmSysConfigAndInfo->SysInfo.InternetConn);
  771. printf ("\r\nMaxChargingPower = %d kW, MaxChargingCurrent = %d A",
  772. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  773. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  774. printf("\r\n\r\n");
  775. }
  776. void SetFanSpeed(char *v1)
  777. {
  778. int speed = atoi(v1);
  779. ShmFanModuleData->TestFanSpeed = speed;
  780. }
  781. void GetFanSpeed()
  782. {
  783. printf("Target Speed = %d \n", ShmFanModuleData->TestFanSpeed);
  784. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  785. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  786. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  787. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  788. }
  789. void SetDebugMode(char *v1)
  790. {
  791. int mode = atoi(v1);
  792. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  793. }
  794. void SetGFDMode(char *v1)
  795. {
  796. int mode = atoi(v1);
  797. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  798. }
  799. // PSU 0 PSU 1 PSU 2 ...
  800. // Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb
  801. // 1 XXX XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX
  802. void GetTemperature(char *inputCmd, unsigned int opt)
  803. {
  804. bool keepRun = false;
  805. bool reflash = false;
  806. int time = 0;
  807. struct timespec _Loop_time;
  808. char strGunTemp[16], strChillerTemp[16];
  809. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  810. {
  811. keepRun = true;
  812. }
  813. printf("\r\n");
  814. printf(" PSU 0 PSU 1 PSU 2 .....\r\n");
  815. printf(" Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb\r\n");
  816. do
  817. {
  818. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  819. if(time >= 1000)
  820. {
  821. if(reflash)
  822. {
  823. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  824. }
  825. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  826. {
  827. sprintf(strGunTemp, "N/A");
  828. sprintf(strChillerTemp, "N/A");
  829. if(_chargingData[i]->ConnectorTemp != 0 && _chargingData[i]->ConnectorTemp != 0xFF)
  830. {
  831. sprintf(strGunTemp, "%3d", _chargingData[i]->ConnectorTemp - 60);
  832. }
  833. if(_chargingData[i]->ChillerTemp != 0 && _chargingData[i]->ChillerTemp != 0xFF)
  834. {
  835. sprintf(strChillerTemp, "%3d", _chargingData[i]->ChillerTemp - 60);
  836. }
  837. printf(" %d %s %s ", i + 1, strGunTemp, strChillerTemp);
  838. for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  839. {
  840. printf(" %3d/%3d/%3d",
  841. ShmPsuData->PsuGroup[i].PsuModule[j].ExletTemp,
  842. ShmPsuData->PsuGroup[i].PsuModule[j].InletTemp,
  843. ShmPsuData->PsuGroup[i].PsuModule[j].CriticalTemp1);
  844. }
  845. printf("\r\n");
  846. }
  847. GetClockTime(&_Loop_time);
  848. if((opt & OPTION_REFLASH) > 0)
  849. {
  850. reflash = true;
  851. }
  852. }
  853. if(keepRun)
  854. {
  855. keepRun = IsLoopStopCmd() ? false : true;
  856. usleep(10000);
  857. }
  858. }while(keepRun);
  859. }
  860. void GetInputVol(char *inputCmd, unsigned int opt)
  861. {
  862. bool keepRun = false;
  863. bool reflash = false;
  864. int time = 0;
  865. struct timespec _Loop_time;
  866. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  867. {
  868. keepRun = true;
  869. }
  870. printf("\r\n");
  871. do
  872. {
  873. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  874. if(time >= 1000)
  875. {
  876. if(reflash)
  877. {
  878. ConsoleReflash(1, 1);
  879. }
  880. printf("L1N_L12 = %4.1f V, L2N_L23 = %4.1f V, L3N_L31 = %4.1f V, DC Input: %4.1f V\r\n",
  881. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  882. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  883. ShmSysConfigAndInfo->SysInfo.InputVoltageT,
  884. ShmSysConfigAndInfo->SysInfo.InputVoltageDc);
  885. GetClockTime(&_Loop_time);
  886. if((opt & OPTION_REFLASH) > 0)
  887. {
  888. reflash = true;
  889. }
  890. }
  891. if(keepRun)
  892. {
  893. keepRun = IsLoopStopCmd() ? false : true;
  894. usleep(10000);
  895. }
  896. }while(keepRun);
  897. printf("\r\n");
  898. }
  899. void GetPsuInformation(char *v1, char *v2, char *v3)
  900. {
  901. printf("**********************AC Contact needed*************************\n");
  902. if(strcmp(v1, "count") == 0)
  903. {
  904. for (int i = 0; i < 4; i++)
  905. {
  906. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  907. }
  908. }
  909. else if(strcmp(v1, "ver") == 0)
  910. {
  911. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  912. {
  913. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  914. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  915. }
  916. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  917. {
  918. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  919. {
  920. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  921. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  922. }
  923. }
  924. }
  925. else if(strcmp(v1, "cap") == 0)
  926. {
  927. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  928. {
  929. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  930. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  931. }
  932. }
  933. else if(strcmp(v1, "input") == 0)
  934. {
  935. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  936. {
  937. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  938. {
  939. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  940. i, count,
  941. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  942. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  943. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  944. }
  945. }
  946. }
  947. else if (strcmp(v1, "output") == 0)
  948. {
  949. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  950. {
  951. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  952. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  953. }
  954. }
  955. else if (strcmp(v1, "test") == 0)
  956. {
  957. int mode = atoi(v2);
  958. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  959. {
  960. ShmPsuData->Work_Step = mode;
  961. }
  962. }
  963. else if (strcmp(v1, "out") == 0)
  964. {
  965. float vol = atof(v2);
  966. float cur = atof(v3);
  967. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  968. {
  969. if (!FindChargingInfoData(0, &_chargingData[0]))
  970. {
  971. printf ("FindChargingInfoData error\n");
  972. return;
  973. }
  974. _chargingData[0]->EvBatterytargetVoltage = vol;
  975. _chargingData[0]->EvBatterytargetCurrent = cur;
  976. }
  977. }
  978. printf("*************************************************\n");
  979. }
  980. void GetConnectorCapInfo(char *v1)
  981. {
  982. int _GunIndex = atoi(v1);
  983. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  984. {
  985. printf ("FindChargingInfoData error\n");
  986. return;
  987. }
  988. printf ("Charger Max Current = %d, Max Power = %d \n",
  989. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  990. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  991. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  992. _GunIndex,
  993. _chargingData[_GunIndex]->RealMaxPower,
  994. _chargingData[_GunIndex]->RealMaxVoltage,
  995. _chargingData[_GunIndex]->RealMaxCurrent);
  996. }
  997. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  998. {
  999. int _GunIndex = atoi(v1);
  1000. float _Voltage = atof(v2);
  1001. float _Current = atof(v3);
  1002. unsigned char PreviousSystemStatus = 0xff;
  1003. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  1004. {
  1005. printf ("FindChargingInfoData error\n");
  1006. return;
  1007. }
  1008. printf ("ReqVoltage = %f, ReqCurrent = %f\n", _Voltage, _Current);
  1009. if(_Voltage > 1000 || _Voltage < 50)
  1010. {
  1011. printf ("Input Voltage over range\n");
  1012. return;
  1013. }
  1014. // if(_Current > 100 || _Current < 2){
  1015. //
  1016. // printf ("Input Current over range\n");
  1017. // return;
  1018. // }
  1019. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  1020. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  1021. //kill ev task
  1022. system("killall Module_EvComm");
  1023. //_Voltage = (_Voltage * 10);
  1024. //_Current = (_Current * 10);
  1025. //system(STTY_US TTY_PATH);
  1026. while(true)
  1027. {
  1028. //fix gun 1
  1029. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  1030. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1031. {
  1032. case S_IDLE:
  1033. {
  1034. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1035. {
  1036. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1037. printf ("[UnconditionalCharge - S_IDLE]\n");
  1038. }
  1039. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  1040. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  1041. }
  1042. break;
  1043. case S_PREPARNING:
  1044. {
  1045. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1046. {
  1047. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1048. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  1049. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1050. printf ("wait find module\n");
  1051. }
  1052. //main 會在此階段判斷以下資料跳到下一個 state
  1053. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  1054. //ShmPsuData->SystemPresentPsuQuantity;
  1055. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  1056. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  1057. //_chargingData[gun_index]->AvailableChargingPower;
  1058. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1059. //sleep(10);
  1060. //清除 main timeout 機制
  1061. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1062. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1063. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1064. }
  1065. break;
  1066. case S_PREPARING_FOR_EV:
  1067. {
  1068. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1069. {
  1070. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1071. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  1072. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  1073. }
  1074. //清除 main timeout 機制
  1075. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1076. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1077. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1078. //充電電壓電流
  1079. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1080. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  1081. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  1082. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1083. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1084. //確定模組己升壓完成
  1085. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  1086. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  1087. {
  1088. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  1089. //EV done
  1090. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  1091. }
  1092. }
  1093. break;
  1094. case S_PREPARING_FOR_EVSE:
  1095. {
  1096. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1097. {
  1098. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1099. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  1100. }
  1101. //printf ("tar vol = %d \n", _Voltage);
  1102. //printf ("tar cur = %d \n", _Current);
  1103. //清除 main timeout 機制
  1104. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1105. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1106. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1107. //充電電壓電流
  1108. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1109. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  1110. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  1111. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1112. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  1113. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  1114. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1115. //確定模組己升壓完成
  1116. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  1117. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  1118. //{
  1119. //printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1120. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  1121. sleep(5);
  1122. //EV done
  1123. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  1124. //}
  1125. //else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  1126. //{
  1127. // printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1128. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1129. //}
  1130. }
  1131. break;
  1132. case S_CHARGING:
  1133. {
  1134. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1135. {
  1136. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1137. //充電電壓電流
  1138. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1139. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  1140. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  1141. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1142. printf ("[UnconditionalCharge - S_CHARGING]\n");
  1143. }
  1144. //ev task do this
  1145. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  1146. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  1147. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
  1148. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1149. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1150. }
  1151. }
  1152. break;
  1153. case S_TERMINATING:
  1154. {
  1155. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1156. {
  1157. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1158. system("/root/Module_EvComm &");
  1159. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  1160. //無阻塞偵測 keybaord 結束
  1161. system(STTY_DEF TTY_PATH);
  1162. }
  1163. sleep(3);
  1164. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  1165. return;
  1166. }
  1167. break;
  1168. case S_COMPLETE:
  1169. {
  1170. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1171. {
  1172. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1173. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  1174. }
  1175. sleep(3);
  1176. return;
  1177. }
  1178. break;
  1179. }
  1180. char word[128];
  1181. char newString[7][10];
  1182. int i,j,ctr;
  1183. memset(word, 0x00, sizeof(word));
  1184. get_char(word);
  1185. if (strlen(word) == 0)
  1186. {
  1187. continue;
  1188. }
  1189. j=0; ctr=0;
  1190. strcpy(newString[1], "-1");
  1191. strcpy(newString[2], "-1");
  1192. for (i = 0; i <= (strlen(word)); i++)
  1193. {
  1194. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1195. {
  1196. newString[ctr][j] = '\0';
  1197. ctr++;
  1198. j = 0;
  1199. }
  1200. else
  1201. {
  1202. newString[ctr][j] = word[i];
  1203. j++;
  1204. }
  1205. }
  1206. if(strcmp(newString[0], "chg") == 0)
  1207. {
  1208. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1209. continue;
  1210. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1211. continue;
  1212. float _vol = atof(newString[1]);
  1213. float _cur = atof(newString[2]);
  1214. if (_cur <= 0 || _cur <= 0)
  1215. continue;
  1216. printf("vol = %f, cur = %f \n", _vol, _cur);
  1217. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  1218. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  1219. }
  1220. else if (strcmp(newString[0], "c") == 0)
  1221. {
  1222. printf("stop \n\r");
  1223. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  1224. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1225. }
  1226. usleep(100000);
  1227. }
  1228. }
  1229. void RunUnconditionalCharge(char *v1, char *v2, char *v3, char *v4)
  1230. {
  1231. float _Voltage[2], _Current[2];
  1232. _Voltage[0] = atof(v1);
  1233. _Current[0] = atof(v2);
  1234. _Voltage[1] = atof(v3);
  1235. _Current[1] = atof(v4);
  1236. unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
  1237. if(!FindChargingInfoData(0, &_chargingData[0]))
  1238. {
  1239. printf ("FindChargingInfoData 0 error\n");
  1240. return;
  1241. }
  1242. if(!FindChargingInfoData(1, &_chargingData[0]))
  1243. {
  1244. printf ("FindChargingInfoData 1 error\n");
  1245. return;
  1246. }
  1247. printf ("Gun 1: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[0], _Current[0]);
  1248. printf ("Gun 2: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[1], _Current[1]);
  1249. if(_Voltage[0] > 1000 || _Voltage[0] < 50 || _Voltage[1] > 1000 || _Voltage[1] < 50)
  1250. {
  1251. printf ("Input Voltage over range\n");
  1252. return;
  1253. }
  1254. //kill ev task
  1255. system("killall Module_EvComm");
  1256. while(true)
  1257. {
  1258. if(_chargingData[0]->SystemStatus == S_IDLE && _chargingData[1]->SystemStatus == S_IDLE)
  1259. {
  1260. _chargingData[0]->SystemStatus = S_REASSIGN_CHECK;
  1261. _chargingData[1]->SystemStatus = S_REASSIGN_CHECK;
  1262. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  1263. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  1264. }
  1265. if(_chargingData[0]->SystemStatus == S_COMPLETE && _chargingData[1]->SystemStatus == S_COMPLETE)
  1266. {
  1267. system(STTY_DEF TTY_PATH);
  1268. sleep(5);
  1269. return;
  1270. }
  1271. for(int i = 0; i < 2; i++)
  1272. {
  1273. switch(_chargingData[i]->SystemStatus)
  1274. {
  1275. case S_IDLE:
  1276. {
  1277. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1278. {
  1279. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1280. printf ("[UnconditionalCharge (%d) - S_IDLE]\n", i);
  1281. }
  1282. }
  1283. break;
  1284. case S_PREPARNING:
  1285. {
  1286. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1287. {
  1288. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1289. printf ("[UnconditionalCharge (%d) - S_PREPARNIN]\n", i);
  1290. printf ("wait find module\n");
  1291. }
  1292. //清除 main timeout 機制
  1293. _chargingData[i]->TimeoutFlag = 0;
  1294. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1295. _chargingData[i]->Type = 9;
  1296. }
  1297. break;
  1298. case S_PREPARING_FOR_EV:
  1299. {
  1300. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1301. {
  1302. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1303. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EV]\n", i);
  1304. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[i] * 10,_Current[i] * 10);
  1305. }
  1306. //清除 main timeout 機制
  1307. _chargingData[i]->TimeoutFlag = 0;
  1308. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1309. _chargingData[i]->Type = 9;
  1310. //充電電壓電流
  1311. _chargingData[i]->EvBatterySoc = 50;
  1312. _chargingData[i]->EvBatterytargetVoltage = 500;
  1313. _chargingData[i]->EvBatterytargetCurrent = 2;
  1314. _chargingData[i]->AvailableChargingCurrent = 1000;
  1315. printf ("Precharge Done = %f \n", _chargingData[i]->PresentChargingVoltage);
  1316. _chargingData[i]->SystemStatus = S_PREPARING_FOR_EVSE;
  1317. }
  1318. break;
  1319. case S_PREPARING_FOR_EVSE:
  1320. {
  1321. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1322. {
  1323. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1324. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EVSE]\n", i);
  1325. }
  1326. //清除 main timeout 機制
  1327. _chargingData[i]->TimeoutFlag = 0;
  1328. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1329. _chargingData[i]->Type = 9;
  1330. //充電電壓電流
  1331. _chargingData[i]->EvBatterySoc = 50;
  1332. _chargingData[i]->EvBatterytargetVoltage = 500;
  1333. _chargingData[i]->EvBatterytargetCurrent = 2;
  1334. _chargingData[i]->AvailableChargingCurrent = 1000;
  1335. printf ("Wait K1K2 = %f \n", _chargingData[i]->PresentChargingVoltage);
  1336. sleep(5);
  1337. //EV done
  1338. _chargingData[i]->SystemStatus = S_CHARGING;
  1339. }
  1340. break;
  1341. case S_CHARGING:
  1342. {
  1343. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1344. {
  1345. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1346. //充電電壓電流
  1347. _chargingData[i]->EvBatterySoc = 50;
  1348. _chargingData[i]->EvBatterytargetVoltage = _Voltage[i];
  1349. _chargingData[i]->EvBatterytargetCurrent = _Current[i];
  1350. _chargingData[i]->AvailableChargingCurrent = 1000;
  1351. printf ("[UnconditionalCharge (%d) - S_CHARGING]\n", i);
  1352. }
  1353. }
  1354. break;
  1355. case S_TERMINATING:
  1356. {
  1357. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1358. {
  1359. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1360. system("/root/Module_EvComm &");
  1361. printf ("[UnconditionalCharge (%d) - S_TERMINATING]\n", i);
  1362. }
  1363. sleep(3);
  1364. _chargingData[i]->SystemStatus = S_COMPLETE;
  1365. }
  1366. break;
  1367. case S_COMPLETE:
  1368. {
  1369. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1370. {
  1371. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1372. printf ("[UnconditionalCharge (%d) - S_COMPLETE]\n", i);
  1373. }
  1374. }
  1375. break;
  1376. }
  1377. }
  1378. char word[128];
  1379. char newString[7][10];
  1380. int i,j,ctr;
  1381. memset(word, 0x00, sizeof(word));
  1382. get_char(word);
  1383. if (strlen(word) == 0)
  1384. {
  1385. continue;
  1386. }
  1387. j=0; ctr=0;
  1388. strcpy(newString[1], "-1");
  1389. strcpy(newString[2], "-1");
  1390. for (i = 0; i <= (strlen(word)); i++)
  1391. {
  1392. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1393. {
  1394. newString[ctr][j] = '\0';
  1395. ctr++;
  1396. j = 0;
  1397. }
  1398. else
  1399. {
  1400. newString[ctr][j] = word[i];
  1401. j++;
  1402. }
  1403. }
  1404. if(strcmp(newString[0], "chg") == 0)
  1405. {
  1406. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1407. continue;
  1408. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1409. continue;
  1410. if (strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  1411. continue;
  1412. int _gun = atoi(newString[1]);
  1413. float _vol = atof(newString[2]);
  1414. float _cur = atof(newString[3]);
  1415. if(_gun >= 2 || _gun < 0)
  1416. continue;
  1417. if (_cur <= 0 || _cur <= 0)
  1418. continue;
  1419. printf("gun %d: vol = %f, cur = %f \n", _gun + 1, _vol, _cur);
  1420. _chargingData[_gun]->EvBatterytargetVoltage = _vol;
  1421. _chargingData[_gun]->EvBatterytargetCurrent = _cur;
  1422. }
  1423. else if (strcmp(newString[0], "c") == 0)
  1424. {
  1425. printf("stop \n\r");
  1426. _chargingData[0]->SystemStatus = S_TERMINATING;
  1427. _chargingData[1]->SystemStatus = S_TERMINATING;
  1428. }
  1429. usleep(100000);
  1430. }
  1431. }
  1432. void SetWiringInfo(char *v1, char *v2)
  1433. {
  1434. int dispenser = atoi(v1);
  1435. int connector = atoi(v2);
  1436. if(dispenser > 0 && dispenser <= GENERAL_GUN_QUANTITY && connector >= 0 && connector <= GENERAL_GUN_QUANTITY)
  1437. {
  1438. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence == (dispenser - 1))
  1439. {
  1440. printf("\r\n");
  1441. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1442. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1443. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = dispenser;
  1444. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += connector;
  1445. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1446. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1447. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1448. }
  1449. else if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > (dispenser - 1))
  1450. {
  1451. printf("\r\n");
  1452. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1453. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1454. int quantity = 0;
  1455. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1456. {
  1457. quantity += ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
  1458. }
  1459. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity = quantity;
  1460. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1461. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1462. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1463. }
  1464. }
  1465. }
  1466. void ShowWiringInfo(void)
  1467. {
  1468. printf("\r\n");
  1469. printf("********** Wiring Info **********\r\n");
  1470. printf("Dispenser = %d, Connector = %d\r\n",
  1471. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
  1472. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
  1473. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > 0)
  1474. {
  1475. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1476. {
  1477. printf("Dispenser[%d] <=> %d\r\n", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
  1478. }
  1479. }
  1480. printf("\r\n");
  1481. }
  1482. void CleanWiringInfo(void)
  1483. {
  1484. printf("\r\n");
  1485. printf("******* Clean Wiring Info *******\r\n");
  1486. memset((char *)&ShmSysConfigAndInfo->SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
  1487. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1488. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.CleanWiringInfo = true;
  1489. printf("\r\n");
  1490. }
  1491. void SetSystemSoftRest(void)
  1492. {
  1493. printf("********* Set Soft Reset ********\r\n");
  1494. ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
  1495. }
  1496. void SetSystemHardReboot(void)
  1497. {
  1498. printf("******** Set Hard Reboot ********\r\n");
  1499. ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
  1500. }
  1501. void SetGroupRole(byte group, byte role)
  1502. {
  1503. if(group < GENERAL_GUN_QUANTITY)
  1504. {
  1505. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != role)
  1506. {
  1507. //printf("\r\nSet Group %d Role = %d", group, role);
  1508. }
  1509. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role = role;
  1510. }
  1511. }
  1512. void SetGroupToIdle(byte group)
  1513. {
  1514. if(group < GENERAL_GUN_QUANTITY)
  1515. {
  1516. SetGroupRole(group, _GROLE_IDLE);
  1517. ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity = 0;
  1518. memset(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1519. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = 0;
  1520. //printf("\r\n Reset Group %02X To Idle", group);
  1521. }
  1522. }
  1523. void SetGroupToMaster(byte group)
  1524. {
  1525. if(group < GENERAL_GUN_QUANTITY)
  1526. {
  1527. SetGroupRole(group, _GROLE_MASTER);
  1528. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = group + 1;
  1529. //printf("\r\n Set Group %02X As Master", group);
  1530. }
  1531. }
  1532. void SetGroupToSlave(byte group, byte target)
  1533. {
  1534. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1535. {
  1536. SetGroupRole(group, _GROLE_SLAVE);
  1537. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = target + 1;
  1538. //printf("\r\n Set Group %02X As Slave", group);
  1539. }
  1540. }
  1541. // group: group index, target: target index
  1542. // add group to target's member
  1543. void AddGroupCollection(byte group, byte target)
  1544. {
  1545. int ParallelConfig = 0;
  1546. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1547. {
  1548. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role != _GROLE_MASTER)
  1549. {
  1550. return;
  1551. }
  1552. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE &&
  1553. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_WAIT_IDLE &&
  1554. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_PRECHARGE_READY)
  1555. {
  1556. return;
  1557. }
  1558. SetGroupToSlave(group, target);
  1559. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity++] = group;
  1560. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1561. if(ParallelConfig != 0)
  1562. {
  1563. ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
  1564. }
  1565. //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);
  1566. }
  1567. }
  1568. // group: group index, target: target index
  1569. // remove group out of target's member
  1570. void RemoveGroupCollection(byte group, byte target)
  1571. {
  1572. int location = 0, slave = 0;
  1573. bool find = false;
  1574. int ParallelConfig = 0;
  1575. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1576. {
  1577. for(int i = 0; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1578. {
  1579. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i])
  1580. {
  1581. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1582. location = i;
  1583. find = true;
  1584. break;
  1585. }
  1586. }
  1587. if(find)
  1588. {
  1589. for(int i = location + 1; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1590. {
  1591. slave = ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i];
  1592. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1593. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i - 1] = slave;
  1594. }
  1595. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity--;
  1596. SetGroupToIdle(group);
  1597. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1598. if(ParallelConfig != 0)
  1599. {
  1600. ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
  1601. }
  1602. //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);
  1603. }
  1604. }
  1605. }
  1606. // Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay
  1607. // 1 (00) 00 3 00 [00] [00] [00] 0000 V 0000 A 0000 kW 0000 A 0000 A 00 XX
  1608. void ShowGroupingInfo(void)
  1609. {
  1610. byte target = 0;
  1611. printf("\r\n Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay");
  1612. for(int i = 0; i < 4; i++)
  1613. {
  1614. target = ShmPsuGrouping->Layout[i];
  1615. printf("\r\n %d (%2d) %2d %d %02X ",
  1616. target + 1, _chargingData[target]->SystemStatus, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role,
  1617. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup);
  1618. for(int j = 0; j < 3; j++)
  1619. {
  1620. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role == 1 && j < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity)
  1621. {
  1622. printf("[%02X] ", ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[j]);
  1623. }
  1624. else
  1625. {
  1626. printf(" ");
  1627. }
  1628. }
  1629. printf(" %4d V %4d A %4d kW %4d A %4d A ",
  1630. (int)_chargingData[target]->PresentChargingVoltage, (int)_chargingData[target]->PresentChargingCurrent,
  1631. (int)(_chargingData[target]->AvailableChargingPower / 10), (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1632. (int)(_chargingData[target]->DeratingChargingCurrent / 10));
  1633. printf("%02X %02X",ShmPsuGrouping->OutputRelayConfig[target].CtrlValue, ShmPsuGrouping->ParallelRelayConfig.CtrlValue);
  1634. }
  1635. printf("\r\n\r\nSystem Capability Current = %4d.%01d A, Power = %3d.%01d kW",
  1636. (ShmPsuData->SystemAvailableCurrent / 10), (ShmPsuData->SystemAvailableCurrent % 10),
  1637. (ShmPsuData->SystemAvailablePower / 10), (ShmPsuData->SystemAvailablePower % 10));
  1638. printf("\r\n\r\n");
  1639. }
  1640. void PsuGroupSwitchToIdle(byte group)
  1641. {
  1642. int master = 0, quantity = 0, location = 0, total = 0;
  1643. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_SLAVE)
  1644. {
  1645. return;
  1646. }
  1647. master = ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup - 1;
  1648. quantity = ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Quantity;
  1649. //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
  1650. for(int i = 0; i < quantity; i++)
  1651. {
  1652. if(total == 0)
  1653. {
  1654. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i])
  1655. {
  1656. location = i;
  1657. total++;
  1658. //printf("\r\n Find Group %02X At Member Index = %d", group, location);
  1659. }
  1660. }
  1661. else
  1662. {
  1663. // find other group in the same direction
  1664. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
  1665. {
  1666. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
  1667. {
  1668. total++;
  1669. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1670. }
  1671. }
  1672. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
  1673. {
  1674. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
  1675. {
  1676. total++;
  1677. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1678. }
  1679. }
  1680. }
  1681. }
  1682. if(total > 0)
  1683. {
  1684. unsigned char collection[GENERAL_GUN_QUANTITY];
  1685. //printf("\r\n There are %d Group Need To Switch Idle:", total);
  1686. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member));
  1687. for(int i = 0; i < total; i++)
  1688. {
  1689. //printf(" %02X", collection[i + location]);
  1690. }
  1691. for(int i = 0; i < total; i++)
  1692. {
  1693. RemoveGroupCollection(collection[i + location], master);
  1694. }
  1695. }
  1696. }
  1697. void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
  1698. {
  1699. int slave = 0, location = 0;
  1700. PsuGroupPartner partner;
  1701. memset(&partner, 0x00, sizeof(PsuGroupPartner));
  1702. // search from left
  1703. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location - 1;
  1704. for(int i = location; i >= 0; i--)
  1705. {
  1706. if(partner.Quantity >= quantity)
  1707. {
  1708. break;
  1709. }
  1710. slave = ShmPsuGrouping->Layout[i];
  1711. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1712. {
  1713. //printf("\r\n Find Group %02X From Left", slave);
  1714. partner.Member[partner.Quantity++] = slave;
  1715. }
  1716. else
  1717. {
  1718. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1719. {
  1720. continue;
  1721. }
  1722. break;
  1723. }
  1724. }
  1725. // search from right
  1726. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location + 1;
  1727. for(int i = location; i < 4; i++)
  1728. {
  1729. if(partner.Quantity >= quantity)
  1730. {
  1731. break;
  1732. }
  1733. slave = ShmPsuGrouping->Layout[i];
  1734. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1735. {
  1736. //printf("\r\n Find Group %02X From Right", slave);
  1737. partner.Member[partner.Quantity++] = slave;
  1738. }
  1739. else
  1740. {
  1741. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1742. {
  1743. continue;
  1744. }
  1745. break;
  1746. }
  1747. }
  1748. memcpy(tPartner, &partner, sizeof(PsuGroupPartner));
  1749. }
  1750. int GetPsuGroupAvailable(byte group)
  1751. {
  1752. //int slave = 0, location = 0, available = 0;
  1753. PsuGroupPartner partner;
  1754. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1755. //printf("\r\n Gun %d Available Quantity = %d", group + 1, partner.Quantity);
  1756. return partner.Quantity;
  1757. #if 0
  1758. // search from left
  1759. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1760. for(int i = location; i >= 0; i--)
  1761. {
  1762. slave = ShmPsuGrouping->Layout[i];
  1763. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1764. {
  1765. available++;
  1766. }
  1767. else
  1768. {
  1769. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1770. {
  1771. continue;
  1772. }
  1773. break;
  1774. }
  1775. }
  1776. // search from right
  1777. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1778. for(int i = location; i < 4; i++)
  1779. {
  1780. slave = ShmPsuGrouping->Layout[i];
  1781. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1782. {
  1783. available++;
  1784. }
  1785. else
  1786. {
  1787. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1788. {
  1789. continue;
  1790. }
  1791. break;
  1792. }
  1793. }
  1794. return available;
  1795. #endif
  1796. }
  1797. void PsuGroupShareCheck(byte group)
  1798. {
  1799. int slave = 0, target = 0, location = 0, share = 0, total = 0;
  1800. total = GetPsuGroupAvailable(group) + 1;
  1801. //printf("\r\n Gun %d Total Group = %d", group + 1, total);
  1802. // search from left
  1803. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1804. for(int i = location; i >= 0; i--)
  1805. {
  1806. slave = ShmPsuGrouping->Layout[i];
  1807. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1808. {
  1809. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1810. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1811. {
  1812. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1813. }
  1814. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1815. break;
  1816. }
  1817. else
  1818. {
  1819. break;
  1820. }
  1821. }
  1822. if(share == 0)
  1823. {
  1824. // search from right
  1825. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1826. for(int i = location; i < 4; i++)
  1827. {
  1828. slave = ShmPsuGrouping->Layout[i];
  1829. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1830. {
  1831. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1832. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1833. {
  1834. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1835. }
  1836. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1837. break;
  1838. }
  1839. else
  1840. {
  1841. break;
  1842. }
  1843. }
  1844. }
  1845. if(share > 0)
  1846. {
  1847. //printf("\r\n Grab %02X", slave);
  1848. PsuGroupSwitchToIdle(slave);
  1849. }
  1850. else
  1851. {
  1852. //printf("\r\n No Need To Grab");
  1853. }
  1854. }
  1855. void SimplePsuGroupStartCharging(byte group)
  1856. {
  1857. //int slave = 0, location = 0;
  1858. int available = 0;
  1859. PsuGroupPartner partner;
  1860. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1861. {
  1862. return;
  1863. }
  1864. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE && ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1865. {
  1866. return;
  1867. }
  1868. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_IDLE)
  1869. {
  1870. SetGroupToMaster(group);
  1871. PsuGroupShareCheck(group);
  1872. }
  1873. else
  1874. {
  1875. available = GetPsuGroupAvailable(group);
  1876. //printf("\r\nGun %d is already master, there are %d available group", group + 1, available);
  1877. if(available == 0)
  1878. {
  1879. return;
  1880. }
  1881. }
  1882. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1883. for(int i = 0; i < partner.Quantity; i++)
  1884. {
  1885. AddGroupCollection(partner.Member[i], group);
  1886. }
  1887. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = true;
  1888. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = true;
  1889. #if 0
  1890. // search from left
  1891. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1892. for(int i = location; i >= 0; i--)
  1893. {
  1894. slave = ShmPsuGrouping->Layout[i];
  1895. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1896. {
  1897. //printf("\r\n Find %02X From Left", slave);
  1898. AddGroupCollection(slave, group);
  1899. }
  1900. else
  1901. {
  1902. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1903. {
  1904. continue;
  1905. }
  1906. break;
  1907. }
  1908. }
  1909. // search from right
  1910. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1911. for(int i = location; i < 4; i++)
  1912. {
  1913. slave = ShmPsuGrouping->Layout[i];
  1914. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1915. {
  1916. //printf("\r\n Find %02X From Right", slave);
  1917. AddGroupCollection(slave, group);
  1918. }
  1919. else
  1920. {
  1921. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1922. {
  1923. continue;
  1924. }
  1925. break;
  1926. }
  1927. }
  1928. #endif
  1929. }
  1930. void PsuGroupStopCharging(byte group)
  1931. {
  1932. int total = 0;
  1933. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1934. {
  1935. return;
  1936. }
  1937. total = ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity;
  1938. if(total > 0)
  1939. {
  1940. unsigned char collection[GENERAL_GUN_QUANTITY];
  1941. //printf("\r\n There are %d Group Need To Stop:", ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity);
  1942. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1943. for(int i = 0; i < total; i++)
  1944. {
  1945. //printf(" %02X", collection[i]);
  1946. }
  1947. for(int i = 0; i < total; i++)
  1948. {
  1949. RemoveGroupCollection(collection[i], group);
  1950. }
  1951. }
  1952. SetGroupToIdle(group);
  1953. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = false;
  1954. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = false;
  1955. }
  1956. void RunSimplePsuGrouping(char *v1, char *v2)
  1957. {
  1958. int group = 0, charging = 0;
  1959. group = atoi(v1);
  1960. charging = atoi(v2);
  1961. group -= 1;
  1962. if(group >= 0 && group < 4)
  1963. {
  1964. if(charging > 0)
  1965. {
  1966. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1967. {
  1968. //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
  1969. PsuGroupSwitchToIdle(group);
  1970. }
  1971. SimplePsuGroupStartCharging(group);
  1972. }
  1973. if(charging == 0)
  1974. {
  1975. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_MASTER)
  1976. {
  1977. PsuGroupStopCharging(group);
  1978. }
  1979. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1980. {
  1981. PsuGroupSwitchToIdle(group);
  1982. }
  1983. }
  1984. ShowGroupingInfo();
  1985. }
  1986. }
  1987. void ShowCabinetInfo(void)
  1988. {
  1989. int ipAddress = 0;
  1990. printf("\r\n");
  1991. printf("Psu Work Step = %d, PsuComm: %d\r\n", ShmPsuData->Work_Step, ShmChargerInfo->Control.CommInfo.PsuComm.CommCnt);
  1992. printf("Psu RxCnt: %d\r\n", ShmChargerInfo->Control.CommInfo.PsuComm.RxCnt);
  1993. printf(" Dispenser: %d / %d, Connector: %d / %d\r\n",
  1994. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
  1995. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
  1996. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
  1997. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
  1998. printf("\r\n");
  1999. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2000. {
  2001. ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
  2002. printf(" Dispenser Connection[%d] Status: %d, DispenserIndex: %d, IP: %d.%d.%d.%d\r\n", i,
  2003. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status,
  2004. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex,
  2005. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  2006. }
  2007. printf("\r\n");
  2008. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2009. {
  2010. printf(" Connector[%d] Index: %2X, Status = %2d , %s\r\n", i, _chargingData[i]->Index, _chargingData[i]->SystemStatus,
  2011. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable ? "Enable" : "Disable");
  2012. }
  2013. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  2014. {
  2015. printf(" Dispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  2016. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  2017. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  2018. {
  2019. ipAddress = 0;
  2020. for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
  2021. {
  2022. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].Status == _CNS_DispenserMatched &&
  2023. i == ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].DispenserIndex)
  2024. {
  2025. ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].IpAddress;
  2026. }
  2027. }
  2028. printf(", ModelName: %s, IP: %d.%d.%d.%d\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName,
  2029. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  2030. for(int j = 0; j < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity; j++)
  2031. {
  2032. unsigned char gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorID[j];
  2033. printf(" - Connector[%d] Gun %d, %s\r\n", j, gun, _chargingData[gun - 1]->ConnectorPlugIn ? "Plugged" : "Unplugged");
  2034. }
  2035. }
  2036. else
  2037. {
  2038. printf(", No Information\r\n");
  2039. }
  2040. }
  2041. printf("\r\n");
  2042. }
  2043. void SetTestControl(char *v1, char *v2)
  2044. {
  2045. int testItem = 0;
  2046. int testItemLen = 3;
  2047. int enable = 0;
  2048. char strTest[32][32] = {"tbl", "tfsb", "chgsm"};
  2049. char strItem[32][32] = {"Balance", "Fast Standby Time", "Charging Simulation"};
  2050. enable = atoi(v2);
  2051. if(enable < 0)
  2052. {
  2053. return;
  2054. }
  2055. for(int i = 0; i < testItemLen; i++)
  2056. {
  2057. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2058. {
  2059. testItem = i + 1;
  2060. break;
  2061. }
  2062. }
  2063. if(testItem != 0)
  2064. {
  2065. if(enable)
  2066. {
  2067. ShmChargerInfo->Control.TestCtrl.CtrlValue |= (1 << (testItem - 1));
  2068. }
  2069. else
  2070. {
  2071. ShmChargerInfo->Control.TestCtrl.CtrlValue &= ~(1 << (testItem - 1));
  2072. }
  2073. printf("%s %s Test Item, Test Control Value = %08X\n",
  2074. enable ? "Enable" : "Disable", strItem[testItem - 1], ShmChargerInfo->Control.TestCtrl.CtrlValue);
  2075. }
  2076. else
  2077. {
  2078. printf("Test Item %s Not Found\n", v1);
  2079. for(int i = 0; i < testItemLen; i++)
  2080. {
  2081. printf(" [%s] -> %s Test\n", strTest[i], strItem[i]);
  2082. }
  2083. }
  2084. printf("\r\n");
  2085. }
  2086. // Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading
  2087. // 1 00 00 0 0000 V 000.0 A 0000 A XXX.XX XXX.XX
  2088. void ShowGroupingDemand(void)
  2089. {
  2090. byte target = 0;
  2091. unsigned char k1k2 = 0;
  2092. printf("\r\n Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading");
  2093. for(int i = 0; i < 4; i++)
  2094. {
  2095. target = ShmPsuGrouping->Layout[i];
  2096. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup != 0)
  2097. {
  2098. k1k2 = _chargingData[ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
  2099. }
  2100. else
  2101. {
  2102. k1k2 = _chargingData[target]->RelayK1K2Status;
  2103. }
  2104. printf("\r\n %d %2d %02X %d %4d V %3d.%d A %4d A %3d.%02d",
  2105. target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup, k1k2,
  2106. (ShmPsuGrouping->GroupOutput[target].GTargetVoltage / 10),
  2107. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent / 10),
  2108. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent % 10),
  2109. (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  2110. (ShmPsuGrouping->GroupOutput[target].OutputLoading / 100),
  2111. (ShmPsuGrouping->GroupOutput[target].OutputLoading % 100));
  2112. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup == target + 1)
  2113. {
  2114. printf(" %3d.%02d", (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading / 100), (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading % 100));
  2115. }
  2116. }
  2117. printf("\r\n\r\n");
  2118. }
  2119. // v1: gun
  2120. // v2: voltage
  2121. // v3: current
  2122. void SetGunStartCharging(char *v1, char *v2, char *v3)
  2123. {
  2124. int gun = 0;
  2125. float _voltage = 0, _current = 0;
  2126. gun = atoi(v1);
  2127. _voltage = atof(v2);
  2128. _current = atof(v3);
  2129. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY || _voltage < 0 || _voltage > 1000 || _current < 0 || _current > 1200)
  2130. {
  2131. printf("\r\nGun Start Charging Input parameter %s, %s, %s over range", v1, v2, v3);
  2132. printf("\r\n\r\n");
  2133. return;
  2134. }
  2135. /*
  2136. if(_chargingData[gun - 1]->SystemStatus == S_IDLE)
  2137. {
  2138. printf("\r\nSet Gun %d Start Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  2139. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  2140. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  2141. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2142. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2143. }
  2144. else if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
  2145. {
  2146. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  2147. {
  2148. printf("\r\nSet Gun %d > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  2149. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2150. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2151. }
  2152. else
  2153. {
  2154. printf("\r\nGun %d Force Charging Is Disable", gun);
  2155. }
  2156. }
  2157. else
  2158. {
  2159. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2160. }
  2161. printf("\r\n\r\n");
  2162. */
  2163. bool wait = true;
  2164. int time = 0;
  2165. struct timespec _Wait_time;
  2166. unsigned char PreviousSystemStatus = 0xFF;
  2167. unsigned short _targetVoltage = 0, _targetCurrent = 0;
  2168. while(wait)
  2169. {
  2170. switch(_chargingData[gun - 1]->SystemStatus)
  2171. {
  2172. case S_IDLE:
  2173. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2174. {
  2175. printf("\r\nGun %d S_IDLE", gun);
  2176. printf("\r\nSet Gun %d Start Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  2177. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  2178. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  2179. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2180. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2181. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2182. }
  2183. break;
  2184. case S_REASSIGN_CHECK:
  2185. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2186. {
  2187. printf("\r\nGun %d S_REASSIGN_CHECK, Wait For Request Charging", gun);
  2188. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2189. }
  2190. break;
  2191. case S_REASSIGN:
  2192. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2193. {
  2194. printf("\r\nGun %d S_REASSIGN, Wait For Grouping", gun);
  2195. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2196. }
  2197. break;
  2198. case S_PREPARNING:
  2199. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2200. {
  2201. printf("\r\nGun %d S_PREPARNING", gun);
  2202. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2203. }
  2204. break;
  2205. case S_PREPARING_FOR_EV:
  2206. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2207. {
  2208. printf("\r\nGun %d S_PREPARING_FOR_EV", gun);
  2209. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2210. }
  2211. break;
  2212. case S_PREPARING_FOR_EVSE:
  2213. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2214. {
  2215. printf("\r\nGun %d S_PREPARING_FOR_EVSE, Wait For EVSE", gun);
  2216. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2217. }
  2218. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  2219. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  2220. {
  2221. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2222. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2223. printf("\r\nGun %d Set Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  2224. }
  2225. break;
  2226. case S_CHARGING:
  2227. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2228. {
  2229. printf("\r\nGun %d S_CHARGING", gun);
  2230. if(PreviousSystemStatus == 0xFF)
  2231. {
  2232. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2233. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2234. printf("\r\nGun %d Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  2235. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  2236. {
  2237. printf("\r\nSet Gun %d Force Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  2238. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2239. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2240. }
  2241. }
  2242. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2243. GetClockTime(&_Wait_time);
  2244. }
  2245. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  2246. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  2247. {
  2248. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2249. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2250. printf("\r\nGun %d Set Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  2251. }
  2252. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2253. if(time >= 3)
  2254. {
  2255. wait = false;
  2256. printf("\r\nDone");
  2257. }
  2258. break;
  2259. case S_TERMINATING:
  2260. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2261. {
  2262. printf("\r\nGun %d S_TERMINATING", gun);
  2263. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2264. }
  2265. wait = false;
  2266. break;
  2267. case S_COMPLETE:
  2268. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2269. {
  2270. printf("\r\nGun %d S_COMPLETE", gun);
  2271. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2272. }
  2273. wait = false;
  2274. break;
  2275. case S_ALARM:
  2276. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2277. {
  2278. printf("\r\nGun %d S_ALARM", gun);
  2279. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2280. }
  2281. wait = false;
  2282. break;
  2283. default:
  2284. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2285. {
  2286. printf("\r\nGun SystemStatus %d Unknown(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2287. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2288. }
  2289. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2290. wait = false;
  2291. break;
  2292. }
  2293. char word[128];
  2294. char newString[7][10];
  2295. int i,j,ctr;
  2296. memset(word, 0x00, sizeof(word));
  2297. get_char(word);
  2298. if (strlen(word) == 0)
  2299. {
  2300. continue;
  2301. }
  2302. j=0; ctr=0;
  2303. strcpy(newString[1], "-1");
  2304. strcpy(newString[2], "-1");
  2305. for (i = 0; i <= (strlen(word)); i++)
  2306. {
  2307. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2308. {
  2309. newString[ctr][j] = '\0';
  2310. ctr++;
  2311. j = 0;
  2312. }
  2313. else
  2314. {
  2315. newString[ctr][j] = word[i];
  2316. j++;
  2317. }
  2318. }
  2319. if(strcmp(newString[0], "c") == 0)
  2320. {
  2321. printf("\r\nStop");
  2322. wait = false;
  2323. }
  2324. usleep(100000);
  2325. }
  2326. printf("\r\n\r\n");
  2327. }
  2328. // v1: gun
  2329. void SetGunStopCharging(char *v1)
  2330. {
  2331. int gun = 0;
  2332. gun = atoi(v1);
  2333. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
  2334. {
  2335. printf("\r\nGun Stop Charging Input parameter %s over range", v1);
  2336. printf("\r\n\r\n");
  2337. return;
  2338. }
  2339. /*
  2340. if(_chargingData[gun - 1]->SystemStatus >= S_REASSIGN_CHECK && _chargingData[gun - 1]->SystemStatus <= S_CHARGING)
  2341. {
  2342. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2343. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2344. }
  2345. else if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2346. {
  2347. printf("\r\nSet Group [%02X] Stop", gun - 1);
  2348. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2349. }
  2350. else
  2351. {
  2352. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2353. }
  2354. printf("\r\n\r\n");
  2355. */
  2356. bool wait = true;
  2357. int time = 0;
  2358. struct timespec _Wait_time;
  2359. unsigned char PreviousSystemStatus = 0xFF;
  2360. while(wait)
  2361. {
  2362. switch(_chargingData[gun - 1]->SystemStatus)
  2363. {
  2364. case S_IDLE:
  2365. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2366. {
  2367. printf("\r\nGun %d S_IDLE", gun);
  2368. if(PreviousSystemStatus == 0xFF)
  2369. {
  2370. if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2371. {
  2372. printf("\r\nSet Group [%02X] Stop", gun - 1);
  2373. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2374. }
  2375. }
  2376. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2377. GetClockTime(&_Wait_time);
  2378. }
  2379. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2380. if(time >= 3)
  2381. {
  2382. wait = false;
  2383. printf("\r\nDone");
  2384. }
  2385. break;
  2386. case S_REASSIGN_CHECK:
  2387. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2388. {
  2389. printf("\r\nGun %d S_REASSIGN_CHECK, Wait For Request Charging", gun);
  2390. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2391. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2392. {
  2393. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2394. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2395. }
  2396. }
  2397. break;
  2398. case S_REASSIGN:
  2399. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2400. {
  2401. printf("\r\nGun %d S_REASSIGN, Wait For Grouping", gun);
  2402. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2403. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2404. {
  2405. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2406. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2407. }
  2408. }
  2409. break;
  2410. case S_PREPARNING:
  2411. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2412. {
  2413. printf("\r\nGun %d S_PREPARNING", gun);
  2414. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2415. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2416. {
  2417. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2418. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2419. }
  2420. }
  2421. break;
  2422. case S_PREPARING_FOR_EV:
  2423. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2424. {
  2425. printf("\r\nGun %d S_PREPARING_FOR_EV", gun);
  2426. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2427. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2428. {
  2429. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2430. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2431. }
  2432. }
  2433. break;
  2434. case S_PREPARING_FOR_EVSE:
  2435. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2436. {
  2437. printf("\r\nGun %d S_PREPARING_FOR_EVSE, Wait For EVSE", gun);
  2438. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2439. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2440. {
  2441. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2442. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2443. }
  2444. }
  2445. break;
  2446. case S_CHARGING:
  2447. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2448. {
  2449. printf("\r\nGun %d S_CHARGING", gun);
  2450. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2451. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2452. {
  2453. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2454. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2455. }
  2456. }
  2457. break;
  2458. case S_TERMINATING:
  2459. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2460. {
  2461. printf("\r\nGun %d S_TERMINATING", gun);
  2462. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2463. }
  2464. break;
  2465. case S_COMPLETE:
  2466. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2467. {
  2468. printf("\r\nGun %d S_COMPLETE", gun);
  2469. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2470. }
  2471. break;
  2472. case S_ALARM:
  2473. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2474. {
  2475. printf("\r\nGun %d S_ALARM", gun);
  2476. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2477. }
  2478. break;
  2479. default:
  2480. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2481. {
  2482. printf("\r\nGun SystemStatus %d Unknown(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2483. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2484. }
  2485. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2486. wait = false;
  2487. break;
  2488. }
  2489. char word[128];
  2490. char newString[7][10];
  2491. int i,j,ctr;
  2492. memset(word, 0x00, sizeof(word));
  2493. get_char(word);
  2494. if (strlen(word) == 0)
  2495. {
  2496. continue;
  2497. }
  2498. j=0; ctr=0;
  2499. strcpy(newString[1], "-1");
  2500. strcpy(newString[2], "-1");
  2501. for (i = 0; i <= (strlen(word)); i++)
  2502. {
  2503. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2504. {
  2505. newString[ctr][j] = '\0';
  2506. ctr++;
  2507. j = 0;
  2508. }
  2509. else
  2510. {
  2511. newString[ctr][j] = word[i];
  2512. j++;
  2513. }
  2514. }
  2515. if(strcmp(newString[0], "c") == 0)
  2516. {
  2517. printf("\r\nStop");
  2518. wait = false;
  2519. }
  2520. usleep(100000);
  2521. }
  2522. printf("\r\n\r\n");
  2523. }
  2524. void SetGunExtend(char *v1)
  2525. {
  2526. int gun = 0;
  2527. gun = atoi(v1);
  2528. if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
  2529. {
  2530. printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
  2531. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
  2532. }
  2533. else
  2534. {
  2535. printf("\r\nGun %d Extend Capability Is Not Available, SystemStatus(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2536. }
  2537. printf("\r\n\r\n");
  2538. }
  2539. // 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 ...
  2540. // 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
  2541. void ShowGunOutput(void)
  2542. {
  2543. byte target = 0;
  2544. unsigned short voltage = 0, current = 0;
  2545. 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 ...");
  2546. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2547. {
  2548. target = ShmPsuGrouping->Layout[i];
  2549. // "\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"
  2550. voltage = (unsigned short)(_chargingData[target]->EvBatterytargetVoltage * 10);
  2551. current = (unsigned short)(_chargingData[target]->EvBatterytargetCurrent * 10);
  2552. printf("\r\n %d %4d.%d V %3d.%d A", target + 1, (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2553. voltage = ShmPsuGrouping->GroupOutput[target].GTargetVoltage;
  2554. current = ShmPsuGrouping->GroupOutput[target].GTargetCurrent;
  2555. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2556. voltage = (unsigned short)(_chargingData[target]->PresentChargingVoltage * 10);
  2557. current = (unsigned short)(_chargingData[target]->PresentChargingCurrent * 10);
  2558. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2559. voltage = ShmPsuData->PsuGroup[target].GroupPresentOutputVoltage;
  2560. current = ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent;
  2561. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2562. /*
  2563. for(int j = 0; j < ShmPsuData->PsuGroup[target].GroupPresentPsuQuantity; j++)
  2564. {
  2565. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2566. }
  2567. */
  2568. }
  2569. printf("\r\n\r\n");
  2570. }
  2571. void SetGpio(char *v1, char *v2)
  2572. {
  2573. int testItem = 0;
  2574. int testItemLen = 1;
  2575. int ioOutput = 0;
  2576. char strTest[32][32] = {"4g"};
  2577. char strItem[32][32] = {"4G Reset"};
  2578. ioOutput = atoi(v2);
  2579. if(ioOutput < 0)
  2580. {
  2581. return;
  2582. }
  2583. for(int i = 0; i < testItemLen; i++)
  2584. {
  2585. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2586. {
  2587. testItem = i + 1;
  2588. break;
  2589. }
  2590. }
  2591. if(testItem != 0)
  2592. {
  2593. if(ioOutput)
  2594. {
  2595. system("echo 1 > /sys/class/gpio/gpio104/value");
  2596. }
  2597. else
  2598. {
  2599. system("echo 0 > /sys/class/gpio/gpio104/value");
  2600. }
  2601. printf("Set %s %s\n",
  2602. strItem[testItem - 1], ioOutput > 0 ? "High" : "Low");
  2603. }
  2604. else
  2605. {
  2606. printf("Gpio Item %s Not Found\n", v1);
  2607. }
  2608. printf("\r\n");
  2609. }
  2610. void ShowStatus(void)
  2611. {
  2612. char *str_cabinet_role[] = {STR_CABINET_ROLE_NONE, STR_CABINET_ROLE_MASTER, STR_CABINET_ROLE_SLAVE};
  2613. for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
  2614. {
  2615. printf("\r\nGun %d Status = %d, IsAvailable = %d, GunEnable = %d",
  2616. i + 1,
  2617. _chargingData[i]->SystemStatus,
  2618. _chargingData[i]->IsAvailable,
  2619. ShmChargerInfo->Control.GunAvailable[i]);
  2620. printf("\r\nAlarmCode");
  2621. printf("\r\n Connector = %6s, EvConn = %6s, Remote = %6s, Vendor = %6s",
  2622. strncmp((char *)_chargingData[i]->ConnectorAlarmCode, "", 6) != 0 ?
  2623. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2624. strncmp((char *)_chargingData[i]->EvConnAlarmCode, "", 6) != 0 ?
  2625. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2626. strncmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode, "", 6) != 0 ?
  2627. (char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode : "No Err",
  2628. strncmp((char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode, "", 6) != 0 ?
  2629. (char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode : "No Err");
  2630. }
  2631. printf("\r\n");
  2632. printf("\r\nPower Cabinet Role: %s, Switch Value: %d",
  2633. ShmChargerInfo->Control.CabinetSwitch <= _CROLE_SLAVE ? str_cabinet_role[ShmChargerInfo->Control.CabinetSwitch] : "Unknown",
  2634. ShmChargerInfo->Control.CabinetSwitch);
  2635. printf("\r\nStatus Code Len = %d", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
  2636. if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
  2637. {
  2638. printf("\r\n WarningCode:");
  2639. for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  2640. {
  2641. printf(" %s", (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  2642. }
  2643. }
  2644. printf("\r\n\r\n");
  2645. }
  2646. void ShowWhiteCardList(void)
  2647. {
  2648. printf("\r\nWhite Card List");
  2649. for(int i = 0; i < 10; i++)
  2650. {
  2651. printf("\r\n White Card [%2d]: %s", i + 1, (char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i]);
  2652. }
  2653. printf("\r\n\r\n");
  2654. }
  2655. void WriteWhiteCard(char *v1, char *v2)
  2656. {
  2657. int cardIndex = 0;
  2658. cardIndex = atoi(v1);
  2659. if(cardIndex < 1 || cardIndex > 10)
  2660. {
  2661. printf("\r\n White Card Index Fail\r\n\r\n");
  2662. return;
  2663. }
  2664. if(strlen(v2) == 0 || strlen(v2) > 31)
  2665. {
  2666. printf("\r\n White Card Fail\r\n\r\n");
  2667. return;
  2668. }
  2669. printf("\r\n Str Len = %d = %s", strlen(v2), v2);
  2670. printf("\r\n Set White Card Index %d = %s", cardIndex, v2);
  2671. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], v2, strlen(v2));
  2672. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  2673. printf("\r\n\r\n");
  2674. }
  2675. void EraseWhiteCard(char *v1)
  2676. {
  2677. int cardIndex = 0;
  2678. cardIndex = atoi(v1);
  2679. if(cardIndex < 1 || cardIndex > 10)
  2680. {
  2681. printf("\r\n White Card Index Fail\r\n\r\n");
  2682. return;
  2683. }
  2684. printf("\r\n Erase White Card Index = %d", cardIndex);
  2685. memset((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], 0x00, 32);
  2686. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  2687. printf("\r\n\r\n");
  2688. }
  2689. void ShowChargerLimit(void)
  2690. {
  2691. int limitPower = -1;
  2692. char *str_gun_type[] = {STR_GUN_TYPE_CHADEMO, STR_GUN_TYPE_CCS, STR_GUN_TYPE_GBT};
  2693. unsigned char inUsingCnt = 0;
  2694. printf("\r\nCharger Limit");
  2695. printf("\r\n System Psu Cnt: %2d", ShmPsuData->SystemPresentPsuQuantity);
  2696. printf("\r\n Charger Max ChargingProfile Power: %d kW", ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1 ?
  2697. (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000);
  2698. printf("\r\n Max Total Current: %d A, Max Total Power: %d kW, Total Energy: %d kW, Total Duration %d",
  2699. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent, ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  2700. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy, ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2701. printf("\r\n\r\n Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur");
  2702. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2703. {
  2704. inUsingCnt = 0;
  2705. for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
  2706. {
  2707. if(ShmChargerInfo->PsuGrouping.GroupCollection[j].Role == _GROLE_MASTER)
  2708. {
  2709. inUsingCnt += ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity;
  2710. }
  2711. }
  2712. // Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur
  2713. // 1 0 CHAdeMO 00 0000 V 0000 A 0000 / 0000 / 0000 kW 0000 / 0000 A
  2714. // Gun 1 Enable, Type: CCS, Psu Cnt: 00, Max Physical Vol: 0000 V, Cur: 0000 A, Max Config Pow: 0000 kW, Cur: 0000 A
  2715. printf("\r\n %d %d ", i + 1, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable);
  2716. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable)
  2717. {
  2718. printf(" %7s %2d",
  2719. _chargingData[i]->Type <= _Type_GB ? str_gun_type[_chargingData[i]->Type] : "???",
  2720. ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity);
  2721. printf(" %4d V %4d A",
  2722. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalVoltage / 10),
  2723. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalCurrent / 10));
  2724. if(ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower != -1)
  2725. {
  2726. limitPower = (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
  2727. if(inUsingCnt > 0)
  2728. {
  2729. limitPower = (limitPower * ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity) / inUsingCnt;
  2730. }
  2731. }
  2732. else
  2733. {
  2734. limitPower = -1;
  2735. }
  2736. printf(" %4d / %4d / %4d kW",
  2737. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].MaxTotalChargingPower / 10),
  2738. _chargingData[i]->ChargingProfilePower == -1 ? (int)_chargingData[i]->ChargingProfilePower : ((int)_chargingData[i]->ChargingProfilePower / 1000),
  2739. limitPower == -1 ? limitPower : (limitPower / 1000));
  2740. printf(" %4d / %4d A",
  2741. ((int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].MaxTotalChargingCurrent / 10),
  2742. _chargingData[i]->ChargingProfileCurrent == -1 ? (int)_chargingData[i]->ChargingProfileCurrent : ((int)_chargingData[i]->ChargingProfileCurrent / 10));
  2743. }
  2744. }
  2745. printf("\r\n\r\n");
  2746. }
  2747. void SetGunCommand(char *v1, char *v2, char *v3)
  2748. {
  2749. int cmdItem = 0;
  2750. int cmdItemLen = 2;
  2751. int gunID = 0;
  2752. int enable = 0;
  2753. char strGunCmd[32][32] = {"enable", "operative"};
  2754. char strDescription[32][32] = {"Available", "Operative"};
  2755. gunID = atoi(v2);
  2756. enable = atoi(v3);
  2757. if(gunID <= 0 || gunID > CONNECTOR_QUANTITY || enable < 0)
  2758. {
  2759. return;
  2760. }
  2761. for(int i = 0; i < cmdItemLen; i++)
  2762. {
  2763. if(strcmp((char *)&strGunCmd[i][0], v1) == 0)
  2764. {
  2765. cmdItem = i + 1;
  2766. break;
  2767. }
  2768. }
  2769. if(cmdItem != 0)
  2770. {
  2771. switch(cmdItem)
  2772. {
  2773. case 1:
  2774. ShmChargerInfo->Control.GunAvailable[gunID - 1] = enable > 0 ? YES : NO;
  2775. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2776. break;
  2777. case 2:
  2778. _chargingData[gunID - 1]->IsAvailable = enable > 0 ? YES : NO;
  2779. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2780. break;
  2781. }
  2782. printf("Gun cmd [%s] [%s]\n", strDescription[cmdItem - 1], enable ? "Enable" : "Disable");
  2783. }
  2784. else
  2785. {
  2786. printf("Gun cmd %s not found\n", v1);
  2787. for(int i = 0; i < cmdItemLen; i++)
  2788. {
  2789. printf(" [%s] -> %s Test\n", strGunCmd[i], strDescription[i]);
  2790. }
  2791. }
  2792. printf("\r\n");
  2793. }
  2794. void ShowWebSystemInfo(void)
  2795. {
  2796. char *str_led_intensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  2797. char *str_qr_code_made[] = {STR_QR_DEFAULT, STR_QR_CUSTOMIZED, STR_QR_CHARGEBOXID};
  2798. char *str_rfid_endian[] = {STR_LITTLE_ENDIAN, STR_BIG_ENDIAN};
  2799. printf("\r\n");
  2800. printf("Web [System]\r\n");
  2801. printf(" *System ID: %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
  2802. printf(" *AuthorisationMode[%7s]\r\n",
  2803. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE ? "Enable" : "Disable");
  2804. printf(" - APP [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAPP > 0 ? "Enable" : "Disable");
  2805. printf(" - QRCode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isQRCode > 0 ? "Enable" : "Disable");
  2806. printf(" - RFID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isRFID > 0 ? "Enable" : "Disable");
  2807. printf(" - EVCCID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID > 0 ? "Enable" : "Disable");
  2808. if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian <= RFID_ENDIAN_BIG)
  2809. {
  2810. printf(" *RfidCardNumEndian [%s]\r\n", str_rfid_endian[ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian]);
  2811. }
  2812. else
  2813. {
  2814. printf(" *RfidCardNumEndian: %d\r\n", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
  2815. }
  2816. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode <= _QR_MODE_Customized)
  2817. {
  2818. printf(" *QR Code Made [%s]\r\n", str_qr_code_made[ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode]);
  2819. }
  2820. else
  2821. {
  2822. printf(" *QR Code Made: %d\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode);
  2823. }
  2824. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == _QR_MODE_Customized)
  2825. {
  2826. printf(" - QR Code Content: %s\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  2827. }
  2828. if(ShmChargerInfo->AuthInfo.QRCodeMode <= _QR_MODE_ChargeBoxId)
  2829. {
  2830. printf(" *QR Code Mode [%s]\r\n", str_qr_code_made[ShmChargerInfo->AuthInfo.QRCodeMode]);
  2831. }
  2832. else
  2833. {
  2834. printf(" *QR Code Mode: %d\r\n", ShmChargerInfo->AuthInfo.QRCodeMode);
  2835. }
  2836. if(ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity <= _LED_INTENSITY_BRIGHTEST)
  2837. {
  2838. printf(" *LED Intensity[%s]\r\n", str_led_intensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
  2839. }
  2840. else
  2841. {
  2842. printf(" *LED Intensity[%d]\r\n", ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity);
  2843. }
  2844. }
  2845. void ShowWebChargingInfo(void)
  2846. {
  2847. printf("\r\n");
  2848. printf("Web [Charging]\r\n");
  2849. printf(" *Max Charging Energy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy);
  2850. printf(" *Max Charging Power : %4d kW\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingPower);
  2851. printf(" *Max Charging Current : %4d A\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  2852. printf(" *Max Charging Duration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2853. printf(" *StopCharging By Button[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton > 0 ? "Enable" : "Disable");
  2854. printf(" *Billing[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.isBilling > 0 ? "Enable" : "Disable");
  2855. printf(" - Currency[%2d]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
  2856. }
  2857. void ShowWebNetworkInfo(void)
  2858. {
  2859. char *str_wifi_mode[] = {"Disable", "Station", "AP Mode"};
  2860. printf("\r\n");
  2861. printf("Web [Network]\r\n");
  2862. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2863. printf(" *DHCP Client[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0 ? "Enable" : "Disable");
  2864. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode <= _SYS_WIFI_MODE_AP)
  2865. {
  2866. printf(" *WiFi Mode [%7s]\r\n", str_wifi_mode[ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode]);
  2867. }
  2868. else
  2869. {
  2870. printf(" *WiFi Mode [%d]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
  2871. }
  2872. printf(" - ConnStatus[%s]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ? "Connected" : "Disconnected");
  2873. printf(" *3G/4G Mode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES ? "Enable" : "Disable");
  2874. printf(" - ConnStatus[%s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ? "Connected" : "Disconnected");
  2875. printf(" - APN : %s\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
  2876. printf(" - RSSI: %d dBm\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
  2877. }
  2878. void ShowWebBackendInfo(void)
  2879. {
  2880. char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
  2881. char *str_security_profile[] = {
  2882. "None security",
  2883. "Unsecured Transport with Basic Atuentication",
  2884. "TLS with Basic Authentication",
  2885. "TLS with Client Side Certificates"
  2886. };
  2887. printf("\r\n");
  2888. printf("Web [Backend]\r\n");
  2889. printf(" *Common\r\n");
  2890. printf(" - Backend Timeout : %d s\r\n", ShmSysConfigAndInfo->SysConfig.BackendConnTimeout);
  2891. if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy <= _OFFLINE_POLICY_NO_CHARGING)
  2892. {
  2893. printf(" - Offline Policy : %s\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
  2894. }
  2895. else
  2896. {
  2897. printf(" - Offline Policy : %d\r\n", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
  2898. }
  2899. printf(" - OfflineMaxEnergy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy);
  2900. printf(" - OfflineMaxDuration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration);
  2901. printf(" *OCPP\r\n");
  2902. printf(" - OcppStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES ? "Connected" : "Disconnected");
  2903. printf(" - OcppURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  2904. printf(" - ChargeBoxId: %s\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2905. printf(" - Vendor : %s\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2906. if(ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile <= 3)
  2907. {
  2908. printf(" - Security : %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile]);
  2909. }
  2910. else
  2911. {
  2912. printf(" - Security : %d\r\n", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2913. }
  2914. printf(" - MaintainStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus == YES ? "Connected" : "Disconnected");
  2915. printf(" - MaintainURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  2916. if(ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile <= 3)
  2917. {
  2918. printf(" - MaintainSecurity: %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile]);
  2919. }
  2920. else
  2921. {
  2922. printf(" - MaintainSecurity: %d\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile);
  2923. }
  2924. printf(" *TTIA[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES ? "Enable" : "Disable");
  2925. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES)
  2926. {
  2927. printf(" - ServerAddress: %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  2928. printf(" - ServerPort : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  2929. printf(" - BusVenderId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  2930. printf(" - Provider : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  2931. printf(" - CompanyNo : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  2932. printf(" - ChargeBoxId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  2933. printf(" - EVSEStation : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  2934. }
  2935. }
  2936. void ShowWebAllInfo(void)
  2937. {
  2938. ShowWebSystemInfo();
  2939. ShowWebChargingInfo();
  2940. ShowWebNetworkInfo();
  2941. ShowWebBackendInfo();
  2942. }
  2943. void ShowWebInfo(char *v1)
  2944. {
  2945. bool find = false;
  2946. int showItem = 0;
  2947. int itemLen = 5;
  2948. char strItem[32][32] = {"system", "charging", "network", "backend", "all"};
  2949. void *actionList[32] = {&ShowWebSystemInfo, &ShowWebChargingInfo, &ShowWebNetworkInfo, &ShowWebBackendInfo, &ShowWebAllInfo};
  2950. void (*ItemAction)();
  2951. for(showItem = 0; showItem < itemLen; showItem++)
  2952. {
  2953. if(strcmp((char *)&strItem[showItem][0], v1) == 0)
  2954. {
  2955. find = true;
  2956. break;
  2957. }
  2958. }
  2959. if(find)
  2960. {
  2961. ItemAction = actionList[showItem];
  2962. ItemAction();
  2963. }
  2964. else
  2965. {
  2966. printf("\r\n");
  2967. printf ("Input cmd fail ------ web [cmd]\r\n");
  2968. for(int i = 0; i < itemLen; i++)
  2969. {
  2970. printf(" [cmd] %s\r\n", (char *)&strItem[i][0]);
  2971. }
  2972. }
  2973. printf("\r\n");
  2974. }
  2975. // Gun 1 ( CCS ) Soc: XXX %, Energy: XXXXX.X kWh, IdTag [XXXXXXXXXXXXXXXX] Transaction [0]
  2976. // Gun 1 ( CCS ) IdTag: XXXXXXXXXXXXXXXX, Soc: XXX %, Energy: XXXX.X kWh
  2977. // (XX) (X) Target: XXXX V, XXXX A, Cap: XXXX A, XXXX kW
  2978. // Output: XXXX V, XXXX A, Limit: XXXX A, XXXX kW
  2979. void ShowGunInfo(int gun)
  2980. {
  2981. char *str_gun_type[] = {"CHAdeMO", " CCS ", " GBT "};
  2982. char acceptId[128];
  2983. Get_Ocpp_TransactionId(gun, acceptId);
  2984. printf(" Gun %d (%s) Soc: %3d %s, Energy: %7.1f kWh, IdTag [%16s] Transaction [%s], TotalCost: %d.%02d\r\n",
  2985. gun + 1,
  2986. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
  2987. _chargingData[gun]->EvBatterySoc, "%",
  2988. _chargingData[gun]->PresentChargedEnergy,
  2989. _chargingData[gun]->StartUserId,
  2990. acceptId,
  2991. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost / 100),
  2992. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost % 100));
  2993. //printf(" Gun %d (%s) IdTag [%16s] Soc: %3d %s, Energy: %4.1f kWh\r\n",
  2994. // i + 1,
  2995. // ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable ? str_gun_type[_chargingData[i]->Type] : "Disable",
  2996. // _chargingData[i]->StartUserId,
  2997. // _chargingData[i]->EvBatterySoc, "%",
  2998. // _chargingData[i]->PresentChargedEnergy);
  2999. printf(" (%2d) (%s) Target: %4d V, %4d A, Cap: %4d A, %4d kW\r\n",
  3000. _chargingData[gun]->SystemStatus,
  3001. _chargingData[gun]->ConnectorPlugIn ? "O" : "X",
  3002. (int)_chargingData[gun]->EvBatterytargetVoltage,
  3003. (int)_chargingData[gun]->EvBatterytargetCurrent,
  3004. (int)(_chargingData[gun]->AvailableChargingCurrent / 10),
  3005. (int)(_chargingData[gun]->AvailableChargingPower / 10));
  3006. printf(" Output: %4d V, %4d A, Limit: %4d A, %4d kW\r\n",
  3007. (int)(_chargingData[gun]->PresentChargingVoltage),
  3008. (int)(_chargingData[gun]->PresentChargingCurrent),
  3009. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityCurrent / 10),
  3010. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityPower / 10));
  3011. }
  3012. void ShowInfo(char *inputCmd, unsigned int opt)
  3013. {
  3014. bool keepRun = false;
  3015. bool reflash = false;
  3016. int time = 0;
  3017. struct timespec _Loop_time;
  3018. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  3019. {
  3020. keepRun = true;
  3021. }
  3022. do
  3023. {
  3024. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  3025. if(time >= 1000)
  3026. {
  3027. if(reflash)
  3028. {
  3029. ConsoleReflash(CONNECTOR_QUANTITY, 4);
  3030. }
  3031. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  3032. {
  3033. printf("\r\n");
  3034. ShowGunInfo(i);
  3035. }
  3036. GetClockTime(&_Loop_time);
  3037. if((opt & OPTION_REFLASH) > 0)
  3038. {
  3039. reflash = true;
  3040. }
  3041. }
  3042. if(keepRun)
  3043. {
  3044. keepRun = IsLoopStopCmd() ? false : true;
  3045. usleep(10000);
  3046. }
  3047. }while(keepRun);
  3048. printf("\r\n");
  3049. }
  3050. int main(void)
  3051. {
  3052. char newString[32][32];
  3053. char inputString[128], normalCmd[128], mainCmd[128], subCmd[128], multiCmd[128];
  3054. int cmdCnt = 0, parseCnt = 0;
  3055. unsigned int option = 0;
  3056. if(InitShareMemory() == FAIL)
  3057. {
  3058. printf ("InitShareMemory = FAIL \n");
  3059. if(ShmStatusCodeData != NULL)
  3060. {
  3061. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3062. }
  3063. sleep(5);
  3064. return 0;
  3065. }
  3066. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  3067. {
  3068. if (!FindChargingInfoData(i, &_chargingData[0]))
  3069. {
  3070. return 0;
  3071. }
  3072. }
  3073. // clean command
  3074. memset(mainCmd, 0x00, sizeof(mainCmd));
  3075. memset(subCmd, 0x00, sizeof(subCmd));
  3076. for(int i = 0; i < 32; i++)
  3077. {
  3078. memset(&newString[i], 0x00, 32);
  3079. }
  3080. for(;;)
  3081. {
  3082. memset(inputString, 0x00, sizeof(inputString));
  3083. memset(normalCmd, 0x00, sizeof(normalCmd));
  3084. get_char(inputString);
  3085. cmdCnt = InputStringNormalize(inputString, normalCmd, &option);
  3086. if(cmdCnt > 0)
  3087. {
  3088. // clean command
  3089. memset(mainCmd, 0x00, sizeof(mainCmd));
  3090. memset(subCmd, 0x00, sizeof(subCmd));
  3091. for(int i = 0; i < 32; i++)
  3092. {
  3093. memset(&newString[i], 0x00, 32);
  3094. }
  3095. //printf("CmdCnt: %d\r\n", cmdCnt);
  3096. //printf("Input: %s", inputString);
  3097. //printf("Normalize: %s\r\n", normalCmd);
  3098. //printf("option: %08X\r\n", option);
  3099. MainAndSubCommandParsing(normalCmd, mainCmd, subCmd);
  3100. //printf("MainCmd: %s\r\n", mainCmd);
  3101. //printf("SubCmd: %s\r\n", subCmd);
  3102. parseCnt = 0;
  3103. strcpy(multiCmd, normalCmd);
  3104. do
  3105. {
  3106. MainAndSubCommandParsing(multiCmd, &newString[parseCnt][0], &newString[parseCnt + 1][0]);
  3107. strcpy(multiCmd, &newString[parseCnt + 1][0]);
  3108. //printf("MultiCmd Parse %d\r\n", parseCnt + 1);
  3109. //printf("MainCmd: %s\r\n", &newString[parseCnt][0]);
  3110. //printf("SubCmd: %s\r\n", &newString[parseCnt + 1][0]);
  3111. parseCnt++;
  3112. }while(parseCnt < cmdCnt - 1);
  3113. //printf("\r\n");
  3114. //for(int i = 0; i < cmdCnt; i++)
  3115. //{
  3116. // printf("MultiCmd %d: [%s]\r\n", i + 1, &newString[i][0]);
  3117. //}
  3118. }
  3119. else
  3120. {
  3121. usleep(100000);
  3122. continue;
  3123. }
  3124. if(strcmp(newString[0], "state") == 0)
  3125. {
  3126. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3127. continue;
  3128. // 槍狀態
  3129. RunStatusProc(newString[1], newString[2]);
  3130. }
  3131. else if(strcmp(newString[0], "card") == 0)
  3132. {
  3133. // 刷卡狀態
  3134. RunCardProc(newString[1], newString[2]);
  3135. }
  3136. else if(strcmp(newString[0], "gun") == 0)
  3137. {
  3138. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3139. continue;
  3140. // 插槍狀態
  3141. RunGunPlugitProc(newString[1], newString[2]);
  3142. }
  3143. else if(strcmp(newString[0], "lock") == 0)
  3144. {
  3145. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3146. continue;
  3147. // 插槍狀態
  3148. GetGunLockStatusProc(newString[1], newString[2]);
  3149. }
  3150. else if(strcmp(newString[0], "sysid") == 0)
  3151. {
  3152. // 測試 sys id
  3153. SetSystemIDProc();
  3154. }
  3155. else if(strcmp(newString[0], "self") == 0)
  3156. {
  3157. // CSU 自我檢測狀態
  3158. RunSelfProc(newString[1]);
  3159. }
  3160. else if(strcmp(newString[0], "ver") == 0)
  3161. {
  3162. //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3163. // continue;
  3164. // 取 FW 版號
  3165. //GetFwVerProc(newString[1]);
  3166. ShowFwVer();
  3167. }
  3168. else if (strcmp(newString[0], "update") == 0)
  3169. {
  3170. // 更新
  3171. FwUpdateFlagProc(newString[1]);
  3172. }
  3173. else if (strcmp(newString[0], "ac") == 0)
  3174. {
  3175. // AC contactor 狀態
  3176. CheckAcStatus(newString[1]);
  3177. }
  3178. else if (strcmp(newString[0], "cable") == 0)
  3179. {
  3180. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3181. continue;
  3182. // cable check pass
  3183. SetCableChkStatus(newString[1], newString[2]);
  3184. }
  3185. else if (strcmp(newString[0], "pow") == 0)
  3186. {
  3187. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3188. continue;
  3189. // cable check pass
  3190. SetPowerValue(newString[1], newString[2]);
  3191. }
  3192. else if (strcmp(newString[0], "model") == 0)
  3193. {
  3194. GetSystemInfo();
  3195. }
  3196. else if(strcmp(newString[0], "fan") == 0)
  3197. {
  3198. // 設定風扇速度
  3199. SetFanSpeed(newString[1]);
  3200. }
  3201. else if(strcmp(newString[0], "speed") == 0)
  3202. {
  3203. // 取得風扇速度
  3204. GetFanSpeed();
  3205. }
  3206. else if(strcmp(newString[0], "debug") == 0)
  3207. {
  3208. // 設定 debug mode
  3209. SetDebugMode(newString[1]);
  3210. }
  3211. else if (strcmp(newString[0], "gfd") == 0)
  3212. {
  3213. // 設定盲沖使用 GFD 功能
  3214. SetGFDMode(newString[1]);
  3215. }
  3216. else if(strcmp(mainCmd, "temp") == 0)
  3217. {
  3218. // 取得溫度
  3219. GetTemperature(subCmd, option);
  3220. }
  3221. else if(strcmp(mainCmd, "acin") == 0)
  3222. {
  3223. // 取得三向輸入電壓
  3224. GetInputVol(subCmd, option);
  3225. }
  3226. else if(strcmp(newString[0], "psu") == 0)
  3227. {
  3228. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  3229. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3230. {
  3231. printf ("PSU : Param fail..Please retry again......\n");
  3232. continue;
  3233. }
  3234. // 取得 PSU 資訊
  3235. GetPsuInformation(newString[1], newString[2], newString[3]);
  3236. }
  3237. else if (strcmp(newString[0], "cap") == 0)
  3238. {
  3239. GetConnectorCapInfo(newString[1]);
  3240. }
  3241. else if(strcmp(newString[0], "error") == 0)
  3242. {
  3243. CreateOneError(newString[1]);
  3244. }
  3245. else if (strcmp(newString[0], "auth") == 0)
  3246. {
  3247. GetAuthorizeFlag(newString[1]);
  3248. }
  3249. else if (strcmp(newString[0], "id") == 0)
  3250. {
  3251. GetOrClearId(newString[1]);
  3252. }
  3253. #if 0
  3254. else if(strcmp(newString[0], "strchg") == 0)
  3255. {
  3256. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  3257. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3258. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3259. {
  3260. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  3261. continue;
  3262. }
  3263. // 槍狀態
  3264. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  3265. }
  3266. else if(strcmp(newString[0], "str2chg") == 0)
  3267. {
  3268. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  3269. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3270. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  3271. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
  3272. strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
  3273. {
  3274. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  3275. continue;
  3276. }
  3277. // 槍狀態
  3278. RunUnconditionalCharge(newString[1], newString[2], newString[3], newString[4]);
  3279. }
  3280. #endif
  3281. else if(strcmp(newString[0], "wiring") == 0)
  3282. {
  3283. if(strcmp(newString[1], "-1") != 0 && strcmp(newString[1], "") != 0 &&
  3284. strcmp(newString[2], "-1") != 0 && strcmp(newString[2], "") != 0)
  3285. {
  3286. SetWiringInfo(newString[1], newString[2]);
  3287. }
  3288. ShowWiringInfo();
  3289. }
  3290. else if(strcmp(newString[0], "cwiring") == 0)
  3291. {
  3292. CleanWiringInfo();
  3293. }
  3294. else if(strcmp(newString[0], "reset") == 0)
  3295. {
  3296. SetSystemSoftRest();
  3297. }
  3298. else if(strcmp(newString[0], "reboot") == 0)
  3299. {
  3300. SetSystemHardReboot();
  3301. }
  3302. else if(strcmp(newString[0], "sgroup") == 0)
  3303. {
  3304. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3305. {
  3306. ShowGroupingInfo();
  3307. continue;
  3308. }
  3309. RunSimplePsuGrouping(newString[1], newString[2]);
  3310. }
  3311. else if(strcmp(newString[0], "cabinet") == 0)
  3312. {
  3313. ShowCabinetInfo();
  3314. }
  3315. else if(strcmp(newString[0], "tctl") == 0)
  3316. {
  3317. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3318. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3319. {
  3320. printf("Test Control Value = %08X\n",ShmChargerInfo->Control.TestCtrl.CtrlValue);
  3321. printf ("Input cmd fail ------ tctl [tcmd] [value]\n\n");
  3322. continue;
  3323. }
  3324. SetTestControl(newString[1], newString[2]);
  3325. }
  3326. else if(strcmp(newString[0], "group") == 0)
  3327. {
  3328. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3329. {
  3330. ShowGroupingInfo();
  3331. continue;
  3332. }
  3333. }
  3334. else if(strcmp(newString[0], "gdmd") == 0)
  3335. {
  3336. ShowGroupingDemand();
  3337. }
  3338. else if(strcmp(newString[0], "gunchg") == 0)
  3339. {
  3340. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3341. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  3342. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  3343. {
  3344. printf ("Input cmd fail ------ gunchg [gun 1-4] [voltage 0-1000] [current 0-100]\n\n");
  3345. continue;
  3346. }
  3347. SetGunStartCharging(newString[1], newString[2], newString[3]);
  3348. }
  3349. else if(strcmp(newString[0], "gunstp") == 0)
  3350. {
  3351. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3352. {
  3353. printf ("Input cmd fail ------ gunstp [gun 1-4]\n\n");
  3354. continue;
  3355. }
  3356. SetGunStopCharging(newString[1]);
  3357. }
  3358. else if(strcmp(newString[0], "gunext") == 0)
  3359. {
  3360. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3361. {
  3362. printf ("Input cmd fail ------ gunext [gun 1-4]\n\n");
  3363. continue;
  3364. }
  3365. SetGunExtend(newString[1]);
  3366. }
  3367. else if(strcmp(newString[0], "output") == 0)
  3368. {
  3369. ShowGunOutput();
  3370. }
  3371. else if(strcmp(newString[0], "gio") == 0)
  3372. {
  3373. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3374. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3375. {
  3376. printf ("Input cmd fail ------ gio [io] [on-off 0-1]\n\n");
  3377. continue;
  3378. }
  3379. SetGpio(newString[1], newString[2]);
  3380. }
  3381. else if(strcmp(newString[0], "status") == 0)
  3382. {
  3383. ShowStatus();
  3384. }
  3385. else if(strcmp(newString[0], "whiteR") == 0)
  3386. {
  3387. ShowWhiteCardList();
  3388. }
  3389. else if(strcmp(newString[0], "whiteW") == 0)
  3390. {
  3391. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3392. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3393. {
  3394. printf ("Input cmd fail ------ whiteW [index 1-10] [card id]\n\n");
  3395. continue;
  3396. }
  3397. WriteWhiteCard(newString[1], newString[2]);
  3398. }
  3399. else if(strcmp(newString[0], "whiteE") == 0)
  3400. {
  3401. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3402. {
  3403. printf ("Input cmd fail ------ whiteE [index 1-10]\n\n");
  3404. continue;
  3405. }
  3406. EraseWhiteCard(newString[1]);
  3407. }
  3408. else if(strcmp(newString[0], "limit") == 0)
  3409. {
  3410. ShowChargerLimit();
  3411. }
  3412. else if(strcmp(newString[0], "pcmd") == 0)
  3413. {
  3414. }
  3415. else if(strcmp(newString[0], "gcmd") == 0)
  3416. {
  3417. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3418. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  3419. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  3420. {
  3421. printf ("Input cmd fail ------ gcmd [cmd] [gun] [value]\n\n");
  3422. continue;
  3423. }
  3424. SetGunCommand(newString[1], newString[2], newString[3]);
  3425. }
  3426. else if(strcmp(newString[0], "web") == 0)
  3427. {
  3428. ShowWebInfo(newString[1]);
  3429. }
  3430. else if(strcmp(mainCmd, "info") == 0)
  3431. {
  3432. ShowInfo(subCmd, option);
  3433. }
  3434. else
  3435. {
  3436. printf ("%s\n", msg);
  3437. }
  3438. usleep(100000);
  3439. }
  3440. return 0;
  3441. }