Skip to content

Commit

Permalink
New Deployment generation feature (#123)
Browse files Browse the repository at this point in the history
* Use argparse mutually exclusive args

* Add cookiecutter templates

* clean up legacy code

* functional push

* overwrite option

* Move command processing to commands.py

* refactor utility_entry to cli.py

* lstrip path_to_fprime

* Hint --overwrite when directory exist

* help text

* rephrase short help text

* help text

* minor comment for readability

* template header guards

* address code scanning alert

* catch exception later up

* spelling

* formatting

* spelling again :(

* gotta love spelling
  • Loading branch information
thomas-bc authored Apr 4, 2023
1 parent 9e01914 commit 67a6e1d
Show file tree
Hide file tree
Showing 19 changed files with 1,363 additions and 349 deletions.
39 changes: 36 additions & 3 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
argc
atoi
bak
Callee
cargs
CDH
cexc
cfg
ci
Expand All @@ -13,19 +17,23 @@ configparser
configs
confparse
consts
contextmanager
contextlib
contextmanager
cookiecutter
COOLDOWN
cpp
CPython
css
cstdlib
ctor
cwd
CXX
datetime
dedent
deduplicated
deepcopy
Deframer
deframing
DEPS
deser
deserialization
Expand All @@ -42,12 +50,14 @@ dirone
dirs
distutils
doctest
Drv
dumpable
Dxyz
elif
endfor
endif
endswith
entrypoint
enum
excinfo
exe
Expand All @@ -64,8 +74,8 @@ filepath
firest
floordiv
FPGA
fprime
fpp
fprime
fromkeys
fromtimestamp
func
Expand All @@ -78,25 +88,30 @@ gcovr
genex
getattr
getcwd
getopt
gh
github
gtest
gui
hasattr
HJK
hostname
hpaulson
hpp
html
http
ifconfig
ifndef
impl
importlib
ini
inlined
intersphinx
isdir
isfile
isinstance
isnumeric
Isr
issubclass
iterdir
itertools
Expand All @@ -112,34 +127,45 @@ jsonable
kevin
kwargs
len
linux
lld
llvm
locs
lstrip
lxml
makedirs
malloc
mallocator
maxdepth
MEMB
memset
metadata
mkdir
mkdtemp
mstarch
mul
MULTILINE
Mutex
namespace
namespaced
nargs
nitpicky
normpath
nullptr
openpty
optarg
optionxform
oran
Packetizer
Paetz
params
pathlib
Peet
pexpect
Pkts
Popen
postprocessed
printf
proj
ptf
py
Expand All @@ -158,6 +184,7 @@ readline
README
readthedocs
recommonmark
recv
reder
Refactor
relpath
Expand All @@ -174,12 +201,15 @@ rsub
rtd
rtruediv
sanitizers
Sched
sched
SCLK
scm
sdd
setuptools
shutil
SIGINT
SIGTERM
sizeof
someotherpath
sphinxcontrib
splitlines
Expand All @@ -199,6 +229,7 @@ subparser
Subproc
sys
tcanham
Tcp
td
tempdir
tempfile
Expand All @@ -210,11 +241,13 @@ toctree
todo
toolchain
toolchains
TOPOLOGYDEFS
truediv
typehints
typename
tz
tzinfo
Udp
uint
Uncomment
undoc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"deployment_name": "MyDeployment",
"path_to_fprime": "./fprime",
"author_name": "",
"__deployment_name_upper": "{{cookiecutter.deployment_name.upper()}}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#####
# '{{cookiecutter.deployment_name}}' Deployment:
#
# This sets up the build for the '{{cookiecutter.deployment_name}}' Application, including custom
# components. In addition, it imports FPrime.cmake, which includes the core F Prime components.
#
#####

###
# Basic Project Setup
###
cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0048 NEW)
project({{cookiecutter.deployment_name}} VERSION 1.0.0 LANGUAGES C CXX)

###
# F' Core Setup
# This includes all of the F prime core components, and imports the make-system.
###
include("${FPRIME_FRAMEWORK_PATH}/cmake/FPrime.cmake")
# NOTE: register custom targets between these two lines
include("${FPRIME_FRAMEWORK_PATH}/cmake/FPrime-Code.cmake")

###
# Components and Topology
###
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Top/")

set(SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/Main.cpp")
set(MOD_DEPS ${PROJECT_NAME}/Top)

register_fprime_deployment()
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// ======================================================================
// \title Main.cpp
// \author {{cookiecutter.author_name}}
// \brief main program for the F' application. Intended for CLI-based systems (Linux, macOS)
//
// ======================================================================
// Used to access topology functions
#include <{{cookiecutter.deployment_name}}/Top/{{cookiecutter.deployment_name}}Topology.hpp>
// Used for signal handling shutdown
#include <signal.h>
// Used for command line argument processing
#include <getopt.h>
// Used for printf functions
#include <cstdlib>

/**
* \brief print command line help message
*
* This will print a command line help message including the available command line arguments.
*
* @param app: name of application
*/
void print_usage(const char* app) {
(void)printf("Usage: ./%s [options]\n-a\thostname/IP address\n-p\tport_number\n", app);
}

/**
* \brief shutdown topology cycling on signal
*
* The reference topology allows for a simulated cycling of the rate groups. This simulated cycling needs to be stopped
* in order for the program to shutdown. This is done via handling signals such that it is performed via Ctrl-C
*
* @param signum
*/
static void signalHandler(int signum) {
{{cookiecutter.deployment_name}}::stopSimulatedCycle();
}

/**
* \brief execute the program
*
* This F´ program is designed to run in standard environments (e.g. Linux/macOs running on a laptop). Thus it uses
* command line inputs to specify how to connect.
*
* @param argc: argument count supplied to program
* @param argv: argument values supplied to program
* @return: 0 on success, something else on failure
*/
int main(int argc, char* argv[]) {
U32 port_number = 0;
I32 option = 0;
char* hostname = nullptr;

// Loop while reading the getopt supplied options
while ((option = getopt(argc, argv, "hp:a:")) != -1) {
switch (option) {
// Handle the -a argument for address/hostname
case 'a':
hostname = optarg;
break;
// Handle the -p port number argument
case 'p':
port_number = static_cast<U32>(atoi(optarg));
break;
// Cascade intended: help output
case 'h':
// Cascade intended: help output
case '?':
// Default case: output help and exit
default:
print_usage(argv[0]);
return (option == 'h') ? 0 : 1;
}
}
// Object for communicating state to the reference topology
{{cookiecutter.deployment_name}}::TopologyState inputs;
inputs.hostname = hostname;
inputs.port = port_number;

// Setup program shutdown via Ctrl-C
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
(void)printf("Hit Ctrl-C to quit\n");

// Setup, cycle, and teardown topology
{{cookiecutter.deployment_name}}::setupTopology(inputs);
{{cookiecutter.deployment_name}}::startSimulatedCycle(1000); // Program loop cycling rate groups at 1Hz
{{cookiecutter.deployment_name}}::teardownTopology(inputs);
(void)printf("Exiting...\n");
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# {{cookiecutter.deployment_name}} Application

This deployment was auto-generated by the F' utility tool.

## Building and Running the {{cookiecutter.deployment_name}} Application

In order to build the {{cookiecutter.deployment_name}} application, or any other F´ application, we first need to generate a build directory. This can be done with the following commands:

```
cd {{cookiecutter.deployment_name}}
fprime-util generate
```

The next step is to build the {{cookiecutter.deployment_name}} application's code.
```
fprime-util build
```

## Running the application and F' GDS

The following command will spin up the F' GDS as well as run the application binary and the components necessary for the GDS and application to communicate.

```
cd {{cookiecutter.deployment_name}}
fprime-gds
```

To run the ground system without starting the {{cookiecutter.deployment_name}} app:
```
cd {{cookiecutter.deployment_name}}
fprime-gds --no-app
```

The application binary may then be run independently from the created 'bin' directory.

```
cd {{cookiecutter.deployment_name}}/build-artifacts/<platform>/bin/
./{{cookiecutter.deployment_name}} -a 127.0.0.1 -p 50000
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
####
# F prime CMakeLists.txt:
#
# SOURCE_FILES: combined list of source and autocoding files
# MOD_DEPS: (optional) module dependencies
####

set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/instances.fpp"
"${CMAKE_CURRENT_LIST_DIR}/{{cookiecutter.deployment_name}}Packets.xml"
"${CMAKE_CURRENT_LIST_DIR}/topology.fpp"
"${CMAKE_CURRENT_LIST_DIR}/{{cookiecutter.deployment_name}}Topology.cpp"
)
set(MOD_DEPS
Fw/Logger
Svc/LinuxTime
# Communication Implementations
Drv/Udp
Drv/TcpClient
)

register_fprime_module()
Loading

0 comments on commit 67a6e1d

Please sign in to comment.