Tracklog

From OpenTom

Jump to: navigation, search

There is not builtin track-logger in the TomTom. But a simple tracklogger, which dumps the Position data including altitude every 2 seconds into a simple ASCI-File can be written with X11-Basic.

Following simple program does the job. Execute it from the shell with:

 xbasic nmea.bas > logfile.dat

or if you want to also use the Navigation software:

  xbasic nmea.bas > logfile.dat &

and then quit the Console. (To stop the tracklogging you need to either reset the device or open TTconsole again and do a

 killall xbasic

Here is the program:

' This program reads the NMEA stream from the GPS-Device of a TomTom Naviagator and
' filters it and outputs Position and altitude data every 2 seconds
' (c) Markus Hoffmann 2008 
' written in X11-Basic
'
' Usage: xbasic nmea.bas
'

logfile$="/mnt/sdcard/statdata/tracklog-"+date$+".dat"
tmpfile$="/tmp/trlog-"+str$(timer)+".dat"

if exist("/var/run/gpsfeed")
  open "I",#1,"/var/run/gpsfeed"
else 
  open "I",#1,"nmea-xx.xx.xxxx.log"    ! ##### Here you must insert the filename of your logfile
  logfile$="tracklog-"+date$+".dat"
endif

dim satinfo$(12)

open "O",#2,tmpfile$
llt=timer
do
  lineinput #1,t$
  if left$(t$)="$"
    t$=right$(t$,len(t$)-1)
    while asc(right$(t$))=13
      t$=left$(t$,len(t$)-1)
    wend
    if mid$(t$,len(t$)-2)="*"
      chk=val("0x"+right$(t$,2))
      t$=left$(t$,len(t$)-3)
      if chk=@calcchk(t$)
        @processline(t$)
      else
        print #2,"# ERROR: CHK-ERROR! <"+t$+">"
      endif
    else
      @processline(t$)
    endif
  endif
  if timer-llt>5*60
    flush #2
    @savelog
    llt=timer
  endif
loop
flush #2
@savelog
close
quit

procedure savelog
  if exist(tmpfile$)
    if not exist(logfile$)
      open "O",#3,logfile$
    else
      open "A",#3,logfile$
    endif
    print #3,"# Tracklog from "+date$+" "+time$+" "+tmpfile$
    close #2
    open "I",#4,tmpfile$
    print #3,input$(#4,lof(#4));
    close #4
    close #3
    system "rm -f "+tmpfile$
    tmpfile$="/tmp/trlog-"+str$(stimer)+".dat"
    open "O",#2,tmpfile$
  endif
return
function calcchk(c$)
  local c,i
  c=0
  for i=0 to len(c$)-1
    c=c xor (peek(varptr(c$)+i) and 0xff)
  next 
  return c
endfunction
procedure processline(l$)
  local a$,b$,t$
  split l$,",",0,a$,b$
  if a$="GPGGA"
    split b$,",",0,t$,b$
    gpstime$=left$(t$,2)+":"+mid$(t$,3,2)+":"+mid$(t$,5,5)
    split b$,",",0,t$,b$
    lat=val(left$(t$,2))+val(right$(t$,len(t$)-2))/60
    split b$,",",0,t$,b$
    if t$="S"
      lat=-lat
    endif  
    split b$,",",0,t$,b$
    lon=val(left$(t$,3))+val(right$(t$,len(t$)-3))/60
    split b$,",",0,t$,b$
    if t$="W"
      lon=-lon
    endif
    split b$,",",0,t$,b$
    quality=val(t$)
    split b$,",",0,t$,b$
    numsat=val(t$)
    split b$,",",0,t$,b$
    dilution=val(t$)
    split b$,",",0,t$,b$
    alt=val(t$)
    split b$,",",0,altunit$,b$
    split b$,",",0,t$,b$
    geosep=val(t$)
    split b$,",",0,geosepunit$,b$
    split b$,",",0,t$,b$
    dgpsalter=val(t$)
    split b$,",",0,t$,b$
    dgpsref=val(t$)
  else if a$="GPRMC"
    split b$,",",0,t$,b$
    gpstime$=left$(t$,2)+":"+mid$(t$,3,2)+":"+mid$(t$,5,5)
    split b$,",",0,status$,b$
    if status$<>"A"
      continuity=0
    endif
    split b$,",",0,t$,b$
    lat=val(left$(t$,2))+val(right$(t$,len(t$)-2))/60
    split b$,",",0,t$,b$
    if t$="S"
      lat=-lat
    endif  
    split b$,",",0,t$,b$
    lon=val(left$(t$,3))+val(right$(t$,len(t$)-3))/60
    split b$,",",0,t$,b$
    if t$="W"
      lon=-lon
    endif
    split b$,",",0,t$,b$
    speed=val(t$)
    split b$,",",0,t$,b$
    kurs=val(t$)
    split b$,",",0,t$,b$
    datum$=left$(t$,2)+"."+mid$(t$,3,2)+".20"+right$(t$,2)
    split b$,",",0,t$,b$
    split b$,",",0,magdeva$,b$
    magdev=val(t$)
    if status$="A"
      if continuity
        print #2,"  + ";  
      else
        print #2," ** ";
        continuity=1
      endif
      print #2,"X=";lon;" ";"Y=";lat;" ";"alt=";alt;" ";
      print #2,"date=";@daten(datum$,gpstime$);" ";
      print #2,"q=";quality;" ";
      print #2,datum$+" "+gpstime$;" ";"v=";speed;" ";"dir=";kurs;" ";
      if len(b$)
        print #2,"comment="+chr$(34)+b$+chr$(34)
      else
        print #2
      endif
    endif
  else if a$="GPGSA"
    if status$<>"A"
      print #2,"# Satinfo: <"+l$+">"
    endif  
  else if a$="GPGSV"
    split b$,",",0,t2$,b$
    split b$,",",0,t1$,b$
    split b$,",",0,t3$,b$
    split b$,",",0,t4$,b$
    split b$,",",0,t5$,b$
    split b$,",",0,t6$,b$
    split b$,",",0,t7$,b$
    if status$<>"A"
      print #2,"# Satinview[";t1$;"/";t2$;"]: #";t4$;"/";t3$;" ele=";t5$;" az=";t6$;" SNR=";t7$
    endif
  else 
    print #2,"# Unknown Message: "+a$+" <"+l$+">"
  endif
return
function jdate$(n)
  local t$,tagzeit
  tagzeit=n mod (24*3600)
  t$=@days2date$(int(n/(24*3600)))
  t$=t$+" "+str$(int(tagzeit/3600),2,2,1)+":"+str$(int((tagzeit mod 3600)/60),2,2,1)+":"+str$(int(tagzeit mod 60),2,2,1)
  return t$
endfunc  
function days2date$(days)
  return juldate$(2447892+days)
endfunction
function daten(d$,t$)
  local n
  n=julian(d$)-2447892
  n=n*(24*3600)
  add n,val(left$(t$,2))*3600+val(mid$(t$,4,2))*60+val(right$(t$,len(t$)-6))
  return n
endfunction

By the way: The output format can be imported by GPS-Earth (see: http://gps-earth.sourceforge.net/)


See also: nmealog

Personal tools