Ravn::HAL::Device::

DoodleRadio class

Connect to a remote gpsd daemon at the current default gateway.

Responsible for generating the following events:

  • sys.gps.position

  • sys.gps.time

Constants

DOODLE_NETWORK

The Ravn network prefix for the Doodle Mesh Rider radio.

Public Instance Methods

discover()

Connect to the remote GPS daemon.

# File lib/ravn/hal/device/doodle_radio.rb, line 32
def discover
        ip   = self.find_default_route or raise "Unable to find Mesh Rider Radio IP."
        @gps = Ravn::GPSClient.new( host: ip )
        self.gps.connect
rescue RuntimeError, Errno::ECONNREFUSED => err
        self.log.error "Error while starting: %s" % [ err.message ]
        sleep( RESET_THROTTLE_TIME )
        self.core&.parent&.tell( reset_device: self )
end

Protected Instance Methods

find_default_route()

Parse the routing table to find the next-hop, which should be the connected radio.

# File lib/ravn/hal/device/doodle_radio.rb, line 50
def find_default_route
        routes = self.list_routes.each_line.
                grep( /\s+UG\s+/ ).
                map( &:split  ).
                select{|g| g[1].start_with?( DOODLE_NETWORK ) }.
                first

        return Array( routes )[1]

rescue => err
        raise "Error while parsing routing table: %s" % [ err.message ]
end
list_routes()

Shell out to route, returning its output as a string.

# File lib/ravn/hal/device/doodle_radio.rb, line 66
def list_routes
        in_pipe, out_pipe = IO.pipe

        output = ""
        pid = Process.spawn( 'route', '-n', out: out_pipe, close_others: true )
        out_pipe.close

        ready, _, _ = select( [ in_pipe ] )
        while ready && ! ready.empty?
                fd = ready.first
                break if fd.eof? || fd.closed?
                output << fd.read
                ready, _, _ = select( [ in_pipe ] )
        end

        pid = Process.waitpid( pid )
        return output

ensure
        in_pipe.close if in_pipe && ! in_pipe.closed?
end