Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ jobs:
bazel: 4.2.2
cppstd: c++14
# Run Bazel 6.5.0 on all compiler versions.
- os: ubuntu-latest
#
# Ubuntu 26.04 (ubuntu-latest) does not provide GCC 9, GCC 10, or Clang 14, so
# pin those builds to Ubuntu 24.04.
- os: ubuntu-24.04
compiler: gcc
version: 9
bazel: 6.5.0
- os: ubuntu-latest
- os: ubuntu-24.04
compiler: gcc
version: 10
bazel: 6.5.0
- os: ubuntu-latest
- os: ubuntu-24.04
compiler: clang
version: 14
bazel: 6.5.0
Expand Down Expand Up @@ -102,7 +105,7 @@ jobs:
version: ${{ matrix.bazel }}

- name: Setup Environment (Linux)
if: matrix.os == 'ubuntu-latest'
if: startsWith(matrix.os, 'ubuntu')
run: |
# Just for Github action builds set USE_BAZEL_VERSION to override the
# .bazelversion file so we can test different Bazel versions even though
Expand Down Expand Up @@ -188,13 +191,15 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
# Ubuntu 26.04 (ubuntu-latest) does not provide GCC 9, GCC 10, or Clang 14, so
# pin those builds to Ubuntu 24.04.
- os: ubuntu-24.04
compiler: gcc
version: 9
- os: ubuntu-latest
- os: ubuntu-24.04
compiler: gcc
version: 10
- os: ubuntu-latest
- os: ubuntu-24.04
compiler: clang
version: 14
- os: windows-latest
Expand All @@ -221,7 +226,7 @@ jobs:
echo "EXT=.exe" >> $GITHUB_ENV

- name: Setup Environment (Linux)
if: matrix.os == 'ubuntu-latest'
if: startsWith(matrix.os, 'ubuntu')
run: |
if [[ "${{ matrix.compiler }}" == "gcc" ]]; then
# Some time between 2/9/2026 and 2/16/2026, the apt packages for
Expand Down Expand Up @@ -266,14 +271,14 @@ jobs:
cmake -DCMAKE_INSTALL_PREFIX=install ..

- name: Build Library And Examples (Linux)
if: matrix.os == 'ubuntu-latest'
if: startsWith(matrix.os, 'ubuntu')
run: |
cd cmake_build
make
make install

- name: Install Test Files (Linux)
if: matrix.os == 'ubuntu-latest'
if: startsWith(matrix.os, 'ubuntu')
run: |
mkdir test
cp cmake_build/examples/message_decode/message_decode ./test/
Expand All @@ -297,7 +302,7 @@ jobs:
cp examples/message_decode/example_data.p1log ./test/

- name: Build External Project Example (CMake, Linux)
if: matrix.os == 'ubuntu-latest'
if: startsWith(matrix.os, 'ubuntu')
run: |
mkdir examples/external_cmake_project/build
cd examples/external_cmake_project/build
Expand Down Expand Up @@ -366,7 +371,9 @@ jobs:
# Run Python unit tests.
test_python:
name: Python Unit Tests
runs-on: ubuntu-latest
# Ubuntu 26.04 (ubuntu-latest) does not provide Python 3.8 or 3.9 for actions/setup-python, so pin these tests
# to Ubuntu 24.04.
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
Expand Down
18 changes: 12 additions & 6 deletions python/fusion_engine_client/messages/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ class MessageHeader:
SYNC = bytes((SYNC0, SYNC1))

_FORMAT = '<BBHIBBHIII'
_SIZE: int = struct.calcsize(_FORMAT)
_STRUCT = struct.Struct(_FORMAT)
_SIZE: int = _STRUCT.size

