From d3ee1b78bc62dd57be6b505eb1269a70cdbb7242 Mon Sep 17 00:00:00 2001 From: Hemna Date: Sun, 20 Dec 2020 16:33:18 -0500 Subject: [PATCH] Fixed issue when RX ack This patch ensures that after we get an ACK, then proessing of the ack message is complete and we don't try and send the ack through plugin filtering. Created send_ack_direct for the send-message command. Also added logic to the send-message command to ensure we wait for an ack from the command sent to APRSD and we also wait for a response message and send an ack to that response before we exit. --- aprsd/main.py | 43 ++++++++++++++++++++++++++++++--- aprsd/messaging.py | 59 +++++++++++++++++++++++++++++----------------- 2 files changed, 78 insertions(+), 24 deletions(-) diff --git a/aprsd/main.py b/aprsd/main.py index 7a32edf..64b903f 100644 --- a/aprsd/main.py +++ b/aprsd/main.py @@ -184,9 +184,14 @@ def process_packet(packet): if not message: LOG.debug("Didn't get a message, could be an ack?") if packet.get("response", None) == "ack": - # looks like an ACK + # looks like an ACKa ack_num = packet.get("msgNo") - messaging.ack_dict.update({ack_num: 1}) + LOG.info("Got ack for message {}".format(ack_num)) + messaging.log_message( + "ACK", packet["raw"], None, ack=ack_num, fromcall=packet["from"] + ) + messaging.ack_dict.update({int(ack_num): 1}) + return msg_number = packet.get("msgNo", None) if msg_number: @@ -279,6 +284,8 @@ def send_message( loglevel, quiet, config_file, aprs_login, aprs_password, tocallsign, command ): """Send a message to a callsign via APRS_IS.""" + global got_ack, got_response + click.echo("{} {} {} {}".format(aprs_login, aprs_password, tocallsign, command)) click.echo("Load config") @@ -302,14 +309,44 @@ def send_message( command = " ".join(command) LOG.info("Sending Command '{}'".format(command)) + got_ack = False + got_response = False + def rx_packet(packet): + global got_ack, got_response # LOG.debug("Got packet back {}".format(packet)) - messaging.log_packet(packet) resp = packet.get("response", None) if resp == "ack": + ack_num = packet.get("msgNo") + LOG.info("We got ack for our sent message {}".format(ack_num)) + messaging.log_packet(packet) + got_ack = True + else: + message = packet.get("message_text", None) + LOG.info("We got a new message") + fromcall = packet["from"] + msg_number = packet.get("msgNo", None) + if msg_number: + ack = msg_number + else: + ack = "0" + messaging.log_message( + "Received Message", packet["raw"], message, fromcall=fromcall, ack=ack + ) + got_response = True + # Send the ack back? + messaging.send_ack_direct(fromcall, ack) + + if got_ack and got_response: sys.exit(0) cl = client.Client(config) + + # Send a message + # then we setup a consumer to rx messages + # 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 messaging.send_message_direct(tocallsign, command, message_number) try: diff --git a/aprsd/messaging.py b/aprsd/messaging.py index de46953..18e71d3 100644 --- a/aprsd/messaging.py +++ b/aprsd/messaging.py @@ -52,6 +52,23 @@ def send_ack(tocall, ack): # end send_ack() +def send_ack_direct(tocall, ack): + """Send an ack message without a separate thread.""" + LOG.debug("Send ACK({}:{}) to radio.".format(tocall, ack)) + cl = client.get_client() + fromcall = CONFIG["aprs"]["login"] + line = "{}>APRS::{}:ack{}\n".format(fromcall, tocall, ack) + log_message( + "Sending ack", + line.rstrip("\n"), + None, + ack=ack, + tocall=tocall, + fromcall=fromcall, + ) + cl.sendall(line) + + def send_message_thread(tocall, message, this_message_number, retry_count): cl = client.get_client() line = "{}>APRS::{}:{}{{{}\n".format( @@ -120,6 +137,27 @@ def send_message(tocall, message): # end send_message() +def send_message_direct(tocall, message, message_number=None): + """Send a message without a separate thread.""" + cl = client.get_client() + if not message_number: + this_message_number = 1 + else: + this_message_number = message_number + fromcall = CONFIG["aprs"]["login"] + line = "{}>APRS::{}:{}{{{}\n".format( + fromcall, + tocall, + message, + str(this_message_number), + ) + LOG.debug("DEBUG: send_message_thread msg:ack combos are: ") + log_message( + "Sending Message", line.rstrip("\n"), message, tocall=tocall, fromcall=fromcall + ) + cl.sendall(line) + + def log_packet(packet): fromcall = packet.get("from", None) tocall = packet.get("to", None) @@ -200,27 +238,6 @@ def log_message( LOG.info("\n".join(log_list)) -def send_message_direct(tocall, message, message_number=None): - """Send a message without a separate thread.""" - cl = client.get_client() - if not message_number: - this_message_number = 1 - else: - this_message_number = message_number - fromcall = CONFIG["aprs"]["login"] - line = "{}>APRS::{}:{}{{{}\n".format( - fromcall, - tocall, - message, - str(this_message_number), - ) - LOG.debug("DEBUG: send_message_thread msg:ack combos are: ") - log_message( - "Sending Message", line.rstrip("\n"), message, tocall=tocall, fromcall=fromcall - ) - cl.sendall(line) - - def process_message(line): f = re.search("^(.*)>", line) fromcall = f.group(1)