1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

Allows modem mode to be set - BUT NOT YET IMPLIMENTED, use NORMAL mode for now.

Fixed bug in pipx plugin import function - wasn't restoring the AES key.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2726 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2011-02-04 23:00:48 +00:00 committed by pip
parent b0cc3d1f5f
commit 41768be215
9 changed files with 103 additions and 19 deletions

View File

@ -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;

View File

@ -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)))
@ -47,6 +47,17 @@ enum {
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)
};
// *****************************************************************************
extern volatile uint32_t random32;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -711,7 +711,7 @@
<item row="0" column="4">
<widget class="QComboBox" name="comboBox_Mode">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="maximumSize">
<size>

View File

@ -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);

View File

@ -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;