Skip to content

Commit

Permalink
uart_example_linux: use noncanonical mode and avoid useless prints
Browse files Browse the repository at this point in the history
  • Loading branch information
Demon000 authored and cristianfatu committed Jan 29, 2020
1 parent 99a02d5 commit 36df955
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions uart_example_linux/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <string.h>
#include "uart.h"

#define LOOPBACK_FORMAT "loopback(%d): %s"
#define LOOPBACK_FORMAT "loopback: %s\r\n"
#define LOOPBACK_FORMAT_LEN strlen(LOOPBACK_FORMAT)
#define MAX_READ_SIZE 235
#define MAX_LOOPBACK_SIZE MAX_READ_SIZE + LOOPBACK_FORMAT_LEN
Expand All @@ -24,26 +24,25 @@ int main() {
dev.filename = "/dev/ttyUL1";
dev.rate = B9600;

rc = uart_start(&dev, true);
rc = uart_start(&dev, false);
if (rc) {
return rc;
}

char read_data[MAX_READ_SIZE];
char loopback_data[MAX_LOOPBACK_SIZE];
size_t read_data_len;
size_t loopback_data_len;

loopback_data_len = uart_writes(&dev, "UART DEMO\r\n");
printf("loopback_data_len: %d\n", loopback_data_len);
printf("UART DEMO\r\n");
uart_writes(&dev, "UART DEMO\r\n");

while (1) {
read_data_len = uart_reads(&dev, read_data, MAX_READ_SIZE);

if (read_data_len > 0) {
printf("read(%d): %s", read_data_len, read_data);
snprintf(loopback_data, MAX_LOOPBACK_SIZE, LOOPBACK_FORMAT, read_data_len, read_data);
loopback_data_len = uart_writes(&dev, loopback_data);
printf("%s", read_data);
snprintf(loopback_data, MAX_LOOPBACK_SIZE, LOOPBACK_FORMAT, read_data);
uart_writes(&dev, loopback_data);
}
}

Expand Down

0 comments on commit 36df955

Please sign in to comment.