Skip to content
Snippets Groups Projects
Commit 633d7984 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-192: Improved naming & comments of extract_bits.

parent f82b7bde
No related branches found
No related tags found
1 merge request!45L2SS-192: Provide interface for raw header fields, add example packet (needs...
......@@ -4,19 +4,19 @@ import numpy
__all__ = ["StatisticsPacket"]
def extract_bits(value: bytes, first: int, last:int=None) -> int:
""" Return bits [first:last] from value, and return their integer value. Bit 0 = LSB.
def get_bit_value(value: bytes, first_bit: int, last_bit:int=None) -> int:
""" Return bits [first_bit:last_bit] from value, and return their integer value. Bit 0 = LSB.
For example, extracting bits 2-3 from b'01100' returns 11 binary = 3 decimal:
extract_bits(b'01100', 2, 3) == 3
get_bit_value(b'01100', 2, 3) == 3
If last is not given, just the value of bit 'first' is returned. """
If 'last_bit' is not given, just the value of bit 'first_bit' is returned. """
# default last to first
if last is None:
last = first
# default last_bit to first_bit
if last_bit is None:
last_bit = first_bit
return value >> first & ((1 << (last - first + 1)) - 1)
return value >> first_bit & ((1 << (last_bit - first_bit + 1)) - 1)
class StatisticsPacket(object):
"""
......@@ -71,15 +71,15 @@ class StatisticsPacket(object):
return {
"_raw": bits,
"antenna_band_index": extract_bits(bits, 15),
"nyquist_zone_index": extract_bits(bits, 13, 14),
"t_adc": extract_bits(bits, 12),
"fsub_type": extract_bits(bits, 11),
"payload_error": extract_bits(bits, 10),
"beam_repositioning_flag": extract_bits(bits, 9),
"subband_calibrated_flag": extract_bits(bits, 8),
"reserved": extract_bits(bits, 5, 7),
"gn_index": extract_bits(bits, 0, 4),
"antenna_band_index": get_bit_value(bits, 15),
"nyquist_zone_index": get_bit_value(bits, 13, 14),
"t_adc": get_bit_value(bits, 12),
"fsub_type": get_bit_value(bits, 11),
"payload_error": get_bit_value(bits, 10),
"beam_repositioning_flag": get_bit_value(bits, 9),
"subband_calibrated_flag": get_bit_value(bits, 8),
"reserved": get_bit_value(bits, 5, 7),
"gn_index": get_bit_value(bits, 0, 4),
}
@property
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment