serialblaster bugfix

This commit is contained in:
Adam Kaliszan 2022-06-10 10:32:11 +02:00 committed by Xiang Xiao
parent 1f0ba0db6e
commit 835f43524b

View File

@ -59,7 +59,8 @@ int main(int argc, FAR char *argv[])
int ret; int ret;
int fd; int fd;
FAR char *devpath; FAR char *devpath;
int size = 0; const int slength = sizeof(s)-1;
int size = slength;
int rem; int rem;
if (argc == 1) if (argc == 1)
@ -84,25 +85,25 @@ int main(int argc, FAR char *argv[])
fd = open(devpath, O_RDWR); fd = open(devpath, O_RDWR);
if (fd < 0) if (fd < 0)
{ {
printf("dev_ttyS2: ERROR Failed to open /dev/ttyS2\n"); printf("%s: ERROR Failed to open %s\n", argv[0], devpath);
return -1; return -1;
} }
rem = size; rem = size;
while (size > sizeof(s)) printf("Sending %d bytes of data to %s (fd=%d)\n", size, devpath, fd);
while (rem > 0)
{ {
if (rem > 26) if (rem > slength)
{ {
ret = write(fd, s, (sizeof(s)-1)); ret = write(fd, s, slength);
rem = rem - slength;
} }
else
rem = rem - 26;
if (rem < 26)
{ {
ret = write(fd, s, rem); ret = write(fd, s, rem);
rem = 0;
} }
size = size - 26;
UNUSED(ret); UNUSED(ret);
} }