From 62bc1af6c6a1201db551e1ec523e757415464fd5 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 25 Oct 2020 13:26:29 +0000 Subject: tidy up, make less awful --- serial_arm.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 serial_arm.c (limited to 'serial_arm.c') 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 +#include +#include +#include +#include +#include +#include +#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; +} + + -- cgit v1.2.3