mirror of
https://github.com/craigerl/aprsd.git
synced 2024-11-10 10:33:31 -05:00
Refactored the main process_packet method
This patch refactored the process_packet method and adjusted the logic for determining if we got a message to filter on. We now look at the format to make a determination. Also isolated the processing of message packets, ack packets and mic-e packets into their own functions.
This commit is contained in:
parent
8161719697
commit
1d898ea20f
@ -4,6 +4,7 @@ CHANGES
|
||||
v1.1.0
|
||||
------
|
||||
|
||||
* Refactored the main process\_packet method
|
||||
* Update README with version 1.1.0 related info
|
||||
* Added fix for an unknown packet type
|
||||
* Ensure fortune is installed
|
||||
|
@ -6,7 +6,7 @@ ENV VERSION=1.0.0
|
||||
ENV APRS_USER=aprs
|
||||
ENV HOME=/home/aprs
|
||||
ENV APRSD=http://github.com/craigerl/aprsd.git
|
||||
ENV APRSD_BRANCH="master"
|
||||
ENV APRSD_BRANCH="v1.1.0"
|
||||
ENV VIRTUAL_ENV=$HOME/.venv3
|
||||
|
||||
ENV INSTALL=$HOME/install
|
||||
|
@ -172,19 +172,7 @@ def setup_logging(config, loglevel, quiet):
|
||||
LOG.addHandler(sh)
|
||||
|
||||
|
||||
def process_packet(packet):
|
||||
"""Process a packet recieved from aprs-is server."""
|
||||
|
||||
LOG.debug("Process packet!")
|
||||
try:
|
||||
LOG.debug("Got message: {}".format(packet))
|
||||
|
||||
fromcall = packet["from"]
|
||||
message = packet.get("message_text", None)
|
||||
if not message:
|
||||
LOG.debug("Didn't get a message, could be an ack?")
|
||||
if packet.get("response", None) == "ack":
|
||||
# looks like an ACKa
|
||||
def process_ack_packet(packet):
|
||||
ack_num = packet.get("msgNo")
|
||||
LOG.info("Got ack for message {}".format(ack_num))
|
||||
messaging.log_message(
|
||||
@ -192,11 +180,19 @@ def process_packet(packet):
|
||||
)
|
||||
messaging.ack_dict.update({int(ack_num): 1})
|
||||
return
|
||||
else:
|
||||
LOG.info("Don't know what to do with this message. Ignoring")
|
||||
|
||||
|
||||
def process_mic_e_packet(packet):
|
||||
LOG.info("Mic-E Packet detected. Currenlty unsupported.")
|
||||
messaging.log_packet(packet)
|
||||
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
|
||||
@ -240,6 +236,31 @@ def process_packet(packet):
|
||||
messaging.send_ack(fromcall, ack)
|
||||
LOG.debug("Packet processing complete")
|
||||
|
||||
|
||||
def process_packet(packet):
|
||||
"""Process a packet recieved from aprs-is server."""
|
||||
|
||||
LOG.debug("Process packet!")
|
||||
try:
|
||||
LOG.debug("Got message: {}".format(packet))
|
||||
|
||||
msg = packet.get("message_text", None)
|
||||
msg_format = packet.get("format", None)
|
||||
msg_response = packet.get("response", None)
|
||||
if msg_format == "message" and msg:
|
||||
# we want to send the message through the
|
||||
# plugins
|
||||
process_message_packet(packet)
|
||||
return
|
||||
elif msg_response == "ack":
|
||||
process_ack_packet(packet)
|
||||
return
|
||||
|
||||
if msg_format == "mic-e":
|
||||
# process a mic-e packet
|
||||
process_mic_e_packet(packet)
|
||||
return
|
||||
|
||||
except (aprslib.ParseError, aprslib.UnknownFormat) as exp:
|
||||
LOG.exception("Failed to parse packet from aprs-is", exp)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user