From 6a6be1469b2e56d790acc50c2d30e277b86a67a0 Mon Sep 17 00:00:00 2001 From: bmy <2583236812@qq.com> Date: Mon, 11 Mar 2024 19:32:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20vofa=20justfloat?= =?UTF-8?q?=20=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/by_frame.c | 12 ++++++++++-- app/by_vofa.c | 15 +++++++++++++++ app/by_vofa.h | 18 ++++++++++++++++++ app/jj_motion.c | 2 +- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 app/by_vofa.c create mode 100644 app/by_vofa.h diff --git a/app/by_frame.c b/app/by_frame.c index 4df88b4..a8df95b 100644 --- a/app/by_frame.c +++ b/app/by_frame.c @@ -49,7 +49,7 @@ void by_frame_parse(uint8_t data_num, uint32_t *data_array) uint16_t crc_cal = 0; uint32_t read_length = 50; - if (fifo_used(&frame_fifo)) { + if (fifo_used(&frame_fifo) >= 12) { fifo_read_buffer(&frame_fifo, frame_buffer_parse, &read_length, FIFO_READ_AND_CLEAN); while (1) { if (cnt_ptr < 50) { @@ -88,9 +88,17 @@ void by_frame_parse(uint8_t data_num, uint32_t *data_array) if (!cnt_crc) { if (crc_cal == crc16_check(data_array_temp, 2 + data_num * sizeof(uint32_t))) { memcpy(data_array, data_array_temp + 2, data_num * sizeof(uint32_t)); - // lwrb_reset(&lwrb_struct); // 处理完直接清空缓冲区,避免堆积产生处理阻塞 memset(data_array_temp, 0, sizeof(data_array_temp)); // printf("parsed done!\r\n"); + for (uint8_t i = 0; i < data_num; i++) { + for (uint8_t j = 0; j < 4; j++) { + uart_write_byte(DEBUG_UART_INDEX, data_array[i] >> (j * 8)); + } + } + uart_write_byte(DEBUG_UART_INDEX, 0x00); + uart_write_byte(DEBUG_UART_INDEX, 0x00); + uart_write_byte(DEBUG_UART_INDEX, 0x80); + uart_write_byte(DEBUG_UART_INDEX, 0x7F); } break; diff --git a/app/by_vofa.c b/app/by_vofa.c new file mode 100644 index 0000000..5978be0 --- /dev/null +++ b/app/by_vofa.c @@ -0,0 +1,15 @@ +#include "by_vofa.h" + +void by_vofa_init(by_vofa_t *vofa, uart_index_enum uart_index, uint8_t param_num, float *param_ptr) +{ + vofa->uart_index = uart_index; + vofa->param_num = param_num; + vofa->param_ptr = param_ptr; +} + +void by_vofa_send(by_vofa_t *vofa) +{ + const uint8_t tail[4] = {0x00, 0x00, 0x80, 0x7F}; + uart_write_buffer(vofa->uart_index, (uint8_t *)vofa->param_ptr, vofa->param_num * 4); + uart_write_buffer(vofa->uart_index, tail, 4); +} \ No newline at end of file diff --git a/app/by_vofa.h b/app/by_vofa.h new file mode 100644 index 0000000..da0fc94 --- /dev/null +++ b/app/by_vofa.h @@ -0,0 +1,18 @@ +#ifndef _BY_VOFA_H__ +#define _BY_VOFA_H__ + +#include +#include + +#include "zf_common_headfile.h" + +typedef struct by_vofa_t { + uart_index_enum uart_index; + uint8_t param_num; + float *param_ptr; +} by_vofa_t; + +void by_vofa_init(by_vofa_t *vofa, uart_index_enum uart_index, uint8_t param_num, float *param_ptr); +void by_vofa_send(by_vofa_t *vofa); + +#endif diff --git a/app/jj_motion.c b/app/jj_motion.c index 9127b20..e450b0c 100644 --- a/app/jj_motion.c +++ b/app/jj_motion.c @@ -72,7 +72,7 @@ void sport_motion(void) PID_Compute(&speed_pid); // in_speed = -encoder_get_count(TIM5_ENCOEDER); // 速度输入,m/s in_speed = sport_get_speed(); - printf("rate:%d\r\n", (int16_t)in_speed); + // printf("rate:%d\r\n", (int16_t)in_speed); PID_Compute(&near_pos_pid); cnt1 = 0; }