#!/usr/bin/ruby # ubx-set.rb - Utility to set Almanac and Ephemeris data for 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 fd = File.open(ARGV[1], 'r') 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 end stream = stream[len..-1] rescue puts "An error occurred: #{$!}" stream = [ ] end end } sleep(2) while !fd.eof? len = fd.read(2).unpack("v")[0] data = fd.read(len) msg = Marshal.load(data) puts msg.to_a.inspect device.write(msg.to_s) device.flush() end fd.close