def rx_packet(packet): global got_ack, got_response # LOG.debug("Got packet back {}".format(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)
def rx_packet(packet): global got_ack, got_response # 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) got_ack = True else: 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, ) got_response = True # Send the ack back? ack = messaging.AckMessage( config["aprs"]["login"], fromcall, msg_id=msg_number, ) ack.send_direct() if got_ack: if wait_response: if got_response: sys.exit(0) else: sys.exit(0)
def process_ack_packet(packet): ack_num = packet.get("msgNo") 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
def rx_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 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
def process_ack_packet(self, packet): ack_num = packet.get("msgNo") LOG.info(f"Got ack for message {ack_num}") messaging.log_message( "RXACK", packet["raw"], None, ack=ack_num, fromcall=packet["from"], ) tracker = messaging.MsgTrack() tracker.remove(ack_num) stats.APRSDStats().ack_rx_inc() return
def process_message_packet(packet): LOG.info("Got a message packet") fromcall = packet["from"] message = packet.get("message_text", None) 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) found_command = False # Get singleton of the PM pm = plugin.PluginManager() try: results = pm.run(fromcall=fromcall, message=message, ack=ack) for reply in results: found_command = True # A plugin can return a null message flag which signals # 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: LOG.debug("Sending '{}'".format(reply)) messaging.send_message(fromcall, reply) else: LOG.debug("Got NULL MESSAGE from plugin") if not found_command: plugins = pm.get_plugins() names = [x.command_name for x in plugins] names.sort() reply = "Usage: {}".format(", ".join(names)) messaging.send_message(fromcall, reply) except Exception as ex: LOG.exception("Plugin failed!!!", ex) reply = "A Plugin failed! try again?" messaging.send_message(fromcall, reply) # let any threads do their thing, then ack # send an ack last messaging.send_ack(fromcall, ack) LOG.debug("Packet processing complete")
def rx_packet(packet): resp = packet.get("response", None) if resp == "ack": ack_num = packet.get("msgNo") console.log(f"We saw an ACK {ack_num} Ignoring") messaging.log_packet(packet) else: 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, console=console, )
def loop(self): """Process a packet recieved from aprs-is server.""" packet = self.packet packets.PacketList().add(packet) fromcall = packet["from"] tocall = packet.get("addresse", None) msg = packet.get("message_text", None) msg_id = packet.get("msgNo", "0") msg_response = packet.get("response", None) # LOG.debug(f"Got packet from '{fromcall}' - {packet}") # We don't put ack packets destined for us through the # plugins. if tocall == self.config["aprs"]["login"] and msg_response == "ack": self.process_ack_packet(packet) else: # It's not an ACK for us, so lets run it through # the plugins. messaging.log_message( "Received Message", packet["raw"], msg, fromcall=fromcall, msg_num=msg_id, ) # Only ack messages that were sent directly to us if tocall == self.config["aprs"]["login"]: stats.APRSDStats().msgs_rx_inc() # let any threads do their thing, then ack # send an ack last ack = messaging.AckMessage( self.config["aprs"]["login"], fromcall, msg_id=msg_id, ) ack.send() pm = plugin.PluginManager() try: results = pm.run(packet) wl = packets.WatchList() wl.update_seen(packet) replied = False for reply in results: if isinstance(reply, list): # one of the plugins wants to send multiple messages replied = True for subreply in reply: LOG.debug(f"Sending '{subreply}'") if isinstance(subreply, messaging.Message): subreply.send() else: msg = messaging.TextMessage( self.config["aprs"]["login"], fromcall, subreply, ) msg.send() elif isinstance(reply, messaging.Message): # We have a message based object. LOG.debug(f"Sending '{reply}'") reply.send() replied = True else: replied = True # A plugin can return a null message flag which signals # 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: LOG.debug(f"Sending '{reply}'") msg = messaging.TextMessage( self.config["aprs"]["login"], fromcall, reply, ) msg.send() # If the message was for us and we didn't have a # response, then we send a usage statement. if tocall == self.config["aprs"]["login"] and not replied: LOG.warning("Sending help!") msg = messaging.TextMessage( self.config["aprs"]["login"], fromcall, "Unknown command! Send 'help' message for help", ) msg.send() except Exception as ex: LOG.error("Plugin failed!!!") LOG.exception(ex) # Do we need to send a reply? if tocall == self.config["aprs"]["login"]: reply = "A Plugin failed! try again?" msg = messaging.TextMessage( self.config["aprs"]["login"], fromcall, reply, ) msg.send() LOG.debug("Packet processing complete")