8000 数据包超长得情况下丢包有问题 · Issue #3 · aeo123/upacker · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

数据包超长得情况下丢包有问题 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Sunxiaowei123370 opened this issue Mar 13, 2021 · 16 comments
Open

数据包超长得情况下丢包有问题 #3

Sunxiaowei123370 opened this issue Mar 13, 2021 · 16 comments

Comments

@Sunxiaowei123370
Copy link

else if (packer->state == 2)
{
//长度信息
packer->flen |= (uint16_t)d << 8;
packer->calc ^= d & 0x3F;

   //数据包超长得情况下直接丢包
    if ((packer->flen & 0x3FFF) > MAX_PACK_SIZE)
    {
        packer->state = 0;
    }
    packer->state = 3;
    packer->cnt = 0;
}

问题:
当数据包超长时并不会直接丢包因为底下又重新给 state 赋值导致state = 0被覆盖。
解决方法:
在 packer->state = 0; 的下一行直接return 0;您看这样改是否妥当。

@aeo123
Copy link
Owner
aeo123 commented Mar 13, 2021 via email

@hcb900330
Copy link

最后怎么解决的啊?我也发现特别长以后丢包

@hcb900330
Copy link

数据报不到4 k 就经常有 传输不到的数据包

@aeo123
Copy link
Owner
aeo123 commented Aug 5, 2021 via email

@hcb900330
Copy link

短包发送每个都可以,长包一旦出问题 ,后面短包也会出问题 ,我用的市QT 与RT thread系统的设备通讯

@hcb900330
Copy link

小于1k的数据没啥问题 大了以后汇有概率的接收不到 我用的cjson字符串传输

@Sunxiaowei123370
Copy link
Author
Sunxiaowei123370 commented Aug 6, 2021 via email

@aeo123
Copy link
Owner
aeo123 commented Aug 6, 2021 via email

@Sunxiaowei123370
Copy link
Author
Sunxiaowei123370 commented Aug 6, 2021 via email

@hcb900330
Copy link

默认的最大的配置我改了16384

< 8000 div class="d-flex">

@hcb900330
Copy link

static int uart_dma_sample(int argc, char *argv[])
{
rt_err_t ret = RT_EOK;
char uart_name[RT_NAME_MAX];
//static char msg_pool[256];
char str[] = "hello RT-Thread!\r\n";

if (argc == 2)
{
    rt_strncpy(uart_name, argv[1], RT_NAME_MAX);
}
else
{
    rt_strncpy(uart_name, SAMPLE_UART_NAME, RT_NAME_MAX);
}
	
	

/* 查找串口设备 */
serial = rt_device_find(uart_name);
	
	
if (!serial)
{
    rt_kprintf("find %s failed!\n", uart_name);
    return RT_ERROR;
}


	
	
	rx_mq=rt_mq_create("rx_mq",sizeof(struct rx_msg),1025,RT_IPC_FLAG_FIFO);


/* 以 DMA 接收及轮询发送方式打开串口设备 */
rt_device_open(serial, RT_DEVICE_FLAG_DMA_RX);
/* 设置接收回调函数 */
rt_device_set_rx_indicate(serial, uart_input);
	//    /* 发送字符串 */
	//    rt_device_write(serial, 0, str, (sizeof(str) - 1));

/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, RT_NULL, 1024, 25, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
    rt_thread_startup(thread);
}
else
{
    ret = RT_ERROR;
}
	
	
	upacker_init(&msg_packer, handle_cb, uart_send);
	

return ret;

}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(uart_dma_sample, uart device dma sample);

@hcb900330
Copy link

/* 接收数据回调函数 */
static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
{
struct rx_msg msg;
rt_err_t result;
msg.dev = dev;
msg.size = size;

result = rt_mq_send(rx_mq, &msg, sizeof(msg));
if ( result == -RT_EFULL)
{
    /* 消息队列满 */
    rt_kprintf("message queue full!\n");
}
return result;

}

static void serial_thread_entry(void *parameter)
{
struct rx_msg msg;
rt_err_t result;
rt_uint32_t rx_length;
static char rx_buffer[RT_SERIAL_RB_BUFSZ + 1];

while (1)
{
    rt_memset(&msg, 0, sizeof(msg));
    /* 从消息队列中读取消息*/
    result = rt_mq_recv(rx_mq, &msg, sizeof(msg),100);
    if (result == RT_EOK)
    {
        /* 从串口读取数据*/
        rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
        //丢到packer解析,成功了调用callback
        upacker_unpack(&msg_packer, (uint8_t *)rx_buffer, msg.size);
        /* 打印数据 */
       //rt_kprintf("%s\n",rx_buffer);
    }
}

}

@hcb900330
Copy link

static void handle_cb(uint8_t *d, uint16_t size)
{
//接收到payload
//rt_kprintf("pack len%d", size);
char *p=rt_malloc(size);
rt_kprintf("size:%d\r\n",size);
rt_memcpy(p,d,size);
rt_kprintf("%s\r\n",p);
rt_free(p);

}

@hcb900330
Copy link

//使用动态内存
#define USE_DYNAMIC_MEM 1

#if USE_DYNAMIC_MEM
#define UP_MALLOC rt_malloc
#define UP_FREE rt_free
#endif

#define MAX_PACK_SIZE 16384 //最长消息长度,最大可用14位即16384
#define STX_L 0X55 //数据包头

@hcb900330
Copy link

最后把这个改大了 RT_SERIAL_RB_BUFSZ 1024*17 好像就好多了

@aeo123
Copy link
Owner
aeo123 commented Aug 9, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0