From 1d7b31716c896d4bc7fc9c91aad0fe2ae5d26bbf Mon Sep 17 00:00:00 2001 From: air <30444667+sszdot@users.noreply.github.com> Date: Wed, 18 Jun 2025 20:14:39 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=20=20=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9Afix=20=E3=80=90=E5=8E=9F=20=20=E5=9B=A0=E3=80=91?= =?UTF-8?q?=EF=BC=9Amavlink=E6=8B=BF=E7=9A=84=E9=A3=9E=E6=8E=A7=E7=94=B5?= =?UTF-8?q?=E5=8E=8B=20=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E6=98=AFint=5F?= =?UTF-8?q?16=20=E5=8F=AA=E8=83=BD=E6=98=BE=E7=A4=BA65=E4=BC=8F=20?= =?UTF-8?q?=E8=B6=85=E5=87=BA=E4=BC=9A=E6=BA=A2=E5=87=BA=20=E3=80=90?= =?UTF-8?q?=E8=BF=87=20=20=E7=A8=8B=E3=80=91=EF=BC=9A=E6=94=B9=E7=94=A8cas?= =?UTF-8?q?e=20MAVLINK=5FMSG=5FID=5FBATTERY=5FSTATUS:=20//=20#147:=20?= =?UTF-8?q?=E9=AB=98=E5=8E=8B/=E5=A4=9A=E7=94=B5=E8=8A=AF=E7=94=B5?= =?UTF-8?q?=E6=B1=A0=E7=8A=B6=E6=80=81=20=E6=8B=BF=E7=94=B5=E5=8E=8B=20?= =?UTF-8?q?=E3=80=90=E5=BD=B1=20=20=E5=93=8D=E3=80=91=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commser.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/commser.cpp b/src/commser.cpp index bf7cccf..8bbc5cb 100644 --- a/src/commser.cpp +++ b/src/commser.cpp @@ -721,12 +721,12 @@ void mavlink_receiveCallback(uint8_t c) { mavlink_sys_status_t sys_status; // 解构的数据放到这个对象 mavlink_msg_sys_status_decode(&msg, &sys_status); // 解构msg数据 - // 电压 - sprintf(buf, "%.2f", (double)sys_status.voltage_battery / 1000); - if (topicPubMsg[1] != buf) - { // 有更新 则更新数据 - topicPubMsg[1] = buf; - } + // // 电压 + // sprintf(buf, "%.2f", (double)sys_status.voltage_battery / 1000); + // if (topicPubMsg[1] != buf) + // { // 有更新 则更新数据 + // topicPubMsg[1] = buf; + // } // 电流 sprintf(buf, "%.2f", (double)sys_status.current_battery / 100); // 解构中 1=10毫安 所以这里/100 最终单位是A 安培 if (topicPubMsg[2] != buf) @@ -742,6 +742,28 @@ void mavlink_receiveCallback(uint8_t c) } break; + case MAVLINK_MSG_ID_BATTERY_STATUS: // #147: 高压/多电芯电池状态 + { + mavlink_battery_status_t battery_status; + mavlink_msg_battery_status_decode(&msg, &battery_status); + + float total_voltage = 0.0f; + for (int i = 0; i < 10; ++i) + { + if (battery_status.voltages[i] != UINT16_MAX) + { // 65535表示无效 + total_voltage += battery_status.voltages[i] / 1000.0f; // 转换成 V + } + } + + sprintf(buf, "%.2f", total_voltage); // 转成字符串 + if (topicPubMsg[1] != buf) + { + topicPubMsg[1] = buf; // 更新电压显示 + } + } + break; + case MAVLINK_MSG_ID_RAW_IMU: // #27: RAW_IMU { mavlink_raw_imu_t raw_imu;