Module_ConfigTools.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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. #include "main.h"
  39. //=================================
  40. // System basic sample constant
  41. //=================================
  42. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  43. #define PASS 1
  44. #define FAIL -1
  45. #define YES 1
  46. #define NO 0
  47. #define ON 1
  48. #define OFF 0
  49. #define MtdBlockSize 0x300000
  50. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  51. struct StatusCodeData *ShmStatusCodeData;
  52. struct OCPP16Data *ShmOCPP16Data;
  53. struct Charger *ShmCharger;
  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=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);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. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  158. result = FAIL;
  159. }
  160. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  161. {
  162. DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
  163. result = FAIL;
  164. }
  165. else
  166. {}
  167. //Initial ShmStatusCodeData
  168. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  169. {
  170. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  171. result = FAIL;
  172. }
  173. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  174. {
  175. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  176. result = FAIL;
  177. }
  178. else
  179. {}
  180. //Initial ShmOCPP16Data
  181. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  182. {
  183. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  184. result = FAIL;
  185. }
  186. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  187. {
  188. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  189. result = FAIL;
  190. }
  191. else
  192. {}
  193. //Initial ShmCharger
  194. if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
  195. {
  196. DEBUG_ERROR("shmget ShmCharger NG\n");
  197. result = FAIL;
  198. }
  199. else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  200. {
  201. DEBUG_ERROR("shmat ShmCharger NG\n");
  202. result = FAIL;
  203. }
  204. else
  205. {}
  206. return result;
  207. }
  208. int main(void)
  209. {
  210. char cmd[128];
  211. if(InitShareMemory() == FAIL)
  212. {
  213. #ifdef SystemLogMessage
  214. DEBUG_ERROR("InitShareMemory NG\n");
  215. #endif
  216. if(ShmStatusCodeData!=NULL)
  217. {
  218. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  219. }
  220. sleep(5);
  221. return 0;
  222. }
  223. else
  224. {
  225. DEBUG_INFO("InitShareMemory OK.\n");
  226. }
  227. for(;;)
  228. {
  229. system("clear");
  230. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  231. printf("\n ===== main menu ==================================");
  232. printf("\n system: system configuration menu.");
  233. printf("\n ocpp: ocpp configuration menu.");
  234. printf("\n network: netwok configuration menu.");
  235. printf("\n test: charger start/stop test.");
  236. printf("\n upgrade: trigger firmware upgrade.");
  237. printf("\n save: Save config.");
  238. printf("\n exit: Exit config tools.");
  239. printf("\n ==================================================");
  240. printf("\n Please input item name to config: ");
  241. scanf("%s", &cmd[0]);
  242. if(strcmp(cmd, "system") == 0)
  243. {
  244. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  245. printf("\n ***** system configuration menu ******************");
  246. printf("\n modelname: EVSE model name.");
  247. printf("\n serialnumber: EVSE serial number.");
  248. printf("\n authentication: Authentication function.");
  249. printf("\n rfidendian: RFID read endian.");
  250. printf("\n **************************************************");
  251. printf("\n Please input operation item: ");
  252. scanf("%s", &cmd[0]);
  253. if(strcmp(cmd, "modelname") == 0)
  254. {
  255. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  256. printf("\n ***** modelname **********************************");
  257. printf("\n Current model name: %s", ShmSysConfigAndInfo->SysConfig.ModelName);
  258. printf("\n 0: Keep current config.");
  259. printf("\n 1: Input new model name.");
  260. printf("\n **************************************************");
  261. printf("\n Please input operation item: ");
  262. scanf("%s", &cmd[0]);
  263. if(atoi(cmd) == 1)
  264. {
  265. printf("\n Please input model name: ");
  266. scanf("%s", &cmd[0]);
  267. memset(&ShmSysConfigAndInfo->SysConfig.ModelName[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
  268. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ModelName[0], (char*)&cmd[0]);
  269. DEBUG_INFO("Input model name: %s\n", ShmSysConfigAndInfo->SysConfig.ModelName);
  270. }
  271. }
  272. else if(strcmp(cmd, "serialnumber") == 0)
  273. {
  274. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  275. printf("\n ***** serialnumber *******************************");
  276. printf("\n Current serial number: %s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  277. printf("\n 0: Keep current config.");
  278. printf("\n 1: Input new serial number.");
  279. printf("\n **************************************************");
  280. printf("\n Please input operation item: ");
  281. scanf("%s", &cmd[0]);
  282. if(atoi(cmd) == 1)
  283. {
  284. printf("\n Please input serial number: ");
  285. scanf("%s", &cmd[0]);
  286. memset(&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
  287. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], (char*)&cmd[0]);
  288. DEBUG_INFO("Input serial number: %s\n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  289. }
  290. }
  291. else if(strcmp(cmd, "authentication") == 0)
  292. {
  293. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  294. printf("\n ***** authentication *****************************");
  295. printf("\n Current mode: %d", ShmSysConfigAndInfo->SysConfig.AuthorisationMode);
  296. printf("\n 0: Enable.");
  297. printf("\n 1: Disable.");
  298. printf("\n **************************************************");
  299. printf("\n Please input authentication mode: ");
  300. scanf("%s", &cmd[0]);
  301. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
  302. if(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
  303. DEBUG_INFO("Authentication: Disable\n");
  304. else
  305. DEBUG_INFO("Authentication: Enable\n");
  306. }
  307. else if(strcmp(cmd, "rfidendian") == 0)
  308. {
  309. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  310. printf("\n ***** rfidendian *********************************");
  311. printf("\n Current mode: %d", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
  312. printf("\n 0: Little endian.");
  313. printf("\n 1: Big endian.");
  314. printf("\n **************************************************");
  315. printf("\n Please input rfid endian mode: ");
  316. scanf("%s", &cmd[0]);
  317. ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
  318. if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
  319. DEBUG_INFO("Authentication: Little endian\n");
  320. else
  321. DEBUG_INFO("Authentication: Big endian\n");
  322. }
  323. }
  324. else if(strcmp(cmd, "ocpp") == 0)
  325. {
  326. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  327. printf("\n ***** ocpp ***************************************");
  328. printf("\n ocppurl: OCPP backend server url.");
  329. printf("\n cboxid: Charger box id.");
  330. printf("\n vender: Charger point vender.");
  331. printf("\n offlinepolicy: Charger off line policy.");
  332. printf("\n localloadbalance: Charger local load balance.");
  333. printf("\n **************************************************");
  334. printf("\n Please input operation item: ");
  335. scanf("%s", &cmd[0]);
  336. if(strcmp(cmd, "ocppurl") == 0)
  337. {
  338. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  339. printf("\n ***** ocppurl ************************************");
  340. printf("\n Current OCPP url: %s", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  341. printf("\n 0: Keep current config.");
  342. printf("\n 1: Input new ocpp url.");
  343. printf("\n **************************************************");
  344. printf("\n Please input operation item: ");
  345. scanf("%s", &cmd[0]);
  346. if(atoi(cmd) == 1)
  347. {
  348. printf("\n Please input ocpp url: ");
  349. scanf("%s", &cmd[0]);
  350. memset(&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  351. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], (char*)&cmd[0]);
  352. DEBUG_INFO("Input ocpp url: %s\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  353. }
  354. }
  355. else if(strcmp(cmd, "cboxid") == 0)
  356. {
  357. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  358. printf("\n ***** cboxid *************************************");
  359. printf("\n Current OCPP charger box id: %s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  360. printf("\n 0: Keep current config.");
  361. printf("\n 1: Input new charger box id.");
  362. printf("\n **************************************************");
  363. printf("\n Please input operation item: ");
  364. scanf("%s", &cmd[0]);
  365. if(atoi(cmd) == 1)
  366. {
  367. printf("\n Please input OCPP charger box id: ");
  368. scanf("%s", &cmd[0]);
  369. memset(&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
  370. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], (char*)&cmd[0]);
  371. DEBUG_INFO("Input ocpp charger box id: %s\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  372. }
  373. }
  374. else if(strcmp(cmd, "vender") == 0)
  375. {
  376. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  377. printf("\n ***** vender *************************************");
  378. printf("\n Current OCPP vender: %s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  379. printf("\n 0: Keep current config.");
  380. printf("\n 1: Input new charger box id.");
  381. printf("\n **************************************************");
  382. printf("\n Please input operation item: ");
  383. scanf("%s", &cmd[0]);
  384. if(atoi(cmd) == 1)
  385. {
  386. printf("\n Please input OCPP vender: ");
  387. scanf("%s", &cmd[0]);
  388. memset(&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  389. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], (char*)&cmd[0]);
  390. DEBUG_INFO("Input ocpp vender: %s\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  391. }
  392. }
  393. else if(strcmp(cmd, "offlinepolicy") == 0)
  394. {
  395. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  396. printf("\n ***** offlinepolicy ******************************");
  397. printf("\n Current off line policy: %d", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
  398. printf("\n 0: Local list.");
  399. printf("\n 2: Free charging.");
  400. printf("\n 3: Deny charging.");
  401. printf("\n **************************************************");
  402. printf("\n Please input off line policy mode: ");
  403. scanf("%s", &cmd[0]);
  404. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = ((0<=atoi(cmd))&&(atoi(cmd)<=3)&&(atoi(cmd)!=1)?atoi(cmd):0);
  405. switch(ShmSysConfigAndInfo->SysConfig.OfflinePolicy)
  406. {
  407. case 0:
  408. DEBUG_INFO("Off line policy: Local list.\n");
  409. break;
  410. case 2:
  411. DEBUG_INFO("Off line policy: Free charging.\n");
  412. break;
  413. case 3:
  414. DEBUG_INFO("Off line policy: Deny charging.\n");
  415. break;
  416. }
  417. }
  418. else if(strcmp(cmd, "localloadbalance") == 0)
  419. {
  420. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  421. printf("\n ***** localloadbalance ***************************");
  422. printf("\n Current local loading balance: %d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging);
  423. printf("\n 0: Disable.");
  424. printf("\n 1: Enable.");
  425. printf("\n **************************************************");
  426. printf("\n Please input local load balance mode: ");
  427. scanf("%s", &cmd[0]);
  428. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
  429. if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
  430. DEBUG_INFO("Local loading balance: Enable\n");
  431. else
  432. DEBUG_INFO("Local loading balance: Disable\n");
  433. }
  434. }
  435. else if(strcmp(cmd, "network") == 0)
  436. {
  437. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  438. printf("\n ***** network *************************************");
  439. printf("\n ethdhcp: Ethernet DHCP client.");
  440. printf("\n wifimode: WiFi mode.");
  441. printf("\n wifidhcp: WiFi DHCP client.");
  442. printf("\n wificssid: WiFi client SSID.");
  443. printf("\n wificpasswd: WiFi client password.");
  444. printf("\n telemode: Telecomm mode.");
  445. printf("\n teleapn: Telecomm APN.");
  446. printf("\n teleid: Telecomm login id.");
  447. printf("\n telepwd: Telecomm login password.");
  448. printf("\n **************************************************");
  449. printf("\n Please input operation item: ");
  450. scanf("%s", &cmd[0]);
  451. if(strcmp(cmd, "ethdhcp") == 0)
  452. {
  453. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  454. printf("\n ***** ethdhcp ************************************");
  455. printf("\n Current ethernet dhcp mode: %d", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient^1);
  456. printf("\n 0: Disable.");
  457. printf("\n 1: Enable.");
  458. printf("\n **************************************************");
  459. printf("\n Please input dhcp mode: ");
  460. scanf("%s", &cmd[0]);
  461. ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
  462. if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient)
  463. DEBUG_INFO("Ethernet dhcp client: Disable\n");
  464. else
  465. DEBUG_INFO("Ethernet dhcp client: Enable\n");
  466. }
  467. else if(strcmp(cmd, "wifimode") == 0)
  468. {
  469. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  470. printf("\n ***** wifimode ***********************************");
  471. printf("\n Current WiFi mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
  472. printf("\n 0: Disable.");
  473. printf("\n 1: Station.");
  474. printf("\n 2: Access point.");
  475. printf("\n **************************************************");
  476. printf("\n Please input WiFi mode: ");
  477. scanf("%s", &cmd[0]);
  478. ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode = ((0<=atoi(cmd))&&(atoi(cmd)<=2)?atoi(cmd):0);
  479. switch(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode)
  480. {
  481. case 0:
  482. DEBUG_INFO("Wifi mode: Disable.\n");
  483. break;
  484. case 1:
  485. DEBUG_INFO("Wifi mode: Station.\n");
  486. break;
  487. case 2:
  488. DEBUG_INFO("Wifi mode: AP.\n");
  489. break;
  490. }
  491. }
  492. else if(strcmp(cmd, "wifidhcp") == 0)
  493. {
  494. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  495. printf("\n ***** wifidhcp ***********************************");
  496. printf("\n Current WiFi dhcp client mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient^1);
  497. printf("\n 0: Disable.");
  498. printf("\n 1: Enable.");
  499. printf("\n **************************************************");
  500. printf("\n Please input WiFi mode: ");
  501. scanf("%s", &cmd[0]);
  502. ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
  503. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient)
  504. DEBUG_INFO("Wifi dhcp client: Disable\n");
  505. else
  506. DEBUG_INFO("Wifi dhcp client: Enable\n");
  507. }
  508. else if(strcmp(cmd, "wificssid") == 0)
  509. {
  510. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  511. printf("\n ***** wificssid **********************************");
  512. printf("\n Current WiFi client SSID: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
  513. printf("\n 0: Keep current config.");
  514. printf("\n 1: Input new WiFi client SSID.");
  515. printf("\n **************************************************");
  516. printf("\n Please input operation item: ");
  517. scanf("%s", &cmd[0]);
  518. if(atoi(cmd) == 1)
  519. {
  520. printf("\n Please input WiFi client SSID: ");
  521. scanf("%s", &cmd[0]);
  522. memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid));
  523. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], (char*)&cmd[0]);
  524. DEBUG_INFO("Wifi client SSID: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
  525. }
  526. }
  527. else if(strcmp(cmd, "wificpasswd") == 0)
  528. {
  529. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  530. printf("\n ***** wificpasswd ********************************");
  531. printf("\n Current WiFi client password: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
  532. printf("\n 0: Keep current config.");
  533. printf("\n 1: Input new WiFi client password.");
  534. printf("\n **************************************************");
  535. printf("\n Please input operation item: ");
  536. scanf("%s", &cmd[0]);
  537. if(atoi(cmd) == 1)
  538. {
  539. printf("\n Please input WiFi client password: ");
  540. scanf("%s", &cmd[0]);
  541. memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword));
  542. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], (char*)&cmd[0]);
  543. DEBUG_INFO("Wifi client password: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
  544. }
  545. }
  546. else if(strcmp(cmd, "telemode") == 0)
  547. {
  548. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  549. printf("\n ***** telemode ***********************************");
  550. printf("\n 0: Disable.");
  551. printf("\n 1: Enable.");
  552. printf("\n **************************************************");
  553. printf("\n Current telecomm mode: %d", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode^1);
  554. printf("\n Please input telecomm mode: ");
  555. scanf("%s", &cmd[0]);
  556. ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
  557. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode)
  558. DEBUG_INFO("Wifi dhcp client: Disable\n");
  559. else
  560. DEBUG_INFO("Wifi dhcp client: Enable\n");
  561. }
  562. else if(strcmp(cmd, "teleapn") == 0)
  563. {
  564. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  565. printf("\n ***** teleapn ************************************");
  566. printf("\n Current telecomm APN: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
  567. printf("\n 0: Keep current config.");
  568. printf("\n 1: Input new telecomm APN.");
  569. printf("\n **************************************************");
  570. printf("\n Please input operation item: ");
  571. scanf("%s", &cmd[0]);
  572. if(atoi(cmd) == 1)
  573. {
  574. printf("\n Please input telecomm APN: ");
  575. scanf("%s", &cmd[0]);
  576. memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn));
  577. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], (char*)&cmd[0]);
  578. DEBUG_INFO("Telecomm APN: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
  579. }
  580. }
  581. else if(strcmp(cmd, "teleid") == 0)
  582. {
  583. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  584. printf("\n ***** teleid *************************************");
  585. printf("\n Current telecomm login id: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId);
  586. printf("\n 0: Keep current config.");
  587. printf("\n 1: Input new telecomm login id.");
  588. printf("\n **************************************************");
  589. printf("\n Please input operation item: ");
  590. scanf("%s", &cmd[0]);
  591. if(atoi(cmd) == 1)
  592. {
  593. printf("\n Please input telecomm login id: ");
  594. scanf("%s", &cmd[0]);
  595. memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId));
  596. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], (char*)&cmd[0]);
  597. DEBUG_INFO("Telecomm CHAP id: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId);
  598. }
  599. }
  600. else if(strcmp(cmd, "telepwd") == 0)
  601. {
  602. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  603. printf("\n ***** telepwd ************************************");
  604. printf("\n Current telecomm login password: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd);
  605. printf("\n 0: Keep current config.");
  606. printf("\n 1: Input new telecomm login password.");
  607. printf("\n **************************************************");
  608. printf("\n Please input operation item: ");
  609. scanf("%s", &cmd[0]);
  610. if(atoi(cmd) == 1)
  611. {
  612. printf("\n Please input telecomm login password: ");
  613. scanf("%s", &cmd[0]);
  614. memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd));
  615. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], (char*)&cmd[0]);
  616. DEBUG_INFO("Telecomm CHAP password: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd);
  617. }
  618. }
  619. }
  620. else if(strcmp(cmd, "test") == 0)
  621. {
  622. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  623. printf("\n ***** test menu **********************************");
  624. printf("\n start: EVSE start charging request.");
  625. printf("\n stop: EVSE stop charging request.");
  626. printf("\n auth: Authorize request.");
  627. printf("\n ccs: CCS flow status.");
  628. printf("\n alarm: Simulate alarm status.");
  629. printf("\n cancel: return to main menu.");
  630. printf("\n **************************************************");
  631. printf("\n Please input operation item: ");
  632. scanf("%s", &cmd[0]);
  633. if(strcmp(cmd, "start") == 0)
  634. {
  635. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  636. printf("\n Please input gun index(1~2): ");
  637. scanf("%s", &cmd[0]);
  638. if((0 < atoi(cmd)) && (atoi(cmd) < 3))
  639. {
  640. ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStart = ON;
  641. DEBUG_INFO("Test start gun-%d, start charging session.\n", atoi(cmd));
  642. }
  643. else
  644. {
  645. printf("\n Invalid input gun_index.");
  646. }
  647. }
  648. else if(strcmp(cmd, "stop") == 0)
  649. {
  650. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  651. printf("\n Please input gun index(1~2): ");
  652. scanf("%s", &cmd[0]);
  653. if((0 < atoi(cmd)) && (atoi(cmd) < 3))
  654. {
  655. ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStop = ON;
  656. DEBUG_INFO("Test start gun-%d, stop charging session.\n", atoi(cmd));
  657. }
  658. else
  659. {
  660. printf("\n Invalid input gun_index.");
  661. }
  662. }
  663. else if(strcmp(cmd, "auth") == 0)
  664. {
  665. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  666. printf("\n Please input idtag: ");
  667. scanf("%s", &cmd[0]);
  668. sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%s", cmd);
  669. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
  670. DEBUG_INFO("Test authentication by %s.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  671. }
  672. else if(strcmp(cmd, "ccs") == 0)
  673. {
  674. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  675. printf("\n Please input gun index(1~2): ");
  676. scanf("%s", &cmd[0]);
  677. if((0 < atoi(cmd)) && (atoi(cmd) < 3))
  678. {
  679. uint8_t gun_index = atoi(cmd)-1;
  680. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  681. printf("\n ***** ccs ****************************************");
  682. printf("\n ccs_hs_status: CCS hand shake status.");
  683. printf("\n cancel: return to main menu.");
  684. printf("\n **************************************************");
  685. printf("\n Please input operation item: ");
  686. scanf("%s", &cmd[0]);
  687. if(strcmp(cmd, "ccs_hs_status") == 0)
  688. {
  689. printf("\n ***** ccs_hs_status *******************************");
  690. printf("\n Current ccs_hs_status: %d", ShmCharger->gun_info[gun_index].ccsHandshakeState);
  691. printf("\n 1: HANDSHAKE_DUTY_5.");
  692. printf("\n 2: HANDSHAKE_DUTY_5_CHECK.");
  693. printf("\n 3: HANDSHAKE_CCS.");
  694. printf("\n 4: HANDSHAKE_CP_STATE_E.");
  695. printf("\n 5: HANDSHAKE_SET_MAX_CURRENT.");
  696. printf("\n 6: HANDSHAKE_BS_MODE.");
  697. printf("\n 7: HANDSHAKE_HLC_MODE.");
  698. printf("\n **************************************************");
  699. printf("\n Please input operation item: ");
  700. scanf("%s", &cmd[0]);
  701. if((0 < atoi(cmd)) && (atoi(cmd) < 9))
  702. {
  703. ShmCharger->gun_info[gun_index].ccsHandshakeState = atoi(cmd);
  704. DEBUG_INFO("Gun-%d CCS hand shake state: %d.\n", gun_index, ShmCharger->gun_info[gun_index].ccsHandshakeState);
  705. }
  706. else
  707. printf("\n Invalid hand shake state.");
  708. }
  709. }
  710. else
  711. {
  712. printf("\n Invalid input gun_index.");
  713. }
  714. }
  715. else if(strcmp(cmd, "alarm") == 0)
  716. {
  717. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  718. printf("\n Please input gun index(1~2): ");
  719. scanf("%s", &cmd[0]);
  720. if((0 < atoi(cmd)) && (atoi(cmd) < 3))
  721. {
  722. ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStart = ON;
  723. DEBUG_INFO("Alarm simulate gun-%d, OVP.\n", atoi(cmd));
  724. }
  725. else
  726. {
  727. printf("\n Invalid input gun_index.");
  728. }
  729. while(1)
  730. {
  731. ShmCharger->gun_info[atoi(cmd)-1].systemAlarmCode.SystemAlarmCode |= ALARM_L1_OVER_VOLTAGE;
  732. ShmCharger->gun_info[atoi(cmd)-1].primaryMcuAlarm.InputAlarmCode |= ALARM_L1_OVER_VOLTAGE;
  733. }
  734. }
  735. else if(strcmp(cmd, "cancel") == 0)
  736. {}
  737. }
  738. else if(strcmp(cmd, "upgrade") == 0)
  739. {
  740. printf("\n Firmware upgrade trigger.");
  741. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = ON;
  742. DEBUG_INFO("Trigger firmware upgrade.\n");
  743. sleep(2);
  744. }
  745. else if(strcmp(cmd, "save") == 0)
  746. {
  747. if(StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig) != PASS)
  748. {
  749. printf("\n Write configuration fail.\r\n");
  750. }
  751. else
  752. {
  753. printf("\n Write configuration OK.\r\n");
  754. DEBUG_INFO("Save configuration.\n");
  755. }
  756. sleep(2);
  757. }
  758. else if(strcmp(cmd, "exit") == 0)
  759. {
  760. printf("\n exit program.\n\n");
  761. DEBUG_INFO("Exit configuration tools.\n");
  762. return FAIL;
  763. }
  764. }
  765. return -1;
  766. }