ReadCmdline.c 114 KB

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