#!/usr/bin/ruby # ubx-get.rb - Utility to retrieve Almanac and Ephemeris data from u-blox GPS # receivers # # Copyright 2008 OpenMoko, Inc. # Authored by Daniel Willmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. gem_original_require 'serialport' require 'ubx-config' device = SerialPort.new(ARGV[0], baudrate=9600, databits=8, stopbits=1, parity=SerialPort::NONE) device.read_timeout=-1 if ARGV[1] fd = File.open(ARGV[1], 'w') end worker = Thread.new() { stream = [] while true begin stream << device.getc (msg, len) = Message.parse(stream.map {|i| i.chr}.to_s) if msg puts msg.to_a.inspect foo = Marshal.dump(msg) if fd fd.write([foo.length].pack("v")) fd.write(foo) end end stream = stream[len..-1] rescue puts "An error occurred: #{$!}" stream = [ ] end end } sleep(1) foo = Message.new(:AID, :ALM, []) puts "Almanach request" device.write(foo.to_s) device.flush() sleep(2) foo = Message.new(:AID, :EPH, []) puts "Ephimeris request" device.write(foo.to_s) device.flush() sleep(2) #foo = Message.new(:AID, :HUI, []) #puts "Health info request" #device.write(foo.to_s) #device.flush() #sleep(2) if fd fd.close end