Module: Syskit::Device
- Defined in:
- lib/syskit/data_service.rb
Overview
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
Instance Method Summary collapse
-
#each_master_device {|device| ... } ⇒ Object
Enumerates the MasterDeviceInstance objects associated with this task context.
- #each_master_driver_service ⇒ Object
-
#find_all_driver_services_for(device) ⇒ Object
Returns the bound data service that is attached to the given device.
-
#find_device_attached_to(service = nil) ⇒ MasterDeviceInstance?
Returns the device object that is attached to the given service.
-
#robot_device(subname = nil) ⇒ Object
Alias for #find_device_attached_to for user code.
Instance Method Details
#each_master_device {|device| ... } ⇒ Object
Enumerates the MasterDeviceInstance objects associated with this task context
It yields the data service and the device model
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/syskit/data_service.rb', line 106 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 ⇒ Object
40 41 42 43 44 |
# File 'lib/syskit/data_service.rb', line 40 def each_master_driver_service model.each_master_driver_service do |srv| yield(srv.bind(self)) end end |
#find_all_driver_services_for(device) ⇒ Object
Returns the bound data service that is attached to the given device
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/syskit/data_service.rb', line 48 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) ⇒ MasterDeviceInstance?
Returns the device object that is attached to the given service.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/syskit/data_service.rb', line 71 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) ⇒ Object
Alias for #find_device_attached_to for user code
(see #find_device_attached_to)
95 96 97 |
# File 'lib/syskit/data_service.rb', line 95 def robot_device(subname = nil) find_device_attached_to(subname) end |