rm_balance/User/device/mrobot.h
2026-02-04 04:10:37 +08:00

85 lines
2.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*基于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的数据了
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ----------------------------------------------------------------- */
#include <stdint.h>
#include <stdbool.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
/* Exported types ----------------------------------------------------------- */
typedef enum {
MROBOT_DEVICE_TYPE_IMU,
MROBOT_DEVICE_TYPE_MOTOR,
MROBOT_DEVICE_TYPE_SENSOR,
MROBOT_DEVICE_TYPE_CUSTOM,
} MRobot_DeviceType_t;
/* 设备打印回调函数类型 */
typedef void (*MRobot_PrintCallback_t)(void *device_data, char *buffer, uint16_t buffer_size);
/* 注册的设备结构 */
typedef struct {
char name[32];
MRobot_DeviceType_t type;
void *data; /* 指向实际设备数据的指针 */
MRobot_PrintCallback_t print_callback; /* 打印设备信息的回调函数 */
} MRobot_Device_t;
/* Exported functions ------------------------------------------------------- */
/**
* @brief 初始化 MRobot 命令行系统(包含 UART 初始化)
*/
void MRobot_Init(void);
/**
* @brief 注册设备到 MRobot 系统
* @param name 设备名称
* @param type 设备类型
* @param data 指向设备数据结构的指针
* @param print_callback 打印设备信息的回调函数
* @retval 0 成功, -1 失败
*/
int8_t MRobot_RegisterDevice(const char *name, MRobot_DeviceType_t type,
void *data, MRobot_PrintCallback_t print_callback);
/**
* @brief MRobot 主循环,在 CLI 任务中调用
*/
void MRobot_Run(void);
#ifdef __cplusplus
}
#endif