module Syskit::Device

Modelling and instance-level functionality for devices

Devices are, in Syskit plugin, the tools that allow to represent the inputs and outputs of your component network, i.e. the components that are tied to “something” (usually hardware) that is not represented in the component network.

New devices can either be created with device_model.new_submodel if the source should not be registered in the system model, or SystemModel#device_type if it should be registered

Public Instance Methods

each_master_device() { |device| ... } click to toggle source

Enumerates the MasterDeviceInstance objects associated with this task context

It yields the data service and the device model

@yieldparam [MasterDeviceInstance] device @see each_device

# File lib/syskit/data_service.rb, line 114
def each_master_device
    if !block_given?
        return enum_for(:each_master_device)
    end

    seen = Set.new
    model.each_master_driver_service do |srv|
        if (device = find_device_attached_to(srv)) && !seen.include?(device.name)
            yield(device)
            seen << device.name
        end
    end
end
each_master_driver_service() { |bind| ... } click to toggle source
# File lib/syskit/data_service.rb, line 48
def each_master_driver_service
    model.each_master_driver_service do |srv|
        yield(srv.bind(self))
    end
end
find_all_driver_services_for(device) click to toggle source

Returns the bound data service that is attached to the given device

# File lib/syskit/data_service.rb, line 56
def find_all_driver_services_for(device)
    if device.respond_to?(:master_device)
        find_all_driver_services_for(device.master_device).map do |driver_srv|
            driver_srv.find_data_service(device.name)
        end
    else
        services = model.each_master_driver_service.find_all do |driver_srv|
            find_device_attached_to(driver_srv) == device
        end
        services.map { |drv| drv.bind(self) }
    end
end
find_device_attached_to(service = nil) click to toggle source

Returns the device object that is attached to the given service.

@param [BoundDataService,String,nil] service the service for which

we want the attached device. It can be omitted in the (very
common) case of tasks that are driving only one device

@return [MasterDeviceInstance,nil] the device object, or nil if

there is no device attached to the required service

@raise [ArgumentError] if the provided service name does not

exist, or if it is nil and this task context drives more than
one device.
# File lib/syskit/data_service.rb, line 79
def find_device_attached_to(service = nil)
    if service && service.respond_to?(:to_str)
        if !(service = find_data_service(service))
            raise ArgumentError, "#{service} is not a known service of #{self}, known services are: #{each_data_service.map(&:name).sort.join(', ')}"
        end
    elsif !service || service.kind_of?(Syskit::Models::DataServiceModel)
        driver_services =
            if service then model.find_all_data_services_from_type(service)
            else model.each_master_driver_service.to_a
            end
        if driver_services.empty?
            raise ArgumentError, "#{self} is not attached to any device"
        elsif driver_services.size > 1
            raise ArgumentError, "#{self} handles more than one device, you must specify one of #{driver_services.map(&:name).sort.join(", ")} explicitely"
        end
        service = driver_services.first
    end

    arguments[:"#{service.name}_dev"]
end
robot_device(subname = nil) click to toggle source

Alias for find_device_attached_to for user code

(see find_device_attached_to)

# File lib/syskit/data_service.rb, line 103
def robot_device(subname = nil)
    find_device_attached_to(subname)
end