Example #1
0
void MainWindow::deviceBrokenPipeSlot(){
	errorState.type = ErrorState::Err_BrokenPipe;
	errorState.startTime = QDateTime::currentDateTimeUtc();

	if(device != NULL){
		qDebug() << "ERROR: Broken pipe, disconnecting" ;

		delete device;
		device = NULL;
	}

	if(ui->portOpenButton->isChecked()){
		//Connect still pressed, we should attempt to reconnect to device

		//Does file still exist
		QFileInfo deviceFile(ui->portCombo->currentText());

		if(deviceFile.exists()){
			if(deviceFile.created().toMSecsSinceEpoch() == errorState.originCreateTime.toMSecsSinceEpoch()){

				qDebug() << "INFO: sleep 2000";
				QTimer::singleShot(2000, this, SLOT(deviceBrokenPipeReconnectSlot()));
				return;
			}
		}
	}

	qDebug() << "INFO: sleep 200";
	QTimer::singleShot(200, this, SLOT(deviceBrokenPipeReconnectSlot()));
}
Example #2
0
bool writeImage(QString devicePath, QString deviceImage, QObject *caller)
{
    utils::writeLog("Writing " + deviceImage + " to " + devicePath);
    WriteImageWorker* worker = NULL;
    if(caller) {
        if(! (worker = qobject_cast<WriteImageWorker*>(caller)) ) {
            worker = NULL;
        }
    }
    QFile imageFile(deviceImage);
    QFile deviceFile(devicePath);
    bool imageOpen = imageFile.open(QIODevice::ReadOnly);
    bool deviceOpen = deviceFile.open(QIODevice::WriteOnly);
    if(!imageOpen) {
        utils::writeLog("Error opening image");
        return false;
    }
    if(!deviceOpen) {
        utils::writeLog("Error opening device");
        return false;
    }
    char buf[512*1024];
    QDataStream in(&imageFile);
    QDataStream out(&deviceFile);
    unsigned total = 0;
    int r = in.readRawData(buf,sizeof(buf));
    int ret;
    while(r>0) {
        ret = out.writeRawData(buf, r);
        if(ret == -1 || ret != r) {
            imageFile.close();
            deviceFile.close();
            utils::writeLog("Error writing to device");
            return false;
        }
        total += r;
        if(worker){
            worker->emitProgressUpdate(total);
        }
        r = in.readRawData(buf,sizeof(buf));
    }
    if(worker){
        worker->emitFlushingFS();
    }
    imageFile.close();
    if(!deviceFile.flush()) {
        return false;
    }
    deviceFile.close();

    updateKernelTable();
    return true;
}
Example #3
0
OsStatus MpodOss::canEnable()
{
    OsStatus status = OS_FAILED;

    OsFile deviceFile(getDeviceName());
    if(deviceFile.exists())
    {
        status = deviceFile.open();
        deviceFile.close();
    }
    else
    {
        status = OS_NOT_FOUND;
    }

    return(status);
}
Example #4
0
bool AnalogyAnalogIOSoftCal::readCalibration()
{
        Logger(Debug, "AnalogyAnalogIOSoftCal::readCalibration()\n");
        m_calibrationFile = comedi_get_default_calibration_path(m_device);
        if (m_calibrationFile == NULL) {
                Logger(Critical, "Unable to find a calibration file for [%s].\n", deviceFile());
                return false;
        }
        else {
                Logger(Debug, "Using calibration file [%s].\n", m_calibrationFile);
        }

        m_calibration = comedi_parse_calibration_file(m_calibrationFile);
        if (m_calibration == NULL) {
                Logger(Critical, "Unable to parse calibration file [%s].\n", m_calibrationFile);
                return false;
        }
        else {
                Logger(Debug, "Successfully parsed calibration file [%s].\n", m_calibrationFile);
        }
        return true;
}