summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Riedmueller <s.riedmueller@phytec.de>2018-12-11 13:32:15 +0100
committerStefan Müller-Klieser <s.mueller-klieser@phytec.de>2018-12-17 14:11:50 +0100
commitcdf5301479c7d1f894226f2dcd7781dd938d1c3f (patch)
tree73c52378e53c0016ec3deea99fbfd13697c5f003
parent1ebc2e12941c7c198e82c31759886161c3ef312d (diff)
downloadmeta-phytec-cdf5301479c7d1f894226f2dcd7781dd938d1c3f.tar.bz2
meta-phytec-cdf5301479c7d1f894226f2dcd7781dd938d1c3f.zip
recipes-devtools: Add rs485test tool
This rs485test tool can be used to test a RS485 connection with special regard to half duplex connections. It contains a target side and host side recipe. Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de> Signed-off-by: Stefan Müller-Klieser <s.mueller-klieser@phytec.de>
-rw-r--r--recipes-devtools/rs485test/rs485test-0.2/LICENSE25
-rw-r--r--recipes-devtools/rs485test/rs485test-0.2/rs485test.c245
-rw-r--r--recipes-devtools/rs485test/rs485test-native_0.2.bb22
-rw-r--r--recipes-devtools/rs485test/rs485test_0.2.bb21
4 files changed, 313 insertions, 0 deletions
diff --git a/recipes-devtools/rs485test/rs485test-0.2/LICENSE b/recipes-devtools/rs485test/rs485test-0.2/LICENSE
new file mode 100644
index 0000000..e28547c
--- /dev/null
+++ b/recipes-devtools/rs485test/rs485test-0.2/LICENSE
@@ -0,0 +1,25 @@
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+--------------------------------------------------------------------------------
+Note:
+Individual files contain the following tag instead of the full license text.
+
+ SPDX-License-Identifier: MIT
+
+This enables machine processing of license information based on the SPDX
+License Identifiers that are here available: http://spdx.org/licenses/
diff --git a/recipes-devtools/rs485test/rs485test-0.2/rs485test.c b/recipes-devtools/rs485test/rs485test-0.2/rs485test.c
new file mode 100644
index 0000000..5394579
--- /dev/null
+++ b/recipes-devtools/rs485test/rs485test-0.2/rs485test.c
@@ -0,0 +1,245 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright (C) 2018 PHYTEC Messtechnik GmbH
+ * Author: Jan Remmet <j.remmet@phytec.de>
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <termios.h>
+#include <poll.h>
+
+#include <sys/ioctl.h>
+#include <asm/ioctls.h>
+
+#include <linux/serial.h>
+
+#define MAX_SEND 64
+#define MAX_RECEIVE 64
+
+int verbose = 0;
+
+void printbuf(char *buf, int size, const char *info)
+{
+ int i;
+
+ printf("%s: %.2d bytes:", info, size);
+ for (i = 0; i < size; i++)
+ printf(" %.2x",buf[i]);
+ printf("\n");
+}
+
+int checkbuf(char *buf, int size, int master)
+{
+ int i;
+ int ret = 0;
+
+ if (!size)
+ return ret;
+
+ if (buf[0] != size) {
+ printf("wrong size %d, should be %d\n", size, buf[0]);
+ ret = -1;
+ }
+ for(i = 1; i < size; i++) {
+ int desired = i;
+ if (master)
+ desired ++;
+ if (buf[i] != desired) {
+ printf("wrong date %x, should be %x @ pos %d\n", buf[i], desired, i);
+ ret = -1;
+ break;
+ }
+ }
+ if (ret)
+ printbuf(buf, size, " error ");
+
+ return ret;
+}
+
+int send_data(int fd, char *buf, int size)
+{
+ int ret;
+ ret = write(fd, buf, size);
+ if (verbose)
+ printbuf(buf, ret, " send ");
+
+ return ret;
+}
+
+int receive_data(int fd, char *buf, int size, int master)
+{
+ int ret;
+ ret = read(fd, buf, size);
+ if (ret) {
+ if (verbose)
+ printbuf(buf, ret, " receive");
+ if (checkbuf(buf, ret, master))
+ ret = -1;
+ }
+ return ret;
+}
+
+int send_pingpong(int fd, char *tbuf)
+{
+ int i, ret;
+ char rbuf[MAX_RECEIVE];
+
+ for(i = 2; i < MAX_SEND; i++) {
+ tbuf[0] = i;
+ ret = send_data(fd, tbuf, i);
+ if (ret > 0) {
+ ret = receive_data(fd, rbuf, sizeof(rbuf), 1);
+ if (ret > 0) {
+ if (ret == i)
+ printf("Ping Pong %d bytes ok\n", i);
+ else
+ printf("Wrong size! send %d receive %d\n", i, ret);
+ }
+ }
+ }
+ return 0;
+}
+
+int send(int fd, int size)
+{
+ char buf[MAX_SEND];
+ int i;
+
+ for(i = 0; i < MAX_SEND; i++)
+ buf[i] = i;
+
+ if (size) {
+ buf[0] = size;
+ send_data(fd, buf, size);
+ } else {
+ send_pingpong(fd, buf);
+ }
+
+ return 0;
+}
+
+int receive(int fd) {
+ char buf[MAX_RECEIVE];
+ int ret, i;
+
+ while(1) {
+ ret = receive_data(fd, buf, sizeof(buf), 0);
+ if (ret > 0) {
+ if (ret < MAX_RECEIVE)
+ for (i = 1; i < MAX_RECEIVE; i++)
+ buf[i] = buf[i] + 1;
+ send_data(fd, buf, ret);
+ } else {
+ printf("No data\n");
+ }
+ }
+
+ return 0;
+}
+
+void print_help()
+{
+ printf("Usage rs485test [s] [m] -d DEVICE\n"
+ " -l [LENGTH] singelshoot\n"
+ " -s set RS485 settings\n"
+ " -m master mode\n"
+ " -v verbose\n"
+ " -d device like /dev/ttyS1\n"
+ );
+ exit(1);
+}
+
+int main(int argc, char *argv[])
+{
+ char dev[64];
+ int master = 0;
+ int setrs485 = 0;
+ int hasdev = 0;
+ int singleshoot = 0;
+
+ struct serial_rs485 rs485ctrl;
+ int c, ret, fd;
+ struct termios ti;
+ speed_t speed = B115200;
+
+ while ((c = getopt (argc, argv, "vsmd:l:")) != -1)
+ switch (c) {
+ case 'd':
+ snprintf(dev, sizeof(dev), "%s",optarg);
+ hasdev = 1;
+ break;
+ case 's':
+ setrs485 = 1;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case 'm':
+ master = 1;
+ break;
+ case 'l':
+ singleshoot = atoi(optarg);
+ master = 1;
+ break;
+ default:
+ print_help();
+ }
+
+ if (!hasdev)
+ print_help();
+
+ /* Open port */
+ fd = open(dev, O_RDWR);
+ if (fd < 0) {
+ printf("%s: Unable to open.\n", dev);
+ return -1;
+ }
+
+ if (setrs485 == 1) {
+ rs485ctrl.flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND;
+ rs485ctrl.delay_rts_before_send = 0;
+ rs485ctrl.delay_rts_after_send = 0;
+
+ ret = ioctl(fd, TIOCSRS485, &rs485ctrl);
+ if (ret) {
+ printf("%s: Unable to set rs485 settings ret:(%i)\n", dev, ret);
+ return -1;
+ }
+ } else {
+ ret = ioctl(fd, TIOCGRS485, &rs485ctrl);
+ if (ret) {
+ printf("%s: Unable to get rs485 settings ret:(%i)\n", dev, ret);
+ } else {
+ printf("flags: %x\n", rs485ctrl.flags);
+ printf("delay_rts_before_send: %d\n", rs485ctrl.delay_rts_before_send);
+ printf("delay_rts_after_send: %d\n", rs485ctrl.delay_rts_after_send);
+ }
+ }
+
+ /* Set the port speed */
+ tcgetattr(fd, &ti);
+ 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 (master)
+ ret = send(fd, singleshoot);
+ else
+ ret = receive(fd);
+
+ close(fd);
+
+ exit(ret);
+}
diff --git a/recipes-devtools/rs485test/rs485test-native_0.2.bb b/recipes-devtools/rs485test/rs485test-native_0.2.bb
new file mode 100644
index 0000000..7566695
--- /dev/null
+++ b/recipes-devtools/rs485test/rs485test-native_0.2.bb
@@ -0,0 +1,22 @@
+DESCRIPTION = "Tool to test RS485 interface in half duplex mode on host side"
+HOMEPAGE = "http://www.phytec.de"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=c748d81368c9a87fff9317b09edacfee"
+SECTION = "devel"
+
+require rs485test_0.2.bb
+
+inherit native deploy
+
+do_compile() {
+ ${CC} -Wall -Werror rs485test.c -o rs485test
+}
+
+do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_TOOLS}"
+do_deploy() {
+ install -d ${DEPLOY_DIR_TOOLS}
+ install -m 0755 ${B}/rs485test ${DEPLOY_DIR_TOOLS}/rs485test-${PV}
+ ln -sf rs485test-${PV} ${DEPLOY_DIR_TOOLS}/rs485test
+}
+
+addtask deploy before do_package after do_install
diff --git a/recipes-devtools/rs485test/rs485test_0.2.bb b/recipes-devtools/rs485test/rs485test_0.2.bb
new file mode 100644
index 0000000..2bcd025
--- /dev/null
+++ b/recipes-devtools/rs485test/rs485test_0.2.bb
@@ -0,0 +1,21 @@
+DESCRIPTION = "Tool to test RS485 interface in half duplex mode on target side"
+HOMEPAGE = "http://www.phytec.de"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=c748d81368c9a87fff9317b09edacfee"
+SECTION = "devel"
+
+SRC_URI = " \
+ file://rs485test.c \
+ file://LICENSE \
+"
+
+S = "${WORKDIR}"
+
+do_compile() {
+ ${CC} -Wall -Werror rs485test.c -o rs485test ${LDFLAGS}
+}
+
+do_install() {
+ install -d ${D}${bindir}
+ install -m 0755 rs485test ${D}${bindir}
+}