aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Doan <daviddoan@Davids-MacBook-Pro-193.local>2023-12-14 16:34:32 -0500
committerDavid Doan <daviddoan@Davids-MacBook-Pro-193.local>2023-12-14 16:34:32 -0500
commit25aa2dd624776f460c7424431b62958f9c524e3d (patch)
treee65c46f8d9e4fbb06f52cfdc36d6fb764e098e80
parent84127ddc9ca0d6fcee3fadc15c6ed137e380689b (diff)
utils
-rw-r--r--Sender.py3
-rw-r--r--__pycache__/utils.cpython-38.pycbin0 -> 853 bytes
-rw-r--r--utils.py31
3 files changed, 33 insertions, 1 deletions
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
--- /dev/null
+++ b/__pycache__/utils.cpython-38.pyc
Binary files 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