Skip to content

Commit 080696c

Browse files
authored
Merge pull request #343 from OpenC3/override
override_tlm sets all by default, works across processes
2 parents 1346e1c + cdde281 commit 080696c

File tree

15 files changed

+250
-458
lines changed

15 files changed

+250
-458
lines changed

openc3-cosmos-cmd-tlm-api/app/controllers/script_autocomplete_controller.rb

+3-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# All changes Copyright 2022, OpenC3, Inc.
1818
# All Rights Reserved
1919
#
20-
# This file may also be used under the terms of a commercial license
20+
# This file may also be used under the terms of a commercial license
2121
# if purchased from OpenC3, Inc.
2222

2323
require 'openc3/config/meta_config_parser'
@@ -26,12 +26,9 @@ class ScriptAutocompleteController < ApplicationController
2626
CMD_KEYWORDS = %w(cmd cmd_no_range_check cmd_no_hazardous_check cmd_no_checks
2727
cmd_raw cmd_raw_no_range_check cmd_raw_no_hazardous_check cmd_raw_no_checks)
2828

29-
TLM_KEYWORDS = %w(set_tlm set_tlm_raw override_tlm override_tlm_raw normalize_tlm
30-
tlm tlm_raw tlm_formatted tlm_with_units
29+
TLM_KEYWORDS = %w(set_tlm override_tlm normalize_tlm tlm
3130
limits_enabled? enable_limits disable_limits
32-
check check_raw check_tolerance check_tolerance_raw
33-
wait wait_raw wait_tolerance wait_tolerance_raw wait_check wait_check_raw
34-
wait_check_tolerance wait_check_tolerance_raw)
31+
check check_tolerance wait wait_tolerance wait_check wait_check_tolerance)
3532

3633
def get_reserved_item_names
3734
render :json => OpenC3::Packet::RESERVED_ITEM_NAMES, :status => 200

openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/plugin.txt

-2
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,12 @@ VARIABLE reduced_log_retain_time 2592000
6969
<% if include_inst and include_inst_int %>
7070
INTERFACE <%= inst_int_name %> simulated_target_interface.rb sim_inst.rb
7171
MAP_TARGET <%= inst_target_name %>
72-
PROTOCOL READ OverrideProtocol
7372
<% end %>
7473

7574
<% if include_inst2 and include_inst2_int %>
7675
INTERFACE <%= inst2_int_name %> simulated_target_interface.rb sim_inst.rb
7776
MAP_TARGET <%= inst2_target_name %>
7877
DONT_LOG
79-
PROTOCOL READ_WRITE OverrideProtocol
8078
<% end %>
8179

8280
<% if include_example and include_example_int %>

openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST/procedures/disconnect.rb

-8
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,15 @@
77
cmd_raw_no_hazardous_check("<%= target_name %> CLEAR")
88
cmd_raw_no_checks("<%= target_name %> COLLECT with TYPE 1, TEMP 100.0")
99
check("<%= target_name %> ADCS BIASX == 100")
10-
check_formatted("<%= target_name %> ADCS BIASX == 100")
11-
check_with_units("<%= target_name %> ADCS BIASX == 100")
12-
check_raw("<%= target_name %> ADCS BIASX == 100")
1310
check_tolerance("<%= target_name %> ADCS BIASX", 5, 0.5)
14-
check_tolerance_raw("<%= target_name %> ADCS BIASX", 5, 0.5)
1511
check_expression("true == false")
1612
wait
1713
wait 5
1814
wait("<%= target_name %> ADCS BIASX > 100", 5)
19-
wait_raw("<%= target_name %> ADCS BIASX > 100", 5)
2015
wait_tolerance("<%= target_name %> ADCS BIASX", 5, 0.5, 5)
21-
wait_tolerance_raw("<%= target_name %> ADCS BIASX", 5, 0.5, 5)
2216
wait_expression("true == false", 5)
2317
wait_packet("<%= target_name %>","ADCS", 2, 5)
2418
wait_check("<%= target_name %> ADCS BIASX == 100", 5)
25-
wait_check_raw("<%= target_name %> ADCS BIASX == 100", 5)
2619
wait_check_tolerance("<%= target_name %> ADCS BIASX", 5, 0.5, 5)
27-
wait_check_tolerance_raw("<%= target_name %> ADCS BIASX", 5, 0.5, 5)
2820
wait_check_expression("true == false", 5)
2921
wait_check_packet("<%= target_name %>","ADCS", 2, 5)

openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/SYSTEM/procedures/openc3_api_test.rb

+17-77
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,19 @@
176176
tlm("INST HEALTH_STATUS ASCIICMD")
177177
tlm("INST HEALTH_STATUS CCSDSAPID")
178178
tlm("INST HEALTH_STATUS TEMP1")
179+
tlm("INST HEALTH_STATUS TEMP1", type: :RAW)
180+
tlm("INST HEALTH_STATUS TEMP1", type: :CONVERTED)
181+
tlm("INST HEALTH_STATUS TEMP1", type: :FORMATTED)
182+
tlm("INST HEALTH_STATUS TEMP1", type: :WITH_UNITS)
179183

180184
tlm("INST", "HEALTH_STATUS", "ARY")
181185
tlm("INST", "HEALTH_STATUS", "ASCIICMD")
182186
tlm("INST", "HEALTH_STATUS", "CCSDSAPID")
183187
tlm("INST", "HEALTH_STATUS", "TEMP1")
188+
tlm("INST", "HEALTH_STATUS", "TEMP1", type: :RAW)
189+
tlm("INST", "HEALTH_STATUS", "TEMP1", type: :CONVERTED)
190+
tlm("INST", "HEALTH_STATUS", "TEMP1", type: :FORMATTED)
191+
tlm("INST", "HEALTH_STATUS", "TEMP1", type: :WITH_UNITS)
184192

185193
# tlm should fail
186194
tlm()
@@ -195,92 +203,24 @@
195203
tlm("INST", "HEALTH_STATUS", "BOB")
196204
tlm("INST", "HEALTH_STATUS", "ARY", "BOB")
197205

198-
# tlm_raw
199-
tlm_raw("INST HEALTH_STATUS ARY")
200-
tlm_raw("INST HEALTH_STATUS ASCIICMD")
201-
tlm_raw("INST HEALTH_STATUS CCSDSAPID")
202-
tlm_raw("INST HEALTH_STATUS TEMP1")
203-
204-
tlm_raw("INST", "HEALTH_STATUS", "ARY")
205-
tlm_raw("INST", "HEALTH_STATUS", "ASCIICMD")
206-
tlm_raw("INST", "HEALTH_STATUS", "CCSDSAPID")
207-
tlm_raw("INST", "HEALTH_STATUS", "TEMP1")
208-
209-
# tlm_raw should fail
210-
tlm_raw()
211-
tlm_raw("BOB")
212-
tlm_raw("INST")
213-
tlm_raw("INST BOB")
214-
tlm_raw("INST HEALTH_STATUS")
215-
tlm_raw("INST HEALTH_STATUS BOB")
216-
tlm_raw("INST HEALTH_STATUS ARY BOB")
217-
tlm_raw("INST", "BOB")
218-
tlm_raw("INST", "HEALTH_STATUS")
219-
tlm_raw("INST", "HEALTH_STATUS", "BOB")
220-
tlm_raw("INST", "HEALTH_STATUS", "ARY", "BOB")
221-
222-
# tlm_formatted
223-
tlm_formatted("INST HEALTH_STATUS ARY")
224-
tlm_formatted("INST HEALTH_STATUS ASCIICMD")
225-
tlm_formatted("INST HEALTH_STATUS CCSDSAPID")
226-
tlm_formatted("INST HEALTH_STATUS TEMP1")
227-
228-
tlm_formatted("INST", "HEALTH_STATUS", "ARY")
229-
tlm_formatted("INST", "HEALTH_STATUS", "ASCIICMD")
230-
tlm_formatted("INST", "HEALTH_STATUS", "CCSDSAPID")
231-
tlm_formatted("INST", "HEALTH_STATUS", "TEMP1")
232-
233-
# tlm_formatted should fail
234-
tlm_formatted()
235-
tlm_formatted("BOB")
236-
tlm_formatted("INST")
237-
tlm_formatted("INST BOB")
238-
tlm_formatted("INST HEALTH_STATUS")
239-
tlm_formatted("INST HEALTH_STATUS BOB")
240-
tlm_formatted("INST HEALTH_STATUS ARY BOB")
241-
tlm_formatted("INST", "BOB")
242-
tlm_formatted("INST", "HEALTH_STATUS")
243-
tlm_formatted("INST", "HEALTH_STATUS", "BOB")
244-
tlm_formatted("INST", "HEALTH_STATUS", "ARY", "BOB")
245-
246-
# tlm_with_units
247-
tlm_with_units("INST HEALTH_STATUS ARY")
248-
tlm_with_units("INST HEALTH_STATUS ASCIICMD")
249-
tlm_with_units("INST HEALTH_STATUS CCSDSAPID")
250-
tlm_with_units("INST HEALTH_STATUS TEMP1")
251-
252-
tlm_with_units("INST", "HEALTH_STATUS", "ARY")
253-
tlm_with_units("INST", "HEALTH_STATUS", "ASCIICMD")
254-
tlm_with_units("INST", "HEALTH_STATUS", "CCSDSAPID")
255-
tlm_with_units("INST", "HEALTH_STATUS", "TEMP1")
256-
257-
# tlm_with_units should fail
258-
tlm_with_units()
259-
tlm_with_units("BOB")
260-
tlm_with_units("INST")
261-
tlm_with_units("INST BOB")
262-
tlm_with_units("INST HEALTH_STATUS")
263-
tlm_with_units("INST HEALTH_STATUS BOB")
264-
tlm_with_units("INST HEALTH_STATUS ARY BOB")
265-
tlm_with_units("INST", "BOB")
266-
tlm_with_units("INST", "HEALTH_STATUS")
267-
tlm_with_units("INST", "HEALTH_STATUS", "BOB")
268-
tlm_with_units("INST", "HEALTH_STATUS", "ARY", "BOB")
269-
270206
# override_tlm
271207
override_tlm("INST HEALTH_STATUS ARY = [0,0,0,0,0,0,0,0,0,0]")
272208
override_tlm("INST HEALTH_STATUS ASCIICMD = 'HI'")
273209
override_tlm("INST HEALTH_STATUS CCSDSAPID = 1000")
274210
override_tlm("INST HEALTH_STATUS TEMP1 = 15")
275211

