2022-11-03 20:38:55 +08:00
|
|
|
/**
|
|
|
|
* @file master_process.c
|
|
|
|
* @author neozng
|
|
|
|
* @brief module for recv&send vision data
|
|
|
|
* @version beta
|
|
|
|
* @date 2022-11-03
|
2022-11-05 21:59:03 +08:00
|
|
|
* @todo 增加对串口调试助手协议的支持,包括vofa和serial debug
|
2022-11-29 16:33:34 +08:00
|
|
|
* @copyright Copyright (c) 2022
|
2022-11-03 20:38:55 +08:00
|
|
|
*
|
|
|
|
*/
|
2022-11-29 16:33:34 +08:00
|
|
|
#include "master_process.h"
|
|
|
|
#include "bsp_usart.h"
|
|
|
|
#include "usart.h"
|
|
|
|
#include "seasky_protocol.h"
|
2022-11-03 20:38:55 +08:00
|
|
|
|
|
|
|
/* use usart1 as vision communication*/
|
2022-11-29 23:11:37 +08:00
|
|
|
static Vision_Recv_s recv_data;
|
2022-11-12 18:03:18 +08:00
|
|
|
// @todo:由于后续需要进行IMU-Cam的硬件触发采集控制,因此可能需要将发送设置为定时任务,或由IMU采集完成产生的中断唤醒的任务,
|
|
|
|
// 使得时间戳对齐. 因此,在send_data中设定其他的标志位数据,让ins_task填充姿态值.
|
|
|
|
// static Vision_Send_s send_data;
|
2022-12-05 21:01:26 +08:00
|
|
|
static USARTInstance *vision_usart_instance;
|
2022-11-03 20:38:55 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 接收解包回调函数,将在bsp_usart.c中被usart rx callback调用
|
2022-11-12 18:03:18 +08:00
|
|
|
* @todo 1.提高可读性,将get_protocol_info的第四个参数增加一个float类型buffer
|
2022-11-03 20:38:55 +08:00
|
|
|
* 2.添加标志位解码
|
|
|
|
*/
|
|
|
|
static void DecodeVision()
|
|
|
|
{
|
|
|
|
static uint16_t flag_register;
|
2022-12-05 21:01:26 +08:00
|
|
|
get_protocol_info(vision_usart_instance->recv_buff, &flag_register, (uint8_t *)&recv_data.pitch);
|
2022-11-03 20:38:55 +08:00
|
|
|
// TODO: code to resolve flag_register;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 视觉通信初始化 */
|
2022-11-29 16:33:34 +08:00
|
|
|
Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle)
|
2022-11-03 20:38:55 +08:00
|
|
|
{
|
2022-11-28 17:54:07 +08:00
|
|
|
USART_Init_Config_s conf;
|
|
|
|
conf.module_callback = DecodeVision;
|
|
|
|
conf.recv_buff_size = VISION_RECV_SIZE;
|
2022-11-29 16:33:34 +08:00
|
|
|
conf.usart_handle = _handle;
|
|
|
|
vision_usart_instance = USARTRegister(&conf);
|
2022-11-05 21:59:03 +08:00
|
|
|
return &recv_data;
|
2022-11-03 20:38:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 发送函数
|
2022-11-12 18:03:18 +08:00
|
|
|
* @todo 1.提高可读性,将get_protocol_send_data的第6个参数增加一个float buffer
|
2022-11-03 20:38:55 +08:00
|
|
|
* 2.添加标志位解码
|
2022-11-12 18:03:18 +08:00
|
|
|
* 3.由于后续需要进行IMU-Cam的硬件触发采集控制,因此可能需要将发送设置为定时任务
|
|
|
|
* 或由IMU采集完成产生的中断唤醒的任务,使得时间戳对齐.
|
2022-11-03 20:38:55 +08:00
|
|
|
*
|
|
|
|
* @param send 待发送数据
|
|
|
|
*/
|
|
|
|
void VisionSend(Vision_Send_s *send)
|
|
|
|
{
|
|
|
|
static uint16_t flag_register;
|
|
|
|
static uint8_t send_buff[VISION_SEND_SIZE];
|
|
|
|
static uint16_t tx_len;
|
|
|
|
// TODO: code to set flag_register
|
|
|
|
|
|
|
|
get_protocol_send_data(0x02, flag_register, &send->yaw, 3, send_buff, &tx_len);
|
2022-11-28 17:54:07 +08:00
|
|
|
USARTSend(vision_usart_instance, send_buff, tx_len);
|
2022-11-12 18:03:18 +08:00
|
|
|
}
|