/*=========================================================================== Combined Charging System (CCS): SECC FactoryConfig.c initiated by Vern, Joseph (since 2019/07/19) =============================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //for pow #include #include "define.h" #include "FactoryConfig.h" #ifdef SystemLogMessage int StoreLogMsg(unsigned char *DataString) { unsigned char Buf[256]; time_t CurrentTime; struct tm *tm; 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, DataString, tm->tm_year + 1900, tm->tm_mon + 1); system(Buf); #ifdef Debug printf("%s \n", DataString); #endif } #endif /**************************************************************************************/ /************This task will create Factory default confgiuration file *****************/ /***********and store it into mtdblock 10,11,12 ****************/ /**************************************************************************************/ int main(int argc, char *argv[]) { struct SysConfigData SysConfig; unsigned int i, Chk; unsigned char *ptr; int fd, wrd; ptr = malloc(sizeof(struct SysConfigData)); if(ptr == NULL) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG"); #endif return 0; } memset(ptr, 0, sizeof(struct SysConfigData)); memset(&SysConfig, 0, sizeof(struct SysConfigData)); //Set default configuration strcpy(SysConfig.Eth0Interface.EthIpAddress, "192.168.0.10"); strcpy(SysConfig.Eth0Interface.EthSubmaskAddress, "255.255.255.0"); strcpy(SysConfig.Eth0Interface.EthGatewayAddress, "192.168.0.254"); strcpy(SysConfig.Eth1Interface.EthIpAddress, "192.168.1.10"); strcpy(SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0"); strcpy(SysConfig.Eth1Interface.EthGatewayAddress, "192.168.1.254"); SysConfig.BackendConnTimeout = 300; //300 seconds //copy default configuration to pointer memcpy(ptr, &SysConfig, sizeof(struct SysConfigData)); //calculate CRC Chk = 0; for(i = 0; i < (sizeof(struct SysConfigData) - 4); i++) { Chk += *(ptr + i); } SysConfig.Checksum = Chk; fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT); if(fd < 0) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG"); #endif free(ptr); return 0; } wrd = write(fd, &SysConfig, sizeof(struct SysConfigData)); close(fd); if(wrd != (sizeof(struct SysConfigData))) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: write /mnt/FactoryDefaultConfig.bin NG"); #endif free(ptr); return 0; } fd = open("/dev/mtdblock12", O_RDWR); if(fd < 0) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: open /dev/mtdblock12 NG"); #endif free(ptr); return 0; } wrd = write(fd, &SysConfig, sizeof(struct SysConfigData)); close(fd); if(wrd != (sizeof(struct SysConfigData))) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: write /dev/mtdblock12 NG"); #endif free(ptr); return 0; } fd = open("/dev/mtdblock11", O_RDWR); if(fd < 0) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: open /dev/mtdblock11 NG"); #endif free(ptr); return 0; } wrd = write(fd, &SysConfig, sizeof(struct SysConfigData)); close(fd); if(wrd != (sizeof(struct SysConfigData))) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: write /dev/mtdblock11 NG"); #endif free(ptr); return 0; } fd = open("/dev/mtdblock10", O_RDWR); if(fd < 0) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: open /dev/mtdblock10 NG"); #endif free(ptr); return 0; } wrd = write(fd, &SysConfig, sizeof(struct SysConfigData)); close(fd); if(wrd != (sizeof(struct SysConfigData))) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: write /dev/mtdblock10 NG"); #endif free(ptr); return 0; } free(ptr); #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: FactoryConfig OK"); #endif }