ReadCmdline.c 42 KB

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