Line data Source code
1 : #include "SLIPSender.hpp" 2 : 3 : template <class Sender> 4 7 : size_t SLIPSender<Sender>::write(const uint8_t *data, size_t len) { 5 : using namespace SLIP_Constants; 6 : 7 7 : size_t sent = 0; 8 : 9 : /* 10 : * for each byte in the packet, send the appropriate character 11 : * sequence 12 : */ 13 77 : while (len--) { 14 70 : 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 7 : sent += this->sender(ESC); 22 7 : sent += this->sender(ESC_END); 23 7 : 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 6 : sent += this->sender(ESC); 32 6 : sent += this->sender(ESC_ESC); 33 6 : break; 34 : /* 35 : * otherwise, we just send the character 36 : */ 37 57 : default: sent += this->sender(*data); 38 57 : } 39 : 40 70 : data++; 41 : } 42 : 43 14 : return sent; 44 7 : } 45 : 46 : template <class Sender, class CRC> 47 3 : size_t SLIPSenderCRC<Sender, CRC>::write(const uint8_t *data, size_t len) { 48 3 : this->crc.process_bytes(data, len); 49 3 : return sender.write(data, len); 50 : }