ReadCmdline.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319
  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. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = value;
  392. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  393. }
  394. void GetAuthorizeFlag(char *v1)
  395. {
  396. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  397. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  398. else
  399. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  400. }
  401. void GetRelayStatus(char *v1)
  402. {
  403. int _index = atoi(v1);
  404. if (!FindChargingInfoData(_index, &_chargingData[0]))
  405. {
  406. printf("FindChargingInfoData error\n");
  407. return;
  408. }
  409. printf("RelayK1K2Status = %d \n", _chargingData[_index]->RelayK1K2Status);
  410. printf("RelayKPK2Status = %d \n", _chargingData[_index]->RelayKPK2Status);
  411. }
  412. void FwUpdateFlagProc()
  413. {
  414. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  415. }
  416. void CheckAcStatus(char *v1)
  417. {
  418. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  419. {
  420. printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  421. }
  422. }
  423. void SetCableChkStatus(char *v1, char *v2)
  424. {
  425. int _index = atoi(v1);
  426. if (!FindChargingInfoData(_index, &_chargingData[0]))
  427. {
  428. printf ("FindChargingInfoData error\n");
  429. return;
  430. }
  431. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  432. }
  433. void SetChargingInfoCCID(char *v1, char* v2)
  434. {
  435. int _index = atoi(v1);
  436. if (!FindChargingInfoData(_index, &_chargingData[0]))
  437. {
  438. printf ("FindChargingInfoData error\n");
  439. return;
  440. }
  441. memcpy(_chargingData[_index]->EVCCID, v2, 8);
  442. _chargingData[_index]->EVCCID[8] = '\0';
  443. }
  444. void GetPowerValue()
  445. {
  446. for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
  447. {
  448. if (!FindChargingInfoData(index, &_chargingData[0]))
  449. {
  450. printf ("FindChargingInfoData error\n");
  451. return;
  452. }
  453. printf ("index = %d, PresentChargingPower = %f \n", index, _chargingData[index]->PresentChargingPower);
  454. }
  455. }
  456. void GetSystemInfo()
  457. {
  458. printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  459. printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  460. printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
  461. printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  462. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  463. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  464. }
  465. void ChangeGunNum()
  466. {
  467. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  468. {
  469. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  470. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  471. }
  472. else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  473. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
  474. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  475. else
  476. {
  477. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  478. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  479. }
  480. }
  481. void GetGunSelectedNum(char *v1)
  482. {
  483. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  484. {
  485. if (AC_QUANTITY > 0 &&
  486. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
  487. {
  488. printf("connector select changed = AC \n");
  489. }
  490. else
  491. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  492. }
  493. else
  494. {
  495. int _index = atoi(v1);
  496. if (_index <= 1)
  497. {
  498. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  499. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  500. printf("connector select changed = %d \n", _index);
  501. }
  502. else if (AC_QUANTITY > 0)
  503. {
  504. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  505. printf("connector select changed = AC \n");
  506. }
  507. }
  508. }
  509. void SetFanSpeed(char *v1)
  510. {
  511. int speed = atoi(v1);
  512. ShmFanModuleData->TestFanSpeed = speed;
  513. }
  514. void GetFanSpeed()
  515. {
  516. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  517. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  518. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  519. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  520. }
  521. void SetDebugMode(char *v1)
  522. {
  523. int mode = atoi(v1);
  524. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  525. }
  526. void SetGFDMode(char *v1)
  527. {
  528. int mode = atoi(v1);
  529. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  530. }
  531. void GetPsuTemp()
  532. {
  533. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  534. {
  535. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  536. {
  537. printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
  538. }
  539. }
  540. }
  541. void GetAcInputVol()
  542. {
  543. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  544. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  545. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  546. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  547. }
  548. void GetPsuInformation(char *v1, char *v2, char *v3)
  549. {
  550. printf("**********************AC Contact needed*************************\n");
  551. if(strcmp(v1, "count") == 0)
  552. {
  553. for (int i = 0; i < 4; i++)
  554. {
  555. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  556. }
  557. }
  558. else if(strcmp(v1, "ver") == 0)
  559. {
  560. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  561. {
  562. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  563. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  564. }
  565. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  566. {
  567. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  568. {
  569. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  570. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  571. }
  572. }
  573. }
  574. else if(strcmp(v1, "cap") == 0)
  575. {
  576. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  577. {
  578. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  579. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  580. }
  581. }
  582. else if(strcmp(v1, "input") == 0)
  583. {
  584. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  585. {
  586. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  587. {
  588. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  589. i, count,
  590. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  591. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  592. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  593. }
  594. }
  595. }
  596. else if (strcmp(v1, "output") == 0)
  597. {
  598. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  599. {
  600. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  601. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  602. }
  603. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
  604. {
  605. if (!FindChargingInfoData(i, &_chargingData[0]))
  606. {
  607. printf ("FindChargingInfoData error\n");
  608. continue;
  609. }
  610. printf("From RB : Group Index = %d, OutputV = %f \n",
  611. i, _chargingData[i]->FireChargingVoltage);
  612. }
  613. }
  614. else if (strcmp(v1, "test") == 0)
  615. {
  616. int mode = atoi(v2);
  617. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  618. {
  619. ShmPsuData->Work_Step = mode;
  620. }
  621. }
  622. else if (strcmp(v1, "out") == 0)
  623. {
  624. float vol = atof(v2);
  625. float cur = atof(v3);
  626. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  627. {
  628. if (!FindChargingInfoData(0, &_chargingData[0]))
  629. {
  630. printf ("FindChargingInfoData error\n");
  631. return;
  632. }
  633. _chargingData[0]->EvBatterytargetVoltage = vol;
  634. _chargingData[0]->EvBatterytargetCurrent = cur;
  635. }
  636. }
  637. printf("*************************************************\n");
  638. }
  639. void GetConnectorCapInfo(char *v1)
  640. {
  641. int _GunIndex = atoi(v1);
  642. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  643. {
  644. printf ("FindChargingInfoData error\n");
  645. return;
  646. }
  647. printf ("Charger Max Current = %d, Max Power = %d \n",
  648. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  649. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  650. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  651. _GunIndex,
  652. _chargingData[_GunIndex]->RealMaxPower,
  653. _chargingData[_GunIndex]->RealMaxVoltage,
  654. _chargingData[_GunIndex]->RealMaxCurrent);
  655. }
  656. static void get_char(char *word)
  657. {
  658. fd_set rfds;
  659. struct timeval tv;
  660. FD_ZERO(&rfds);
  661. FD_SET(0, &rfds);
  662. tv.tv_sec = 0;
  663. tv.tv_usec = 10; //wait input timout time
  664. //if input
  665. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  666. {
  667. fgets(word, 128, stdin);
  668. }
  669. }
  670. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  671. {
  672. int _GunIndex;
  673. float _Voltage;
  674. float _Current;
  675. if (strcmp(v1, "auto") == EQUAL)
  676. {
  677. _usingAutoRun = 0x01;
  678. _GunIndex = atoi(v2);
  679. _Voltage = 500;
  680. _Current = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 1000) / _Voltage;
  681. }
  682. else
  683. {
  684. _usingAutoRun = 0x00;
  685. _GunIndex = atoi(v1);
  686. _Voltage = atof(v2);
  687. _Current = atof(v3);
  688. }
  689. unsigned char PreviousSystemStatus = 0xff;
  690. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  691. {
  692. printf ("FindChargingInfoData error\n");
  693. return;
  694. }
  695. printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  696. ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
  697. if(_Voltage > 1000 || _Voltage < 50)
  698. {
  699. printf ("Input Voltage over range\n");
  700. return;
  701. }
  702. // if(_Current > 100 || _Current < 2){
  703. //
  704. // printf ("Input Current over range\n");
  705. // return;
  706. // }
  707. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  708. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  709. //kill ev task
  710. system("killall Module_EvComm");
  711. //_Voltage = (_Voltage * 10);
  712. //_Current = (_Current * 10);
  713. //system(STTY_US TTY_PATH);
  714. while(true)
  715. {
  716. //fix gun 1
  717. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  718. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  719. {
  720. case S_IDLE:
  721. {
  722. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  723. {
  724. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  725. printf ("[UnconditionalCharge - S_IDLE]\n");
  726. }
  727. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  728. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  729. }
  730. break;
  731. case S_PREPARNING:
  732. {
  733. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  734. {
  735. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  736. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  737. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  738. printf ("wait find module\n");
  739. }
  740. //main 會在此階段判斷以下資料跳到下一個 state
  741. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  742. //ShmPsuData->SystemPresentPsuQuantity;
  743. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  744. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  745. //_chargingData[gun_index]->AvailableChargingPower;
  746. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  747. //sleep(10);
  748. //清除 main timeout 機制
  749. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  750. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  751. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  752. }
  753. break;
  754. case S_PREPARING_FOR_EV:
  755. {
  756. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  757. {
  758. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  759. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  760. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  761. }
  762. //清除 main timeout 機制
  763. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  764. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  765. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  766. //充電電壓電流
  767. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  768. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  769. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  770. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  771. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  772. //確定模組己升壓完成
  773. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  774. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  775. {
  776. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  777. //EV done
  778. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  779. }
  780. }
  781. break;
  782. case S_PREPARING_FOR_EVSE:
  783. {
  784. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  785. {
  786. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  787. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  788. }
  789. //printf ("tar vol = %d \n", _Voltage);
  790. //printf ("tar cur = %d \n", _Current);
  791. //清除 main timeout 機制
  792. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  793. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  794. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  795. //充電電壓電流
  796. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  797. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  798. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  799. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  800. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  801. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  802. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  803. //確定模組己升壓完成
  804. if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  805. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  806. {
  807. printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  808. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  809. sleep(5);
  810. //EV done
  811. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  812. }
  813. else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  814. {
  815. printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  816. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  817. }
  818. }
  819. break;
  820. case S_CHARGING:
  821. {
  822. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  823. {
  824. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  825. if (_usingAutoRun == 0x00)
  826. {
  827. //充電電壓電流
  828. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  829. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  830. }
  831. else
  832. {
  833. _curAutoRunCount = 0;
  834. gettimeofday(&_autoTime, NULL);
  835. }
  836. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  837. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  838. printf ("[UnconditionalCharge - S_CHARGING]\n");
  839. }
  840. if (_usingAutoRun == 0x01)
  841. {
  842. if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
  843. ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60))
  844. {
  845. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  846. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  847. }
  848. else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60)
  849. {
  850. _curAutoRunCount++;
  851. if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT)
  852. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  853. else
  854. gettimeofday(&_autoTime, NULL);
  855. }
  856. else
  857. {
  858. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 0;
  859. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 0;
  860. }
  861. }
  862. // printf("out : vol = %f, cur = %f \n",
  863. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
  864. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  865. //ev task do this
  866. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  867. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  868. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
  869. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  870. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  871. }
  872. }
  873. break;
  874. case S_TERMINATING:
  875. {
  876. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  877. {
  878. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  879. system("/root/Module_EvComm &");
  880. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  881. //無阻塞偵測 keybaord 結束
  882. system(STTY_DEF TTY_PATH);
  883. }
  884. sleep(3);
  885. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  886. return;
  887. }
  888. break;
  889. case S_COMPLETE:
  890. {
  891. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  892. {
  893. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  894. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  895. }
  896. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower = 0;
  897. sleep(3);
  898. return;
  899. }
  900. break;
  901. }
  902. char word[128];
  903. char newString[7][10];
  904. int i,j,ctr;
  905. memset(word, 0x00, sizeof(word));
  906. get_char(word);
  907. if (strlen(word) == 0)
  908. continue;
  909. j=0; ctr=0;
  910. strcpy(newString[1], "-1");
  911. strcpy(newString[2], "-1");
  912. for (i = 0; i <= (strlen(word)); i++)
  913. {
  914. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  915. {
  916. newString[ctr][j] = '\0';
  917. ctr++;
  918. j = 0;
  919. }
  920. else
  921. {
  922. newString[ctr][j] = word[i];
  923. j++;
  924. }
  925. }
  926. if(strcmp(newString[0], "chg") == 0)
  927. {
  928. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  929. continue;
  930. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  931. continue;
  932. float _vol = atof(newString[1]);
  933. float _cur = atof(newString[2]);
  934. if (_cur <= 0 || _cur <= 0)
  935. continue;
  936. printf("vol = %f, cur = %f \n", _vol, _cur);
  937. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  938. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  939. }
  940. else if (strcmp(newString[0], "c") == 0)
  941. {
  942. printf("stop \n\r");
  943. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  944. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  945. }
  946. usleep(100000);
  947. }
  948. }
  949. int main(void)
  950. {
  951. if(InitShareMemory() == FAIL)
  952. {
  953. printf ("InitShareMemory = FAIL \n");
  954. if(ShmStatusCodeData != NULL)
  955. {
  956. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  957. }
  958. sleep(5);
  959. return 0;
  960. }
  961. for(;;)
  962. {
  963. char word[128];
  964. char newString[7][10];
  965. int i,j,ctr;
  966. fgets(word, sizeof(word), stdin);
  967. j=0; ctr=0;
  968. strcpy(newString[1], "-1");
  969. strcpy(newString[2], "-1");
  970. for (i = 0; i <= (strlen(word)); i++)
  971. {
  972. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  973. {
  974. newString[ctr][j] = '\0';
  975. ctr++;
  976. j = 0;
  977. }
  978. else
  979. {
  980. newString[ctr][j] = word[i];
  981. j++;
  982. }
  983. }
  984. if(strcmp(newString[0], "state") == 0)
  985. {
  986. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  987. continue;
  988. // 槍狀態
  989. RunStatusProc(newString[1], newString[2]);
  990. }
  991. else if(strcmp(newString[0], "card") == 0)
  992. {
  993. // 刷卡狀態
  994. RunCardProc(newString[1], newString[2]);
  995. }
  996. else if(strcmp(newString[0], "gun") == 0)
  997. {
  998. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  999. continue;
  1000. // 插槍狀態
  1001. RunGunPlugitProc(newString[1], newString[2]);
  1002. }
  1003. else if(strcmp(newString[0], "lock") == 0)
  1004. {
  1005. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1006. continue;
  1007. // 插槍狀態
  1008. GetGunLockStatusProc(newString[1], newString[2]);
  1009. }
  1010. else if(strcmp(newString[0], "sysid") == 0)
  1011. {
  1012. // 測試 sys id
  1013. SetSystemIDProc();
  1014. }
  1015. else if(strcmp(newString[0], "self") == 0)
  1016. {
  1017. // CSU 自我檢測狀態
  1018. RunSelfProc(newString[1]);
  1019. }
  1020. else if(strcmp(newString[0], "ver") == 0)
  1021. {
  1022. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1023. continue;
  1024. // 取 FW 版號
  1025. GetFwVerProc(newString[1]);
  1026. }
  1027. else if (strcmp(newString[0], "update") == 0)
  1028. {
  1029. // 更新
  1030. FwUpdateFlagProc(newString[1]);
  1031. }
  1032. else if (strcmp(newString[0], "ac") == 0)
  1033. {
  1034. // AC contactor 狀態
  1035. CheckAcStatus(newString[1]);
  1036. }
  1037. else if (strcmp(newString[0], "cable") == 0)
  1038. {
  1039. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1040. continue;
  1041. // cable check pass
  1042. SetCableChkStatus(newString[1], newString[2]);
  1043. }
  1044. else if (strcmp(newString[0], "pow") == 0)
  1045. {
  1046. // get output power
  1047. GetPowerValue();
  1048. }
  1049. else if (strcmp(newString[0], "model") == 0)
  1050. {
  1051. GetSystemInfo();
  1052. }
  1053. else if(strcmp(newString[0], "select") == 0)
  1054. {
  1055. // 取得 / 設定 當前選的槍號
  1056. GetGunSelectedNum(newString[1]);
  1057. }
  1058. else if(strcmp(newString[0], "change") == 0)
  1059. {
  1060. // 模擬按鈕改變選槍
  1061. ChangeGunNum();
  1062. }
  1063. else if(strcmp(newString[0], "fan") == 0)
  1064. {
  1065. // 設定風扇速度
  1066. SetFanSpeed(newString[1]);
  1067. }
  1068. else if(strcmp(newString[0], "speed") == 0)
  1069. {
  1070. // 取得風扇速度
  1071. GetFanSpeed();
  1072. }
  1073. else if(strcmp(newString[0], "debug") == 0)
  1074. {
  1075. // 設定 debug mode
  1076. SetDebugMode(newString[1]);
  1077. }
  1078. else if (strcmp(newString[0], "gfd") == 0)
  1079. {
  1080. // 設定盲沖使用 GFD 功能
  1081. SetGFDMode(newString[1]);
  1082. }
  1083. else if(strcmp(newString[0], "temp") == 0)
  1084. {
  1085. // 取得 PSU 溫度
  1086. GetPsuTemp();
  1087. }
  1088. else if(strcmp(newString[0], "acin") == 0)
  1089. {
  1090. // 取得三向輸入電壓
  1091. GetAcInputVol();
  1092. }
  1093. else if(strcmp(newString[0], "psu") == 0)
  1094. {
  1095. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1096. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1097. {
  1098. printf ("PSU : Param fail..Please retry again......\n");
  1099. continue;
  1100. }
  1101. // 取得 PSU 資訊
  1102. GetPsuInformation(newString[1], newString[2], newString[3]);
  1103. }
  1104. else if (strcmp(newString[0], "cap") == 0)
  1105. {
  1106. GetConnectorCapInfo(newString[1]);
  1107. }
  1108. else if(strcmp(newString[0], "error") == 0)
  1109. {
  1110. CreateOneError(newString[1]);
  1111. }
  1112. else if (strcmp(newString[0], "auth") == 0)
  1113. {
  1114. GetAuthorizeFlag(newString[1]);
  1115. }
  1116. else if (strcmp(newString[0], "relay") == 0)
  1117. {
  1118. GetRelayStatus(newString[1]);
  1119. }
  1120. else if (strcmp(newString[0], "ccid") == 0)
  1121. {
  1122. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1123. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1124. {
  1125. printf ("Input ccid fail.\n");
  1126. continue;
  1127. }
  1128. SetChargingInfoCCID(newString[1], newString[2]);
  1129. }
  1130. else if (strcmp(newString[0], "test") == 0)
  1131. {
  1132. printf("v = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  1133. // for(int i = 0; i < 2; i++)
  1134. // {
  1135. // if (!FindChargingInfoData(i, &_chargingData[0]))
  1136. // {
  1137. // printf("FindChargingInfoData error\n");
  1138. // }
  1139. // else
  1140. // {
  1141. // printf("v = %d, vv = %d \n", _chargingData[i]->SystemStatus, _chargingData[i]->IsAvailable);
  1142. // }
  1143. // }
  1144. }
  1145. else if(strcmp(newString[0], "strchg") == 0)
  1146. {
  1147. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1148. if (strcmp(newString[1], "auto") == 0)
  1149. {
  1150. newString[3][0] = 0;
  1151. }
  1152. else if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1153. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1154. {
  1155. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1156. continue;
  1157. }
  1158. // 槍狀態
  1159. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1160. }
  1161. else
  1162. printf ("%s\n", msg);
  1163. usleep(100000);
  1164. }
  1165. return 0;
  1166. }