--- /dev/null
+#!/bin/sh
+
+# apm/event.d script for GPS
+# we are in charge of powering it on and putting it in FixNOW mode for suspend.
+PATH=/usr/local/bin:$PATH
+export PATH
+case $1 in
+
+ start )
+ # power on
+ echo 1 > /sys/bus/platform/drivers/neo1973-pm-gps/neo1973-pm-gps.0/power_on
+ echo 1 > /sys/bus/platform/drivers/neo1973-pm-gps/neo1973-pm-gps.0/keep_on_in_suspend
+
+ mkdir -p /tmp/ubx
+ # Configure FixNOW
+ reacq_time=180 # seconds to try to reaquire after signal lost (3 minutes)
+ acq_time=180 # seconds to try to acquire (3 minutes)
+ reacq_off=1800 # seconds to stay off if reacq failed (30 minutes)
+ acq_off=1800 # seconds to stay off if acq failed (30 minutes)
+ on=35 # seconds to stay on once we have a fix
+ off=1500 # seconds to stay off when we have a fix (25 minutes)
+ ubxgen.py 06 0E L 18d4 \
+ ${reacq_time}000d4 ${acq_time}000d4 ${reacq_off}000d4 ${acq_off}000d4 \
+ ${on}000d4 ${off}000d4 0d4 0d4 > /tmp/ubx/CFG-FXN
+
+ # enable FixNOW
+ sens=00 # sensitivity - normal (01=fast 02=high 03=auto)
+ power=01 # 00=Continuous 01=FixNOW
+ ubxgen.py 06 11 L $sens $power > /tmp/ubx/Enable-FixNOW
+
+ # wake up and return to Continuous mode
+ power=00
+ echo -en '\0377\0377\0377\0377\0377\0377\0377\0377\0377\0377\0377' > /tmp/ubx/Enable-Cont
+ ubxgen.py 06 11 L $sens $power >> /tmp/ubx/Enable-Cont
+ # Request position info so it starts flowing
+ ubxgen.py 02 40 L >> /tmp/ubx/Enable-Cont
+
+ { echo -n "Power on: "; date ; } >> /var/log/gps-ttff
+ echo "Battery: `cat /sys/class/power_supply/battery/capacity`%" >> /var/log/gps-ttff
+ gpspipe -r | time -f 'TTFF: %e (%x)' 2>> /var/log/gps-ttff grep -s -m1 'GPRMC,[0-9.]*,A,[0-9.]*,[NS],[0-9.]*,[WE],[0-9.]*[1-9]' > /dev/null &
+ echo $! > /var/run/ttff.pid
+
+;;
+suspend )
+
+ # record location of suspend
+ pos=`gpspipe -r -n10 | awk -F, '/GPRMC/ {print $4, $5, $6, $7 ; exit} '`
+ echo "$pos `cat /var/run/gsm-state/cellid` `cat /var/run/gsm-state/cell`" >> /var/log/locations
+
+
+ # enable and enter FixNOW mode, sleeping for 20 minutes
+ # between fixes
+ [ -s /var/run/ttff.pid ] && kill `cat /var/run/ttff.pid`
+ rm /var/run/ttff.pid
+ { echo -n "Suspend: " ; date ; } >> /var/log/gps-ttff
+ cat /tmp/ubx/CFG-FXN /tmp/ubx/Enable-FixNOW > /dev/ttySAC1
+
+ # make sure we resume within 99 minutes.
+ if /media/card/wkalrm | grep pending > /dev/null
+ then /media/card/wkalrm off
+ fi
+ if /media/card/wkalrm | grep -s 'alarm disabled' > /dev/null
+ then /media/card/wkalrm +99m
+ fi
+;;
+
+resume )
+ # wake up the GPS, restore continuous mode, and enable reporting
+
+ cat /tmp/ubx/Enable-Cont > /dev/ttySAC1
+ { echo -n "Resume: " ; date ; } >> /var/log/gps-ttff
+ echo "Battery: `cat /sys/class/power_supply/battery/capacity`%" >> /var/log/gps-ttff
+ gpspipe -r | time -f 'TTFF: %e (%x)' 2>> /var/log/gps-ttff grep -s -m1 'GPRMC,[0-9.]*,A,[0-9.]*,[NS],[0-9.]*,[WE],[0-9.]*[1-9]' > /dev/null &
+ echo $! > /var/run/ttff.pid
+
+;;
+esac
+
--- /dev/null
+#!/usr/bin/python
+#
+# ubx packet generator
+#
+# v0.2
+#
+# Wilfried Klaebe <wk-openmoko@chaos.in-kiel.de>
+# NeilBrown <neilb@suse.de>
+#
+# Usage:
+#
+# ubxgen.py 06 13 04 00 01 00 00 00 > packet.ubx
+#
+# prepends 0xb5 0x62 header,
+# appends checksum,
+# outputs binary packet to stdout
+#
+# Numbers can be given in decimal with a suffix 'dN' where
+# 'N' is the number of bytes. These are converted in little-endian
+# The value 'L' can be given which is th 2-byte length
+# of the rest of the message
+#
+# you can send the packet to GPS chip like this:
+#
+# cat packet.ubx > /dev/ttySAC1
+
+import sys
+import binascii
+
+cs0=0
+cs1=0
+
+sys.stdout.write("\xb5\x62")
+
+outbuf = []
+leng = None
+
+for d in sys.argv[1:]:
+ if d == 'L':
+ leng = len(outbuf)
+ outbuf.append(0)
+ outbuf.append(0)
+ elif 'd' in d:
+ p = d.index('d')
+ bytes = int(d[p+1:])
+ d = int(d[0:p])
+ while bytes > 0:
+ b = d % 256
+ d = int(d/256)
+ outbuf.append(b)
+ bytes -= 1
+ else:
+ c = binascii.unhexlify(d)
+ outbuf.append(ord(c))
+
+if leng != None:
+ l = len(outbuf) - (leng + 2)
+ outbuf[leng] = l % 256
+ outbuf[leng+1] = int(l/256)
+
+for c in outbuf:
+ sys.stdout.write(chr(c))
+ cs0 += c
+ cs0 &= 255
+ cs1 += cs0
+ cs1 &= 255
+
+sys.stdout.write(chr(cs0)+chr(cs1))