添加了不同等级的日志

This commit is contained in:
NeoZng
2023-03-19 11:11:40 +08:00
parent 6f7bf8e9d7
commit eefc0883ed
11 changed files with 53 additions and 26 deletions

6
.vscode/launch.json vendored
View File

@@ -19,8 +19,10 @@
"configFiles": [ "configFiles": [
"openocd_dap.cfg", // 配置文件已经在根目录提供,若要修改以此类推,openocd的路径下的share/scripts中有各种写好的配置文件 "openocd_dap.cfg", // 配置文件已经在根目录提供,若要修改以此类推,openocd的路径下的share/scripts中有各种写好的配置文件
], ],
"runToEntryPoint": "main" // 调试时在main函数入口停下 "runToEntryPoint": "main", // 调试时在main函数入口停下
//"preLaunchTask": "build task",//先运行Build任务编译项目,取消注释即可使用 //"preLaunchTask": "build task",//先运行Build任务编译项目,取消注释即可使用
//"preLaunchTask": "log", // 调试时同时开启RTT viewer窗口
// 若想要在调试前编译并且打开log,可只使用log的prelaunch task并为log任务添加depends on依赖
}, },
// 使用j-link进行调试时的参考配置 // 使用j-link进行调试时的参考配置
{ {
@@ -37,6 +39,8 @@
"svdFile": "STM32F407.svd", "svdFile": "STM32F407.svd",
"rtos": "FreeRTOS", "rtos": "FreeRTOS",
// "preLaunchTask": "build task",//先运行Build任务,取消注释即可使用 // "preLaunchTask": "build task",//先运行Build任务,取消注释即可使用
//"preLaunchTask": "log", // 调试时同时开启RTT viewer窗口
// 若想要在调试前编译并且打开log,可只使用log的prelaunch task并为log任务添加depends on依赖
}, },
], ],
} }

3
.vscode/tasks.json vendored
View File

@@ -36,6 +36,9 @@
"command":"JlinkRTTClient", "command":"JlinkRTTClient",
"args": [], "args": [],
"problemMatcher": [], "problemMatcher": [],
// "dependsOn":[
// "build task", // 可以添加多个.
// ]
} }
] ]
} }

View File

@@ -17,6 +17,7 @@
#include "super_cap.h" #include "super_cap.h"
#include "message_center.h" #include "message_center.h"
// referee需要移动到module层
///////////////////////// /////////////////////////
#include "referee.h" #include "referee.h"
#include "rm_referee.h" #include "rm_referee.h"

View File

@@ -1,5 +1,7 @@
// app
#include "robot_def.h" #include "robot_def.h"
#include "robot_cmd.h" #include "robot_cmd.h"
// module
#include "remote_control.h" #include "remote_control.h"
#include "ins_task.h" #include "ins_task.h"
#include "master_process.h" #include "master_process.h"

View File

@@ -1,5 +1,6 @@
#include "gimbal.h" #include "gimbal.h"
#include "robot_def.h" #include "robot_def.h"
#include "dji_motor.h" #include "dji_motor.h"
#include "ins_task.h" #include "ins_task.h"
#include "message_center.h" #include "message_center.h"

View File

@@ -1,5 +1,6 @@
#include "shoot.h" #include "shoot.h"
#include "robot_def.h" #include "robot_def.h"
#include "dji_motor.h" #include "dji_motor.h"
#include "message_center.h" #include "message_center.h"
#include "bsp_dwt.h" #include "bsp_dwt.h"

View File

@@ -6,6 +6,7 @@
/* can instance ptrs storage, used for recv callback */ /* can instance ptrs storage, used for recv callback */
// 在CAN产生接收中断会遍历数组,选出hcan和rxid与发生中断的实例相同的那个,调用其回调函数 // 在CAN产生接收中断会遍历数组,选出hcan和rxid与发生中断的实例相同的那个,调用其回调函数
// @todo: 后续为每个CAN总线单独添加一个can_instance指针数组,提高回调查找的性能
static CANInstance *can_instance[CAN_MX_REGISTER_CNT] = {NULL}; static CANInstance *can_instance[CAN_MX_REGISTER_CNT] = {NULL};
static uint8_t idx; // 全局CAN实例索引,每次有新的模块注册会自增 static uint8_t idx; // 全局CAN实例索引,每次有新的模块注册会自增

View File

