Skip to content

Commit

Permalink
Merge pull request #116 from BallAerospace/refactor_script
Browse files Browse the repository at this point in the history
Refactor script
  • Loading branch information
jmthomas committed Apr 23, 2015
2 parents 38e1efb + 0a12e80 commit 06033bf
Show file tree
Hide file tree
Showing 20 changed files with 3,163 additions and 2,192 deletions.
2 changes: 1 addition & 1 deletion demo/procedures/cosmos_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
["CCSDSAPID", 999, nil, "CCSDS primary header application id", nil, nil, false],
["CCSDSSEQFLAGS", 3, nil, "CCSDS primary header sequence flags", nil, nil, false],
["CCSDSSEQCNT", 0, nil, "CCSDS primary header sequence count", nil, nil, false],
["CCSDSLENGTH", 0, nil, "CCSDS primary header packet length", nil, nil, false],
["CCSDSLENGTH", 12, nil, "CCSDS primary header packet length", nil, nil, false],
["PKTID", 1, nil, "Packet id", nil, nil, false],
["TYPE", 0, {"NORMAL"=>0, "SPECIAL"=>1}, "Collect type", nil, nil, true],
["DURATION", 1.0, nil, "Collect duration", nil, nil, false],
Expand Down
5 changes: 3 additions & 2 deletions ext/cosmos/ext/telemetry/telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ static VALUE value(int argc, VALUE* argv, VALUE self)
* can be passed which will convert all items the same way. Or
* an array of symbols can be passed to control how each item is
* converted.
* @return [Array, Array] The first array contains the item values and the
* second their limits state
* @return [Array, Array, Array] The first array contains the item values, the
* second their limits state, and the third the limits settings which includes
* red, yellow, and green (if given) limits values.
*/
static VALUE values_and_limits_states(int argc, VALUE* argv, VALUE self) {
VALUE item_array = Qnil;
Expand Down
3 changes: 2 additions & 1 deletion lib/cosmos/packets/telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ def limits_change_callback=(limits_change_callback)
# an array of symbols can be passed to control how each item is
# converted.
# @return [Array, Array, Array] The first array contains the item values and the
# second their limits state, and the third their limits settings
# second their limits state, and the third their limits settings which includes
# the red, yellow, and green (if given) limits values.
# def values_and_limits_states(item_array, value_types = :CONVERTED)

# Iterates through all the telemetry packets and marks them stale if they
Expand Down
110 changes: 110 additions & 0 deletions lib/cosmos/script/cmd_tlm_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# encoding: ascii-8bit

# Copyright 2014 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 get_interface_names
return $cmd_tlm_server.get_interface_names
end

def connect_interface(interface_name, *params)
return $cmd_tlm_server.connect_interface(interface_name, *params)
end

def disconnect_interface(interface_name)
return $cmd_tlm_server.disconnect_interface(interface_name)
end

def interface_state(interface_name)
return $cmd_tlm_server.interface_state(interface_name)
end

def map_target_to_interface(target_name, interface_name)
return $cmd_tlm_server.map_target_to_interface(target_name, interface_name)
end

def get_router_names
return $cmd_tlm_server.get_router_names
end

def connect_router(router_name, *params)
return $cmd_tlm_server.connect_router(router_name, *params)
end

def disconnect_router(router_name)
return $cmd_tlm_server.disconnect_router(router_name)
end

def router_state(router_name)
return $cmd_tlm_server.router_state(router_name)
end

def get_cmd_log_filename(packet_log_writer_name = 'DEFAULT')
return $cmd_tlm_server.get_cmd_log_filename(packet_log_writer_name)
end

def get_tlm_log_filename(packet_log_writer_name = 'DEFAULT')
return $cmd_tlm_server.get_tlm_log_filename(packet_log_writer_name)
end

def start_logging(packet_log_writer_name = 'ALL', label = nil)
return $cmd_tlm_server.start_logging(packet_log_writer_name, label)
end

def stop_logging(packet_log_writer_name = 'ALL')
return $cmd_tlm_server.stop_logging(packet_log_writer_name)
end

def start_cmd_log(packet_log_writer_name = 'ALL', label = nil)
return $cmd_tlm_server.start_cmd_log(packet_log_writer_name, label)
end

def start_tlm_log(packet_log_writer_name = 'ALL', label = nil)
return $cmd_tlm_server.start_tlm_log(packet_log_writer_name, label)
end

def stop_cmd_log(packet_log_writer_name = 'ALL')
return $cmd_tlm_server.stop_cmd_log(packet_log_writer_name)
end

def stop_tlm_log(packet_log_writer_name = 'ALL')
return $cmd_tlm_server.stop_tlm_log(packet_log_writer_name)
end

def start_raw_logging_interface(interface_name = 'ALL')
return $cmd_tlm_server.start_raw_logging_interface(interface_name)
end

def stop_raw_logging_interface(interface_name = 'ALL')
return $cmd_tlm_server.stop_raw_logging_interface(interface_name)
end

def start_raw_logging_router(router_name = 'ALL')
return $cmd_tlm_server.start_raw_logging_router(router_name)
end

def stop_raw_logging_router(router_name = 'ALL')
return $cmd_tlm_server.stop_raw_logging_router(router_name)
end

def get_server_message_log_filename
return $cmd_tlm_server.get_server_message_log_filename
end

def start_new_server_message_log
return $cmd_tlm_server.start_new_server_message_log
end

end # module Script

end # module Cosmos
166 changes: 166 additions & 0 deletions lib/cosmos/script/commands.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# encoding: ascii-8bit

# Copyright 2014 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

# Log any warnings about disabling checks and log the command itself
# NOTE: This is a helper method and should not be called directly
def _log_cmd(target_name, cmd_name, cmd_params, raw, no_range, no_hazardous)
if no_range
Logger.warn "Command #{target_name} #{cmd_name} being sent ignoring range checks"
end
if no_hazardous
Logger.warn "Command #{target_name} #{cmd_name} being sent ignoring hazardous warnings"
end
Logger.info build_cmd_output_string(target_name, cmd_name, cmd_params, raw)
end

# Send the command and log the results
# NOTE: This is a helper method and should not be called directly
def _cmd(cmd, cmd_no_hazardous, *args)
raw = cmd.include?('raw')
no_range = cmd.include?('no_range') || cmd.include?('no_checks')
no_hazardous = cmd.include?('no_hazardous') || cmd.include?('no_checks')

begin
if $cmd_tlm_disconnect
# In disconnect mode we call API methods directly on the server
target_name, cmd_name, cmd_params = $cmd_tlm_server.send(cmd, *args)
else
# In connected mode we forward method calls through the JsonDrb object
# so we must call method_missing
target_name, cmd_name, cmd_params = $cmd_tlm_server.method_missing(cmd, *args)
end
_log_cmd(target_name, cmd_name, cmd_params, raw, no_range, no_hazardous)
rescue HazardousError => e
ok_to_proceed = prompt_for_hazardous(e.target_name,
e.cmd_name,
e.hazardous_description)
if ok_to_proceed
if $cmd_tlm_disconnect
target_name, cmd_name, cmd_params = $cmd_tlm_server.send(cmd_no_hazardous, *args)
else
target_name, cmd_name, cmd_params = $cmd_tlm_server.method_missing(cmd_no_hazardous, *args)
end
_log_cmd(target_name, cmd_name, cmd_params, raw, no_range, no_hazardous)
else
retry unless prompt_for_script_abort()
end
end
end

# Send a command to the specified target
# Usage:
# cmd(target_name, cmd_name, cmd_params = {})
# or
# cmd('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
def cmd(*args)
_cmd('cmd', 'cmd_no_hazardous_check', *args)
end

# Send a command to the specified target without range checking parameters
# Usage:
# cmd_no_range_check(target_name, cmd_name, cmd_params = {})
# or
# cmd_no_range_check('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
def cmd_no_range_check(*args)
_cmd('cmd_no_range_check', 'cmd_no_checks', *args)
end

# Send a command to the specified target without hazardous checks
# Usage:
# cmd_no_hazardous_check(target_name, cmd_name, cmd_params = {})
# or
# cmd_no_hazardous_check('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
def cmd_no_hazardous_check(*args)
_cmd('cmd_no_hazardous_check', nil, *args)
end

# Send a command to the specified target without range checking or hazardous checks
# Usage:
# cmd_no_checks(target_name, cmd_name, cmd_params = {})
# or
# cmd_no_checks('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
def cmd_no_checks(*args)
_cmd('cmd_no_checks', nil, *args)
end

# Send a command to the specified target without running conversions
# Usage:
# cmd_raw(target_name, cmd_name, cmd_params = {})
# or
# cmd_raw('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
def cmd_raw(*args)
_cmd('cmd_raw', 'cmd_raw_no_hazardous_check', *args)
end

# Send a command to the specified target without range checking parameters or running conversions
# Usage:
# cmd_raw_no_range_check(target_name, cmd_name, cmd_params = {})
# or
# cmd_raw_no_range_check('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
def cmd_raw_no_range_check(*args)
_cmd('cmd_raw_no_range_check', 'cmd_raw_no_checks', *args)
end

# Send a command to the specified target without hazardous checks or running conversions
# Usage:
# cmd_raw_no_hazardous_check(target_name, cmd_name, cmd_params = {})
# or
# cmd_raw_no_hazardous_check('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
def cmd_raw_no_hazardous_check(*args)
_cmd('cmd_raw_no_hazardous_check', nil, *args)
end

# Send a command to the specified target without range checking or hazardous checks or running conversions
# Usage:
# cmd_raw_no_checks(target_name, cmd_name, cmd_params = {})
# or
# cmd_raw_no_checks('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
def cmd_raw_no_checks(*args)
_cmd('cmd_raw_no_checks', nil, *args)
end

# Sends raw data through an interface
def send_raw(interface_name, data)
return $cmd_tlm_server.send_raw(interface_name, data)
end

# Sends raw data through an interface from a file
def send_raw_file(interface_name, filename)
data = nil
File.open(filename, 'rb') {|file| data = file.read}
return $cmd_tlm_server.send_raw(interface_name, data)
end

# Returns all the target commands as an array of arrays listing the command
# name and description.
def get_cmd_list(target_name)
return $cmd_tlm_server.get_cmd_list(target_name)
end

# Returns all the parameters for given command as an array of arrays
# containing the parameter name, default value, states, description, units
# full name, units abbreviation, and whether it is required.
def get_cmd_param_list(target_name, cmd_name)
return $cmd_tlm_server.get_cmd_param_list(target_name, cmd_name)
end

# Returns whether a command is hazardous (true or false)
def get_cmd_hazardous(target_name, cmd_name, cmd_params = {})
return $cmd_tlm_server.get_cmd_hazardous(target_name, cmd_name, cmd_params)
end

end
end

4 changes: 2 additions & 2 deletions lib/cosmos/script/extract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def extract_fields_from_cmd_text(text)
return [target_name, cmd_name, cmd_params]
end

def extract_fields_from_tlm_text (text)
def extract_fields_from_tlm_text(text)
split_string = text.split
raise "ERROR: Telemetry Item must be specified as 'TargetName PacketName ItemName' : #{text}" if split_string.length != 3
target_name = split_string[0]
Expand All @@ -96,7 +96,7 @@ def extract_fields_from_set_tlm_text(text)
return [target_name, packet_name, item_name, value]
end

def extract_fields_from_check_text (text)
def extract_fields_from_check_text(text)
split_string = text.split
raise "ERROR: Check improperly specified: #{text}" if split_string.length < 3
target_name = split_string[0]
Expand Down
Loading

0 comments on commit 06033bf

Please sign in to comment.