Skip to content
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

Tlm screen api #652

Merged
19 commits merged into from
Nov 16, 2017
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
2 changes: 1 addition & 1 deletion demo/config/tools/cmd_tlm_server/cmd_tlm_server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ BACKGROUND_TASK example_background_task.rb
STOPPED
BACKGROUND_TASK limits_groups.rb 5 # Initial delay to allow interfaces to connect

COLLECT_METADATA
#COLLECT_METADATA
Copy link

Choose a reason for hiding this comment

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

Is there a reason this got commented out?

Copy link
Author

Choose a reason for hiding this comment

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

Every time I start CmdTlmServer it pops up and annoys me. I could be convinced to put it back as the default with a good argument.

Copy link

Choose a reason for hiding this comment

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

I only mention because #655 found a bug in the basic install because we we NOT using it. As long as it's part of the AHK test I'm ok leaving it out.

32 changes: 32 additions & 0 deletions demo/procedures/replay_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
set_line_delay(0)
set_replay_mode(true)
filenames = get_output_logs_filenames()
replay_select_file(filenames[-1])
status = 'Analyzing'
while status =~ /Analyzing/
status, playback_delay, filename, file_start, file_current, file_end, file_index, file_max_index = replay_status
wait(1)
end
100.times do
replay_step_forward()
end
100.times do
replay_step_back()
end
replay_move_end()
replay_move_index(file_max_index / 2)
replay_move_start()
replay_set_playback_delay(0.1)
replay_play()
wait(2)
replay_set_playback_delay(0.125)
wait(5)
replay_set_playback_delay(nil)
wait(2)
replay_set_playback_delay(0.0)
wait(4)
replay_stop()
replay_reverse_play()
wait(5)
cmd_tlm_clear_counters()
cmd_tlm_reload()
42 changes: 39 additions & 3 deletions ext/cosmos/ext/structure/structure.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static ID id_ivar_neg_bit_size = 0;
static ID id_ivar_fixed_size = 0;
static ID id_ivar_short_buffer_allowed = 0;
static ID id_ivar_mutex = 0;
static ID id_ivar_create_index = 0;

static ID id_const_ASCII_8BIT_STRING = 0;
static ID id_const_ZERO_STRING = 0;
Expand Down Expand Up @@ -1189,6 +1190,16 @@ static VALUE structure_item_spaceship(VALUE self, VALUE other_item) {
int other_bit_offset = FIX2INT(rb_ivar_get(other_item, id_ivar_bit_offset));
int bit_size = 0;
int other_bit_size = 0;
int create_index = 0;
int other_create_index = 0;
int have_create_index = 0;
volatile VALUE v_create_index = rb_ivar_get(self, id_ivar_create_index);
volatile VALUE v_other_create_index = rb_ivar_get(other_item, id_ivar_create_index);
if (RTEST(v_create_index) && RTEST(v_other_create_index)) {
create_index = FIX2INT(v_create_index);
other_create_index = FIX2INT(v_other_create_index);
have_create_index = 1;
}

/* Handle same bit offset case */
if ((bit_offset == 0) && (other_bit_offset == 0)) {
Expand All @@ -1198,7 +1209,15 @@ static VALUE structure_item_spaceship(VALUE self, VALUE other_item) {
bit_size = FIX2INT(rb_ivar_get(self, id_ivar_bit_size));
other_bit_size = FIX2INT(rb_ivar_get(other_item, id_ivar_bit_size));
if (bit_size == other_bit_size) {
return INT2FIX(0);
if (have_create_index) {
if (create_index <= other_create_index) {
return INT2FIX(-1);
} else {
return INT2FIX(1);
}
} else {
return INT2FIX(0);
}
} if (bit_size < other_bit_size) {
return INT2FIX(-1);
} else {
Expand All @@ -1210,7 +1229,15 @@ static VALUE structure_item_spaceship(VALUE self, VALUE other_item) {
if (((bit_offset >= 0) && (other_bit_offset >= 0)) || ((bit_offset < 0) && (other_bit_offset < 0))) {
/* Both Have Same Sign */
if (bit_offset == other_bit_offset) {
return INT2FIX(0);
if (have_create_index) {
if (create_index <= other_create_index) {
return INT2FIX(-1);
} else {
return INT2FIX(1);
}
} else {
return INT2FIX(0);
}
} else if (bit_offset < other_bit_offset) {
return INT2FIX(-1);
} else {
Expand All @@ -1219,7 +1246,15 @@ static VALUE structure_item_spaceship(VALUE self, VALUE other_item) {
} else {
/* Different Signs */
if (bit_offset == other_bit_offset) {
return INT2FIX(0);
if (have_create_index) {
if (create_index <= other_create_index) {
return INT2FIX(-1);
} else {
return INT2FIX(1);
}
} else {
return INT2FIX(0);
}
} else if (bit_offset < other_bit_offset) {
return INT2FIX(1);
} else {
Expand Down Expand Up @@ -1387,6 +1422,7 @@ void Init_structure (void)
id_ivar_fixed_size = rb_intern("@fixed_size");
id_ivar_short_buffer_allowed = rb_intern("@short_buffer_allowed");
id_ivar_mutex = rb_intern("@mutex");
id_ivar_create_index = rb_intern("@create_index");

symbol_LITTLE_ENDIAN = ID2SYM(rb_intern("LITTLE_ENDIAN"));
symbol_BIG_ENDIAN = ID2SYM(rb_intern("BIG_ENDIAN"));
Expand Down
1 change: 1 addition & 0 deletions lib/cosmos/gui/qt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def self.check_log_configuration(packet_log_reader, log_filename)
end
end
end
return config_change_success, change_error
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/cosmos/interfaces/protocols/fixed_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def read_packet(packet)

# Identifies an unknown buffer of data as a Packet. The raw data is
# returned but the packet that matched is recorded so it can be set in the
# post_read_packet callback.
# read_packet callback.
#
# @return [String|Symbol] The identified packet data or :STOP if more data
# is required to build a packet
Expand Down Expand Up @@ -82,7 +82,7 @@ def identify_and_finish_packet
return :STOP if @data.length < identified_packet.defined_length
end
# Set some variables so we can update the packet in
# post_read_packet
# read_packet
@received_time = Time.now.sys
@target_name = identified_packet.target_name
@packet_name = identified_packet.packet_name
Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/packets/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def define(item)
# to re-sort. We also re-sort if the current item is less than the less
# item because we are inserting.
if last_item.bit_offset <= 0 or item.bit_offset <= 0 or item.bit_offset < last_item.bit_offset
@sorted_items = @sorted_items.sort {|item1, item2| item1 <=> item2}
@sorted_items = @sorted_items.sort
end
else
@sorted_items << item
Expand Down
42 changes: 37 additions & 5 deletions lib/cosmos/packets/structure_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module Cosmos
class StructureItem
include Comparable

@@create_index = 0

# Valid data types adds :DERIVED to those defined by BinaryAccessor
DATA_TYPES = BinaryAccessor::DATA_TYPES << :DERIVED

Expand Down Expand Up @@ -81,6 +83,8 @@ def initialize(name, bit_offset, bit_size, data_type, endianness, array_size = n
self.bit_size = bit_size
self.array_size = array_size
self.overflow = overflow
@create_index = @@create_index
@@create_index += 1
@structure_item_constructed = true
verify_overall()
end
Expand Down Expand Up @@ -190,6 +194,10 @@ def overflow=(overflow)
verify_overall() if @structure_item_constructed
end

def create_index
@create_index.to_i
end

if RUBY_ENGINE != 'ruby' or ENV['COSMOS_NO_EXT']
# Comparison Operator based on bit_offset. This means that StructureItems
# with different names or bit sizes are equal if they have the same bit
Expand All @@ -202,9 +210,17 @@ def <=>(other_item)
if (@bit_offset == 0) && (other_bit_offset == 0)
# Both bit_offsets are 0 so sort by bit_size
# This allows derived items with bit_size of 0 to be listed first
# Compare based on bit size
# Compare based on bit size then create index
if @bit_size == other_bit_size
return 0
if @create_index
if @create_index <= other_item.create_index
return -1
else
return 1
end
else
return 0
end
elsif @bit_size < other_bit_size
return -1
else
Expand All @@ -216,16 +232,32 @@ def <=>(other_item)
if ((@bit_offset >= 0) && (other_bit_offset >= 0)) || ((@bit_offset < 0) && (other_bit_offset < 0))
# Both Have Same Sign
if @bit_offset == other_bit_offset
return 0
elsif @bit_offset < other_bit_offset
if @create_index
if @create_index <= other_item.create_index
return -1
else
return 1
end
else
return 0
end
elsif @bit_offset <= other_bit_offset
return -1
else
return 1
end
else
# Different Signs
if @bit_offset == other_bit_offset
return 0
if @create_index
if @create_index < other_item.create_index
return -1
else
return 1
end
else
return 0
end
elsif @bit_offset < other_bit_offset
return 1
else
Expand Down
12 changes: 12 additions & 0 deletions lib/cosmos/script/cmd_tlm_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,17 @@ def unsubscribe_server_messages(id)
def get_server_message(id, non_block = false)
return $cmd_tlm_server.get_server_message(id, non_block)
end

def cmd_tlm_reload
return $cmd_tlm_server.cmd_tlm_reload
end

def cmd_tlm_clear_counters
return $cmd_tlm_server.cmd_tlm_clear_counters
end

def get_output_logs_filenames(filter = '*tlm.bin')
return $cmd_tlm_server.get_output_logs_filenames(filter)
end
end
end
60 changes: 60 additions & 0 deletions lib/cosmos/script/replay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# encoding: ascii-8bit

# Copyright 2017 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 General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt

module Cosmos

module Script
private

def replay_select_file(filename, packet_log_reader = "DEFAULT")
$cmd_tlm_server.replay_select_file(filename, packet_log_reader)
end

def replay_status
$cmd_tlm_server.replay_status
end

def replay_set_playback_delay(delay)
$cmd_tlm_server.replay_set_playback_delay(delay)
end

def replay_play
$cmd_tlm_server.replay_play
end

def replay_reverse_play
$cmd_tlm_server.replay_reverse_play
end

def replay_stop
$cmd_tlm_server.replay_stop
end

def replay_step_forward
$cmd_tlm_server.replay_step_forward
end

def replay_step_back
$cmd_tlm_server.replay_step_back
end

def replay_move_start
$cmd_tlm_server.replay_move_start
end

def replay_move_end
$cmd_tlm_server.replay_move_end
end

def replay_move_index(index)
$cmd_tlm_server.replay_move_index(index)
end
end
end
22 changes: 20 additions & 2 deletions lib/cosmos/script/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'cosmos/io/json_drb_object'
require 'cosmos/tools/cmd_tlm_server/cmd_tlm_server'
require 'cosmos/script/cmd_tlm_server'
require 'cosmos/script/replay'
require 'cosmos/script/commands'
require 'cosmos/script/telemetry'
require 'cosmos/script/limits'
Expand All @@ -20,6 +21,7 @@

$cmd_tlm_server = nil
$cmd_tlm_disconnect = false
$cmd_tlm_replay_mode = false

module Cosmos
class CheckError < RuntimeError; end
Expand All @@ -39,6 +41,7 @@ module Script
# Called when this module is mixed in using "include Cosmos::Script"
def self.included(base)
$cmd_tlm_disconnect = false
$cmd_tlm_replay_mode = false
$cmd_tlm_server = nil
initialize_script_module()
end
Expand All @@ -48,8 +51,12 @@ def initialize_script_module(config_file = CmdTlmServer::DEFAULT_CONFIG_FILE)
# Start up a standalone CTS in disconnected mode
$cmd_tlm_server = CmdTlmServer.new(config_file, false, true)
else
# Start a Json connect to the real CTS server
$cmd_tlm_server = JsonDRbObject.new(System.connect_hosts['CTS_API'], System.ports['CTS_API'])
# Start a Json connect to the real server
if $cmd_tlm_replay_mode
$cmd_tlm_server = JsonDRbObject.new(System.connect_hosts['REPLAY_API'], System.ports['REPLAY_API'])
else
$cmd_tlm_server = JsonDRbObject.new(System.connect_hosts['CTS_API'], System.ports['CTS_API'])
end
end
end

Expand All @@ -72,5 +79,16 @@ def script_disconnect
$cmd_tlm_server.disconnect if $cmd_tlm_server && !$cmd_tlm_disconnect
end

def set_replay_mode(replay_mode)
if replay_mode != $cmd_tlm_replay_mode
$cmd_tlm_replay_mode = replay_mode
initialize_script_module()
end
end

def get_replay_mode
$cmd_tlm_replay_mode
end

end
end
14 changes: 14 additions & 0 deletions lib/cosmos/script/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ def show_backtrace(value = true)
end
end

###########################
# Telemetry Screen methods
###########################

# Get the organized list of available telemetry screens
def get_screen_list(config_filename = nil, force_refresh = false)
$cmd_tlm_server.get_screen_list(config_filename, force_refresh)
end

# Get a specific screen definition
def get_screen_definition(screen_full_name, config_filename = nil, force_refresh = false)
$cmd_tlm_server.get_screen_definition(screen_full_name, config_filename, force_refresh)
end

end # module Script

end # module Cosmos
Loading