-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradio_controller.py
40 lines (29 loc) · 1.01 KB
/
radio_controller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import time
import serial.tools.list_ports
class RadioController:
def __init__(self, port):
self.port = port
self.ser = serial.Serial(port, 9600, timeout=1)
def send_command(self, command):
self.ser.write(command.encode())
time.sleep(0.1) # Wait for the radio to process the command
def read_cw_signal(self):
# Implement logic to read CW signal from the radio
# For example, read from serial port and interpret Morse code
cw_signal = (
self.ser.readline().decode().strip()
) # Example assuming Morse code is sent over serial
return cw_signal
def close(self):
self.ser.close()
class RadioFactory:
@staticmethod
def detect_radios():
return [
port.device
for port in serial.tools.list_ports.comports()
if "Icom" in port.description
]
@staticmethod
def create_radio(port):
return RadioController(port)