Class: OpenC3::DecomInterfaceTopic

Inherits:
Topic show all
Defined in:
lib/openc3/topics/decom_interface_topic.rb

Class Method Summary collapse

Methods inherited from Topic

clear_topics, get_cnt, method_missing

Class Method Details

.build_cmd(target_name, cmd_name, cmd_params, range_check, raw, scope:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/openc3/topics/decom_interface_topic.rb', line 23

def self.build_cmd(target_name, cmd_name, cmd_params, range_check, raw, scope:)
  data = {}
  data['target_name'] = target_name.to_s.upcase
  data['cmd_name'] = cmd_name.to_s.upcase
  data['cmd_params'] = cmd_params
  data['range_check'] = range_check
  data['raw'] = raw
  # DecomMicroservice is listening to the DECOMINTERFACE topic and is responsible
  # for actually building the command. This was deliberate to allow this to work
  # with or without an interface.
  ack_topic = "{#{scope}__ACKCMD}TARGET__#{target_name}"
  Topic.update_topic_offsets([ack_topic])
  decom_id = Topic.write_topic("#{scope}__DECOMINTERFACE__{#{target_name}}",
      { 'build_cmd' => JSON.generate(data, allow_nan: true) }, '*', 100)
  timeout = 5 # Arbitrary 5s timeout
  time = Time.now
  while (Time.now - time) < timeout
    Topic.read_topics([ack_topic]) do |_topic, _msg_id, msg_hash, _redis|
      if msg_hash["id"] == decom_id
        if msg_hash["result"] == "SUCCESS"
          return msg_hash
        else
          raise msg_hash["message"]
        end
      end
    end
  end
  raise "Timeout of #{timeout}s waiting for cmd ack. Does target '#{target_name}' exist?"
end

.inject_tlm(target_name, packet_name, item_hash = nil, type: :CONVERTED, scope:) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/openc3/topics/decom_interface_topic.rb', line 53

def self.inject_tlm(target_name, packet_name, item_hash = nil, type: :CONVERTED, scope:)
  data = {}
  data['target_name'] = target_name.to_s.upcase
  data['packet_name'] = packet_name.to_s.upcase
  data['item_hash'] = item_hash
  data['type'] = type
  Topic.write_topic("#{scope}__DECOMINTERFACE__{#{target_name}}",
      { 'inject_tlm' => JSON.generate(data, allow_nan: true) }, '*', 100)
end