gps_pvt 0.10.1 → 0.10.3

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.
@@ -46,10 +46,10 @@ rule
46
46
  DefinitiveNameAndNumberForm : identifier LCBRACE DefinitiveNumberForm RCBRACE
47
47
 
48
48
  TagDefault :
49
- EXPLICIT TAGS {raise} # not supported
50
- | IMPLICIT TAGS {raise} # not supported
51
- | AUTOMATIC TAGS
52
- | {raise} # not supported
49
+ EXPLICIT TAGS {@tags = val[0]}
50
+ | IMPLICIT TAGS {@tags = val[0]}
51
+ | AUTOMATIC TAGS {@tags = val[0]} # 12.3
52
+ | {@tags = :EXPLICIT} # 12.2
53
53
 
54
54
  ExtensionDefault :
55
55
  EXTENSIBILITY IMPLIED
@@ -179,8 +179,8 @@ rule
179
179
  #| RelativeOIDType
180
180
  | SequenceType
181
181
  | SequenceOfType
182
- #| SetType
183
- #| SetOfType
182
+ | SetType
183
+ | SetOfType
184
184
  | TaggedType
185
185
  | UTCTime # 43. Universal time
186
186
 
@@ -199,32 +199,34 @@ rule
199
199
  | ObjectClassFieldValue
200
200
 
201
201
  BuiltinValue : # 16.9
202
- BitStringValue
203
- | BooleanValue
204
- | CharacterStringValue
205
- | ChoiceValue
202
+ BitStringValue # String, Array, Hash (possible returned value, same below)
203
+ | BooleanValue # true/false
204
+ | CharacterStringValue # String, Array, Hash
205
+ | ChoiceValue # Hash
206
206
  #| EmbeddedPDVValue
207
- | EnumeratedValue
207
+ | EnumeratedValue # String
208
208
  #| ExternalValue
209
209
  #| InstanceOfValue
210
- | IntegerValue
211
- | NullValue
212
- | ObjectIdentifierValue
213
- | OctetStringValue
214
- | RealValue
210
+ | IntegerValue # Number, String
211
+ | NullValue # nil
212
+ | ObjectIdentifierValue # Array
213
+ | OctetStringValue # String, Hash
214
+ | RealValue # Number, Hash(M * B^E), String([PLUS|MINUS]_INFINITY)
215
215
  #| RelativeOIDValue
216
- | SequenceValue
217
- | SequenceOfValue
218
- #| SetValue
219
- #| SetOfValue
216
+ | SequenceValue # Hash
217
+ | SequenceOfValue # Array, Hash
218
+ | SetValue # Hash
219
+ | SetOfValue # Array, Hash
220
220
  #| TaggedValue
221
221
 
222
222
  #ReferencedValue : DefinedValue | ValueFromObject # 16.11
223
223
  #ReferencedValue : identifier
224
224
 
225
+ NamedValue : identifier Value {result = {val[0] => val[1]}} # 16.13
226
+
225
227
  # 17. Notation for the boolean type
226
228
  BooleanType : BOOLEAN
227
- BooleanValue : TRUE | FALSE
229
+ BooleanValue : TRUE {result = true} | FALSE {result = false}
228
230
 
229
231
  # 18. Notation for the integer type
230
232
  IntegerType :
@@ -240,7 +242,7 @@ rule
240
242
  number
241
243
  | MINUS number {result = -val[1]}
242
244
 
243
- IntegerValue :
245
+ IntegerValue : # returning Number or String
244
246
  SignedNumber
245
247
  | identifier
246
248
 
@@ -299,13 +301,13 @@ rule
299
301
  # 20. Notation for the real type
300
302
  RealType : REAL
301
303
 
302
- RealValue :
304
+ RealValue : # returning Number, Hash (M * B^E) or String ([PLUS|MINUS]_INFINITY)
303
305
  NumericRealValue
304
306
  | SpecialRealValue
305
307
  NumericRealValue :
306
308
  realnumber
307
- | MINUS realnumber
308
- | SequenceValue
309
+ | MINUS realnumber {result = -val[1]}
310
+ | SequenceValue # 20.3 in M * B^E format
309
311
  SpecialRealValue : PLUS_INFINITY | MINUS_INFINITY
310
312
 
311
313
  # 21. Notation for the bitstring
@@ -319,22 +321,22 @@ rule
319
321
  identifier LCBRACE number RCBRACE {result = {val[0] => val[2]}}
320
322
  | identifier LCBRACE DefinedValue RCBRACE {result = {val[0] => val[2]}}
321
323
 
