Module_ConfigTools.c 33 KB

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