27 #if defined(ARDUINO) && ARDUINO < 100
28 #error "This library requires Arduino 1.0 or newer."
32 #define KANGAROO_BIT_PACKED_MAX_VALUE 536870911
33 #define KANGAROO_COMMAND_MAX_DATA_LENGTH 27
34 #define KANGAROO_COMMAND_MAX_BUFFER_LENGTH 32
35 #define KANGAROO_CRC_GOOD_VALUE 0x307e
36 #define KANGAROO_DEFAULT_ADDRESS 128
37 #define KANGAROO_DEFAULT_COMMAND_RETRY_INTERVAL 100
38 #define KANGAROO_DEFAULT_COMMAND_TIMEOUT KANGAROO_INFINITE_TIMEOUT
39 #define KANGAROO_INFINITE_TIMEOUT -1
40 #define KANGAROO_UNSPECIFIED_LIMIT -1
59 KANGAROO_UNRECOGNIZED_CODE = 0x05,
61 KANGAROO_INVALID_STATUS = -0x01,
63 KANGAROO_PORT_NOT_OPEN = -0x03
87 KANGAROO_GET_ECHO_CODE = 0x10,
89 KANGAROO_GET_SEQUENCE_CODE = 0x40
101 KANGAROO_MOVE_SEQUENCE_CODE = 0x40
113 KANGAROO_STATUS_ECHO_CODE = 0x10,
115 KANGAROO_STATUS_SEQUENCE_CODE = 0x40
120 KANGAROO_CMD_START = 0x20,
121 KANGAROO_CMD_UNITS = 0x21,
122 KANGAROO_CMD_HOME = 0x22,
123 KANGAROO_CMD_STATUS = 0x23,
124 KANGAROO_CMD_MOVE = 0x24,
125 KANGAROO_CMD_SYSTEM = 0x25
164 enum KangarooReplyCode
166 KANGAROO_RC_STATUS = 0x43
173 void write(byte data);
174 void write(
const byte* data,
size_t lengthOfData);
178 inline uint16_t value()
const {
return _crc; }
179 void value(uint16_t crc) { _crc = crc; }
181 static uint16_t value(
const byte* data,
size_t lengthOfData);
187 class KangarooCommandWriter
190 KangarooCommandWriter();
193 inline const byte* data ()
const {
return _data; }
194 inline size_t length ()
const {
return _length; }
197 void write ( byte data );
198 void write (
const byte* data,
size_t length);
199 void writeBitPackedNumber( int32_t number );
202 size_t writeToBuffer(byte* buffer, byte address, KangarooCommand command)
const;
203 static size_t writeToBuffer(byte* buffer, byte address, KangarooCommand command,
const byte* data,
size_t lengthOfData);
204 void writeToStream(Stream& port, byte address, KangarooCommand command)
const;
205 static void writeToStream(Stream& port, byte address, KangarooCommand command,
const byte* data,
size_t lengthOfData);
208 byte _address, _command;
size_t _length;
209 byte _data[KANGAROO_COMMAND_MAX_DATA_LENGTH];
212 class KangarooReplyReceiver
215 KangarooReplyReceiver();
218 inline byte address()
const {
return _data[0]; }
219 inline KangarooReplyCode command()
const {
return (KangarooReplyCode)_data[1]; }
220 inline const byte* data ()
const {
return &_data[3]; }
221 inline size_t length ()
const {
return _length - 5; }
224 inline boolean ready()
const {
return _ready; }
225 void read (byte data);
229 size_t _length;
boolean _ready;
230 byte _data[KANGAROO_COMMAND_MAX_BUFFER_LENGTH];
233 class KangarooReplyReader
236 KangarooReplyReader(
const byte* data,
size_t length);
239 boolean canRead ()
const;
240 boolean tryRead (byte* value);
242 int32_t readBitPackedNumber();
246 const byte* _dataEnd;
270 inline char channel()
const {
return (
char)_channel; }
288 inline int32_t
value()
const {
return _value; }
290 inline byte echoCode ()
const {
return _echoCode; }
291 inline byte sequenceCode()
const {
return _sequenceCode; }
292 inline boolean valid ()
const {
return _valid; }
332 boolean parse(
const byte* data,
size_t length);
336 byte _channel, _flags, _echoCode, _sequenceCode, _type;
360 inline Stream&
port() {
return _port; }
363 boolean tryReceivePacket();
370 KangarooReplyReceiver _receiver;
426 friend class Kangaroo;
450 inline char name()
const {
return _name; }
456 inline byte
address()
const {
return _address; }
644 inline void streaming(
boolean enabled) { _streaming = enabled; }
689 KangarooCommandWriter& contents,
692 void setNoReply(KangarooCommand command, KangarooCommandWriter& contents,
696 boolean updateMonitoredResult(
const KangarooTimeout& timeout,
boolean acceptRepliesWithStartupSequenceCode);
706 int32_t _commandRetryInterval;
707 int32_t _commandTimeout;
709 uint32_t _monitorCode;
713 byte _monitoredSequenceCode;
714 boolean _monitoredSequenceCodeIsReady;
738 boolean valid()
const;
781 uint32_t monitorCode;