Browse Source

serial over USB is evil, really evil

tth 1 year ago
parent
commit
73348c2339
2 changed files with 34 additions and 11 deletions
  1. 33
    10
      serial/t.c
  2. 1
    1
      simulator/send-random/send-random.ino

+ 33
- 10
serial/t.c View File

@@ -3,17 +3,41 @@
3 3
 #include  <stdio.h>
4 4
 #include  <stdlib.h>
5 5
 #include  <time.h>
6
+#include  <unistd.h>			//Used for UART
7
+#include  <fcntl.h>			//Used for UART
8
+#include  <errno.h>
6 9
 
7 10
 #include  "serial.h"
8 11
 
9 12
 int	verbosity;
10 13
 
14
+/* ----------------------------------------------------- */
15
+int openserial(char *dev)
16
+{
17
+int	uart;
18
+
19
+fprintf(stderr, "%s ( %s )\n", __func__, dev);
20
+uart = open(dev, O_RDONLY | O_NOCTTY);
21
+if (uart < 0)
22
+	{
23
+	perror("unable to open uart");
24
+	return -1;
25
+	}
26
+return uart;
27
+}
28
+/* ----------------------------------------------------- */
29
+
11 30
 int main (int argc, char *argv[])
12 31
 {
13
-int		serial_in;
14
-int		byte;
32
+int		serial_in, foo;
33
+unsigned char	byte;
15 34
 
16
-serial_in = prepare_UART("/dev/ttyACM0", 9600);
35
+if (2 != argc) {
36
+	fprintf(stderr, "device name ?\n");
37
+	return 2;
38
+	}
39
+
40
+serial_in = openserial(argv[1]);
17 41
 fprintf(stderr, "prepare uart -> %d\n", serial_in);
18 42
 
19 43
 if (serial_in < 0) {
@@ -21,17 +45,16 @@ if (serial_in < 0) {
21 45
 	}
22 46
 
23 47
 for (;;) {
24
-
25
-	byte = getbyte(serial_in);
26
-
27
-	if (byte < 0) {
28
-		fprintf(stderr, "get byte : err is %d\n", byte);
48
+	foo = read(serial_in, &byte, 1);
49
+	if (1 != foo) {
50
+		fprintf(stderr, "get byte : err is %d\n", errno);
29 51
 		}
30 52
 	else	{
31
-		printf("%9ld  %02x/%d\n",
32
-			time(NULL), byte, byte);
53
+		printf("%9ld  %02x/%d\n", time(NULL), byte, byte);
33 54
 		}
34 55
 	}
35 56
 
36 57
 return 0;
37 58
 }
59
+
60
+/* ----------------------------------------------------- */

+ 1
- 1
simulator/send-random/send-random.ino View File

@@ -48,7 +48,7 @@ void sendvalues(void)
48 48
 void loop() {
49 49
   updatevalues();
50 50
   sendvalues();
51
-  delay(5000);
51
+  delay(1000);
52 52
 }
53 53
 
54 54
 /* -------------------------------------------------- */

Loading…
Cancel
Save