河北水利局项目

This commit is contained in:
2025-12-15 16:07:49 +08:00
commit f11a7c2b95
1146 changed files with 452892 additions and 0 deletions

77
yw/comp.c Normal file
View File

@@ -0,0 +1,77 @@
#include "stdafx.h"
#include "veryw.h"
extern bool manager_get_data(u8 * addr,u8* data,u8* state,u8* state2);
extern bool meter_find_id_fromaddr(u8 * addr,u16 * id);
extern void concent_read_onedata(u16 id,u8 * data,u8 state,u8 state2);
void sj_data_ack(u8 * meter,u8 * data)
{
// u16 len = 0;
// u8 * q = get_uart_send();
// sj_frame_data_ack(q,&len,meter,data);
// concent_send_uart(q,len);
u16 id = 0;
if(meter_find_id_fromaddr(meter,&id))
{
concent_read_onedata(id,data,data[4],data[5]);
}
}
void cur_dl_grouphistroy(u8 curnum,u8 * cur_addrgroup,u8 *outnum,u8 * outaddrgroup)
{
//
u8 i = 0;
* outnum = curnum;
u8 addr[7];
u8 tmpdata[20];
u8 state = 0;
u8 state2 = 0;
memset(addr,0,sizeof(addr));
memset(tmpdata,0,sizeof(tmpdata));
//
for(i=0;i<curnum;i++)
{
//
memset(addr,0,sizeof(addr));
memset(tmpdata,0,sizeof(tmpdata));
memmove(&outaddrgroup[i*21],&cur_addrgroup[i*6],6);
memmove(addr,&cur_addrgroup[i*6],6);
if(manager_get_data(addr,tmpdata,&state,&state2))
{
tmpdata[4] = state;
tmpdata[5] = state2;
}
else
{
memset(tmpdata,0xEE,sizeof(tmpdata));
}
memmove(&outaddrgroup[i*21+6],tmpdata,15);
}
}
void cur_gate_close(u16 id)
{
}
void cur_gate_open(u16 id)
{
}
void cur_3762_dl(u16 id)
{
}

44
yw/concenttime.c Normal file
View File

@@ -0,0 +1,44 @@
#include "stdafx.h"
#include "concenttime.h"
#include "rtc_ext.h"
/*
设置集中器时间
*/
//static u8 concenttime[6];
void concenttime_get(u8 * timeval)
{
// r8025t_get_time(&time_tt);
st_rtc_ext rtc_dat = {0x00};
read_rtc_time(&rtc_dat);
timeval[0] = rtc_dat.sec;
timeval[1] = rtc_dat.min;
timeval[2] = rtc_dat.hour;
timeval[3] = rtc_dat.day;
timeval[4] = rtc_dat.month;
timeval[5] = rtc_dat.year;
timeval[6] = 0x21;
}
void concenttime_set(u8 * time)
{
//秒分时日月年
st_rtc_ext rtc_dat = {0x00};
rtc_dat.sec = time[0];;
rtc_dat.min = time[1];
rtc_dat.hour = time[2];
rtc_dat.day = time[3];
rtc_dat.month = time[4];
rtc_dat.year = (0x20<<8)|time[5];
rtc_dat.week = 1;
set_rtc_time(rtc_dat);
}

9
yw/concenttime.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef __CONCENTTIME__
#define __CONCENTTIME__
#include "global.h"
void concenttime_set(u8 * time);
void concenttime_get(u8 * timeval);
#endif

47
yw/crc.c Normal file
View File

@@ -0,0 +1,47 @@
#include "stdafx.h"
#include "crc.h"
/*
static u16 crc16(unsigned char *buf,unsigned short length)
{
int i = 0;
int j = 0;
int crc16 = 0xffff;
for (i = 0;i < length;i++)
{
crc16 = crc16 ^ buf[i];
for (j = 0;j < 8;j++)
{
if (crc16 & 0x01)
{
crc16 = (crc16 >> 1) ^ 0xa001;
}
else
{
crc16 = crc16 >> 1;
}
}
}
return (u16)crc16;
}
*/
static unsigned int cal_crc16(unsigned char *ptr, unsigned int len)
{
unsigned int crc;
unsigned char i;
crc=0xffff;
while(len--!=0) {
crc = crc^(*ptr);
for(i=0; i<8; i++) {
if((crc&0x0001)==0x0001) {crc>>=1;crc^=0xA001;}
else crc>>=1;
}
ptr++;
}
return(crc);
}
u16 get_crc(u8 * val,u16 len)
{
return cal_crc16(val,len);
}

