#!/usr/bin/env ruby class Sylphide_Ublox_Extracter =begin 生データを取得 [[GPS時刻, 衛星数, [CP, Pseudo, Doppler, PRN, Q, SS, LLI]]...] =end def Sylphide_Ublox_Extracter.extract(stream) gps_raw_enabled = false gps_data = [] buf = [] stream.each{|line| line.chop! if gps_raw_enabled then case line when /^GPS_Time : ([\d\.]+)/ buf << $1.to_f when /^Number of satellites : (\d+)/ buf << $1.to_i when /^RAW\((\d+)\) : / index = $1.to_i values = $'.split(/[, ]+/) #p values =begin carrier_phase, psuedo_range, doppler sv_number quarity, signal_strength lock_indicator =end 3.times{|i| values[i] = values[i].to_f} (3...values.size).each{|i| values[i] = values[i].to_i } buf << values if index + 1 >= buf[1] then #p buf gps_data << buf #p gps_data buf = [] gps_raw_enabled = false end end elsif line =~ /^Number of satellites : (\d+)/ and $1.to_i >= 4 then gps_raw_enabled = true end } return gps_data end =begin 位置を取得 [[GPS時刻, 緯度, 経度, 高度, 水平精度, 垂直精度]...] =end def Sylphide_Ublox_Extracter.extract2(stream) gps_valid_data = false gps_data = [] buf = nil stream.each{|line| line.chop! if gps_valid_data then case line when /^GPS_Time : ([\d\.]+)/ buf = [] buf << $1.to_f when /^Position\(lat, long, alt\) : / buf << $'.split(/[, ]+/).collect{|item| item.to_f} when /^Position_Acc\(h, v\) : / buf << $'.split(/[, ]+/).collect{|item| item.to_f} gps_data << buf.flatten end elsif line =~ /^Number of satellites : (\d+)/ and $1.to_i >= 4 then gps_valid_data = true end } return gps_data end =begin 位置と速度を取得 [[GPS時刻, 緯度, 経度, 高度, 水平精度, 垂直精度, 速度N, 速度E, 速度D, 速度精度]...] =end def Sylphide_Ublox_Extracter.extract3(stream) gps_valid_data = false gps_data = [] buf = nil stream.each{|line| line.chop! if gps_valid_data then case line when /^GPS_Time : ([\d\.]+)/ buf = [$1.to_f] when /^Position\(lat, long, alt\) : / buf << $'.split(/[, ]+/).collect{|item| item.to_f} when /^Position_Acc\(h, v\) : / buf << $'.split(/[, ]+/).collect{|item| item.to_f} gps_data << buf.flatten when /^Velocity\(N, E, D\) : / buf << $'.split(/[, ]+/).collect{|item| item.to_f} when /^Velocity_Acc : / buf << $'.to_f gps_data.last.push(*buf.flatten) if buf[0] == gps_data.last[0] end elsif line =~ /^Number of satellites : (\d+)/ and $1.to_i >= 4 then gps_valid_data = true end } return gps_data end end if __FILE__ == $0 then gps_data_sv = {} Sylphide_Ublox_Extracter::extract($stdin).each{|time_data| gps_time = time_data.shift time_data.shift time_data.each{|sv_data| sv_num = sv_data.delete_at(3) unless gps_data_sv.include?(sv_num) then gps_data_sv[sv_num] = [] end gps_data_sv[sv_num] << [gps_time, sv_data].flatten! } } gps_data_sv.each{|key, val| fname = sprintf("ublox_sv_%03d.csv", key) fp = open(fname, "w") val.each{|v| fp.puts(v.join(', ')) } fp.close } end