Module: OpenC3::Api
- Included in:
- AuthorizedApi, CommandValidator, GemModel, Interface, LimitsResponse, PluginModel, PythonPackageModel
- Defined in:
- lib/openc3/api/api.rb,
lib/openc3/api/cmd_api.rb,
lib/openc3/api/tlm_api.rb,
lib/openc3/api/stash_api.rb,
lib/openc3/api/config_api.rb,
lib/openc3/api/limits_api.rb,
lib/openc3/api/router_api.rb,
lib/openc3/api/target_api.rb,
lib/openc3/api/metrics_api.rb,
lib/openc3/api/settings_api.rb,
lib/openc3/api/interface_api.rb,
lib/openc3/api/offline_access_api.rb
Constant Summary collapse
- SUBSCRIPTION_DELIMITER =
2x double underscore since __ is reserved
'____'
- DELAY_METRICS =
{}
- DURATION_METRICS =
{}
- SUM_METRICS =
{}
Constants included from ApiShared
OpenC3::ApiShared::DEFAULT_TLM_POLLING_RATE
Constants included from Extract
Extract::SCANNING_REGULAR_EXPRESSION
Instance Method Summary collapse
- #_build_cmd_output_string(method_name, target_name, cmd_name, cmd_params, packet) ⇒ Object
-
#_cmd_implementation(method_name, *args, range_check:, hazardous_check:, raw:, timeout: nil, log_message: nil, manual: false, validate: true, scope: $openc3_scope, token: $openc3_token, **kwargs) ⇒ Object
NOTE: When adding new keywords to this method, make sure to update script/commands.rb.
-
#_extract_target_command_names(method_name, *args) ⇒ Object
PRIVATE implementation details.
- #_extract_target_command_parameter_names(method_name, *args) ⇒ Object
- #_extract_target_packet_item_names(method_name, *args) ⇒ Object
-
#_extract_target_packet_names(method_name, *args) ⇒ Object
PRIVATE.
-
#_get_and_set_cmd(method, *args, manual:, scope:, token:) ⇒ Object
Helper method for disable_cmd / enable_cmd.
-
#_get_item(target_name, packet_name, item_name, cache_timeout: nil, scope:) ⇒ Object
Gets an item.
-
#_limits_group(group_name, action:, manual:, scope:, token:) ⇒ Object
Enables or disables a limits group.
- #_set_tlm_process_args(args, method_name, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #_tlm_process_args(args, method_name, cache_timeout: nil, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #_validate_tlm_type(type) ⇒ Object
-
#build_cmd(*args, range_check: true, raw: false, manual: false, scope: $openc3_scope, token: $openc3_token, **kwargs) ⇒ Object
(also: #build_command)
Build a command binary.
-
#cmd(*args, **kwargs) ⇒ Object
The following methods send a command packet to a target.
-
#cmd_no_checks(*args, **kwargs) ⇒ Object
Send a command packet to a target without performing any value range checks or hazardous checks both on the command itself and its parameters.
-
#cmd_no_hazardous_check(*args, **kwargs) ⇒ Object
Send a command packet to a target without performing any hazardous checks both on the command itself and its parameters.
-
#cmd_no_range_check(*args, **kwargs) ⇒ Object
Send a command packet to a target without performing any value range checks on the parameters.
- #cmd_raw(*args, **kwargs) ⇒ Object
- #cmd_raw_no_checks(*args, **kwargs) ⇒ Object
- #cmd_raw_no_hazardous_check(*args, **kwargs) ⇒ Object
- #cmd_raw_no_range_check(*args, **kwargs) ⇒ Object
- #config_tool_names(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#connect_interface(interface_name, *interface_params, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Connects an interface and starts its telemetry gathering thread.
-
#connect_router(router_name, *router_params, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Connects a router and starts its command gathering thread.
- #delete_config(tool, name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #disable_cmd(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#disable_limits(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Disable limit checking for a telemetry item.
-
#disable_limits_group(group_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Disables limits for all the items in the group.
-
#disconnect_interface(interface_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Disconnects from an interface and kills its telemetry gathering thread.
-
#disconnect_router(router_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Disconnects a router and kills its command gathering thread.
- #enable_cmd(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#enable_limits(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Enable limits checking for a telemetry item.
-
#enable_limits_group(group_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Enables limits for all the items in the group.
-
#get_all_cmd_names(target_name, hidden: false, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String>
(also: #get_all_command_names)
Returns an array of all the command packet names.
-
#get_all_cmds(target_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Hash>
(also: #get_all_commands)
Returns an array of all the commands as a hash.
-
#get_all_interface_info(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Array<String, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric>>
Get information about all interfaces.
-
#get_all_router_info(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Array<String, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric>>
Consolidate all router info into a single API call.
- #get_all_settings(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#get_all_target_info(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Array<String, String, Numeric, Numeric>] Array of Arrays \[name, interface, cmd_cnt, tlm_cnt]
DEPRECATED: Get information about all targets Warning this call can take a long time with many defined packets.
-
#get_all_tlm(target_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Hash>
(also: #get_all_telemetry)
Returns an array of all the telemetry packet hashes.
-
#get_all_tlm_names(target_name, hidden: false, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String>
(also: #get_all_telemetry_names)
Returns an array of all the telemetry packet names.
-
#get_cmd(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
(also: #get_command)
Returns a hash of the given command.
-
#get_cmd_buffer(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Returns the raw buffer from the most recent specified command packet.
-
#get_cmd_cnt(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Numeric
Get the transmit count for a command packet.
-
#get_cmd_cnts(target_commands, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Numeric
Get the transmit counts for command packets.
-
#get_cmd_hazardous(*args, manual: false, scope: $openc3_scope, token: $openc3_token, **kwargs) ⇒ Boolean
Returns whether the specified command is hazardous.
-
#get_cmd_time(target_name = nil, command_name = nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Target Name, Command Name, Time Seconds, Time Microseconds>
Returns the time the most recent command was sent.
-
#get_cmd_value(*args, type: :CONVERTED, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Returns a value from the specified command Supports the following call syntax: get_cmd_value(“TGT PKT ITEM”, type: :RAW) get_cmd_value(“TGT”, “PKT”, “ITEM”, type: :RAW) get_cmd_value(“TGT”, “PKT”, “ITEM”, :RAW) # DEPRECATED.
-
#get_interface(interface_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Get information about an interface.
-
#get_interface_names(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String>
All the interface names.
-
#get_item(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Returns a telemetry packet item hash.
-
#get_limits(target_name, packet_name, item_name, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash{String => Array<Number, Number, Number, Number, Number, Number>}
Get a Hash of all the limits sets defined for an item.
-
#get_limits_events(offset = nil, count: 100, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash, Integer
Returns limits events starting at the provided offset.
-
#get_limits_groups(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash{String => Array<Array<String, String, String>>]
Returns all limits_groups and their members.
-
#get_limits_set(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ String
Returns the active limits set that applies to all telemetry.
-
#get_limits_sets(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String>
Returns all defined limits sets.
- #get_metrics(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#get_out_of_limits(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Array<String, String, String, String>>
Return an array of arrays indicating all items in the packet that are out of limits [[target name, packet name, item name, item limits state], …].
-
#get_overall_limits_state(ignored_items = nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ String
Get the overall limits state which is the worse case of all limits items.
-
#get_overrides(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Get the list of CVT overrides.
-
#get_packet_derived_items(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String>
Get the list of derived telemetry items for a packet.
-
#get_packets(id, block: nil, count: 1000, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String, Array<Hash>] Array of the ID and array of all packets found
Get packets based on ID returned from subscribe_packet.
-
#get_param(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
(also: #get_parameter)
Returns a hash of the given command parameter.
-
#get_router(router_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Get information about a router.
-
#get_router_names(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String>
All the router names.
- #get_setting(name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #get_settings(*settings, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#get_target(target_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Gets the full target hash.
-
#get_target_interfaces(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Array<String, String] Array of Arrays \[name, interfaces]
Get all targets and their interfaces.
-
#get_target_names(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String>
(also: #get_target_list)
Returns the list of all target names.
-
#get_tlm(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
(also: #get_telemetry)
Returns a telemetry packet hash.
-
#get_tlm_buffer(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Returns the raw buffer for a telemetry packet.
-
#get_tlm_cnt(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Numeric
Get the receive count for a telemetry packet.
-
#get_tlm_cnts(target_packets, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Numeric>
Get the transmit counts for telemetry packets.
-
#get_tlm_packet(*args, stale_time: 30, type: :CONVERTED, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String, Object, Symbol|nil>
Returns all the values (along with their limits state) for a packet.
-
#get_tlm_values(items, stale_time: 30, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Object, Symbol>
Returns all the item values (along with their limits state).
-
#inject_tlm(target_name, packet_name, item_hash = nil, type: :CONVERTED, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Injects a packet into the system as if it was received from an interface.
- #interface_cmd(interface_name, cmd_name, *cmd_params, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #interface_protocol_cmd(interface_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1,, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#limits_enabled?(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Boolean
(also: #limits_enabled)
Whether the limits are enabled for the given item.
- #list_configs(tool, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #list_settings(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #load_config(tool, name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#map_target_to_interface(target_name, interface_name, cmd_only: false, tlm_only: false, unmap_old: true, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Associates a target and all its commands and telemetry with a particular interface.
-
#normalize_tlm(*args, type: :ALL, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Normalize a telemetry item in a packet to its default behavior.
- #offline_access_needed(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#override_tlm(*args, type: :ALL, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Override the current value table such that a particular item always returns the same value (for a given type) even when new telemetry packets are received from the target.
- #router_cmd(router_name, cmd_name, *cmd_params, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #router_protocol_cmd(router_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1,, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #save_config(tool, name, data, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#send_raw(interface_name, data, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Send a raw binary string to the specified interface.
-
#set_limits(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low = nil, green_high = nil, limits_set = 'CUSTOM', persistence = nil, enabled = true, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Change the limits settings for a given item.
-
#set_limits_set(limits_set, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Changes the active limits set that applies to all telemetry.
- #set_offline_access(offline_access_token, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #set_setting(name, data, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object (also: #save_setting)
-
#set_tlm(*args, type: :CONVERTED, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Set a telemetry item in the current value table.
-
#start_raw_logging_interface(interface_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Starts raw logging for an interface.
-
#start_raw_logging_router(router_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Starts raw logging for a router.
- #stash_all(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #stash_delete(key, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #stash_get(key, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #stash_keys(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #stash_set(key, value, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#stop_raw_logging_interface(interface_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Stop raw logging for an interface.
-
#stop_raw_logging_router(router_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Stop raw logging for a router.
-
#subscribe_packets(packets, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ String
(also: #subscribe_packet)
Subscribe to a list of packets.
-
#tlm(*args, type: :CONVERTED, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Request a telemetry item from a packet.
- #tlm_formatted(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
- #tlm_raw(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
-
#tlm_variable(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
deprecated
Deprecated.
Use tlm with type:
- #tlm_with_units(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Instance Method Details
#_build_cmd_output_string(method_name, target_name, cmd_name, cmd_params, packet) ⇒ Object
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
# File 'lib/openc3/api/cmd_api.rb', line 546 def _build_cmd_output_string(method_name, target_name, cmd_name, cmd_params, packet) output_string = "#{method_name}(\"" output_string << (target_name + ' ' + cmd_name) if cmd_params.nil? or cmd_params.empty? output_string << '")' else params = [] cmd_params.each do |key, value| next if Packet::RESERVED_ITEM_NAMES.include?(key) item = packet['items'].find { |find_item| find_item['name'] == key.to_s } begin item_type = item['data_type'].intern rescue item_type = nil end if value.is_a?(String) value = value.dup if item_type == :BLOCK or item_type == :STRING if !value.is_printable? value = "0x" + value.simple_formatted else value = value.inspect end else value = value.convert_to_value.to_s end if value.length > 256 value = value[0..255] + "...'" end value.tr!('"', "'") elsif value.is_a?(Array) value = "[#{value.join(", ")}]" end params << "#{key} #{value}" end params = params.join(", ") output_string << (' with ' + params + '")') end return output_string end |
#_cmd_implementation(method_name, *args, range_check:, hazardous_check:, raw:, timeout: nil, log_message: nil, manual: false, validate: true, scope: $openc3_scope, token: $openc3_token, **kwargs) ⇒ Object
NOTE: When adding new keywords to this method, make sure to update script/commands.rb
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'lib/openc3/api/cmd_api.rb', line 456 def _cmd_implementation(method_name, *args, range_check:, hazardous_check:, raw:, timeout: nil, log_message: nil, manual: false, validate: true, scope: $openc3_scope, token: $openc3_token, **kwargs) extract_string_kwargs_to_args(args, kwargs) unless [nil, true, false].include?() raise "Invalid log_message parameter: #{}. Must be true or false." end unless timeout.nil? begin Float(timeout) rescue ArgumentError, TypeError raise "Invalid timeout parameter: #{timeout}. Must be numeric." end end case args.length when 1 target_name, cmd_name, cmd_params = extract_fields_from_cmd_text(args[0], scope: scope) when 2, 3 target_name = args[0] cmd_name = args[1] if args.length == 2 cmd_params = {} else cmd_params = args[2] end else # Invalid number of arguments raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{method_name}()" end target_name = target_name.upcase cmd_name = cmd_name.upcase cmd_params = cmd_params.transform_keys(&:upcase) user = (permission: 'cmd', target_name: target_name, packet_name: cmd_name, manual: manual, scope: scope, token: token) if user.nil? user = {} user['username'] = ENV['OPENC3_MICROSERVICE_NAME'] # Get the caller stack trace to determine the point in the code where the command was called # This code works but ultimately we didn't want to overload 'username' and take a performance hit # caller.each do |frame| # # Look for the following line in the stack trace which indicates custom code # # /tmp/d20240827-62-8e57pf/targets/INST/lib/example_limits_response.rb:31:in `call' # if frame.include?("/targets/#{target_name}") # user = {} # # username is the name of the custom code file # user['username'] = frame.split("/targets/")[-1].split(':')[0] # break # end # end end packet = TargetModel.packet(target_name, cmd_name, type: :CMD, scope: scope) if packet['disabled'] error = DisabledError.new error.target_name = target_name error.cmd_name = cmd_name raise error end if .nil? # This means the default was used, no argument was passed = true # Default is true # If the packet has the DISABLE_MESSAGES keyword then no messages by default = false if packet["messages_disabled"] # Check if any of the parameters have DISABLE_MESSAGES cmd_params.each do |key, value| item = packet['items'].find { |find_item| find_item['name'] == key.to_s } if item && item['states'] && item['states'][value] && item['states'][value]["messages_disabled"] = false end end end cmd_string = _build_cmd_output_string(method_name, target_name, cmd_name, cmd_params, packet) if Logger.info(cmd_string, scope: scope) end username = user && user['username'] ? user['username'] : 'anonymous' command = { 'target_name' => target_name, 'cmd_name' => cmd_name, 'cmd_params' => cmd_params, 'range_check' => range_check.to_s, 'hazardous_check' => hazardous_check.to_s, 'raw' => raw.to_s, 'cmd_string' => cmd_string, 'username' => username, 'validate' => validate.to_s } CommandTopic.send_command(command, timeout: timeout, scope: scope) end |
#_extract_target_command_names(method_name, *args) ⇒ Object
PRIVATE implementation details
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/openc3/api/cmd_api.rb', line 415 def _extract_target_command_names(method_name, *args) target_name = nil command_name = nil case args.length when 1 target_name, command_name = args[0].upcase.split when 2 target_name = args[0].upcase command_name = args[1].upcase else # Invalid number of arguments raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{method_name}()" end if target_name.nil? or command_name.nil? raise "ERROR: Target name and command name required. Usage: #{method_name}(\"TGT CMD\") or #{method_name}(\"TGT\", \"CMD\")" end return [target_name, command_name] end |
#_extract_target_command_parameter_names(method_name, *args) ⇒ Object
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/openc3/api/cmd_api.rb', line 434 def _extract_target_command_parameter_names(method_name, *args) target_name = nil command_name = nil parameter_name = nil case args.length when 1 target_name, command_name, parameter_name = args[0].upcase.split when 3 target_name = args[0].upcase command_name = args[1].upcase parameter_name = args[2].upcase else # Invalid number of arguments raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{method_name}()" end if target_name.nil? or command_name.nil? or parameter_name.nil? raise "ERROR: Target name, command name and parameter name required. Usage: #{method_name}(\"TGT CMD PARAM\") or #{method_name}(\"TGT\", \"CMD\", \"PARAM\")" end return [target_name, command_name, parameter_name] end |
#_extract_target_packet_item_names(method_name, *args) ⇒ Object
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/openc3/api/tlm_api.rb', line 445 def _extract_target_packet_item_names(method_name, *args) target_name = nil packet_name = nil item_name = nil case args.length when 1 target_name, packet_name, item_name = args[0].upcase.split when 3 target_name = args[0].upcase packet_name = args[1].upcase item_name = args[2].upcase else # Invalid number of arguments raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{method_name}()" end if target_name.nil? or packet_name.nil? or item_name.nil? raise "ERROR: Target name, packet name and item name are required. Usage: #{method_name}(\"TGT PKT ITEM\") or #{method_name}(\"TGT\", \"PKT\", \"ITEM\")" end return [target_name, packet_name, item_name] end |
#_extract_target_packet_names(method_name, *args) ⇒ Object
PRIVATE
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/openc3/api/tlm_api.rb', line 426 def _extract_target_packet_names(method_name, *args) target_name = nil packet_name = nil case args.length when 1 target_name, packet_name = args[0].upcase.split when 2 target_name = args[0].upcase packet_name = args[1].upcase else # Invalid number of arguments raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{method_name}()" end if target_name.nil? or packet_name.nil? raise "ERROR: Both target name and packet name required. Usage: #{method_name}(\"TGT PKT\") or #{method_name}(\"TGT\", \"PKT\")" end return [target_name, packet_name] end |
#_get_and_set_cmd(method, *args, manual:, scope:, token:) ⇒ Object
Helper method for disable_cmd / enable_cmd
138 139 140 141 142 143 |
# File 'lib/openc3/api/cmd_api.rb', line 138 def _get_and_set_cmd(method, *args, manual:, scope:, token:) target_name, command_name = _extract_target_command_names(method, *args) (permission: 'admin', target_name: target_name, packet_name: command_name, manual: manual, scope: scope, token: token) command = yield TargetModel.packet(target_name, command_name, type: :CMD, scope: scope) TargetModel.set_packet(target_name, command_name, command, type: :CMD, scope: scope) end |
#_get_item(target_name, packet_name, item_name, cache_timeout: nil, scope:) ⇒ Object
Gets an item. The code below is mostly duplicated from tlm_process_args in tlm_api.rb.
377 378 379 380 381 |
# File 'lib/openc3/api/limits_api.rb', line 377 def _get_item(target_name, packet_name, item_name, cache_timeout: nil, scope:) # Determine if this item exists, it will raise appropriate errors if not packet_name = CvtModel.determine_latest_packet_for_item(target_name, item_name, cache_timeout: cache_timeout, scope: $openc3_scope) if packet_name == 'LATEST' return TargetModel.packet_item(target_name, packet_name, item_name, scope: scope) end |
#_limits_group(group_name, action:, manual:, scope:, token:) ⇒ Object
Enables or disables a limits group
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/openc3/api/limits_api.rb', line 326 def _limits_group(group_name, action:, manual:, scope:, token:) (permission: 'tlm_set', manual: manual, scope: scope, token: token) group_name.upcase! group = get_limits_groups(scope: scope, token: token)[group_name] raise "LIMITS_GROUP #{group_name} undefined. Ensure your telemetry definition contains the line: LIMITS_GROUP #{group_name}" unless group Logger.info("#{action.to_s.capitalize} Limits Group: #{group_name}", scope: scope) last_target_name = nil last_packet_name = nil packet = nil group.sort.each do |target_name, packet_name, item_name| if last_target_name != target_name || last_packet_name != packet_name if last_target_name && last_packet_name TargetModel.set_packet(last_target_name, last_packet_name, packet, scope: scope) end packet = TargetModel.packet(target_name, packet_name, scope: scope) end packet['items'].each do |item| if item['name'] == item_name if action == :enable enabled = true item['limits']['enabled'] = true = "Enabling Limits for '#{target_name} #{packet_name} #{item_name}'" elsif action == :disable enabled = false item['limits'].delete('enabled') = "Disabling Limits for '#{target_name} #{packet_name} #{item_name}'" end Logger.info(, scope: scope) event = { type: :LIMITS_ENABLE_STATE, target_name: target_name, packet_name: packet_name, item_name: item_name, enabled: enabled, time_nsec: Time.now.to_nsec_from_epoch, message: } LimitsEventTopic.write(event, scope: scope) break end end last_target_name = target_name last_packet_name = packet_name end if last_target_name && last_packet_name TargetModel.set_packet(last_target_name, last_packet_name, packet, scope: scope) end end |
#_set_tlm_process_args(args, method_name, scope: $openc3_scope, token: $openc3_token) ⇒ Object
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
# File 'lib/openc3/api/tlm_api.rb', line 506 def _set_tlm_process_args(args, method_name, scope: $openc3_scope, token: $openc3_token) case args.length when 1 target_name, packet_name, item_name, value = extract_fields_from_set_tlm_text(args[0]) when 4 target_name = args[0] packet_name = args[1] item_name = args[2] value = args[3] else # Invalid number of arguments raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{method_name}()" end target_name = target_name.upcase packet_name = packet_name.upcase item_name = item_name.upcase # Determine if this item exists, it will raise appropriate errors if not TargetModel.packet_item(target_name, packet_name, item_name, scope: scope) return [target_name, packet_name, item_name, value] end |
#_tlm_process_args(args, method_name, cache_timeout: nil, scope: $openc3_scope, token: $openc3_token) ⇒ Object
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/openc3/api/tlm_api.rb', line 480 def _tlm_process_args(args, method_name, cache_timeout: nil, scope: $openc3_scope, token: $openc3_token) case args.length when 1 target_name, packet_name, item_name = extract_fields_from_tlm_text(args[0]) when 3 target_name = args[0] packet_name = args[1] item_name = args[2] else # Invalid number of arguments raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{method_name}()" end target_name = target_name.upcase packet_name = packet_name.upcase item_name = item_name.upcase if packet_name == 'LATEST' packet_name = CvtModel.determine_latest_packet_for_item(target_name, item_name, cache_timeout: cache_timeout, scope: scope) else # Determine if this item exists, it will raise appropriate errors if not TargetModel.packet_item(target_name, packet_name, item_name, scope: scope) end return [target_name, packet_name, item_name] end |
#_validate_tlm_type(type) ⇒ Object
466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/openc3/api/tlm_api.rb', line 466 def _validate_tlm_type(type) case type.intern when :RAW return '' when :CONVERTED return 'C' when :FORMATTED return 'F' when :WITH_UNITS return 'U' end return nil end |
#build_cmd(*args, range_check: true, raw: false, manual: false, scope: $openc3_scope, token: $openc3_token, **kwargs) ⇒ Object Also known as: build_command
Build a command binary
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/openc3/api/cmd_api.rb', line 111 def build_cmd(*args, range_check: true, raw: false, manual: false, scope: $openc3_scope, token: $openc3_token, **kwargs) extract_string_kwargs_to_args(args, kwargs) case args.length when 1 target_name, cmd_name, cmd_params = extract_fields_from_cmd_text(args[0], scope: scope) when 2, 3 target_name = args[0] cmd_name = args[1] if args.length == 2 cmd_params = {} else cmd_params = args[2] end else # Invalid number of arguments raise "ERROR: Invalid number of arguments (#{args.length}) passed to build_command()" end target_name = target_name.upcase cmd_name = cmd_name.upcase cmd_params = cmd_params.transform_keys(&:upcase) (permission: 'cmd_info', target_name: target_name, manual: manual, scope: scope, token: token) DecomInterfaceTopic.build_cmd(target_name, cmd_name, cmd_params, range_check, raw, scope: scope) end |
#cmd(*args, **kwargs) ⇒ Object
The following methods send a command packet to a target. The ‘raw’ version of the equivalent command methods do not perform command parameter conversions.
Accepts two different calling styles:
cmd("TGT CMD with PARAM1 val, PARAM2 val")
cmd('TGT','CMD','PARAM1'=>val,'PARAM2'=>val)
Favor the first syntax where possible as it is more succinct.
72 73 74 |
# File 'lib/openc3/api/cmd_api.rb', line 72 def cmd(*args, **kwargs) _cmd_implementation('cmd', *args, range_check: true, hazardous_check: true, raw: false, **kwargs) end |
#cmd_no_checks(*args, **kwargs) ⇒ Object
Send a command packet to a target without performing any value range checks or hazardous checks both on the command itself and its parameters.
101 102 103 |
# File 'lib/openc3/api/cmd_api.rb', line 101 def cmd_no_checks(*args, **kwargs) _cmd_implementation('cmd_no_checks', *args, range_check: false, hazardous_check: false, raw: false, **kwargs) end |
#cmd_no_hazardous_check(*args, **kwargs) ⇒ Object
Send a command packet to a target without performing any hazardous checks both on the command itself and its parameters. Useful in scripts to prevent popping up warnings to the user.
92 93 94 |
# File 'lib/openc3/api/cmd_api.rb', line 92 def cmd_no_hazardous_check(*args, **kwargs) _cmd_implementation('cmd_no_hazardous_check', *args, range_check: true, hazardous_check: false, raw: false, **kwargs) end |
#cmd_no_range_check(*args, **kwargs) ⇒ Object
Send a command packet to a target without performing any value range checks on the parameters. Useful for testing to allow sending command parameters outside the allowable range as defined in the configuration.
82 83 84 |
# File 'lib/openc3/api/cmd_api.rb', line 82 def cmd_no_range_check(*args, **kwargs) _cmd_implementation('cmd_no_range_check', *args, range_check: false, hazardous_check: true, raw: false, **kwargs) end |
#cmd_raw(*args, **kwargs) ⇒ Object
75 76 77 |
# File 'lib/openc3/api/cmd_api.rb', line 75 def cmd_raw(*args, **kwargs) _cmd_implementation('cmd_raw', *args, range_check: true, hazardous_check: true, raw: true, **kwargs) end |
#cmd_raw_no_checks(*args, **kwargs) ⇒ Object
104 105 106 |
# File 'lib/openc3/api/cmd_api.rb', line 104 def cmd_raw_no_checks(*args, **kwargs) _cmd_implementation('cmd_raw_no_checks', *args, range_check: false, hazardous_check: false, raw: true, **kwargs) end |
#cmd_raw_no_hazardous_check(*args, **kwargs) ⇒ Object
95 96 97 |
# File 'lib/openc3/api/cmd_api.rb', line 95 def cmd_raw_no_hazardous_check(*args, **kwargs) _cmd_implementation('cmd_raw_no_hazardous_check', *args, range_check: true, hazardous_check: false, raw: true, **kwargs) end |
#cmd_raw_no_range_check(*args, **kwargs) ⇒ Object
85 86 87 |
# File 'lib/openc3/api/cmd_api.rb', line 85 def cmd_raw_no_range_check(*args, **kwargs) _cmd_implementation('cmd_raw_no_range_check', *args, range_check: false, hazardous_check: true, raw: true, **kwargs) end |
#config_tool_names(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
36 37 38 39 |
# File 'lib/openc3/api/config_api.rb', line 36 def config_tool_names(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) ToolConfigModel.config_tool_names(scope: scope) end |
#connect_interface(interface_name, *interface_params, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Connects an interface and starts its telemetry gathering thread
66 67 68 69 70 |
# File 'lib/openc3/api/interface_api.rb', line 66 def connect_interface(interface_name, *interface_params, manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token) InterfaceTopic.connect_interface(interface_name, *interface_params, scope: scope) end |
#connect_router(router_name, *router_params, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Connects a router and starts its command gathering thread
64 65 66 67 68 |
# File 'lib/openc3/api/router_api.rb', line 64 def connect_router(router_name, *router_params, manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', router_name: router_name, manual: manual, scope: scope, token: token) RouterTopic.connect_router(router_name, *router_params, scope: scope) end |
#delete_config(tool, name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
56 57 58 59 |
# File 'lib/openc3/api/config_api.rb', line 56 def delete_config(tool, name, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system_set', manual: manual, scope: scope, token: token) ToolConfigModel.delete_config(tool, name, scope: scope) end |
#disable_cmd(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/openc3/api/cmd_api.rb', line 154 def disable_cmd(*args, manual: false, scope: $openc3_scope, token: $openc3_token) _get_and_set_cmd('disable_cmd', *args, manual: manual, scope: scope, token: token) do |command| command['disabled'] = true command end end |
#disable_limits(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Disable limit checking for a telemetry item
Accepts two different calling styles:
disable_limits("TGT PKT ITEM")
disable_limits('TGT','PKT','ITEM')
Favor the first syntax where possible as it is more succinct.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/openc3/api/limits_api.rb', line 160 def disable_limits(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name, item_name = _tlm_process_args(args, 'disable_limits', scope: scope) (permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) packet = TargetModel.packet(target_name, packet_name, scope: scope) found_item = nil packet['items'].each do |item| if item['name'] == item_name item['limits'].delete('enabled') found_item = item break end end raise "Item '#{target_name} #{packet_name} #{item_name}' does not exist" unless found_item TargetModel.set_packet(target_name, packet_name, packet, scope: scope) = "Disabling Limits for '#{target_name} #{packet_name} #{item_name}'" Logger.info(, scope: scope) event = { type: :LIMITS_ENABLE_STATE, target_name: target_name, packet_name: packet_name, item_name: item_name, enabled: false, time_nsec: Time.now.to_nsec_from_epoch, message: } LimitsEventTopic.write(event, scope: scope) end |
#disable_limits_group(group_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Disables limits for all the items in the group
277 278 279 |
# File 'lib/openc3/api/limits_api.rb', line 277 def disable_limits_group(group_name, manual: false, scope: $openc3_scope, token: $openc3_token) _limits_group(group_name, action: :disable, manual: manual, scope: scope, token: token) end |
#disconnect_interface(interface_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Disconnects from an interface and kills its telemetry gathering thread
75 76 77 78 79 |
# File 'lib/openc3/api/interface_api.rb', line 75 def disconnect_interface(interface_name, manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token) InterfaceTopic.disconnect_interface(interface_name, scope: scope) end |
#disconnect_router(router_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Disconnects a router and kills its command gathering thread
73 74 75 76 77 |
# File 'lib/openc3/api/router_api.rb', line 73 def disconnect_router(router_name, manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', router_name: router_name, manual: manual, scope: scope, token: token) RouterTopic.disconnect_router(router_name, scope: scope) end |
#enable_cmd(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/openc3/api/cmd_api.rb', line 146 def enable_cmd(*args, manual: false, scope: $openc3_scope, token: $openc3_token) _get_and_set_cmd('enable_cmd', *args, manual: manual, scope: scope, token: token) do |command| command['disabled'] = false command end end |
#enable_limits(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Enable limits checking for a telemetry item
Accepts two different calling styles:
enable_limits("TGT PKT ITEM")
enable_limits('TGT','PKT','ITEM')
Favor the first syntax where possible as it is more succinct.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/openc3/api/limits_api.rb', line 127 def enable_limits(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name, item_name = _tlm_process_args(args, 'enable_limits', scope: scope) (permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) packet = TargetModel.packet(target_name, packet_name, scope: scope) found_item = nil packet['items'].each do |item| if item['name'] == item_name item['limits']['enabled'] = true found_item = item break end end raise "Item '#{target_name} #{packet_name} #{item_name}' does not exist" unless found_item TargetModel.set_packet(target_name, packet_name, packet, scope: scope) = "Enabling Limits For '#{target_name} #{packet_name} #{item_name}'" Logger.info(, scope: scope) event = { type: :LIMITS_ENABLE_STATE, target_name: target_name, packet_name: packet_name, item_name: item_name, enabled: true, time_nsec: Time.now.to_nsec_from_epoch, message: } LimitsEventTopic.write(event, scope: scope) end |
#enable_limits_group(group_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Enables limits for all the items in the group
270 271 272 |
# File 'lib/openc3/api/limits_api.rb', line 270 def enable_limits_group(group_name, manual: false, scope: $openc3_scope, token: $openc3_token) _limits_group(group_name, action: :enable, manual: manual, scope: scope, token: token) end |
#get_all_cmd_names(target_name, hidden: false, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String> Also known as: get_all_command_names
Returns an array of all the command packet names
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/openc3/api/cmd_api.rb', line 211 def get_all_cmd_names(target_name, hidden: false, manual: false, scope: $openc3_scope, token: $openc3_token) begin packets = get_all_cmds(target_name, scope: scope, token: token) rescue RuntimeError packets = [] end names = [] packets.each do |packet| if hidden names << packet['packet_name'] else names << packet['packet_name'] unless packet['hidden'] end end return names end |
#get_all_cmds(target_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Hash> Also known as: get_all_commands
Returns an array of all the commands as a hash
198 199 200 201 202 |
# File 'lib/openc3/api/cmd_api.rb', line 198 def get_all_cmds(target_name, manual: false, scope: $openc3_scope, token: $openc3_token) target_name = target_name.upcase (permission: 'cmd_info', target_name: target_name, manual: manual, scope: scope, token: token) TargetModel.packets(target_name, type: :CMD, scope: scope) end |
#get_all_interface_info(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Array<String, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric>>
Get information about all interfaces
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/openc3/api/interface_api.rb', line 117 def get_all_interface_info(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) info = [] InterfaceStatusModel.all(scope: scope).each do |_int_name, int| info << [int['name'], int['state'], int['clients'], int['txsize'], int['rxsize'], int['txbytes'], int['rxbytes'], int['txcnt'], int['rxcnt']] end info.sort! { |a, b| a[0] <=> b[0] } info end |
#get_all_router_info(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Array<String, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric>>
Consolidate all router info into a single API call
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/openc3/api/router_api.rb', line 115 def get_all_router_info(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) info = [] RouterStatusModel.all(scope: scope).each do |_router_name, router| info << [router['name'], router['state'], router['clients'], router['txsize'], router['rxsize'],\ router['txbytes'], router['rxbytes'], router['rxcnt'], router['txcnt']] end info.sort! { |a, b| a[0] <=> b[0] } info end |
#get_all_settings(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
42 43 44 45 |
# File 'lib/openc3/api/settings_api.rb', line 42 def get_all_settings(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) SettingModel.all(scope: scope) end |
#get_all_target_info(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Array<String, String, Numeric, Numeric>] Array of Arrays \[name, interface, cmd_cnt, tlm_cnt]
DEPRECATED: Get information about all targets Warning this call can take a long time with many defined packets
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/openc3/api/target_api.rb', line 79 def get_all_target_info(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) info = [] get_target_names(scope: scope, token: token).each do |target_name| cmd_cnt = 0 packets = TargetModel.packets(target_name, type: :CMD, scope: scope) packets.each do |packet| cmd_cnt += Topic.get_cnt("#{scope}__COMMAND__{#{target_name}}__#{packet['packet_name']}") end tlm_cnt = 0 packets = TargetModel.packets(target_name, type: :TLM, scope: scope) packets.each do |packet| tlm_cnt += Topic.get_cnt("#{scope}__TELEMETRY__{#{target_name}}__#{packet['packet_name']}") end interface_names = [] InterfaceModel.all(scope: scope).each do |_name, interface| if interface['target_names'].include? target_name interface_names << interface['name'] end end info << [target_name, interface_names.join(","), cmd_cnt, tlm_cnt] end info end |
#get_all_tlm(target_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Hash> Also known as: get_all_telemetry
Returns an array of all the telemetry packet hashes
278 279 280 281 282 |
# File 'lib/openc3/api/tlm_api.rb', line 278 def get_all_tlm(target_name, manual: false, scope: $openc3_scope, token: $openc3_token) target_name = target_name.upcase (permission: 'tlm', target_name: target_name, manual: manual, scope: scope, token: token) TargetModel.packets(target_name, type: :TLM, scope: scope) end |
#get_all_tlm_names(target_name, hidden: false, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String> Also known as: get_all_telemetry_names
Returns an array of all the telemetry packet names
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/openc3/api/tlm_api.rb', line 290 def get_all_tlm_names(target_name, hidden: false, manual: false, scope: $openc3_scope, token: $openc3_token) begin packets = get_all_tlm(target_name, manual: manual, scope: scope, token: token) rescue RuntimeError packets = [] end names = [] packets.each do |packet| if hidden names << packet['packet_name'] else names << packet['packet_name'] unless packet['hidden'] end end return names end |
#get_cmd(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash Also known as: get_command
Returns a hash of the given command
234 235 236 237 238 |
# File 'lib/openc3/api/cmd_api.rb', line 234 def get_cmd(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, command_name = _extract_target_command_names('get_cmd', *args) (permission: 'cmd_info', target_name: target_name, manual: manual, scope: scope, token: token) TargetModel.packet(target_name, command_name, type: :CMD, scope: scope) end |
#get_cmd_buffer(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Returns the raw buffer from the most recent specified command packet.
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/openc3/api/cmd_api.rb', line 180 def get_cmd_buffer(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, command_name = _extract_target_command_names('get_cmd_buffer', *args) (permission: 'cmd_info', target_name: target_name, packet_name: command_name, manual: manual, scope: scope, token: token) TargetModel.packet(target_name, command_name, type: :CMD, scope: scope) topic = "#{scope}__COMMAND__{#{target_name}}__#{command_name}" msg_id, msg_hash = Topic.(topic) if msg_id msg_hash['buffer'] = msg_hash['buffer'].b return msg_hash end return nil end |
#get_cmd_cnt(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Numeric
Get the transmit count for a command packet
386 387 388 389 390 391 |
# File 'lib/openc3/api/cmd_api.rb', line 386 def get_cmd_cnt(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, command_name = _extract_target_command_names('get_cmd_cnt', *args) (permission: 'system', target_name: target_name, packet_name: command_name, manual: manual, scope: scope, token: token) TargetModel.packet(target_name, command_name, type: :CMD, scope: scope) Topic.get_cnt("#{scope}__COMMAND__{#{target_name}}__#{command_name}") end |
#get_cmd_cnts(target_commands, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Numeric
Get the transmit counts for command packets
397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/openc3/api/cmd_api.rb', line 397 def get_cmd_cnts(target_commands, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) unless target_commands.is_a?(Array) and target_commands[0].is_a?(Array) raise "get_cmd_cnts takes an array of arrays containing target, packet_name, e.g. [['INST', 'COLLECT'], ['INST', 'ABORT']]" end counts = [] target_commands.each do |target_name, command_name| target_name = target_name.upcase command_name = command_name.upcase counts << Topic.get_cnt("#{scope}__COMMAND__{#{target_name}}__#{command_name}") end counts end |
#get_cmd_hazardous(*args, manual: false, scope: $openc3_scope, token: $openc3_token, **kwargs) ⇒ Boolean
Returns whether the specified command is hazardous
Accepts two different calling styles:
get_cmd_hazardous("TGT CMD with PARAM1 val, PARAM2 val")
get_cmd_hazardous('TGT','CMD',{'PARAM1'=>val,'PARAM2'=>val})
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/openc3/api/cmd_api.rb', line 265 def get_cmd_hazardous(*args, manual: false, scope: $openc3_scope, token: $openc3_token, **kwargs) extract_string_kwargs_to_args(args, kwargs) case args.length when 1 target_name, command_name, parameters = extract_fields_from_cmd_text(args[0], scope: scope) when 2, 3 target_name = args[0] command_name = args[1] if args.length == 2 parameters = {} else parameters = args[2] end else # Invalid number of arguments raise "ERROR: Invalid number of arguments (#{args.length}) passed to get_cmd_hazardous()" end target_name = target_name.upcase command_name = command_name.upcase parameters = parameters.transform_keys(&:upcase) (permission: 'cmd_info', target_name: target_name, packet_name: command_name, manual: manual, scope: scope, token: token) packet = TargetModel.packet(target_name, command_name, type: :CMD, scope: scope) return true if packet['hazardous'] packet['items'].each do |item| next unless parameters.keys.include?(item['name']) && item['states'] # States are an array of the name followed by a hash of 'value' and sometimes 'hazardous' item['states'].each do |name, hash| parameter_name = parameters[item['name']] # Remove quotes from string parameters parameter_name = parameter_name.gsub('"', '').gsub("'", '') if parameter_name.is_a?(String) # To be hazardous the state must be marked hazardous # Check if either the state name or value matches the param passed if hash['hazardous'] && (name == parameter_name || hash['value'] == parameter_name) return true end end end false end |
#get_cmd_time(target_name = nil, command_name = nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Target Name, Command Name, Time Seconds, Time Microseconds>
Returns the time the most recent command was sent
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/openc3/api/cmd_api.rb', line 348 def get_cmd_time(target_name = nil, command_name = nil, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'cmd_info', target_name: target_name, packet_name: command_name, manual: manual, scope: scope, token: token) if target_name and command_name target_name = target_name.upcase command_name = command_name.upcase time = CommandDecomTopic.get_cmd_item(target_name, command_name, 'RECEIVED_TIMESECONDS', type: :CONVERTED, scope: scope) return [target_name, command_name, time.to_i, ((time.to_f - time.to_i) * 1_000_000).to_i] else if target_name.nil? targets = TargetModel.names(scope: scope) else target_name = target_name.upcase targets = [target_name] end time = 0 command_name = nil targets.each do |cur_target| TargetModel.packets(cur_target, type: :CMD, scope: scope).each do |packet| cur_time = CommandDecomTopic.get_cmd_item(cur_target, packet["packet_name"], 'RECEIVED_TIMESECONDS', type: :CONVERTED, scope: scope) next unless cur_time if cur_time > time time = cur_time command_name = packet["packet_name"] target_name = cur_target end end end target_name = nil unless command_name return [target_name, command_name, time.to_i, ((time.to_f - time.to_i) * 1_000_000).to_i] end end |
#get_cmd_value(*args, type: :CONVERTED, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Returns a value from the specified command Supports the following call syntax:
get_cmd_value("TGT PKT ITEM", type: :RAW)
get_cmd_value("TGT", "PKT", "ITEM", type: :RAW)
get_cmd_value("TGT", "PKT", "ITEM", :RAW) # DEPRECATED
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/openc3/api/cmd_api.rb', line 314 def get_cmd_value(*args, type: :CONVERTED, manual: false, scope: $openc3_scope, token: $openc3_token) target_name = nil command_name = nil parameter_name = nil case args.length when 1 target_name, command_name, parameter_name = args[0].upcase.split when 3 target_name = args[0].upcase command_name = args[1].upcase parameter_name = args[2].upcase when 4 target_name = args[0].upcase command_name = args[1].upcase parameter_name = args[2].upcase type = args[3].upcase else # Invalid number of arguments raise "ERROR: Invalid number of arguments (#{args.length}) passed to get_cmd_value()" end if target_name.nil? or command_name.nil? or parameter_name.nil? raise "ERROR: Target name, command name and parameter name required. Usage: get_cmd_value(\"TGT CMD PARAM\") or #{method_name}(\"TGT\", \"CMD\", \"PARAM\")" end (permission: 'cmd_info', target_name: target_name, packet_name: command_name, manual: manual, scope: scope, token: token) CommandDecomTopic.get_cmd_item(target_name, command_name, parameter_name, type: type, scope: scope) end |
#get_interface(interface_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Get information about an interface
48 49 50 51 52 53 54 |
# File 'lib/openc3/api/interface_api.rb', line 48 def get_interface(interface_name, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', interface_name: interface_name, manual: manual, scope: scope, token: token) interface = InterfaceModel.get(name: interface_name, scope: scope) raise "Interface '#{interface_name}' does not exist" unless interface interface.merge(InterfaceStatusModel.get(name: interface_name, scope: scope)) end |
#get_interface_names(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String>
Returns All the interface names.
57 58 59 60 |
# File 'lib/openc3/api/interface_api.rb', line 57 def get_interface_names(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) InterfaceModel.names(scope: scope) end |
#get_item(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Returns a telemetry packet item hash
328 329 330 331 332 |
# File 'lib/openc3/api/tlm_api.rb', line 328 def get_item(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name, item_name = _extract_target_packet_item_names('get_item', *args) (permission: 'tlm', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) TargetModel.packet_item(target_name, packet_name, item_name, scope: scope) end |
#get_limits(target_name, packet_name, item_name, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash{String => Array<Number, Number, Number, Number, Number, Number>}
Get a Hash of all the limits sets defined for an item. Hash keys are the limit set name in uppercase (note there is always a DEFAULT) and the value is an array of limit values: red low, yellow low, yellow high, red high, <green low, green high>. Green low and green high are optional.
For example: {‘DEFAULT’ => [-80, -70, 60, 80, -20, 20],
'TVAC' => [-25, -10, 50, 55] }
193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/openc3/api/limits_api.rb', line 193 def get_limits(target_name, packet_name, item_name, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'tlm', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) limits = {} item = _get_item(target_name, packet_name, item_name, cache_timeout: cache_timeout, scope: scope) item['limits'].each do |key, vals| next unless vals.is_a?(Hash) limits[key] = [vals['red_low'], vals['yellow_low'], vals['yellow_high'], vals['red_high']] limits[key].concat([vals['green_low'], vals['green_high']]) if vals['green_low'] end return limits end |
#get_limits_events(offset = nil, count: 100, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash, Integer
Returns limits events starting at the provided offset. Passing nil for an offset will return the last received limits event and associated offset.
316 317 318 319 |
# File 'lib/openc3/api/limits_api.rb', line 316 def get_limits_events(offset = nil, count: 100, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'tlm', manual: manual, scope: scope, token: token) LimitsEventTopic.read(offset, count: count, scope: scope) end |
#get_limits_groups(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash{String => Array<Array<String, String, String>>]
Returns all limits_groups and their members
262 263 264 265 |
# File 'lib/openc3/api/limits_api.rb', line 262 def get_limits_groups(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'tlm', manual: manual, scope: scope, token: token) TargetModel.limits_groups(scope: scope) end |
#get_limits_set(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ String
Returns the active limits set that applies to all telemetry
303 304 305 306 |
# File 'lib/openc3/api/limits_api.rb', line 303 def get_limits_set(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'tlm', manual: manual, scope: scope, token: token) LimitsEventTopic.current_set(scope: scope) end |
#get_limits_sets(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String>
Returns all defined limits sets
284 285 286 287 |
# File 'lib/openc3/api/limits_api.rb', line 284 def get_limits_sets(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'tlm', manual: manual, scope: scope, token: token) LimitsEventTopic.sets(scope: scope).keys end |
#get_metrics(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/openc3/api/metrics_api.rb', line 69 def get_metrics(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) sum_metrics = SUM_METRICS.dup duration_metrics = DURATION_METRICS.dup delay_metrics = DELAY_METRICS.dup metrics = MetricModel.all(scope: scope) metrics.each do |_microservice_name, metrics| next unless metrics and metrics['values'] metrics['values'].each do |metric_name, data| value = data['value'] if sum_metrics[metric_name] sum_metrics[metric_name] += value elsif duration_metrics[metric_name] previous = duration_metrics[metric_name] duration_metrics[metric_name] = value if value > previous elsif delay_metrics.include?(metric_name) previous = delay_metrics[metric_name] delay_metrics[metric_name] = value if value > previous else # Ignore other metrics for now end end end result = delay_metrics result.merge!(duration_metrics) result.merge!(sum_metrics) result.merge!(MetricModel.redis_metrics) return result end |
#get_out_of_limits(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Array<String, String, String, String>>
Return an array of arrays indicating all items in the packet that are out of limits
[[target name, packet name, item name, item limits state], ...]
50 51 52 53 |
# File 'lib/openc3/api/limits_api.rb', line 50 def get_out_of_limits(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'tlm', manual: manual, scope: scope, token: token) LimitsEventTopic.out_of_limits(scope: scope) end |
#get_overall_limits_state(ignored_items = nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ String
Get the overall limits state which is the worse case of all limits items. For example if any limits are YELLOW_LOW or YELLOW_HIGH then the overall limits state is YELLOW. If a single limit item then turns RED_HIGH the overall limits state is RED.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/openc3/api/limits_api.rb', line 62 def get_overall_limits_state(ignored_items = nil, manual: false, scope: $openc3_scope, token: $openc3_token) # We only need to check out of limits items so call get_out_of_limits() which authorizes out_of_limits = get_out_of_limits(scope: scope, token: token) overall = 'GREEN' # Build easily matchable ignore list if ignored_items ignored_items.map! do |item| raise "Invalid ignored item: #{item}. Must be [TGT, PKT, ITEM] where ITEM can be nil." if item.length != 3 item.join('__') end else ignored_items = [] end out_of_limits.each do |target_name, packet_name, item_name, limits_state| # Ignore this item if we match one of the ignored items. Checking against /^#{item}/ # allows us to detect matches against a TGT__PKT__ with no item defined. next if ignored_items.detect { |item| "#{target_name}__#{packet_name}__#{item_name}" =~ /^#{item}/ } if limits_state == 'RED' || limits_state == 'RED_HIGH' || limits_state == 'RED_LOW' overall = limits_state break # Red is as high as we go so no need to look for more end case overall # If our overall state is currently blue or green we can go to any state when 'BLUE', 'GREEN', 'GREEN_HIGH', 'GREEN_LOW' overall = limits_state # else YELLOW - Stay at YELLOW until we find a red end end overall = 'GREEN' if overall == 'GREEN_HIGH' || overall == 'GREEN_LOW' || overall == 'BLUE' overall = 'YELLOW' if overall == 'YELLOW_HIGH' || overall == 'YELLOW_LOW' overall = 'RED' if overall == 'RED_HIGH' || overall == 'RED_LOW' return overall end |
#get_overrides(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Get the list of CVT overrides
178 179 180 181 |
# File 'lib/openc3/api/tlm_api.rb', line 178 def get_overrides(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'tlm', manual: manual, scope: scope, token: token) CvtModel.overrides(scope: scope) end |
#get_packet_derived_items(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String>
Get the list of derived telemetry items for a packet
417 418 419 420 421 422 |
# File 'lib/openc3/api/tlm_api.rb', line 417 def get_packet_derived_items(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name = _extract_target_packet_names('get_packet_derived_items', *args) (permission: 'tlm', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) packet = TargetModel.packet(target_name, packet_name, scope: scope) return packet['items'].select { |item| item['data_type'] == 'DERIVED' }.map { |item| item['name'] } end |
#get_packets(id, block: nil, count: 1000, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String, Array<Hash>] Array of the ID and array of all packets found
Get packets based on ID returned from subscribe_packet.
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/openc3/api/tlm_api.rb', line 366 def get_packets(id, block: nil, count: 1000, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'tlm', manual: manual, scope: scope, token: token) # Split the list of topic, ID values and turn it into a hash for easy updates lookup = Hash[*id.split(SUBSCRIPTION_DELIMITER)] xread = Topic.read_topics(lookup.keys, lookup.values, nil, count) # Always don't block # Return the original ID and and empty array if we didn't get anything packets = [] return [id, packets] if xread.empty? xread.each do |topic, data| data.each do |id, msg_hash| lookup[topic] = id # save the new ID json_hash = JSON.parse(msg_hash['json_data'], :allow_nan => true, :create_additions => true) msg_hash.delete('json_data') packets << msg_hash.merge(json_hash) end end return lookup.to_a.join(SUBSCRIPTION_DELIMITER), packets end |
#get_param(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash Also known as: get_parameter
Returns a hash of the given command parameter
249 250 251 252 253 |
# File 'lib/openc3/api/cmd_api.rb', line 249 def get_param(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, command_name, parameter_name = _extract_target_command_parameter_names('get_param', *args) (permission: 'cmd_info', target_name: target_name, packet_name: command_name, manual: manual, scope: scope, token: token) TargetModel.packet_item(target_name, command_name, parameter_name, type: :CMD, scope: scope) end |
#get_router(router_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Get information about a router
46 47 48 49 50 51 52 |
# File 'lib/openc3/api/router_api.rb', line 46 def get_router(router_name, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', router_name: router_name, manual: manual, scope: scope, token: token) router = RouterModel.get(name: router_name, scope: scope) raise "Router '#{router_name}' does not exist" unless router router.merge(RouterStatusModel.get(name: router_name, scope: scope)) end |
#get_router_names(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String>
Returns All the router names.
55 56 57 58 |
# File 'lib/openc3/api/router_api.rb', line 55 def get_router_names(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) RouterModel.names(scope: scope) end |
#get_setting(name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/openc3/api/settings_api.rb', line 47 def get_setting(name, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) setting = SettingModel.get(name: name, scope: scope) if setting setting['data'] else nil end end |
#get_settings(*settings, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/openc3/api/settings_api.rb', line 57 def get_settings(*settings, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) result = [] settings.each { |name| result << get_setting(name, scope: scope, token: token) } result end |
#get_target(target_name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Gets the full target hash
51 52 53 54 |
# File 'lib/openc3/api/target_api.rb', line 51 def get_target(target_name, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', target_name: target_name, manual: manual, scope: scope, token: token) TargetModel.get(name: target_name, scope: scope) end |
#get_target_interfaces(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Array<String, String] Array of Arrays \[name, interfaces]
Get all targets and their interfaces
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/openc3/api/target_api.rb', line 59 def get_target_interfaces(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) info = [] interfaces = InterfaceModel.all(scope: scope) get_target_names(scope: scope, token: token).each do |target_name| interface_names = [] interfaces.each do |_name, interface| if interface['target_names'].include? target_name interface_names << interface['name'] end end info << [target_name, interface_names.join(",")] end info end |
#get_target_names(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String> Also known as: get_target_list
Returns the list of all target names
39 40 41 42 |
# File 'lib/openc3/api/target_api.rb', line 39 def get_target_names(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) TargetModel.names(scope: scope) end |
#get_tlm(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash Also known as: get_telemetry
Returns a telemetry packet hash
314 315 316 317 318 |
# File 'lib/openc3/api/tlm_api.rb', line 314 def get_tlm(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name = _extract_target_packet_names('get_tlm', *args) (permission: 'tlm', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) TargetModel.packet(target_name, packet_name, scope: scope) end |
#get_tlm_buffer(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Hash
Returns the raw buffer for a telemetry packet.
207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/openc3/api/tlm_api.rb', line 207 def get_tlm_buffer(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name = _extract_target_packet_names('get_tlm_buffer', *args) (permission: 'tlm', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) TargetModel.packet(target_name, packet_name, scope: scope) topic = "#{scope}__TELEMETRY__{#{target_name}}__#{packet_name}" msg_id, msg_hash = Topic.(topic) if msg_id msg_hash['buffer'] = msg_hash['buffer'].b return msg_hash end return nil end |
#get_tlm_cnt(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Numeric
Get the receive count for a telemetry packet
390 391 392 393 394 395 |
# File 'lib/openc3/api/tlm_api.rb', line 390 def get_tlm_cnt(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name = _extract_target_packet_names('get_tlm_cnt', *args) (permission: 'system', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) TargetModel.packet(target_name, packet_name, scope: scope) Topic.get_cnt("#{scope}__TELEMETRY__{#{target_name}}__#{packet_name}") end |
#get_tlm_cnts(target_packets, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Numeric>
Get the transmit counts for telemetry packets
401 402 403 404 405 406 407 408 409 410 |
# File 'lib/openc3/api/tlm_api.rb', line 401 def get_tlm_cnts(target_packets, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) counts = [] target_packets.each do |target_name, packet_name| target_name = target_name.upcase packet_name = packet_name.upcase counts << Topic.get_cnt("#{scope}__TELEMETRY__{#{target_name}}__#{packet_name}") end counts end |
#get_tlm_packet(*args, stale_time: 30, type: :CONVERTED, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<String, Object, Symbol|nil>
Returns all the values (along with their limits state) for a packet.
229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/openc3/api/tlm_api.rb', line 229 def get_tlm_packet(*args, stale_time: 30, type: :CONVERTED, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name = _extract_target_packet_names('get_tlm_packet', *args) (permission: 'tlm', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) packet = TargetModel.packet(target_name, packet_name, scope: scope) t = _validate_tlm_type(type) raise ArgumentError, "Unknown type '#{type}' for #{target_name} #{packet_name}" if t.nil? items = packet['items'].map { | item | item['name'].upcase } cvt_items = items.map { | item | [target_name, packet_name, item, type] } current_values = CvtModel.get_tlm_values(cvt_items, stale_time: stale_time, cache_timeout: cache_timeout, scope: scope) items.zip(current_values).map { | item , values | [item, values[0], values[1]]} end |
#get_tlm_values(items, stale_time: 30, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Array<Object, Symbol>
Returns all the item values (along with their limits state). The items can be from any target and packet and thus must be fully qualified with their target and packet names.
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/openc3/api/tlm_api.rb', line 251 def get_tlm_values(items, stale_time: 30, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) if !items.is_a?(Array) || !items[0].is_a?(String) raise ArgumentError, "items must be array of strings: ['TGT__PKT__ITEM__TYPE', ...]" end packets = [] cvt_items = [] items.each_with_index do |item, index| item_upcase = item.to_s.upcase target_name, packet_name, item_name, value_type = item_upcase.split('__') raise ArgumentError, "items must be formatted as TGT__PKT__ITEM__TYPE" if target_name.nil? || packet_name.nil? || item_name.nil? || value_type.nil? packet_name = CvtModel.determine_latest_packet_for_item(target_name, item_name, cache_timeout: cache_timeout, scope: scope) if packet_name == 'LATEST' # Change packet_name in case of LATEST and ensure upcase cvt_items[index] = [target_name, packet_name, item_name, value_type] packets << [target_name, packet_name] end packets.uniq! packets.each do |target_name, packet_name| (permission: 'tlm', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) end CvtModel.get_tlm_values(cvt_items, stale_time: stale_time, cache_timeout: cache_timeout, scope: scope) end |
#inject_tlm(target_name, packet_name, item_hash = nil, type: :CONVERTED, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Injects a packet into the system as if it was received from an interface
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/openc3/api/tlm_api.rb', line 122 def inject_tlm(target_name, packet_name, item_hash = nil, type: :CONVERTED, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) type = type.to_s.intern target_name = target_name.upcase packet_name = packet_name.upcase unless CvtModel::VALUE_TYPES.include?(type) raise "Unknown type '#{type}' for #{target_name} #{packet_name}" end if item_hash item_hash = item_hash.transform_keys(&:upcase) # Check that the items exist ... exceptions are raised if not TargetModel.packet_items(target_name, packet_name, item_hash.keys, scope: scope) else # Check that the packet exists ... exceptions are raised if not TargetModel.packet(target_name, packet_name, scope: scope) end # See if this target has a tlm interface interface_name = nil InterfaceModel.all(scope: scope).each do |_name, interface| if interface['tlm_target_names'].include? target_name interface_name = interface['name'] break end end # Use an interface microservice if it exists, other use the decom microservice if interface_name InterfaceTopic.inject_tlm(interface_name, target_name, packet_name, item_hash, type: type, scope: scope) else DecomInterfaceTopic.inject_tlm(target_name, packet_name, item_hash, type: type, scope: scope) end end |
#interface_cmd(interface_name, cmd_name, *cmd_params, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
150 151 152 153 154 |
# File 'lib/openc3/api/interface_api.rb', line 150 def interface_cmd(interface_name, cmd_name, *cmd_params, manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token) InterfaceTopic.interface_cmd(interface_name, cmd_name, *cmd_params, scope: scope) end |
#interface_protocol_cmd(interface_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1,, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
156 157 158 159 160 |
# File 'lib/openc3/api/interface_api.rb', line 156 def interface_protocol_cmd(interface_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1, manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token) InterfaceTopic.protocol_cmd(interface_name, cmd_name, *cmd_params, read_write: read_write, index: index, scope: scope) end |
#limits_enabled?(*args, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Boolean Also known as: limits_enabled
Whether the limits are enabled for the given item
Accepts two different calling styles:
limits_enabled?("TGT PKT ITEM")
limits_enabled?('TGT','PKT','ITEM')
Favor the first syntax where possible as it is more succinct.
111 112 113 114 115 |
# File 'lib/openc3/api/limits_api.rb', line 111 def limits_enabled?(*args, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name, item_name = _tlm_process_args(args, 'limits_enabled?', scope: scope) (permission: 'tlm', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) return TargetModel.packet_item(target_name, packet_name, item_name, scope: scope)['limits']['enabled'] ? true : false end |
#list_configs(tool, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
41 42 43 44 |
# File 'lib/openc3/api/config_api.rb', line 41 def list_configs(tool, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) ToolConfigModel.list_configs(tool, scope: scope) end |
#list_settings(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
37 38 39 40 |
# File 'lib/openc3/api/settings_api.rb', line 37 def list_settings(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) SettingModel.names(scope: scope) end |
#load_config(tool, name, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
46 47 48 49 |
# File 'lib/openc3/api/config_api.rb', line 46 def load_config(tool, name, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) ToolConfigModel.load_config(tool, name, scope: scope) end |
#map_target_to_interface(target_name, interface_name, cmd_only: false, tlm_only: false, unmap_old: true, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Associates a target and all its commands and telemetry with a particular interface. All the commands will go out over and telemetry be received from that interface.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/openc3/api/interface_api.rb', line 134 def map_target_to_interface(target_name, interface_name, cmd_only: false, tlm_only: false, unmap_old: true, manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token) new_interface = InterfaceModel.get_model(name: interface_name, scope: scope) if Array === target_name target_names = target_name else target_names = [target_name] end target_names.each do |name| new_interface.map_target(name, cmd_only: cmd_only, tlm_only: tlm_only, unmap_old: unmap_old) Logger.info("Target #{name} mapped to Interface #{interface_name}", scope: scope) end nil end |
#normalize_tlm(*args, type: :ALL, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Normalize a telemetry item in a packet to its default behavior. Called after override_tlm to restore standard processing.
Accepts two different calling styles:
normalize_tlm("TGT PKT ITEM")
normalize_tlm('TGT','PKT','ITEM')
Favor the first syntax where possible as it is more succinct.
196 197 198 199 200 |
# File 'lib/openc3/api/tlm_api.rb', line 196 def normalize_tlm(*args, type: :ALL, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name, item_name = _tlm_process_args(args, __method__, scope: scope) (permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) CvtModel.normalize(target_name, packet_name, item_name, type: type.intern, scope: scope) end |
#offline_access_needed(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/openc3/api/offline_access_api.rb', line 30 def offline_access_needed(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system', manual: manual, scope: scope, token: token) begin (permission: 'script_view', manual: manual, scope: scope, token: token) rescue # Not needed if can't run scripts return false end info = user_info(token) if info['roles'].to_s.include?("offline_access") username = info['username'] if username and username != '' model = OfflineAccessModel.get_model(name: username, scope: scope) if model and model.offline_access_token auth = OpenC3KeycloakAuthentication.new(ENV['OPENC3_KEYCLOAK_URL']) valid_token = auth.get_token_from_refresh_token(model.offline_access_token) if valid_token return false else model.offline_access_token = nil model.update return true end end return true else return false end else return false end end |
#override_tlm(*args, type: :ALL, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Override the current value table such that a particular item always returns the same value (for a given type) even when new telemetry packets are received from the target.
Accepts two different calling styles:
override_tlm("TGT PKT ITEM = 1.0")
override_tlm('TGT','PKT','ITEM', 10.0)
Favor the first syntax where possible as it is more succinct.
171 172 173 174 175 |
# File 'lib/openc3/api/tlm_api.rb', line 171 def override_tlm(*args, type: :ALL, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name, item_name, value = _set_tlm_process_args(args, __method__, scope: scope) (permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) CvtModel.override(target_name, packet_name, item_name, value, type: type.intern, scope: scope) end |
#router_cmd(router_name, cmd_name, *cmd_params, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
126 127 128 129 130 |
# File 'lib/openc3/api/router_api.rb', line 126 def router_cmd(router_name, cmd_name, *cmd_params, manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', router_name: router_name, manual: manual, scope: scope, token: token) RouterTopic.router_cmd(router_name, cmd_name, *cmd_params, scope: scope) end |
#router_protocol_cmd(router_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1,, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
132 133 134 135 136 |
# File 'lib/openc3/api/router_api.rb', line 132 def router_protocol_cmd(router_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1, manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', router_name: router_name, manual: manual, scope: scope, token: token) RouterTopic.protocol_cmd(router_name, cmd_name, *cmd_params, read_write: read_write, index: index, scope: scope) end |
#save_config(tool, name, data, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
51 52 53 54 |
# File 'lib/openc3/api/config_api.rb', line 51 def save_config(tool, name, data, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'system_set', manual: manual, scope: scope, token: token) ToolConfigModel.save_config(tool, name, data, scope: scope) end |
#send_raw(interface_name, data, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Send a raw binary string to the specified interface.
165 166 167 168 169 170 171 172 173 |
# File 'lib/openc3/api/cmd_api.rb', line 165 def send_raw(interface_name, data, manual: false, scope: $openc3_scope, token: $openc3_token) interface_name = interface_name.upcase interface = get_interface(interface_name, scope: scope, token: token) # Verify we have command authority on all the targets mapped to this interface interface['cmd_target_names'].each do |target_name| (permission: 'cmd_raw', interface_name: interface_name, target_name: target_name, manual: manual, scope: scope, token: token) end InterfaceTopic.write_raw(interface_name, data, scope: scope) end |
#set_limits(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low = nil, green_high = nil, limits_set = 'CUSTOM', persistence = nil, enabled = true, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Change the limits settings for a given item. By default, a new limits set called ‘CUSTOM’ is created to avoid overriding existing limits.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/openc3/api/limits_api.rb', line 208 def set_limits(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low = nil, green_high = nil, limits_set = 'CUSTOM', persistence = nil, enabled = true, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) if (red_low > yellow_low) || (yellow_low >= yellow_high) || (yellow_high > red_high) raise "Invalid limits specified. Ensure yellow limits are within red limits." end if (green_low && green_high) && ((yellow_low > green_low) || (green_low >= green_high) || (green_high > yellow_high)) raise "Invalid limits specified. Ensure green limits are within yellow limits." end packet = TargetModel.packet(target_name, packet_name, scope: scope) found_item = nil packet['items'].each do |item| if item['name'] == item_name if item['limits'] item['limits']['persistence_setting'] = persistence if persistence if enabled item['limits']['enabled'] = true else item['limits'].delete('enabled') end limits = {} limits['red_low'] = red_low limits['yellow_low'] = yellow_low limits['yellow_high'] = yellow_high limits['red_high'] = red_high limits['green_low'] = green_low if green_low && green_high limits['green_high'] = green_high if green_low && green_high item['limits'][limits_set] = limits found_item = item break else raise "Cannot set_limits on item without any limits" end end end raise "Item '#{target_name} #{packet_name} #{item_name}' does not exist" unless found_item = "Setting '#{target_name} #{packet_name} #{item_name}' limits to #{red_low} #{yellow_low} #{yellow_high} #{red_high}" << " #{green_low} #{green_high}" if green_low && green_high << " in set #{limits_set} with persistence #{persistence} as enabled #{enabled}" Logger.info(, scope: scope) TargetModel.set_packet(target_name, packet_name, packet, scope: scope) event = { type: :LIMITS_SETTINGS, target_name: target_name, packet_name: packet_name, item_name: item_name, red_low: red_low, yellow_low: yellow_low, yellow_high: yellow_high, red_high: red_high, green_low: green_low, green_high: green_high, limits_set: limits_set, persistence: persistence, enabled: enabled, time_nsec: Time.now.to_nsec_from_epoch, message: } LimitsEventTopic.write(event, scope: scope) end |
#set_limits_set(limits_set, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Changes the active limits set that applies to all telemetry
292 293 294 295 296 297 298 |
# File 'lib/openc3/api/limits_api.rb', line 292 def set_limits_set(limits_set, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'tlm_set', manual: manual, scope: scope, token: token) = "Setting Limits Set: #{limits_set}" Logger.info(, scope: scope) LimitsEventTopic.write({ type: :LIMITS_SET, set: limits_set.to_s, time_nsec: Time.now.to_nsec_from_epoch, message: }, scope: scope) end |
#set_offline_access(offline_access_token, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/openc3/api/offline_access_api.rb', line 63 def set_offline_access(offline_access_token, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'script_view', manual: manual, scope: scope, token: token) info = user_info(token) username = info['username'] raise "Invalid username" if not username or username == '' model = OfflineAccessModel.get_model(name: username, scope: scope) if model model.offline_access_token = offline_access_token model.update else model = OfflineAccessModel.new(name: username, offline_access_token: offline_access_token, scope: scope) model.create end end |
#set_setting(name, data, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object Also known as: save_setting
64 65 66 67 68 |
# File 'lib/openc3/api/settings_api.rb', line 64 def set_setting(name, data, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'admin', manual: manual, scope: scope, token: token) SettingModel.set({ name: name, data: data }, scope: scope) LocalMode.save_setting(scope, name, data) end |
#set_tlm(*args, type: :CONVERTED, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Set a telemetry item in the current value table.
Note: If this is done while OpenC3 is currently receiving telemetry, this value could get overwritten at any time. Thus this capability is best used for testing or for telemetry items that are not received regularly through the target interface.
Accepts two different calling styles:
set_tlm("TGT PKT ITEM = 1.0")
set_tlm('TGT','PKT','ITEM', 10.0)
Favor the first syntax where possible as it is more succinct.
110 111 112 113 114 |
# File 'lib/openc3/api/tlm_api.rb', line 110 def set_tlm(*args, type: :CONVERTED, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name, item_name, value = _set_tlm_process_args(args, __method__, scope: scope) (permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) CvtModel.set_item(target_name, packet_name, item_name, value, type: type.intern, scope: scope) end |
#start_raw_logging_interface(interface_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Starts raw logging for an interface
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/openc3/api/interface_api.rb', line 84 def start_raw_logging_interface(interface_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token) if interface_name == 'ALL' get_interface_names().each do |interface_name| InterfaceTopic.start_raw_logging(interface_name, scope: scope) end else InterfaceTopic.start_raw_logging(interface_name, scope: scope) end end |
#start_raw_logging_router(router_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Starts raw logging for a router
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/openc3/api/router_api.rb', line 82 def start_raw_logging_router(router_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', router_name: router_name, manual: manual, scope: scope, token: token) if router_name == 'ALL' get_router_names().each do |router_name| RouterTopic.start_raw_logging(router_name, scope: scope) end else RouterTopic.start_raw_logging(router_name, scope: scope) end end |
#stash_all(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
47 48 49 50 |
# File 'lib/openc3/api/stash_api.rb', line 47 def stash_all(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'script_view', manual: manual, scope: scope, token: token) StashModel.all(scope: scope).transform_values { |hash| JSON.parse(hash["value"], :allow_nan => true, :create_additions => true) } end |
#stash_delete(key, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
57 58 59 60 61 |
# File 'lib/openc3/api/stash_api.rb', line 57 def stash_delete(key, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'script_run', manual: manual, scope: scope, token: token) model = StashModel.get_model(name: key, scope: scope) model.destroy if model end |
#stash_get(key, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/openc3/api/stash_api.rb', line 37 def stash_get(key, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'script_view', manual: manual, scope: scope, token: token) result = StashModel.get(name: key, scope: scope) if result JSON.parse(result['value'], :allow_nan => true, :create_additions => true) else nil end end |
#stash_keys(manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
52 53 54 55 |
# File 'lib/openc3/api/stash_api.rb', line 52 def stash_keys(manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'script_view', manual: manual, scope: scope, token: token) StashModel.names(scope: scope) end |
#stash_set(key, value, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
32 33 34 35 |
# File 'lib/openc3/api/stash_api.rb', line 32 def stash_set(key, value, manual: false, scope: $openc3_scope, token: $openc3_token) (permission: 'script_run', manual: manual, scope: scope, token: token) StashModel.set( {name: key, value: JSON.generate(value.as_json(:allow_nan => true)) }, scope: scope) end |
#stop_raw_logging_interface(interface_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Stop raw logging for an interface
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/openc3/api/interface_api.rb', line 99 def stop_raw_logging_interface(interface_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token) if interface_name == 'ALL' get_interface_names().each do |interface_name| InterfaceTopic.stop_raw_logging(interface_name, scope: scope) end else InterfaceTopic.stop_raw_logging(interface_name, scope: scope) end end |
#stop_raw_logging_router(router_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Stop raw logging for a router
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/openc3/api/router_api.rb', line 97 def stop_raw_logging_router(router_name = 'ALL', manual: false, scope: $openc3_scope, token: $openc3_token) # TODO: Check if they have command authority for the targets mapped to this interface (permission: 'system_set', router_name: router_name, manual: manual, scope: scope, token: token) if router_name == 'ALL' get_router_names().each do |router_name| RouterTopic.stop_raw_logging(router_name, scope: scope) end else RouterTopic.stop_raw_logging(router_name, scope: scope) end end |
#subscribe_packets(packets, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ String Also known as: subscribe_packet
Subscribe to a list of packets. An ID is returned which is passed to get_packets(id) to return packets.
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/openc3/api/tlm_api.rb', line 342 def subscribe_packets(packets, manual: false, scope: $openc3_scope, token: $openc3_token) if !packets.is_a?(Array) || !packets[0].is_a?(Array) raise ArgumentError, "packets must be nested array: [['TGT','PKT'],...]" end result = {} packets.each do |target_name, packet_name| target_name = target_name.upcase packet_name = packet_name.upcase (permission: 'tlm', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) topic = "#{scope}__DECOM__{#{target_name}}__#{packet_name}" id, _ = Topic.(topic) result[topic] = id ? id : '0-0' end result.to_a.join(SUBSCRIPTION_DELIMITER) end |
#tlm(*args, type: :CONVERTED, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Request a telemetry item from a packet.
Accepts two different calling styles:
tlm("TGT PKT ITEM")
tlm('TGT','PKT','ITEM')
Favor the first syntax where possible as it is more succinct.
72 73 74 75 76 |
# File 'lib/openc3/api/tlm_api.rb', line 72 def tlm(*args, type: :CONVERTED, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) target_name, packet_name, item_name = _tlm_process_args(args, 'tlm', cache_timeout: cache_timeout, scope: scope) (permission: 'tlm', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token) CvtModel.get_item(target_name, packet_name, item_name, type: type.intern, cache_timeout: cache_timeout, scope: scope) end |
#tlm_formatted(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
82 83 84 |
# File 'lib/openc3/api/tlm_api.rb', line 82 def tlm_formatted(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) tlm(*args, type: :FORMATTED, cache_timeout: cache_timeout, manual: manual, scope: scope, token: token) end |
#tlm_raw(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
78 79 80 |
# File 'lib/openc3/api/tlm_api.rb', line 78 def tlm_raw(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) tlm(*args, type: :RAW, cache_timeout: cache_timeout, manual: manual, scope: scope, token: token) end |
#tlm_variable(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
Use tlm with type:
91 92 93 |
# File 'lib/openc3/api/tlm_api.rb', line 91 def tlm_variable(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) tlm(*args[0..-2], type: args[-1].intern, cache_timeout: cache_timeout, manual: manual, scope: scope, token: token) end |
#tlm_with_units(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) ⇒ Object
86 87 88 |
# File 'lib/openc3/api/tlm_api.rb', line 86 def tlm_with_units(*args, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token) tlm(*args, type: :WITH_UNITS, cache_timeout: cache_timeout, manual: manual, scope: scope, token: token) end |