Skip to content

Instantly share code, notes, and snippets.

@Arnavion
Created August 12, 2022 19:44
Show Gist options
  • Save Arnavion/eb4b48b40af6a10756c0a712a108d494 to your computer and use it in GitHub Desktop.
Save Arnavion/eb4b48b40af6a10756c0a712a108d494 to your computer and use it in GitHub Desktop.
Pinephone pmoS GPS
# /etc/init.d/gps-nmea
#!/sbin/openrc-run
command=/usr/local/bin/gps-nmea.py
command_args=
command_background=true
pidfile="/run/${RC_SVCNAME}.pid"
output_logger='logger -p daemon.info -t gps-nmea.stdout'
error_logger='logger -p daemon.err -t gps-nmea.stderr'
depend() {
need dbus
need modemmanager
use syslog
}
start_pre() {
mkdir -p /var/lib/gps-nmea/
(
curl --fail --silent --show-error --location --output /var/lib/gps-nmea/agps-xtradata.bin.new 'https://xtrapath4.izatcloud.net/xtra3gr.bin' &&
mv /var/lib/gps-nmea/agps-xtradata.bin.new /var/lib/gps-nmea/agps-xtradata.bin
) || :
}
# /usr/local/bin/gps-nmea.py
#!/usr/bin/python3
import gi
import pydbus
import time
MM_MODEM_LOCATION_SOURCE_AGPS_MSB = 1 << 6
MM_MODEM_LOCATION_SOURCE_GPS_NMEA = 1 << 2
def try_modem_added(object_path, interfaces):
if 'org.freedesktop.ModemManager1.Modem.Location' in interfaces:
while True:
try:
print(f"added modem {object_path}", flush=True)
modem = bus.get('.ModemManager1', object_path)['org.freedesktop.ModemManager1.Modem.Location']
modem.InjectAssistanceData(xtradata)
modem.Setup(0, True)
modem.Setup(MM_MODEM_LOCATION_SOURCE_AGPS_MSB | MM_MODEM_LOCATION_SOURCE_GPS_NMEA, True)
print(f"set up modem {object_path}", flush=True)
break
except Exception as e:
print(f"error with modem {object_path}: {e}", flush=True)
time.sleep(1)
with open('/var/lib/gps-nmea/agps-xtradata.bin', 'rb') as f:
xtradata = f.read()
bus = pydbus.SystemBus()
manager = bus.get('.ModemManager1')['org.freedesktop.DBus.ObjectManager']
manager.InterfacesAdded.connect(try_modem_added)
for object_path, interfaces in manager.GetManagedObjects().items():
try_modem_added(object_path, interfaces)
loop = gi.repository.GLib.MainLoop()
loop.run()
# /usr/local/bin/gpsmonng
#!/bin/bash
clear
while sleep 1; do
printf -- '--- %s\n' "$(date)"
mmcli -m any --location-get |
awk '
/\$GPGSV,/ {
split($0, parts, ",");
for (i = 5; i < length(parts); i += 4) {
if (parts[i + 3] == "") {
printf ("~prn:%s ele:%s azi:%s~\n", parts[i], parts[i + 1], parts[i + 2]);
}
else {
printf ("[prn:%s ele:%s azi:%s snr:%s]\n", parts[i], parts[i + 1], parts[i + 2], parts[i + 3]);
}
}
}
'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment