Class: OGNClient::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/ogn_client/message.rb

Overview

Generic OGN flavoured APRS parser

You can pass any raw OGN flavoured APRS message string to the parse class method and receive an instance of the appropriate subclass (Comment, Receiver or Sender) or nil if the message string could not be parsed.

Comment example:

raw = "# aprsc 2.0.14-g28c5a6a 29 Jun 2014 07:46:15 GMT GLIDERN1 37.187.40.234:14580"
obj = OGNClient::Message.parse(raw)   # => #<OGNClient::Comment:0x007feaf1012898>
obj.comment   # => "aprsc 2.0.14-g28c5a6a 29 Jun 2014 07:46:15 GMT GLIDERN1 37.187.40.234:14580"

Sender example:

raw = "FLRDF0A52>APRS,qAS,LSTB:/220132h4658.70N/00707.72Ez090/054/A=001424 id06DF0A52 +020fpm +0.0rot 55.2dB 0e -6.2kHz"
obj = OGNClient::Message.parse(raw)   # => #<OGNClient::Sender:0x007feaec1daba8>
obj.id   # => "DF0A52"

Malformed example:

raw = "FOOBAR>not a valid message"
obj = OGNClient::Message.parse(raw)   # => nil

Direct Known Subclasses

Comment, ReceiverBeacon, ReceiverStatus, SenderBeacon

Constant Summary collapse

POSITION_PATTERN =
%r(^
  (?<callsign>.+?)>APRS,(?:.+?,){1,2}
  (?<receiver>.+?):[/>]
  (?<time>\d{6})h
  (?:(?<latitude>\d{4}\.\d{2}[NS]).(?<longitude>\d{5}\.\d{2}[EW]).)?
  (?:(?<heading>\d{3})/(?<ground_speed>\d{3}))?
  (?:/A=(?<altitude>\d{6}))?\s*
  (?:!W((?<latitude_enhancement>\d)(?<longitude_enhancement>\d))!)?
  (?:\s|$)
)x

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#altitudeObject

WGS84 meters above mean sea level QNH



41
42
43
# File 'lib/ogn_client/message.rb', line 41

def altitude
  @altitude
end

#callsignObject

origin callsign



36
37
38
# File 'lib/ogn_client/message.rb', line 36

def callsign
  @callsign
end

#ground_speedObject

kilometers per hour



43
44
45
# File 'lib/ogn_client/message.rb', line 43

def ground_speed
  @ground_speed
end

#headingObject

degrees from 1 to 360



42
43
44
# File 'lib/ogn_client/message.rb', line 42

def heading
  @heading
end

#latitudeObject

WGS84 degrees from -90 (S) to 90 (N)



40
41
42
# File 'lib/ogn_client/message.rb', line 40

def latitude
  @latitude
end

#longitudeObject

WGS84 degrees from -180 (W) to 180 (E)



39
40
41
# File 'lib/ogn_client/message.rb', line 39

def longitude
  @longitude
end

#rawObject (readonly)

Returns the value of attribute raw.



35
36
37
# File 'lib/ogn_client/message.rb', line 35

def raw
  @raw
end

#receiverObject

receiver callsign



37
38
39
# File 'lib/ogn_client/message.rb', line 37

def receiver
  @receiver
end

#timeObject

zulu/UTC time with date



38
39
40
# File 'lib/ogn_client/message.rb', line 38

def time
  @time
end

Class Method Details

.parse(raw, date: nil) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/ogn_client/message.rb', line 45

def self.parse(raw, date: nil)
  fail(OGNClient::MessageError, "raw message must be String but is #{raw.class}") unless raw.is_a? String
  raw = raw.chomp.force_encoding('ASCII-8BIT').encode('UTF-8')
  OGNClient::SenderBeacon.new.send(:parse, raw, date: date) ||
    OGNClient::ReceiverStatus.new.send(:parse, raw, date: date) ||
    OGNClient::ReceiverBeacon.new.send(:parse, raw, date: date) ||
    OGNClient::Comment.new.send(:parse, raw) ||
    fail(OGNClient::MessageError, "message payload parsing failed: `#{raw}'")
end

Instance Method Details

#to_sObject



55
56
57
# File 'lib/ogn_client/message.rb', line 55

def to_s
  @raw
end