class Syskit::NetworkGeneration::PortDynamics
A representation of the actual dynamics of a port
At the last stages, the Engine object will try to create and update PortDynamics for each known ports.
The PortDynamics objects maintain a list of so-called 'triggers'. One trigger represents a single periodic event on a port (i.e. reception on an input port and emission on an output port). It states that the port will receive/send Syskit::NetworkGeneration::PortDynamics::Trigger#sample_count samples at a period of Syskit::NetworkGeneration::PortDynamics::Trigger#period. If period is zero, it means that it will happend “every once in a while”.
A sample is virtual: it is not an actual data sample on the connection. The translation between both is given by #sample_size.
Attributes
The name of the port we are computing dynamics for. This is used for debugging purposes only
The number of data samples per trigger, if the port's model value needs to be overriden
The set of registered triggers for this port, as a list of Trigger objects, where
period is in seconds and #sample_count is the
count of samples sent at period intervals
Public Class Methods
# File lib/syskit/network_generation/dataflow_dynamics.rb, line 78 def initialize(name, sample_size = 1) @name = name @sample_size = sample_size.to_int @triggers = Set.new end
Public Instance Methods
# File lib/syskit/network_generation/dataflow_dynamics.rb, line 86 def add_trigger(name, period, sample_count) if sample_count != 0 DataFlowDynamics.debug { " [#{self.name}]: adding trigger from #{name} - #{period} #{sample_count}" } triggers << Trigger.new(name, period, sample_count) end end
# File lib/syskit/network_generation/dataflow_dynamics.rb, line 84 def empty?; triggers.empty? end
# File lib/syskit/network_generation/dataflow_dynamics.rb, line 93 def merge(other_dynamics) DataFlowDynamics.debug do DataFlowDynamics.debug "adding triggers from #{other_dynamics.name} to #{name}" DataFlowDynamics.log_nest(4) do DataFlowDynamics.log_pp(:debug, other_dynamics) end break end triggers.merge(other_dynamics.triggers) true end
# File lib/syskit/network_generation/dataflow_dynamics.rb, line 105 def minimal_period triggers.map(&:period).min end
# File lib/syskit/network_generation/dataflow_dynamics.rb, line 130 def pretty_print(pp) pp.seplist(triggers) do |tr| pp.text "(#{tr.name}): #{tr.period} #{tr.sample_count}" end end
# File lib/syskit/network_generation/dataflow_dynamics.rb, line 126 def queue_size(duration) (1 + sample_count(duration)) * sample_size end
# File lib/syskit/network_generation/dataflow_dynamics.rb, line 116 def sample_count(duration) triggers.map do |trigger| if trigger.period == 0 trigger.sample_count else (duration/trigger.period).floor * trigger.sample_count end end.inject(&:+) end
# File lib/syskit/network_generation/dataflow_dynamics.rb, line 109 def sampled_at(duration) result = PortDynamics.new(name, sample_size) names = triggers.map(&:name) result.add_trigger("#{name}.resample(#{names.join(",")},#{duration})", duration, queue_size(duration)) result end