【类 型】:feat 写入参数 功能
【原 因】: 【过 程】: 【影 响】:
This commit is contained in:
parent
dcbd67fb7f
commit
798be02055
@ -781,3 +781,30 @@ void FoodCube::sendCommandAck(uint16_t command, uint8_t result)
|
|||||||
// 通过串口发送数据
|
// 通过串口发送数据
|
||||||
SWrite(buf, len, mavlinkSerial);
|
SWrite(buf, len, mavlinkSerial);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 向飞控写入参数
|
||||||
|
* @param param_id 参数名称(例如 "COMPASS_OFS_X")
|
||||||
|
* @param value 参数值(浮点数)
|
||||||
|
*/
|
||||||
|
void FoodCube::setParam(const char *param_id, float value)
|
||||||
|
{
|
||||||
|
mavlink_message_t msg;
|
||||||
|
mavlink_param_set_t param_set;
|
||||||
|
|
||||||
|
// 设置参数
|
||||||
|
param_set.param_value = value;
|
||||||
|
strncpy(param_set.param_id, param_id, sizeof(param_set.param_id));
|
||||||
|
param_set.param_id[sizeof(param_set.param_id) - 1] = '\0'; // 确保字符串以null结尾
|
||||||
|
param_set.target_system = 1; // 目标系统 ID
|
||||||
|
param_set.target_component = 1; // 目标组件 ID
|
||||||
|
|
||||||
|
// 打包参数设置消息
|
||||||
|
mavlink_msg_param_set_encode(MAVLINK_SYSTEM_ID, MAVLINK_COMPONENT_ID, &msg, ¶m_set);
|
||||||
|
|
||||||
|
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
|
||||||
|
int len = mavlink_msg_to_send_buffer(buf, &msg);
|
||||||
|
|
||||||
|
// 通过串口发送数据
|
||||||
|
SWrite(buf, len, mavlinkSerial);
|
||||||
|
}
|
@ -76,6 +76,7 @@ public:
|
|||||||
|
|
||||||
void mav_send_command(mavlink_command_long_t &msg_cmd);
|
void mav_send_command(mavlink_command_long_t &msg_cmd);
|
||||||
void sendCommandAck(uint16_t command, uint8_t result);
|
void sendCommandAck(uint16_t command, uint8_t result);
|
||||||
|
void setParam(const char *param_id, float value);
|
||||||
|
|
||||||
/*云台相机控制*/
|
/*云台相机控制*/
|
||||||
void udpSendToCamera(uint8_t *p_command, uint32_t len);
|
void udpSendToCamera(uint8_t *p_command, uint32_t len);
|
||||||
|
@ -213,6 +213,19 @@ void mqtt_receiveCallback(char *topic, byte *payload, unsigned int length)
|
|||||||
fc.sendCommandAck(1, 1); // 摆好校准
|
fc.sendCommandAck(1, 1); // 摆好校准
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (key == "setParam")
|
||||||
|
{
|
||||||
|
String todoJson = value; // 转换值
|
||||||
|
/* json 反序列化 */
|
||||||
|
DynamicJsonDocument doc(128);
|
||||||
|
deserializeJson(doc, todoJson);
|
||||||
|
JsonObject obj = doc.as<JsonObject>();
|
||||||
|
// 提取参数
|
||||||
|
const char *item = obj["item"]; // 获取 item 字段
|
||||||
|
float paramValue = obj["value"]; // 获取 value 字段
|
||||||
|
// 调用 setParam 函数
|
||||||
|
fc.setParam(item, paramValue);
|
||||||
|
}
|
||||||
else if (key == "refreshRequest")
|
else if (key == "refreshRequest")
|
||||||
{
|
{
|
||||||
refreshRequest(); // 刷新各种请求
|
refreshRequest(); // 刷新各种请求
|
||||||
|
Loading…
Reference in New Issue
Block a user