Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tpetazzoni/6e1799f1ef814010debcaeeb2d193f58 to your computer and use it in GitHub Desktop.
Save tpetazzoni/6e1799f1ef814010debcaeeb2d193f58 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
#include <time.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *uart = argv[1];
struct termios t;
struct timeval start, end;
int fd, ret;
char *buf = "abcdefghijklmnopqrs\n";
int count;
int len = strlen(buf);
printf("%s\n", uart);
fd = open(uart, O_RDWR);
assert(fd >= 0);
ret = tcgetattr(fd, &t);
assert(ret == 0);
cfsetispeed(&t, B57600);
cfsetospeed(&t, B57600);
ret = tcsetattr(fd, TCSANOW, &t);
assert(ret == 0);
count = 0;
while(1)
{
struct timespec ts = {
.tv_sec = 0,
.tv_nsec = 16 * 1000 * 1000,
};
write(fd, buf, len);
nanosleep(&ts, NULL);
count++;
if (count % 100 == 0)
printf("Sent %d packets\n", count);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment