reciver changes

This commit is contained in:
2019-10-06 17:27:58 +02:00
parent 53c42b050a
commit d91e08db15
6 changed files with 37 additions and 22 deletions

View File

@ -242,9 +242,9 @@ CMAKE_CACHEFILE_DIR:INTERNAL=/home/philipp/Programming/avr/RGBcontroller
//Major version of cmake used to create the current loaded cache
CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3
//Minor version of cmake used to create the current loaded cache
CMAKE_CACHE_MINOR_VERSION:INTERNAL=13
CMAKE_CACHE_MINOR_VERSION:INTERNAL=14
//Patch version of cmake used to create the current loaded cache
CMAKE_CACHE_PATCH_VERSION:INTERNAL=2
CMAKE_CACHE_PATCH_VERSION:INTERNAL=4
//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE
CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1
//Path to CMake executable.
@ -343,7 +343,7 @@ CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1
//ADVANCED property for variable: CMAKE_RANLIB
CMAKE_RANLIB-ADVANCED:INTERNAL=1
//Path to CMake installation.
CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.13
CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.14
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG

View File

@ -30,8 +30,8 @@ int8_t W433DataReciver::reciveBit(uint8_t index)
if(
timesBuffer[index] < 0 &&
isTime(timesBuffer[index+1], SMALL_TIME, true, SMALL_TIME_TOLERANCE) &&
isTime(timesBuffer[index+2], LARGE_TIME, false, LARGE_TIME_TOLERANCE) &&
isTime(timesBuffer[index+3], SMALL_TIME, true, SMALL_TIME_TOLERANCE)
isTime(timesBuffer[index+2], LARGE_TIME, false, LARGE_TIME_TOLERANCE) //&&
//isTime(timesBuffer[index+3], SMALL_TIME, true, SMALL_TIME_TOLERANCE)
)
{
return 1;
@ -39,8 +39,8 @@ int8_t W433DataReciver::reciveBit(uint8_t index)
else if(
timesBuffer[index] < 0 &&
isTime(timesBuffer[index+1], LARGE_TIME, true, LARGE_TIME_TOLERANCE) &&
isTime(timesBuffer[index+2], SMALL_TIME, false, SMALL_TIME_TOLERANCE) &&
isTime(timesBuffer[index+3], SMALL_TIME, true, SMALL_TIME_TOLERANCE)
isTime(timesBuffer[index+2], SMALL_TIME, false, SMALL_TIME_TOLERANCE) //&&
//isTime(timesBuffer[index+3], SMALL_TIME, true, SMALL_TIME_TOLERANCE)
)
{
return 0;
@ -67,8 +67,8 @@ bool W433DataReciver::reciveSync(const uint16_t elapsedTime)
if(syncCount > 4 && syncFailCount < 3) ++syncFailCount;
else
{
syncCount = 0;
syncFailCount = 0;
//if(syncCount > 7) error(ERR_SYNC_FAIL);
setState(LOOKING_FOR_SYNC);
}
}
if(syncCount > 10) return true;
@ -79,6 +79,7 @@ bool W433DataReciver::recivedByte(const uint16_t elapsedTime)
{
timesBuffer[timesBufferIndex] = readPin(_port, _pin) ? 0-elapsedTime : elapsedTime;
++timesBufferIndex;
if(timesBufferIndex == 32) writePin(&PORTC, PC0, true);
return timesBufferIndex == 32;
}
@ -119,14 +120,14 @@ void W433DataReciver::interrupt()
if(elapsedTime < DISCARD_TIME)
{
if(timesBufferIndex > 0 && elapsedTime + timesBuffer[timesBufferIndex-1] < LARGE_TIME+LARGE_TIME_TOLERANCE)
if(timesBufferIndex > 0 && elapsedTime + abs(timesBuffer[timesBufferIndex-1]) < LARGE_TIME+LARGE_TIME_TOLERANCE)
{
writePin(&PORTC, PC2, true);
previousTime = *_timerRegister - elapsedTime - abs(timesBuffer[timesBufferIndex-1]);
--timesBufferIndex;
timesBufferIndex-=1;
}
return;
}
previousTime = *_timerRegister;
*_timerOverflowRegister = *_timerOverflowRegister | 0x01;
@ -136,7 +137,7 @@ void W433DataReciver::interrupt()
}
else if(state == LOOKING_FOR_SYNC_END)
{
if(elapsedTime > SYNC_TIME + SYNC_TIME_TOLERANCE)
if(elapsedTime > SYNC_TIME + SYNC_END_TIME_TOLERANCE)
{
if(elapsedTime < LARGE_TIME - LARGE_TIME_TOLERANCE)
{
@ -194,7 +195,9 @@ void W433DataReciver::interrupt()
if(computedChecksum == recivedChecksum)
{
#ifdef USE_RINGBUFFER
_ringBuffer.write(const_cast<uint8_t*>(buffer), sizeof(packet));
#endif
if(_packetCallback != nullptr)(*_packetCallback)(packet, _userData);
}
else error(ERR_CHECKSUM);
@ -204,7 +207,9 @@ void W433DataReciver::interrupt()
}
}
#ifdef USE_RINGBUFFER
RingBuffer<W433DataReciver::RINGBUFFER_LENGTH, uint8_t>* W433DataReciver::getRingBuffer()
{
return &_ringBuffer;
}
#endif

View File

@ -2,10 +2,12 @@
#include <stdint.h>
#include "ringbuffer.h"
//#define USE_RINGBUFFER
class W433DataReciver
{
public:
static constexpr uint8_t RINGBUFFER_LENGTH = 32;
//errors
@ -25,9 +27,10 @@ private:
static constexpr uint16_t LARGE_TIME = 2000;
static constexpr uint16_t SMALL_TIME = 500;
static constexpr uint8_t SYNC_TIME_TOLERANCE = SYNC_TIME*0.20;
static constexpr uint16_t SYNC_END_TIME_TOLERANCE = SYNC_TIME*0.80;
static constexpr uint16_t LARGE_TIME_TOLERANCE = LARGE_TIME*0.30;
static constexpr uint8_t SMALL_TIME_TOLERANCE = SMALL_TIME*0.30;
static constexpr uint8_t DISCARD_TIME = SMALL_TIME*0.3;
static constexpr uint16_t DISCARD_TIME = SMALL_TIME*0.6;
static constexpr uint16_t TICKS_PER_US = (F_CPU) / (1000000*CLOCK_DEVIDER) ;
static constexpr uint8_t signature = 0xA5;
@ -46,7 +49,9 @@ private:
volatile uint16_t *_timerRegister;
volatile uint8_t *_timerOverflowRegister;
#ifdef USE_RINGBUFFER
RingBuffer<RINGBUFFER_LENGTH, uint8_t> _ringBuffer;
#endif
volatile uint16_t previousTime = 0;
volatile uint8_t timesBufferIndex = 0;
@ -82,5 +87,7 @@ public:
static void initTimer();
static void staticInterrupt();
void interrupt();
#ifdef USE_RINGBUFFER
RingBuffer<RINGBUFFER_LENGTH, uint8_t>* getRingBuffer();
#endif
};

View File

@ -7,10 +7,10 @@
class WirelessRelay
{
public:
static const uint16_t LARGE_TIME = 750;
static const uint8_t SMALL_TIME = 250;
static constexpr uint16_t LARGE_TIME = 750;
static constexpr uint8_t SMALL_TIME = 250;
static const uint16_t MAX_NAME_LENGTH = 16;
static constexpr uint16_t MAX_NAME_LENGTH = 16;
private:
bool _state = false;

View File

@ -49,7 +49,7 @@ inline static void printHelp(Serial* serial)
serial->write_p(PSTR("Available Commands: \n\
help : Show this prompt.\n\
relay add [id] [name] : Add Wireless Relay.\n\
relay delete : Delete last Relay.\n\
relay delete [n] : Delete n'th Relay.\n\
relay [on/off] [nn] : Turn on/off nth relay.\n\
relay resend [on/off] : Turn on/off periodic auto resend.\n\
state : Get machine readable state.\n\
@ -134,11 +134,14 @@ void relayDispatch(SVector<WirelessRelay, MAX_RELAYS>* relays, Pwm16b* auxPwm, c
}
else if( strcmp(token, "delete") == 0 )
{
token = strtok(NULL, " \n");
if(relays->count() > 0)
{
relays->erase(relays->count());
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "Deleting relay NUMBER: %u NAME: %s\n", relays->count(), relays->at(relays->count()).getName());
uint16_t index = relays->count();
if( token != NULL) index = atoi(token);
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "Deleting relay NUMBER: %u NAME: %s\n", index, relays->at(index).getName());
serial->write(buffer, SNPRINTF_BUFFER_SIZE);
relays->erase(index);
save();
}
}

View File

@ -71,7 +71,7 @@ public:
if(position > stored) return false;
array[position].~T();
--stored;
for( size_t i = position; i < stored; i++ ) array[i] = array[i+1];
for( size_t i = position; i < stored; i++ ) memcpy(&array[i], &array[i+1], sizeof(T));
return true;
}