# serial_port **Repository Path**: wust_zc/serial_port ## Basic Information - **Project Name**: serial_port - **Description**: 一个简单的serial驱动程序 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-09-26 - **Last Updated**: 2024-08-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # serial 使用串口读取数据,解析数据。 串口数据是基于字节流的,当数据发送较快的时候,会导致数据包处理不了。 ## 使用自定义协议区分帧头帧尾。 struct DataFrame { uint8_t header0; //0xA5 uint8_t header1; //0x5A uint8_t id; //src uint8_t dst; uint16_t cmd; uint16_t len; uint8_t* data; uint8_t xor; uint8_t tail; //0xFE } ## 处理方法 1、接收串口数据。 2、直接在接收线程处理数据。 3、解的完整包进入数据处理回调,如果数据不完整,则保留为全局变量。不需要使用缓存。 大致思路,将串口数据存入buff,记录偏移datelen。解析的时候判断帧头帧尾,数据长度以及crc。记录offset,然后再移动位置。