skipstone/examples/read.c-e
2017-11-21 22:24:52 +00:00

45 lines
913 B
Text

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <skipstone/skipstone.h>
static void usage(int argc, char **argv) {
fprintf(stderr, "usage: %s /dev/rfcommX\n", argv[0]);
exit(1);
}
int main(int argc, char **argv) {
skipstone_watch_link *link;
void *buf;
uint16_t len, endpoint;
if (argc != 2) {
usage(argc, argv);
}
if ((buf = malloc(SKIPSTONE_MESSAGE_MAX_PAYLOAD)) == NULL) {
goto error_malloc_buf;
}
if ((link = skipstone_watch_link_open_serial(argv[1])) == NULL) {
goto error_watch_link_open;
}
while (skipstone_recv(link, buf, &len, &endpoint) >= 0) {
printf("Received message %hu bytes for endpoint %hu\n",
len, endpoint);
}
perror("skipstone_recv()");
skipstone_watch_link_close(link);
return 0;
error_watch_link_open:
free(buf);
error_malloc_buf:
return 1;
}