Browse Source

adding the 'putbyte' function

phyto 6 months ago
parent
commit
33c96b1a63
3 changed files with 19 additions and 4 deletions
  1. 2
    0
      serial/Makefile
  2. 15
    2
      serial/serial.c
  3. 2
    2
      serial/serial.h

+ 2
- 0
serial/Makefile View File

@@ -1,3 +1,5 @@
1
+# ---------------------------------------------------
2
+#  May be we have to put those objs in a .a ?
1 3
 
2 4
 OPT = -Wall -DDEBUG_LEVEL=0
3 5
 OBJS = serial.o funcs.o

+ 15
- 2
serial/serial.c View File

@@ -122,13 +122,26 @@ byte = 0;
122 122
 foo = read(fd, &byte, 1);
123 123
 if (1 != foo)
124 124
         {
125
-	fprintf(stderr, "byte %d rd %d errno %d\n",
126
-					byte, foo, errno);
125
+	fprintf(stderr, "%s : byte %d rd %d errno %d\n",
126
+				__func__, byte, foo, errno);
127 127
         return -1;
128 128
         }
129 129
 return (int)byte;
130 130
 }
131
+/* -------------------------------------------------------------------- */
132
+int putbyte(int fd, unsigned char byte)
133
+{
134
+int		foo = -1;
131 135
 
136
+foo = write(fd, &byte, 1);
137
+if (1 != foo)
138
+        {
139
+	fprintf(stderr, "%s : %d -> %d errno %d\n",
140
+				__func__, byte, foo, errno);
141
+        }
142
+
143
+return foo;
144
+}
132 145
 /* -------------------------------------------------------------------- */
133 146
 /* timeout is in milliseconds */
134 147
 int getbyte_to (int fd, int to_ms)

+ 2
- 2
serial/serial.h View File

@@ -6,8 +6,8 @@
6 6
 
7 7
 int prepare_UART(char *port, int bauds);
8 8
 
9
-int getbyte(int fd);			/* really brotched func */
10
-
9
+int getbyte(int fd);				/* really brotched func */
10
+int putbyte(int fd, unsigned char byte);
11 11
 
12 12
 /* timeout is exprimed in milliseconds. */
13 13
 int getbyte_to (int fd, int to_ms);

Loading…
Cancel
Save