generated from hulk/gd32e23x_template
Revert "update"
This reverts commit cc4d89811481595e64b21d5c06526eb281f75803.
This commit is contained in:
parent
9f615ba3a3
commit
ac74c30923
@ -35,20 +35,9 @@ typedef enum
|
||||
VALIDATION_LENGTH_ERROR = 8
|
||||
} validation_result_t;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PS_LEN = 0,
|
||||
PS_TYPE,
|
||||
PS_PAYLOAD,
|
||||
PS_CRC,
|
||||
PS_NULL
|
||||
} packet_state;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// void process_command(uint8_t* cmd, size_t length);
|
||||
void process_command(void);
|
||||
void process_command(uint8_t* cmd, size_t length);
|
||||
|
||||
uint8_t calculate_crc(uint8_t data[], uint8_t data_length);
|
||||
|
||||
@ -64,8 +53,4 @@ void gd60914_tempture_report(void);
|
||||
|
||||
void ultrasonic_distance_report(void);
|
||||
|
||||
void process_printer(void);
|
||||
|
||||
void get_command (void);
|
||||
|
||||
#endif //RS485_PROTOCOL_H
|
||||
|
@ -1,8 +1,8 @@
|
||||
/* memory map */
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K
|
||||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 16K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 4K
|
||||
}
|
||||
|
||||
ENTRY(Reset_Handler)
|
||||
|
@ -174,7 +174,7 @@ void USART0_IRQHandler(void) {
|
||||
if (RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_IDLE)) {
|
||||
usart_interrupt_flag_clear(USART0, USART_INT_FLAG_IDLE);
|
||||
|
||||
// process_command(rx_buffer, rx_index); // 处理指令
|
||||
process_command(rx_buffer, rx_index); // 处理指令
|
||||
|
||||
rx_index = 0; // 重置缓冲区索引
|
||||
return;
|
||||
|
@ -6,53 +6,48 @@
|
||||
|
||||
extern uint8_t g_temperature_uint8[2];
|
||||
|
||||
static uint8_t buffer_length = 0;
|
||||
static int serial_count = 0;
|
||||
static uint8_t serial_char = 0x00;
|
||||
static packet_state state = PS_NULL;
|
||||
void process_command(uint8_t *cmd, size_t length) {
|
||||
char combined_str[3];
|
||||
validation_result_t validate = VALIDATION_SUCCESS;
|
||||
|
||||
// void process_command(uint8_t *cmd, size_t length) {
|
||||
// char combined_str[3];
|
||||
// validation_result_t validate = VALIDATION_SUCCESS;
|
||||
//
|
||||
// validate = (validate_package_header(cmd) |
|
||||
// validate_package_type(cmd) |
|
||||
// validate_data_length(cmd) |
|
||||
// validate_package_crc(cmd, length));
|
||||
//
|
||||
// switch (validate) {
|
||||
// case VALIDATION_SUCCESS:
|
||||
// // printf("%d", length);
|
||||
// sprintf(combined_str, "%c%c", cmd[3], cmd[4]);
|
||||
// if (strcmp(combined_str, "M1") == 0) {
|
||||
// ultrasonic_distance_report();
|
||||
// } else if (strcmp(combined_str, "M2") == 0) {
|
||||
// gd60914_tempture_report();
|
||||
// } else if (strcmp(combined_str, "M3") == 0)
|
||||
// {
|
||||
// printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
||||
// fwdgt_reset_mcu();
|
||||
// } else {
|
||||
// printf("%c%c%c%c%c%c%c", 0xB5, 0xF0, 0x03, 0x65, 0x72, 0x72, 0x3C);
|
||||
// return;
|
||||
// }
|
||||
// break;
|
||||
// case VALIDATION_CRC_ERROR:
|
||||
// printf("%c%c%c%c%c%c%c", 0xB5, 0xF1, 0x03, 0x65, 0x72, 0x72, 0x3D);
|
||||
// break;
|
||||
// case VALIDATION_HEADER_ERROR:
|
||||
// printf("%c%c%c%c%c%c%c", 0xB5, 0xF2, 0x03, 0x65, 0x72, 0x72, 0x3E);
|
||||
// break;
|
||||
// case VALIDATION_TYPE_ERROR:
|
||||
// printf("%c%c%c%c%c%c%c", 0xB5, 0xF3, 0x03, 0x65, 0x72, 0x72, 0x3F);
|
||||
// break;
|
||||
// case VALIDATION_LENGTH_ERROR:
|
||||
// printf("%c%c%c%c%c%c%c", 0xB5, 0xF4, 0x03, 0x65, 0x72, 0x72, 0x40);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
validate = (validate_package_header(cmd) |
|
||||
validate_package_type(cmd) |
|
||||
validate_data_length(cmd) |
|
||||
validate_package_crc(cmd, length));
|
||||
|
||||
switch (validate) {
|
||||
case VALIDATION_SUCCESS:
|
||||
// printf("%d", length);
|
||||
sprintf(combined_str, "%c%c", cmd[3], cmd[4]);
|
||||
if (strcmp(combined_str, "M1") == 0) {
|
||||
ultrasonic_distance_report();
|
||||
} else if (strcmp(combined_str, "M2") == 0) {
|
||||
gd60914_tempture_report();
|
||||
} else if (strcmp(combined_str, "M3") == 0)
|
||||
{
|
||||
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
||||
fwdgt_reset_mcu();
|
||||
} else {
|
||||
printf("%c%c%c%c%c%c%c", 0xB5, 0xF0, 0x03, 0x65, 0x72, 0x72, 0x3C);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case VALIDATION_CRC_ERROR:
|
||||
printf("%c%c%c%c%c%c%c", 0xB5, 0xF1, 0x03, 0x65, 0x72, 0x72, 0x3D);
|
||||
break;
|
||||
case VALIDATION_HEADER_ERROR:
|
||||
printf("%c%c%c%c%c%c%c", 0xB5, 0xF2, 0x03, 0x65, 0x72, 0x72, 0x3E);
|
||||
break;
|
||||
case VALIDATION_TYPE_ERROR:
|
||||
printf("%c%c%c%c%c%c%c", 0xB5, 0xF3, 0x03, 0x65, 0x72, 0x72, 0x3F);
|
||||
break;
|
||||
case VALIDATION_LENGTH_ERROR:
|
||||
printf("%c%c%c%c%c%c%c", 0xB5, 0xF4, 0x03, 0x65, 0x72, 0x72, 0x40);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t calculate_crc(uint8_t data[], uint8_t data_length) {
|
||||
uint8_t crc = 0;
|
||||
@ -126,27 +121,3 @@ void ultrasonic_distance_report(void) {
|
||||
printf("%c%c", package_data[0], package_data[1]);
|
||||
printf("%c", calculate_crc(combined_data, 6));
|
||||
}
|
||||
|
||||
|
||||
void process_printer(void) {
|
||||
if(buffer_length < (RX_BUFFER_SIZE - 1)) {
|
||||
get_command();
|
||||
}
|
||||
if(buffer_length) {
|
||||
process_command();
|
||||
}
|
||||
}
|
||||
|
||||
void get_command (void) {
|
||||
static uint8_t testchar=0;
|
||||
static uint8_t check_sum = 0;
|
||||
static uint8_t packet_len ;
|
||||
static uint8_t packet_type;
|
||||
state = PS_NULL;
|
||||
serial_count = 0;
|
||||
serial_char=0;
|
||||
}
|
||||
|
||||
void process_command(void) {
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user