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

3
.gitignore vendored
View File

@ -28,5 +28,6 @@ viz/*.a
audio/t audio/t
audio/*.wav audio/*.wav
hi/log.* ui/log.*
ui/t

View File

@ -10,6 +10,8 @@
#include "serial.h" #include "serial.h"
extern int verbosity;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
static int baudrate2const(int bauds) static int baudrate2const(int bauds)
{ {
@ -107,6 +109,11 @@ tcsetattr(uart0, TCSANOW, &options);
tcflush(uart0, TCIFLUSH); /* do it again, sam */ tcflush(uart0, TCIFLUSH); /* do it again, sam */
if (verbosity) {
fprintf(stderr, "%s %s uart0 = %d\n",
__FILE__, __func__, uart0);
}
return uart0; return uart0;
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */

View File

@ -18,7 +18,7 @@ if (param->magic != 0xfde9) {
return 1; return 1;
} }
if (param->delai < 100) { if (param->delai < 100) {
prtln("delay too short"); prt(param->delai); prtln("delay too short");
return 2; return 2;
} }
delta = param->temp_maxi - param->temp_mini; 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) { void test_relais(short nb) {
short foo; short foo;
prtln("test du relais frigo"); prtln("test du relais frigo");
for (foo=0; foo<nb; foo++) { for (foo=0; foo<nb; foo++) {
digitalWrite(RELAIS_FRIGO, HIGH); controle_frigo(1);
delay(parametres.delai); delay(parametres.delai);
digitalWrite(RELAIS_FRIGO, LOW); controle_frigo(1);
delay(parametres.delai); delay(parametres.delai);
} }
} }
@ -189,11 +191,14 @@ do {
case 'h': hexdump((unsigned char *)&parametres, case 'h': hexdump((unsigned char *)&parametres,
sizeof(Global)); break; sizeof(Global)); break;
case 's': setvalue(line, &parametres); break; case 's': setvalue(line, &parametres); break;
case 'T': test_relais(5); break;
case 'v': validate_config(&parametres); break; case 'v': validate_config(&parametres); break;
case '+': controle_frigo(1); break; case '+': controle_frigo(1); break;
case '-': controle_frigo(0); break; case '-': controle_frigo(0); break;
case '1': controle_ventilo(1); break;
case '0': controle_ventilo(0); break;
case 'T': test_relais(5); break;
default: prtln("gni ?"); break; default: prtln("gni ?"); break;
} }

View File

@ -125,6 +125,12 @@ void loop() {
case '-': /* eteint le frigo */ case '-': /* eteint le frigo */
controle_frigo(0); controle_frigo(0);
break; break;
case '1': /* allume le ventilo */
controle_ventilo(1);
break;
case '0': /* eteint le ventilo */
controle_ventilo(0);
break;
default: default:
prtln("M bad control code"); prtln("M bad control code");
break; break;

41
ui/t.c
View File

@ -13,8 +13,38 @@
int verbosity; 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) void help(int k)
{ {
puts("options : "); puts("options : ");
@ -31,7 +61,7 @@ int opt, foo;
int serial_in; int serial_in;
char *device = "/dev/ttyS0"; char *device = "/dev/ttyS0";
int K = 0; int K = 0;
char ligne[100]; // char ligne[100];
while ((opt = getopt(argc, argv, "d:hv")) != -1) { while ((opt = getopt(argc, argv, "d:hv")) != -1) {
switch (opt) { 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); printf("*** device: %s\n", device);
sleep(1);
serial_in = prepare_UART(device, 9600); serial_in = prepare_UART(device, 9600);
if (serial_in < 0) { if (serial_in < 0) {
fprintf(stderr, "\n%s : open device : error %d on %s\n", fprintf(stderr, "err open %s : %d\n", device, serial_in);
argv[0], serial_in, device);
exit(1); exit(1);
} }

View File

@ -6,6 +6,9 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/select.h> #include <sys/select.h>
#include <ncurses.h> #include <ncurses.h>
@ -15,6 +18,8 @@
extern int verbosity; extern int verbosity;
int special_dumper(FILE *fp, unsigned char octet);
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
static void bordure(WINDOW * w, char *texte, int type) 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; int flag_exit = 0;
long tstart, tcur; long tstart, tcur;
char ligne[100]; char ligne[100];
int received;
/* --- variables for select */ /* --- variables for select */
struct timeval tv; struct timeval tv;
fd_set rfds; fd_set rfds;
int retval; int retval,mfd;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__,
@ -46,18 +52,51 @@ tstart = time(NULL);
wclear(glass); wrefresh(glass); 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 { do {
tcur = time(NULL); tcur = time(NULL);
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(fd_local, &rfds); /* stdin */ FD_SET(fd_local, &rfds); /* stdin */
FD_SET(fd_remote, &rfds); /* teletype */ 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); } while (! flag_exit);
@ -71,12 +110,12 @@ int run_the_terminal(int fd_serial, char *title, WINDOW *win)
WINDOW *terminal, *ecran; WINDOW *terminal, *ecran;
int wid_term, hei_term, lin_term, col_term; int wid_term, hei_term, lin_term, col_term;
int foo; int foo;
char ligne[100]; // char ligne[100];
unsigned char byte; // unsigned char byte;
int fd_stdin; int fd_stdin;
lin_term = col_term = 4; /* position */ lin_term = col_term = 4; /* position */
wid_term = 40; wid_term = 60;
hei_term = 25; hei_term = 25;
fd_stdin = fileno(stdin); /* for select or pool */ fd_stdin = fileno(stdin); /* for select or pool */
@ -94,13 +133,14 @@ if (verbosity) {
#if DEBUG_LEVEL > 1 #if DEBUG_LEVEL > 1
fprintf(stderr, "in '%s', mvwaddstr -> %d\n", __func__, foo); fprintf(stderr, "in '%s', mvwaddstr -> %d\n", __func__, foo);
#endif #endif
wrefresh(ecran); sleep(2); wrefresh(ecran); sleep(1);
} }
foo = interactive(ecran, fd_stdin, fd_serial); foo = interactive(ecran, fd_stdin, fd_serial);
if (foo) {
sleep(1); fprintf(stderr, "interactive -> %d\n", foo);
sleep(1);
}
delwin(terminal); delwin(terminal);
touchwin(stdscr); wrefresh(stdscr); touchwin(stdscr); wrefresh(stdscr);