diff --git a/Makefile b/Makefile index fd68c20..5499563 100644 --- a/Makefile +++ b/Makefile @@ -6,16 +6,21 @@ CC = gcc CCOPT = -Wall -g CLIB = core/libdd2m-core.a viz/libdd2m-viz.a -all: essai fake-values +all: essai -# --------------------------------------------- +# ------------------------------------------------------- -O = serial/serial.o serial/funcs.o +OSERIAL = serial/serial.o serial/funcs.o -essai: essai.c Makefile $(CLIB) - $(CC) ${CCOPT} $< $(CLIB) ${O} -lncurses -o $@ +essai.o: essai.c Makefile + $(CC) ${CCOPT} $< -c + + +essai: essai.o Makefile $(CLIB) + $(CC) ${CCOPT} $< $(CLIB) ${OSERIAL} -lncurses -o $@ fake-values: fake-values.c Makefile $(CLIB) $(CC) ${CCOPT} $< $(CLIB) -o $@ -# --------------------------------------------- +# ------------------------------------------------------- + diff --git a/essai.c b/essai.c index 1ca1cbf..46b6cc6 100644 --- a/essai.c +++ b/essai.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -17,7 +18,7 @@ int verbosity; /* --------------------------------------------------------------- */ -int affiche_valeurs(int sfd, int nbloops) +int traite_les_messages(int sfd, int nbloops) { int idx, foo, key; char ligne[200]; @@ -27,56 +28,75 @@ FILE *fp; time_t temps, old_temps = (time_t)0L; - -/* XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX */ fp = fopen("serial/foo.dat", "a"); if (NULL==fp) { - fprintf(stderr, "***** error fopen datafile *****\n"); + fprintf(stderr, "*** error fopen datafile ***\n"); return -1; } -/* XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX */ for (idx=0; idx %d\n", + key, foo); + } + else { + sprintf(ligne, "Key 0x%02X invalid ", key); + fprintf(stderr, "%s\n", ligne); + aff_message(ligne); sleep(1); aff_message(""); + } } + + /* here we are waiting for a frame from the + Arduino. In the future, we may have an + finely tunned event-synth system here */ foo = getline_to(sfd, ligne, 100, 0); - - if (*ligne == 'M') { - message(ligne); - } - #if DEBUG_LEVEL if (foo) fprintf(stderr, "get values -> %d\n", foo); #endif - foo = parse4_Ivalues(ligne, 'T', Idatas); + switch (*ligne) { + + case 'M': + case 'L': + aff_message(ligne); + break; + + case 'T': + foo = parse4_Ivalues(ligne, 'T', Idatas); #if DEBUG_LEVEL - if (foo) fprintf(stderr, "parse I val -> %d\n", foo); + if (foo) fprintf(stderr, "parse I val -> %d\n", foo); #endif + values2temperature(Idatas, Fdatas); - values2temperature(Idatas, Fdatas); + for (foo=0; foo<3; foo++) { + sprintf(ligne, "%4d", Idatas[foo]); + minidigit_affstr(stdscr, 12+(12*foo), 8, ligne); + aff7segs_float(stdscr, 8+(12*foo), 55, Fdatas[foo]); + } - for (foo=0; foo<3; foo++) { - sprintf(ligne, "%4d", Idatas[foo]); - minidigit_affstr(stdscr, 12+(12*foo), 8, ligne); - aff7segs_float(stdscr, 8+(12*foo), 55, Fdatas[foo]); - } + /* here we are loging all that temps values */ - /* here we are trying to log all that temps values */ - if (NULL!=fp) { temps = time(NULL); if ((temps-old_temps) > 50) { fprintf(fp, "%ld %f %f %f %f\n", temps, - Fdatas[0], Fdatas[1], Fdatas[2], Fdatas[3]); + Fdatas[0], Fdatas[1], + Fdatas[2], Fdatas[3]); fflush(fp); old_temps = temps; } + break; /* case 'T' */ } + fflush(stderr); /* really WTF? here */ + } fclose(fp); @@ -102,7 +122,7 @@ exit(0); int main(int argc, char *argv[]) { -int opt, foo; +int opt; int serial_in; char *device = "/dev/ttyACM0"; @@ -115,21 +135,24 @@ while ((opt = getopt(argc, argv, "d:hv")) != -1) { } } +printf("\n**** %s **** compiled the %s at %s ***\n", + argv[0], __DATE__, __TIME__); serial_in = prepare_UART(device, 9600); if (serial_in < 0) { - fprintf(stderr, "%s : open device : error %d on %s\n", + fprintf(stderr, "\n%s : open device : error %d on %s\n", argv[0], serial_in, device); exit(1); } +sleep(1); initscr(); nonl(); cbreak(); noecho(); keypad(stdscr, TRUE); /* acces aux touches 'curseur' */ fond_ecran(" Demonstrator "); -affiche_valeurs(serial_in, 50000000); +traite_les_messages(serial_in, 50000000); /* * plop, on a fini, il faut restaurer la console diff --git a/simulator/rdtemp/cli.ino b/simulator/rdtemp/cli.ino index 19930d5..f05b3e2 100644 --- a/simulator/rdtemp/cli.ino +++ b/simulator/rdtemp/cli.ino @@ -10,8 +10,6 @@ #define DEBUG 0 /* -------------------------------------------------- */ /* some interesting macros */ -#define prt(a) Serial.print(a) -#define prtln(a) Serial.println(a) /* -------------------------------------------------- */ char waitkey(char echo) @@ -78,7 +76,7 @@ static void clihelp() prtln("r\tread config"); prtln("w\twrite config"); prtln("T\ttest relay"); - prtln("0/1\tcontrole frigo"); + prtln("+/-\tcontrole frigo"); prtln("h\thexdump config"); } /* --------------------------------------------------------------- */ @@ -148,7 +146,7 @@ do { prt("$ "); ret = readline(line,TLINE); #if DEBUG > 1 - hexdump((unsigned char *)line, ret); + prt("readline -> "); hexdump((unsigned char *)line, ret); #endif key = *(sptr = strtok(line, " ")); diff --git a/simulator/rdtemp/rdtemp.ino b/simulator/rdtemp/rdtemp.ino index c730ebb..5b48ade 100644 --- a/simulator/rdtemp/rdtemp.ino +++ b/simulator/rdtemp/rdtemp.ino @@ -10,6 +10,9 @@ #define RELAIS_FRIGO 42 #define RELAIS_VENTILO 40 +#define prt(a) Serial.print(a) +#define prtln(a) Serial.println(a) + typedef struct { unsigned short magic; @@ -73,9 +76,7 @@ void updatevalues(short *ptr) delay(50); } } - for (foo=0; foo>> read config"); magic = 0; EEPROM.get(0, magic); -prt("magic is "); prtln(magic); +prt("M magic is "); prtln(magic); if (0xfde9 != magic) return -1; EEPROM.get(0, *where); return -2; @@ -61,7 +61,7 @@ prtln(""); prt("Delay : "); prtln(what->delai); prt("Temp mini : "); prtln(what->temp_mini); prt("Temp maxi : "); prtln(what->temp_maxi); - +prt("Control : "); prtln(what->control); return -1; } /* --------------------------------------------------------------- */