mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
PipX modem can now be configured from GCS in realtime.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2695 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
878829a7cf
commit
40e9a592c8
@ -203,6 +203,15 @@ void apiconfig_processInputPacket(void *buf, uint16_t len)
|
||||
memcpy((char *)saved_settings.aes_key, (char *)settings->aes_key, sizeof(saved_settings.aes_key));
|
||||
|
||||
saved_settings_save(); // save the new settings
|
||||
|
||||
ph_set_remote_serial_number(0, 0);
|
||||
PIOS_COM_ChangeBaud(PIOS_COM_SERIAL, saved_settings.serial_baudrate);
|
||||
rfm22_setFreqCalibration(saved_settings.rf_xtal_cap);
|
||||
ph_setNominalCarrierFrequency(saved_settings.frequency_Hz);
|
||||
ph_setDatarate(saved_settings.max_rf_bandwidth);
|
||||
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);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -45,6 +45,9 @@ uint16_t ph_putData(const int connection_index, const void *data, uint16_t len);
|
||||
uint16_t ph_getData_used(const int connection_index);
|
||||
uint16_t ph_getData(const int connection_index, void *data, uint16_t len);
|
||||
|
||||
void ph_setNominalCarrierFrequency(float frequency_hz);
|
||||
float ph_getNominalCarrierFrequency(void);
|
||||
|
||||
void ph_setDatarate(uint32_t datarate_bps);
|
||||
uint32_t ph_getDatarate(void);
|
||||
|
||||
@ -54,6 +57,7 @@ uint8_t ph_getTxPower(void);
|
||||
void ph_set_AES128_key(const void *key);
|
||||
|
||||
int ph_set_remote_serial_number(int connection_index, uint32_t sn);
|
||||
void ph_set_remote_encryption(int connection_index, bool enabled, const void *key);
|
||||
|
||||
void ph_init(uint32_t our_sn, uint32_t datarate_bps, uint8_t tx_power);
|
||||
|
||||
|
@ -572,6 +572,9 @@ enum { RX_WAIT_PREAMBLE_MODE = 0,
|
||||
|
||||
// ************************************
|
||||
|
||||
void rfm22_setFreqCalibration(uint8_t value);
|
||||
uint8_t rfm22_getFreqCalibration(void);
|
||||
|
||||
void rfm22_setDatarate(uint32_t datarate_bps);
|
||||
uint32_t rfm22_getDatarate(void);
|
||||
|
||||
|
@ -453,11 +453,9 @@ void init_RF_module(void)
|
||||
while (1);
|
||||
}
|
||||
|
||||
// set carrier frequency
|
||||
rfm22_setNominalCarrierFrequency(saved_settings.frequency_Hz);
|
||||
|
||||
rfm22_setFreqCalibration(saved_settings.rf_xtal_cap);
|
||||
ph_setNominalCarrierFrequency(saved_settings.frequency_Hz);
|
||||
ph_setDatarate(saved_settings.max_rf_bandwidth);
|
||||
|
||||
ph_setTxPower(saved_settings.max_tx_power);
|
||||
}
|
||||
|
||||
@ -671,6 +669,11 @@ int main()
|
||||
|
||||
saved_settings_init();
|
||||
|
||||
#if !defined(PIOS_COM_DEBUG)
|
||||
if (saved_settings.serial_baudrate != 0xffffffff)
|
||||
PIOS_COM_ChangeBaud(PIOS_COM_SERIAL, saved_settings.serial_baudrate);
|
||||
#endif
|
||||
|
||||
// *************
|
||||
// read the API mode pin
|
||||
|
||||
@ -686,6 +689,7 @@ int main()
|
||||
else
|
||||
if ( GPIO_IN(_868MHz_PIN) && !GPIO_IN(_915MHz_PIN)) saved_settings.frequency_band = freqBand_915MHz; // 915MHz band
|
||||
|
||||
// set some defaults if they are not set
|
||||
switch (saved_settings.frequency_band)
|
||||
{
|
||||
case freqBand_434MHz:
|
||||
@ -800,9 +804,9 @@ int main()
|
||||
break;
|
||||
}
|
||||
|
||||
if (serial_number_crc32 == 0x176C1EC6) saved_settings.destination_id = 0xA524A3B0; // modem 1, open a connection to modem 2
|
||||
else
|
||||
if (serial_number_crc32 == 0xA524A3B0) saved_settings.destination_id = 0x176C1EC6; // modem 2, open a connection to modem 1
|
||||
// if (serial_number_crc32 == 0x176C1EC6) saved_settings.destination_id = 0xA524A3B0; // modem 1, open a connection to modem 2
|
||||
// else
|
||||
// if (serial_number_crc32 == 0xA524A3B0) saved_settings.destination_id = 0x176C1EC6; // modem 2, open a connection to modem 1
|
||||
|
||||
// *************
|
||||
|
||||
@ -836,13 +840,6 @@ int main()
|
||||
|
||||
init_RF_module();
|
||||
|
||||
// *************
|
||||
// initialize the USB interface
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
// PIOS_USB_HID_Init(0); // this is not needed as it gets called by the com init routine .. thank you Ed!
|
||||
#endif
|
||||
|
||||
// *************
|
||||
|
||||
saved_settings_save();
|
||||
@ -850,8 +847,7 @@ int main()
|
||||
booting = FALSE;
|
||||
|
||||
// *************
|
||||
|
||||
ph_set_remote_serial_number(0, saved_settings.destination_id);
|
||||
// Main executive loop
|
||||
|
||||
#if defined(PIOS_COM_DEBUG)
|
||||
DEBUG_PRINTF("\r\n");
|
||||
@ -860,8 +856,9 @@ int main()
|
||||
DEBUG_PRINTF("RF TX power: %d\r\n", ph_getTxPower());
|
||||
#endif
|
||||
|
||||
// *************
|
||||
// Main executive loop
|
||||
// start a remote connection going
|
||||
ph_set_remote_encryption(0, saved_settings.aes_enable, (const void *)saved_settings.aes_key);
|
||||
ph_set_remote_serial_number(0, saved_settings.destination_id);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
@ -280,20 +280,11 @@ int ph_startConnect(int connection_index, uint32_t sn)
|
||||
|
||||
t_connection *conn = &connection[connection_index];
|
||||
|
||||
if (sn != 0 && sn == our_serial_number)
|
||||
return -2; // same as our own
|
||||
|
||||
if (sn == BROADCAST_ADDR)
|
||||
{
|
||||
|
||||
return -3;
|
||||
}
|
||||
conn->link_state = link_disconnected;
|
||||
|
||||
LINK_LED_OFF;
|
||||
|
||||
conn->link_state = link_disconnected;
|
||||
|
||||
conn->serial_number = sn;
|
||||
conn->serial_number = sn;
|
||||
|
||||
conn->tx_sequence = 0;
|
||||
conn->tx_sequence_data_size = 0;
|
||||
@ -331,13 +322,23 @@ int ph_startConnect(int connection_index, uint32_t sn)
|
||||
|
||||
conn->not_ready_timer = -1;
|
||||
|
||||
// conn->send_encrypted = true;
|
||||
conn->send_encrypted = false;
|
||||
// conn->send_encrypted = true;
|
||||
// conn->send_encrypted = false;
|
||||
|
||||
conn->rx_rssi_dBm = -200;
|
||||
conn->rx_afc_Hz = 0;
|
||||
|
||||
conn->link_state = link_connecting;
|
||||
if (sn != 0 && sn == our_serial_number)
|
||||
return -2; // same as our own
|
||||
|
||||
if (sn == BROADCAST_ADDR)
|
||||
{
|
||||
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (conn->serial_number != 0)
|
||||
conn->link_state = link_connecting;
|
||||
|
||||
return connection_index;
|
||||
}
|
||||
@ -1379,6 +1380,19 @@ void ph_processLinks(int connection_index)
|
||||
}
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// set/get the carrier frequency
|
||||
|
||||
void ph_setNominalCarrierFrequency(float frequency_hz)
|
||||
{
|
||||
rfm22_setNominalCarrierFrequency(frequency_hz);
|
||||
}
|
||||
|
||||
float ph_getNominalCarrierFrequency(void)
|
||||
{
|
||||
return rfm22_getNominalCarrierFrequency();
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// set/get the RF datarate
|
||||
|
||||
@ -1417,10 +1431,13 @@ uint8_t ph_getTxPower(void)
|
||||
|
||||
void ph_set_AES128_key(const void *key)
|
||||
{
|
||||
memmove(aes_key, key, sizeof(aes_key));
|
||||
if (!key)
|
||||
return;
|
||||
|
||||
// create the AES decryption key
|
||||
aes_decrypt_key_128_create(aes_key, (void *)&dec_aes_key);
|
||||
memmove(aes_key, key, sizeof(aes_key));
|
||||
|
||||
// create the AES decryption key
|
||||
aes_decrypt_key_128_create(aes_key, (void *)&dec_aes_key);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
@ -1443,6 +1460,17 @@ int ph_set_remote_serial_number(int connection_index, uint32_t sn)
|
||||
return -4;
|
||||
}
|
||||
|
||||
void ph_set_remote_encryption(int connection_index, bool enabled, const void *key)
|
||||
{
|
||||
if (connection_index < 0 || connection_index >= PH_MAX_CONNECTIONS)
|
||||
return;
|
||||
|
||||
t_connection *conn = &connection[connection_index];
|
||||
|
||||
ph_set_AES128_key(key);
|
||||
conn->send_encrypted = enabled;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// can be called from an interrupt if you wish
|
||||
|
||||
@ -1554,7 +1582,7 @@ void ph_init(uint32_t our_sn, uint32_t datarate_bps, uint8_t tx_power)
|
||||
|
||||
conn->not_ready_timer = -1;
|
||||
|
||||
conn->send_encrypted = true;
|
||||
conn->send_encrypted = false;
|
||||
|
||||
conn->rx_rssi_dBm = -200;
|
||||
conn->rx_afc_Hz = 0;
|
||||
|
@ -207,6 +207,8 @@ volatile int16_t temperature_reg; // the temperature sensor reading
|
||||
bool debug_outputted;
|
||||
#endif
|
||||
|
||||
volatile uint8_t osc_load_cap; // xtal frequency calibration value
|
||||
|
||||
volatile uint8_t rssi; // the current RSSI (register value)
|
||||
volatile int16_t rssi_dBm; // dBm value
|
||||
|
||||
@ -387,6 +389,32 @@ uint8_t rfm22_read(uint8_t addr)
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************
|
||||
// set/get the frequency calibration value
|
||||
|
||||
void rfm22_setFreqCalibration(uint8_t value)
|
||||
{
|
||||
osc_load_cap = value;
|
||||
|
||||
if (!initialized || power_on_reset)
|
||||
return; // we haven't yet been initialized
|
||||
|
||||
#if defined(RFM22_EXT_INT_USE)
|
||||
exec_using_spi = TRUE;
|
||||
#endif
|
||||
|
||||
rfm22_write(rfm22_xtal_osc_load_cap, osc_load_cap);
|
||||
|
||||
#if defined(RFM22_EXT_INT_USE)
|
||||
exec_using_spi = FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t rfm22_getFreqCalibration(void)
|
||||
{
|
||||
return osc_load_cap;
|
||||
}
|
||||
|
||||
// ************************************
|
||||
// radio datarate about 19200 Baud
|
||||
// radio frequency deviation 45kHz
|
||||
@ -1796,15 +1824,15 @@ int rfm22_init(uint32_t min_frequency_hz, uint32_t max_frequency_hz, uint32_t fr
|
||||
rfm22_write(rfm22_op_and_func_ctrl2, 0x00);
|
||||
|
||||
// calibrate our RF module to be exactly on frequency .. different for every module
|
||||
if (serial_number_crc32 == 0x176C1EC6) rfm22_write(rfm22_xtal_osc_load_cap, OSC_LOAD_CAP_1);
|
||||
osc_load_cap = OSC_LOAD_CAP; // default
|
||||
/* if (serial_number_crc32 == 0x176C1EC6) osc_load_cap = OSC_LOAD_CAP_1;
|
||||
else
|
||||
if (serial_number_crc32 == 0xA524A3B0) rfm22_write(rfm22_xtal_osc_load_cap, OSC_LOAD_CAP_2);
|
||||
if (serial_number_crc32 == 0xA524A3B0) osc_load_cap = OSC_LOAD_CAP_2;
|
||||
else
|
||||
if (serial_number_crc32 == 0x9F6393C1) rfm22_write(rfm22_xtal_osc_load_cap, OSC_LOAD_CAP_3);
|
||||
if (serial_number_crc32 == 0x9F6393C1) osc_load_cap = OSC_LOAD_CAP_3;
|
||||
else
|
||||
if (serial_number_crc32 == 0x994ECD31) rfm22_write(rfm22_xtal_osc_load_cap, OSC_LOAD_CAP_4);
|
||||
else
|
||||
rfm22_write(rfm22_xtal_osc_load_cap, OSC_LOAD_CAP); // default
|
||||
if (serial_number_crc32 == 0x994ECD31) osc_load_cap = OSC_LOAD_CAP_4;
|
||||
*/ rfm22_write(rfm22_xtal_osc_load_cap, osc_load_cap);
|
||||
|
||||
rfm22_write(rfm22_op_and_func_ctrl1, rfm22_opfc1_xton); // READY mode
|
||||
// rfm22_write(rfm22_op_and_func_ctrl1, rfm22_opfc1_pllon); // TUNE mode
|
||||
|
Loading…
x
Reference in New Issue
Block a user