Class: OpenC3::DecomInterfaceTopic
- Defined in:
- lib/openc3/topics/decom_interface_topic.rb
Class Method Summary collapse
- .build_cmd(target_name, cmd_name, cmd_params, range_check, raw, timeout: 5, scope:) ⇒ Object
- .get_tlm_buffer(target_name, packet_name, timeout: 5, scope:) ⇒ Object
- .inject_tlm(target_name, packet_name, item_hash = nil, type: :CONVERTED, scope:) ⇒ Object
Methods inherited from Topic
clear_topics, get_cnt, method_missing
Class Method Details
.build_cmd(target_name, cmd_name, cmd_params, range_check, raw, timeout: 5, scope:) ⇒ Object
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 24 def self.build_cmd(target_name, cmd_name, cmd_params, range_check, raw, timeout: 5, 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) 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 |
.get_tlm_buffer(target_name, packet_name, timeout: 5, scope:) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/openc3/topics/decom_interface_topic.rb', line 63 def self.get_tlm_buffer(target_name, packet_name, timeout: 5, scope:) data = {} data['target_name'] = target_name.to_s.upcase data['packet_name'] = packet_name.to_s.upcase # DecomMicroservice is listening to the DECOMINTERFACE topic and has # the most recent decommed packets including subpackets ack_topic = "{#{scope}__ACKCMD}TARGET__#{target_name}" Topic.update_topic_offsets([ack_topic]) decom_id = Topic.write_topic("#{scope}__DECOMINTERFACE__{#{target_name}}", { 'get_tlm_buffer' => JSON.generate(data, allow_nan: true) }, '*', 100) 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" msg_hash["stored"] = ConfigParser.handle_true_false(msg_hash["stored"]) extra = msg_hash["extra"] if extra and extra.length > 0 msg_hash["extra"] = JSON.parse(extra, allow_nan: true, create_additions: true) end return msg_hash else raise msg_hash["message"] end end end end raise "Timeout of #{timeout}s waiting for 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 |