Skip to content

Commit

Permalink
merge other branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmelt committed Nov 16, 2017
2 parents 3376479 + abd673f commit 2f4bbd5
Show file tree
Hide file tree
Showing 24 changed files with 244 additions and 118 deletions.
1 change: 1 addition & 0 deletions cosmos.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ spec = Gem::Specification.new do |s|
s.add_development_dependency 'guard-rspec', '~> 4.0'
s.add_development_dependency 'simplecov', '~> 0.11'
s.add_development_dependency 'coveralls', '~> 0.8'
s.add_development_dependency 'codecov', '~> 0.1'
s.add_development_dependency 'benchmark-ips', '~> 2.0'
s.add_development_dependency 'ruby-prof', '~> 0.15.0' if RUBY_ENGINE == 'ruby' # MRI Only

Expand Down
1 change: 1 addition & 0 deletions demo/config/targets/INST/cmd_tlm_server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

INTERFACE INST_INT simulated_target_interface.rb sim_inst.rb
TARGET INST
PROTOCOL READ_WRITE OverrideProtocol
1 change: 1 addition & 0 deletions demo/config/targets/INST/cmd_tlm_server2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
INTERFACE INST2_INT simulated_target_interface.rb sim_inst.rb
TARGET INST2
DONT_LOG
PROTOCOL READ_WRITE OverrideProtocol
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/config/config_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def error(message, usage = "", url = @url)

# Called by the ERB template to render a partial
def render(template_name, options = {})
raise Error.new(self, "Partial name '#{template_name}' must begin with an underscore.") if template_name[0] != '_'
b = binding
if options[:locals]
if RUBY_VERSION.split('.')[0..1].join.to_i >= 21
Expand Down
1 change: 0 additions & 1 deletion lib/cosmos/io/buffered_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def read(read_length)
if @buffer.length <= 0
return nil
end

if read_length <= @buffer.length
result = @buffer[@buffer_index, read_length]
@buffer_index += read_length
Expand Down
4 changes: 3 additions & 1 deletion lib/cosmos/io/json_drb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def graceful_kill
# @param object [Object] The object to send the DRb requests to. This
# object must either include the Cosmos::Script module or be the
# CmdTlmServer.
def start_service(hostname = nil, port = nil, object = nil)
def start_service(hostname = nil, port = nil, object = nil, max_threads = 1000)
server_started = false
@server_mutex.synchronize do
server_started = true if @server
Expand All @@ -132,6 +132,8 @@ def start_service(hostname = nil, port = nil, object = nil)
:Host => hostname,
:Port => port,
:Silent => true,
:Verbose => false,
:Threads => "0:#{max_threads}",
}

# The run call will block until the server is stopped.
Expand Down
6 changes: 3 additions & 3 deletions lib/cosmos/io/json_drb_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def connect
if !@http
@http = HTTPClient.new
@http.connect_timeout = @connect_timeout
@http.receive_timeout = @connect_timeout
@http.receive_timeout = nil # Allow long polling
end
rescue => e
raise DRb::DRbConnError, e.message
Expand All @@ -123,7 +123,7 @@ def make_request(method_name, method_params, first_try)
STDOUT.puts request_data if JsonDRb.debug?
@request_in_progress = true
headers = {'Content-Type' => 'application/json-rpc'}
res = @http.post(@uri,
res = @http.post(@uri,
:body => request_data,
:header => headers)
response_data = res.body
Expand All @@ -140,7 +140,7 @@ def make_request(method_name, method_params, first_try)

def handle_response(response_data)
# The code below will always either raise or return breaking out of the loop
if response_data
if response_data and response_data.to_s.length > 0
response = JsonRpcResponse.from_json(response_data)
if JsonRpcErrorResponse === response
if response.error.data
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
6 changes: 5 additions & 1 deletion lib/cosmos/system/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,11 @@ def recursively_deflate_directory(disk_file_path, io, zip_file_path)

def put_into_archive(disk_file_path, io, zip_file_path)
io.get_output_stream(zip_file_path) do |f|
f.write(File.open(disk_file_path, 'rb').read)
data = nil
File.open(disk_file_path, 'rb') do |file|
data = file.read
end
f.write(data)
end
end

Expand Down
35 changes: 15 additions & 20 deletions lib/cosmos/tools/cmd_tlm_server/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def initialize
]
@tlm_viewer_config_filename = nil
@tlm_viewer_config = nil
@mutex = Mutex.new
end

############################################################################
Expand Down Expand Up @@ -693,27 +692,23 @@ def normalize_tlm(*args)
private

def _override(method, tgt_pkt_item)
# synchronize this method due to the interface.public_send which can cause
# ConcurrencyError exceptions in JRuby
@mutex.synchronize do
target = System.targets[tgt_pkt_item[0]]
raise "Target '#{tgt_pkt_item[0]}' does not exist" unless target
interface = System.targets[tgt_pkt_item[0]].interface
raise "Target '#{tgt_pkt_item[0]}' has no interface" unless interface
found = false
if interface.read_protocols
interface.read_protocols.each do |protocol|
found = true if protocol.kind_of? OverrideProtocol
end
end
if found
# Test to see if this telemetry item exists
System.telemetry.value(tgt_pkt_item[0], tgt_pkt_item[1], tgt_pkt_item[2], :RAW)
interface.public_send("_#{method}", *tgt_pkt_item)
else
raise "Interface #{interface.name} does not have override ability. Is 'PROTOCOL READ_WRITE OverrideProtocol' under the interface definition?"
target = System.targets[tgt_pkt_item[0]]
raise "Target '#{tgt_pkt_item[0]}' does not exist" unless target
interface = System.targets[tgt_pkt_item[0]].interface
raise "Target '#{tgt_pkt_item[0]}' has no interface" unless interface
found = false
if interface.read_protocols
interface.read_protocols.each do |protocol|
found = true if protocol.kind_of? OverrideProtocol
end
end
if found
# Test to see if this telemetry item exists
System.telemetry.value(tgt_pkt_item[0], tgt_pkt_item[1], tgt_pkt_item[2], :RAW)
interface.public_send("_#{method}", *tgt_pkt_item)
else
raise "Interface #{interface.name} does not have override ability. Is 'PROTOCOL READ_WRITE OverrideProtocol' under the interface definition?"
end
nil
end

Expand Down
Loading

0 comments on commit 2f4bbd5

Please sign in to comment.