1
0
mirror of https://github.com/craigerl/aprsd.git synced 2024-12-22 09:31:42 -05:00

Merge pull request #100 from craigerl/webchat_gps

Send GPS Beacon from webchat interface
This commit is contained in:
Walter A. Boring IV 2022-11-30 11:25:34 -05:00 committed by GitHub
commit 78329f79f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 9 deletions

View File

@ -91,21 +91,29 @@ class KISS3Client:
# payload
# )).encode('US-ASCII'),
# payload = str(msg).encode('US-ASCII')
payload = None
path = ["WIDE1-1", "WIDE2-1"]
if isinstance(msg, messaging.AckMessage):
msg_payload = f"ack{msg.id}"
elif isinstance(msg, messaging.RawMessage):
payload = msg.message.encode("US-ASCII")
path = ["WIDE2-1"]
else:
msg_payload = f"{msg.message}{{{str(msg.id)}"
if not payload:
payload = (
":{:<9}:{}".format(
msg.tocall,
msg_payload,
)
).encode("US-ASCII")
LOG.debug(f"Send '{payload}' TO KISS")
frame = Frame.ui(
destination=msg.tocall,
source=msg.fromcall,
path=["WIDE1-1", "WIDE2-1"],
path=path,
info=payload,
)
self.kiss.write(frame)

View File

@ -9,6 +9,7 @@ import threading
import time
import aprslib
from aprslib import util as aprslib_util
import click
import flask
from flask import request
@ -433,6 +434,32 @@ class SendMessageNamespace(Namespace):
msg.send()
# self._msg_queues["tx"].put(msg)
def on_gps(self, data):
LOG.debug(f"WS on_GPS: {data}")
lat = aprslib_util.latitude_to_ddm(data["latitude"])
long = aprslib_util.longitude_to_ddm(data["longitude"])
LOG.debug(f"Lat DDM {lat}")
LOG.debug(f"Long DDM {long}")
local_datetime = datetime.datetime.now()
utc_offset_timedelta = datetime.datetime.utcnow() - local_datetime
result_utc_datetime = local_datetime + utc_offset_timedelta
time_zulu = result_utc_datetime.strftime("%d%H%M")
# now construct a beacon to send over the client connection
txt = (
f"{self._config['aprs']['login']}>APZ100,WIDE2-1"
f":!{lat}{long}#PHG7260 APRSD WebChat Beacon"
)
txt = f"@{time_zulu}z{lat}1{long}$APRSD WebChat Beacon"
LOG.debug(f"Sending {txt}")
beacon_msg = messaging.RawMessage(txt)
beacon_msg.fromcall = self._config["aprs"]["login"]
beacon_msg.tocall = "APDW16"
beacon_msg.send_direct()
def handle_message(self, data):
LOG.debug(f"WS Data {data}")

View File

@ -1,11 +1,11 @@
var cleared = false;
var callsign_list = {};
var message_list = {};
const socket = io("/sendmsg");
function size_dict(d){c=0; for (i in d) ++c; return c}
function init_chat() {
const socket = io("/sendmsg");
socket.on('connect', function () {
console.log("Connected to socketio");
});
@ -44,6 +44,54 @@ function init_chat() {
socket.emit("send", msg);
$('#message').val('');
});
$("#send_beacon").click(function() {
console.log("Send a beacon!")
getLocation();
});
}
function getLocation() {
if (navigator.geolocation) {
console.log("getCurrentPosition");
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
var msg = "Geolocation is not supported by this browser."
console.log(msg);
alert(msg)
}
}
function showError(error) {
console.log("showError");
console.log(error);
var msg = "";
switch(error.code) {
case error.PERMISSION_DENIED:
msg = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
msg = "Location information is unavailable."
break;
case error.TIMEOUT:
msg = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
msg = "An unknown error occurred."
break;
}
console.log(msg);
alert(msg);
}
function showPosition(position) {
console.log("showPosition Called");
msg = {
'latitude': position.coords.latitude,
'longitude': position.coords.longitude
}
console.log(msg);
socket.emit("gps", msg);
}

View File

@ -63,6 +63,7 @@
<input type="text" name="message" id="message" size="40" maxlength="40">
</div>
<input type="submit" name="submit" class="ui button" id="send_msg" value="Send" />
<button type="button" class="ui button" id="send_beacon" value="Send GPS Beacon">Send GPS Beacon</button>
</form>
</div>
</div>

View File

@ -19,7 +19,7 @@ ENV APRSD_PIP_VERSION=${APRSD_VERSION}
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install -y git build-essential rustc cargo
RUN apt install -y git build-essential
RUN apt install -y libffi-dev python3-dev libssl-dev libxml2-dev libxslt-dev
RUN apt install -y python3 python3-pip python3-dev python3-lxml