Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <unistd.h>
#include <getopt.h> //for C11 compliance
#include <stdlib.h>
#include <limits.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
Expand Down Expand Up @@ -180,11 +181,12 @@ void print_help()

int main(int argc, char *argv[])
{
char dev[64];
char dev[PATH_MAX];
char *endp;
int master = 0;
int setrs485half = 0;
int setrs485full = 0;
int hasdev = 0;
int hasdev = 0;
int singleshoot = 0;

struct serial_rs485 rs485ctrl = {0};
Expand All @@ -196,7 +198,10 @@ int main(int argc, char *argv[])
while ((c = getopt (argc, argv, "vsfmd:l:")) != -1)
switch (c) {
case 'd':
snprintf(dev, sizeof(dev), "%s",optarg);
if (snprintf(dev, sizeof(dev), "%s", optarg) >= (int)sizeof(dev)) {
printf("Device path too long: %s\n", optarg);
return -1;
}
hasdev = 1;
break;
case 's':
Expand All @@ -212,9 +217,21 @@ int main(int argc, char *argv[])
master = 1;
break;
case 'l':
singleshoot = atoi(optarg);
{
long parsed;

errno = 0;
parsed = strtol(optarg, &endp, 10);
if (errno || endp == optarg || *endp != '\0' ||
parsed < 1 || parsed > MAX_SEND) {
printf("Invalid length '%s'. Use a value between 1 and %d.\n",
optarg, MAX_SEND);
return -1;
}
singleshoot = (int)parsed;
master = 1;
break;
}
default:
print_help();
}
Expand Down Expand Up @@ -267,24 +284,41 @@ int main(int argc, char *argv[])
}

/* Set the port speed */
tcgetattr(fd, &ti);
if (tcgetattr(fd, &ti)) {
perror("tcgetattr");
ret = -1;
goto restore_settings;
}
ti.c_iflag = 0;
ti.c_oflag = 0;
ti.c_cflag = CS8 | CREAD | CLOCAL;
ti.c_lflag = 0;
ti.c_cc[VTIME] = 1;
ti.c_cc[VMIN] = MAX_RECEIVE;

cfsetospeed(&ti, speed);
cfsetispeed(&ti, speed);
tcsetattr(fd, TCSANOW, &ti);
if (cfsetospeed(&ti, speed)) {
perror("cfsetospeed");
ret = -1;
goto restore_settings;
}
if (cfsetispeed(&ti, speed)) {
perror("cfsetispeed");
ret = -1;
goto restore_settings;
}
if (tcsetattr(fd, TCSANOW, &ti)) {
perror("tcsetattr");
ret = -1;
goto restore_settings;
}

if (master)
ret = send(fd, singleshoot);
else
ret = receive(fd);


restore_settings:
/* restore orginial rs485 settings if available */
if (!cant_save && !already_enabled)
set_rs485_ioctl(fd, &rs485ctrl_orig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=c748d81368c9a87fff9317b09edacfee"
SECTION = "devel"

require rs485test_0.2.bb
require rs485test_0.3.bb

inherit deploy native

Expand Down