ogn_client-ruby 0.2.2 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc7bfb92c9ee1a6a43a8fbe34b66a795c1a34551
4
- data.tar.gz: 663f89af96ca723f2042fa46c943abf831c0dc9e
3
+ metadata.gz: 457a6b32a8d8a124283e05e320f14b6d4d2a1310
4
+ data.tar.gz: cca65cf62df04c2ae068ba0adeee9fe1805769d8
5
5
  SHA512:
6
- metadata.gz: 47cd82bc99d6c9147ab1af0cbf29dbff876d536e50416f914a00a292b82dbb50b8f3e87a91faad2fe91ff52eb8024d57baa83541d504389895c6030a7852330e
7
- data.tar.gz: 58a4744ec0cb1b4bcb9c35a3138b080d7bca6c301f953ceb08cb0204f0e8669ea6237aa04e5c0db68a8a88baeb8ba76332e4e97d577738a961627c506ff67618
6
+ metadata.gz: 4b1dee00b45b66bdfe7a02070e6c8acb518a5df6f7d9c248aee836dab60ce01907bd84590e3b346c9c9defb9a39b6b8c19eda8cf814a1ee8278d6b64e11f4160
7
+ data.tar.gz: d6f3e85e414a4d3533376295676019e0f9c78015bec1346743711f9c3859782a80f7578d2d18b42bfe2ae9c3b7f37e4c6e03a9e257fd01ebf44104f4503e6dc3
@@ -1,3 +1,8 @@
1
+ ## 0.2.3
2
+
3
+ * add support for explicit message date
4
+ * fix ogn2kml for larger tracks
5
+
1
6
  ## 0.2.2
2
7
 
3
8
  * add example executables
data/README.md CHANGED
@@ -61,6 +61,13 @@ The factory method `OGNClient::Message.parse` will return one an instance of `OG
61
61
 
62
62
  In production, you may want to rescue from these errors and ignore the message. You should, however, log the offending messages messages, [file a bug](#community-support) and replay them once the bug has been fixed.
63
63
 
64
+ :point_up: Raw APRS messages do not contain the date, but assume the current day. This may cause trouble around midnight, however, the parser deals with such edge cases gracefully. Things are a little different when parsing raw APRS messages recorded in the past e.g. with `ognlogd`. Since the parser has no means to detect the date the APRS messages have been sent, you have to pass it as an option:
65
+
66
+ ```ruby
67
+ raw_aprs = File.open('2017-06-24.log', &:gets)
68
+ OGNClient::Message.parse(raw_aprs, date: '2017-06-24')
69
+ ```
70
+
64
71
  #### OGNClient::SenderBeacon
65
72
 
66
73
  Sender beacons are usually coming from aircraft equipped with [FLARM](https://flarm.com) (anti-collision warning system) or similar devices which broadcast position data as RF beacons.
@@ -20,6 +20,7 @@ class Converter
20
20
  END
21
21
  o.on('-a', '--about', 'author and license information') { puts 'Written by Sven Schwyn (bitcetera.com) and distributed under MIT license.'; exit }
22
22
  o.on('-c', '--callsign STRING', String, 'aircraft callsign (e.g. FLRAABBCC)') { |v| @callsign = v }
23
+ o.on('-d', '--date YYYY-MM-DD', String, 'date the APRS messages were recorded (default: today)') { |v| @date = v }
23
24
  o.on('-o', '--outfile FILE', String, 'generated KML file (default: INFILE.kml)') { |v| @outfile = v.sub(/\.kml$/, '') + '.kml' }
24
25
  end.parse!
25
26
  @infile = ARGV.pop
@@ -93,12 +94,13 @@ class Converter
93
94
  climb_rate['name'] = 'Climb Rate'
94
95
  turn_rate = XML::Node.new(:'gx:SimpleArrayData')
95
96
  turn_rate['name'] = 'Turn Rate'
97
+ array_data = { when: [], coord: [], angles: [] }
96
98
  lines.each do |line|
97
- if (sender = OGNClient::Message.parse(line)).is_a? OGNClient::SenderBeacon
99
+ if (sender = OGNClient::Message.parse(line, date: @date)).is_a? OGNClient::SenderBeacon
98
100
  if !@callsign || sender.callsign == @callsign
99
- track << XML::Node.new(:when, sender.time.xmlschema)
100
- track << XML::Node.new(:'gx:coord', "#{sender.longitude} #{sender.latitude} #{sender.altitude}")
101
- track << XML::Node.new(:'gx:angles', "#{sender.heading} 0 0")
101
+ array_data[:when] << XML::Node.new(:when, sender.time.xmlschema)
102
+ array_data[:coord] << XML::Node.new(:'gx:coord', "#{sender.longitude} #{sender.latitude} #{sender.altitude}")
103
+ array_data[:angles] << XML::Node.new(:'gx:angles', "#{sender.heading} 0 0")
102
104
  time << XML::Node.new(:'gx:value', sender.time.getlocal.strftime('%H:%M:%S'))
103
105
  ground_speed << XML::Node.new(:'gx:value', sender.ground_speed.to_i.to_s)
104
106
  climb_rate << XML::Node.new(:'gx:value', sender.climb_rate.to_i.to_s)
@@ -107,6 +109,9 @@ class Converter
107
109
  end
108
110
  progressbar.increment
109
111
  end
112
+ array_data.keys.each do |key|
113
+ array_data[key].each { |d| track << d }
114
+ end
110
115
  track << (extended_data = XML::Node.new(:ExtendedData))
111
116
  extended_data << (schema_data = XML::Node.new(:SchemaData))
112
117
  schema_data['schemaUrl'] = '#schema'
@@ -1,4 +1,5 @@
1
1
  require 'socket'
2
+ require 'time'
2
3
 
3
4
  require_relative 'ogn_client/version'
4
5
  require_relative 'ogn_client/errors'
@@ -42,12 +42,12 @@ module OGNClient
42
42
  attr_reader :heading # degrees from 1 to 360
43
43
  attr_reader :ground_speed # kilometers per hour
44
44
 
45
- def self.parse(raw)
45
+ def self.parse(raw, date: nil)
46
46
  fail(OGNClient::MessageError, "raw message must be String but is #{raw.class}") unless raw.is_a? String
47
47
  raw = raw.chomp.force_encoding('ASCII-8BIT').encode('UTF-8')
48
- OGNClient::SenderBeacon.new.send(:parse, raw) ||
49
- OGNClient::ReceiverStatus.new.send(:parse, raw) ||
50
- OGNClient::ReceiverBeacon.new.send(:parse, raw) ||
48
+ OGNClient::SenderBeacon.new.send(:parse, raw, date: date) ||
49
+ OGNClient::ReceiverStatus.new.send(:parse, raw, date: date) ||
50
+ OGNClient::ReceiverBeacon.new.send(:parse, raw, date: date) ||
51
51
  OGNClient::Comment.new.send(:parse, raw) ||
52
52
  fail(OGNClient::MessageError, "message payload parsing failed: `#{raw}'")
