This commit is contained in:
Robofish 2026-02-04 13:03:11 +08:00
parent 8712efa6f2
commit 20afc1a656
2 changed files with 861 additions and 536 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,14 @@
/*基于freertos_cli实现的虚拟命令行
help可以获得帮助
htop freertos任务状态等信息
cd可以切换目录
/ (root)
|-- /dev
|-- bmi088
|-- chassis_motor1
|-- /modules
|-- balance_chassis
|-- gimbal
|-- shoot
dev里可以用show命令查看设备信息
modules暂无实现
dev里的设备有哪些MRobot_RegisterDevices()
线
atti_esit任务里注册了bmi088和他的结构体cli线程里需要能够打印bmi088的数据
show的时候就可以看到imu的数据了
*/
/**
* @file mrobot.h
* @brief MRobot CLI - FreeRTOS CLI
*
* :
* - IMU
* - Unix cd, ls, pwd
* - htop
* -
* - 线
*/
#pragma once
@ -31,38 +19,103 @@ extern "C" {
/* Includes ----------------------------------------------------------------- */
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "component/ahrs.h"
#include "device/device.h"
#include "bsp/uart.h"
/* Exported constants ------------------------------------------------------- */
#define MROBOT_MAX_DEVICES 32
#define MROBOT_MAX_CMD_LEN 128
#define MROBOT_MAX_OUTPUT_LEN 512
#define MROBOT_RX_BUFFER_SIZE 256
/* Configuration ------------------------------------------------------------ */
/* 可在编译时通过 -D 选项覆盖这些默认值 */
/* Exported types ----------------------------------------------------------- */
#ifndef MROBOT_MAX_DEVICES
#define MROBOT_MAX_DEVICES 32 /* 最大设备数 */
#endif
#ifndef MROBOT_MAX_CUSTOM_COMMANDS
#define MROBOT_MAX_CUSTOM_COMMANDS 16 /* 最大自定义命令数 */
#endif
#ifndef MROBOT_CMD_BUFFER_SIZE
#define MROBOT_CMD_BUFFER_SIZE 128 /* 命令缓冲区大小 */
#endif
#ifndef MROBOT_OUTPUT_BUFFER_SIZE
#define MROBOT_OUTPUT_BUFFER_SIZE 512 /* 输出缓冲区大小 */
#endif
#ifndef MROBOT_DEVICE_NAME_LEN
#define MROBOT_DEVICE_NAME_LEN 32 /* 设备名最大长度 */
#endif
#ifndef MROBOT_PATH_MAX_LEN
#define MROBOT_PATH_MAX_LEN 64 /* 路径最大长度 */
#endif
#ifndef MROBOT_HTOP_REFRESH_MS
#define MROBOT_HTOP_REFRESH_MS 200 /* htop 刷新间隔 (ms) */
#endif
#ifndef MROBOT_UART_PORT
#define MROBOT_UART_PORT BSP_UART_VOFA /* 默认 UART 端口 */
#endif
/* Error codes -------------------------------------------------------------- */
typedef enum {
MROBOT_DEVICE_TYPE_IMU,
MROBOT_DEVICE_TYPE_MOTOR,
MROBOT_DEVICE_TYPE_SENSOR,
MROBOT_DEVICE_TYPE_CUSTOM,
MROBOT_OK = 0, /* 成功 */
MROBOT_ERR_FULL = -1, /* 容量已满 */
MROBOT_ERR_NULL_PTR = -2, /* 空指针 */
MROBOT_ERR_INVALID_ARG = -3, /* 无效参数 */
MROBOT_ERR_NOT_FOUND = -4, /* 未找到 */
MROBOT_ERR_ALLOC = -5, /* 内存分配失败 */
MROBOT_ERR_BUSY = -6, /* 设备忙 */
MROBOT_ERR_NOT_INIT = -7, /* 未初始化 */
} MRobot_Error_t;
/* Device types ------------------------------------------------------------- */
typedef enum {
MROBOT_DEVICE_TYPE_IMU, /* IMU 设备 */
MROBOT_DEVICE_TYPE_MOTOR, /* 电机设备 */
MROBOT_DEVICE_TYPE_SENSOR, /* 传感器设备 */
MROBOT_DEVICE_TYPE_CUSTOM, /* 自定义设备 */
MROBOT_DEVICE_TYPE_NUM /* 设备类型总数 */
} MRobot_DeviceType_t;
/* 设备打印回调函数类型 */
typedef void (*MRobot_PrintCallback_t)(void *device_data, char *buffer, uint16_t buffer_size);
/* CLI 运行状态 */
typedef enum {
MROBOT_STATE_IDLE, /* 空闲状态,等待输入 */
MROBOT_STATE_HTOP, /* htop 模式 */
MROBOT_STATE_PROCESSING, /* 正在处理命令 */
} MRobot_State_t;
/* 命令处理回调函数类型(与 pdCOMMAND_LINE_CALLBACK 相同) */
/* Callback types ----------------------------------------------------------- */
/**
* @brief
* @param device_data
* @param buffer
* @param buffer_size
* @return
*/
typedef int (*MRobot_PrintCallback_t)(const void *device_data, char *buffer, size_t buffer_size);
/**
* @brief FreeRTOS CLI
*/
typedef long (*MRobot_CommandCallback_t)(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString);
/* 注册的设备结构 */
/* Device structure --------------------------------------------------------- */
typedef struct {
char name[32];
MRobot_DeviceType_t type;
void *data; /* 指向实际设备数据的指针 */
MRobot_PrintCallback_t print_callback; /* 打印设备信息的回调函数 */
char name[MROBOT_DEVICE_NAME_LEN]; /* 设备名称 */
MRobot_DeviceType_t type; /* 设备类型 */
void *data; /* 设备数据指针 */
MRobot_PrintCallback_t print_cb; /* 打印回调函数 */
} MRobot_Device_t;
/* 设备模板结构体 - 使用 AHRS 标准结构 */
/* 标准设备数据结构 ---------------------------------------------------------- */
/**
* @brief IMU
*/
typedef struct {
DEVICE_Header_t header;
AHRS_Accl_t accl; /* 加速度 m/s² */
@ -72,6 +125,9 @@ typedef struct {
float temp; /* 温度 °C */
} DEVICE_IMU_t;
/**
* @brief
*/
typedef struct {
float rotor_abs_angle; /* 转子绝对角度 */
float rotor_speed; /* 实际转子转速 */
@ -79,62 +135,113 @@ typedef struct {
float temp; /* 温度 */
} DEVICE_MOTOR_Feedback_t;
/**
* @brief
*/
typedef struct {
DEVICE_Header_t header;
bool reverse; /* 是否反装 true表示反装 */
bool reverse; /* 是否反装 */
DEVICE_MOTOR_Feedback_t feedback;
} DEVICE_MOTOR_t;
/* Exported functions ------------------------------------------------------- */
/* Public API --------------------------------------------------------------- */
/**
* @brief MRobot UART
* @brief MRobot CLI
* @note FreeRTOS
*/
void MRobot_Init(void);
/**
* @brief MRobot
* @param name
* @param type
* @param data
* @param print_callback
* @retval 0 , -1
* @brief MRobot CLI
*/
int8_t MRobot_RegisterDevice(const char *name, MRobot_DeviceType_t type,
void *data, MRobot_PrintCallback_t print_callback);
void MRobot_DeInit(void);
/**
* @brief IMU MRobot使
* @brief CLI
* @return MRobot_State_t
*/
MRobot_State_t MRobot_GetState(void);
/**
* @brief MRobot
* @param name MROBOT_DEVICE_NAME_LEN-1
* @param type
* @param data NULL
* @param print_cb NULL show
* @return MRobot_Error_t
*/
MRobot_Error_t MRobot_RegisterDevice(const char *name, MRobot_DeviceType_t type,
void *data, MRobot_PrintCallback_t print_cb);
/**
* @brief
* @param name
* @return MRobot_Error_t
*/
MRobot_Error_t MRobot_UnregisterDevice(const char *name);
/**
* @brief IMU 使
* @param name
* @param imu_device DEVICE_IMU_t
* @retval 0 , -1
* @return MRobot_Error_t
*/
int8_t MRobot_RegisterIMU(const char *name, void *imu_device);
MRobot_Error_t MRobot_RegisterIMU(const char *name, DEVICE_IMU_t *imu_device);
/**
* @brief MRobot使
* @brief 使
* @param name
* @param motor MOTOR_t
* @retval 0 , -1
* @param motor MOTOR_t
* @return MRobot_Error_t
*/
int8_t MRobot_RegisterMotor(const char *name, void *motor);
MRobot_Error_t MRobot_RegisterMotor(const char *name, void *motor);
/**
* @brief MRobot CLI
* @param command "test"
* @param help_text "test: 测试命令\r\n"
* @param callback
* @param param_count 0=-1=
* @retval 0 , -1
* @brief
* @param command
* @param help_text
* @param callback
* @param param_count -1
* @return MRobot_Error_t
*/
int8_t MRobot_RegisterCommand(const char *command, const char *help_text,
MRobot_Error_t MRobot_RegisterCommand(const char *command, const char *help_text,
MRobot_CommandCallback_t callback, int8_t param_count);
/**
* @brief MRobot CLI
* @brief
* @return
*/
uint8_t MRobot_GetDeviceCount(void);
/**
* @brief
* @param name
* @return NULL
*/
const MRobot_Device_t *MRobot_FindDevice(const char *name);
/**
* @brief MRobot CLI
* @note 10ms
*/
void MRobot_Run(void);
/**
* @brief CLI 线
* @param str
* @return MRobot_Error_t
*/
MRobot_Error_t MRobot_Print(const char *str);
/**
* @brief CLI 线
* @param fmt
* @param ...
* @return
*/
int MRobot_Printf(const char *fmt, ...);
#ifdef __cplusplus
}
#endif