summaryrefslogtreecommitdiffstats
path: root/serial_rx.c
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 /serial_rx.c
parent232cf21c35c79458969fd661d18ca779c5418c2e (diff)
downloadgalaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.tar.gz
galaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.tar.bz2
galaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.zip
split out rx and add syslog support
Diffstat (limited to 'serial_rx.c')
-rw-r--r--serial_rx.c66
1 files changed, 15 insertions, 51 deletions
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;
}