summaryrefslogtreecommitdiff
path: root/recipes-extended
diff options
context:
space:
mode:
authorJesse Gilles <jgilles@multitech.com>2015-01-23 15:35:47 -0600
committerJesse Gilles <jgilles@multitech.com>2015-01-23 15:35:47 -0600
commit3bb0e9740d8f9ffd8f5e6618d2965712258c2eaa (patch)
treeffbd729b689b6e73ba70bb917feab71a6fd26252 /recipes-extended
parentd138f76cd8cb1dee1bb0318ee029f9c078de6196 (diff)
downloadmeta-mlinux-3bb0e9740d8f9ffd8f5e6618d2965712258c2eaa.tar.gz
meta-mlinux-3bb0e9740d8f9ffd8f5e6618d2965712258c2eaa.tar.bz2
meta-mlinux-3bb0e9740d8f9ffd8f5e6618d2965712258c2eaa.zip
recipes-extended/multitech: add set-rs485
Add simple utility to enable RS-485 half-duplex mode for a given tty device
Diffstat (limited to 'recipes-extended')
-rw-r--r--recipes-extended/multitech/set-rs485/set-rs485.c81
-rw-r--r--recipes-extended/multitech/set-rs485_0.1.bb18
2 files changed, 99 insertions, 0 deletions
diff --git a/recipes-extended/multitech/set-rs485/set-rs485.c b/recipes-extended/multitech/set-rs485/set-rs485.c
new file mode 100644
index 0000000..1e53092
--- /dev/null
+++ b/recipes-extended/multitech/set-rs485/set-rs485.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <linux/serial.h>
+
+int openserial(char *devicename)
+{
+ int fd;
+
+ if ((fd = open(devicename, O_RDWR)) == -1) {
+ perror("openserial(): open()");
+ return 0;
+ }
+
+ return fd;
+}
+
+int setRS485(int fd, int state)
+{
+ struct serial_rs485 rs485;
+
+ if (ioctl(fd, TIOCGRS485, &rs485) == -1) {
+ perror("TIOCGRS485");
+ return 0;
+ }
+
+ //printf("Old RS485 flags %x\n", rs485.flags);
+
+ if (state)
+ rs485.flags |= SER_RS485_ENABLED;
+ else
+ rs485.flags &= ~SER_RS485_ENABLED;
+
+ if (ioctl(fd, TIOCSRS485, &rs485) == -1) {
+ perror("TIOCSRS485");
+ return 0;
+ }
+
+ //printf("New RS485 flags %x\n", rs485.flags);
+
+ return 1;
+}
+
+int main(int argc, char *argv[])
+{
+ int fd;
+
+ if (argc != 3) {
+ printf("Usage: set_rs485hd tty 0|1\n");
+ return 1;
+ }
+
+ char *serialdev = argv[1];
+ char *state_str = argv[2];
+
+ int state = atoi(state_str);
+
+ fd = openserial(serialdev);
+ if (!fd) {
+ fprintf(stderr, "Error while initializing %s.\n", serialdev);
+ return 1;
+ }
+
+ printf("%s: setting RS485 to ", serialdev);
+
+ if (state)
+ printf("%s\n", "enabled");
+ else
+ printf("%s\n", "disabled");
+
+ if (setRS485(fd, state))
+ return 0;
+ else
+ return 1;
+}
+
diff --git a/recipes-extended/multitech/set-rs485_0.1.bb b/recipes-extended/multitech/set-rs485_0.1.bb
new file mode 100644
index 0000000..09fe9f9
--- /dev/null
+++ b/recipes-extended/multitech/set-rs485_0.1.bb
@@ -0,0 +1,18 @@
+DESCRIPTION = "Enables RS485 mode for a serial tty device"
+HOMEPAGE = "http://www.multitech.net/"
+PRIORITY = "optional"
+LICENSE = "GPLv2+"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6"
+PR = "r0"
+
+SRC_URI = "file://set-rs485.c"
+S = "${WORKDIR}"
+
+do_compile() {
+ ${CC} ${CFLAGS} ${LDFLAGS} -o set-rs485 set-rs485.c
+}
+
+do_install() {
+ install -d ${D}${bindir}
+ install -m 0755 set-rs485 ${D}${bindir}/
+}