Parse packets

This commit is contained in:
assada 2023-07-22 19:46:06 +03:00
parent d0f9ba3690
commit 4953ad0cca
Signed by: assada
GPG Key ID: 8905E8CE5CC3000D
3 changed files with 74 additions and 7 deletions

28
aprs.py
View File

@ -6,6 +6,7 @@ import irc.client
import irc.client_aio
from ax253 import Frame
from datetime import datetime
import kiss
import aprslib
@ -21,6 +22,22 @@ nickname = os.environ.get('BOT_NICK', "aprsbot")
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG) ## TODO: Make logging level configurable
def parse_frame(date, frame):
try:
parsed = aprslib.parse(str(frame))
except (aprslib.ParseError, aprslib.UnknownFormat) as exp:
logger.error(f"Failed to parse frame: {frame}")
return str(frame)
formatted_string = date.strftime('%H:%M:%S.%f')[:-3] + " " + "{} -> {} -> {}:".format(parsed["from"], parsed["via"], parsed["to"])
formatted_string += " <{:.4f} {:.4f}>".format(parsed["latitude"], parsed["longitude"]) if "longitude" in parsed and "latitude" in parsed else ""
formatted_string += " tUNIT: " + ",".join(parsed["tUNIT"]) if "tUNIT" in parsed else ""
formatted_string += " tPARM: " + ",".join(parsed["tPARM"]) if "tPARM" in parsed else ""
formatted_string += " tEQNS: " + ",".join([''.join(str(i)) for i in parsed["tEQNS"]]) if "tEQNS" in parsed else ""
formatted_string += " tBITS: {}".format(parsed["tBITS"]) if "tBITS" in parsed else ""
formatted_string += " {}".format(parsed["comment"]) if "comment" in parsed else ""
formatted_string += " {}".format(parsed["title"]) if "title" in parsed else ""
return formatted_string
async def main():
logger.info(f"Connecting to {server}:{port} as {nickname}")
loop = asyncio.get_event_loop()
@ -36,16 +53,13 @@ async def main():
loop=loop,
)
irc_client.privmsg(channel, '[APRS] Starting...')
irc_client.privmsg(channel, 'Starting...')
async for frame in kiss_protocol.read():
try:
packet = aprslib.parse(str(frame))
except (aprslib.ParseError, aprslib.UnknownFormat) as exp:
pass
## TODO: Build APRS message from packet
time = datetime.utcnow()
logger.debug(f"Received frame: {frame}")
irc_client.privmsg(channel, str(frame)) ## TODO: Parse frame and send to channel
irc_client.privmsg(channel, parse_frame(time, frame))
if __name__ == "__main__":

35
packets.log Normal file
View File

