Class: OGNClient::APRS

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

Overview

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.

Constant Summary collapse

SERVER =
'aprs.glidernet.org'
PORT_FILTERED =
14580
PORT_UNFILTERED =
10152
AGENT =
"#{RUBY_ENGINE}-ogn_client"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callsign:, filter: nil) ⇒ APRS

Returns a new instance of APRS.



22
23
24
25
26
# File 'lib/ogn_client/aprs.rb', line 22

def initialize(callsign:, filter: nil)
	@callsign = callsign.upcase
  @filter = filter
  @port = filter ? PORT_FILTERED : PORT_UNFILTERED
end

Instance Attribute Details

#callsignObject (readonly)

Returns the value of attribute callsign.



20
21
22
# File 'lib/ogn_client/aprs.rb', line 20

def callsign
  @callsign
end

#filterObject (readonly)

Returns the value of attribute filter.



20
21
22
# File 'lib/ogn_client/aprs.rb', line 20

def filter
  @filter
end

#socketObject (readonly)

Returns the value of attribute socket.



20
21
22
# File 'lib/ogn_client/aprs.rb', line 20

def socket
  @socket
end

Class Method Details

.start(callsign:, filter: nil, &block) ⇒ Object



28
29
30
# File 'lib/ogn_client/aprs.rb', line 28

def self.start(callsign:, filter: nil, &block)
  new(callsign: callsign, filter: filter).start(&block)
end

Instance Method Details

#startObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ogn_client/aprs.rb', line 32

def start
	@socket = TCPSocket.open SERVER, @port
  @socket.puts handshake
  @socket.flush
  if block_given?
    begin
      return yield(@socket)
    ensure
      @socket.close
    end
  end
  self
end