From 54072a2103d9833dd3aadc3b9e200842b2cea7f5 Mon Sep 17 00:00:00 2001 From: Hemna Date: Tue, 12 Jan 2021 14:50:49 -0500 Subject: [PATCH] Added --raw format for sending messages aprsd send-message --raw "RAW APRS MESSAGE HERE" --- aprsd/main.py | 22 +++++++++++++++------- aprsd/messaging.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/aprsd/main.py b/aprsd/main.py index acc784c..ecec1c7 100644 --- a/aprsd/main.py +++ b/aprsd/main.py @@ -234,8 +234,9 @@ def sample_config(): default=False, help="Don't wait for an ack, just sent it to APRS-IS and bail.", ) -@click.argument("tocallsign") -@click.argument("command", nargs=-1) +@click.option("--raw", default=None, help="Send a raw message. Implies --no-ack") +@click.argument("tocallsign", required=False) +@click.argument("command", nargs=-1, required=False) def send_message( loglevel, quiet, @@ -243,15 +244,13 @@ def send_message( aprs_login, aprs_password, no_ack, + raw, tocallsign, command, ): """Send a message to a callsign via APRS_IS.""" global got_ack, got_response - if not quiet: - click.echo("{} {} {} {}".format(aprs_login, aprs_password, tocallsign, command)) - click.echo("Load config") config = utils.parse_config(config_file) if not aprs_login: click.echo("Must set --aprs_login or APRS_LOGIN") @@ -269,7 +268,11 @@ def send_message( LOG.info("APRSD Started version: {}".format(aprsd.__version__)) if type(command) is tuple: command = " ".join(command) - LOG.info("Sending Command '{}'".format(command)) + if not quiet: + if raw: + LOG.info("L'{}' R'{}'".format(aprs_login, raw)) + else: + LOG.info("L'{}' To'{}' C'{}'".format(aprs_login, tocallsign, command)) got_ack = False got_response = False @@ -317,7 +320,12 @@ def send_message( # We should get an ack back as well as a new message # we should bail after we get the ack and send an ack back for the # message - msg = messaging.TextMessage(aprs_login, tocallsign, command) + if raw: + msg = messaging.RawMessage(raw) + msg.send_direct() + sys.exit(0) + else: + msg = messaging.TextMessage(aprs_login, tocallsign, command) msg.send_direct() if no_ack: diff --git a/aprsd/messaging.py b/aprsd/messaging.py index 491ba11..34044c9 100644 --- a/aprsd/messaging.py +++ b/aprsd/messaging.py @@ -212,6 +212,46 @@ class Message(metaclass=abc.ABCMeta): pass +class RawMessage(Message): + """Send a raw message. + + This class is used for custom messages that contain the entire + contents of an APRS message in the message field. + + """ + + message = None + + def __init__(self, message): + super().__init__(None, None, msg_id=None) + self.message = message + + def __repr__(self): + return self.message + + def __str__(self): + return self.message + + def send(self): + tracker = MsgTrack() + tracker.add(self) + LOG.debug("Length of MsgTrack is {}".format(len(tracker))) + thread = SendMessageThread(message=self) + thread.start() + + def send_direct(self): + """Send a message without a separate thread.""" + cl = client.get_client() + log_message( + "Sending Message Direct", + repr(self).rstrip("\n"), + self.message, + tocall=self.tocall, + fromcall=self.fromcall, + ) + cl.sendall(repr(self)) + + class TextMessage(Message): """Send regular ARPS text/command messages/replies."""