mirror of
https://github.com/craigerl/aprsd.git
synced 2024-11-25 01:18:43 -05:00
Compare commits
No commits in common. "8cdbf18befd709a88100934cce953572b3a5f473" and "758007ea3ff809944f9ed4685c74e7eaff0f813b" have entirely different histories.
8cdbf18bef
...
758007ea3f
2
Makefile
2
Makefile
@ -24,7 +24,7 @@ run: venv ## Create a virtual environment for running aprsd commands
|
|||||||
|
|
||||||
changelog: dev
|
changelog: dev
|
||||||
npm i -g auto-changelog
|
npm i -g auto-changelog
|
||||||
auto-changelog -l false --sort-commits date -o ChangeLog.md
|
auto-changelog -l false -o ChangeLog.md
|
||||||
|
|
||||||
docs: changelog
|
docs: changelog
|
||||||
m2r --overwrite ChangeLog.md
|
m2r --overwrite ChangeLog.md
|
||||||
|
@ -33,11 +33,7 @@ class Aprsdis(aprslib.IS):
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.thread_stop = True
|
self.thread_stop = True
|
||||||
LOG.warning("Shutdown Aprsdis client.")
|
LOG.info("Shutdown Aprsdis client.")
|
||||||
|
|
||||||
def close(self):
|
|
||||||
LOG.warning("Closing Aprsdis client.")
|
|
||||||
super().close()
|
|
||||||
|
|
||||||
@wrapt.synchronized(lock)
|
@wrapt.synchronized(lock)
|
||||||
def send(self, packet: core.Packet):
|
def send(self, packet: core.Packet):
|
||||||
|
@ -42,8 +42,7 @@ def signal_handler(sig, frame):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
# Last save to disk
|
LOG.info(collector.Collector().collect())
|
||||||
collector.Collector().collect()
|
|
||||||
|
|
||||||
|
|
||||||
class APRSDListenThread(rx.APRSDRXThread):
|
class APRSDListenThread(rx.APRSDRXThread):
|
||||||
|
@ -64,7 +64,7 @@ def signal_handler(sig, frame):
|
|||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
# packets.WatchList().save()
|
# packets.WatchList().save()
|
||||||
# packets.SeenList().save()
|
# packets.SeenList().save()
|
||||||
stats.stats_collector.collect()
|
LOG.info(stats.stats_collector.collect())
|
||||||
LOG.info("Telling flask to bail.")
|
LOG.info("Telling flask to bail.")
|
||||||
signal.signal(signal.SIGTERM, sys.exit(0))
|
signal.signal(signal.SIGTERM, sys.exit(0))
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ def signal_handler(sig, frame):
|
|||||||
packets.WatchList().save()
|
packets.WatchList().save()
|
||||||
packets.SeenList().save()
|
packets.SeenList().save()
|
||||||
packets.PacketList().save()
|
packets.PacketList().save()
|
||||||
collector.Collector().collect()
|
LOG.info(collector.Collector().collect())
|
||||||
# signal.signal(signal.SIGTERM, sys.exit(0))
|
# signal.signal(signal.SIGTERM, sys.exit(0))
|
||||||
# sys.exit(0)
|
# sys.exit(0)
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from geopy.distance import geodesic
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from aprsd import utils
|
from aprsd.packets.core import AckPacket, RejectPacket
|
||||||
from aprsd.packets.core import AckPacket, GPSPacket, RejectPacket
|
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger()
|
LOG = logging.getLogger()
|
||||||
@ -18,8 +16,6 @@ TO_COLOR = "fg #D033FF"
|
|||||||
TX_COLOR = "red"
|
TX_COLOR = "red"
|
||||||
RX_COLOR = "green"
|
RX_COLOR = "green"
|
||||||
PACKET_COLOR = "cyan"
|
PACKET_COLOR = "cyan"
|
||||||
DISTANCE_COLOR = "fg #FF5733"
|
|
||||||
DEGREES_COLOR = "fg #FFA900"
|
|
||||||
|
|
||||||
|
|
||||||
def log_multiline(packet, tx: Optional[bool] = False, header: Optional[bool] = True) -> None:
|
def log_multiline(packet, tx: Optional[bool] = False, header: Optional[bool] = True) -> None:
|
||||||
@ -101,21 +97,19 @@ def log(packet, tx: Optional[bool] = False, header: Optional[bool] = True) -> No
|
|||||||
if header:
|
if header:
|
||||||
if tx:
|
if tx:
|
||||||
via_color = "red"
|
via_color = "red"
|
||||||
# arrow = f"<{via_color}>-></{via_color}>"
|
arrow = f"<{via_color}>-></{via_color}>"
|
||||||
arrow = f"<{via_color}>\u2192</{via_color}>"
|
|
||||||
logit.append(
|
logit.append(
|
||||||
f"<red>TX\u2191</red> "
|
f"<red>TX {arrow}</red> "
|
||||||
f"<cyan>{name}</cyan>"
|
f"<cyan>{name}</cyan>"
|
||||||
f":{packet.msgNo}"
|
f":{packet.msgNo}"
|
||||||
f" ({packet.send_count + 1} of {pkt_max_send_count})",
|
f" ({packet.send_count + 1} of {pkt_max_send_count})",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
via_color = "fg #1AA730"
|
via_color = "fg #828282"
|
||||||
#arrow = f"<{via_color}>-></{via_color}>"
|
arrow = f"<{via_color}>-></{via_color}>"
|
||||||
arrow = f"<{via_color}>\u2192</{via_color}>"
|
left_arrow = f"<{via_color}><-</{via_color}>"
|
||||||
f"<{via_color}><-</{via_color}>"
|
|
||||||
logit.append(
|
logit.append(
|
||||||
f"<fg #1AA730>RX\u2193</fg #1AA730> "
|
f"<fg #1AA730>RX</fg #1AA730> {left_arrow} "
|
||||||
f"<cyan>{name}</cyan>"
|
f"<cyan>{name}</cyan>"
|
||||||
f":{packet.msgNo}",
|
f":{packet.msgNo}",
|
||||||
)
|
)
|
||||||
@ -145,19 +139,5 @@ def log(packet, tx: Optional[bool] = False, header: Optional[bool] = True) -> No
|
|||||||
msg = msg.replace("<", "\\<")
|
msg = msg.replace("<", "\\<")
|
||||||
logit.append(f"<light-yellow><b>{msg}</b></light-yellow>")
|
logit.append(f"<light-yellow><b>{msg}</b></light-yellow>")
|
||||||
|
|
||||||
# is there distance information?
|
|
||||||
if isinstance(packet, GPSPacket) and CONF.latitude and CONF.longitude:
|
|
||||||
my_coords = (CONF.latitude, CONF.longitude)
|
|
||||||
packet_coords = (packet.latitude, packet.longitude)
|
|
||||||
try:
|
|
||||||
bearing = utils.calculate_initial_compass_bearing(my_coords, packet_coords)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"Failed to calculate bearing: {e}")
|
|
||||||
bearing = 0
|
|
||||||
logit.append(
|
|
||||||
f" : <{DEGREES_COLOR}>{utils.degrees_to_cardinal(bearing, full_string=True)}</{DEGREES_COLOR}>"
|
|
||||||
f"<{DISTANCE_COLOR}>@{geodesic(my_coords, packet_coords).miles:.2f}miles</{DISTANCE_COLOR}>",
|
|
||||||
)
|
|
||||||
|
|
||||||
LOGU.opt(colors=True).info(" ".join(logit))
|
LOGU.opt(colors=True).info(" ".join(logit))
|
||||||
log_multiline(packet, tx, header)
|
log_multiline(packet, tx, header)
|
||||||
|
@ -3,7 +3,6 @@ import logging
|
|||||||
import time
|
import time
|
||||||
import tracemalloc
|
import tracemalloc
|
||||||
|
|
||||||
from loguru import logger
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from aprsd import packets, utils
|
from aprsd import packets, utils
|
||||||
@ -15,7 +14,6 @@ from aprsd.threads import APRSDThread, APRSDThreadList
|
|||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
LOGU = logger
|
|
||||||
|
|
||||||
|
|
||||||
class KeepAliveThread(APRSDThread):
|
class KeepAliveThread(APRSDThread):
|
||||||
@ -89,12 +87,7 @@ class KeepAliveThread(APRSDThread):
|
|||||||
key = thread["name"]
|
key = thread["name"]
|
||||||
if not alive:
|
if not alive:
|
||||||
LOG.error(f"Thread {thread}")
|
LOG.error(f"Thread {thread}")
|
||||||
|
LOG.info(f"{key: <15} Alive? {str(alive): <5} {str(age): <20}")
|
||||||
thread_hex = f"fg {utils.hex_from_name(key)}"
|
|
||||||
t_name = f"<{thread_hex}>{key:<15}</{thread_hex}>"
|
|
||||||
thread_msg = f"{t_name} Alive? {str(alive): <5} {str(age): <20}"
|
|
||||||
LOGU.opt(colors=True).info(thread_msg)
|
|
||||||
# LOG.info(f"{key: <15} Alive? {str(alive): <5} {str(age): <20}")
|
|
||||||
|
|
||||||
# check the APRS connection
|
# check the APRS connection
|
||||||
cl = client_factory.create()
|
cl = client_factory.create()
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import errno
|
import errno
|
||||||
import functools
|
import functools
|
||||||
import math
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
@ -83,16 +82,6 @@ def rgb_from_name(name):
|
|||||||
return red, green, blue
|
return red, green, blue
|
||||||
|
|
||||||
|
|
||||||
def hextriplet(colortuple):
|
|
||||||
"""Convert a color tuple to a hex triplet."""
|
|
||||||
return "#" + "".join(f"{i:02X}" for i in colortuple)
|
|
||||||
|
|
||||||
|
|
||||||
def hex_from_name(name):
|
|
||||||
"""Create a hex color from a string."""
|
|
||||||
return hextriplet(rgb_from_name(name))
|
|
||||||
|
|
||||||
|
|
||||||
def human_size(bytes, units=None):
|
def human_size(bytes, units=None):
|
||||||
"""Returns a human readable string representation of bytes"""
|
"""Returns a human readable string representation of bytes"""
|
||||||
if not units:
|
if not units:
|
||||||
@ -172,47 +161,3 @@ def load_entry_points(group):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Extension {ep.name} of group {group} failed to load with {e}", file=sys.stderr)
|
print(f"Extension {ep.name} of group {group} failed to load with {e}", file=sys.stderr)
|
||||||
print(traceback.format_exc(), file=sys.stderr)
|
print(traceback.format_exc(), file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def calculate_initial_compass_bearing(start, end):
|
|
||||||
if (type(start) != tuple) or (type(end) != tuple):
|
|
||||||
raise TypeError("Only tuples are supported as arguments")
|
|
||||||
|
|
||||||
lat1 = math.radians(float(start[0]))
|
|
||||||
lat2 = math.radians(float(end[0]))
|
|
||||||
|
|
||||||
diffLong = math.radians(float(end[1]) - float(start[1]))
|
|
||||||
|
|
||||||
x = math.sin(diffLong) * math.cos(lat2)
|
|
||||||
y = math.cos(lat1) * math.sin(lat2) - (
|
|
||||||
math.sin(lat1)
|
|
||||||
* math.cos(lat2) * math.cos(diffLong)
|
|
||||||
)
|
|
||||||
|
|
||||||
initial_bearing = math.atan2(x, y)
|
|
||||||
|
|
||||||
# Now we have the initial bearing but math.atan2 return values
|
|
||||||
# from -180° to + 180° which is not what we want for a compass bearing
|
|
||||||
# The solution is to normalize the initial bearing as shown below
|
|
||||||
initial_bearing = math.degrees(initial_bearing)
|
|
||||||
compass_bearing = (initial_bearing + 360) % 360
|
|
||||||
|
|
||||||
return compass_bearing
|
|
||||||
|
|
||||||
|
|
||||||
def degrees_to_cardinal(bearing, full_string=False):
|
|
||||||
if full_string:
|
|
||||||
DIRECTIONS = [
|
|
||||||
"North", "North-Northeast", "Northeast", "East-Northeast", "East", "East-Southeast",
|
|
||||||
"Southeast", "South-Southeast", "South", "South-Southwest", "Southwest", "West-Southwest",
|
|
||||||
"West", "West-Northwest", "Northwest", "North-Northwest", "North",
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
DIRECTIONS = [
|
|
||||||
"N", "NNE", "NE", "ENE", "E", "ESE",
|
|
||||||
"SE", "SSE", "S", "SSW", "SW", "WSW",
|
|
||||||
"W", "WNW", "NW", "NNW", "N",
|
|
||||||
]
|
|
||||||
|
|
||||||
cardinal = DIRECTIONS[round(bearing / 22.5)]
|
|
||||||
return cardinal
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM python:3.11-slim AS build
|
FROM python:3.11-slim as build
|
||||||
|
|
||||||
ARG VERSION=3.4.0
|
ARG VERSION=3.4.0
|
||||||
# pass this in as 'dev' if you want to install from github repo vs pypi
|
# pass this in as 'dev' if you want to install from github repo vs pypi
|
||||||
@ -40,7 +40,7 @@ RUN set -ex \
|
|||||||
|
|
||||||
|
|
||||||
### Final stage
|
### Final stage
|
||||||
FROM build AS install
|
FROM build as final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN pip3 install -U pip
|
RUN pip3 install -U pip
|
||||||
@ -64,8 +64,6 @@ RUN aprsd --version
|
|||||||
ADD bin/setup.sh /app
|
ADD bin/setup.sh /app
|
||||||
ADD bin/admin.sh /app
|
ADD bin/admin.sh /app
|
||||||
|
|
||||||
|
|
||||||
FROM install AS final
|
|
||||||
# For the web admin interface
|
# For the web admin interface
|
||||||
EXPOSE 8001
|
EXPOSE 8001
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user