#include <iostream>
#include <time.h>
#include <cassert>
#include "SerialPortReceiverThread.h"

SerialPortReceiverThread::SerialPortReceiverThread(
	SerialPort& serialPort, ON_BYTE_RECEIVED onByteReceived)
	: serialPort(serialPort), onByteReceived(onByteReceived)
{

}

bool SerialPortReceiverThread::run()
{
	uint8_t data;
	if (serialPort.IsOpen()) {
		if (serialPort.Read(&data, 0, 1)) {
			this->onByteReceived(data);
		}
		else {
			Sleep(10);
		}
	}
	return true;
}

#include <iostream>
#include <time.h>
#include <cassert>
#include "SerialPortReceiverThread.h"

SerialPortReceiverThread::SerialPortReceiverThread(
	SerialPort& serialPort, ON_BYTE_RECEIVED onByteReceived)
	: serialPort(serialPort), onByteReceived(onByteReceived)
{

}

bool SerialPortReceiverThread::run()
{
	uint8_t data;
	if (serialPort.IsOpen()) {
		if (serialPort.Read(&data, 0, 1) == 1) {
			this->onByteReceived(data);
		}
		else {
			Sleep(10);
		}
	}
	return true;
}

Fix a bug receiving unknown character
Fix a bug receiving unknown character

On timeout in receiving, treat a invalid character as valid.
