-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crc9 fixed, transmission generator 1/2, more tests
- Loading branch information
Showing
24 changed files
with
455 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
okdmr/dmrlib/etsi/layer2/elements/fragment_sequence_number.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from bitarray import bitarray | ||
from bitarray.util import ba2int, int2ba | ||
|
||
from okdmr.dmrlib.utils.bits_interface import BitsInterface | ||
|
||
|
||
class FragmentSequenceNumber(BitsInterface): | ||
SINGLE_UNCONFIRMED_FRAGMENT_VALUE: int = 0b0000 | ||
SINGLE_CONFIRMED_FRAGMENT_VALUE: int = 0b1000 | ||
|
||
def __init__(self, value: int = 0): | ||
assert ( | ||
0b0000 <= value <= 0b1111 | ||
), f"FSN value out of range 0b0000-0b1111 got {bin(value)}" | ||
self.value: int = value | ||
|
||
def is_last(self) -> bool: | ||
return ( | ||
# single (last) unconfirmed fragment | ||
self.value == FragmentSequenceNumber.SINGLE_UNCONFIRMED_FRAGMENT_VALUE | ||
# 0b1000 is single confirmed, bigger values are last fragment | ||
or self.value >= FragmentSequenceNumber.SINGLE_CONFIRMED_FRAGMENT_VALUE | ||
) | ||
|
||
def __repr__(self) -> str: | ||
desc: str = "" | ||
if self.value == FragmentSequenceNumber.SINGLE_UNCONFIRMED_FRAGMENT_VALUE: | ||
desc = "Unconfirmed data single fragment" | ||
elif self.value == FragmentSequenceNumber.SINGLE_CONFIRMED_FRAGMENT_VALUE: | ||
desc = "Confirmed data single fragment" | ||
else: | ||
num: int = self.value & 0b111 | ||
is_last: str = "Last" if self.is_last() else "Subsequent" | ||
desc = f"{is_last} confirmed data fragment, number {num}" | ||
return f"[FSN: {desc}]" | ||
|
||
@staticmethod | ||
def from_bits(bits: bitarray) -> "FragmentSequenceNumber": | ||
return FragmentSequenceNumber(value=ba2int(bits[0:4])) | ||
|
||
def as_bits(self) -> bitarray: | ||
return int2ba(self.value, length=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.