10
yw/crc.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef __CRC__
#define __CRC__
#include "global.h"
u16 get_crc(u8 * val,u16 len);
#endif

307
yw/doc.c Normal file
View File

@@ -0,0 +1,307 @@
#include "stdafx.h"
#include "doc.h"
static struct meter_struct meter[MAX_METER_NUM];
//static u16 meter_num = 0;
/*
增加电表
id 总是保持统一
*/
void meter_init()
{
memset(meter,0,sizeof(meter));
}
bool meter_find(u8 * addr,u16 * index)
{
for(u16 i = 0;i<MAX_METER_NUM;i++)
{
if(0 == memcmp(addr,meter[i].addr,6))
{
*index = i;
return true;
}
}
return false;
}
void meter_add(u16 id,u8 * addr,u8 type,u8 pro,u8 baud,u8 * pd,u8 * coladdr,u8 port)
{
//判断是否是唯一。
//如果有相同的。不加入
u16 index = 0;
if(!meter_find(addr,&index))
{
if(id<MAX_METER_NUM)
{
meter[id].id = id;
memmove(meter[id].addr,addr,7);
meter[id].type = type;
meter[id].pro = pro;
meter[id].baud = baud;
memmove(meter[id].password,pd,4);
memmove(meter[id].colladdr,coladdr,6);
meter[id].port = port;
}
}
}
/*
读电表档案
*/
bool is_meter_read(u8 * val)
{
u8 * num = val;
// if(*num<MAX_METER_NUM)
{
u8 * id = val + 1;
for(u8 i=0; i<*num; i++)
{
u16 index = (id[1]<<8)|id[0];
if(index>MAX_METER_NUM)
{
return false;
}
id = id + 2;
}
return true;
}
//return false;
}
void meter_read(u8 * id,u8 * val,u16 * len)
{
u8 num = * id;
u8 i = 0;
u16 index = 0;
//因为容易挂,所以对数据合法性判断
if(is_meter_read(id))
{
id = id + 1;
* val = num;
val = val + 1;
// if(num<MAX_METER_NUM)
{
for(i=0;i<num;i++)
{
index = (id[1]<<8)|id[0];
//0 1
//val[0] = id[0];
//val[1] = id[1];
//为统一,用表里实际的值来填充!
val[0] = meter[index].id&0xFF;//id[0];
val[1] = meter[index].id>>8&0xFF;//id[1];
//234 567 8
memmove(&val[2],meter[index].addr,7);
//9
val[9] = meter[index].type;
//10
val[10] = meter[index].pro;
//11
val[11] = meter[index].baud;
//12 13 14 15
memmove(&val[12],meter[index].password,4);
//16 17 18 19 20 21
//memmove(&val[16],meter[index].colladdr,4);
//22
//val[22] = meter[index].port;
id = id + 2;
//val = val + 23;
val = val + 17;
}
//*len = 23 * num + 1;
*len = 17 * num + 1;
}
}
}
bool meter_find_id_fromaddr(u8 * addr,u16 * id)
{
for(u16 i = 0;i<MAX_METER_NUM;i++)
{
if(0 == memcmp(addr,meter[i].addr,6))
{
* id = i;
return true;
}
}
return false;
}
bool meter_find_addr6(u8 * addr)
{
for(u16 i = 0;i<MAX_METER_NUM;i++)
{
if(0 == memcmp(addr,meter[i].addr,6) && meter[i].id == i)
{
return true;
}
}
return false;
}
bool meter_find_addr6_relay(u8 * addr)
{
u8 * relay = NULL;
for(u16 i = 0;i<MAX_METER_NUM;i++)
{
relay = addr + 6;
if(0 == memcmp(addr,meter[i].addr,6) && meter[i].id == i && 0 == memcmp(relay,meter[i].colladdr,6))
{
return true;
}
}
return false;
}
void meter_close(u8 * id)
{
}
void doc_write()
{
}
void doc_read()
{
}
bool is_doctype_ok(u16 index)
{
//暂时认为全部打开,有命令可以设置关闭。
// if((meter[index].type == 0x81 || meter[index].type == 0x01)&&(meter[index].id != 0))
//0x81 有阀门
//0x01 没有阀门
//
if((meter[index].id != 0) && meter[index].id == index)
{
return true;
}
return false;
}
//合法的档案总数
u16 meter_get_count()
{
u16 count = 0;
u16 i = 0;
for(i=0;i<MAX_METER_NUM;i++)
{
if(is_doctype_ok(i))
{
count++;
}
}
return count;
}
//按序号得到的档案id号。
bool meter_get_id(u16 index,u16 * id)
{
//count 档案里有用的才用。
//index是有序的索引值。
//id是实际返回的值
u16 count = 0;
u16 i = 0;
for(i=0;i<MAX_METER_NUM;i++)
{
if(is_doctype_ok(i))
{
if(index == count)
{
*id = meter[i].id;
return true;
}
count ++;
}
}
return false;
}
//按序号得到的档案地址号。
bool meter_get_addr(u16 index,u8 * addr)
{
//count 档案里有用的才用。
//index是有序的索引值。
//id是实际返回的值
u16 count = 0;
u16 i = 0;
for(i=0;i<MAX_METER_NUM;i++)
{
if(is_doctype_ok(i))
{
if(index == count)
{
memmove(addr,meter[i].addr,7);
return true;
}
count ++;
}
}
return false;
}
//按序号得到的档案地址号。
bool meter_get_relay(u16 index,u8 * addr)
{
//count 档案里有用的才用。
//index是有序的索引值。
//id是实际返回的值
u16 count = 0;
u16 i = 0;
for(i=0;i<MAX_METER_NUM;i++)
{
if(is_doctype_ok(i))
{
if(index == count)
{
memmove(addr,meter[i].colladdr,6);
return true;
}
count ++;
}
}
return false;
}
//id 为实际电表数组里的下标
bool meter_getaddress_fromid(u16 id,u8 * addr)
{
if(id<MAX_METER_NUM)
{
if(NULL != addr)
{
memmove(addr,meter[id].addr,7);
return true;
}
}
else
{
printf("\r\n**********meter_getfromid 大于电表总数 id >= MAX_METER_NUM **********\n\r\n");
}
return false;
}

