#!/usr/bin/ruby class ADExtractor def initialize(options = {}) @time_xyz = {} end attr_reader :time_xyz def process(page) if page[0] == ?A then start_time = page[1...5].unpack("V").first # ms 5.step(31, 3){|n| @time_xyz[start_time] = page[n...(n+3)].unpack("c*") start_time += 20 # 50Hz } return true else return false end end end if __FILE__ == $0 then $stderr.puts "Usage #{__FILE__} log.dat" if ARGV.size < 1 then exit end file_name = ARGV.shift extractor = ADExtractor::new open(file_name){|io| io.binmode page_count = -1 while !io.eof? page_count += 1 extractor.process(io.read(32)) end extractor.time_xyz.to_a.sort{|a, b| a[0] <=> b[0]}.each{|time, xyz_g| x, y, z = xyz_g puts sprintf("%10d%5d%5d%5d", time, x, y, z) } } end