123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/can.h>
- #include <linux/can/raw.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include "../../define.h"
- #include "Config.h"
- #define Debug
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
- #define PASS 1
- #define FAIL -1
- #define OUTPUT_FLASH 0x01
- #define OUTPUT_FILE 0x02
- struct SysConfigData SysConfig;
- int StoreLogMsg(const char *fmt, ...);
- int StoreLogMsg(const char *fmt, ...)
- {
- char Buf[4096+256];
- char buffer[4096];
- time_t CurrentTime;
- struct tm *tm;
- 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);
- sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
- tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
- buffer,
- tm->tm_year+1900,tm->tm_mon+1);
- system(Buf);
- return rc;
- }
- void helpOutput(void)
- {
- printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
- printf("Generate factory default configuration value\r\n\r\n");
- printf("OPTION:\r\n");
- printf(" -a Write to file(/mnt) & flash\r\n");
- printf(" -f Write to file(/mnt)\r\n");
- printf(" -m Write to flash\r\n");
- }
- /**************************************************************************************/
- /************This task will create Factory default confgiuration file *****************/
- /***********and store it into mtdblock 10,11,12 ****************/
- /**************************************************************************************/
- int main(int argc,char *argv[])
- {
- unsigned char outType=0;
- unsigned int i,Chk, MtdBlockSize=0x600000;
- unsigned char *ptr;
- int fd,wrd;
- ptr=malloc(MtdBlockSize);
- if(ptr==NULL)
- {
- #ifdef SystemLogMessage
- StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG");
- #endif
- return 0;
- }
- memset(ptr, 0, MtdBlockSize);
- memset(&SysConfig, 0, sizeof(struct SysConfigData));
- /*
- * TODO: Set factory default configuration
- */
- //********** System **********// udhcpc -i eth1 -s ./dhcp_script/eth1.script
- //
- strcpy((char *)SysConfig.ModelName, "DSYE36200E02L0");
- strcpy((char *)SysConfig.SerialNumber, "");
- memset(SysConfig.SystemId, 0x00, sizeof(SysConfig.SystemId));
- char Dash = '-';
- strcat((char *)SysConfig.SystemId, (char *)SysConfig.ModelName);
- strncat((char *)SysConfig.SystemId, &Dash, 1);
- strcat((char *)SysConfig.SystemId, (char *)SysConfig.SerialNumber);
- strcpy((char *)SysConfig.SystemDateTime, "");
- SysConfig.AuthorisationMode = _SYS_AUTHORIZE_OCPP;
- SysConfig.DefaultLanguage = 0;
- SysConfig.RfidCardNumEndian = 0;
- SysConfig.AcPlugInTimes = 0;
- SysConfig.GbPlugInTimes = 0;
- SysConfig.Ccs1PlugInTime = 0;
- SysConfig.Ccs2PlugInTimes = 0;
- SysConfig.ChademoPlugInTimes = 0;
- //********** Charging **********//
- SysConfig.RatingCurrent = 500; // 最大可輸出電流
- SysConfig.MaxChargingEnergy = 0;
- SysConfig.MaxChargingPower = 360; // 最大功率 : 跟著 model name 跑
- SysConfig.MaxChargingCurrent = 500; // 最大可輸出電流
- SysConfig.MaxChargingDuration = 0;
- SysConfig.PhaseLossPolicy = 0;
- for(unsigned char i = 0; i < 10; i++)
- strcpy((char *)SysConfig.LocalWhiteCard, "");
- strcpy((char *)SysConfig.UserId, "");
- //********** Network **********//
- strcpy((char *)SysConfig.FtpServer, "");
- SysConfig.Eth0Interface.EthDhcpClient = 0;
- strcpy((char *) SysConfig.Eth0Interface.EthIpAddress, "192.168.1.10");
- strcpy((char *) SysConfig.Eth0Interface.EthSubmaskAddress, "255.255.255.0");
- strcpy((char *) SysConfig.Eth0Interface.EthGatewayAddress, "192.168.1.254");
- SysConfig.Eth1Interface.EthDhcpClient = 0;
- strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.0.10");
- strcpy((char *) SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
- strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
- SysConfig.AthInterface.WifiMode = 0;
- strcpy((char *) SysConfig.AthInterface.WifiSsid, "");
- strcpy((char *) SysConfig.AthInterface.WifiPassword, "");
- SysConfig.AthInterface.WifiRssi = 0;
- SysConfig.AthInterface.WifiDhcpServer = 0;
- SysConfig.AthInterface.WifiDhcpClient = 0;
- strcpy((char *) SysConfig.AthInterface.WifiMacAddress, "");
- strcpy((char *) SysConfig.AthInterface.WifiIpAddress, "");
- strcpy((char *) SysConfig.AthInterface.WifiSubmaskAddress, "");
- strcpy((char *) SysConfig.AthInterface.WifiGatewayAddress, "");
- SysConfig.AthInterface.WifiNetworkConn = 0;
- strcpy((char *) SysConfig.TelecomInterface.TelcomModelName, "");
- strcpy((char *) SysConfig.TelecomInterface.TelcomSoftwareVer, "");
- //strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "Internet");
- strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "");
- SysConfig.TelecomInterface.TelcomRssi = 0;
- strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapId, " ");
- strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
- strcpy((char *) SysConfig.TelecomInterface.TelcomModemImei, "");
- strcpy((char *) SysConfig.TelecomInterface.TelcomSimImsi, "");
- strcpy((char *) SysConfig.TelecomInterface.TelcomSimIccid, "");
- SysConfig.TelecomInterface.TelcomSimStatus = 0;
- SysConfig.TelecomInterface.TelcomModemMode = 0;
- strcpy((char *) SysConfig.TelecomInterface.TelcomIpAddress, "");
- SysConfig.TelecomInterface.TelcomNetworkConn = 0;
- strcpy((char *)SysConfig.chargePointVendor, "Phihong Technology");
- //********** Backend **********//
- SysConfig.BackendConnTimeout = 300; //300 seconds
- SysConfig.OfflinePolicy = 0;
- SysConfig.OfflineMaxChargeEnergy = 0;
- SysConfig.OfflineMaxChargeDuration = 0;
- strcpy((char *) SysConfig.OcppServerURL, "");
- strcpy((char *) SysConfig.ChargeBoxId, "");
- //copy default configuration to pointer
- memcpy(ptr,&SysConfig,sizeof(struct SysConfigData));
- //calculate CRC
- Chk=0;
- for(i=0;i<(MtdBlockSize-4);i++)
- {
- Chk+=*(ptr+i);
- }
- memcpy( ptr+MtdBlockSize-4,&Chk,4);
- /*
- * Parameter process
- */
- if (argc > 1)
- {
- char *arg = argv[1];
- switch (arg[0])
- {
- case '-':
- switch (arg[1])
- {
- case 'a':
- outType |= OUTPUT_FILE;
- outType |= OUTPUT_FLASH;
- break;
- case 'f':
- outType |= OUTPUT_FILE;
- break;
- case 'm':
- outType |= OUTPUT_FLASH;
- break;
- default:
- helpOutput();
- break;
- }
- break;
- default:
- helpOutput();
- break;
- }
- }
- else
- {
- helpOutput();
- }
- /*
- * Configuration bin file generate
- */
- if((outType&OUTPUT_FILE)>0)
- {
- fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
- if (fd < 0)
- {
- StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
- free(ptr);
- return 0;
- }
- wrd=write(fd, ptr, MtdBlockSize);
- close(fd);
- if(wrd<MtdBlockSize)
- {
- StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
- free(ptr);
- return 0;
- }
- StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\n");
- }
- /*
- * Flash memory write
- */
- if((outType&OUTPUT_FLASH)>0)
- {
- // Save factory default setting value to flash factory default setting block
- fd = open("/dev/mtdblock12", O_RDWR);
- if (fd < 0)
- {
- StoreLogMsg("open /dev/mtdblock12 NG\r\n");
- free(ptr);
- return 0;
- }
- wrd=write(fd, ptr, MtdBlockSize);
- close(fd);
- if(wrd<MtdBlockSize)
- {
- StoreLogMsg("write /dev/mtdblock12 NG\r\n");
- free(ptr);
- return 0;
- }
- // Save factory default setting value to flash backup setting block
- fd = open("/dev/mtdblock11", O_RDWR);
- if (fd < 0)
- {
- StoreLogMsg("open /dev/mtdblock11 NG\r\n");
- free(ptr);
- return 0;
- }
- wrd=write(fd, ptr, MtdBlockSize);
- close(fd);
- if(wrd<MtdBlockSize)
- {
- StoreLogMsg("write /dev/mtdblock11 NG\r\n");
- free(ptr);
- return 0;
- }
- // Save factory default setting value to flash setting block
- fd = open("/dev/mtdblock10", O_RDWR);
- if (fd < 0)
- {
- StoreLogMsg("open /dev/mtdblock10 NG\r\n");
- free(ptr);
- return 0;
- }
- wrd=write(fd, ptr, MtdBlockSize);
- close(fd);
- if(wrd<MtdBlockSize)
- {
- StoreLogMsg("write /dev/mtdblock10 NG\r\n");
- free(ptr);
- return 0;
- }
- StoreLogMsg("FactoryConfig write to flash OK\r\n");
- }
- free(ptr);
- return FAIL;
- }
|