46
yw/doc.h Normal file
View File

@@ -0,0 +1,46 @@
#ifndef __DOC__
#define __DOC__
#include "global.h"
//#define MAX_METER_NUM (200) //超过200写flash会挂未查明原因
#define MAX_METER_NUM (200)
/*
档案
*/
struct meter_struct
{
u16 id; //表序号 BCD 2
u8 addr[7]; //表地址BCD 7
u8 type; //表类型代码BCD 1
u8 pro; //协议类别BCD 1
u8 baud; //波特率BCD 1
u8 password[4]; //表密码HEX 4
u8 colladdr[6]; //采集模块/中继器编号(地址) BCD 6
u8 port; //采集端口BCD 1
u8 state; //开关
u8 isopen; //档案是否关闭
};
void meter_close(u8 * id);
void meter_add(u16 id,u8 * addr,u8 type,u8 pro,u8 baud,u8 * pd,u8 * coladdr,u8 port);
void meter_read(u8 * id,u8 * val,u16 * len);
void doc_write();
void doc_read();
u16 meter_get_count();
bool meter_getfromid(u16 id,u8 * addr);
bool meter_get_id(u16 index,u16 * id);
bool meter_get_addr(u16 index,u8 * addr);
bool meter_find_id(u8 * addr,u16 * id);
bool meter_find_addr6(u8 * addr);
//直接根据index得到id;
bool meter_get_real_id(u16 index,u16 * id);
bool is_doctype_ok(u16 index);
bool meter_find_id_fromaddr(u8 * addr,u16 * id);
bool meter_getaddress_fromid(u16 id,u8 * addr);
bool meter_get_addr(u16 index,u8 * addr);
bool meter_get_id(u16 index,u16 * id);
#endif

96
yw/frame.c Normal file
View File

