|
@@ -36,6 +36,9 @@
|
|
|
#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;
|
|
|
struct SysConfigAndInfo *ShmSysConfigAndInfo;
|
|
@@ -186,24 +189,35 @@ int InitShareMemory()
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+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");
|
|
|
+}
|
|
|
+
|
|
|
//================================================
|
|
|
// Main process
|
|
|
//================================================
|
|
|
-int main(void)
|
|
|
+int main(int argc, char *argv[])
|
|
|
{
|
|
|
-
|
|
|
- unsigned int i,Chk;
|
|
|
+ unsigned char outType=0;
|
|
|
+ unsigned int i,Chk,MtdBlockSize=0x600000;
|
|
|
unsigned char *ptr;
|
|
|
int fd,wrd;
|
|
|
|
|
|
- ptr=malloc(sizeof(struct SysConfigData));
|
|
|
+ ptr=malloc(MtdBlockSize);
|
|
|
if(ptr==NULL)
|
|
|
{
|
|
|
- DEBUG_ERROR("malloc for SysConfigData NG\r\n");
|
|
|
-
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG");
|
|
|
+ #endif
|
|
|
return 0;
|
|
|
}
|
|
|
- memset(ptr,0,sizeof(struct SysConfigData));
|
|
|
+ memset(ptr,0,MtdBlockSize);
|
|
|
memset(&SysConfig,0,sizeof(struct SysConfigData));
|
|
|
|
|
|
/*
|
|
@@ -213,7 +227,7 @@ int main(void)
|
|
|
time_t t = time(NULL);
|
|
|
struct tm tm = *localtime(&t);
|
|
|
strcpy((char*)SysConfig.ModelName, "AWLU770100W1P0");
|
|
|
- strcpy((char*)SysConfig.SerialNumber, "D195200001A0");
|
|
|
+ strcpy((char*)SysConfig.SerialNumber, "D19520001A0");
|
|
|
sprintf((char*)SysConfig.SystemId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
|
|
|
sprintf((char*)SysConfig.SystemDateTime, "%d-%d-%d %d:%d:%d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
|
SysConfig.AuthorisationMode = 0; // 0:PH card 1: OCPP backend 2: PH backend 3: Free Mode
|
|
@@ -254,7 +268,7 @@ int main(void)
|
|
|
SysConfig.OfflinePolicy = 0; // 0: Local list 1: PH RFID 2: Free 3: Deny
|
|
|
SysConfig.OfflineMaxChargeEnergy = 0; // 0: Same as MaxChargeEnergy Other: 1~65535KWH
|
|
|
SysConfig.OfflineMaxChargeDuration = 0; // 0: Same as MaxChargeDuration Other: 1~65535 minutes
|
|
|
- strcpy((char*)SysConfig.OcppServerURL, "ws://evsocket.phihong.com.tw/");
|
|
|
+ strcpy((char*)SysConfig.OcppServerURL, "ws://192.168.0.246:8080/ocpp/");
|
|
|
sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
|
|
|
|
|
|
|
|
@@ -263,94 +277,143 @@ int main(void)
|
|
|
|
|
|
// Calculate CRC
|
|
|
Chk=0;
|
|
|
- for(i=0;i<(sizeof(struct SysConfigData)-4);i++)
|
|
|
+ for(i=0;i<(MtdBlockSize-4);i++)
|
|
|
{
|
|
|
Chk+=*(ptr+i);
|
|
|
}
|
|
|
- SysConfig.Checksum=Chk;
|
|
|
+ memcpy( ptr+MtdBlockSize-4,&Chk,4);
|
|
|
|
|
|
- // Save factory default setting value to file
|
|
|
- fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
-
|
|
|
- DEBUG_ERROR("open /mnt/FactoryDefaultConfig.bin NG\r\n");
|
|
|
-
|
|
|
- free(ptr);
|
|
|
- return 0;
|
|
|
- }
|
|
|
- wrd=write(fd, &SysConfig, sizeof(struct SysConfigData));
|
|
|
- close(fd);
|
|
|
- if(wrd!=(sizeof(struct SysConfigData)))
|
|
|
+ /*
|
|
|
+ * Parameter process
|
|
|
+ */
|
|
|
+ if(argc>1)
|
|
|
{
|
|
|
- DEBUG_ERROR("write /mnt/FactoryDefaultConfig.bin NG\r\n");
|
|
|
-
|
|
|
- free(ptr);
|
|
|
- return 0;
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- // Save factory default setting value to flash factory default setting block
|
|
|
- fd = open("/dev/mtdblock12", O_RDWR);
|
|
|
- if (fd < 0)
|
|
|
+ else
|
|
|
{
|
|
|
-
|
|
|
- DEBUG_ERROR("open /dev/mtdblock12 NG\r\n");
|
|
|
-
|
|
|
- free(ptr);
|
|
|
- return 0;
|
|
|
+ helpOutput();
|
|
|
}
|
|
|
- wrd=write(fd, &SysConfig, sizeof(struct SysConfigData));
|
|
|
- close(fd);
|
|
|
- if(wrd!=(sizeof(struct SysConfigData)))
|
|
|
- {
|
|
|
- DEBUG_ERROR("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)
|
|
|
- {
|
|
|
- DEBUG_ERROR("open /dev/mtdblock11 NG\r\n");
|
|
|
-
|
|
|
- free(ptr);
|
|
|
- return 0;
|
|
|
- }
|
|
|
- wrd=write(fd, &SysConfig, sizeof(struct SysConfigData));
|
|
|
- close(fd);
|
|
|
- if(wrd!=(sizeof(struct SysConfigData)))
|
|
|
+ /*
|
|
|
+ * Configuration bin file generate
|
|
|
+ */
|
|
|
+ if((outType&OUTPUT_FILE)>0)
|
|
|
{
|
|
|
- DEBUG_ERROR("write /dev/mtdblock11 NG\r\n");
|
|
|
-
|
|
|
- free(ptr);
|
|
|
- return 0;
|
|
|
+ // Save factory default setting value to file
|
|
|
+ fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
|
|
|
+ if (fd < 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ DEBUG_ERROR("open /mnt/FactoryDefaultConfig.bin NG\r\n");
|
|
|
+
|
|
|
+ free(ptr);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ wrd=write(fd, ptr, MtdBlockSize);
|
|
|
+ close(fd);
|
|
|
+ if(wrd<MtdBlockSize)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("write /mnt/FactoryDefaultConfig.bin NG\r\n");
|
|
|
+
|
|
|
+ free(ptr);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ DEBUG_INFO("FactoryConfig write to file in /mnt OK.\r\n");
|
|
|
}
|
|
|
|
|
|
- // Save factory default setting value to flash setting block
|
|
|
- fd = open("/dev/mtdblock10", O_RDWR);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
- DEBUG_ERROR("open /dev/mtdblock10 NG\r\n");
|
|
|
-
|
|
|
- free(ptr);
|
|
|
- return 0;
|
|
|
- }
|
|
|
- wrd=write(fd, &SysConfig, sizeof(struct SysConfigData));
|
|
|
- close(fd);
|
|
|
- if(wrd!=(sizeof(struct SysConfigData)))
|
|
|
+ /*
|
|
|
+ * Flash memory write
|
|
|
+ */
|
|
|
+ if((outType&OUTPUT_FLASH)>0)
|
|
|
{
|
|
|
- DEBUG_ERROR("write /dev/mtdblock10 NG\r\n");
|
|
|
-
|
|
|
- free(ptr);
|
|
|
- return 0;
|
|
|
+ // Save factory default setting value to flash factory default setting block
|
|
|
+ fd = open("/dev/mtdblock12", O_RDWR);
|
|
|
+ if (fd < 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ DEBUG_ERROR("open /dev/mtdblock12 NG\r\n");
|
|
|
+
|
|
|
+ free(ptr);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ wrd=write(fd, ptr, MtdBlockSize);
|
|
|
+ close(fd);
|
|
|
+ if(wrd<MtdBlockSize)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("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)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("open /dev/mtdblock11 NG\r\n");
|
|
|
+
|
|
|
+ free(ptr);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ wrd=write(fd, ptr, MtdBlockSize);
|
|
|
+ close(fd);
|
|
|
+ if(wrd<MtdBlockSize)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("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)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("open /dev/mtdblock10 NG\r\n");
|
|
|
+
|
|
|
+ free(ptr);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ wrd=write(fd, ptr, MtdBlockSize);
|
|
|
+ close(fd);
|
|
|
+ if(wrd<MtdBlockSize)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("write /dev/mtdblock10 NG\r\n");
|
|
|
+
|
|
|
+ free(ptr);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ DEBUG_INFO("FactoryConfig write to flash OK\r\n");
|
|
|
}
|
|
|
|
|
|
free(ptr);
|
|
|
|
|
|
- DEBUG_INFO("FactoryConfig OK\r\n");
|
|
|
-
|
|
|
-
|
|
|
return FAIL;
|
|
|
}
|