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.

173 lines
4.3 KiB

1 year ago
/*****************************************************************************
update by cc @201501101001
.
uartcom/uartlib.c:
(线),
(lcd等固屏输出的)使
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...)
-----------------------------------------------------------------------------------------
uartcom/uartcom0
uart相关的通讯协议 com + n
uart口来对应
typedef struct _ts_lcm_pro_; ? LCM的协议------------
L3_UARTcom0_exp_protocol
-----------------------------------------------------------------------------------------
uartcom/uprotocol: uartcom + n服务的
struct _s_protocol_ ()------struct _s_protocol_
void L1_uart_2buf(struct _s_protocol_ *p)
--------------------------------------------------------------------------------------------
msp/uartx.c cpu相关
L0_UART0_Init
UART0_IRQHandler
L0_Usend_uc----------s_at0
-----------------------------------------------------------------------------------------
********************************************************************************/
#include "tpc_debug.h"
///#include "c_lib.h"
TS_pp_debug_ ts_debug_rec;
TS_s2b_debug_ ts_s2b_debug;////协议处理变量
/*
void L1_s2b_debug_init(void) //reentrant
{
ts_s2b_debug.ok = 0;
ts_s2b_debug.debugok = 0;
ts_s2b_debug.head = 0;
ts_s2b_debug.num = 0;
ts_s2b_debug.f = 0xf0;
ts_s2b_debug.sp = (U8 *)&ts_debug_rec;
}
*/
//NUM: 0 1 2 3 4
// Fx R1 R2 R3 ocr
// F+从机 R1 R2 R3 校验
//相关功能移动到tpc_fx.c
/// 实践中发现 如果收到多个以0d0a结束的短协议时,如果
/// 协议之间间隔时间太短,ok处理不及时 会出现丢失协议的
/// 的情况,所以 对于短暂的多个协议 应该有一定容量的缓冲
/// 保留 ,同时 处理完协议后,应该清除接收缓冲,否则缓冲
/// 会在自身满了后自动清除
//_s_HRTU_P_rf_
/// _s_HRTU_Pfx_
/// fx 11 22 33 oc -- oc = 11+ 22+33
//buf 0 1 2 3 [4]
//fd 01 02 03 06 fd为头 010203为数据 06为数据校验和(01+02+03)
//对于连续的多条协议,如果前一条处理不及时,可能会被后一条覆盖
#if 0
void L1_s2b_PH1 (TP_Handler_X *p)
{
if (0 == p->head)
{
if (D_HETU_FX_fi == (p->reg & p->head_0))
{
p->head = 1;
p->num = 1;
p->buf[0] = p->reg;
//p->ok = 1;
}
}
else
{
p->buf[p->num++] = p->reg;
if(p->num >= D_HETU_FX_buf_max) // [D_HETU_FX_buf_max == 5]
{
p->ocr = p->buf[1];
p->ocr += p->buf[2];
p->ocr += p->buf[3];
if(p->ocr == p->buf[D_HETU_FX_buf_max-1])
{
if (p->ok != 1)
{
p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文
}
}
p->head = 0; //放在if (p->ok != 1) 外
}
}
}
#else
#endif
/*
//MODBUS协议解析函数 012345
//超出D_tp_handle_x_len,不继续保存数据
void L1_s2b_PH5_debug222(TS_s2b_debug_ *p)
{
/// p->ok = 1;
if(p->head == 0)
{
if(p->reg&0xf0 == p->f)
{
p->head = 1;
p->max = 5;
p->num = 0;
p->sp[p->num++] = p->reg;
}
}
else
{
p->sp[p->num++] = p->reg;
if(p->num < p->max)
{
}else
{////
p->ok = 1;
p->debugok = 1;
p->head = 0;
p->num = 0;
}
}
}
void L1_s2b_PH5_debug(TS_s2b_debug_ *p)
{
/// p->ok = 1;
if(p->head == 0)
{
p->f2 = p->reg&0xf0;
if(p->f2 == p->f)
{
p->head = 1;
p->max = 5;
p->num = 0;
p->sp[p->num++] = p->reg;
}
}
else
{
p->sp[p->num++] = p->reg;
if(p->num < p->max)
{
}else
{////
p->ok = 1;
p->debugok = 1;
p->head = 0;
p->num = 0;
}
}
}
*/
/******************************************************************************
** End Of File
******************************************************************************/