diff --git a/src/commser.cpp b/src/commser.cpp index 8bbc5cb..7f30cb5 100644 --- a/src/commser.cpp +++ b/src/commser.cpp @@ -795,6 +795,27 @@ void mavlink_receiveCallback(uint8_t c) } break; + case MAVLINK_MSG_ID_ADSB_VEHICLE: // #246 ADSB + { + mavlink_adsb_vehicle_t adsb; + mavlink_msg_adsb_vehicle_decode(&msg, &adsb); + + // 提取并转换数据 + uint32_t icao = adsb.ICAO_address; + float lat = adsb.lat / 1e7; + float lon = adsb.lon / 1e7; + int alt = adsb.altitude; + float heading = adsb.heading / 10.0f; + + // 构建 JSON 字符串 + char jsonString[256]; + snprintf(jsonString, sizeof(jsonString), "{\"icao\":%u,\"lat\":%.7f,\"lon\":%.7f,\"alt\":%d,\"heading\":%.1f}", icao, lat, lon, alt, heading); + + // 发送 MQTT 消息 + fc.pubMQTTmsg("ceshi", jsonString); + } + break; + case MAVLINK_MSG_ID_STATUSTEXT: // #253 文本信息 { char buf[51]; // 定义一个局部缓冲区,大小为 51