#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUF_SIZE 32
#define TIMEOUT_S 0.5
#define BAUDRATE 115200
static void __print_usage(void)
{
printf("\n");
printf("Usage: rc_uart_loopback {bus}\n");
printf("This sends a short message out the specified bus and then\n");
printf("reads it back in. This requires connecting RX to TX to make a loopback.\n");
printf("For Robotics Cape or BeagleBone Blue specify bus 0,1,2 or 5\n");
printf("\n");
return;
}
int main(int argc, char *argv[])
{
char* test_str = "Hello World";
int bytes = strlen(test_str);
uint8_t buf[BUF_SIZE];
int ret;
int bus;
if(argc!=2){
__print_usage();
return -1;
}
else bus = atoi(argv[1]);
if(!(bus==0||bus==1||bus==2||bus==5)){
__print_usage();
return -1;
}
printf("\ntesting UART bus %d\n\n", bus);
printf("Failed to rc_uart_init%d\n", bus);
return -1;
}
printf("Sending %d bytes: %s \n", bytes, test_str);
printf("reading bytes:\n");
memset(buf,0,sizeof(buf));
if(ret<0) fprintf(stderr,"Error reading bus\n");
else if(ret==0) printf("timeout reached, %d bytes read\n", ret);
else printf("Received %d bytes: %s \n", ret, buf);
printf("\n");
printf("Sending %d bytes: %s \n", bytes, test_str);
printf("reading line:\n");
memset(buf,0,sizeof(buf));
if(ret<0) fprintf(stderr,"Error reading bus\n");
else if(ret==0) printf("timeout reached, %d bytes read\n", ret);
else printf("Received %d bytes: %s \n", ret, buf);
return 0;
}