ReadCmdline.c 43 KB

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