#!/usr/bin/ruby =begin log.datのサイズを削減するためのファイル GPS時刻が入っていない部分を消去する =end $: << File::join(File::dirname(__FILE__), 'swig') require 'build_SWIG/SylphideProcessor.so' $options = {} ARGV.reject!{|arg| if arg =~ /--([^=]+)=?/ then $options[$1.to_sym] = $' true else false end } processor = SylphideProcessor::SylphideLog::new(1024) fname_src = ARGV.shift fname_dst = File::join(File::dirname(fname_src), "#{File::basename(fname_src, '.*')}.trunc.dat") $options[:out] ||= fname_dst $stderr.puts "src: #{fname_src} => dst: #{$options[:out]}" open(fname_src){|src_io| proc{|&block| if $options[:out] == '-' then block.call($stdout) else open($options[:out], 'w'){|dst_io| block.call(dst_io) } end }.call{|dst_io| do_write = false while true page = src_io.read(SylphideProcessor::PAGE_SIZE) break unless page processor.process(page){|observer| case observer when SylphideProcessor::APacketObserver if observer.fetch_ITOW < 10 then # threshold is 10 sec do_write = false end when SylphideProcessor::GPacketObserver #$stderr.puts "GPSTime: #{observer.fetch_ITOW}" #$stderr.puts "G #{format('0x%02X', observer.ubx_class)}, #{format('0x%02X', observer.ubx_id)}" case observer.ubx_class when 0x01 case observer.ubx_id when 0x03 #$stderr.puts (observer.status.status_flags & SylphideProcessor::GStatus::TOW_VALID) do_write = true if (observer.status.status_flags & SylphideProcessor::GStatus::TOW_VALID) > 0 end end end } dst_io.write(page) if do_write end } }