diff --git a/openrtx/include/protocols/M17/M17Demodulator.h b/openrtx/include/protocols/M17/M17Demodulator.h index da1d0991..cb74f6b7 100644 --- a/openrtx/include/protocols/M17/M17Demodulator.h +++ b/openrtx/include/protocols/M17/M17Demodulator.h @@ -109,6 +109,13 @@ public: */ bool isLocked(); + /** + * Invert baseband signal phase before decoding. + * + * @param status: if set to true signal phase is inverted. + */ + void invertPhase(const bool status); + private: /** @@ -150,6 +157,7 @@ private: bool newFrame; ///< A new frame has been fully decoded. int16_t basebandBridge[M17_BRIDGE_SIZE] = { 0 }; ///< Bridge buffer int16_t phase; ///< Phase of the signal w.r.t. sampling + bool invPhase; ///< Invert signal phase /* * State variables diff --git a/openrtx/include/rtx/rtx.h b/openrtx/include/rtx/rtx.h index 80a365c2..6b4e44d7 100644 --- a/openrtx/include/rtx/rtx.h +++ b/openrtx/include/rtx/rtx.h @@ -55,8 +55,9 @@ typedef struct uint8_t rxCan : 4, /**< M17 Channel Access Number for RX squelch */ txCan : 4; /**< M17 Channel Access Number for TX squelch */ - char source_address[10]; /**< M17 call source address */ + char source_address[10]; /**< M17 call source address */ char destination_address[10]; /**< M17 call routing address */ + bool invertRxPhase; /**< M17 RX phase inversion */ } rtxStatus_t; diff --git a/openrtx/src/core/threads.c b/openrtx/src/core/threads.c index 9cc9057d..be1d4b11 100644 --- a/openrtx/src/core/threads.c +++ b/openrtx/src/core/threads.c @@ -103,12 +103,13 @@ void *ui_task(void *arg) rtx_cfg.rxTone = ctcss_tone[state.channel.fm.rxTone]; rtx_cfg.txToneEn = state.channel.fm.txToneEn; rtx_cfg.txTone = ctcss_tone[state.channel.fm.txTone]; - pthread_mutex_unlock(&rtx_mutex); // Copy new M17 source and destination addresses strncpy(rtx_cfg.source_address, state.settings.callsign, 10); strncpy(rtx_cfg.destination_address, state.m17_data.dst_addr, 10); + pthread_mutex_unlock(&rtx_mutex); + rtx_configure(&rtx_cfg); sync_rtx = false; } diff --git a/openrtx/src/protocols/M17/M17Demodulator.cpp b/openrtx/src/protocols/M17/M17Demodulator.cpp index ad35299c..6a6f5301 100644 --- a/openrtx/src/protocols/M17/M17Demodulator.cpp +++ b/openrtx/src/protocols/M17/M17Demodulator.cpp @@ -435,7 +435,8 @@ bool M17Demodulator::update() for(size_t i = 0; i < baseband.len; i++) { float elem = static_cast< float >(baseband.data[i]); - baseband.data[i] = static_cast< int16_t >(M17::rrc_24k(elem)); + if(invPhase) elem = 0.0f - elem; + baseband.data[i] = static_cast< int16_t >(M17::rrc_24k(elem)); } // Process the buffer @@ -574,3 +575,8 @@ bool M17Demodulator::update() return newFrame; } + +void M17Demodulator::invertPhase(const bool status) +{ + invPhase = status; +} diff --git a/openrtx/src/rtx/OpMode_M17.cpp b/openrtx/src/rtx/OpMode_M17.cpp index c43d90bb..da06ce7c 100644 --- a/openrtx/src/rtx/OpMode_M17.cpp +++ b/openrtx/src/rtx/OpMode_M17.cpp @@ -66,6 +66,12 @@ void OpMode_M17::update(rtxStatus_t *const status, const bool newCfg) { (void) newCfg; + // Force inversion of RX phase for MD3x0 VHF radios + #ifdef PLATFORM_MD3x0 + const hwInfo_t* hwinfo = platform_getHwInfo(); + status->invertRxPhase |= hwinfo->vhf_band; + #endif + // Main FSM logic switch(status->opStatus) { @@ -135,6 +141,7 @@ void OpMode_M17::rxState(rtxStatus_t *const status) { decoder.reset(); demodulator.startBasebandSampling(); + demodulator.invertPhase(status->invertRxPhase); audio_enableAmp(); codec_startDecode(SINK_SPK); diff --git a/openrtx/src/rtx/rtx.cpp b/openrtx/src/rtx/rtx.cpp index 7975c977..7d12d7e6 100644 --- a/openrtx/src/rtx/rtx.cpp +++ b/openrtx/src/rtx/rtx.cpp @@ -46,18 +46,19 @@ void rtx_init(pthread_mutex_t *m) /* * Default initialisation for rtx status */ - rtxStatus.opMode = OPMODE_NONE; - rtxStatus.bandwidth = BW_25; - rtxStatus.txDisable = 0; - rtxStatus.opStatus = OFF; - rtxStatus.rxFrequency = 430000000; - rtxStatus.txFrequency = 430000000; - rtxStatus.txPower = 0.0f; - rtxStatus.sqlLevel = 1; - rtxStatus.rxToneEn = 0; - rtxStatus.rxTone = 0; - rtxStatus.txToneEn = 0; - rtxStatus.txTone = 0; + rtxStatus.opMode = OPMODE_NONE; + rtxStatus.bandwidth = BW_25; + rtxStatus.txDisable = 0; + rtxStatus.opStatus = OFF; + rtxStatus.rxFrequency = 430000000; + rtxStatus.txFrequency = 430000000; + rtxStatus.txPower = 0.0f; + rtxStatus.sqlLevel = 1; + rtxStatus.rxToneEn = 0; + rtxStatus.rxTone = 0; + rtxStatus.txToneEn = 0; + rtxStatus.txTone = 0; + rtxStatus.invertRxPhase = false; currMode = &noMode; /*