diff --git a/flight/PipXtreme/api_config.c b/flight/PipXtreme/api_config.c index 834c6a783..f356dc721 100644 --- a/flight/PipXtreme/api_config.c +++ b/flight/PipXtreme/api_config.c @@ -84,6 +84,7 @@ typedef struct typedef struct { + uint8_t mode; uint32_t serial_baudrate; // serial usart baudrate uint32_t destination_id; uint32_t frequency_Hz; @@ -208,12 +209,13 @@ int apiconfig_sendSettingsPacket(void) header->spare = 0; header->data_size = sizeof(t_pipx_config_settings); - settings->serial_baudrate = saved_settings.serial_baudrate; + settings->mode = saved_settings.mode; settings->destination_id = saved_settings.destination_id; settings->frequency_Hz = saved_settings.frequency_Hz; settings->max_rf_bandwidth = saved_settings.max_rf_bandwidth; settings->max_tx_power = saved_settings.max_tx_power; settings->rf_xtal_cap = saved_settings.rf_xtal_cap; + settings->serial_baudrate = saved_settings.serial_baudrate; settings->aes_enable = saved_settings.aes_enable; memcpy((char *)settings->aes_key, (char *)saved_settings.aes_key, sizeof(settings->aes_key)); @@ -285,16 +287,12 @@ void apiconfig_processInputPacket(void *buf, uint16_t len) t_pipx_config_settings *settings = (t_pipx_config_settings *)data; + saved_settings.mode = settings->mode; saved_settings.destination_id = settings->destination_id; - saved_settings.frequency_Hz = settings->frequency_Hz; - saved_settings.max_tx_power = settings->max_tx_power; - saved_settings.max_rf_bandwidth = settings->max_rf_bandwidth; - saved_settings.rf_xtal_cap = settings->rf_xtal_cap; - saved_settings.serial_baudrate = settings->serial_baudrate; saved_settings.aes_enable = settings->aes_enable; @@ -311,6 +309,28 @@ void apiconfig_processInputPacket(void *buf, uint16_t len) ph_setTxPower(saved_settings.max_tx_power); ph_set_remote_serial_number(0, saved_settings.destination_id); ph_set_remote_encryption(0, saved_settings.aes_enable, (const void *)saved_settings.aes_key); + switch (saved_settings.mode) + { + case modeNormal: // normal 2-way packet mode + break; + case modeStreamTx: // 1-way continuous tx packet mode + break; + case modeStreamRx: // 1-way continuous rx packet mode + break; + case modePPMTx: // PPM tx mode + break; + case modePPMRx: // PPM rx mode + break; + case modeScanSpectrum: // scan the receiver over the whole band + break; + case modeTxBlankCarrierTest: // blank carrier Tx mode (for calibrating the carrier frequency say) + break; + case modeTxSpectrumTest: // pseudo random Tx data mode (for checking the Tx carrier spectrum) + break; + default: // unknown mode + saved_settings.mode = modeNormal; + break; + } } break; diff --git a/flight/PipXtreme/inc/main.h b/flight/PipXtreme/inc/main.h index 5ec56dd15..9f3d6c0a9 100644 --- a/flight/PipXtreme/inc/main.h +++ b/flight/PipXtreme/inc/main.h @@ -33,7 +33,7 @@ // firmware version #define version_major 0 // 0 to 255 -#define version_minor 1 // 0 to 255 +#define version_minor 2 // 0 to 255 // macro's for reading internal flash memory #define mem8(addr) (*((volatile uint8_t *)(addr))) @@ -41,10 +41,21 @@ #define mem32(addr) (*((volatile uint32_t *)(addr))) enum { - freqBand_UNKNOWN = 0, - freqBand_434MHz, - freqBand_868MHz, - freqBand_915MHz + freqBand_UNKNOWN = 0, + freqBand_434MHz, + freqBand_868MHz, + freqBand_915MHz +}; + +enum { + modeNormal = 0, // normal 2-way packet mode + modeStreamTx, // 1-way continuous tx packet mode + modeStreamRx, // 1-way continuous rx packet mode + modePPMTx, // PPM tx mode + modePPMRx, // PPM rx mode + modeScanSpectrum, // scan the receiver over the whole band + modeTxBlankCarrierTest, // blank carrier Tx mode (for calibrating the carrier frequency say) + modeTxSpectrumTest // pseudo random Tx data mode (for checking the Tx carrier spectrum) }; // ***************************************************************************** diff --git a/flight/PipXtreme/inc/saved_settings.h b/flight/PipXtreme/inc/saved_settings.h index 8f063934d..14534ca77 100644 --- a/flight/PipXtreme/inc/saved_settings.h +++ b/flight/PipXtreme/inc/saved_settings.h @@ -54,7 +54,9 @@ typedef struct bool aes_enable; uint8_t aes_key[16]; - uint8_t spare[32]; // allow for future unknown settings + uint8_t mode; + + uint8_t spare[31]; // allow for future unknown settings uint32_t crc; } __attribute__((__packed__)) t_saved_settings; diff --git a/flight/PipXtreme/main.c b/flight/PipXtreme/main.c index cd2f0609b..42733eb46 100644 --- a/flight/PipXtreme/main.c +++ b/flight/PipXtreme/main.c @@ -689,10 +689,14 @@ int main() else if ( GPIO_IN(_868MHz_PIN) && !GPIO_IN(_915MHz_PIN)) saved_settings.frequency_band = freqBand_915MHz; // 915MHz band + if (saved_settings.mode == 0xff) + saved_settings.mode = modeNormal; + // set some defaults if they are not set switch (saved_settings.frequency_band) { case freqBand_434MHz: + if (saved_settings.min_frequency_Hz == 0xffffffff) { saved_settings.frequency_Hz = 434000000; diff --git a/flight/PipXtreme/rfm22b.c b/flight/PipXtreme/rfm22b.c index 0c2436906..965df7f12 100644 --- a/flight/PipXtreme/rfm22b.c +++ b/flight/PipXtreme/rfm22b.c @@ -179,6 +179,8 @@ uint32_t carrier_frequency_hz; // the current RF frequency we are on uint32_t carrier_datarate_bps; // the RF data rate we are using +uint32_t rf_bandwidth_used; // the RF bandwidth currently used + uint8_t hbsel; // holds the hbsel (1 or 2) float frequency_step_size; // @@ -444,6 +446,8 @@ void rfm22_setDatarate(uint32_t datarate_bps) carrier_datarate_bps = datarate_bps = data_rate[lookup_index]; + rf_bandwidth_used = rx_bandwidth[lookup_index]; + // ******************************** #if defined(RFM22_DEBUG) @@ -1202,6 +1206,10 @@ void rfm22_processInt(void) { rssi = rfm22_read(rfm22_rssi); // read rx signal strength .. 45 = -100dBm, 205 = -20dBm rssi_dBm = ((int16_t)rssi / 2) - 122; // convert to dBm + + // calibrate the RSSI value (rf bandwidth appears to affect it) +// if (rf_bandwidth_used > 0) +// rssi_dBm -= 10000 / rf_bandwidth_used; } else { @@ -1750,6 +1758,8 @@ int rfm22_init(uint32_t min_frequency_hz, uint32_t max_frequency_hz, uint32_t fr lookup_index = 0; + rf_bandwidth_used = 0; + rfm22_int_timer = 0; rfm22_int_time_outs = 0; prev_rfm22_int_time_outs = 0; diff --git a/flight/PipXtreme/saved_settings.c b/flight/PipXtreme/saved_settings.c index 8e585f668..9786dead7 100644 --- a/flight/PipXtreme/saved_settings.c +++ b/flight/PipXtreme/saved_settings.c @@ -295,6 +295,8 @@ void saved_settings_init(void) memset((void *)&saved_settings, 0xff, sizeof(t_saved_settings)); + saved_settings.mode = modeNormal; + saved_settings.destination_id = 0; saved_settings.frequency_band = freqBand_UNKNOWN; diff --git a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.ui b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.ui index 58671aeeb..4b04f804f 100644 --- a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.ui +++ b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.ui @@ -711,7 +711,7 @@ - false + true diff --git a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.cpp index ef26b95c1..60e4c72d0 100644 --- a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.cpp @@ -67,6 +67,19 @@ enum { // *************************************************************************************** +enum { + modeNormal = 0, // normal 2-way packet mode + modeStreamTx, // 1-way continuous tx packet mode + modeStreamRx, // 1-way continuous rx packet mode + modePPMTx, // PPM tx mode + modePPMRx, // PPM rx mode + modeScanSpectrum, // scan the receiver over the whole band + modeTxBlankCarrierTest, // blank carrier Tx mode (for calibrating the carrier frequency say) + modeTxSpectrumTest // pseudo random Tx data mode (for checking the Tx carrier spectrum) +}; + +// *************************************************************************************** + #define Poly32 0x04c11db7 // 32-bit polynomial .. this should produce the same as the STM32 hardware CRC uint32_t CRC_Table32[] = { @@ -143,10 +156,14 @@ PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) : m_widget->comboBox_SerialBaudrate->setCurrentIndex(m_widget->comboBox_SerialBaudrate->findText("57600")); m_widget->comboBox_Mode->clear(); - m_widget->comboBox_Mode->addItem("Normal", 0); - m_widget->comboBox_Mode->addItem("Scan Spectrum", 1); - m_widget->comboBox_Mode->addItem("Calibrate Tx Carrier Frequency", 2); - m_widget->comboBox_Mode->addItem("Test Tx Spectrum", 3); + m_widget->comboBox_Mode->addItem("Normal", modeNormal); + m_widget->comboBox_Mode->addItem("Stream Tx", modeStreamTx); + m_widget->comboBox_Mode->addItem("Stream Rx", modeStreamRx); + m_widget->comboBox_Mode->addItem("PPM Tx", modePPMTx); + m_widget->comboBox_Mode->addItem("PPM Rx", modePPMRx); + m_widget->comboBox_Mode->addItem("Scan Spectrum", modeScanSpectrum); + m_widget->comboBox_Mode->addItem("Test Tx Blank Carrier Frequency", modeTxBlankCarrierTest); + m_widget->comboBox_Mode->addItem("Test Tx Spectrum", modeTxSpectrumTest); m_widget->comboBox_SerialPortSpeed->clear(); for (int i = 0; i < m_widget->comboBox_SerialBaudrate->count(); i++) @@ -487,6 +504,8 @@ void PipXtremeGadgetWidget::saveToFlash() t_pipx_config_settings settings; + settings.mode = m_widget->comboBox_Mode->itemData(m_widget->comboBox_Mode->currentIndex()).toUInt(); + s = m_widget->lineEdit_PairedSerialNumber->text().trimmed().toLower(); s.replace(' ', ""); // remove all spaces if (s.startsWith("0x")) @@ -851,6 +870,16 @@ void PipXtremeGadgetWidget::processRxPacket(quint8 *packet, int packet_size) memcpy(&pipx_config_details, data, sizeof(t_pipx_config_details)); + if (pipx_config_details.major_version < 0 || (pipx_config_details.major_version == 0 && pipx_config_details.minor_version < 2)) + { + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Critical); + msgBox.setText("You need to update your modem firmware to V0.2 or later"); + msgBox.exec(); + disconnectPort(true); + return; + } + m_widget->lineEdit_FirmwareVersion->setText(QString::number(pipx_config_details.major_version) + "." + QString::number(pipx_config_details.minor_version)); m_widget->lineEdit_SerialNumber->setText(QString::number(pipx_config_details.serial_number, 16).toUpper()); @@ -895,6 +924,8 @@ void PipXtremeGadgetWidget::processRxPacket(quint8 *packet, int packet_size) memcpy(&pipx_config_settings, data, sizeof(t_pipx_config_settings)); + m_widget->comboBox_Mode->setCurrentIndex(m_widget->comboBox_Mode->findData(pipx_config_settings.mode)); + m_widget->lineEdit_PairedSerialNumber->setText(QString::number(pipx_config_settings.destination_id, 16).toUpper()); m_widget->spinBox_FrequencyCalibration->setValue(pipx_config_settings.rf_xtal_cap); @@ -1261,6 +1292,7 @@ void PipXtremeGadgetWidget::importSettings() // return; } + pipx_config_settings.mode = settings.value("settings/mode", 0).toUInt(); pipx_config_settings.destination_id = settings.value("settings/paired_serial_number", 0).toUInt(); pipx_config_settings.rf_xtal_cap = settings.value("settings/frequency_calibration", 0x7f).toUInt(); pipx_config_settings.frequency_Hz = settings.value("settings/frequency", (pipx_config_details.min_frequency_Hz + pipx_config_details.max_frequency_Hz) / 2).toUInt(); @@ -1271,6 +1303,7 @@ void PipXtremeGadgetWidget::importSettings() for (int i = 0; i < (int)sizeof(pipx_config_settings.aes_key); i++) pipx_config_settings.aes_key[i] = settings.value("settings/aes_key_" + QString::number(i), 0).toUInt(); + m_widget->comboBox_Mode->setCurrentIndex(m_widget->comboBox_Mode->findData(pipx_config_settings.mode)); m_widget->lineEdit_PairedSerialNumber->setText(QString::number(pipx_config_settings.destination_id, 16).toUpper()); m_widget->spinBox_FrequencyCalibration->setValue(pipx_config_settings.rf_xtal_cap); m_widget->doubleSpinBox_Frequency->setValue((double)pipx_config_settings.frequency_Hz / 1e6); @@ -1281,7 +1314,7 @@ void PipXtremeGadgetWidget::importSettings() QString key = ""; for (int i = 0; i < (int)sizeof(pipx_config_settings.aes_key); i++) key += QString::number(pipx_config_settings.aes_key[i], 16).rightJustified(2, '0'); -// m_widget->lineEdit_AESKey->setText(key); + m_widget->lineEdit_AESKey->setText(key); m_widget->checkBox_AESEnable->setChecked(pipx_config_settings.aes_enable); } @@ -1323,6 +1356,7 @@ void PipXtremeGadgetWidget::exportSettings() settings.setValue("details/min_frequency", pipx_config_details.min_frequency_Hz); settings.setValue("details/max_frequency", pipx_config_details.max_frequency_Hz); settings.setValue("details/frequency_band", pipx_config_details.frequency_band); + settings.setValue("settings/mode", pipx_config_settings.mode); settings.setValue("settings/paired_serial_number", pipx_config_settings.destination_id); settings.setValue("settings/frequency_calibration", pipx_config_settings.rf_xtal_cap); settings.setValue("settings/frequency", pipx_config_settings.frequency_Hz); diff --git a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.h b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.h index b1a7329ae..eedaabe6f 100644 --- a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.h @@ -89,7 +89,8 @@ typedef struct typedef struct { - uint32_t serial_baudrate; // serial uart baudrate + uint8_t mode; + uint32_t serial_baudrate; uint32_t destination_id; uint32_t frequency_Hz; uint32_t max_rf_bandwidth;