Skip to content

Commit

Permalink
Trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
PartTimeLegend committed Apr 12, 2024
1 parent 5ecbba3 commit 5355796
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 70 deletions.
9 changes: 9 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
tmp
2 changes: 2 additions & 0 deletions .trunk/configs/.isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile=black
2 changes: 2 additions & 0 deletions .trunk/configs/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prettier friendly markdownlint config (all formatting rules disabled)
extends: markdownlint/style/prettier
7 changes: 7 additions & 0 deletions .trunk/configs/.yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
5 changes: 5 additions & 0 deletions .trunk/configs/ruff.toml
Original file line number Diff line number Diff line change
@@ -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"]
38 changes: 38 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 7 additions & 6 deletions cw_message_sender.py
Original file line number Diff line number Diff line change
@@ -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;")
21 changes: 13 additions & 8 deletions cw_message_sender_factory.py
Original file line number Diff line number Diff line change
@@ -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
]
59 changes: 32 additions & 27 deletions main.py
Original file line number Diff line number Diff line change
@@ -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.")
69 changes: 40 additions & 29 deletions radio_controller.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 5355796

Please sign in to comment.