From 25aa2dd624776f460c7424431b62958f9c524e3d Mon Sep 17 00:00:00 2001 From: David Doan Date: Thu, 14 Dec 2023 16:34:32 -0500 Subject: utils --- Sender.py | 3 ++- __pycache__/utils.cpython-38.pyc | Bin 0 -> 853 bytes utils.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 __pycache__/utils.cpython-38.pyc create mode 100644 utils.py diff --git a/Sender.py b/Sender.py index 7eab893..ca0183e 100644 --- a/Sender.py +++ b/Sender.py @@ -1,6 +1,7 @@ import numpy as np import pyaudio import threading +from utils import * """ Play a single frequency. @@ -201,7 +202,7 @@ send_thread = threading.Thread(target=link_layer.send_data) # Start the threads send_thread.start() -# take in range width, the number of bytes, and the bytes themsleve, and starting freq +# take in range width, the number of bytes, and the bytes themselves, and starting freq # cmdline args: data, start freq, bytes per transmit, frequency range # 18500, 1000 range diff --git a/__pycache__/utils.cpython-38.pyc b/__pycache__/utils.cpython-38.pyc new file mode 100644 index 0000000..ae3eb9b Binary files /dev/null and b/__pycache__/utils.cpython-38.pyc differ diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..ffa671f --- /dev/null +++ b/utils.py @@ -0,0 +1,31 @@ + +# given the cmdline arg, turns the byte sequencies into a list of frequencies, and vice versa + +# 1875 1924 +24, -25, range/2, 1, flipping new info 2 sending or not + + +def make_frequencies_map(start_freq, freq_step, byte_per_transmit, is_sender=True): + freq_list = [None] * (byte_per_transmit + 3) + sender_range = freq_step // 2 + plus_minus = sender_range // (byte_per_transmit + 3) + + for i in range(byte_per_transmit + 3): + freq_list[i] = start_freq + i * plus_minus + if not is_sender: + freq_list[i] += sender_range + + return freq_list + + +def frequencies_to_bytes(frequencies, start_freq, freq_step, byte_per_transmit, is_sender=True): + freq_list = make_frequencies_map(start_freq, freq_step, byte_per_transmit, is_sender) + byte_list = [None] * len(frequencies) + + sender_range = freq_step // 2 + plus_minus = sender_range // (byte_per_transmit + 3) + + for i in range(len(frequencies)): + byte_list[i] = 0 + if frequencies[i] <= freq_list[i] < frequencies[i] + plus_minus - 1: byte_list[i] = 1 + + return byte_list \ No newline at end of file -- cgit v1.2.3-70-g09d2