F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Main.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Main.cpp
3 // \author mstarch
4 // \brief main program for reference application. Intended for CLI-based systems (Linux, macOS)
5 //
6 // \copyright
7 // Copyright 2009-2022, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 // ======================================================================
11 // Used to access topology functions
12 #include <Ref/Top/RefTopology.hpp>
13 // Used for signal handling shutdown
14 #include <signal.h>
15 // Used for command line argument processing
16 #include <getopt.h>
17 // Used for atoi
18 #include <cstdlib>
19 // Used to get the Os::Console
20 #include <Os/Os.hpp>
21 // Used for logging to the console
22 #include <Fw/Logger/Logger.hpp>
23 
31 void print_usage(const char* app) {
32  Fw::Logger::log("Usage: ./%s [options]\n-a\thostname/IP address\n-p\tport_number\n", app);
33 }
34 
43 static void signalHandler(int signum) {
45 }
46 
57 int main(int argc, char* argv[]) {
58  Os::init();
59  U16 port_number = 0;
60  I32 option = 0;
61  char* hostname = nullptr;
62 
63  // Loop while reading the getopt supplied options
64  while ((option = getopt(argc, argv, "hp:a:")) != -1) {
65  switch (option) {
66  // Handle the -a argument for address/hostname
67  case 'a':
68  hostname = optarg;
69  break;
70  // Handle the -p port number argument
71  case 'p':
72  port_number = static_cast<U16>(atoi(optarg));
73  break;
74  // Cascade intended: help output
75  case 'h':
76  // Cascade intended: help output
77  case '?':
78  // Default case: output help and exit
79  default:
80  print_usage(argv[0]);
81  return (option == 'h') ? 0 : 1;
82  }
83  }
84  // Object for communicating state to the reference topology
85  Ref::TopologyState inputs;
86  inputs.hostname = hostname;
87  inputs.port = port_number;
88 
89  // Setup program shutdown via Ctrl-C
90  signal(SIGINT, signalHandler);
91  signal(SIGTERM, signalHandler);
92  Fw::Logger::log("Hit Ctrl-C to quit\n");
93 
94  // Setup, cycle, and teardown topology
95  Ref::setupTopology(inputs);
96  Ref::startRateGroups(Fw::TimeInterval(1, 0)); // Program loop cycling rate groups at 1Hz
97  Ref::teardownTopology(inputs);
98  Fw::Logger::log("Exiting...\n");
99  return 0;
100 }
static void log(const char *format,...)
log a formated string with supplied arguments
Definition: Logger.cpp:21
void startRateGroups(const Fw::TimeInterval &interval)
cycle the rate group driver based in a system timer
Definition: RefTopology.cpp:87
required type definition to carry state
void teardownTopology(const TopologyState &state)
teardown the F´ topology
Definition: RefTopology.cpp:99
int main(int argc, char *argv[])
execute the program
Definition: Main.cpp:57
U16 port
Port for TCP communication.
const char * hostname
Hostname for TCP communication.
void init()
Initialize the OS Abstraction Layer (OSAL)
Definition: Os.cpp:15
static void signalHandler(int signum)
shutdown topology cycling on signal
Definition: Main.cpp:43
void stopRateGroups()
stop the rate groups
Definition: RefTopology.cpp:95
void setupTopology(const TopologyState &state)
initialize and run the F´ topology
Definition: RefTopology.cpp:60
void print_usage(const char *app)
print commandline help message
Definition: Main.cpp:31