diff --git a/mos.yml b/mos.yml index 647a7cd..4ad4820 100644 --- a/mos.yml +++ b/mos.yml @@ -23,6 +23,7 @@ cdefs: MPIDE: 0 TEENSYDUINO: 0 RH_PLATFORM: RH_PLATFORM_ESP8266 + MONGOOSE_OS: 1 libs: # common mgos libs diff --git a/src/RadioHead/RHGenericDriver.cpp b/src/RadioHead/RHGenericDriver.cpp index 3ca5e74..bc7ec12 100644 --- a/src/RadioHead/RHGenericDriver.cpp +++ b/src/RadioHead/RHGenericDriver.cpp @@ -144,18 +144,11 @@ void RHGenericDriver::printBuffer(const char* prompt, const uint8_t* buf, uint8_ uint8_t i; #ifdef RH_HAVE_SERIAL - Serial.println(prompt); + LOG(LL_DEBUG, ("%s", prompt)); for (i = 0; i < len; i++) { - if (i % 16 == 15) - Serial.println(buf[i], HEX); - else - { - Serial.print(buf[i], HEX); - Serial.print(' '); - } + LOG(LL_DEBUG, (" %d: %02x", i, buf[i])); } - Serial.println(""); #endif } diff --git a/src/RadioHead/RHHardwareSPI.cpp b/src/RadioHead/RHHardwareSPI.cpp index 4b1e064..a0aaab2 100644 --- a/src/RadioHead/RHHardwareSPI.cpp +++ b/src/RadioHead/RHHardwareSPI.cpp @@ -252,7 +252,7 @@ void RHHardwareSPI::begin() SPI.begin(frequency, bitOrder, dataMode); #elif (RH_PLATFORM == RH_PLATFORM_STM32F2) // Photon - Serial.println("HERE"); + //Serial.println("HERE"); uint8_t dataMode; if (_dataMode == DataMode0) dataMode = SPI_MODE0; diff --git a/src/RadioHead/RHReliableDatagram.cpp b/src/RadioHead/RHReliableDatagram.cpp index 811fdf6..f9bacd7 100644 --- a/src/RadioHead/RHReliableDatagram.cpp +++ b/src/RadioHead/RHReliableDatagram.cpp @@ -13,6 +13,38 @@ #include "RHReliableDatagram.h" +#ifdef MONGOOSE_OS +/* +static bool s_randomSeedCalled = false; + +static void randomSeed(unsigned long seed) { + if(seed != 0) { + srand(seed); + s_randomSeedCalled = true; + } +} +*/ + +static long random(long howbig) { + if(howbig == 0) { + return 0; + } + // if randomSeed was called, fall back to software PRNG + // uint32_t val = (s_randomSeedCalled) ? rand() : RANDOM_REG32; + uint32_t val = rand(); + return val % howbig; +} + +static long random(long howsmall, long howbig) { + if(howsmall >= howbig) { + return howsmall; + } + long diff = howbig - howsmall; + return random(diff) + howsmall; +} +#endif + + //////////////////////////////////////////////////////////////////// // Constructors RHReliableDatagram::RHReliableDatagram(RHGenericDriver& driver, uint8_t thisAddress) diff --git a/src/RadioHead/RHRouter.cpp b/src/RadioHead/RHRouter.cpp index 1f7414e..ca27fcd 100644 --- a/src/RadioHead/RHRouter.cpp +++ b/src/RadioHead/RHRouter.cpp @@ -109,13 +109,7 @@ void RHRouter::printRoutingTable() uint8_t i; for (i = 0; i < RH_ROUTING_TABLE_SIZE; i++) { - Serial.print(i, DEC); - Serial.print(" Dest: "); - Serial.print(_routes[i].dest, DEC); - Serial.print(" Next Hop: "); - Serial.print(_routes[i].next_hop, DEC); - Serial.print(" State: "); - Serial.println(_routes[i].state, DEC); + LOG(LL_DEBUG, ("%d Dest: %d, Next Hop: %d, State: %d", i, _routes[i].dest, _routes[i].next_hop, _routes[i].state)); } #endif } @@ -197,6 +191,8 @@ uint8_t RHRouter::route(RoutedMessage* message, uint8_t messageLen) // Subclasses may want to override this to peek at messages going past void RHRouter::peekAtMessage(RoutedMessage* message, uint8_t messageLen) { + (void) message; + (void) messageLen; // Default does nothing } diff --git a/src/RadioHead/RH_NRF24.cpp b/src/RadioHead/RH_NRF24.cpp index 948b96d..1ddc58c 100644 --- a/src/RadioHead/RH_NRF24.cpp +++ b/src/RadioHead/RH_NRF24.cpp @@ -236,8 +236,7 @@ bool RH_NRF24::printRegisters() { if ((r <= RH_NRF24_REG_17_FIFO_STATUS) || (r >= RH_NRF24_REG_1C_DYNPD)) { - Serial.print(r, HEX); - Serial.print(": "); + LOG(LL_DEBUG, ("%02x: ", r)); uint8_t len = 1; // Address registers are 5 bytes in size if ( (RH_NRF24_REG_0A_RX_ADDR_P0 == r) @@ -250,10 +249,8 @@ bool RH_NRF24::printRegisters() spiBurstReadRegister(r, buf, len); for (uint8_t j = 0; j < len; ++j) { - Serial.print(buf[j], HEX); - Serial.print(" "); + LOG(LL_DEBUG, (" %d: %02x", j, buf[j])); } - Serial.println(""); } } #endif diff --git a/src/RadioHead/RadioHead.h b/src/RadioHead/RadioHead.h index 8e53d59..7e8c5b8 100644 --- a/src/RadioHead/RadioHead.h +++ b/src/RadioHead/RadioHead.h @@ -669,6 +669,9 @@ #define RadioHead_h #include "Arduino.h" +#if defined(MONGOOSE_OS) +#include "mgos.h" +#endif // Official version numbers are maintained automatically by Makefile: #define RH_VERSION_MAJOR 1 @@ -837,6 +840,16 @@ #error Platform unknown! #endif +#ifdef MONGOOSE_OS +#ifndef xt_rsil + #define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state)); state;})) +#endif + +#ifndef xt_wsr_ps + #define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory") +#endif +#endif + //////////////////////////////////////////////////// // This is an attempt to make a portable atomic block #if (RH_PLATFORM == RH_PLATFORM_ARDUINO) @@ -877,9 +890,6 @@ #define YIELD yield(); #elif (RH_PLATFORM == RH_PLATFORM_ESP8266) // ESP8266 also hash it -#if defined(MONGOOSE_OS) -extern void yield(void); -#endif #define YIELD yield(); #else #define YIELD