diff --git a/Inc/board_config.h b/Inc/board_config.h index 39844df..7171109 100644 --- a/Inc/board_config.h +++ b/Inc/board_config.h @@ -27,6 +27,11 @@ // #define EDDY_DRIVE_CURRENT_DETECTION // Eddy Drive Current Detection : Enable #undef EDDY_DRIVE_CURRENT_DETECTION // Eddy Drive Current Detection : Disable +/* >>>>>>>>>>>>>>>>>>>>[COMMAND DEBUG]<<<<<<<<<<<<<<<<<<<< */ + +// #define COM_DEBUG // Enable Command Debug Information +#undef COM_DEBUG // Disable Command Debug Information + /* >>>>>>>>>>>>>>>>>>>>>[LDC1612 DEBUG]<<<<<<<<<<<<<<<<<<<< */ // #define LDC_DEBUG // LDC1612 Driver Debug : Enable @@ -34,12 +39,6 @@ /******************************************************************************/ -#define MCU_CODE 24U - -#define FW_VERSION_MAJOR 1 -#define FW_VERSION_MINOR 1 -#define FW_VERSION_PATCH 3 - /* Dynamic USART Configuration Structure */ typedef struct { uint32_t rcu_usart; diff --git a/Src/command.c b/Src/command.c index 2d035b6..ba13289 100644 --- a/Src/command.c +++ b/Src/command.c @@ -81,6 +81,14 @@ /** @brief 传感器周期上报使能标志 */ volatile bool g_eddy_current_sensor_report_enabled = false; +/* Debug output control */ +#ifdef COM_DEBUG + #include + #define COMMAND_DEBUG(fmt, ...) printf("[COMMAND] " fmt "\n", ##__VA_ARGS__) +#else + #define COMMAND_DEBUG(fmt, ...) +#endif + /** @name 预设响应数据 * @{ */ static const uint8_t s_report_status_ok[] = { 'o', 'k' }; /**< 成功响应数据 */ @@ -197,6 +205,36 @@ static void send_response(uint8_t type, const uint8_t *payload, uint8_t len) */ static inline bool is_dec_digit(uint8_t c) { return (c >= '0' && c <= '9'); } +/** + * @brief 将一个无符号整数转换为字符串并追加到缓冲区。 + * @param value 要转换的数字。 + * @param buffer 指向目标缓冲区的指针,转换后的字符串将写入此处。 + * @return uint8_t 写入的字符数。 + */ +static uint8_t uint_to_str(uint32_t value, char *buffer) { + char temp[10]; // 32位无符号整数最多10位 + int i = 0; + + if (value == 0) { + buffer[0] = '0'; + return 1; + } + + // 将数字逆序转换为字符存入临时数组 + while (value > 0) { + temp[i++] = (char)((value % 10) + '0'); + value /= 10; + } + + // 将逆序的字符串反转并存入目标缓冲区 + uint8_t len = (uint8_t)i; + for (int j = 0; j < len; j++) { + buffer[j] = temp[--i]; + } + + return len; +} + /** * @brief 从缓冲区解析十进制无符号整数。 * @details 从指定位置开始连续读取十进制数字字符,累加构成32位无符号整数。