Skip to content

override_tlm sets all by default, works across processes #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

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

TLM_KEYWORDS = %w(set_tlm set_tlm_raw override_tlm override_tlm_raw normalize_tlm
tlm tlm_raw tlm_formatted tlm_with_units
TLM_KEYWORDS = %w(set_tlm override_tlm normalize_tlm tlm
limits_enabled? enable_limits disable_limits
check check_raw check_tolerance check_tolerance_raw
wait wait_raw wait_tolerance wait_tolerance_raw wait_check wait_check_raw
wait_check_tolerance wait_check_tolerance_raw)
check check_tolerance wait wait_tolerance wait_check wait_check_tolerance)

def get_reserved_item_names
render :json => OpenC3::Packet::RESERVED_ITEM_NAMES, :status => 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ VARIABLE reduced_log_retain_time 2592000
<% if include_inst and include_inst_int %>
INTERFACE <%= inst_int_name %> simulated_target_interface.rb sim_inst.rb
MAP_TARGET <%= inst_target_name %>
PROTOCOL READ OverrideProtocol
<% end %>

<% if include_inst2 and include_inst2_int %>
INTERFACE <%= inst2_int_name %> simulated_target_interface.rb sim_inst.rb
MAP_TARGET <%= inst2_target_name %>
DONT_LOG
PROTOCOL READ_WRITE OverrideProtocol
<% end %>

<% if include_example and include_example_int %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,15 @@
cmd_raw_no_hazardous_check("<%= target_name %> CLEAR")
cmd_raw_no_checks("<%= target_name %> COLLECT with TYPE 1, TEMP 100.0")
check("<%= target_name %> ADCS BIASX == 100")
check_formatted("<%= target_name %> ADCS BIASX == 100")
check_with_units("<%= target_name %> ADCS BIASX == 100")
check_raw("<%= target_name %> ADCS BIASX == 100")
check_tolerance("<%= target_name %> ADCS BIASX", 5, 0.5)
check_tolerance_raw("<%= target_name %> ADCS BIASX", 5, 0.5)
check_expression("true == false")
wait
wait 5
wait("<%= target_name %> ADCS BIASX > 100", 5)
wait_raw("<%= target_name %> ADCS BIASX > 100", 5)
wait_tolerance("<%= target_name %> ADCS BIASX", 5, 0.5, 5)
wait_tolerance_raw("<%= target_name %> ADCS BIASX", 5, 0.5, 5)
wait_expression("true == false", 5)
wait_packet("<%= target_name %>","ADCS", 2, 5)
wait_check("<%= target_name %> ADCS BIASX == 100", 5)
wait_check_raw("<%= target_name %> ADCS BIASX == 100", 5)
wait_check_tolerance("<%= target_name %> ADCS BIASX", 5, 0.5, 5)
wait_check_tolerance_raw("<%= target_name %> ADCS BIASX", 5, 0.5, 5)
wait_check_expression("true == false", 5)
wait_check_packet("<%= target_name %>","ADCS", 2, 5)
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,19 @@
tlm("INST HEALTH_STATUS ASCIICMD")
tlm("INST HEALTH_STATUS CCSDSAPID")
tlm("INST HEALTH_STATUS TEMP1")
tlm("INST HEALTH_STATUS TEMP1", type: :RAW)
tlm("INST HEALTH_STATUS TEMP1", type: :CONVERTED)
tlm("INST HEALTH_STATUS TEMP1", type: :FORMATTED)
tlm("INST HEALTH_STATUS TEMP1", type: :WITH_UNITS)

tlm("INST", "HEALTH_STATUS", "ARY")
tlm("INST", "HEALTH_STATUS", "ASCIICMD")
tlm("INST", "HEALTH_STATUS", "CCSDSAPID")
tlm("INST", "HEALTH_STATUS", "TEMP1")
tlm("INST", "HEALTH_STATUS", "TEMP1", type: :RAW)
tlm("INST", "HEALTH_STATUS", "TEMP1", type: :CONVERTED)
tlm("INST", "HEALTH_STATUS", "TEMP1", type: :FORMATTED)
tlm("INST", "HEALTH_STATUS", "TEMP1", type: :WITH_UNITS)

# tlm should fail
tlm()
Expand All @@ -195,92 +203,24 @@
tlm("INST", "HEALTH_STATUS", "BOB")
tlm("INST", "HEALTH_STATUS", "ARY", "BOB")

# tlm_raw
tlm_raw("INST HEALTH_STATUS ARY")
tlm_raw("INST HEALTH_STATUS ASCIICMD")
tlm_raw("INST HEALTH_STATUS CCSDSAPID")
tlm_raw("INST HEALTH_STATUS TEMP1")

tlm_raw("INST", "HEALTH_STATUS", "ARY")
tlm_raw("INST", "HEALTH_STATUS", "ASCIICMD")
tlm_raw("INST", "HEALTH_STATUS", "CCSDSAPID")
tlm_raw("INST", "HEALTH_STATUS", "TEMP1")

# tlm_raw should fail
tlm_raw()
tlm_raw("BOB")
tlm_raw("INST")
tlm_raw("INST BOB")
tlm_raw("INST HEALTH_STATUS")
tlm_raw("INST HEALTH_STATUS BOB")
tlm_raw("INST HEALTH_STATUS ARY BOB")
tlm_raw("INST", "BOB")
tlm_raw("INST", "HEALTH_STATUS")
tlm_raw("INST", "HEALTH_STATUS", "BOB")
tlm_raw("INST", "HEALTH_STATUS", "ARY", "BOB")

# tlm_formatted
tlm_formatted("INST HEALTH_STATUS ARY")
tlm_formatted("INST HEALTH_STATUS ASCIICMD")
tlm_formatted("INST HEALTH_STATUS CCSDSAPID")
tlm_formatted("INST HEALTH_STATUS TEMP1")

tlm_formatted("INST", "HEALTH_STATUS", "ARY")
tlm_formatted("INST", "HEALTH_STATUS", "ASCIICMD")
tlm_formatted("INST", "HEALTH_STATUS", "CCSDSAPID")
tlm_formatted("INST", "HEALTH_STATUS", "TEMP1")

# tlm_formatted should fail
tlm_formatted()
tlm_formatted("BOB")
tlm_formatted("INST")
tlm_formatted("INST BOB")
tlm_formatted("INST HEALTH_STATUS")
tlm_formatted("INST HEALTH_STATUS BOB")
tlm_formatted("INST HEALTH_STATUS ARY BOB")
tlm_formatted("INST", "BOB")
tlm_formatted("INST", "HEALTH_STATUS")
tlm_formatted("INST", "HEALTH_STATUS", "BOB")
tlm_formatted("INST", "HEALTH_STATUS", "ARY", "BOB")

# tlm_with_units
tlm_with_units("INST HEALTH_STATUS ARY")
tlm_with_units("INST HEALTH_STATUS ASCIICMD")
tlm_with_units("INST HEALTH_STATUS CCSDSAPID")
tlm_with_units("INST HEALTH_STATUS TEMP1")

tlm_with_units("INST", "HEALTH_STATUS", "ARY")
tlm_with_units("INST", "HEALTH_STATUS", "ASCIICMD")
tlm_with_units("INST", "HEALTH_STATUS", "CCSDSAPID")
tlm_with_units("INST", "HEALTH_STATUS", "TEMP1")

# tlm_with_units should fail
tlm_with_units()
tlm_with_units("BOB")
tlm_with_units("INST")
tlm_with_units("INST BOB")
tlm_with_units("INST HEALTH_STATUS")
tlm_with_units("INST HEALTH_STATUS BOB")
tlm_with_units("INST HEALTH_STATUS ARY BOB")
tlm_with_units("INST", "BOB")
tlm_with_units("INST", "HEALTH_STATUS")
tlm_with_units("INST", "HEALTH_STATUS", "BOB")
tlm_with_units("INST", "HEALTH_STATUS", "ARY", "BOB")

# override_tlm
override_tlm("INST HEALTH_STATUS ARY = [0,0,0,0,0,0,0,0,0,0]")
override_tlm("INST HEALTH_STATUS ASCIICMD = 'HI'")
override_tlm("INST HEALTH_STATUS CCSDSAPID = 1000")
override_tlm("INST HEALTH_STATUS TEMP1 = 15")

# override_tlm_raw
override_tlm_raw("INST HEALTH_STATUS ARY = [0,0,0,0,0,0,0,0,0,0]")
override_tlm_raw("INST HEALTH_STATUS ASCIICMD = 'HI'")
override_tlm_raw("INST HEALTH_STATUS CCSDSAPID = 1000")
override_tlm_raw("INST HEALTH_STATUS TEMP1 = 10000")
wait_check("INST HEALTH_STATUS ARY == [1,2,3]", 5)
wait_check("INST HEALTH_STATUS ASCIICMD == 'HI'", 5)
wait_check("INST HEALTH_STATUS CCSDSAPID == 1000", 5)
wait_check("INST HEALTH_STATUS TEMP1 == 15", 5)

# normalize_tlm
normalize_tlm("INST HEALTH_STATUS ARY")
normalize_tlm("INST HEALTH_STATUS ASCIICMD")
normalize_tlm("INST HEALTH_STATUS CCSDSAPID")
normalize_tlm("INST HEALTH_STATUS TEMP1")

wait_check("INST HEALTH_STATUS ARY != [1,2,3]", 5)
wait_check("INST HEALTH_STATUS ASCIICMD != 'HI'", 5)
wait_check("INST HEALTH_STATUS CCSDSAPID != 1000", 5)
wait_check("INST HEALTH_STATUS TEMP1 != 15", 5)
4 changes: 0 additions & 4 deletions openc3/data/config/interface_modifiers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ PROTOCOL:
Protocols can be either READ, WRITE, or READ_WRITE. READ protocols act on the data
received by the interface while write acts on the data before it is sent out. READ_WRITE applies
the protocol to both reading and writing.<br/><br/>
There is only one built in protocol implemented by override_protocol.rb.
This protocol allows for Scripts to use the override_tlm() and normalize_tlm() methods to permanently
change a telemetry value. Note, this differs from set_tlm() as set_tlm() is over-written by new
incoming telemetry.<br/><br/>
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>
since: 4.0.0
parameters:
Expand Down
6 changes: 3 additions & 3 deletions openc3/lib/openc3/api/tlm_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def inject_tlm(target_name, packet_name, item_hash = nil, type: :CONVERTED, scop
# @param args The args must either be a string followed by a value or
# three strings followed by a value (see the calling style in the
# description).
# @param type [Symbol] Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS
def override_tlm(*args, type: :CONVERTED, scope: $openc3_scope, token: $openc3_token)
# @param type [Symbol] Telemetry type, :ALL (default), :RAW, :CONVERTED, :FORMATTED, :WITH_UNITS
def override_tlm(*args, type: :ALL, scope: $openc3_scope, token: $openc3_token)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an API change we should note but I think it makes more sense. Especially because PacketViewer shows the WITH_UNITS by default and a call to override_tlm now changes the value in PacketViewer (least surprise).

target_name, packet_name, item_name, value = set_tlm_process_args(args, __method__, scope: scope)
authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
CvtModel.override(target_name, packet_name, item_name, value, type: type.intern, scope: scope)
Expand All @@ -179,7 +179,7 @@ def override_tlm(*args, type: :CONVERTED, scope: $openc3_scope, token: $openc3_t
#
# @param args The args must either be a string or three strings
# (see the calling style in the description).
# @param type [Symbol] Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS
# @param type [Symbol] Telemetry type, :ALL (default), :RAW, :CONVERTED, :FORMATTED, :WITH_UNITS
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All actually already was the default for normalize but this comment was wrong

# Also takes :ALL which means to normalize all telemetry types
def normalize_tlm(*args, type: :ALL, scope: $openc3_scope, token: $openc3_token)
target_name, packet_name, item_name = tlm_process_args(args, __method__, scope: scope)
Expand Down
3 changes: 1 addition & 2 deletions openc3/lib/openc3/interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

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

autoload(:OverrideProtocol, 'openc3/interfaces/protocols/override_protocol.rb')
autoload(:CrcProtocol, 'openc3/interfaces/protocols/crc_protocol.rb')
autoload(:IgnorePacketProtocol, 'openc3/interfaces/protocols/ignore_packet_protocol.rb')
end
30 changes: 0 additions & 30 deletions openc3/lib/openc3/interfaces/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ class Interface
# @return [Array<[Protocol Class, Protocol Args, Protocol kind (:READ, :WRITE, :READ_WRITE)>] Info to recreate protocols
attr_accessor :protocol_info

# @return [Hash or nil] Hash of overridden telemetry points
attr_accessor :override_tlm

# @return [String] Most recently read raw data
attr_accessor :read_raw_data

Expand Down Expand Up @@ -166,7 +163,6 @@ def initialize
@read_protocols = []
@write_protocols = []
@protocol_info = []
@override_tlm = nil
@read_raw_data = ''
@written_raw_data = ''
@read_raw_data_time = nil
Expand Down Expand Up @@ -411,8 +407,6 @@ def copy_to(other_interface)
self.protocol_info.each do |protocol_class, protocol_args, read_write|
other_interface.add_protocol(protocol_class, protocol_args, read_write)
end
other_interface.override_tlm = nil
other_interface.override_tlm = self.override_tlm.clone if self.override_tlm
end

# Set an interface or router specific option
Expand Down Expand Up @@ -483,29 +477,5 @@ def add_protocol(protocol_class, protocol_args, read_write)
@protocol_info << [protocol_class, protocol_args, read_write]
protocol.interface = self
end

def _override_tlm(target_name, packet_name, item_name, value)
_override(target_name, packet_name, item_name, value, :CONVERTED)
end

def _override_tlm_raw(target_name, packet_name, item_name, value)
_override(target_name, packet_name, item_name, value, :RAW)
end

def _normalize_tlm(target_name, packet_name, item_name)
@override_tlm ||= {}
pkt = @override_tlm[target_name]
if pkt
items = @override_tlm[target_name][packet_name]
items.delete(item_name) if items
end
end

def _override(target_name, packet_name, item_name, value, type)
@override_tlm ||= {}
@override_tlm[target_name] ||= {}
@override_tlm[target_name][packet_name] ||= {}
@override_tlm[target_name][packet_name][item_name] = [value, type]
end
end
end
63 changes: 2 additions & 61 deletions openc3/lib/openc3/interfaces/protocols/override_protocol.rb
Original file line number Diff line number Diff line change
@@ -1,63 +1,4 @@
# encoding: ascii-8bit

# Copyright 2022 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/interfaces/protocols/protocol'

module OpenC3
# Protocol which permanently overrides an item value such that reading the
# item returns the overriden value. Methods are prefixed with underscores
# so the API can include the original name which calls out to these
# methods. Clearing the override requires calling normalize_tlm.
class OverrideProtocol < Protocol
# @param allow_empty_data [true/false/nil] See Protocol#initialize
def initialize(allow_empty_data = nil)
super(allow_empty_data)
end

# Called to perform modifications on a read packet before it is given to the user
#
# @param packet [Packet] Original packet
# @return [Packet] Potentially modified packet
def read_packet(packet)
if @interface.override_tlm && !@interface.override_tlm.empty?
# Need to make sure packet is identified and defined
target_names = nil
target_names = @interface.tlm_target_names if @interface
identified_packet = System.telemetry.identify_and_define_packet(packet, target_names)
if identified_packet
packet = identified_packet
packets = @interface.override_tlm[packet.target_name]
if packets
items = packets[packet.packet_name]
if items
items.each do |item_name, value|
# This should be safe because we check at the API level it exists
packet.write(item_name, value[0], value[1])
end
end
end
end
end
return packet
end
end
end
# This class is deprecated and this file exists only to satisfy existing code requiring it
# TODO: Remove this in a future release
4 changes: 1 addition & 3 deletions openc3/lib/openc3/interfaces/simulated_target_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/interfaces/interface'
require 'openc3/interfaces/protocols/override_protocol'

module OpenC3
# An interface class that provides simulated telemetry and command responses
Expand All @@ -38,7 +37,6 @@ def initialize(sim_target_file)
@sim_target = nil
@write_raw_allowed = false
@raw_logger_pair = nil
add_protocol(OverrideProtocol, [], :READ)
end

# Initialize the simulated target object and "connect" to the target
Expand Down
Loading