code cleanup

This commit is contained in:
DJ2LS 2021-03-07 16:24:09 +01:00 committed by GitHub
parent 0cbc70320b
commit c62ac5019e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 17 deletions

View file

@ -12,7 +12,6 @@ import argparse
import logging import logging
import threading import threading
import static import static
import helpers import helpers
@ -30,17 +29,17 @@ if __name__ == '__main__':
parser.add_argument('--rx', dest="audio_input_device", default=0, help="sound card for listening.", type=int) parser.add_argument('--rx', dest="audio_input_device", default=0, help="sound card for listening.", type=int)
parser.add_argument('--tx', dest="audio_output_device", default=0, help="sound card for transmitting.", type=int) parser.add_argument('--tx', dest="audio_output_device", default=0, help="sound card for transmitting.", type=int)
parser.add_argument('--port', dest="socket_port", default=3000, help="Set the port, the socket is listening on.", type=int) parser.add_argument('--port', dest="socket_port", default=3000, help="Set the port, the socket is listening on.", type=int)
parser.add_argument('--mode', dest="freedv_data_mode", default=12, help="Set the mode.", type=int) #parser.add_argument('--mode', dest="freedv_data_mode", default=12, help="Set the mode.", type=int)
args = parser.parse_args() args = parser.parse_args()
static.FREEDV_DATA_MODE = args.freedv_data_mode #static.FREEDV_DATA_MODE = args.freedv_data_mode
static.AUDIO_INPUT_DEVICE = args.audio_input_device static.AUDIO_INPUT_DEVICE = args.audio_input_device
static.AUDIO_OUTPUT_DEVICE = args.audio_output_device static.AUDIO_OUTPUT_DEVICE = args.audio_output_device
static.PORT = args.socket_port static.PORT = args.socket_port
#--------------------------------------------START CMD SERVER #--------------------------------------------START CMD SERVER
import sock # we need to wait until we got all parameters from argparse import sock # we need to wait until we got all parameters from argparse first before loading sock
cmd_server_thread = threading.Thread(target=sock.start_cmd_socket, name="cmd server") cmd_server_thread = threading.Thread(target=sock.start_cmd_socket, name="cmd server")
cmd_server_thread.start() cmd_server_thread.start()

View file

@ -281,10 +281,9 @@ class RF():
else: else:
pass pass
#vars()['food']
bytes_out = (ctypes.c_ubyte * bytes_per_frame) ################################################################## DATA BYTES PER FRAME SETZEN! bytes_out = (ctypes.c_ubyte * bytes_per_frame)
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:
@ -301,12 +300,11 @@ class RF():
#demod loop #demod loop
while (static.CHANNEL_STATE == 'RECEIVING_DATA' and static.ARQ_DATA_CHANNEL_MODE == mode) or (static.CHANNEL_STATE == 'RECEIVING_SIGNALLING' and static.FREEDV_SIGNALLING_MODE == mode): while (static.CHANNEL_STATE == 'RECEIVING_DATA' and static.ARQ_DATA_CHANNEL_MODE == mode) or (static.CHANNEL_STATE == 'RECEIVING_SIGNALLING' and static.FREEDV_SIGNALLING_MODE == mode):
time.sleep(0.01)
# refresh vars, so the correct parameters of the used mode are set
static.FREEDV_DATA_BYTES_PER_FRAME = bytes_per_frame static.FREEDV_DATA_BYTES_PER_FRAME = bytes_per_frame
static.FREEDV_DATA_PAYLOAD_PER_FRAME = bytes_per_frame - 2 static.FREEDV_DATA_PAYLOAD_PER_FRAME = bytes_per_frame - 2
time.sleep(0.01)
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)
@ -315,6 +313,7 @@ class RF():
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
#logging.debug(self.c_lib.freedv_get_rx_status(freedv)) #logging.debug(self.c_lib.freedv_get_rx_status(freedv))
#print("listening-" + str(mode) + "-" + str(self.c_lib.freedv_get_rx_status(freedv))) #print("listening-" + str(mode) + "-" + str(self.c_lib.freedv_get_rx_status(freedv)))
#-------------STUCK IN SYNC DETECTOR #-------------STUCK IN SYNC DETECTOR
stuck_in_sync_counter += 1 stuck_in_sync_counter += 1
if self.c_lib.freedv_get_rx_status(freedv) == 10: if self.c_lib.freedv_get_rx_status(freedv) == 10:
@ -338,10 +337,6 @@ class RF():
if nbytes == bytes_per_frame:##########################################################FREEDV_DATA_BYTES_PER_FRAME if nbytes == bytes_per_frame:##########################################################FREEDV_DATA_BYTES_PER_FRAME
self.calculate_ber(freedv) self.calculate_ber(freedv)
rxstatus = self.c_lib.freedv_get_rx_status(freedv)
#logging.debug("DATA-" + str(rxstatus))
# counter reset for stuck in sync counter # counter reset for stuck in sync counter
stuck_in_sync_counter = 0 stuck_in_sync_counter = 0
stuck_in_sync_10_counter = 0 stuck_in_sync_10_counter = 0
@ -429,9 +424,9 @@ class RF():
else: else:
logging.info("OTHER FRAME: " + str(bytes_out[:-2])) logging.info("OTHER FRAME: " + str(bytes_out[:-2]))
print(frametype) print(frametype)
# DO UNSYNC AFTER LAST BURST by checking the frame nums agains the total frames per burst # DO UNSYNC AFTER LAST BURST by checking the frame nums agains the total frames per burst
if frame == n_frames_per_burst: if frame == n_frames_per_burst:
logging.debug("LAST FRAME ---> UNSYNC") logging.debug("LAST FRAME ---> UNSYNC")
self.c_lib.freedv_set_sync(freedv, 0) #FORCE UNSYNC self.c_lib.freedv_set_sync(freedv, 0) #FORCE UNSYNC
@ -439,7 +434,7 @@ class RF():
#logging.info("DATA-" + str(mode) + " " +str(rxstatus)) #logging.info("DATA-" + str(mode) + " " +str(rxstatus))
if rxstatus == 10: if rxstatus == 10:
self.c_lib.freedv_set_sync(freedv, 0) #FORCE UNSYNC self.c_lib.freedv_set_sync(freedv, 0) #FORCE UNSYNC
print(" -SYNC 10- Trigger - M:" + str(mode)) logging.warning("MODEM | SYNC 10 TRIGGER | M:" + str(mode))
self.calculate_ber(freedv) self.calculate_ber(freedv)