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.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/openc3/utilities/simulated_target.rb', line 39

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.



37
38
39
# File 'lib/openc3/utilities/simulated_target.rb', line 37

def tlm_packets
  @tlm_packets
end

Instance Method Details

#read(count_100hz, time) ⇒ Object



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

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

#set_ratesObject



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

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

#tick_incrementObject



76
77
78
# File 'lib/openc3/utilities/simulated_target.rb', line 76

def tick_increment
  return 1 # Override this method to optimize
end

#tick_period_secondsObject



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

def tick_period_seconds
  return 0.01 # Override this method to optimize
end

#write(packet) ⇒ Object



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

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