Skip to content

Commit

Permalink
Merge pull request #568 from pavel-demin/develop
Browse files Browse the repository at this point in the history
replace gpsd with gpsd-timepps and add PPS refclock to chrony configuration in alpine
  • Loading branch information
pavel-demin authored Sep 24, 2017
2 parents 67e5f97 + 293bcce commit 1665bca
Show file tree
Hide file tree
Showing 8 changed files with 360 additions and 1 deletion.
1 change: 1 addition & 0 deletions alpine/etc/chrony/chrony.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
refclock SHM 2 refid PPS precision 1e-9
pool pool.ntp.org iburst offline
makestep 1 -1
driftfile /var/lib/chrony/chrony.drift
3 changes: 3 additions & 0 deletions alpine/etc/conf.d/gpsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DEVICE="/dev/ttyPS1 /dev/pps0"
BAUDRATE="9600"
ARGS="-n "
60 changes: 60 additions & 0 deletions alpine/gpsd-timepps/APKBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
pkgname=gpsd-timepps
pkgver=3.17
pkgrel=1
pkgdesc="A GPS daemon"
arch=all
url="http://catb.org/gpsd/"
license="BSD"
depends=""
makedepends="scons python2-dev libcap-dev ncurses-dev"
install=
subpackages="$pkgname-dev"
source="http://download-mirror.savannah.gnu.org/releases/gpsd/gpsd-$pkgver.tar.gz
timepps.h
ttydefaults.patch
gpsd.initd
gpsd.confd"

_builddir="$srcdir"/gpsd-$pkgver


prepare() {
local i

sudo cp timepps.h /usr/include/sys/

cd "$_builddir"
for i in $source; do
case $i in
*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
esac
done
}

build() {
cd "$_builddir"
scons -j1 \
prefix=/usr \
|| return 1
}

package() {
cd "$_builddir"

mkdir -p "$pkgdir"/usr/lib
cp -a "$_builddir"/libgps*.so* "$pkgdir"/usr/lib/

mkdir -p "$pkgdir"/usr/sbin
for a in gpsdecode gpsd gpsctl gpsdctl gpspipe; do
install -m755 -D "$_builddir/"$a "$pkgdir"/usr/sbin/
done

install -m755 -D "$srcdir"/gpsd.initd "$pkgdir"/etc/init.d/gpsd
install -m644 -D "$srcdir"/gpsd.confd "$pkgdir"/etc/conf.d/gpsd
}

sha512sums="71085053f600730e0f2de269c59ce0a17ae106ef01403f02d78418b267c6adb9818d541fba59eb23bf71cdb67c5442c82b4948d262ef7e74bb993dcae677a1b1 gpsd-3.17.tar.gz
eb11fc19243d1789016d88eb7645bfe67c46304547781489bf36eb1dd4c252d523681ff835a6488fa0ef62b6b9e2f781c672279f4439f5d5640a3f214a113048 timepps.h
e2af8f52fc2d7e663882b6d12c5f4d709aa267b16eb9aeca2a70d8ecc681ae72359f3efcd1636cde576bc8579e008f242574bc0adfab7252d3e763f039e86135 ttydefaults.patch
a0e7bf206ad51c31195f86f79ef92adca425d7f988534c0f70a2dd3053613f6fc46820d62d0330aaef7ca100b5f2ab781ce9643f25b4c99c844ae66e7eec5cbc gpsd.initd
55d4a51f82d445d3ac93b2855132ef4380908ed045feba6298ed1d0b607cd9054b5325c024dc52b370983ebd5d9b377537aee7d7128c97aa22e3075f4134d404 gpsd.confd"
29 changes: 29 additions & 0 deletions alpine/gpsd-timepps/gpsd.confd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# /etc/conf.d/gpsd

# The GPS device (/dev/ttyUSB0, /dev/ttyS0, ...)

DEVICE=""
BAUDRATE="4800"

# Optional arguments
# Options include:
# -b = bluetooth-safe: open data sources read-only
# -n = don't wait for client connects to poll GPS
# -N = don't go into background
# -F sockfile = specify control socket location
# -G = make gpsd listen on INADDR_ANY
# -D integer (default 0) = set debug level
# -S integer (default 2947) = set port for daemon

ARGS="-n "

# Serial setup
#
# For serial interfaces, options such as low_latency are recommended
# Also, http://catb.org/gpsd/upstream-bugs.html#tiocmwait recommends
# setting the baudrate with stty
# Uncomment the following lines if using a serial device:
#
# /bin/stty -F ${DEVICE} ${BAUDRATE}
# /bin/setserial ${DEVICE} low_latency

