123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- /*===========================================================================
- Combined Charging System (CCS): SECC
- FactoryConfig.c
- initiated by Vern, Joseph
- (since 2019/07/19)
- =============================================================================*/
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <linux/termios.h>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <stdlib.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/sockios.h>
- #include <linux/socket.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <math.h>//for pow
- #include <unistd.h>
- #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
- }
|