This commit is contained in:
2026-03-28 04:56:40 +08:00
parent e8d6bbac42
commit 24340d93f3

View File

@@ -6,7 +6,7 @@
#include <config/setconfig.h> #include <config/setconfig.h>
#include <log.h> #include <log.h>
#include <string> #include <string>
#include <fmt/format.h> #include <cstdio>
// ANGLE_SCALE: 角度单位换算系数。发出的整数 = yaw_deg / ANGLE_SCALE // ANGLE_SCALE: 角度单位换算系数。发出的整数 = yaw_deg / ANGLE_SCALE
// 例: 1.0f → 单位为度; 0.01f → 单位为厘度(精度更高) // 例: 1.0f → 单位为度; 0.01f → 单位为厘度(精度更高)
@@ -33,9 +33,13 @@ static bool sendTarget(Serial &serial, double yaw_deg, double pitch_deg, double
// 格式: "s <yaw_int> <pitch_int> <dist> <shoot_delay> e\n" // 格式: "s <yaw_int> <pitch_int> <dist> <shoot_delay> e\n"
int16_t yaw_tmp = static_cast<int16_t>(yaw_deg / ANGLE_SCALE); int16_t yaw_tmp = static_cast<int16_t>(yaw_deg / ANGLE_SCALE);
int16_t pitch_tmp = static_cast<int16_t>(pitch_deg / ANGLE_SCALE); int16_t pitch_tmp = static_cast<int16_t>(pitch_deg / ANGLE_SCALE);
std::string frame = fmt::format("s {} {} {} {} e\n", yaw_tmp, pitch_tmp, dist, shoot_delay); char buf[64];
std::snprintf(buf, sizeof(buf), "s %d %d %.1f %u e\n",
(int)yaw_tmp, (int)pitch_tmp, dist, (unsigned)shoot_delay);
std::string frame(buf);
return serial.WriteData(reinterpret_cast<const uint8_t*>(frame.data()), frame.size()); return serial.WriteData(reinterpret_cast<const uint8_t*>(frame.data()), frame.size());
// ---- 原始二进制打包(已注释)---- // ---- 原始二进制打包(已注释)----
// static short x_tmp, y_tmp, z_tmp; // static short x_tmp, y_tmp, z_tmp;
// uint8_t buff[10]; // uint8_t buff[10];