@ -0,0 +1,35 @@
HP2PCO-13>APMI04,WIDE2-1,qAR,HP2DFA-1:=0921.46N/07953.61W_ DIGIPEATER PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI02,WIDE2-2,qAR,HP2DFA-6:=0921.46N/07953.61W_ WX STATION PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI04,WIDE2-1,qAR,HP2DFA-1:=0921.46N/07953.61W_ DIGIPEATER PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI02,WIDE2-2,qAR,HP2DFA-1:=0921.46N/07953.61W_ WX STATION PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI04,WIDE2-1,qAR,HP2DFA-1:=0921.46N/07953.61W_ DIGIPEATER PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI04,DIRECT,qAR,HP2DFA-6::HP2PCO-13:BITS.11111111,HP2PCO-3 Telemetry
HP2PCO-13>APMI04,DIRECT,qAR,HP2DFA-6::HP2PCO-13:EQNS.0,0.079,0,0,10,0,0,10,0,0,1,0,0,0,0
HP2PCO-13>APMI04,DIRECT,qAR,HP2DFA-6::HP2PCO-13:UNIT.Volt,Pkt,Pkt,Pcnt,None,On,On,On,On,Hi,Hi,Hi,Hi
HP2PCO-13>APMI04,DIRECT,qAR,HP2DFA-1::HP2PCO-13:PARM.Vin,Rx1h,Dg1h,Eff1h,A5,O1,O2,O3,O4,I1,I2,I3,I4
HP2PCO-13>APMI02,WIDE2-2,qAR,HP2DFA-1:=0921.46N/07953.61W_ WX STATION PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI04,WIDE2-1,qAR,HP2DFA-1:=0921.46N/07953.61W_ DIGIPEATER PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI02,WIDE2-2,qAR,HP2DFA-6:=0921.46N/07953.61W_ WX STATION PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI04,WIDE2-1,qAO,HP2DFA-6:=0921.46N/07953.61W_ DIGIPEATER PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI02,WIDE2-2,qAR,HP2DFA-1:=0921.46N/07953.61W_ WX STATION PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI04,WIDE2-1,qAR,HP2DFA-1:=0921.46N/07953.61W_ DIGIPEATER PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI02,WIDE2-2,qAR,HP2DFA-1:=0921.46N/07953.61W_ WX STATION PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI04,DIRECT,qAR,HP2DFA-6::HP2PCO-13:BITS.11111111,HP2PCO-3 Telemetry
HP2PCO-13>APMI04,DIRECT,qAO,HP2DFA-6::HP2PCO-13:EQNS.0,0.079,0,0,10,0,0,10,0,0,1,0,0,0,0
HP2PCO-13>APMI04,DIRECT,qAR,HP2DFA-6::HP2PCO-13:UNIT.Volt,Pkt,Pkt,Pcnt,None,On,On,On,On,Hi,Hi,Hi,Hi
HP2PCO-13>APMI04,DIRECT,qAR,HP2DFA-1::HP2PCO-13:PARM.Vin,Rx1h,Dg1h,Eff1h,A5,O1,O2,O3,O4,I1,I2,I3,I4
HP2PCO-13>APMI02,WIDE2-2,qAR,HP2DFA-1:=0921.46N/07953.61W_ WX STATION PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI04,WIDE2-1,qAR,HP2DFA-1:=0921.46N/07953.61W_ DIGIPEATER PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI02,WIDE2-2,qAR,HP2DFA-6:=0921.46N/07953.61W_ WX STATION PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI04,WIDE2-1,qAR,HP2DFA-1:=0921.46N/07953.61W_ DIGIPEATER PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP2PCO-13>APMI02,WIDE2-2,qAR,HP2DFA-1:=0921.46N/07953.61W_ WX STATION PCARA OESTE EN LA CIUDAD DE COLON RED APRS PANAMA II 12.7V
HP1CDB-10>APHP01,TCPIP*,qAC,T2SJC:!0902.40N/07925.04W-HP1CDB Carlos Daniel Baquero 73. / Raspbian Proyect by hp3icc
HP1CDB-10>APHP01,TCPIP*,qAC,T2MCI:!0902.40N/07925.04W-HP1CDB Carlos Daniel Baquero 73. / Raspbian Proyect by hp3icc
HP1CDB-10>APHP01,TCPIP*,qAC,T2MCI:!0902.40N/07925.04W-HP1CDB Carlos Daniel Baquero 73. / Raspbian Proyect by hp3icc
UR4UWA-4>APMI03,WIDE2-2,qAR,UT3UKU-10:@221717z5032.04N/03036.30E-PLXDigi U=12.3V.
UR4UWA-4>APMI03,WIDE2-2,qAR,UT3UKU-10::UR4UWA-4 :BITS.11111111,PLXDigi Telemetry
UR4UWA-4>APMI03,WIDE2-2,qAR,UT3UKU-10::UR4UWA-4 :EQNS.0,0.075,0,0,1,0,0,1,0,0,1,0,0,1,0
UR4UWA-4>APMI03,WIDE2-2,qAR,UT3UKU-10::UR4UWA-4 :UNIT.Volt,Pkt,Pkt,Pcnt,Pcnt,On,On,On,On,Hi,Hi,Hi,Hi
UR4UWA-4>APMI03,WIDE2-2,qAR,UT3UKU-10::UR4UWA-4 :PARM.Vin,Rx1h,Dg1h,Eff1h,Eff,O1,O2,O3,O4,I1,I2,I3,I4
UT3UKU-10>APJI43,UR4UWA-4,WIDE2-1:<IGATE,MSG_CNT=0,LOC_CNT=3

18
par.py Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
import aprslib
from datetime import datetime
packets = open('packets.log', 'r')
for packetString in packets:
formatted_string = datetime.utcnow().strftime('%H:%M:%S.%f')[:-3] + " " + "{} -> {} -> {}:".format(parsed["from"], parsed["via"], parsed["to"])
formatted_string += " <{:.4f} {:.4f}>".format(parsed["latitude"], parsed["longitude"]) if "longitude" in parsed and "latitude" in parsed else ""
formatted_string += " tUNIT: " + ",".join(parsed["tUNIT"]) if "tUNIT" in parsed else ""
formatted_string += " tPARM: " + ",".join(parsed["tPARM"]) if "tPARM" in parsed else ""
formatted_string += " tEQNS: " + ",".join([''.join(str(i)) for i in parsed["tEQNS"]]) if "tEQNS" in parsed else ""
formatted_string += " tBITS: {}".format(parsed["tBITS"]) if "tBITS" in parsed else ""
formatted_string += " {}".format(parsed["comment"]) if "comment" in parsed else ""
formatted_string += " {}".format(parsed["title"]) if "title" in parsed else ""
#print(parsed)
print(formatted_string)