From ae4c5334d0479f7beb25ce82455271b6129ea6dd Mon Sep 17 00:00:00 2001 From: tth Date: Mon, 14 Jan 2019 03:20:54 +0100 Subject: [PATCH] first lut function --- core/Makefile | 13 ++++++++++ core/lut1024.h | 17 ++++++++++++ core/lut1024f.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ core/mklut.pl | 10 +++++++ core/t.c | 45 ++++++++++++++++++++++++++++++++ serial/t.c | 3 +-- 6 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 core/Makefile create mode 100644 core/lut1024.h create mode 100644 core/lut1024f.c create mode 100755 core/mklut.pl create mode 100644 core/t.c diff --git a/core/Makefile b/core/Makefile new file mode 100644 index 0000000..766f682 --- /dev/null +++ b/core/Makefile @@ -0,0 +1,13 @@ +# +# +# + +lut1024f.o: lut1024f.c lut1024.h + gcc -Wall -c $< + +t: t.c lut1024f.o lut1024.h + gcc -Wall $< lut1024f.o -o $@ + +foo.lut1024f: mklut.pl Makefile + ./mklut.pl quux > $@ + diff --git a/core/lut1024.h b/core/lut1024.h new file mode 100644 index 0000000..f271685 --- /dev/null +++ b/core/lut1024.h @@ -0,0 +1,17 @@ +/* + * LUT 1024 - DEALING WITH DISCRETE VALUES + */ + + +typedef struct { + int flags; + float vals[1024]; + } Lut1024f; + +/* ---------------------------------------------------------------- */ + +int slurp_lut1024f(FILE *fp, Lut1024f *where, int notused); +int load_lut1024f(char *fname, Lut1024f *where, int notused); + +/* ---------------------------------------------------------------- */ + diff --git a/core/lut1024f.c b/core/lut1024f.c new file mode 100644 index 0000000..accf37b --- /dev/null +++ b/core/lut1024f.c @@ -0,0 +1,69 @@ +/* + * LUT 1024 -> FLOAT + */ + +#include +#include +#include + +#include "lut1024.h" + +extern int verbosity; + +/* ---------------------------------------------------------------- */ + +int slurp_lut1024f(FILE *fp, Lut1024f *where, int notused) +{ +int count, foo; + +for(count=0; count<1024; count++) { + foo = fscanf(fp, "%f", &where->vals[foo]); + if (1 != foo) { + fprintf(stderr, "%s: bad read %d\n", __func__, foo); + return -2; + } + } + +return -1; +} + +/* ---------------------------------------------------------------- */ + +int load_lut1024f(char *fname, Lut1024f *where, int notused) +{ +FILE *fplut; +char firstline[100]; +char label[] = "LUT1024F"; +int foo; + +#if DEBUG_LEVEL +fprintg(stderr, ">>> %s ( '%s' %p %d )\n", __func__, + fname, where, notused); +#endif + +if (NULL==(fplut=fopen(fname, "r"))) { + perror(fname); + return -2; + } + +fprintf(stderr, "%s: getting first line\n", __func__); + +if (NULL==fgets(firstline, 20, fplut)) { + fprintf(stderr, "%s: nothing to read from %s\n", + __func__, fname); + return -3; + } + +foo = strncmp(label, firstline, sizeof(label)-1); +if (foo) { + fprintf(stderr, "%s: bad label [%s]\n", __func__, firstline); + exit(5); + } + + +fclose(fplut); + +return -1; +} + +/* ---------------------------------------------------------------- */ diff --git a/core/mklut.pl b/core/mklut.pl new file mode 100755 index 0000000..d0f1892 --- /dev/null +++ b/core/mklut.pl @@ -0,0 +1,10 @@ +#!/usr/bin/perl + +my $foo; + +print "LUT1024F\n"; + +for ($foo=0; $foo<1024; $foo++) { + print rand()*3.30, "\n"; + } +0; \ No newline at end of file diff --git a/core/t.c b/core/t.c new file mode 100644 index 0000000..df47ff2 --- /dev/null +++ b/core/t.c @@ -0,0 +1,45 @@ +/* + * main de test des core functions + */ + +#include +#include +#include + +#include "lut1024.h" + + +int verbosity; + +/* ---------------------------------------------------------------- */ + +int main (int argc, char *argv[]) +{ +int foo, opt; + +/* set some default values */ +verbosity = 0; + + +while ((opt = getopt(argc, argv, "v")) != -1) { + switch (opt) { + case 'v': verbosity++; break; + + + default: + fprintf(stderr, "%s : uh ?", argv[0]); + exit(1); + break; + } + + } + + +foo = load_lut1024f("foo.lut1024f", NULL, 1); + +fprintf(stderr, "chargement de la lut --> %d\n", foo); + +return 0; +} + +/* ---------------------------------------------------------------- */ diff --git a/serial/t.c b/serial/t.c index fef41c6..eed23c6 100644 --- a/serial/t.c +++ b/serial/t.c @@ -53,14 +53,13 @@ return 0; int main (int argc, char *argv[]) { int serial_in; -char *device; +char *device = "/dev/ttyACM0"; int nbre, speed, opt; /* set some default values */ verbosity = 0; nbre = 25; speed = 9600; -device = "/dev/ttyACM0"; while ((opt = getopt(argc, argv, "d:n:v")) != -1) { switch (opt) {