Browse Source

added the K parameter

phyto 6 months ago
parent
commit
dcc394a088
3 changed files with 91 additions and 4 deletions
  1. 5
    1
      essai.c
  2. 21
    3
      serial/t.c
  3. 65
    0
      ui/t.c

+ 5
- 1
essai.c View File

@@ -7,7 +7,7 @@
7 7
 #include	<stdlib.h>
8 8
 #include	<ctype.h>
9 9
 #include	<string.h>
10
-#include	<curses.h>
10
+#include	<ncurses.h>
11 11
 #include	<time.h>
12 12
 
13 13
 #include	"core/utils.h"
@@ -17,6 +17,7 @@
17 17
 
18 18
 int	verbosity;
19 19
 
20
+
20 21
 /* --------------------------------------------------------------- */
21 22
 int traite_les_messages(int sfd, int nbloops)
22 23
 {
@@ -115,6 +116,7 @@ void help(int k)
115 116
 {
116 117
 puts("options : ");
117 118
 puts("\t-d\tserial device to read.");
119
+puts("\t-K\tset the K parameter.");
118 120
 puts("\t-v\tincrease verbosity.");
119 121
 exit(0);
120 122
 }
@@ -125,12 +127,14 @@ int main(int argc, char *argv[])
125 127
 int		opt;
126 128
 int		serial_in;
127 129
 char		*device = "/dev/ttyACM0";
130
+int		K = 0;
128 131
 char		ligne[100];
129 132
 
130 133
 while ((opt = getopt(argc, argv, "d:hv")) != -1) {
131 134
 	switch (opt) {
132 135
 		case 'd':	device = optarg;	break;
133 136
 		case 'h':	help(0);		break;
137
+		case 'K':	K = atoi(optarg);	break;
134 138
 		case 'v':	verbosity++;		break;
135 139
 		default:				break;
136 140
 		}

+ 21
- 3
serial/t.c View File

@@ -108,24 +108,30 @@ void help(int k)
108 108
 {
109 109
 puts("options : ");
110 110
 puts("\t-d\tserial device to read.");
111
+puts("\t-K\tset the K parameter.");
111 112
 puts("\t-n\tnumber of records to grab.");
113
+puts("\t-t\tselect the function");
112 114
 puts("\t-v\tincrease verbosity.");
113 115
 }
114 116
 /* ---------------------------------------------------------------- */
115 117
 int main (int argc, char *argv[])
116 118
 {
117 119
 int		serial_in;
118
-char		*device = "/dev/ttyACM0";
119
-int		nbre, speed, opt;
120
+char		*device = "/dev/ttyS0";
121
+int		nbre, speed, opt, K=0;
122
+int		param, retv;
120 123
 
121 124
 /* set some default values */
122 125
 verbosity	= 0;
123 126
 nbre		= 25;
124 127
 speed		= 9600;
128
+param		= 1;
125 129
 
126 130
 while ((opt = getopt(argc, argv, "d:n:vh")) != -1) {
127 131
 	switch (opt) {
132
+		case 'p':	param = atoi(optarg);	break;
128 133
 		case 'v':	verbosity++;		break;
134
+		case 'K':	K = atoi(optarg);	break;
129 135
 		case 'n':	nbre = atoi(optarg);	break;
130 136
 		case 'd':	device = optarg;	break;
131 137
 		case 'h':	help(0);		exit(0);
@@ -151,7 +157,19 @@ if (serial_in < 0) {
151 157
 
152 158
 fprintf(stderr, "going to listen on %d\n", serial_in);
153 159
 
154
-(void)loop(serial_in, nbre);
160
+switch (param) {
161
+	case 0:
162
+		retv = loop(serial_in, nbre);
163
+		break;
164
+	case 1:
165
+		retv = essai_terminal(serial_in, device, 0);
166
+		break;
167
+	default:
168
+		retv = -1;
169
+		break;
170
+	}
171
+
172
+fprintf(stderr, "Returned value is %d\n", retv);
155 173
 
156 174
 return 0;
157 175
 }

+ 65
- 0
ui/t.c View File

@@ -0,0 +1,65 @@
1
+/*
2
+ *		essais de gadgets UI
3
+ */
4
+
5
+#include  <stdio.h>
6
+#include <stdlib.h>
7
+#include <unistd.h>
8
+
9
+#include  <ncurses.h>
10
+
11
+#include  "../serial/serial.h"
12
+#include  "terminal.h"
13
+
14
+int	verbosity;
15
+
16
+
17
+/* ---------------------------------------------------------------- */
18
+void help(int k)
19
+{
20
+puts("options : ");
21
+puts("\t-d\tserial device to read.");
22
+puts("\t-K\tset the K parameter.");
23
+puts("\t-v\tincrease verbosity.");
24
+
25
+exit(0);
26
+}
27
+/* ---------------------------------------------------------------- */
28
+int main(int argc, char *argv[])
29
+{
30
+int		opt, foo;
31
+int		serial_in;
32
+char		*device = "/dev/ttyS0";
33
+int		K = 0;
34
+char		ligne[100];
35
+
36
+while ((opt = getopt(argc, argv, "d:hv")) != -1) {
37
+	switch (opt) {
38
+		case 'd':	device = optarg;	break;
39
+		case 'h':	help(0);		break;
40
+		case 'K':	K = atoi(optarg);	break;
41
+		case 'v':	verbosity++;		break;
42
+		default:				break;
43
+		}
44
+	}
45
+
46
+printf("\n*** compiled %s %s ***\n", __DATE__, __TIME__);
47
+printf("*** device: %s\n", device);
48
+
49
+sleep(1);
50
+
51
+serial_in = prepare_UART(device, 9600);
52
+if (serial_in < 0) {
53
+	fprintf(stderr, "\n%s : open device : error %d on %s\n",
54
+				argv[0], serial_in, device);
55
+	exit(1);
56
+	}
57
+
58
+sleep(1);
59
+
60
+foo = essai_terminal(serial_in, device, K);
61
+
62
+return 0;
63
+}
64
+/* ---------------------------------------------------------------- */
65
+

Loading…
Cancel
Save