nmea_plus 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb6a15ea1c4b8d040614ae117703221df082cf53
4
- data.tar.gz: 3d738a04a524c69e02c371befc3d1edd9f913a96
3
+ metadata.gz: 1f71c1e2ce5125ec0729070d9bc7955bf0e764ff
4
+ data.tar.gz: 8058c722fb35884334c9b87e750948791bd9c441
5
5
  SHA512:
6
- metadata.gz: f026b1f759c56c97952ea97b3b7a6190c0930e4cb02486a715cf704eefe5fa8c4f012c19b6b8778dd32be709be95cc671c23f267096635ddcd55d3f2e1d1074c
7
- data.tar.gz: 9002792450538ed8f492db5f54707f1631bc44f27acede7a44868b82900755177da03974922565249ebde61b175fd56023aa5cf23878d0141b606dbad891ceb8
6
+ metadata.gz: 1e49686ab20cf85f0d91743e026af130d2e372be651e3410ae60570a8efa2d33c8df63b14bfce7a499cb31e073fe34cf88da508db181fd6825d8081aa749b7a0
7
+ data.tar.gz: 33c30c99d96467c453c1c8046efa321af8c60c3ca971e877db1adad3d49193a2a326e26b94264a4bc7f80e01a41c8699950b0c9aa3aaed65ea7ee0c796dd52ae
@@ -23,11 +23,13 @@ module NMEAPlus
23
23
  if @throw_on_parse_fail
24
24
  yield @decoder.parse(line)
25
25
  else
26
+ got_error = false
26
27
  begin
27
28
  y = @decoder.parse(line)
28
- yield y
29
29
  rescue
30
+ got_error = true
30
31
  end
32
+ yield y unless got_error
31
33
  end
32
34
  end
33
35
  end
@@ -1,7 +1,7 @@
1
1
  #--
2
2
  # DO NOT MODIFY!!!!
3
3
  # This file is automatically generated by rex 1.0.5
4
- # from lexical definition file "/Users/iakatz/Code Base/nmea_plus/parser/tokenizer.rex".
4
+ # from lexical definition file "/Users/iakatz/Code Base/ship_spotter/nmea_plus/parser/tokenizer.rex".
5
5
  #++
6
6
 
7
7
 
@@ -26,6 +26,14 @@ module NMEAPlus
26
26
  '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !"#$%&\'()*+,-./0123456789:;<=>?'[ord]
27
27
  end
28
28
 
29
+ # access part of the payload. if there aren't bytes, there, return nil
30
+ # else execute a block
31
+ def _access(start, length)
32
+ part = @payload_bitstring[start, length]
33
+ return nil if part.nil? || part.empty?
34
+ yield part
35
+ end
36
+
29
37
  # convert an entire string from the payload
30
38
  def _6b_string(start, length)
31
39
  # pull out 6b chunks from the string, use their value as a lookup into the ascii array
@@ -37,7 +45,7 @@ module NMEAPlus
37
45
  end
38
46
 
39
47
  def _bit_slices(start, length, chunk_size)
40
- @payload_bitstring[start, length].chars.each_slice(chunk_size)
48
+ _access(start, length) { |bits| bits.chars.each_slice(chunk_size) }
41
49
  end
42
50
 
43
51
  # convert a string but trim off the 0s ('@')
@@ -47,18 +55,19 @@ module NMEAPlus
47
55
 
48
56
  # directly convert a string to a binary number as you'd read it
49
57
  def _6b_unsigned_integer(start, length)
50
- @payload_bitstring[start, length].to_i(2)
58
+ _access(start, length) { |bits| bits.to_i(2) }
51
59
  end
52
60
 
53
61
  # perform a twos complement operation on part of the payload
54
62
  def _6b_twoscomplement(start, length)
55
63
  # two's complement: flip bits, then add 1
56
- @payload_bitstring[start, length].tr("01", "10").to_i(2) + 1
64
+ _access(start, length) { |bits| bits.tr("01", "10").to_i(2) + 1 }
57
65
  end
58
66
 
59
67
  def _6b_integer(start, length)
60
68
  # MSB is 1 for negative
61
- _6b_twoscomplement(start, length) * (@payload_bitstring[start] == 0 ? 1 : -1)
69
+ twoc = _6b_twoscomplement(start, length)
70
+ twoc && twoc * (@payload_bitstring[start] == 0 ? 1 : -1)
62
71
  end
63
72
 
64
73
  # scale an integer by dividing it by 10^decimal_places
