Class: OpenC3::SimulatedTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/openc3/utilities/simulated_target.rb

Overview

Base class for all virtual OpenC3 targets which must be implemented by a subclass. Provides a framework and helper methods to implement a virtual target which can cycle telemetry values and emit telemetry packets.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_name) ⇒ SimulatedTarget

Returns a new instance of SimulatedTarget.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/openc3/utilities/simulated_target.rb', line 34

def initialize(target_name)
  @tlm_packets = {}

  # Generate copy of telemetry packets for this target
  System.telemetry.packets(target_name).each do |name, packet|
    @tlm_packets[name] = packet.clone
    @tlm_packets[name].enable_method_missing
  end

  # Set defaults, template, and id values
  @tlm_packets.each do |name, packet|
    packet.restore_defaults
    ids = packet.id_items
    ids.each do |id|
      packet.public_send((id.name + '=').to_sym, id.id_value)
    end
  end

  @current_cycle_delta = {}
end

Instance Attribute Details

#tlm_packetsObject

Returns the value of attribute tlm_packets.



32
33
34
# File 'lib/openc3/utilities/simulated_target.rb', line 32

def tlm_packets
  @tlm_packets
end

Instance Method Details

#read(count_100hz, time) ⇒ Object



63
64
65
# File 'lib/openc3/utilities/simulated_target.rb', line 63

def read(count_100hz, time)
  get_pending_packets(count_100hz)
end

#set_ratesObject



55
56
57
# File 'lib/openc3/utilities/simulated_target.rb', line 55

def set_rates
  raise "Error: set_rates must be implemented by subclass"
end

#tick_incrementObject



71
72
73
# File 'lib/openc3/utilities/simulated_target.rb', line 71

def tick_increment
  return 1 # Override this method to optimize
end

#tick_period_secondsObject



67
68
69
# File 'lib/openc3/utilities/simulated_target.rb', line 67

def tick_period_seconds
  return 0.01 # Override this method to optimize
end

#write(packet) ⇒ Object



59
60
61
# File 'lib/openc3/utilities/simulated_target.rb', line 59

def write(packet)
  raise "Error: write must be implemented by subclass"
end