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