276-
# override_tlm_raw
277-
override_tlm_raw("INST HEALTH_STATUS ARY = [0,0,0,0,0,0,0,0,0,0]")
278-
override_tlm_raw("INST HEALTH_STATUS ASCIICMD = 'HI'")
279-
override_tlm_raw("INST HEALTH_STATUS CCSDSAPID = 1000")
280-
override_tlm_raw("INST HEALTH_STATUS TEMP1 = 10000")
212+
wait_check("INST HEALTH_STATUS ARY == [1,2,3]", 5)
213+
wait_check("INST HEALTH_STATUS ASCIICMD == 'HI'", 5)
214+
wait_check("INST HEALTH_STATUS CCSDSAPID == 1000", 5)
215+
wait_check("INST HEALTH_STATUS TEMP1 == 15", 5)
281216

282217
# normalize_tlm
283218
normalize_tlm("INST HEALTH_STATUS ARY")
284219
normalize_tlm("INST HEALTH_STATUS ASCIICMD")
285220
normalize_tlm("INST HEALTH_STATUS CCSDSAPID")
286221
normalize_tlm("INST HEALTH_STATUS TEMP1")
222+
223+
wait_check("INST HEALTH_STATUS ARY != [1,2,3]", 5)
224+
wait_check("INST HEALTH_STATUS ASCIICMD != 'HI'", 5)
225+
wait_check("INST HEALTH_STATUS CCSDSAPID != 1000", 5)
226+
wait_check("INST HEALTH_STATUS TEMP1 != 15", 5)

openc3/data/config/interface_modifiers.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ PROTOCOL:
7878
Protocols can be either READ, WRITE, or READ_WRITE. READ protocols act on the data
7979
received by the interface while write acts on the data before it is sent out. READ_WRITE applies
8080
the protocol to both reading and writing.<br/><br/>
81-
There is only one built in protocol implemented by override_protocol.rb.
82-
This protocol allows for Scripts to use the override_tlm() and normalize_tlm() methods to permanently
83-
change a telemetry value. Note, this differs from set_tlm() as set_tlm() is over-written by new
84-
incoming telemetry.<br/><br/>
8581
For information on creating your own custom protocol please see <a href="https://openc3.com/docs/v5/protocols">https://openc3.com/docs/v5/protocols</a>
8682
since: 4.0.0
8783
parameters:

