From 54a41cfeb3035bdc8e699a31ea631ff86a48ebdf Mon Sep 17 00:00:00 2001 From: phyto Date: Mon, 20 May 2019 14:49:31 +0200 Subject: [PATCH] terminal is working, but expect some bugs... --- .gitignore | 3 +- serial/serial.c | 7 +++++ simulator/rdtemp/cli.ino | 19 +++++++----- simulator/rdtemp/rdtemp.ino | 6 ++++ ui/t.c | 41 +++++++++++++++++++----- ui/terminal.c | 62 ++++++++++++++++++++++++++++++------- 6 files changed, 112 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index ce52380..569df87 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,6 @@ viz/*.a audio/t audio/*.wav -hi/log.* +ui/log.* +ui/t diff --git a/serial/serial.c b/serial/serial.c index edf44c3..fb94436 100644 --- a/serial/serial.c +++ b/serial/serial.c @@ -10,6 +10,8 @@ #include "serial.h" +extern int verbosity; + /* -------------------------------------------------------------------- */ static int baudrate2const(int bauds) { @@ -107,6 +109,11 @@ tcsetattr(uart0, TCSANOW, &options); tcflush(uart0, TCIFLUSH); /* do it again, sam */ +if (verbosity) { + fprintf(stderr, "%s %s uart0 = %d\n", + __FILE__, __func__, uart0); + } + return uart0; } /* -------------------------------------------------------------------- */ diff --git a/simulator/rdtemp/cli.ino b/simulator/rdtemp/cli.ino index fba2cbd..e96c36b 100644 --- a/simulator/rdtemp/cli.ino +++ b/simulator/rdtemp/cli.ino @@ -18,7 +18,7 @@ if (param->magic != 0xfde9) { return 1; } if (param->delai < 100) { - prtln("delay too short"); + prt(param->delai); prtln("delay too short"); return 2; } delta = param->temp_maxi - param->temp_mini; @@ -121,16 +121,18 @@ switch(key) { } /* --------------------------------------------------------------- */ - +/* + * use this function with caution, it can burn your system ! + */ void test_relais(short nb) { short foo; prtln("test du relais frigo"); for (foo=0; foo 1 +fprintf(stderr, "%s $%x %c\n", __func__, octet, octet); +#endif + +buffer[idx++] = octet; + +if (idx==16) { + fprintf(fp, "dmp : "); + for (foo=0; foo<16; foo++) { + fprintf(fp, "%02x ", buffer[foo]); + } + fprintf(fp, " - |"); + for (foo=0; foo<16; foo++) { + c = buffer[foo]; + fprintf(fp, "%c", isprint(c) ? c : ' '); + } + fprintf(fp, "|\n"); fflush(fp); + idx = 0; + } + +return 0; +} +/* ---------------------------------------------------------------- */ + void help(int k) { puts("options : "); @@ -31,7 +61,7 @@ int opt, foo; int serial_in; char *device = "/dev/ttyS0"; int K = 0; -char ligne[100]; +// char ligne[100]; while ((opt = getopt(argc, argv, "d:hv")) != -1) { switch (opt) { @@ -43,15 +73,12 @@ while ((opt = getopt(argc, argv, "d:hv")) != -1) { } } -printf("\n*** compiled %s %s ***\n", __DATE__, __TIME__); +printf("\n*** compiled %s %s\n", __DATE__, __TIME__); printf("*** device: %s\n", device); -sleep(1); - serial_in = prepare_UART(device, 9600); if (serial_in < 0) { - fprintf(stderr, "\n%s : open device : error %d on %s\n", - argv[0], serial_in, device); + fprintf(stderr, "err open %s : %d\n", device, serial_in); exit(1); } diff --git a/ui/terminal.c b/ui/terminal.c index 8d8a35b..600831b 100644 --- a/ui/terminal.c +++ b/ui/terminal.c @@ -6,6 +6,9 @@ #include #include #include +#include +#include +#include #include #include @@ -15,6 +18,8 @@ extern int verbosity; +int special_dumper(FILE *fp, unsigned char octet); + /* ---------------------------------------------------------------- */ static void bordure(WINDOW * w, char *texte, int type) { @@ -31,11 +36,12 @@ static int interactive(WINDOW *glass, int fd_local, int fd_remote) int flag_exit = 0; long tstart, tcur; char ligne[100]; +int received; /* --- variables for select */ struct timeval tv; fd_set rfds; -int retval; +int retval,mfd; #if DEBUG_LEVEL fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, @@ -46,18 +52,51 @@ tstart = time(NULL); wclear(glass); wrefresh(glass); +mfd = (fd_local>fd_remote ? fd_local : fd_remote) + 1; /* XXX */ + +#if DEBUG_LEVEL +sprintf(ligne, "%s : mfd is %d\n", __func__, mfd); +waddstr(glass, ligne); wrefresh(glass); +#endif + do { tcur = time(NULL); FD_ZERO(&rfds); FD_SET(fd_local, &rfds); /* stdin */ FD_SET(fd_remote, &rfds); /* teletype */ - tv.tv_sec = tv.tv_sec = 0; /* no timeout */ + tv.tv_sec = tv.tv_usec = 0; /* no timeout */ - retval = select(2, &rfds, NULL, NULL, &tv); + retval = select(mfd, &rfds, NULL, NULL, &tv); + if (-1 == retval) { + sprintf(ligne, "err select %s\n", strerror(errno)); + waddstr(glass, ligne); wrefresh(glass); + continue; + } + /*** est-ce la liaison serie ? */ + if (FD_ISSET(fd_remote, &rfds)) { + /* get the incoming byte */ + received = getbyte(fd_remote); + if (verbosity) { + special_dumper(stderr, received); + fflush(stderr); + } + waddch(glass, received); + if ('\n' == received) waddch(glass, '\r'); + } - wrefresh(glass); usleep(155*1000); + /*** est-ce le yuser avec son clavier ? */ + if (FD_ISSET(fd_local, &rfds)) { + received = getch(); + if (verbosity) { + sprintf(ligne, " $%02x from yuser\n", received); + waddstr(glass, ligne); + } + putbyte(fd_remote, received); + } + + wrefresh(glass); } while (! flag_exit); @@ -71,12 +110,12 @@ int run_the_terminal(int fd_serial, char *title, WINDOW *win) WINDOW *terminal, *ecran; int wid_term, hei_term, lin_term, col_term; int foo; -char ligne[100]; -unsigned char byte; +// char ligne[100]; +// unsigned char byte; int fd_stdin; lin_term = col_term = 4; /* position */ -wid_term = 40; +wid_term = 60; hei_term = 25; fd_stdin = fileno(stdin); /* for select or pool */ @@ -94,13 +133,14 @@ if (verbosity) { #if DEBUG_LEVEL > 1 fprintf(stderr, "in '%s', mvwaddstr -> %d\n", __func__, foo); #endif - wrefresh(ecran); sleep(2); + wrefresh(ecran); sleep(1); } foo = interactive(ecran, fd_stdin, fd_serial); - -sleep(1); - +if (foo) { + fprintf(stderr, "interactive -> %d\n", foo); + sleep(1); + } delwin(terminal); touchwin(stdscr); wrefresh(stdscr);