From 3ca437617cedc38470aa96586a50dd200f020cd9 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 30 Dec 2021 21:06:25 -0500 Subject: [PATCH] initial commit --- README.md | 4 ++ coords.py | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 57 ++++++++++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 README.md create mode 100644 coords.py create mode 100644 main.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..eabd358 --- /dev/null +++ b/README.md @@ -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. + \ No newline at end of file diff --git a/coords.py b/coords.py new file mode 100644 index 0000000..7867ac0 --- /dev/null +++ b/coords.py @@ -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() diff --git a/main.py b/main.py new file mode 100644 index 0000000..2937493 --- /dev/null +++ b/main.py @@ -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()