#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; int disarm = 0; const char *host = NULL; unsigned port = 10005; int fd; int timeout = 15; while ((opt = getopt (argc, argv, "h:p:z:USPRBFTADW")) != -1) { switch (opt) { case 'h': host = optarg; break; case 'p': port = 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; case 'W': disarm++; break; default: /* '?' */ return usage (argv[0]); } } if (!host) return (usage (argv[0])); fd = open_tcp_client (host, port); if (fd < 0) { perror ("open tcp port"); return -1; } if (disarm) { if (!show_state (fd, zone)) return 0; action = 0; } if (action == -1) return show_state (fd, zone); 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"); break; case SIA_FN_REJECT: printf ("Panel nacks command\n"); return -1; } while (disarm && timeout && show_state (fd, zone)) sleep (2); return !timeout; }