openc3/lib/openc3/api/tlm_api.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def inject_tlm(target_name, packet_name, item_hash = nil, type: :CONVERTED, scop
161161
# @param args The args must either be a string followed by a value or
162162
# three strings followed by a value (see the calling style in the
163163
# description).
164-
# @param type [Symbol] Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS
165-
def override_tlm(*args, type: :CONVERTED, scope: $openc3_scope, token: $openc3_token)
164+
# @param type [Symbol] Telemetry type, :ALL (default), :RAW, :CONVERTED, :FORMATTED, :WITH_UNITS
165+
def override_tlm(*args, type: :ALL, scope: $openc3_scope, token: $openc3_token)
166166
target_name, packet_name, item_name, value = set_tlm_process_args(args, __method__, scope: scope)
167167
authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
168168
CvtModel.override(target_name, packet_name, item_name, value, type: type.intern, scope: scope)
@@ -179,7 +179,7 @@ def override_tlm(*args, type: :CONVERTED, scope: $openc3_scope, token: $openc3_t
179179
#
180180
# @param args The args must either be a string or three strings
181181
# (see the calling style in the description).
182-
# @param type [Symbol] Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS
182+
# @param type [Symbol] Telemetry type, :ALL (default), :RAW, :CONVERTED, :FORMATTED, :WITH_UNITS
183183
# Also takes :ALL which means to normalize all telemetry types
184184
def normalize_tlm(*args, type: :ALL, scope: $openc3_scope, token: $openc3_token)
185185
target_name, packet_name, item_name = tlm_process_args(args, __method__, scope: scope)

openc3/lib/openc3/interfaces.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# All changes Copyright 2022, OpenC3, Inc.
1818
# All Rights Reserved
1919
#
20-
# This file may also be used under the terms of a commercial license
20+
# This file may also be used under the terms of a commercial license
2121
# if purchased from OpenC3, Inc.
2222

2323
module OpenC3
@@ -41,7 +41,6 @@ module OpenC3
4141
autoload(:TemplateProtocol, 'openc3/interfaces/protocols/template_protocol.rb')
4242
autoload(:TerminatedProtocol, 'openc3/interfaces/protocols/terminated_protocol.rb')
4343

44-
autoload(:OverrideProtocol, 'openc3/interfaces/protocols/override_protocol.rb')
4544
autoload(:CrcProtocol, 'openc3/interfaces/protocols/crc_protocol.rb')
4645
autoload(:IgnorePacketProtocol, 'openc3/interfaces/protocols/ignore_packet_protocol.rb')
4746
end

openc3/lib/openc3/interfaces/interface.rb

-30
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ class Interface
112112
# @return [Array<[Protocol Class, Protocol Args, Protocol kind (:READ, :WRITE, :READ_WRITE)>] Info to recreate protocols
113113
attr_accessor :protocol_info
114114

115-
# @return [Hash or nil] Hash of overridden telemetry points
116-
attr_accessor :override_tlm
117-
118115
# @return [String] Most recently read raw data
119116
attr_accessor :read_raw_data
120117

@@ -166,7 +163,6 @@ def initialize
166163
@read_protocols = []
167164
@write_protocols = []
168165
@protocol_info = []
169-
@override_tlm = nil
170166
@read_raw_data = ''
171167
@written_raw_data = ''
172168
@read_raw_data_time = nil
@@ -411,8 +407,6 @@ def copy_to(other_interface)
411407
self.protocol_info.each do |protocol_class, protocol_args, read_write|
412408
other_interface.add_protocol(protocol_class, protocol_args, read_write)
413409
end
414-
other_interface.override_tlm = nil
415-
other_interface.override_tlm = self.override_tlm.clone if self.override_tlm
416410
end
417411

418412
# Set an interface or router specific option
@@ -483,29 +477,5 @@ def add_protocol(protocol_class, protocol_args, read_write)
483477
@protocol_info << [protocol_class, protocol_args, read_write]
484478
protocol.interface = self
485479
end
486-
487-
def _override_tlm(target_name, packet_name, item_name, value)
488-
_override(target_name, packet_name, item_name, value, :CONVERTED)
489-
end
490-
491-
def _override_tlm_raw(target_name, packet_name, item_name, value)
492-
_override(target_name, packet_name, item_name, value, :RAW)
493-
end
494-
495-
def _normalize_tlm(target_name, packet_name, item_name)
496-
@override_tlm ||= {}
497-
pkt = @override_tlm[target_name]
498-
if pkt
499-
items = @override_tlm[target_name][packet_name]
500-
items.delete(item_name) if items
501-
end
502-
end
503-
504-
def _override(target_name, packet_name, item_name, value, type)
505-
@override_tlm ||= {}
506-
@override_tlm[target_name] ||= {}
507-
@override_tlm[target_name][packet_name] ||= {}
508-
@override_tlm[target_name][packet_name][item_name] = [value, type]
509-
end
510480
end
511481
end
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,4 @@
11
# encoding: ascii-8bit
22

3-
# Copyright 2022 Ball Aerospace & Technologies Corp.
4-
# All Rights Reserved.
5-
#
6-
# This program is free software; you can modify and/or redistribute it
7-
# under the terms of the GNU Affero General Public License
8-
# as published by the Free Software Foundation; version 3 with
9-
# attribution addendums as found in the LICENSE.txt
10-
#
11-
# This program is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
# GNU Affero General Public License for more details.
15-
16-
# Modified by OpenC3, Inc.
17-
# All changes Copyright 2022, OpenC3, Inc.
18-
# All Rights Reserved
19-
#
20-
# This file may also be used under the terms of a commercial license
21-
# if purchased from OpenC3, Inc.
22-
23-
require 'openc3/interfaces/protocols/protocol'
24-
25-
module OpenC3
26-
# Protocol which permanently overrides an item value such that reading the
27-
# item returns the overriden value. Methods are prefixed with underscores
28-
# so the API can include the original name which calls out to these
29-
# methods. Clearing the override requires calling normalize_tlm.
30-
class OverrideProtocol < Protocol
31-
# @param allow_empty_data [true/false/nil] See Protocol#initialize
32-
def initialize(allow_empty_data = nil)
33-
super(allow_empty_data)
34-
end
35-
36-
# Called to perform modifications on a read packet before it is given to the user
37-
#
38-
# @param packet [Packet] Original packet
39-
# @return [Packet] Potentially modified packet
40-
def read_packet(packet)
41-
if @interface.override_tlm && !@interface.override_tlm.empty?
42-
# Need to make sure packet is identified and defined
43-
target_names = nil
44-
target_names = @interface.tlm_target_names if @interface
45-
identified_packet = System.telemetry.identify_and_define_packet(packet, target_names)
46-
if identified_packet
47-
packet = identified_packet
48-
packets = @interface.override_tlm[packet.target_name]
49-
if packets
50-
items = packets[packet.packet_name]
51-
if items
52-
items.each do |item_name, value|
53-
# This should be safe because we check at the API level it exists
54-
packet.write(item_name, value[0], value[1])
55-
end
56-
end
57-
end
58-
end
59-
end
60-
return packet
61-
end
62-
end
63-
end
3+
# This class is deprecated and this file exists only to satisfy existing code requiring it
4+
# TODO: Remove this in a future release

openc3/lib/openc3/interfaces/simulated_target_interface.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
# All changes Copyright 2022, OpenC3, Inc.
1818
# All Rights Reserved
1919
#
20-
# This file may also be used under the terms of a commercial license
20+
# This file may also be used under the terms of a commercial license
2121
# if purchased from OpenC3, Inc.
2222

2323
require 'openc3/interfaces/interface'
24-
require 'openc3/interfaces/protocols/override_protocol'
2524

2625
module OpenC3
2726
# An interface class that provides simulated telemetry and command responses
@@ -38,7 +37,6 @@ def initialize(sim_target_file)
3837
@sim_target = nil
3938
@write_raw_allowed = false
4039
@raw_logger_pair = nil
41-
add_protocol(OverrideProtocol, [], :READ)
4240
end
4341

4442
# Initialize the simulated target object and "connect" to the target

0 commit comments

Comments
 (0)