serial/ structuration du code
This commit is contained in:
parent
704a51d3b2
commit
dd359c9f82
10
serial/essai.sh
Executable file
10
serial/essai.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
DEVICE="/dev/ttyACM0"
|
||||
|
||||
for p in {0..15}
|
||||
do
|
||||
echo pass $p
|
||||
./t ${DEVICE} | tee -a foo.dat
|
||||
sleep 8
|
||||
done
|
@ -34,3 +34,10 @@ for (foo=0; foo<4; foo++) {
|
||||
return value;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int parse4values(char *line, char cflag, float array[4])
|
||||
{
|
||||
|
||||
|
||||
return -777;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
@ -17,5 +17,6 @@ int getline_to(int fd, char *where, int szm, int to_ms);
|
||||
/* auxiliary and test functions */
|
||||
|
||||
int parseXvalue(char *asciidatas, char id);
|
||||
int parse4values(char *line, char cflag, float array[4]);
|
||||
|
||||
|
||||
|
72
serial/t.c
72
serial/t.c
@ -12,38 +12,76 @@
|
||||
#include <fcntl.h> //Used for UART
|
||||
#include <errno.h>
|
||||
#include <termios.h> //Used for UART
|
||||
#include <getopt.h>
|
||||
|
||||
#include "serial.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
int loop(int sfd, int iters)
|
||||
{
|
||||
int count, foo;
|
||||
long temps;
|
||||
char ligne[200];
|
||||
|
||||
for (count=0; count<iters; count++) {
|
||||
foo = getline_to(sfd, ligne, 100, 0);
|
||||
//
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "getline #%d -> %d\n", count, foo);
|
||||
fprintf(stderr, "%s\n", ligne);
|
||||
}
|
||||
foo = parseXvalue(ligne, 'X');
|
||||
//
|
||||
if (foo >= 0) {
|
||||
temps = time(NULL);
|
||||
printf("%ld %d\n", temps, foo);
|
||||
fflush(stdout);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "%s: parse -> %d\n", __func__, foo);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int serial_in, foo, count;
|
||||
char ligne[200];
|
||||
int serial_in;
|
||||
char *device;
|
||||
int nbre, speed, opt;
|
||||
|
||||
if (2 != argc) {
|
||||
fprintf(stderr, "give me a device name, please.\n");
|
||||
return 2;
|
||||
/* set some default values */
|
||||
verbosity = 0;
|
||||
nbre = 25;
|
||||
speed = 9600;
|
||||
device = "/dev/ttyACM0";
|
||||
|
||||
while ((opt = getopt(argc, argv, "d:n:v")) != -1) {
|
||||
switch (opt) {
|
||||
case 'v': verbosity++; break;
|
||||
case 'n': nbre = atoi(optarg); break;
|
||||
case 'd': device = optarg; break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "%s : uh ?", argv[0]);
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
|
||||
serial_in = prepare_UART(argv[1], 9600);
|
||||
}
|
||||
|
||||
serial_in = prepare_UART(device, speed);
|
||||
if (serial_in < 0) {
|
||||
fprintf(stderr, "%s : open device : error %d on %s\n",
|
||||
argv[0], serial_in, device);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "going to listen on %d\n", serial_in);
|
||||
|
||||
for (count=0; count<100000; count++) {
|
||||
foo = getline_to(serial_in, ligne, 100, 0);
|
||||
fprintf(stderr, "getline #%d -> %d\n", count, foo);
|
||||
fprintf(stderr, "%s\n", ligne);
|
||||
foo = parseXvalue(ligne, 'X');
|
||||
// fprintf(stderr, "parse -> %d\n", foo);
|
||||
if (foo>= 0) {
|
||||
printf("%d %d\n", count, foo);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
(void)loop(serial_in, nbre);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user