Class: OpenC3::InterfaceTopic
- Defined in:
- lib/openc3/topics/interface_topic.rb
Class Method Summary collapse
- .connect_interface(interface_name, *interface_params, scope:) ⇒ Object
- .disconnect_interface(interface_name, scope:) ⇒ Object
- .inject_tlm(interface_name, target_name, packet_name, item_hash = nil, type: :CONVERTED, scope:) ⇒ Object
- .interface_cmd(interface_name, cmd_name, *cmd_params, scope:) ⇒ Object
- .protocol_cmd(interface_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1,, scope:) ⇒ Object
- .receive_commands(interface, scope:) ⇒ Object
- .shutdown(interface, scope:) ⇒ Object
- .start_raw_logging(interface_name, scope:) ⇒ Object
- .stop_raw_logging(interface_name, scope:) ⇒ Object
-
.topics(interface, scope:) ⇒ Object
Generate a list of topics for this interface.
- .write_raw(interface_name, data, scope:) ⇒ Object
Methods inherited from Topic
clear_topics, get_cnt, method_missing
Class Method Details
.connect_interface(interface_name, *interface_params, scope:) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/openc3/topics/interface_topic.rb', line 54 def self.connect_interface(interface_name, *interface_params, scope:) if interface_params && !interface_params.empty? Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'connect' => 'true', 'params' => JSON.generate(interface_params) }, '*', 100) else Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'connect' => 'true' }, '*', 100) end end |
.disconnect_interface(interface_name, scope:) ⇒ Object
62 63 64 |
# File 'lib/openc3/topics/interface_topic.rb', line 62 def self.disconnect_interface(interface_name, scope:) Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'disconnect' => 'true' }, '*', 100) end |
.inject_tlm(interface_name, target_name, packet_name, item_hash = nil, type: :CONVERTED, scope:) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/openc3/topics/interface_topic.rb', line 96 def self.inject_tlm(interface_name, 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}__CMD}INTERFACE__#{interface_name}", { 'inject_tlm' => JSON.generate(data, allow_nan: true) }, '*', 100) end |
.interface_cmd(interface_name, cmd_name, *cmd_params, scope:) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/openc3/topics/interface_topic.rb', line 80 def self.interface_cmd(interface_name, cmd_name, *cmd_params, scope:) data = {} data['cmd_name'] = cmd_name data['cmd_params'] = cmd_params Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'interface_cmd' => JSON.generate(data, allow_nan: true) }, '*', 100) end |
.protocol_cmd(interface_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1,, scope:) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/openc3/topics/interface_topic.rb', line 87 def self.protocol_cmd(interface_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1, scope:) data = {} data['cmd_name'] = cmd_name data['cmd_params'] = cmd_params data['read_write'] = read_write.to_s.upcase data['index'] = index Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'protocol_cmd' => JSON.generate(data, allow_nan: true) }, '*', 100) end |
.receive_commands(interface, scope:) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/openc3/topics/interface_topic.rb', line 38 def self.receive_commands(interface, scope:) while true Topic.read_topics(InterfaceTopic.topics(interface, scope: scope)) do |topic, msg_id, msg_hash, redis| result = yield topic, msg_id, msg_hash, redis ack_topic = topic.split("__") ack_topic[1] = 'ACK' + ack_topic[1] ack_topic = ack_topic.join("__") Topic.write_topic(ack_topic, { 'result' => result, 'id' => msg_id }, '*', 100) end end end |
.shutdown(interface, scope:) ⇒ Object
74 75 76 77 78 |
# File 'lib/openc3/topics/interface_topic.rb', line 74 def self.shutdown(interface, scope:) Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface.name}", { 'shutdown' => 'true' }, '*', 100) sleep 1 # Give some time for the interface to shutdown InterfaceTopic.clear_topics(InterfaceTopic.topics(interface, scope: scope)) end |
.start_raw_logging(interface_name, scope:) ⇒ Object
66 67 68 |
# File 'lib/openc3/topics/interface_topic.rb', line 66 def self.start_raw_logging(interface_name, scope:) Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'log_stream' => 'true' }, '*', 100) end |
.stop_raw_logging(interface_name, scope:) ⇒ Object
70 71 72 |
# File 'lib/openc3/topics/interface_topic.rb', line 70 def self.stop_raw_logging(interface_name, scope:) Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'log_stream' => 'false' }, '*', 100) end |
.topics(interface, scope:) ⇒ Object
Generate a list of topics for this interface. This includes the interface itself and all the targets which are assigned to this interface.
29 30 31 32 33 34 35 36 |
# File 'lib/openc3/topics/interface_topic.rb', line 29 def self.topics(interface, scope:) topics = [] topics << "{#{scope}__CMD}INTERFACE__#{interface.name}" interface.cmd_target_names.each do |target_name| topics << "{#{scope}__CMD}TARGET__#{target_name}" end topics end |