@@ -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
"""
@@ -308,6 +310,98 @@ def __iter__(self):
308
310
yield "percentage" , round (self .humidity / 100 )
309
311
310
312
313
+ class LinearAccelerationDB (DataBlock ):
314
+ """Represents a linear acceleration data block"""
315
+
316
+ def __init__ (self , mission_time : int , x_axis : int , y_axis : int , z_axis : int ) -> None :
317
+ """
318
+ Constructs a linear acceleration data block.
319
+
320
+ Args:
321
+ mission_time: The mission time the linear acceleration was measured in milliseconds since launch.
322
+ x_axis: The acceleration about the x axis in meters per second squared.
323
+ y_axis: The acceleration about the y axis in meters per second squared.
324
+ z_axis: The acceleration about the z axis in meters per second squared.
325
+
326
+ """
327
+ super ().__init__ (mission_time )
328
+ self .x_axis : int = x_axis
329
+ self .y_axis : int = y_axis
330
+ self .z_axis : int = z_axis
331
+
332
+ @classmethod
333
+ def from_bytes (cls , payload : bytes ) -> Self :
334
+ """
335
+ Constructs a linear acceleration data block from bytes.
336
+ Returns:
337
+ A linear acceleration data block.
338
+ """
339
+ parts = struct .unpack ("<Ihhhh" , payload )
340
+ return cls (parts [0 ], parts [1 ] / 100 , parts [2 ] / 100 , parts [3 ] / 100 )
341
+
342
+ def __len__ (self ) -> int :
343
+ """
344
+ Get the length of a linear acceleration data block in bytes
345
+ Returns:
346
+ The length of a linear acceleration data block in bytes not including the block header.
347
+ """
348
+ return 10
349
+
350
+ def __str__ (self ):
351
+ return f"""{ self .__class__ .__name__ } -> time: { self .mission_time } ms, x-axis: { self .x_axis } m/s^2, y-axis:
352
+ { self .y_axis } m/s^2, z-axis: { self .z_axis } m/s^2"""
353
+
354
+ def __iter__ (self ):
355
+ yield "mission_time" , self .mission_time
356
+ yield "acceleration" , {"x_axis" : self .x_axis , "y_axis" : self .y_axis , "z_axis" : self .z_axis }
357
+
358
+
359
+ class AngularVelocityDB (DataBlock ):
360
+ """Represents an angular velocity data block"""
361
+
362
+ def __init__ (self , mission_time : int , x_axis : int , y_axis : int , z_axis : int ) -> None :
363
+ """
364
+ Constructus an angular velocity data block.
365
+
366
+ Args:
367
+ mission_time: The mission time the angular velocity was measured in milliseconds since launch.
368
+ x_axis: The velocity about the x axis in degrees per second.
369
+ y_axis: The velocity about the y axis in degrees per second.
370
+ z_axis: The velocity about the z axis in degrees per second.
371
+
372
+ """
373
+ super ().__init__ (mission_time )
374
+ self .x_axis : int = x_axis
375
+ self .y_axis : int = y_axis
376
+ self .z_axis : int = z_axis
377
+
378
+ @classmethod
379
+ def from_bytes (cls , payload : bytes ) -> Self :
380
+ """
381
+ Constructs an angular velocity data block from bytes.
382
+ Returns:
383
+ An angular velocity data block.
384
+ """
385
+ parts = struct .unpack ("<Ihhhh" , payload )
386
+ return cls (parts [0 ], parts [1 ] / 10 , parts [2 ] / 10 , parts [3 ] / 10 )
387
+
388
+ def __len__ (self ) -> int :
389
+ """
390
+ Get the length of an angular velocity data block in bytes
391
+ Returns:
392
+ The length of an angular velocity data block in bytes not including the block header.
393
+ """
394
+ return 10
395
+
396
+ def __str__ (self ):
397
+ return f"""{ self .__class__ .__name__ } -> time: { self .mission_time } ms, x-axis: { self .x_axis } dps, y-axis:
398
+ { self .y_axis } dps, z-axis: { self .z_axis } dps"""
399
+
400
+ def __iter__ (self ):
401
+ yield "mission_time" , self .mission_time
402
+ yield "velocity" , {"x_axis" : self .x_axis , "y_axis" : self .y_axis , "z_axis" : self .z_axis }
403
+
404
+
311
405
def parse_data_block (type : DataBlockSubtype , payload : bytes ) -> DataBlock :
312
406
"""
313
407
Parses a bytes payload into the correct data block type.
@@ -331,5 +425,9 @@ def parse_data_block(type: DataBlockSubtype, payload: bytes) -> DataBlock:
331
425
return PressureDB .from_bytes (payload )
332
426
case DataBlockSubtype .HUMIDITY :
333
427
return HumidityDB .from_bytes (payload )
428
+ case DataBlockSubtype .ACCELERATION :
429
+ return LinearAccelerationDB .from_bytes (payload )
430
+ case DataBlockSubtype .ANGULAR_VELOCITY :
431
+ return AngularVelocityDB .from_bytes (payload )
334
432
case _:
335
433
raise NotImplementedError
0 commit comments