mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
first NAK frame
Needs to be tested, when a frame is getting lost.... No frame handling on the RX ( TX) side, just a message at this time
This commit is contained in:
parent
b815f655ac
commit
2e88b542cf
|
@ -195,9 +195,6 @@ def arq_data_received(data_in):
|
||||||
if frame_payload_crc == static.FRAME_CRC:
|
if frame_payload_crc == static.FRAME_CRC:
|
||||||
logging.log(25, "ARQ | RX | DATA FRAME SUCESSFULLY RECEIVED! :-) ")
|
logging.log(25, "ARQ | RX | DATA FRAME SUCESSFULLY RECEIVED! :-) ")
|
||||||
|
|
||||||
transfer_rates = helpers.calculate_transfer_rate()
|
|
||||||
print(str(transfer_rates[0]) + " bit/s")
|
|
||||||
print(str(transfer_rates[1]) + " B/min")
|
|
||||||
|
|
||||||
# append received frame to RX_BUFFER
|
# append received frame to RX_BUFFER
|
||||||
static.RX_BUFFER.append(complete_data_frame)
|
static.RX_BUFFER.append(complete_data_frame)
|
||||||
|
@ -209,11 +206,11 @@ def arq_data_received(data_in):
|
||||||
ack_frame[2:3] = static.MYCALLSIGN_CRC8
|
ack_frame[2:3] = static.MYCALLSIGN_CRC8
|
||||||
|
|
||||||
# TRANSMIT ACK FRAME FOR BURST-----------------------------------------------
|
# TRANSMIT ACK FRAME FOR BURST-----------------------------------------------
|
||||||
time.sleep(0.5) # 0.5
|
#time.sleep(0.5) # 0.5
|
||||||
logging.info("ARQ | TX | ARQ DATA FRAME ACK [" + str(static.FRAME_CRC.hex()) + "] [BER." + str(static.BER) + "]")
|
logging.info("ARQ | TX | ARQ DATA FRAME ACK [" + str(static.FRAME_CRC.hex()) + "] [BER." + str(static.BER) + "]")
|
||||||
|
|
||||||
modem.transmit_signalling(ack_frame)
|
modem.transmit_signalling(ack_frame)
|
||||||
|
modem.transmit_signalling(ack_frame)
|
||||||
while static.CHANNEL_STATE == 'SENDING_SIGNALLING':
|
while static.CHANNEL_STATE == 'SENDING_SIGNALLING':
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
@ -227,6 +224,21 @@ def arq_data_received(data_in):
|
||||||
print(static.ARQ_RX_FRAME_BUFFER)
|
print(static.ARQ_RX_FRAME_BUFFER)
|
||||||
logging.error("ARQ | RX | DATA FRAME NOT SUCESSFULLY RECEIVED!")
|
logging.error("ARQ | RX | DATA FRAME NOT SUCESSFULLY RECEIVED!")
|
||||||
|
|
||||||
|
# BUILDING ACK FRAME FOR DATA FRAME -----------------------------------------------
|
||||||
|
nak_frame = bytearray(14)
|
||||||
|
nak_frame[:1] = bytes([63])
|
||||||
|
nak_frame[1:2] = static.DXCALLSIGN_CRC8
|
||||||
|
nak_frame[2:3] = static.MYCALLSIGN_CRC8
|
||||||
|
|
||||||
|
# TRANSMIT ACK FRAME FOR BURST-----------------------------------------------
|
||||||
|
#time.sleep(0.5) # 0.5
|
||||||
|
logging.info("ARQ | TX | NAK")
|
||||||
|
|
||||||
|
modem.transmit_signalling(nak_frame)
|
||||||
|
while static.CHANNEL_STATE == 'SENDING_SIGNALLING':
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
|
||||||
helpers.arq_reset_frame_machine()
|
helpers.arq_reset_frame_machine()
|
||||||
|
|
||||||
logging.info("DATA [" + str(static.MYCALLSIGN, 'utf-8') + "]<<X>>[" + str(static.DXCALLSIGN, 'utf-8') + "] [BER." + str(static.BER) + "]")
|
logging.info("DATA [" + str(static.MYCALLSIGN, 'utf-8') + "]<<X>>[" + str(static.DXCALLSIGN, 'utf-8') + "] [BER." + str(static.BER) + "]")
|
||||||
|
@ -353,6 +365,8 @@ def arq_transmit(data_out):
|
||||||
helpers.arq_reset_ack(False)
|
helpers.arq_reset_ack(False)
|
||||||
static.ARQ_RPT_FRAMES = []
|
static.ARQ_RPT_FRAMES = []
|
||||||
|
|
||||||
|
# the order of ACK check is important! speciall the FRAME ACK after RPT needs to be checked really early!
|
||||||
|
|
||||||
|
|
||||||
# --------------- BREAK LOOP IF FRAME ACK HAS BEEN RECEIVED EARLIER AS EXPECTED
|
# --------------- BREAK LOOP IF FRAME ACK HAS BEEN RECEIVED EARLIER AS EXPECTED
|
||||||
elif static.ARQ_FRAME_ACK_RECEIVED:
|
elif static.ARQ_FRAME_ACK_RECEIVED:
|
||||||
|
@ -367,11 +381,6 @@ def arq_transmit(data_out):
|
||||||
pass # no break here so we can continue with the next try of repeating the burst
|
pass # no break here so we can continue with the next try of repeating the burst
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --------------- BREAK LOOP IF ACK HAS BEEN RECEIVED
|
# --------------- BREAK LOOP IF ACK HAS BEEN RECEIVED
|
||||||
elif static.ARQ_ACK_RECEIVED:
|
elif static.ARQ_ACK_RECEIVED:
|
||||||
transfer_rates = helpers.calculate_transfer_rate()
|
transfer_rates = helpers.calculate_transfer_rate()
|
||||||
|
@ -389,11 +398,6 @@ def arq_transmit(data_out):
|
||||||
print("ARQ_RX_ACK_TIMEOUT " + str(static.ARQ_RX_ACK_TIMEOUT))
|
print("ARQ_RX_ACK_TIMEOUT " + str(static.ARQ_RX_ACK_TIMEOUT))
|
||||||
break
|
break
|
||||||
|
|
||||||
print("static.ARQ_ACK_RECEIVED" + str(static.ARQ_ACK_RECEIVED))
|
|
||||||
print("static.ARQ_FRAME_ACK_RECEIVED" + str(static.ARQ_FRAME_ACK_RECEIVED))
|
|
||||||
print("static.ARQ_N_SENT_FRAMES" + str(static.ARQ_N_SENT_FRAMES))
|
|
||||||
print("static.ARQ_TX_N_TOTAL_ARQ_FRAMES" + str(static.ARQ_TX_N_TOTAL_ARQ_FRAMES))
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------WAITING AREA FOR FRAME ACKs
|
# --------------------------------WAITING AREA FOR FRAME ACKs
|
||||||
|
|
||||||
|
@ -424,7 +428,7 @@ def arq_transmit(data_out):
|
||||||
|
|
||||||
# -------------------------BREAK TX BUFFER LOOP IF ALL PACKETS HAVE BEEN SENT AND WE GOT A FRAME ACK
|
# -------------------------BREAK TX BUFFER LOOP IF ALL PACKETS HAVE BEEN SENT AND WE GOT A FRAME ACK
|
||||||
elif static.ARQ_N_SENT_FRAMES == static.TX_BUFFER_SIZE and static.ARQ_FRAME_ACK_RECEIVED:
|
elif static.ARQ_N_SENT_FRAMES == static.TX_BUFFER_SIZE and static.ARQ_FRAME_ACK_RECEIVED:
|
||||||
logging.log(25, "ARQ | RX | FRAME ACK RECEIVED - DATA TRANSMITTED! :-)")
|
logging.log(25, "ARQ | RX | FRAME ACK! - DATA TRANSMITTED! :-)")
|
||||||
break
|
break
|
||||||
|
|
||||||
elif not static.ARQ_FRAME_ACK_RECEIVED and time.time() > frameacktimeout: # == False and static.ARQ_RX_FRAME_TIMEOUT == True:
|
elif not static.ARQ_FRAME_ACK_RECEIVED and time.time() > frameacktimeout: # == False and static.ARQ_RX_FRAME_TIMEOUT == True:
|
||||||
|
@ -485,6 +489,8 @@ def burst_rpt_received(data_in):
|
||||||
missing = missing_area[i:i + 2]
|
missing = missing_area[i:i + 2]
|
||||||
static.ARQ_RPT_FRAMES.insert(0, missing)
|
static.ARQ_RPT_FRAMES.insert(0, missing)
|
||||||
|
|
||||||
|
def frame_nack_received():
|
||||||
|
print("NAK RECEIVED :-/")
|
||||||
|
|
||||||
# ############################################################################################################
|
# ############################################################################################################
|
||||||
# ARQ DATA CHANNEL HANDLER
|
# ARQ DATA CHANNEL HANDLER
|
||||||
|
@ -506,6 +512,10 @@ def open_dc_and_transmit(data_out, mode, n_frames):
|
||||||
# wait until data channel is open
|
# wait until data channel is open
|
||||||
while not static.ARQ_READY_FOR_DATA:
|
while not static.ARQ_READY_FOR_DATA:
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
#on a new transmission we reset the timer
|
||||||
|
static.ARQ_START_OF_TRANSMISSION = int(time.time())
|
||||||
|
|
||||||
# transmit data
|
# transmit data
|
||||||
arq_transmit(data_out)
|
arq_transmit(data_out)
|
||||||
|
|
||||||
|
@ -513,7 +523,7 @@ def open_dc_and_transmit(data_out, mode, n_frames):
|
||||||
|
|
||||||
|
|
||||||
async def arq_open_data_channel(mode):
|
async def arq_open_data_channel(mode):
|
||||||
print(type(mode))
|
|
||||||
if mode == 0:
|
if mode == 0:
|
||||||
static.ARQ_DATA_CHANNEL_MODE = get_best_mode_for_transmission()
|
static.ARQ_DATA_CHANNEL_MODE = get_best_mode_for_transmission()
|
||||||
print(static.ARQ_DATA_CHANNEL_MODE)
|
print(static.ARQ_DATA_CHANNEL_MODE)
|
||||||
|
@ -575,7 +585,7 @@ def arq_received_data_channel_opener(data_in):
|
||||||
|
|
||||||
|
|
||||||
modem.transmit_signalling(connection_frame)
|
modem.transmit_signalling(connection_frame)
|
||||||
modem.transmit_signalling(connection_frame)
|
#modem.transmit_signalling(connection_frame)
|
||||||
while static.CHANNEL_STATE == 'SENDING_SIGNALLING':
|
while static.CHANNEL_STATE == 'SENDING_SIGNALLING':
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
|
34
modem.py
34
modem.py
|
@ -233,8 +233,6 @@ class RF():
|
||||||
static.MYCALLSIGN_CRC8 + \
|
static.MYCALLSIGN_CRC8 + \
|
||||||
payload_data
|
payload_data
|
||||||
|
|
||||||
# print(arqframe)
|
|
||||||
|
|
||||||
buffer = bytearray(static.FREEDV_DATA_PAYLOAD_PER_FRAME) # create TX buffer
|
buffer = bytearray(static.FREEDV_DATA_PAYLOAD_PER_FRAME) # create TX buffer
|
||||||
buffer[:len(arqframe)] = arqframe # set buffersize to length of data which will be send
|
buffer[:len(arqframe)] = arqframe # set buffersize to length of data which will be send
|
||||||
|
|
||||||
|
@ -250,10 +248,12 @@ class RF():
|
||||||
|
|
||||||
for n in range(0, len(static.ARQ_RPT_FRAMES)):
|
for n in range(0, len(static.ARQ_RPT_FRAMES)):
|
||||||
|
|
||||||
|
|
||||||
missing_frame = int.from_bytes(static.ARQ_RPT_FRAMES[n], "big")
|
missing_frame = int.from_bytes(static.ARQ_RPT_FRAMES[n], "big")
|
||||||
|
|
||||||
# ---------------------------BUILD ARQ BURST ---------------------------------------------------------------------
|
# ---------------------------BUILD ARQ BURST ---------------------------------------------------------------------
|
||||||
frame_type = 10 + missing_frame # static.ARQ_TX_N_FRAMES_PER_BURST
|
frame_type = 10 + missing_frame # static.ARQ_TX_N_FRAMES_PER_BURST
|
||||||
|
|
||||||
frame_type = bytes([frame_type])
|
frame_type = bytes([frame_type])
|
||||||
|
|
||||||
payload_data = bytes(static.TX_BUFFER[static.ARQ_N_SENT_FRAMES + missing_frame - 1])
|
payload_data = bytes(static.TX_BUFFER[static.ARQ_N_SENT_FRAMES + missing_frame - 1])
|
||||||
|
@ -272,6 +272,7 @@ class RF():
|
||||||
static.MYCALLSIGN_CRC8 + \
|
static.MYCALLSIGN_CRC8 + \
|
||||||
payload_data
|
payload_data
|
||||||
|
|
||||||
|
|
||||||
buffer = bytearray(static.FREEDV_DATA_PAYLOAD_PER_FRAME) # create TX buffer
|
buffer = bytearray(static.FREEDV_DATA_PAYLOAD_PER_FRAME) # create TX buffer
|
||||||
buffer[:len(arqframe)] = arqframe # set buffersize to length of data which will be send
|
buffer[:len(arqframe)] = arqframe # set buffersize to length of data which will be send
|
||||||
|
|
||||||
|
@ -304,7 +305,7 @@ class RF():
|
||||||
# --------------------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def receive(self, mode):
|
def receive(self, mode):
|
||||||
force = True
|
force = False
|
||||||
|
|
||||||
self.c_lib.freedv_open.restype = ctypes.POINTER(ctypes.c_ubyte)
|
self.c_lib.freedv_open.restype = ctypes.POINTER(ctypes.c_ubyte)
|
||||||
freedv = self.c_lib.freedv_open(mode)
|
freedv = self.c_lib.freedv_open(mode)
|
||||||
|
@ -328,7 +329,7 @@ class RF():
|
||||||
bytes_out = bytes_out() # get pointer to bytes_out
|
bytes_out = bytes_out() # get pointer to bytes_out
|
||||||
|
|
||||||
while static.FREEDV_RECEIVE == True:
|
while static.FREEDV_RECEIVE == True:
|
||||||
time.sleep(0.05)
|
time.sleep(0.01)
|
||||||
|
|
||||||
# stuck in sync counter
|
# stuck in sync counter
|
||||||
stuck_in_sync_counter = 0
|
stuck_in_sync_counter = 0
|
||||||
|
@ -354,16 +355,15 @@ class RF():
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
# refresh vars, so the correct parameters of the used mode are set
|
# refresh vars, so the correct parameters of the used mode are set
|
||||||
static.FREEDV_DATA_BYTES_PER_FRAME = bytes_per_frame
|
if mode == static.ARQ_DATA_CHANNEL_MODE:
|
||||||
static.FREEDV_DATA_PAYLOAD_PER_FRAME = bytes_per_frame - 2
|
static.FREEDV_DATA_BYTES_PER_FRAME = bytes_per_frame
|
||||||
|
static.FREEDV_DATA_PAYLOAD_PER_FRAME = bytes_per_frame - 2
|
||||||
|
|
||||||
nin = self.c_lib.freedv_nin(freedv)
|
nin = self.c_lib.freedv_nin(freedv)
|
||||||
#nin = int(nin*(static.AUDIO_SAMPLE_RATE_RX/static.MODEM_SAMPLE_RATE))
|
#nin = int(nin*(static.AUDIO_SAMPLE_RATE_RX/static.MODEM_SAMPLE_RATE))
|
||||||
|
|
||||||
data_in = self.stream_rx.read(nin, exception_on_overflow=False)
|
data_in = self.stream_rx.read(nin, exception_on_overflow=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static.AUDIO_RMS = audioop.rms(data_in, 2)
|
static.AUDIO_RMS = audioop.rms(data_in, 2)
|
||||||
# self.c_lib.freedv_rawdatarx.argtype = [ctypes.POINTER(ctypes.c_ubyte), data_bytes_out, data_in] # check if really neccessary
|
# self.c_lib.freedv_rawdatarx.argtype = [ctypes.POINTER(ctypes.c_ubyte), data_bytes_out, data_in] # check if really neccessary
|
||||||
nbytes = self.c_lib.freedv_rawdatarx(freedv, bytes_out, data_in) # demodulate audio
|
nbytes = self.c_lib.freedv_rawdatarx(freedv, bytes_out, data_in) # demodulate audio
|
||||||
|
@ -384,16 +384,17 @@ class RF():
|
||||||
stuck_in_sync_counter = 0
|
stuck_in_sync_counter = 0
|
||||||
stuck_in_sync_10_counter = 0
|
stuck_in_sync_10_counter = 0
|
||||||
|
|
||||||
if stuck_in_sync_counter >= 66 and stuck_in_sync_10_counter >= 2:
|
elif stuck_in_sync_counter >= 66 and stuck_in_sync_10_counter >= 2:
|
||||||
logging.critical("MODEM | stuck in sync #2")
|
logging.critical("MODEM | stuck in sync #2")
|
||||||
self.c_lib.freedv_set_sync(freedv, 0) # FORCE UNSYNC
|
self.c_lib.freedv_set_sync(freedv, 0) # FORCE UNSYNC
|
||||||
stuck_in_sync_counter = 0
|
stuck_in_sync_counter = 0
|
||||||
stuck_in_sync_10_counter = 0
|
stuck_in_sync_10_counter = 0
|
||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
#self.calculate_ber(freedv)
|
|
||||||
self.calculate_snr(freedv)
|
self.calculate_snr(freedv)
|
||||||
# forward data only if broadcast or we are the receiver
|
# forward data only if broadcast or we are the receiver
|
||||||
# bytes_out[1:2] == callsign check for signalling frames, bytes_out[6:7] == callsign check for data frames, bytes_out[1:2] == b'\x01' --> broadcasts like CQ
|
# bytes_out[1:2] == callsign check for signalling frames, bytes_out[6:7] == callsign check for data frames, bytes_out[1:2] == b'\x01' --> broadcasts like CQ
|
||||||
|
# we could also create an own function, which returns True. In this case we could add callsign blacklists and so on
|
||||||
if nbytes == bytes_per_frame and bytes(bytes_out[1:2]) == static.MYCALLSIGN_CRC8 or bytes(bytes_out[6:7]) == static.MYCALLSIGN_CRC8 or bytes(bytes_out[1:2]) == b'\x01':
|
if nbytes == bytes_per_frame and bytes(bytes_out[1:2]) == static.MYCALLSIGN_CRC8 or bytes(bytes_out[6:7]) == static.MYCALLSIGN_CRC8 or bytes(bytes_out[1:2]) == b'\x01':
|
||||||
self.calculate_ber(freedv)
|
self.calculate_ber(freedv)
|
||||||
self.calculate_snr(freedv)
|
self.calculate_snr(freedv)
|
||||||
|
@ -410,9 +411,6 @@ class RF():
|
||||||
|
|
||||||
#self.c_lib.freedv_set_frames_per_burst(freedv_data, n_frames_per_burst);
|
#self.c_lib.freedv_set_frames_per_burst(freedv_data, n_frames_per_burst);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if 50 >= frametype >= 10:
|
if 50 >= frametype >= 10:
|
||||||
if frame != 3 or force == True:
|
if frame != 3 or force == True:
|
||||||
|
|
||||||
|
@ -442,6 +440,11 @@ class RF():
|
||||||
logging.debug("REPEAT REQUEST RECEIVED....")
|
logging.debug("REPEAT REQUEST RECEIVED....")
|
||||||
data_handler.burst_rpt_received(bytes_out[:-2])
|
data_handler.burst_rpt_received(bytes_out[:-2])
|
||||||
|
|
||||||
|
# FRAME NAK
|
||||||
|
elif frametype == 63:
|
||||||
|
logging.debug("FRAME NAK RECEIVED....")
|
||||||
|
data_handler.frame_nack_received(bytes_out[:-2])
|
||||||
|
|
||||||
# CQ FRAME
|
# CQ FRAME
|
||||||
elif frametype == 200:
|
elif frametype == 200:
|
||||||
logging.debug("CQ RECEIVED....")
|
logging.debug("CQ RECEIVED....")
|
||||||
|
@ -532,4 +535,7 @@ class RF():
|
||||||
|
|
||||||
self.c_lib.freedv_get_modem_stats(freedv,byref(modem_stats_sync), byref(modem_stats_snr))
|
self.c_lib.freedv_get_modem_stats(freedv,byref(modem_stats_sync), byref(modem_stats_snr))
|
||||||
modem_stats_snr = modem_stats_snr.value
|
modem_stats_snr = modem_stats_snr.value
|
||||||
static.SNR = int(modem_stats_snr)
|
try:
|
||||||
|
static.SNR = int(modem_stats_snr)
|
||||||
|
except:
|
||||||
|
static.SNR = 0
|
||||||
|
|
Loading…
Reference in a new issue