123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949 |
- /*
- * Module_ConfigTools.c
- *
- * Created on: 2020¦~6¤ë22¤é
- * Author: foluswen
- */
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <dirent.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <termios.h>
- #include <errno.h>
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <stdbool.h>
- #include <stddef.h>
- #include <stdint.h>
- #include "define.h"
- #include "main.h"
- //=================================
- // System basic sample constant
- //=================================
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
- #define PASS 1
- #define FAIL -1
- #define YES 1
- #define NO 0
- #define ON 1
- #define OFF 0
- #define MtdBlockSize 0x300000
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct OCPP16Data *ShmOCPP16Data;
- struct Charger *ShmCharger;
- int StoreLogMsg(const char *fmt, ...)
- {
- char Buf[4096+256];
- char buffer[4096];
- time_t CurrentTime;
- struct tm *tm;
- struct timeval tv;
- va_list args;
- va_start(args, fmt);
- int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
- va_end(args);
- memset(Buf,0,sizeof(Buf));
- CurrentTime = time(NULL);
- tm=localtime(&CurrentTime);
- gettimeofday(&tv, NULL); // get microseconds, 10^-6
- sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]ConfigToolsLog",
- tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
- buffer,
- tm->tm_year+1900,tm->tm_mon+1);
- #ifdef SystemLogMessage
- system(Buf);
- #endif
- #ifdef ConsloePrintLog
- 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);
- #endif
- return rc;
- }
- int runShellCmd(const char*cmd)
- {
- int result = FAIL;
- char buf[256];
- FILE *fp;
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- DEBUG_INFO("%s\n", buf);
- }
- result = PASS;
- }
- pclose(fp);
- return result;
- }
- int StoreUsrConfigData(struct SysConfigData *UsrData)
- {
- int result = PASS;
- int fd,wrd;
- unsigned int i,Chk;
- unsigned char *ptr, *BufTmp;
- Chk=0;
- ptr=(unsigned char *)UsrData;
- if((BufTmp=malloc(MtdBlockSize))!=NULL)
- {
- memset(BufTmp,0,MtdBlockSize);
- memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
- for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
- Chk+=*(BufTmp+i);
- memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
- // Output configuration to file.
- fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
- if (fd < 0)
- {
- DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
- free(BufTmp);
- return 0;
- }
- wrd=write(fd, BufTmp, MtdBlockSize);
- close(fd);
- if(wrd<MtdBlockSize)
- {
- DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
- free(BufTmp);
- return 0;
- }
- DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
- DEBUG_INFO("Erase /dev/mtd10.\n");
- runShellCmd("flash_erase /dev/mtd10 0 0");
- DEBUG_INFO("Write /dev/mtd10.\n");
- runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
- DEBUG_INFO("Erase /dev/mtd11.\n");
- runShellCmd("flash_erase /dev/mtd11 0 0");
- DEBUG_INFO("Write /dev/mtd11.\n");
- runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
- system("rm -f /mnt/EvseConfig.bin");
- DEBUG_INFO("EvseConfig write to flash OK\n");
- }
- else
- {
- DEBUG_ERROR("alloc BlockSize NG\r\n");
- result = FAIL;
- }
- if(BufTmp!=NULL)
- free(BufTmp);
- return result;
- }
- int InitShareMemory()
- {
- int result = PASS;
- int MeterSMId;
- //Initial ShmSysConfigAndInfo
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
- result = FAIL;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
- result = FAIL;
- }
- else
- {}
- //Initial ShmStatusCodeData
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
- result = FAIL;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
- result = FAIL;
- }
- else
- {}
- //Initial ShmOCPP16Data
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
- result = FAIL;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
- result = FAIL;
- }
- else
- {}
- //Initial ShmCharger
- if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmCharger NG\n");
- result = FAIL;
- }
- else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmCharger NG\n");
- result = FAIL;
- }
- else
- {}
- return result;
- }
- int main(void)
- {
- char cmd[128];
- if(InitShareMemory() == FAIL)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("InitShareMemory NG\n");
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
- }
- sleep(5);
- return 0;
- }
- else
- {
- DEBUG_INFO("InitShareMemory OK.\n");
- }
- for(;;)
- {
- system("clear");
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ===== main menu ==================================");
- printf("\n system: system configuration menu.");
- printf("\n ocpp: ocpp configuration menu.");
- printf("\n network: netwok configuration menu.");
- printf("\n test: charger start/stop test.");
- printf("\n upgrade: trigger firmware upgrade.");
- printf("\n save: Save config.");
- printf("\n exit: Exit config tools.");
- printf("\n ==================================================");
- printf("\n Please input item name to config: ");
- scanf("%s", &cmd[0]);
- if(strcmp(cmd, "system") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** system configuration menu ******************");
- printf("\n modelname: EVSE model name.");
- printf("\n serialnumber: EVSE serial number.");
- printf("\n authentication: Authentication function.");
- printf("\n rfidendian: RFID read endian.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(strcmp(cmd, "modelname") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** modelname **********************************");
- printf("\n Current model name: %s", ShmSysConfigAndInfo->SysConfig.ModelName);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new model name.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input model name: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.ModelName[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ModelName[0], (char*)&cmd[0]);
- DEBUG_INFO("Input model name: %s\n", ShmSysConfigAndInfo->SysConfig.ModelName);
- }
- }
- else if(strcmp(cmd, "serialnumber") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** serialnumber *******************************");
- printf("\n Current serial number: %s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new serial number.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input serial number: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], (char*)&cmd[0]);
- DEBUG_INFO("Input serial number: %s\n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
- }
- }
- else if(strcmp(cmd, "authentication") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** authentication *****************************");
- printf("\n Current mode: %d", ShmSysConfigAndInfo->SysConfig.AuthorisationMode);
- printf("\n 0: Enable.");
- printf("\n 1: Disable.");
- printf("\n **************************************************");
- printf("\n Please input authentication mode: ");
- scanf("%s", &cmd[0]);
- ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
- if(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
- DEBUG_INFO("Authentication: Disable\n");
- else
- DEBUG_INFO("Authentication: Enable\n");
- }
- else if(strcmp(cmd, "rfidendian") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** rfidendian *********************************");
- printf("\n Current mode: %d", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
- printf("\n 0: Little endian.");
- printf("\n 1: Big endian.");
- printf("\n **************************************************");
- printf("\n Please input rfid endian mode: ");
- scanf("%s", &cmd[0]);
- ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
- if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
- DEBUG_INFO("Authentication: Little endian\n");
- else
- DEBUG_INFO("Authentication: Big endian\n");
- }
- }
- else if(strcmp(cmd, "ocpp") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** ocpp ***************************************");
- printf("\n ocppurl: OCPP backend server url.");
- printf("\n ocppsecurity: OCPP backend server security profile.");
- printf("\n mtserverurl: Maintain backend server url.");
- printf("\n cboxid: Charger box id.");
- printf("\n vender: Charger point vender.");
- printf("\n offlinepolicy: Charger off line policy.");
- printf("\n localpowersharing: Charger local load balance.");
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing == 1)
- {
- printf("\n powersharingcapacity: Power Sharing Capacity.");
- }
- else if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing == 2)
- {
- printf("\n powersharingserverip: Power Sharing Server IP.");
- }
- else
- {}
- printf("\n maintainurl: Maintain server url.");
- printf("\n maintainsecurity: Maintain server security profile.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(strcmp(cmd, "ocppurl") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** ocppurl ************************************");
- printf("\n Current OCPP url: %s", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new ocpp url.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input ocpp url: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], (char*)&cmd[0]);
- DEBUG_INFO("Input ocpp url: %s\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
- }
- }
- if(strcmp(cmd, "mtserverurl") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** mtserverurl ********************************");
- printf("\n Current maintain server url: %s", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new ocpp url.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input maintain server url: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.MaintainServerURL[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL[0], (char*)&cmd[0]);
- DEBUG_INFO("Input maintain server url: %s\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
- }
- }
- else if(strcmp(cmd, "ocppsecurity") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** ocppsecurity *******************************");
- printf("\n Current OCPP security profile: %d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
- printf("\n 0: Profile-0.");
- printf("\n 1: Profile-1.");
- printf("\n 2: Profile-2.");
- printf("\n 3: Profile-3.");
- printf("\n **************************************************");
- printf("\n Please input OCPP security profile: ");
- scanf("%s", &cmd[0]);
- ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = ((0<=atoi(cmd))&&(atoi(cmd)<=3)&&(atoi(cmd)!=1)?atoi(cmd):0);
- DEBUG_INFO("OCPP security profile: %d.\n");
- }
- else if(strcmp(cmd, "cboxid") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** cboxid *************************************");
- printf("\n Current OCPP charger box id: %s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new charger box id.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input OCPP charger box id: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], (char*)&cmd[0]);
- DEBUG_INFO("Input ocpp charger box id: %s\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
- }
- }
- else if(strcmp(cmd, "vender") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** vender *************************************");
- printf("\n Current OCPP vender: %s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new charger box id.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input OCPP vender: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], (char*)&cmd[0]);
- DEBUG_INFO("Input ocpp vender: %s\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
- }
- }
- else if(strcmp(cmd, "offlinepolicy") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** offlinepolicy ******************************");
- printf("\n Current off line policy: %d", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
- printf("\n 0: Local list.");
- printf("\n 2: Free charging.");
- printf("\n 3: Deny charging.");
- printf("\n **************************************************");
- printf("\n Please input off line policy mode: ");
- scanf("%s", &cmd[0]);
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy = ((0<=atoi(cmd))&&(atoi(cmd)<=3)&&(atoi(cmd)!=1)?atoi(cmd):0);
- switch(ShmSysConfigAndInfo->SysConfig.OfflinePolicy)
- {
- case 0:
- DEBUG_INFO("Off line policy: Local list.\n");
- break;
- case 2:
- DEBUG_INFO("Off line policy: Free charging.\n");
- break;
- case 3:
- DEBUG_INFO("Off line policy: Deny charging.\n");
- break;
- }
- }
- else if(strcmp(cmd, "localpowersharing") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** localpowersharing **************************");
- printf("\n Current local power sharing: %d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
- printf("\n 0: Disable.");
- printf("\n 1: Master.");
- printf("\n 2: Slave.");
- printf("\n **************************************************");
- printf("\n Please input local load balance mode: ");
- scanf("%s", &cmd[0]);
- ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = ((0<=atoi(cmd))&&(atoi(cmd)<=2)?atoi(cmd):0);
- switch(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing)
- {
- case 0:
- DEBUG_INFO("Local loading balance: Disable\n");
- break;
- case 1:
- DEBUG_INFO("Local loading balance: Master\n");
- break;
- case 2:
- DEBUG_INFO("Local loading balance: Slave\n");
- break;
- }
- }
- else if(strcmp(cmd, "powersharingcapacity") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** powersharingcapacity ***********************");
- printf("\n Current local power sharing capacity: %d", ShmSysConfigAndInfo->SysConfig.PowerSharingCapacityPower);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new capacity(W).");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input capacity(W): ");
- scanf("%s", &cmd[0]);
- ShmSysConfigAndInfo->SysConfig.PowerSharingCapacityPower = ((0<=atoi(cmd))?atoi(cmd):0);
- }
- }
- else if(strcmp(cmd, "powersharingserverip") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** powersharingserverip ***********************");
- printf("\n Current power sharing server IP: %s", ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new server IP address.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
-
- if(atoi(cmd) == 1)
- {
- printf("\n Please input power sharing server IP address: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP[0], (char*)&cmd[0]);
- DEBUG_INFO("Input server IP address: %s\n", ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP);
- }
- }
- else if(strcmp(cmd, "maintainurl") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** maintainurl ********************************");
- printf("\n Current maintain url: %s", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new maintain url.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input maintain url: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.MaintainServerURL[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL[0], (char*)&cmd[0]);
- DEBUG_INFO("Input maintain url: %s\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
- }
- }
- else if(strcmp(cmd, "maintainsecurity") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** maintainsecurity ***************************");
- printf("\n Current maintain security profile: %d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile);
- printf("\n 0: Profile-0.");
- printf("\n 1: Profile-1.");
- printf("\n 2: Profile-2.");
- printf("\n 3: Profile-3.");
- printf("\n **************************************************");
- printf("\n Please input maintain security profile: ");
- scanf("%s", &cmd[0]);
- ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = ((0<=atoi(cmd))&&(atoi(cmd)<=3)&&(atoi(cmd)!=1)?atoi(cmd):0);
- DEBUG_INFO("Maintain security profile: %d.\n");
- }
- }
- else if(strcmp(cmd, "network") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** network *************************************");
- printf("\n ethdhcp: Ethernet DHCP client.");
- printf("\n wifimode: WiFi mode.");
- printf("\n wifidhcp: WiFi DHCP client.");
- printf("\n wificssid: WiFi client SSID.");
- printf("\n wificpasswd: WiFi client password.");
- printf("\n telemode: Telecomm mode.");
- printf("\n teleapn: Telecomm APN.");
- printf("\n teleid: Telecomm login id.");
- printf("\n telepwd: Telecomm login password.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(strcmp(cmd, "ethdhcp") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** ethdhcp ************************************");
- printf("\n Current ethernet dhcp mode: %d", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient^1);
- printf("\n 0: Disable.");
- printf("\n 1: Enable.");
- printf("\n **************************************************");
- printf("\n Please input dhcp mode: ");
- scanf("%s", &cmd[0]);
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
- if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient)
- DEBUG_INFO("Ethernet dhcp client: Disable\n");
- else
- DEBUG_INFO("Ethernet dhcp client: Enable\n");
- }
- else if(strcmp(cmd, "wifimode") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** wifimode ***********************************");
- printf("\n Current WiFi mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
- printf("\n 0: Disable.");
- printf("\n 1: Station.");
- printf("\n 2: Access point.");
- printf("\n **************************************************");
- printf("\n Please input WiFi mode: ");
- scanf("%s", &cmd[0]);
- ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode = ((0<=atoi(cmd))&&(atoi(cmd)<=2)?atoi(cmd):0);
- switch(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode)
- {
- case 0:
- DEBUG_INFO("Wifi mode: Disable.\n");
- break;
- case 1:
- DEBUG_INFO("Wifi mode: Station.\n");
- break;
- case 2:
- DEBUG_INFO("Wifi mode: AP.\n");
- break;
- }
- }
- else if(strcmp(cmd, "wifidhcp") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** wifidhcp ***********************************");
- printf("\n Current WiFi dhcp client mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient^1);
- printf("\n 0: Disable.");
- printf("\n 1: Enable.");
- printf("\n **************************************************");
- printf("\n Please input WiFi mode: ");
- scanf("%s", &cmd[0]);
- ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient)
- DEBUG_INFO("Wifi dhcp client: Disable\n");
- else
- DEBUG_INFO("Wifi dhcp client: Enable\n");
- }
- else if(strcmp(cmd, "wificssid") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** wificssid **********************************");
- printf("\n Current WiFi client SSID: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new WiFi client SSID.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input WiFi client SSID: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], (char*)&cmd[0]);
- DEBUG_INFO("Wifi client SSID: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
- }
- }
- else if(strcmp(cmd, "wificpasswd") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** wificpasswd ********************************");
- printf("\n Current WiFi client password: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new WiFi client password.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input WiFi client password: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], (char*)&cmd[0]);
- DEBUG_INFO("Wifi client password: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
- }
- }
- else if(strcmp(cmd, "telemode") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** telemode ***********************************");
- printf("\n 0: Disable.");
- printf("\n 1: Enable.");
- printf("\n **************************************************");
- printf("\n Current telecomm mode: %d", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode^1);
- printf("\n Please input telecomm mode: ");
- scanf("%s", &cmd[0]);
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode)
- DEBUG_INFO("Wifi dhcp client: Disable\n");
- else
- DEBUG_INFO("Wifi dhcp client: Enable\n");
- }
- else if(strcmp(cmd, "teleapn") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** teleapn ************************************");
- printf("\n Current telecomm APN: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new telecomm APN.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input telecomm APN: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], (char*)&cmd[0]);
- DEBUG_INFO("Telecomm APN: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
- }
- }
- else if(strcmp(cmd, "teleid") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** teleid *************************************");
- printf("\n Current telecomm login id: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new telecomm login id.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input telecomm login id: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], (char*)&cmd[0]);
- DEBUG_INFO("Telecomm CHAP id: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId);
- }
- }
- else if(strcmp(cmd, "telepwd") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** telepwd ************************************");
- printf("\n Current telecomm login password: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd);
- printf("\n 0: Keep current config.");
- printf("\n 1: Input new telecomm login password.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(atoi(cmd) == 1)
- {
- printf("\n Please input telecomm login password: ");
- scanf("%s", &cmd[0]);
- memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd));
- strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], (char*)&cmd[0]);
- DEBUG_INFO("Telecomm CHAP password: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd);
- }
- }
- }
- else if(strcmp(cmd, "test") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ***** test menu **********************************");
- printf("\n start: EVSE start charging request.");
- printf("\n stop: EVSE stop charging request.");
- printf("\n auth: Authorize request.");
- printf("\n alarm: Simulate alarm status.");
- printf("\n cancel: return to main menu.");
- printf("\n **************************************************");
- printf("\n Please input operation item: ");
- scanf("%s", &cmd[0]);
- if(strcmp(cmd, "start") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n Please input gun index(1~2): ");
- scanf("%s", &cmd[0]);
- if((0 < atoi(cmd)) && (atoi(cmd) < 3))
- {
- ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStart = ON;
- DEBUG_INFO("Test start gun-%d, start charging session.\n", atoi(cmd));
- }
- else
- {
- printf("\n Invalid input gun_index.");
- }
- }
- else if(strcmp(cmd, "stop") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n Please input gun index(1~2): ");
- scanf("%s", &cmd[0]);
- if((0 < atoi(cmd)) && (atoi(cmd) < 3))
- {
- ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStop = ON;
- DEBUG_INFO("Test start gun-%d, stop charging session.\n", atoi(cmd));
- }
- else
- {
- printf("\n Invalid input gun_index.");
- }
- }
- else if(strcmp(cmd, "auth") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n Please input idtag: ");
- scanf("%s", &cmd[0]);
- sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%s", cmd);
- ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
- DEBUG_INFO("Test authentication by %s.\n", ShmSysConfigAndInfo->SysConfig.UserId);
- }
- else if(strcmp(cmd, "alarm") == 0)
- {
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n Please input gun index(1~2): ");
- scanf("%s", &cmd[0]);
- if((0 < atoi(cmd)) && (atoi(cmd) < 3))
- {
- DEBUG_INFO("Alarm simulate gun-%d, OVP.\n", atoi(cmd));
- while(1)
- {
- ShmCharger->gun_info[atoi(cmd)-1].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
- ShmCharger->gun_info[atoi(cmd)-1].primaryMcuAlarm.InputAlarmCode |= ALARM_OVER_VOLTAGE;
- }
- }
- else
- {
- printf("\n Invalid input gun_index.");
- sleep(1);
- }
- }
- else if(strcmp(cmd, "cancel") == 0)
- {}
- }
- else if(strcmp(cmd, "upgrade") == 0)
- {
- printf("\n Firmware upgrade trigger.");
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = ON;
- DEBUG_INFO("Trigger firmware upgrade.\n");
- sleep(2);
- }
- else if(strcmp(cmd, "save") == 0)
- {
- if(StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig) != PASS)
- {
- printf("\n Write configuration fail.\r\n");
- }
- else
- {
- printf("\n Write configuration OK.\r\n");
- DEBUG_INFO("Save configuration.\n");
- }
- sleep(2);
- }
- else if(strcmp(cmd, "exit") == 0)
- {
- printf("\n exit program.\n\n");
- DEBUG_INFO("Exit configuration tools.\n");
- return FAIL;
- }
- }
- return -1;
- }
|