Sha256: d4ef39d1afb506ebb36d1c9161f3a4d57c1080ec5ddc7b959d9596dcc6b87c00
Contents?: true
Size: 1.6 KB
Versions: 8
Compression:
Stored size: 1.6 KB
Contents
# encoding: ascii-8bit # Copyright 2017 Ball Aerospace & Technologies Corp. # All Rights Reserved. # # This program is free software; you can modify and/or redistribute it # under the terms of the GNU General Public License # as published by the Free Software Foundation; version 3 with # attribution addendums as found in the LICENSE.txt require 'cosmos/interfaces/interface' module Cosmos # Base class for interfaces that act read and write from a stream class StreamInterface < Interface attr_accessor :stream def initialize(protocol_type = nil, protocol_args = []) super() @stream = nil @protocol_type = ConfigParser::handle_nil(protocol_type) @protocol_args = protocol_args if @protocol_type protocol_class_name = protocol_type.to_s.capitalize << 'Protocol' klass = Cosmos.require_class(protocol_class_name.class_name_to_filename) add_protocol(klass, protocol_args, :READ_WRITE) end end def connect super() @stream.connect if @stream end def connected? if @stream @stream.connected? else false end end def disconnect @stream.disconnect if @stream super() end def read_interface begin data = @stream.read rescue Timeout::Error Logger.instance.error "#{@name}: Timeout waiting for data to be read" data = nil end return nil if data.nil? or data.length <= 0 read_interface_base(data) data end def write_interface(data) write_interface_base(data) @stream.write(data) end end end
Version data entries
8 entries across 8 versions & 1 rubygems