From 206024b2c74516c83d71a253900a0187b1fedf4c Mon Sep 17 00:00:00 2001 From: Carl Klemm Date: Fri, 17 Jan 2020 17:25:37 +0100 Subject: [PATCH] Relay dispatch now waits for reciver to finish reciving packet --- CMakeCache.txt | 6 +++--- CMakeLists.txt | 2 +- W433DataReciver.cpp | 5 +++++ W433DataReciver.h | 1 + main.cpp | 8 +++++--- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CMakeCache.txt b/CMakeCache.txt index 3d982c5..1e71adc 100644 --- a/CMakeCache.txt +++ b/CMakeCache.txt @@ -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=14 +CMAKE_CACHE_MINOR_VERSION:INTERNAL=15 //Patch version of cmake used to create the current loaded cache -CMAKE_CACHE_PATCH_VERSION:INTERNAL=4 +CMAKE_CACHE_PATCH_VERSION:INTERNAL=5 //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.14 +CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.15 //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ff9cc9..8bd4cc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ set(CMAKE_LINKER /usr/bin/avr-ld) # Compiler flags add_definitions(-mmcu=${MCU} -DF_CPU=${CPU_SPEED}) -add_definitions(-s -c -g -Os -flto -Wall -std=c++17 ) +add_definitions(-s -c -g -Os -flto -Wall -std=c++17 -fno-strict-aliasing) add_definitions(-fno-exceptions -ffunction-sections -fdata-sections) # Linker flags diff --git a/W433DataReciver.cpp b/W433DataReciver.cpp index e9b8387..4a9173d 100644 --- a/W433DataReciver.cpp +++ b/W433DataReciver.cpp @@ -48,6 +48,11 @@ int8_t W433DataReciver::reciveBit(uint8_t index) else return -1; } +void W433DataReciver::waitForReciveIdle(const uint16_t timeoutMs) +{ + for(uint16_t i = 0; i < timeoutMs && state != LOOKING_FOR_SYNC; ++i ) _delay_ms(1); +} + bool W433DataReciver::isTime(int16_t input, const uint16_t time, const bool state, const uint16_t tollerance) { diff --git a/W433DataReciver.h b/W433DataReciver.h index 01baf58..5673467 100644 --- a/W433DataReciver.h +++ b/W433DataReciver.h @@ -86,6 +86,7 @@ public: ~W433DataReciver(); static void initTimer(); static void staticInterrupt(); + void waitForReciveIdle(const uint16_t timeoutMs = 2000); void interrupt(); #ifdef USE_RINGBUFFER RingBuffer* getRingBuffer(); diff --git a/main.cpp b/main.cpp index fceccbb..d716589 100644 --- a/main.cpp +++ b/main.cpp @@ -298,7 +298,7 @@ void auxDispatch(Pwm16b* auxPwm, char* token, Serial* serial) } } -void serialDispatch(Serial* serial, SVector* relays, RgbLed* rgbled, Pwm16b* auxPwm) +void serialDispatch(Serial* serial, SVector* relays, RgbLed* rgbled, Pwm16b* auxPwm, W433DataReciver* reciver) { if(serial->dataIsWaiting()) @@ -315,6 +315,7 @@ void serialDispatch(Serial* serial, SVector* relays, } else if(strcmp(token, "rgb") == 0) { + reciver->waitForReciveIdle(); rgbDispatch(rgbled, strtok(NULL, " \n"), serial); } else if(strcmp(token, "aux") == 0) @@ -440,13 +441,13 @@ int main() setBit(&PCMSK1, PCINT8, true); W433DataReciver reciver(&PINC, PC0, &TCNT1, &TIFR1, &sensorPacketRecived, reinterpret_cast(&serial), &reciverError); - serial.write_p(PSTR("RGBController v1.0 starting\n")); + serial.write_p(PSTR("RGBController v1.1 starting\n")); load(); while(true) { - serialDispatch(&serial, &relays, &rgbled, &pwmTc1); + serialDispatch(&serial, &relays, &rgbled, &pwmTc1, &reciver); rgbled.logic(); if(doorOne != readPin(&PINB, PB3) && !sensorsPaused) @@ -486,6 +487,7 @@ int main() { for(uint16_t i = 0; i < relays.count(); i++) { + reciver.waitForReciveIdle(); relays[i].resend(); _delay_ms(100); }