#include "global.th" #include "config_work.th" #include "common.th" Configuration config; string get_parameter(string param){ romfile.open("sdf.txt"); int str_start = 1; unsigned long pos,pos2; pos = romfile.find(str_start,param+"=",1); pos +=len(param+"="); romfile.pointer32=pos; pos2 = romfile.find(pos,chr(13),1); return romfile.getdata(pos2-pos); } string get_parameter_from_file(string param,string filename){ fd.filenum = 2; fd.open(filename); fd.setpointer(1); unsigned long pos,pos2; pos=fd.find(1,param+"=",1,FORWARD,1,PL_FD_FIND_EQUAL); if (pos == 0){ fd.close(); return ""; } fd.setpointer(pos+len(param+"=")); pos2 = fd.find(pos+len(param),chr(13),1,FORWARD,1,PL_FD_FIND_EQUAL)-len(param+"="); string r = fd.getdata(pos2-pos); //d("|<"+param+"='"+r+"'"+chr(13)); fd.close(); return r; } bool format_flash(int flash_size, int file_count){ return (fd.format(config.FLASH_SIZE,config.FLASH_FILES) == PL_FD_STATUS_OK); } void config_load(){ d("load config"); if (config.STORE_LOCATON == FLASH){ fd.filenum=1; fd.open("config"); string s =fd.getdata(200); while (len(s)>0){ d(s); s=fd.getdata(200); } //d("config file size:" +str(fd.filesize)); fd.close(); config.IP= get_parameter_from_file("ip","config"); //config.STORE_LOCATON = get_parameter_from_file("STORE_LOCATON","config"); //config.FLASH_SIZE = get_parameter_from_file("FLASH_SIZE","config"); //config.FLASH_FILES = get_parameter_from_file("FLASH_FILES","config"); config.STORE_BRAKER = get_parameter_from_file("sb","config"); config.STORE_ENCODER = get_parameter_from_file("se","config"); if (config.STORE_ENCODER){ config.EncoderCfg.encoderPort = get_parameter_from_file("en.p","config"); config.EncoderCfg.encoderMode = get_parameter_from_file("en.m","config"); config.EncoderCfg.encoderInterval= get_parameter_from_file("en.int","config"); config.EncoderCfg.workedPorts = get_parameter_from_file("en.wp","config"); config.EncoderCfg.windowWidth = get_parameter_from_file("en.wn","config"); config.EncoderCfg.reinitInterval = get_parameter_from_file("en.ri","config"); } //if (config.STORE_BRAKER){ for (int i = 0; i0){ c.Enable = get_parameter_from_file("br["+str(i)+"].e","config"); c.SensPort= get_parameter_from_file("br["+str(i)+"].s","config"); c.DropPort=get_parameter_from_file("br["+str(i)+"].d","config"); c.Relay=get_parameter_from_file("br["+str(i)+"].r","config"); c.Timeout=get_parameter_from_file("br["+str(i)+"].t","config"); } } //} char arr[1024]; get_config(arr); } } char *get_config( char *array){ string sb=""; string r = chr(13)+chr(10); sb += "ip="+config.IP+r; string t[] = {"none","eeprom","flash"}; sb += "store="+ t[config.STORE_LOCATON]+r; if (config.STORE_LOCATON == FLASH){ sb += "fs=" + str(config.FLASH_SIZE)+r; sb += "ff=" + str(config.FLASH_FILES)+r; } //d("|>>>"+sb); memcpy(array,sb,len(sb)); array+=len(sb); sb=""; if (config.EncoderCfg.encoderPort>0){ config.STORE_ENCODER = true; sb += "en.p="+str(config.EncoderCfg.encoderPort)+r; sb += "en.m="+str(config.EncoderCfg.encoderMode)+r; sb += "en.int="+str(config.EncoderCfg.encoderInterval)+r; sb += "en.wp="+config.EncoderCfg.workedPorts+r; sb += "en.wn="+str(config.EncoderCfg.windowWidth)+r; sb += "en.ri="+str(config.EncoderCfg.reinitInterval)+r; } sb += "se=" + str(config.STORE_ENCODER)+r; d(sb); memcpy(array,sb,len(sb)); array+=len(sb); sb=""; for (int i = 0; i>>"+b); } sb+=b; } sb += "sb=" + str(config.STORE_BRAKER)+r; d(sb); memcpy(array,sb,len(sb)); array+=len(sb); return array; } void config_write(){ if (config.STORE_LOCATON == NONE){ fd.filenum = 1; fd.delete("config"); } if (config.STORE_LOCATON == FLASH){ fd.mount(); fd.filenum = 1; //d("flash size = "+ stri(fd.capacity)); if (fd.open("config") == PL_FD_STATUS_NOT_FOUND) fd.create("config"); if (fd.open("config") == PL_FD_STATUS_OK){ //d("before write:file size:" +str(fd.filesize)); fd.setpointer(0); char prep[1000]; char *ptr = get_config(prep); char *out = prep; int length = ptr - out; while (out < ptr){ string s; char *ss = s; if (out+100