1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

Started updating the connection manager to tell the connection plugins to poll or not in a central location. Updated the rawhid and serialconnection plugins to reflect this.

More updates to uploader gadget.

Updated the telemetrymonitor and telemetrymanager to set the GCS connection status to "Disconnected" when the user click on "Disconnect" (was not done before, and lead to confusion...)



git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2385 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2011-01-12 00:05:51 +00:00 committed by edouard
parent 3d7407a82a
commit 809f4f7e07
13 changed files with 137 additions and 46 deletions

View File

@ -247,6 +247,45 @@ void ConnectionManager::unregisterAll(IConnection *connection)
} }
} }
/**
* Tells every connection plugin to stop polling for devices if they
* are doing that.
*/
void ConnectionManager::suspendPolling()
{
QList<IConnection*> connections;
connections.clear();
for(QLinkedList<devListItem>::iterator iter = m_devList.begin();
iter != m_devList.end(); iter++ ){
if (!connections.contains(iter->connection))
connections.append(iter->connection);
}
foreach (IConnection* cnx, connections) {
cnx->suspendPolling();
}
}
/**
* Tells every connection plugin to resume polling for devices if they
* are doing that.
*/
void ConnectionManager::resumePolling()
{
QList<IConnection*> connections;
connections.clear();
for(QLinkedList<devListItem>::iterator iter = m_devList.begin();
iter != m_devList.end(); iter++ ){
if (!connections.contains(iter->connection))
connections.append(iter->connection);
}
foreach (IConnection* cnx, connections) {
cnx->resumePolling();
}
}
/** /**
* Register a device from a specific connection plugin * Register a device from a specific connection plugin
*/ */
@ -267,6 +306,7 @@ void ConnectionManager::registerDevice(IConnection *conn, const QString &devN, c
*/ */
void ConnectionManager::devChanged(IConnection *connection) void ConnectionManager::devChanged(IConnection *connection)
{ {
//clear device list combobox //clear device list combobox
m_availableDevList->clear(); m_availableDevList->clear();

View File

@ -71,6 +71,8 @@ public:
QIODevice *getCurrentConnection(); // NOTE: this is never implemented ?? QIODevice *getCurrentConnection(); // NOTE: this is never implemented ??
devListItem getCurrentDevice() { return m_connectionDevice;} devListItem getCurrentDevice() { return m_connectionDevice;}
bool disconnectDevice(); bool disconnectDevice();
void suspendPolling();
void resumePolling();
protected: protected:
void unregisterAll(IConnection *connection); void unregisterAll(IConnection *connection);

View File

@ -70,6 +70,13 @@ public:
*/ */
virtual QString shortName() {return connectionName();} virtual QString shortName() {return connectionName();}
/**
* Manage whether the plugin is allowed to poll for devices
* or not
*/
virtual void suspendPolling() {};
virtual void resumePolling() {};
signals: signals:
/** /**
* Available devices list has changed, signal it to connection manager (and whoever wants to know) * Available devices list has changed, signal it to connection manager (and whoever wants to know)

View File

@ -67,7 +67,7 @@ void RawHIDEnumerationThread::run()
} }
} }
msleep(500); //update available devices twice per second (doesn't need more) msleep(1000); //update available devices every second (doesn't need more)
} }
} }
@ -90,7 +90,8 @@ RawHIDConnection::~RawHIDConnection()
void RawHIDConnection::onEnumerationChanged() void RawHIDConnection::onEnumerationChanged()
{ {
emit availableDevChanged(this); if (enablePolling)
emit availableDevChanged(this);
} }
QStringList RawHIDConnection::availableDevices() QStringList RawHIDConnection::availableDevices()
@ -156,19 +157,17 @@ QString RawHIDConnection::shortName()
/** /**
Tells the Raw HID plugin to stop polling for USB devices Tells the Raw HID plugin to stop polling for USB devices
*/ */
bool RawHIDConnection::suspendPolling() void RawHIDConnection::suspendPolling()
{ {
enablePolling = false; enablePolling = false;
return true;
} }
/** /**
Tells the Raw HID plugin to resume polling for USB devices Tells the Raw HID plugin to resume polling for USB devices
*/ */
bool RawHIDConnection::resumePolling() void RawHIDConnection::resumePolling()
{ {
enablePolling = true; enablePolling = true;
return true;
} }

View File

@ -83,8 +83,8 @@ public:
virtual QString connectionName(); virtual QString connectionName();
virtual QString shortName(); virtual QString shortName();
bool suspendPolling(); virtual void suspendPolling();
bool resumePolling(); virtual void resumePolling();
bool deviceOpened() {return m_deviceOpened;} bool deviceOpened() {return m_deviceOpened;}

View File

@ -73,7 +73,7 @@ void SerialEnumerationThread::run()
SerialConnection::SerialConnection() SerialConnection::SerialConnection()
: m_enumerateThread(this) : enablePolling(true), m_enumerateThread(this)
{ {
serialHandle = NULL; serialHandle = NULL;
@ -102,8 +102,10 @@ SerialConnection::~SerialConnection()
void SerialConnection::onEnumerationChanged() void SerialConnection::onEnumerationChanged()
{ {
emit availableDevChanged(this); if (enablePolling)
emit availableDevChanged(this);
} }
bool sortPorts(const QextPortInfo &s1,const QextPortInfo &s2) bool sortPorts(const QextPortInfo &s1,const QextPortInfo &s2)
{ {
return s1.portName<s2.portName; return s1.portName<s2.portName;
@ -112,12 +114,15 @@ bool sortPorts(const QextPortInfo &s1,const QextPortInfo &s2)
QStringList SerialConnection::availableDevices() QStringList SerialConnection::availableDevices()
{ {
QStringList list; QStringList list;
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
//sort the list by port number (nice idea from PT_Dreamer :)) if (enablePolling) {
qSort(ports.begin(), ports.end(),sortPorts); QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
foreach( QextPortInfo port, ports ) {
list.append(port.friendName); //sort the list by port number (nice idea from PT_Dreamer :))
qSort(ports.begin(), ports.end(),sortPorts);
foreach( QextPortInfo port, ports ) {
list.append(port.friendName);
}
} }
return list; return list;
@ -175,6 +180,22 @@ QString SerialConnection::shortName()
return QString("Serial"); return QString("Serial");
} }
/**
Tells the Serial plugin to stop polling for serial devices
*/
void SerialConnection::suspendPolling()
{
enablePolling = false;
}
/**
Tells the Serial plugin to resume polling for serial devices
*/
void SerialConnection::resumePolling()
{
enablePolling = true;
}
SerialPlugin::SerialPlugin() SerialPlugin::SerialPlugin()
{ {

View File

@ -81,11 +81,16 @@ public:
virtual QString connectionName(); virtual QString connectionName();
virtual QString shortName(); virtual QString shortName();
virtual void suspendPolling();
virtual void resumePolling();
bool deviceOpened() {return m_deviceOpened;} bool deviceOpened() {return m_deviceOpened;}
private: private:
QextSerialPort* serialHandle; QextSerialPort* serialHandle;
bool enablePolling;
protected slots: protected slots:
void onEnumerationChanged(); void onEnumerationChanged();

View File

@ -72,6 +72,7 @@ void TelemetryManager::onStop()
delete telemetryMon; delete telemetryMon;
delete telemetry; delete telemetry;
delete utalk; delete utalk;
onDisconnect();
} }
void TelemetryManager::onConnect() void TelemetryManager::onConnect()

View File

@ -54,6 +54,14 @@ TelemetryMonitor::TelemetryMonitor(UAVObjectManager* objMngr, Telemetry* tel)
statsTimer->start(STATS_CONNECT_PERIOD_MS); statsTimer->start(STATS_CONNECT_PERIOD_MS);
} }
TelemetryMonitor::~TelemetryMonitor() {
// Before saying goodbye, set the GCS connection status to disconnected too:
GCSTelemetryStats::DataFields gcsStats = gcsStatsObj->getData();
gcsStats.Status = GCSTelemetryStats::STATUS_DISCONNECTED;
// Set data
gcsStatsObj->setData(gcsStats);
}
/** /**
* Initiate object retrieval, initialize queue with objects to be retrieved. * Initiate object retrieval, initialize queue with objects to be retrieved.
*/ */

View File

@ -46,6 +46,7 @@ class TelemetryMonitor : public QObject
public: public:
TelemetryMonitor(UAVObjectManager* objMngr, Telemetry* tel); TelemetryMonitor(UAVObjectManager* objMngr, Telemetry* tel);
~TelemetryMonitor();
signals: signals:
void connected(); void connected();

View File

@ -25,7 +25,7 @@ int16_t port::pfSerialRead(void)
{ {
char c[1]; char c[1];
if(sport->bytesAvailable()) if( sport->bytesAvailable() )
{ {
sport->read(c,1); sport->read(c,1);
} }

View File

@ -32,7 +32,7 @@ bool qsspt::sendData(uint8_t * buf,uint16_t size)
msize=size; msize=size;
sendbufmutex.unlock(); sendbufmutex.unlock();
msendwait.lock(); msendwait.lock();
sendwait.wait(&msendwait,100000); sendwait.wait(&msendwait,10000);
msendwait.unlock(); msendwait.unlock();
return true; return true;
} }

View File

@ -127,8 +127,13 @@ void UploaderGadgetWidget::onAutopilotDisconnect(){
m_config->haltButton->setEnabled(false); m_config->haltButton->setEnabled(false);
m_config->resetButton->setEnabled(false); m_config->resetButton->setEnabled(false);
m_config->bootButton->setEnabled(true); m_config->bootButton->setEnabled(true);
m_config->rescueButton->setEnabled(true); if (currentStep == IAP_STATE_BOOTLOADER) {
m_config->telemetryLink->setEnabled(true); m_config->rescueButton->setEnabled(false);
m_config->telemetryLink->setEnabled(false);
} else {
m_config->rescueButton->setEnabled(true);
m_config->telemetryLink->setEnabled(true);
}
} }
@ -147,6 +152,8 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
switch (currentStep) { switch (currentStep) {
case IAP_STATE_READY: case IAP_STATE_READY:
getSerialPorts(); // Useful in case a new serial port appeared since the initial list,
// otherwise we won't find it when we stop the board.
// The board is running, send the 1st IAP Reset order: // The board is running, send the 1st IAP Reset order:
fwIAP->getField("Command")->setValue("1122"); fwIAP->getField("Command")->setValue("1122");
connect(fwIAP,SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToBootloader(UAVObject*, bool))); connect(fwIAP,SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToBootloader(UAVObject*, bool)));
@ -192,17 +199,14 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
disconnect(fwIAP, SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToBootloader(UAVObject*, bool))); disconnect(fwIAP, SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToBootloader(UAVObject*, bool)));
break; break;
} }
// stop the polling thread: otherwise it will mess up DFU
// Do it now, because otherwise it will send bad stuff to
// the board before we have time to stop it.
RawHIDConnection *cnx = pm->getObject<RawHIDConnection>();
cnx->suspendPolling();
// The board is now reset: we have to disconnect telemetry // The board is now reset: we have to disconnect telemetry
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager(); Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
QString dli = cm->getCurrentDevice().devName; QString dli = cm->getCurrentDevice().devName;
QString dlj = cm->getCurrentDevice().displayedName; QString dlj = cm->getCurrentDevice().displayedName;
cm->disconnectDevice(); cm->disconnectDevice();
// Tell connections to stop their polling threads: otherwise it will mess up DFU
cm->suspendPolling();
log("Board Halt"); log("Board Halt");
m_config->boardStatus->setText("Bootloader"); m_config->boardStatus->setText("Bootloader");
if (dlj.startsWith("USB")) if (dlj.startsWith("USB"))
@ -229,7 +233,7 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
log("Could not enter DFU mode."); log("Could not enter DFU mode.");
delete dfu; delete dfu;
dfu = NULL; dfu = NULL;
cnx->resumePolling(); cm->resumePolling();
return; return;
} }
dfu->AbortOperation(); dfu->AbortOperation();
@ -238,7 +242,7 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
log("Could not enter DFU mode."); log("Could not enter DFU mode.");
delete dfu; delete dfu;
dfu = NULL; dfu = NULL;
cnx->resumePolling(); cm->resumePolling();
return; return;
} }
//dfu.StatusRequest(); //dfu.StatusRequest();
@ -248,7 +252,7 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
log("Inconsistent number of devices! Aborting"); log("Inconsistent number of devices! Aborting");
delete dfu; delete dfu;
dfu = NULL; dfu = NULL;
cnx->resumePolling(); cm->resumePolling();
return; return;
} }
// Delete all previous tabs: // Delete all previous tabs:
@ -264,11 +268,13 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
dw->populate(); dw->populate();
m_config->systemElements->addTab(dw, QString("Device") + QString::number(i)); m_config->systemElements->addTab(dw, QString("Device") + QString::number(i));
} }
/*
m_config->haltButton->setEnabled(false); m_config->haltButton->setEnabled(false);
m_config->resetButton->setEnabled(false); m_config->resetButton->setEnabled(false);
m_config->bootButton->setEnabled(true); m_config->bootButton->setEnabled(true);
m_config->telemetryLink->setEnabled(false); m_config->telemetryLink->setEnabled(false);
m_config->rescueButton->setEnabled(false); m_config->rescueButton->setEnabled(false);
*/
if (resetOnly) { if (resetOnly) {
resetOnly=false; resetOnly=false;
delay::msleep(3500); delay::msleep(3500);
@ -307,16 +313,18 @@ void UploaderGadgetWidget::systemReset()
*/ */
void UploaderGadgetWidget::systemBoot() void UploaderGadgetWidget::systemBoot()
{ {
clearLog(); clearLog();
m_config->bootButton->setEnabled(false);
if (currentStep != IAP_STATE_BOOTLOADER) { if (currentStep != IAP_STATE_BOOTLOADER) {
this->repaint(); // The board is now reset: we have to disconnect telemetry
// Stop the polling thread just in case (really necessary) Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); cm->suspendPolling();
RawHIDConnection *cnx = pm->getObject<RawHIDConnection>();
cnx->suspendPolling();
} }
QString devName = m_config->telemetryLink->currentText(); QString devName = m_config->telemetryLink->currentText();
log("Attempting to boot the system through " + devName + ".");
repaint();
if (!dfu) { if (!dfu) {
if (devName == "USB") if (devName == "USB")
@ -330,17 +338,16 @@ void UploaderGadgetWidget::systemBoot()
log("Could not enter DFU mode."); log("Could not enter DFU mode.");
delete dfu; delete dfu;
dfu = NULL; dfu = NULL;
m_config->bootButton->setEnabled(true);
return; return;
} }
log("Booting system..."); log("Booting system...");
dfu->JumpToApp(); dfu->JumpToApp();
// Restart the polling thread // Restart the polling thread
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); // The board is now reset: we have to disconnect telemetry
RawHIDConnection *cnx = pm->getObject<RawHIDConnection>(); Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
cnx->resumePolling(); cm->resumePolling();
// m_config->bootButton->setEnabled(false); m_config->bootButton->setEnabled(true);
//m_config->haltButton->setEnabled(true);
//m_config->resetButton->setEnabled(true);
m_config->rescueButton->setEnabled(true); m_config->rescueButton->setEnabled(true);
m_config->telemetryLink->setEnabled(true); m_config->telemetryLink->setEnabled(true);
m_config->boardStatus->setText("Running"); m_config->boardStatus->setText("Running");
@ -364,14 +371,12 @@ void UploaderGadgetWidget::systemBoot()
*/ */
void UploaderGadgetWidget::systemRescue() void UploaderGadgetWidget::systemRescue()
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
RawHIDConnection *cnx = pm->getObject<RawHIDConnection>();
switch (rescueStep) { switch (rescueStep) {
case RESCUE_STEP0: { case RESCUE_STEP0: {
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
cm->disconnectDevice(); cm->disconnectDevice();
// stop the polling thread: otherwise it will mess up DFU // stop the polling thread: otherwise it will mess up DFU
cnx->suspendPolling(); cm->suspendPolling();
// Delete all previous tabs: // Delete all previous tabs:
while (m_config->systemElements->count()) { while (m_config->systemElements->count()) {
QWidget *qw = m_config->systemElements->widget(0); QWidget *qw = m_config->systemElements->widget(0);
@ -414,7 +419,9 @@ void UploaderGadgetWidget::systemRescue()
{ {
rescueStep = RESCUE_STEP0; rescueStep = RESCUE_STEP0;
log("Could not enter DFU mode."); log("Could not enter DFU mode.");
cnx->resumePolling(); delete dfu;
dfu = NULL;
cm->resumePolling();
return; return;
} }
if(!dfu->findDevices() || (dfu->numberOfDevices != 1)) if(!dfu->findDevices() || (dfu->numberOfDevices != 1))
@ -423,7 +430,7 @@ void UploaderGadgetWidget::systemRescue()
log("Could not detect mainboard."); log("Could not detect mainboard.");
delete dfu; delete dfu;
dfu = NULL; dfu = NULL;
cnx->resumePolling(); cm->resumePolling();
return; return;
} }
rescueStep = RESCUE_POWER1; rescueStep = RESCUE_POWER1;
@ -449,7 +456,7 @@ void UploaderGadgetWidget::systemRescue()
log("Could not detect devices."); log("Could not detect devices.");
delete dfu; delete dfu;
dfu = NULL; dfu = NULL;
cnx->resumePolling(); cm->resumePolling();
return; return;
} }
log(QString("Found ") + QString::number(dfu->numberOfDevices) + QString(" device(s).")); log(QString("Found ") + QString::number(dfu->numberOfDevices) + QString(" device(s)."));
@ -457,7 +464,7 @@ void UploaderGadgetWidget::systemRescue()
log("Inconsistent number of devices, aborting!"); log("Inconsistent number of devices, aborting!");
delete dfu; delete dfu;
dfu = NULL; dfu = NULL;
cnx->resumePolling(); cm->resumePolling();
return; return;
} }
for(int i=0;i<dfu->numberOfDevices;i++) { for(int i=0;i<dfu->numberOfDevices;i++) {