@@ -0,0 +1,96 @@
#include "stdafx.h"
#include "FreeRTOS.h"
#include "task.h"
#include "frame.h"
#include "frame1.h"
#include "doc.h"
#include "veryw.h"
#include "netpara.h"
#include "hearttime.h"
#include "isreport.h"
#include "rptime.h"
#include "concenttime.h"
#include "include.h"
/*
Ö÷Õ¾ºÍ¼¯ÖÐÆ÷½»»¥
*/
extern void gprs_send_flag();
extern void gprs_send_proc_direct(u8 * val,u16 len );
extern void gprs_recv_judge_timeset();
extern void cur_3762_dl(u16 id);
extern void cur_gate_open(u16 id);
extern void cur_gate_close(u16 id);
extern void rpprocess_recvack();
extern u8 report_get_curnum();
extern u8 * report_getdataval();
extern int format_1();
extern void meter_init();
extern void f3762_sync_setflag2();
extern void set_time_save();
extern void concent_read_batdata(u8 * val,u16 * len,u8 num,u8 * data);
extern void rp_assigned_getdata(u8 num,u8 * pnum);
extern void ClearMeterInfo_realdl( void );
extern void mbus_master_tx_begin();
extern void controlkeyaddr(u8 *str1,u8 val);
extern void simul_plc_rx_addr(u8 *str1);
extern u8 * smt_get_val();
extern u8 smt_get_len();
extern void amt_task(u8 * val);
extern void concent_upgrade(u32 * seg);
extern u16 get_crc(u8 * val,u16 len);
void concent_up_fail();
extern u8 send_buff[512];
extern u16 send_buff_len;
extern u8 recv_buff[512];
extern u16 recv_buff_len;
u8 * get_uart_recv()
{
return recv_buff;
}
u16 get_uart_recv_len()
{
return recv_buff_len;
}
u8 * get_uart_send()
{
return send_buff;
}
u16 get_uart_send_len()
{
return send_buff_len;
}
u16 * get_uart_send_plen()
{
return (&send_buff_len);
}
void concent_send_uart(u8 * val,u16 len)
{
memmove(send_buff,val,len);
send_buff_len = len;
// gprs_send_proc_direct(get_uart_send(),get_uart_send_len());
gprs_send_flag();
}
void concent_send_gprs()
{
gprs_send_proc_direct(get_uart_send(),get_uart_send_len());
}

33
yw/frame.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef __FRAME__
#define __FRAME__
#include "global.h"
struct frame_struct
{
u8 begin;
u16 len;
u16 serial;
u8 ctl;
u8 addr[5];
u8 * data;
u16 crc;
u8 end;
};
u16 getid_frombcd(u8 * p);
void getbcd_fromid(u8 * p,u16 id);
//unsigned char BCDToHex(unsigned int bcd_data);
//unsigned int Hex2BCD(unsigned char hex_data);
void P2From16(unsigned char * P2,unsigned short Val);
unsigned short U16From2(unsigned char * P2);
u8 * frame_get_valpos(u8 * val);
void frame_fill_head(u8 * val,u16 len,u8 afn);
void frame_fill_ack_head(u8 * val,u16 len,u8 afn);
void frame_fill_end(u8 * val,u16 len);
bool frame_islegal(u8 * val);
u16 get_recvserial();
void set_recvserial(u16 serial);
u8 * concent_getsend_pval();
void concent_rp_data(u8 * val,u16 * len,u16 datalen);
#endif

74
yw/frame1.h Normal file
View File

