Reference
\param data The command data.
\param length The number of bytes of data.
\param buffer The buffer to write into.
\return How many bytes were written. This always equals 4 + length. */
size_t writeKangarooCommand(uint8_t address, uint8_t command,
const uint8_t* data, uint8_t length,
uint8_t* buffer)
{
size_t i; uint16_t crc;
buffer[0] = address; buffer[1] = command;
for (i = 0; i < length; i ++) { buffer[2 + i] = data[i]; }
crc = crc14(data, 2 + length);
buffer[2 + length] = crc & 0x7f;
buffer[3 + length] = (crc >> 7) & 0x7f;
return 4 + length;
}
/*! Writes a Move command for Position into a buffer.
This could have many, many more options, but I've kept it basic
to make the example easier to read.
\param address The address of the Kangaroo. By default, this is 128.
\param channel The channel name.
By default, for Independent Mode, these are '1' and '2'.
For Mixed Mode, these are 'D' and 'T'.
\param position The position to go to.
\param speedLimit The speed limit to use. Negative numbers use the default.
\param buffer The buffer to write into.
\return How many bytes were written (at most 18). */
size_t writeKangarooPositionCommand(uint8_t address, char channel,
int32_t position, int32_t speedLimit,
uint8_t* buffer)
{
uint8_t data[14]; size_t length = 0;
data[length ++] = (uint8_t)channel;
data[length ++] = 0;
// move flags
data[length ++] = 1;
// Position
length += bitpackNumber(&data[length], position);
if (speedLimit >= 0)
{
data[length ++] = 2;
// Speed (Limit if combined with Position)
length += bitpackNumber(&data[length], speedLimit);
}
return writeKangarooCommand(address, 36, data, length, buffer);
}
7