Browse Source

first lut function

tth 1 year ago
parent
commit
ae4c5334d0
6 changed files with 155 additions and 2 deletions
  1. 13
    0
      core/Makefile
  2. 17
    0
      core/lut1024.h
  3. 69
    0
      core/lut1024f.c
  4. 10
    0
      core/mklut.pl
  5. 45
    0
      core/t.c
  6. 1
    2
      serial/t.c

+ 13
- 0
core/Makefile View File

@@ -0,0 +1,13 @@
1
+#
2
+#
3
+#
4
+
5
+lut1024f.o:	lut1024f.c lut1024.h
6
+	gcc -Wall -c $<
7
+
8
+t:	t.c lut1024f.o  lut1024.h
9
+	gcc -Wall $< lut1024f.o -o $@
10
+
11
+foo.lut1024f:	mklut.pl Makefile
12
+	./mklut.pl quux > $@
13
+

+ 17
- 0
core/lut1024.h View File

@@ -0,0 +1,17 @@
1
+/*
2
+ *	LUT 1024 - DEALING WITH DISCRETE VALUES 
3
+ */
4
+
5
+
6
+typedef struct {
7
+	int		flags;
8
+	float		vals[1024];
9
+	} Lut1024f;
10
+
11
+/* ---------------------------------------------------------------- */
12
+
13
+int slurp_lut1024f(FILE *fp, Lut1024f *where, int notused);
14
+int load_lut1024f(char *fname, Lut1024f *where, int notused);
15
+
16
+/* ---------------------------------------------------------------- */
17
+

+ 69
- 0
core/lut1024f.c View File

@@ -0,0 +1,69 @@
1
+/*
2
+ *	LUT 1024 -> FLOAT
3
+ */
4
+
5
+#include	<stdio.h>
6
+#include	<stdlib.h>
7
+#include 	<string.h>
8
+
9
+#include	"lut1024.h"
10
+
11
+extern int	verbosity;
12
+
13
+/* ---------------------------------------------------------------- */
14
+
15
+int slurp_lut1024f(FILE *fp, Lut1024f *where, int notused)
16
+{
17
+int	count, foo;
18
+
19
+for(count=0; count<1024; count++) {
20
+	foo = fscanf(fp, "%f", &where->vals[foo]);
21
+	if (1 != foo) {
22
+		fprintf(stderr, "%s: bad read %d\n", __func__, foo);
23
+		return -2;
24
+		}
25
+	}
26
+
27
+return -1;
28
+}
29
+
30
+/* ---------------------------------------------------------------- */
31
+
32
+int load_lut1024f(char *fname, Lut1024f *where, int notused)
33
+{
34
+FILE	*fplut;
35
+char	firstline[100];
36
+char	label[] = "LUT1024F";
37
+int	foo;
38
+
39
+#if DEBUG_LEVEL
40
+fprintg(stderr, ">>> %s ( '%s' %p %d )\n", __func__,
41
+			fname, where, notused);
42
+#endif
43
+
44
+if (NULL==(fplut=fopen(fname, "r"))) {
45
+	perror(fname);
46
+	return -2;
47
+	}
48
+
49
+fprintf(stderr, "%s: getting first line\n", __func__);
50
+
51
+if (NULL==fgets(firstline, 20, fplut)) {
52
+	fprintf(stderr, "%s: nothing to read from %s\n",
53
+					__func__, fname);
54
+	return -3;
55
+	}
56
+
57
+foo = strncmp(label, firstline, sizeof(label)-1);
58
+if (foo) {
59
+	fprintf(stderr, "%s: bad label [%s]\n", __func__, firstline);
60
+	exit(5);
61
+	}
62
+
63
+
64
+fclose(fplut);
65
+
66
+return -1;
67
+}
68
+
69
+/* ---------------------------------------------------------------- */

+ 10
- 0
core/mklut.pl View File

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

+ 45
- 0
core/t.c View File

@@ -0,0 +1,45 @@
1
+/*
2
+ *	main de test des core functions
3
+ */
4
+
5
+#include  <stdio.h>
6
+#include  <stdlib.h>
7
+#include  <getopt.h>
8
+
9
+#include	"lut1024.h"
10
+
11
+
12
+int verbosity;
13
+
14
+/* ---------------------------------------------------------------- */
15
+
16
+int main (int argc, char *argv[])
17
+{
18
+int		foo, opt;
19
+
20
+/* set some default values */
21
+verbosity	= 0;
22
+
23
+
24
+while ((opt = getopt(argc, argv, "v")) != -1) {
25
+	switch (opt) {
26
+		case 'v':	verbosity++;		break;
27
+
28
+
29
+		default:
30
+			fprintf(stderr, "%s : uh ?", argv[0]);
31
+			exit(1);
32
+			break;
33
+		}
34
+
35
+	}
36
+
37
+
38
+foo = load_lut1024f("foo.lut1024f", NULL, 1);
39
+
40
+fprintf(stderr, "chargement de la lut --> %d\n", foo);
41
+
42
+return 0;
43
+}
44
+
45
+/* ---------------------------------------------------------------- */

+ 1
- 2
serial/t.c View File

@@ -53,14 +53,13 @@ return 0;
53 53
 int main (int argc, char *argv[])
54 54
 {
55 55
 int		serial_in;
56
-char		*device;
56
+char		*device = "/dev/ttyACM0";
57 57
 int		nbre, speed, opt;
58 58
 
59 59
 /* set some default values */
60 60
 verbosity	= 0;
61 61
 nbre		= 25;
62 62
 speed		= 9600;
63
-device		= "/dev/ttyACM0";
64 63
 
65 64
 while ((opt = getopt(argc, argv, "d:n:v")) != -1) {
66 65
 	switch (opt) {

Loading…
Cancel
Save