Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Compiling and uploading a crontab to my Radioduino

by jwkrahn (Abbot)
on May 30, 2021 at 00:55 UTC ( [id://11133281]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Compiling and uploading a crontab to my Radioduino
in thread Compiling and uploading a crontab to my Radioduino

You can send up to 16 bytes in one packet, but you might only want to change three bytes. The datalength says how many bytes to change,

Yes, that is what I assumed, but your code always sets the datalength value to 16.

You might try it like this:

while ( my $line = <$ifh> ) { # Ignore comments next if $line =~ /^#/; # Split elements and do some very basic validation my ( $runonce, $hour, $minute, $second, $command, $offset, @values + ) = split ' ', $line; @values or croak( "Line $.: has not enough values: $line\n" ); # Turn the given command NAME into the correct command NUMBER defined $commandmap{ $command } or croak( "Line $.: Unknown comman +d $command\n" ); my $numcommand = $commandmap{ $command }; # Internally in the Radioduino, the "runonce" flag also serves # as "invalid record" flag, so turn the plaintext 0/1 boolean into + the correct number my $mode = $runonce + 1; # Turn everything into binary my $event = pack 'C C C C n C C C16', $mode, $hour, $minute, $second, $offset, $numcommand, scalar @values, @values, ( 0 ) x 16; # Write binary entry to file print $ofh $event; print $line, "\n"; }

Replies are listed 'Best First'.
Re^4: Compiling and uploading a crontab to my Radioduino
by cavac (Parson) on May 30, 2021 at 10:09 UTC

    but your code always sets the datalength value to 16

    *facepalm*

    Well, that certainly explains why i had some "unexpected features"(tm) during tests. You probably just saved me a weekend of debugging. Thank you very much!

    Please don't understand the following as a critisism, just as why i prefer a different coding style: Your version of the code is much more compact, which is nice. But it makes it (in my opinion) much harder to read and comprehend, especially for beginners. That's why i also try to avoid pack()/unpack() and also all those implicit things like $_. More explicit code makes it also easier to port between different programming languages.

    perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133281]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found