Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ComDriver select for new deployments #159

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
argc
atoi
bak
baudrate
Callee
cargs
CDH
Expand Down Expand Up @@ -168,6 +169,7 @@ Pkts
Popen
postprocessed
printf
PRIu
proj
ptf
py
Expand Down Expand Up @@ -252,6 +254,7 @@ typehints
typename
tz
tzinfo
uart
Udp
uint
Uncomment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"deployment_name": "MyDeployment",
"com_driver_type": ["TcpClient", "TcpServer", "UART"],
"__deployment_name_upper": "{{cookiecutter.deployment_name.upper()}}",
"__prompts__": {
"deployment_name": "Deployment name"
"deployment_name": "Deployment name",
"com_driver_type": "Select communication driver type"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
* @param app: name of application
*/
void print_usage(const char* app) {
{%- if cookiecutter.com_driver_type == "UART" %}
(void)printf("Usage: ./%s [options]\n-b\tBaud rate\n-d\tUART Device\n", app);
{%- else %}
(void)printf("Usage: ./%s [options]\n-a\thostname/IP address\n-p\tport_number\n", app);
{%- endif %}
}

/**
Expand All @@ -46,21 +50,41 @@ static void signalHandler(int signum) {
* @return: 0 on success, something else on failure
*/
int main(int argc, char* argv[]) {
U32 port_number = 0;
I32 option = 0;
char* hostname = nullptr;
{%- if cookiecutter.com_driver_type == "UART" %}
CHAR* uart_device = nullptr;
U32 baud_rate = 0;
{%- else %}
CHAR* hostname = nullptr;
U16 port_number = 0;
{%- endif %}

// Loop while reading the getopt supplied options
{%- if cookiecutter.com_driver_type == "UART" %}
while ((option = getopt(argc, argv, "hb:d:")) != -1) {
{%- else %}
while ((option = getopt(argc, argv, "hp:a:")) != -1) {
{%- endif %}
switch (option) {
{%- if cookiecutter.com_driver_type == "UART" %}
// Handle the -b baud rate argument
case 'b':
baud_rate = static_cast<U32>(atoi(optarg));
break;
// Handle the -d device argument
case 'd':
uart_device = optarg;
break;
{%- else %}
// 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));
port_number = static_cast<U16>(atoi(optarg));
break;
{%- endif %}
// Cascade intended: help output
case 'h':
// Cascade intended: help output
Expand All @@ -73,8 +97,13 @@ int main(int argc, char* argv[]) {
}
// Object for communicating state to the reference topology
{{cookiecutter.deployment_name}}::TopologyState inputs;
{%- if cookiecutter.com_driver_type == "UART" %}
inputs.baudRate = baud_rate;
inputs.uartDevice = uart_device;
{%- else %}
inputs.hostname = hostname;
inputs.port = port_number;
{%- endif %}

// Setup program shutdown via Ctrl-C
signal(SIGINT, signalHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ set(MOD_DEPS
Svc/LinuxTime
# Communication Implementations
Drv/Udp
{%- if cookiecutter.com_driver_type == "TcpClient" %}
Drv/TcpClient
{%- elif cookiecutter.com_driver_type == "TcpServer" %}
Drv/TcpServer
{%- elif cookiecutter.com_driver_type == "UART" %}
Drv/LinuxUartDriver
{%- endif %}
)

register_fprime_module()
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,19 @@ module {{cookiecutter.deployment_name}} {
# Passive component instances
# ----------------------------------------------------------------------

@ Communications driver. May be swapped with other comm drivers like UART
@ Communications driver. May be swapped with other com drivers like UART or TCP
{%- if cookiecutter.com_driver_type == "UART" %}
instance comDriver: Drv.LinuxUartDriver base id 0x4000
{%- else %}
@ Note: Here we have TCP reliable uplink and UDP (low latency) downlink
instance comDriver: Drv.ByteStreamDriverModel base id 0x4000 \
{%- if cookiecutter.com_driver_type == "TcpServer" %}
type "Drv::TcpServer" \ # type specified to select implementor of ByteStreamDriverModel
at "../../Drv/TcpServer/TcpServer.hpp" # location of above implementor must also be specified
{%- elif cookiecutter.com_driver_type == "TcpClient" %}
type "Drv::TcpClient" \ # type specified to select implementor of ByteStreamDriverModel
at "../../Drv/TcpClient/TcpClient.hpp" # location of above implementor must also be specified
{%- endif -%}{% endif %}

instance framer: Svc.Framer base id 0x4100

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,9 @@

<ignore>
<channel name="cmdDisp.CommandErrors"/>
{%- if cookiecutter.com_driver_type == "UART" %}
<channel name="comDriver.BytesSent"/>
<channel name="comDriver.BytesRecv"/>
{%- endif %}
</ignore>
</packets>
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void configureTopology() {
deframer.setup(deframing);

// Note: Uncomment when using Svc:TlmPacketizer
//tlmSend.setPacketList({{cookiecutter.deployment_name}}PacketsPkts, {{cookiecutter.deployment_name}}PacketsIgnore, 1);
// tlmSend.setPacketList({{cookiecutter.deployment_name}}PacketsPkts, {{cookiecutter.deployment_name}}PacketsIgnore, 1);

// Events (highest-priority)
configurationTable.entries[0] = {.depth = 100, .priority = 0};
Expand Down Expand Up @@ -151,13 +151,29 @@ void setupTopology(const TopologyState& state) {
// loadParameters();
// Autocoded task kick-off (active components). Function provided by autocoder.
startTasks(state);
// Initialize socket client communication if and only if there is a valid specification
{%- if (cookiecutter.com_driver_type in ["TcpServer", "TcpClient"]) %}
// Initialize socket communication if and only if there is a valid specification
if (state.hostname != nullptr && state.port != 0) {
Os::TaskString name("ReceiveTask");
// Uplink is configured for receive so a socket task is started
comDriver.configure(state.hostname, state.port);
{%- if (cookiecutter.com_driver_type == "TcpServer") %}
comDriver.startup();
{%- endif %}
comDriver.startSocketTask(name, true, COMM_PRIORITY, Default::STACK_SIZE);
}
{%- elif cookiecutter.com_driver_type == "UART" %}
if (state.uartDevice != nullptr) {
Os::TaskString name("ReceiveTask");
// Uplink is configured for receive so a socket task is started
if (comDriver.open(state.uartDevice, static_cast<Drv::LinuxUartDriver::UartBaudRate>(state.baudRate),
Drv::LinuxUartDriver::NO_FLOW, Drv::LinuxUartDriver::PARITY_NONE, Svc::DeframerCfg::RING_BUFFER_SIZE)) {
comDriver.startReadThread(COMM_PRIORITY, Default::STACK_SIZE);
} else {
printf("Failed to open UART device %s at baud rate %" PRIu32 "\n", state.uartDevice, state.baudRate);
}
}
{%- endif %}
}

// Variables used for cycle simulation
Expand Down Expand Up @@ -192,8 +208,13 @@ void teardownTopology(const TopologyState& state) {
freeThreads(state);

// Other task clean-up.
{%- if cookiecutter.com_driver_type == "UART" %}
comDriver.quitReadThread();
(void)comDriver.join(nullptr);
{%- else %}
comDriver.stopSocketTask();
(void)comDriver.joinSocketTask(nullptr);
{%- endif %}

// Resource deallocation
cmdSeq.deallocateBuffer(mallocator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace {{cookiecutter.deployment_name}} {
* The state argument carries command line inputs used to setup the topology. For an explanation of the required type
* {{cookiecutter.deployment_name}}::TopologyState see: {{cookiecutter.deployment_name}}TopologyDefs.hpp.
*
* \param state: object shuttling CLI arguments (hostname, port) needed to construct the topology
* \param state: object shuttling CLI arguments (e.g. hostname/port, or UART baudrate) needed to construct the topology
*/
void setupTopology(const TopologyState& state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ namespace {{cookiecutter.deployment_name}} {
* \brief required type definition to carry state
*
* The topology autocoder requires an object that carries state with the name `{{cookiecutter.deployment_name}}::TopologyState`. Only the type
* definition is required by the autocoder and the contents of this object are otherwise opaque to the autocoder. The
* contents are entirely up to the definition of the project. This reference application specifies hostname and port
* fields, which are derived by command line inputs.
* definition is required by the autocoder and the contents of this object are otherwise opaque to the autocoder. The contents are entirely up
* to the definition of the project. Here, they are derived from command line inputs.
*/
struct TopologyState {
const char* hostname;
U32 port;
{%- if (cookiecutter.com_driver_type == "UART") %}
const CHAR* uartDevice;
U32 baudRate;
{%- else %}
const CHAR* hostname;
U16 port;
{%- endif %}
};

/**
Expand Down
Loading