13 my $path = shift @ARGV;
14 die "Usage: $0 queue/IMEI\n" unless $path;
16 # strip slash to recognize by-name/name/ as symlink
17 if ( -d $path && $path =~ m{/$} ) {
26 $path = readlink $path;
27 warn "# using $path\n";
31 if ( $path =~ m{$queue/(\d+)} ) {
33 if ( ! -e "$queue/$imei") {
34 die "can't find $queue/$imei\n";
37 die "can't find IMEI in $path\n";
42 if ( $ARGV[0] =~ m/interval/ ) {
44 my $interval = $ARGV[1] || 30 * 60;
45 print "set heartbeat interval to $interval s\n";
46 $raw = write_parameter_frame( "\x21" => "\x04" . pack('l',$interval) );
47 } elsif ( $ARGV[0] =~ m/zero/ ) {
48 my $rel_zero = $ARGV[1] // 0;
49 print "Set relative zero $rel_zero\n";
50 $raw = write_parameter_frame( "\x3a" => "\x01" . pack('C',$rel_zero) );
52 } elsif ( $ARGV[0] =~ m/arming/ ) {
53 my $rel_zero = $ARGV[1] // 1;
54 print "Set alarm arming $rel_zero\n";
55 $raw = write_parameter_frame( "\x3a" => "\x11" . pack('C',$rel_zero) );
57 } elsif ( $ARGV[0] =~ m/mqtt/ ) {
58 my @mqtt = qw(185 201 196 30 1883);
59 print "Set server port ", join(' ', @mqtt), "\n";
60 $raw = write_parameter_frame( "\x14" => "\x06" . pack('CCCCs',@mqtt) );
63 print "read_parameter_frame\n";
64 $raw = read_parameter_frame( "\x00" => "\x04\xe8\x03\x00\x00",
67 "\x1a\x21\x22\x23\x24\x33\x34\x35\x3a\x3b",
72 # temporary store to done
74 write_file "$queue/$imei/.todo.$t", $raw;
75 # atomic rename to ensure that file is complete
77 rename "$queue/$imei/.todo.$t", "$queue/$imei/.pending/$t";