322
- BitStringValue :
324
+ BitStringValue : # returning String, Array or Hash
323
325
  bstring
324
326
  | hstring
325
- | LBRACE IdentifierList RBRACE
326
- | LBRACE RBRACE
327
- | CONTAINING Value
327
+ | LBRACE IdentifierList RBRACE {result = val[1]}
328
+ | LBRACE RBRACE {result = []}
329
+ | CONTAINING Value {result = {:containing => val[1]}}
328
330
  IdentifierList :
329
- identifier
330
- | IdentifierList COMMA identifier
331
+ identifier {result = [val[0]]}
332
+ | IdentifierList COMMA identifier {result << val[2]}
331
333
 
332
334
  # 22. Notation for the octetstring type
333
335
  OctetStringType : OCTET STRING {result = {:type => :OCTET_STRING}}
334
- OctetStringValue :
336
+ OctetStringValue : # returning String or Hash
335
337
  bstring
336
338
  | hstring
337
- | CONTAINING Value
339
+ | CONTAINING Value {result = {:containing => val[1]}}
338
340
 
339
341
  # 23. Notation for the null type
340
342
  NullType : NULL
@@ -409,12 +411,12 @@ rule
409
411
  | NamedType DEFAULT Value {result = val[0].merge({:default => val[2]})}
410
412
  | COMPONENTS OF Type {result = val[2]; raise} /* TODO 24.4 says only root components of SEQUENCE are included */
411
413
 
412
- SequenceValue :
413
- LBRACE ComponentValueList RBRACE
414
- | LBRACE RBRACE
414
+ SequenceValue : # returning Hash
415
+ LBRACE ComponentValueList RBRACE {result = val[1]}
416
+ | LBRACE RBRACE {result = {}}
415
417
  ComponentValueList :
416
- NamedValue
417
- | ComponentValueList COMMA NamedValue
418
+ NamedValue {result = val[0]}
419
+ | ComponentValueList COMMA NamedValue {result = val[0].merge(val[2])}
418
420
 
419
421
  # 25 Notation for sequence-of types
420
422
  SequenceOfType :
@@ -423,19 +425,50 @@ rule
423
425
  }
424
426
  SequenceOfType_t : Type | NamedType
425
427
 
426
- SequenceOfValue :
427
- LBRACE ValueList RBRACE
428
- | LBRACE NamedValueList RBRACE
429
- | LBRACE RBRACE
428
+ SequenceOfValue : # returning Array or Hash
429
+ LBRACE ValueList RBRACE {result = val[1]}
430
+ | LBRACE NamedValueList RBRACE {result = val[1]}
431
+ | LBRACE RBRACE {result = {}}
430
432
  ValueList :
431
- Value
432
- | ValueList COMMA Value
433
+ Value {result = [val[0]]}
434
+ | ValueList COMMA Value {result << val[2]}
433
435
  NamedValueList :
434
- NamedValue
435
- | NamedValueList COMMA NamedValue
436
+ NamedValue {result = val[0]}
437
+ | NamedValueList COMMA NamedValue {result = val[0].merge(val[2])}
438
+
439
+ # 26. Notation for set types
440
+ SetType :
441
+ /*SET LBRACE RBRACE
442
+ | SET LBRACE ExtensionAndException OptionalExtensionMarker RBRACE
443
+ |*/ SET LBRACE ComponentTypeLists RBRACE {
444
+ # 26.3
445
+ val[2].merge!({:automatic_tagging => false}) \
446
+ if (@tags != :AUTOMATIC) \
447
+ || (val[2][:root] + (val[2][:extension] || [])).any?{|v|
448
+ v[:type][1][:tag] rescue false
449
+ }
450
+ result = {:type => [val[0], val[2]]}
451
+ }
452
+
453
+ SetValue : SequenceValue # returning Hash
454
+
455
+ # 27. Notation for set-of types
456
+ SetOfType :
457
+ SET OF SetOfType_t {
458
+ result = {:type => ["#{val[0]}_#{val[1]}".to_sym, val[2]]}
459
+ }
460
+ SetOfType_t : Type | NamedType
461
+
462
+ SetOfValue : SequenceOfValue # returning Array or Hash
436
463
 
437
464
  # 28. Notation for choice types
438
465
  ChoiceType : CHOICE LBRACE AlternativeTypeLists RBRACE {
466
+ # 28.2
467
+ val[2].merge!({:automatic_tagging => false}) \
468
+ if (@tags != :AUTOMATIC) \
469
+ || (val[2][:root] + (val[2][:extension] || [])).any?{|v|
470
+ v[:type][1][:tag] rescue false
471
+ }
439
472
  result = {:type => [val[0], val[2]]}
440
473
  }
