#pragma once

#include "uart.hpp"

template<unsigned packetSize>
class UartConnect
{
public:
	UartConnect() : bytealtered_ppm(0), bytelost_ppm(0), remote(0) {}
	void connect(UartBlock<packetSize>* uart)
	{
		remote = uart;
	}
	virtual void send(const uint8_t* buffer, unsigned len)
	{
		while(len--) {
			if ((rand()&((1<<20)-1))>bytelost_ppm) {
				if((rand()&((1<<20)-1))>bytealtered_ppm) {
					remote->onChar(*buffer++);
				} else {
					remote->onChar((*buffer++)^42);
				}
			} else {
				buffer++;
			}
		}
	}
	unsigned bytealtered_ppm;
	unsigned bytelost_ppm;
private:
	UartBlock<packetSize>* remote;
};
