mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-26 07:02:15 +03:00
emulation on host: show timestamp on console output (#6507)
* emulation on host: option to add timestamp on console output
This commit is contained in:
@ -129,24 +129,26 @@ void help (const char* argv0, int exitcode)
|
|||||||
" -b - blocking tty/mocked-uart (default: not blocking tty)\n"
|
" -b - blocking tty/mocked-uart (default: not blocking tty)\n"
|
||||||
" -S - spiffs size in KBytes (default: %zd)\n"
|
" -S - spiffs size in KBytes (default: %zd)\n"
|
||||||
" -L - littlefs size in KBytes (default: %zd)\n"
|
" -L - littlefs size in KBytes (default: %zd)\n"
|
||||||
" -v - mock verbose\n"
|
"\t (spiffs, littlefs: negative value will force mismatched size)\n"
|
||||||
" (negative value will force mismatched size)\n"
|
" -T - show timestamp on output\n"
|
||||||
|
" -v - verbose\n"
|
||||||
, argv0, MOCK_PORT_SHIFTER, spiffs_kb, littlefs_kb);
|
, argv0, MOCK_PORT_SHIFTER, spiffs_kb, littlefs_kb);
|
||||||
exit(exitcode);
|
exit(exitcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct option options[] =
|
static struct option options[] =
|
||||||
{
|
{
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "fast", no_argument, NULL, 'f' },
|
{ "fast", no_argument, NULL, 'f' },
|
||||||
{ "local", no_argument, NULL, 'l' },
|
{ "local", no_argument, NULL, 'l' },
|
||||||
{ "sigint", no_argument, NULL, 'c' },
|
{ "sigint", no_argument, NULL, 'c' },
|
||||||
{ "blockinguart", no_argument, NULL, 'b' },
|
{ "blockinguart", no_argument, NULL, 'b' },
|
||||||
{ "verbose", no_argument, NULL, 'v' },
|
{ "verbose", no_argument, NULL, 'v' },
|
||||||
{ "interface", required_argument, NULL, 'i' },
|
{ "timestamp", no_argument, NULL, 'T' },
|
||||||
{ "spiffskb", required_argument, NULL, 'S' },
|
{ "interface", required_argument, NULL, 'i' },
|
||||||
{ "littlefskb", required_argument, NULL, 'L' },
|
{ "spiffskb", required_argument, NULL, 'S' },
|
||||||
{ "portshifter", required_argument, NULL, 's' },
|
{ "littlefskb", required_argument, NULL, 'L' },
|
||||||
|
{ "portshifter", required_argument, NULL, 's' },
|
||||||
};
|
};
|
||||||
|
|
||||||
void cleanup ()
|
void cleanup ()
|
||||||
@ -182,7 +184,7 @@ int main (int argc, char* const argv [])
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
int n = getopt_long(argc, argv, "hlcfbvi:S:s:L:", options, NULL);
|
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:", options, NULL);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
break;
|
break;
|
||||||
switch (n)
|
switch (n)
|
||||||
@ -217,6 +219,9 @@ int main (int argc, char* const argv [])
|
|||||||
case 'v':
|
case 'v':
|
||||||
mockdebug = true;
|
mockdebug = true;
|
||||||
break;
|
break;
|
||||||
|
case 'T':
|
||||||
|
serial_timestamp = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
help(argv[0], EXIT_FAILURE);
|
help(argv[0], EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h> // write
|
#include <unistd.h> // write
|
||||||
|
#include <sys/time.h> // gettimeofday
|
||||||
|
#include <time.h> // localtime
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
@ -59,13 +61,35 @@ struct uart_
|
|||||||
struct uart_rx_buffer_ * rx_buffer;
|
struct uart_rx_buffer_ * rx_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool serial_timestamp = false;
|
||||||
|
|
||||||
// write one byte to the emulated UART
|
// write one byte to the emulated UART
|
||||||
static void
|
static void
|
||||||
uart_do_write_char(const int uart_nr, char c)
|
uart_do_write_char(const int uart_nr, char c)
|
||||||
{
|
{
|
||||||
|
static bool w = false;
|
||||||
|
|
||||||
if (uart_nr >= UART0 && uart_nr <= UART1)
|
if (uart_nr >= UART0 && uart_nr <= UART1)
|
||||||
if (1 != write(uart_nr + 1, &c, 1))
|
{
|
||||||
fprintf(stderr, "Unable to write character to emulated UART stream: %d\n", c);
|
if (serial_timestamp && (c == '\n' || c == '\r'))
|
||||||
|
{
|
||||||
|
if (w)
|
||||||
|
{
|
||||||
|
FILE* out = uart_nr == UART0? stdout: stderr;
|
||||||
|
timeval tv;
|
||||||
|
gettimeofday(&tv, nullptr);
|
||||||
|
const tm* tm = localtime(&tv.tv_sec);
|
||||||
|
fprintf(out, "\r\n%d:%02d:%02d.%06d: ", tm->tm_hour, tm->tm_min, tm->tm_sec, (int)tv.tv_usec);
|
||||||
|
fflush(out);
|
||||||
|
w = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
write(uart_nr + 1, &c, 1);
|
||||||
|
w = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// write a new byte into the RX FIFO buffer
|
// write a new byte into the RX FIFO buffer
|
||||||
|
@ -85,7 +85,7 @@ int ets_printf (const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
|||||||
int mockverbose (const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
int mockverbose (const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
|
|
||||||
extern const char* host_interface; // cmdline parameter
|
extern const char* host_interface; // cmdline parameter
|
||||||
|
extern bool serial_timestamp;
|
||||||
extern int mock_port_shifter;
|
extern int mock_port_shifter;
|
||||||
|
|
||||||
#define NO_GLOBAL_BINDING 0xffffffff
|
#define NO_GLOBAL_BINDING 0xffffffff
|
||||||
|
Reference in New Issue
Block a user