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.
172 lines
4.3 KiB
172 lines
4.3 KiB
|
|
/*****************************************************************************
|
|
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
|
|
******************************************************************************/
|
|
|
|
|