terminal is working, but expect some bugs...

This commit is contained in:
phyto
2019-05-20 14:49:31 +02:00
parent 6ad5283de9
commit 54a41cfeb3
6 changed files with 112 additions and 26 deletions

41
ui/t.c
View File

@@ -13,8 +13,38 @@
int verbosity;
/* ---------------------------------------------------------------- */
int special_dumper(FILE *fp, unsigned char octet)
{
static int idx = 0;
static unsigned char buffer[16];
int foo, c;
#if DEBUG_LEVEL > 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);
}

View File

@@ -6,6 +6,9 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/select.h>
#include <ncurses.h>
@@ -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);