@@ -4,7 +4,6 @@
#include "SEGGER_RTT_Conf.h" #include "SEGGER_RTT_Conf.h"
#include <stdio.h> #include <stdio.h>
#define BUFFER_INDEX 0
void BSPLogInit() void BSPLogInit()
{ {

View File

@@ -1,6 +1,20 @@
#ifndef _BSP_LOG_H #ifndef _BSP_LOG_H
#define _BSP_LOG_H #define _BSP_LOG_H
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
#include <stdio.h>
#define BUFFER_INDEX 0
/**
* @brief 日志系统初始化
*
*/
void BSPLogInit();
/** /**
* @brief 日志功能原型,供下面的LOGI,LOGW,LOGE等使用 * @brief 日志功能原型,供下面的LOGI,LOGW,LOGE等使用
* *
@@ -12,20 +26,24 @@
##__VA_ARGS__, \ ##__VA_ARGS__, \
RTT_CTRL_RESET) RTT_CTRL_RESET)
/*------下面是日志输出的接口--------*/
/* 清屏 */ /* 清屏 */
#define LOG_CLEAR() SEGGER_RTT_WriteString(0, " "RTT_CTRL_CLEAR) #define LOG_CLEAR() SEGGER_RTT_WriteString(0, " "RTT_CTRL_CLEAR)
/* 无颜色日志输出 */ /* 无颜色日志输出 */
#define LOG(format,...) LOG_PROTO("","",format,##__VA_ARGS__) #define LOG(format,...) LOG_PROTO("","",format,##__VA_ARGS__)
/* 有颜色格式日志输出 */ /* 有颜色格式日志输出,建议使用这些宏来输出日志 */
#define LOGINFO(format,...) LOG_PROTO("I: ", RTT_CTRL_TEXT_BRIGHT_GREEN , format, ##__VA_ARGS__) // information level
#define LOGWARNING(format,...) LOG_PROTO("W: ", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__) #define LOGINFO(format,...) LOG_PROTO("I", RTT_CTRL_TEXT_BRIGHT_GREEN , format, ##__VA_ARGS__)
#define LOGERROR(format,...) LOG_PROTO("E: ", RTT_CTRL_TEXT_BRIGHT_RED , format, ##__VA_ARGS__) // warning level
#define LOGWARNING(format,...) LOG_PROTO("W", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__)
// error level
#define LOGERROR(format,...) LOG_PROTO("E", RTT_CTRL_TEXT_BRIGHT_RED , format, ##__VA_ARGS__)
/** /**
* @brief 通过segger RTT打印日志,支持格式化输出,格式化输出的实现参考printf * @brief 通过segger RTT打印日志,支持格式化输出,格式化输出的实现参考printf.
* *
* @param fmt 格式字符串 * @param fmt 格式字符串
* @param ... 参数列表 * @param ... 参数列表

View File

@@ -11,20 +11,21 @@
#include "bsp_usb.h" #include "bsp_usb.h"
static uint8_t *bsp_usb_rx_buffer; // 接收到的数据会被放在这里,buffer size为2028 static uint8_t *bsp_usb_rx_buffer; // 接收到的数据会被放在这里,buffer size为2048
// 注意usb单个数据包(Full speed模式下)最大为64byte,超出可能会出现丢包情况 // 注意usb单个数据包(Full speed模式下)最大为64byte,超出可能会出现丢包情况
// 这是传输完成的回调函数,在usbd_cdc_if.c中被调用 // 这是传输完成的回调函数,在usbd_cdc_if.c中被调用
__weak void USBTransmitCpltCallback(uint32_t len) __weak void USBTransmitCpltCallback(uint32_t len)
{ {
// 本次发送的数据 // 本次发送的数据长度
UNUSED(len); UNUSED(len);
// 传输完成会调用此函数,to do something // 传输完成会调用此函数,to do something
} }
// 这是接收回调函数
__weak void USBReceiveCpltCallback(uint32_t len) __weak void USBReceiveCpltCallback(uint32_t len)
{ {
// 本次接收的数据 // 本次接收的数据长度
UNUSED(len); UNUSED(len);
// 传输完成会调用此函数,to do something // 传输完成会调用此函数,to do something
} }

View File

@@ -1,5 +1,6 @@
#include "dji_motor.h" #include "dji_motor.h"
#include "general_def.h" #include "general_def.h"
#include "bsp_log.h"
static uint8_t idx = 0; // register idx,是该文件的全局电机索引,在注册时使用 static uint8_t idx = 0; // register idx,是该文件的全局电机索引,在注册时使用
@@ -32,16 +33,6 @@ static CANInstance sender_assignment[6] = {
*/ */
static uint8_t sender_enable_flag[6] = {0}; static uint8_t sender_enable_flag[6] = {0};
/**
* @brief 当注册的电机id冲突时,会进入这个函数并提示冲突的ID
* @todo 通过segger jlink 发送日志
*/
static void IDcrash_Handler(uint8_t conflict_motor_idx, uint8_t temp_motor_idx)
{
while (1)
;
}
/** /**
* @brief 根据电调/拨码开关上的ID,根据说明书的默认id分配方式计算发送ID和接收ID, * @brief 根据电调/拨码开关上的ID,根据说明书的默认id分配方式计算发送ID和接收ID,
* 并对电机进行分组以便处理多电机控制命令 * 并对电机进行分组以便处理多电机控制命令
@@ -79,7 +70,10 @@ static void MotorSenderGrouping(DJIMotorInstance *motor, CAN_Init_Config_s *conf
for (size_t i = 0; i < idx; ++i) for (size_t i = 0; i < idx; ++i)
{ {
if (dji_motor_instance[i]->motor_can_instance->can_handle == config->can_handle && dji_motor_instance[i]->motor_can_instance->rx_id == config->rx_id) if (dji_motor_instance[i]->motor_can_instance->can_handle == config->can_handle && dji_motor_instance[i]->motor_can_instance->rx_id == config->rx_id)
IDcrash_Handler(i, idx); {
LOGERROR("[dji_motor] ID crash. Check in debug mode, add dji_motor_instance to watch to get more information."); // 后续可以把id和CAN打印出来
while (1); // 6020的id 1-4和2006/3508的id 5-8会发生冲突(若有注册,即1!5,2!6,3!7,4!8) (1!5!,LTC! (((不是)
}
} }
break; break;
@@ -103,7 +97,10 @@ static void MotorSenderGrouping(DJIMotorInstance *motor, CAN_Init_Config_s *conf
for (size_t i = 0; i < idx; ++i) for (size_t i = 0; i < idx; ++i)
{ {
if (dji_motor_instance[i]->motor_can_instance->can_handle == config->can_handle && dji_motor_instance[i]->motor_can_instance->rx_id == config->rx_id) if (dji_motor_instance[i]->motor_can_instance->can_handle == config->can_handle && dji_motor_instance[i]->motor_can_instance->rx_id == config->rx_id)
IDcrash_Handler(i, idx); {
LOGERROR("[dji_motor] ID crash. Check in debug mode, add dji_motor_instance to watch to get more information.");
while (1); // 6020的id 1-4和2006/3508的id 5-8会发生冲突(若有注册,即1!5,2!6,3!7,4!8)
}
} }
break; break;
@@ -139,7 +136,7 @@ static void DecodeDJIMotor(CANInstance *_instance)
CURRENT_SMOOTH_COEF * (float)((int16_t)(rxbuff[4] << 8 | rxbuff[5])); CURRENT_SMOOTH_COEF * (float)((int16_t)(rxbuff[4] << 8 | rxbuff[5]));
measure->temperate = rxbuff[6]; measure->temperate = rxbuff[6];
// 多圈角度计算,前提是两次采样间电机转过的角度小于180°,高速转动时可能会出现问题,自己画个图就清楚计算过程了 // 多圈角度计算,前提是假设两次采样间电机转过的角度小于180°,自己画个图就清楚计算过程了
if (measure->ecd - measure->last_ecd > 4096) if (measure->ecd - measure->last_ecd > 4096)
measure->total_round--; measure->total_round--;
else if (measure->ecd - measure->last_ecd < -4096) else if (measure->ecd - measure->last_ecd < -4096)
@@ -191,8 +188,7 @@ void DJIMotorChangeFeed(DJIMotorInstance *motor, Closeloop_Type_e loop, Feedback
} }
else else
{ {
while (1) LOGERROR("[dji_motor] loop type error, check memory access and func param");// 检查是否传入了正确的LOOP类型,或发生了指针越界
; // LOOP TYPE ERROR!!!检查是否传入了正确的LOOP类型,或发生了指针越界
} }
} }