yelvlab f130674630 Revert "测试提交"
This reverts commit 6c9543648f5c719cc00f1a56cb2e5e6426dcd664.
2024-12-26 01:02:07 +08:00

60 lines
1.7 KiB
C

//
// Created by dell on 24-12-3.
//
#ifndef RS485_H
#define RS485_H
#include "gd32e23x_it.h"
#include "gd32e23x.h"
#include "systick.h"
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
/******************************************************************************/
#define RS485_RCU RCU_USART0
#define RS485_GPIO_RCU RCU_GPIOA
#define RS485_GPIO_PORT GPIOA
#define RS485_TX_PIN GPIO_PIN_2
#define RS485_RX_PIN GPIO_PIN_3
#define RS485_PHY USART0
#define RS485_BAUDRATE 115200U
#define RS485_EN_PIN GPIO_PIN_1
/******************************************************************************/
#define RX_BUFFER_SIZE 32
#define LDC1612_PACKAGE_HEADER 0xD5
#define LDC1612_BOARD_TYPE 0x03
#define LDC1612_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 rs485_config(void);
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);
void eddy_current_value_report(void);
void tempture_value_report(void);
#endif //RS485_H