first lut function

This commit is contained in:
tth 2019-01-14 03:20:54 +01:00
parent 9becddcdac
commit ae4c5334d0
6 changed files with 155 additions and 2 deletions

13
core/Makefile Normal file
View File

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

17
core/lut1024.h Normal file
View File

@ -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);
/* ---------------------------------------------------------------- */

69
core/lut1024f.c Normal file
View File

@ -0,0 +1,69 @@
/*
* LUT 1024 -> FLOAT
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}
/* ---------------------------------------------------------------- */

10
core/mklut.pl Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/perl
my $foo;
print "LUT1024F\n";
for ($foo=0; $foo<1024; $foo++) {
print rand()*3.30, "\n";
}
0;

45
core/t.c Normal file
View File

@ -0,0 +1,45 @@
/*
* main de test des core functions
*/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#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;
}
/* ---------------------------------------------------------------- */

View File

@ -53,14 +53,13 @@ return 0;
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
int serial_in; int serial_in;
char *device; char *device = "/dev/ttyACM0";
int nbre, speed, opt; int nbre, speed, opt;
/* set some default values */ /* set some default values */
verbosity = 0; verbosity = 0;
nbre = 25; nbre = 25;
speed = 9600; speed = 9600;
device = "/dev/ttyACM0";
while ((opt = getopt(argc, argv, "d:n:v")) != -1) { while ((opt = getopt(argc, argv, "d:n:v")) != -1) {
switch (opt) { switch (opt) {