1
0
Fork 0

bidirectionnal communication, first milestone reached

Dieser Commit ist enthalten in:
phyto 2019-05-14 15:46:49 +02:00
Ursprung 565c70b54f
Commit 6d597e59e8
5 geänderte Dateien mit 69 neuen und 42 gelöschten Zeilen

Datei anzeigen

@ -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 $@
# ---------------------------------------------
# -------------------------------------------------------

75
essai.c
Datei anzeigen

@ -5,6 +5,7 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <curses.h>
#include <time.h>
@ -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<nbloops; idx++) {
if (kbhit()) {
message("!!! KEY !!!");
sleep(2);
static char valid_k[] = "+-";
key = getch();
/* if it is a valid key, send it to the Arduino */
if (NULL!=strchr(valid_k, key)) {
foo = putbyte(sfd, key);
fprintf(stderr, "put byte %02X -> %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

Datei anzeigen

@ -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, " "));

Datei anzeigen

@ -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<NBVAL; foo++) { ptr[foo] /= NB_PASSE; }
digitalWrite(LED_BUILTIN, LOW);
}
/* -------------------------------------------------- */
@ -125,13 +126,13 @@ void loop() {
controle_frigo(0);
break;
default:
Serial.print("M bad control code");
prtln("M bad control code");
break;
}
}
delay(DELAI);
/* ETERNEL LOOP HERE */
/* ETERNAL LOOP END HERE */
}
/* -------------------------------------------------- */

Datei anzeigen

@ -27,7 +27,7 @@ prtln(">>> 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;
}
/* --------------------------------------------------------------- */