Skip to content

Commit

Permalink
Merge pull request #1483 from OpenC3/pydocs
Browse files Browse the repository at this point in the history
Update docs with Python info
  • Loading branch information
ryanmelt authored Aug 17, 2024
2 parents 78a93ba + 24292c0 commit e78ec82
Show file tree
Hide file tree
Showing 126 changed files with 1,699 additions and 1,384 deletions.
2 changes: 1 addition & 1 deletion docs.openc3.com/docs/configuration/_telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ When defining telemetry items you can choose from the following data types: INT,

:::info Printing Data

Most data types can be printed in a COSMOS script simply by doing <code>puts tlm("TGT PKT ITEM")</code>. However, if the ITEM is a BLOCK data type and contains binary (non-ASCII) data then that won't work. COSMOS comes with a built-in method called <code>formatted</code> to help you view binary data. If ITEM is a BLOCK type containing binary try <code>puts tlm("TGT PKT ITEM").formatted</code> which will print the bytes out as hex.
Most data types can be printed in a COSMOS script simply by doing <code>print(tlm("TGT PKT ITEM"))</code>. However, if the ITEM is a BLOCK data type and contains binary (non-ASCII) data then that won't work. COSMOS comes with a built-in method called <code>formatted</code> to help you view binary data. If ITEM is a BLOCK type containing binary try <code>puts tlm("TGT PKT ITEM").formatted</code> (Ruby) and <code>print(formatted(tlm("TGT PKT ITEM")))</code> (Python) which will print the bytes out as hex.
:::

### ID Items
Expand Down
45 changes: 34 additions & 11 deletions docs.openc3.com/docs/configuration/command.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ APPEND_PARAMETER STRING 1024 STRING "NOOP" "String parameter"
#### WRITE_CONVERSION
**Applies a conversion when writing the current command parameter**

Conversions are implemented in a custom Ruby file which should be
located in the target's lib folder. The class must require 'openc3/conversions/conversion'
and inherit from Conversion. It must implement the initialize method if it
takes extra parameters and must always implement the call method. The conversion
Conversions are implemented in a custom Ruby or Python file which should be
located in the target's lib folder. The class must inherit from Conversion.
It must implement the `initialize` (Ruby) or `__init__` (Python) method if it
takes extra parameters and must always implement the `call` method. The conversion
factor is applied to the value entered by the user before it is written into
the binary command packet and sent.

Expand All @@ -223,10 +223,10 @@ values to the command. That can be used to check parameter values passed in.

| Parameter | Description | Required |
|-----------|-------------|----------|
| Class Filename | The filename which contains the Ruby class. The filename must be named after the class such that the class is a CamelCase version of the underscored filename. For example, 'the_great_conversion.rb' should contain 'class TheGreatConversion'. | True |
| Class Filename | The filename which contains the Ruby or Python class. The filename must be named after the class such that the class is a CamelCase version of the underscored filename. For example, 'the_great_conversion.rb' should contain 'class TheGreatConversion'. | True |
| Parameter | Additional parameter values for the conversion which are passed to the class constructor. | False |

Example Usage:
Ruby Example:
```ruby
WRITE_CONVERSION the_great_conversion.rb 1000

Expand All @@ -246,6 +246,21 @@ module OpenC3
end
```

Python Example:
```python
WRITE_CONVERSION the_great_conversion.py 1000

Defined in the_great_conversion.py:

from openc3.conversions.conversion import Conversion
class TheGreatConversion(Conversion):
def __init__(self, multiplier):
super().__init__()
self.multiplier = float(multiplier)
def call(self, value, packet, buffer):
return value * multiplier
```

#### POLY_WRITE_CONVERSION
**Adds a polynomial conversion factor to the current command parameter**

Expand Down Expand Up @@ -285,12 +300,12 @@ SEG_POLY_WRITE_CONVERSION 100 12 0.5 0.3 # Apply the conversion to all values >=
Adds a generic conversion function to the current command parameter.
This conversion factor is applied to the value entered by the user before it
is written into the binary command packet and sent. The conversion is specified
as ruby code that receives two implied parameters. 'value' which is the raw
as Ruby or Python code that receives two implied parameters. 'value' which is the raw
value being written and 'packet' which is a reference to the command packet
class (Note, referencing the packet as 'myself' is still supported for backwards
compatibility). The last line of ruby code given should return the converted
compatibility). The last line of code should return the converted
value. The GENERIC_WRITE_CONVERSION_END keyword specifies that all lines of
ruby code for the conversion have been given.
code for the conversion have been given.

:::info Multiple write conversions on command parameters
When a command is built, each item gets written (and write conversions are run)
Expand All @@ -307,11 +322,19 @@ Generic conversions are not a good long term solution. Consider creating a conve
:::


Example Usage:
Ruby Example:
```ruby
APPEND_PARAMETER ITEM1 32 UINT 0 0xFFFFFFFF 0
GENERIC_WRITE_CONVERSION_START
(value * 1.5).to_i # Convert the value by a scale factor
return (value * 1.5).to_i # Convert the value by a scale factor
GENERIC_WRITE_CONVERSION_END
```

Python Example:
```python
APPEND_PARAMETER ITEM1 32 UINT 0 0xFFFFFFFF 0
GENERIC_WRITE_CONVERSION_START
return int(value * 1.5) # Convert the value by a scale factor
GENERIC_WRITE_CONVERSION_END
```

Expand Down
55 changes: 44 additions & 11 deletions docs.openc3.com/docs/configuration/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ If the plugin has a top level lib folder or lists runtime dependencies in the ge
## INTERFACE
**Defines a connection to a physical target**

Interfaces are what OpenC3 uses to talk to a particular piece of hardware. Interfaces require a Ruby file which implements all the interface methods necessary to talk to the hardware. OpenC3 defines many built in interfaces or you can define your own as long as it implements the interface protocol.
Interfaces are what OpenC3 uses to talk to a particular piece of hardware. Interfaces require a Ruby or Python file which implements all the interface methods necessary to talk to the hardware. OpenC3 defines many built in interfaces or you can define your own as long as it implements the interface protocol.

| Parameter | Description | Required |
|-----------|-------------|----------|
| Interface Name | Name of the interface. This name will appear in the Interfaces tab of the Server and is also referenced by other keywords. The OpenC3 convention is to name interfaces after their targets with '_INT' appended to the name, e.g. INST_INT for the INST target. | True |
| Filename | Ruby file to use when instantiating the interface.<br/><br/>Valid Values: <span class="values">tcpip_client_interface.rb, tcpip_server_interface.rb, udp_interface.rb, serial_interface.rb</span> | True |
| Filename | Ruby or Python file to use when instantiating the interface.<br/><br/>Valid Values: <span class="values">tcpip_client_interface, tcpip_server_interface, udp_interface, serial_interface</span> | True |

Additional parameters are required. Please see the [Interfaces](../configuration/interfaces.md) documentation for more details.

Expand All @@ -83,38 +83,56 @@ The following keywords must follow a INTERFACE keyword.
|-----------|-------------|----------|
| Target Name | Target name to map to this interface | True |

Example Usage:
Ruby Example:
```ruby
INTERFACE DATA_INT tcpip_client_interface.rb host.docker.internal 8080 8081 10.0 nil BURST
MAP_TARGET DATA
```

Python Example:
```python
INTERFACE DATA_INT openc3/interfaces/tcpip_client_interface.py host.docker.internal 8080 8081 10.0 nil BURST
MAP_TARGET DATA
```

### MAP_CMD_TARGET
<div class="right">(Since 5.2.0)</div>**Maps a target name to an interface for commands only**

| Parameter | Description | Required |
|-----------|-------------|----------|
| Target Name | Command target name to map to this interface | True |

Example Usage:
Ruby Example:
```ruby
INTERFACE CMD_INT tcpip_client_interface.rb host.docker.internal 8080 8081 10.0 nil BURST
MAP_CMD_TARGET DATA # Only DATA commands go on the CMD_INT interface
```

Python Example:
```python
INTERFACE CMD_INT openc3/interfaces/tcpip_client_interface.py host.docker.internal 8080 8081 10.0 nil BURST
MAP_CMD_TARGET DATA # Only DATA commands go on the CMD_INT interface
```

### MAP_TLM_TARGET
<div class="right">(Since 5.2.0)</div>**Maps a target name to an interface for telemetry only**

| Parameter | Description | Required |
|-----------|-------------|----------|
| Target Name | Telemetry target name to map to this interface | True |

Example Usage:
Ruby Example:
```ruby
INTERFACE TLM_INT tcpip_client_interface.rb host.docker.internal 8080 8081 10.0 nil BURST
MAP_TLM_TARGET DATA # Only DATA telemetry received on TLM_INT interface
```

Python Example:
```python
INTERFACE TLM_INT openc3/interfaces/tcpip_client_interface.py host.docker.internal 8080 8081 10.0 nil BURST
MAP_TLM_TARGET DATA # Only DATA telemetry received on TLM_INT interface
```

### DONT_CONNECT
**Server will not automatically try to connect to the interface at startup**

Expand Down Expand Up @@ -169,16 +187,20 @@ Protocols can be either READ, WRITE, or READ_WRITE. READ protocols act on the da
| Parameter | Description | Required |
|-----------|-------------|----------|
| Type | Whether to apply the protocol on incoming data, outgoing data, or both<br/><br/>Valid Values: <span class="values">READ, WRITE, READ_WRITE</span> | True |
| Protocol Filename or Classname | Ruby filename or class name which implements the protocol | True |
| Protocol Filename or Classname | Ruby or Python filename or class name which implements the protocol | True |
| Protocol specific parameters | Additional parameters used by the protocol | False |

Example Usage:
Ruby Example:
```ruby
INTERFACE DATA_INT tcpip_client_interface.rb host.docker.internal 8080 8081 10.0 nil nil
MAP_TARGET DATA
# Rather than defining the LENGTH protocol on the INTERFACE line we define it here
PROTOCOL READ LengthProtocol 0 16 0 1 BIG_ENDIAN 4 0xBA5EBA11
INTERFACE DATA_INT tcpip_client_interface.rb host.docker.internal 8080 8081 10.0 nil BURST
```

Python Example:
```python
INTERFACE DATA_INT openc3/interfaces/tcpip_client_interface.py host.docker.internal 8080 8081 10.0 nil BURST
MAP_TARGET DATA
PROTOCOL READ IgnorePacketProtocol INST IMAGE # Drop all INST IMAGE packets
```
Expand Down Expand Up @@ -273,11 +295,16 @@ Command line to execute to run the microservice.
|-----------|-------------|----------|
| Args | One or more arguments to exec to run the microservice. | True |

Example Usage:
Ruby Example:
```ruby
CMD ruby interface_microservice.rb DEFAULT__INTERFACE__INT1
```

Python Example:
```python
CMD python interface_microservice.py DEFAULT__INTERFACE__INT1
```

### CONTAINER
<div class="right">(Since 5.7.0)</div>**Docker Container**

Expand Down Expand Up @@ -309,7 +336,7 @@ Creates an router which receives command packets from their remote clients and s
| Parameter | Description | Required |
|-----------|-------------|----------|
| Name | Name of the router | True |
| Filename | Ruby file to use when instantiating the interface.<br/><br/>Valid Values: <span class="values">tcpip_client_interface.rb, tcpip_server_interface.rb, udp_interface.rb, serial_interface.rb</span> | True |
| Filename | Ruby or Python file to use when instantiating the interface.<br/><br/>Valid Values: <span class="values">tcpip_client_interface, tcpip_server_interface, udp_interface, serial_interface</span> | True |

Additional parameters are required. Please see the [Interfaces](../configuration/interfaces.md) documentation for more details.

Expand Down Expand Up @@ -610,12 +637,18 @@ Command line to execute to run the microservice.
|-----------|-------------|----------|
| Args | One or more arguments to exec to run the microservice. | True |

Example Usage:
Ruby Example:
```ruby
MICROSERVICE EXAMPLE openc3-example
CMD ruby example_target.rb
```

Python Example:
```python
MICROSERVICE EXAMPLE openc3-example
CMD python example_target.py
```

### OPTION
**Pass an option to the microservice**

Expand Down
Loading

0 comments on commit e78ec82

Please sign in to comment.