You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
239 lines
5.6 KiB
239 lines
5.6 KiB
#include "app_config.h"
|
|
///#include "../bsp/cs1232.h"
|
|
#include "../bsp/chipid.h"
|
|
// #include "../msp/eeprom.h"
|
|
// #include "../msp/msp_eeprom.h"
|
|
#include "../clib/clib.h"
|
|
|
|
|
|
|
|
GlobalParam G;
|
|
GlobalRegister R;
|
|
//WR_Buf wr_buf;
|
|
|
|
void L3_param_init(void)
|
|
{
|
|
G.head[0] = HEAD0;
|
|
G.head[1] = HEAD1;
|
|
|
|
//U8 i;
|
|
G.debug = 1;
|
|
//station模式状态
|
|
G.st_status = 0; //0:none 1:wifi_ok 2:tcp_connect_ok
|
|
//station模式sid
|
|
Lc_strcpy(G.st_sid,"sdf");
|
|
// Lc_strcpy(G.st_sid,"iPhone11");
|
|
//station模式pwd
|
|
Lc_strcpy(G.st_pwd,"dfasgg");
|
|
// Lc_strcpy(G.st_pwd,"12345678");
|
|
//ap模式状态
|
|
G.ap_status = 0;//0: none 1: ap_ok 2:tcp_server_ok
|
|
//ap模式sid
|
|
Lc_strcpy(G.ap_sid,"cc_pen_ap");
|
|
//ap模式pwd
|
|
Lc_strcpy(G.ap_pwd,"ccsens123");
|
|
|
|
#if 0
|
|
wr_buf.wIndex = wr_buf.rIndex = 0;
|
|
wr_buf.maxsize = sizeof(wr_buf.buf)/sizeof(PenPoint);
|
|
for(i=0;i<wr_buf.maxsize;i++)
|
|
{
|
|
wr_buf.buf[i].time = wr_buf.buf[i].x_axis = wr_buf.buf[i].y_axis = 0;
|
|
}
|
|
#endif
|
|
|
|
G.tail[0] = TAIL0;
|
|
G.tail[1] = TAIL1;
|
|
}
|
|
|
|
|
|
//读取reg内容,写入iap
|
|
void L3_reg_2_iap(void)
|
|
{
|
|
#if 0
|
|
iapData.slaver_id = R.p.slaver_id;
|
|
iapData.adc_ch_status = R.p.adc_ch_status;
|
|
iapData.weight_max = R.p.weight_max;
|
|
iapData.lmd = R.p.lmd;
|
|
iapData.adc_blur_mid = R.p.adc_blur_mid;
|
|
iapData.adc_blur_avg = R.p.adc_blur_avg;
|
|
iapData.adc_blur_shift[0] = R.p.adc_blur_shift[0];
|
|
iapData.adc_blur_shift[1] = R.p.adc_blur_shift[1];
|
|
iapData.adc_blur_shift[2] = R.p.adc_blur_shift[2];
|
|
iapData.adc_blur_threshold[0] = R.p.adc_blur_threshold[0];
|
|
iapData.adc_blur_threshold[1] = R.p.adc_blur_threshold[1];
|
|
//写入eeprom
|
|
if(L1_eep_write_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, (U8*)&iapData,sizeof(IapData),TRUE) == 0)
|
|
{
|
|
L0_uart0_sendstr("e2p write success");
|
|
}
|
|
|
|
if(L1_eep_write_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, D_EEP_SECTOR_BLOCK_SIZE, (U8*)&R.p,sizeof(R.p),TRUE) == 0)
|
|
{
|
|
L0_uart0_sendstr("e2p write success");
|
|
return;
|
|
}
|
|
L0_uart0_sendstr("e2p write failed");
|
|
#endif
|
|
}
|
|
|
|
//读取iap内容,写入reg
|
|
void L3_iap_2_reg(void)
|
|
{
|
|
#if 0
|
|
if(L1_eep_read_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, (U8*)&iapData, NULL) == 1)
|
|
{
|
|
L0_uart0_sendstr("e2p read failed");
|
|
}
|
|
L0_uart0_sendstr("e2p read success");
|
|
R.p.slaver_id = iapData.slaver_id;
|
|
R.p.adc_ch_status = iapData.adc_ch_status;
|
|
R.p.weight_max = iapData.weight_max ;
|
|
R.p.lmd = iapData.lmd;
|
|
R.p.adc_blur_mid = iapData.adc_blur_mid;
|
|
R.p.adc_blur_avg = iapData.adc_blur_avg;
|
|
R.p.adc_blur_shift[0] = iapData.adc_blur_shift[0];
|
|
R.p.adc_blur_shift[1] = iapData.adc_blur_shift[1];
|
|
R.p.adc_blur_shift[2] = iapData.adc_blur_shift[2];
|
|
R.p.adc_blur_threshold[0] = iapData.adc_blur_threshold[0];
|
|
R.p.adc_blur_threshold[1] = iapData.adc_blur_threshold[1];
|
|
|
|
if(L1_eep_read_block(D_EEP_PARAM_IN_SECTOR, D_EEP_PARAM_IN_BLOCK, D_EEP_SECTOR_BLOCK_SIZE, (U8*)&R.p, NULL) == 0)
|
|
{
|
|
L0_uart0_sendstr("e2p read success");
|
|
return;
|
|
}
|
|
L0_uart0_sendstr("e2p read failed");
|
|
#endif
|
|
}
|
|
|
|
void L3_reg_reset(void)
|
|
{
|
|
U8 i = 0;
|
|
|
|
R.app_status = POW_OFF;
|
|
|
|
R.pen_sta = 0;
|
|
|
|
R.pen_net_sta = 0;
|
|
|
|
R.pen_ele_sta = 0;
|
|
R.question_sta = 0;
|
|
R.spee_order = 0;
|
|
|
|
R.oid.type = 0;
|
|
R.oid.dat = 0;
|
|
|
|
R.game.type = 0;
|
|
R.game.dat = 0;
|
|
|
|
|
|
|
|
for(i=0;i<CCMD_SLAVER_INFO_MAX;i++)
|
|
{
|
|
G.ccmd_slaver_info[i].mask = 0;
|
|
}
|
|
|
|
//认证包
|
|
G.ccmd_slaver_info[0].slaver = SLAVER_TCP_SERVER_ID;
|
|
G.ccmd_slaver_info[0].oper = MODBUS_OPER_AUTH;
|
|
G.ccmd_slaver_info[0].mask = 0;
|
|
#if 0
|
|
//心跳包
|
|
G.ccmd_slaver_info[1].slaver = SLAVER_TCP_SERVER_ID;
|
|
G.ccmd_slaver_info[1].oper = MODBUS_OPER_PING;
|
|
G.ccmd_slaver_info[1].mask = 0;
|
|
#endif
|
|
//数据包
|
|
G.ccmd_slaver_info[1].slaver = SLAVER_TCP_SERVER_ID;
|
|
G.ccmd_slaver_info[1].oper = MODBUS_OPER_WRITE_M;
|
|
G.ccmd_slaver_info[1].reg = 0x20;
|
|
G.ccmd_slaver_info[1].regnum = 0x00;//基础数量,程序每次应动态添加点数
|
|
G.ccmd_slaver_info[1].bytes = 0;
|
|
G.ccmd_slaver_info[1].buf = 0;
|
|
G.ccmd_slaver_info[1].mask = 0;
|
|
G.ccmd_slaver_info[1].extra_num = 0;
|
|
//普通码
|
|
G.modbusstmp = 0;
|
|
G.authed = 0;
|
|
G.flowStartVal = 1;
|
|
G.pen_up = 0;
|
|
G.datapkg = 0;
|
|
G.pen_t = 1;
|
|
G.debug = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void L3_reg_init(void)
|
|
{
|
|
//R.reserved1 = R.reserved2 = R.reserved3 = 0x55;
|
|
//R.zero = 0;
|
|
//R.status_eep_save = 0;
|
|
L3_reg_reset();
|
|
L3_iap_2_reg();
|
|
}
|
|
#if 0
|
|
void Lc_buf_full(WR_Buf *p)
|
|
{
|
|
if((p->rIndex+1)%(p->maxsize) == p->wIndex)
|
|
{
|
|
p->full = 1;
|
|
}
|
|
}
|
|
U16 Lc_write_cyc_buf(PenPoint *wbuf ,WR_Buf *wp ,U16 wlen)
|
|
{
|
|
U8 nulllen = (wp->maxsize - wp->wIndex + wp->rIndex - 1) % wp->maxsize;
|
|
if(nulllen >= wlen)
|
|
{
|
|
wp->readdr = (wp->wIndex + wlen) % wp->maxsize;
|
|
if(wp->readdr > wp->wIndex || wp->readdr == 0)
|
|
{
|
|
Lc_buf_copy_uc((U8 *)&wp->buf[wp->wIndex], (U8 *)wbuf, wlen*sizeof(PenPoint));
|
|
}
|
|
else
|
|
{
|
|
wp->relen = wlen - wp->readdr;
|
|
Lc_buf_copy_uc((U8 *)&wp->buf[wp->wIndex], (U8 *)wbuf, wp->relen*sizeof(PenPoint));
|
|
Lc_buf_copy_uc((U8 *)&wp->buf[0], (U8 *)(wbuf+wp->relen), wp->readdr*sizeof(PenPoint));
|
|
}
|
|
wp->wIndex = wp->readdr;
|
|
return wlen;
|
|
}
|
|
else
|
|
{
|
|
//L0_uart0_sendstr("X");
|
|
wp->full = 1;
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
U16 Lc_read_cyc_buf(PenPoint *rbuf ,WR_Buf *rp ,U16 rlen)
|
|
{
|
|
U8 validlen = (rp->maxsize - rp->rIndex + rp->wIndex) % rp->maxsize;
|
|
if(validlen >= rlen)
|
|
{
|
|
rp->readdr = (rp->rIndex + rlen) % rp->maxsize;
|
|
if(rp->readdr < rp->wIndex || rp->readdr == 0)
|
|
{
|
|
Lc_buf_copy_uc((U8 *)rbuf, (U8 *)&rp->buf[rp->rIndex],rlen*sizeof(PenPoint));
|
|
}
|
|
else
|
|
{
|
|
rp->relen = rlen - rp->readdr;
|
|
Lc_buf_copy_uc((U8 *)rbuf,(U8 *) &rp->buf[rp->rIndex], rp->relen*sizeof(PenPoint));
|
|
Lc_buf_copy_uc((U8 *)(rbuf+rp->relen), (U8 *)&rp->buf[0], rp->readdr*sizeof(PenPoint));
|
|
}
|
|
rp->rIndex = rp->readdr;
|
|
return rlen;
|
|
}
|
|
else
|
|
{
|
|
rp->null = 1;
|
|
return 0;
|
|
}
|
|
}
|
|
#endif
|
|
|