@@ -30,6 +30,7 @@ class DataBlockSubtype(IntEnum):
30
30
ANGULAR_VELOCITY = 0x07
31
31
HUMIDITY = 0x08
32
32
COORDINATES = 0x09
33
+ VOLTAGE = 0x0A
33
34
34
35
def __str__ (self ):
35
36
match self :
@@ -53,6 +54,8 @@ def __str__(self):
53
54
return "HUMIDITY"
54
55
case DataBlockSubtype .COORDINATES :
55
56
return "COORDINATES"
57
+ case DataBlockSubtype .VOLTAGE :
58
+ return "VOLTAGE"
56
59
57
60
58
61
class DataBlock (ABC ):
@@ -105,6 +108,7 @@ def parse(block_subtype: DataBlockSubtype, payload: bytes) -> DataBlock:
105
108
DataBlockSubtype .LIN_ACCEL_REL : RelativeLinearAccelerationDB ,
106
109
DataBlockSubtype .LIN_ACCEL_ABS : AbsoluteLinearAccelerationDB ,
107
110
DataBlockSubtype .ANGULAR_VELOCITY : AngularVelocityDB ,
111
+ DataBlockSubtype .VOLTAGE : VoltageDB ,
108
112
}
109
113
110
114
subtype = SUBTYPE_CLASSES .get (block_subtype )
@@ -435,17 +439,46 @@ def __iter__(self):
435
439
yield "angular_velocity" , {"x" : self .x_axis , "y" : self .y_axis , "z" : self .z_axis , "magnitude" : self .magnitude }
436
440
437
441
438
- # TODO: Remove this function
439
- def parse_data_block (type : DataBlockSubtype , payload : bytes ) -> DataBlock :
440
- """
441
- Parses a bytes payload into the correct data block type.
442
- Args:
443
- type: The type of data block to parse the bytes into.
444
- payload: The bytes payload to parse into a data block.
445
- Returns:
446
- The parse data block.
447
- Raises:
448
- ValueError: Raised if the bytes cannot be parsed into the corresponding type.
449
- """
450
-
451
- return DataBlock .parse (type , payload )
442
+ class VoltageDB (DataBlock ):
443
+ """Represents a voltage data block"""
444
+
445
+ def __init__ (self , mission_time : int , id : int , voltage : int ) -> None :
446
+ """
447
+ Constructus a voltage data block.
448
+
449
+ Args:
450
+ mission_time: The mission time the voltage was measured in milliseconds since launch.
451
+ id: A numerical id associated with the voltage measurement for identification by the receiver
452
+ voltage: The measured voltage in units of millivolts
453
+ """
454
+ super ().__init__ (mission_time )
455
+ self .id : int = id
456
+ self .voltage : int = voltage
457
+
458
+ @classmethod
459
+ def from_bytes (cls , payload : bytes ) -> Self :
460
+ """
461
+ Constructs a voltage data block from bytes.
462
+ Returns:
463
+ A voltage data block.
464
+ """
465
+ parts = struct .unpack ("<IHh" , payload )
466
+ return cls (parts [0 ], parts [1 ], parts [2 ])
467
+
468
+ def __len__ (self ) -> int :
469
+ """
470
+ Get the length of a voltage data block in bytes
471
+ Returns:
472
+ The length of a voltage data block in bytes not including the block header.
473
+ """
474
+ return 8
475
+
476
+ def __str__ (self ):
477
+ return (
478
+ f"""{ self .__class__ .__name__ } -> time: { self .mission_time } ms, id: { self .id } , voltage: { self .voltage } mV"""
479
+ )
480
+
481
+ def __iter__ (self ):
482
+ yield "mission_time" , self .mission_time
483
+ yield "id" , self .id
484
+ yield "voltage" , self .voltage
0 commit comments