Module_ConfigTools.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*
  2. * Module_ConfigTools.c
  3. *
  4. * Created on: 2020¦~6¤ë22¤é
  5. * Author: foluswen
  6. */
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <sys/time.h>
  10. #include <sys/timeb.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/mman.h>
  17. #include <linux/wireless.h>
  18. #include <arpa/inet.h>
  19. #include <netinet/in.h>
  20. #include <dirent.h>
  21. #include <unistd.h>
  22. #include <stdarg.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <unistd.h>
  26. #include <fcntl.h>
  27. #include <termios.h>
  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 <stdbool.h>
  35. #include <stddef.h>
  36. #include <stdint.h>
  37. #include "define.h"
  38. //=================================
  39. // System basic sample constant
  40. //=================================
  41. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  42. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  43. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  44. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  45. #define PASS 1
  46. #define FAIL -1
  47. #define YES 1
  48. #define NO 0
  49. #define ON 1
  50. #define OFF 0
  51. #define MtdBlockSize 0x600000
  52. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  53. struct StatusCodeData *ShmStatusCodeData;
  54. int StoreLogMsg(const char *fmt, ...)
  55. {
  56. char Buf[4096+256];
  57. char buffer[4096];
  58. time_t CurrentTime;
  59. struct tm *tm;
  60. struct timeval tv;
  61. va_list args;
  62. va_start(args, fmt);
  63. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  64. va_end(args);
  65. memset(Buf,0,sizeof(Buf));
  66. CurrentTime = time(NULL);
  67. tm=localtime(&CurrentTime);
  68. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  69. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]ConfigToolsLog",
  70. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
  71. buffer,
  72. tm->tm_year+1900,tm->tm_mon+1);
  73. #ifdef SystemLogMessage
  74. system(Buf);
  75. #endif
  76. #ifdef ConsloePrintLog
  77. printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
  78. #endif
  79. return rc;
  80. }
  81. int runShellCmd(const char*cmd)
  82. {
  83. int result = FAIL;
  84. char buf[256];
  85. FILE *fp;
  86. fp = popen(cmd, "r");
  87. if(fp != NULL)
  88. {
  89. while(fgets(buf, sizeof(buf), fp) != NULL)
  90. {
  91. DEBUG_INFO("%s\n", buf);
  92. }
  93. result = PASS;
  94. }
  95. pclose(fp);
  96. return result;
  97. }
  98. int StoreUsrConfigData(struct SysConfigData *UsrData)
  99. {
  100. int result = PASS;
  101. int fd,wrd;
  102. unsigned int i,Chk;
  103. unsigned char *ptr, *BufTmp;
  104. Chk=0;
  105. ptr=(unsigned char *)UsrData;
  106. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  107. {
  108. memset(BufTmp,0,MtdBlockSize);
  109. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  110. for(i=0;i<MtdBlockSize-4;i++)
  111. Chk+=*(BufTmp+i);
  112. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  113. // Output configuration to file.
  114. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  115. if (fd < 0)
  116. {
  117. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  118. free(BufTmp);
  119. return 0;
  120. }
  121. wrd=write(fd, BufTmp, MtdBlockSize);
  122. close(fd);
  123. if(wrd<MtdBlockSize)
  124. {
  125. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  126. free(BufTmp);
  127. return 0;
  128. }
  129. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  130. DEBUG_INFO("Erase /dev/mtd10.\n");
  131. runShellCmd("flash_erase /dev/mtd10 0 0");
  132. DEBUG_INFO("Write /dev/mtd10.\n");
  133. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  134. DEBUG_INFO("Erase /dev/mtd11.\n");
  135. runShellCmd("flash_erase /dev/mtd11 0 0");
  136. DEBUG_INFO("Write /dev/mtd11.\n");
  137. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  138. system("rm -f /mnt/EvseConfig.bin");
  139. DEBUG_INFO("EvseConfig write to flash OK\n");
  140. }
  141. else
  142. {
  143. DEBUG_ERROR("alloc BlockSize NG\r\n");
  144. result = FAIL;
  145. }
  146. if(BufTmp!=NULL)
  147. free(BufTmp);
  148. return result;
  149. }
  150. int InitShareMemory()
  151. {
  152. int result = PASS;
  153. int MeterSMId;
  154. //Initial ShmSysConfigAndInfo
  155. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  156. {
  157. #ifdef SystemLogMessage
  158. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  159. #endif
  160. result = FAIL;
  161. }
  162. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  163. {
  164. #ifdef SystemLogMessage
  165. DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
  166. #endif
  167. result = FAIL;
  168. }
  169. //Initial ShmStatusCodeData
  170. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  171. {
  172. #ifdef SystemLogMessage
  173. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  174. #endif
  175. result = FAIL;
  176. }
  177. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  178. {
  179. #ifdef SystemLogMessage
  180. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  181. #endif
  182. result = FAIL;
  183. }
  184. return result;
  185. }
  186. int main(void)
  187. {
  188. char cmd[128];
  189. if(InitShareMemory() == FAIL)
  190. {
  191. #ifdef SystemLogMessage
  192. DEBUG_ERROR("InitShareMemory NG\n");
  193. #endif
  194. if(ShmStatusCodeData!=NULL)
  195. {
  196. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  197. }
  198. sleep(5);
  199. return 0;
  200. }
  201. else
  202. {
  203. DEBUG_INFO("InitShareMemory OK.\r\n");
  204. }
  205. for(;;)
  206. {
  207. system("clear");
  208. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  209. printf("\n ===== main menu ===================================");
  210. printf("\n system: system configuration menu.");
  211. printf("\n ocpp: ocpp configuration menu.");
  212. printf("\n network: netwok configuration menu.");
  213. printf("\n test: charger start/stop test.");
  214. printf("\n upgrade: trigger firmware upgrade.");
  215. printf("\n save: Save config.");
  216. printf("\n exit: Exit config tools.");
  217. printf("\n =================================================");
  218. printf("\n Please input item name to config: ");
  219. scanf("%s", &cmd[0]);
  220. if(strcmp(cmd, "system") == 0)
  221. {
  222. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  223. printf("\n ***** system configuration menu ******************");
  224. printf("\n modelname: EVSE model name.");
  225. printf("\n serialnumber: EVSE serial number.");
  226. printf("\n *************************************************");
  227. printf("\n Please input operation item: ");
  228. scanf("%s", &cmd[0]);
  229. if(strcmp(cmd, "modelname") == 0)
  230. {
  231. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  232. printf("\n *************************************************");
  233. printf("\n Current model name: %s", ShmSysConfigAndInfo->SysConfig.ModelName);
  234. printf("\n 0: Keep current config.");
  235. printf("\n 1: Input new model name.");
  236. printf("\n *************************************************");
  237. printf("\n Please input operation item: ");
  238. scanf("%s", &cmd[0]);
  239. if(atoi(cmd) == 1)
  240. {
  241. printf("\n Please input model name: ");
  242. scanf("%s", &cmd[0]);
  243. memset(&ShmSysConfigAndInfo->SysConfig.ModelName[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
  244. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ModelName[0], (char*)&cmd[0]);
  245. }
  246. }
  247. else if(strcmp(cmd, "serialnumber") == 0)
  248. {
  249. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  250. printf("\n *************************************************");
  251. printf("\n Current serial number: %s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  252. printf("\n 0: Keep current config.");
  253. printf("\n 1: Input new serial number.");
  254. printf("\n *************************************************");
  255. printf("\n Please input operation item: ");
  256. scanf("%s", &cmd[0]);
  257. if(atoi(cmd) == 1)
  258. {
  259. printf("\n Please input serial number: ");
  260. scanf("%s", &cmd[0]);
  261. memset(&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
  262. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], (char*)&cmd[0]);
  263. }
  264. }
  265. }
  266. else if(strcmp(cmd, "ocpp") == 0)
  267. {
  268. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  269. printf("\n *************************************************");
  270. printf("\n ocppurl: OCPP backend server url.");
  271. printf("\n cboxid: Charger box id.");
  272. printf("\n *************************************************");
  273. printf("\n Please input operation item: ");
  274. scanf("%s", &cmd[0]);
  275. if(strcmp(cmd, "ocppurl") == 0)
  276. {
  277. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  278. printf("\n *************************************************");
  279. printf("\n Current OCPP url: %s", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  280. printf("\n 0: Keep current config.");
  281. printf("\n 1: Input new ocpp url.");
  282. printf("\n *************************************************");
  283. printf("\n Please input operation item: ");
  284. scanf("%s", &cmd[0]);
  285. if(atoi(cmd) == 1)
  286. {
  287. printf("\n Please input ocpp url: ");
  288. scanf("%s", &cmd[0]);
  289. memset(&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  290. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], (char*)&cmd[0]);
  291. }
  292. }
  293. else if(strcmp(cmd, "cboxid") == 0)
  294. {
  295. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  296. printf("\n *************************************************");
  297. printf("\n Current OCPP charger box id: %s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  298. printf("\n 0: Keep current config.");
  299. printf("\n 1: Input new charger box id.");
  300. printf("\n *************************************************");
  301. printf("\n Please input operation item: ");
  302. scanf("%s", &cmd[0]);
  303. if(atoi(cmd) == 1)
  304. {
  305. printf("\n Please input OCPP charger box id: ");
  306. scanf("%s", &cmd[0]);
  307. memset(&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
  308. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], (char*)&cmd[0]);
  309. }
  310. }
  311. }
  312. else if(strcmp(cmd, "network") == 0)
  313. {
  314. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  315. printf("\n *************************************************");
  316. printf("\n ethdhcp: Ethernet DHCP client.");
  317. printf("\n wifimode: WiFi mode.");
  318. printf("\n wifidhcp: WiFi DHCP client.");
  319. printf("\n wificssid: WiFi client SSID.");
  320. printf("\n wificpasswd: WiFi client password.");
  321. printf("\n telemode: Telecomm mode.");
  322. printf("\n teleapn: Telecomm APN.");
  323. printf("\n teleid: Telecomm login id.");
  324. printf("\n telepwd: Telecomm login password.");
  325. printf("\n *************************************************");
  326. printf("\n Please input operation item: ");
  327. scanf("%s", &cmd[0]);
  328. if(strcmp(cmd, "ethdhcp") == 0)
  329. {
  330. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  331. printf("\n *************************************************");
  332. printf("\n 0: Disable.");
  333. printf("\n 1: Enable.");
  334. printf("\n *************************************************");
  335. printf("\n Current ethernet dhcp mode: %d", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient^1);
  336. printf("\n Please input dhcp mode: ");
  337. scanf("%s", &cmd[0]);
  338. ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
  339. }
  340. else if(strcmp(cmd, "wifimode") == 0)
  341. {
  342. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  343. printf("\n *************************************************");
  344. printf("\n 0: Disable.");
  345. printf("\n 1: Station.");
  346. printf("\n 2: Access point.");
  347. printf("\n *************************************************");
  348. printf("\n Current WiFi mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
  349. printf("\n Please input WiFi mode: ");
  350. scanf("%s", &cmd[0]);
  351. ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode = ((0<=atoi(cmd))&&(atoi(cmd)<=2)?atoi(cmd):0);
  352. }
  353. else if(strcmp(cmd, "wifidhcp") == 0)
  354. {
  355. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  356. printf("\n *************************************************");
  357. printf("\n 0: Disable.");
  358. printf("\n 1: Enable.");
  359. printf("\n *************************************************");
  360. printf("\n Current WiFi dhcp client mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient^1);
  361. printf("\n Please input WiFi mode: ");
  362. scanf("%s", &cmd[0]);
  363. ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
  364. }
  365. else if(strcmp(cmd, "wificssid") == 0)
  366. {
  367. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  368. printf("\n *************************************************");
  369. printf("\n Current WiFi client SSID: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
  370. printf("\n 0: Keep current config.");
  371. printf("\n 1: Input new WiFi client SSID.");
  372. printf("\n *************************************************");
  373. printf("\n Please input operation item: ");
  374. scanf("%s", &cmd[0]);
  375. if(atoi(cmd) == 1)
  376. {
  377. printf("\n Please input WiFi client SSID: ");
  378. scanf("%s", &cmd[0]);
  379. memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid));
  380. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], (char*)&cmd[0]);
  381. }
  382. }
  383. else if(strcmp(cmd, "wificpasswd") == 0)
  384. {
  385. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  386. printf("\n *************************************************");
  387. printf("\n Current WiFi client password: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
  388. printf("\n 0: Keep current config.");
  389. printf("\n 1: Input new WiFi client password.");
  390. printf("\n *************************************************");
  391. printf("\n Please input operation item: ");
  392. scanf("%s", &cmd[0]);
  393. if(atoi(cmd) == 1)
  394. {
  395. printf("\n Please input WiFi client password: ");
  396. scanf("%s", &cmd[0]);
  397. memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword));
  398. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], (char*)&cmd[0]);
  399. }
  400. }
  401. else if(strcmp(cmd, "telemode") == 0)
  402. {
  403. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  404. printf("\n *************************************************");
  405. printf("\n 0: Disable.");
  406. printf("\n 1: Enable.");
  407. printf("\n *************************************************");
  408. printf("\n Current telecomm mode: %d", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode^1);
  409. printf("\n Please input telecomm mode: ");
  410. scanf("%s", &cmd[0]);
  411. ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
  412. }
  413. else if(strcmp(cmd, "teleapn") == 0)
  414. {
  415. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  416. printf("\n *************************************************");
  417. printf("\n Current telecomm APN: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
  418. printf("\n 0: Keep current config.");
  419. printf("\n 1: Input new telecomm APN.");
  420. printf("\n *************************************************");
  421. printf("\n Please input operation item: ");
  422. scanf("%s", &cmd[0]);
  423. if(atoi(cmd) == 1)
  424. {
  425. printf("\n Please input telecomm APN: ");
  426. scanf("%s", &cmd[0]);
  427. memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn));
  428. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], (char*)&cmd[0]);
  429. }
  430. }
  431. else if(strcmp(cmd, "teleid") == 0)
  432. {
  433. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  434. printf("\n *************************************************");
  435. printf("\n Current telecomm login id: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId);
  436. printf("\n 0: Keep current config.");
  437. printf("\n 1: Input new telecomm login id.");
  438. printf("\n *************************************************");
  439. printf("\n Please input operation item: ");
  440. scanf("%s", &cmd[0]);
  441. if(atoi(cmd) == 1)
  442. {
  443. printf("\n Please input telecomm login id: ");
  444. scanf("%s", &cmd[0]);
  445. memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId));
  446. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], (char*)&cmd[0]);
  447. }
  448. }
  449. else if(strcmp(cmd, "telepwd") == 0)
  450. {
  451. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  452. printf("\n *************************************************");
  453. printf("\n Current telecomm login password: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd);
  454. printf("\n 0: Keep current config.");
  455. printf("\n 1: Input new telecomm login password.");
  456. printf("\n *************************************************");
  457. printf("\n Please input operation item: ");
  458. scanf("%s", &cmd[0]);
  459. if(atoi(cmd) == 1)
  460. {
  461. printf("\n Please input telecomm login password: ");
  462. scanf("%s", &cmd[0]);
  463. memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd));
  464. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], (char*)&cmd[0]);
  465. }
  466. }
  467. }
  468. else if(strcmp(cmd, "test") == 0)
  469. {
  470. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  471. printf("\n ***** test menu ******************");
  472. printf("\n start: EVSE start charging request.");
  473. printf("\n stop: EVSE stop charging request.");
  474. printf("\n cancel: return to main menu.");
  475. printf("\n *************************************************");
  476. printf("\n Please input operation item: ");
  477. scanf("%s", &cmd[0]);
  478. if(strcmp(cmd, "start") == 0)
  479. {
  480. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  481. printf("\n Please input gun index(1~2): ");
  482. scanf("%s", &cmd[0]);
  483. if((0 < atoi(cmd)) && (atoi(cmd) < 3))
  484. {
  485. ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStart = ON;
  486. }
  487. else
  488. {
  489. printf("\n Invalid input gun_index.");
  490. }
  491. }
  492. else if(strcmp(cmd, "stop") == 0)
  493. {
  494. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  495. printf("\n Please input gun index(1~2): ");
  496. scanf("%s", &cmd[0]);
  497. if((0 < atoi(cmd)) && (atoi(cmd) < 3))
  498. {
  499. ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStop = ON;
  500. }
  501. else
  502. {
  503. printf("\n Invalid input gun_index.");
  504. }
  505. }
  506. else if(strcmp(cmd, "cancel") == 0)
  507. {}
  508. }
  509. else if(strcmp(cmd, "upgrade") == 0)
  510. {
  511. printf("\n Firmware upgrade trigger.");
  512. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = ON;
  513. sleep(2);
  514. }
  515. else if(strcmp(cmd, "save") == 0)
  516. {
  517. if(StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig) != PASS)
  518. {
  519. printf("\n Write configuration fail.\r\n");
  520. }
  521. else
  522. printf("\n Write configuration OK.\r\n");
  523. sleep(2);
  524. }
  525. else if(strcmp(cmd, "exit") == 0)
  526. {
  527. printf("\n exit program.\n\n");
  528. return FAIL;
  529. }
  530. }
  531. return -1;
  532. }