441
474
  /*
@@ -472,14 +505,30 @@ rule
472
505
  NamedType {result = [val[0]]}
473
506
  | AlternativeTypeList COMMA NamedType {result << val[2]}
474
507
 
475
- ChoiceValue : identifier COLON Value
508
+ ChoiceValue : # returning Hash
509
+ identifier COLON Value {result = {val[0] => val[2]}}
476
510
 
477
511
  # 30. Notation for tagged types
478
- TaggedType :
512
+ /*TaggedType :
479
513
  Tag Type
480
514
  | Tag IMPLICIT Type
481
- | Tag EXPLICIT Type
482
- Tag : LBRACKET Class ClassNumber RBRACKET
515
+ | Tag EXPLICIT Type*/
516
+ TaggedType :
517
+ Tag TaggingConstruction Type {
518
+ result = val[2] # => {} having :type or :typeref keys
519
+ result[:type] = [result[:type]].flatten(1)
520
+ (result[:type][1] ||= {}).merge!({:tag => val[0]})
521
+ # TODO 30.6 c) to check whether Type is an untagged CHOICE after extraction of ReferencedType
522
+ result[:type][1].merge!({:tag_cnstr => val[1]}) if val[1]
523
+ }
524
+ TaggingConstruction :
525
+ IMPLICIT {result = nil}
526
+ | EXPLICIT # 30.6 a)
527
+ | {result = :EXPLICIT if @tags == :EXPLICIT} # 30.6 b)
528
+ Tag :
529
+ LBRACKET Class ClassNumber RBRACKET
530
+ {result = val[1] ? val[1..2] : val[2]}
531
+ # if class specified, array is returned; otherwise, integer.
483
532
  ClassNumber :
484
533
  number
485
534
  | DefinedValue
@@ -494,12 +543,12 @@ rule
494
543
  # 31. Notation for the object identifier type
495
544
  ObjectIdentifierType : OBJECT IDENTIFIER
496
545
 
497
- ObjectIdentifierValue :
498
- LBRACE ObjIdComponentsList RBRACE
499
- | LBRACKET DefinedValue ObjIdComponentsList RBRACKET
546
+ ObjectIdentifierValue : # returning Array
547
+ LBRACE ObjIdComponentsList RBRACE {result = val[1]}
548
+ | LBRACKET DefinedValue ObjIdComponentsList RBRACKET {result = [val[1]] + val[2]}
500
549
  ObjIdComponentsList :
501
- ObjIdComponents
502
- | ObjIdComponentsList ObjIdComponents
550
+ ObjIdComponents {result = [val[0]]}
551
+ | ObjIdComponentsList ObjIdComponents {result << val[1]}
503
552
  ObjIdComponents :
504
553
  NameForm
505
554
  | NumberForm
@@ -509,13 +558,13 @@ rule
509
558
  NumberForm :
510
559
  number
511
560
  | DefinedValue
512
- NameAndNumberForm : identifier LCBRACE NumberForm RCBRACE
561
+ NameAndNumberForm : identifier LCBRACE NumberForm RCBRACE {result = val.values_at(0, 2)}
513
562
 
514
563
  # 36. Notation for character string types
515
564
  CharacterStringType :
516
565
  RestrictedCharacterStringType
517
566
  | UnrestrictedCharacterStringType
518
- CharacterStringValue :
567
+ CharacterStringValue : # returning String, Array or Hash
519
568
  RestrictedCharacterStringValue
520
569
  | UnrestrictedCharacterStringValue
521
570
 
@@ -535,26 +584,26 @@ rule
535
584
  | VideotexString*/
536
585
  | VisibleString
537
586
 
538
- RestrictedCharacterStringValue :
587
+ RestrictedCharacterStringValue : # returning String or Array
539
588
  cstring
540
589
  | CharacterStringList
541
590
  | Quadruple
542
591
  | Tuple
543
- CharacterStringList : LBRACE CharSyms RBRACE
592
+ CharacterStringList : LBRACE CharSyms RBRACE {result = val[1]}
544
593
  CharSyms :
545
- CharsDefn
546
- | CharSyms COMMA CharsDefn
594
+ CharsDefn {result = [val[0]]}
595
+ | CharSyms COMMA CharsDefn {result << val[2]}
547
596
  CharsDefn :
548
597
  cstring
549
598
  | Quadruple
550
599
  | Tuple
551
600
  | DefinedValue
