1
0
mirror of https://github.com/peterantypas/maiana.git synced 2025-05-20 01:10:09 -07:00

Fixed mysterious hard fault

This commit is contained in:
Peter Antypas 2016-05-31 17:59:49 -07:00
parent ceaf7de8e5
commit ec3c02f093
4 changed files with 28 additions and 23 deletions

View File

@ -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<uint8_t> 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];
}

View File

@ -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<uint8_t> mSorted;
};
#endif /* NOISEFLOORDETECTOR_HPP_ */

View File

@ -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

View File

@ -15,8 +15,9 @@
#include "TXScheduler.hpp"
#include "Utils.hpp"
#include "system_stm32f30x.h"
#include "core_cm4.h"
#include "stm32f30x.h"
#include <diag/Trace.h>
#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;