# The header layout as a numpy structured type, matching _FORMAT, for reading many headers at once.
_NUMPY_DTYPE = np.dtype([('sync0', 'u1'), ('sync1', 'u1'), ('reserved', '<u2'), ('crc', '<u4'),
Expand All @@ -258,6 +259,10 @@ class MessageHeader:
# The offset of the payload_size_bytes field within the header.
PAYLOAD_SIZE_OFFSET_BYTES = 16

# The offset within the header at which the CRC calculation starts: the protocol_version field, just after the CRC
# field. The CRC covers everything from there to the end of the payload.
CRC_START_OFFSET_BYTES = 8

_MAX_EXPECTED_SIZE_BYTES = (1 << 24)

def __init__(self, message_type: MessageType = MessageType.INVALID):
Expand Down Expand Up @@ -286,7 +291,7 @@ def calculate_crc(self, payload: bytes):
# protocol_version, then add the payload into the CRC.
self.payload_size_bytes = len(payload)
header_buffer = self.pack()
self.crc = crc32(header_buffer[8:])
self.crc = crc32(header_buffer[MessageHeader.CRC_START_OFFSET_BYTES:])
self.crc = crc32(payload, self.crc)
return self.crc

Expand All @@ -297,7 +302,8 @@ def validate_crc(self, buffer: bytes, offset: int = 0):
(self.payload_size_bytes, MessageHeader._MAX_EXPECTED_SIZE_BYTES))

message_size_bytes = MessageHeader._SIZE + self.payload_size_bytes
crc = crc32(buffer[(offset + 8):(offset + message_size_bytes)])
# The memoryview avoids copying the message out of the buffer just to compute its CRC.
crc = crc32(memoryview(buffer)[(offset + MessageHeader.CRC_START_OFFSET_BYTES):(offset + message_size_bytes)])
if crc != self.crc:
raise ValueError('CRC mismatch. [type=%s, payload_size=%d B, expected=0x%08x, computed=0x%08x]' %
(self.get_type_string(), self.payload_size_bytes, self.crc, crc))
Expand Down Expand Up @@ -332,11 +338,11 @@ def pack(self, buffer: bytes = None, offset: int = 0, payload: bytes = None, ret
self.message_version, int(self.message_type), self.sequence_number, self.payload_size_bytes,
int(self.source_identifier))
if buffer is None:
buffer = struct.pack(MessageHeader._FORMAT, *args)
buffer = MessageHeader._STRUCT.pack(*args)
if payload is not None:
buffer += payload
else:
struct.pack_into(MessageHeader._FORMAT, buffer, offset, *args)
MessageHeader._STRUCT.pack_into(buffer, offset, *args)
if payload is not None:
offset += MessageHeader._SIZE
buffer[offset:offset + len(payload)] = payload
Expand Down Expand Up @@ -368,7 +374,7 @@ def unpack(self, buffer: bytes, offset: int = 0, validate_sync: bool = False, va
self.crc, self.protocol_version,
self.message_version, message_type_int,
self.sequence_number, self.payload_size_bytes, self.source_identifier) = \
struct.unpack_from(MessageHeader._FORMAT, buffer, offset)
MessageHeader._STRUCT.unpack_from(buffer, offset)

if validate_sync and (sync0 != MessageHeader.SYNC0 or sync1 != MessageHeader.SYNC1):
raise ValueError('Received invalid sync bytes. [sync0=0x%02x, sync1=0x%02x]' % (sync0, sync1))
Expand Down
92 changes: 47 additions & 45 deletions python/fusion_engine_client/messages/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class ROSPoseMessage(MessagePayload):
MESSAGE_VERSION = 0

_FORMAT = '< 3d 4d'
_SIZE: int = struct.calcsize(_FORMAT)
_STRUCT = struct.Struct(_FORMAT)
_SIZE: int = _STRUCT.size

def __init__(self):
# The time of the message, in P1 time (beginning at power-on)
Expand All @@ -44,9 +45,10 @@ def pack(self, buffer: bytes = None, offset: int = 0, return_buffer: bool = True

offset += self.p1_time.pack(buffer, offset, return_buffer=False)

struct.pack_into(ROSPoseMessage._FORMAT, buffer, offset,
self.position_rel_m[0], self.position_rel_m[1], self.position_rel_m[2],
self.orientation[0], self.orientation[1], self.orientation[2], self.orientation[3])
ROSPoseMessage._STRUCT.pack_into(
buffer, offset,
self.position_rel_m[0], self.position_rel_m[1], self.position_rel_m[2],
self.orientation[0], self.orientation[1], self.orientation[2], self.orientation[3])

if return_buffer:
return buffer
Expand All @@ -59,8 +61,7 @@ def unpack(self, buffer: bytes, offset: int = 0, message_version: int = MessageP
offset += self.p1_time.unpack(buffer, offset)
(self.position_rel_m[0], self.position_rel_m[1], self.position_rel_m[2],
self.orientation[0], self.orientation[1], self.orientation[2], self.orientation[3]) = \
struct.unpack_from(ROSPoseMessage._FORMAT,
buffer=buffer, offset=offset)
ROSPoseMessage._STRUCT.unpack_from(buffer=buffer, offset=offset)
offset += ROSPoseMessage._SIZE
return offset - initial_offset

Expand Down Expand Up @@ -95,7 +96,8 @@ class ROSGPSFixMessage(MessagePayload):
MESSAGE_VERSION = 0

_FORMAT = '< ddd ddd ddd d ddddd dddddddddd 9d B 3B'
_SIZE: int = struct.calcsize(_FORMAT)
_STRUCT = struct.Struct(_FORMAT)
_SIZE: int = _STRUCT.size

def __init__(self):
self.p1_time = Timestamp()
Expand Down Expand Up @@ -167,37 +169,38 @@ def pack(self, buffer: bytes = None, offset: int = 0, return_buffer: bool = True

offset += self.p1_time.pack(buffer, offset, return_buffer=False)

struct.pack_into(ROSGPSFixMessage._FORMAT, buffer, offset,
self.latitude_deg,
self.longitude_deg,
self.altitude_m,
self.track_deg,
self.speed_mps,
self.climb_mps,
self.pitch_deg,
self.roll_deg,
self.dip_deg,
self.gps_time,
self.gdop,
self.pdop,
self.hdop,
self.vdop,
self.tdop,
self.err_3d_m,
self.err_horiz_m,
self.err_vert_m,
self.err_track_deg,
self.err_speed_mps,
self.err_climb_mps,
self.err_time_sec,
self.err_pitch_deg,
self.err_roll_deg,
self.err_dip_deg,
self.position_covariance_m2[0], self.position_covariance_m2[1], self.position_covariance_m2[2],
self.position_covariance_m2[3], self.position_covariance_m2[4], self.position_covariance_m2[5],
self.position_covariance_m2[6], self.position_covariance_m2[7], self.position_covariance_m2[8],
self.position_covariance_type,
self.reserved[0], self.reserved[1], self.reserved[2])
ROSGPSFixMessage._STRUCT.pack_into(
buffer, offset,
self.latitude_deg,
self.longitude_deg,
self.altitude_m,
self.track_deg,
self.speed_mps,
self.climb_mps,
self.pitch_deg,
self.roll_deg,
self.dip_deg,
self.gps_time,
self.gdop,
self.pdop,
self.hdop,
self.vdop,
self.tdop,
self.err_3d_m,
self.err_horiz_m,
self.err_vert_m,
self.err_track_deg,
self.err_speed_mps,
self.err_climb_mps,
self.err_time_sec,
self.err_pitch_deg,
self.err_roll_deg,
self.err_dip_deg,
self.position_covariance_m2[0], self.position_covariance_m2[1], self.position_covariance_m2[2],
self.position_covariance_m2[3], self.position_covariance_m2[4], self.position_covariance_m2[5],
self.position_covariance_m2[6], self.position_covariance_m2[7], self.position_covariance_m2[8],
self.position_covariance_type,
self.reserved[0], self.reserved[1], self.reserved[2])

if return_buffer:
return buffer
Expand Down Expand Up @@ -238,8 +241,7 @@ def unpack(self, buffer: bytes, offset: int = 0, message_version: int = MessageP
self.position_covariance_m2[6], self.position_covariance_m2[7], self.position_covariance_m2[8],
self.position_covariance_type,
self.reserved[0], self.reserved[1], self.reserved[2]) = \
struct.unpack_from(ROSGPSFixMessage._FORMAT,
buffer=buffer, offset=offset)
ROSGPSFixMessage._STRUCT.unpack_from(buffer=buffer, offset=offset)
offset += ROSGPSFixMessage._SIZE
return offset - initial_offset

Expand Down Expand Up @@ -267,7 +269,8 @@ class ROSIMUMessage(MessagePayload):
MESSAGE_VERSION = 0

_FORMAT = '< 4d 9d 3d 9d 3d 9d'
_SIZE: int = struct.calcsize(_FORMAT)
_STRUCT = struct.Struct(_FORMAT)
_SIZE: int = _STRUCT.size

def __init__(self):
self.p1_time = Timestamp()
Expand Down Expand Up @@ -296,8 +299,8 @@ def pack(self, buffer: bytes = None, offset: int = 0, return_buffer: bool = True

offset += self.p1_time.pack(buffer, offset, return_buffer=False)

struct.pack_into(
ROSIMUMessage._FORMAT, buffer, offset,
ROSIMUMessage._STRUCT.pack_into(
buffer, offset,
self.orientation[0], self.orientation[1], self.orientation[2], self.orientation[3],
self.orientation_covariance[0], self.orientation_covariance[1], self.orientation_covariance[2],
self.orientation_covariance[3], self.orientation_covariance[4], self.orientation_covariance[5],
Expand Down Expand Up @@ -334,8 +337,7 @@ def unpack(self, buffer: bytes, offset: int = 0, message_version: int = MessageP
self.acceleration_covariance[3], self.acceleration_covariance[4], self.acceleration_covariance[5],
self.acceleration_covariance[6], self.acceleration_covariance[7], self.acceleration_covariance[8],
) = \
struct.unpack_from(ROSIMUMessage._FORMAT,
buffer=buffer, offset=offset)
ROSIMUMessage._STRUCT.unpack_from(buffer=buffer, offset=offset)
offset += ROSIMUMessage._SIZE
return offset - initial_offset

Expand Down
9 changes: 5 additions & 4 deletions python/fusion_engine_client/messages/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class Timestamp:
_INVALID = 0xFFFFFFFF

_FORMAT = '<II'
_SIZE: int = struct.calcsize(_FORMAT)
_STRUCT = struct.Struct(_FORMAT)
_SIZE: int = _STRUCT.size

def __init__(self, time_sec=math.nan):
self.seconds = float(time_sec)
Expand Down Expand Up @@ -104,18 +105,18 @@ def pack(self, buffer: bytes = None, offset: int = 0, return_buffer: bool = Fals
frac_part_ns = int((self.seconds - int_part) * 1e9)

if buffer is None:
buffer = struct.pack(Timestamp._FORMAT, int_part, frac_part_ns)
buffer = Timestamp._STRUCT.pack(int_part, frac_part_ns)
else:
args = (int_part, frac_part_ns)
struct.pack_into(Timestamp._FORMAT, buffer, offset, *args)
Timestamp._STRUCT.pack_into(buffer, offset, *args)

if return_buffer:
return buffer
else:
return self.calcsize()

def unpack(self, buffer: bytes, offset: int = 0) -> int:
(int_part, frac_part_ns) = struct.unpack_from(Timestamp._FORMAT, buffer, offset)
(int_part, frac_part_ns) = Timestamp._STRUCT.unpack_from(buffer, offset)
if int_part == Timestamp._INVALID or frac_part_ns == Timestamp._INVALID:
self.seconds = math.nan
else:
Expand Down
Loading
Loading