XLSW_3DP_US-IR/inc/rs485_protocol.h

77 lines
1.6 KiB
C

//
// 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 <stdlib.h>
#include <string.h>
#include "ultrasonic_analog.h"
/******************************************************************************/
#define PROTOCOL_PACKAGE_HEADER 0xD5
#define PROTOCOL_BOARD_TYPE 0x04
#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;
typedef enum
{
PS_LEN = 0,
PS_TYPE,
PS_PAYLOAD,
PS_CRC,
PS_NULL
} packet_state_t;
/******************************************************************************/
#define BUF_SIZE 8
#define MAX_CMD_SIZE 16
#define PACKET_START_BYTE 0xD5
bool code_seen(char code);
// void process_command(uint8_t* cmd, size_t length);
void process_command(void);
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 gd60914_tempture_report(void);
void ultrasonic_distance_report(void);
void process_printer(void);
void get_command (void);
#endif //RS485_PROTOCOL_H