@@ -0,0 +1,74 @@
#ifndef __FRAME1__
#define __FRAME1__
#define CTL_INIT_DOWN 0x01 //1.集中器初始化
#define CTL_INIT_UP 0x81
#define CTL_LOAD_DOWN 0x02 //2.集中器登录网络
#define CTL_LOAD_UP 0x82
#define CTL_HEART_DOWN 0x03 //3.网络心跳数据包
#define CTL_HEART_UP 0x83
#define CTL_FILE_DOWN 0x04 //4.下载水表档案
#define CTL_FILE_UP 0x84
#define CTL_SETCLOSE_DOWN 0x05 //5.设置关闭相关水表档案
#define CTL_SETCLOSE_UP 0x85
#define CTL_SETRPCLOSE_DOWN 0x06 //6.设置集中器上报停止
#define CTL_SETRPCLOSE_UP 0x86
#define CTL_SETRPOPEN_DOWN 0x07 //7.设置集中器上报允许
#define CTL_SETRPOPEN_UP 0x87
#define CTL_SETRPHTIME_DOWN 0x08 //8.设置集中器上报时间
#define CTL_SETRPHTIME_UP 0x88
#define CTL_SETADDR_DOWN 0x09 //9.设置集中器地址
#define CTL_SETADDR_UP 0x89
#define CTL_SETNETPARA_DOWN 0x0A //10.设置集中器网络参数
#define CTL_SETNETPARA_UP 0x8A
#define CTL_SETTIME_DOWN 0x0B //11.设置集中器时间
#define CTL_SETTIME_UP 0x8B
#define CTL_SETHSPACE_DOWN 0x0C //12.设置集中器心跳包间隔时间
#define CTL_SETHSPACE_UP 0x8C
#define CTL_SETONECLOSE_DOWN 0x0D //13.设置集中器关闭指定的水表阀门
#define CTL_SETONECLOSE_UP 0x8D
#define CTL_SETONEOPEN_DOWN 0x0E //14.设置集中器开启指定的水表阀门
#define CTL_SETONEOPEN_UP 0x8E
#define CTL_SETTIMING_DOWN 0x0F //15.设置集中器定时开关水表阀门
#define CTL_SETTIMING_UP 0x8F
#define CTL_RDFILE_DOWN 0x10 //16.读取水表档案
#define CTL_RDFILE_UP 0x90
#define CTL_RDNETPARA_DOWN 0x11 //17.读取集中器网络参数
#define CTL_RDNETPARA_UP 0x91
#define CTL_RDHSPACE_DOWN 0x12 //18.读取集中器心跳包间隔时间
#define CTL_RDHSPACE_UP 0x92
#define CTL_RDRPSTARE_DOWN 0x13 //19.读取集中器上报是否允许
#define CTL_RDRPSTARE_UP 0x93
#define CTL_RDRPHTIME_DOWN 0x14 //20.读取集中器上报时间
#define CTL_RDRPHTIME_UP 0x94
#define CTL_RDREALDATA_DOWN 0x15 //21.抄读集中器中单块水表的实时数据
#define CTL_RDREALDATA_UP 0x95
#define CTL_RDASSIGNDATA_DOWN 0x16 //22.抄读集中器中所指定的水表数据//历史数据?
#define CTL_RDASSIGNDATA_UP 0x96
#define CTL_RDTIME_DOWN 0x17 //23.读取集中器实时时钟
#define CTL_RDTIME_UP 0x97
#define CTL_RDVER_DOWN 0x18 //24.读取集中器版本号
#define CTL_RDVER_UP 0x98
#define CTL_TRPDATA_DOWN 0x19 //25.集中器定时自动上传水表数据
#define CTL_TRPDATA_UP 0x99
#define CTL_RDPIC_DOWN 0x1A //26.抄读集中器中单块摄像水表的实时二值画图片信息数据
#define CTL_RDPIC_UP 0x9A
//#define CTL_RDGRAYPIC_DOWN 0x1B //27.抄读集中器中单块摄像水表的实时灰度图片信息数据
//#define CTL_RDGRAYPIC_UP 0x9B
#define CTL_TRPSTATE_DOWN 0x1C //28.集中器上传定时开关水表阀门操作的执行状态信息
#define CTL_TRPSTATE_UP 0x9C
#define CTL_SETPRICE_DOWN 0x1D //29.下发价格
#define CTL_SETPRICE_UP 0x9D
#define CTL_CURFAIL_UP 0xFF //30.集中器应答当前操作失败通信帧
#define CTL_UPGRADE_DOWN 0x1B //升级下发
#define CTL_UPGRADE_UP 0x9B //升级回应
#define DIRECTION_UP 0x01 //集中器主动上传数据
#define DIRECTION_DOWN 0x02 //回应
#endif

138
yw/generalyw.c Normal file
View File

