-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ffac-update-location-gps: add first version to update a location base…
…d on an attached GPS device
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# SPDX-FileCopyrightText: 2024 Florian Maurer, xelo | ||
# SPDX-License-Identifier: MIT | ||
include $(TOPDIR)/rules.mk | ||
|
||
PKG_NAME:=ffac-update-location-gps | ||
PKG_VERSION:=1.0 | ||
PKG_RELEASE:=1 | ||
|
||
PKG_LICENSE:=MIT | ||
|
||
include $(TOPDIR)/../package/gluon.mk | ||
|
||
define Package/$(PKG_NAME) | ||
TITLE:=Use attached GPS controller to update location from it | ||
DEPENDS:=+kmod-usb-core +kmod-usb-acm +kmod-usb-serial-pl2303 | ||
endef | ||
|
||
define Package/$(PKG_NAME)/description | ||
The functionality of this is meant to update the location based on the NMEA output of a location system | ||
endef | ||
|
||
$(eval $(call BuildPackageGluon,$(PKG_NAME))) |
2 changes: 2 additions & 0 deletions
2
ffac-update-location-gps/files/etc/config/update-location-gps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
config settings 'settings' | ||
option enabled '0' |
24 changes: 24 additions & 0 deletions
24
ffac-update-location-gps/files/etc/hotplug.d/usb/10-update-location-gps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
TTYPATH="/sys${DEVPATH}/tty" | ||
LOCKPATH="/tmp/update-location-gps" | ||
|
||
ENABLED=$(uci get update-location-gps.settings.enabled) | ||
|
||
if [ "${ACTION}" = "add" ]; then | ||
[ "${ENABLED}" != "1" ] && exit 0 | ||
test -e "${LOCKPATH}" && exit 0 | ||
if test -e "${TTYPATH}"; then | ||
TTY_NAME=$(find "${TTYPATH}" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | sed -n 's|.*/tty/||p') | ||
logger -t hotplug "USB GPS device was plugged in" | ||
echo "${DEVPATH}" > "${LOCKPATH}" | ||
echo "*/5 * * * * /usr/bin/update-location-gps /dev/${TTY_NAME} > logger -t update-location-gps" > "/usr/lib/micron.d/update-location-gps" | ||
fi | ||
fi | ||
|
||
if [ "${ACTION}" = "remove" ]; then | ||
if [ "${DEVPATH}" = "$(cat ${LOCKPATH})" ]; then | ||
logger -t hotplug "USB GPS device was removed" | ||
rm -f "/usr/lib/micron.d/update-location-gps" | ||
rm "${LOCKPATH}" | ||
fi | ||
fi |
73 changes: 73 additions & 0 deletions
73
ffac-update-location-gps/luasrc/usr/bin/update-location-gps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/lua | ||
|
||
-- Get GPS device tty | ||
local TTY_DEVICE = arg[1] | ||
|
||
local uci = require('simple-uci').cursor() | ||
|
||
os.execute("stty -F " .. TTY_DEVICE .. " raw 4800 cs8 clocal -parenb crtscts -cstopb") | ||
|
||
-- Use GPS as Stream | ||
local file = io.open(TTY_DEVICE, "r") | ||
|
||
while true do | ||
local this_line = file:read("*line") | ||
if not this_line then break end -- Exit loop if no more lines | ||
|
||
local nc = this_line:match("^([^,]+)") | ||
|
||
if nc == '$GPRMC' then | ||
local fields = {} | ||
for field in this_line:gmatch("([^,]+)") do | ||
table.insert(fields, field) | ||
end | ||
|
||
local valid = fields[3] | ||
|
||
if valid == "A" then | ||
-- First: Retrieve coordinate | ||
local lat = fields[4] | ||
local lon = fields[6] | ||
|
||
-- Second: Determine if coordinate is oriented North/South or East/West | ||
local latdir = fields[5] | ||
local londir = fields[7] | ||
|
||
-- Split DEGREES from coordinate | ||
local latdeg = tonumber(lat:sub(1, 2)) | ||
local londeg = tonumber(lon:sub(1, 3)) | ||
|
||
-- Split MINUTES.SECONDS from coordinate | ||
local latmin = tonumber(lat:sub(3)) | ||
local lonmin = tonumber(lon:sub(4)) | ||
|
||
-- Convert from Degree-Minutes to Decimal-Minutes | ||
local latdec = latmin / 60 | ||
local londec = lonmin / 60 | ||
|
||
-- Use negative notation instead of North/South or East/West | ||
if latdir == 'S' then | ||
latdeg = -latdeg | ||
end | ||
if londir == 'W' then | ||
londeg = -londeg | ||
end | ||
lat = string.format("%f", latdeg + latdec) | ||
lon = string.format("%f", londeg + londec) | ||
|
||
print("Position is valid Lat/Lon:", lat, lon) | ||
-- set temp location in gluon-node-info | ||
uci:set('gluon-node-info', '@location[0]', 'share_location', '1') | ||
uci:set('gluon-node-info', '@location[0]', 'latitude', lat) | ||
uci:set('gluon-node-info', '@location[0]', 'longitude', lon) | ||
uci:save('gluon-node-info') | ||
break | ||
else | ||
print("Position is Invalid...", valid) | ||
break | ||
end | ||
end | ||
end | ||
|
||
file:close() | ||
os.exit(0) |