show empty svg if there is no data
[zc] / zc-send
diff --git a/zc-send b/zc-send
index ff6a882..3e188ca 100755 (executable)
--- a/zc-send
+++ b/zc-send
@@ -13,23 +13,56 @@ 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";
 }
 
-my $raw = read_parameter_frame( "\x00" => "\x04\xe8\x03\x00\x00",
-       "\x21",
-       "\x44",
-       "\x12",
-       "\x14",
-       "\x1a\x21\x22\x23\x24\x33\x34\x35\x3b" );
+my $raw;
+
+if ( $ARGV[0] =~ m/interval/ ) {
+       # heartbeat interval
+       my $interval = $ARGV[1] || 30 * 60;
+       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;
+       print "Set relative zero $rel_zero\n";
+       $raw = write_parameter_frame( "\x3a" => "\x01" . pack('C',$rel_zero) );
 
-# heartbeat interval
-my $raw = write_parameter_frame( "\x21" => "\x04" . pack('l',60) );
+} 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",
+       "\x0e\x0f\x11\x12",
+       "\x14",
+       "\x1a\x21\x22\x23\x24\x33\x34\x35\x3a\x3b",
+       "\x44",
+       );
+}
 
 # temporary store to done
 my $t = time();