generated from hulk/gd32e23x_template
添加协议解析
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
#define USART_PHY USART0
|
||||
#define USART_PHY_BAUDRATE 115200U
|
||||
#define RS485_EN_PORT GPIOA
|
||||
#define RS485_EN_PIN GPIO_PIN_1
|
||||
#define RS485_EN_PIN GPIO_PIN_4
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
@@ -39,6 +39,9 @@ OF SUCH DAMAGE.
|
||||
#include "main.h"
|
||||
#include "systick.h"
|
||||
#include "board_config.h"
|
||||
#include "usart.h"
|
||||
#include "fwdgt.h"
|
||||
#include "rs485_protocol.h"
|
||||
|
||||
/* function declarations */
|
||||
/* this function handles NMI exception */
|
||||
|
51
inc/rs485_protocol.h
Normal file
51
inc/rs485_protocol.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Created by yelv1 on 24-12-31.
|
||||
//
|
||||
|
||||
#ifndef RS485_PROTOCOL_H
|
||||
#define RS485_PROTOCOL_H
|
||||
|
||||
#include "gd32e23x.h"
|
||||
#include "systick.h"
|
||||
#include "gd32e23x_libopt.h"
|
||||
#include "board_config.h"
|
||||
#include "usart.h"
|
||||
#include "fwdgt.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define RX_BUFFER_SIZE 32
|
||||
|
||||
#define PROTOCOL_PACKAGE_HEADER 0xD5
|
||||
#define PROTOCOL_BOARD_TYPE 0x03
|
||||
#define PROTOCOL_PACKAGE_LENGTH 0x02
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
VALIDATION_SUCCESS = 0,
|
||||
VALIDATION_CRC_ERROR = 1,
|
||||
VALIDATION_HEADER_ERROR = 2,
|
||||
VALIDATION_TYPE_ERROR = 4,
|
||||
VALIDATION_LENGTH_ERROR = 8
|
||||
} validation_result_t;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void process_command(uint8_t* cmd, size_t length);
|
||||
|
||||
uint8_t calculate_crc(uint8_t data[], uint8_t data_length);
|
||||
|
||||
validation_result_t validate_package_crc(uint8_t* data, uint8_t data_length);
|
||||
|
||||
validation_result_t validate_package_header(uint8_t* data);
|
||||
|
||||
validation_result_t validate_package_type(uint8_t* data);
|
||||
|
||||
validation_result_t validate_data_length(uint8_t* data);
|
||||
|
||||
#endif //RS485_PROTOCOL_H
|
Reference in New Issue
Block a user