diff --git a/.trunk/.gitignore b/.trunk/.gitignore new file mode 100644 index 0000000..15966d0 --- /dev/null +++ b/.trunk/.gitignore @@ -0,0 +1,9 @@ +*out +*logs +*actions +*notifications +*tools +plugins +user_trunk.yaml +user.yaml +tmp diff --git a/.trunk/configs/.isort.cfg b/.trunk/configs/.isort.cfg new file mode 100644 index 0000000..b9fb3f3 --- /dev/null +++ b/.trunk/configs/.isort.cfg @@ -0,0 +1,2 @@ +[settings] +profile=black diff --git a/.trunk/configs/.markdownlint.yaml b/.trunk/configs/.markdownlint.yaml new file mode 100644 index 0000000..b40ee9d --- /dev/null +++ b/.trunk/configs/.markdownlint.yaml @@ -0,0 +1,2 @@ +# Prettier friendly markdownlint config (all formatting rules disabled) +extends: markdownlint/style/prettier diff --git a/.trunk/configs/.yamllint.yaml b/.trunk/configs/.yamllint.yaml new file mode 100644 index 0000000..184e251 --- /dev/null +++ b/.trunk/configs/.yamllint.yaml @@ -0,0 +1,7 @@ +rules: + quoted-strings: + required: only-when-needed + extra-allowed: ["{|}"] + key-duplicates: {} + octal-values: + forbid-implicit-octal: true diff --git a/.trunk/configs/ruff.toml b/.trunk/configs/ruff.toml new file mode 100644 index 0000000..f5a235c --- /dev/null +++ b/.trunk/configs/ruff.toml @@ -0,0 +1,5 @@ +# Generic, formatter-friendly config. +select = ["B", "D3", "E", "F"] + +# Never enforce `E501` (line length violations). This should be handled by formatters. +ignore = ["E501"] diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml new file mode 100644 index 0000000..0d84f44 --- /dev/null +++ b/.trunk/trunk.yaml @@ -0,0 +1,38 @@ +# This file controls the behavior of Trunk: https://docs.trunk.io/cli +# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml +version: 0.1 +cli: + version: 1.21.0 +# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins) +plugins: + sources: + - id: trunk + ref: v1.4.5 + uri: https://github.com/trunk-io/plugins +# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) +runtimes: + enabled: + - node@18.12.1 + - python@3.10.8 +# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration) +lint: + enabled: + - actionlint@1.6.27 + - bandit@1.7.8 + - black@24.3.0 + - checkov@3.2.60 + - git-diff-check + - isort@5.13.2 + - markdownlint@0.39.0 + - osv-scanner@1.7.0 + - prettier@3.2.5 + - ruff@0.3.5 + - trivy@0.50.1 + - trufflehog@3.71.0 + - yamllint@1.35.1 +actions: + enabled: + - trunk-announce + - trunk-check-pre-push + - trunk-fmt-pre-commit + - trunk-upgrade-available diff --git a/cw_message_sender.py b/cw_message_sender.py index 132e2b7..a13adfa 100644 --- a/cw_message_sender.py +++ b/cw_message_sender.py @@ -1,6 +1,7 @@ -class CWMessageSender: - def __init__(self, radio_controller): - self.radio_controller = radio_controller - - def send_cw_message(self, message): - self.radio_controller.send_command(f'KYR1;TX2;MN080;{message};MN255;KYR0;') +class CWMessageSender: + + def __init__(self, radio_controller): + self.radio_controller = radio_controller + + def send_cw_message(self, message): + self.radio_controller.send_command(f"KYR1;TX2;MN080;{message};MN255;KYR0;") diff --git a/cw_message_sender_factory.py b/cw_message_sender_factory.py index e29855f..acf0f16 100644 --- a/cw_message_sender_factory.py +++ b/cw_message_sender_factory.py @@ -1,8 +1,13 @@ -from cw_message_sender import CWMessageSender -from radio_controller import RadioFactory - -class CWMessageSenderFactory: - @staticmethod - def create_cw_message_senders(): - available_radios = RadioFactory.detect_radios() - return [CWMessageSender(RadioFactory.create_radio(port)) for port in available_radios] +from cw_message_sender import CWMessageSender +from radio_controller import RadioFactory + + +class CWMessageSenderFactory: + + @staticmethod + def create_cw_message_senders(): + available_radios = RadioFactory.detect_radios() + return [ + CWMessageSender(RadioFactory.create_radio(port)) + for port in available_radios + ] diff --git a/main.py b/main.py index 72c74e1..0cecb65 100644 --- a/main.py +++ b/main.py @@ -1,27 +1,32 @@ -from cw_message_sender_factory import CWMessageSenderFactory - -if __name__ == "__main__": - cw_senders = CWMessageSenderFactory.create_cw_message_senders() - - if cw_senders: - try: - while True: - message = input("Enter CW message to send (or type 'exit' to quit): ") - if message.lower() == 'exit': - break - - for cw_sender in cw_senders: - cw_sender.send_cw_message(message) - - # Read CW signals - for cw_sender in cw_senders: - cw_signal = cw_sender.radio_controller.read_cw_signal() - print("Received CW signal from", cw_sender.radio_controller.port, ":", cw_signal) - - except KeyboardInterrupt: - pass - finally: - for cw_sender in cw_senders: - cw_sender.radio_controller.close() - else: - print("No Icom radios detected.") +from cw_message_sender_factory import CWMessageSenderFactory + +if __name__ == "__main__": + cw_senders = CWMessageSenderFactory.create_cw_message_senders() + + if cw_senders: + try: + while True: + message = input("Enter CW message to send (or type 'exit' to quit): ") + if message.lower() == "exit": + break + + for cw_sender in cw_senders: + cw_sender.send_cw_message(message) + + # Read CW signals + for cw_sender in cw_senders: + cw_signal = cw_sender.radio_controller.read_cw_signal() + print( + "Received CW signal from", + cw_sender.radio_controller.port, + ":", + cw_signal, + ) + + except KeyboardInterrupt: + pass + finally: + for cw_sender in cw_senders: + cw_sender.radio_controller.close() + else: + print("No Icom radios detected.") diff --git a/radio_controller.py b/radio_controller.py index e1335a3..37a0d8e 100644 --- a/radio_controller.py +++ b/radio_controller.py @@ -1,29 +1,40 @@ -import serial.tools.list_ports -import time - -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) +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)