kopia lustrzana https://github.com/DL7AD/pecanpico9
Updated decoder software
Implemented stdin connection Implemented APRS-IS connection Implemented error handling at internet lossDevelop
rodzic
34795ac9e5
commit
cf5fc0329b
|
@ -8,6 +8,7 @@ import urllib2
|
||||||
import io
|
import io
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
import aprs
|
||||||
|
|
||||||
# Parse arguments from terminal
|
# Parse arguments from terminal
|
||||||
parser = argparse.ArgumentParser(description='APRS/SSDV decoder')
|
parser = argparse.ArgumentParser(description='APRS/SSDV decoder')
|
||||||
|
@ -19,8 +20,14 @@ parser.add_argument('-b', '--baudrate', help='Baudrate for serial device', defau
|
||||||
parser.add_argument('-s', '--server', help='Server URL', default='https://ssdv.habhub.org/api/v0/packets')
|
parser.add_argument('-s', '--server', help='Server URL', default='https://ssdv.habhub.org/api/v0/packets')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.device is not '-': # Use serial connection (probably TNC)
|
if args.device == 'I': # Connect to APRS-IS
|
||||||
try:
|
|
||||||
|
aprsis = aprs.TCP('DL4MDW', aprs_filter='t/u u/APECAN')
|
||||||
|
aprsis.start()
|
||||||
|
|
||||||
|
elif args.device is not '-': # Use serial connection (probably TNC)
|
||||||
|
|
||||||
|
try:
|
||||||
serr = serial.Serial(
|
serr = serial.Serial(
|
||||||
port=args.device,
|
port=args.device,
|
||||||
baudrate=args.baudrate,
|
baudrate=args.baudrate,
|
||||||
|
@ -42,17 +49,25 @@ if args.log is not None:
|
||||||
|
|
||||||
jsons = []
|
jsons = []
|
||||||
|
|
||||||
while 1:
|
def received_data(data):
|
||||||
# Read a line (from stdin or serial)
|
global jsons
|
||||||
data = sys.stdin.readline() if args.device is '-' else ser.readline()
|
|
||||||
|
|
||||||
# Parse line and detect data
|
if str(type(data)) == "<class 'aprs.classes.Frame'>": # APRS-IS
|
||||||
m = re.search("(.*)\>APECAN:\{\{I(.*)", data)
|
|
||||||
try:
|
call = str(data.source)
|
||||||
call = m.group(1)
|
aprs = data.text[3:]
|
||||||
aprs = m.group(2)
|
receiver = 'APRS-IS/' + str(data.path.pop())
|
||||||
except:
|
|
||||||
continue # message format incorrect (probably no APRS message or line cut off too short)
|
else: # serial or stdin
|
||||||
|
|
||||||
|
# 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
|
||||||
|
@ -60,7 +75,7 @@ while 1:
|
||||||
data = base91.decode(aprs) # Decode Base91
|
data = base91.decode(aprs) # Decode Base91
|
||||||
|
|
||||||
if len(data) != 219:
|
if len(data) != 219:
|
||||||
continue # APRS message sampled too short
|
return # APRS message sampled too short
|
||||||
|
|
||||||
# Calculate CRC for SSDV server
|
# Calculate CRC for SSDV server
|
||||||
crc = binascii.crc32(data) & 0xffffffff
|
crc = binascii.crc32(data) & 0xffffffff
|
||||||
|
@ -72,7 +87,7 @@ while 1:
|
||||||
\"packet\": \"""" + ssdv + """\",
|
\"packet\": \"""" + ssdv + """\",
|
||||||
\"encoding\": \"hex\",
|
\"encoding\": \"hex\",
|
||||||
\"received\": \"""" + datetime.datetime.now().isoformat('T')[:19] + """Z\",
|
\"received\": \"""" + datetime.datetime.now().isoformat('T')[:19] + """Z\",
|
||||||
\"receiver\": \"""" + args.call + """\"
|
\"receiver\": \"""" + receiver + """\"
|
||||||
}""")
|
}""")
|
||||||
|
|
||||||
print 'Received packet call %02x%02x%02x%02x image %d packet %d' % (data[1], data[2], data[3], data[4], data[5], data[7] + data[6] * 256)
|
print 'Received packet call %02x%02x%02x%02x image %d packet %d' % (data[1], data[2], data[3], data[4], data[5], data[7] + data[6] * 256)
|
||||||
|
@ -86,9 +101,26 @@ while 1:
|
||||||
jsons = []
|
jsons = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = urllib2.urlopen(req, "".join(json.split(' '))) # Send packets to server
|
error = True
|
||||||
print 'Send to SSDV data server: OK'
|
while error:
|
||||||
|
try:
|
||||||
|
result = urllib2.urlopen(req, "".join(json.split(' '))) # Send packets to server
|
||||||
|
print 'Send to SSDV data server: OK'
|
||||||
|
error = False
|
||||||
|
except urllib2.URLError, error:
|
||||||
|
print 'Send to SSDV data server: failed (connection error :( trying again...)'
|
||||||
|
|
||||||
except urllib2.HTTPError, error: # The server did not like our packets :(
|
except urllib2.HTTPError, error: # The server did not like our packets :(
|
||||||
print 'Send to SSDV data server: failed'
|
print 'Send to SSDV data server: failed (the server did not like our packets :( )'
|
||||||
print error.read()
|
print error.read()
|
||||||
|
|
||||||
|
if args.device == 'I': # APRS-IS
|
||||||
|
|
||||||
|
aprsis.receive(callback=received_data) # Register APRS callback
|
||||||
|
|
||||||
|
else: # stdin or serial
|
||||||
|
|
||||||
|
while 1:
|
||||||
|
data = sys.stdin.readline() if args.device is '-' else ser.readline() # Read a line
|
||||||
|
received_data(data)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue