Skip to content

Commit

Permalink
feat: Add close windows
Browse files Browse the repository at this point in the history
  • Loading branch information
JahazielLem committed Jan 20, 2025
1 parent c6cea72 commit 75d481a
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions catlora_sdr/catlora.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
DEFAULT_START_FERQ = 868
DEFAULT_END_FREQ = 928


class SpectrumScan:
def __init__(self):
self.catsniffer = Catsniffer()
Expand All @@ -25,18 +26,28 @@ def __init__(self):
self.start_freq = DEFAULT_START_FERQ
self.end_freq = DEFAULT_END_FREQ
self.num_ticks = 50
self.fig.canvas.mpl_connect("close_event", self.on_close)

def __data_dissector(self, plot_data):
raw_data = plot_data[len("@S"):-len("@E")]
raw_data = plot_data[len("@S") : -len("@E")]
freq, data = raw_data.split(";")
freq = float(freq)
if freq not in self.frequency_list:
self.frequency_list.append(freq)

data = list(map(int, data.split(",")[:-1]))
index = int(round((freq - self.start_freq) / (self.end_freq - self.start_freq) * (self.num_ticks*12 - 1)))
index = int(
round(
(freq - self.start_freq)
/ (self.end_freq - self.start_freq)
* (self.num_ticks * 12 - 1)
)
)
self.data_matrix[:, index] = data


def on_close(self, event):
self.recv_running = False

def stop_task(self):
self.recv_running = False

Expand All @@ -58,16 +69,21 @@ def recv_task(self):
self.__data_dissector(bytestream)

def create_plot(self):
self.ax.set_ylabel('RSSI [dBm]')
self.ax.set_xlabel('Frequency (Hz)')
self.ax.set_xlim(self.start_freq-5, self.end_freq)
self.ax.set_ylabel("RSSI [dBm]")
self.ax.set_xlabel("Frequency (Hz)")
self.ax.set_xlim(self.start_freq - 5, self.end_freq)
precise_ticks = np.linspace(self.start_freq, self.end_freq, self.num_ticks)
self.ax.set_xticks(precise_ticks)
self.ax.set_xticklabels([f"{tick:.1f}" for tick in precise_ticks], rotation=45)
self.ax.set_aspect('auto')
self.ax.set_aspect("auto")
self.fig.suptitle("Catsniffer LoRa Spectral Scan")
self.fig.canvas.manager.set_window_title("PWNLabs - ElectroniCats")
self.im = self.ax.imshow(self.data_matrix, cmap=DEFAULT_COLOR_MAP, aspect='auto', extent=[self.start_freq, self.end_freq, -4*34, DEFAULT_RSSI_OFFSET])
self.im = self.ax.imshow(
self.data_matrix,
cmap=DEFAULT_COLOR_MAP,
aspect="auto",
extent=[self.start_freq, self.end_freq, -4 * 34, DEFAULT_RSSI_OFFSET],
)
self.fig.colorbar(self.im)

def show_plot(self, i):
Expand All @@ -80,10 +96,11 @@ def main(self):
serial_path = self.catsniffer.find_catsniffer_serial_port()
print(serial_path)
self.catsniffer.set_serial_path(serial_path)
self.catsniffer.open()
recv_worker = threading.Thread(target=self.recv_task, daemon=True)
recv_worker.start()
self.create_plot()
ani = animation.FuncAnimation(self.fig, self.show_plot, interval=100)
animation.FuncAnimation(self.fig, self.show_plot, interval=100)
plt.show()
while self.recv_running:
time.sleep(0.1)
Expand All @@ -92,6 +109,7 @@ def main(self):
self.catsniffer.close()
print("Exited")


if __name__ == "__main__":
sc = SpectrumScan()
try:
Expand Down

0 comments on commit 75d481a

Please sign in to comment.