#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*標準輸入輸出定義*/ #include /*標準函數庫定義*/ #include /*Unix 標準函數定義*/ #include /*檔控制定義*/ #include /*PPSIX 終端控制定義*/ #include /*錯誤號定義*/ #include #include #include #include #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 #define EQUAL 0 struct SysConfigData SysConfig; int StoreLogMsg(const char *fmt, ...); int StoreLogMsg(const char *fmt, ...) { char Buf[4096+256]; char buffer[4096]; va_list args; struct timeb SeqEndTime; struct tm *tm; va_start(args, fmt); int rc = vsnprintf(buffer, sizeof(buffer), fmt, args); va_end(args); memset(Buf,0,sizeof(Buf)); ftime(&SeqEndTime); SeqEndTime.time = time(NULL); tm=localtime(&SeqEndTime.time); sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %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,SeqEndTime.millitm, 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"); } 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) { StoreLogMsg("%s\n", buf); } result = PASS; } pclose(fp); return result; } void CustomChange(char *custom) { if (strcmp(custom, "C0") == EQUAL) { // Bosch SysConfig.AuthorisationMode = AUTH_MODE_DISABLE; SysConfig.isRFID = 0; } else if (strcmp(custom, "N0") == EQUAL || strcmp(custom, "N1") == EQUAL) { // Noodoe (Shell) SysConfig.isAPP = 0; } else if (strcmp(custom, "CL") == EQUAL) { // ChargeLab SysConfig.AuthorisationMode = AUTH_MODE_ENABLE; SysConfig.RfidCardNumEndian = RFID_ENDIAN_BIG; strcpy((char *) SysConfig.OcppServerURL, "wss://ocpp.io"); sprintf((char *) SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber); strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "m2minternet.apn"); strcpy((char *) SysConfig.AthInterface.WifiSsid, "ChargeLab-EVC"); strcpy((char *) SysConfig.AthInterface.WifiPassword, "evc-pwd-default-21"); SysConfig.OfflinePolicy = _OFFLINE_POLICY_LOCAL_LIST; strcpy((char *)SysConfig.chargePointVendor, "ChargeLab"); SysConfig.AthInterface.WifiMode = 1; SysConfig.TelecomInterface.TelcomEnabled = 1; } } /**************************************************************************************/ /************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 int MtdBlockSize = 0x300000; 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 // if (argc == 4) { strcpy((char *)SysConfig.ModelName, argv[2]); strcpy((char *)SysConfig.SerialNumber, argv[3]); } else { strcpy((char *)SysConfig.ModelName, "DSYE301E00D2PH"); strcpy((char *)SysConfig.SerialNumber, "NeedSetupSN"); } memset(SysConfig.SystemId, 0x00, sizeof(SysConfig.SystemId)); strcat((char *)SysConfig.SystemId, (char *)SysConfig.ModelName); strcat((char *)SysConfig.SystemId, (char *)SysConfig.SerialNumber); strcpy((char *)SysConfig.SystemDateTime, ""); SysConfig.AuthorisationMode = AUTH_MODE_ENABLE; SysConfig.DefaultLanguage = 0; SysConfig.RfidCardNumEndian = RFID_ENDIAN_LITTLE; SysConfig.AcPlugInTimes = 0; SysConfig.GbPlugInTimes = 0; SysConfig.Ccs1PlugInTime = 0; SysConfig.Ccs2PlugInTimes = 0; SysConfig.ChademoPlugInTimes = 0; SysConfig.BillingData.isBilling = 0; SysConfig.isAPP = 1; SysConfig.isQRCode = 1; SysConfig.isRFID = 1; //********** Charging **********// SysConfig.MaxChargingEnergy = 0; //SysConfig.MaxChargingCurrent = 200; // 最大可輸出電流 (整樁) SysConfig.MaxChargingDuration = 0; SysConfig.AcMaxChargingCurrent = 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"); // if(SysConfig.ModelName[10] == 'W' || SysConfig.ModelName[10] == 'D') // SysConfig.AthInterface.WifiMode = 2; // else // SysConfig.AthInterface.WifiMode = 0; SysConfig.AthInterface.WifiMode = 0; SysConfig.TelecomInterface.TelcomEnabled = 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 = _OFFLINE_POLICY_FREE_CHARGING; SysConfig.OfflineMaxChargeEnergy = 0; SysConfig.OfflineMaxChargeDuration = 0; strcpy((char *) SysConfig.OcppServerURL, ""); strcpy((char *) SysConfig.ChargeBoxId, ""); strcpy((char *) SysConfig.MaintainServerURL, "wss://ocpp.phihong.com.tw:2013/"); SysConfig.LedInfo.Intensity = 2; // ********** 客製化 ********** // char _buf[3] = {0}; memcpy(_buf, &SysConfig.ModelName[12], 2); CustomChange(_buf); //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); // } for(i = ARRAY_SIZE(SysConfig.CsuBootLoadFwRev); 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); fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT | O_TRUNC); if (fd < 0) { StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG"); free(ptr); return 0; } wrd=write(fd, ptr, MtdBlockSize); close(fd); if(wrd0) { StoreLogMsg("Erase /dev/mtd10.\n"); runShellCmd("flash_erase /dev/mtd10 0 0"); StoreLogMsg("Write /dev/mtd10.\n"); runShellCmd("nandwrite -p /dev/mtd10 /mnt/FactoryDefaultConfig.bin"); StoreLogMsg("Erase /dev/mtd11.\n"); runShellCmd("flash_erase /dev/mtd11 0 0"); StoreLogMsg("Write /dev/mtd11.\n"); runShellCmd("nandwrite -p /dev/mtd11 /mnt/FactoryDefaultConfig.bin"); StoreLogMsg("Erase /dev/mtd12.\n"); runShellCmd("flash_erase /dev/mtd12 0 0"); StoreLogMsg("Write /dev/mtd12.\n"); runShellCmd("nandwrite -p /dev/mtd12 /mnt/FactoryDefaultConfig.bin"); system("rm -f /mnt/FactoryDefaultConfig.bin"); StoreLogMsg("FactoryConfig write to flash OK\n"); } free(ptr); } /* * 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