diff --git a/okdmr/dmrlib/etsi/fec/vbptc_32_11.py b/okdmr/dmrlib/etsi/fec/vbptc_32_11.py index 5444535..fefa29d 100644 --- a/okdmr/dmrlib/etsi/fec/vbptc_32_11.py +++ b/okdmr/dmrlib/etsi/fec/vbptc_32_11.py @@ -174,7 +174,7 @@ def fill_encoding_table( return table @staticmethod - def encode(bits_deinterleaved: bitarray) -> bitarray: + def encode(bits_deinterleaved: bitarray, even_parity: bool = True) -> bitarray: """ Takes 11 bits of data (info bits) and return interleaved and FEC protected 32 bits :param bits_deinterleaved: @@ -209,7 +209,7 @@ def encode(bits_deinterleaved: bitarray) -> bitarray: # fill columns with parity bit for column in range(0, 16): - table[:, column] = VBPTC3211.set_parity(table[:, column]) + table[:, column] = VBPTC3211.set_parity(table[:, column], even_parity) out: bitarray = bitarray([0] * 32) for index, ( @@ -224,7 +224,7 @@ def encode(bits_deinterleaved: bitarray) -> bitarray: return out @staticmethod - def set_parity(column: numpy.ndarray) -> numpy.ndarray: + def set_parity(column: numpy.ndarray, even_parity: bool = True) -> numpy.ndarray: assert len(column) == 2 - column[1] = column[0] + column[1] = column[0] if even_parity else not column[0] return column diff --git a/okdmr/tests/dmrlib/etsi/fec/test_vbptc_32_11.py b/okdmr/tests/dmrlib/etsi/fec/test_vbptc_32_11.py index 0b4cf6b..6d0e390 100644 --- a/okdmr/tests/dmrlib/etsi/fec/test_vbptc_32_11.py +++ b/okdmr/tests/dmrlib/etsi/fec/test_vbptc_32_11.py @@ -13,14 +13,18 @@ def test_vbptc_sanity(): def test_encode_decode_vbptc(): - bursts: List[(str,)] = [ - ("00000100010110000000100010100100",), + # payload, even_parity + bursts: List[(str, bool)] = [ + # even parity (default) + ("00000100010110000000100010100100", True), + # same payload mock with odd paritiy + ("01010001000011010101110111110001", False), # following are not valid vbptc protected payloads, probably something proprietary / unidentified - # ("00001100000100010010010001000001",), - # ("00010111000010100000011001000100",), + # ("00001100000100010010010001000001", ), + # ("00010111000010100000011001000100", ), ] - for (burst,) in bursts: + for burst, even_parity in bursts: on_air_bits = bitarray(burst) deinterleaved_all_bits = VBPTC3211.deinterleave_all_bits(on_air_bits) @@ -31,9 +35,9 @@ def test_encode_decode_vbptc(): deinterleaved_data_bits = VBPTC3211.deinterleave_data_bits(on_air_bits) - encoded_all_bits = VBPTC3211.encode(deinterleaved_all_bits) - encoded_data_bits = VBPTC3211.encode(deinterleaved_data_bits) - encoded_info_bits = VBPTC3211.encode(deinterleaved_info_bits) + encoded_all_bits = VBPTC3211.encode(deinterleaved_all_bits, even_parity) + encoded_data_bits = VBPTC3211.encode(deinterleaved_data_bits, even_parity) + encoded_info_bits = VBPTC3211.encode(deinterleaved_info_bits, even_parity) assert encoded_all_bits == encoded_data_bits assert encoded_data_bits == encoded_info_bits