Skip to content

Commit

Permalink
Cleanup cmd apis
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Dec 10, 2023
1 parent 6bf1244 commit 1962b9f
Show file tree
Hide file tree
Showing 18 changed files with 270 additions and 151 deletions.
50 changes: 25 additions & 25 deletions docs.openc3.com/docs/guides/scripting-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ The following API methods are either deprecated (will not be ported to COSMOS 5)
| get_all_packet_logger_info | Command and Telemetry Server | Deprecated |
| get_all_target_info | Command and Telemetry Server | Deprecated, use get_target_interfaces |
| get_background_tasks | Command and Telemetry Server | Deprecated |
| get_all_cmd_info | Command and Telemetry Server | Deprecated, use get_all_commands |
| get_all_cmd_info | Command and Telemetry Server | Deprecated, use get_all_cmds |
| get_all_tlm_info | Command and Telemetry Server | Deprecated, use get_all_telemetry |
| get_cmd_list | Command and Telemetry Server | Deprecated, use get_all_commands |
| get_cmd_list | Command and Telemetry Server | Deprecated, use get_all_cmds |
| get_cmd_log_filename | Command and Telemetry Server | Deprecated |
| get_cmd_param_list | Command and Telemetry Server | Deprecated, use get_command |
| get_cmd_param_list | Command and Telemetry Server | Deprecated, use get_cmd |
| get_cmd_tlm_disconnect | Script Runner | Deprecated, use $disconnect |
| get_disconnected_targets | Script Runner | Unimplemented |
| get_interface_info | Command and Telemetry Server | Deprecated, use get_interface |
Expand Down Expand Up @@ -756,20 +756,20 @@ cmd_raw_no_checks("INST COLLECT with DURATION 11, TYPE 1")
cmd_raw_no_checks("INST", "COLLECT", {"DURATION": 11, "TYPE": 1})
```

### build_command (since 5.8.0)
### build_cmd (since 5.13.0, since 5.8.0 as build_command)

Builds a command binary string

Ruby Syntax:

```ruby
build_command(<ARGS>, range_check: true, raw: false)
build_cmd(<ARGS>, range_check: true, raw: false)
```

Python Syntax:

```python
build_command(<ARGS>, range_check=True, raw=False)
build_cmd(<ARGS>, range_check=True, raw=False)
```

| Parameter | Description |
Expand All @@ -781,14 +781,14 @@ build_command(<ARGS>, range_check=True, raw=False)
Ruby Example:

```ruby
x = build_command("INST COLLECT with DURATION 10, TYPE NORMAL")
x = build_cmd("INST COLLECT with DURATION 10, TYPE NORMAL")
puts x #=> {"id"=>"1696437370872-0", "result"=>"SUCCESS", "time"=>"1696437370872305961", "received_time"=>"1696437370872305961", "target_name"=>"INST", "packet_name"=>"COLLECT", "received_count"=>"3", "buffer"=>"\x13\xE7\xC0\x00\x00\f\x00\x01\x00\x00A \x00\x00\xAB\x00\x00\x00\x00"}
```

Python Example:

```python
x = build_command("INST COLLECT with DURATION 10, TYPE NORMAL")
x = build_cmd("INST COLLECT with DURATION 10, TYPE NORMAL")
print(x) #=> {'id': '1697298167748-0', 'result': 'SUCCESS', 'time': '1697298167749155717', 'received_time': '1697298167749155717', 'target_name': 'INST', 'packet_name': 'COLLECT', 'received_count': '2', 'buffer': bytearray(b'\x13\xe7\xc0\x00\x00\x0c\x00\x01\x00\x00A \x00\x00\xab\x00\x00\x00\x00')}
```

Expand All @@ -813,14 +813,14 @@ Ruby / Python Example:
send_raw("INST_INT", data)
```

### get_all_commands (since 5.0.0)
### get_all_cmds (since 5.13.0, since 5.0.0 as get_all_commands)

Returns an array of the commands that are available for a particular target. The returned array is an array of hashes which fully describe the command packet.

Ruby / Python Syntax:

```ruby
get_all_commands("<Target Name>")
get_all_cmds("<Target Name>")
```

| Parameter | Description |
Expand All @@ -830,7 +830,7 @@ get_all_commands("<Target Name>")
Ruby Example:

```ruby
cmd_list = get_all_commands("INST")
cmd_list = get_all_cmds("INST")
puts cmd_list #=>
# [{"target_name"=>"INST",
# "packet_name"=>"ABORT",
Expand All @@ -844,7 +844,7 @@ puts cmd_list #=>
Python Example:

```python
cmd_list = get_all_commands("INST")
cmd_list = get_all_cmds("INST")
print(cmd_list) #=>
# [{'target_name': 'INST',
# 'packet_name': 'ABORT',
Expand All @@ -855,14 +855,14 @@ print(cmd_list) #=>
# }]
```

### get_all_command_names (since 5.0.6)
### get_all_cmd_names (since 5.13.0, since 5.0.6 as get_all_command_names)

Returns an array of the command names for a particular target.

Ruby / Python Syntax:

```ruby
get_all_command_names("<Target Name>")
get_all_cmd_names("<Target Name>")
```

| Parameter | Description |
Expand All @@ -872,25 +872,25 @@ get_all_command_names("<Target Name>")
Ruby Example:

```ruby
cmd_list = get_all_command_names("INST")
cmd_list = get_all_cmd_names("INST")
puts cmd_list #=> ['ABORT', 'ARYCMD', 'ASCIICMD', ...]
```

Python Example:

```python
cmd_list = get_all_command_names("INST")
cmd_list = get_all_cmd_names("INST")
print(cmd_list) #=> ['ABORT', 'ARYCMD', 'ASCIICMD', ...]
```

### get_command (since 5.0.0)
### get_cmd (since 5.13.0, since 5.0.0 as get_command)

Returns a command hash which fully describes the command packet.

Ruby / Python Syntax:

```ruby
get_command("<Target Name>", "<Packet Name>")
get_cmd("<Target Name>", "<Packet Name>")
```

| Parameter | Description |
Expand All @@ -901,7 +901,7 @@ get_command("<Target Name>", "<Packet Name>")
Ruby / Python Example:

```ruby
abort_cmd = get_command("INST", "ABORT")
abort_cmd = get_cmd("INST", "ABORT")
puts abort_cmd #=>
# [{"target_name"=>"INST",
# "packet_name"=>"ABORT",
Expand All @@ -915,7 +915,7 @@ puts abort_cmd #=>
Python Example:

```python
abort_cmd = get_command("INST")
abort_cmd = get_cmd("INST")
print(abort_cmd) #=>
# [{'target_name': 'INST',
# 'packet_name': 'ABORT',
Expand All @@ -926,14 +926,14 @@ print(abort_cmd) #=>
# }]
```

### get_parameter (since 5.0.0)
### get_param (since 5.13.0, since 5.0.0 as get_parameter)

Returns a hash of the given command parameter

Ruby / Python Syntax:

```ruby
get_parameter("<Target Name>", "<Command Name>", "<Parameter Name>")
get_param("<Target Name>", "<Command Name>", "<Parameter Name>")
```

| Parameter | Description |
Expand All @@ -945,7 +945,7 @@ get_parameter("<Target Name>", "<Command Name>", "<Parameter Name>")
Ruby Example:

```ruby
param = get_parameter("INST", "COLLECT", "TYPE")
param = get_param("INST", "COLLECT", "TYPE")
puts param #=>
# {"name"=>"TYPE", "bit_offset"=>64, "bit_size"=>16, "data_type"=>"UINT",
# "description"=>"Collect type which can be normal or special", "default"=>0,
Expand All @@ -956,7 +956,7 @@ puts param #=>
Python Example:

```python
param = get_parameter("INST", "COLLECT", "TYPE")
param = get_param("INST", "COLLECT", "TYPE")
print(param) #=>
# {'name': 'TYPE', 'bit_offset': 64, 'bit_size': 16, 'data_type': 'UINT',
# 'description': 'Collect type which can be normal or special', 'default': 0,
Expand All @@ -966,7 +966,7 @@ print(param) #=>

### get_cmd_buffer

Returns a packet hash (similar to get_command) along with the raw packet buffer as a Ruby string.
Returns a packet hash (similar to get_cmd) along with the raw packet buffer as a Ruby string.

Ruby / Python Syntax:

Expand Down
2 changes: 0 additions & 2 deletions examples/external_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

puts get_target_names()

puts get_all_target_info()

puts tlm('INST ADCS POSX')

puts cmd("INST ABORT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@
send_raw("INT1", "\x00\x00")
send_raw("INT1", "\x00\x00", "\x00\x00")

# get_all_commands
# get_all_cmds
expected_cmds = %w(ABORT ARYCMD ASCIICMD CLEAR COLLECT FLTCMD SETPARAMS SLRPNLDEPLOY SLRPNLRESET)
commands = get_all_commands("INST")
commands = get_all_cmds("INST")
puts commands.inspect

# get_all_commands should fail
get_all_commands()
get_all_commands("BOB")
get_all_commands("BOB", "TED")
# get_all_cmds should fail
get_all_cmds()
get_all_cmds("BOB")
get_all_cmds("BOB", "TED")

# get_cmd_hazardous
hazardous = get_cmd_hazardous("INST", "COLLECT", "TYPE" => "SPECIAL")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export default {
.then(
(target) => {
this.ignoredParams = target.ignored_parameters
return this.api.get_command(this.targetName, this.commandName)
return this.api.get_cmd(this.targetName, this.commandName)
},
(error) => {
this.displayError('getting ignored parameters', error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default {
created() {
this.api.get_target_names().then((targets) => {
targets.map((target) => {
this.api.get_all_command_names(target).then((names) => {
this.api.get_all_cmd_names(target).then((names) => {
this.data = this.data.concat(
names.map((packet) => {
return { target_name: target, packet_name: packet, count: 0 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default {
this.ignoredItems = target.ignored_items
})
// TODO: Test with large DB as this returns ALL commands
this.api.get_all_commands(this.target).then((packets) => {
this.api.get_all_cmds(this.target).then((packets) => {
this.commands = packets
})
this.api.get_all_telemetry(this.target).then((packets) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default class MnemonicChecker {
if (!this.targets[target][cmdOrTlm]) {
const method = lineObj.mnemonic.item
? 'get_all_telemetry'
: 'get_all_commands'
: 'get_all_cmds'
const response = await this.api[method](target)
this.targets[target][cmdOrTlm] = response.reduce(
(result, packetInfo) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,7 @@ export default {
}
this.internalDisabled = true
const cmd =
this.mode === 'tlm'
? 'get_all_telemetry_names'
: 'get_all_command_names'
this.mode === 'tlm' ? 'get_all_telemetry_names' : 'get_all_cmd_names'
this.api[cmd](this.selectedTargetName).then((names) => {
this.packetNames = names.map((name) => {
return {
Expand Down Expand Up @@ -339,7 +337,7 @@ export default {
return
}
this.internalDisabled = true
const cmd = this.mode === 'tlm' ? 'get_telemetry' : 'get_command'
const cmd = this.mode === 'tlm' ? 'get_telemetry' : 'get_cmd'
this.api[cmd](this.selectedTargetName, this.selectedPacketName).then(
(packet) => {
this.itemNames = packet.items
Expand Down Expand Up @@ -420,7 +418,7 @@ export default {
return value === packet.value
})
this.selectedPacketName = packet.value
const cmd = this.mode === 'tlm' ? 'get_telemetry' : 'get_command'
const cmd = this.mode === 'tlm' ? 'get_telemetry' : 'get_cmd'
this.api[cmd](this.selectedTargetName, this.selectedPacketName).then(
(packet) => {
this.description = packet.description
Expand Down Expand Up @@ -486,7 +484,7 @@ export default {
allTargetPacketItems: function () {
this.packetNames.forEach((packetName) => {
if (packetName === this.ALL) return
const cmd = this.mode === 'tlm' ? 'get_telemetry' : 'get_command'
const cmd = this.mode === 'tlm' ? 'get_telemetry' : 'get_cmd'
this.api[cmd](this.selectedTargetName, packetName.value).then(
(packet) => {
packet.items.forEach((item) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ export class OpenC3Api {
return this.exec('get_item', [target, packet, item])
}

get_param(target, packet, item) {
return this.exec('get_param', [target, packet, item])
}
// DEPRECATED for get_param
get_parameter(target, packet, item) {
return this.exec('get_parameter', [target, packet, item])
}
Expand Down Expand Up @@ -363,14 +367,26 @@ export class OpenC3Api {
})
}

get_all_cmds(target_name) {
return this.exec('get_all_cmds', [target_name])
}
// DEPRECATED for get_all_cmds
get_all_commands(target_name) {
return this.exec('get_all_commands', [target_name])
}

get_all_cmd_names(target_name) {
return this.exec('get_all_cmd_names', [target_name])
}
// DEPRECATED for get_all_cmd_names
get_all_command_names(target_name) {
return this.exec('get_all_command_names', [target_name])
}

get_cmd(target_name, command_name) {
return this.exec('get_cmd', [target_name, command_name])
}
// DEPRECATED for get_cmd
get_command(target_name, command_name) {
return this.exec('get_command', [target_name, command_name])
}
Expand Down Expand Up @@ -524,6 +540,14 @@ export class OpenC3Api {
}
}

build_cmd(target_name, command_name, param_list) {
if (command_name === undefined) {
return this.exec('build_cmd', target_name)
} else {
return this._cmd('build_cmd', target_name, command_name, param_list)
}
}
// DEPRECATED for build_cmd
build_command(target_name, command_name, param_list) {
if (command_name === undefined) {
return this.exec('build_command', target_name)
Expand Down
Loading

0 comments on commit 1962b9f

Please sign in to comment.