feat: 实验性上行数据接收
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
#include "lwrb.h"
|
||||
#include "crc16.h"
|
||||
|
||||
uint8_t frame_buffer_recv[(2 * (4 + BY_FRAME_DATA_NUM * sizeof(uint32_t))) + 1];
|
||||
uint8_t frame_buffer_send[4 + BY_FRAME_DATA_NUM * sizeof(uint32_t)];
|
||||
uint8_t frame_buffer_recv[(2 * (4 + BY_FRAME_DATA_NUM_RECV * sizeof(uint32_t))) + 1];
|
||||
uint8_t frame_buffer_send[4 + BY_FRAME_DATA_NUM_SEND * sizeof(uint32_t)];
|
||||
uint8_t frame_parse_busy;
|
||||
lwrb_t lwrb_ctx;
|
||||
|
||||
@@ -19,10 +19,10 @@ void by_frame_init(void)
|
||||
uart_rx_interrupt(BY_FRAME_UART_INDEX, ENABLE);
|
||||
}
|
||||
|
||||
void by_frame_send(uint32_t *data_array)
|
||||
void by_frame_send(uint32_t* data_array)
|
||||
{
|
||||
uint16_t crc_cal = 0;
|
||||
const uint8_t data_byte_num = BY_FRAME_DATA_NUM * sizeof(uint32_t);
|
||||
const uint8_t data_byte_num = BY_FRAME_DATA_NUM_SEND * sizeof(uint32_t);
|
||||
|
||||
frame_buffer_send[0] = BY_FRAME_HEAD_1;
|
||||
frame_buffer_send[1] = BY_FRAME_HEAD_2;
|
||||
@@ -49,9 +49,9 @@ void by_frame_parse(uint32_t *data_array)
|
||||
uint32_t len = lwrb_get_full(&lwrb_ctx); // 缓冲区大小
|
||||
uint8_t status = 0; // 状态 0-未找到帧头 1-找到帧头 2-校验
|
||||
uint16_t frame_start = 0; // 帧起始位置
|
||||
uint8_t frame_buf[4 + BY_FRAME_DATA_NUM * sizeof(uint32_t)] = {0}; // 帧
|
||||
uint8_t buf[(4 + BY_FRAME_DATA_NUM * sizeof(uint32_t)) * 2] = {0}; // 用于解析的数据块
|
||||
const uint8_t data_byte_num = BY_FRAME_DATA_NUM * sizeof(uint32_t);
|
||||
uint8_t frame_buf[4 + BY_FRAME_DATA_NUM_RECV * sizeof(uint32_t)] = {0}; // 帧
|
||||
uint8_t buf[(4 + BY_FRAME_DATA_NUM_RECV * sizeof(uint32_t)) * 2] = {0}; // 用于解析的数据块
|
||||
const uint8_t data_byte_num = BY_FRAME_DATA_NUM_RECV * sizeof(uint32_t);
|
||||
|
||||
if (len < 2 * (4 + data_byte_num)) {
|
||||
// 当前要求缓冲区满
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
#define BY_FRAME_UART_INDEX (UART_2)
|
||||
#define BY_FRAME_UART_BAUDRATE (115200)
|
||||
|
||||
#define BY_FRAME_DATA_NUM (3)
|
||||
#define BY_FRAME_DATA_NUM_SEND (3)
|
||||
#define BY_FRAME_DATA_NUM_RECV (1)
|
||||
|
||||
extern void by_frame_init(void);
|
||||
void by_frame_send(uint32_t *data_array);
|
||||
void by_frame_parse(uint32_t *data_array);
|
||||
extern void by_frame_parse_uart_handle(uint8_t data);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -112,7 +112,13 @@ void aim_distance_select(void)
|
||||
|
||||
void ElementJudge()
|
||||
{
|
||||
Check_shield();
|
||||
|
||||
if(begin_flag == 1){
|
||||
shield_type = SHIELD_BEGIN;
|
||||
begin_flag = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (shield_type == SHIELD_NONE) {
|
||||
CheckGarage();
|
||||
if (garage_type == GARAGE_NONE) {
|
||||
@@ -162,7 +168,11 @@ void ElementRun()
|
||||
|
||||
void MidLineTrack()
|
||||
{
|
||||
if (cross_type == CROSS_IN) {
|
||||
if (shield_type == SHIELD_BEGIN) {
|
||||
shield_type = SHIELD_NONE;
|
||||
system_delay_ms(1000); // 斑马线发车延时
|
||||
}
|
||||
else if (cross_type == CROSS_IN) {
|
||||
if (track_type == TRACK_LEFT) {
|
||||
mid_track = mid_left; // 这是为了预先分配内存
|
||||
GetMidLine_Left(pts_far_resample_left + far_Lpt0_rpts0s_id, pts_far_resample_left_count - far_Lpt0_rpts0s_id, mid_left, (int)round(ANGLEDIST / RESAMPLEDIST), PIXPERMETER * ROADWIDTH / 2);
|
||||
|
||||
@@ -92,15 +92,11 @@ void USART1_IRQHandler(void)
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {
|
||||
// uint8_t data = (uint8_t)USART_ReceiveData(USART2);
|
||||
// by_frame_parse_uart_handle(data);
|
||||
USART_ReceiveData(USART2);
|
||||
NVIC_SystemReset();
|
||||
by_frame_parse_uart_handle((uint8_t)USART_ReceiveData(USART2));
|
||||
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
|
||||
}
|
||||
|
||||
if (USART_GetFlagStatus(USART2, USART_FLAG_ORE) != RESET) {
|
||||
|
||||
USART_ClearFlag(USART2, USART_FLAG_ORE); // <20><><EFBFBD><EFBFBD> ORE <20><>־λ
|
||||
USART_ReceiveData(USART2);
|
||||
}
|
||||
|
||||
10
app/main.c
10
app/main.c
@@ -32,7 +32,7 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
TYPE_UNION recv_data[BY_FRAME_DATA_NUM_RECV];
|
||||
clock_init(SYSTEM_CLOCK_144M);
|
||||
system_delay_init();
|
||||
debug_init();
|
||||
@@ -54,6 +54,14 @@ int main(void)
|
||||
|
||||
printf("start running\r\n");
|
||||
while (1) {
|
||||
memset(recv_data, 0, sizeof(recv_data));
|
||||
by_frame_parse(&recv_data[0].u32);
|
||||
if(0xEB == recv_data[0].u32) {
|
||||
NVIC_SystemReset();
|
||||
}else if (0x5C == recv_data[0].u32) {
|
||||
begin_flag = 1;
|
||||
}
|
||||
|
||||
Page_Run();
|
||||
by_buzzer_run();
|
||||
tiny_frame_param[0].f32 = pure_angle;
|
||||
|
||||
Reference in New Issue
Block a user