@@ -0,0 +1,138 @@
#include "stdafx.h"
#include "frame.h"
#include "crc.h"
/*
帧的通用表达
*/
static u16 send_serial = 0;
static u16 recv_serial = 0;
static u16 get_sendserial()
{
return (send_serial++);
}
/*
static void serialserial_add(u8 * value)
{
send_serial ++;
value[0] = send_serial&0xFF;
value[1] = (send_serial>>8)&0xFF;
}
*/
static u16 get_recvserial()
{
return recv_serial;
}
void set_recvserial(u16 serial)
{
recv_serial = serial;
}
/*
//0x30 ---> 30
unsigned char BCDToHex(unsigned int bcd_data)
{
unsigned char temp;
unsigned char tmp1 = bcd_data&0x0f;
unsigned char tmp2 = (bcd_data>>4)&0x0f;
unsigned char tmp3 = (bcd_data>>8)&0x0f;
unsigned char tmp4 = (bcd_data>>12)&0x0f;
temp=(tmp4*1000) + (tmp3*100)+(tmp2*10)+tmp1;
return temp;
}
*/
//30--->0x30
unsigned int Hex2BCD(unsigned char hex_data)
{
unsigned int bcd_data;
unsigned char temp;
temp=hex_data%100;
bcd_data=((unsigned int)hex_data)/100<<8;
bcd_data=bcd_data|temp/10<<4;
bcd_data=bcd_data|temp%10;
return bcd_data;
}
//将u16数字转换成 2个字节。
void P2From16(unsigned char * P2,unsigned short Val)
{
P2[0] = (Val&0xFF);
P2[1] = ((Val)>>8)&0xFF;
}
/*
//199 0x99 0x01
u16 getid_frombcd(u8 * p)
{
return BCDToHex(p[1]) * 100 + BCDToHex(p[0]);
}
void getbcd_fromid(u8 * p,u16 id)
{
u8 id1 = id%100;
u8 id2 = id/100;
p[0] = Hex2BCD(id1);
p[1] = Hex2BCD(id2);
}
*/
/*
得到校验和
*/
u8 * frame_get_valpos(u8 * val)
{
return &val[6];
}
void frame_fill_head(u8 * val,u16 len,u8 afn)
{
val[0] = 0x68;
val[1] = len&0xFF;
val[2] = (len>>8)&0xFF;
val[3] = get_sendserial()&0xFF;
val[4] = (get_sendserial()>>8)&0xFF;
val[5] = afn;
}
void frame_fill_ack_head(u8 * val,u16 len,u8 afn)
{
val[0] = 0x68;
val[1] = len&0xFF;
val[2] = (len>>8)&0xFF;
val[3] = get_recvserial()&0xFF;
val[4] = (get_recvserial()>>8)&0xFF;
val[5] = afn;
}
void frame_fill_end(u8 * val,u16 len)
{
u16 ck = 0;
val[1] = len&0xFF;
val[2] = (len>>8)&0xFF;
ck = get_crc(&val[1],len-4);
val[len-3] = ck&0xFF;
val[len-2] = (ck>>8)&0xFF;
val[len-1] = 0x16;
}
bool frame_islegal(u8 * val)
{
u16 len = U16From2(&val[1]);
u16 ck1 = 0;
u16 ck2 = 0;
if(0x68 == val[0] && 0x16 == val[len-1])
{
ck1 = get_crc(&val[1],len-4);
ck2 = U16From2(&val[len-3]);
if(ck1 == ck2)
{
return true;
}
}
return false;
}

25
yw/hearttime.c Normal file
View File

@@ -0,0 +1,25 @@
#include "stdafx.h"
#include "hearttime.h"
static u8 spacetime = 120;
u8 hearttime_get()
{
return spacetime;
}
void hearttime_set(u8 space)
{
spacetime = space;
}
void hearttime_write()
{
heart_writefile(&spacetime,sizeof(spacetime));
}
void hearttime_read()
{
heart_readfile(&spacetime,sizeof(spacetime));
}

10
yw/hearttime.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef __HEARTTIME__
#define __HEARTTIME__
#include "global.h"
u8 hearttime_get();
void hearttime_set(u8 space);
void hearttime_write();
void hearttime_read();
#endif

46
yw/isreport.c Normal file
View File

@@ -0,0 +1,46 @@
#include "stdafx.h"
#include "isreport.h"
/*
ÉĎą¨ÍŁÖš
*/
static u8 isreport = 0xAA;
bool isreport_get()
{
if(isreport == 0x55)
{
return true;
}
return false;
}
u8 isreport_getval()
{
return isreport;
}
void isreport_set(bool isrp)
{
if(isrp)
{
isreport = 0x55;
}
else
{
isreport = 0xAA;
}
}
void isreport_write()
{
isrp_writefile((u8*)&isreport,sizeof(isreport));
}
void isreport_read()
{
isrp_readfile((u8*)&isreport,sizeof(isreport));
}

13
yw/isreport.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef __ISREPORT__
#define __ISREPORT__
#include "global.h"
void isreport_set(bool isrp);
bool isreport_get();
void isreport_write();
void isreport_read();
u8 isreport_getval();
#endif

374
yw/netpara.c Normal file
View File

