From bcb1d72a97c315b811ac5acc3462aee0c91d5eff Mon Sep 17 00:00:00 2001 From: NeoZng Date: Wed, 19 Apr 2023 19:28:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=A1=BA=E5=BA=8F=E5=92=8C=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HAL_N_Middlewares/Src/main.c | 242 --------------------------------- Src/freertos.c | 2 +- application/chassis/chassis.c | 4 +- modules/referee/referee.md | 30 +++- modules/referee/referee_UI.c | 2 +- modules/referee/referee_task.c | 109 ++++++--------- modules/referee/referee_task.h | 8 +- modules/referee/rm_referee.c | 32 +---- modules/referee/rm_referee.h | 36 ++--- 9 files changed, 93 insertions(+), 372 deletions(-) delete mode 100644 HAL_N_Middlewares/Src/main.c diff --git a/HAL_N_Middlewares/Src/main.c b/HAL_N_Middlewares/Src/main.c deleted file mode 100644 index a06f22e..0000000 --- a/HAL_N_Middlewares/Src/main.c +++ /dev/null @@ -1,242 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2023 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -#include "cmsis_os.h" -#include "adc.h" -#include "can.h" -#include "crc.h" -#include "dac.h" -#include "dma.h" -#include "i2c.h" -#include "rng.h" -#include "rtc.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" -#include "usb_device.h" -#include "gpio.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include "robot.h" -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN PD */ -/* USER CODE END PD */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN PM */ - -/* USER CODE END PM */ - -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -void SystemClock_Config(void); -void MX_FREERTOS_Init(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); - /* USER CODE BEGIN Init */ - - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - MX_ADC1_Init(); - MX_CAN1_Init(); - MX_CAN2_Init(); - MX_SPI1_Init(); - MX_TIM4_Init(); - MX_TIM5_Init(); - MX_USART3_UART_Init(); - MX_RNG_Init(); - MX_RTC_Init(); - MX_TIM1_Init(); - MX_TIM10_Init(); - MX_USART1_UART_Init(); - MX_USART6_UART_Init(); - MX_TIM8_Init(); - MX_I2C2_Init(); - MX_I2C3_Init(); - MX_SPI2_Init(); - MX_CRC_Init(); - MX_DAC_Init(); - /* USER CODE BEGIN 2 */ - RobotInit(); - /* USER CODE END 2 */ - - /* Call init function for freertos objects (in freertos.c) */ - MX_FREERTOS_Init(); - - /* Start scheduler */ - osKernelStart(); - - /* We should never get here as control is now taken by the scheduler */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) - { - /* USER CODE END WHILE */ - - /* USER CODE BEGIN 3 */ - } - /* USER CODE END 3 */ -} - -/** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) -{ - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - - /** Configure the main internal regulator output voltage - */ - __HAL_RCC_PWR_CLK_ENABLE(); - __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); - - /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLM = 6; - RCC_OscInitStruct.PLL.PLLN = 168; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; - RCC_OscInitStruct.PLL.PLLQ = 7; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { - Error_Handler(); - } - - /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) - { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief Period elapsed callback in non blocking mode - * @note This function is called when TIM14 interrupt took place, inside - * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment - * a global variable "uwTick" used as application time base. - * @param htim : TIM handle - * @retval None - */ -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) -{ - /* USER CODE BEGIN Callback 0 */ - - /* USER CODE END Callback 0 */ - if (htim->Instance == TIM14) - { - HAL_IncTick(); - } - /* USER CODE BEGIN Callback 1 */ - - /* USER CODE END Callback 1 */ -} - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return state */ - __disable_irq(); - while (1) - { - } - /* USER CODE END Error_Handler_Debug */ -} - -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line number, - ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/Src/freertos.c b/Src/freertos.c index 2a2b1a2..4f339e6 100644 --- a/Src/freertos.c +++ b/Src/freertos.c @@ -206,7 +206,7 @@ void StartROBOTTASK(void const *argument) void StartUITASK(void const *argument) { - Referee_Interactive_init(); + My_UI_init(); while (1) { Referee_Interactive_task(); diff --git a/application/chassis/chassis.c b/application/chassis/chassis.c index 3306643..1e0a1a2 100644 --- a/application/chassis/chassis.c +++ b/application/chassis/chassis.c @@ -16,7 +16,7 @@ #include "dji_motor.h" #include "super_cap.h" #include "message_center.h" -#include "rm_referee.h" +#include "referee_task.h" #include "general_def.h" #include "bsp_dwt.h" @@ -103,7 +103,7 @@ void ChassisInit() chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_REVERSE; motor_rb = DJIMotorInit(&chassis_motor_config); - referee_data = RefereeInit(&huart6,&ui_data); // 裁判系统初始化 + referee_data = Referee_Interactive_init(&huart6,&ui_data); // 裁判系统初始化 // while (referee_data->GameRobotState.robot_id ==0); // Referee_Interactive_init(referee_data); diff --git a/modules/referee/referee.md b/modules/referee/referee.md index 2b09cc3..abf58c0 100644 --- a/modules/referee/referee.md +++ b/modules/referee/referee.md @@ -1 +1,29 @@ -# referee \ No newline at end of file +# referee + + +若需要进行多机交互,可增加此函数: +```c +void CommBetweenRobotSend(referee_id_t *_id, robot_interactive_data_t *_data) +{ + Communicate_SendData_t SendData; + uint8_t temp_datalength = Interactive_Data_LEN_Head + Communicate_Data_LEN; // 计算交互数据长度 6+n,n为交互数据长度 + + SendData.FrameHeader.SOF = REFEREE_SOF; + SendData.FrameHeader.DataLength = temp_datalength; + SendData.FrameHeader.Seq = UI_Seq; + SendData.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&SendData, LEN_CRC8, 0xFF); + + SendData.CmdID = ID_student_interactive; + + SendData.datahead.data_cmd_id = Communicate_Data_ID; + SendData.datahead.sender_ID = _id->Robot_ID; + SendData.datahead.receiver_ID = _id->Receiver_Robot_ID; + + SendData.Data = *_data; + + SendData.frametail = Get_CRC16_Check_Sum((uint8_t *)&SendData, LEN_HEADER + LEN_CMDID + temp_datalength, 0xFFFF); + + RefereeSend((uint8_t *)&SendData, LEN_HEADER + LEN_CMDID + temp_datalength + LEN_TAIL); // 发送 + UI_Seq++; // 包序号+1 +} +``` \ No newline at end of file diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index 651a891..d58a152 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -389,7 +389,7 @@ void UI_ReFresh(referee_id_t *_id, int cnt, ...) graphData = va_arg(ap, Graph_Data_t); // 访问参数列表中的每个项,第二个参数是你要返回的参数的类型,在取值时需要将其强制转化为指定类型的变量 memcpy(buffer + (LEN_HEADER + LEN_CMDID + Interactive_Data_LEN_Head + UI_Operate_LEN_PerDraw * i), (uint8_t *)&graphData, UI_Operate_LEN_PerDraw); } - Append_CRC16_Check_Sum(buffer,temp_datalength); + Append_CRC16_Check_Sum(buffer, temp_datalength); RefereeSend(buffer, temp_datalength); // 发送CRC16校验值 va_end(ap); // 结束可变参数的获取 diff --git a/modules/referee/referee_task.c b/modules/referee/referee_task.c index fe1b616..123700e 100644 --- a/modules/referee/referee_task.c +++ b/modules/referee/referee_task.c @@ -16,21 +16,32 @@ static Referee_Interactive_info_t *Interactive_data; // UI绘制需要的机器人状态数据 static referee_info_t *referee_recv_info; // 接收到的裁判系统数据 -static void DeterminRobotID(referee_info_t *_referee_info); -static void My_UI_init(referee_info_t *_referee_info); -static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_info_t *_Interactive_data); +/** + * @brief 判断各种ID,选择客户端ID + * @param referee_info_t *referee_recv_info + * @retval none + * @attention + */ +static void DeterminRobotID() +{ + // id小于7是红色,大于7是蓝色,0为红色,1为蓝色 #define Robot_Red 0 #define Robot_Blue 1 + referee_recv_info->referee_id.Robot_Color = referee_recv_info->GameRobotState.robot_id > 7 ? Robot_Blue : Robot_Red; + referee_recv_info->referee_id.Robot_ID = referee_recv_info->GameRobotState.robot_id; + referee_recv_info->referee_id.Cilent_ID = 0x0100 + referee_recv_info->referee_id.Robot_ID; // 计算客户端ID + referee_recv_info->referee_id.Receiver_Robot_ID = 0; +} + +static void My_UI_Refresh(referee_info_t *referee_recv_info, Referee_Interactive_info_t *_Interactive_data); static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data); // 模式切换检测 // syhtod 正式上车后需删除 static void robot_mode_change(Referee_Interactive_info_t *_Interactive_data); // 测试用函数,实现模式自动变化 -static void UI_test_init(referee_info_t *_referee_info); // UI测试函数 -void Referee_Interactive_init() +referee_info_t *Referee_Interactive_init(UART_HandleTypeDef *referee_usart_handle, Referee_Interactive_info_t *UI_data) { - RefereeGetUIData(&referee_recv_info, &Interactive_data); - while (referee_recv_info->GameRobotState.robot_id == 0); - DeterminRobotID(referee_recv_info); - My_UI_init(referee_recv_info); + referee_recv_info = RefereeInit(referee_usart_handle); // 初始化裁判系统的串口,并返回裁判系统反馈数据指针 + Interactive_data = UI_data; // 获取UI绘制需要的机器人状态数据 + return referee_recv_info; } void Referee_Interactive_task() @@ -44,9 +55,10 @@ static String_Data_t UI_State_sta[6]; // 机器人状态,静态只需画一次 static String_Data_t UI_State_dyn[6]; // 机器人状态,动态先add才能change static uint32_t shoot_line_location[10] = {540, 960, 490, 515, 565}; -static void My_UI_init(referee_info_t *_referee_info) +void My_UI_init() { - UIDelete(&_referee_info->referee_id, UI_Data_Del_ALL, 0); + DeterminRobotID(); + UIDelete(&referee_recv_info->referee_id, UI_Data_Del_ALL, 0); // 清空UI // // 绘制发射基准线 Line_Draw(&UI_shoot_line[0], "sl0", UI_Graph_ADD, 7, UI_Color_White, 3, 710, shoot_line_location[0], 1210, shoot_line_location[0]); @@ -55,40 +67,40 @@ static void My_UI_init(referee_info_t *_referee_info) Line_Draw(&UI_shoot_line[3], "sl3", UI_Graph_ADD, 7, UI_Color_Yellow, 2, 810, shoot_line_location[3], 1110, shoot_line_location[3]); Line_Draw(&UI_shoot_line[4], "sl4", UI_Graph_ADD, 7, UI_Color_Yellow, 2, 810, shoot_line_location[4], 1110, shoot_line_location[4]); - UI_ReFresh(&_referee_info->referee_id, 5, UI_shoot_line[0], UI_shoot_line[1], UI_shoot_line[2], UI_shoot_line[3], UI_shoot_line[4]); + UI_ReFresh(&referee_recv_info->referee_id, 5, UI_shoot_line[0], UI_shoot_line[1], UI_shoot_line[2], UI_shoot_line[3], UI_shoot_line[4]); // 绘制车辆状态标志指示 Char_Draw(&UI_State_sta[0], "ss0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 150, 750, "chassis:"); - Char_ReFresh(&_referee_info->referee_id, UI_State_sta[0]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_sta[0]); Char_Draw(&UI_State_sta[1], "ss1", UI_Graph_ADD, 8, UI_Color_Yellow, 15, 2, 150, 700, "gimbal:"); - Char_ReFresh(&_referee_info->referee_id, UI_State_sta[1]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_sta[1]); Char_Draw(&UI_State_sta[2], "ss2", UI_Graph_ADD, 8, UI_Color_Orange, 15, 2, 150, 650, "shoot:"); - Char_ReFresh(&_referee_info->referee_id, UI_State_sta[2]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_sta[2]); Char_Draw(&UI_State_sta[3], "ss3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 600, "frict:"); - Char_ReFresh(&_referee_info->referee_id, UI_State_sta[3]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_sta[3]); Char_Draw(&UI_State_sta[4], "ss4", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 550, "lid:"); - Char_ReFresh(&_referee_info->referee_id, UI_State_sta[4]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_sta[4]); // 底盘功率显示,静态 Char_Draw(&UI_State_sta[5], "ss5", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 720, 210, "Power:"); - Char_ReFresh(&_referee_info->referee_id, UI_State_sta[5]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_sta[5]); // 绘制车辆状态标志,动态 // 由于初始化时xxx_last_mode默认为0,所以此处对应UI也应该设为0时对应的UI,防止模式不变的情况下无法置位flag,导致UI无法刷新 Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 270, 750, "zeroforce"); - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[0]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[0]); Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_ADD, 8, UI_Color_Yellow, 15, 2, 270, 700, "zeroforce"); - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[1]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[1]); Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_ADD, 8, UI_Color_Orange, 15, 2, 270, 650, "off"); - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[2]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[2]); Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 270, 600, "off"); - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[3]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[3]); Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 270, 550, "open "); - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[4]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[4]); // 底盘功率显示,动态 Char_Draw(&UI_State_dyn[5], "sd5", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 840, 210, "0000"); - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[5]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[5]); } static uint8_t count = 0; @@ -144,7 +156,7 @@ static void robot_mode_change(Referee_Interactive_info_t *_Interactive_data) // } } -static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_info_t *_Interactive_data) +static void My_UI_Refresh(referee_info_t *referee_recv_info, Referee_Interactive_info_t *_Interactive_data) { Mode_Change_Check(_Interactive_data); // chassis @@ -166,7 +178,7 @@ static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_inf Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750, "follow "); break; } - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[0]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[0]); _Interactive_data->Referee_Interactive_Flag.chassis_flag = 0; } // gimbal @@ -190,7 +202,7 @@ static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_inf break; } } - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[1]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[1]); _Interactive_data->Referee_Interactive_Flag.gimbal_flag = 0; } // shoot @@ -209,7 +221,7 @@ static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_inf break; } } - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[2]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[2]); _Interactive_data->Referee_Interactive_Flag.shoot_flag = 0; } @@ -228,7 +240,7 @@ static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_inf break; } } - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[3]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[3]); _Interactive_data->Referee_Interactive_Flag.friction_flag = 0; } @@ -247,7 +259,7 @@ static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_inf break; } } - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[4]); + Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[4]); _Interactive_data->Referee_Interactive_Flag.lid_flag = 0; } } @@ -290,40 +302,3 @@ static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data) _Interactive_data->lid_last_mode = _Interactive_data->lid_mode; } } - -/** - * @brief 判断各种ID,选择客户端ID - * @param referee_info_t *_referee_info - * @retval none - * @attention - */ -static void DeterminRobotID(referee_info_t *_referee_info) -{ - // id小于7是红色,大于7是蓝色,0为红色,1为蓝色 #define Robot_Red 0 #define Robot_Blue 1 - _referee_info->referee_id.Robot_Color = _referee_info->GameRobotState.robot_id > 7 ? Robot_Blue : Robot_Red; - _referee_info->referee_id.Robot_ID = _referee_info->GameRobotState.robot_id; - _referee_info->referee_id.Cilent_ID = 0x0100 + _referee_info->referee_id.Robot_ID; // 计算客户端ID - _referee_info->referee_id.Receiver_Robot_ID = 0; -} - -/* 测试用函数 */ -static void UI_test_init(referee_info_t *_referee_info) -{ - Graph_Data_t graph[5]; - Graph_Data_t num[2]; - String_Data_t sdata[1]; - UIDelete(&_referee_info->referee_id, UI_Data_Del_ALL, 0); - - Line_Draw(&graph[0], "s0", UI_Graph_ADD, 0, UI_Color_White, 3, 710, 540, 1210, 540); - Rectangle_Draw(&graph[1], "s1", UI_Graph_ADD, 0, UI_Color_Yellow, 4, 600, 200, 800, 500); - Circle_Draw(&graph[2], "s2", UI_Graph_ADD, 0, UI_Color_Green, 5, 960, 540, 100); - Elliptical_Draw(&graph[3], "s3", UI_Graph_ADD, 0, UI_Color_Orange, 3, 960, 540, 100, 20); - Arc_Draw(&graph[4], "s4", UI_Graph_ADD, 0, UI_Color_Purplish_red, 30, 160, 3, 1200, 550, 50, 100); - - Float_Draw(&num[0], "s5", UI_Graph_ADD, 0, UI_Color_Pink, 50, 3, 5, 1050, 660, 1245545); - Integer_Draw(&num[1], "s6", UI_Graph_ADD, 0, UI_Color_Cyan, 50, 5, 1050, 460, 12345); - UI_ReFresh(&_referee_info->referee_id, 7, graph[0], graph[1], graph[2], graph[3], graph[4], num[0], num[1]); - - Char_Draw(&sdata[0], "s7", UI_Graph_ADD, 0, UI_Color_Green, 20, 2, 620, 710, "number:%d", 123); - Char_ReFresh(&_referee_info->referee_id, sdata[0]); -} diff --git a/modules/referee/referee_task.h b/modules/referee/referee_task.h index 4a2555b..c6c8ff2 100644 --- a/modules/referee/referee_task.h +++ b/modules/referee/referee_task.h @@ -8,7 +8,13 @@ * @brief 初始化裁判系统交互任务(UI和多机通信) * */ -void Referee_Interactive_init(); +referee_info_t *Referee_Interactive_init(UART_HandleTypeDef *referee_usart_handle, Referee_Interactive_info_t *UI_data); + +/** + * @brief 在referee task之前调用,添加在freertos.c中 + * + */ +void My_UI_init(); /** * @brief 裁判系统交互任务(UI和多机通信) diff --git a/modules/referee/rm_referee.c b/modules/referee/rm_referee.c index 8300dc2..41b9484 100644 --- a/modules/referee/rm_referee.c +++ b/modules/referee/rm_referee.c @@ -19,7 +19,6 @@ static USARTInstance *referee_usart_instance; // 裁判系统串口实例 static referee_info_t referee_info; // 裁判系统数据 -static Referee_Interactive_info_t *UI_tmp; // UI绘制需要的机器人状态数据 static void RefereeRxCallback(); static void JudgeReadData(uint8_t *buff); @@ -27,46 +26,17 @@ static void JudgeReadData(uint8_t *buff); uint8_t UI_Seq = 0; // 包序号,供整个referee文件使用 /* 裁判系统通信初始化 */ -referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle, Referee_Interactive_info_t *UI_data) +referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) { USART_Init_Config_s conf; conf.module_callback = RefereeRxCallback; conf.usart_handle = referee_usart_handle; conf.recv_buff_size = RE_RX_BUFFER_SIZE; referee_usart_instance = USARTRegister(&conf); - UI_tmp = UI_data; return &referee_info; } -void RefereeGetUIData(referee_info_t **recv_info_pp, Referee_Interactive_info_t **UI_data_pp) -{ - *recv_info_pp = &referee_info; - *UI_data_pp = UI_tmp; -} -void CommBetweenRobotSend(referee_id_t *_id, robot_interactive_data_t *_data) -{ - Communicate_SendData_t SendData; - uint8_t temp_datalength = Interactive_Data_LEN_Head + Communicate_Data_LEN; // 计算交互数据长度 6+n,n为交互数据长度 - - SendData.FrameHeader.SOF = REFEREE_SOF; - SendData.FrameHeader.DataLength = temp_datalength; - SendData.FrameHeader.Seq = UI_Seq; - SendData.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&SendData, LEN_CRC8, 0xFF); - - SendData.CmdID = ID_student_interactive; - - SendData.datahead.data_cmd_id = Communicate_Data_ID; - SendData.datahead.sender_ID = _id->Robot_ID; - SendData.datahead.receiver_ID = _id->Receiver_Robot_ID; - - SendData.Data = *_data; - - SendData.frametail = Get_CRC16_Check_Sum((uint8_t *)&SendData, LEN_HEADER + LEN_CMDID + temp_datalength, 0xFFFF); - - RefereeSend((uint8_t *)&SendData, LEN_HEADER + LEN_CMDID + temp_datalength + LEN_TAIL); // 发送 - UI_Seq++; // 包序号+1 -} /** * @brief 裁判系统数据发送函数,由于使用 diff --git a/modules/referee/rm_referee.h b/modules/referee/rm_referee.h index 477a3e3..9db1748 100644 --- a/modules/referee/rm_referee.h +++ b/modules/referee/rm_referee.h @@ -68,8 +68,8 @@ typedef struct lid_mode_e lid_mode; // 弹舱盖打开 loader_mode_e loader_mode; // 单发...连发 Chassis_Power_Data_s Chassis_Power_Data; // 功率控制 - - //上一次的模式,用于flag判断 + + // 上一次的模式,用于flag判断 chassis_mode_e chassis_last_mode; // 底盘模式 gimbal_mode_e gimbal_last_mode; // 云台模式 shoot_mode_e shoot_last_mode; // 发射模式设置 @@ -81,35 +81,19 @@ typedef struct #pragma pack() /** - * @brief 裁判系统通信初始化, 该函数会初始化裁判系统串口,开启中断,同时将UI绘制的数据指针传入 - * + * @brief 裁判系统通信初始化,该函数会初始化裁判系统串口,开启中断 + * * @param referee_usart_handle 串口handle,C板一般用串口6 - * @param UI_data UI绘制数据指针,即保存着UI绘制的各种状态数据 * @return referee_info_t* 返回裁判系统反馈的数据,包括热量/血量/状态等 */ -referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle, Referee_Interactive_info_t *UI_data); +referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle); /** - * @brief 由UI绘制的任务初始化调用,用于获取裁判系统反馈的数据指针和UI绘制的数据指针,以便UI绘制任务使用 - * - * @param recv_info_pp 指向裁判系统反馈的数据指针 - * @param UI_data_pp - */ -void RefereeGetUIData(referee_info_t **recv_info_pp, Referee_Interactive_info_t **UI_data_pp); - -/** - * @brief 发送机器人间的交互数据 - * @param referee_id_t *_id sender为本机器人,receiver为接收方机器人,发送前设置Receiver_Robot_ID再调用该函数 - * robot_interactive_data_t *data 数据段 - * @retval none - * @attention - */ -void CommBetweenRobotSend(referee_id_t *_id, robot_interactive_data_t *_data); - -/** - * @brief 发送函数 - * @todo - * @param + * @brief UI绘制和交互数的发送接口,由UI绘制任务和多机通信函数调用 + * @note 内部包含了一个实时系统的延时函数,这是因为裁判系统接收CMD数据至高位10Hz + * + * @param send 发送数据首地址 + * @param tx_len 发送长度 */ void RefereeSend(uint8_t *send, uint16_t tx_len);