summaryrefslogtreecommitdiffstats
path: root/serial_arm.c
diff options
context:
space:
mode:
authorroot <root@nolonger-other.tetra.james.local>2020-10-25 13:26:29 +0000
committerroot <root@nolonger-other.tetra.james.local>2020-10-25 13:26:29 +0000
commit62bc1af6c6a1201db551e1ec523e757415464fd5 (patch)
tree49c2eadf8a51e7e43a059f1aff59997c3c169c5e /serial_arm.c
parent4b4e4972088d82cac99941398834d8e6d661682c (diff)
downloadgalaxy_tools-62bc1af6c6a1201db551e1ec523e757415464fd5.tar.gz
galaxy_tools-62bc1af6c6a1201db551e1ec523e757415464fd5.tar.bz2
galaxy_tools-62bc1af6c6a1201db551e1ec523e757415464fd5.zip
tidy up, make less awful
Diffstat (limited to 'serial_arm.c')
-rw-r--r--serial_arm.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/serial_arm.c b/serial_arm.c
new file mode 100644
index 0000000..d1a5149
--- /dev/null
+++ b/serial_arm.c
@@ -0,0 +1,147 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <termios.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include "util.h"
+#include "sia.h"
+#include "arm.h"
+
+
+
+
+static int usage (const char *name)
+{
+ fprintf (stderr, "Usage:\n");
+ fprintf (stderr, "%s -h host [-p port] [-z zone] [-U|-S|-P|-R|-B|-F|-T|-A|-D]\n", name);
+ fprintf (stderr, "\n");
+ fprintf (stderr, " -U Unset system/zone\n");
+ fprintf (stderr, " -S Set system/zone\n");
+ fprintf (stderr, " -P Part set system/zone\n");
+ fprintf (stderr, " -R Reset system/zone\n");
+ fprintf (stderr, " -B aBort set system/zone\n");
+ fprintf (stderr, " -F Force set system/zone\n");
+ fprintf (stderr, " -T sTate system/zone\n");
+ fprintf (stderr, " -A Alarm system/zone\n");
+ fprintf (stderr, " -D reaDy system/zone\n");
+
+
+ return -1;
+}
+
+
+int main (int argc, char *argv[])
+{
+ SIA_Block b;
+ char cmd[SIA_MAX_DATA_LENGTH];
+ unsigned opt;
+ int zone = -1;
+ int action = -1;
+ const char *port = NULL;
+ unsigned baud = 9600;
+ int fd;
+
+ while ((opt = getopt (argc, argv, "h:p:z:USPRBFTAD")) != -1) {
+ switch (opt) {
+ case 'p':
+ port = optarg;
+ break;
+
+ case 'b':
+ baud = atoi (optarg);
+ break;
+
+ case 'z':
+ zone = atoi (optarg);
+ break;
+
+ case 'U':
+ action = 0;
+ break;
+
+ case 'S':
+ action = 1;
+ break;
+
+ case 'P':
+ action = 2;
+ break;
+
+ case 'R':
+ action = 3;
+ break;
+
+ case 'B':
+ action = 4;
+ break;
+
+ case 'F':
+ action = 5;
+ break;
+
+ case 'T':
+ action = 6;
+ break;
+
+ case 'A':
+ action = 7;
+ break;
+
+ case 'D':
+ action = 8;
+ break;
+
+ default: /* '?' */
+ return usage (argv[0]);
+ }
+ }
+
+ if (!port) return (usage (argv[0]));
+
+ fd = open_tty (port, baud);
+
+ set_blocking (fd);
+
+
+ if (fd < 0) {
+ perror ("open tcp port");
+ return -1;
+ }
+
+
+
+ if (action == -1) {
+ if (show_state (fd))
+ return -1;
+
+ return 0;
+ }
+
+
+ if (zone != -1)
+ sprintf (cmd, "SA%d*%d", zone, action);
+ else
+ sprintf (cmd, "SA*%d", action);
+
+
+ if (auth_cmd_with_ack (fd, SIA_FN_CONTROL, cmd, strlen (cmd), &b)) {
+ printf ("Command failed\n");
+ return -1;
+ }
+
+ switch (b.function) {
+ case SIA_FN_ACKNOLEDGE:
+ printf ("Panel acks command\n");
+ return 0;
+
+ case SIA_FN_REJECT:
+ printf ("Panel nacks command\n");
+ /*fall through */
+ }
+
+ return -1;
+}
+
+