Easy Timestamping with Bash

10/02/2015

Here’s a quick Bash script to prefix lines read from standard input by a time stamp.

#!/usr/bin/env bash

while read line
do
    echo $(date "$@") "$line"
done

This script takes the same arguments as the traditional Unix date program. With no arguments, it prints some default-formatted date, but if you feel like it, you can pass it the same arguments as date. For example:

.../geolocalisation> cat /dev/ttyACM0 | ts.sh +"%H:%I:%M:%S.%N" | grep GPRMC | tee $(date | tr \  - | tr : - ).dat
15:03:42:57.355437828 $GPGGA,204226.000,4821.6737,N,06844.4790,W,1,08,1.2,-0.9,M,,,,00$GPRMC,204247.000,A,4821.6740,N,06844.4799,W,0.00,181.2,060215,,*2B
15:03:42:57.629415235 $GPRMC,204248.000,A,4821.6740,N,06844.4799,W,0.00,181.2,060215,,*24
15:03:42:57.881812555 $GPRMC,204249.000,A,4821.6740,N,06844.4800,W,0.00,181.2,060215,,*2A
15:03:42:58.150091204 $GPRMC,204250.000,A,4821.6740,N,06844.4800,W,0.00,181.2,060215,,*22
15:03:42:58.420285771 $GPRMC,204251.000,A,4821.6740,N,06844.4800,W,0.00,181.2,060215,,*23
15:03:42:58.682492676 $GPRMC,204252.000,A,4821.6740,N,06844.4800,W,0.00,181.2,060215,,*20

So Let’s examine the script more closely. The $@ passed as argument to date is the series of all arguments passed to the script. Why is it enclosed in quotes? Because it preserves the structures of the arguments passed to the script for date. In the specific case of date it might not be necessary because of the nature of its arguments, but should you replace date with some other command, it may cause problems to remove the quotes. The $line is also enclosed in quotes because otherwise the script misbehaves: it would, for example, try to expand *.


Comparing GPSes (yet more GPS data)

03/02/2015

In a few other entries, I’ve toyed with GPS, either getting or parsing the data with Bash, assessing or using the GPS data. However, when we use GPS, we suppose that the precision varies by brand and model&mdashsome will have greater precision—but our intuition tells us that two GPS devices of the same brand and model should perform identically. That’s what we’re used to with, or at least expect from, computers. But what about USB GPS devices?

162px-Gray_compass_rose.svg

So I got two instances of the same model+brand GPS. Let them call them GPS-1 and GPS-2. Do they perform similarly?

Read the rest of this entry »


Test Drive (more GPS data)

04/06/2013

In a few previous entries, we looked at how to capture, parse, and evaluate the precision of a NMEA-capable GPS. The next step is to take it on a test drive.

map-detail

The setup is simple: a laptop, a USB GPS, a car, and a map. The map is provided by Google Maps, of course. The car and the laptop do not really matter (as long as one of the two runs Linux and has a USB port); the USB GPS is the Columbus V800.

Read the rest of this entry »


A First Look At GPS Data

21/05/2013

In previous installments, we looked at how to read data from a serial-over-USB GPS, then how to parse the data. However, getting data isn’t everything, we must also ascertain it’s valid

map-detail

The first thing that comes to mind to test the device’s precision (while I don’t really know how to check for the accuracy) by plug it in, leave it stationary, and collect the readings for a good while

Read the rest of this entry »


Parsing GPS data with Bash

07/05/2013

Last time we looked at how to get the data to the GPS and now we will have a look at how to parse the data. Turns out that except for the check-sum, everything is pretty straight forward, even in Bash.

map-detail

So, why bash in the first place? Well, there’s not real reason except that for the something else I’m working on, it’s the ideal glue-code language, allowing me to invoke simply other programs that I do not want to re-code (or take parts of) to do what I want. I must say that I even have a C# version of the GPS data grabber, but while fancier, it does not bring much more than the Bash version.

Read the rest of this entry »


Reading GPS data with Bash

30/04/2013

I am presently working on something that requires geolocation. Not knowing much about GPSes and related topics, I decided to get a USB GPS. This week, let’s have a look at how we can extract information from the USB GPS using Bash.

map-detail

The first step is to locate your USB GPS as a device. If it’s NMEA compliant, it should mount automagically as a USB serial port. You would think that lsusb -v would show you the device, but it does not always. Sometimes it shows as “Brand X GPS”, sometimes it only shows as a generic device, say “MediaTek Inc.”, or even as a modem. It will typically show up as /dev/ttyUSB0 or /dev/ttyACM0.

Read the rest of this entry »


Suggested Reading: Lost Cat

21/04/2013

Caroline Paul, Wendy MacNaughton — Lost Cat: A True Story of Love, Desperation, and GPS Technology — Bloomsburt, 2013, 176 pp. ISBN 1608199770

(Buy at Amazon.com)

(Buy at Amazon.com)

This is a story of Tibia the cat that suddenly vanishes for five weeks before coming back. In full health, shiny coat, happy. Then vanishes again. Quickly, Caroline Paul catlover, couchridden following a plane crash, worries about Tibby, wondering where he was and why he didn’t come back sooner. Then begins a detective story: will a GPS and a camera attached to the cat reveal its whereabouts?

Read the rest of this entry »