adding the 'putbyte' function

This commit is contained in:
phyto 2019-05-14 15:33:00 +02:00
parent 970231b357
commit 33c96b1a63
3 changed files with 19 additions and 4 deletions

View File

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

View File

@ -122,13 +122,26 @@ byte = 0;
foo = read(fd, &byte, 1); foo = read(fd, &byte, 1);
if (1 != foo) if (1 != foo)
{ {
fprintf(stderr, "byte %d rd %d errno %d\n", fprintf(stderr, "%s : byte %d rd %d errno %d\n",
byte, foo, errno); __func__, byte, foo, errno);
return -1; return -1;
} }
return (int)byte; return (int)byte;
} }
/* -------------------------------------------------------------------- */
int putbyte(int fd, unsigned char byte)
{
int foo = -1;
foo = write(fd, &byte, 1);
if (1 != foo)
{
fprintf(stderr, "%s : %d -> %d errno %d\n",
__func__, byte, foo, errno);
}
return foo;
}
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* timeout is in milliseconds */ /* timeout is in milliseconds */
int getbyte_to (int fd, int to_ms) int getbyte_to (int fd, int to_ms)

View File

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