38 changes: 38 additions & 0 deletions alpine/gpsd-timepps/gpsd.initd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/sbin/openrc-run
# Copyright 2012 Nathan Angelacos

description="GPS daemon"

depend() {
need net
after firewall
use ntp-server
}

GPS=${SVCNAME#*.}
if [ -n "${GPS}" ] && [ ${SVCNAME} != "gpsd" ]; then
GPSPID="/var/run/gpsd.${GPS}.pid"
else
GPSPID="/var/run/gpsd.pid"
fi

start() {

if [ -z "${DEVICE}" ]; then
eerror "Specify a GPS device in /etc/conf.d/${SVCNAME}"
return 1
fi

ebegin "Starting gpsd"
start-stop-daemon --start --quiet \
--exec /usr/sbin/gpsd \
-- ${ARGS} -P "${GPSPID}" ${DEVICE}
eend $? "Failed to start gpsd"
}

stop() {
ebegin "Stopping gpsd"
start-stop-daemon --stop --quiet \
--pidfile "${GPSPID}"
eend $? "Failed to stop gpsd"
}
216 changes: 216 additions & 0 deletions alpine/gpsd-timepps/timepps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/*
* timepps.h -- PPS API main header
*
* Copyright (C) 2005-2007 Rodolfo Giometti <[email protected]>
* Copyright (C) 2009-2011 Alexander Gordeev <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Source: https://github.com/ago/pps-tools/ - Retreived Dec 2013
*/

#ifndef _SYS_TIMEPPS_H_
#define _SYS_TIMEPPS_H_

#include <errno.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/pps.h>

#define LINUXPPS 1 /* signal we are using LinuxPPS */

/*
* New data structures
*/

struct ntp_fp {
unsigned int integral;
unsigned int fractional;
};

union pps_timeu {
struct timespec tspec;
struct ntp_fp ntpfp;
unsigned long longpad[3];
};

struct pps_info {
unsigned long assert_sequence; /* seq. num. of assert event */
unsigned long clear_sequence; /* seq. num. of clear event */
union pps_timeu assert_tu; /* time of assert event */
union pps_timeu clear_tu; /* time of clear event */
int current_mode; /* current mode bits */
};

struct pps_params {
int api_version; /* API version # */
int mode; /* mode bits */
union pps_timeu assert_off_tu; /* offset compensation for assert */
union pps_timeu clear_off_tu; /* offset compensation for clear */
};

typedef int pps_handle_t; /* represents a PPS source */
typedef unsigned long pps_seq_t; /* sequence number */
typedef struct ntp_fp ntp_fp_t; /* NTP-compatible time stamp */
typedef union pps_timeu pps_timeu_t; /* generic data type for time stamps */
typedef struct pps_info pps_info_t;
typedef struct pps_params pps_params_t;

#define assert_timestamp assert_tu.tspec
#define clear_timestamp clear_tu.tspec

#define assert_timestamp_ntpfp assert_tu.ntpfp
#define clear_timestamp_ntpfp clear_tu.ntpfp

#define assert_offset assert_off_tu.tspec
#define clear_offset clear_off_tu.tspec

#define assert_offset_ntpfp assert_off_tu.ntpfp
#define clear_offset_ntpfp clear_off_tu.ntpfp

/*
* The PPS API
*/

static __inline int time_pps_create(int source, pps_handle_t *handle)
{
int ret;
struct pps_kparams dummy;

if (!handle) {
errno = EINVAL;
return -1;
}

/* First we check if current device is a valid PPS one by
* doing a dummy PPS_GETPARAMS...
*/
ret = ioctl(source, PPS_GETPARAMS, &dummy);
if (ret) {
errno = EOPNOTSUPP;
return -1;
}

/* ... then since in LinuxPPS there are no differences between a
* "PPS source" and a "PPS handle", we simply return the same value.
*/
*handle = source;

return 0;
}

static __inline int time_pps_destroy(pps_handle_t handle)
{
return close(handle);
}

static __inline int time_pps_getparams(pps_handle_t handle,
pps_params_t *ppsparams)
{
int ret;
struct pps_kparams __ppsparams;

ret = ioctl(handle, PPS_GETPARAMS, &__ppsparams);

ppsparams->api_version = __ppsparams.api_version;
ppsparams->mode = __ppsparams.mode;
ppsparams->assert_off_tu.tspec.tv_sec = __ppsparams.assert_off_tu.sec;
ppsparams->assert_off_tu.tspec.tv_nsec = __ppsparams.assert_off_tu.nsec;
ppsparams->clear_off_tu.tspec.tv_sec = __ppsparams.clear_off_tu.sec;
ppsparams->clear_off_tu.tspec.tv_nsec = __ppsparams.clear_off_tu.nsec;

return ret;
}

static __inline int time_pps_setparams(pps_handle_t handle,
const pps_params_t *ppsparams)
{
struct pps_kparams __ppsparams;

__ppsparams.api_version = ppsparams->api_version;
__ppsparams.mode = ppsparams->mode;
__ppsparams.assert_off_tu.sec = ppsparams->assert_off_tu.tspec.tv_sec;
__ppsparams.assert_off_tu.nsec = ppsparams->assert_off_tu.tspec.tv_nsec;
__ppsparams.clear_off_tu.sec = ppsparams->clear_off_tu.tspec.tv_sec;
__ppsparams.clear_off_tu.nsec = ppsparams->clear_off_tu.tspec.tv_nsec;

return ioctl(handle, PPS_SETPARAMS, &__ppsparams);
}

/* Get capabilities for handle */
static __inline int time_pps_getcap(pps_handle_t handle, int *mode)
{
return ioctl(handle, PPS_GETCAP, mode);
}

static __inline int time_pps_fetch(pps_handle_t handle, const int tsformat,
pps_info_t *ppsinfobuf,
const struct timespec *timeout)
{
struct pps_fdata __fdata;
int ret;

/* Sanity checks */
if (tsformat != PPS_TSFMT_TSPEC) {
errno = EINVAL;
return -1;
}

if (timeout) {
__fdata.timeout.sec = timeout->tv_sec;
__fdata.timeout.nsec = timeout->tv_nsec;
__fdata.timeout.flags = ~PPS_TIME_INVALID;
} else
__fdata.timeout.flags = PPS_TIME_INVALID;

ret = ioctl(handle, PPS_FETCH, &__fdata);

ppsinfobuf->assert_sequence = __fdata.info.assert_sequence;
ppsinfobuf->clear_sequence = __fdata.info.clear_sequence;
ppsinfobuf->assert_tu.tspec.tv_sec = __fdata.info.assert_tu.sec;
ppsinfobuf->assert_tu.tspec.tv_nsec = __fdata.info.assert_tu.nsec;
ppsinfobuf->clear_tu.tspec.tv_sec = __fdata.info.clear_tu.sec;
ppsinfobuf->clear_tu.tspec.tv_nsec = __fdata.info.clear_tu.nsec;
ppsinfobuf->current_mode = __fdata.info.current_mode;

return ret;
}

#ifdef PPS_KC_BIND

static __inline int time_pps_kcbind(pps_handle_t handle,
const int kernel_consumer,
const int edge, const int tsformat)
{
struct pps_bind_args __bind_args;

__bind_args.tsformat = tsformat;
__bind_args.edge = edge;
__bind_args.consumer = kernel_consumer;

return ioctl(handle, PPS_KC_BIND, &__bind_args);
}

#else /* !PPS_KC_BIND */

static __inline int time_pps_kcbind(pps_handle_t handle,
const int kernel_consumer,
const int edge, const int tsformat)
{
/* LinuxPPS doesn't implement kernel consumer feature */
errno = EOPNOTSUPP;
return -1;
}

#endif /* PPS_KC_BIND */

#endif /* _SYS_TIMEPPS_H_ */
12 changes: 12 additions & 0 deletions alpine/gpsd-timepps/ttydefaults.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/gpsmon.c b/gpsmon.c
index c3001c8..965ea98 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -19,6 +19,7 @@
#include <sys/time.h> /* expected to declare select(2) a la SuS */
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/ttydefaults.h>
#include <sys/select.h>
#include <fcntl.h>
#include <unistd.h>
2 changes: 1 addition & 1 deletion scripts/alpine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ echo $alpine_url/community >> $root_dir/etc/apk/repositories
chroot $root_dir /bin/sh <<- EOF_CHROOT
apk update
apk add openssh iw wpa_supplicant dhcpcd dnsmasq hostapd-rtl871xdrv iptables avahi dcron chrony gpsd subversion make gcc musl-dev fftw-dev libconfig-dev alsa-lib-dev alsa-utils curl wget less nano bc
apk add openssh iw wpa_supplicant dhcpcd dnsmasq hostapd-rtl871xdrv iptables avahi dcron chrony gpsd-timepps subversion make gcc musl-dev fftw-dev libconfig-dev alsa-lib-dev alsa-utils curl wget less nano bc
ln -s /etc/init.d/bootmisc etc/runlevels/boot/bootmisc
ln -s /etc/init.d/hostname etc/runlevels/boot/hostname
Expand Down

0 comments on commit 1665bca

Please sign in to comment.