From f9d25888f366a43a75493dbe3131e749f42a3e16 Mon Sep 17 00:00:00 2001 From: Peter Antypas Date: Sun, 27 Dec 2020 08:01:44 -0800 Subject: [PATCH] Minor cleanup --- latest/Firmware/Inc/bsp/bsp.hpp | 2 +- latest/Firmware/Src/NoiseFloorDetector.cpp | 5 +++ latest/Firmware/Src/Receiver.cpp | 37 ++-------------------- 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/latest/Firmware/Inc/bsp/bsp.hpp b/latest/Firmware/Inc/bsp/bsp.hpp index ff3b87c..ba64a47 100644 --- a/latest/Firmware/Inc/bsp/bsp.hpp +++ b/latest/Firmware/Inc/bsp/bsp.hpp @@ -27,7 +27,7 @@ // Either modify this header or define a different symbol in the preprocessor to build for a different board #ifndef BOARD_REV -#define BOARD_REV 100 +#define BOARD_REV 61 #endif /** diff --git a/latest/Firmware/Src/NoiseFloorDetector.cpp b/latest/Firmware/Src/NoiseFloorDetector.cpp index 405ef23..fdca105 100644 --- a/latest/Firmware/Src/NoiseFloorDetector.cpp +++ b/latest/Firmware/Src/NoiseFloorDetector.cpp @@ -22,6 +22,7 @@ #include "EventQueue.hpp" #include "AISChannels.h" #include +#include #define WINDOW_SIZE 10 @@ -46,7 +47,11 @@ NoiseFloorDetector::NoiseFloorDetector() void NoiseFloorDetector::report(char channel, uint8_t rssi) { +#if BOARD_REV == 61 or BOARD_REV == 52 + if ( rssi < 0x12 ) // Not realistic, likely a bug +#else if ( rssi < 0x32 ) // Not realistic, likely a bug +#endif return; if ( channel == 'A' ) diff --git a/latest/Firmware/Src/Receiver.cpp b/latest/Firmware/Src/Receiver.cpp index 4e7ffa1..c2bb296 100644 --- a/latest/Firmware/Src/Receiver.cpp +++ b/latest/Firmware/Src/Receiver.cpp @@ -73,7 +73,6 @@ void Receiver::switchToChannel(VHFChannel channel) mNextChannel = channel; } -// TODO: This is a really, really long operation - over 320us !!! void Receiver::startListening(VHFChannel channel, bool reconfigGPIOs) { if ( reconfigGPIOs ) @@ -94,9 +93,7 @@ void Receiver::startListening(VHFChannel channel, bool reconfigGPIOs) /** * This never takes more than 65us now :D */ - //bsp_signal_high(); - sendCmdNoWait(START_RX, &options, sizeof options);//, NULL, 0); - //bsp_signal_low(); + sendCmdNoWait(START_RX, &options, sizeof options); } void Receiver::resetBitScanner() @@ -111,22 +108,14 @@ void Receiver::resetBitScanner() mRXPacket->reset(); } -/* - * TODO: Under a worst case scenario, this interrupt service method - * can take up to 320us to complete (that's 4 clock bits!!!) - * - * Re-architecting will be necessary to resolve this. - */ void Receiver::onBitClock() { - //bsp_signal_high(); ++mSlotBitNumber; // Don't waste time processing bits when the transceiver is transmitting if ( gRadioState == RADIO_TRANSMITTING ) { - //bsp_signal_low(); return; } @@ -147,29 +136,10 @@ void Receiver::onBitClock() { startReceiving(mChannel, false); } -#if ENABLE_TX - /** - * This trick ensures that we only sample RSSI every N time slots and never in the - * same time slot for both ICs, so we don't conduct long SPI operations on consecutive - * interrupt handlers that might exceed the bit clock period. There is no reason for RSSI - * collection to have a high duty cycle anyway, it just serves to establish the noise floor. - */ -#if FULL_RSSI_SAMPLING else if ( mTimeSlot != 0xffffffff && mSlotBitNumber != 0xffff && mSlotBitNumber == CCA_SLOT_BIT ) { mRXPacket->setRSSI(reportRSSI()); } -#else - else if ( mTimeSlot != 0xffffffff && mSlotBitNumber != 0xffff && - mTimeSlot % 17 == mChipID && - mSlotBitNumber == CCA_SLOT_BIT - 1 ) - { - mRXPacket->setRSSI(reportRSSI()); - } -#endif -#endif - - //bsp_signal_low(); } /** @@ -221,6 +191,7 @@ Receiver::Action Receiver::processNRZIBit(uint8_t bit) * we gain enough confidence that this is not random noise. */ if ( mBitWindow == 0b1010101001111110 || mBitWindow == 0b0101010101111110 ) + //if ( (mBitWindow & 0x0fff) == 0b101001111110 || (mBitWindow &0x0fff) == 0b010101111110 ) { mBitState = BIT_STATE_IN_PACKET; mRXPacket->setChannel(mChannel); @@ -230,7 +201,7 @@ Receiver::Action Receiver::processNRZIBit(uint8_t bit) } case BIT_STATE_IN_PACKET: { - if ( mOneBitCount >= 7 || mRXPacket->size() >= MAX_AIS_RX_PACKET_SIZE ) + if ( mOneBitCount >= 7 || mRXPacket->size() >= MAX_AIS_RX_PACKET_SIZE - 2 ) { // Start over return RESTART_RX; @@ -337,11 +308,9 @@ void Receiver::pushPacket() */ uint8_t Receiver::reportRSSI() { - //bsp_signal_high(); uint8_t rssi = readRSSI(); char channel = AIS_CHANNELS[mChannel].designation; NoiseFloorDetector::instance().report(channel, rssi); - //bsp_signal_low(); return rssi; }