@@ -72,11 +81,11 @@ module NMEAPlus
72
81
  end
73
82
 
74
83
  def _6b_boolean(start, _)
75
- @payload_bitstring[start].to_i == 1
84
+ _access(start, 1) { |bits| bits.to_i == 1 }
76
85
  end
77
86
 
78
87
  def _2b_data_string(start, length)
79
- @payload_bitstring[start, length]
88
+ _access(start, length)
80
89
  end
81
90
 
82
91
  # use shorthand for data types as defined in http://catb.org/gpsd/AIVDM.html
@@ -31,6 +31,72 @@ module NMEAPlus
31
31
  payload_reader :destination, 302, 120, :_t
32
32
  payload_reader :dte?, 422, 1, :_b
33
33
 
34
+ def ship_cargo_type_description
35
+ case ship_cargo_type
36
+ when 0 then return nil
37
+ when 1...19 then return "(future use)"
38
+ when 20 then return "WIG (any)"
39
+ when 21 then return "WIG Hazardous category A"
40
+ when 22 then return "WIG Hazardous category B"
41
+ when 23 then return "WIG Hazardous category C"
42
+ when 24 then return "WIG Hazardous category D"
43
+ when 25...29 then return "WIG (future use)"
44
+ when 30 then return "Fishing"
45
+ when 31 then return "Towing"
46
+ when 32 then return "Towing (large)"
47
+ when 33 then return "Dredging/underwater ops"
48
+ when 34 then return "Diving ops"
49
+ when 35 then return "Military ops"
50
+ when 36 then return "Sailing"
51
+ when 37 then return "Pleasure craft"
52
+ when 38, 39 then return "Reserved"
53
+ when 40 then return "High Speed Craft"
54
+ when 41 then return "HSC Hazardous category A"
55
+ when 42 then return "HSC Hazardous category B"
56
+ when 43 then return "HSC Hazardous category C"
57
+ when 44 then return "HSC Hazardous category D"
58
+ when 45...48 then return "HSC (reserved)"
59
+ when 49 then return "HSC (no additional information)"
60
+ when 50 then return "Pilot Vessel"
61
+ when 51 then return "Search and Rescue Vessel"
62
+ when 52 then return "Tug"
63
+ when 53 then return "Port Tender"
64
+ when 54 then return "Anti-pollution equipment"
65
+ when 55 then return "Law Enforcement"
66
+ when 56, 57 then return "Spare - Local Vessel"
67
+ when 58 then return "Medical Transport"
68
+ when 59 then return "Noncombatant ship according to RR Resolution No. 18"
69
+ when 60 then return "Passenger"
70
+ when 61 then return "Passenger, Hazardous category A"
71
+ when 62 then return "Passenger, Hazardous category B"
72
+ when 63 then return "Passenger, Hazardous category C"
73
+ when 64 then return "Passenger, Hazardous category D"
74
+ when 65..68 then return "Passenger, Reserved for future use"
75
+ when 69 then return "Passenger, No additional information"
76
+ when 70 then return "Cargo"
77
+ when 71 then return "Cargo, Hazardous category A"
78
+ when 72 then return "Cargo, Hazardous category B"
79
+ when 73 then return "Cargo, Hazardous category C"
80
+ when 74 then return "Cargo, Hazardous category D"
81
+ when 75..78 then return "Cargo, Reserved for future use"
82
+ when 79 then return "Cargo, No additional information"
83
+ when 80 then return "Tanker"
84
+ when 81 then return "Tanker, Hazardous category A"
85
+ when 82 then return "Tanker, Hazardous category B"
86
+ when 83 then return "Tanker, Hazardous category C"
87
+ when 84 then return "Tanker, Hazardous category D"
88
+ when 85.88 then return "Tanker, Reserved for future use"
89
+ when 89 then return "Tanker, No additional information"
90
+ when 90 then return "Other Type"
91
+ when 91 then return "Other Type, Hazardous category A"
92
+ when 92 then return "Other Type, Hazardous category B"
93
+ when 93 then return "Other Type, Hazardous category C"
94
+ when 94 then return "Other Type, Hazardous category D"
95
+ when 95..98 then return "Other Type, Reserved for future use"
96
+ when 99 then return "Other Type, no additional information"
97
+ end
98
+ end
99
+
34
100
  end
35
101
  end
36
102
  end
@@ -1,3 +1,3 @@
1
1
  module NMEAPlus
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nmea_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Katz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2015-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: racc