mirror of https://github.com/FOME-Tech/fome-fw.git
simulator: more arguments (#432)
* simulator: improve READMEs * simulator: use argp for argument parsing * simulator: plumb SocketCAN device argument * simulator: change verbosity argument use a --quiet instead, as --verbose is a "set-only" option without arguments and cannot be "unset" if default * simulator: timeout is an option, not an argument * simulator: github workflow uses --timeout option
This commit is contained in:
parent
6ba19ac38e
commit
be7a2ddc9c
|
@ -40,7 +40,7 @@ jobs:
|
||||||
|
|
||||||
- name: Run Linux Simulator for 10 seconds
|
- name: Run Linux Simulator for 10 seconds
|
||||||
working-directory: ./simulator/
|
working-directory: ./simulator/
|
||||||
run: ./build/fome_simulator 10
|
run: ./build/fome_simulator --timeout 10
|
||||||
|
|
||||||
- name: Upload Linux built simulator
|
- name: Upload Linux built simulator
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
Win32 or posix version of firmware allows to explore rusEFI on a PC without any embedded hardware!
|
Win32 or POSIX version of firmware allows to explore FOME on a PC without any embedded hardware!
|
||||||
|
|
||||||
Simulator runs a subset of ECU on your pc, easier to debug some things, tighter dev loop.
|
Simulator runs a subset of ECU on your pc, easier to debug some things, tighter dev loop.
|
||||||
|
|
||||||
|
@ -6,4 +6,3 @@ Simulator runs a subset of ECU on your pc, easier to debug some things, tighter
|
||||||
* mocked analog sensors
|
* mocked analog sensors
|
||||||
* mocked outputs
|
* mocked outputs
|
||||||
* SocketCAN integration on Linux
|
* SocketCAN integration on Linux
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <argp.h>
|
||||||
|
|
||||||
|
/* Program documentation. */
|
||||||
|
static char doc[] =
|
||||||
|
"FOME Simulator -- https://wiki.fome.tech/";
|
||||||
|
|
||||||
|
/* A description of the arguments we accept. */
|
||||||
|
static char args_doc[] = "";
|
||||||
|
|
||||||
|
/* The options we understand. */
|
||||||
|
static struct argp_option options[] = {
|
||||||
|
{"quiet", 'q', 0, 0, "Don't produce verbose output", 0 },
|
||||||
|
{"socketcan-device",
|
||||||
|
'd', "DEVICE", 0, "SocketCAN DEVICE (default: can0) to use", 0 },
|
||||||
|
{"timeout", 't', "SECONDS", 0, "Run for SECONDS and then exit (negative values ignored)", 0 },
|
||||||
|
{ 0, 0, 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Used by main to communicate with parse_opt. */
|
||||||
|
struct arguments
|
||||||
|
{
|
||||||
|
int quiet;
|
||||||
|
char * socketcanDevice;
|
||||||
|
int timeout;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Parse a single option. */
|
||||||
|
static error_t
|
||||||
|
parse_opt(int key, char * arg, struct argp_state * state)
|
||||||
|
{
|
||||||
|
/* Get the input argument from argp_parse, which we
|
||||||
|
know is a pointer to our arguments structure. */
|
||||||
|
struct arguments * arguments = (struct arguments *)state->input;
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case 'd':
|
||||||
|
arguments->socketcanDevice = arg;
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
arguments->quiet = 1;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
arguments->timeout = atoi(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ARGP_KEY_ARG:
|
||||||
|
/* if (state->arg_num >= 0) */ {
|
||||||
|
/* Too many arguments. */
|
||||||
|
argp_usage(state);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ARGP_KEY_END:
|
||||||
|
case ARGP_KEY_NO_ARGS:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return ARGP_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Our argp parser. */
|
||||||
|
static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 };
|
|
@ -18,6 +18,7 @@
|
||||||
#include "chprintf.h"
|
#include "chprintf.h"
|
||||||
#include "rusEfiFunctionalTest.h"
|
#include "rusEfiFunctionalTest.h"
|
||||||
#include "flash_int.h"
|
#include "flash_int.h"
|
||||||
|
#include "libc_argp.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
@ -143,6 +144,14 @@ static virtual_timer_t exitTimer;
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
setbuf(stdout, NULL);
|
setbuf(stdout, NULL);
|
||||||
|
|
||||||
|
struct arguments arguments;
|
||||||
|
arguments.quiet = 0;
|
||||||
|
arguments.socketcanDevice = (char *)"can0";
|
||||||
|
arguments.timeout = -1;
|
||||||
|
argp_parse(&argp, argc, argv, 0, 0, &arguments);
|
||||||
|
|
||||||
|
verboseMode = arguments.quiet == 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* System initializations.
|
* System initializations.
|
||||||
* - HAL initialization, this also initializes the configured device drivers
|
* - HAL initialization, this also initializes the configured device drivers
|
||||||
|
@ -153,12 +162,10 @@ int main(int argc, char** argv) {
|
||||||
halInit();
|
halInit();
|
||||||
chSysInit();
|
chSysInit();
|
||||||
|
|
||||||
if (argc == 2) {
|
if (arguments.timeout >= 0) {
|
||||||
int timeoutSeconds = atoi(argv[1]);
|
printf("Running rusEFI simulator for %d seconds, then exiting.\n\n", arguments.timeout);
|
||||||
printf("Running rusEFI simulator for %d seconds, then exiting.\n\n", timeoutSeconds);
|
|
||||||
|
|
||||||
chSysLock();
|
chSysLock();
|
||||||
chVTSetI(&exitTimer, MY_US2ST(timeoutSeconds * 1e6), [](void*) { exit(0); }, nullptr);
|
chVTSetI(&exitTimer, MY_US2ST(arguments.timeout * 1e6), [](void *) { exit(0); }, nullptr);
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +185,7 @@ int main(int argc, char** argv) {
|
||||||
cputs(" - Listening for connections on SD2");
|
cputs(" - Listening for connections on SD2");
|
||||||
chEvtRegister(chnGetEventSource(&SD2), &sd2fel, 2);
|
chEvtRegister(chnGetEventSource(&SD2), &sd2fel, 2);
|
||||||
|
|
||||||
rusEfiFunctionalTest();
|
rusEfiFunctionalTest(arguments.socketcanDevice);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Events servicing loop.
|
* Events servicing loop.
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Here we have FOME PC version ("simulator"). Same Makefile would build Win32 or \*nix/POSIX.
|
|
@ -1 +0,0 @@
|
||||||
Here we have rusEfi PC version. Same Makefile would build win32 or unux posix.
|
|
|
@ -84,7 +84,7 @@ static void runChprintfTest() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rusEfiFunctionalTest(void) {
|
void rusEfiFunctionalTest(char const * const socketcanDevice) {
|
||||||
printToConsole("Running rusEfi simulator version:");
|
printToConsole("Running rusEfi simulator version:");
|
||||||
static char versionBuffer[20];
|
static char versionBuffer[20];
|
||||||
itoa10(versionBuffer, (int)getRusEfiVersion());
|
itoa10(versionBuffer, (int)getRusEfiVersion());
|
||||||
|
@ -128,8 +128,8 @@ void rusEfiFunctionalTest(void) {
|
||||||
|
|
||||||
#if HAL_USE_CAN
|
#if HAL_USE_CAN
|
||||||
// Set CAN device name
|
// Set CAN device name
|
||||||
CAND1.deviceName = "can0";
|
CAND1.deviceName = socketcanDevice;
|
||||||
|
printf("Using SocketCAN device: %s\n", CAND1.deviceName);
|
||||||
initCan();
|
initCan();
|
||||||
#endif // HAL_USE_CAN
|
#endif // HAL_USE_CAN
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void rusEfiFunctionalTest(void);
|
void rusEfiFunctionalTest(char const * const socketcanDevice);
|
||||||
void printPendingMessages(void);
|
void printPendingMessages(void);
|
||||||
void logMsg(const char *fmt, ...);
|
void logMsg(const char *fmt, ...);
|
||||||
|
|
Loading…
Reference in New Issue