kopia lustrzana https://github.com/DL7AD/pecanpico9
Removed APRS library and implemented native Telnet connection instead
rodzic
ea793f8d11
commit
aa258b9517
|
@ -8,7 +8,9 @@ import urllib2
|
||||||
import io
|
import io
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
import aprs
|
import getpass
|
||||||
|
import telnetlib
|
||||||
|
import time
|
||||||
|
|
||||||
# Parse arguments from terminal
|
# Parse arguments from terminal
|
||||||
parser = argparse.ArgumentParser(description='APRS/SSDV decoder')
|
parser = argparse.ArgumentParser(description='APRS/SSDV decoder')
|
||||||
|
@ -17,13 +19,13 @@ parser.add_argument('-l', '--log', help='Name of the logfile')
|
||||||
parser.add_argument('-n', '--grouping', help='Amount packets that will be sent to the SSDV server in one request', default=1, type=int)
|
parser.add_argument('-n', '--grouping', help='Amount packets that will be sent to the SSDV server in one request', default=1, type=int)
|
||||||
parser.add_argument('-d', '--device', help='Serial device (\'-\' for stdin)', default='-')
|
parser.add_argument('-d', '--device', help='Serial device (\'-\' for stdin)', default='-')
|
||||||
parser.add_argument('-b', '--baudrate', help='Baudrate for serial device', default=9600, type=int)
|
parser.add_argument('-b', '--baudrate', help='Baudrate for serial device', default=9600, type=int)
|
||||||
parser.add_argument('-s', '--server', help='Server URL', default='https://ssdv.habhub.org/api/v0/packets')
|
parser.add_argument('-s', '--server', help='SSDV server URL', default='https://ssdv.habhub.org/api/v0/packets')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.device == 'I': # Connect to APRS-IS
|
if args.device == 'I': # Connect to APRS-IS
|
||||||
|
|
||||||
aprsis = aprs.TCP('DL4MDW', aprs_filter='t/u u/APECAN')
|
tn = telnetlib.Telnet("rotate.aprs2.net", 14580)
|
||||||
aprsis.start()
|
tn.write("user DL7AD filter u/APECAN\n")
|
||||||
|
|
||||||
elif args.device is not '-': # Use serial connection (probably TNC)
|
elif args.device is not '-': # Use serial connection (probably TNC)
|
||||||
|
|
||||||
|
@ -49,25 +51,17 @@ if args.log is not None:
|
||||||
|
|
||||||
jsons = []
|
jsons = []
|
||||||
|
|
||||||
def received_data(data):
|
def received_data(data):
|
||||||
global jsons
|
global jsons
|
||||||
|
|
||||||
if str(type(data)) == "<class 'aprs.classes.Frame'>": # APRS-IS
|
# Parse line and detect data
|
||||||
|
m = re.search("(.*)\>APECAN(.*):\{\{I(.*)", data)
|
||||||
call = str(data.source)
|
try:
|
||||||
aprs = data.text[3:]
|
call = m.group(1)
|
||||||
receiver = 'APRS-IS/' + str(data.path.pop())
|
aprs = m.group(3)
|
||||||
|
receiver = args.call
|
||||||
else: # serial or stdin
|
except:
|
||||||
|
return # message format incorrect (probably no APRS message or line cut off too short)
|
||||||
# Parse line and detect data
|
|
||||||
m = re.search("(.*)\>APECAN(.*):\{\{I(.*)", data)
|
|
||||||
try:
|
|
||||||
call = m.group(1)
|
|
||||||
aprs = m.group(3)
|
|
||||||
receiver = 'APRS/'+m.group(2) if len(m.group(2)) > 0 else 'APRS/'+args.call
|
|
||||||
except:
|
|
||||||
return # message format incorrect (probably no APRS message or line cut off too short)
|
|
||||||
|
|
||||||
if args.log is not None:
|
if args.log is not None:
|
||||||
f.write(data) # Log data to file
|
f.write(data) # Log data to file
|
||||||
|
@ -120,11 +114,20 @@ def received_data(data):
|
||||||
|
|
||||||
if args.device == 'I': # APRS-IS
|
if args.device == 'I': # APRS-IS
|
||||||
|
|
||||||
aprsis.receive(callback=received_data) # Register APRS callback
|
buf = ''
|
||||||
|
while True:
|
||||||
|
buf += tn.read_eager()
|
||||||
|
if '\n' in buf:
|
||||||
|
pbuf = buf.split('\n')
|
||||||
|
for i in range(len(pbuf)-1):
|
||||||
|
print(pbuf[i])
|
||||||
|
received_data(pbuf[i])
|
||||||
|
buf = pbuf[-1]
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
else: # stdin or serial
|
else: # stdin or serial
|
||||||
|
|
||||||
while 1:
|
while True:
|
||||||
data = sys.stdin.readline() if args.device is '-' else ser.readline() # Read a line
|
data = sys.stdin.readline() if args.device is '-' else ser.readline() # Read a line
|
||||||
received_data(data)
|
received_data(data)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue