-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Jbsco/main
Implementing COSMOS support
- Loading branch information
Showing
17 changed files
with
514 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# Configure cosmos plugin | ||
# | ||
|
||
assembly_dir=$1 | ||
# Build all cosmos plugin command and telemetry files: | ||
cd $assembly_dir | ||
plugin=`redo what 2>&1 | grep "cosmos" | awk '{ print $2 }'` | ||
echo $plugin | xargs redo-ifchange | ||
cd - >/dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copy COSMOS plugin configuration from Adamant into COSMOS plugin directory | ||
# Ex. `./install_cosmos_plugin.sh ../../src/assembly/linux/linux_example.assembly.yaml ../../../cosmos-project` if COSMOS is adjacent to adamant_example | ||
|
||
adamant_assembly_model=$1 # path to assembly yaml file | ||
cosmos_plugin_dir=$2 # path to COSMOS plugin within the COSMOS installation | ||
|
||
if [[ $1 == "" ]] | ||
then | ||
echo "Adamant assembly model argument not provided." | ||
echo "Usage: \"./install_cosmos_plugin.sh ../../src/assembly/linux/linux_example.assembly.yaml ../../../cosmos-project/openc3-cosmos-plugin-dir\"" | ||
echo "Exiting." | ||
exit 1 | ||
elif [[ $2 == "" ]] | ||
then | ||
echo "COSMOS plugin directory argument not provided." | ||
echo "Usage: \"./install_cosmos_plugin.sh ../../src/assembly/linux/linux_example.assembly.yaml ../../../cosmos-project/openc3-cosmos-plugin-dir\"" | ||
echo "Exiting." | ||
exit 1 | ||
fi | ||
|
||
this_dir=`readlink -f "${BASH_SOURCE[0]}" | xargs dirname` | ||
adamant_assembly_name=${adamant_assembly_model%.assembly.yaml} | ||
adamant_assembly_name=${adamant_assembly_name##*/} | ||
adamant_assembly_dir=`dirname $adamant_assembly_model` | ||
cosmos_plugin_dir=`realpath $cosmos_plugin_dir` | ||
|
||
# Get build directory: | ||
adamant_assembly_name_short=(${adamant_assembly_name//_/ }) | ||
adamant_assembly_name_upper=$(tr [:lower:] [:upper:] <<< "$adamant_assembly_name") | ||
adamant_assembly_cmdtlm_dir=`realpath $adamant_assembly_dir/build/cosmos/plugin` | ||
adamant_assembly_plugin_dir=`realpath $adamant_assembly_dir/main/cosmos/plugin` | ||
adamant_protocol_dir=`realpath $this_dir/../../../adamant/gnd/cosmos` | ||
|
||
# Copy all protocol files (plugins compile with only needed protocols): | ||
echo "Copying over plugin files..." | ||
cp -vfa $adamant_protocol_dir/*.rb $cosmos_plugin_dir/targets/$adamant_assembly_name_upper/lib/ | ||
|
||
do_copy() { | ||
src=$1 | ||
dest=$2 | ||
if [[ -f "$src" ]]; then | ||
cp -vf "$src" "$dest" | ||
else | ||
echo "\"$src\" does not exist, run \"redo cosmos_config\" from the Adamant assembly, or make sure the required source is present." | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Copy plugin configuration files with error checking: | ||
do_copy "$adamant_assembly_cmdtlm_dir/${adamant_assembly_name}_ccsds_cosmos_commands.txt" $cosmos_plugin_dir/targets/$adamant_assembly_name_upper/cmd_tlm/cmd.txt | ||
do_copy "$adamant_assembly_cmdtlm_dir/${adamant_assembly_name}_ccsds_cosmos_telemetry.txt" $cosmos_plugin_dir/targets/$adamant_assembly_name_upper/cmd_tlm/tlm.txt | ||
do_copy "$adamant_assembly_plugin_dir/plugin.txt" $cosmos_plugin_dir/plugin.txt | ||
echo "Success." | ||
echo "Plugin files copied to $cosmos_plugin_dir." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import socket | ||
import threading | ||
import binascii | ||
import serial | ||
|
||
SYNC_PATTERN = bytearray([0xFE, 0xD4, 0xAF, 0xEE]) # Byte pattern for syncing | ||
|
||
|
||
def setup_serial(tty, baudrate): | ||
seri = serial.Serial(tty, baudrate) | ||
return seri | ||
|
||
|
||
def recv_from_serial(seri, sock, stop_event): | ||
first_time = True | ||
buffer = bytearray() | ||
while not stop_event.is_set(): | ||
if seri.in_waiting: | ||
# read all available bytes | ||
data = seri.read(seri.in_waiting) | ||
buffer.extend(data) | ||
|
||
# find sync pattern index | ||
sync_idx = buffer.find(SYNC_PATTERN) | ||
|
||
# if we found the sync pattern in the buffer | ||
while sync_idx != -1: | ||
# exclude the first iteration | ||
if sync_idx != 0: | ||
|
||
if not first_time: | ||
# before the sync pattern is the data | ||
print("tlm: " + str(binascii.hexlify(buffer[:sync_idx]))) | ||
sock.sendall(buffer[:sync_idx]) | ||
else: | ||
first_time = False | ||
# remove processed bytes (including sync pattern) | ||
buffer = buffer[sync_idx + len(SYNC_PATTERN):] | ||
# try to find the next sync pattern | ||
sync_idx = buffer.find(SYNC_PATTERN) | ||
|
||
|
||
def send_to_serial(seri, sock, stop_event): | ||
while not stop_event.is_set(): | ||
data = sock.recv(2048) | ||
if data: | ||
# prepend sync pattern and write to serial port | ||
print("cmd: " + str(binascii.hexlify(data))) | ||
seri.write(SYNC_PATTERN + data) | ||
|
||
|
||
def main(args): | ||
# Setup serial connection | ||
seri = setup_serial(args.tty, args.baudrate) | ||
# Setup TCP/IP connection | ||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
sock.connect((args.ip, args.port)) | ||
|
||
# Event to signal the threads to stop | ||
stop_event = threading.Event() | ||
|
||
# Create and start threads | ||
recv_thread = threading.Thread( | ||
target=recv_from_serial, args=(seri, sock, stop_event) | ||
) | ||
send_thread = threading.Thread(target=send_to_serial, args=(seri, sock, stop_event)) | ||
recv_thread.start() | ||
send_thread.start() | ||
|
||
try: | ||
# Wait for both threads to finish | ||
recv_thread.join() | ||
send_thread.join() | ||
except KeyboardInterrupt: | ||
# When Ctrl+C is pressed, signal the threads to stop | ||
stop_event.set() | ||
recv_thread.join() | ||
send_thread.join() | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
description="Bridge between serial device and TCP, using CCSDS 32-bit sync pattern as a delimiter over serial." | ||
) | ||
parser.add_argument("--tty", help="Path to the tty device.", required=True) | ||
parser.add_argument("--baudrate", help="The baud rate.", required=True, type=int) | ||
parser.add_argument("--ip", help="The IP address to connect to.", required=True) | ||
parser.add_argument( | ||
"--port", help="The port to connect to.", required=True, type=int | ||
) | ||
|
||
args = parser.parse_args() | ||
main(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# COSMOS interface documentation is available at: https://docs.openc3.com/docs/configuration/interfaces | ||
# Set variables here to allow variation in your plugin. | ||
# Variables are able to be modified at time of install in COSMOS. | ||
Variable linux_example_target_name Linux_Example | ||
Variable crc_parameter_name CRC | ||
Variable checksum_parameter_name Checksum | ||
Variable port_w 2003 | ||
Variable port_r 2003 | ||
|
||
Target Linux_Example <%= linux_example_target_name %> | ||
# TCP example interface: | ||
Interface <%= linux_example_target_name %>_INT tcpip_server_interface.rb <%= port_w %> <%= port_r %> 10.0 nil Length 32 16 7 | ||
Map_Target <%= linux_example_target_name %> | ||
Protocol Read crc_protocol.rb <%= crc_parameter_name %> false "ERROR" -16 16 | ||
Protocol Write cmd_checksum.rb <%= checksum_parameter_name %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Create Cosmos plugin configuration files: | ||
export TARGET= | ||
this_dir=`dirname "$0"` | ||
cosmos_dir=`realpath $this_dir/../../../../gnd/cosmos` | ||
assembly_dir=`realpath $this_dir/..` | ||
$cosmos_dir/build_cosmos_plugin.sh $assembly_dir >/dev/null |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
if [[ $1 == "" ]] | ||
then | ||
echo "COSMOS plugin directory path not provided." | ||
echo "Usage: \"./install_cosmos_plugin.sh ../../../../../cosmos-project/openc3-cosmos-linux-example/\"" | ||
echo "Exiting." | ||
exit 1 | ||
fi | ||
|
||
cosmos_dir=$1 | ||
this_dir=`readlink -f "${BASH_SOURCE[0]}" | xargs dirname` | ||
assembly_yaml=`ls -1 $this_dir/../*.assembly.yaml` | ||
$this_dir/../../../../gnd/cosmos/install_cosmos_plugin.sh $assembly_yaml $cosmos_dir |
Oops, something went wrong.