#11 Implement inter command timeout
This commit is contained in:
parent
f553dbf7db
commit
ef764dabc6
5 changed files with 50 additions and 5 deletions
2
Makefile
2
Makefile
|
|
@ -1,5 +1,5 @@
|
||||||
CC=clang
|
CC=clang
|
||||||
CFLAGS=-Wall -MMD -pthread -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE
|
CFLAGS=-Wall -MMD -pthread -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=199309L
|
||||||
LDFLAGS=-lpthread -lncurses
|
LDFLAGS=-lpthread -lncurses
|
||||||
|
|
||||||
DIR_SRC=src
|
DIR_SRC=src
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,8 @@ bytenuts_print_stats()
|
||||||
cheerios_insert(st_line, strlen(st_line));
|
cheerios_insert(st_line, strlen(st_line));
|
||||||
sprintf(st_line, "serial_path: %s\r\n", bytenuts.config.serial_path);
|
sprintf(st_line, "serial_path: %s\r\n", bytenuts.config.serial_path);
|
||||||
cheerios_insert(st_line, strlen(st_line));
|
cheerios_insert(st_line, strlen(st_line));
|
||||||
|
sprintf(st_line, "inter_cmd_to: %d\r\n", bytenuts.config.inter_cmd_to);
|
||||||
|
cheerios_insert(st_line, strlen(st_line));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -357,6 +359,13 @@ parse_args(int argc, char **argv)
|
||||||
bytenuts.config.escape = argv[i][9];
|
bytenuts.config.escape = argv[i][9];
|
||||||
bytenuts.config_overrides[3] = 1;
|
bytenuts.config_overrides[3] = 1;
|
||||||
}
|
}
|
||||||
|
else if (arg_len > 15 && !memcmp(argv[i], "--inter_cmd_to=", 15)) {
|
||||||
|
long cmd_to = strtol(&argv[i][15], NULL, 10);
|
||||||
|
if (cmd_to >= 0) {
|
||||||
|
bytenuts.config.inter_cmd_to = cmd_to;
|
||||||
|
bytenuts.config_overrides[4] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (!strcmp(argv[i], "--resume") || !strcmp(argv[i], "-r")) {
|
else if (!strcmp(argv[i], "--resume") || !strcmp(argv[i], "-r")) {
|
||||||
bytenuts.resume = 1;
|
bytenuts.resume = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -404,6 +413,12 @@ load_configs()
|
||||||
else if (!bytenuts.config_overrides[3] && !memcmp(line, "escape=", 7)) {
|
else if (!bytenuts.config_overrides[3] && !memcmp(line, "escape=", 7)) {
|
||||||
bytenuts.config.escape = line[7];
|
bytenuts.config.escape = line[7];
|
||||||
}
|
}
|
||||||
|
else if (!bytenuts.config_overrides[4] && !memcmp(line, "inter_cmd_to=", 13)) {
|
||||||
|
long cmd_to = strtol(&line[13], NULL, 10);
|
||||||
|
if (cmd_to >= 0) {
|
||||||
|
bytenuts.config.inter_cmd_to = cmd_to;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
|
||||||
|
|
@ -27,6 +28,7 @@ typedef struct bytenuts_config_struct {
|
||||||
char *config_path; /* config file path */
|
char *config_path; /* config file path */
|
||||||
char *log_path; /* path to the log file (if it exists) */
|
char *log_path; /* path to the log file (if it exists) */
|
||||||
char *serial_path; /* path to the target serial device */
|
char *serial_path; /* path to the target serial device */
|
||||||
|
uint32_t inter_cmd_to; /* inter command timeout in ms */
|
||||||
} bytenuts_config_t;
|
} bytenuts_config_t;
|
||||||
|
|
||||||
#define CONFIG_DEFAULT (bytenuts_config_t){ \
|
#define CONFIG_DEFAULT (bytenuts_config_t){ \
|
||||||
|
|
@ -38,12 +40,13 @@ typedef struct bytenuts_config_struct {
|
||||||
.config_path = NULL, \
|
.config_path = NULL, \
|
||||||
.log_path = NULL, \
|
.log_path = NULL, \
|
||||||
.serial_path = NULL, \
|
.serial_path = NULL, \
|
||||||
|
.inter_cmd_to = 10, \
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct bytenuts_struct {
|
typedef struct bytenuts_struct {
|
||||||
int serial_fd;
|
int serial_fd;
|
||||||
bytenuts_config_t config;
|
bytenuts_config_t config;
|
||||||
int config_overrides[4];
|
int config_overrides[5];
|
||||||
int resume;
|
int resume;
|
||||||
bytenuts_state_t state;
|
bytenuts_state_t state;
|
||||||
WINDOW *status_win;
|
WINDOW *status_win;
|
||||||
|
|
|
||||||
31
src/ingest.c
31
src/ingest.c
|
|
@ -8,10 +8,12 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "bytenuts.h"
|
#include "bytenuts.h"
|
||||||
#include "cheerios.h"
|
#include "cheerios.h"
|
||||||
#include "ingest.h"
|
#include "ingest.h"
|
||||||
|
#include "timer_math.h"
|
||||||
|
|
||||||
static void *ingest_thread(void *arg);
|
static void *ingest_thread(void *arg);
|
||||||
|
|
||||||
|
|
@ -21,10 +23,11 @@ static int mode_normal(int ch);
|
||||||
static int mode_xmodem(int block_sz);
|
static int mode_xmodem(int block_sz);
|
||||||
static int mode_hex(int ch);
|
static int mode_hex(int ch);
|
||||||
static int handle_functions(int ch);
|
static int handle_functions(int ch);
|
||||||
static int print_stats();
|
static int print_stats(void);
|
||||||
static int auto_complete();
|
static int auto_complete(void);
|
||||||
static int read_cmd_page(int idx);
|
static int read_cmd_page(int idx);
|
||||||
static void update_cmd_pg_status();
|
static void update_cmd_pg_status(void);
|
||||||
|
static void inter_command_wait(void);
|
||||||
|
|
||||||
int
|
int
|
||||||
ingest_start(bytenuts_t *bytenuts)
|
ingest_start(bytenuts_t *bytenuts)
|
||||||
|
|
@ -70,6 +73,10 @@ ingest_start(bytenuts_t *bytenuts)
|
||||||
}
|
}
|
||||||
update_cmd_pg_status();
|
update_cmd_pg_status();
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ingest.cmd_ts);
|
||||||
|
/* ensure first command is not delayed */
|
||||||
|
timer_sub_ms(&ingest.cmd_ts, ingest.config->inter_cmd_to);
|
||||||
|
|
||||||
ingest.running = 1;
|
ingest.running = 1;
|
||||||
if (pthread_create(&ingest.thr, NULL, ingest_thread, NULL)) {
|
if (pthread_create(&ingest.thr, NULL, ingest_thread, NULL)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -471,6 +478,7 @@ mode_normal(int ch)
|
||||||
else
|
else
|
||||||
ending = "\r\n";
|
ending = "\r\n";
|
||||||
|
|
||||||
|
inter_command_wait();
|
||||||
cheerios_input(ingest.inbuf, inlen);
|
cheerios_input(ingest.inbuf, inlen);
|
||||||
cheerios_input(ending, strlen(ending));
|
cheerios_input(ending, strlen(ending));
|
||||||
if (ingest.config->echo) {
|
if (ingest.config->echo) {
|
||||||
|
|
@ -688,6 +696,7 @@ mode_hex(int ch)
|
||||||
hexlen++;
|
hexlen++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inter_command_wait();
|
||||||
cheerios_input(hexbuf, hexlen);
|
cheerios_input(hexbuf, hexlen);
|
||||||
if (ingest.config->echo) {
|
if (ingest.config->echo) {
|
||||||
cheerios_insert(">> (hex)\r\n", 10);
|
cheerios_insert(">> (hex)\r\n", 10);
|
||||||
|
|
@ -1029,3 +1038,19 @@ update_cmd_pg_status()
|
||||||
bytenuts_set_status(STATUS_CMDPAGE, "n/a");
|
bytenuts_set_status(STATUS_CMDPAGE, "n/a");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
inter_command_wait()
|
||||||
|
{
|
||||||
|
struct timespec target;
|
||||||
|
struct timespec now;
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_REALTIME, &now);
|
||||||
|
memcpy(&target, &ingest.cmd_ts, sizeof(struct timespec));
|
||||||
|
|
||||||
|
timer_add_ms(&target, ingest.config->inter_cmd_to);
|
||||||
|
timer_sub(&target, &now);
|
||||||
|
|
||||||
|
nanosleep(&target, NULL);
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ingest.cmd_ts);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "bytenuts.h"
|
#include "bytenuts.h"
|
||||||
|
|
||||||
|
|
@ -40,6 +41,7 @@ typedef struct ingest_struct {
|
||||||
int cmd_pgs_n;
|
int cmd_pgs_n;
|
||||||
/* what command page is currently selected */
|
/* what command page is currently selected */
|
||||||
int cmd_pg_cur;
|
int cmd_pg_cur;
|
||||||
|
struct timespec cmd_ts; /* last command sent timestamp */
|
||||||
} ingest_t;
|
} ingest_t;
|
||||||
|
|
||||||
/* startup the input window thread */
|
/* startup the input window thread */
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue