#!/usr/bin/perl

# This script provides a fake GPS that
# uses the NIST time as a base
# This can be used in place of an actual GPS
# for use with gpsd.
# To do so, replace the $LAT and $LONG values
# to match your local site.
# Also, set the ip address for the time server
# most appropriate for your use.  Check with
# the NIST for current time server addresses.
#
# You will want to use the new -w flag for
# gpsd to specify a polling interval also
# Otherwise, you will overpoll the NIST server
# and get odd results.  Poll every 60 seconds
# in a normal situation to most nearly approximate
# the corrective action that gpsd would take
# using a normal GPS.  Polling at 900 seconds
# (15 minutes) is good if you have an accurate
# clock.
# If you have a truly lousy clock, you might
# consider polling with a very short delay (1 second)
# and using the -h switch to force the time to
# be "jump" adjusted each second.  This is NOT
# recommended!! But it is an interesting option...
#
# normal use example:
#
#	gpsd -fsax fakegps -w 60
#

$| = 1;

# Vashon Island, Washington, USA
$LAT = 47.2518;
$NS = 'N';
$LONG = 122.4468;
$EW = 'W';

# Timeserver is time-nw.nist.gov
$TIMESVR = '131.107.1.10';

$NTIME = `nisttime -ta $TIMESVR`;
# TEST -- just use regular date instead
# $NTIME = `date`;
chomp($NTIME);

$HEAD = '$GPRMC';
$TIME = `date -u -d "$NTIME" +%H%M%S`;
$VALID = 'A';
$KNOTS = 0;
$TRACK = 0;
$DATE = `date -u -d "$NTIME" +%d%m%y`;

chomp($TIME);
chomp($DATE);

$out = "$HEAD,$TIME,$VALID,$LAT,$NS,$LONG,$EW,$KNOTS,$TRACK,$DATE";
# give the readout
print "$out\n";




