mirror of
https://github.com/craigerl/aprsd.git
synced 2025-07-17 07:45:16 -04:00
Make sure packet has addressee field
Before dereferencing it in the rx thread. This covers the case for an Unknown Packet
This commit is contained in:
parent
1ae437581f
commit
034f11b4f9
@ -674,7 +674,7 @@ class ThirdPartyPacket(Packet, DataClassJsonMixin):
|
||||
|
||||
@dataclass_json(undefined=Undefined.INCLUDE)
|
||||
@dataclass(unsafe_hash=True)
|
||||
class UnknownPacket:
|
||||
class UnknownPacket(Packet):
|
||||
"""Catchall Packet for things we don't know about.
|
||||
|
||||
All of the unknown attributes are stored in the unknown_fields
|
||||
|
@ -12,13 +12,13 @@ LOG = logging.getLogger()
|
||||
LOGU = logger
|
||||
CONF = cfg.CONF
|
||||
|
||||
FROM_COLOR = "fg #C70039"
|
||||
TO_COLOR = "fg #D033FF"
|
||||
TX_COLOR = "red"
|
||||
RX_COLOR = "green"
|
||||
PACKET_COLOR = "cyan"
|
||||
DISTANCE_COLOR = "fg #FF5733"
|
||||
DEGREES_COLOR = "fg #FFA900"
|
||||
FROM_COLOR = 'fg #C70039'
|
||||
TO_COLOR = 'fg #D033FF'
|
||||
TX_COLOR = 'red'
|
||||
RX_COLOR = 'green'
|
||||
PACKET_COLOR = 'cyan'
|
||||
DISTANCE_COLOR = 'fg #FF5733'
|
||||
DEGREES_COLOR = 'fg #FFA900'
|
||||
|
||||
|
||||
def log_multiline(
|
||||
@ -27,11 +27,11 @@ def log_multiline(
|
||||
"""LOG a packet to the logfile."""
|
||||
if not CONF.enable_packet_logging:
|
||||
return
|
||||
if CONF.log_packet_format == "compact":
|
||||
if CONF.log_packet_format == 'compact':
|
||||
return
|
||||
|
||||
# asdict(packet)
|
||||
logit = ["\n"]
|
||||
logit = ['\n']
|
||||
name = packet.__class__.__name__
|
||||
|
||||
if isinstance(packet, AckPacket):
|
||||
@ -41,57 +41,67 @@ def log_multiline(
|
||||
|
||||
if header:
|
||||
if tx:
|
||||
header_str = f"<{TX_COLOR}>TX</{TX_COLOR}>"
|
||||
header_str = f'<{TX_COLOR}>TX</{TX_COLOR}>'
|
||||
logit.append(
|
||||
f"{header_str}________(<{PACKET_COLOR}>{name}</{PACKET_COLOR}> "
|
||||
f"TX:{packet.send_count + 1} of {pkt_max_send_count}",
|
||||
f'{header_str}________(<{PACKET_COLOR}>{name}</{PACKET_COLOR}> '
|
||||
f'TX:{packet.send_count + 1} of {pkt_max_send_count}',
|
||||
)
|
||||
else:
|
||||
header_str = f"<{RX_COLOR}>RX</{RX_COLOR}>"
|
||||
header_str = f'<{RX_COLOR}>RX</{RX_COLOR}>'
|
||||
logit.append(
|
||||
f"{header_str}________(<{PACKET_COLOR}>{name}</{PACKET_COLOR}>)",
|
||||
f'{header_str}________(<{PACKET_COLOR}>{name}</{PACKET_COLOR}>)',
|
||||
)
|
||||
|
||||
else:
|
||||
header_str = ""
|
||||
logit.append(f"__________(<{PACKET_COLOR}>{name}</{PACKET_COLOR}>)")
|
||||
header_str = ''
|
||||
logit.append(f'__________(<{PACKET_COLOR}>{name}</{PACKET_COLOR}>)')
|
||||
# log_list.append(f" Packet : {packet.__class__.__name__}")
|
||||
if packet.msgNo:
|
||||
logit.append(f" Msg # : {packet.msgNo}")
|
||||
logit.append(f' Msg # : {packet.msgNo}')
|
||||
if packet.from_call:
|
||||
logit.append(f" From : <{FROM_COLOR}>{packet.from_call}</{FROM_COLOR}>")
|
||||
logit.append(f' From : <{FROM_COLOR}>{packet.from_call}</{FROM_COLOR}>')
|
||||
if packet.to_call:
|
||||
logit.append(f" To : <{TO_COLOR}>{packet.to_call}</{TO_COLOR}>")
|
||||
if hasattr(packet, "path") and packet.path:
|
||||
logit.append(f" Path : {'=>'.join(packet.path)}")
|
||||
if hasattr(packet, "via") and packet.via:
|
||||
logit.append(f" VIA : {packet.via}")
|
||||
logit.append(f' To : <{TO_COLOR}>{packet.to_call}</{TO_COLOR}>')
|
||||
if hasattr(packet, 'path') and packet.path:
|
||||
logit.append(f' Path : {"=>".join(packet.path)}')
|
||||
if hasattr(packet, 'via') and packet.via:
|
||||
logit.append(f' VIA : {packet.via}')
|
||||
|
||||
if not isinstance(packet, AckPacket) and not isinstance(packet, RejectPacket):
|
||||
msg = packet.human_info
|
||||
|
||||
if msg:
|
||||
msg = msg.replace("<", "\\<")
|
||||
logit.append(f" Info : <light-yellow><b>{msg}</b></light-yellow>")
|
||||
msg = msg.replace('<', '\\<')
|
||||
logit.append(f' Info : <light-yellow><b>{msg}</b></light-yellow>')
|
||||
|
||||
if hasattr(packet, "comment") and packet.comment:
|
||||
logit.append(f" Comment : {packet.comment}")
|
||||
if hasattr(packet, 'comment') and packet.comment:
|
||||
logit.append(f' Comment : {packet.comment}')
|
||||
|
||||
raw = packet.raw.replace("<", "\\<")
|
||||
logit.append(f" Raw : <fg #828282>{raw}</fg #828282>")
|
||||
logit.append(f"{header_str}________(<{PACKET_COLOR}>{name}</{PACKET_COLOR}>)")
|
||||
raw = packet.raw.replace('<', '\\<')
|
||||
logit.append(f' Raw : <fg #828282>{raw}</fg #828282>')
|
||||
logit.append(f'{header_str}________(<{PACKET_COLOR}>{name}</{PACKET_COLOR}>)')
|
||||
|
||||
LOGU.opt(colors=True).info("\n".join(logit))
|
||||
LOGU.opt(colors=True).info('\n'.join(logit))
|
||||
LOG.debug(repr(packet))
|
||||
|
||||
|
||||
def log(packet, tx: Optional[bool] = False, header: Optional[bool] = True) -> None:
|
||||
def log(
|
||||
packet,
|
||||
tx: Optional[bool] = False,
|
||||
header: Optional[bool] = True,
|
||||
packet_count: Optional[int] = None,
|
||||
) -> None:
|
||||
if not CONF.enable_packet_logging:
|
||||
return
|
||||
if CONF.log_packet_format == "multiline":
|
||||
if CONF.log_packet_format == 'multiline':
|
||||
log_multiline(packet, tx, header)
|
||||
return
|
||||
|
||||
if not packet_count:
|
||||
packet_count = ''
|
||||
else:
|
||||
packet_count = f'({packet_count:d})'
|
||||
|
||||
logit = []
|
||||
name = packet.__class__.__name__
|
||||
if isinstance(packet, AckPacket):
|
||||
@ -101,47 +111,47 @@ def log(packet, tx: Optional[bool] = False, header: Optional[bool] = True) -> No
|
||||
|
||||
if header:
|
||||
if tx:
|
||||
via_color = "red"
|
||||
arrow = f"<{via_color}>\u2192</{via_color}>"
|
||||
via_color = 'red'
|
||||
arrow = f'<{via_color}>\u2192</{via_color}>'
|
||||
logit.append(
|
||||
f"<red>TX\u2191</red> "
|
||||
f"<cyan>{name}</cyan>"
|
||||
f":{packet.msgNo}"
|
||||
f" ({packet.send_count + 1} of {pkt_max_send_count})",
|
||||
f'<red>TX{packet_count}\u2191</red> '
|
||||
f'<cyan>{name}</cyan>'
|
||||
f':{packet.msgNo}'
|
||||
f' ({packet.send_count + 1} of {pkt_max_send_count})',
|
||||
)
|
||||
else:
|
||||
via_color = "fg #1AA730"
|
||||
arrow = f"<{via_color}>\u2192</{via_color}>"
|
||||
f"<{via_color}><-</{via_color}>"
|
||||
via_color = 'fg #1AA730'
|
||||
arrow = f'<{via_color}>\u2192</{via_color}>'
|
||||
f'<{via_color}><-</{via_color}>'
|
||||
logit.append(
|
||||
f"<fg #1AA730>RX\u2193</fg #1AA730> "
|
||||
f"<cyan>{name}</cyan>"
|
||||
f":{packet.msgNo}",
|
||||
f'<fg #1AA730>RX{packet_count}\u2193</fg #1AA730> '
|
||||
f'<cyan>{name}</cyan>'
|
||||
f':{packet.msgNo}',
|
||||
)
|
||||
else:
|
||||
via_color = "green"
|
||||
arrow = f"<{via_color}>-></{via_color}>"
|
||||
via_color = 'green'
|
||||
arrow = f'<{via_color}>-></{via_color}>'
|
||||
logit.append(
|
||||
f"<cyan>{name}</cyan>" f":{packet.msgNo}",
|
||||
f'<cyan>{name}</cyan>:{packet.msgNo}',
|
||||
)
|
||||
|
||||
tmp = None
|
||||
if packet.path:
|
||||
tmp = f"{arrow}".join(packet.path) + f"{arrow} "
|
||||
tmp = f'{arrow}'.join(packet.path) + f'{arrow} '
|
||||
|
||||
logit.append(
|
||||
f"<{FROM_COLOR}>{packet.from_call}</{FROM_COLOR}> {arrow}"
|
||||
f"{tmp if tmp else ' '}"
|
||||
f"<{TO_COLOR}>{packet.to_call}</{TO_COLOR}>",
|
||||
f'<{FROM_COLOR}>{packet.from_call}</{FROM_COLOR}> {arrow}'
|
||||
f'{tmp if tmp else " "}'
|
||||
f'<{TO_COLOR}>{packet.to_call}</{TO_COLOR}>',
|
||||
)
|
||||
|
||||
if not isinstance(packet, AckPacket) and not isinstance(packet, RejectPacket):
|
||||
logit.append(":")
|
||||
logit.append(':')
|
||||
msg = packet.human_info
|
||||
|
||||
if msg:
|
||||
msg = msg.replace("<", "\\<")
|
||||
logit.append(f"<light-yellow><b>{msg}</b></light-yellow>")
|
||||
msg = msg.replace('<', '\\<')
|
||||
logit.append(f'<light-yellow><b>{msg}</b></light-yellow>')
|
||||
|
||||
# is there distance information?
|
||||
if isinstance(packet, GPSPacket) and CONF.latitude and CONF.longitude:
|
||||
@ -150,12 +160,12 @@ def log(packet, tx: Optional[bool] = False, header: Optional[bool] = True) -> No
|
||||
try:
|
||||
bearing = utils.calculate_initial_compass_bearing(my_coords, packet_coords)
|
||||
except Exception as e:
|
||||
LOG.error(f"Failed to calculate bearing: {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}>@{haversine(my_coords, packet_coords, unit=Unit.MILES):.2f}miles</{DISTANCE_COLOR}>",
|
||||
f' : <{DEGREES_COLOR}>{utils.degrees_to_cardinal(bearing, full_string=True)}</{DEGREES_COLOR}>'
|
||||
f'<{DISTANCE_COLOR}>@{haversine(my_coords, packet_coords, unit=Unit.MILES):.2f}miles</{DISTANCE_COLOR}>',
|
||||
)
|
||||
|
||||
LOGU.opt(colors=True).info(" ".join(logit))
|
||||
LOGU.opt(colors=True).info(' '.join(logit))
|
||||
log_multiline(packet, tx, header)
|
||||
|
@ -32,6 +32,8 @@ class APRSDRXThread(APRSDThread):
|
||||
# getting blocked by the APRS server trying to send us packets.
|
||||
packet_queue = None
|
||||
|
||||
pkt_count = 0
|
||||
|
||||
def __init__(self, packet_queue):
|
||||
super().__init__('RX_PKT')
|
||||
self.packet_queue = packet_queue
|
||||
@ -91,7 +93,8 @@ class APRSDRXThread(APRSDThread):
|
||||
'No packet received from decode_packet. Most likely a failure to parse'
|
||||
)
|
||||
return
|
||||
packet_log.log(packet)
|
||||
self.pkt_count += 1
|
||||
packet_log.log(packet, packet_count=self.pkt_count)
|
||||
pkt_list = packets.PacketList()
|
||||
|
||||
if isinstance(packet, packets.AckPacket):
|
||||
@ -215,7 +218,7 @@ class APRSDProcessPacketThread(APRSDFilterThread):
|
||||
our_call = CONF.callsign.lower()
|
||||
|
||||
from_call = packet.from_call
|
||||
if packet.addresse:
|
||||
if hasattr(packet, 'addresse') and packet.addresse:
|
||||
to_call = packet.addresse
|
||||
else:
|
||||
to_call = packet.to_call
|
||||
|
Loading…
x
Reference in New Issue
Block a user