Files
fprime/RPI/Main.cpp
Thomas Boyer-Chammard 564cb5773b Add Os::RawTime OSAL implementation, refactor Os::IntervalTimer (#2923)
* Add Os::RawTime and preliminary rule-based tests

* Implement Stubs and stub tests tests + misc improvements

* Update delay functions to use Fw::TimeInterval instead of Fw::Time

* Replace TimerVal with Os::RawTime FPP type, SERIALIZED_SIZE fixed to 2*sizeof(U32)

* Fix spelling and legacy code

* Fix test import

* Remove TimerVal files and misc clean up

* Add Fw/Time as dependency of Os module

* Fix include guards

* Fix default constructors and missing getHandle stub

* Add Handle and Serialization size to FpConfig, refactor interface for less vtable calls, refactor IntervalTimer

* Fixes for new OS CMake API

* Add RawTime FPP Model

* Rename getRawTime to now(), better error handling, added docs for all functions

* Correct handle size, spelling, and more robust test IntervalTimer test

* Peer review changes

* Move `Os.RawTime` to `Os/Types.fpp`

* Fix unused variable

* Fix spelling and comments

* spelling extravaganza

* Update metadata

check-spelling run (pull_request_target) for os-interval-timer

Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com>
on-behalf-of: @check-spelling <check-spelling-bot@check-spelling.dev>

* Reference based approach to minuend and subtrahend

---------

Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com>
Co-authored-by: Thomas Boyer-Chammard <thomas-bc@users.noreply.github.com>
Co-authored-by: M Starch <LeStarch@googlemail.com>
2024-10-14 10:06:45 -07:00

70 lines
1.7 KiB
C++

#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <getopt.h>
#include <signal.h>
#include <Os/Os.hpp>
#include <Fw/Time/Time.hpp>
#include <RPI/Top/RPITopologyAc.hpp>
RPI::TopologyState state;
void print_usage(const char* app) {
(void) printf("Usage: ./%s [options]\n-p\tport_number\n-a\thostname/IP address\n",app);
}
// Handle a signal, e.g. control-C
static void sighandler(int signum) {
// Call the teardown function
// This causes the Linux timer to quit
RPI::teardown(state);
}
int main(int argc, char* argv[]) {
Os::init();
I32 option = 0;
while ((option = getopt(argc, argv, "hp:a:")) != -1){
switch(option) {
case 'h':
print_usage(argv[0]);
return 0;
break;
case 'p':
state.portNumber = static_cast<U32>(atoi(optarg));
break;
case 'a':
state.hostName = optarg;
break;
case '?':
return 1;
default:
print_usage(argv[0]);
return 1;
}
}
(void) printf("Hit Ctrl-C to quit\n");
RPI::setup(state);
// register signal handlers to exit program
signal(SIGINT,sighandler);
signal(SIGTERM,sighandler);
// Start the Linux timer.
// The timer runs on the main thread until it quits
// in the teardown function, called from the signal
// handler.
RPI::linuxTimer.startTimer(100); //!< 10Hz
// Signal handler was called, and linuxTimer quit.
// Time to exit the program.
// Give time for threads to exit.
(void) printf("Waiting for threads...\n");
Os::Task::delay(Fw::TimeInterval(1, 0));
(void) printf("Exiting...\n");
return 0;
}