Merge branch 'pc7' of github.com:rclasen/GoldenCheetah into release_3.0.0dev

This commit is contained in:
Mark Liversedge
2011-07-25 20:03:16 +01:00
5 changed files with 109 additions and 28 deletions

View File

@@ -75,9 +75,18 @@ struct Devices
{
virtual DevicePtr newDevice( CommPortPtr ) = 0;
virtual bool canCleanup() { return false; };
virtual QString downloadInstructions() const { return ""; };
// port *might* be supported by this device type implementation:
virtual bool supportsPort( CommPortPtr dev ) { (void)dev; return true; };
// port is only useful for this device type - no matter if it's
// actually supported. Prevents this port to be offered for download
// with other device types:
virtual bool exclusivePort( CommPortPtr dev ) { (void)dev; return false; };
// cleanup for this device type is implemented:
virtual bool canCleanup() { return false; };
virtual QString downloadInstructions() const { return ""; };
static QList<QString> typeNames();
static DevicesPtr getType(const QString &deviceTypeName );

View File

@@ -26,7 +26,6 @@
#include <QtGui>
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <stdio.h>
DownloadRideDialog::DownloadRideDialog(MainWindow *mainWindow,
const QDir &home) :
@@ -36,8 +35,15 @@ DownloadRideDialog::DownloadRideDialog(MainWindow *mainWindow,
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle("Download Ride Data");
portCombo = new QComboBox(this);
deviceCombo = new QComboBox(this);
QList<QString> deviceTypes = Devices::typeNames();
assert(deviceTypes.size() > 0);
BOOST_FOREACH(QString device, deviceTypes) {
deviceCombo->addItem(device);
}
connect(deviceCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(deviceChanged(QString)));
portCombo = new QComboBox(this);
statusLabel = new QTextEdit(this);
statusLabel->setReadOnly(true);
@@ -49,14 +55,6 @@ DownloadRideDialog::DownloadRideDialog(MainWindow *mainWindow,
progressLabel->setIndent(10);
progressLabel->setTextFormat(Qt::PlainText);
deviceCombo = new QComboBox(this);
QList<QString> deviceTypes = Devices::typeNames();
assert(deviceTypes.size() > 0);
BOOST_FOREACH(QString device, deviceTypes) {
deviceCombo->addItem(device);
}
connect(deviceCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(deviceChanged(QString)));
downloadButton = new QPushButton(tr("&Download"), this);
eraseRideButton = new QPushButton(tr("&Erase Ride(s)"), this);
rescanButton = new QPushButton(tr("&Rescan"), this);
@@ -117,7 +115,7 @@ DownloadRideDialog::setReadyInstruct()
void
DownloadRideDialog::scanCommPorts()
{
portCombo->clear();
QString err;
devList = CommPort::listCommPorts(err);
if (err != "") {
@@ -126,19 +124,49 @@ DownloadRideDialog::scanCommPorts()
QMessageBox::warning(0, "Error Loading Device Drivers", msg,
QMessageBox::Ok, QMessageBox::NoButton);
}
updatePort();
}
void
DownloadRideDialog::updatePort()
{
portCombo->clear();
QList<QString> typeNames( Devices::typeNames() );
DevicesPtr selectedType = Devices::getType(deviceCombo->currentText());
for (int i = 0; i < devList.size(); ++i) {
portCombo->addItem(devList[i]->id());
// XXX Hack: SRM PCV download cables use the PL2203 chipset. If the
// first device name contains "PL2303", then, we're probably dealing
// with an SRM, so go ahead and select the SRM device. Generalize?
if ((i == 0) && devList[i]->name().contains("PL2303")) {
int j = deviceCombo->findText("SRM");
if (j >= 0)
deviceCombo->setCurrentIndex(j);
// suppress unsupported ports
if( ! selectedType->supportsPort( devList.at(i) ) )
continue;
// suppress ports exclusively supported by other devices
bool otherExclusive = false;
for( int t = 0; t < typeNames.size(); ++t ){
DevicesPtr otherType = Devices::getType(typeNames.at(t));
// hmm, comparing pointers makes me feel a bit dizzy...
if( selectedType == otherType )
continue;
if( otherType->exclusivePort( devList.at(i) ) ){
otherExclusive = true;
break;
}
}
if( otherExclusive )
continue;
// add port
portCombo->addItem( devList[i]->id());
// make an exclusive port the default selection:
if( selectedType->exclusivePort( devList.at(i) ) )
portCombo->setCurrentIndex(portCombo->findText(devList[i]->id()));
}
if (portCombo->count() > 0)
downloadButton->setFocus();
setReadyInstruct();
}
@@ -214,8 +242,8 @@ DownloadRideDialog::deviceChanged( QString deviceType )
{
(void)deviceType;
updateAction(action);
setReadyInstruct();
updateAction(action); // adjust erase button visibility
updatePort();
}
void

View File

@@ -70,6 +70,7 @@ class DownloadRideDialog : public QDialog
downloadAction action;
void updateAction( downloadAction action );
void updatePort();
};
#endif // _GC_DownloadRideDialog_h

View File

@@ -23,7 +23,6 @@
#include <boost/scoped_ptr.hpp>
#include <boost/foreach.hpp>
#include <errno.h>
#include <stdio.h>
#define tr(s) QObject::tr(s)
@@ -38,6 +37,36 @@ SrmDevices::newDevice( CommPortPtr dev )
return DevicePtr( new SrmDevice( dev, protoVersion));
}
bool
SrmDevices::supportsPort( CommPortPtr dev )
{
if( dev->type() == "Serial" )
return true;
return false;
}
bool
SrmDevices::exclusivePort( CommPortPtr dev )
{
switch( protoVersion ){
case 5:
// XXX: this has to go, once we have other devices using prolific
if( dev->type() == "Serial" && dev->name().contains( "PL2303" ) )
return true;
break;
case 6:
case 7:
if( dev->type() == "D2XX" && dev->name().startsWith( "POWERCONTROL" ) )
return true;
break;
}
return false;
}
static bool
get_tmpname(const QDir &tmpdir, QString &tmpname, QString &err)
{
@@ -423,6 +452,7 @@ SrmDevice::download( const QDir &tmpdir,
for( split = splitList; *split; ++split ){
FILE *fh( NULL );
srmio_time_t stime;
srmio_data_t fixed;
DeviceDownloadFile file;
file.extension = "srm";
@@ -430,7 +460,15 @@ SrmDevice::download( const QDir &tmpdir,
if (!get_tmpname(tmpdir, file.name, err))
goto fail;
if( ! srmio_data_time_start( *split, &stime ) ){
fixed = srmio_data_fixup( *split );
if( ! fixed ){
err = tr("Couldn't fixup data: %1")
.arg(strerror(errno));
goto fail;
}
if( ! srmio_data_time_start( fixed, &stime ) ){
srmio_data_free(fixed);
err = tr("Couldn't get start time of data: %1")
.arg(strerror(errno));
goto fail;
@@ -439,13 +477,15 @@ SrmDevice::download( const QDir &tmpdir,
fh = fopen( file.name.toAscii().constData(), "w" );
if( ! fh ){
srmio_data_free(fixed);
err = tr( "failed to open file %1: %2")
.arg(file.name)
.arg(strerror(errno));
goto fail;
}
if( ! srmio_file_srm7_write(*split, fh) ){
if( ! srmio_file_srm7_write(fixed, fh) ){
srmio_data_free(fixed);
err = tr("Couldn't write to file %1: %2")
.arg(file.name)
.arg(strerror(errno));
@@ -456,6 +496,7 @@ SrmDevice::download( const QDir &tmpdir,
files.append(file);
fclose( fh );
srmio_data_free(fixed);
}

View File

@@ -29,6 +29,8 @@ struct SrmDevices : public Devices
virtual DevicePtr newDevice( CommPortPtr dev );
virtual bool canCleanup( void ) {return true; };
virtual bool supportsPort( CommPortPtr dev );
virtual bool exclusivePort( CommPortPtr dev );
private:
int protoVersion;