Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions python/append_crc32c.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import struct

from gnuradio import gr
import numpy
import pmt

from . import crc32c
from . import crc as _crc_module

_crc_fn = _crc_module(32, 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, True, True)


class append_crc32c(gr.basic_block):
Expand All @@ -38,7 +39,8 @@ def handle_msg(self, msg_pmt):
print('[ERROR] Received invalid message type. Expected u8vector')
return
packet = bytes(pmt.u8vector_elements(msg))
crc = crc32c.crc(packet if self.include_header else packet[4:])
data = packet if self.include_header else packet[4:]
crc = _crc_fn.compute(list(data))
packet += struct.pack('>I', crc)
self.message_port_pub(
pmt.intern('out'),
Expand Down
10 changes: 5 additions & 5 deletions python/check_crc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import struct

from gnuradio import gr
import numpy
import pmt

from . import crc32c
from . import crc as _crc_module
from . import csp_header

_crc_fn = _crc_module(32, 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, True, True)


class check_crc(gr.basic_block):
"""docstring for block check_crc"""
Expand Down Expand Up @@ -57,9 +58,8 @@ def handle_msg(self, msg_pmt):
if self.verbose:
print('Malformed CSP packet (too short)')
return
crc = crc32c.crc(packet[:-4]
if self.include_header
else packet[4:-4])
crc = _crc_fn.compute(
list(packet[:-4] if self.include_header else packet[4:-4]))
packet_crc = struct.unpack('>I', bytes(packet[-4:]))[0]
if crc == packet_crc:
if self.verbose:
Expand Down
2 changes: 1 addition & 1 deletion python/hdlc_deframer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import numpy
import pmt

from . import crc, hdlc
from . import crc


def pack(s):
Expand Down
8 changes: 5 additions & 3 deletions python/hdlc_framer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import numpy
import pmt

from . import crc, hdlc
from . import crc

_flag = bytes([0, 1, 1, 1, 1, 1, 1, 0])


class hdlc_framer(gr.basic_block):
Expand Down Expand Up @@ -45,7 +47,7 @@ def handle_msg(self, msg_pmt):
data.append(crc_val & 0xff)
data.append((crc_val >> 8) & 0xff)

buff = list(hdlc.flag * self.preamble_bytes)
buff = list(_flag * self.preamble_bytes)
ones = 0 # number of consecutive ones
for byte in data:
for _ in range(8):
Expand All @@ -61,7 +63,7 @@ def handle_msg(self, msg_pmt):
buff.append(0)
ones = 0
byte >>= 1
buff.extend(hdlc.flag * self.postamble_bytes)
buff.extend(_flag * self.postamble_bytes)

self.message_port_pub(
pmt.intern('out'),
Expand Down
1 change: 0 additions & 1 deletion python/k2sat_deframer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import pmt

from . import hdlc_deframer
from . import hdlc


class k2sat_deframer(gr.basic_block):
Expand Down
12 changes: 7 additions & 5 deletions python/mobitex_to_datablocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import pmt
import numpy as np

from .check_eseo_crc import crc16_ccitt_zero as crc16_ccitt_zero
from . import crc as _crc_module
from .mobitex_fec import decode, encode, Status

_crc_fn = _crc_module(16, 0x1021, 0x0000, 0x0000, False, False)


def decode_control(control0: int, control1: int, fec: int) -> \
Optional[Tuple[List[int], int]]:
Expand Down Expand Up @@ -60,8 +62,8 @@ def encode_control(control0: int, control1: int) -> int:


def check_callsign_crc(callsign: bytes, crc: bytes):
computed_crc = crc16_ccitt_zero(
callsign).to_bytes(length=2, byteorder='big')
computed_crc = _crc_fn.compute(
list(callsign)).to_bytes(length=2, byteorder='big')

return computed_crc == crc

Expand Down Expand Up @@ -129,8 +131,8 @@ def compare_expected_callsign(
Returns:
reference callsign CRC along with number of bit errors.
"""
crc_ref = crc16_ccitt_zero(
callsign_ref).to_bytes(length=2, byteorder='big')
crc_ref = _crc_fn.compute(
list(callsign_ref)).to_bytes(length=2, byteorder='big')

bit_errors = hamming_distance(
callsign + crc,
Expand Down
2 changes: 1 addition & 1 deletion python/pwsat2_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import numpy
import pmt

from . import crc, hdlc
from . import crc
from .submit import parse_timestamp


Expand Down
2 changes: 0 additions & 2 deletions python/tubix20_reframer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
from gnuradio import gr
import pmt

from .check_eseo_crc import crc16_ccitt_zero as crc16_ccitt_zero


class tubix20_reframer(gr.basic_block):
"""
Expand Down