ReadCmdline.c 43 KB

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