Added reciver debugging
This commit is contained in:
@ -8,8 +8,8 @@
|
||||
|
||||
W433DataReciver* W433DataReciver::instance = nullptr;
|
||||
|
||||
W433DataReciver::W433DataReciver(volatile unsigned char* const port , const unsigned char pin, volatile uint16_t * timerRegister, volatile uint8_t* const timerOverflowRegister, void (* const packetCallback)(uint32_t, void*), void* const userData ):
|
||||
_port(port), _pin(pin), _timerRegister(timerRegister), _timerOverflowRegister(timerOverflowRegister), _packetCallback(packetCallback), _userData(userData)
|
||||
W433DataReciver::W433DataReciver(volatile unsigned char* const port , const unsigned char pin, volatile uint16_t * timerRegister, volatile uint8_t* const timerOverflowRegister, void (* const packetCallback)(uint32_t, void*), void* const userData, void (*errorCodeHandler)(uint8_t, void*) ):
|
||||
_port(port), _pin(pin), _timerRegister(timerRegister), _timerOverflowRegister(timerOverflowRegister), _packetCallback(packetCallback), _errorCodeHandler(errorCodeHandler), _userData(userData)
|
||||
{
|
||||
instance = this;
|
||||
for(uint8_t i = 0; i < 33; i++) timesBuffer[i] = 0;
|
||||
@ -62,7 +62,11 @@ bool W433DataReciver::reciveSync(const uint16_t elapsedTime)
|
||||
{
|
||||
++syncCount;
|
||||
}
|
||||
else syncCount = 0;
|
||||
else
|
||||
{
|
||||
if(syncCount > 5) error(ERR_SYNC_FAIL);
|
||||
syncCount = 0;
|
||||
}
|
||||
if(syncCount > 10) return true;
|
||||
else return false;
|
||||
}
|
||||
@ -81,12 +85,21 @@ uint8_t W433DataReciver::assmbleByte()
|
||||
{
|
||||
int8_t bit = reciveBit(i*4);
|
||||
if(bit >= 0) byte = byte | (bit << (7-i));
|
||||
else setState(LOOKING_FOR_SYNC);
|
||||
else
|
||||
{
|
||||
setState(LOOKING_FOR_SYNC);
|
||||
error(ERR_BYTE_ASM);
|
||||
}
|
||||
}
|
||||
timesBufferIndex = 0;
|
||||
return byte;
|
||||
}
|
||||
|
||||
void W433DataReciver::error(const uint8_t errorCode)
|
||||
{
|
||||
if(_errorCodeHandler != nullptr) (*_errorCodeHandler)(errorCode, _userData);
|
||||
}
|
||||
|
||||
void W433DataReciver::setState(const uint8_t stateIn)
|
||||
{
|
||||
state = stateIn;
|
||||
@ -119,7 +132,11 @@ void W433DataReciver::interrupt()
|
||||
{
|
||||
if(elapsedTime > SYNC_TIME + 50)
|
||||
{
|
||||
if(elapsedTime < LARGE_TIME + 50) setState(LOOKING_FOR_SYNC);
|
||||
if(elapsedTime < LARGE_TIME + 50)
|
||||
{
|
||||
setState(LOOKING_FOR_SYNC);
|
||||
error(ERR_NO_SYNC_END);
|
||||
}
|
||||
else
|
||||
{
|
||||
timesBuffer[0] = -LARGE_TIME;
|
||||
@ -134,7 +151,11 @@ void W433DataReciver::interrupt()
|
||||
{
|
||||
uint8_t recivedSignature = assmbleByte();
|
||||
if( recivedSignature == signature) setState(RECVING_PACKET);
|
||||
else setState(LOOKING_FOR_SYNC);
|
||||
else
|
||||
{
|
||||
error(ERR_WRONG_SIG);
|
||||
setState(LOOKING_FOR_SYNC);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( state == RECVING_PACKET )
|
||||
@ -170,6 +191,7 @@ void W433DataReciver::interrupt()
|
||||
_ringBuffer.write(const_cast<uint8_t*>(buffer), sizeof(packet));
|
||||
if(_packetCallback != nullptr)(*_packetCallback)(packet, _userData);
|
||||
}
|
||||
else error(ERR_CHECKSUM);
|
||||
packet = 0;
|
||||
setState(LOOKING_FOR_SYNC);
|
||||
}
|
||||
|
Reference in New Issue
Block a user