53
53
  end
@@ -58,8 +58,9 @@ module OGNClient
58
58
 
59
59
  private
60
60
 
61
- def parse(raw)
61
+ def parse(raw, date: nil)
62
62
  @raw = raw
63
+ @date = Date.parse(date) if date
63
64
  raw.match POSITION_PATTERN do |match|
64
65
  %i(callsign receiver time altitude).each do |attr|
65
66
  send("#{attr}=", match[attr]) if match[attr]
@@ -82,9 +83,13 @@ module OGNClient
82
83
  end
83
84
 
84
85
  def time=(raw)
85
- now = Time.now.utc
86
- time = Time.new(now.year, now.month, now.day, raw[0,2], raw[2,2], raw[4,2], 0)
87
- time -= 86400 if time > now # adjust date of beacons sent just before midnight
86
+ if @date
87
+ time = Time.new(@date.year, @date.month, @date.day, raw[0,2], raw[2,2], raw[4,2], 0)
88
+ else
89
+ now = Time.now.utc
90
+ time = Time.new(now.year, now.month, now.day, raw[0,2], raw[2,2], raw[4,2], 0)
91
+ time -= 86400 if time > now # adjust date of beacons sent just before midnight
92
+ end
88
93
  @time = time
89
94
  end
90
95
 
@@ -9,7 +9,7 @@ module OGNClient
9
9
 
10
10
  private
11
11
 
12
- def parse(raw)
12
+ def parse(raw, date: nil)
13
13
  raw.match RECEIVER_BEACON_PATTERN do
14
14
  super unless @raw
15
15
  self
@@ -63,7 +63,7 @@ module OGNClient
63
63
 
64
64
  private
65
65
 
66
- def parse(raw)
66
+ def parse(raw, date: nil)
67
67
  raw.match RECEIVER_STATUS_PATTERN do |match|
68
68
  super unless @raw
69
69
  %i(version platform cpu_load cpu_temperature ram_free ram_total ntp_offset ntp_correction voltage amperage rf_correction_manual rf_correction_automatic senders visible_senders signal_quality senders_signal_quality senders_messages good_senders_signal_quality good_and_bad_senders good_senders).each do |attr|
@@ -3,7 +3,7 @@ module OGNClient
3
3
  class SenderBeacon < Message
4
4
 
5
5
  SENDER_BEACON_PATTERN = %r(
6
- id(?<details>\w{2})(?<id>\w+?)\s?
6
+ id(?<details>\w{2})(?<id>\w{6})\s?
7
7
  (?:(?<climb_rate>[+-]\d+?)fpm\s)?
8
8
  (?:(?<turn_rate>[+-][\d.]+?)rot\s)?
9
9
  (?:FL(?<flight_level>[\d.]+)\s)?
@@ -62,7 +62,7 @@ module OGNClient
62
62
 
63
63
  private
64
64
 
65
- def parse(raw)
65
+ def parse(raw, date: nil)
66
66
  raw.match SENDER_BEACON_PATTERN do |match|
67
67
  super unless @raw
68
68
  %i(details id flight_level climb_rate turn_rate signal_power signal_quality errors frequency_offset gps_accuracy flarm_software_version flarm_hardware_version flarm_id proximity).each do |attr|
@@ -1,3 +1,3 @@
1
1
  module OGNClient
2
- VERSION = "0.2.2".freeze
2
+ VERSION = "0.2.3".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ogn_client-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Schwyn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-27 00:00:00.000000000 Z
11
+ date: 2017-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler