Class: Cosmos::OverrideProtocol

Inherits:
Protocol show all
Defined in:
lib/cosmos/interfaces/protocols/override_protocol.rb

Overview

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.

Instance Attribute Summary

Attributes inherited from Protocol

#allow_empty_data, #interface

Instance Method Summary collapse

Methods inherited from Protocol

#connect_reset, #disconnect_reset, #post_write_interface, #read_data, #reset, #write_data, #write_packet

Constructor Details

#initialize(allow_empty_data = nil) ⇒ OverrideProtocol

Returns a new instance of OverrideProtocol.

Parameters:

  • allow_empty_data (true/false/nil) (defaults to: nil)

    See Protocol#initialize



29
30
31
# File 'lib/cosmos/interfaces/protocols/override_protocol.rb', line 29

def initialize(allow_empty_data = nil)
  super(allow_empty_data)
end

Instance Method Details

#read_packet(packet) ⇒ Packet

Called to perform modifications on a read packet before it is given to the user

Parameters:

  • packet (Packet)

    Original packet

Returns:

  • (Packet)

    Potentially modified packet



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cosmos/interfaces/protocols/override_protocol.rb', line 37

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.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