-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from BallAerospace/refactor_script
Refactor script
- Loading branch information
Showing
20 changed files
with
3,163 additions
and
2,192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.