Revert "simulator: more arguments (#432)"

This reverts commit be7a2ddc9c.
This commit is contained in:
Matthew Kennedy 2024-08-05 13:40:04 -07:00
parent 70025791c6
commit 1452a1dcc7
8 changed files with 14 additions and 85 deletions

View File

@ -40,7 +40,7 @@ jobs:
- name: Run Linux Simulator for 10 seconds
working-directory: ./simulator/
run: ./build/fome_simulator --timeout 10
run: ./build/fome_simulator 10
- name: Upload Linux built simulator
uses: actions/upload-artifact@v4

View File

@ -1,65 +0,0 @@
#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 };

View File

@ -18,7 +18,6 @@
#include "chprintf.h"
#include "rusEfiFunctionalTest.h"
#include "flash_int.h"
#include "libc_argp.h"
#include <iostream>
#include <filesystem>
@ -144,14 +143,6 @@ static virtual_timer_t exitTimer;
int main(int argc, char** argv) {
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.
* - HAL initialization, this also initializes the configured device drivers
@ -162,10 +153,12 @@ int main(int argc, char** argv) {
halInit();
chSysInit();
if (arguments.timeout >= 0) {
printf("Running rusEFI simulator for %d seconds, then exiting.\n\n", arguments.timeout);
if (argc == 2) {
int timeoutSeconds = atoi(argv[1]);
printf("Running rusEFI simulator for %d seconds, then exiting.\n\n", timeoutSeconds);
chSysLock();
chVTSetI(&exitTimer, MY_US2ST(arguments.timeout * 1e6), [](void *) { exit(0); }, nullptr);
chVTSetI(&exitTimer, MY_US2ST(timeoutSeconds * 1e6), [](void*) { exit(0); }, nullptr);
chSysUnlock();
}
@ -185,7 +178,7 @@ int main(int argc, char** argv) {
cputs(" - Listening for connections on SD2");
chEvtRegister(chnGetEventSource(&SD2), &sd2fel, 2);
rusEfiFunctionalTest(arguments.socketcanDevice);
rusEfiFunctionalTest();
/*
* Events servicing loop.

View File

@ -1,4 +1,4 @@
Win32 or POSIX version of firmware allows to explore FOME on a PC without any embedded hardware!
Win32 or posix version of firmware allows to explore rusEFI on a PC without any embedded hardware!
Simulator runs a subset of ECU on your pc, easier to debug some things, tighter dev loop.
@ -6,3 +6,4 @@ Simulator runs a subset of ECU on your pc, easier to debug some things, tighter
* mocked analog sensors
* mocked outputs
* SocketCAN integration on Linux

View File

@ -1 +0,0 @@
Here we have FOME PC version ("simulator"). Same Makefile would build Win32 or \*nix/POSIX.

View File

@ -0,0 +1 @@
Here we have rusEfi PC version. Same Makefile would build win32 or unux posix.

View File

@ -84,7 +84,7 @@ static void runChprintfTest() {
}
void rusEfiFunctionalTest(char const * const socketcanDevice) {
void rusEfiFunctionalTest(void) {
printToConsole("Running rusEfi simulator version:");
static char versionBuffer[20];
itoa10(versionBuffer, (int)getRusEfiVersion());
@ -128,8 +128,8 @@ void rusEfiFunctionalTest(char const * const socketcanDevice) {
#if HAL_USE_CAN
// Set CAN device name
CAND1.deviceName = socketcanDevice;
printf("Using SocketCAN device: %s\n", CAND1.deviceName);
CAND1.deviceName = "can0";
initCan();
#endif // HAL_USE_CAN

View File

@ -7,6 +7,6 @@
#pragma once
void rusEfiFunctionalTest(char const * const socketcanDevice);
void rusEfiFunctionalTest(void);
void printPendingMessages(void);
void logMsg(const char *fmt, ...);