ReadCmdline.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  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. typedef unsigned char byte;
  38. #define PASS 1
  39. #define FAIL -1
  40. #define EQUAL 0
  41. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  42. #define NO_DEFINE 255
  43. #define DEFAULT_AC_INDEX 2
  44. #define YES 1
  45. #define NO 0
  46. #define AUTORUN_STEP1_TIME_START 140 // Minutes
  47. #define AUTORUN_STEP1_TIME_END 150
  48. #define AUTORUN_STEP2_TIME_START 210
  49. #define AUTORUN_STEP2_TIME_END 410
  50. #define AUTORUN_END_TIME 480
  51. #define AUTORUN_CYCLE_COUNT 30
  52. #define TTY_PATH "/dev/tty"
  53. #define STTY_US "stty raw -echo -F "
  54. #define STTY_DEF "stty -raw echo -F "
  55. byte _curAutoRunCount = 0;
  56. byte _usingAutoRun = 0;
  57. struct timeval _autoTime;
  58. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  59. struct StatusCodeData *ShmStatusCodeData;
  60. struct PrimaryMcuData *ShmPrimaryMcuData;
  61. struct CHAdeMOData *ShmCHAdeMOData;
  62. struct CcsData *ShmCcsData;
  63. struct GBTData *ShmGBTData;
  64. struct FanModuleData *ShmFanModuleData;
  65. struct RelayModuleData *ShmRelayModuleData;
  66. struct LedModuleData *ShmLedModuleData;
  67. struct PsuData *ShmPsuData;
  68. struct DcCommonInformation *ShmDcCommonData;
  69. struct OCPP16Data *ShmOCPP16Data;
  70. struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  71. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  72. char *msg = "state : get gun state (index) \n"
  73. "card : scanning card (x) : \n"
  74. "gun : get gun plugit state (index) \n"
  75. "lock : get gun locked state (index) \n"
  76. "self : self test state (x) \n"
  77. "ver : ver of board (407 or index or rb or fan) \n"
  78. "ac : get ac relay state (x) \n";
  79. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  80. {
  81. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  82. {
  83. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  84. {
  85. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  86. return true;
  87. }
  88. }
  89. for (byte index = 0; index < CCS_QUANTITY; index++)
  90. {
  91. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  92. {
  93. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  94. return true;
  95. }
  96. }
  97. for (byte index = 0; index < GB_QUANTITY; index++)
  98. {
  99. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  100. {
  101. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  108. {
  109. if (target < AC_QUANTITY)
  110. {
  111. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  112. return true;
  113. }
  114. return false;
  115. }
  116. int InitShareMemory()
  117. {
  118. int result = PASS;
  119. int MeterSMId;
  120. //initial ShmSysConfigAndInfo
  121. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  122. {
  123. result = FAIL;
  124. }
  125. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  126. {
  127. result = FAIL;
  128. }
  129. //initial ShmStatusCodeData
  130. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  131. {
  132. result = FAIL;
  133. }
  134. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  135. {
  136. result = FAIL;
  137. }
  138. if (CHAdeMO_QUANTITY > 0) {
  139. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  140. IPC_CREAT | 0777)) < 0) {
  141. result = FAIL;
  142. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  143. == (void *) -1) {
  144. result = FAIL;
  145. } else {
  146. }
  147. }
  148. if (CCS_QUANTITY > 0) {
  149. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  150. IPC_CREAT | 0777)) < 0) {
  151. result = FAIL;
  152. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  153. result = FAIL;
  154. } else {
  155. }
  156. }
  157. if (GB_QUANTITY > 0) {
  158. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  159. IPC_CREAT | 0777)) < 0) {
  160. return 0;
  161. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  162. return 0;
  163. }
  164. }
  165. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  166. {
  167. result = FAIL;
  168. }
  169. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  170. {
  171. result = FAIL;
  172. }
  173. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  174. {
  175. result = FAIL;
  176. }
  177. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  178. {
  179. result = FAIL;
  180. }
  181. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  182. {
  183. result = FAIL;
  184. }
  185. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  186. {
  187. result = FAIL;
  188. }
  189. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  190. {
  191. result = FAIL;
  192. }
  193. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  194. {
  195. result = FAIL;
  196. }
  197. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  198. {
  199. result = FAIL;
  200. }
  201. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  202. {
  203. result = FAIL;
  204. }
  205. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  206. {
  207. result = FAIL;
  208. }
  209. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  210. {
  211. result = FAIL;
  212. }
  213. if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
  214. {
  215. result = FAIL;
  216. }
  217. else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  218. {
  219. result = FAIL;
  220. }
  221. return result;
  222. }
  223. unsigned long GetTimeoutValue(struct timeval _sour_time)
  224. {
  225. struct timeval _end_time;
  226. gettimeofday(&_end_time, NULL);
  227. return (_end_time.tv_sec - _sour_time.tv_sec);
  228. }
  229. void RunStatusProc(char *v1, char *v2)
  230. {
  231. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  232. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  233. if (strcmp(v1, "ac") == 0)
  234. {
  235. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  236. {
  237. printf("FindChargingInfoData (AC) false \n");
  238. }
  239. printf("AC Status = %d \n", ac_chargingInfo[0]->SystemStatus);
  240. printf("AC ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  241. return;
  242. }
  243. int _index = atoi(v1);
  244. if (_index <= 1)
  245. {
  246. if (!FindChargingInfoData(_index, &_chargingData[0]))
  247. {
  248. printf ("FindChargingInfoData error\n");
  249. return;
  250. }
  251. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  252. {
  253. // get
  254. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  255. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  256. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  257. printf ("SOC = %d \n", _chargingData[_index]->EvBatterySoc);
  258. printf ("Maximum battery Voltage = %f \n", _chargingData[_index]->EvBatteryMaxVoltage);
  259. printf("Charging mode = %d \n", ShmSysConfigAndInfo->SysInfo.MainChargingMode);
  260. printf("maxTemp = %d, temp-I = %d, temp-II = %d \n",
  261. _chargingData[_index]->ConnectorTemp - 60,
  262. ShmDcCommonData->ConnectorTemp1[_index] - 60,
  263. ShmDcCommonData->ConnectorTemp2[_index] - 60);
  264. }
  265. else
  266. {
  267. // set
  268. _chargingData[_index]->SystemStatus = atoi(v2);
  269. }
  270. }
  271. else
  272. {
  273. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  274. {
  275. printf("FindChargingInfoData (AC) false \n");
  276. }
  277. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  278. {
  279. // get
  280. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  281. }
  282. else
  283. {
  284. // set
  285. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  286. }
  287. }
  288. }
  289. void RunCardProc(char *v1, char *v2)
  290. {
  291. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  292. {
  293. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  294. {
  295. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  296. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  297. }
  298. else
  299. {
  300. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  301. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  302. }
  303. }
  304. else
  305. {
  306. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  307. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  308. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  309. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  310. }
  311. }
  312. void RunGunPlugitProc(char *v1, char *v2)
  313. {
  314. if (strcmp(v1, "ac") == 0)
  315. {
  316. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  317. {
  318. printf("FindChargingInfoData (AC) false \n");
  319. }
  320. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  321. {
  322. // get
  323. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  324. }
  325. else
  326. {
  327. // set
  328. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  329. }
  330. return;
  331. }
  332. int _index = atoi(v1);
  333. if (!FindChargingInfoData(_index, &_chargingData[0]))
  334. {
  335. printf("FindChargingInfoData error\n");
  336. return;
  337. }
  338. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  339. {
  340. // get
  341. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  342. }
  343. else
  344. {
  345. // set
  346. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  347. }
  348. }
  349. void GetGunLockStatusProc(char *v1, char *v2)
  350. {
  351. int _index = atoi(v1);
  352. if (!FindChargingInfoData(_index, &_chargingData[0]))
  353. {
  354. printf("FindChargingInfoData error\n");
  355. return;
  356. }
  357. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  358. {
  359. _chargingData[_index]->GunLocked = atoi(v2);
  360. }
  361. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  362. }
  363. void SetSystemIDProc()
  364. {
  365. char *systemId = "Alston_Test";
  366. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  367. }
  368. void RunSelfProc()
  369. {
  370. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  371. }
  372. void GetFwVerProc(char *v1)
  373. {
  374. if (strcmp(v1, "407") == 0)
  375. {
  376. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  377. }
  378. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0)
  379. {
  380. int _index = atoi(v1);
  381. if (_index == 0)
  382. printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
  383. else if (_index == 1)
  384. printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
  385. }
  386. else if (strcmp(v1, "rb") == 0)
  387. {
  388. printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  389. }
  390. else if (strcmp(v1, "fan") == 0)
  391. {
  392. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  393. }
  394. else if (strcmp(v1, "dc") == 0)
  395. {
  396. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  397. }
  398. else if (strcmp(v1, "led") == 0)
  399. {
  400. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  401. }
  402. else if (strcmp(v1, "ac") == 0)
  403. {
  404. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  405. {
  406. printf("FindChargingInfoData (AC) false \n");
  407. }
  408. printf("AC Version = %s \n", ac_chargingInfo[0]->version);
  409. }
  410. else if (strcmp(v1, "all") == 0)
  411. {
  412. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  413. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  414. printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
  415. printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
  416. printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  417. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  418. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  419. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  420. {
  421. printf("FindChargingInfoData (AC) false \n");
  422. }
  423. printf("AC Version = %s \n", ac_chargingInfo[0]->version);
  424. }
  425. }
  426. void CreateOneError()
  427. {
  428. for (byte i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  429. {
  430. printf("(%d). %s \n", i, &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  431. }
  432. }
  433. void GetAuthorizeFlag(char *v1)
  434. {
  435. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  436. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  437. else
  438. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  439. }
  440. void GetRelayStatus(char *v1)
  441. {
  442. int _index = atoi(v1);
  443. if (!FindChargingInfoData(_index, &_chargingData[0]))
  444. {
  445. printf("FindChargingInfoData error\n");
  446. return;
  447. }
  448. printf("RelayK1K2Status = %d \n", _chargingData[_index]->RelayK1K2Status);
  449. printf("RelayKPK2Status = %d \n", _chargingData[_index]->RelayKPK2Status);
  450. }
  451. void GetSOC(char *v1)
  452. {
  453. int _index = atoi(v1);
  454. if (!FindChargingInfoData(_index, &_chargingData[0]))
  455. {
  456. printf("FindChargingInfoData error\n");
  457. return;
  458. }
  459. printf("Soc = %d \n", _chargingData[_index]->EvBatterySoc);
  460. }
  461. void FwUpdateFlagProc()
  462. {
  463. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  464. }
  465. void CheckAcStatus(char *v1)
  466. {
  467. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  468. {
  469. printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  470. }
  471. else
  472. ShmSysConfigAndInfo->SysInfo.AcContactorStatus = atoi(v1);
  473. }
  474. void SetCableChkStatus(char *v1, char *v2)
  475. {
  476. int _index = atoi(v1);
  477. if (!FindChargingInfoData(_index, &_chargingData[0]))
  478. {
  479. printf ("FindChargingInfoData error\n");
  480. return;
  481. }
  482. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  483. }
  484. void SetChargingInfoCCID(char *v1, char* v2)
  485. {
  486. int _index = atoi(v1);
  487. if (!FindChargingInfoData(_index, &_chargingData[0]))
  488. {
  489. printf ("FindChargingInfoData error\n");
  490. return;
  491. }
  492. memcpy(_chargingData[_index]->EVCCID, v2, strlen(v2));
  493. _chargingData[_index]->EVCCID[strlen(v2)] = '\0';
  494. }
  495. void GetGunTemp(char *v1)
  496. {
  497. int _index = atoi(v1);
  498. if (!FindChargingInfoData(_index, &_chargingData[0]))
  499. {
  500. printf ("FindChargingInfoData error\n");
  501. return;
  502. }
  503. printf("Gun_%d, maxTemp = %d, temp 1 = %d, temp 2 = %d \n",
  504. _index,
  505. _chargingData[_index]->ConnectorTemp - 60,
  506. ShmDcCommonData->ConnectorTemp1[_index] - 60,
  507. ShmDcCommonData->ConnectorTemp2[_index] - 60);
  508. }
  509. void GetOffered(char *v1)
  510. {
  511. int _index = atoi(v1);
  512. if (!FindChargingInfoData(_index, &_chargingData[0]))
  513. {
  514. printf ("FindChargingInfoData error\n");
  515. return;
  516. }
  517. printf("Gun_%d, PowerOffered = %f, CurrentOffered = %f \n",
  518. _index,
  519. _chargingData[_index]->PowerOffered,
  520. _chargingData[_index]->CurrentOffered);
  521. }
  522. void GetEvStatus(char *v1)
  523. {
  524. int _index = atoi(v1);
  525. if (!FindChargingInfoData(_index, &_chargingData[0]))
  526. {
  527. printf ("FindChargingInfoData error\n");
  528. return;
  529. }
  530. if (_chargingData[_index]->Type == _Type_Chademo)
  531. printf ("Chademo status= %d \n", ShmCHAdeMOData->evse[_chargingData[_index]->type_index].EvboardStatus);
  532. else if (_chargingData[_index]->Type == _Type_CCS)
  533. printf ("CCS status= %d \n", ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].PresentMsgFlowStatus);
  534. else if (_chargingData[_index]->Type == _Type_GB)
  535. printf ("GBT status = %d \n", ShmGBTData->evse[_chargingData[_index]->type_index].EvboardStatus);
  536. }
  537. void GetDcMeterInfor(char *v1)
  538. {
  539. int _index = atoi(v1);
  540. if (!FindChargingInfoData(_index, &_chargingData[0]))
  541. {
  542. printf ("FindChargingInfoData error\n");
  543. return;
  544. }
  545. printf("Index = %d, LinkStatus = %d presetVoltage = %f, presentCurrent = %f, presentPower = %f, totlizeImportEnergy = %f, totlizeExportEnergy = %f \n",
  546. _index,
  547. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].LinkStatus,
  548. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presetVoltage,
  549. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presentCurrent,
  550. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presentPower,
  551. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeImportEnergy,
  552. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeExportEnergy);
  553. }
  554. void GetPowerValue()
  555. {
  556. for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
  557. {
  558. if (!FindChargingInfoData(index, &_chargingData[0]))
  559. {
  560. printf ("FindChargingInfoData error\n");
  561. return;
  562. }
  563. printf ("index = %d, PresentChargingPower = %f \n", index, _chargingData[index]->PresentChargingPower);
  564. }
  565. }
  566. void GetSystemInfo()
  567. {
  568. printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  569. printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  570. printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
  571. printf ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  572. ShmPsuData->SystemAvailablePower / 10,
  573. ShmPsuData->SystemAvailableCurrent / 10
  574. );
  575. printf ("Config : ChargingPower = %d, ChargingCurrent = %d \n",
  576. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  577. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  578. }
  579. void ChangeGunNum()
  580. {
  581. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  582. {
  583. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  584. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  585. }
  586. else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  587. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
  588. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  589. else
  590. {
  591. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  592. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  593. }
  594. }
  595. void GetGunSelectedNum(char *v1)
  596. {
  597. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  598. {
  599. if (AC_QUANTITY > 0 &&
  600. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
  601. {
  602. printf("connector select changed = AC \n");
  603. }
  604. else
  605. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  606. }
  607. else
  608. {
  609. int _index = atoi(v1);
  610. if (_index <= 1)
  611. {
  612. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  613. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  614. printf("connector select changed = %d \n", _index);
  615. }
  616. else if (AC_QUANTITY > 0)
  617. {
  618. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  619. printf("connector select changed = AC \n");
  620. }
  621. }
  622. }
  623. void SetFanSpeed(char *v1)
  624. {
  625. int speed = atoi(v1);
  626. ShmFanModuleData->TestFanSpeed = speed;
  627. }
  628. void ShowSysInformation()
  629. {
  630. if (!ShmSysConfigAndInfo->SysConfig.ShowInformation)
  631. ShmSysConfigAndInfo->SysConfig.ShowInformation = 0x01;
  632. else
  633. ShmSysConfigAndInfo->SysConfig.ShowInformation = 0x00;
  634. printf("Show inform = %d \n", ShmSysConfigAndInfo->SysConfig.ShowInformation);
  635. }
  636. void GetFanSpeed()
  637. {
  638. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  639. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  640. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  641. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  642. }
  643. void SetDebugMode(char *v1)
  644. {
  645. int mode = atoi(v1);
  646. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  647. }
  648. void SetGFDMode(char *v1)
  649. {
  650. int mode = atoi(v1);
  651. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  652. }
  653. void GetPsuTemp()
  654. {
  655. char _ex_maxTemp = 0;
  656. char _cr_maxTemp = 0;
  657. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  658. {
  659. _ex_maxTemp = 0;
  660. _cr_maxTemp = 0;
  661. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  662. {
  663. if (ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp > _ex_maxTemp)
  664. _ex_maxTemp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
  665. if (ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1 > _cr_maxTemp)
  666. _cr_maxTemp = ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1;
  667. }
  668. printf("D.D. Temp = %d ------ Env Temp = %d \n", _ex_maxTemp, _cr_maxTemp);
  669. }
  670. }
  671. void GetAcInputVol()
  672. {
  673. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  674. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  675. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  676. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  677. }
  678. void GetPsuInformation(char *v1, char *v2, char *v3)
  679. {
  680. printf("**********************AC Contact needed*************************\n");
  681. if(strcmp(v1, "count") == 0)
  682. {
  683. for (int i = 0; i < 4; i++)
  684. {
  685. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  686. }
  687. }
  688. else if(strcmp(v1, "ver") == 0)
  689. {
  690. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  691. {
  692. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  693. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  694. }
  695. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  696. {
  697. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  698. {
  699. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  700. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  701. }
  702. }
  703. }
  704. else if(strcmp(v1, "cap") == 0)
  705. {
  706. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  707. {
  708. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  709. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  710. }
  711. }
  712. else if(strcmp(v1, "input") == 0)
  713. {
  714. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  715. {
  716. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  717. {
  718. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  719. i, count,
  720. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  721. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  722. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  723. }
  724. }
  725. }
  726. else if (strcmp(v1, "output") == 0)
  727. {
  728. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  729. {
  730. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  731. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  732. }
  733. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
  734. {
  735. if (!FindChargingInfoData(i, &_chargingData[0]))
  736. {
  737. printf ("FindChargingInfoData error\n");
  738. continue;
  739. }
  740. printf("From RB : Group Index = %d, OutputV = %f \n",
  741. i, _chargingData[i]->FireChargingVoltage);
  742. }
  743. }
  744. else if (strcmp(v1, "test") == 0)
  745. {
  746. int mode = atoi(v2);
  747. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  748. {
  749. ShmPsuData->Work_Step = mode;
  750. }
  751. }
  752. else if (strcmp(v1, "out") == 0)
  753. {
  754. float vol = atof(v2);
  755. float cur = atof(v3);
  756. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  757. {
  758. if (!FindChargingInfoData(0, &_chargingData[0]))
  759. {
  760. printf ("FindChargingInfoData error\n");
  761. return;
  762. }
  763. _chargingData[0]->EvBatterytargetVoltage = vol;
  764. _chargingData[0]->EvBatterytargetCurrent = cur;
  765. }
  766. }
  767. printf("*************************************************\n");
  768. }
  769. void GetConnectorCapInfo(char *v1)
  770. {
  771. int _GunIndex = atoi(v1);
  772. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  773. {
  774. printf ("FindChargingInfoData error\n");
  775. return;
  776. }
  777. printf ("Charger Max Current = %d, Max Power = %d \n",
  778. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  779. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  780. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  781. _GunIndex,
  782. _chargingData[_GunIndex]->RealMaxPower,
  783. _chargingData[_GunIndex]->RealMaxVoltage,
  784. _chargingData[_GunIndex]->RealMaxCurrent);
  785. }
  786. static void get_char(char *word)
  787. {
  788. fd_set rfds;
  789. struct timeval tv;
  790. FD_ZERO(&rfds);
  791. FD_SET(0, &rfds);
  792. tv.tv_sec = 0;
  793. tv.tv_usec = 10; //wait input timout time
  794. //if input
  795. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  796. {
  797. fgets(word, 128, stdin);
  798. }
  799. }
  800. void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
  801. {
  802. float _Voltage[2];
  803. float _Current[2];
  804. _Voltage[0] = atof(g1_vol);
  805. _Current[0] = atof(g1_cur);
  806. _Voltage[1] = atof(g2_vol);
  807. _Current[1] = atof(g2_cur);
  808. printf ("g1_vol = %f, g1_cur = %f pow1 = %f (KW) \n", _Voltage[0], _Current[0], (_Voltage[0] * _Current[0]) / 1000);
  809. printf ("g2_vol = %f, g2_cur = %f pow2 = %f (KW) \n", _Voltage[1], _Current[1], (_Voltage[1] * _Current[1]) / 1000);
  810. if(_Voltage[0] > 1000 || _Voltage[0] < 50 ||
  811. _Voltage[1] > 1000 || _Voltage[1] < 50)
  812. {
  813. printf ("Input Voltage over range\n");
  814. return;
  815. }
  816. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
  817. {
  818. if (!FindChargingInfoData(_index, &_chargingData[0]))
  819. {
  820. printf("AverageCharging : FindChargingInfoData false \n");
  821. return;
  822. }
  823. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  824. _chargingData[_index]->Type = 9;
  825. }
  826. sleep(1);
  827. system("killall Module_EvComm");
  828. unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
  829. bool isComplete[2] = {false, false};
  830. while(1)
  831. {
  832. for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
  833. {
  834. switch(_chargingData[gun_index]->SystemStatus)
  835. {
  836. case SYS_MODE_IDLE:
  837. {
  838. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  839. {
  840. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  841. printf ("[AverageCharging (%d) - SYS_MODE_IDLE] \n", gun_index);
  842. }
  843. _chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARING;
  844. }
  845. break;
  846. case SYS_MODE_PREPARING:
  847. {
  848. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  849. {
  850. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  851. printf ("[AverageCharging (%d) - S_PREPARNIN] \n", gun_index);
  852. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  853. printf ("wait find module\n");
  854. }
  855. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  856. //清除 main timeout 機制
  857. _chargingData[gun_index]->TimeoutFlag = 0;
  858. }
  859. break;
  860. case SYS_MODE_PREPARE_FOR_EV:
  861. {
  862. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  863. {
  864. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  865. printf ("[AverageCharging (%d) - SYS_MODE_PREPARE_FOR_EV] \n", gun_index);
  866. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[gun_index] * 10, _Current[gun_index] * 10);
  867. }
  868. //清除 main timeout 機制
  869. _chargingData[gun_index]->TimeoutFlag = 0;
  870. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  871. _chargingData[gun_index]->Type = 9;
  872. //充電電壓電流
  873. _chargingData[gun_index]->EvBatterySoc = 50;
  874. _chargingData[gun_index]->EvBatterytargetVoltage = 500;
  875. _chargingData[gun_index]->EvBatterytargetCurrent = 2;
  876. _chargingData[gun_index]->AvailableChargingCurrent = 1000;
  877. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  878. //確定模組己升壓完成
  879. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  880. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  881. {
  882. printf ("Preparing Done = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
  883. //EV done
  884. _chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
  885. }
  886. }
  887. break;
  888. case SYS_MODE_PREPARE_FOR_EVSE:
  889. {
  890. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  891. {
  892. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  893. printf ("[AverageCharging (%d) - SYS_MODE_PREPARE_FOR_EVSE]\n", gun_index);
  894. }
  895. //printf ("tar vol = %d \n", _Voltage);
  896. //printf ("tar cur = %d \n", _Current);
  897. //清除 main timeout 機制
  898. _chargingData[gun_index]->TimeoutFlag = 0;
  899. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  900. _chargingData[gun_index]->Type = 9;
  901. //充電電壓電流
  902. _chargingData[gun_index]->EvBatterySoc = 50;
  903. _chargingData[gun_index]->EvBatterytargetVoltage = 500;
  904. _chargingData[gun_index]->EvBatterytargetCurrent = 2;
  905. _chargingData[gun_index]->AvailableChargingCurrent = 1000;
  906. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  907. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  908. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  909. //確定模組己升壓完成
  910. if(_chargingData[gun_index]->GroundFaultStatus == 0x01 ||
  911. _chargingData[gun_index]->GroundFaultStatus == 0x03)
  912. {
  913. printf ("First Ground Fault State (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
  914. printf ("Wait K1K2 = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
  915. sleep(5);
  916. //EV done
  917. _chargingData[gun_index]->SystemStatus = SYS_MODE_CHARGING;
  918. }
  919. else if (_chargingData[gun_index]->GroundFaultStatus > 0x02)
  920. {
  921. printf ("First Ground Fault check Fail (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
  922. _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
  923. }
  924. }
  925. break;
  926. case SYS_MODE_CHARGING:
  927. {
  928. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  929. {
  930. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  931. //充電電壓電流
  932. _chargingData[gun_index]->EvBatterytargetVoltage = _Voltage[gun_index];
  933. _chargingData[gun_index]->EvBatterytargetCurrent = _Current[gun_index];
  934. _chargingData[gun_index]->EvBatterySoc = 50;
  935. _chargingData[gun_index]->AvailableChargingCurrent = 1000;
  936. printf ("[AverageCharging (%d) - SYS_MODE_CHARGING]\n", gun_index);
  937. }
  938. //ev task do this
  939. _chargingData[gun_index]->PresentChargingPower =
  940. ((float)((_chargingData[gun_index]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  941. if (_chargingData[gun_index]->GroundFaultStatus == 0x02)
  942. {
  943. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
  944. _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
  945. }
  946. }
  947. break;
  948. case SYS_MODE_TERMINATING:
  949. {
  950. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  951. {
  952. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  953. printf ("[AverageCharging (%d) - SYS_MODE_TERMINATING] \n", gun_index);
  954. //無阻塞偵測 keybaord 結束
  955. system(STTY_DEF TTY_PATH);
  956. }
  957. sleep(3);
  958. _chargingData[gun_index]->SystemStatus = SYS_MODE_COMPLETE;
  959. }
  960. break;
  961. case SYS_MODE_COMPLETE:
  962. {
  963. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  964. {
  965. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  966. printf ("[AverageCharging (%d) - SYS_MODE_COMPLETE] \n", gun_index);
  967. }
  968. _chargingData[gun_index]->PresentChargingPower = 0;
  969. isComplete[gun_index] = true;
  970. sleep(3);
  971. }
  972. break;
  973. }
  974. }
  975. if (isComplete[0] == true && isComplete[1] == true)
  976. return;
  977. char word[128];
  978. char newString[7][10];
  979. int i,j,ctr;
  980. memset(word, 0x00, sizeof(word));
  981. get_char(word);
  982. if (strlen(word) == 0)
  983. continue;
  984. j=0; ctr=0;
  985. strcpy(newString[1], "-1");
  986. strcpy(newString[2], "-1");
  987. for (i = 0; i <= (strlen(word)); i++)
  988. {
  989. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  990. {
  991. newString[ctr][j] = '\0';
  992. ctr++;
  993. j = 0;
  994. }
  995. else
  996. {
  997. newString[ctr][j] = word[i];
  998. j++;
  999. }
  1000. }
  1001. if (strcmp(newString[0], "c") == 0)
  1002. {
  1003. for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
  1004. {
  1005. ShmDcCommonData->StartToChargingFlag[gun_index] = 0x00;
  1006. _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
  1007. }
  1008. printf("stop \n\r");
  1009. }
  1010. usleep(100000);
  1011. }
  1012. }
  1013. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  1014. {
  1015. int _GunIndex;
  1016. float _Voltage;
  1017. float _Current;
  1018. if (strcmp(v1, "auto") == EQUAL)
  1019. {
  1020. _usingAutoRun = 0x01;
  1021. _GunIndex = atoi(v2);
  1022. _Voltage = 500;
  1023. _Current = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 1000) / _Voltage;
  1024. }
  1025. else
  1026. {
  1027. _usingAutoRun = 0x00;
  1028. _GunIndex = atoi(v1);
  1029. _Voltage = atof(v2);
  1030. _Current = atof(v3);
  1031. }
  1032. unsigned char PreviousSystemStatus = 0xff;
  1033. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  1034. {
  1035. printf ("FindChargingInfoData error\n");
  1036. return;
  1037. }
  1038. printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  1039. ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
  1040. if(_Voltage > 1000 || _Voltage < 50)
  1041. {
  1042. printf ("Input Voltage over range\n");
  1043. return;
  1044. }
  1045. // if(_Current > 100 || _Current < 2){
  1046. //
  1047. // printf ("Input Current over range\n");
  1048. // return;
  1049. // }
  1050. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  1051. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  1052. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  1053. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1054. sleep(1);
  1055. //kill ev task
  1056. system("killall Module_EvComm");
  1057. //_Voltage = (_Voltage * 10);
  1058. //_Current = (_Current * 10);
  1059. //system(STTY_US TTY_PATH);
  1060. while(true)
  1061. {
  1062. //fix gun 1
  1063. switch(_chargingData[_GunIndex]->SystemStatus)
  1064. {
  1065. case SYS_MODE_IDLE:
  1066. {
  1067. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1068. {
  1069. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1070. printf ("[UnconditionalCharge - SYS_MODE_IDLE]\n");
  1071. }
  1072. ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x01;
  1073. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARING;
  1074. }
  1075. break;
  1076. case SYS_MODE_PREPARING:
  1077. {
  1078. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1079. {
  1080. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1081. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  1082. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1083. printf ("wait find module\n");
  1084. }
  1085. //main 會在此階段判斷以下資料跳到下一個 state
  1086. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  1087. //ShmPsuData->SystemPresentPsuQuantity;
  1088. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  1089. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  1090. //_chargingData[gun_index]->AvailableChargingPower;
  1091. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1092. //sleep(10);
  1093. //清除 main timeout 機制
  1094. _chargingData[_GunIndex]->TimeoutFlag = 0;
  1095. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1096. _chargingData[_GunIndex]->Type = 9;
  1097. }
  1098. break;
  1099. case SYS_MODE_PREPARE_FOR_EV:
  1100. {
  1101. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1102. {
  1103. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1104. printf ("[UnconditionalCharge - SYS_MODE_PREPARE_FOR_EV]\n");
  1105. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  1106. }
  1107. //清除 main timeout 機制
  1108. _chargingData[_GunIndex]->TimeoutFlag = 0;
  1109. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1110. _chargingData[_GunIndex]->Type = 9;
  1111. //充電電壓電流
  1112. _chargingData[_GunIndex]->EvBatterySoc = 50;
  1113. _chargingData[_GunIndex]->EvBatterytargetVoltage = 500;
  1114. _chargingData[_GunIndex]->EvBatterytargetCurrent = 2;
  1115. _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
  1116. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1117. //確定模組己升壓完成
  1118. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  1119. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  1120. {
  1121. printf ("Precharge Done = %f \n", _chargingData[_GunIndex]->PresentChargingVoltage);
  1122. //EV done
  1123. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
  1124. }
  1125. }
  1126. break;
  1127. case SYS_MODE_PREPARE_FOR_EVSE:
  1128. {
  1129. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1130. {
  1131. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1132. printf ("[UnconditionalCharge - SYS_MODE_PREPARE_FOR_EVSE]\n");
  1133. }
  1134. //printf ("tar vol = %d \n", _Voltage);
  1135. //printf ("tar cur = %d \n", _Current);
  1136. //清除 main timeout 機制
  1137. _chargingData[_GunIndex]->TimeoutFlag = 0;
  1138. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1139. _chargingData[_GunIndex]->Type = 9;
  1140. //充電電壓電流
  1141. _chargingData[_GunIndex]->EvBatterySoc = 50;
  1142. _chargingData[_GunIndex]->EvBatterytargetVoltage = 500;
  1143. _chargingData[_GunIndex]->EvBatterytargetCurrent = 2;
  1144. _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
  1145. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  1146. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  1147. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1148. //確定模組己升壓完成
  1149. if(_chargingData[_GunIndex]->GroundFaultStatus == 0x01 ||
  1150. _chargingData[_GunIndex]->GroundFaultStatus == 0x03)
  1151. {
  1152. printf ("First Ground Fault State (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
  1153. printf ("Wait K1K2 = %f \n", _chargingData[_GunIndex]->PresentChargingVoltage);
  1154. sleep(5);
  1155. //EV done
  1156. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_CHARGING;
  1157. }
  1158. else if (_chargingData[_GunIndex]->GroundFaultStatus > 0x02)
  1159. {
  1160. printf ("First Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
  1161. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
  1162. }
  1163. }
  1164. break;
  1165. case SYS_MODE_CHARGING:
  1166. {
  1167. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1168. {
  1169. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1170. if (_usingAutoRun == 0x00)
  1171. {
  1172. //充電電壓電流
  1173. _chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
  1174. _chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
  1175. }
  1176. else
  1177. {
  1178. _curAutoRunCount = 0;
  1179. gettimeofday(&_autoTime, NULL);
  1180. }
  1181. _chargingData[_GunIndex]->EvBatterySoc = 50;
  1182. _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
  1183. printf ("[UnconditionalCharge - SYS_MODE_CHARGING]\n");
  1184. }
  1185. if (_usingAutoRun == 0x01)
  1186. {
  1187. if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
  1188. ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60))
  1189. {
  1190. _chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
  1191. _chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
  1192. }
  1193. else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60)
  1194. {
  1195. _curAutoRunCount++;
  1196. if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT)
  1197. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
  1198. else
  1199. gettimeofday(&_autoTime, NULL);
  1200. }
  1201. else
  1202. {
  1203. _chargingData[_GunIndex]->EvBatterytargetVoltage = 0;
  1204. _chargingData[_GunIndex]->EvBatterytargetCurrent = 0;
  1205. }
  1206. }
  1207. // printf("out : vol = %f, cur = %f \n",
  1208. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
  1209. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  1210. //ev task do this
  1211. _chargingData[_GunIndex]->PresentChargingPower =
  1212. ((float)((_chargingData[_GunIndex]->PresentChargingVoltage) * (_chargingData[_GunIndex]->PresentChargingCurrent)) / 1000);
  1213. if (_chargingData[_GunIndex]->GroundFaultStatus == 0x02){
  1214. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
  1215. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
  1216. }
  1217. }
  1218. break;
  1219. case SYS_MODE_TERMINATING:
  1220. {
  1221. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1222. {
  1223. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1224. system("/root/Module_EvComm &");
  1225. printf ("[UnconditionalCharge - SYS_MODE_TERMINATING]\n");
  1226. //無阻塞偵測 keybaord 結束
  1227. system(STTY_DEF TTY_PATH);
  1228. }
  1229. sleep(3);
  1230. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_COMPLETE;
  1231. return;
  1232. }
  1233. break;
  1234. case SYS_MODE_COMPLETE:
  1235. {
  1236. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1237. {
  1238. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1239. printf ("[UnconditionalCharge - SYS_MODE_COMPLETE]\n");
  1240. }
  1241. _chargingData[_GunIndex]->PresentChargingPower = 0;
  1242. sleep(3);
  1243. return;
  1244. }
  1245. break;
  1246. }
  1247. char word[128];
  1248. char newString[7][10];
  1249. int i,j,ctr;
  1250. memset(word, 0x00, sizeof(word));
  1251. get_char(word);
  1252. if (strlen(word) == 0)
  1253. continue;
  1254. j=0; ctr=0;
  1255. strcpy(newString[1], "-1");
  1256. strcpy(newString[2], "-1");
  1257. for (i = 0; i <= (strlen(word)); i++)
  1258. {
  1259. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1260. {
  1261. newString[ctr][j] = '\0';
  1262. ctr++;
  1263. j = 0;
  1264. }
  1265. else
  1266. {
  1267. newString[ctr][j] = word[i];
  1268. j++;
  1269. }
  1270. }
  1271. if(strcmp(newString[0], "chg") == 0)
  1272. {
  1273. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1274. continue;
  1275. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1276. continue;
  1277. float _vol = atof(newString[1]);
  1278. float _cur = atof(newString[2]);
  1279. if (_cur <= 0 || _cur <= 0)
  1280. continue;
  1281. printf("vol = %f, cur = %f \n", _vol, _cur);
  1282. _chargingData[_GunIndex]->EvBatterytargetVoltage = _vol;
  1283. _chargingData[_GunIndex]->EvBatterytargetCurrent = _cur;
  1284. }
  1285. else if (strcmp(newString[0], "c") == 0)
  1286. {
  1287. printf("stop \n\r");
  1288. ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x00;
  1289. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
  1290. }
  1291. usleep(100000);
  1292. }
  1293. }
  1294. int main(void)
  1295. {
  1296. if(InitShareMemory() == FAIL)
  1297. {
  1298. printf ("InitShareMemory = FAIL \n");
  1299. if(ShmStatusCodeData != NULL)
  1300. {
  1301. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1302. }
  1303. sleep(5);
  1304. return 0;
  1305. }
  1306. for(;;)
  1307. {
  1308. char word[128];
  1309. char newString[7][10];
  1310. int i,j,ctr;
  1311. fgets(word, sizeof(word), stdin);
  1312. j=0; ctr=0;
  1313. strcpy(newString[1], "-1");
  1314. strcpy(newString[2], "-1");
  1315. for (i = 0; i <= (strlen(word)); i++)
  1316. {
  1317. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1318. {
  1319. newString[ctr][j] = '\0';
  1320. ctr++;
  1321. j = 0;
  1322. }
  1323. else
  1324. {
  1325. newString[ctr][j] = word[i];
  1326. j++;
  1327. }
  1328. }
  1329. if(strcmp(newString[0], "state") == 0 || strcmp(newString[0], "st") == 0)
  1330. {
  1331. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1332. continue;
  1333. // 槍狀態
  1334. printf("=========================== \n");
  1335. RunStatusProc(newString[1], newString[2]);
  1336. printf("=========================== \n");
  1337. }
  1338. else if(strcmp(newString[0], "card") == 0)
  1339. {
  1340. // 刷卡狀態
  1341. RunCardProc(newString[1], newString[2]);
  1342. }
  1343. else if(strcmp(newString[0], "gun") == 0)
  1344. {
  1345. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1346. continue;
  1347. // 插槍狀態
  1348. RunGunPlugitProc(newString[1], newString[2]);
  1349. }
  1350. else if(strcmp(newString[0], "lock") == 0)
  1351. {
  1352. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1353. continue;
  1354. // 插槍狀態
  1355. GetGunLockStatusProc(newString[1], newString[2]);
  1356. }
  1357. else if(strcmp(newString[0], "sysid") == 0)
  1358. {
  1359. // 測試 sys id
  1360. SetSystemIDProc();
  1361. }
  1362. else if(strcmp(newString[0], "self") == 0)
  1363. {
  1364. // CSU 自我檢測狀態
  1365. RunSelfProc(newString[1]);
  1366. }
  1367. else if(strcmp(newString[0], "ver") == 0)
  1368. {
  1369. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1370. continue;
  1371. // 取 FW 版號
  1372. GetFwVerProc(newString[1]);
  1373. }
  1374. else if (strcmp(newString[0], "update") == 0)
  1375. {
  1376. // 更新
  1377. FwUpdateFlagProc(newString[1]);
  1378. }
  1379. else if (strcmp(newString[0], "ac") == 0)
  1380. {
  1381. // AC contactor 狀態
  1382. CheckAcStatus(newString[1]);
  1383. }
  1384. else if (strcmp(newString[0], "cable") == 0)
  1385. {
  1386. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1387. continue;
  1388. // cable check pass
  1389. SetCableChkStatus(newString[1], newString[2]);
  1390. }
  1391. else if (strcmp(newString[0], "pow") == 0)
  1392. {
  1393. // get output power
  1394. GetPowerValue();
  1395. }
  1396. else if (strcmp(newString[0], "model") == 0)
  1397. {
  1398. GetSystemInfo();
  1399. }
  1400. else if(strcmp(newString[0], "select") == 0)
  1401. {
  1402. // 取得 / 設定 當前選的槍號
  1403. GetGunSelectedNum(newString[1]);
  1404. }
  1405. else if(strcmp(newString[0], "change") == 0)
  1406. {
  1407. // 模擬按鈕改變選槍
  1408. ChangeGunNum();
  1409. }
  1410. else if(strcmp(newString[0], "fan") == 0)
  1411. {
  1412. // 設定風扇速度
  1413. SetFanSpeed(newString[1]);
  1414. }
  1415. else if(strcmp(newString[0], "show") == 0)
  1416. {
  1417. ShowSysInformation();
  1418. }
  1419. else if(strcmp(newString[0], "speed") == 0)
  1420. {
  1421. // 取得風扇速度
  1422. GetFanSpeed();
  1423. }
  1424. else if(strcmp(newString[0], "debug") == 0)
  1425. {
  1426. // 設定 debug mode
  1427. SetDebugMode(newString[1]);
  1428. }
  1429. else if (strcmp(newString[0], "gfd") == 0)
  1430. {
  1431. // 設定盲沖使用 GFD 功能
  1432. SetGFDMode(newString[1]);
  1433. }
  1434. else if(strcmp(newString[0], "temp") == 0)
  1435. {
  1436. // 取得 PSU 溫度
  1437. GetPsuTemp();
  1438. }
  1439. else if(strcmp(newString[0], "acin") == 0)
  1440. {
  1441. // 取得三向輸入電壓
  1442. GetAcInputVol();
  1443. }
  1444. else if(strcmp(newString[0], "psu") == 0)
  1445. {
  1446. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1447. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1448. {
  1449. printf ("PSU : Param fail..Please retry again......\n");
  1450. continue;
  1451. }
  1452. // 取得 PSU 資訊
  1453. GetPsuInformation(newString[1], newString[2], newString[3]);
  1454. }
  1455. else if (strcmp(newString[0], "cap") == 0)
  1456. {
  1457. GetConnectorCapInfo(newString[1]);
  1458. }
  1459. else if(strcmp(newString[0], "error") == 0)
  1460. {
  1461. CreateOneError();
  1462. }
  1463. else if (strcmp(newString[0], "auth") == 0)
  1464. {
  1465. GetAuthorizeFlag(newString[1]);
  1466. }
  1467. else if (strcmp(newString[0], "relay") == 0)
  1468. {
  1469. GetRelayStatus(newString[1]);
  1470. }
  1471. else if (strcmp(newString[0], "ccid") == 0)
  1472. {
  1473. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1474. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1475. {
  1476. printf ("Input ccid fail.\n");
  1477. continue;
  1478. }
  1479. SetChargingInfoCCID(newString[1], newString[2]);
  1480. }
  1481. else if (strcmp(newString[0], "guntemp") == 0)
  1482. {
  1483. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1484. {
  1485. printf ("Input guntemp fail.\n");
  1486. continue;
  1487. }
  1488. GetGunTemp(newString[1]);
  1489. }
  1490. else if (strcmp(newString[0], "offer") == 0)
  1491. {
  1492. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1493. {
  1494. printf ("offer fail.\n");
  1495. continue;
  1496. }
  1497. GetOffered(newString[1]);
  1498. }
  1499. else if (strcmp(newString[0], "evstate") == 0)
  1500. {
  1501. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1502. {
  1503. printf ("evstate fail.\n");
  1504. continue;
  1505. }
  1506. GetEvStatus(newString[1]);
  1507. }
  1508. else if (strcmp(newString[0], "meter") == 0)
  1509. {
  1510. // DC meter infor
  1511. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1512. {
  1513. printf ("meter cmd fail.\n");
  1514. continue;
  1515. }
  1516. GetDcMeterInfor(newString[1]);
  1517. }
  1518. else if (strcmp(newString[0], "soc") == 0)
  1519. {
  1520. GetSOC(newString[1]);
  1521. }
  1522. else if (strcmp(newString[0], "run") == 0)
  1523. {
  1524. if (ShmDcCommonData->_isAutoRunTest == YES)
  1525. ShmDcCommonData->_isAutoRunTest = NO;
  1526. else
  1527. ShmDcCommonData->_isAutoRunTest = YES;
  1528. printf ("_isAutoRunTest = %d \n", ShmDcCommonData->_isAutoRunTest);
  1529. }
  1530. else if (strcmp(newString[0], "test") == 0)
  1531. {
  1532. // Test Command
  1533. printf ("mode = %d \n", ShmSysConfigAndInfo->SysInfo.MainChargingMode);
  1534. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  1535. printf ("mode = %d \n", ShmSysConfigAndInfo->SysInfo.MainChargingMode);
  1536. }
  1537. else if(strcmp(newString[0], "strchg") == 0)
  1538. {
  1539. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1540. if (strcmp(newString[1], "auto") == 0)
  1541. {
  1542. newString[3][0] = 0;
  1543. }
  1544. else if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1545. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1546. {
  1547. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1548. continue;
  1549. }
  1550. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1551. }
  1552. else if(strcmp(newString[0], "avechg") == 0)
  1553. {
  1554. // 雙槍同時忙充輸出
  1555. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1556. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  1557. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
  1558. strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
  1559. {
  1560. printf ("Input cmd fail ------ avechg\n");
  1561. continue;
  1562. }
  1563. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount < 2 ||
  1564. ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == 1)
  1565. {
  1566. printf ("Sorry, This is single gun system. \n");
  1567. continue;
  1568. }
  1569. AverageCharging(newString[1], newString[2], newString[3], newString[4]);
  1570. }
  1571. else
  1572. printf ("%s\n", msg);
  1573. usleep(100000);
  1574. }
  1575. return 0;
  1576. }