@@ -0,0 +1,374 @@
#include "stdafx.h"
#include "netpara.h"
#include "gprs.h"
extern int net_connect_first;
extern afn04_F3_st comm_04F3_param;
/*
网络参数
*/
struct netpara_struct
{
u8 type;
u8 ip1[4]; //主ip
u16 port1;
u8 ip2[4]; //备用ip
u16 port2;
u8 ip3[4]; //网关
u16 port3;
u8 ip4[4]; //代理服务器
u16 port4;
u8 apn[16];
u8 localip[4]; //本地ip
u16 localport; //本地端口
u8 mask[4]; //子网掩码
u8 localmac[6]; //mac地址
};
static struct netpara_struct netpara;
u8 netpara_gettype()
{
return netpara.type;
}
//主ip
u8 * netpara_getip1()
{
return netpara.ip1;
}
u16 netpara_getport1()
{
return netpara.port1;
}
//备用ip
u8 * netpara_getip2()
{
return netpara.ip2;
}
u16 netpara_getport2()
{
return netpara.port2;
}
//网关
u8 * netpara_getip3()
{
return netpara.ip3;
}
u16 netpara_getport3()
{
return netpara.port3;
}
//代理服务器
u8 * netpara_getip4()
{
return netpara.ip4;
}
u16 netpara_getport4()
{
return netpara.port4;
}
//apn
u8 * netpara_getapn()
{
return netpara.apn;
}
//本地
u8 * netpara_getlocalip()
{
return netpara.localip;
}
u16 netpara_getlocalport()
{
return netpara.localport;
}
u8 * netpara_getmask()
{
return netpara.mask;
}
u8 * netpara_getlocalmac()
{
return netpara.localmac;
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//设置
void netpara_settype(u8 type)
{
netpara.type = type;
}
//主ip
void netpara_setip1(u8 * ip1)
{
memmove(netpara.ip1,ip1,4);
}
void netpara_setport1(u16 port1)
{
netpara.port1 = port1;
}
//备用ip
void netpara_setip2(u8 * ip2)
{
memmove(netpara.ip2,ip2,4);
}
void netpara_setport2(u16 port2)
{
netpara.port2 = port2;
}
//网关
void netpara_setip3(u8 * ip3)
{
memmove(netpara.ip3,ip3,4);
}
void netpara_setport3(u16 port3)
{
netpara.port3 = port3;
}
//代理服务器
void netpara_setip4(u8 * ip4)
{
memmove(netpara.ip4,ip4,4);
}
void netpara_setport4(u16 port4)
{
netpara.port4 = port4;
}
void netpara_setapn(u8 * apn)
{
memmove(netpara.apn,apn,16);
}
//本地
void netpara_setlocalip(u8 * localip)
{
memmove(netpara.localip,localip,4);
}
void netpara_setlocalport(u16 port)
{
netpara.localport = port;
}
void netpara_setmask(u8 * mask)
{
memmove(netpara.mask,mask,4);
}
void netpara_setlocalmac(u8 * mac)
{
memmove(netpara.localmac,mac,6);
}
void netpara_setval(u8 *val)
{
//0
//1 2 3 4 5 6 ip1
//7 8 9 10 11 12 ip2
//13 14 15 16 17 18 ip3
//19 20 21 22 23 24 ip4
//25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
//41 42 43 44 45 46
//47 48 49 50
//51 52 53 54 55 56
u16 port = 0;
netpara_settype(val[0]);
port = (val[6]<<8)|val[5];
netpara_setip1(&val[1]);
netpara_setport1(port);
port = (val[12]<<8)|val[11];
netpara_setip2(&val[7]);
netpara_setport2(port);
port = (val[18]<<8)|val[17];
netpara_setip3(&val[13]);
netpara_setport3(port);
port = (val[24]<<8)|val[23];
netpara_setip4(&val[19]);
netpara_setport4(port);
netpara_setapn(&val[25]);
port = (val[46]<<8)|val[45];
netpara_setlocalip(&val[41]);
netpara_setlocalport(port);
netpara_setmask(&val[47]);
netpara_setlocalmac(&val[51]);
//*
//
comm_04F3_param.primary.ip1 = netpara.ip1[0];
comm_04F3_param.primary.ip2 = netpara.ip1[1];
comm_04F3_param.primary.ip3 = netpara.ip1[2];
comm_04F3_param.primary.ip4 = netpara.ip1[3];
comm_04F3_param.primary.port = netpara.port1;
comm_04F3_param.reserve.ip1 = netpara.ip2[0];;
comm_04F3_param.reserve.ip2 = netpara.ip2[1];
comm_04F3_param.reserve.ip3 = netpara.ip2[2];
comm_04F3_param.reserve.ip4 = netpara.ip2[3];
comm_04F3_param.reserve.port = netpara.port2;
memcpy(comm_04F3_param.APN, netpara.apn, sizeof(netpara.apn));
//*/
}
void net_para_save()
{
/*
ipflag.ip3 = 1;//延时更新ip
ipflag.ipchange = 1;
//M3761_Param_To_UIP();
//NET 重新连接
net_connect_first = 0;
//GPRS 重新连接
gprs_init_flag= 0;
gprs_connect_flag = 0;
gprs_socket_flag = 0;
system_save();
*/
ipport_write();
ipport_init();
}
void netpara_getval(u8 *val)
{
//0
//1 2 3 4 5 6 ip1
//7 8 9 10 11 12 ip2
//13 14 15 16 17 18 ip3
//19 20 21 22 23 24 ip4
//25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
//41 42 43 44 45 46
//47 48 49 50
//51 52 53 54 55 56
//11 + 3 = 14 + 57 = 71 = 0x47
netpara.ip1[0] = comm_04F3_param.primary.ip1;
netpara.ip1[1] =comm_04F3_param.primary.ip2;
netpara.ip1[2] = comm_04F3_param.primary.ip3;
netpara.ip1[3] =comm_04F3_param.primary.ip4 ;
netpara.port1 = comm_04F3_param.primary.port;
netpara.ip2[0] = comm_04F3_param.reserve.ip1;;
netpara.ip2[1] = comm_04F3_param.reserve.ip2;
netpara.ip2[2] =comm_04F3_param.reserve.ip3 ;
netpara.ip2[3] = comm_04F3_param.reserve.ip4;
netpara.port2 = comm_04F3_param.reserve.port;
memcpy(netpara.apn,comm_04F3_param.APN , sizeof(netpara.apn));
u16 port = 0;
u8 * p = NULL;
val[0] = netpara_gettype();
p = netpara_getip1();
memmove(&val[1],p,4);
port = netpara_getport1();
val[5] = port&0xFF;
val[6] = (port>>8)&0xFF;
p = netpara_getip2();
memmove(&val[7],p,4);
port = netpara_getport2();
val[11] = port&0xFF;
val[12] = (port>>8)&0xFF;
p = netpara_getip3();
memmove(&val[13],p,4);
port = netpara_getport3();
val[17] = port&0xFF;
val[18] = (port>>8)&0xFF;
p = netpara_getip4();
memmove(&val[19],p,4);
port = netpara_getport4();
val[23] = port&0xFF;
val[24] = (port>>8)&0xFF;
p = netpara_getapn();
memmove(&val[25],p,16);
p = netpara_getlocalip();
memmove(&val[41],p,4);
port = netpara_getlocalport();
val[45] = port&0xFF;
val[46] = (port>>8)&0xFF;
p = netpara_getmask();
memmove(&val[47],p,4);
p = netpara_getlocalmac();
memmove(&val[51],p,6);
}
void netpara_write()
{
}
void netpara_read()
{
}

11
yw/netpara.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef __NETPARA__
#define __NETPARA__
#include "global.h"
void netpara_setval(u8 *val);
void netpara_getval(u8 *val);
void netpara_write();
void netpara_read();
#endif

70
yw/rptime.c Normal file
View File

@@ -0,0 +1,70 @@
#include "stdafx.h"
#include "rptime.h"
struct rptime_struct
{
u8 type;
u8 year;
u8 month;
u8 day;
u8 hour;
u8 minute;
u8 second;
};
struct rptime_struct rptime;
void rptime_get(u8 * val)
{
val[0] = rptime.type;
val[1] = rptime.year;
val[2] = rptime.month;
val[3] = rptime.day;
val[4] = rptime.hour;
val[5] = rptime.minute;
val[6] = rptime.second;
}
void rptime_set(u8 * val)
{
rptime.type = val[0];
rptime.year = val[1];
rptime.month = val[2];
rptime.day = val[3];
rptime.hour = val[4];
rptime.minute = val[5];
rptime.second = val[6];
}
u8 rp_getday()
{
return rptime.day;
}
u8 rp_gethour()
{
return rptime.hour;
}
u8 rp_getminute()
{
return rptime.minute;
}
u8 rp_getsecond()
{
return rptime.second;
}
void rptime_write()
{
rptime_writefile((u8*)&rptime,sizeof(rptime));
}
void rptime_read()
{
rptime_readfile((u8*)&rptime,sizeof(rptime));
}

15
yw/rptime.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef __RPTIME__
#define __RPTIME__
#include "global.h"
void rptime_get(u8 * val);
void rptime_set(u8 * val);
void rptime_write();
void rptime_read();
u8 rp_getday();
u8 rp_gethour();
u8 rp_getminute();
u8 rp_getsecond();
#endif

6
yw/stdafx.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef __STDAFX__
#define __STDAFX__
#endif

6
yw/ver.c Normal file
View File

@@ -0,0 +1,6 @@
#include "stdafx.h"
#include "veryw.h"
//const u8 ver[8] = {0x48,0x54,0x00,0x00,0x19,0x09,0x19,0x00};

8
yw/veryw.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef __VERYW__
#define __VERYW__
#include "global.h"
u8 * get_veryw();
#endif