Arduino KVComm  master
Key-Value pair communication library for Arduino
SLIPSender.ipp
Go to the documentation of this file.
1 #include "SLIPSender.hpp"
2 
3 template <class Sender>
4 size_t SLIPSender<Sender>::write(const uint8_t *data, size_t len) {
5  using namespace SLIP_Constants;
6 
7  size_t sent = 0;
8 
9  /*
10  * for each byte in the packet, send the appropriate character
11  * sequence
12  */
13  while (len--) {
14  switch (*data) {
15  /*
16  * if it's the same code as an END character, we send a
17  * special two character code so as not to make the
18  * receiver think we sent an END
19  */
20  case END:
21  sent += this->sender(ESC);
22  sent += this->sender(ESC_END);
23  break;
24 
25  /*
26  * if it's the same code as an ESC character,
27  * we send a special two character code so as not
28  * to make the receiver think we sent an ESC
29  */
30  case ESC:
31  sent += this->sender(ESC);
32  sent += this->sender(ESC_ESC);
33  break;
34  /*
35  * otherwise, we just send the character
36  */
37  default: sent += this->sender(*data);
38  }
39 
40  data++;
41  }
42 
43  return sent;
44 }
45 
46 template <class Sender, class CRC>
47 size_t SLIPSenderCRC<Sender, CRC>::write(const uint8_t *data, size_t len) {
48  this->crc.process_bytes(data, len);
49  return sender.write(data, len);
50 }
SLIPSender::write
size_t write(const uint8_t *data, size_t len)
Write some data as the body of a packet.
Definition: SLIPSender.ipp:4
SLIP_Constants
SLIP special character codes.
Definition: SLIP.hpp:9
SLIP_Constants::ESC_END
const static uint8_t ESC_END
ESC ESC_END means END data byte.
Definition: SLIP.hpp:12
SLIP_Constants::ESC_ESC
const static uint8_t ESC_ESC
ESC ESC_ESC means ESC data byte.
Definition: SLIP.hpp:13
SLIPSenderCRC::write
size_t write(const uint8_t *data, size_t len)
Write some data as the body of a packet.
Definition: SLIPSender.ipp:47
SLIP_Constants::ESC
const static uint8_t ESC
indicates byte stuffing
Definition: SLIP.hpp:11
SLIPSender.hpp
SLIP_Constants::END
const static uint8_t END
indicates end of packet
Definition: SLIP.hpp:10