Browse Source

random things...

tth 7 months ago
parent
commit
254ae77e1a
6 changed files with 31 additions and 16 deletions
  1. 1
    0
      .gitignore
  2. 1
    0
      BUILD.txt
  3. 1
    1
      core/config.h
  4. 4
    5
      core/dd2-monitor.conf
  5. 23
    9
      core/parseconf.c
  6. 1
    1
      core/t.c

+ 1
- 0
.gitignore View File

@@ -4,6 +4,7 @@ fake-values
4 4
 essai
5 5
 serial/t
6 6
 core/t
7
+core/*.a
7 8
 
8 9
 doc/*.toc
9 10
 doc/*.log

+ 1
- 0
BUILD.txt View File

@@ -11,6 +11,7 @@ First step, build some parts of the core library :
11 11
 
12 12
 Then you must have datas for working on. One source of datas
13 13
 is the four values who came from the Arduino over serial line.
14
+At this time, you must look at the configuration file.
14 15
 
15 16
 	$ cd serial
16 17
 	$ make t

+ 1
- 1
core/config.h View File

@@ -8,7 +8,7 @@ typedef struct {
8 8
 
9 9
 	int	valid;
10 10
 	
11
-
11
+	char	*input_device;
12 12
 
13 13
 
14 14
 	} Configuration;

+ 4
- 5
core/dd2-monitor.conf View File

@@ -1,10 +1,9 @@
1
-
1
+#
2 2
 # experimental config file
3
+#
3 4
 
4
-
5
-input_device	s	/def/ttyACM0
6
-
7
-
5
+input_device	s	/dev/ttyACM0
6
+input_speed	s	9600
8 7
 
9 8
 
10 9
 

+ 23
- 9
core/parseconf.c View File

@@ -10,13 +10,14 @@
10 10
 extern int 			verbosity;
11 11
 extern Configuration		config;
12 12
 
13
-#define  CMP(a)   (!strcmp(cptr, a))
13
+#define  CMP(a)   (!strcmp(keyptr, a))
14 14
 
15 15
 /* ---------------------------------------------------------------- */
16 16
 int parse_config(char *fname, int flags)
17 17
 {
18 18
 FILE		*fp;
19
-char		line[SZ_STRINGS+1], *cptr;
19
+char		line[SZ_STRINGS+1],
20
+		*keyptr, *typeptr, *cptr;
20 21
 int		numligne;
21 22
 
22 23
 #if DEBUG_LEVEL
@@ -49,23 +50,35 @@ while (fgets(line, SZ_STRINGS, fp))
49 50
 		}
50 51
 
51 52
 	/* seek for the first token in this line */
52
-	if (NULL==(cptr = strtok(line, " \t"))) {
53
+	if (NULL==(keyptr = strtok(line, " \t"))) {
53 54
 		/* Got an empty line */
54 55
 		continue;
55 56
 		}
56
-
57 57
 	/* skip comments */
58
-	if ('#'==*cptr)		continue;
59
-
60
-	if(verbosity)	fprintf(stderr, "[%s]\n", cptr);
58
+	if ('#'==*keyptr)		continue;
59
+	/* seek for the type field */
60
+	if (NULL==(typeptr = strtok(NULL, " \t"))) {
61
+		/* we can(t get a type flag ? wtf ? */
62
+		fprintf(stderr, "ERROR line %d : no type\n", numligne); 
63
+		continue;
64
+		}
61 65
 
66
+	if(verbosity)
67
+		fprintf(stderr, "[%s] type %s\n", keyptr, typeptr);
62 68
 
69
+	if CMP("abort") { 
70
+		fprintf(stderr, "abort in config file\n");
71
+		}
63 72
 
73
+	if (CMP("input_device")) {
74
+		config.input_device = strdup(strtok(NULL, " \t"));
75
+		continue;
76
+		}
64 77
 	}
65 78
 
66 79
 fclose(fp);
67 80
 
68
-return -1;
81
+return 0;
69 82
 }
70 83
 /* ---------------------------------------------------------------- */
71 84
 int show_config(char *title)
@@ -75,7 +88,8 @@ if (verbosity) {
75 88
 	printf("********** %s **********\n", title);
76 89
 	}
77 90
 
78
-printf("valid         %d\n", config.valid);
91
+printf("valid           :  %d\n", config.valid);
92
+printf("input device    :  %s\n", config.input_device);
79 93
 
80 94
 puts("");
81 95
 return 0;

+ 1
- 1
core/t.c View File

@@ -42,7 +42,7 @@ while ((opt = getopt(argc, argv, "v")) != -1) {
42 42
 	}
43 43
 
44 44
 
45
-foo = parse_config(conffile, 1);
45
+foo = parse_config(conffile, 0);
46 46
 fprintf(stderr, "parse_config(%s) -> %d\n\n", conffile, foo);
47 47
 show_config("foo");
48 48
 

Loading…
Cancel
Save