initial commit

This commit is contained in:
Alex 2021-12-30 21:06:25 -05:00
commit 3ca437617c
No known key found for this signature in database
GPG Key ID: 35EAACA0716F3723
3 changed files with 178 additions and 0 deletions

4
README.md Normal file
View File

@ -0,0 +1,4 @@
# APRS-draw
APRS-draw is a project to faciliate the drawing of shapes on APRS by entering in points.
Currently points can be taken in by GPX file named points.gpx in the working directory you are in.

117
coords.py Normal file
View File

@ -0,0 +1,117 @@
#! /usr/bin/env python
# Simple script to convert normal coords to APRS coordinates
import xml.sax
import sys
class CoordHandler(xml.sax.ContentHandler):
counter = 0
lats = []
lons = []
def __init__(self):
pass
def startElement(self, tag, attrs):
# Handle waypoints
if tag == 'wpt':
self.counter += 1
lat = float(attrs['lat'])
lon = float(attrs['lon'])
# format latitude for APRS
if lat < 0:
northsouth = 'S'
else:
northsouth = 'N'
lat = abs(lat)
lat_degrees = str(int(lat))
if len(lat_degrees) < 2:
lat_degrees = '0' + lat_degrees
lat_minutes = ((lat % 1) * 60).__round__(2)
lat_partial_minutes = str((lat_minutes % 1).__round__(2))[1:]
lat_minutes = str(int(lat_minutes))
while len(lat_minutes) < 2:
lat_minutes = '0' + lat_minutes
while len(lat_partial_minutes) < 3:
lat_partial_minutes += '0'
lat_aprs = lat_degrees + lat_minutes + lat_partial_minutes + northsouth
# format longitude for APRS
if lon < 0:
eastwest = 'W'
else:
eastwest = 'E'
lon = abs(lon)
lon_degrees = str(int(abs(lon)))
if len(lon_degrees) < 3:
lon_degrees = '0' + lon_degrees
lon_minutes = ((lon % 1) * 60).__round__(2)
lon_partial_minutes = str((lon_minutes % 1).__round__(2))[1:]
lon_minutes = str(int(lon_minutes))
while len(lon_minutes) < 2:
lon_minutes = '0' + lon_minutes
while len(lon_partial_minutes) < 3:
lon_partial_minutes += '0'
lon_aprs = lon_degrees + lon_minutes + lon_partial_minutes + eastwest
# Data Verification
if len(lat_aprs) != 8:
print('lat: ' + str(len(lat_aprs)), file=sys.stderr)
print('lat: ' + str(lat_aprs), file=sys.stderr)
raise
if len(lon_aprs) != 9:
print('lon: ' + str(len(lon_aprs)), file=sys.stderr)
print('lon: ' + str(lon_aprs), file=sys.stderr)
raise
self.lats.append(lat_aprs)
self.lons.append(lon_aprs)
def endElement(self, tag):
pass
def characters(self, content):
pass
def main():
# create an XMLReader
parser = xml.sax.make_parser()
# turn off namepsaces
parser.setFeature(xml.sax.handler.feature_namespaces, 0)
# override the default ContextHandler
xml.sax.parse("points.gpx", CoordHandler())
print(CoordHandler.lats)
print(CoordHandler.lons)
pass
if __name__ == '__main__':
main()

57
main.py Normal file
View File

@ -0,0 +1,57 @@
import socket
import sys
import time
lat_points = []
lon_points = []
call = b'N0CALL'
passcode = b''
server = 'noam.aprs2.net'
port = 14580
message = b'Hello, World'
def set_posit(connection: socket, lat: bytes, lon: bytes, message: bytes):
packet = b'' + call + b'>APRS,TCPIP*:' + b'!' + \
lat + b'/' + lon + b'/' + message + b'\n'
connection.send(packet)
print(b'sent:' + packet)
time.sleep(5)
def main():
points = 0
if len(lat_points) == len(lon_points):
points = len(lat_points)
else:
print('lat: ' + str(len(lat_points)) +
'\nlon: ' + str(len(lon_points)))
print('lat and lon points are not equal')
sys.exit(1)
connection: socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.connect((server, port))
r = connection.recv(1024)
print('server is running: ' + str(r))
# Logs into the server
connection.send(b'user ' + call + b' pass ' +
passcode + b' vers aprs-draw 0.0.0' b'\n')
r = connection.recv(1024)
print('logged in: ' + str(r))
for i in range(points):
lat = bytes(lat_points[i], 'utf-8')
lon = bytes(lon_points[i], 'utf-8')
set_posit(connection, lat, lon, message)
connection.close()
pass
if __name__ == '__main__':
main()