From bfc0a5a1e9bd56c808edac679a50426efc5d322e Mon Sep 17 00:00:00 2001 From: Hemna Date: Fri, 16 Dec 2022 14:04:08 -0500 Subject: [PATCH] Cleaned out all references to messaging The messaging.py now is nothing but a shell that contains a link to packets.NULL_MESSAGE to help maintain some backwards compatibility with plugins. Packets dataclass has fully replaced messaging objects. --- aprsd/clients/kiss.py | 20 ++-- aprsd/cmds/dev.py | 4 +- aprsd/cmds/server.py | 3 - aprsd/flask.py | 194 +++++++++++++++++++------------------- aprsd/messaging.py | 3 +- aprsd/packets/__init__.py | 13 ++- aprsd/packets/core.py | 11 ++- aprsd/plugin.py | 4 +- aprsd/plugins/email.py | 45 ++++----- aprsd/plugins/notify.py | 23 ++--- aprsd/plugins/query.py | 21 +++-- aprsd/threads/rx.py | 44 +-------- 12 files changed, 180 insertions(+), 205 deletions(-) diff --git a/aprsd/clients/kiss.py b/aprsd/clients/kiss.py index 79db9b7..48e4f92 100644 --- a/aprsd/clients/kiss.py +++ b/aprsd/clients/kiss.py @@ -4,7 +4,7 @@ import aprslib from ax253 import Frame import kiss -from aprsd import messaging +from aprsd.packets import core from aprsd.utils import trace @@ -83,7 +83,7 @@ class KISS3Client: self.kiss.read(callback=self.parse_frame, min_frames=None) LOG.debug("END blocking KISS consumer") - def send(self, msg): + def send(self, packet): """Send an APRS Message object.""" # payload = (':%-9s:%s' % ( @@ -93,26 +93,26 @@ class KISS3Client: # payload = str(msg).encode('US-ASCII') payload = None path = ["WIDE1-1", "WIDE2-1"] - if isinstance(msg, messaging.AckMessage): - msg_payload = f"ack{msg.id}" - elif isinstance(msg, messaging.RawMessage): - payload = msg.message.encode("US-ASCII") + if isinstance(packet, core.AckPacket): + msg_payload = f"ack{packet.msgNo}" + elif isinstance(packet, core.Packet): + payload = packet.raw.encode("US-ASCII") path = ["WIDE2-1"] else: - msg_payload = f"{msg.message}{{{str(msg.id)}" + msg_payload = f"{packet.raw}{{{str(packet.msgNo)}" if not payload: payload = ( ":{:<9}:{}".format( - msg.tocall, + packet.to_call, msg_payload, ) ).encode("US-ASCII") LOG.debug(f"Send '{payload}' TO KISS") frame = Frame.ui( - destination=msg.tocall, - source=msg.fromcall, + destination=packet.to_call, + source=packet.from_call, path=path, info=payload, ) diff --git a/aprsd/cmds/dev.py b/aprsd/cmds/dev.py index c3979ed..16d6da1 100644 --- a/aprsd/cmds/dev.py +++ b/aprsd/cmds/dev.py @@ -8,7 +8,7 @@ import logging import click # local imports here -from aprsd import cli_helper, client, messaging, packets, plugin, stats, utils +from aprsd import cli_helper, client, packets, plugin, stats, utils from aprsd.aprsd import cli from aprsd.utils import trace @@ -102,7 +102,7 @@ def test_plugin( client.Client(config) stats.APRSDStats(config) - messaging.MsgTrack(config=config) + packets.PacketTrack(config=config) packets.WatchList(config=config) packets.SeenList(config=config) diff --git a/aprsd/cmds/server.py b/aprsd/cmds/server.py index 4bb50cc..084f072 100644 --- a/aprsd/cmds/server.py +++ b/aprsd/cmds/server.py @@ -80,14 +80,12 @@ def server(ctx, flush): packets.PacketList(config=config) if flush: LOG.debug("Deleting saved MsgTrack.") - #messaging.MsgTrack(config=config).flush() packets.PacketTrack(config=config).flush() packets.WatchList(config=config) packets.SeenList(config=config) else: # Try and load saved MsgTrack list LOG.debug("Loading saved MsgTrack object.") - #messaging.MsgTrack(config=config).load() packets.PacketTrack(config=config).load() packets.WatchList(config=config).load() packets.SeenList(config=config).load() @@ -103,7 +101,6 @@ def server(ctx, flush): ) rx_thread.start() - #messaging.MsgTrack().restart() packets.PacketTrack().restart() keepalive = threads.KeepAliveThread(config=config) diff --git a/aprsd/flask.py b/aprsd/flask.py index 21de182..76865c1 100644 --- a/aprsd/flask.py +++ b/aprsd/flask.py @@ -14,11 +14,12 @@ import flask_classful from flask_httpauth import HTTPBasicAuth from flask_socketio import Namespace, SocketIO from werkzeug.security import check_password_hash, generate_password_hash +import wrapt import aprsd from aprsd import client from aprsd import config as aprsd_config -from aprsd import messaging, packets, plugin, stats, threads, utils +from aprsd import packets, plugin, stats, threads, utils from aprsd.clients import aprsis from aprsd.logging import log from aprsd.logging import rich as aprsd_logging @@ -32,7 +33,7 @@ users = None class SentMessages: _instance = None - lock = None + lock = threading.Lock() msgs = {} @@ -41,16 +42,16 @@ class SentMessages: if cls._instance is None: cls._instance = super().__new__(cls) # Put any initialization here. - cls.lock = threading.Lock() return cls._instance - def add(self, msg): - with self.lock: - self.msgs[msg.id] = self._create(msg.id) - self.msgs[msg.id]["from"] = msg.fromcall - self.msgs[msg.id]["to"] = msg.tocall - self.msgs[msg.id]["message"] = msg.message.rstrip("\n") - self.msgs[msg.id]["raw"] = str(msg).rstrip("\n") + @wrapt.synchronized(lock) + def add(self, packet): + self.msgs[packet.msgNo] = self._create(packet.msgNo) + self.msgs[packet.msgNo]["from"] = packet.from_call + self.msgs[packet.msgNo]["to"] = packet.to_call + self.msgs[packet.msgNo]["message"] = packet.message_text.rstrip("\n") + packet._build_raw() + self.msgs[packet.msgNo]["raw"] = packet.raw.rstrip("\n") def _create(self, id): return { @@ -66,34 +67,34 @@ class SentMessages: "reply": None, } + @wrapt.synchronized(lock) def __len__(self): - with self.lock: - return len(self.msgs.keys()) + return len(self.msgs.keys()) + @wrapt.synchronized(lock) def get(self, id): - with self.lock: - if id in self.msgs: - return self.msgs[id] + if id in self.msgs: + return self.msgs[id] + @wrapt.synchronized(lock) def get_all(self): - with self.lock: - return self.msgs + return self.msgs + @wrapt.synchronized(lock) def set_status(self, id, status): - with self.lock: - self.msgs[id]["last_update"] = str(datetime.datetime.now()) - self.msgs[id]["status"] = status + self.msgs[id]["last_update"] = str(datetime.datetime.now()) + self.msgs[id]["status"] = status + @wrapt.synchronized(lock) def ack(self, id): """The message got an ack!""" - with self.lock: - self.msgs[id]["last_update"] = str(datetime.datetime.now()) - self.msgs[id]["ack"] = True + self.msgs[id]["last_update"] = str(datetime.datetime.now()) + self.msgs[id]["ack"] = True + @wrapt.synchronized(lock) def reply(self, id, packet): """We got a packet back from the sent message.""" - with self.lock: - self.msgs[id]["reply"] = packet + self.msgs[id]["reply"] = packet # HTTPBasicAuth doesn't work on a class method. @@ -107,7 +108,7 @@ def verify_password(username, password): return username -class SendMessageThread(threads.APRSDThread): +class SendMessageThread(threads.APRSDRXThread): """Thread for sending a message from web.""" aprsis_client = None @@ -115,10 +116,10 @@ class SendMessageThread(threads.APRSDThread): got_ack = False got_reply = False - def __init__(self, config, info, msg, namespace): + def __init__(self, config, info, packet, namespace): self.config = config self.request = info - self.msg = msg + self.packet = packet self.namespace = namespace self.start_time = datetime.datetime.now() msg = "({} -> {}) : {}".format( @@ -180,8 +181,8 @@ class SendMessageThread(threads.APRSDThread): except LoginError as e: f"Failed to setup Connection {e}" - self.msg.send_direct(aprsis_client=self.aprs_client) - SentMessages().set_status(self.msg.id, "Sent") + self.packet.send_direct(aprsis_client=self.aprs_client) + SentMessages().set_status(self.packet.msgNo, "Sent") while not self.thread_stop: can_loop = self.loop() @@ -190,59 +191,55 @@ class SendMessageThread(threads.APRSDThread): threads.APRSDThreadList().remove(self) LOG.debug("Exiting") - def rx_packet(self, packet): + def process_ack_packet(self, packet): global socketio - # LOG.debug("Got packet back {}".format(packet)) - resp = packet.get("response", None) - if resp == "ack": - ack_num = packet.get("msgNo") - LOG.info(f"We got ack for our sent message {ack_num}") - messaging.log_packet(packet) - SentMessages().ack(self.msg.id) - socketio.emit( - "ack", SentMessages().get(self.msg.id), - namespace="/sendmsg", - ) - stats.APRSDStats().ack_rx_inc() - self.got_ack = True - if self.request["wait_reply"] == "0" or self.got_reply: - # We aren't waiting for a reply, so we can bail - self.stop() - self.thread_stop = self.aprs_client.thread_stop = True + ack_num = packet.msgNo + LOG.info(f"We got ack for our sent message {ack_num}") + packet.log("RXACK") + SentMessages().ack(self.packet.msgNo) + stats.APRSDStats().ack_rx_inc() + socketio.emit( + "ack", SentMessages().get(self.packet.msgNo), + namespace="/sendmsg", + ) + if self.request["wait_reply"] == "0" or self.got_reply: + # We aren't waiting for a reply, so we can bail + self.stop() + self.thread_stop = self.aprs_client.thread_stop = True + + def process_our_message_packet(self, packet): + global socketio + packets.PacketList().add(packet) + stats.APRSDStats().msgs_rx_inc() + msg_number = packet.msgNo + SentMessages().reply(self.packet.msgNo, packet) + SentMessages().set_status(self.packet.msgNo, "Got Reply") + socketio.emit( + "reply", SentMessages().get(self.packet.msgNo), + namespace="/sendmsg", + ) + ack_pkt = packets.AckPacket( + from_call=self.request["from"], + to_call=packet.from_call, + msgNo=msg_number, + ) + ack_pkt.send_direct(aprsis_client=self.aprsis_client) + SentMessages().set_status(self.packet.msgNo, "Ack Sent") + + # Now we can exit, since we are done. + self.got_reply = True + if self.got_ack: + self.stop() + self.thread_stop = self.aprs_client.thread_stop = True + + def process_packet(self, *args, **kwargs): + packet = self._client.decode_packet(*args, **kwargs) + packet.log(header="RX Packet") + + if isinstance(packet, packets.AckPacket): + self.process_ack_packet(packet) else: - packets.PacketList().add(packet) - stats.APRSDStats().msgs_rx_inc() - message = packet.get("message_text", None) - fromcall = packet["from"] - msg_number = packet.get("msgNo", "0") - messaging.log_message( - "Received Message", - packet["raw"], - message, - fromcall=fromcall, - ack=msg_number, - ) - SentMessages().reply(self.msg.id, packet) - SentMessages().set_status(self.msg.id, "Got Reply") - socketio.emit( - "reply", SentMessages().get(self.msg.id), - namespace="/sendmsg", - ) - - # Send the ack back? - ack = messaging.AckMessage( - self.request["from"], - fromcall, - msg_id=msg_number, - ) - ack.send_direct() - SentMessages().set_status(self.msg.id, "Ack Sent") - - # Now we can exit, since we are done. - self.got_reply = True - if self.got_ack: - self.stop() - self.thread_stop = self.aprs_client.thread_stop = True + self.process_our_message_packet(packet) def loop(self): # we have a general time limit expecting results of @@ -265,7 +262,9 @@ class SendMessageThread(threads.APRSDThread): # This will register a packet consumer with aprslib # When new packets come in the consumer will process # the packet - self.aprs_client.consumer(self.rx_packet, raw=False, blocking=False) + self.aprs_client.consumer( + self.process_packet, raw=False, blocking=False, + ) except aprslib.exceptions.ConnectionDrop: LOG.error("Connection dropped.") return False @@ -353,7 +352,7 @@ class APRSDFlask(flask_classful.FlaskView): @auth.login_required def messages(self): - track = messaging.MsgTrack() + track = packets.PacketTrack() msgs = [] for id in track: LOG.info(track[id].dict()) @@ -393,13 +392,13 @@ class APRSDFlask(flask_classful.FlaskView): @auth.login_required def save(self): """Save the existing queue to disk.""" - track = messaging.MsgTrack() + track = packets.PacketTrack() track.save() return json.dumps({"messages": "saved"}) def _stats(self): stats_obj = stats.APRSDStats() - track = messaging.MsgTrack() + track = packets.PacketTrack() now = datetime.datetime.now() time_format = "%m-%d-%Y %H:%M:%S" @@ -444,7 +443,7 @@ class SendMessageNamespace(Namespace): _config = None got_ack = False reply_sent = False - msg = None + packet = None request = None def __init__(self, namespace=None, config=None): @@ -466,24 +465,27 @@ class SendMessageNamespace(Namespace): global socketio LOG.debug(f"WS: on_send {data}") self.request = data - msg = messaging.TextMessage( - data["from"], data["to"], - data["message"], + self.packet = packets.MessagePacket( + from_call=data["from"], + to_call=data["to"], + message_text=data["message"], ) - self.msg = msg msgs = SentMessages() - msgs.add(msg) - msgs.set_status(msg.id, "Sending") + msgs.add(self.packet) + msgs.set_status(self.packet.msgNo, "Sending") socketio.emit( - "sent", SentMessages().get(self.msg.id), + "sent", SentMessages().get(self.packet.msgNo), namespace="/sendmsg", ) - socketio.start_background_task(self._start, self._config, data, msg, self) + socketio.start_background_task( + self._start, self._config, data, + self.packet, self, + ) LOG.warning("WS: on_send: exit") - def _start(self, config, data, msg, namespace): - msg_thread = SendMessageThread(self._config, data, msg, self) + def _start(self, config, data, packet, namespace): + msg_thread = SendMessageThread(self._config, data, packet, self) msg_thread.start() def handle_message(self, data): diff --git a/aprsd/messaging.py b/aprsd/messaging.py index 3e25742..3fe3a79 100644 --- a/aprsd/messaging.py +++ b/aprsd/messaging.py @@ -1,3 +1,4 @@ # What to return from a plugin if we have processed the message # and it's ok, but don't send a usage string back -NULL_MESSAGE = -1 + +# REMOVE THIS FILE diff --git a/aprsd/packets/__init__.py b/aprsd/packets/__init__.py index 2edb578..8eb8fc0 100644 --- a/aprsd/packets/__init__.py +++ b/aprsd/packets/__init__.py @@ -1,8 +1,11 @@ -from aprsd.packets.core import ( +from aprsd.packets.core import ( # noqa: F401 AckPacket, GPSPacket, MessagePacket, MicEPacket, Packet, PathPacket, StatusPacket, WeatherPacket, ) -from aprsd.packets.packet_list import PacketList -from aprsd.packets.seen_list import SeenList -from aprsd.packets.tracker import PacketTrack -from aprsd.packets.watch_list import WatchList +from aprsd.packets.packet_list import PacketList # noqa: F401 +from aprsd.packets.seen_list import SeenList # noqa: F401 +from aprsd.packets.tracker import PacketTrack # noqa: F401 +from aprsd.packets.watch_list import WatchList # noqa: F401 + + +NULL_MESSAGE = -1 diff --git a/aprsd/packets/core.py b/aprsd/packets/core.py index 2623c0f..a52f19b 100644 --- a/aprsd/packets/core.py +++ b/aprsd/packets/core.py @@ -46,6 +46,12 @@ class Packet(metaclass=abc.ABCMeta): _transport = None _raw_message = None + def __post__init(self): + if not self.msgNo: + c = counter.PacketCounter() + c.increment() + self.msgNo = c.value + def get(self, key, default=None): """Emulate a getter on a dict.""" if hasattr(self, key): @@ -55,11 +61,6 @@ class Packet(metaclass=abc.ABCMeta): def _init_for_send(self): """Do stuff here that is needed prior to sending over the air.""" - if not self.msgNo: - c = counter.PacketCounter() - c.increment() - self.msgNo = c.value - # now build the raw message for sending self._build_raw() diff --git a/aprsd/plugin.py b/aprsd/plugin.py index 885740b..db85a5d 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -13,7 +13,7 @@ import pluggy from thesmuggler import smuggle import aprsd -from aprsd import client, messaging, threads +from aprsd import client, packets, threads from aprsd.packets import watch_list @@ -162,7 +162,7 @@ class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta): @hookimpl def filter(self, packet): - result = messaging.NULL_MESSAGE + result = packets.NULL_MESSAGE if self.enabled: wl = watch_list.WatchList() if wl.callsign_in_watchlist(packet.from_call): diff --git a/aprsd/plugins/email.py b/aprsd/plugins/email.py index a9facec..557bd19 100644 --- a/aprsd/plugins/email.py +++ b/aprsd/plugins/email.py @@ -10,7 +10,7 @@ import time import imapclient -from aprsd import messaging, packets, plugin, stats, threads +from aprsd import packets, plugin, stats, threads from aprsd.utils import trace @@ -90,10 +90,10 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase): if not self.enabled: # Email has not been enabled # so the plugin will just NOOP - return messaging.NULL_MESSAGE + return packets.NULL_MESSAGE fromcall = packet.from_call - message = packet.get("message_text", None) + message = packet.message_text ack = packet.get("msgNo", "0") reply = None @@ -109,7 +109,7 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase): if r is not None: LOG.debug("RESEND EMAIL") resend_email(self.config, r.group(1), fromcall) - reply = messaging.NULL_MESSAGE + reply = packets.NULL_MESSAGE # -user@address.com body of email elif re.search(r"^-([A-Za-z0-9_\-\.@]+) (.*)", message): # (same search again) @@ -142,7 +142,7 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase): if not too_soon or ack == 0: LOG.info(f"Send email '{content}'") send_result = send_email(self.config, to_addr, content) - reply = messaging.NULL_MESSAGE + reply = packets.NULL_MESSAGE if send_result != 0: reply = f"-{to_addr} failed" else: @@ -157,7 +157,7 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase): self.email_sent_dict.clear() self.email_sent_dict[ack] = now else: - reply = messaging.NULL_MESSAGE + reply = packets.NULL_MESSAGE LOG.info( "Email for message number " + ack @@ -165,7 +165,6 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase): ) else: reply = "Bad email address" - # messaging.send_message(fromcall, "Bad email address") return reply @@ -466,13 +465,12 @@ def resend_email(config, count, fromcall): from_addr = shortcuts_inverted[from_addr] # asterisk indicates a resend reply = "-" + from_addr + " * " + body.decode(errors="ignore") - # messaging.send_message(fromcall, reply) - msg = messaging.TextMessage( - config["aprs"]["login"], - fromcall, - reply, + pkt = packets.MessagePacket( + from_call=config["aprsd"]["callsign"], + to_call=fromcall, + message_text=reply, ) - msg.send() + pkt.send() msgexists = True if msgexists is not True: @@ -489,9 +487,12 @@ def resend_email(config, count, fromcall): str(m).zfill(2), str(s).zfill(2), ) - # messaging.send_message(fromcall, reply) - msg = messaging.TextMessage(config["aprs"]["login"], fromcall, reply) - msg.send() + pkt = packets.MessagePacket( + from_call=config["aprsd"]["callsign"], + to_call=fromcall, + message_text=reply, + ) + pkt.send() # check email more often since we're resending one now EmailInfo().delay = 60 @@ -605,12 +606,14 @@ class APRSDEmailThread(threads.APRSDThread): from_addr = shortcuts_inverted[from_addr] reply = "-" + from_addr + " " + body.decode(errors="ignore") - msg = messaging.TextMessage( - self.config["aprs"]["login"], - self.config["ham"]["callsign"], - reply, + # Send the message to the registered user in the + # config ham.callsign + pkt = packets.MessagePacket( + from_call=self.config["aprsd"]["callsign"], + to_call=self.config["ham"]["callsign"], + message_text=reply, ) - msg.send() + pkt.send() # flag message as sent via aprs try: server.add_flags(msgid, ["APRS"]) diff --git a/aprsd/plugins/notify.py b/aprsd/plugins/notify.py index d75a19c..326b487 100644 --- a/aprsd/plugins/notify.py +++ b/aprsd/plugins/notify.py @@ -1,6 +1,6 @@ import logging -from aprsd import messaging, packets, plugin +from aprsd import packets, plugin LOG = logging.getLogger("APRSD") @@ -34,20 +34,21 @@ class NotifySeenPlugin(plugin.APRSDWatchListPluginBase): wl.max_delta(), ), ) - packet_type = packet.packet_type + packet_type = packet.__class__.__name__ # we shouldn't notify the alert user that they are online. if fromcall != notify_callsign: - msg = messaging.TextMessage( - self.config["aprs"]["login"], - notify_callsign, - f"{fromcall} was just seen by type:'{packet_type}'", - # We don't need to keep this around if it doesn't go thru - allow_delay=False, + pkt = packets.MessagePacket( + from_call=self.config["aprsd"]["callsign"], + to_call=notify_callsign, + message_text=( + f"{fromcall} was just seen by type:'{packet_type}'" + ), + _allow_delay=False, ) - return msg + return pkt else: LOG.debug("fromcall and notify_callsign are the same, not notifying") - return messaging.NULL_MESSAGE + return packets.NULL_MESSAGE else: LOG.debug( "Not old enough to notify on callsign '{}' : {} < {}".format( @@ -56,4 +57,4 @@ class NotifySeenPlugin(plugin.APRSDWatchListPluginBase): wl.max_delta(), ), ) - return messaging.NULL_MESSAGE + return packets.NULL_MESSAGE diff --git a/aprsd/plugins/query.py b/aprsd/plugins/query.py index e1fc267..04e6b0c 100644 --- a/aprsd/plugins/query.py +++ b/aprsd/plugins/query.py @@ -2,7 +2,8 @@ import datetime import logging import re -from aprsd import messaging, packets, plugin +from aprsd import packets, plugin +from aprsd.packets import tracker from aprsd.utils import trace @@ -24,10 +25,10 @@ class QueryPlugin(plugin.APRSDRegexCommandPluginBase): message = packet.get("message_text", None) # ack = packet.get("msgNo", "0") - tracker = messaging.MsgTrack() + pkt_tracker = tracker.PacketTrack() now = datetime.datetime.now() reply = "Pending messages ({}) {}".format( - len(tracker), + len(pkt_tracker), now.strftime("%H:%M:%S"), ) @@ -38,11 +39,11 @@ class QueryPlugin(plugin.APRSDRegexCommandPluginBase): # resend last N most recent: "!3" r = re.search(r"^\!([0-9]).*", message) if r is not None: - if len(tracker) > 0: + if len(pkt_tracker) > 0: last_n = r.group(1) - reply = messaging.NULL_MESSAGE + reply = packets.NULL_MESSAGE LOG.debug(reply) - tracker.restart_delayed(count=int(last_n)) + pkt_tracker.restart_delayed(count=int(last_n)) else: reply = "No pending msgs to resend" LOG.debug(reply) @@ -51,10 +52,10 @@ class QueryPlugin(plugin.APRSDRegexCommandPluginBase): # resend all: "!a" r = re.search(r"^\![aA].*", message) if r is not None: - if len(tracker) > 0: - reply = messaging.NULL_MESSAGE + if len(pkt_tracker) > 0: + reply = packets.NULL_MESSAGE LOG.debug(reply) - tracker.restart_delayed() + pkt_tracker.restart_delayed() else: reply = "No pending msgs" LOG.debug(reply) @@ -65,7 +66,7 @@ class QueryPlugin(plugin.APRSDRegexCommandPluginBase): if r is not None: reply = "Deleted ALL pending msgs." LOG.debug(reply) - tracker.flush() + pkt_tracker.flush() return reply return reply diff --git a/aprsd/threads/rx.py b/aprsd/threads/rx.py index 478a7ee..134c12c 100644 --- a/aprsd/threads/rx.py +++ b/aprsd/threads/rx.py @@ -4,7 +4,7 @@ import time import aprslib -from aprsd import client, messaging, packets, plugin, stats +from aprsd import client, packets, plugin, stats from aprsd.threads import APRSDThread @@ -66,7 +66,6 @@ class APRSDPluginRXThread(APRSDRXThread): def process_packet(self, *args, **kwargs): packet = self._client.decode_packet(*args, **kwargs) # LOG.debug(raw) - #packet = packets.Packet.factory(raw.copy()) packet.log(header="RX Packet") thread = APRSDPluginProcessPacketThread( config=self.config, @@ -186,7 +185,7 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread): replied = True for subreply in reply: LOG.debug(f"Sending '{subreply}'") - if isinstance(subreply, messaging.Message): + if isinstance(subreply, packets.Packet): subreply.send() else: msg_pkt = packets.MessagePacket( @@ -195,23 +194,9 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread): message_text=subreply, ) msg_pkt.send() - #msg = messaging.TextMessage( - # self.config["aprsd"]["callsign"], - # from_call, - # subreply, - #) - #msg.send() - elif isinstance(reply, messaging.Message): + elif isinstance(reply, packets.Packet): # We have a message based object. - LOG.debug(f"Sending '{reply}'") - # Convert this to the new packet - msg_pkt = packets.MessagePacket( - from_call=reply.fromcall, - to_call=reply.tocall, - message_text=reply._raw_message, - ) - #reply.send() - msg_pkt.send() + reply.send() replied = True else: replied = True @@ -219,7 +204,7 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread): # us that they processed the message correctly, but have # nothing to reply with, so we avoid replying with a # usage string - if reply is not messaging.NULL_MESSAGE: + if reply is not packets.NULL_MESSAGE: LOG.debug(f"Sending '{reply}'") msg_pkt = packets.MessagePacket( from_call=self.config["aprsd"]["callsign"], @@ -230,13 +215,6 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread): msg_pkt.send() LOG.warning("Calling msg_pkg.send() --- DONE") - #msg = messaging.TextMessage( - # self.config["aprsd"]["callsign"], - # from_call, - # reply, - #) - #msg.send() - # If the message was for us and we didn't have a # response, then we send a usage statement. if to_call == self.config["aprsd"]["callsign"] and not replied: @@ -247,12 +225,6 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread): message_text="Unknown command! Send 'help' message for help", ) msg_pkt.send() - #msg = messaging.TextMessage( - # self.config["aprsd"]["callsign"], - # from_call, - # "Unknown command! Send 'help' message for help", - #) - #msg.send() except Exception as ex: LOG.error("Plugin failed!!!") LOG.exception(ex) @@ -265,11 +237,5 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread): message_text=reply, ) msg_pkt.send() - #msg = messaging.TextMessage( - # self.config["aprsd"]["callsign"], - # from_call, - # reply, - #) - #msg.send() LOG.debug("Completed process_our_message_packet")