Skip to content

Commit

Permalink
odd parity option for B.2.2.2 Reverse Channel Single Burst BPTC, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
smarek committed Nov 30, 2024
1 parent 75d6f52 commit 8e3c84d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions okdmr/dmrlib/etsi/fec/vbptc_32_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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, (
Expand All @@ -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
20 changes: 12 additions & 8 deletions okdmr/tests/dmrlib/etsi/fec/test_vbptc_32_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 8e3c84d

Please sign in to comment.