diff --git a/src/NoiseFloorDetector.cpp b/src/NoiseFloorDetector.cpp index 3abc32f..7fa5a60 100644 --- a/src/NoiseFloorDetector.cpp +++ b/src/NoiseFloorDetector.cpp @@ -22,14 +22,15 @@ NoiseFloorDetector &NoiseFloorDetector::instance() NoiseFloorDetector::NoiseFloorDetector() : mUTC(0), mStartTime(0), mLastDumpTime(0) { + mSorted.reserve(WINDOW_SIZE); EventQueue::instance().addObserver(this, CLOCK_EVENT); } -uint8_t NoiseFloorDetector::report(VHFChannel channel, uint8_t rssi) +void NoiseFloorDetector::report(VHFChannel channel, uint8_t rssi) { // If we don't have time yet, we certainly don't have fix so we can't be transmitting anyway, so no data collection if ( mUTC == 0 ) - return 0xff; + return; if ( mData.find(channel) == mData.end() ) { ChannelReadings r; @@ -38,7 +39,7 @@ uint8_t NoiseFloorDetector::report(VHFChannel channel, uint8_t rssi) } ChannelReadings &window = mData[channel]; - return processSample(window, rssi); + processSample(window, rssi); } uint8_t NoiseFloorDetector::getNoiseFloor(VHFChannel channel) @@ -69,7 +70,7 @@ void NoiseFloorDetector::processEvent(Event *e) } } -uint8_t NoiseFloorDetector::processSample(ChannelReadings &window, uint8_t rssi) +void NoiseFloorDetector::processSample(ChannelReadings &window, uint8_t rssi) { while ( window.size() >= WINDOW_SIZE ) window.pop_back(); @@ -79,7 +80,7 @@ uint8_t NoiseFloorDetector::processSample(ChannelReadings &window, uint8_t rssi) r.timestamp = mUTC; r.reading = rssi; window.push_back(r); - return 0xff; + return; } // Insert the reading at the start if it qualifies @@ -92,11 +93,6 @@ uint8_t NoiseFloorDetector::processSample(ChannelReadings &window, uint8_t rssi) break; } } - - if ( mUTC - mStartTime < 30 ) - return 0xff; - - return medianValue(window); } uint8_t NoiseFloorDetector::medianValue(ChannelReadings &window) @@ -104,13 +100,12 @@ uint8_t NoiseFloorDetector::medianValue(ChannelReadings &window) if ( window.empty() ) return 0xff; - vector sorted; - sorted.reserve(WINDOW_SIZE); + mSorted.clear(); for ( ChannelReadings::iterator i = window.begin(); i != window.end(); ++i ) - sorted.push_back(i->reading); + mSorted.push_back(i->reading); - sort(sorted.begin(), sorted.end()); - return sorted[sorted.size()/2]; + sort(mSorted.begin(), mSorted.end()); + return mSorted[mSorted.size()/2]; } diff --git a/src/NoiseFloorDetector.hpp b/src/NoiseFloorDetector.hpp index 2dd5535..6520772 100644 --- a/src/NoiseFloorDetector.hpp +++ b/src/NoiseFloorDetector.hpp @@ -21,7 +21,7 @@ public: // Called directly by each receiver to report every RSSI reading at every SOTDMA slot, returns latest noise floor or 0xff if not enough data exists - uint8_t report(VHFChannel channel, uint8_t rssi); + void report(VHFChannel channel, uint8_t rssi); void reset(); @@ -40,7 +40,7 @@ private: private: NoiseFloorDetector(); - uint8_t processSample(ChannelReadings &window, uint8_t rssi); + void processSample(ChannelReadings &window, uint8_t rssi); uint8_t medianValue(ChannelReadings &window); void dump(); private: @@ -48,6 +48,8 @@ private: time_t mStartTime; time_t mLastDumpTime; ChannelData mData; + vector mSorted; }; + #endif /* NOISEFLOORDETECTOR_HPP_ */ diff --git a/src/globals.h b/src/globals.h index 235a259..0759eca 100644 --- a/src/globals.h +++ b/src/globals.h @@ -17,8 +17,8 @@ /* - * If this is defined, the device transmits low-power carrier at a nominal frequency of 162.075Mhz, - * two channels above AIS. This is meant to be used for crystal calibration only + * If this is defined, the device transmits low-power carrier on channel 86 (161.925MHz). + * This is meant to be used for crystal calibration only */ //#define CALIBRATION_MODE 1 @@ -36,7 +36,7 @@ #ifdef TX_TEST_MODE #define TX_POWER_LEVEL PWR_P16 #else -#define TX_POWER_LEVEL PWR_M10 +#define TX_POWER_LEVEL PWR_M27 #endif #endif @@ -44,7 +44,7 @@ #define OUTPUT_GPS_NMEA #define ENABLE_PRINTF2 -// Some AIS messages can occupy 5 time slots (5x256 = 1280). We call it quits at 2 slots. +// Some AIS messages can occupy 5 time slots (5x256 = 1280). Nothing we care about exceeds 2 slots. #define MAX_AIS_RX_PACKET_SIZE 512 @@ -54,7 +54,7 @@ // For testing, it's necessary to transmit longer packets for a basic RTL-SDR receiver to not "miss" them. #define MAX_AIS_TX_PACKET_SIZE 1280 #else -// As a class B transponder, we never transmit anything bigger than 256 bits +// As a class B transponder, we never transmit anything bigger than 240 bits. #define MAX_AIS_TX_PACKET_SIZE 300 #endif diff --git a/src/main.cpp b/src/main.cpp index f647de1..27b7c03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,8 +15,9 @@ #include "TXScheduler.hpp" #include "Utils.hpp" #include "system_stm32f30x.h" +#include "core_cm4.h" #include "stm32f30x.h" - +#include #include "DataTerminal.hpp" #include "TXScheduler.hpp" #include "DebugPrinter.hpp" @@ -57,6 +58,13 @@ main(int argc, char* argv[]) // at high speed. printf2_Init(230400); +#ifdef DEBUG + // Disable buffered memory writes to debug imprecise bus faults + SCnSCB->ACTLR |= SCnSCB_ACTLR_DISDEFWBUF_Msk; + trace_printf("ACTLR: %.8x\n", SCnSCB->ACTLR); +#endif + + EEPROM::instance().init(); /* struct StationData __d;