From a5c24e54b21d69bd8af8267c2ed4fbfaac1bc04d Mon Sep 17 00:00:00 2001 From: Nunu Date: Mon, 25 Dec 2023 02:52:12 +0100 Subject: [PATCH] Working with next channel logic. --- Makefile | 4 ++++ app/spectrum.c | 46 ++++++++++++++++++++++++++++++++++++++-------- radio.c | 12 ++++++++++-- radio.h | 6 ++++-- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 349f571..4f83e04 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ ENABLE_SCAN_RANGES := 1 ENABLE_SPECTRUM_COPY_VFO := 1 ENABLE_SPECTRUM_SHOW_CHANNEL_NAME := 1 ENABLE_ADJUSTABLE_RX_GAIN_SETTINGS := 1 +ENABLE_SPECTRUM_CHANNEL_SCAN := 1 ############################################################# @@ -376,6 +377,9 @@ endif ifeq ($(ENABLE_ADJUSTABLE_RX_GAIN_SETTINGS),1) CFLAGS += -DENABLE_ADJUSTABLE_RX_GAIN_SETTINGS endif +ifeq ($(ENABLE_SPECTRUM_CHANNEL_SCAN),1) + CFLAGS += -DENABLE_SPECTRUM_CHANNEL_SCAN +endif LDFLAGS = ifeq ($(ENABLE_CLANG),0) diff --git a/app/spectrum.c b/app/spectrum.c index 64605b3..fbdb191 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -34,6 +34,13 @@ struct FrequencyBandInfo { #define F_MAX frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper +#ifdef ENABLE_SPECTRUM_CHANNEL_SCAN + //Idea - make this user adjustable to compensate for different antennas, frontends, conditions + #define UHF_NOISE_FLOOR 40 + // TODO: refactor to find index of first memory channel, someone migght have first 10 memory channels blank + int channelIndex = 0; +#endif + const uint16_t RSSI_MAX_VALUE = 65535; static uint16_t R30, R37, R3D, R43, R47, R48, R7E; @@ -270,7 +277,9 @@ uint16_t GetScanStep() { return scanStepValues[settings.scanStepIndex]; } uint16_t GetStepsCount() { -#ifdef ENABLE_SCAN_RANGES +#ifdef ENABLE_SPECTRUM_CHANNEL_SCAN + return RADIO_MemoryChannelsCount(); +#elif ENABLE_SCAN_RANGES if(gScanRangeStart) { return (gScanRangeStop - gScanRangeStart) / GetScanStep(); } @@ -339,8 +348,8 @@ uint16_t GetRssi() { // testing autodelay based on Glitch value // Read only for valid channels (makes it even faster for ppl with less than 200 channels stored) - if(RADIO_CheckValidChannel(scanInfo.i, false, 0)==false) - return 0; + // if(RADIO_CheckValidChannel(scanInfo.i, false, 0)==false) + // return 0; while ((BK4819_ReadRegister(0x63) & 0b11111111) >= 255) { SYSTICK_DelayUs(100); @@ -350,9 +359,10 @@ uint16_t GetRssi() { // Increase perceived RSSI for UHF bands to imitate radio squelch // in the future this offset could be adjustable by user? // TODO: Move this logic to Measure() function and set rssi = scanInfo.rssi there - if(FREQUENCY_GetBand(fMeasure) > BAND4_174MHz) - rssi+=40; - + #ifdef ENABLE_SPECTRUM_CHANNEL_SCAN + if(FREQUENCY_GetBand(fMeasure) > BAND4_174MHz) + rssi+=UHF_NOISE_FLOOR; + #endif return rssi; } @@ -400,7 +410,7 @@ static void InitScan() { scanInfo.f = GetFStart(); scanInfo.scanStep = GetScanStep(); - scanInfo.measurementsCount = MR_CHANNEL_LAST +1; + scanInfo.measurementsCount = GetStepsCount(); } static void ResetBlacklist() { @@ -1207,7 +1217,27 @@ static void Scan() { static void NextScanStep() { ++peak.t; ++scanInfo.i; - scanInfo.f = gMR_ChannelFrequencyAttributes[scanInfo.i].Frequency; + #ifdef ENABLE_SPECTRUM_CHANNEL_SCAN + int nextChannel; + // nextChannel = RADIO_FindNextChannel(channelIndex, RADIO_CHANNEL_UP, false, Vfo); + // channelIndex = nextChannel; + // scanInfo.f = gMR_ChannelFrequencyAttributes[channelIndex].Frequency; + + + + nextChannel = RADIO_FindNextChannel((scanInfo.i % RADIO_MemoryChannelsCount()) + 1, 1, false, 0); + if (nextChannel == 0xFF) + { // no valid channel found + nextChannel = MR_CHANNEL_FIRST; + } + channelIndex = nextChannel; + scanInfo.f = gMR_ChannelFrequencyAttributes[channelIndex].Frequency; + + // scanInfo.f = gMR_ChannelFrequencyAttributes[scanInfo.i].Frequency; + #elif + scanInfo.f += scanInfo.scanStep; + #endif + } static void UpdateScan() { diff --git a/radio.c b/radio.c index 98520a2..8b32cb8 100644 --- a/radio.c +++ b/radio.c @@ -104,7 +104,7 @@ bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO) uint8_t RADIO_FindNextChannel(uint8_t Channel, int8_t Direction, bool bCheckScanList, uint8_t VFO) { unsigned int i; - + for (i = 0; IS_MR_CHANNEL(i); i++) { if (Channel == 0xFF) @@ -118,7 +118,7 @@ uint8_t RADIO_FindNextChannel(uint8_t Channel, int8_t Direction, bool bCheckScan Channel += Direction; } - + return 0xFF; } @@ -1143,3 +1143,11 @@ void RADIO_SendEndOfTransmission(void) BK4819_ExitDTMF_TX(true); } +#ifdef ENABLE_SPECTRUM_CHANNEL_SCAN + uint8_t RADIO_MemoryChannelsCount(void) + { + uint8_t i=0; + for (i = MR_CHANNEL_FIRST; RADIO_CheckValidChannel(i, false, 0); ++i) {} + return i; + } +#endif \ No newline at end of file diff --git a/radio.h b/radio.h index a4218aa..e5d185b 100644 --- a/radio.h +++ b/radio.h @@ -165,6 +165,8 @@ void RADIO_PrepareTX(void); void RADIO_EnableCxCSS(void); void RADIO_PrepareCssTX(void); void RADIO_SendEndOfTransmission(void); - - +#endif + +#ifdef ENABLE_SPECTRUM_CHANNEL_SCAN + uint8_t RADIO_MemoryChannelsCount(void); #endif