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

Fixes a bug in the rfm22b driver that was reading past the end of the bindings list when receiving a status message. Also adds some formatting changes that came about after doing a make uncrustify_all.

This commit is contained in:
Brian Webb 2013-05-26 08:36:38 -07:00
parent 26e14482b7
commit e9f83bcc80
4 changed files with 54 additions and 58 deletions

View File

@ -50,9 +50,9 @@ static void updateSettings();
#define U2C_STACK_SIZE_BYTES 260 #define U2C_STACK_SIZE_BYTES 260
#define C2U_STACK_SIZE_BYTES 316 #define C2U_STACK_SIZE_BYTES 316
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1) #define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
#define BRIDGE_BUF_LEN 10 #define BRIDGE_BUF_LEN 10
// **************** // ****************
// Private variables // Private variables

View File

@ -265,16 +265,15 @@ static const struct pios_rfm22b_transition rfm22b_transitions[RADIO_STATE_NUM_ST
[RADIO_STATE_RX_DATA] = { [RADIO_STATE_RX_DATA] = {
.entry_fn = radio_rxData, .entry_fn = radio_rxData,
.next_state = { .next_state = {
[RADIO_EVENT_INT_RECEIVED] = RADIO_STATE_RX_DATA, [RADIO_EVENT_INT_RECEIVED] = RADIO_STATE_RX_DATA,
[RADIO_EVENT_TX_START] = RADIO_STATE_TX_START, [RADIO_EVENT_TX_START] = RADIO_STATE_TX_START,
[RADIO_EVENT_REQUEST_CONNECTION] = RADIO_STATE_REQUESTING_CONNECTION, [RADIO_EVENT_ACK_TIMEOUT] = RADIO_STATE_RECEIVING_NACK,
[RADIO_EVENT_ACK_TIMEOUT] = RADIO_STATE_RECEIVING_NACK, [RADIO_EVENT_RX_COMPLETE] = RADIO_STATE_SENDING_ACK,
[RADIO_EVENT_RX_COMPLETE] = RADIO_STATE_SENDING_ACK,
[RADIO_EVENT_RX_MODE] = RADIO_STATE_RX_MODE, [RADIO_EVENT_RX_MODE] = RADIO_STATE_RX_MODE,
[RADIO_EVENT_STATUS_RECEIVED] = RADIO_STATE_RECEIVING_STATUS, [RADIO_EVENT_STATUS_RECEIVED] = RADIO_STATE_RECEIVING_STATUS,
[RADIO_EVENT_CONNECTION_REQUESTED] = RADIO_STATE_ACCEPTING_CONNECTION, [RADIO_EVENT_CONNECTION_REQUESTED] = RADIO_STATE_ACCEPTING_CONNECTION,
[RADIO_EVENT_PACKET_ACKED] = RADIO_STATE_RECEIVING_ACK, [RADIO_EVENT_PACKET_ACKED] = RADIO_STATE_RECEIVING_ACK,
[RADIO_EVENT_PACKET_NACKED] = RADIO_STATE_RECEIVING_NACK, [RADIO_EVENT_PACKET_NACKED] = RADIO_STATE_RECEIVING_NACK,
[RADIO_EVENT_FAILURE] = RADIO_STATE_RX_FAILURE, [RADIO_EVENT_FAILURE] = RADIO_STATE_RX_FAILURE,
[RADIO_EVENT_TIMEOUT] = RADIO_STATE_TIMEOUT, [RADIO_EVENT_TIMEOUT] = RADIO_STATE_TIMEOUT,
[RADIO_EVENT_ERROR] = RADIO_STATE_ERROR, [RADIO_EVENT_ERROR] = RADIO_STATE_ERROR,
@ -307,6 +306,7 @@ static const struct pios_rfm22b_transition rfm22b_transitions[RADIO_STATE_NUM_ST
.entry_fn = rfm22_receiveStatus, .entry_fn = rfm22_receiveStatus,
.next_state = { .next_state = {
[RADIO_EVENT_RX_COMPLETE] = RADIO_STATE_TX_START, [RADIO_EVENT_RX_COMPLETE] = RADIO_STATE_TX_START,
[RADIO_EVENT_REQUEST_CONNECTION] = RADIO_STATE_REQUESTING_CONNECTION,
[RADIO_EVENT_TIMEOUT] = RADIO_STATE_TIMEOUT, [RADIO_EVENT_TIMEOUT] = RADIO_STATE_TIMEOUT,
[RADIO_EVENT_ERROR] = RADIO_STATE_ERROR, [RADIO_EVENT_ERROR] = RADIO_STATE_ERROR,
[RADIO_EVENT_INITIALIZE] = RADIO_STATE_INITIALIZING, [RADIO_EVENT_INITIALIZE] = RADIO_STATE_INITIALIZING,
@ -517,7 +517,7 @@ int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, uint32_t spi_id, uint32_t slave_nu
PIOS_EXTI_Init(cfg->exti_cfg); PIOS_EXTI_Init(cfg->exti_cfg);
// Register the watchdog timer for the radio driver task // Register the watchdog timer for the radio driver task
#ifdef PIOS_WDG_RFM22B #if defined(PIOS_INCLUDE_WDG) && defined(PIOS_WDG_RFM22B)
PIOS_WDG_RegisterFlag(PIOS_WDG_RFM22B); PIOS_WDG_RegisterFlag(PIOS_WDG_RFM22B);
#endif /* PIOS_WDG_RFM22B */ #endif /* PIOS_WDG_RFM22B */
@ -1156,7 +1156,7 @@ static void pios_rfm22_task(void *parameters)
portTickType lastPPMTicks = lastEventTicks; portTickType lastPPMTicks = lastEventTicks;
while (1) { while (1) {
#ifdef PIOS_WDG_RFM22B #if defined(PIOS_INCLUDE_WDG) && defined(PIOS_WDG_RFM22B)
// Update the watchdog timer // Update the watchdog timer
PIOS_WDG_UpdateFlag(PIOS_WDG_RFM22B); PIOS_WDG_UpdateFlag(PIOS_WDG_RFM22B);
#endif /* PIOS_WDG_RFM22B */ #endif /* PIOS_WDG_RFM22B */
@ -1988,21 +1988,7 @@ static enum pios_radio_event radio_receivePacket(struct pios_rfm22b_dev *radio_d
switch (p->header.type) { switch (p->header.type) {
case PACKET_TYPE_STATUS: case PACKET_TYPE_STATUS:
ret_event = RADIO_EVENT_STATUS_RECEIVED; ret_event = RADIO_EVENT_STATUS_RECEIVED;
// Send a connection request message if we're not connected, and this is a status message from a modem that we're bound to.
if (radio_dev->coordinator && !rfm22_isConnected(radio_dev)) {
PHStatusPacketHandle status = (PHStatusPacketHandle) & (radio_dev->rx_packet);
uint32_t source_id = status->source_id;
for (uint8_t i = 0; OPLINKSETTINGS_BINDINGS_NUMELEM; ++i) {
if (radio_dev->bindings[i].pairID == source_id) {
radio_dev->cur_binding = i;
ret_event = RADIO_EVENT_REQUEST_CONNECTION;
break;
}
}
}
break; break;
case PACKET_TYPE_CON_REQUEST: case PACKET_TYPE_CON_REQUEST:
ret_event = RADIO_EVENT_CONNECTION_REQUESTED; ret_event = RADIO_EVENT_CONNECTION_REQUESTED;
break; break;
@ -2333,19 +2319,20 @@ static enum pios_radio_event rfm22_receiveNack(struct pios_rfm22b_dev *rfm22b_de
* @param[in] rfm22b_dev The device structure * @param[in] rfm22b_dev The device structure
* @return enum pios_radio_event The next event to inject * @return enum pios_radio_event The next event to inject
*/ */
static enum pios_radio_event rfm22_receiveStatus(struct pios_rfm22b_dev *rfm22b_dev) static enum pios_radio_event rfm22_receiveStatus(struct pios_rfm22b_dev *radio_dev)
{ {
PHStatusPacketHandle status = (PHStatusPacketHandle) & (rfm22b_dev->rx_packet); PHStatusPacketHandle status = (PHStatusPacketHandle) & (radio_dev->rx_packet);
int8_t rssi = rfm22b_dev->rssi_dBm; int8_t rssi = radio_dev->rssi_dBm;
int8_t afc = rfm22b_dev->afc_correction_Hz; int8_t afc = radio_dev->afc_correction_Hz;
uint32_t id = status->source_id; uint32_t id = status->source_id;
enum pios_radio_event ret_event = RADIO_EVENT_RX_COMPLETE;
// Have we seen this device recently? // Have we seen this device recently?
bool found = false; bool found = false;
uint8_t id_idx = 0; uint8_t id_idx = 0;
for (; id_idx < OPLINKSTATUS_PAIRIDS_NUMELEM; ++id_idx) { for (; id_idx < OPLINKSTATUS_PAIRIDS_NUMELEM; ++id_idx) {
if (rfm22b_dev->pair_stats[id_idx].pairID == id) { if (radio_dev->pair_stats[id_idx].pairID == id) {
found = true; found = true;
break; break;
} }
@ -2353,27 +2340,37 @@ static enum pios_radio_event rfm22_receiveStatus(struct pios_rfm22b_dev *rfm22b_
// If we have seen it, update the RSSI and reset the last contact couter // If we have seen it, update the RSSI and reset the last contact couter
if (found) { if (found) {
rfm22b_dev->pair_stats[id_idx].rssi = rssi; radio_dev->pair_stats[id_idx].rssi = rssi;
rfm22b_dev->pair_stats[id_idx].afc_correction = afc; radio_dev->pair_stats[id_idx].afc_correction = afc;
rfm22b_dev->pair_stats[id_idx].lastContact = 0; radio_dev->pair_stats[id_idx].lastContact = 0;
// If we haven't seen it, find a slot to put it in.
} else { } else {
// If we haven't seen it, find a slot to put it in.
uint8_t min_idx = 0; uint8_t min_idx = 0;
int8_t min_rssi = rfm22b_dev->pair_stats[0].rssi; int8_t min_rssi = radio_dev->pair_stats[0].rssi;
for (id_idx = 1; id_idx < OPLINKSTATUS_PAIRIDS_NUMELEM; ++id_idx) { for (id_idx = 1; id_idx < OPLINKSTATUS_PAIRIDS_NUMELEM; ++id_idx) {
if (rfm22b_dev->pair_stats[id_idx].rssi < min_rssi) { if (radio_dev->pair_stats[id_idx].rssi < min_rssi) {
min_rssi = rfm22b_dev->pair_stats[id_idx].rssi; min_rssi = radio_dev->pair_stats[id_idx].rssi;
min_idx = id_idx; min_idx = id_idx;
} }
} }
rfm22b_dev->pair_stats[min_idx].pairID = id; radio_dev->pair_stats[min_idx].pairID = id;
rfm22b_dev->pair_stats[min_idx].rssi = rssi; radio_dev->pair_stats[min_idx].rssi = rssi;
rfm22b_dev->pair_stats[min_idx].afc_correction = afc; radio_dev->pair_stats[min_idx].afc_correction = afc;
rfm22b_dev->pair_stats[min_idx].lastContact = 0; radio_dev->pair_stats[min_idx].lastContact = 0;
} }
return RADIO_EVENT_RX_COMPLETE; // Send a connection request message if we're not connected, and this is a status message from a modem that we're bound to.
if (radio_dev->coordinator && !rfm22_isConnected(radio_dev)) {
for (uint8_t i = 0; i < OPLINKSETTINGS_BINDINGS_NUMELEM; ++i) {
if (radio_dev->bindings[i].pairID == id) {
radio_dev->cur_binding = i;
ret_event = RADIO_EVENT_REQUEST_CONNECTION;
break;
}
}
}
return ret_event;
} }

View File

@ -95,7 +95,7 @@ void ConfigRevoHWWidget::setupCustomCombos()
connect(m_ui->cbFlexi, SIGNAL(currentIndexChanged(int)), this, SLOT(flexiPortChanged(int))); connect(m_ui->cbFlexi, SIGNAL(currentIndexChanged(int)), this, SLOT(flexiPortChanged(int)));
connect(m_ui->cbMain, SIGNAL(currentIndexChanged(int)), this, SLOT(mainPortChanged(int))); connect(m_ui->cbMain, SIGNAL(currentIndexChanged(int)), this, SLOT(mainPortChanged(int)));
connect(m_ui->cbModem, SIGNAL(currentIndexChanged(int)), this, SLOT(modemPortChanged(int))); connect(m_ui->cbModem, SIGNAL(currentIndexChanged(int)), this, SLOT(modemPortChanged(int)));
} }
void ConfigRevoHWWidget::refreshWidgetsValues(UAVObject *obj) void ConfigRevoHWWidget::refreshWidgetsValues(UAVObject *obj)
@ -295,7 +295,7 @@ void ConfigRevoHWWidget::modemPortChanged(int index)
m_ui->cbTxPower->setVisible(true); m_ui->cbTxPower->setVisible(true);
m_ui->lblInitFreq->setVisible(true); m_ui->lblInitFreq->setVisible(true);
m_ui->leInitFreq->setVisible(true); m_ui->leInitFreq->setVisible(true);
if(!m_refreshing) { if (!m_refreshing) {
QMessageBox::warning(this, tr("Warning"), tr("Activating the Radio requires an antenna be attached or modem damage will occur.")); QMessageBox::warning(this, tr("Warning"), tr("Activating the Radio requires an antenna be attached or modem damage will occur."));
} }
} else { } else {

View File

@ -42,7 +42,7 @@ static bool HID_GetStrProperty(IOHIDDeviceRef dev, CFStringRef property, QString
/** /**
* \brief Initialize the USB monitor * \brief Initialize the USB monitor
* *
* \note * \note
*/ */
USBMonitor::USBMonitor(QObject *parent) : QThread(parent), m_terminate(1) USBMonitor::USBMonitor(QObject *parent) : QThread(parent), m_terminate(1)
{ {
@ -57,7 +57,7 @@ USBMonitor::USBMonitor(QObject *parent) : QThread(parent), m_terminate(1)
/** /**
* \brief Free the USB monitor * \brief Free the USB monitor
* *
* \note * \note
*/ */
USBMonitor::~USBMonitor() USBMonitor::~USBMonitor()
{ {
@ -68,7 +68,7 @@ USBMonitor::~USBMonitor()
/** /**
* \brief Event received callback * \brief Event received callback
* *
* \note * \note
*/ */
void USBMonitor::deviceEventReceived() void USBMonitor::deviceEventReceived()
{ {
@ -78,7 +78,7 @@ void USBMonitor::deviceEventReceived()
/** /**
* \brief instace of USB monitor * \brief instace of USB monitor
* *
* \note * \note
*/ */
USBMonitor *USBMonitor::instance() USBMonitor *USBMonitor::instance()
{ {
@ -91,7 +91,7 @@ USBMonitor *USBMonitor::m_instance = 0;
/** /**
* \brief Remove device * \brief Remove device
* *
* \note * \note
*/ */
void USBMonitor::removeDevice(IOHIDDeviceRef dev) void USBMonitor::removeDevice(IOHIDDeviceRef dev)
{ {
@ -111,7 +111,7 @@ void USBMonitor::removeDevice(IOHIDDeviceRef dev)
/** /**
* \brief Static callback for the USB driver to indicate device removed * \brief Static callback for the USB driver to indicate device removed
* *
* \note * \note
*/ */
void USBMonitor::detach_callback(void *context, IOReturn r, void *hid_mgr, IOHIDDeviceRef dev) void USBMonitor::detach_callback(void *context, IOReturn r, void *hid_mgr, IOHIDDeviceRef dev)
{ {
@ -127,7 +127,7 @@ void USBMonitor::detach_callback(void *context, IOReturn r, void *hid_mgr, IOHID
/** /**
* \brief Add device * \brief Add device
* *
* \note * \note
*/ */
void USBMonitor::addDevice(USBPortInfo info) void USBMonitor::addDevice(USBPortInfo info)
{ {
@ -142,7 +142,7 @@ void USBMonitor::addDevice(USBPortInfo info)
/** /**
* \brief Attach device * \brief Attach device
* *
* \note * \note
*/ */
void USBMonitor::attach_callback(void *context, IOReturn r, void *hid_mgr, IOHIDDeviceRef dev) void USBMonitor::attach_callback(void *context, IOReturn r, void *hid_mgr, IOHIDDeviceRef dev)
{ {
@ -180,7 +180,7 @@ void USBMonitor::attach_callback(void *context, IOReturn r, void *hid_mgr, IOHID
/** /**
* \brief Returns a list of all currently available devices * \brief Returns a list of all currently available devices
* *
* \note * \note
*/ */
QList<USBPortInfo> USBMonitor::availableDevices() QList<USBPortInfo> USBMonitor::availableDevices()
{ {
@ -218,7 +218,7 @@ QList<USBPortInfo> USBMonitor::availableDevices(int vid, int pid, int bcdDeviceM
/** /**
* \brief USBMonitor thread * \brief USBMonitor thread
* *
* \note * \note
*/ */
void USBMonitor::run() void USBMonitor::run()
{ {
@ -297,4 +297,3 @@ static bool HID_GetStrProperty(IOHIDDeviceRef dev, CFStringRef property, QString
} }
return false; return false;
} }