This commit is contained in:
2025-01-20 10:28:43 +08:00
parent 7ffb8c0612
commit a5c1c857a9
6 changed files with 170 additions and 61 deletions

View File

@@ -13,17 +13,19 @@
#include "fwdgt.h"
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ultrasonic_analog.h"
/******************************************************************************/
#define RX_BUFFER_SIZE 32
#define PROTOCOL_PACKAGE_HEADER 0xD5
#define PROTOCOL_BOARD_TYPE 0x04
#define PROTOCOL_PACKAGE_LENGTH 0x02
#define MAX_SERIAL_CMD_SIZE 16
#define MAX_SERIAL_CMD_COUNT 8
/******************************************************************************/
typedef enum
@@ -35,9 +37,21 @@ typedef enum
VALIDATION_LENGTH_ERROR = 8
} validation_result_t;
typedef enum {
PS_LEN,
PS_TYPE,
PS_PAYLOAD,
PS_CRC,
PS_NULL
}packet_state_t;
/******************************************************************************/
void process_command(uint8_t* cmd, size_t length);
// void process_command(uint8_t* cmd, size_t length);
bool code_seen(char code);
float code_value(void);
uint8_t calculate_crc(uint8_t data[], uint8_t data_length);
@@ -53,4 +67,10 @@ void gd60914_tempture_report(void);
void ultrasonic_distance_report(void);
void start_communication(void);
void get_command(void);
void prcess_command(void);
#endif //RS485_PROTOCOL_H

View File

@@ -8,8 +8,25 @@
#include "gd32e23x.h"
#include "board_config.h"
#define RX_BUFFER_SIZE 64
typedef struct
{
unsigned char buffer[RX_BUFFER_SIZE];
volatile unsigned int head;
volatile unsigned int tail;
}ring_buffer_t;
static ring_buffer_t rx_buffer = {{0}, 0, 0}; // ring buffer for USART0
void usart_config(void);
void rs485_config(void);
void store_char(unsigned char data, ring_buffer_t *rx_buf);
uint16_t uart_available(void);
int uart_read(void);
#endif //USART_H