openEmbroider  0.1
an open source embroidery software
uartconnect.hpp
1 #pragma once
2 
3 #include "uart.hpp"
4 
5 template<unsigned packetSize>
7 {
8 public:
9  UartConnect() : bytealtered_ppm(0), bytelost_ppm(0), remote(0) {}
10  void connect(UartBlock<packetSize>* uart)
11  {
12  remote = uart;
13  }
14  virtual void send(const uint8_t* buffer, unsigned len)
15  {
16  while(len--) {
17  if ((rand()&((1<<20)-1))>bytelost_ppm) {
18  if((rand()&((1<<20)-1))>bytealtered_ppm) {
19  remote->onChar(*buffer++);
20  } else {
21  remote->onChar((*buffer++)^42);
22  }
23  } else {
24  buffer++;
25  }
26  }
27  }
28  unsigned bytealtered_ppm;
29  unsigned bytelost_ppm;
30 private:
31  UartBlock<packetSize>* remote;
32 };
Definition: uart.hpp:7
Definition: uartconnect.hpp:6