Class: OpenC3::InterfaceTopic
- Inherits:
-
Topic
show all
- Defined in:
- lib/openc3/topics/interface_topic.rb
Constant Summary
collapse
- COMMAND_ACK_TIMEOUT_S =
30
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
-
.interface_details(interface_name, timeout: nil, scope:) ⇒ Object
-
.interface_target_disable(interface_name, target_name, cmd_only: false, tlm_only: false, scope:) ⇒ Object
-
.interface_target_enable(interface_name, target_name, cmd_only: false, tlm_only: false, 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, timeout: nil, scope:) ⇒ Object
Methods inherited from Topic
clear_topics, get_cnt, method_missing
Class Method Details
.connect_interface(interface_name, *interface_params, scope:) ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/openc3/topics/interface_topic.rb', line 74
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, allow_nan: true) }, '*', 100)
else
Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'connect' => 'true' }, '*', 100)
end
end
|
.disconnect_interface(interface_name, scope:) ⇒ Object
82
83
84
|
# File 'lib/openc3/topics/interface_topic.rb', line 82
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
114
115
116
117
118
119
120
121
|
# File 'lib/openc3/topics/interface_topic.rb', line 114
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
98
99
100
101
102
103
|
# File 'lib/openc3/topics/interface_topic.rb', line 98
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
|
.interface_details(interface_name, timeout: nil, scope:) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/openc3/topics/interface_topic.rb', line 141
def self.interface_details(interface_name, timeout: nil, scope:)
interface_name = interface_name.upcase
timeout = COMMAND_ACK_TIMEOUT_S unless timeout
ack_topic = "{#{scope}__ACKCMD}INTERFACE__#{interface_name}"
Topic.update_topic_offsets([ack_topic])
cmd_id = Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'interface_details' => '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"] == cmd_id
return JSON.parse(msg_hash["result"], :allow_nan => true, :create_additions => true)
end
end
end
raise "Timeout of #{timeout}s waiting for cmd ack"
end
|
.interface_target_disable(interface_name, target_name, cmd_only: false, tlm_only: false, scope:) ⇒ Object
132
133
134
135
136
137
138
139
|
# File 'lib/openc3/topics/interface_topic.rb', line 132
def self.interface_target_disable(interface_name, target_name, cmd_only: false, tlm_only: false, scope:)
data = {}
data['target_name'] = target_name.to_s.upcase
data['cmd_only'] = cmd_only
data['tlm_only'] = tlm_only
data['action'] = 'disable'
Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'target_control' => JSON.generate(data, allow_nan: true) }, '*', 100)
end
|
.interface_target_enable(interface_name, target_name, cmd_only: false, tlm_only: false, scope:) ⇒ Object
123
124
125
126
127
128
129
130
|
# File 'lib/openc3/topics/interface_topic.rb', line 123
def self.interface_target_enable(interface_name, target_name, cmd_only: false, tlm_only: false, scope:)
data = {}
data['target_name'] = target_name.to_s.upcase
data['cmd_only'] = cmd_only
data['tlm_only'] = tlm_only
data['action'] = 'enable'
Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'target_control' => JSON.generate(data, allow_nan: true) }, '*', 100)
end
|
.protocol_cmd(interface_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1,, scope:) ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/openc3/topics/interface_topic.rb', line 105
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/openc3/topics/interface_topic.rb', line 36
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
if result
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
end
|
.shutdown(interface, scope:) ⇒ Object
94
95
96
|
# File 'lib/openc3/topics/interface_topic.rb', line 94
def self.shutdown(interface, scope:)
Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface.name}", { 'shutdown' => 'true' }, '*', 100)
end
|
.start_raw_logging(interface_name, scope:) ⇒ Object
86
87
88
|
# File 'lib/openc3/topics/interface_topic.rb', line 86
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
90
91
92
|
# File 'lib/openc3/topics/interface_topic.rb', line 90
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.
26
27
28
29
30
31
32
33
34
|
# File 'lib/openc3/topics/interface_topic.rb', line 26
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 << "OPENC3__SYSTEM__EVENTS" topics
end
|
.write_raw(interface_name, data, timeout: nil, scope:) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/openc3/topics/interface_topic.rb', line 51
def self.write_raw(interface_name, data, timeout: nil, scope:)
interface_name = interface_name.upcase
timeout = COMMAND_ACK_TIMEOUT_S unless timeout
ack_topic = "{#{scope}__ACKCMD}INTERFACE__#{interface_name}"
Topic.update_topic_offsets([ack_topic])
cmd_id = Topic.write_topic("{#{scope}__CMD}INTERFACE__#{interface_name}", { 'raw' => data }, '*', 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"] == cmd_id
if msg_hash["result"] == "SUCCESS"
return
else
raise msg_hash["result"]
end
end
end
end
raise "Timeout of #{timeout}s waiting for cmd ack"
end
|