From f332d48e9b57af017ed0e7ec3c6ab6c5b520a428 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Wed, 28 Sep 2016 00:02:35 +0200 Subject: [PATCH 01/10] LP-345 RFM22: Add frequency band selection. 433, 868 and 915Mhz band --- flight/pios/common/pios_rfm22b.c | 94 +++++++++++-------- flight/pios/inc/pios_rfm22b.h | 2 +- flight/pios/inc/pios_rfm22b_priv.h | 3 + .../discoveryf4bare/firmware/pios_board.c | 2 +- .../boards/oplinkmini/firmware/pios_board.c | 2 +- .../boards/revolution/firmware/pios_board.c | 2 +- .../boards/sparky2/firmware/pios_board.c | 2 +- shared/uavobjectdefinition/oplinksettings.xml | 7 +- 8 files changed, 66 insertions(+), 48 deletions(-) diff --git a/flight/pios/common/pios_rfm22b.c b/flight/pios/common/pios_rfm22b.c index 1bc83015a..4d4a9aa46 100644 --- a/flight/pios/common/pios_rfm22b.c +++ b/flight/pios/common/pios_rfm22b.c @@ -66,54 +66,56 @@ #include /* Local Defines */ -#define STACK_SIZE_BYTES 200 -#define TASK_PRIORITY (tskIDLE_PRIORITY + 4) // flight control relevant device driver (ppm link) -#define ISR_TIMEOUT 1 // ms -#define EVENT_QUEUE_SIZE 5 -#define RFM22B_DEFAULT_RX_DATARATE RFM22_datarate_9600 -#define RFM22B_DEFAULT_TX_POWER RFM22_tx_pwr_txpow_0 -#define RFM22B_NOMINAL_CARRIER_FREQUENCY 430000000 -#define RFM22B_LINK_QUALITY_THRESHOLD 20 -#define RFM22B_DEFAULT_MIN_CHANNEL 0 -#define RFM22B_DEFAULT_MAX_CHANNEL 250 -#define RFM22B_PPM_ONLY_DATARATE RFM22_datarate_9600 +#define STACK_SIZE_BYTES 200 +#define TASK_PRIORITY (tskIDLE_PRIORITY + 4) // flight control relevant device driver (ppm link) +#define ISR_TIMEOUT 1 // ms +#define EVENT_QUEUE_SIZE 5 +#define RFM22B_DEFAULT_RX_DATARATE RFM22_datarate_9600 +#define RFM22B_DEFAULT_TX_POWER RFM22_tx_pwr_txpow_0 +#define RFM22B_NOMINAL_CARRIER_FREQUENCY_433 430000000 +#define RFM22B_NOMINAL_CARRIER_FREQUENCY_868 860000000 +#define RFM22B_NOMINAL_CARRIER_FREQUENCY_915 900000000 +#define RFM22B_LINK_QUALITY_THRESHOLD 20 +#define RFM22B_DEFAULT_MIN_CHANNEL 0 +#define RFM22B_DEFAULT_MAX_CHANNEL 250 +#define RFM22B_PPM_ONLY_DATARATE RFM22_datarate_9600 // PPM encoding limits -#define RFM22B_PPM_MIN 1 -#define RFM22B_PPM_MAX 511 -#define RFM22B_PPM_INVALID 0 -#define RFM22B_PPM_SCALE 2 -#define RFM22B_PPM_MIN_US 990 -#define RFM22B_PPM_MAX_US (RFM22B_PPM_MIN_US + (RFM22B_PPM_MAX - RFM22B_PPM_MIN) * RFM22B_PPM_SCALE) +#define RFM22B_PPM_MIN 1 +#define RFM22B_PPM_MAX 511 +#define RFM22B_PPM_INVALID 0 +#define RFM22B_PPM_SCALE 2 +#define RFM22B_PPM_MIN_US 990 +#define RFM22B_PPM_MAX_US (RFM22B_PPM_MIN_US + (RFM22B_PPM_MAX - RFM22B_PPM_MIN) * RFM22B_PPM_SCALE) // The maximum amount of time without activity before initiating a reset. -#define PIOS_RFM22B_SUPERVISOR_TIMEOUT 150 // ms +#define PIOS_RFM22B_SUPERVISOR_TIMEOUT 150 // ms // this is too adjust the RF module so that it is on frequency -#define OSC_LOAD_CAP 0x7F // cap = 12.5pf .. default +#define OSC_LOAD_CAP 0x7F // cap = 12.5pf .. default -#define TX_PREAMBLE_NIBBLES 12 // 7 to 511 (number of nibbles) -#define RX_PREAMBLE_NIBBLES 6 // 5 to 31 (number of nibbles) -#define SYNC_BYTES 4 -#define HEADER_BYTES 4 -#define LENGTH_BYTES 1 +#define TX_PREAMBLE_NIBBLES 12 // 7 to 511 (number of nibbles) +#define RX_PREAMBLE_NIBBLES 6 // 5 to 31 (number of nibbles) +#define SYNC_BYTES 4 +#define HEADER_BYTES 4 +#define LENGTH_BYTES 1 // the size of the rf modules internal FIFO buffers -#define FIFO_SIZE 64 +#define FIFO_SIZE 64 -#define TX_FIFO_HI_WATERMARK 62 // 0-63 -#define TX_FIFO_LO_WATERMARK 32 // 0-63 +#define TX_FIFO_HI_WATERMARK 62 // 0-63 +#define TX_FIFO_LO_WATERMARK 32 // 0-63 -#define RX_FIFO_HI_WATERMARK 32 // 0-63 +#define RX_FIFO_HI_WATERMARK 32 // 0-63 // preamble byte (preceeds SYNC_BYTE's) -#define PREAMBLE_BYTE 0x55 +#define PREAMBLE_BYTE 0x55 // RF sync bytes (32-bit in all) -#define SYNC_BYTE_1 0x2D -#define SYNC_BYTE_2 0xD4 -#define SYNC_BYTE_3 0x4B -#define SYNC_BYTE_4 0x59 +#define SYNC_BYTE_1 0x2D +#define SYNC_BYTE_2 0xD4 +#define SYNC_BYTE_3 0x4B +#define SYNC_BYTE_4 0x59 #ifndef RX_LED_ON #define RX_LED_ON @@ -187,7 +189,7 @@ static enum pios_radio_event rfm22_timeout(struct pios_rfm22b_dev *rfm22b_dev); static enum pios_radio_event rfm22_error(struct pios_rfm22b_dev *rfm22b_dev); static enum pios_radio_event rfm22_fatal_error(struct pios_rfm22b_dev *rfm22b_dev); static void rfm22b_add_rx_status(struct pios_rfm22b_dev *rfm22b_dev, enum pios_rfm22b_rx_packet_status status); -static void rfm22_setNominalCarrierFrequency(struct pios_rfm22b_dev *rfm22b_dev, uint8_t init_chan); +static void rfm22_setNominalCarrierFrequency(struct pios_rfm22b_dev *rfm22b_dev, uint8_t init_chan, uint32_t frequency_hz); static bool rfm22_setFreqHopChannel(struct pios_rfm22b_dev *rfm22b_dev, uint8_t channel); static void rfm22_generateDeviceID(struct pios_rfm22b_dev *rfm22b_dev); static void rfm22_updatePairStatus(struct pios_rfm22b_dev *radio_dev); @@ -391,7 +393,7 @@ static struct pios_rfm22b_dev *g_rfm22b_dev = NULL; * @param[in] slave_num The SPI bus slave number. * @param[in] cfg The device configuration. */ -int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, uint32_t spi_id, uint32_t slave_num, const struct pios_rfm22b_cfg *cfg) +int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, uint32_t spi_id, uint32_t slave_num, const struct pios_rfm22b_cfg *cfg, OPLinkSettingsRFBandOptions band) { PIOS_DEBUG_Assert(rfm22b_id); PIOS_DEBUG_Assert(cfg); @@ -436,6 +438,20 @@ int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, uint32_t spi_id, uint32_t slave_nu rfm22b_dev->stats.rx_seq = 0; rfm22b_dev->stats.tx_failure = 0; + // Set the frequency band + switch (band) { + case OPLINKSETTINGS_RFBAND_915MHZ: + rfm22b_dev->base_freq = RFM22B_NOMINAL_CARRIER_FREQUENCY_915; + break; + case OPLINKSETTINGS_RFBAND_868MHZ: + rfm22b_dev->base_freq = RFM22B_NOMINAL_CARRIER_FREQUENCY_868; + break; + case OPLINKSETTINGS_RFBAND_433MHZ: + default: + rfm22b_dev->base_freq = RFM22B_NOMINAL_CARRIER_FREQUENCY_433; + break; + } + // Initialize the channels. PIOS_RFM22B_SetChannelConfig(*rfm22b_id, RFM22B_DEFAULT_RX_DATARATE, RFM22B_DEFAULT_MIN_CHANNEL, RFM22B_DEFAULT_MAX_CHANNEL, false, true, false); @@ -1566,7 +1582,7 @@ static enum pios_radio_event rfm22_init(struct pios_rfm22b_dev *rfm22b_dev) vTaskDelay(1 + (1 / (portTICK_RATE_MS + 1))); // Initialize the frequency and datarate to te default. - rfm22_setNominalCarrierFrequency(rfm22b_dev, 0); + rfm22_setNominalCarrierFrequency(rfm22b_dev, 0, rfm22b_dev->base_freq); pios_rfm22_setDatarate(rfm22b_dev); return RADIO_EVENT_INITIALIZED; @@ -1656,10 +1672,8 @@ static void pios_rfm22_setDatarate(struct pios_rfm22b_dev *rfm22b_dev) * @param[in] rfm33b_dev The device structure pointer. * @param[in] init_chan The initial channel to tune to. */ -static void rfm22_setNominalCarrierFrequency(struct pios_rfm22b_dev *rfm22b_dev, uint8_t init_chan) +static void rfm22_setNominalCarrierFrequency(struct pios_rfm22b_dev *rfm22b_dev, uint8_t init_chan, uint32_t frequency_hz) { - // Set the frequency channels to start at 430MHz - uint32_t frequency_hz = RFM22B_NOMINAL_CARRIER_FREQUENCY; // The step size is 10MHz / 250 = 40khz, and the step size is specified in 10khz increments. uint8_t freq_hop_step_size = 4; @@ -1682,7 +1696,7 @@ static void rfm22_setNominalCarrierFrequency(struct pios_rfm22b_dev *rfm22b_dev, // Claim the SPI bus. rfm22_claimBus(rfm22b_dev); - // Setthe frequency hopping step size. + // Set the frequency hopping step size. rfm22_write(rfm22b_dev, RFM22_frequency_hopping_step_size, freq_hop_step_size); // frequency hopping channel (0-255) diff --git a/flight/pios/inc/pios_rfm22b.h b/flight/pios/inc/pios_rfm22b.h index 16dd460b2..6158771ad 100644 --- a/flight/pios/inc/pios_rfm22b.h +++ b/flight/pios/inc/pios_rfm22b.h @@ -101,7 +101,7 @@ struct rfm22b_stats { }; /* Public Functions */ -extern int32_t PIOS_RFM22B_Init(uint32_t *rfb22b_id, uint32_t spi_id, uint32_t slave_num, const struct pios_rfm22b_cfg *cfg); +extern int32_t PIOS_RFM22B_Init(uint32_t *rfb22b_id, uint32_t spi_id, uint32_t slave_num, const struct pios_rfm22b_cfg *cfg, OPLinkSettingsRFBandOptions band); extern void PIOS_RFM22B_Reinit(uint32_t rfb22b_id); extern void PIOS_RFM22B_SetTxPower(uint32_t rfm22b_id, enum rfm22b_tx_power tx_pwr); extern void PIOS_RFM22B_SetChannelConfig(uint32_t rfm22b_id, enum rfm22b_datarate datarate, uint8_t min_chan, uint8_t max_chan, bool coordinator, bool ppm_mode, bool ppm_only); diff --git a/flight/pios/inc/pios_rfm22b_priv.h b/flight/pios/inc/pios_rfm22b_priv.h index 953c90fc0..5a66bd180 100644 --- a/flight/pios/inc/pios_rfm22b_priv.h +++ b/flight/pios/inc/pios_rfm22b_priv.h @@ -283,6 +283,9 @@ struct pios_rfm22b_dev { // Are we sending / receiving only PPM data? bool ppm_only_mode; + // The base freq in Hertz + uint32_t base_freq; + // The channel list uint8_t channels[RFM22B_NUM_CHANNELS]; // The number of frequency hopping channels. diff --git a/flight/targets/boards/discoveryf4bare/firmware/pios_board.c b/flight/targets/boards/discoveryf4bare/firmware/pios_board.c index a58fd1d31..77c0f357e 100644 --- a/flight/targets/boards/discoveryf4bare/firmware/pios_board.c +++ b/flight/targets/boards/discoveryf4bare/firmware/pios_board.c @@ -784,7 +784,7 @@ void PIOS_Board_Init(void) if (oplinkSettings.MaxRFPower != OPLINKSETTINGS_MAXRFPOWER_0) { /* Configure the RFM22B device. */ const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev); - if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg)) { + if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) { PIOS_Assert(0); } diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board.c b/flight/targets/boards/oplinkmini/firmware/pios_board.c index a6f7574ca..c96321da1 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board.c @@ -413,7 +413,7 @@ void PIOS_Board_Init(void) // Configure the RFM22B device const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev); - if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg)) { + if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) { PIOS_Assert(0); } diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index 7f7ddee07..5bb74f47f 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -912,7 +912,7 @@ void PIOS_Board_Init(void) } else { /* Configure the RFM22B device. */ const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev); - if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg)) { + if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) { PIOS_Assert(0); } diff --git a/flight/targets/boards/sparky2/firmware/pios_board.c b/flight/targets/boards/sparky2/firmware/pios_board.c index e8a82a2f4..444653c3b 100644 --- a/flight/targets/boards/sparky2/firmware/pios_board.c +++ b/flight/targets/boards/sparky2/firmware/pios_board.c @@ -852,7 +852,7 @@ void PIOS_Board_Init(void) } else { /* Configure the RFM22B device. */ const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev); - if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg)) { + if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) { PIOS_Assert(0); } diff --git a/shared/uavobjectdefinition/oplinksettings.xml b/shared/uavobjectdefinition/oplinksettings.xml index dbf450360..0fe17836f 100644 --- a/shared/uavobjectdefinition/oplinksettings.xml +++ b/shared/uavobjectdefinition/oplinksettings.xml @@ -9,6 +9,7 @@ + @@ -16,19 +17,19 @@ - + - + - + From ab8e0400f069c821485bae69ce3659d50ce5478d Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Wed, 28 Sep 2016 00:05:03 +0200 Subject: [PATCH 02/10] LP-345 OPLink: Update GUI with RF Band dropdown --- .../src/plugins/config/configoplinkwidget.cpp | 34 +- .../src/plugins/config/configoplinkwidget.h | 6 + ground/gcs/src/plugins/config/oplink.ui | 795 +++++++++--------- 3 files changed, 452 insertions(+), 383 deletions(-) diff --git a/ground/gcs/src/plugins/config/configoplinkwidget.cpp b/ground/gcs/src/plugins/config/configoplinkwidget.cpp index 611cb7a17..64b39d016 100644 --- a/ground/gcs/src/plugins/config/configoplinkwidget.cpp +++ b/ground/gcs/src/plugins/config/configoplinkwidget.cpp @@ -41,7 +41,6 @@ // Channel range and Frequency display static const int MAX_CHANNEL_NUM = 250; static const int MIN_CHANNEL_RANGE = 10; -static const float FIRST_FREQUENCY = 430.000; static const float FREQUENCY_STEP = 0.040; ConfigOPLinkWidget::ConfigOPLinkWidget(QWidget *parent) : ConfigTaskWidget(parent, false), statusUpdated(false) @@ -76,6 +75,7 @@ ConfigOPLinkWidget::ConfigOPLinkWidget(QWidget *parent) : ConfigTaskWidget(paren addWidgetBinding("OPLinkSettings", "LinkType", m_oplink->LinkType); addWidgetBinding("OPLinkSettings", "CoordID", m_oplink->CoordID); addWidgetBinding("OPLinkSettings", "CustomDeviceID", m_oplink->CustomDeviceID); + addWidgetBinding("OPLinkSettings", "RFBand", m_oplink->RFBand); addWidgetBinding("OPLinkSettings", "MinChannel", m_oplink->MinimumChannel); addWidgetBinding("OPLinkSettings", "MaxChannel", m_oplink->MaximumChannel); addWidgetBinding("OPLinkSettings", "MaxRFPower", m_oplink->MaxRFTxPower); @@ -111,6 +111,7 @@ ConfigOPLinkWidget::ConfigOPLinkWidget(QWidget *parent) : ConfigTaskWidget(paren // Connect the selection changed signals. connect(m_oplink->Protocol, SIGNAL(currentIndexChanged(int)), this, SLOT(protocolChanged())); connect(m_oplink->LinkType, SIGNAL(currentIndexChanged(int)), this, SLOT(linkTypeChanged())); + connect(m_oplink->RFBand, SIGNAL(currentIndexChanged(int)), this, SLOT(rfBandChanged())); connect(m_oplink->MinimumChannel, SIGNAL(valueChanged(int)), this, SLOT(minChannelChanged())); connect(m_oplink->MaximumChannel, SIGNAL(valueChanged(int)), this, SLOT(maxChannelChanged())); connect(m_oplink->MainPort, SIGNAL(currentIndexChanged(int)), this, SLOT(mainPortChanged())); @@ -256,6 +257,7 @@ void ConfigOPLinkWidget::updateSettings() m_oplink->UnbindButton->setEnabled(is_enabled && is_bound && !is_coordinator); m_oplink->CustomDeviceID->setEnabled(is_coordinator); + m_oplink->RFBand->setEnabled(is_receiver || is_coordinator); m_oplink->MinimumChannel->setEnabled(is_receiver || is_coordinator); m_oplink->MaximumChannel->setEnabled(is_receiver || is_coordinator); @@ -289,6 +291,27 @@ void ConfigOPLinkWidget::maxChannelChanged() channelChanged(true); } +void ConfigOPLinkWidget::rfBandChanged() +{ + switch (getComboboxSelectedOption(m_oplink->RFBand)) { + case OPLinkSettings::RFBAND_915MHZ: + frequency_base = 900.0f; + frequency_step = FREQUENCY_STEP * 2.0f; + break; + case OPLinkSettings::RFBAND_868MHZ: + frequency_base = 860.0f; + frequency_step = FREQUENCY_STEP * 2.0f; + break; + case OPLinkSettings::RFBAND_433MHZ: + frequency_base = 430.0f; + frequency_step = FREQUENCY_STEP; + break; + } + + // Update frequency display according to the RF band change + updateFrequencyDisplay(); +} + void ConfigOPLinkWidget::channelChanged(bool isMax) { int minChannel = m_oplink->MinimumChannel->value(); @@ -315,9 +338,14 @@ void ConfigOPLinkWidget::channelChanged(bool isMax) m_oplink->MaximumChannel->setValue(maxChannel); m_oplink->MinimumChannel->setValue(minChannel); + updateFrequencyDisplay(); +} + +void ConfigOPLinkWidget::updateFrequencyDisplay() +{ // Calculate and Display frequency in MHz - float minFrequency = FIRST_FREQUENCY + (minChannel * FREQUENCY_STEP); - float maxFrequency = FIRST_FREQUENCY + (maxChannel * FREQUENCY_STEP); + float minFrequency = frequency_base + (m_oplink->MinimumChannel->value() * frequency_step); + float maxFrequency = frequency_base + (m_oplink->MaximumChannel->value() * frequency_step); m_oplink->MinFreq->setText("(" + QString::number(minFrequency, 'f', 3) + " MHz)"); m_oplink->MaxFreq->setText("(" + QString::number(maxFrequency, 'f', 3) + " MHz)"); diff --git a/ground/gcs/src/plugins/config/configoplinkwidget.h b/ground/gcs/src/plugins/config/configoplinkwidget.h index 70043e257..9cdb37ee9 100644 --- a/ground/gcs/src/plugins/config/configoplinkwidget.h +++ b/ground/gcs/src/plugins/config/configoplinkwidget.h @@ -46,6 +46,10 @@ protected: virtual void refreshWidgetsValuesImpl(UAVObject *obj); private: + // Frequency display settings + float frequency_base; + float frequency_step; + Ui_OPLinkWidget *m_oplink; OPLinkStatus *oplinkStatusObj; @@ -68,7 +72,9 @@ private slots: void minChannelChanged(); void maxChannelChanged(); + void rfBandChanged(); void channelChanged(bool isMax); + void updateFrequencyDisplay(); void mainPortChanged(); void flexiPortChanged(); diff --git a/ground/gcs/src/plugins/config/oplink.ui b/ground/gcs/src/plugins/config/oplink.ui index 546fd0a37..7c074263a 100644 --- a/ground/gcs/src/plugins/config/oplink.ui +++ b/ground/gcs/src/plugins/config/oplink.ui @@ -95,22 +95,6 @@ Configuration - - - - - 50 - false - - - - Flexi Port - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - @@ -148,345 +132,6 @@ The device must be rebooted for the binding to take place. - - - - Clear the binding/coordinator ID - - - Unbind - - - - - - - - - - 0 - 0 - - - - - 60 - 16777215 - - - - - 50 - false - - - - Channel 0 is 430 MHz, channel 250 is 440 MHz, and the channel spacing is 40 KHz. - - - 250 - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - 440.000 (MHz) - - - - - - - - - - 50 - false - - - - VCP Port - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 80 - 0 - - - - - 50 - false - - - - Max Chan - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 80 - 0 - - - - - 50 - false - - - - Min Chan - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 16777215 - 16777215 - - - - Choose the function for the flexi port. - - - - - - - - 16777215 - 16777215 - - - - Set the modem protocol - - - Qt::LeftToRight - - - 0 - - - - - - - - 16777215 - 16777215 - - - - Choose the function for the USB virtual com port. - - - - - - - Com speed in bps. - - - - - - - - - - 0 - 0 - - - - - 60 - 16777215 - - - - - 50 - false - - - - Channel 0 is 430 MHz, channel 250 is 440 MHz, and the channel spacing is 40 KHz. - - - 250 - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - 430.000 (MHz) - - - - - - - - - - 50 - false - - - - Protocol - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 50 - false - - - - Com Speed - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 16777215 - 16777215 - - - - Set the maximum TX output power the modem will use (mW) -0 to disable the modem. - - - Qt::LeftToRight - - - 0 - - - - - - - - 50 - false - - - - Link Type - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 50 - false - - - - Device ID - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 16777215 - 16777215 - - - - Configure what type of packets will be sent over the link - - - Qt::LeftToRight - - - 0 - - - @@ -545,6 +190,82 @@ Leave blank to use autogenerated Device ID. + + + + + 50 + false + + + + Main Port + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 80 + 0 + + + + + 50 + false + + + + Max Chan + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 16777215 + 16777215 + + + + Set the modem protocol + + + Qt::LeftToRight + + + 0 + + + + + + + + 16777215 + 16777215 + + + + Choose the function for the main port. + + + @@ -567,24 +288,72 @@ Leave blank to use autogenerated Device ID. - - - - - 50 - false - + + + + Qt::Horizontal - - Main Port + + + 40 + 20 + - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + - - + + + + + + + 0 + 0 + + + + + 60 + 16777215 + + + + + 50 + false + + + + Channel 0 is 430 MHz, channel 250 is 440 MHz, and the channel spacing is 40 KHz. + + + 250 + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + 440.000 (MHz) + + + + + + + 16777215 @@ -592,7 +361,183 @@ Leave blank to use autogenerated Device ID. - Choose the function for the main port. + Choose the function for the flexi port. + + + + + + + Clear the binding/coordinator ID + + + Unbind + + + + + + + + 0 + 0 + + + + + 80 + 0 + + + + + 50 + false + + + + Min Chan + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 50 + false + + + + Protocol + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 50 + false + + + + Com Speed + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Com speed in bps. + + + + + + + + 50 + false + + + + Link Type + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 0 + 0 + + + + + 60 + 16777215 + + + + + 50 + false + + + + Channel 0 is 430 MHz, channel 250 is 440 MHz, and the channel spacing is 40 KHz. + + + 250 + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + 430.000 (MHz) + + + + + + + + + + 50 + false + + + + Device ID + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 50 + false + + + + Flexi Port + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -615,18 +560,108 @@ Leave blank to use autogenerated Device ID. - - - - Qt::Horizontal - - + + + - 40 - 20 + 16777215 + 16777215 - + + Configure what type of packets will be sent over the link + + + Qt::LeftToRight + + + 0 + + + + + + + + 16777215 + 16777215 + + + + Set the maximum TX output power the modem will use (mW) +0 to disable the modem. + + + Qt::LeftToRight + + + 0 + + + + + + + + 50 + false + + + + RF Band + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 90 + 16777215 + + + + Set the RF Band used. + + + Qt::LeftToRight + + + 0 + + + + + + + + 50 + false + + + + VCP Port + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 16777215 + 16777215 + + + + Choose the function for the USB virtual com port. + + From 7800f49705940bbe3cd6eb1adbf9246a9e3559e5 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Mon, 3 Oct 2016 14:56:40 +0200 Subject: [PATCH 03/10] LP-346 RFM22 tuning: Add AFC value to OplinkStatus --- flight/modules/System/systemmod.c | 23 +++++++------- flight/pios/common/pios_rfm22b.c | 34 +++++++++++---------- flight/pios/inc/pios_rfm22b.h | 2 +- flight/pios/inc/pios_rfm22b_priv.h | 2 +- shared/uavobjectdefinition/oplinkstatus.xml | 1 + 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/flight/modules/System/systemmod.c b/flight/modules/System/systemmod.c index 2cf86e751..d1ff52fd3 100644 --- a/flight/modules/System/systemmod.c +++ b/flight/modules/System/systemmod.c @@ -292,18 +292,19 @@ static void systemTask(__attribute__((unused)) void *parameters) static uint16_t prev_tx_seq = 0; static uint16_t prev_rx_seq = 0; - oplinkStatus.DeviceID = PIOS_RFM22B_DeviceID(pios_rfm22b_id); - oplinkStatus.RxGood = radio_stats.rx_good; - oplinkStatus.RxCorrected = radio_stats.rx_corrected; - oplinkStatus.RxErrors = radio_stats.rx_error; - oplinkStatus.RxMissed = radio_stats.rx_missed; - oplinkStatus.RxFailure = radio_stats.rx_failure; - oplinkStatus.TxDropped = radio_stats.tx_dropped; - oplinkStatus.TxFailure = radio_stats.tx_failure; - oplinkStatus.Resets = radio_stats.resets; - oplinkStatus.Timeouts = radio_stats.timeouts; + oplinkStatus.DeviceID = PIOS_RFM22B_DeviceID(pios_rfm22b_id); + oplinkStatus.RxGood = radio_stats.rx_good; + oplinkStatus.RxCorrected = radio_stats.rx_corrected; + oplinkStatus.RxErrors = radio_stats.rx_error; + oplinkStatus.RxMissed = radio_stats.rx_missed; + oplinkStatus.RxFailure = radio_stats.rx_failure; + oplinkStatus.TxDropped = radio_stats.tx_dropped; + oplinkStatus.TxFailure = radio_stats.tx_failure; + oplinkStatus.Resets = radio_stats.resets; + oplinkStatus.Timeouts = radio_stats.timeouts; oplinkStatus.RSSI = radio_stats.rssi; - oplinkStatus.LinkQuality = radio_stats.link_quality; + oplinkStatus.LinkQuality = radio_stats.link_quality; + oplinkStatus.AFCCorrection = radio_stats.afc_correction; if (first_time) { first_time = false; } else { diff --git a/flight/pios/common/pios_rfm22b.c b/flight/pios/common/pios_rfm22b.c index 4d4a9aa46..07254fd29 100644 --- a/flight/pios/common/pios_rfm22b.c +++ b/flight/pios/common/pios_rfm22b.c @@ -427,16 +427,17 @@ int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, uint32_t spi_id, uint32_t slave_nu rfm22b_dev->stats.packets_per_sec = 0; rfm22b_dev->stats.rx_good = 0; rfm22b_dev->stats.rx_corrected = 0; - rfm22b_dev->stats.rx_error = 0; - rfm22b_dev->stats.rx_missed = 0; - rfm22b_dev->stats.tx_dropped = 0; - rfm22b_dev->stats.resets = 0; - rfm22b_dev->stats.timeouts = 0; - rfm22b_dev->stats.link_quality = 0; + rfm22b_dev->stats.rx_error = 0; + rfm22b_dev->stats.rx_missed = 0; + rfm22b_dev->stats.tx_dropped = 0; + rfm22b_dev->stats.resets = 0; + rfm22b_dev->stats.timeouts = 0; + rfm22b_dev->stats.link_quality = 0; rfm22b_dev->stats.rssi = 0; - rfm22b_dev->stats.tx_seq = 0; - rfm22b_dev->stats.rx_seq = 0; - rfm22b_dev->stats.tx_failure = 0; + rfm22b_dev->stats.afc_correction = 0; + rfm22b_dev->stats.tx_seq = 0; + rfm22b_dev->stats.rx_seq = 0; + rfm22b_dev->stats.tx_failure = 0; // Set the frequency band switch (band) { @@ -1072,13 +1073,13 @@ pios_rfm22b_int_result PIOS_RFM22B_ProcessRx(uint32_t rfm22b_id) // read the 10-bit signed afc correction value // bits 9 to 2 - uint16_t afc_correction = (uint16_t)rfm22_read(rfm22b_dev, RFM22_afc_correction_read) << 8; + int16_t afc_correction = (uint16_t)rfm22_read(rfm22b_dev, RFM22_afc_correction_read) << 8; // bits 1 & 0 - afc_correction |= (uint16_t)rfm22_read(rfm22b_dev, RFM22_ook_counter_value1) & 0x00c0; + afc_correction |= (int16_t)rfm22_read(rfm22b_dev, RFM22_ook_counter_value1) & 0x00c0; afc_correction >>= 6; // convert the afc value to Hz int32_t afc_corr = (int32_t)(rfm22b_dev->frequency_step_size * afc_correction + 0.5f); - rfm22b_dev->afc_correction_Hz = (afc_corr < -127) ? -127 : ((afc_corr > 127) ? 127 : afc_corr); + rfm22b_dev->afc_correction_Hz = afc_corr; // read rx signal strength .. 45 = -100dBm, 205 = -20dBm uint8_t rssi = rfm22_read(rfm22b_dev, RFM22_rssi); @@ -1699,8 +1700,8 @@ static void rfm22_setNominalCarrierFrequency(struct pios_rfm22b_dev *rfm22b_dev, // Set the frequency hopping step size. rfm22_write(rfm22b_dev, RFM22_frequency_hopping_step_size, freq_hop_step_size); - // frequency hopping channel (0-255) - rfm22b_dev->frequency_step_size = 156.25f * hbsel; + // frequency step + rfm22b_dev->frequency_step_size = 156.25f * (hbsel + 1); // frequency hopping channel (0-255) rfm22b_dev->channel = init_chan; @@ -2063,9 +2064,10 @@ static enum pios_radio_event radio_receivePacket(struct pios_rfm22b_dev *radio_d radio_dev->rx_destination_id == rfm22_destinationID(radio_dev)) { rfm22_synchronizeClock(radio_dev); } - radio_dev->stats.link_state = OPLINKSTATUS_LINKSTATE_CONNECTED; - radio_dev->last_contact = xTaskGetTickCount(); + radio_dev->stats.link_state = OPLINKSTATUS_LINKSTATE_CONNECTED; + radio_dev->last_contact = xTaskGetTickCount(); radio_dev->stats.rssi = radio_dev->rssi_dBm; + radio_dev->stats.afc_correction = radio_dev->afc_correction_Hz; } else { ret_event = RADIO_EVENT_RX_COMPLETE; } diff --git a/flight/pios/inc/pios_rfm22b.h b/flight/pios/inc/pios_rfm22b.h index 6158771ad..14b6fbaa4 100644 --- a/flight/pios/inc/pios_rfm22b.h +++ b/flight/pios/inc/pios_rfm22b.h @@ -96,7 +96,7 @@ struct rfm22b_stats { uint8_t timeouts; uint8_t link_quality; int8_t rssi; - int8_t afc_correction; + int32_t afc_correction; uint8_t link_state; }; diff --git a/flight/pios/inc/pios_rfm22b_priv.h b/flight/pios/inc/pios_rfm22b_priv.h index 5a66bd180..9d267d7d6 100644 --- a/flight/pios/inc/pios_rfm22b_priv.h +++ b/flight/pios/inc/pios_rfm22b_priv.h @@ -297,7 +297,7 @@ struct pios_rfm22b_dev { // current frequency hop channel index uint8_t channel_index; // afc correction reading (in Hz) - int8_t afc_correction_Hz; + int32_t afc_correction_Hz; // The packet timers. portTickType packet_start_ticks; diff --git a/shared/uavobjectdefinition/oplinkstatus.xml b/shared/uavobjectdefinition/oplinkstatus.xml index fdb3d5053..7d9605c61 100644 --- a/shared/uavobjectdefinition/oplinkstatus.xml +++ b/shared/uavobjectdefinition/oplinkstatus.xml @@ -19,6 +19,7 @@ + From ea377973fc63f6b74c73dc226d1ce15cd78a536d Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Mon, 3 Oct 2016 18:35:51 +0200 Subject: [PATCH 04/10] LP-346 RFM22 tuning: Add XtalCap value for fine tuning --- flight/pios/common/pios_rfm22b.c | 9 +++++++-- flight/targets/boards/oplinkmini/firmware/pios_board.c | 4 ++++ flight/targets/boards/revolution/board_hw_defs.c | 4 ++-- flight/targets/boards/revolution/firmware/pios_board.c | 5 +++++ flight/targets/boards/sparky2/board_hw_defs.c | 2 +- flight/targets/boards/sparky2/firmware/pios_board.c | 4 ++++ shared/uavobjectdefinition/oplinksettings.xml | 1 + 7 files changed, 24 insertions(+), 5 deletions(-) diff --git a/flight/pios/common/pios_rfm22b.c b/flight/pios/common/pios_rfm22b.c index 07254fd29..1cb46f45f 100644 --- a/flight/pios/common/pios_rfm22b.c +++ b/flight/pios/common/pios_rfm22b.c @@ -1573,8 +1573,13 @@ static enum pios_radio_event rfm22_init(struct pios_rfm22b_dev *rfm22b_dev) // RX FIFO Almost Full Threshold (0 - 63) rfm22_write(rfm22b_dev, RFM22_rx_fifo_control, RX_FIFO_HI_WATERMARK); - // Set the frequency calibration - rfm22_write(rfm22b_dev, RFM22_xtal_osc_load_cap, rfm22b_dev->cfg.RFXtalCap); + // Set the xtal capacitor for frequency calibration + // Cint = 1.8 pF + 0.085 pF x xlc[6:0] + 3.7 pF x xlc[7] (xtalshift) + // cfg.RFXtalCap 0 to 171 range give Cint = 1.8pF to 16.295pF range + // Default is 127, equal to 12.595pF + rfm22_write(rfm22b_dev, + RFM22_xtal_osc_load_cap, + (rfm22b_dev->cfg.RFXtalCap < 128) ? rfm22b_dev->cfg.RFXtalCap : (rfm22b_dev->cfg.RFXtalCap + 84)); // Release the bus rfm22_releaseBus(rfm22b_dev); diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board.c b/flight/targets/boards/oplinkmini/firmware/pios_board.c index c96321da1..14a109b50 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board.c @@ -413,6 +413,10 @@ void PIOS_Board_Init(void) // Configure the RFM22B device const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev); + + // Set the Xtal capacitor value + pios_rfm22b_cfg.RFXtalCap = oplinkSettings.RFXtalCap; + if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) { PIOS_Assert(0); } diff --git a/flight/targets/boards/revolution/board_hw_defs.c b/flight/targets/boards/revolution/board_hw_defs.c index 74770d980..251e6a5f5 100644 --- a/flight/targets/boards/revolution/board_hw_defs.c +++ b/flight/targets/boards/revolution/board_hw_defs.c @@ -640,7 +640,7 @@ static const struct pios_exti_cfg pios_exti_rfm22b_cfg __exti_config = { }, }; -const struct pios_rfm22b_cfg pios_rfm22b_rm1_cfg = { +struct pios_rfm22b_cfg pios_rfm22b_rm1_cfg = { .spi_cfg = &pios_spi_telem_flash_cfg, .exti_cfg = &pios_exti_rfm22b_cfg, .RFXtalCap = 0x7f, @@ -648,7 +648,7 @@ const struct pios_rfm22b_cfg pios_rfm22b_rm1_cfg = { .gpio_direction = GPIO0_RX_GPIO1_TX, }; -const struct pios_rfm22b_cfg pios_rfm22b_rm2_cfg = { +struct pios_rfm22b_cfg pios_rfm22b_rm2_cfg = { .spi_cfg = &pios_spi_telem_flash_cfg, .exti_cfg = &pios_exti_rfm22b_cfg, .RFXtalCap = 0x7f, diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index 5bb74f47f..7ac888523 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -912,6 +912,11 @@ void PIOS_Board_Init(void) } else { /* Configure the RFM22B device. */ const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev); + + // Set the Xtal capacitor value + pios_rfm22b_rm1_cfg.RFXtalCap = oplinkSettings.RFXtalCap; + pios_rfm22b_rm2_cfg.RFXtalCap = oplinkSettings.RFXtalCap; + if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) { PIOS_Assert(0); } diff --git a/flight/targets/boards/sparky2/board_hw_defs.c b/flight/targets/boards/sparky2/board_hw_defs.c index 25afb14e2..2c63d0fcf 100644 --- a/flight/targets/boards/sparky2/board_hw_defs.c +++ b/flight/targets/boards/sparky2/board_hw_defs.c @@ -431,7 +431,7 @@ static const struct pios_exti_cfg pios_exti_rfm22b_cfg __exti_config = { }, }; -const struct pios_rfm22b_cfg pios_rfm22b_cfg = { +struct pios_rfm22b_cfg pios_rfm22b_cfg = { .spi_cfg = &pios_spi_telem_flash_cfg, .exti_cfg = &pios_exti_rfm22b_cfg, .RFXtalCap = 0x7f, diff --git a/flight/targets/boards/sparky2/firmware/pios_board.c b/flight/targets/boards/sparky2/firmware/pios_board.c index 444653c3b..266d35a8a 100644 --- a/flight/targets/boards/sparky2/firmware/pios_board.c +++ b/flight/targets/boards/sparky2/firmware/pios_board.c @@ -852,6 +852,10 @@ void PIOS_Board_Init(void) } else { /* Configure the RFM22B device. */ const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev); + + // Set the Xtal capacitor value + pios_rfm22b_cfg.RFXtalCap = oplinkSettings.RFXtalCap; + if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) { PIOS_Assert(0); } diff --git a/shared/uavobjectdefinition/oplinksettings.xml b/shared/uavobjectdefinition/oplinksettings.xml index 0fe17836f..1e538934e 100644 --- a/shared/uavobjectdefinition/oplinksettings.xml +++ b/shared/uavobjectdefinition/oplinksettings.xml @@ -13,6 +13,7 @@ + From 8e1d6f6d86f4fd886c1e4bce5b1cb74afc633c9e Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Mon, 3 Oct 2016 18:48:10 +0200 Subject: [PATCH 05/10] LP-346 RFM22 tuning: Missing AFCCorrection update for OPLink --- flight/modules/OPLink/oplinkmod.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/flight/modules/OPLink/oplinkmod.c b/flight/modules/OPLink/oplinkmod.c index 6727cdde3..eb86e4632 100644 --- a/flight/modules/OPLink/oplinkmod.c +++ b/flight/modules/OPLink/oplinkmod.c @@ -152,18 +152,19 @@ static void systemTask(__attribute__((unused)) void *parameters) if (pios_rfm22b_id) { // Update the status - oplinkStatus.DeviceID = PIOS_RFM22B_DeviceID(pios_rfm22b_id); - oplinkStatus.RxGood = radio_stats.rx_good; - oplinkStatus.RxCorrected = radio_stats.rx_corrected; - oplinkStatus.RxErrors = radio_stats.rx_error; - oplinkStatus.RxMissed = radio_stats.rx_missed; - oplinkStatus.RxFailure = radio_stats.rx_failure; - oplinkStatus.TxDropped = radio_stats.tx_dropped; - oplinkStatus.TxFailure = radio_stats.tx_failure; - oplinkStatus.Resets = radio_stats.resets; - oplinkStatus.Timeouts = radio_stats.timeouts; + oplinkStatus.DeviceID = PIOS_RFM22B_DeviceID(pios_rfm22b_id); + oplinkStatus.RxGood = radio_stats.rx_good; + oplinkStatus.RxCorrected = radio_stats.rx_corrected; + oplinkStatus.RxErrors = radio_stats.rx_error; + oplinkStatus.RxMissed = radio_stats.rx_missed; + oplinkStatus.RxFailure = radio_stats.rx_failure; + oplinkStatus.TxDropped = radio_stats.tx_dropped; + oplinkStatus.TxFailure = radio_stats.tx_failure; + oplinkStatus.Resets = radio_stats.resets; + oplinkStatus.Timeouts = radio_stats.timeouts; oplinkStatus.RSSI = radio_stats.rssi; - oplinkStatus.LinkQuality = radio_stats.link_quality; + oplinkStatus.LinkQuality = radio_stats.link_quality; + oplinkStatus.AFCCorrection = radio_stats.afc_correction; if (first_time) { first_time = false; } else { From 54fa56d42177e89b3e7503519a6069ad54687f84 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Mon, 3 Oct 2016 21:30:02 +0200 Subject: [PATCH 06/10] LP-346 RFM22 tuning: Add Gui for tuning. --- .../src/plugins/config/configoplinkwidget.cpp | 7 + ground/gcs/src/plugins/config/oplink.ui | 147 +++++++++++++++--- 2 files changed, 135 insertions(+), 19 deletions(-) diff --git a/ground/gcs/src/plugins/config/configoplinkwidget.cpp b/ground/gcs/src/plugins/config/configoplinkwidget.cpp index 64b39d016..87ecf8255 100644 --- a/ground/gcs/src/plugins/config/configoplinkwidget.cpp +++ b/ground/gcs/src/plugins/config/configoplinkwidget.cpp @@ -84,6 +84,9 @@ ConfigOPLinkWidget::ConfigOPLinkWidget(QWidget *parent) : ConfigTaskWidget(paren addWidgetBinding("OPLinkSettings", "FlexiPort", m_oplink->FlexiPort); addWidgetBinding("OPLinkSettings", "VCPPort", m_oplink->VCPPort); + addWidgetBinding("OPLinkSettings", "RFXtalCap", m_oplink->RFXtalCapValue); + addWidgetBinding("OPLinkSettings", "RFXtalCap", m_oplink->RFXtalCapSlider); + addWidgetBinding("OPLinkStatus", "DeviceID", m_oplink->DeviceID); addWidgetBinding("OPLinkStatus", "RxGood", m_oplink->Good); addWidgetBinding("OPLinkStatus", "RxCorrected", m_oplink->Corrected); @@ -104,6 +107,7 @@ ConfigOPLinkWidget::ConfigOPLinkWidget(QWidget *parent) : ConfigTaskWidget(paren addWidgetBinding("OPLinkStatus", "TXRate", m_oplink->TXRate); addWidgetBinding("OPLinkStatus", "RXPacketRate", m_oplink->RXPacketRate); addWidgetBinding("OPLinkStatus", "TXPacketRate", m_oplink->TXPacketRate); + addWidgetBinding("OPLinkStatus", "AFCCorrection", m_oplink->AFCCorrection); // initially hide port combo boxes setPortsVisible(false); @@ -172,6 +176,9 @@ void ConfigOPLinkWidget::updateStatus() m_oplink->PairSignalStrengthBar1->setValue(linkConnected ? m_oplink->RSSI->text().toInt() : -127); m_oplink->PairSignalStrengthLabel1->setText(QString("%1dB").arg(m_oplink->PairSignalStrengthBar1->value())); + int afc_valueKHz = m_oplink->AFCCorrection->text().toInt() / 1000; + m_oplink->AFCCorrectionBar->setValue(afc_valueKHz); + // Enable components based on the board type connected. switch (oplinkStatusObj->boardType()) { case 0x09: // Revolution, DiscoveryF4Bare, RevoNano, RevoProto diff --git a/ground/gcs/src/plugins/config/oplink.ui b/ground/gcs/src/plugins/config/oplink.ui index 7c074263a..892151857 100644 --- a/ground/gcs/src/plugins/config/oplink.ui +++ b/ground/gcs/src/plugins/config/oplink.ui @@ -776,7 +776,7 @@ Leave blank to use autogenerated Device ID. - + Qt::Vertical @@ -789,7 +789,7 @@ Leave blank to use autogenerated Device ID. - + @@ -1353,6 +1353,22 @@ Leave blank to use autogenerated Device ID. + + + + + 50 + false + + + + RSSI + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + @@ -1391,22 +1407,6 @@ Leave blank to use autogenerated Device ID. - - - - - 50 - false - - - - RSSI - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - @@ -1866,10 +1866,30 @@ Leave blank to use autogenerated Device ID. + + + + AFC Correction + + + + + + + + 101 + 16777215 + + + + The automatic frequency correction in Hz. + + + - + Qt::Horizontal @@ -1882,6 +1902,95 @@ Leave blank to use autogenerated Device ID. + + + + Frequency Tuning + + + + 9 + + + 9 + + + 9 + + + 9 + + + + + The xtal capacitor value for fine tune frequency and get a AFC value close to zero. Default value is 127. + + + 171 + + + 1 + + + 127 + + + Qt::Horizontal + + + + + + + The xtal capacitor value for fine tune frequency and get a AFC value close to zero. Default value is 127. + + + 171 + + + + + + + Xtal Capacitor + + + + + + + The Automatic Frequency Correction: How much the modem will correct a frequency misalignement between the two modems. + + + -50 + + + 50 + + + 0 + + + Qt::AlignCenter + + + true + + + %v KHz + + + + + + + AFC Correction + + + + + + From 1e920ec67c0b0e6e476616fb253949bc81ee99d6 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Tue, 4 Oct 2016 00:41:40 +0200 Subject: [PATCH 07/10] LP-346 RFM22 tuning: Allow XtalCap value changes without reboot. --- flight/modules/OPLink/oplinkmod.c | 20 ++++++++++++++++++ flight/modules/System/systemmod.c | 27 +++++++++++++++++++++++++ flight/pios/common/pios_rfm22b.c | 15 ++++++++++++++ flight/pios/inc/pios_rfm22b.h | 1 + ground/gcs/src/plugins/config/oplink.ui | 9 ++++++--- 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/flight/modules/OPLink/oplinkmod.c b/flight/modules/OPLink/oplinkmod.c index eb86e4632..b5fec4244 100644 --- a/flight/modules/OPLink/oplinkmod.c +++ b/flight/modules/OPLink/oplinkmod.c @@ -67,9 +67,11 @@ static xTaskHandle systemTaskHandle; static bool stackOverflow; static bool mallocFailed; volatile int initTaskDone = 0; +static OPLinkSettingsData previousOPLinkSettings; // Private functions static void systemTask(void *parameters); +static void checkOPLinkSettingsUpdatedCb(UAVObjEvent *ev); /** * Create the module task. @@ -133,6 +135,8 @@ static void systemTask(__attribute__((unused)) void *parameters) PIOS_SYS_Reset(); } + OPLinkSettingsConnectCallback(checkOPLinkSettingsUpdatedCb); + // Initialize vars lastSysTime = xTaskGetTickCount(); @@ -242,6 +246,22 @@ void vApplicationMallocFailedHook(void) #endif } +/** + * Called whenever OPLink settings changed + */ +static void checkOPLinkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) +{ + OPLinkSettingsData currentOPLinkSettings; + + OPLinkSettingsGet(¤tOPLinkSettings); + // Check if RFXtalCap value changed + if (currentOPLinkSettings.RFXtalCap != previousOPLinkSettings.RFXtalCap) { + PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, currentOPLinkSettings.RFXtalCap); + PIOS_RFM22B_Reinit(pios_rfm22b_id); + previousOPLinkSettings = currentOPLinkSettings; + } +} + /** * @} * @} diff --git a/flight/modules/System/systemmod.c b/flight/modules/System/systemmod.c index d1ff52fd3..a1d0a1f6f 100644 --- a/flight/modules/System/systemmod.c +++ b/flight/modules/System/systemmod.c @@ -129,6 +129,11 @@ static void updateWDGstats(); static uint8_t i2c_error_activity[PIOS_I2C_ERROR_COUNT_NUMELEM]; #endif +#ifdef PIOS_INCLUDE_RFM22B +static OPLinkSettingsData previousOPLinkSettings; +static void checkOPLinkSettingsUpdatedCb(UAVObjEvent *ev); +#endif + extern uintptr_t pios_uavo_settings_fs_id; extern uintptr_t pios_user_fs_id; @@ -231,6 +236,10 @@ static void systemTask(__attribute__((unused)) void *parameters) HwSettingsConnectCallback(checkSettingsUpdatedCb); SystemSettingsConnectCallback(checkSettingsUpdatedCb); +#ifdef PIOS_INCLUDE_RFM22B + OPLinkSettingsConnectCallback(checkOPLinkSettingsUpdatedCb); +#endif + #ifdef DIAG_TASKS TaskInfoData taskInfoData; CallbackInfoData callbackInfoData; @@ -454,6 +463,24 @@ static void checkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) } } +#ifdef PIOS_INCLUDE_RFM22B +/** + * Called whenever OPLink settings changed + */ +static void checkOPLinkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) +{ + OPLinkSettingsData currentOPLinkSettings; + + OPLinkSettingsGet(¤tOPLinkSettings); + // Check if RFXtalCap value changed + if (currentOPLinkSettings.RFXtalCap != previousOPLinkSettings.RFXtalCap) { + PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, currentOPLinkSettings.RFXtalCap); + PIOS_RFM22B_Reinit(pios_rfm22b_id); + previousOPLinkSettings = currentOPLinkSettings; + } +} +#endif /* ifdef PIOS_INCLUDE_RFM22B */ + #ifdef DIAG_TASKS static void taskMonitorForEachCallback(uint16_t task_id, const struct pios_task_info *task_info, void *context) { diff --git a/flight/pios/common/pios_rfm22b.c b/flight/pios/common/pios_rfm22b.c index 1cb46f45f..665d0a13a 100644 --- a/flight/pios/common/pios_rfm22b.c +++ b/flight/pios/common/pios_rfm22b.c @@ -652,6 +652,21 @@ void PIOS_RFM22B_SetChannelConfig(uint32_t rfm22b_id, enum rfm22b_datarate datar } } +/** + * Set a XtalCap + * + * @param[in] rfm22b_id The RFM22B device index. + * @param[in] XtalCap Value. + */ +void PIOS_RFM22B_SetXtalCap(uint32_t rfm22b_id, uint8_t xtal_cap) +{ + struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rfm22b_id; + + if (PIOS_RFM22B_Validate(rfm22b_dev)) { + rfm22b_dev->cfg.RFXtalCap = xtal_cap; + } +} + /** * Set a modem to be a coordinator or not. * diff --git a/flight/pios/inc/pios_rfm22b.h b/flight/pios/inc/pios_rfm22b.h index 14b6fbaa4..696532839 100644 --- a/flight/pios/inc/pios_rfm22b.h +++ b/flight/pios/inc/pios_rfm22b.h @@ -105,6 +105,7 @@ extern int32_t PIOS_RFM22B_Init(uint32_t *rfb22b_id, uint32_t spi_id, uint32_t s extern void PIOS_RFM22B_Reinit(uint32_t rfb22b_id); extern void PIOS_RFM22B_SetTxPower(uint32_t rfm22b_id, enum rfm22b_tx_power tx_pwr); extern void PIOS_RFM22B_SetChannelConfig(uint32_t rfm22b_id, enum rfm22b_datarate datarate, uint8_t min_chan, uint8_t max_chan, bool coordinator, bool ppm_mode, bool ppm_only); +extern void PIOS_RFM22B_SetXtalCap(uint32_t rfm22b_id, uint8_t xtal_cap); extern void PIOS_RFM22B_SetCoordinatorID(uint32_t rfm22b_id, uint32_t coord_id); extern void PIOS_RFM22B_SetDeviceID(uint32_t rfm22b_id, uint32_t device_id); extern uint32_t PIOS_RFM22B_DeviceID(uint32_t rfb22b_id); diff --git a/ground/gcs/src/plugins/config/oplink.ui b/ground/gcs/src/plugins/config/oplink.ui index 892151857..46e0aa298 100644 --- a/ground/gcs/src/plugins/config/oplink.ui +++ b/ground/gcs/src/plugins/config/oplink.ui @@ -1923,7 +1923,8 @@ Leave blank to use autogenerated Device ID. - The xtal capacitor value for fine tune frequency and get a AFC value close to zero. Default value is 127. + Adjust the xtal capacitor value to fine tune frequency and +get an AFC value close to zero. Default value is 127. 171 @@ -1942,7 +1943,8 @@ Leave blank to use autogenerated Device ID. - The xtal capacitor value for fine tune frequency and get a AFC value close to zero. Default value is 127. + Adjust the xtal capacitor value to fine tune frequency and +get an AFC value close to zero. Default value is 127. 171 @@ -1959,7 +1961,8 @@ Leave blank to use autogenerated Device ID. - The Automatic Frequency Correction: How much the modem will correct a frequency misalignement between the two modems. + The Automatic Frequency Correction: How much the modem will correct +a frequency misalignement between the two modems. -50 From 340d3045583c3565f4d56e529aeee58278381d30 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Fri, 16 Dec 2016 20:27:07 +0100 Subject: [PATCH 08/10] LP-345 Changes from review - Typos - Initialize previousOPLinkSettings --- flight/modules/OPLink/oplinkmod.c | 12 ++++++++---- flight/modules/System/systemmod.c | 11 +++++++---- .../boards/discoveryf4bare/firmware/pios_board.c | 4 ++-- .../targets/boards/oplinkmini/firmware/pios_board.c | 2 +- .../targets/boards/revolution/firmware/pios_board.c | 4 ++-- flight/targets/boards/sparky2/firmware/pios_board.c | 4 ++-- ground/gcs/src/plugins/config/configoplinkwidget.h | 8 ++++---- 7 files changed, 26 insertions(+), 19 deletions(-) diff --git a/flight/modules/OPLink/oplinkmod.c b/flight/modules/OPLink/oplinkmod.c index b5fec4244..8c0b4195a 100644 --- a/flight/modules/OPLink/oplinkmod.c +++ b/flight/modules/OPLink/oplinkmod.c @@ -16,7 +16,8 @@ * @{ * * @file oplinkmod.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016. + * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief System module * * @see The GNU Public License (GPL) Version 3 @@ -71,7 +72,7 @@ static OPLinkSettingsData previousOPLinkSettings; // Private functions static void systemTask(void *parameters); -static void checkOPLinkSettingsUpdatedCb(UAVObjEvent *ev); +static void oplinkSettingsUpdatedCb(UAVObjEvent *ev); /** * Create the module task. @@ -135,7 +136,10 @@ static void systemTask(__attribute__((unused)) void *parameters) PIOS_SYS_Reset(); } - OPLinkSettingsConnectCallback(checkOPLinkSettingsUpdatedCb); + // Initialize previousOPLinkSettings used by callback + OPLinkSettingsGet(&previousOPLinkSettings); + + OPLinkSettingsConnectCallback(oplinkSettingsUpdatedCb); // Initialize vars lastSysTime = xTaskGetTickCount(); @@ -249,7 +253,7 @@ void vApplicationMallocFailedHook(void) /** * Called whenever OPLink settings changed */ -static void checkOPLinkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) +static void oplinkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) { OPLinkSettingsData currentOPLinkSettings; diff --git a/flight/modules/System/systemmod.c b/flight/modules/System/systemmod.c index a1d0a1f6f..2a911d5bd 100644 --- a/flight/modules/System/systemmod.c +++ b/flight/modules/System/systemmod.c @@ -16,7 +16,7 @@ * @{ * * @file systemmod.c - * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015. + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015-2016. * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010-2015. * @brief System module * @@ -131,7 +131,7 @@ static uint8_t i2c_error_activity[PIOS_I2C_ERROR_COUNT_NUMELEM]; #ifdef PIOS_INCLUDE_RFM22B static OPLinkSettingsData previousOPLinkSettings; -static void checkOPLinkSettingsUpdatedCb(UAVObjEvent *ev); +static void oplinkSettingsUpdatedCb(UAVObjEvent *ev); #endif extern uintptr_t pios_uavo_settings_fs_id; @@ -237,7 +237,10 @@ static void systemTask(__attribute__((unused)) void *parameters) SystemSettingsConnectCallback(checkSettingsUpdatedCb); #ifdef PIOS_INCLUDE_RFM22B - OPLinkSettingsConnectCallback(checkOPLinkSettingsUpdatedCb); + // Initialize previousOPLinkSettings used by callback + OPLinkSettingsGet(&previousOPLinkSettings); + + OPLinkSettingsConnectCallback(oplinkSettingsUpdatedCb); #endif #ifdef DIAG_TASKS @@ -467,7 +470,7 @@ static void checkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) /** * Called whenever OPLink settings changed */ -static void checkOPLinkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) +static void oplinkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) { OPLinkSettingsData currentOPLinkSettings; diff --git a/flight/targets/boards/discoveryf4bare/firmware/pios_board.c b/flight/targets/boards/discoveryf4bare/firmware/pios_board.c index 77c0f357e..f1b3cfe80 100644 --- a/flight/targets/boards/discoveryf4bare/firmware/pios_board.c +++ b/flight/targets/boards/discoveryf4bare/firmware/pios_board.c @@ -761,10 +761,10 @@ void PIOS_Board_Init(void) } /* hwsettings_rm_flexiport */ - /* Initalize the RFM22B radio COM device. */ + /* Initialize the RFM22B radio COM device. */ #if defined(PIOS_INCLUDE_RFM22B) - /* Fetch the OPinkSettings object. */ + /* Fetch the OPLinkSettings object. */ OPLinkSettingsData oplinkSettings; OPLinkSettingsGet(&oplinkSettings); diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board.c b/flight/targets/boards/oplinkmini/firmware/pios_board.c index 14a109b50..a3dd3f4af 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board.c @@ -396,7 +396,7 @@ void PIOS_Board_Init(void) PIOS_SYS_SerialNumberGetBinary(oplinkStatus.CPUSerial); oplinkStatus.BoardRevision = bdinfo->board_rev; - /* Initalize the RFM22B radio COM device. */ + /* Initialize the RFM22B radio COM device. */ if (is_enabled) { if (openlrs) { #if defined(PIOS_INCLUDE_OPENLRS) diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index 7ac888523..d6fb08c3e 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -867,10 +867,10 @@ void PIOS_Board_Init(void) GPIO_WriteBit(pios_sbus_cfg.inv.gpio, pios_sbus_cfg.inv.init.GPIO_Pin, pios_sbus_cfg.gpio_inv_disable); } - /* Initalize the RFM22B radio COM device. */ + /* Initialize the RFM22B radio COM device. */ #if defined(PIOS_INCLUDE_RFM22B) - /* Fetch the OPinkSettings object. */ + /* Fetch the OPLinkSettings object. */ OPLinkSettingsData oplinkSettings; OPLinkSettingsGet(&oplinkSettings); diff --git a/flight/targets/boards/sparky2/firmware/pios_board.c b/flight/targets/boards/sparky2/firmware/pios_board.c index 266d35a8a..9823bf135 100644 --- a/flight/targets/boards/sparky2/firmware/pios_board.c +++ b/flight/targets/boards/sparky2/firmware/pios_board.c @@ -807,10 +807,10 @@ void PIOS_Board_Init(void) } /* hwsettings_spk2_mainport */ - /* Initalize the RFM22B radio COM device. */ + /* Initialize the RFM22B radio COM device. */ #if defined(PIOS_INCLUDE_RFM22B) - /* Fetch the OPinkSettings object. */ + /* Fetch the OPLinkSettings object. */ OPLinkSettingsData oplinkSettings; OPLinkSettingsGet(&oplinkSettings); diff --git a/ground/gcs/src/plugins/config/configoplinkwidget.h b/ground/gcs/src/plugins/config/configoplinkwidget.h index 9cdb37ee9..959e28b7d 100644 --- a/ground/gcs/src/plugins/config/configoplinkwidget.h +++ b/ground/gcs/src/plugins/config/configoplinkwidget.h @@ -46,15 +46,15 @@ protected: virtual void refreshWidgetsValuesImpl(UAVObject *obj); private: - // Frequency display settings - float frequency_base; - float frequency_step; - Ui_OPLinkWidget *m_oplink; OPLinkStatus *oplinkStatusObj; OPLinkSettings *oplinkSettingsObj; + // Frequency display settings + float frequency_base; + float frequency_step; + // Is the status current? bool statusUpdated; From 2872a3467ae368d5373d25c53d162b3be5bb8b20 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Thu, 22 Dec 2016 18:49:19 +0100 Subject: [PATCH 09/10] LP-345 Simplify xtalcap callback check, reuse PIOS_RFM22B_SetXtalCap at boot --- flight/modules/OPLink/oplinkmod.c | 18 +++++++++--------- flight/modules/System/systemmod.c | 18 +++++++++--------- .../discoveryf4bare/firmware/pios_board.c | 3 ++- .../boards/oplinkmini/firmware/pios_board.c | 4 +--- .../targets/boards/revolution/board_hw_defs.c | 4 ++-- .../boards/revolution/firmware/pios_board.c | 5 +---- flight/targets/boards/sparky2/board_hw_defs.c | 2 +- .../boards/sparky2/firmware/pios_board.c | 4 +--- 8 files changed, 26 insertions(+), 32 deletions(-) diff --git a/flight/modules/OPLink/oplinkmod.c b/flight/modules/OPLink/oplinkmod.c index 8c0b4195a..a1106a1e9 100644 --- a/flight/modules/OPLink/oplinkmod.c +++ b/flight/modules/OPLink/oplinkmod.c @@ -68,7 +68,7 @@ static xTaskHandle systemTaskHandle; static bool stackOverflow; static bool mallocFailed; volatile int initTaskDone = 0; -static OPLinkSettingsData previousOPLinkSettings; +static uint8_t previousRFXtalCap; // Private functions static void systemTask(void *parameters); @@ -136,9 +136,8 @@ static void systemTask(__attribute__((unused)) void *parameters) PIOS_SYS_Reset(); } - // Initialize previousOPLinkSettings used by callback - OPLinkSettingsGet(&previousOPLinkSettings); - + // Initialize previousRFXtalCap used by callback + OPLinkSettingsRFXtalCapGet(&previousRFXtalCap); OPLinkSettingsConnectCallback(oplinkSettingsUpdatedCb); // Initialize vars @@ -255,14 +254,15 @@ void vApplicationMallocFailedHook(void) */ static void oplinkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) { - OPLinkSettingsData currentOPLinkSettings; + uint8_t currentRFXtalCap; + + OPLinkSettingsRFXtalCapGet(¤tRFXtalCap); - OPLinkSettingsGet(¤tOPLinkSettings); // Check if RFXtalCap value changed - if (currentOPLinkSettings.RFXtalCap != previousOPLinkSettings.RFXtalCap) { - PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, currentOPLinkSettings.RFXtalCap); + if (currentRFXtalCap != previousRFXtalCap) { + PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, currentRFXtalCap); PIOS_RFM22B_Reinit(pios_rfm22b_id); - previousOPLinkSettings = currentOPLinkSettings; + previousRFXtalCap = currentRFXtalCap; } } diff --git a/flight/modules/System/systemmod.c b/flight/modules/System/systemmod.c index 2a911d5bd..a09a77fa3 100644 --- a/flight/modules/System/systemmod.c +++ b/flight/modules/System/systemmod.c @@ -130,7 +130,7 @@ static uint8_t i2c_error_activity[PIOS_I2C_ERROR_COUNT_NUMELEM]; #endif #ifdef PIOS_INCLUDE_RFM22B -static OPLinkSettingsData previousOPLinkSettings; +static uint8_t previousRFXtalCap; static void oplinkSettingsUpdatedCb(UAVObjEvent *ev); #endif @@ -237,9 +237,8 @@ static void systemTask(__attribute__((unused)) void *parameters) SystemSettingsConnectCallback(checkSettingsUpdatedCb); #ifdef PIOS_INCLUDE_RFM22B - // Initialize previousOPLinkSettings used by callback - OPLinkSettingsGet(&previousOPLinkSettings); - + // Initialize previousRFXtalCap used by callback + OPLinkSettingsRFXtalCapGet(&previousRFXtalCap); OPLinkSettingsConnectCallback(oplinkSettingsUpdatedCb); #endif @@ -472,14 +471,15 @@ static void checkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) */ static void oplinkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) { - OPLinkSettingsData currentOPLinkSettings; + uint8_t currentRFXtalCap; + + OPLinkSettingsRFXtalCapGet(¤tRFXtalCap); - OPLinkSettingsGet(¤tOPLinkSettings); // Check if RFXtalCap value changed - if (currentOPLinkSettings.RFXtalCap != previousOPLinkSettings.RFXtalCap) { - PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, currentOPLinkSettings.RFXtalCap); + if (currentRFXtalCap != previousRFXtalCap) { + PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, currentRFXtalCap); PIOS_RFM22B_Reinit(pios_rfm22b_id); - previousOPLinkSettings = currentOPLinkSettings; + previousRFXtalCap = currentRFXtalCap; } } #endif /* ifdef PIOS_INCLUDE_RFM22B */ diff --git a/flight/targets/boards/discoveryf4bare/firmware/pios_board.c b/flight/targets/boards/discoveryf4bare/firmware/pios_board.c index f1b3cfe80..fe2559b32 100644 --- a/flight/targets/boards/discoveryf4bare/firmware/pios_board.c +++ b/flight/targets/boards/discoveryf4bare/firmware/pios_board.c @@ -825,8 +825,9 @@ void PIOS_Board_Init(void) /* Set the radio configuration parameters. */ PIOS_RFM22B_SetDeviceID(pios_rfm22b_id, oplinkSettings.CustomDeviceID); - PIOS_RFM22B_SetChannelConfig(pios_rfm22b_id, datarate, oplinkSettings.MinChannel, oplinkSettings.MaxChannel, is_coordinator, is_oneway, ppm_mode, ppm_only); PIOS_RFM22B_SetCoordinatorID(pios_rfm22b_id, oplinkSettings.CoordID); + PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, oplinkSettings.RFXtalCap); + PIOS_RFM22B_SetChannelConfig(pios_rfm22b_id, datarate, oplinkSettings.MinChannel, oplinkSettings.MaxChannel, is_coordinator, data_mode, ppm_mode); /* Set the PPM callback if we should be receiving PPM. */ if (ppm_mode || (ppm_only && !is_coordinator)) { diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board.c b/flight/targets/boards/oplinkmini/firmware/pios_board.c index a3dd3f4af..f1e3b78a5 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board.c @@ -414,9 +414,6 @@ void PIOS_Board_Init(void) // Configure the RFM22B device const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev); - // Set the Xtal capacitor value - pios_rfm22b_cfg.RFXtalCap = oplinkSettings.RFXtalCap; - if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) { PIOS_Assert(0); } @@ -489,6 +486,7 @@ void PIOS_Board_Init(void) // Set the radio configuration parameters. PIOS_RFM22B_SetDeviceID(pios_rfm22b_id, oplinkSettings.CustomDeviceID); PIOS_RFM22B_SetCoordinatorID(pios_rfm22b_id, oplinkSettings.CoordID); + PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, oplinkSettings.RFXtalCap); PIOS_RFM22B_SetChannelConfig(pios_rfm22b_id, datarate, oplinkSettings.MinChannel, oplinkSettings.MaxChannel, is_coordinator, data_mode, ppm_mode); /* Set the PPM callback if we should be receiving PPM. */ diff --git a/flight/targets/boards/revolution/board_hw_defs.c b/flight/targets/boards/revolution/board_hw_defs.c index 251e6a5f5..74770d980 100644 --- a/flight/targets/boards/revolution/board_hw_defs.c +++ b/flight/targets/boards/revolution/board_hw_defs.c @@ -640,7 +640,7 @@ static const struct pios_exti_cfg pios_exti_rfm22b_cfg __exti_config = { }, }; -struct pios_rfm22b_cfg pios_rfm22b_rm1_cfg = { +const struct pios_rfm22b_cfg pios_rfm22b_rm1_cfg = { .spi_cfg = &pios_spi_telem_flash_cfg, .exti_cfg = &pios_exti_rfm22b_cfg, .RFXtalCap = 0x7f, @@ -648,7 +648,7 @@ struct pios_rfm22b_cfg pios_rfm22b_rm1_cfg = { .gpio_direction = GPIO0_RX_GPIO1_TX, }; -struct pios_rfm22b_cfg pios_rfm22b_rm2_cfg = { +const struct pios_rfm22b_cfg pios_rfm22b_rm2_cfg = { .spi_cfg = &pios_spi_telem_flash_cfg, .exti_cfg = &pios_exti_rfm22b_cfg, .RFXtalCap = 0x7f, diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index d6fb08c3e..15b0a2f9b 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -913,10 +913,6 @@ void PIOS_Board_Init(void) /* Configure the RFM22B device. */ const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev); - // Set the Xtal capacitor value - pios_rfm22b_rm1_cfg.RFXtalCap = oplinkSettings.RFXtalCap; - pios_rfm22b_rm2_cfg.RFXtalCap = oplinkSettings.RFXtalCap; - if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) { PIOS_Assert(0); } @@ -960,6 +956,7 @@ void PIOS_Board_Init(void) /* Set the radio configuration parameters. */ PIOS_RFM22B_SetDeviceID(pios_rfm22b_id, oplinkSettings.CustomDeviceID); PIOS_RFM22B_SetCoordinatorID(pios_rfm22b_id, oplinkSettings.CoordID); + PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, oplinkSettings.RFXtalCap); PIOS_RFM22B_SetChannelConfig(pios_rfm22b_id, datarate, oplinkSettings.MinChannel, oplinkSettings.MaxChannel, is_coordinator, data_mode, ppm_mode); /* Set the PPM callback if we should be receiving PPM. */ diff --git a/flight/targets/boards/sparky2/board_hw_defs.c b/flight/targets/boards/sparky2/board_hw_defs.c index 2c63d0fcf..25afb14e2 100644 --- a/flight/targets/boards/sparky2/board_hw_defs.c +++ b/flight/targets/boards/sparky2/board_hw_defs.c @@ -431,7 +431,7 @@ static const struct pios_exti_cfg pios_exti_rfm22b_cfg __exti_config = { }, }; -struct pios_rfm22b_cfg pios_rfm22b_cfg = { +const struct pios_rfm22b_cfg pios_rfm22b_cfg = { .spi_cfg = &pios_spi_telem_flash_cfg, .exti_cfg = &pios_exti_rfm22b_cfg, .RFXtalCap = 0x7f, diff --git a/flight/targets/boards/sparky2/firmware/pios_board.c b/flight/targets/boards/sparky2/firmware/pios_board.c index 9823bf135..c73b96aea 100644 --- a/flight/targets/boards/sparky2/firmware/pios_board.c +++ b/flight/targets/boards/sparky2/firmware/pios_board.c @@ -853,9 +853,6 @@ void PIOS_Board_Init(void) /* Configure the RFM22B device. */ const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev); - // Set the Xtal capacitor value - pios_rfm22b_cfg.RFXtalCap = oplinkSettings.RFXtalCap; - if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) { PIOS_Assert(0); } @@ -899,6 +896,7 @@ void PIOS_Board_Init(void) /* Set the radio configuration parameters. */ PIOS_RFM22B_SetDeviceID(pios_rfm22b_id, oplinkSettings.CustomDeviceID); PIOS_RFM22B_SetCoordinatorID(pios_rfm22b_id, oplinkSettings.CoordID); + PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, oplinkSettings.RFXtalCap); PIOS_RFM22B_SetChannelConfig(pios_rfm22b_id, datarate, oplinkSettings.MinChannel, oplinkSettings.MaxChannel, is_coordinator, data_mode, ppm_mode); /* Set the PPM callback if we should be receiving PPM. */ From e0fcb92698bc6e55a14e85a03d556eaeaac14064 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Sun, 25 Dec 2016 12:49:55 +0100 Subject: [PATCH 10/10] LP-345 Set correct RSSI unit - Define tab navigation order --- .../src/plugins/config/configoplinkwidget.cpp | 2 +- ground/gcs/src/plugins/config/oplink.ui | 108 +++++++++++++++++- 2 files changed, 106 insertions(+), 4 deletions(-) diff --git a/ground/gcs/src/plugins/config/configoplinkwidget.cpp b/ground/gcs/src/plugins/config/configoplinkwidget.cpp index 87ecf8255..634cab08d 100644 --- a/ground/gcs/src/plugins/config/configoplinkwidget.cpp +++ b/ground/gcs/src/plugins/config/configoplinkwidget.cpp @@ -174,7 +174,7 @@ void ConfigOPLinkWidget::updateStatus() bool linkConnected = (oplinkStatusObj->linkState() == OPLinkStatus_LinkState::Connected); m_oplink->PairSignalStrengthBar1->setValue(linkConnected ? m_oplink->RSSI->text().toInt() : -127); - m_oplink->PairSignalStrengthLabel1->setText(QString("%1dB").arg(m_oplink->PairSignalStrengthBar1->value())); + m_oplink->PairSignalStrengthLabel1->setText(QString("%1dBm").arg(m_oplink->PairSignalStrengthBar1->value())); int afc_valueKHz = m_oplink->AFCCorrection->text().toInt() / 1000; m_oplink->AFCCorrectionBar->setValue(afc_valueKHz); diff --git a/ground/gcs/src/plugins/config/oplink.ui b/ground/gcs/src/plugins/config/oplink.ui index 46e0aa298..5e6dfca6f 100644 --- a/ground/gcs/src/plugins/config/oplink.ui +++ b/ground/gcs/src/plugins/config/oplink.ui @@ -16,6 +16,9 @@ + + Qt::NoFocus + OPLink Configuration @@ -38,6 +41,9 @@ + + Qt::NoFocus + QFrame::NoFrame @@ -367,6 +373,9 @@ Leave blank to use autogenerated Device ID. + + Qt::NoFocus + Clear the binding/coordinator ID @@ -708,7 +717,7 @@ Leave blank to use autogenerated Device ID. - -100dB + -100dBm Qt::AlignCenter @@ -872,6 +881,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -909,6 +921,12 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + + + true + 8 @@ -968,6 +986,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + The modems current state. @@ -1034,6 +1055,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1062,6 +1086,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1106,6 +1133,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1156,6 +1186,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + The percentage of packets that were corrected with error correction @@ -1197,6 +1230,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1231,6 +1267,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + The percentage of packets that were corrected with error correction @@ -1256,6 +1295,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1332,6 +1374,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + true @@ -1399,6 +1444,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1459,6 +1507,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1487,6 +1538,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + The percentage of packets that could not be corrected with error correction @@ -1524,6 +1578,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + The percentage of packets that were not received at all @@ -1549,6 +1606,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1571,6 +1631,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + true @@ -1628,6 +1691,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + The number of packets that were unable to be transmitted @@ -1697,6 +1763,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + The percentage of packets that were not received at all @@ -1744,6 +1813,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1766,6 +1838,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1820,6 +1895,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1842,6 +1920,9 @@ Leave blank to use autogenerated Device ID. false + + Qt::NoFocus + false @@ -1881,6 +1962,9 @@ Leave blank to use autogenerated Device ID. 16777215 + + Qt::NoFocus + The automatic frequency correction in Hz. @@ -1922,6 +2006,9 @@ Leave blank to use autogenerated Device ID. + + Qt::NoFocus + Adjust the xtal capacitor value to fine tune frequency and get an AFC value close to zero. Default value is 127. @@ -2040,6 +2127,9 @@ a frequency misalignement between the two modems. 25 + + Qt::NoFocus + @@ -2097,8 +2187,20 @@ a frequency misalignement between the two modems. - FirmwareVersion - SerialNumber + Protocol + MaxRFTxPower + LinkType + ComSpeed + CustomDeviceID + CoordID + UnbindButton + RFBand + MaximumChannel + MinimumChannel + MainPort + FlexiPort + VCPPort + RFXtalCapValue applyButton saveButton