Browse Source

serial : this patch need a real-life test

tth 1 year ago
parent
commit
d75dba1954
2 changed files with 18 additions and 11 deletions
  1. 2
    1
      .gitignore
  2. 16
    10
      serial/serial.c

+ 2
- 1
.gitignore View File

@@ -1,7 +1,8 @@
1 1
 a.out
2 2
 *.o
3 3
 fake-values
4
-essai serial/t
4
+essai
5
+serial/t
5 6
 doc/*.toc doc/*.log doc/*.aux doc/*.pdf
6 7
 
7 8
 

+ 16
- 10
serial/serial.c View File

@@ -146,21 +146,27 @@ retval = retval < 0 ? -1 : retval;
146 146
 switch (retval) {
147 147
 
148 148
 	case -1:
149
-		fprintf(stderr, "omg ?\n");		break;
149
+		fprintf(stderr, "omg ?\n");
150
+		byte = -1;
151
+		break;
150 152
 
151 153
 	case 0:
152
-		fprintf(stderr, "timeout\n");		break;
153
-
154
-
154
+		fprintf(stderr, "timeout\n");
155
+		byte = -99;
156
+		break;
155 157
 
156 158
 	default:
157
-		return -99;
159
+		if (retval==fd) {
160
+			read(fd, &byte, 1);
161
+			fprintf(stderr, "got 0x%02x\n", byte);
162
+			}
163
+		else	{
164
+			fprintf(stderr, "%d bad fd ?\n", retval);
165
+			byte = -3;
166
+			}
167
+		break;
158 168
 	}
159 169
 
160
-
161
-
162
-
163
-
164
-return -3;
170
+return byte;
165 171
 }
166 172
 /* -------------------------------------------------------------------- */

Loading…
Cancel
Save