January
2006, Issue 186
Electronic
Scarecrow
CHECKING
FOR REPLIES
After
all the sensors have been read, the main routine checks
if the latest outgoing packet has been acknowledged.
Normally, the ACK packet should arrive while the sensors
are being read. Each request packet (except for resent
duplicates) has a unique sequence number with a matching
reply having the same number. If these numbers don’t
match, it means a reply has been lost. If this occurs
too many times, the transmit power increases unless
it’s already at its maximum. In this sort of case, you
can only assume an unrecoverable problem, so the remote
will sleep for 1 h before retrying.
When
a valid reply is received, the routine checks if it’s
a block of download data. If it is and its data length
is nonzero, the data is written to the sound file download
buffer in flash memory. A zero length download packet
indicates the end of data and contains a checksum. If
it’s a code update, the buffer needs to be copied to
the executable code area, overwriting the existing code.
The bootloader handles this and will reset the system
if the update succeeds.
Finally,
the code checks the packet’s flags. Two flags control
output actions, activating either the auxiliary output
or the sound playback function. The playback routine
looks for a wav formatted file in the sound file flash
memory buffer area, which must be in 8-bit 8-kHz PCM
format. If the file is found, it turns on the external
amplifier and plays the sound file. The file can be
looped several times as specified by the packet flags
to produce up to 5 s of sound. A third packet flag enables
Download mode, which erases the download buffer and
prepares to receive a new data file.