terminal is working, but expect some bugs...
This commit is contained in:
parent
6ad5283de9
commit
54a41cfeb3
3
.gitignore
vendored
3
.gitignore
vendored
@ -28,5 +28,6 @@ viz/*.a
|
||||
audio/t
|
||||
audio/*.wav
|
||||
|
||||
hi/log.*
|
||||
ui/log.*
|
||||
ui/t
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
@ -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<nb; foo++) {
|
||||
digitalWrite(RELAIS_FRIGO, HIGH);
|
||||
controle_frigo(1);
|
||||
delay(parametres.delai);
|
||||
|
||||
digitalWrite(RELAIS_FRIGO, LOW);
|
||||
controle_frigo(1);
|
||||
delay(parametres.delai);
|
||||
}
|
||||
}
|
||||
@ -189,11 +191,14 @@ do {
|
||||
case 'h': hexdump((unsigned char *)¶metres,
|
||||
sizeof(Global)); break;
|
||||
case 's': setvalue(line, ¶metres); break;
|
||||
case 'T': test_relais(5); break;
|
||||
|
||||
case 'v': validate_config(¶metres); break;
|
||||
|
||||
case '+': controle_frigo(1); 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;
|
||||
}
|
||||
|
@ -125,6 +125,12 @@ void loop() {
|
||||
case '-': /* eteint le frigo */
|
||||
controle_frigo(0);
|
||||
break;
|
||||
case '1': /* allume le ventilo */
|
||||
controle_ventilo(1);
|
||||
break;
|
||||
case '0': /* eteint le ventilo */
|
||||
controle_ventilo(0);
|
||||
break;
|
||||
default:
|
||||
prtln("M bad control code");
|
||||
break;
|
||||
|
41
ui/t.c
41
ui/t.c
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user