mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-10-06 09:02:52 +08:00
refactor(gps): shrink the GPS driver by ~4 KB of flash (#28309)
* refactor(gps): publish RTCM chunks without a per-topic template publish_rtcm_chunks() was instantiated once for Publication and once for PublicationMulti, duplicating the chunking loop. Select the topic inside the loop instead. px4_fmu-v6x_default: gps.cpp.obj 8744 -> 8590 B. Assisted-by: Claude:claude-fable-5 * build(gps): bump GPSDrivers to 2b05a67 Pulls in the flash-diet refactor (#230) and the unsupported-config-key fixes (#225). px4_fmu-v6x_default: -4,200 B from #230, +816 B from #225.
This commit is contained in:
+1
-1
Submodule src/drivers/gps/devices updated: 836094f464...2b05a67361
+19
-26
@@ -1651,16 +1651,19 @@ GPS::publishSatelliteInfo()
|
||||
}
|
||||
}
|
||||
|
||||
// Chunk an RTCM byte stream into a uORB message and publish it. RTCM frames larger than the
|
||||
// message payload are split across consecutive publications (flags LSB = fragmented). Templated
|
||||
// on the publication so the same code serves both the corrections and moving-baseline topics.
|
||||
template <typename PubT>
|
||||
static void publish_rtcm_chunks(PubT &pub, const uint8_t *data, size_t len, hrt_abstime timestamp,
|
||||
uint32_t device_id)
|
||||
// Chunk an RTCM byte stream into uORB messages. Frames larger than the message payload are split
|
||||
// across consecutive publications (flags LSB = fragmented).
|
||||
void
|
||||
GPS::publishRTCMCorrections(uint8_t *data, size_t len)
|
||||
{
|
||||
// If this GPS is a moving base, its RTCM output is moving-baseline data for a rover (not
|
||||
// external corrections). Route it to a dedicated topic so downstream consumers can tell it
|
||||
// apart from fixed-base RTCM.
|
||||
const bool moving_base = _helper && _helper->isMovingBase();
|
||||
|
||||
rtcm_data_s msg{};
|
||||
msg.timestamp = timestamp;
|
||||
msg.device_id = device_id;
|
||||
msg.timestamp = hrt_absolute_time();
|
||||
msg.device_id = get_device_id();
|
||||
|
||||
const size_t capacity = sizeof(msg.data);
|
||||
msg.flags = (len > capacity) ? 1 : 0; // LSB: 1=fragmented
|
||||
@@ -1671,28 +1674,18 @@ static void publish_rtcm_chunks(PubT &pub, const uint8_t *data, size_t len, hrt_
|
||||
const size_t chunk = math::min(len - written, capacity);
|
||||
msg.len = chunk;
|
||||
memcpy(msg.data, &data[written], chunk);
|
||||
pub.publish(msg);
|
||||
|
||||
if (moving_base) {
|
||||
_rtcm_moving_baseline_pub.publish(msg);
|
||||
|
||||
} else {
|
||||
_rtcm_corrections_pub.publish(msg);
|
||||
}
|
||||
|
||||
written += chunk;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GPS::publishRTCMCorrections(uint8_t *data, size_t len)
|
||||
{
|
||||
const hrt_abstime timestamp = hrt_absolute_time();
|
||||
const uint32_t device_id = get_device_id();
|
||||
|
||||
// If this GPS is a moving base, its RTCM output is moving-baseline data for a rover (not
|
||||
// external corrections). Route it to a dedicated topic so downstream consumers can tell it
|
||||
// apart from fixed-base RTCM.
|
||||
if (_helper && _helper->isMovingBase()) {
|
||||
publish_rtcm_chunks(_rtcm_moving_baseline_pub, data, len, timestamp, device_id);
|
||||
|
||||
} else {
|
||||
publish_rtcm_chunks(_rtcm_corrections_pub, data, len, timestamp, device_id);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GPS::publishRelativePosition(sensor_gnss_relative_s &gnss_relative)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user