/** * @brief 从文件中载入终端参数 * @return 0成功, 否则失败 */ int LoadParaTerm(void) { int rt=-1; DebugPrint(0, " load param term...\n"); rt = para_readflash_bin(PARA_FILEINDEX_COMB,(unsigned char *)¶_comb,sizeof(para_comb)); AssertLog(rt==-1,"readflash para_term failed!\n"); if(rt==-1) { LoadDefParaTerm(); return 1; } return 0; }
int LoadParaTerm(void) { XINREF pf; char str[100]; int i; struct hostent *mast_host; struct in_addr *sin_addr; DebugPrint(0, " load param term..."); DebugPrint(0, " sizeof(term)=%d\r\n",sizeof(para_term_tG)); LoadDefParaTerm(); if(getuciConfigvar("sn",str) == 0) { PrintLog(0,"SN:%s\n",str); ParaTermG.deviceid[0] = str[0]-0x30; ParaTermG.deviceid[1] = str[1]-0x30; ParaTermG.deviceid[2] = str[2]-0x30; ParaTermG.deviceid[3] = str[3]-0x30; ParaTermG.deviceid[4] = str[4]-0x30; ParaTermG.deviceid[5] = str[5]-0x30; ParaTermG.deviceid[6] = str[6]-0x30; ParaTermG.deviceid[7] = str[7]-0x30; } if(getuciConfigvar("firststart",str) == 0) { ParaTermG.first_start = str[0]-0x30; } if(getuciConfigvar("musicmonth",str) == 0) { ParaTermG.Musicmonth = str[0]-0x30; } if(getuciConfigvar("master_addr",str) == 0) { PrintLog(0,"master_addr:%s\n",str); mast_host = gethostbyname(str); if(mast_host != NULL) { PrintLog(0,"Master IP Address :%s\n",inet_ntoa(*((struct in_addr *)mast_host->h_addr))); PrintLog(0,"Master HostName :%s\n",mast_host->h_name); sin_addr = (struct in_addr *)mast_host->h_addr; memcpy(ParaTermG.svraddr.net.ip,&sin_addr->s_addr,4); //ParaTermG.svraddr.net.ip[0] = sin_addr->s_addr.s_b1; //ParaTermG.svraddr.net.ip[1] = sin_addr->s_addr.s_b2; //ParaTermG.svraddr.net.ip[2] = sin_addr->s_addr.s_b3; //ParaTermG.svraddr.net.ip[3] = sin_addr->S_un_b.s_b4; } } if(getuciConfigvar("master_port",str) == 0) { PrintLog(0,"master_port:%s\n",str); ParaTermG.svraddr.net.port = atoi(str); } PrintLog(0,"music_volume:%s\n",str); if(getuciConfigvar("music_volume",str) == 0) { PrintLog(0,"music_volume:%s\n",str); ParaTermG.music_volume = atoi(str); setvolume(ParaTermG.music_volume); } else { PrintLog(0,"music_volume:%s\n",str); ParaTermG.music_volume = 20; setvolume(ParaTermG.music_volume); } sprintf(str,"ParaTermG.device_code = %s\n",ParaTermG.device_code); load_hardinfo(); pf = XinOpen(PARAM_SAVE_PATH "/term.xin", 'r'); if(NULL == pf) { pf = XinOpen(PARAM_BAK_PATH "/term.xin", 'r'); if(NULL == pf) { DebugPrint(0, "no file\n"); // SaveParaTerm(); return 1; } } /*读主站IP*/ ParaTermG.svraddr.net.chn = XinReadInt(pf, "svraddrflag",0x04);//读上行连接方式 if(XinReadString(pf, "svraddrIp", str, 24) > 0) { StringToIp(str, ParaTermG.svraddr.net.ip); } ParaTermG.svraddr.net.port = XinReadInt(pf, "svrport", 8300); /*读主站2IP*/ ParaTermG.svraddr_1.net.chn = XinReadInt(pf, "svraddrflag1",0x04);//读上行连接方式 if(XinReadString(pf, "svraddrIp1", str, 24) > 0) { StringToIp(str, ParaTermG.svraddr_1.net.ip); } ParaTermG.svraddr_1.net.port = XinReadInt(pf, "svrport1", 9001); /*读主站3IP*/ ParaTermG.svraddr_2.net.chn = XinReadInt(pf, "svraddrflag2",0x04);//读上行连接方式 if(XinReadString(pf, "svraddrIp2", str, 24) > 0) { StringToIp(str, ParaTermG.svraddr_2.net.ip); } ParaTermG.svraddr_2.net.port = XinReadInt(pf, "svrport2", 9001); /*读网关地址*/ if(XinReadString(pf, "gateaddr", str, 24) > 0) { StringToIp(str, ParaTermG.gate_addr.net.ip); } /*by ydl add 2011-03-21*/ ParaTermG.gate_addr.net.port = XinReadInt(pf, "gateport", 9001); /*读短信中心号码*/ //XinReadHex(pf, "smsaddr", str,16); int rtn; rtn = XinReadHex(pf, "smsaddr", (unsigned char *)str, 8); if (rtn != -1) { sms_phone_tonormal(rtn, (unsigned char *)str, ParaTermG.sms_addr); } XinReadString(pf, "apn", ParaTermG.apn,16); /*by ydl modify 2011-05-15*/ XinReadString( pf, "cdmausr", ParaTermG.cdma_usr,32 ); XinReadString(pf, "cdmapwd", ParaTermG.cdma_pwd, 32); XinReadHex(pf, "norpwd", ParaTermG.nor_pwd, 3);//普通密码 XinReadHex(pf, "compwd", ParaTermG.com_pwd, 3);//设置密码 XinReadHex(pf, "admpwd", ParaTermG.adm_pwd,3);//管理员密码 /*默认振铃次数*/ ParaTermG.search_device = XinReadInt( pf, "search_device", 0); /*任务开始时间*/ ParaTermG.task_starthour = XinReadInt(pf, "taskstarthour", 0x01); /*任务执行间隔*/ ParaTermG.task_startdev = XinReadInt(pf, "taskstartdev", 0x01);//间隔一小时 /*默认载波中继方式*/ ParaTermG.plc_route_type = XinReadInt( pf, "plcroutetype", 0x00);//自动中继 /*默认线损阀值*/ XinReadHex( pf, "gatelinewaste",ParaTermG.gate_linewaste, 2);// 1表示0.1% /*重点用户数据上传时间*///保存为BCD码例如,如果是12点,则保存的是12而不是0x12 ParaTermG.hour_upimpdata = XinReadInt( pf, "hourupimpdata", 0xFF);//不主动上传 /*日冻结上传时间*/ ParaTermG.hour_updaydata = XinReadInt( pf, "hourupdaydata", 0xFF);//不主动上传 /*告警使能控制字*/ ParaTermG.alarm_flag = XinReadInt( pf, "alarmflag", 0);//不告警 /*级联从终端地址*/ //XinReadHex(pf, "cascadeaddr", ParaTermG.cascade_addr, 16); unsigned char tmpbuf[16]; XinReadHex(pf, "cascadeaddr", tmpbuf, 16); Cascade_AddrChange(tmpbuf, ParaTermG.cascade_addr,1); //加载注册信息 ParaTermG.reg.autoflag = XinReadInt( pf, "AutoFlag", 0x01); //检查注册码是不是本机使用的 XinReadString(pf,"RegeCode",ParaTermG.reg.register_code,13); char tempregcode[13]; MakeRegisteCode(tempregcode); if(strcmp(ParaTermG.reg.register_code,tempregcode) == 0) //注册验证成功 { ParaTermG.reg.autoflag = 1; } else { ParaTermG.reg.autoflag = 0; } ParaTermG.reg.autoflag = 1; /*级联标记*/ ParaTermG.cascade_flag = XinReadInt( pf, "cascadeflag", 1);//默认为主集中器,且不允许级联 /*月末数据抄收开始时间*/ ParaTermG.day_read_mondata = XinReadInt( pf, "dayreadmondata", 0x01);//一号开始冻结 /*月末数据抄收开始时间*/ ParaTermG.hour_read_mondata = XinReadInt( pf, "hourreadmondata", 0x01);// 1点 /*月冻结上传开始时间*/ ParaTermG.day_up_mondata = XinReadInt( pf, "dayupmondata", 0x03); // 3号 ParaTermG.hour_up_mondata = XinReadInt( pf, "hourupmondata", 0x05);//5点上传 // printf("day_mont=%d,hour_mont=%d",ParaTermG.day_read_mondata,ParaTermG.hour_read_mondata); // printf("day_up_mont=%d,hour_up_mont=%d",ParaTermG.day_up_mondata,ParaTermG.hour_up_mondata); XinReadHex(pf,"peibian_addr",tmpbuf,4); Cascade_AddrChange(tmpbuf,ParaTermG.peibian_addr,0); XinReadHex(pf, "ct", ParaTermG.ct, 2);//配变CT for(i=0;i<MAX_485PORT;i++){ sprintf((char *)tmpbuf,"baud%d",i); ParaTermG.port[i].baud = XinReadInt(pf, (char *)tmpbuf, 4); //默认为1200 sprintf((char *)tmpbuf,"databits%d",i); ParaTermG.port[i].databits = XinReadInt(pf, (char *)tmpbuf, 8);//默认为8 sprintf((char *)tmpbuf,"stopbits%d",i); ParaTermG.port[i].stopbits = XinReadInt(pf, (char *)tmpbuf, 1);//默认为1 sprintf((char *)tmpbuf,"parity%d",i); ParaTermG.port[i].parity = XinReadInt(pf, (char *)tmpbuf, 1);//校验位 sprintf((char *)tmpbuf,"func%d",i); ParaTermG.port[i].func= XinReadInt(pf, (char *)tmpbuf, i);//端口功能 } DebugPrint(0, "ok\n"); XinClose(pf); return 0; }