class OGNClient::APRS

Minimalistic APRS implementation for OGN

Use a unique all-uppercase callsign to create the instance and then connect with or without filters.

OGNClient::APRS.start(callsign: 'OGNC', filter: 'r/33/-97/200') do |aprs|
  puts aprs.gets until aprs.eof?
end

See www.aprs-is.net/javAPRSFilter.aspx for available filters.

Constants

AGENT
PORT_FILTERED
PORT_UNFILTERED
SERVER

Attributes

callsign[R]
filter[R]
socket[R]

Public Class Methods

new(callsign:, filter: nil) click to toggle source
   # File lib/ogn_client/aprs.rb
22 def initialize(callsign:, filter: nil)
23     @callsign = callsign.upcase
24   @filter = filter
25   @port = filter ? PORT_FILTERED : PORT_UNFILTERED
26 end
start(callsign:, filter: nil, &block) click to toggle source
   # File lib/ogn_client/aprs.rb
28 def self.start(callsign:, filter: nil, &block)
29   new(callsign: callsign, filter: filter).start(&block)
30 end

Public Instance Methods

start() { |socket| ... } click to toggle source
   # File lib/ogn_client/aprs.rb
32 def start
33     @socket = TCPSocket.open SERVER, @port
34   @socket.puts handshake
35   @socket.flush
36   if block_given?
37     begin
38       return yield(@socket)
39     ensure
40       @socket.close
41     end
42   end
43   self
44 end

Private Instance Methods

handshake(readonly: true) click to toggle source

Build the handshake to connect to the server

   # File lib/ogn_client/aprs.rb
60 def handshake(readonly: true)
61   {
62     user: @callsign,
63     pass: passcode(readonly: readonly),
64     vers: "#{AGENT} #{OGNClient::VERSION}",
65     filter: @filter
66   }.map { |k, v| "#{k} #{v}" if v }.compact.join(' ')
67 end
passcode(readonly: true) click to toggle source

Calculate the passcode from the callsign

   # File lib/ogn_client/aprs.rb
49 def passcode(readonly: true)
50   if readonly
51     -1
52   else
53     @callsign.split('-').first.chars.reduce([0x73E2, true]) do |hash, char|
54       [hash.first ^ (hash.last ? char.ord << 8 : char.ord), !hash.last]
55     end.first & 0x7FFF
56   end
57 end