gps_pvt 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9977db11c202c0e16e0db9a06a91419011732835f8d406194f4663342e79eef
4
- data.tar.gz: 485793ee595d5245e383f70de03efd77f98f1e4228ba74b782c80fb2d0e06946
3
+ metadata.gz: a75bed6b9453e7fe5b435eb2c10bd82e7c736654b6d34461368b79274ee223e3
4
+ data.tar.gz: 55577769f09988ce63809f52b14a82bfa7fd958f68547f36263647b147559831
5
5
  SHA512:
6
- metadata.gz: ee59dd138de2243ea47a170c8d0724803fb3a5e19b28b5fe360649614c827b020000dc264dfd810b48346cfb3ddd0929925633d9769848a782ee6c65feeb0143
7
- data.tar.gz: 63230d1fee5eadb80487df64d679300144a457efaaa6f9874a6574bb600c47307f4cedab607385d9bfd73a5c43e0e066f22ee09ccd0b81a6294d688c753d3e08
6
+ metadata.gz: 01c350f1e321119d0b4693a9b96bc99003b92e37783cdc53f0779e02111ec880d2b26e30e1f1ccec81faaaca16d730b8e17a5d24eb9bacd2934fe0ffaf083284
7
+ data.tar.gz: 6cab5c290099b0dd7604940822c9399dc93d7656651fe4c38003202745c8b5f561c68cb452ece7c2d9b35740d7621b47e809341cec2228d3551e3238e2648c23
data/exe/gps2ubx CHANGED
@@ -31,7 +31,7 @@ misc_options = {
31
31
  files = ARGV.collect{|arg|
32
32
  next [arg, nil] unless arg =~ /^--([^=]+)=?/
33
33
  k, v = [$1.downcase.to_sym, $']
34
- next [v, k] if [:rinex_nav, :rinex_obs].include?(k) # file type
34
+ next [v, k] if [:rinex_nav, :rinex_obs, :ubx, :rtcm3].include?(k) # file type
35
35
  options << [$1.to_sym, $']
36
36
  nil
37
37
  }.compact
@@ -43,14 +43,10 @@ files.collect!{|fname, ftype|
43
43
  when /\.\d{2}o(?:\.gz)?$/; :rinex_obs
44
44
  when /\.ubx$/; :ubx
45
45
  end
46
- fname = proc{
47
- next fname if File::exist?(fname)
48
- if uri = URI::parse(fname) and !uri.instance_of?(URI::Generic) then
49
- ftype ||= uri.read_format if uri.instance_of?(URI::Ntrip)
50
- next uri
51
- end
52
- raise "File not found: #{fname}"
53
- }.call
46
+ if (!(uri = URI::parse(fname)).instance_of?(URI::Generic) rescue false) then
47
+ ftype ||= uri.read_format if uri.instance_of?(URI::Ntrip)
48
+ fname = uri
49
+ end
54
50
  raise "Format cannot be guessed, use --(format, ex. rinex_obs)=#{fname}" unless ftype
55
51
  [fname, ftype]
56
52
  }
@@ -70,7 +66,7 @@ options.reject!{|opt|
70
66
 
71
67
  rcv = GPS_PVT::Receiver::new(options)
72
68
 
73
- obs = []
69
+ obs = Queue::new
74
70
  rcv.define_singleton_method(:run){|meas, t_meas, *args|
75
71
  obs << [t_meas, meas]
76
72
  }
@@ -98,15 +94,23 @@ files.each{|fname, ftype|
98
94
  }
99
95
 
100
96
  # other files
101
- files.each{|fname, ftype|
102
- case ftype
103
- when :ubx; rcv.parse_ubx(fname){}
104
- when :rinex_obs; rcv.parse_rinex_obs(fname){}
105
- when :rtcm3; rcv.parse_rtcm3(fname){}
97
+ threads = files.collect{|fname, ftype|
98
+ task = case ftype
99
+ when :ubx; proc{rcv.parse_ubx(fname){}}
100
+ when :rinex_obs; proc{rcv.parse_rinex_obs(fname){}}
101
+ when :rtcm3; proc{rcv.parse_rtcm3(fname){}}
106
102
  end
107
- }
103
+ case fname
104
+ when URI::Ntrip; Thread::new(&task)
105
+ else; task.call; nil
106
+ end
107
+ }.compact
108
108
 
109
- obs.sort!{|a, b| a[0] <=> b[0]} # Sort by measurement time
109
+ obs = proc{
110
+ tmp = []
111
+ tmp << obs.pop until obs.empty?
112
+ tmp
113
+ }.call.sort!{|a, b| b[0] <=> a[0]} if threads.empty? # Sort by measurement time
110
114
 
111
115
  # Time packet for solution of leap seconds
112
116
  gen_gpstime = proc{
@@ -368,7 +372,18 @@ gen_list << gen_gpstime unless misc_options[:ubx_rawx]
368
372
  gen_list << (misc_options[:ubx_rawx] ? gen_sfrbx : gen_sfrb) if misc_options[:broadcast_data]
369
373
  gen_list << (misc_options[:ubx_rawx] ? gen_rawx : gen_raw)
370
374
  STDOUT.binmode
371
- obs.each{|t_meas, meas|
372
- meas2 = meas.to_hash
373
- gen_list.each{|gen| print gen.call(t_meas, meas2)}
375
+
376
+ task_dump = proc{
377
+ until obs.empty? do
378
+ t_meas, meas = obs.pop
379
+ meas2 = meas.to_hash
380
+ gen_list.each{|gen| print gen.call(t_meas, meas2)}
381
+ end
374
382
  }
383
+ if threads.empty? then
384
+ task_dump.call
385
+ else
386
+ (threads << Thread::new{loop{
387
+ task_dump.call
388
+ }}).each{|th| th.join}
389
+ end
data/exe/gps_get CHANGED
@@ -20,30 +20,21 @@ files = ARGV.collect{|arg|
20
20
  nil
21
21
  }.compact
22
22
 
23
- spec2io = proc{
24
- io_pool = {}
25
- proc{|spec, mode_r|
26
- mode_r = true if (mode_r == nil)
27
- next (io_pool[spec] ||= open(spec)) if Serial::SPEC =~ spec # serial port
28
- if (uri = (URI::parse(spec) rescue nil)) and !uri.instance_of?(URI::Generic) then # URI
29
- if mode_r then
30
- case uri
31
- when URI::Ntrip; next URI::open(uri)
32
- else; next GPS_PVT::Util::get_txt(uri)
33
- end
34
- end
35
- raise "Unknown URI: #{spec}"
36
- end
37
- if mode_r then # file
38
- next STDIN if spec == '-'
39
- next open(GPS_PVT::Util::get_txt(spec), 'r') if File::exist?(spec)
40
- raise "File not found: #{spec}"
41
- else
42
- next STDOUT if spec == '-'
43
- open(spec, 'a+')
44
- end
45
- }
46
- }.call
23
+ spec2io = proc{|spec, mode_r|
24
+ mode_r = ((nil == mode_r) || mode_r)
25
+ is_stream = false
26
+ if (!(uri = URI::parse(spec)).instance_of?(URI::Generic) rescue false) then
27
+ spec = uri
28
+ is_stream = true if uri.kind_of?(URI::Ntrip)
29
+ else
30
+ is_stream = GPS_PVT::Util::special_stream?(spec)
31
+ end
32
+ if is_stream || (!mode_r) then
33
+ GPS_PVT::Util::open(spec, mode_r ? 'r' : 'a+')
34
+ else
35
+ open(GPS_PVT::Util::get_txt(spec), 'r')
36
+ end
37
+ }
47
38
 
48
39
  STDIN.binmode
49
40
  STDOUT.binmode
data/exe/gps_pvt CHANGED
@@ -77,15 +77,10 @@ files.collect!{|fname, ftype|
77
77
  when /\.atx(?:\.Z)?$/; :antex
78
78
  when /\.clk$/; :rinex_clk
79
79
  end
80
- fname = proc{
81
- next fname if File::exist?(fname)
82
- next fname if ((fname =~ Serial::SPEC) rescue false)
83
- if uri = URI::parse(fname) and !uri.instance_of?(URI::Generic) then
84
- ftype ||= uri.read_format if uri.instance_of?(URI::Ntrip)
85
- next uri
86
- end
87
- raise "File not found: #{fname}"
88
- }.call
80
+ if (!(uri = URI::parse(fname)).instance_of?(URI::Generic) rescue false) then
81
+ ftype ||= uri.read_format if uri.instance_of?(URI::Ntrip)
82
+ fname = uri
83
+ end
89
84
  raise "Format cannot be guessed, use --(format, ex. rinex_nav)=#{fname}" unless ftype
90
85
  [fname, ftype]
91
86
  }
@@ -137,10 +132,11 @@ files.each{|fname, ftype|
137
132
  }
138
133
 
139
134
  # other files
140
- files.each{|fname, ftype|
135
+ files.collect{|fname, ftype|
141
136
  case ftype
142
- when :ubx; rcv.parse_ubx(fname)
143
- when :rinex_obs; rcv.parse_rinex_obs(fname)
144
- when :rtcm3; rcv.parse_rtcm3(fname)
137
+ when :ubx; Thread::new{rcv.parse_ubx(fname)}
138
+ when :rinex_obs; Thread::new{rcv.parse_rinex_obs(fname)}
139
+ when :rtcm3; Thread::new{rcv.parse_rtcm3(fname)}
140
+ else; nil
145
141
  end
146
- }
142
+ }.compact.each{|th| th.join}
@@ -7,7 +7,7 @@ class Receiver
7
7
  def parse_rtcm3(src, opt = {}, &b)
8
8
  $stderr.print "Reading RTCM3 stream (%s) "%[src]
9
9
  require_relative '../rtcm3'
10
- src_io = open(src)
10
+ src_io = Util::open(src)
11
11
  rtcm3 = GPS_PVT::RTCM3::new(src_io)
12
12
  ref_time = case (ref_time = opt[:ref_time])
13
13
  when GPS::Time;
@@ -460,7 +460,7 @@ class Receiver
460
460
  $stderr.print "Reading UBX file (%s) "%[ubx_fname]
461
461
  require_relative 'ubx'
462
462
 
463
- ubx = UBX::new(open(ubx_fname))
463
+ ubx = UBX::new(Util::open(ubx_fname))
464
464
  ubx_kind = Hash::new(0)
465
465
 
466
466
  after_run = b || proc{|pvt| puts pvt.to_s if pvt}
data/lib/gps_pvt/util.rb CHANGED
@@ -23,14 +23,6 @@ proc{
23
23
  }
24
24
  def eof?; false; end
25
25
  }
26
- module Kernel
27
- open_orig = instance_method(:open)
28
- define_method(:open){|*args, &b|
29
- return open_orig.bind(self).call(*args, &b) unless Serial::SPEC =~ args[0]
30
- Serial::new($1, $2 ? $2.to_i : 115200)
31
- }
32
- module_function(:open)
33
- end
34
26
  }.call if require 'rubyserial'
35
27
 
36
28
  require 'open-uri'
@@ -41,7 +33,7 @@ class URI::Ntrip
41
33
  pnt_list = self.read_source_table(options).mount_points
42
34
  case pnt_list[self.mount_point][:format]
43
35
  when /u-?b(?:lo)?x/i; :ubx
44
- when /RTCM 3/i; :rtcm3
36
+ when /RTCM ?3/i; :rtcm3
45
37
  else; nil
46
38
  end
47
39
  end
@@ -50,6 +42,24 @@ end
50
42
  module GPS_PVT
51
43
  module Util
52
44
  class << self
45
+ def special_stream?(spec)
46
+ ['-', (Serial::SPEC rescue nil)].compact.any?{|v| v === spec}
47
+ end
48
+ def open(*args, &b)
49
+ return args[0].open(*args[1..-1], &b) if args[0].respond_to?(:open)
50
+ case args[0].to_str
51
+ when (Serial::SPEC rescue nil)
52
+ return ((@serial_ports ||= {})[$1] ||= Serial::new($1, $2 ? $2.to_i : 115200))
53
+ when '-'
54
+ if (/^[wa]/ === args[1]) \
55
+ || (args[1].kind_of?(Integer) && ((File::Constants::WRONLY & args[1]) > 0)) then
56
+ return STDOUT
57
+ else
58
+ return STDIN
59
+ end
60
+ end rescue nil
61
+ super
62
+ end
53
63
  def inflate(src, type = :gz)
54
64
  case type
55
65
  when :gz
@@ -66,7 +76,7 @@ module Util
66
76
  end
67
77
  def get_txt(fname_or_uri)
68
78
  is_uri = fname_or_uri.kind_of?(URI)
69
- (is_uri ? URI : Kernel).send(:open, fname_or_uri){|src|
79
+ open(fname_or_uri){|src|
70
80
  compressed = proc{
71
81
  case src.content_type
72
82
  when /gzip/; next :gz
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GPS_PVT
4
- VERSION = "0.9.0"
4
+ VERSION = "0.9.1"
5
5
 
6
6
  def GPS_PVT.version_compare(a, b)
7
7
  Gem::Version::new(a) <=> Gem::Version::new(b)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gps_pvt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - fenrir(M.Naruoka)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-22 00:00:00.000000000 Z
11
+ date: 2023-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyserial