mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
emulation on host: option for FS persistence location (#7424)
* fix warnings * emulation on host: option -P to change FS persistence location * exit on SIGTERM too, with SIGINT
This commit is contained in:
parent
f1651fba89
commit
cc1cc0b2ce
@ -153,6 +153,7 @@ DEBUG += -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP
|
||||
endif
|
||||
|
||||
FLAGS += $(DEBUG) -Wall $(OPTZ) -fno-common -g $(M32)
|
||||
FLAGS += -fstack-check -fstack-protector-all
|
||||
FLAGS += -DHTTPCLIENT_1_1_COMPATIBLE=0
|
||||
FLAGS += -DLWIP_IPV6=0
|
||||
FLAGS += -DHOST_MOCK=1
|
||||
|
@ -49,6 +49,7 @@ bool ignore_sigint = false;
|
||||
bool restore_tty = false;
|
||||
bool mockdebug = false;
|
||||
int mock_port_shifter = MOCK_PORT_SHIFTER;
|
||||
const char* fspath = nullptr;
|
||||
|
||||
#define STDIN STDIN_FILENO
|
||||
|
||||
@ -120,19 +121,24 @@ void help (const char* argv0, int exitcode)
|
||||
printf(
|
||||
"%s - compiled with esp8266/arduino emulator\n"
|
||||
"options:\n"
|
||||
" -h\n"
|
||||
" -i <interface> - use this interface for IP address\n"
|
||||
" -l - bind tcp/udp servers to interface only (not 0.0.0.0)\n"
|
||||
" -s - port shifter (default: %d, when root: 0)\n"
|
||||
" -c - ignore CTRL-C (send it via Serial)\n"
|
||||
" -f - no throttle (possibly 100%%CPU)\n"
|
||||
" -b - blocking tty/mocked-uart (default: not blocking tty)\n"
|
||||
" -S - spiffs size in KBytes (default: %zd)\n"
|
||||
" -L - littlefs size in KBytes (default: %zd)\n"
|
||||
"\t-h\n"
|
||||
"\tnetwork:\n"
|
||||
"\t-i <interface> - use this interface for IP address\n"
|
||||
"\t-l - bind tcp/udp servers to interface only (not 0.0.0.0)\n"
|
||||
"\t-s - port shifter (default: %d, when root: 0)\n"
|
||||
"\tterminal:\n"
|
||||
"\t-b - blocking tty/mocked-uart (default: not blocking tty)\n"
|
||||
"\t-T - show timestamp on output\n"
|
||||
"\tFS:\n"
|
||||
"\t-P - path for fs-persistent files (default: %s-)\n"
|
||||
"\t-S - spiffs size in KBytes (default: %zd)\n"
|
||||
"\t-L - littlefs size in KBytes (default: %zd)\n"
|
||||
"\t (spiffs, littlefs: negative value will force mismatched size)\n"
|
||||
" -T - show timestamp on output\n"
|
||||
" -v - verbose\n"
|
||||
, argv0, MOCK_PORT_SHIFTER, spiffs_kb, littlefs_kb);
|
||||
"\tgeneral:\n"
|
||||
"\t-c - ignore CTRL-C (send it via Serial)\n"
|
||||
"\t-f - no throttle (possibly 100%%CPU)\n"
|
||||
"\t-v - verbose\n"
|
||||
, argv0, MOCK_PORT_SHIFTER, argv0, spiffs_kb, littlefs_kb);
|
||||
exit(exitcode);
|
||||
}
|
||||
|
||||
@ -146,6 +152,7 @@ static struct option options[] =
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "timestamp", no_argument, NULL, 'T' },
|
||||
{ "interface", required_argument, NULL, 'i' },
|
||||
{ "fspath", required_argument, NULL, 'P' },
|
||||
{ "spiffskb", required_argument, NULL, 'S' },
|
||||
{ "littlefskb", required_argument, NULL, 'L' },
|
||||
{ "portshifter", required_argument, NULL, 's' },
|
||||
@ -158,6 +165,23 @@ void cleanup ()
|
||||
mock_stop_uart();
|
||||
}
|
||||
|
||||
void make_fs_filename (String& name, const char* fspath, const char* argv0)
|
||||
{
|
||||
name.clear();
|
||||
if (fspath)
|
||||
{
|
||||
int lastSlash = -1;
|
||||
for (int i = 0; argv0[i]; i++)
|
||||
if (argv0[i] == '/')
|
||||
lastSlash = i;
|
||||
name = fspath;
|
||||
name += '/';
|
||||
name += &argv0[lastSlash + 1];
|
||||
}
|
||||
else
|
||||
name = argv0;
|
||||
}
|
||||
|
||||
void control_c (int sig)
|
||||
{
|
||||
(void)sig;
|
||||
@ -177,6 +201,7 @@ int main (int argc, char* const argv [])
|
||||
blocking_uart = false; // global
|
||||
|
||||
signal(SIGINT, control_c);
|
||||
signal(SIGTERM, control_c);
|
||||
if (geteuid() == 0)
|
||||
mock_port_shifter = 0;
|
||||
else
|
||||
@ -184,7 +209,7 @@ int main (int argc, char* const argv [])
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:", options, NULL);
|
||||
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:P:", options, NULL);
|
||||
if (n < 0)
|
||||
break;
|
||||
switch (n)
|
||||
@ -213,6 +238,9 @@ int main (int argc, char* const argv [])
|
||||
case 'L':
|
||||
littlefs_kb = atoi(optarg);
|
||||
break;
|
||||
case 'P':
|
||||
fspath = optarg;
|
||||
break;
|
||||
case 'b':
|
||||
blocking_uart = true;
|
||||
break;
|
||||
@ -231,7 +259,8 @@ int main (int argc, char* const argv [])
|
||||
|
||||
if (spiffs_kb)
|
||||
{
|
||||
String name = argv[0];
|
||||
String name;
|
||||
make_fs_filename(name, fspath, argv[0]);
|
||||
name += "-spiffs";
|
||||
name += String(spiffs_kb > 0? spiffs_kb: -spiffs_kb, DEC);
|
||||
name += "KB";
|
||||
@ -240,7 +269,8 @@ int main (int argc, char* const argv [])
|
||||
|
||||
if (littlefs_kb)
|
||||
{
|
||||
String name = argv[0];
|
||||
String name;
|
||||
make_fs_filename(name, fspath, argv[0]);
|
||||
name += "-littlefs";
|
||||
name += String(littlefs_kb > 0? littlefs_kb: -littlefs_kb, DEC);
|
||||
name += "KB";
|
||||
|
@ -121,7 +121,7 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
mockverbose("joined multicast group addr %08lx\n", ntohl(mcast));
|
||||
mockverbose("joined multicast group addr %08lx\n", (long)ntohl(mcast));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user