From dcc394a0888dc43bdd952bec9d0058e4631055da Mon Sep 17 00:00:00 2001 From: phyto Date: Thu, 16 May 2019 12:28:47 +0200 Subject: [PATCH] added the K parameter --- essai.c | 6 ++++- serial/t.c | 24 +++++++++++++++++--- ui/t.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 ui/t.c diff --git a/essai.c b/essai.c index 63ff8f6..c852d0e 100644 --- a/essai.c +++ b/essai.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include "core/utils.h" @@ -17,6 +17,7 @@ int verbosity; + /* --------------------------------------------------------------- */ int traite_les_messages(int sfd, int nbloops) { @@ -115,6 +116,7 @@ void help(int k) { puts("options : "); puts("\t-d\tserial device to read."); +puts("\t-K\tset the K parameter."); puts("\t-v\tincrease verbosity."); exit(0); } @@ -125,12 +127,14 @@ int main(int argc, char *argv[]) int opt; int serial_in; char *device = "/dev/ttyACM0"; +int K = 0; char ligne[100]; while ((opt = getopt(argc, argv, "d:hv")) != -1) { switch (opt) { case 'd': device = optarg; break; case 'h': help(0); break; + case 'K': K = atoi(optarg); break; case 'v': verbosity++; break; default: break; } diff --git a/serial/t.c b/serial/t.c index 7d69f5b..ade83a6 100644 --- a/serial/t.c +++ b/serial/t.c @@ -108,24 +108,30 @@ void help(int k) { puts("options : "); puts("\t-d\tserial device to read."); +puts("\t-K\tset the K parameter."); puts("\t-n\tnumber of records to grab."); +puts("\t-t\tselect the function"); puts("\t-v\tincrease verbosity."); } /* ---------------------------------------------------------------- */ int main (int argc, char *argv[]) { int serial_in; -char *device = "/dev/ttyACM0"; -int nbre, speed, opt; +char *device = "/dev/ttyS0"; +int nbre, speed, opt, K=0; +int param, retv; /* set some default values */ verbosity = 0; nbre = 25; speed = 9600; +param = 1; while ((opt = getopt(argc, argv, "d:n:vh")) != -1) { switch (opt) { + case 'p': param = atoi(optarg); break; case 'v': verbosity++; break; + case 'K': K = atoi(optarg); break; case 'n': nbre = atoi(optarg); break; case 'd': device = optarg; break; case 'h': help(0); exit(0); @@ -151,7 +157,19 @@ if (serial_in < 0) { fprintf(stderr, "going to listen on %d\n", serial_in); -(void)loop(serial_in, nbre); +switch (param) { + case 0: + retv = loop(serial_in, nbre); + break; + case 1: + retv = essai_terminal(serial_in, device, 0); + break; + default: + retv = -1; + break; + } + +fprintf(stderr, "Returned value is %d\n", retv); return 0; } diff --git a/ui/t.c b/ui/t.c new file mode 100644 index 0000000..8151a99 --- /dev/null +++ b/ui/t.c @@ -0,0 +1,65 @@ +/* + * essais de gadgets UI + */ + +#include +#include +#include + +#include + +#include "../serial/serial.h" +#include "terminal.h" + +int verbosity; + + +/* ---------------------------------------------------------------- */ +void help(int k) +{ +puts("options : "); +puts("\t-d\tserial device to read."); +puts("\t-K\tset the K parameter."); +puts("\t-v\tincrease verbosity."); + +exit(0); +} +/* ---------------------------------------------------------------- */ +int main(int argc, char *argv[]) +{ +int opt, foo; +int serial_in; +char *device = "/dev/ttyS0"; +int K = 0; +char ligne[100]; + +while ((opt = getopt(argc, argv, "d:hv")) != -1) { + switch (opt) { + case 'd': device = optarg; break; + case 'h': help(0); break; + case 'K': K = atoi(optarg); break; + case 'v': verbosity++; break; + default: break; + } + } + +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); + exit(1); + } + +sleep(1); + +foo = essai_terminal(serial_in, device, K); + +return 0; +} +/* ---------------------------------------------------------------- */ +