ReadCmdline.c 41 KB

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