Module_ConfigTools.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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 ocppsecurity: OCPP backend server security profile.");
  330. printf("\n mtserverurl: Maintain backend server url.");
  331. printf("\n cboxid: Charger box id.");
  332. printf("\n vender: Charger point vender.");
  333. printf("\n offlinepolicy: Charger off line policy.");
  334. printf("\n localloadbalance: Charger local load balance.");
  335. printf("\n maintainurl: Maintain server url.");
  336. printf("\n maintainsecurity: Maintain server security profile.");
  337. printf("\n **************************************************");
  338. printf("\n Please input operation item: ");
  339. scanf("%s", &cmd[0]);
  340. if(strcmp(cmd, "ocppurl") == 0)
  341. {
  342. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  343. printf("\n ***** ocppurl ************************************");
  344. printf("\n Current OCPP url: %s", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  345. printf("\n 0: Keep current config.");
  346. printf("\n 1: Input new ocpp url.");
  347. printf("\n **************************************************");
  348. printf("\n Please input operation item: ");
  349. scanf("%s", &cmd[0]);
  350. if(atoi(cmd) == 1)
  351. {
  352. printf("\n Please input ocpp url: ");
  353. scanf("%s", &cmd[0]);
  354. memset(&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  355. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], (char*)&cmd[0]);
  356. DEBUG_INFO("Input ocpp url: %s\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  357. }
  358. }
  359. if(strcmp(cmd, "mtserverurl") == 0)
  360. {
  361. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  362. printf("\n ***** mtserverurl *********************************");
  363. printf("\n Current maintain server url: %s", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  364. printf("\n 0: Keep current config.");
  365. printf("\n 1: Input new ocpp url.");
  366. printf("\n **************************************************");
  367. printf("\n Please input operation item: ");
  368. scanf("%s", &cmd[0]);
  369. if(atoi(cmd) == 1)
  370. {
  371. printf("\n Please input maintain server url: ");
  372. scanf("%s", &cmd[0]);
  373. memset(&ShmSysConfigAndInfo->SysConfig.MaintainServerURL[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  374. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL[0], (char*)&cmd[0]);
  375. DEBUG_INFO("Input maintain server url: %s\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  376. }
  377. }
  378. else if(strcmp(cmd, "ocppsecurity") == 0)
  379. {
  380. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  381. printf("\n ***** ocppsecurity *******************************");
  382. printf("\n Current OCPP security profile: %d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  383. printf("\n 0: Profile-0.");
  384. printf("\n 1: Profile-1.");
  385. printf("\n 2: Profile-2.");
  386. printf("\n 3: Profile-3.");
  387. printf("\n **************************************************");
  388. printf("\n Please input OCPP security profile: ");
  389. scanf("%s", &cmd[0]);
  390. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = ((0<=atoi(cmd))&&(atoi(cmd)<=3)&&(atoi(cmd)!=1)?atoi(cmd):0);
  391. DEBUG_INFO("OCPP security profile: %d.\n");
  392. }
  393. else if(strcmp(cmd, "cboxid") == 0)
  394. {
  395. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  396. printf("\n ***** cboxid *************************************");
  397. printf("\n Current OCPP charger box id: %s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  398. printf("\n 0: Keep current config.");
  399. printf("\n 1: Input new charger box id.");
  400. printf("\n **************************************************");
  401. printf("\n Please input operation item: ");
  402. scanf("%s", &cmd[0]);
  403. if(atoi(cmd) == 1)
  404. {
  405. printf("\n Please input OCPP charger box id: ");
  406. scanf("%s", &cmd[0]);
  407. memset(&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
  408. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], (char*)&cmd[0]);
  409. DEBUG_INFO("Input ocpp charger box id: %s\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  410. }
  411. }
  412. else if(strcmp(cmd, "vender") == 0)
  413. {
  414. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  415. printf("\n ***** vender *************************************");
  416. printf("\n Current OCPP vender: %s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  417. printf("\n 0: Keep current config.");
  418. printf("\n 1: Input new charger box id.");
  419. printf("\n **************************************************");
  420. printf("\n Please input operation item: ");
  421. scanf("%s", &cmd[0]);
  422. if(atoi(cmd) == 1)
  423. {
  424. printf("\n Please input OCPP vender: ");
  425. scanf("%s", &cmd[0]);
  426. memset(&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  427. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], (char*)&cmd[0]);
  428. DEBUG_INFO("Input ocpp vender: %s\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  429. }
  430. }
  431. else if(strcmp(cmd, "offlinepolicy") == 0)
  432. {
  433. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  434. printf("\n ***** offlinepolicy ******************************");
  435. printf("\n Current off line policy: %d", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
  436. printf("\n 0: Local list.");
  437. printf("\n 2: Free charging.");
  438. printf("\n 3: Deny charging.");
  439. printf("\n **************************************************");
  440. printf("\n Please input off line policy mode: ");
  441. scanf("%s", &cmd[0]);
  442. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = ((0<=atoi(cmd))&&(atoi(cmd)<=3)&&(atoi(cmd)!=1)?atoi(cmd):0);
  443. switch(ShmSysConfigAndInfo->SysConfig.OfflinePolicy)
  444. {
  445. case 0:
  446. DEBUG_INFO("Off line policy: Local list.\n");
  447. break;
  448. case 2:
  449. DEBUG_INFO("Off line policy: Free charging.\n");
  450. break;
  451. case 3:
  452. DEBUG_INFO("Off line policy: Deny charging.\n");
  453. break;
  454. }
  455. }
  456. else if(strcmp(cmd, "localloadbalance") == 0)
  457. {
  458. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  459. printf("\n ***** localloadbalance ***************************");
  460. printf("\n Current local loading balance: %d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging);
  461. printf("\n 0: Disable.");
  462. printf("\n 1: Enable.");
  463. printf("\n **************************************************");
  464. printf("\n Please input local load balance mode: ");
  465. scanf("%s", &cmd[0]);
  466. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
  467. if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
  468. DEBUG_INFO("Local loading balance: Enable\n");
  469. else
  470. DEBUG_INFO("Local loading balance: Disable\n");
  471. }
  472. else if(strcmp(cmd, "maintainurl") == 0)
  473. {
  474. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  475. printf("\n ***** maintainurl *********************************");
  476. printf("\n Current maintain url: %s", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  477. printf("\n 0: Keep current config.");
  478. printf("\n 1: Input new maintain url.");
  479. printf("\n **************************************************");
  480. printf("\n Please input operation item: ");
  481. scanf("%s", &cmd[0]);
  482. if(atoi(cmd) == 1)
  483. {
  484. printf("\n Please input maintain url: ");
  485. scanf("%s", &cmd[0]);
  486. memset(&ShmSysConfigAndInfo->SysConfig.MaintainServerURL[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  487. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL[0], (char*)&cmd[0]);
  488. DEBUG_INFO("Input maintain url: %s\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  489. }
  490. }
  491. else if(strcmp(cmd, "maintainsecurity") == 0)
  492. {
  493. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  494. printf("\n ***** maintainsecurity ****************************");
  495. printf("\n Current maintain security profile: %d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile);
  496. printf("\n 0: Profile-0.");
  497. printf("\n 1: Profile-1.");
  498. printf("\n 2: Profile-2.");
  499. printf("\n 3: Profile-3.");
  500. printf("\n **************************************************");
  501. printf("\n Please input maintain security profile: ");
  502. scanf("%s", &cmd[0]);
  503. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = ((0<=atoi(cmd))&&(atoi(cmd)<=3)&&(atoi(cmd)!=1)?atoi(cmd):0);
  504. DEBUG_INFO("Maintain security profile: %d.\n");
  505. }
  506. }
  507. else if(strcmp(cmd, "network") == 0)
  508. {
  509. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  510. printf("\n ***** network *************************************");
  511. printf("\n ethdhcp: Ethernet DHCP client.");
  512. printf("\n wifimode: WiFi mode.");
  513. printf("\n wifidhcp: WiFi DHCP client.");
  514. printf("\n wificssid: WiFi client SSID.");
  515. printf("\n wificpasswd: WiFi client password.");
  516. printf("\n telemode: Telecomm mode.");
  517. printf("\n teleapn: Telecomm APN.");
  518. printf("\n teleid: Telecomm login id.");
  519. printf("\n telepwd: Telecomm login password.");
  520. printf("\n **************************************************");
  521. printf("\n Please input operation item: ");
  522. scanf("%s", &cmd[0]);
  523. if(strcmp(cmd, "ethdhcp") == 0)
  524. {
  525. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  526. printf("\n ***** ethdhcp ************************************");
  527. printf("\n Current ethernet dhcp mode: %d", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient^1);
  528. printf("\n 0: Disable.");
  529. printf("\n 1: Enable.");
  530. printf("\n **************************************************");
  531. printf("\n Please input dhcp mode: ");
  532. scanf("%s", &cmd[0]);
  533. ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
  534. if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient)
  535. DEBUG_INFO("Ethernet dhcp client: Disable\n");
  536. else
  537. DEBUG_INFO("Ethernet dhcp client: Enable\n");
  538. }
  539. else if(strcmp(cmd, "wifimode") == 0)
  540. {
  541. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  542. printf("\n ***** wifimode ***********************************");
  543. printf("\n Current WiFi mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
  544. printf("\n 0: Disable.");
  545. printf("\n 1: Station.");
  546. printf("\n 2: Access point.");
  547. printf("\n **************************************************");
  548. printf("\n Please input WiFi mode: ");
  549. scanf("%s", &cmd[0]);
  550. ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode = ((0<=atoi(cmd))&&(atoi(cmd)<=2)?atoi(cmd):0);
  551. switch(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode)
  552. {
  553. case 0:
  554. DEBUG_INFO("Wifi mode: Disable.\n");
  555. break;
  556. case 1:
  557. DEBUG_INFO("Wifi mode: Station.\n");
  558. break;
  559. case 2:
  560. DEBUG_INFO("Wifi mode: AP.\n");
  561. break;
  562. }
  563. }
  564. else if(strcmp(cmd, "wifidhcp") == 0)
  565. {
  566. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  567. printf("\n ***** wifidhcp ***********************************");
  568. printf("\n Current WiFi dhcp client mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient^1);
  569. printf("\n 0: Disable.");
  570. printf("\n 1: Enable.");
  571. printf("\n **************************************************");
  572. printf("\n Please input WiFi mode: ");
  573. scanf("%s", &cmd[0]);
  574. ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
  575. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient)
  576. DEBUG_INFO("Wifi dhcp client: Disable\n");
  577. else
  578. DEBUG_INFO("Wifi dhcp client: Enable\n");
  579. }
  580. else if(strcmp(cmd, "wificssid") == 0)
  581. {
  582. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  583. printf("\n ***** wificssid **********************************");
  584. printf("\n Current WiFi client SSID: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
  585. printf("\n 0: Keep current config.");
  586. printf("\n 1: Input new WiFi client SSID.");
  587. printf("\n **************************************************");
  588. printf("\n Please input operation item: ");
  589. scanf("%s", &cmd[0]);
  590. if(atoi(cmd) == 1)
  591. {
  592. printf("\n Please input WiFi client SSID: ");
  593. scanf("%s", &cmd[0]);
  594. memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid));
  595. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], (char*)&cmd[0]);
  596. DEBUG_INFO("Wifi client SSID: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
  597. }
  598. }
  599. else if(strcmp(cmd, "wificpasswd") == 0)
  600. {
  601. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  602. printf("\n ***** wificpasswd ********************************");
  603. printf("\n Current WiFi client password: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
  604. printf("\n 0: Keep current config.");
  605. printf("\n 1: Input new WiFi client password.");
  606. printf("\n **************************************************");
  607. printf("\n Please input operation item: ");
  608. scanf("%s", &cmd[0]);
  609. if(atoi(cmd) == 1)
  610. {
  611. printf("\n Please input WiFi client password: ");
  612. scanf("%s", &cmd[0]);
  613. memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword));
  614. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], (char*)&cmd[0]);
  615. DEBUG_INFO("Wifi client password: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
  616. }
  617. }
  618. else if(strcmp(cmd, "telemode") == 0)
  619. {
  620. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  621. printf("\n ***** telemode ***********************************");
  622. printf("\n 0: Disable.");
  623. printf("\n 1: Enable.");
  624. printf("\n **************************************************");
  625. printf("\n Current telecomm mode: %d", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode^1);
  626. printf("\n Please input telecomm mode: ");
  627. scanf("%s", &cmd[0]);
  628. ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
  629. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode)
  630. DEBUG_INFO("Wifi dhcp client: Disable\n");
  631. else
  632. DEBUG_INFO("Wifi dhcp client: Enable\n");
  633. }
  634. else if(strcmp(cmd, "teleapn") == 0)
  635. {
  636. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  637. printf("\n ***** teleapn ************************************");
  638. printf("\n Current telecomm APN: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
  639. printf("\n 0: Keep current config.");
  640. printf("\n 1: Input new telecomm APN.");
  641. printf("\n **************************************************");
  642. printf("\n Please input operation item: ");
  643. scanf("%s", &cmd[0]);
  644. if(atoi(cmd) == 1)
  645. {
  646. printf("\n Please input telecomm APN: ");
  647. scanf("%s", &cmd[0]);
  648. memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn));
  649. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], (char*)&cmd[0]);
  650. DEBUG_INFO("Telecomm APN: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
  651. }
  652. }
  653. else if(strcmp(cmd, "teleid") == 0)
  654. {
  655. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  656. printf("\n ***** teleid *************************************");
  657. printf("\n Current telecomm login id: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId);
  658. printf("\n 0: Keep current config.");
  659. printf("\n 1: Input new telecomm login id.");
  660. printf("\n **************************************************");
  661. printf("\n Please input operation item: ");
  662. scanf("%s", &cmd[0]);
  663. if(atoi(cmd) == 1)
  664. {
  665. printf("\n Please input telecomm login id: ");
  666. scanf("%s", &cmd[0]);
  667. memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId));
  668. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], (char*)&cmd[0]);
  669. DEBUG_INFO("Telecomm CHAP id: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId);
  670. }
  671. }
  672. else if(strcmp(cmd, "telepwd") == 0)
  673. {
  674. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  675. printf("\n ***** telepwd ************************************");
  676. printf("\n Current telecomm login password: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd);
  677. printf("\n 0: Keep current config.");
  678. printf("\n 1: Input new telecomm login password.");
  679. printf("\n **************************************************");
  680. printf("\n Please input operation item: ");
  681. scanf("%s", &cmd[0]);
  682. if(atoi(cmd) == 1)
  683. {
  684. printf("\n Please input telecomm login password: ");
  685. scanf("%s", &cmd[0]);
  686. memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd));
  687. strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], (char*)&cmd[0]);
  688. DEBUG_INFO("Telecomm CHAP password: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd);
  689. }
  690. }
  691. }
  692. else if(strcmp(cmd, "test") == 0)
  693. {
  694. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  695. printf("\n ***** test menu **********************************");
  696. printf("\n start: EVSE start charging request.");
  697. printf("\n stop: EVSE stop charging request.");
  698. printf("\n auth: Authorize request.");
  699. printf("\n alarm: Simulate alarm status.");
  700. printf("\n cancel: return to main menu.");
  701. printf("\n **************************************************");
  702. printf("\n Please input operation item: ");
  703. scanf("%s", &cmd[0]);
  704. if(strcmp(cmd, "start") == 0)
  705. {
  706. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  707. printf("\n Please input gun index(1~2): ");
  708. scanf("%s", &cmd[0]);
  709. if((0 < atoi(cmd)) && (atoi(cmd) < 3))
  710. {
  711. ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStart = ON;
  712. DEBUG_INFO("Test start gun-%d, start charging session.\n", atoi(cmd));
  713. }
  714. else
  715. {
  716. printf("\n Invalid input gun_index.");
  717. }
  718. }
  719. else if(strcmp(cmd, "stop") == 0)
  720. {
  721. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  722. printf("\n Please input gun index(1~2): ");
  723. scanf("%s", &cmd[0]);
  724. if((0 < atoi(cmd)) && (atoi(cmd) < 3))
  725. {
  726. ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStop = ON;
  727. DEBUG_INFO("Test start gun-%d, stop charging session.\n", atoi(cmd));
  728. }
  729. else
  730. {
  731. printf("\n Invalid input gun_index.");
  732. }
  733. }
  734. else if(strcmp(cmd, "auth") == 0)
  735. {
  736. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  737. printf("\n Please input idtag: ");
  738. scanf("%s", &cmd[0]);
  739. sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%s", cmd);
  740. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
  741. DEBUG_INFO("Test authentication by %s.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  742. }
  743. else if(strcmp(cmd, "alarm") == 0)
  744. {
  745. memset(cmd, 0x00, ARRAY_SIZE(cmd));
  746. printf("\n Please input gun index(1~2): ");
  747. scanf("%s", &cmd[0]);
  748. if((0 < atoi(cmd)) && (atoi(cmd) < 3))
  749. {
  750. DEBUG_INFO("Alarm simulate gun-%d, OVP.\n", atoi(cmd));
  751. while(1)
  752. {
  753. ShmCharger->gun_info[atoi(cmd)-1].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
  754. ShmCharger->gun_info[atoi(cmd)-1].primaryMcuAlarm.InputAlarmCode |= ALARM_OVER_VOLTAGE;
  755. }
  756. }
  757. else
  758. {
  759. printf("\n Invalid input gun_index.");
  760. sleep(1);
  761. }
  762. }
  763. else if(strcmp(cmd, "cancel") == 0)
  764. {}
  765. }
  766. else if(strcmp(cmd, "upgrade") == 0)
  767. {
  768. printf("\n Firmware upgrade trigger.");
  769. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = ON;
  770. DEBUG_INFO("Trigger firmware upgrade.\n");
  771. sleep(2);
  772. }
  773. else if(strcmp(cmd, "save") == 0)
  774. {
  775. if(StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig) != PASS)
  776. {
  777. printf("\n Write configuration fail.\r\n");
  778. }
  779. else
  780. {
  781. printf("\n Write configuration OK.\r\n");
  782. DEBUG_INFO("Save configuration.\n");
  783. }
  784. sleep(2);
  785. }
  786. else if(strcmp(cmd, "exit") == 0)
  787. {
  788. printf("\n exit program.\n\n");
  789. DEBUG_INFO("Exit configuration tools.\n");
  790. return FAIL;
  791. }
  792. }
  793. return -1;
  794. }