ReadCmdline.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  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 AUTORUN_STEP1_TIME_START 140 // Minutes
  45. #define AUTORUN_STEP1_TIME_END 150
  46. #define AUTORUN_STEP2_TIME_START 210
  47. #define AUTORUN_STEP2_TIME_END 410
  48. #define AUTORUN_END_TIME 480
  49. #define AUTORUN_CYCLE_COUNT 30
  50. #define TTY_PATH "/dev/tty"
  51. #define STTY_US "stty raw -echo -F "
  52. #define STTY_DEF "stty -raw echo -F "
  53. byte _curAutoRunCount = 0;
  54. byte _usingAutoRun = 0;
  55. struct timeval _autoTime;
  56. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  57. struct StatusCodeData *ShmStatusCodeData;
  58. struct PrimaryMcuData *ShmPrimaryMcuData;
  59. struct CHAdeMOData *ShmCHAdeMOData;
  60. struct CcsData *ShmCcsData;
  61. struct GBTData *ShmGBTData;
  62. struct FanModuleData *ShmFanModuleData;
  63. struct RelayModuleData *ShmRelayModuleData;
  64. struct LedModuleData *ShmLedModuleData;
  65. struct PsuData *ShmPsuData;
  66. struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  67. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  68. char *msg = "state : get gun state (index) \n"
  69. "card : scanning card (x) : \n"
  70. "gun : get gun plugit state (index) \n"
  71. "lock : get gun locked state (index) \n"
  72. "self : self test state (x) \n"
  73. "ver : ver of board (407 or index or rb or fan) \n"
  74. "ac : get ac relay state (x) \n";
  75. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  76. {
  77. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  78. {
  79. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  80. {
  81. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  82. return true;
  83. }
  84. }
  85. for (byte index = 0; index < CCS_QUANTITY; index++)
  86. {
  87. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  88. {
  89. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  90. return true;
  91. }
  92. }
  93. for (byte index = 0; index < GB_QUANTITY; index++)
  94. {
  95. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  96. {
  97. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  98. return true;
  99. }
  100. }
  101. return false;
  102. }
  103. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  104. {
  105. if (target < AC_QUANTITY)
  106. {
  107. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  108. return true;
  109. }
  110. return false;
  111. }
  112. int InitShareMemory()
  113. {
  114. int result = PASS;
  115. int MeterSMId;
  116. //initial ShmSysConfigAndInfo
  117. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  118. {
  119. result = FAIL;
  120. }
  121. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  122. {
  123. result = FAIL;
  124. }
  125. else
  126. {}
  127. //initial ShmStatusCodeData
  128. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  129. {
  130. result = FAIL;
  131. }
  132. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  133. {
  134. result = FAIL;
  135. }
  136. else
  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. memset(ShmGBTData, 0, sizeof(struct GBTData));
  165. }
  166. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  167. {
  168. result = FAIL;
  169. }
  170. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  171. {
  172. result = FAIL;
  173. }
  174. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  175. {
  176. result = FAIL;
  177. }
  178. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  179. {
  180. result = FAIL;
  181. }
  182. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  183. {
  184. result = FAIL;
  185. }
  186. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  187. {
  188. result = FAIL;
  189. }
  190. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  191. {
  192. result = FAIL;
  193. }
  194. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  195. {
  196. result = FAIL;
  197. }
  198. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  199. {
  200. result = FAIL;
  201. }
  202. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  203. {
  204. result = FAIL;
  205. }
  206. return result;
  207. }
  208. unsigned long GetTimeoutValue(struct timeval _sour_time)
  209. {
  210. struct timeval _end_time;
  211. gettimeofday(&_end_time, NULL);
  212. return (_end_time.tv_sec - _sour_time.tv_sec);
  213. }
  214. void RunStatusProc(char *v1, char *v2)
  215. {
  216. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  217. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  218. if (strcmp(v1, "ac") == 0)
  219. {
  220. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  221. {
  222. printf("FindChargingInfoData (AC) false \n");
  223. }
  224. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  225. return;
  226. }
  227. int _index = atoi(v1);
  228. if (_index <= 1)
  229. {
  230. if (!FindChargingInfoData(_index, &_chargingData[0]))
  231. {
  232. printf ("FindChargingInfoData error\n");
  233. return;
  234. }
  235. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  236. {
  237. // get
  238. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  239. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  240. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  241. }
  242. else
  243. {
  244. // set
  245. _chargingData[_index]->SystemStatus = atoi(v2);
  246. }
  247. }
  248. else
  249. {
  250. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  251. {
  252. printf("FindChargingInfoData (AC) false \n");
  253. }
  254. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  255. {
  256. // get
  257. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  258. }
  259. else
  260. {
  261. // set
  262. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  263. }
  264. }
  265. }
  266. void RunCardProc(char *v1, char *v2)
  267. {
  268. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  269. {
  270. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  271. {
  272. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  273. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  274. }
  275. else
  276. {
  277. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  278. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  279. }
  280. }
  281. else
  282. {
  283. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  284. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  285. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  286. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  287. }
  288. }
  289. void RunGunPlugitProc(char *v1, char *v2)
  290. {
  291. if (strcmp(v1, "ac") == 0)
  292. {
  293. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  294. {
  295. printf("FindChargingInfoData (AC) false \n");
  296. }
  297. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  298. {
  299. // get
  300. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  301. }
  302. else
  303. {
  304. // set
  305. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  306. }
  307. return;
  308. }
  309. int _index = atoi(v1);
  310. if (!FindChargingInfoData(_index, &_chargingData[0]))
  311. {
  312. printf("FindChargingInfoData error\n");
  313. return;
  314. }
  315. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  316. {
  317. // get
  318. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  319. }
  320. else
  321. {
  322. // set
  323. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  324. }
  325. }
  326. void GetGunLockStatusProc(char *v1, char *v2)
  327. {
  328. int _index = atoi(v1);
  329. if (!FindChargingInfoData(_index, &_chargingData[0]))
  330. {
  331. printf("FindChargingInfoData error\n");
  332. return;
  333. }
  334. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  335. {
  336. _chargingData[_index]->GunLocked = atoi(v2);
  337. }
  338. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  339. }
  340. void SetSystemIDProc()
  341. {
  342. char *systemId = "Alston_Test";
  343. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  344. }
  345. void RunSelfProc()
  346. {
  347. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  348. }
  349. void GetFwVerProc(char *v1)
  350. {
  351. if (strcmp(v1, "407") == 0)
  352. {
  353. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  354. }
  355. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0)
  356. {
  357. int _index = atoi(v1);
  358. if (_index == 0)
  359. printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
  360. else if (_index == 1)
  361. printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
  362. }
  363. else if (strcmp(v1, "rb") == 0)
  364. {
  365. printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  366. }
  367. else if (strcmp(v1, "fan") == 0)
  368. {
  369. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  370. }
  371. else if (strcmp(v1, "dc") == 0)
  372. {
  373. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  374. }
  375. else if (strcmp(v1, "led") == 0)
  376. {
  377. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  378. }
  379. else if (strcmp(v1, "ac") == 0)
  380. {
  381. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  382. {
  383. printf("FindChargingInfoData (AC) false \n");
  384. }
  385. printf("AC Version = %s \n", ac_chargingInfo[0]->version);
  386. }
  387. }
  388. void CreateOneError(char *v1)
  389. {
  390. int value = atoi(v1);
  391. ShmPrimaryMcuData->InputDet.bits.EmergencyButton = value;
  392. //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = value;
  393. //ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  394. }
  395. void GetAuthorizeFlag(char *v1)
  396. {
  397. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  398. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  399. else
  400. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  401. }
  402. void GetRelayStatus(char *v1)
  403. {
  404. int _index = atoi(v1);
  405. if (!FindChargingInfoData(_index, &_chargingData[0]))
  406. {
  407. printf("FindChargingInfoData error\n");
  408. return;
  409. }
  410. printf("RelayK1K2Status = %d \n", _chargingData[_index]->RelayK1K2Status);
  411. printf("RelayKPK2Status = %d \n", _chargingData[_index]->RelayKPK2Status);
  412. }
  413. void FwUpdateFlagProc()
  414. {
  415. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  416. }
  417. void CheckAcStatus(char *v1)
  418. {
  419. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  420. {
  421. printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  422. }
  423. }
  424. void SetCableChkStatus(char *v1, char *v2)
  425. {
  426. int _index = atoi(v1);
  427. if (!FindChargingInfoData(_index, &_chargingData[0]))
  428. {
  429. printf ("FindChargingInfoData error\n");
  430. return;
  431. }
  432. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  433. }
  434. void SetChargingInfoCCID(char *v1, char* v2)
  435. {
  436. int _index = atoi(v1);
  437. if (!FindChargingInfoData(_index, &_chargingData[0]))
  438. {
  439. printf ("FindChargingInfoData error\n");
  440. return;
  441. }
  442. memcpy(_chargingData[_index]->EVCCID, v2, 8);
  443. _chargingData[_index]->EVCCID[8] = '\0';
  444. }
  445. void GetPowerValue()
  446. {
  447. for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
  448. {
  449. if (!FindChargingInfoData(index, &_chargingData[0]))
  450. {
  451. printf ("FindChargingInfoData error\n");
  452. return;
  453. }
  454. printf ("index = %d, PresentChargingPower = %f \n", index, _chargingData[index]->PresentChargingPower);
  455. }
  456. }
  457. void GetSystemInfo()
  458. {
  459. printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  460. printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  461. printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
  462. printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  463. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  464. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  465. }
  466. void ChangeGunNum()
  467. {
  468. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  469. {
  470. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  471. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  472. }
  473. else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  474. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
  475. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  476. else
  477. {
  478. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  479. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  480. }
  481. }
  482. void GetGunSelectedNum(char *v1)
  483. {
  484. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  485. {
  486. if (AC_QUANTITY > 0 &&
  487. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
  488. {
  489. printf("connector select changed = AC \n");
  490. }
  491. else
  492. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  493. }
  494. else
  495. {
  496. int _index = atoi(v1);
  497. if (_index <= 1)
  498. {
  499. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  500. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  501. printf("connector select changed = %d \n", _index);
  502. }
  503. else if (AC_QUANTITY > 0)
  504. {
  505. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  506. printf("connector select changed = AC \n");
  507. }
  508. }
  509. }
  510. void SetFanSpeed(char *v1)
  511. {
  512. int speed = atoi(v1);
  513. ShmFanModuleData->TestFanSpeed = speed;
  514. }
  515. void GetFanSpeed()
  516. {
  517. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  518. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  519. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  520. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  521. }
  522. void SetDebugMode(char *v1)
  523. {
  524. int mode = atoi(v1);
  525. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  526. }
  527. void SetGFDMode(char *v1)
  528. {
  529. int mode = atoi(v1);
  530. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  531. }
  532. void GetPsuTemp()
  533. {
  534. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  535. {
  536. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  537. {
  538. printf("D.D. Temp = %d ------ Env Temp = %d \n",
  539. ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp,
  540. ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1);
  541. }
  542. }
  543. }
  544. void GetAcInputVol()
  545. {
  546. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  547. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  548. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  549. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  550. }
  551. void GetPsuInformation(char *v1, char *v2, char *v3)
  552. {
  553. printf("**********************AC Contact needed*************************\n");
  554. if(strcmp(v1, "count") == 0)
  555. {
  556. for (int i = 0; i < 4; i++)
  557. {
  558. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  559. }
  560. }
  561. else if(strcmp(v1, "ver") == 0)
  562. {
  563. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  564. {
  565. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  566. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  567. }
  568. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  569. {
  570. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  571. {
  572. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  573. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  574. }
  575. }
  576. }
  577. else if(strcmp(v1, "cap") == 0)
  578. {
  579. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  580. {
  581. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  582. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  583. }
  584. }
  585. else if(strcmp(v1, "input") == 0)
  586. {
  587. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  588. {
  589. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  590. {
  591. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  592. i, count,
  593. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  594. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  595. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  596. }
  597. }
  598. }
  599. else if (strcmp(v1, "output") == 0)
  600. {
  601. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  602. {
  603. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  604. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  605. }
  606. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
  607. {
  608. if (!FindChargingInfoData(i, &_chargingData[0]))
  609. {
  610. printf ("FindChargingInfoData error\n");
  611. continue;
  612. }
  613. printf("From RB : Group Index = %d, OutputV = %f \n",
  614. i, _chargingData[i]->FireChargingVoltage);
  615. }
  616. }
  617. else if (strcmp(v1, "test") == 0)
  618. {
  619. int mode = atoi(v2);
  620. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  621. {
  622. ShmPsuData->Work_Step = mode;
  623. }
  624. }
  625. else if (strcmp(v1, "out") == 0)
  626. {
  627. float vol = atof(v2);
  628. float cur = atof(v3);
  629. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  630. {
  631. if (!FindChargingInfoData(0, &_chargingData[0]))
  632. {
  633. printf ("FindChargingInfoData error\n");
  634. return;
  635. }
  636. _chargingData[0]->EvBatterytargetVoltage = vol;
  637. _chargingData[0]->EvBatterytargetCurrent = cur;
  638. }
  639. }
  640. printf("*************************************************\n");
  641. }
  642. void GetConnectorCapInfo(char *v1)
  643. {
  644. int _GunIndex = atoi(v1);
  645. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  646. {
  647. printf ("FindChargingInfoData error\n");
  648. return;
  649. }
  650. printf ("Charger Max Current = %d, Max Power = %d \n",
  651. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  652. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  653. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  654. _GunIndex,
  655. _chargingData[_GunIndex]->RealMaxPower,
  656. _chargingData[_GunIndex]->RealMaxVoltage,
  657. _chargingData[_GunIndex]->RealMaxCurrent);
  658. }
  659. static void get_char(char *word)
  660. {
  661. fd_set rfds;
  662. struct timeval tv;
  663. FD_ZERO(&rfds);
  664. FD_SET(0, &rfds);
  665. tv.tv_sec = 0;
  666. tv.tv_usec = 10; //wait input timout time
  667. //if input
  668. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  669. {
  670. fgets(word, 128, stdin);
  671. }
  672. }
  673. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  674. {
  675. int _GunIndex;
  676. float _Voltage;
  677. float _Current;
  678. if (strcmp(v1, "auto") == EQUAL)
  679. {
  680. _usingAutoRun = 0x01;
  681. _GunIndex = atoi(v2);
  682. _Voltage = 500;
  683. _Current = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 1000) / _Voltage;
  684. }
  685. else
  686. {
  687. _usingAutoRun = 0x00;
  688. _GunIndex = atoi(v1);
  689. _Voltage = atof(v2);
  690. _Current = atof(v3);
  691. }
  692. unsigned char PreviousSystemStatus = 0xff;
  693. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  694. {
  695. printf ("FindChargingInfoData error\n");
  696. return;
  697. }
  698. printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  699. ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
  700. if(_Voltage > 1000 || _Voltage < 50)
  701. {
  702. printf ("Input Voltage over range\n");
  703. return;
  704. }
  705. // if(_Current > 100 || _Current < 2){
  706. //
  707. // printf ("Input Current over range\n");
  708. // return;
  709. // }
  710. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  711. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  712. //kill ev task
  713. system("killall Module_EvComm");
  714. //_Voltage = (_Voltage * 10);
  715. //_Current = (_Current * 10);
  716. //system(STTY_US TTY_PATH);
  717. while(true)
  718. {
  719. //fix gun 1
  720. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  721. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  722. {
  723. case S_IDLE:
  724. {
  725. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  726. {
  727. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  728. printf ("[UnconditionalCharge - S_IDLE]\n");
  729. }
  730. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  731. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  732. }
  733. break;
  734. case S_PREPARNING:
  735. {
  736. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  737. {
  738. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  739. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  740. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  741. printf ("wait find module\n");
  742. }
  743. //main 會在此階段判斷以下資料跳到下一個 state
  744. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  745. //ShmPsuData->SystemPresentPsuQuantity;
  746. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  747. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  748. //_chargingData[gun_index]->AvailableChargingPower;
  749. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  750. //sleep(10);
  751. //清除 main timeout 機制
  752. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  753. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  754. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  755. }
  756. break;
  757. case S_PREPARING_FOR_EV:
  758. {
  759. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  760. {
  761. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  762. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  763. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  764. }
  765. //清除 main timeout 機制
  766. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  767. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  768. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  769. //充電電壓電流
  770. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  771. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  772. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  773. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  774. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  775. //確定模組己升壓完成
  776. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  777. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  778. {
  779. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  780. //EV done
  781. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  782. }
  783. }
  784. break;
  785. case S_PREPARING_FOR_EVSE:
  786. {
  787. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  788. {
  789. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  790. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  791. }
  792. //printf ("tar vol = %d \n", _Voltage);
  793. //printf ("tar cur = %d \n", _Current);
  794. //清除 main timeout 機制
  795. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  796. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  797. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  798. //充電電壓電流
  799. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  800. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  801. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  802. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  803. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  804. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  805. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  806. //確定模組己升壓完成
  807. if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  808. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  809. {
  810. printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  811. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  812. sleep(5);
  813. //EV done
  814. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  815. }
  816. else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  817. {
  818. printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  819. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  820. }
  821. }
  822. break;
  823. case S_CHARGING:
  824. {
  825. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  826. {
  827. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  828. if (_usingAutoRun == 0x00)
  829. {
  830. //充電電壓電流
  831. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  832. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  833. }
  834. else
  835. {
  836. _curAutoRunCount = 0;
  837. gettimeofday(&_autoTime, NULL);
  838. }
  839. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  840. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  841. printf ("[UnconditionalCharge - S_CHARGING]\n");
  842. }
  843. if (_usingAutoRun == 0x01)
  844. {
  845. if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
  846. ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60))
  847. {
  848. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  849. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  850. }
  851. else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60)
  852. {
  853. _curAutoRunCount++;
  854. if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT)
  855. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  856. else
  857. gettimeofday(&_autoTime, NULL);
  858. }
  859. else
  860. {
  861. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 0;
  862. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 0;
  863. }
  864. }
  865. // printf("out : vol = %f, cur = %f \n",
  866. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
  867. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  868. //ev task do this
  869. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  870. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  871. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
  872. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  873. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  874. }
  875. }
  876. break;
  877. case S_TERMINATING:
  878. {
  879. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  880. {
  881. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  882. system("/root/Module_EvComm &");
  883. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  884. //無阻塞偵測 keybaord 結束
  885. system(STTY_DEF TTY_PATH);
  886. }
  887. sleep(3);
  888. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  889. return;
  890. }
  891. break;
  892. case S_COMPLETE:
  893. {
  894. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  895. {
  896. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  897. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  898. }
  899. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower = 0;
  900. sleep(3);
  901. return;
  902. }
  903. break;
  904. }
  905. char word[128];
  906. char newString[7][10];
  907. int i,j,ctr;
  908. memset(word, 0x00, sizeof(word));
  909. get_char(word);
  910. if (strlen(word) == 0)
  911. continue;
  912. j=0; ctr=0;
  913. strcpy(newString[1], "-1");
  914. strcpy(newString[2], "-1");
  915. for (i = 0; i <= (strlen(word)); i++)
  916. {
  917. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  918. {
  919. newString[ctr][j] = '\0';
  920. ctr++;
  921. j = 0;
  922. }
  923. else
  924. {
  925. newString[ctr][j] = word[i];
  926. j++;
  927. }
  928. }
  929. if(strcmp(newString[0], "chg") == 0)
  930. {
  931. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  932. continue;
  933. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  934. continue;
  935. float _vol = atof(newString[1]);
  936. float _cur = atof(newString[2]);
  937. if (_cur <= 0 || _cur <= 0)
  938. continue;
  939. printf("vol = %f, cur = %f \n", _vol, _cur);
  940. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  941. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  942. }
  943. else if (strcmp(newString[0], "c") == 0)
  944. {
  945. printf("stop \n\r");
  946. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  947. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  948. }
  949. usleep(100000);
  950. }
  951. }
  952. int main(void)
  953. {
  954. if(InitShareMemory() == FAIL)
  955. {
  956. printf ("InitShareMemory = FAIL \n");
  957. if(ShmStatusCodeData != NULL)
  958. {
  959. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  960. }
  961. sleep(5);
  962. return 0;
  963. }
  964. for(;;)
  965. {
  966. char word[128];
  967. char newString[7][10];
  968. int i,j,ctr;
  969. fgets(word, sizeof(word), stdin);
  970. j=0; ctr=0;
  971. strcpy(newString[1], "-1");
  972. strcpy(newString[2], "-1");
  973. for (i = 0; i <= (strlen(word)); i++)
  974. {
  975. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  976. {
  977. newString[ctr][j] = '\0';
  978. ctr++;
  979. j = 0;
  980. }
  981. else
  982. {
  983. newString[ctr][j] = word[i];
  984. j++;
  985. }
  986. }
  987. if(strcmp(newString[0], "state") == 0)
  988. {
  989. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  990. continue;
  991. // 槍狀態
  992. RunStatusProc(newString[1], newString[2]);
  993. }
  994. else if(strcmp(newString[0], "card") == 0)
  995. {
  996. // 刷卡狀態
  997. RunCardProc(newString[1], newString[2]);
  998. }
  999. else if(strcmp(newString[0], "gun") == 0)
  1000. {
  1001. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1002. continue;
  1003. // 插槍狀態
  1004. RunGunPlugitProc(newString[1], newString[2]);
  1005. }
  1006. else if(strcmp(newString[0], "lock") == 0)
  1007. {
  1008. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1009. continue;
  1010. // 插槍狀態
  1011. GetGunLockStatusProc(newString[1], newString[2]);
  1012. }
  1013. else if(strcmp(newString[0], "sysid") == 0)
  1014. {
  1015. // 測試 sys id
  1016. SetSystemIDProc();
  1017. }
  1018. else if(strcmp(newString[0], "self") == 0)
  1019. {
  1020. // CSU 自我檢測狀態
  1021. RunSelfProc(newString[1]);
  1022. }
  1023. else if(strcmp(newString[0], "ver") == 0)
  1024. {
  1025. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1026. continue;
  1027. // 取 FW 版號
  1028. GetFwVerProc(newString[1]);
  1029. }
  1030. else if (strcmp(newString[0], "update") == 0)
  1031. {
  1032. // 更新
  1033. FwUpdateFlagProc(newString[1]);
  1034. }
  1035. else if (strcmp(newString[0], "ac") == 0)
  1036. {
  1037. // AC contactor 狀態
  1038. CheckAcStatus(newString[1]);
  1039. }
  1040. else if (strcmp(newString[0], "cable") == 0)
  1041. {
  1042. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1043. continue;
  1044. // cable check pass
  1045. SetCableChkStatus(newString[1], newString[2]);
  1046. }
  1047. else if (strcmp(newString[0], "pow") == 0)
  1048. {
  1049. // get output power
  1050. GetPowerValue();
  1051. }
  1052. else if (strcmp(newString[0], "model") == 0)
  1053. {
  1054. GetSystemInfo();
  1055. }
  1056. else if(strcmp(newString[0], "select") == 0)
  1057. {
  1058. // 取得 / 設定 當前選的槍號
  1059. GetGunSelectedNum(newString[1]);
  1060. }
  1061. else if(strcmp(newString[0], "change") == 0)
  1062. {
  1063. // 模擬按鈕改變選槍
  1064. ChangeGunNum();
  1065. }
  1066. else if(strcmp(newString[0], "fan") == 0)
  1067. {
  1068. // 設定風扇速度
  1069. SetFanSpeed(newString[1]);
  1070. }
  1071. else if(strcmp(newString[0], "speed") == 0)
  1072. {
  1073. // 取得風扇速度
  1074. GetFanSpeed();
  1075. }
  1076. else if(strcmp(newString[0], "debug") == 0)
  1077. {
  1078. // 設定 debug mode
  1079. SetDebugMode(newString[1]);
  1080. }
  1081. else if (strcmp(newString[0], "gfd") == 0)
  1082. {
  1083. // 設定盲沖使用 GFD 功能
  1084. SetGFDMode(newString[1]);
  1085. }
  1086. else if(strcmp(newString[0], "temp") == 0)
  1087. {
  1088. // 取得 PSU 溫度
  1089. GetPsuTemp();
  1090. }
  1091. else if(strcmp(newString[0], "acin") == 0)
  1092. {
  1093. // 取得三向輸入電壓
  1094. GetAcInputVol();
  1095. }
  1096. else if(strcmp(newString[0], "psu") == 0)
  1097. {
  1098. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1099. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1100. {
  1101. printf ("PSU : Param fail..Please retry again......\n");
  1102. continue;
  1103. }
  1104. // 取得 PSU 資訊
  1105. GetPsuInformation(newString[1], newString[2], newString[3]);
  1106. }
  1107. else if (strcmp(newString[0], "cap") == 0)
  1108. {
  1109. GetConnectorCapInfo(newString[1]);
  1110. }
  1111. else if(strcmp(newString[0], "error") == 0)
  1112. {
  1113. CreateOneError(newString[1]);
  1114. }
  1115. else if (strcmp(newString[0], "auth") == 0)
  1116. {
  1117. GetAuthorizeFlag(newString[1]);
  1118. }
  1119. else if (strcmp(newString[0], "relay") == 0)
  1120. {
  1121. GetRelayStatus(newString[1]);
  1122. }
  1123. else if (strcmp(newString[0], "ccid") == 0)
  1124. {
  1125. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1126. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1127. {
  1128. printf ("Input ccid fail.\n");
  1129. continue;
  1130. }
  1131. SetChargingInfoCCID(newString[1], newString[2]);
  1132. }
  1133. else if (strcmp(newString[0], "test") == 0)
  1134. {
  1135. }
  1136. else if(strcmp(newString[0], "strchg") == 0)
  1137. {
  1138. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1139. if (strcmp(newString[1], "auto") == 0)
  1140. {
  1141. newString[3][0] = 0;
  1142. }
  1143. else if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1144. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1145. {
  1146. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1147. continue;
  1148. }
  1149. // 槍狀態
  1150. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1151. }
  1152. else
  1153. printf ("%s\n", msg);
  1154. usleep(100000);
  1155. }
  1156. return 0;
  1157. }