added arming
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 8 Oct 2020 10:23:20 +0000 (12:23 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 8 Oct 2020 10:23:20 +0000 (12:23 +0200)
zc-send

diff --git a/zc-send b/zc-send
index 4d9639f..93dfe81 100755 (executable)
--- a/zc-send
+++ b/zc-send
@@ -13,10 +13,26 @@ my $queue = "queue";
 my $path = shift @ARGV;
 die "Usage: $0 queue/IMEI\n" unless $path;
 
+# strip slash to recognize by-name/name/ as symlink
+if ( -d $path && $path =~ m{/$} ) {
+       my $tmp = $path;
+       $tmp =~ s{/$}{};
+       if ( -l $tmp ) {
+               $path = $tmp;
+       }
+}
+
+if ( -l $path ) {
+       $path = readlink $path;
+       warn "# using $path\n";
+}
 
 my $imei;
-if ( $path =~ m{$queue/(\w+)/} ) {
+if ( $path =~ m{$queue/(\d+)} ) {
        $imei = $1;
+       if ( ! -e "$queue/$imei") {
+               die "can't find $queue/$imei\n";
+       }
 } else {
        die "can't find IMEI in $path\n";
 }
@@ -29,18 +45,23 @@ if ( $ARGV[0] =~ m/interval/ ) {
        print "set heartbeat interval to $interval s\n";
        $raw = write_parameter_frame( "\x21" => "\x04" . pack('l',$interval) );
 } elsif ( $ARGV[0] =~ m/zero/ ) {
-       my $rel_zero = $ARGV[1] || 0;
+       my $rel_zero = $ARGV[1] // 0;
        print "Set relative zero $rel_zero\n";
        $raw = write_parameter_frame( "\x3a" => "\x01" . pack('C',$rel_zero) );
 
+} elsif ( $ARGV[0] =~ m/arming/ ) {
+       my $rel_zero = $ARGV[1] // 1;
+       print "Set alarm arming $rel_zero\n";
+       $raw = write_parameter_frame( "\x3a" => "\x11" . pack('C',$rel_zero) );
+
 } else {
        print "read_parameter_frame\n";
        $raw = read_parameter_frame( "\x00" => "\x04\xe8\x03\x00\x00",
-       "\x21",
-       "\x44",
-       "\x12",
+       "\x0e\x0f\x11\x12",
        "\x14",
-       "\x1a\x21\x22\x23\x24\x33\x34\x35\x3a\x3b" );
+       "\x1a\x21\x22\x23\x24\x33\x34\x35\x3a\x3b",
+       "\x44",
+       );
 }
 
 # temporary store to done