mirror of
https://github.com/goldenfishs/MRobot.git
synced 2026-03-07 08:32:16 +08:00
更新名称
This commit is contained in:
parent
10a15bdff9
commit
27a7ed2102
@ -1,4 +1,4 @@
|
|||||||
bsp,can,fdcan,dwt,gpio,i2c,mm,spi,uart,pwm,time,flash
|
bsp,can,fdcan,dwt,gpio,i2c,mm,spi,uart,pwm,time,flash
|
||||||
component,ahrs,capacity,cmd,crc8,crc16,error_detect,filter,FreeRTOS_CLI,limiter,mixer,pid,ui,user_math
|
component,ahrs,capacity,cmd,crc8,crc16,error_detect,filter,FreeRTOS_CLI,limiter,mixer,pid,ui,user_math
|
||||||
device,dr16,bmi088,ist8310,motor,motor_rm,motor_dm,motor_vesc,motor_lk,motor_lz,motor_odrive,dm_imu,rc_can,servo,buzzer,led,ws2812,vofa,ops9,oid,lcd_driver,mrobot
|
device,dr16,bmi088,ist8310,motor,motor_rm,motor_dm,motor_vesc,motor_lk,motor_lz,motor_odrive,dm_imu,rc_can,servo,buzzer,led,ws2812,vofa,ops9,oid,lcd_driver,putty
|
||||||
module,
|
module,
|
||||||
|
@ -261,7 +261,7 @@ devices:
|
|||||||
header: "lcd.h"
|
header: "lcd.h"
|
||||||
source: "lcd.c"
|
source: "lcd.c"
|
||||||
|
|
||||||
mrobot:
|
putty:
|
||||||
name: "MRobot CLI"
|
name: "MRobot CLI"
|
||||||
description: "基于 FreeRTOS CLI 的嵌入式调试命令行系统,支持设备注册与监控、类 Unix 文件系统命令、htop 风格任务监控等"
|
description: "基于 FreeRTOS CLI 的嵌入式调试命令行系统,支持设备注册与监控、类 Unix 文件系统命令、htop 风格任务监控等"
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -269,9 +269,9 @@ devices:
|
|||||||
component: ["freertos_cli"]
|
component: ["freertos_cli"]
|
||||||
bsp_requirements:
|
bsp_requirements:
|
||||||
- type: "uart"
|
- type: "uart"
|
||||||
var_name: "BSP_UART_MROBOT"
|
var_name: "BSP_UART_PUTTY"
|
||||||
description: "用于 MRobot CLI 命令行交互"
|
description: "用于 MRobot CLI 命令行交互"
|
||||||
thread_signals: []
|
thread_signals: []
|
||||||
files:
|
files:
|
||||||
header: "mrobot.h"
|
header: "putty.h"
|
||||||
source: "mrobot.c"
|
source: "putty.c"
|
||||||
@ -1,10 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* @file mrobot.c
|
* @file putty.c
|
||||||
* @brief MRobot CLI 实现
|
* @brief Putty CLI 实现
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
#include "device/mrobot.h"
|
#include "device/putty.h"
|
||||||
#include "component/freertos_cli.h"
|
#include "component/freertos_cli.h"
|
||||||
#include "bsp/uart.h"
|
#include "bsp/uart.h"
|
||||||
#include "bsp/mm.h"
|
#include "bsp/mm.h"
|
||||||
@ -39,19 +39,19 @@ static const char *const CLI_WELCOME_MESSAGE =
|
|||||||
/* CLI 上下文结构体 - 封装所有状态 */
|
/* CLI 上下文结构体 - 封装所有状态 */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* 设备管理 */
|
/* 设备管理 */
|
||||||
MRobot_Device_t devices[MROBOT_MAX_DEVICES];
|
Putty_Device_t devices[PUTTY_MAX_DEVICES];
|
||||||
uint8_t device_count;
|
uint8_t device_count;
|
||||||
|
|
||||||
/* 自定义命令 */
|
/* 自定义命令 */
|
||||||
CLI_Command_Definition_t *custom_cmds[MROBOT_MAX_CUSTOM_COMMANDS];
|
CLI_Command_Definition_t *custom_cmds[PUTTY_MAX_CUSTOM_COMMANDS];
|
||||||
uint8_t custom_cmd_count;
|
uint8_t custom_cmd_count;
|
||||||
|
|
||||||
/* CLI 状态 */
|
/* CLI 状态 */
|
||||||
MRobot_State_t state;
|
Putty_State_t state;
|
||||||
char current_path[MROBOT_PATH_MAX_LEN];
|
char current_path[PUTTY_PATH_MAX_LEN];
|
||||||
|
|
||||||
/* 命令缓冲区 */
|
/* 命令缓冲区 */
|
||||||
uint8_t cmd_buffer[MROBOT_CMD_BUFFER_SIZE];
|
uint8_t cmd_buffer[PUTTY_CMD_BUFFER_SIZE];
|
||||||
volatile uint8_t cmd_index;
|
volatile uint8_t cmd_index;
|
||||||
volatile bool cmd_ready;
|
volatile bool cmd_ready;
|
||||||
|
|
||||||
@ -61,20 +61,20 @@ typedef struct {
|
|||||||
volatile bool htop_exit;
|
volatile bool htop_exit;
|
||||||
|
|
||||||
/* 输出缓冲区 */
|
/* 输出缓冲区 */
|
||||||
char output_buffer[MROBOT_OUTPUT_BUFFER_SIZE];
|
char output_buffer[PUTTY_OUTPUT_BUFFER_SIZE];
|
||||||
|
|
||||||
/* 初始化标志 */
|
/* 初始化标志 */
|
||||||
bool initialized;
|
bool initialized;
|
||||||
|
|
||||||
/* 互斥锁 */
|
/* 互斥锁 */
|
||||||
SemaphoreHandle_t mutex;
|
SemaphoreHandle_t mutex;
|
||||||
} MRobot_Context_t;
|
} Putty_Context_t;
|
||||||
|
|
||||||
/* Private variables -------------------------------------------------------- */
|
/* Private variables -------------------------------------------------------- */
|
||||||
static MRobot_Context_t ctx = {
|
static Putty_Context_t ctx = {
|
||||||
.device_count = 0,
|
.device_count = 0,
|
||||||
.custom_cmd_count = 0,
|
.custom_cmd_count = 0,
|
||||||
.state = MROBOT_STATE_IDLE,
|
.state = PUTTY_STATE_IDLE,
|
||||||
.current_path = "/",
|
.current_path = "/",
|
||||||
.cmd_index = 0,
|
.cmd_index = 0,
|
||||||
.cmd_ready = false,
|
.cmd_ready = false,
|
||||||
@ -85,7 +85,6 @@ static MRobot_Context_t ctx = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Private function prototypes ---------------------------------------------- */
|
/* Private function prototypes ---------------------------------------------- */
|
||||||
/* 命令处理函数 */
|
|
||||||
static BaseType_t cmd_help(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString);
|
static BaseType_t cmd_help(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString);
|
||||||
static BaseType_t cmd_htop(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString);
|
static BaseType_t cmd_htop(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString);
|
||||||
static BaseType_t cmd_cd(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString);
|
static BaseType_t cmd_cd(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString);
|
||||||
@ -128,8 +127,8 @@ static void send_string(const char *str) {
|
|||||||
* @brief 发送命令提示符
|
* @brief 发送命令提示符
|
||||||
*/
|
*/
|
||||||
static void send_prompt(void) {
|
static void send_prompt(void) {
|
||||||
char prompt[MROBOT_PATH_MAX_LEN + 32];
|
char prompt[PUTTY_PATH_MAX_LEN + 32];
|
||||||
snprintf(prompt, sizeof(prompt), MROBOT_USER_NAME "@" MROBOT_HOST_NAME ":%s$ ", ctx.current_path);
|
snprintf(prompt, sizeof(prompt), PUTTY_USER_NAME "@" PUTTY_HOST_NAME ":%s$ ", ctx.current_path);
|
||||||
send_string(prompt);
|
send_string(prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +146,7 @@ static void uart_rx_callback(void) {
|
|||||||
uint8_t ch = ctx.uart_rx_char;
|
uint8_t ch = ctx.uart_rx_char;
|
||||||
|
|
||||||
/* htop 模式下检查退出键 */
|
/* htop 模式下检查退出键 */
|
||||||
if (ctx.state == MROBOT_STATE_HTOP) {
|
if (ctx.state == PUTTY_STATE_HTOP) {
|
||||||
if (ch == 'q' || ch == 'Q' || ch == 27) {
|
if (ch == 'q' || ch == 'Q' || ch == 27) {
|
||||||
ctx.htop_exit = true;
|
ctx.htop_exit = true;
|
||||||
}
|
}
|
||||||
@ -187,7 +186,7 @@ static BaseType_t cmd_help(char *pcWriteBuffer, size_t xWriteBufferLen, const ch
|
|||||||
(void)pcCommandString;
|
(void)pcCommandString;
|
||||||
|
|
||||||
int offset = snprintf(pcWriteBuffer, xWriteBufferLen,
|
int offset = snprintf(pcWriteBuffer, xWriteBufferLen,
|
||||||
"MRobot CLI v2.0\r\n"
|
"Putty CLI v2.0\r\n"
|
||||||
"================\r\n"
|
"================\r\n"
|
||||||
"Built-in Commands:\r\n");
|
"Built-in Commands:\r\n");
|
||||||
|
|
||||||
@ -217,7 +216,7 @@ static BaseType_t cmd_htop(char *pcWriteBuffer, size_t xWriteBufferLen, const ch
|
|||||||
(void)pcCommandString;
|
(void)pcCommandString;
|
||||||
(void)pcWriteBuffer;
|
(void)pcWriteBuffer;
|
||||||
(void)xWriteBufferLen;
|
(void)xWriteBufferLen;
|
||||||
/* htop 模式在 MRobot_Run 中处理 */
|
/* htop 模式在 Putty_Run 中处理 */
|
||||||
return pdFALSE;
|
return pdFALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +237,7 @@ static BaseType_t cmd_cd(char *pcWriteBuffer, size_t xWriteBufferLen, const char
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 安全复制路径参数 */
|
/* 安全复制路径参数 */
|
||||||
char path[MROBOT_PATH_MAX_LEN];
|
char path[PUTTY_PATH_MAX_LEN];
|
||||||
size_t copy_len = (size_t)param_len < sizeof(path) - 1 ? (size_t)param_len : sizeof(path) - 1;
|
size_t copy_len = (size_t)param_len < sizeof(path) - 1 ? (size_t)param_len : sizeof(path) - 1;
|
||||||
strncpy(path, param, copy_len);
|
strncpy(path, param, copy_len);
|
||||||
path[copy_len] = '\0';
|
path[copy_len] = '\0';
|
||||||
@ -304,7 +303,7 @@ static BaseType_t cmd_show(char *pcWriteBuffer, size_t xWriteBufferLen, const ch
|
|||||||
/* 使用局部静态变量跟踪多次打印状态 */
|
/* 使用局部静态变量跟踪多次打印状态 */
|
||||||
static uint32_t print_count = 0;
|
static uint32_t print_count = 0;
|
||||||
static uint32_t current_iter = 0;
|
static uint32_t current_iter = 0;
|
||||||
static char target_device[MROBOT_DEVICE_NAME_LEN] = {0};
|
static char target_device[PUTTY_DEVICE_NAME_LEN] = {0};
|
||||||
|
|
||||||
/* 首次调用时解析参数 */
|
/* 首次调用时解析参数 */
|
||||||
if (current_iter == 0) {
|
if (current_iter == 0) {
|
||||||
@ -380,7 +379,7 @@ static BaseType_t cmd_show(char *pcWriteBuffer, size_t xWriteBufferLen, const ch
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* 显示指定设备 */
|
/* 显示指定设备 */
|
||||||
const MRobot_Device_t *dev = MRobot_FindDevice(target_device);
|
const Putty_Device_t *dev = Putty_FindDevice(target_device);
|
||||||
|
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
snprintf(pcWriteBuffer, xWriteBufferLen,
|
snprintf(pcWriteBuffer, xWriteBufferLen,
|
||||||
@ -404,7 +403,7 @@ static BaseType_t cmd_show(char *pcWriteBuffer, size_t xWriteBufferLen, const ch
|
|||||||
/* 判断是否继续打印 */
|
/* 判断是否继续打印 */
|
||||||
current_iter++;
|
current_iter++;
|
||||||
if (current_iter < print_count) {
|
if (current_iter < print_count) {
|
||||||
osDelay(MROBOT_HTOP_REFRESH_MS);
|
osDelay(PUTTY_HTOP_REFRESH_MS);
|
||||||
return pdTRUE;
|
return pdTRUE;
|
||||||
} else {
|
} else {
|
||||||
current_iter = 0;
|
current_iter = 0;
|
||||||
@ -417,7 +416,7 @@ static BaseType_t cmd_show(char *pcWriteBuffer, size_t xWriteBufferLen, const ch
|
|||||||
* ========================================================================== */
|
* ========================================================================== */
|
||||||
static void handle_htop_mode(void) {
|
static void handle_htop_mode(void) {
|
||||||
send_string(ANSI_CLEAR_SCREEN);
|
send_string(ANSI_CLEAR_SCREEN);
|
||||||
send_string("=== MRobot Task Monitor (Press 'q' to exit) ===\r\n\r\n");
|
send_string("=== Putty Task Monitor (Press 'q' to exit) ===\r\n\r\n");
|
||||||
|
|
||||||
/* 获取任务列表 */
|
/* 获取任务列表 */
|
||||||
char task_buffer[1024];
|
char task_buffer[1024];
|
||||||
@ -465,20 +464,20 @@ static void handle_htop_mode(void) {
|
|||||||
|
|
||||||
/* 检查退出 */
|
/* 检查退出 */
|
||||||
if (ctx.htop_exit) {
|
if (ctx.htop_exit) {
|
||||||
ctx.state = MROBOT_STATE_IDLE;
|
ctx.state = PUTTY_STATE_IDLE;
|
||||||
ctx.htop_exit = false;
|
ctx.htop_exit = false;
|
||||||
send_string(ANSI_CLEAR_SCREEN);
|
send_string(ANSI_CLEAR_SCREEN);
|
||||||
send_prompt();
|
send_prompt();
|
||||||
}
|
}
|
||||||
|
|
||||||
osDelay(MROBOT_HTOP_REFRESH_MS);
|
osDelay(PUTTY_HTOP_REFRESH_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
/* 公共 API 实现 */
|
/* 公共 API 实现 */
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
|
|
||||||
void MRobot_Init(void) {
|
void Putty_Init(void) {
|
||||||
if (ctx.initialized) return;
|
if (ctx.initialized) return;
|
||||||
|
|
||||||
/* 创建互斥锁 */
|
/* 创建互斥锁 */
|
||||||
@ -487,7 +486,7 @@ void MRobot_Init(void) {
|
|||||||
/* 初始化状态(保留已注册的设备) */
|
/* 初始化状态(保留已注册的设备) */
|
||||||
// 注意:不清除 devices 和 device_count,因为其他任务可能已经注册了设备
|
// 注意:不清除 devices 和 device_count,因为其他任务可能已经注册了设备
|
||||||
ctx.custom_cmd_count = 0;
|
ctx.custom_cmd_count = 0;
|
||||||
ctx.state = MROBOT_STATE_IDLE;
|
ctx.state = PUTTY_STATE_IDLE;
|
||||||
strcpy(ctx.current_path, "/");
|
strcpy(ctx.current_path, "/");
|
||||||
ctx.cmd_index = 0;
|
ctx.cmd_index = 0;
|
||||||
ctx.cmd_ready = false;
|
ctx.cmd_ready = false;
|
||||||
@ -518,7 +517,7 @@ void MRobot_Init(void) {
|
|||||||
ctx.initialized = true;
|
ctx.initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MRobot_DeInit(void) {
|
void Putty_DeInit(void) {
|
||||||
if (!ctx.initialized) return;
|
if (!ctx.initialized) return;
|
||||||
|
|
||||||
/* 释放自定义命令内存 */
|
/* 释放自定义命令内存 */
|
||||||
@ -538,23 +537,23 @@ void MRobot_DeInit(void) {
|
|||||||
ctx.initialized = false;
|
ctx.initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MRobot_State_t MRobot_GetState(void) {
|
Putty_State_t Putty_GetState(void) {
|
||||||
return ctx.state;
|
return ctx.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
MRobot_Error_t MRobot_RegisterDevice(const char *name, void *data, MRobot_PrintCallback_t print_cb) {
|
Putty_Error_t Putty_RegisterDevice(const char *name, void *data, Putty_PrintCallback_t print_cb) {
|
||||||
if (name == NULL || data == NULL) {
|
if (name == NULL || data == NULL) {
|
||||||
return MROBOT_ERR_NULL_PTR;
|
return PUTTY_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.device_count >= MROBOT_MAX_DEVICES) {
|
if (ctx.device_count >= PUTTY_MAX_DEVICES) {
|
||||||
return MROBOT_ERR_FULL;
|
return PUTTY_ERR_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 检查重名 */
|
/* 检查重名 */
|
||||||
for (uint8_t i = 0; i < ctx.device_count; i++) {
|
for (uint8_t i = 0; i < ctx.device_count; i++) {
|
||||||
if (strcmp(ctx.devices[i].name, name) == 0) {
|
if (strcmp(ctx.devices[i].name, name) == 0) {
|
||||||
return MROBOT_ERR_INVALID_ARG; /* 设备名已存在 */
|
return PUTTY_ERR_INVALID_ARG; /* 设备名已存在 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,8 +562,8 @@ MRobot_Error_t MRobot_RegisterDevice(const char *name, void *data, MRobot_PrintC
|
|||||||
xSemaphoreTake(ctx.mutex, portMAX_DELAY);
|
xSemaphoreTake(ctx.mutex, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(ctx.devices[ctx.device_count].name, name, MROBOT_DEVICE_NAME_LEN - 1);
|
strncpy(ctx.devices[ctx.device_count].name, name, PUTTY_DEVICE_NAME_LEN - 1);
|
||||||
ctx.devices[ctx.device_count].name[MROBOT_DEVICE_NAME_LEN - 1] = '\0';
|
ctx.devices[ctx.device_count].name[PUTTY_DEVICE_NAME_LEN - 1] = '\0';
|
||||||
ctx.devices[ctx.device_count].data = data;
|
ctx.devices[ctx.device_count].data = data;
|
||||||
ctx.devices[ctx.device_count].print_cb = print_cb;
|
ctx.devices[ctx.device_count].print_cb = print_cb;
|
||||||
ctx.device_count++;
|
ctx.device_count++;
|
||||||
@ -573,12 +572,12 @@ MRobot_Error_t MRobot_RegisterDevice(const char *name, void *data, MRobot_PrintC
|
|||||||
xSemaphoreGive(ctx.mutex);
|
xSemaphoreGive(ctx.mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return MROBOT_OK;
|
return PUTTY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
MRobot_Error_t MRobot_UnregisterDevice(const char *name) {
|
Putty_Error_t Putty_UnregisterDevice(const char *name) {
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
return MROBOT_ERR_NULL_PTR;
|
return PUTTY_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.mutex != NULL) {
|
if (ctx.mutex != NULL) {
|
||||||
@ -596,30 +595,30 @@ MRobot_Error_t MRobot_UnregisterDevice(const char *name) {
|
|||||||
if (ctx.mutex != NULL) {
|
if (ctx.mutex != NULL) {
|
||||||
xSemaphoreGive(ctx.mutex);
|
xSemaphoreGive(ctx.mutex);
|
||||||
}
|
}
|
||||||
return MROBOT_OK;
|
return PUTTY_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.mutex != NULL) {
|
if (ctx.mutex != NULL) {
|
||||||
xSemaphoreGive(ctx.mutex);
|
xSemaphoreGive(ctx.mutex);
|
||||||
}
|
}
|
||||||
return MROBOT_ERR_NOT_FOUND;
|
return PUTTY_ERR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
MRobot_Error_t MRobot_RegisterCommand(const char *command, const char *help_text,
|
Putty_Error_t Putty_RegisterCommand(const char *command, const char *help_text,
|
||||||
MRobot_CommandCallback_t callback, int8_t param_count) {
|
Putty_CommandCallback_t callback, int8_t param_count) {
|
||||||
if (command == NULL || help_text == NULL || callback == NULL) {
|
if (command == NULL || help_text == NULL || callback == NULL) {
|
||||||
return MROBOT_ERR_NULL_PTR;
|
return PUTTY_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.custom_cmd_count >= MROBOT_MAX_CUSTOM_COMMANDS) {
|
if (ctx.custom_cmd_count >= PUTTY_MAX_CUSTOM_COMMANDS) {
|
||||||
return MROBOT_ERR_FULL;
|
return PUTTY_ERR_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 动态分配命令结构体 */
|
/* 动态分配命令结构体 */
|
||||||
CLI_Command_Definition_t *cmd_def = BSP_Malloc(sizeof(CLI_Command_Definition_t));
|
CLI_Command_Definition_t *cmd_def = BSP_Malloc(sizeof(CLI_Command_Definition_t));
|
||||||
if (cmd_def == NULL) {
|
if (cmd_def == NULL) {
|
||||||
return MROBOT_ERR_ALLOC;
|
return PUTTY_ERR_ALLOC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 初始化命令定义 */
|
/* 初始化命令定义 */
|
||||||
@ -634,14 +633,14 @@ MRobot_Error_t MRobot_RegisterCommand(const char *command, const char *help_text
|
|||||||
ctx.custom_cmds[ctx.custom_cmd_count] = cmd_def;
|
ctx.custom_cmds[ctx.custom_cmd_count] = cmd_def;
|
||||||
ctx.custom_cmd_count++;
|
ctx.custom_cmd_count++;
|
||||||
|
|
||||||
return MROBOT_OK;
|
return PUTTY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MRobot_GetDeviceCount(void) {
|
uint8_t Putty_GetDeviceCount(void) {
|
||||||
return ctx.device_count;
|
return ctx.device_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MRobot_Device_t *MRobot_FindDevice(const char *name) {
|
const Putty_Device_t *Putty_FindDevice(const char *name) {
|
||||||
if (name == NULL) return NULL;
|
if (name == NULL) return NULL;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < ctx.device_count; i++) {
|
for (uint8_t i = 0; i < ctx.device_count; i++) {
|
||||||
@ -652,10 +651,10 @@ const MRobot_Device_t *MRobot_FindDevice(const char *name) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MRobot_Printf(const char *fmt, ...) {
|
int Putty_Printf(const char *fmt, ...) {
|
||||||
if (fmt == NULL || !ctx.initialized) return -1;
|
if (fmt == NULL || !ctx.initialized) return -1;
|
||||||
|
|
||||||
char buffer[MROBOT_OUTPUT_BUFFER_SIZE];
|
char buffer[PUTTY_OUTPUT_BUFFER_SIZE];
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
int len = format_float_va(buffer, sizeof(buffer), fmt, args);
|
int len = format_float_va(buffer, sizeof(buffer), fmt, args);
|
||||||
@ -710,7 +709,7 @@ static int format_float_va(char *buf, size_t size, const char *fmt, va_list args
|
|||||||
switch (*p) {
|
switch (*p) {
|
||||||
case 'f': { /* 浮点数 */
|
case 'f': { /* 浮点数 */
|
||||||
double val = va_arg(args, double);
|
double val = va_arg(args, double);
|
||||||
written = MRobot_FormatFloat(buf_ptr, buf_remain, (float)val, precision);
|
written = Putty_FormatFloat(buf_ptr, buf_remain, (float)val, precision);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'd':
|
case 'd':
|
||||||
@ -785,7 +784,7 @@ static int format_float_va(char *buf, size_t size, const char *fmt, va_list args
|
|||||||
return (int)(buf_ptr - buf);
|
return (int)(buf_ptr - buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MRobot_Snprintf(char *buf, size_t size, const char *fmt, ...) {
|
int Putty_Snprintf(char *buf, size_t size, const char *fmt, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
int len = format_float_va(buf, size, fmt, args);
|
int len = format_float_va(buf, size, fmt, args);
|
||||||
@ -793,7 +792,7 @@ int MRobot_Snprintf(char *buf, size_t size, const char *fmt, ...) {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MRobot_FormatFloat(char *buf, size_t size, float val, int precision) {
|
int Putty_FormatFloat(char *buf, size_t size, float val, int precision) {
|
||||||
if (buf == NULL || size == 0) return 0;
|
if (buf == NULL || size == 0) return 0;
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@ -831,22 +830,22 @@ int MRobot_FormatFloat(char *buf, size_t size, float val, int precision) {
|
|||||||
return (written > 0) ? (offset + written) : offset;
|
return (written > 0) ? (offset + written) : offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MRobot_Run(void) {
|
void Putty_Run(void) {
|
||||||
if (!ctx.initialized) return;
|
if (!ctx.initialized) return;
|
||||||
|
|
||||||
/* htop 模式 */
|
/* htop 模式 */
|
||||||
if (ctx.state == MROBOT_STATE_HTOP) {
|
if (ctx.state == PUTTY_STATE_HTOP) {
|
||||||
handle_htop_mode();
|
handle_htop_mode();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 处理命令 */
|
/* 处理命令 */
|
||||||
if (ctx.cmd_ready) {
|
if (ctx.cmd_ready) {
|
||||||
ctx.state = MROBOT_STATE_PROCESSING;
|
ctx.state = PUTTY_STATE_PROCESSING;
|
||||||
|
|
||||||
/* 检查是否是 htop 命令 */
|
/* 检查是否是 htop 命令 */
|
||||||
if (strcmp((char *)ctx.cmd_buffer, "htop") == 0) {
|
if (strcmp((char *)ctx.cmd_buffer, "htop") == 0) {
|
||||||
ctx.state = MROBOT_STATE_HTOP;
|
ctx.state = PUTTY_STATE_HTOP;
|
||||||
ctx.htop_exit = false;
|
ctx.htop_exit = false;
|
||||||
} else {
|
} else {
|
||||||
/* 处理其他命令 */
|
/* 处理其他命令 */
|
||||||
@ -863,7 +862,7 @@ void MRobot_Run(void) {
|
|||||||
} while (more != pdFALSE);
|
} while (more != pdFALSE);
|
||||||
|
|
||||||
send_prompt();
|
send_prompt();
|
||||||
ctx.state = MROBOT_STATE_IDLE;
|
ctx.state = PUTTY_STATE_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.cmd_index = 0;
|
ctx.cmd_index = 0;
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @file mrobot.h
|
* @file putty.h
|
||||||
* @brief MRobot CLI - 基于 FreeRTOS CLI 的嵌入式调试命令行系统
|
* @brief Putty CLI - 基于 FreeRTOS CLI 的嵌入式调试命令行系统
|
||||||
*
|
*
|
||||||
* 功能特性:
|
* 功能特性:
|
||||||
* - 设备注册与监控(IMU、电机、传感器等)
|
* - 设备注册与监控(IMU、电机、传感器等)
|
||||||
@ -25,7 +25,7 @@
|
|||||||
* // 2. 实现打印回调
|
* // 2. 实现打印回调
|
||||||
* static int print_imu(const void *data, char *buf, size_t size) {
|
* static int print_imu(const void *data, char *buf, size_t size) {
|
||||||
* const MyIMU_t *imu = (const MyIMU_t *)data;
|
* const MyIMU_t *imu = (const MyIMU_t *)data;
|
||||||
* return MRobot_Snprintf(buf, size,
|
* return Putty_Snprintf(buf, size,
|
||||||
* " Status: %s\r\n"
|
* " Status: %s\r\n"
|
||||||
* " Accel : X=%.3f Y=%.3f Z=%.3f\r\n"
|
* " Accel : X=%.3f Y=%.3f Z=%.3f\r\n"
|
||||||
* " Euler : R=%.2f P=%.2f Y=%.2f\r\n"
|
* " Euler : R=%.2f P=%.2f Y=%.2f\r\n"
|
||||||
@ -37,7 +37,7 @@
|
|||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* // 3. 注册设备
|
* // 3. 注册设备
|
||||||
* MRobot_RegisterDevice("imu", &my_imu, print_imu);
|
* Putty_RegisterDevice("imu", &my_imu, print_imu);
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @example 电机设备注册示例
|
* @example 电机设备注册示例
|
||||||
@ -53,7 +53,7 @@
|
|||||||
*
|
*
|
||||||
* static int print_motor(const void *data, char *buf, size_t size) {
|
* static int print_motor(const void *data, char *buf, size_t size) {
|
||||||
* const MyMotor_t *m = (const MyMotor_t *)data;
|
* const MyMotor_t *m = (const MyMotor_t *)data;
|
||||||
* return MRobot_Snprintf(buf, size,
|
* return Putty_Snprintf(buf, size,
|
||||||
* " Status : %s\r\n"
|
* " Status : %s\r\n"
|
||||||
* " Angle : %.2f deg\r\n"
|
* " Angle : %.2f deg\r\n"
|
||||||
* " Speed : %.1f RPM\r\n"
|
* " Speed : %.1f RPM\r\n"
|
||||||
@ -63,10 +63,10 @@
|
|||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* // 注册 4 个电机
|
* // 注册 4 个电机
|
||||||
* MRobot_RegisterDevice("motor0", &motor[0], print_motor);
|
* Putty_RegisterDevice("motor0", &motor[0], print_motor);
|
||||||
* MRobot_RegisterDevice("motor1", &motor[1], print_motor);
|
* Putty_RegisterDevice("motor1", &motor[1], print_motor);
|
||||||
* MRobot_RegisterDevice("motor2", &motor[2], print_motor);
|
* Putty_RegisterDevice("motor2", &motor[2], print_motor);
|
||||||
* MRobot_RegisterDevice("motor3", &motor[3], print_motor);
|
* Putty_RegisterDevice("motor3", &motor[3], print_motor);
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @example 自定义校准命令示例
|
* @example 自定义校准命令示例
|
||||||
@ -79,24 +79,24 @@
|
|||||||
* const char *param = FreeRTOS_CLIGetParameter(cmd, 1, NULL);
|
* const char *param = FreeRTOS_CLIGetParameter(cmd, 1, NULL);
|
||||||
*
|
*
|
||||||
* if (param == NULL) {
|
* if (param == NULL) {
|
||||||
* return MRobot_Snprintf(buf, size, "Usage: cali <gyro|accel|save>\r\n");
|
* return Putty_Snprintf(buf, size, "Usage: cali <gyro|accel|save>\r\n");
|
||||||
* }
|
* }
|
||||||
* if (strncmp(param, "gyro", 4) == 0) {
|
* if (strncmp(param, "gyro", 4) == 0) {
|
||||||
* // 采集 1000 次陀螺仪数据求平均
|
* // 采集 1000 次陀螺仪数据求平均
|
||||||
* MRobot_Snprintf(buf, size, "Calibrating gyro... keep IMU still!\r\n");
|
* Putty_Snprintf(buf, size, "Calibrating gyro... keep IMU still!\r\n");
|
||||||
* // ... 校准逻辑 ...
|
* // ... 校准逻辑 ...
|
||||||
* return 0;
|
* return 0;
|
||||||
* }
|
* }
|
||||||
* if (strncmp(param, "save", 4) == 0) {
|
* if (strncmp(param, "save", 4) == 0) {
|
||||||
* // 保存到 Flash
|
* // 保存到 Flash
|
||||||
* MRobot_Snprintf(buf, size, "Calibration saved to flash.\r\n");
|
* Putty_Snprintf(buf, size, "Calibration saved to flash.\r\n");
|
||||||
* return 0;
|
* return 0;
|
||||||
* }
|
* }
|
||||||
* return MRobot_Snprintf(buf, size, "Unknown: %s\r\n", param);
|
* return Putty_Snprintf(buf, size, "Unknown: %s\r\n", param);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* // 注册命令
|
* // 注册命令
|
||||||
* MRobot_RegisterCommand("cali", "cali <gyro|accel|save>: IMU calibration\r\n", cmd_cali, -1);
|
* Putty_RegisterCommand("cali", "cali <gyro|accel|save>: IMU calibration", cmd_cali, -1);
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -115,60 +115,60 @@ extern "C" {
|
|||||||
/* Configuration ------------------------------------------------------------ */
|
/* Configuration ------------------------------------------------------------ */
|
||||||
/* 可在编译时通过 -D 选项覆盖这些默认值 */
|
/* 可在编译时通过 -D 选项覆盖这些默认值 */
|
||||||
|
|
||||||
#ifndef MROBOT_MAX_DEVICES
|
#ifndef PUTTY_MAX_DEVICES
|
||||||
#define MROBOT_MAX_DEVICES 64 /* 最大设备数 */
|
#define PUTTY_MAX_DEVICES 64 /* 最大设备数 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MROBOT_MAX_CUSTOM_COMMANDS
|
#ifndef PUTTY_MAX_CUSTOM_COMMANDS
|
||||||
#define MROBOT_MAX_CUSTOM_COMMANDS 16 /* 最大自定义命令数 */
|
#define PUTTY_MAX_CUSTOM_COMMANDS 16 /* 最大自定义命令数 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MROBOT_CMD_BUFFER_SIZE
|
#ifndef PUTTY_CMD_BUFFER_SIZE
|
||||||
#define MROBOT_CMD_BUFFER_SIZE 128 /* 命令缓冲区大小 */
|
#define PUTTY_CMD_BUFFER_SIZE 128 /* 命令缓冲区大小 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MROBOT_OUTPUT_BUFFER_SIZE
|
#ifndef PUTTY_OUTPUT_BUFFER_SIZE
|
||||||
#define MROBOT_OUTPUT_BUFFER_SIZE 512 /* 输出缓冲区大小 */
|
#define PUTTY_OUTPUT_BUFFER_SIZE 512 /* 输出缓冲区大小 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MROBOT_DEVICE_NAME_LEN
|
#ifndef PUTTY_DEVICE_NAME_LEN
|
||||||
#define MROBOT_DEVICE_NAME_LEN 32 /* 设备名最大长度 */
|
#define PUTTY_DEVICE_NAME_LEN 32 /* 设备名最大长度 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MROBOT_PATH_MAX_LEN
|
#ifndef PUTTY_PATH_MAX_LEN
|
||||||
#define MROBOT_PATH_MAX_LEN 64 /* 路径最大长度 */
|
#define PUTTY_PATH_MAX_LEN 64 /* 路径最大长度 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MROBOT_HTOP_REFRESH_MS
|
#ifndef PUTTY_HTOP_REFRESH_MS
|
||||||
#define MROBOT_HTOP_REFRESH_MS 200 /* htop 刷新间隔 (ms) */
|
#define PUTTY_HTOP_REFRESH_MS 200 /* htop 刷新间隔 (ms) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MROBOT_USER_NAME
|
#ifndef PUTTY_USER_NAME
|
||||||
#define MROBOT_USER_NAME "root" /* CLI 用户名 */
|
#define PUTTY_USER_NAME "root" /* CLI 用户名 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MROBOT_HOST_NAME
|
#ifndef PUTTY_HOST_NAME
|
||||||
#define MROBOT_HOST_NAME "MRobot" /* CLI 主机名 */
|
#define PUTTY_HOST_NAME "MRobot" /* CLI 主机名 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Error codes -------------------------------------------------------------- */
|
/* Error codes -------------------------------------------------------------- */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MROBOT_OK = 0, /* 成功 */
|
PUTTY_OK = 0, /* 成功 */
|
||||||
MROBOT_ERR_FULL = -1, /* 容量已满 */
|
PUTTY_ERR_FULL = -1, /* 容量已满 */
|
||||||
MROBOT_ERR_NULL_PTR = -2, /* 空指针 */
|
PUTTY_ERR_NULL_PTR = -2, /* 空指针 */
|
||||||
MROBOT_ERR_INVALID_ARG = -3, /* 无效参数 */
|
PUTTY_ERR_INVALID_ARG = -3, /* 无效参数 */
|
||||||
MROBOT_ERR_NOT_FOUND = -4, /* 未找到 */
|
PUTTY_ERR_NOT_FOUND = -4, /* 未找到 */
|
||||||
MROBOT_ERR_ALLOC = -5, /* 内存分配失败 */
|
PUTTY_ERR_ALLOC = -5, /* 内存分配失败 */
|
||||||
MROBOT_ERR_BUSY = -6, /* 设备忙 */
|
PUTTY_ERR_BUSY = -6, /* 设备忙 */
|
||||||
MROBOT_ERR_NOT_INIT = -7, /* 未初始化 */
|
PUTTY_ERR_NOT_INIT = -7, /* 未初始化 */
|
||||||
} MRobot_Error_t;
|
} Putty_Error_t;
|
||||||
|
|
||||||
/* CLI 运行状态 */
|
/* CLI 运行状态 */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MROBOT_STATE_IDLE, /* 空闲状态,等待输入 */
|
PUTTY_STATE_IDLE, /* 空闲状态,等待输入 */
|
||||||
MROBOT_STATE_HTOP, /* htop 模式 */
|
PUTTY_STATE_HTOP, /* htop 模式 */
|
||||||
MROBOT_STATE_PROCESSING, /* 正在处理命令 */
|
PUTTY_STATE_PROCESSING, /* 正在处理命令 */
|
||||||
} MRobot_State_t;
|
} Putty_State_t;
|
||||||
|
|
||||||
/* Callback types ----------------------------------------------------------- */
|
/* Callback types ----------------------------------------------------------- */
|
||||||
|
|
||||||
@ -180,54 +180,54 @@ typedef enum {
|
|||||||
* @return 实际写入的字节数
|
* @return 实际写入的字节数
|
||||||
* @note 用户需要自行实现此函数来格式化设备数据
|
* @note 用户需要自行实现此函数来格式化设备数据
|
||||||
*/
|
*/
|
||||||
typedef int (*MRobot_PrintCallback_t)(const void *device_data, char *buffer, size_t buffer_size);
|
typedef int (*Putty_PrintCallback_t)(const void *device_data, char *buffer, size_t buffer_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 命令处理回调函数类型(与 FreeRTOS CLI 兼容)
|
* @brief 命令处理回调函数类型(与 FreeRTOS CLI 兼容)
|
||||||
*/
|
*/
|
||||||
typedef long (*MRobot_CommandCallback_t)(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString);
|
typedef long (*Putty_CommandCallback_t)(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString);
|
||||||
|
|
||||||
/* Device structure --------------------------------------------------------- */
|
/* Device structure --------------------------------------------------------- */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char name[MROBOT_DEVICE_NAME_LEN]; /* 设备名称 */
|
char name[PUTTY_DEVICE_NAME_LEN]; /* 设备名称 */
|
||||||
void *data; /* 用户设备数据指针 */
|
void *data; /* 用户设备数据指针 */
|
||||||
MRobot_PrintCallback_t print_cb; /* 用户打印回调函数 */
|
Putty_PrintCallback_t print_cb; /* 用户打印回调函数 */
|
||||||
} MRobot_Device_t;
|
} Putty_Device_t;
|
||||||
|
|
||||||
/* Public API --------------------------------------------------------------- */
|
/* Public API --------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 初始化 MRobot CLI 系统
|
* @brief 初始化 Putty CLI 系统
|
||||||
* @note 必须在 FreeRTOS 调度器启动后调用
|
* @note 必须在 FreeRTOS 调度器启动后调用
|
||||||
*/
|
*/
|
||||||
void MRobot_Init(void);
|
void Putty_Init(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 反初始化 MRobot CLI 系统,释放资源
|
* @brief 反初始化 Putty CLI 系统,释放资源
|
||||||
*/
|
*/
|
||||||
void MRobot_DeInit(void);
|
void Putty_DeInit(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 获取当前 CLI 状态
|
* @brief 获取当前 CLI 状态
|
||||||
* @return MRobot_State_t 当前状态
|
* @return Putty_State_t 当前状态
|
||||||
*/
|
*/
|
||||||
MRobot_State_t MRobot_GetState(void);
|
Putty_State_t Putty_GetState(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 注册设备到 MRobot 系统
|
* @brief 注册设备到 Putty 系统
|
||||||
* @param name 设备名称(会被截断到 MROBOT_DEVICE_NAME_LEN-1)
|
* @param name 设备名称(会被截断到 PUTTY_DEVICE_NAME_LEN-1)
|
||||||
* @param data 设备数据指针(不能为 NULL)
|
* @param data 设备数据指针(不能为 NULL)
|
||||||
* @param print_cb 打印回调函数(可为 NULL,但无法用 show 命令查看)
|
* @param print_cb 打印回调函数(可为 NULL,但无法用 show 命令查看)
|
||||||
* @return MRobot_Error_t 错误码
|
* @return Putty_Error_t 错误码
|
||||||
*/
|
*/
|
||||||
MRobot_Error_t MRobot_RegisterDevice(const char *name, void *data, MRobot_PrintCallback_t print_cb);
|
Putty_Error_t Putty_RegisterDevice(const char *name, void *data, Putty_PrintCallback_t print_cb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 注销设备
|
* @brief 注销设备
|
||||||
* @param name 设备名称
|
* @param name 设备名称
|
||||||
* @return MRobot_Error_t 错误码
|
* @return Putty_Error_t 错误码
|
||||||
*/
|
*/
|
||||||
MRobot_Error_t MRobot_UnregisterDevice(const char *name);
|
Putty_Error_t Putty_UnregisterDevice(const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 注册自定义命令
|
* @brief 注册自定义命令
|
||||||
@ -235,29 +235,29 @@ MRobot_Error_t MRobot_UnregisterDevice(const char *name);
|
|||||||
* @param help_text 帮助文本
|
* @param help_text 帮助文本
|
||||||
* @param callback 命令回调函数
|
* @param callback 命令回调函数
|
||||||
* @param param_count 参数个数(-1 表示可变参数)
|
* @param param_count 参数个数(-1 表示可变参数)
|
||||||
* @return MRobot_Error_t 错误码
|
* @return Putty_Error_t 错误码
|
||||||
*/
|
*/
|
||||||
MRobot_Error_t MRobot_RegisterCommand(const char *command, const char *help_text,
|
Putty_Error_t Putty_RegisterCommand(const char *command, const char *help_text,
|
||||||
MRobot_CommandCallback_t callback, int8_t param_count);
|
Putty_CommandCallback_t callback, int8_t param_count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 获取已注册设备数量
|
* @brief 获取已注册设备数量
|
||||||
* @return 设备数量
|
* @return 设备数量
|
||||||
*/
|
*/
|
||||||
uint8_t MRobot_GetDeviceCount(void);
|
uint8_t Putty_GetDeviceCount(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 根据名称查找设备
|
* @brief 根据名称查找设备
|
||||||
* @param name 设备名称
|
* @param name 设备名称
|
||||||
* @return 设备指针,未找到返回 NULL
|
* @return 设备指针,未找到返回 NULL
|
||||||
*/
|
*/
|
||||||
const MRobot_Device_t *MRobot_FindDevice(const char *name);
|
const Putty_Device_t *Putty_FindDevice(const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MRobot 主循环,在 CLI 任务中周期性调用
|
* @brief Putty 主循环,在 CLI 任务中周期性调用
|
||||||
* @note 建议调用周期 10ms
|
* @note 建议调用周期 10ms
|
||||||
*/
|
*/
|
||||||
void MRobot_Run(void);
|
void Putty_Run(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 格式化输出到 CLI 终端(线程安全,支持浮点数)
|
* @brief 格式化输出到 CLI 终端(线程安全,支持浮点数)
|
||||||
@ -273,23 +273,23 @@ void MRobot_Run(void);
|
|||||||
* - %% : 百分号
|
* - %% : 百分号
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* MRobot_Printf("Euler: R=%.2f P=%.2f Y=%.2f\\r\\n", roll, pitch, yaw);
|
* Putty_Printf("Euler: R=%.2f P=%.2f Y=%.2f\\r\\n", roll, pitch, yaw);
|
||||||
*/
|
*/
|
||||||
int MRobot_Printf(const char *fmt, ...);
|
int Putty_Printf(const char *fmt, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 格式化到缓冲区(用于回调函数,支持浮点数)
|
* @brief 格式化到缓冲区(用于回调函数,支持浮点数)
|
||||||
* @note 格式说明符同 MRobot_Printf
|
* @note 格式说明符同 Putty_Printf
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* static int print_imu(const void *data, char *buf, size_t size) {
|
* static int print_imu(const void *data, char *buf, size_t size) {
|
||||||
* const BMI088_t *imu = (const BMI088_t *)data;
|
* const BMI088_t *imu = (const BMI088_t *)data;
|
||||||
* return MRobot_Snprintf(buf, size,
|
* return Putty_Snprintf(buf, size,
|
||||||
* " Accel: X=%.3f Y=%.3f Z=%.3f\\r\\n",
|
* " Accel: X=%.3f Y=%.3f Z=%.3f\\r\\n",
|
||||||
* imu->accl.x, imu->accl.y, imu->accl.z);
|
* imu->accl.x, imu->accl.y, imu->accl.z);
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
int MRobot_Snprintf(char *buf, size_t size, const char *fmt, ...);
|
int Putty_Snprintf(char *buf, size_t size, const char *fmt, ...);
|
||||||
|
|
||||||
/* Utility functions -------------------------------------------------------- */
|
/* Utility functions -------------------------------------------------------- */
|
||||||
|
|
||||||
@ -303,10 +303,10 @@ int MRobot_Snprintf(char *buf, size_t size, const char *fmt, ...);
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* char buf[16];
|
* char buf[16];
|
||||||
* MRobot_FormatFloat(buf, sizeof(buf), 3.14159f, 2); // "3.14"
|
* Putty_FormatFloat(buf, sizeof(buf), 3.14159f, 2); // "3.14"
|
||||||
* MRobot_FormatFloat(buf, sizeof(buf), -0.001f, 4); // "-0.0010"
|
* Putty_FormatFloat(buf, sizeof(buf), -0.001f, 4); // "-0.0010"
|
||||||
*/
|
*/
|
||||||
int MRobot_FormatFloat(char *buf, size_t size, float val, int precision);
|
int Putty_FormatFloat(char *buf, size_t size, float val, int precision);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user