Skip to content

Commit c274075

Browse files
committed
Add datablock parsing for lin acceleration and angular velocity
1 parent 1e00205 commit c274075

File tree

1 file changed

+94
-1
lines changed

1 file changed

+94
-1
lines changed

modules/telemetry/v1/data_block.py

+94-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def parse(block_subtype: DataBlockSubtype, payload: bytes) -> DataBlock:
105105
DataBlockSubtype.TEMPERATURE: TemperatureDB,
106106
DataBlockSubtype.PRESSURE: PressureDB,
107107
DataBlockSubtype.HUMIDITY: HumidityDB,
108+
DataBlockSubtype.ACCELERATION: LinearAccelerationDB,
109+
DataBlockSubtype.ANGULAR_VELOCITY: AngularVelocityDB,
108110
}
109111

110112
subtype = SUBTYPE_CLASSES.get(block_subtype)
@@ -234,7 +236,7 @@ def __init__(self, mission_time: int, pressure: int) -> None:
234236
Constructs a pressure data block.
235237
236238
Args:
237-
mission_time: The mission time the altitude was measured at in milliseconds since launch.
239+
mission_time: The mission time the pressure was measured at in milliseconds since launch.
238240
pressure: The pressure in millibars.
239241
240242
"""
@@ -307,6 +309,93 @@ def __iter__(self):
307309
yield "mission_time", self.mission_time
308310
yield "percentage", round(self.humidity / 100)
309311

312+
class LinearAccelerationDB(DataBlock):
313+
"""Represents a linear acceleration data block"""
314+
315+
def __init__(self, mission_time: int, x_axis: int, y_axis: int, z_axis: int) -> None:
316+
"""
317+
Constructus a linear acceleration data block.
318+
319+
Args:
320+
mission_time: The mission time the linear acceleration was measured in milliseconds since launch.
321+
x_axis: The acceleration about the x axis in meters per second squared.
322+
y_axis: The acceleration about the y axis in meters per second squared.
323+
z_axis: The acceleration about the z axis in meters per second squared.
324+
325+
"""
326+
super().__init__(mission_time)
327+
self.x_axis: int = x_axis
328+
self.y_axis: int = y_axis
329+
self.z_axis: int = z_axis
330+
331+
@classmethod
332+
def from_bytes(cls, payload: bytes) -> Self:
333+
"""
334+
Constructs a linear acceleration data block from bytes.
335+
Returns:
336+
A linear acceleration data block.
337+
"""
338+
parts = struct.unpack("<Ihhh", payload)
339+
return cls(parts[0], parts[1] / 100, parts[2] / 100, parts[3] / 100)
340+
341+
def __len__(self) -> int:
342+
"""
343+
Get the length of a linear acceleration data block in bytes
344+
Returns:
345+
The length of a linear acceleration data block in bytes not including the block header.
346+
"""
347+
return 10
348+
349+
def __str__(self):
350+
return f"{self.__class__.__name__} -> time: {self.mission_time} ms, x-axis: {self.x_axis} m/s^2, y-axis: {self.y_axis} m/s^2, z-axis: {self.z_axis} m/s^2"
351+
352+
def __iter__(self):
353+
yield "mission_time", self.mission_time
354+
yield "acceleration", {"x_axis": self.x_axis, "y_axis": self.y_axis, "z_axis": self.z_axis}
355+
356+
class AngularVelocityDB(DataBlock):
357+
"""Represents an angular velocity data block"""
358+
359+
def __init__(self, mission_time: int, x_axis: int, y_axis: int, z_axis: int) -> None:
360+
"""
361+
Constructus an angular velocity data block.
362+
363+
Args:
364+
mission_time: The mission time the angular velocity was measured in milliseconds since launch.
365+
x_axis: The velocity about the x axis in degrees per second.
366+
y_axis: The velocity about the y axis in degrees per second.
367+
z_axis: The velocity about the z axis in degrees per second.
368+
369+
"""
370+
super().__init__(mission_time)
371+
self.x_axis: int = x_axis
372+
self.y_axis: int = y_axis
373+
self.z_axis: int = z_axis
374+
375+
@classmethod
376+
def from_bytes(cls, payload: bytes) -> Self:
377+
"""
378+
Constructs an angular velocity data block from bytes.
379+
Returns:
380+
An angular velocity data block.
381+
"""
382+
parts = struct.unpack("<Ihhh", payload)
383+
return cls(parts[0], parts[1] / 10, parts[2] / 10, parts[3] / 10)
384+
385+
def __len__(self) -> int:
386+
"""
387+
Get the length of an angular velocity data block in bytes
388+
Returns:
389+
The length of an angular velocity data block in bytes not including the block header.
390+
"""
391+
return 10
392+
393+
def __str__(self):
394+
return f"{self.__class__.__name__} -> time: {self.mission_time} ms, x-axis: {self.x_axis} dps, y-axis: {self.y_axis} dps, z-axis: {self.z_axis} dps"
395+
396+
def __iter__(self):
397+
yield "mission_time", self.mission_time
398+
yield "velocity", {"x_axis": self.x_axis, "y_axis": self.y_axis, "z_axis": self.z_axis}
310399

311400
def parse_data_block(type: DataBlockSubtype, payload: bytes) -> DataBlock:
312401
"""
@@ -331,5 +420,9 @@ def parse_data_block(type: DataBlockSubtype, payload: bytes) -> DataBlock:
331420
return PressureDB.from_bytes(payload)
332421
case DataBlockSubtype.HUMIDITY:
333422
return HumidityDB.from_bytes(payload)
423+
case DataBlockSubtype.ACCELERATION:
424+
return LinearAccelerationDB.from_bytes(payload)
425+
case DataBlockSubtype.ANGULAR_VELOCITY:
426+
return AngularVelocityDB.from_bytes(payload)
334427
case _:
335428
raise NotImplementedError

0 commit comments

Comments
 (0)