@@ -105,6 +105,8 @@ def parse(block_subtype: DataBlockSubtype, payload: bytes) -> DataBlock:
105
105
DataBlockSubtype .TEMPERATURE : TemperatureDB ,
106
106
DataBlockSubtype .PRESSURE : PressureDB ,
107
107
DataBlockSubtype .HUMIDITY : HumidityDB ,
108
+ DataBlockSubtype .ACCELERATION : LinearAccelerationDB ,
109
+ DataBlockSubtype .ANGULAR_VELOCITY : AngularVelocityDB ,
108
110
}
109
111
110
112
subtype = SUBTYPE_CLASSES .get (block_subtype )
@@ -234,7 +236,7 @@ def __init__(self, mission_time: int, pressure: int) -> None:
234
236
Constructs a pressure data block.
235
237
236
238
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.
238
240
pressure: The pressure in millibars.
239
241
240
242
"""
@@ -307,6 +309,93 @@ def __iter__(self):
307
309
yield "mission_time" , self .mission_time
308
310
yield "percentage" , round (self .humidity / 100 )
309
311
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 }
310
399
311
400
def parse_data_block (type : DataBlockSubtype , payload : bytes ) -> DataBlock :
312
401
"""
@@ -331,5 +420,9 @@ def parse_data_block(type: DataBlockSubtype, payload: bytes) -> DataBlock:
331
420
return PressureDB .from_bytes (payload )
332
421
case DataBlockSubtype .HUMIDITY :
333
422
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 )
334
427
case _:
335
428
raise NotImplementedError
0 commit comments