552
- Quadruple : LBRACE Group COMMA Plane COMMA Row COMMA Cell RBRACE
601
+ Quadruple : LBRACE Group COMMA Plane COMMA Row COMMA Cell RBRACE {result = val.values_at(1, 3, 5, 7)}
553
602
  Group : number
554
603
  Plane : number
555
604
  Row : number
556
605
  Cell : number
557
- Tuple : LBRACE TableColumn COMMA TableRow RBRACE
606
+ Tuple : LBRACE TableColumn COMMA TableRow RBRACE {result = val.values_at(1, 3)}
558
607
  TableColumn : number
559
608
  TableRow : number
560
609
 
data/lib/gps_pvt/ntrip.rb CHANGED
@@ -129,13 +129,16 @@ OpenURI.class_eval{
129
129
  def OpenURI.open_ntrip(buf, target, proxy, options) # :nodoc:
130
130
  GPS_PVT::Ntrip.start(target.host, target.port){|ntrip|
131
131
  # get source table
132
- tbl = ntrip.get_source_table(options){|str| str}
132
+ tbl_str = ntrip.get_source_table(options){|str| str}
133
133
  if target.root? then
134
- buf << tbl
134
+ buf << tbl_str
135
135
  buf.io.rewind
136
+ buf.io.define_singleton_method(:source_table){
137
+ GPS_PVT::Ntrip::parse_source_table(tbl_str)
138
+ }
136
139
  next
137
140
  end
138
- tbl = GPS_PVT::Ntrip::parse_source_table(tbl)
141
+ tbl = GPS_PVT::Ntrip::parse_source_table(tbl_str)
139
142
 
140
143
  # check mount point
141
144
  mnt_pt = target.mount_point
@@ -0,0 +1,137 @@
1
+ =begin
2
+ Additional Almanac handler for receiver
3
+ =end
4
+
5
+ module GPS_PVT
6
+ class Receiver
7
+ def correct_week_sem_yuma_almanac(src, week_rem = 0)
8
+ t_ref = case src.to_s
9
+ when /www\.navcen\.uscg\.gov\/.*\/(\d{4})\//
10
+ # ex) https://www.navcen.uscg.gov/sites/default/files/gps/almanac/20XX/(Sem|Yuma)/003.(al3|alm)
11
+ GPS_PVT::GPS::Time::new(Time::new($1.to_i).to_a.slice(0, 6).reverse)
12
+ when /www\.navcen\.uscg\.gov\/.*\/current_(sem|yuma)/
13
+ GPS_PVT::GPS::Time::now
14
+ else
15
+ raise
16
+ end
17
+ q, rem = t_ref.week.divmod(1024)
18
+ delta = rem - (week_rem % 1024)
19
+ if delta <= -512 then
20
+ q -= 1
21
+ elsif delta > 512 then
22
+ q += 1
23
+ end
24
+ q * 1024 + week_rem
25
+ end
26
+
27
+ def parse_sem_almanac(src)
28
+ src_io = open(Util::get_txt(src))
29
+ raise unless src_io.readline =~ /(\d+)\s+(\S+)/ # line 1
30
+ num, name = [$1.to_i, $2]
31
+ raise unless src_io.readline =~ /(\d+)\s+(\d+)/ # line 2
32
+ week, t_oa = [$1.to_i, $2.to_i]
33
+ week = correct_week_sem_yuma_almanac(src, week)
34
+ src_io.readline # line 3
35
+
36
+ num.times.each{
37
+ eph = GPS::Ephemeris::new
38
+ 9.times{|i| # line R-1..9
39
+ case i
40
+ when 0, 1, 2, 6, 7
41
+ # N/A items; 1 => SV reference number, 7 => configuration code
42
+ k = {0 => :svid, 2 => :URA_index, 6 => :SV_health}[i]
43
+ v = Integer(src_io.readline)
44
+ eph.send("#{k}=".to_sym, v) if k
45
+ when 3..5
46
+ res = src_io.readline.scan(/[+-]?\d+(?:\.\d+)?(?:E[+-]\d+)?/).collect{|s| Float(s)}
47
+ raise unless res.size == 3
48
+ res.zip({
49
+ 3 => [:e, [:i0, GPS::GPS_SC2RAD], [:dot_Omega0, GPS::GPS_SC2RAD]],
50
+ 4 => [:sqrt_A, [:Omega0, GPS::GPS_SC2RAD], [:omega, GPS::GPS_SC2RAD]],
51
+ 5 => [[:M0, GPS::GPS_SC2RAD], :a_f0, :a_f1],
52
+ }[i]).each{|v, (k, sf)|
53
+ eph.send("#{k}=".to_sym, sf ? (sf * v) : v)
54
+ }
55
+ when 8
56
+ src_io.readline
57
+ end
58
+ }
59
+ eph.i0 = GPS::GPS_SC2RAD * 0.3 + eph.i0
60
+ eph.WN = week
61
+ eph.t_oc = eph.t_oe = t_oa
62
+ [:iodc, :t_GD, :a_f2, :iode, :c_rs, :delta_n,
63
+ :c_uc, :c_us, :c_ic, :c_is, :c_rc, :dot_i0, :iode_subframe3].each{|k|
64
+ eph.send("#{k}=", 0)
65
+ }
66
+ critical{@solver.gps_space_node.register_ephemeris(eph.svid, eph)}
67
+ }
68
+
69
+ $stderr.puts "Read SEM Almanac file (%s): %d items."%[src, num]
70
+ end
71
+
72
+ YUMA_ITEMS = [
73
+ [proc{|s| s.to_i}, {
74
+ :ID => :svid,
75
+ :Health => :SV_health,
76
+ :week => :WN,
77
+ }],
78
+ [proc{|s| Float(s)}, {
79
+ :Eccentricity => :e,
80
+ "Time of Applicability" => [:t_oc, :t_oe],
81
+ "Orbital Inclination" => :i0,
82
+ "Rate of Right Ascen" => :dot_Omega0,
83
+ 'SQRT\(A\)' => :sqrt_A,
84
+ "Right Ascen at Week" => :Omega0,
85
+ "Argument of Perigee" => :omega,
86
+ "Mean Anom" => :M0,
87
+ "Af0" => :a_f0,
88
+ "Af1" => :a_f1,
89
+ }],
90
+ ].collect{|cnv, key_list|
91
+ key_list.collect{|k1, k2_list|
92
+ [/#{k1}[^:]*:/, cnv,
93
+ *([k2_list].flatten(1).collect{|k2|
94
+ "#{k2}=".to_sym
95
+ })]
96
+ }
97
+ }.flatten(1)
98
+
99
+ def parse_yuma_almanac(src)
100
+ src_io = open(Util::get_txt(src))
101
+ num = 0
102
+
103
+ idx_line = -1
104
+ eph, items = nil
105
+ while !src_io.eof?
106
+ line = src_io.readline.chomp
107
+ if idx_line < 0 then
108
+ if line =~ /^\*{8}/ then
109
+ eph = GPS::Ephemeris::new
110
+ items = YUMA_ITEMS.clone
111
+ idx_line = 0
112
+ end
113
+ next
114
+ end
115
+ raise unless i = items.index{|re, cnv, *k_list|
116
+ next false unless re =~ line
117
+ v = cnv.call($')
118
+ k_list.each{|k| eph.send(k, v)}
119
+ true
120
+ }
121
+ items.delete_at(i)
122
+ next unless items.empty?
123
+
124
+ [:iodc, :t_GD, :a_f2, :iode, :c_rs, :delta_n,
125
+ :c_uc, :c_us, :c_ic, :c_is, :c_rc, :dot_i0, :iode_subframe3].each{|k|
126
+ eph.send("#{k}=", 0)
127
+ }
128
+ eph.WN = correct_week_sem_yuma_almanac(src, eph.WN)
129
+ critical{@solver.gps_space_node.register_ephemeris(eph.svid, eph)}
130
+ num += 1
131
+ idx_line = -1
132
+ end
133
+
134
+ $stderr.puts "Read YUMA Almanac file (%s): %d items."%[src, num]
135
+ end
136
+ end
137
+ end
@@ -58,13 +58,11 @@ class Receiver
58
58
  end
59
59
  end
60
60
 
61
- module GPS
62
-
63
61
  [
64
- Ionospheric_UTC_Parameters,
65
- Ephemeris, Ephemeris_SBAS, Ephemeris_GLONASS,
62
+ :Ionospheric_UTC_Parameters,
63
+ :Ephemeris, :Ephemeris_SBAS, :Ephemeris_GLONASS,
66
64
  ].each{|cls|
67
- cls.class_eval{
65
+ GPS.const_get(cls).class_eval{
68
66
  proc{|func_list|
69
67
  func_list.select!{|func|
70
68
  (/=$/ !~ func.to_s) && func_list.include?("#{func}=".to_sym)
@@ -78,4 +76,3 @@ module GPS
78
76
  }
79
77
  }
80
78
  end
81
- end
@@ -732,4 +732,5 @@ end
732
732
 
733
733
  require_relative 'receiver/rtcm3'
734
734
  require_relative 'receiver/agps'
735
+ require_relative 'receiver/almanac'
735
736
  require_relative 'receiver/extension'