This commit is contained in:
Lev 2025-04-28 20:36:17 +00:00 committed by GitHub
commit 37bbf38ee4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 66 additions and 41 deletions

View file

@ -57,7 +57,7 @@ coming soon. This software is experimental and could have bugs. Bug reports and
5. Rename `example_config.ini`:
```sh
mv example_config.ini config.ini
cp example_config.ini config.ini
```
6. Set up the configuration in `config.ini`:

View file

@ -22,9 +22,17 @@ unack_lock = Lock()
message_counter = 1
message_lock = threading.Lock()
# Global flag to indicate shutdown
shutdown_event = threading.Event()
JSON_URL = "https://aprs-deviceid.aprsfoundation.org/tocalls.pretty.json"
def shutdown():
"""Signal the APRS loop to shut down."""
print("Shutdown signal received. Stopping APRS communications...")
shutdown_event.set()
def fetch_device_data():
local_file = "tocalls_cache.json"
@ -148,7 +156,11 @@ def start():
print(f"BBS Callsign: {my_callsign}")
while True:
for frame in ki.read(min_frames=1):
if shutdown_event.is_set():
print("Shutdown event set. Exiting APRS loop.")
ki.stop()
break
for frame in ki.read(min_frames=0):
try:
if config.RAW_PACKET_DISPLAY:
print(f"{COLOR_RAW}RAW PACKET:{COLOR_RESET} {frame}")

13
main.py
View file

@ -3,6 +3,9 @@ import aprs_comm
import threading
import time
import signal
import sys
def scheduled_cleanup():
"""Periodically run cleanup of expired bulletins."""
@ -14,6 +17,11 @@ def scheduled_cleanup():
print(f"Error during cleanup: {e}")
time.sleep(24 * 60 * 60) # Run cleanup every 24 hours
def signal_handler(signum, frame):
print(f"Received signal {signum}. Shutting down...")
aprs_comm.shutdown()
def main():
banner = """
\033[96m
@ -34,8 +42,13 @@ def main():
cleanup_thread = threading.Thread(target=scheduled_cleanup, daemon=True)
cleanup_thread.start()
print("Setting up signal handlers...")
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
signal.signal(signal.SIGTERM, signal_handler) # kill command
print("Starting APRS communications...")
aprs_comm.start()
return 0
if __name__ == "__main__":
main()