Ravn::HAL::

Device class

Abstract device class

Emits: - sys.device.info

Consumes: - sys.startup

Constants

PRC163Radio

L3Harris PRC-163 radio adapter.

This device reads and write asynchronously from a USB TTY device connected to the radio. It has a thread managing the low-level IO, and a timer to periodically send the commands that turn into the events required by the BDE (GPS, time, etc.).

Both reading and writing happen in two stages: a queue and a buffer.

write_queue -> write_buffer -> <TTY> -> read_buffer -> read_queue

Commands for the radio are appended to the write_queue. The IO thread pulls each command off of the queue and appends it to the write_buffer, then writes as much as it can to the radio. It then reads any pending output from the radio into the read_buffer and then breaks as many whole lines off of that as it can, appending each one to the read_queue. The read_queue is then scanned for events, and those are emitted up the tree.

== Emits:

  • sys.device.info

    • sys.gps.position

    • sys.gps.time

    • sys.radio.battery

    • sys.radio.channel

    • sys.radio.volume

    • sys.radio.versions

== Consumes:

  • sys.radio.command

This class includes code from the ruby-termios examples, used under the terms of the Ruby License. The original software does not include a copyright statement, so none is duplicated here.

Refs:

  • L3Harris Ascii Interface Design Document (RF-335M/1.3.1/February 19, 2021) obsidian://open?vault=Software%20Notes&file=Radios%2FL3Harris%20PRC-163%2Fattachments%2FL3Harris%20Ascii%20PLATFORM%20163%201.3.1.pdf

RESET_THROTTLE_TIME

For fail-fast actors, throttle recovery time.

WearOSWatch

A class representing an Android WearOS device, currently targetting a Samsung Galaxy Watch over bluetooth. (This could theoretically be used with any bluetooth connected Android display.)

Attributes

device_info_stash R

The Hash of seen sys.device.info messages, keyed by the device info Hash

startup_message R

The system metadata message delivered to the device when the system starts

Public Class Methods

inherited( klass )

Register interest in the BDE startup packet.

# File lib/ravn/hal/device.rb, line 41
def self::inherited( klass )
        super
        klass.register_message_handler 'sys.startup', :retain_startup_message
        klass.register_message_handler 'sys.device.info', :retain_other_device_info
end
new( * )

Add some instance variables to all devices.

# File lib/ravn/hal/device.rb, line 49
def initialize( * )
        @startup_message = nil
        @device_info_stash = {}

        super
end

Public Instance Methods

default_executor()

Use the IO execution thread pool be default to avoid deadlocking non-io threads

# File lib/ravn/hal/device.rb, line 89
def default_executor
        return Concurrent.global_io_executor
end
discover()

Do any discovery of the adapted device that needs to be done during startup.

# File lib/ravn/hal/device.rb, line 77
def discover
        self.emit_device_info
end
emit_device_info()

Send a sys.device.info message

# File lib/ravn/hal/device.rb, line 95
def emit_device_info
        self.log.info "Emitting device info for %p" % [ self ]
        message = self.make_device_info_message
        self.filter_up( message )
end
gather_device_info()

Return a Hash that contains information describing this device for intra-device communication.

# File lib/ravn/hal/device.rb, line 117
def gather_device_info
        type_name = self.class.name || "anonymous%x" % [ self.identifier ]
        type = type_name.sub( /.*::/, '' ).un_camelcase

        return {
                type: type,
                vendor: 'unknown',
                identifier: self.identifier,
        }
end
identifier()

Return the Integer identifier for this device.

# File lib/ravn/hal/device.rb, line 110
def identifier
        return self.class.object_id
end
make_device_info_message()

Return a sys.device.info event describing this device.

# File lib/ravn/hal/device.rb, line 103
def make_device_info_message
        data = self.gather_device_info
        return Ravn::HAL::Message.new( 'sys.device.info', data: )
end
other_device_info_messages()

Return any sys.device.info messages (Ravn::HAL::Message objects) that have been seen.

# File lib/ravn/hal/device.rb, line 139
def other_device_info_messages
        return self.device_info_stash.values
end
retain_other_device_info( message )

Save device information to replay when this device is finished starting.

# File lib/ravn/hal/device.rb, line 145
def retain_other_device_info( message )
        self.log.debug "Got a device info message: %p" % [ message ]
        key = message.data
        self.device_info_stash[ key ] = message
end
retain_startup_message( message )

When the system startup message is seen, save it for optional later replay to connecting clients.

# File lib/ravn/hal/device.rb, line 131
def retain_startup_message( message )
        self.log.debug "Caching startup message: %p" % [ message ]
        @startup_message = message
end
start()

Actor API — start the wrapper.

# File lib/ravn/hal/device.rb, line 71
def start
        self.discover
end
stop()

Actor API — stop the wrapper.

# File lib/ravn/hal/device.rb, line 83
def stop
        # No-op
end