git-svn-id: svn://svn.openwrt.org/openwrt/packages@5908 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
florian 2006-12-27 19:21:05 +00:00
parent 4b2601d406
commit f6791a95a1
5 changed files with 219 additions and 0 deletions

68
net/ntpd/Makefile Normal file
View File

@ -0,0 +1,68 @@
#
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id: Makefile 5624 2006-11-23 00:29:07Z nbd $
include $(TOPDIR)/rules.mk
PKG_NAME:=ntp
PKG_VERSION:=4.2.2p4
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/
PKG_MD5SUM:=916fe57525f8327f340b203f129088fa
PKG_CAT:=zcat
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
include $(INCLUDE_DIR)/package.mk
define Package/ntpd
SECTION:=net
CATEGORY:=Network
TITLE:=full featured NTP server
DEPENDS:=+libreadline
DESCRIPTION:=\
The full featured original ntpd
URL:=http://www.ntp.org/
endef
define Package/ntpd/conffiles
/etc/ntp.conf
endef
define Build/Configure
$(call Build/Configure/Default, \
--disable-all-clocks \
--disable-parse-clocks \
--enable-NMEA \
--enable-LOCAL-CLOCK \
--enable-SHM \
--enable-linuxcaps \
)
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CFLAGS="$(TARGET_CFLAGS)"
endef
define Package/ntpd/install
$(INSTALL_DIR) $(1)/usr/sbin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpd/ntpd $(1)/usr/sbin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpdate/ntpdate $(1)/usr/sbin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpdc/ntpdc $(1)/usr/sbin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpq/ntpq $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/etc
$(INSTALL_DATA) ./files/ntp.conf $(1)/etc/
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DATA) ./files/ntpd.init $(1)/etc/init.d/ntpd
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
$(INSTALL_DATA) ./files/ntpd.hotplug $(1)/etc/hotplug.d/iface/20-ntpd
endef
$(eval $(call BuildPackage,ntpd))

23
net/ntpd/files/ntp.conf Normal file
View File

@ -0,0 +1,23 @@
# use a random selection of 8 public stratum 2 servers
# see http://twiki.ntp.org/bin/view/Servers/NTPPoolServers
restrict default nomodify notrap noquery
restrict 127.0.0.1
restrict 192.168.1.253
driftfile /etc/ntp.drift
server 127.127.1.0
fudge 127.127.1.0 stratum 10
# GPS(NMEA)+PPS
#server 127.127.20.0 minpoll 4 prefer
#fudge 127.127.20.0 flag3 1 flag2 0
# SMA PPS
#server 127.127.28.0 minpoll 4 prefer
#fudge 127.127.28.0 refid PPS flag3 1
#server 192.168.1.253

View File

@ -0,0 +1,10 @@
NAME=ntpd
CONFIG=/etc/ntp.conf
COMMAND=/usr/sbin/$NAME
[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
[ -x $COMMAND ] && [ -r $CONFIG ] && {
killall ntpd
/etc/init.d/ntpd start
} &
}

13
net/ntpd/files/ntpd.init Normal file
View File

@ -0,0 +1,13 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=60
start() {
# ln -sf /dev/ttyS0 /dev/gps0
# /usr/sbin/setgarmin -d /dev/gps -c /etc/setgarmin.conf
/usr/sbin/ntpd -g
}
stop() {
killall ntpd
}

View File

@ -0,0 +1,105 @@
diff -Naurp ntp-4.2.2p4.orig/ntpd/refclock_nmea.c ntp-4.2.2p4.mash/ntpd/refclock_nmea.c
--- ntp-4.2.2p4.orig/ntpd/refclock_nmea.c 2006-06-06 22:16:53.000000000 +0200
+++ ntp-4.2.2p4.mash/ntpd/refclock_nmea.c 2006-12-13 16:22:26.000000000 +0100
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <ctype.h>
+#include <sys/ioctl.h>
#include "ntpd.h"
#include "ntp_io.h"
@@ -72,6 +72,7 @@
#define RANGEGATE 500000 /* range gate (ns) */
#define LENNMEA 75 /* min timecode length */
+#define LENPPS LINUXPPS_MAX_NAME_LEN
/*
* Tables to compute the ddd of year form icky dd/mm timecode. Viva la
@@ -92,6 +93,7 @@ struct nmeaunit {
pps_params_t pps_params; /* pps parameters */
pps_info_t pps_info; /* last pps data */
pps_handle_t handle; /* pps handlebars */
+ int handle_created; /* pps handle created flag */
#endif /* HAVE_PPSAPI */
};
@@ -140,7 +142,12 @@ nmea_start(
register struct nmeaunit *up;
struct refclockproc *pp;
int fd;
+#ifdef PPS_HAVE_FINDPATH
+ char id[LENPPS] = "",
+ path[LENPPS];
+#endif /* PPS_HAVE_FINDPATH */
char device[20];
+ uint bits, mask=~0, outb=0;
/*
* Open serial port. Use CLK line discipline, if available.
@@ -225,18 +232,42 @@ nmea_start(
memcpy((char *)&pp->refid, REFID, 4);
up->pollcnt = 2;
gps_send(pp->io.fd,"$PMOTG,RMC,0000*1D\r\n", peer);
+ gps_send(pp->io.fd,"$PGRMO,,2\r\n", peer);
+ gps_send(pp->io.fd,"$PGRMO,GPRMC,1\r\n", peer);
+ gps_send(pp->io.fd,"$PGRMO,,,,,,,,,,,,2\r\n", peer);
+
+ mask &= ~TIOCM_RTS;
+ mask &= ~TIOCM_DTR;
+ outb |= TIOCM_RTS;
+ ioctl(fd, TIOCMGET, &bits);
+ bits &= mask;
+ bits |= outb;
+ ioctl(fd, TIOCMSET, &bits);
#ifdef HAVE_PPSAPI
/*
* Start the PPSAPI interface if it is there. Default to use
* the assert edge and do not enable the kernel hardpps.
*/
+#ifdef PPS_HAVE_FINDPATH
+ /* Get the PPS source's real name */
+ time_pps_readlink(device, LENPPS, path, LENPPS);
+
+ /* Try to find the source */
+ fd = time_pps_findpath(path, LENPPS, id, LENPPS);
+ if (fd < 0) {
+ msyslog(LOG_ERR, "refclock_nmea: cannot find PPS path \"%s\" in the system", path);
+ return (0);
+ }
+ msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\" at id #%d on \"%s\"", path, fd, id);
+#endif /* PPS_HAVE_FINDPATH */
if (time_pps_create(fd, &up->handle) < 0) {
- up->handle = 0;
+ up->handle_created = 0;
msyslog(LOG_ERR,
"refclock_nmea: time_pps_create failed: %m");
return (1);
}
+ up->handle_created = ~0;
return(nmea_ppsapi(peer, 0, 0));
#else
return (1);
@@ -258,8 +289,10 @@ nmea_shutdown(
pp = peer->procptr;
up = (struct nmeaunit *)pp->unitptr;
#ifdef HAVE_PPSAPI
- if (up->handle != 0)
+ if (up->handle_created) {
time_pps_destroy(up->handle);
+ up->handle_created = 0;
+ }
#endif /* HAVE_PPSAPI */
io_closeclock(&pp->io);
free(up);
@@ -367,7 +400,7 @@ nmea_pps(
/*
* Convert the timespec nanoseconds field to ntp l_fp units.
*/
- if (up->handle == 0)
+ if (!up->handle_created)
return (0);
timeout.tv_sec = 0;
timeout.tv_nsec = 0;