mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
some code adjustments
This commit is contained in:
parent
3e3d96a4bb
commit
618bf3ae4b
|
@ -118,7 +118,6 @@ class DataFrameFactory:
|
|||
return frame
|
||||
|
||||
def deconstruct(self, frame):
|
||||
extracted_data = {}
|
||||
buffer_position = 1
|
||||
|
||||
# Extract frametype and get the corresponding template
|
||||
|
@ -129,8 +128,7 @@ class DataFrameFactory:
|
|||
# Handle the case where the frame type is not recognized
|
||||
raise ValueError(f"Unknown frame type: {frametype}")
|
||||
|
||||
extracted_data["frame_type"] = FR_TYPE(frametype).name
|
||||
extracted_data["frame_type_int"] = frametype
|
||||
extracted_data = {"frame_type": FR_TYPE(frametype).name, "frame_type_int": frametype}
|
||||
|
||||
for key, item_length in frame_template.items():
|
||||
if key != "frame_length":
|
||||
|
@ -204,7 +202,7 @@ class DataFrameFactory:
|
|||
mode_int = codec2.freedv_get_mode_value_by_name(mode)
|
||||
|
||||
payload = {
|
||||
"mycallsign": helpers.FEC_WAKEUP(self.myfullcall),
|
||||
"mycallsign": helpers.callsign_to_bytes(self.myfullcall),
|
||||
"mode": bytes([mode_int]),
|
||||
"n_bursts": bytes([1]) # n payload bursts,
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ FRAME DISPATCHER - We are dispatching the received frames to the needed function
|
|||
"""
|
||||
import threading
|
||||
import helpers
|
||||
import structlog
|
||||
from modem_frametypes import FRAME_TYPE as FR_TYPE
|
||||
import event_manager
|
||||
from queues import DATA_QUEUE_RECEIVED, DATA_QUEUE_TRANSMIT, MODEM_TRANSMIT_QUEUE
|
||||
|
@ -23,7 +24,9 @@ from protocol_arq_session import SESSION
|
|||
class DISPATCHER():
|
||||
|
||||
def __init__(self, config, event_queue, states):
|
||||
print("loading frame dispatcher.....\n")
|
||||
self.log = structlog.get_logger("frame_dispatcher")
|
||||
|
||||
self.log.info("loading frame dispatcher.....\n")
|
||||
self.config = config
|
||||
self.event_queue = event_queue
|
||||
self.states = states
|
||||
|
@ -140,10 +143,10 @@ class DISPATCHER():
|
|||
Returns:
|
||||
|
||||
"""
|
||||
|
||||
if self.check_if_valid_frame(bytes_out):
|
||||
# get frame as dictionary
|
||||
deconstructed_frame = self.frame_factory.deconstruct(bytes_out)
|
||||
if self.check_if_valid_frame(deconstructed_frame):
|
||||
# get frame as dictionary
|
||||
|
||||
frametype = deconstructed_frame["frame_type_int"]
|
||||
print(deconstructed_frame)
|
||||
print(frametype)
|
||||
|
@ -184,12 +187,14 @@ class DISPATCHER():
|
|||
frame_type=FR_TYPE(int.from_bytes(bytes_out[:1], byteorder="big")).name,
|
||||
)
|
||||
|
||||
def check_if_valid_frame(self, bytes_out):
|
||||
def check_if_valid_frame(self, deconstructed_frame):
|
||||
# Process data only if broadcast or we are the receiver
|
||||
# bytes_out[1:4] == callsign check for signalling frames,
|
||||
# bytes_out[2:5] == transmission
|
||||
# we could also create an own function, which returns True.
|
||||
frametype = int.from_bytes(bytes(bytes_out[:1]), "big")
|
||||
|
||||
|
||||
#deconstructed_frame["mycallsign"]
|
||||
|
||||
# check for callsign CRC
|
||||
_valid1, _ = helpers.check_callsign(self.arq.mycallsign, bytes(bytes_out[1:4]), self.arq.ssid_list)
|
||||
|
@ -197,12 +202,13 @@ class DISPATCHER():
|
|||
# check for session ID
|
||||
_valid3 = helpers.check_session_id(self.arq.session_id, bytes(bytes_out[1:2])) # signalling frames
|
||||
_valid4 = helpers.check_session_id(self.arq.session_id, bytes(bytes_out[2:3])) # arq data frames
|
||||
if (
|
||||
return bool(
|
||||
(
|
||||
_valid1
|
||||
or _valid2
|
||||
or _valid3
|
||||
or _valid4
|
||||
or frametype
|
||||
or deconstructed_frame["frame_type_int"]
|
||||
in [
|
||||
FR_TYPE.CQ.value,
|
||||
FR_TYPE.QRV.value,
|
||||
|
@ -212,14 +218,12 @@ class DISPATCHER():
|
|||
FR_TYPE.FEC.value,
|
||||
FR_TYPE.FEC_WAKEUP.value,
|
||||
]
|
||||
):
|
||||
return True
|
||||
return False
|
||||
)
|
||||
)
|
||||
|
||||
def get_id_from_frame(self, data):
|
||||
if data[:1] in [FR_TYPE.ARQ_DC_OPEN_N, FR_TYPE.ARQ_DC_OPEN_W]:
|
||||
session_id = data[13:14]
|
||||
return session_id
|
||||
return data[13:14]
|
||||
return None
|
||||
|
||||
def initialize_arq_instance(self):
|
||||
|
@ -239,4 +243,4 @@ class DISPATCHER():
|
|||
if id := self.get_id_from_frame(data):
|
||||
instance = self.initialize_arq_instance()
|
||||
self.states.register_arq_instance_by_id(id, instance)
|
||||
instance['arq_irs'].arq_received_data_channel_opener
|
||||
instance['arq_irs'].arq_received_data_channel_opener()
|
||||
|
|
|
@ -36,7 +36,7 @@ def wait(seconds: float) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
def get_crc_8(data) -> bytes:
|
||||
def get_crc_8(data: str) -> bytes:
|
||||
"""Author: DJ2LS
|
||||
|
||||
Get the CRC8 of a byte string
|
||||
|
@ -55,7 +55,7 @@ def get_crc_8(data) -> bytes:
|
|||
return crc_data
|
||||
|
||||
|
||||
def get_crc_16(data) -> bytes:
|
||||
def get_crc_16(data: str) -> bytes:
|
||||
"""Author: DJ2LS
|
||||
|
||||
Get the CRC16 of a byte string
|
||||
|
@ -74,7 +74,7 @@ def get_crc_16(data) -> bytes:
|
|||
crc_algorithm = crcengine.new("crc16-ccitt-false") # load crc16 library
|
||||
return crc_algorithm(data).to_bytes(2, byteorder="big")
|
||||
|
||||
def get_crc_24(data: bytes) -> bytes:
|
||||
def get_crc_24(data: str) -> bytes:
|
||||
"""Author: DJ2LS
|
||||
|
||||
Get the CRC24-OPENPGP of a byte string
|
||||
|
@ -102,7 +102,7 @@ def get_crc_24(data: bytes) -> bytes:
|
|||
return crc_algorithm(data).to_bytes(3,byteorder="big")
|
||||
|
||||
|
||||
def get_crc_32(data: bytes) -> bytes:
|
||||
def get_crc_32(data: str) -> bytes:
|
||||
"""Author: DJ2LS
|
||||
|
||||
Get the CRC32 of a byte string
|
||||
|
|
Loading…
Reference in a new issue