examples/serialblaster, serialrx, udpblaster: Update to serial/UDP tests.
This commit is contained in:
parent
049616a651
commit
da100102a7
@ -19,4 +19,9 @@ config EXAMPLES_SERIALBLASTER_PRIORITY
|
||||
int "CPU hog task priority"
|
||||
default 50
|
||||
|
||||
config EXAMPLES_SERIALBLASTER_DEVPATH
|
||||
string "Serial device path"
|
||||
default "/dev/ttyS2"
|
||||
---help---
|
||||
The default path to the serial device
|
||||
endif
|
||||
|
@ -44,8 +44,11 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <nuttx/clock.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@ -70,16 +73,60 @@ static const char s[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
int ret;
|
||||
int fd;
|
||||
FAR char *devpath;
|
||||
int size = 0;
|
||||
int rem;
|
||||
|
||||
while (1)
|
||||
if (argc == 1)
|
||||
{
|
||||
#ifdef BUFFERED_IO
|
||||
ret = fputs(s, stdout);
|
||||
#else
|
||||
ret = write(1, s, sizeof(s)-1);
|
||||
#endif
|
||||
devpath = CONFIG_EXAMPLES_SERIALBLASTER_DEVPATH;
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
devpath = argv[1];
|
||||
}
|
||||
else if (argc == 3)
|
||||
{
|
||||
devpath = argv[1];
|
||||
size = strtol(argv[2], NULL, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [devpath]\n", argv[0]);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
fd = open(devpath, O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("dev_ttyS2: ERROR Failed to open /dev/ttyS2\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rem = size;
|
||||
while (size > sizeof(s))
|
||||
{
|
||||
if (rem > 26)
|
||||
{
|
||||
ret = write(fd, s, (sizeof(s)-1));
|
||||
}
|
||||
|
||||
rem = rem - 26;
|
||||
if (rem < 26)
|
||||
{
|
||||
ret = write(fd, s, rem);
|
||||
}
|
||||
|
||||
size = size - 26;
|
||||
UNUSED(ret);
|
||||
}
|
||||
|
||||
up_udelay(5000000);
|
||||
close(fd);
|
||||
return 0;
|
||||
|
||||
errout:
|
||||
fflush(stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ config EXAMPLES_SERIALRX_PRIORITY
|
||||
|
||||
config EXAMPLES_SERIALRX_BUFFERED
|
||||
bool "Buffered I/O"
|
||||
default y
|
||||
default n
|
||||
---help---
|
||||
Use buffered I/O
|
||||
|
||||
|
@ -48,14 +48,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@ -69,8 +62,13 @@ int main(int argc, FAR char *argv[])
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_SERIALRX_BUFFERED
|
||||
FAR FILE *f;
|
||||
int fd;
|
||||
int nbytes;
|
||||
int cnt;
|
||||
#else
|
||||
int fd;
|
||||
int cnt;
|
||||
int bytecount = 0;
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLES_SERIALRX_PRINTHYPHEN
|
||||
int count = 0;
|
||||
@ -90,6 +88,11 @@ int main(int argc, FAR char *argv[])
|
||||
{
|
||||
devpath = argv[1];
|
||||
}
|
||||
else if (argc == 3)
|
||||
{
|
||||
devpath = argv[1];
|
||||
bytecount = strtol(argv[2], NULL, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [devpath]\n", argv[0]);
|
||||
@ -101,6 +104,7 @@ int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
buf = (FAR char *)malloc(CONFIG_EXAMPLES_SERIALRX_BUFSIZE);
|
||||
#endif
|
||||
|
||||
if (buf == NULL)
|
||||
{
|
||||
fprintf(stderr, "ERROR: malloc failed: %d\n", errno);
|
||||
@ -115,7 +119,7 @@ int main(int argc, FAR char *argv[])
|
||||
goto errout_with_buf;
|
||||
}
|
||||
#else
|
||||
fd = open(devpath, O_RDONLY);
|
||||
fd = open(devpath, O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: open failed: %d\n", errno);
|
||||
@ -125,11 +129,12 @@ int main(int argc, FAR char *argv[])
|
||||
|
||||
printf("Reading from %s\n", devpath);
|
||||
fflush(stdout);
|
||||
|
||||
while (!eof)
|
||||
cnt = 0;
|
||||
while (cnt < bytecount)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_SERIALRX_BUFFERED
|
||||
size_t n = fread(buf, 1, CONFIG_EXAMPLES_SERIALRX_BUFSIZE, f);
|
||||
size_t n = fread(buf, 1, 26, f);
|
||||
cnt++;
|
||||
if (feof(f))
|
||||
{
|
||||
eof = true;
|
||||
@ -142,6 +147,7 @@ int main(int argc, FAR char *argv[])
|
||||
}
|
||||
#else
|
||||
ssize_t n = read(fd, buf, CONFIG_EXAMPLES_SERIALRX_BUFSIZE);
|
||||
up_udelay(1000);
|
||||
if (n == 0)
|
||||
{
|
||||
eof = true;
|
||||
@ -167,24 +173,25 @@ int main(int argc, FAR char *argv[])
|
||||
{
|
||||
printf("0x%02x ", i, buf[i]);
|
||||
}
|
||||
fflush(stdout);
|
||||
#elif defined(CONFIG_EXAMPLES_SERIALRX_PRINTSTR)
|
||||
buf[n] = '\0';
|
||||
printf("%s", buf);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
#endif /*Kamal*/
|
||||
cnt += n;
|
||||
}
|
||||
|
||||
UNUSED(eof);
|
||||
}
|
||||
#ifdef CONFIG_EXAMPLES_SERIALRX_PRINTHYPHEN
|
||||
printf("\n");
|
||||
#endif
|
||||
printf("EOF reached\n");
|
||||
printf("Total bytes received = %d\n", cnt); /* Kamal */
|
||||
fflush(stdout);
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_SERIALRX_BUFFERED
|
||||
fclose(f);
|
||||
#else
|
||||
up_udelay(1000000);
|
||||
close(fd);
|
||||
#endif
|
||||
|
||||
|
@ -122,7 +122,7 @@ static void netest_initialize(void)
|
||||
uint8_t mac[IFHWADDRLEN];
|
||||
#endif
|
||||
|
||||
/* Many embedded network interfaces must have a software assigned MAC */
|
||||
/* Many embedded network interfaces must have a software assigned MAC */
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_UDPBLASTER_NOMAC
|
||||
mac[0] = 0x00;
|
||||
@ -182,7 +182,6 @@ static void netest_initialize(void)
|
||||
*/
|
||||
|
||||
netlib_ifup("eth0");
|
||||
|
||||
}
|
||||
#endif /*CONFIG_EXAMPLES_UDPBLASTER_INIT */
|
||||
|
||||
@ -233,7 +232,7 @@ int main(int argc, FAR char *argv[])
|
||||
target.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_UDPBLASTER_TARGETIP);
|
||||
addrlen = sizeof(struct sockaddr_in);
|
||||
|
||||
if (bind(sockfd, (struct sockaddr*)&target, addrlen) < 0)
|
||||
if (bind(sockfd, (struct sockaddr *)&target, addrlen) < 0)
|
||||
{
|
||||
printf("server: ERROR bind failure: %d\n", errno);
|
||||
ret = EXIT_FAILURE;
|
||||
@ -272,7 +271,7 @@ int main(int argc, FAR char *argv[])
|
||||
target.sin6_addr.s6_addr16[7] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_8);
|
||||
addrlen = sizeof(struct sockaddr_in6);
|
||||
|
||||
if (bind(sockfd, (struct sockaddr*)&target, addrlen) < 0)
|
||||
if (bind(sockfd, (struct sockaddr *)&target, addrlen) < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR bind failure: %d\n", errno);
|
||||
ret = EXIT_FAILURE;
|
||||
@ -283,7 +282,7 @@ int main(int argc, FAR char *argv[])
|
||||
npackets = 0;
|
||||
ndots = 0;
|
||||
|
||||
for (;;)
|
||||
for (; ; )
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_UDPBLASTER_POLLOUT
|
||||
struct pollfd fds[1];
|
||||
@ -318,16 +317,16 @@ int main(int argc, FAR char *argv[])
|
||||
goto errout_with_socket;
|
||||
}
|
||||
|
||||
if (++npackets >= 10)
|
||||
if (++npackets >= 10000)
|
||||
{
|
||||
putchar('.');
|
||||
npackets = 0;
|
||||
|
||||
if (++ndots >= 50)
|
||||
{
|
||||
putchar('\n');
|
||||
ndots = 0;
|
||||
}
|
||||
{
|
||||
putchar('\n');
|
||||
ndots = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user