summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames <31272717+gpd-pocket-hacker@users.noreply.github.com>2020-10-31 18:25:41 +0000
committerJames <31272717+gpd-pocket-hacker@users.noreply.github.com>2020-10-31 19:32:32 +0000
commitc3606b0b60e37f5af9e7b71a9e19c3f8097b4a61 (patch)
tree9866aac3d1c354fb6f042d640b4fa470ee8809d3
parent232cf21c35c79458969fd661d18ca779c5418c2e (diff)
downloadgalaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.tar.gz
galaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.tar.bz2
galaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.zip
split out rx and add syslog support
-rw-r--r--Makefile37
-rw-r--r--keypad.c1
-rw-r--r--net_rx.c70
-rw-r--r--rx.c62
-rw-r--r--serial_rx.c66
-rw-r--r--util.c4
6 files changed, 122 insertions, 118 deletions
diff --git a/Makefile b/Makefile
index 68f78bf..aa4c00f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,34 @@
CFLAGS=-Wall ${CURSES_CFLAGS}
-CURSES_CFLAGS=$(shell pkg-config --cflags ncurses)
-CURSES_LIBS=$(shell pkg-config --libs ncurses)
+PKG_CONFIG=pkg-config
+CURSES_CFLAGS=$(shell ${PKG_CONNFIG} --cflags ncursesw)
+CURSES_LIBS=$(shell ${PKG_CONFIG} --libs ncursesw)
-all: net_rx net_arm serial_rx serial_arm serial_keypad net_keypad
+#export STAGING_DIR
-net_rx:util.o sia.o net_rx.o
-net_arm:util.o sia.o net_arm.o arm.c
-serial_rx:util.o sia.o serial_rx.o
-serial_arm:util.o sia.o serial_arm.o arm.c
+#TOOLS_DIR=/root/projects/openwrt/tpl-wdr3600/trunk-50149/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.16
+#STAGING_DIR=/root/projects/openwrt/tpl-wdr3600/trunk-50149/staging_dir/target-mips_34kc_musl-1.1.16/
+
+#TOOLS_DIR=/root/projects/openwrt/tpl-wdr3600/trunk-47381/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.11
+#STAGING_DIR=/root/projects/openwrt/tpl-wdr3600/trunk-47381/staging_dir/target-mips_34kc_musl-1.1.11
+
+#CC=${TOOLS_DIR}/bin/mips-openwrt-linux-gcc
+
+CFLAGS=-I${STAGING_DIR}/include -I${TOOLS_DIR}/include
+
+PROGS=net_rx net_arm serial_rx serial_arm serial_keypad net_keypad
+
+PREFIX=/usr/local
+
+all: ${PROGS}
+
+install: ${PROGS}
+ mkdir -p ${DESTDIR}/${PREFIX}/bin
+ for i in ${PROGS}; do install -m 755 $$i ${DESTDIR}/${PREFIX}/bin/$$i; done
+
+net_rx:util.o sia.o net_rx.o rx.o
+net_arm:util.o sia.o net_arm.o arm.o
+serial_rx:util.o sia.o serial_rx.o rx.o
+serial_arm:util.o sia.o serial_arm.o arm.o
serial_keypad:util.o keypad.o serial_keypad.o
${CC} ${CFLAGS} ${LDFLAGS} -o $@ $^ ${CURSES_LIBS} ${LIBS}
@@ -16,7 +37,7 @@ net_keypad:util.o keypad.o net_keypad.o
${CC} ${CFLAGS} ${LDFLAGS} -o $@ $^ ${CURSES_LIBS} ${LIBS}
tidy:
- astyle -A3 -s2 --attach-extern-c -L -c -w -Y -m0 -f -p -H -U -k3 -xj -xd sia.c sia.h util.c util.h serial_rx.c net_rx.c serial_arm.c net_arm.c arm.c keypad.c net_keypad.c serial_keypad.c
+ astyle -A3 -s2 --attach-extern-c -L -c -w -Y -m0 -f -p -H -U -k3 -xj -xd sia.c sia.h util.c util.h serial_rx.c net_rx.c serial_arm.c net_arm.c arm.c keypad.c net_keypad.c serial_keypad.c rx.c
clean:
/bin/rm -f *.o
diff --git a/keypad.c b/keypad.c
index 78c67a2..847eccd 100644
--- a/keypad.c
+++ b/keypad.c
@@ -644,7 +644,6 @@ int gd_keypad (int fd, const char *dfn, int debug)
}
}
-
if (gd_init (fd)) {
printf ("Failed to init comms with panel\n");
return -1;
diff --git a/net_rx.c b/net_rx.c
index a3d95e4..1ea0993 100644
--- a/net_rx.c
+++ b/net_rx.c
@@ -5,68 +5,18 @@
#include <termios.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <syslog.h>
#include "util.h"
#include "sia.h"
-
-
-
-
-void msg (char *account, char *event, char *ascii)
-{
- printf ("%s %64s %s\n", account, event, ascii);
-}
-
-
-static int new_block (int fd, SIA_Block *b)
-{
- static int have_ascii_messages = 0; /*SIA level 3 doesn't have ascii, SIA level 4 does */
-
- static char account[SIA_MAX_DATA_LENGTH + 1];
- static char event[SIA_MAX_DATA_LENGTH + 1];
- static char ascii[SIA_MAX_DATA_LENGTH + 1];
-
- unsigned len = sia_data_length (b);
-
- if (sia_ack_if_needed (fd, b))
- return -1;
-
- switch (b->function) {
- case SIA_FN_ACCOUNT_ID:
- memcpy (account, b->data, len);
- account[len] = 0;
- break;
-
- case SIA_FN_NEW_EVENT:
- case SIA_FN_OLD_EVENT:
- memcpy (event, b->data, len);
- event[len] = 0;
-
- if (!have_ascii_messages) msg (account, event, "");
-
- break;
-
- case SIA_FN_ASCII:
- have_ascii_messages = 1;
- memcpy (ascii, b->data, len);
- ascii[len] = 0;
-
- msg (account, event, ascii);
- break;
- }
-
- return 0;
-}
-
-static void periodic_task (void)
-{
-}
+extern int new_block (int fd, SIA_Block *b, int log);
+extern void periodic_task (void);
static int usage (const char *name)
{
fprintf (stderr, "Usage:\n");
- fprintf (stderr, "%s [ -p listen_port ]\n\n", name);
+ fprintf (stderr, "%s [ -l ] [ -p listen_port ]\n\n", name);
fprintf (stderr, "listen_port defaults to 10002\n");
return 1;
@@ -83,22 +33,30 @@ int main (int argc, char *argv[])
int afd = -1;
SIA_Block b;
struct timeval tv = {0};
+ int log = 0;
unsigned char buf[SIA_MAX_BLOCK_LENGTH];
unsigned ptr = 0;
- while ((opt = getopt (argc, argv, "p:")) != -1) {
+ while ((opt = getopt (argc, argv, "p:l")) != -1) {
switch (opt) {
case 'p':
port = atoi (optarg);
break;
+ case 'l':
+ log++;
+ break;
+
default: /* '?' */
return usage (argv[0]);
}
}
+ if (log)
+ openlog ("net_rx", 0, LOG_USER);
+
fd = open_tcp_server (port);
if (fd < 0) {
@@ -159,7 +117,7 @@ int main (int argc, char *argv[])
break;
default: /*Valid block */
- new_block (afd, &b);
+ new_block (afd, &b, log);
ptr = 0;
break;
}
diff --git a/rx.c b/rx.c
new file mode 100644
index 0000000..09d969f
--- /dev/null
+++ b/rx.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <syslog.h>
+
+#include "sia.h"
+
+static void msg (char *account, char *event, char *ascii, int log)
+{
+ if (log)
+ syslog (LOG_WARNING, "SIA: %s %64s %s", account, event, ascii);
+
+ printf ("%s %64s %s\n", account, event, ascii);
+}
+
+
+int new_block (int fd, SIA_Block *b, int log)
+{
+ static int have_ascii_messages = 0; /*SIA level 3 doesn't have ascii, SIA level 4 does */
+
+ static char account[SIA_MAX_DATA_LENGTH + 1];
+ static char event[SIA_MAX_DATA_LENGTH + 1];
+ static char ascii[SIA_MAX_DATA_LENGTH + 1];
+
+ unsigned len = sia_data_length (b);
+
+ if (sia_ack_if_needed (fd, b))
+ return -1;
+
+ switch (b->function) {
+ case SIA_FN_ACCOUNT_ID:
+ memcpy (account, b->data, len);
+ account[len] = 0;
+ break;
+
+ case SIA_FN_NEW_EVENT:
+ case SIA_FN_OLD_EVENT:
+ memcpy (event, b->data, len);
+ event[len] = 0;
+
+ if (!have_ascii_messages) msg (account, event, "", log);
+
+ break;
+
+ case SIA_FN_ASCII:
+ have_ascii_messages = 1;
+ memcpy (ascii, b->data, len);
+ ascii[len] = 0;
+
+ msg (account, event, ascii, log);
+ break;
+ }
+
+ return 0;
+}
+
+void periodic_task (void)
+{
+}
+
+
diff --git a/serial_rx.c b/serial_rx.c
index d481417..8ef66ec 100644
--- a/serial_rx.c
+++ b/serial_rx.c
@@ -3,65 +3,20 @@
#include <unistd.h>
#include <string.h>
#include <termios.h>
+#include <syslog.h>
#include "util.h"
#include "sia.h"
-
-
-
-void msg (char *account, char *event, char *ascii)
-{
- printf ("%s %64s %s\n", account, event, ascii);
-}
-
-
-static int new_block (int fd, SIA_Block *b)
-{
- static int have_ascii_messages = 0; /*SIA level 3 doesn't have ascii, SIA level 4 does */
-
- static char account[SIA_MAX_DATA_LENGTH + 1];
- static char event[SIA_MAX_DATA_LENGTH + 1];
- static char ascii[SIA_MAX_DATA_LENGTH + 1];
-
- unsigned len = sia_data_length (b);
-
- if (sia_ack_if_needed (fd, b))
- return -1;
-
- switch (b->function) {
- case SIA_FN_ACCOUNT_ID:
- memcpy (account, b->data, len);
- account[len] = 0;
- break;
-
- case SIA_FN_NEW_EVENT:
- case SIA_FN_OLD_EVENT:
- memcpy (event, b->data, len);
- event[len] = 0;
-
- if (!have_ascii_messages) msg (account, event, "");
-
- break;
-
- case SIA_FN_ASCII:
- have_ascii_messages = 1;
- memcpy (ascii, b->data, len);
- ascii[len] = 0;
-
- msg (account, event, ascii);
- break;
- }
-
- return 0;
-}
+extern int new_block (int fd, SIA_Block *b, int log);
+//extern void periodic_task(void);
static int usage (const char *name)
{
fprintf (stderr, "Usage:\n");
- fprintf (stderr, "%s [ -b baud ] -p serial_device\n\n", name);
+ fprintf (stderr, "%s [ -l ] [ -b baud ] -p serial_device\n\n", name);
fprintf (stderr, "baud defaults to 9600\n");
return 1;
@@ -76,12 +31,13 @@ int main (int argc, char *argv[])
int fd;
SIA_Block b;
ssize_t red;
+ int log = 0;
unsigned char buf[SIA_MAX_BLOCK_LENGTH];
unsigned ptr = 0;
- while ((opt = getopt (argc, argv, "p:b:")) != -1) {
+ while ((opt = getopt (argc, argv, "p:b:l:")) != -1) {
switch (opt) {
case 'p':
port = optarg;
@@ -91,6 +47,11 @@ int main (int argc, char *argv[])
baud = atoi (optarg);
break;
+ case 'l':
+ log++;
+ break;
+
+
default: /* '?' */
return usage (argv[0]);
}
@@ -101,6 +62,9 @@ int main (int argc, char *argv[])
if (!port)
return usage (argv[0]);
+ if (log)
+ openlog ("serial_rx", 0, LOG_USER);
+
fd = open_tty (port, baud);
set_blocking (fd);
@@ -127,7 +91,7 @@ int main (int argc, char *argv[])
break;
default: /*Valid block */
- new_block (fd, &b);
+ new_block (fd, &b, log);
ptr = 0;
break;
}
diff --git a/util.c b/util.c
index e06fc62..21c1eb9 100644
--- a/util.c
+++ b/util.c
@@ -1,6 +1,6 @@
#include <string.h>
#include <unistd.h>
-#include <termio.h>
+//#include <termio.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/types.h>
@@ -233,7 +233,7 @@ int open_tty (const char *path, int baud)
struct termios termios;
speed_t s = baud_to_speed_t (baud);
- if (s == (speed_t) -1) return -1;
+ if (s == (speed_t) - 1) return -1;
fd = open (path, O_RDWR | O_NOCTTY | O_NONBLOCK);