Esempio n. 1
0
void TcpClient::readClient() {
    while(_socket->canReadLine()) {
        QByteArray lineBA = _socket->readLine();

        QString line = QString(lineBA).trimmed();
        DEBUG << "Client says: " << line;
        // Split the command in strings
        QStringList subLine = line.split(" ", QString::SkipEmptyParts);
        QString command = subLine.value(0);
        if(command == "disconnect") {
            DEBUG << "killing this client connection";
            deleteLater();
        } else if(command == "sub") { // Subscribe command
            if(subLine.length() >= 2) {
                QString refName = subLine[1].trimmed();

                double accuracy = 0;
                if(subLine.length() >=3)
                    accuracy = subLine[2].toDouble();

                DataRef *ref = getSubscribedRef(refName);
                if(!ref) { // Ref not subscribed yet, try to subscribe
                    ref = _refProvider->subscribeRef(refName);
                    if(ref) { // Succesfully subscribed
                        connect(ref, SIGNAL(changed(DataRef*)), this, SLOT(refChanged(DataRef*)));
                        _subscribedRefs.insert(ref);
                        ref->setAccuracy(accuracy);
                        //TODO: why is ref->updateValue() not sufficient here?
                        if(ref->type() == xplmType_Float) {
                            _refValueF[ref] = qobject_cast<FloatDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_Int) {
                            _refValueI[ref] = qobject_cast<IntDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_Double) {
                            _refValueD[ref] = qobject_cast<DoubleDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_FloatArray) {
                            _refValueFA[ref] = qobject_cast<FloatArrayDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_IntArray) {
                            _refValueIA[ref] = qobject_cast<IntArrayDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_Data) {
                            _refValueB[ref] = qobject_cast<DataDataRef*>(ref)->value();
                        }
                        INFO << "Subscribed to " << ref->name() << ", accuracy " << accuracy << ", type " << ref->typeString();
                    } else {
                        INFO << "Ref not found" << refName;
                    }
                } else { // Ref already subscribed - update accuracy
Esempio n. 2
0
void TcpClient::readClient() {
    while(_socket->canReadLine()) {
        QByteArray lineBA = _socket->readLine();

        QString line = QString(lineBA);
        qDebug() << Q_FUNC_INFO << "Client says: " << line;
        QStringList subLine = line.split(" ", QString::SkipEmptyParts);
        QString command = subLine.value(0);
        if(command == "disconnect") {
            deleteLater();
        } else if(command == "sub") {
            if(subLine.length() >= 2) {
                QString refName = subLine[1].trimmed();

                double accuracy = 0;
                if(subLine.length() >=3)
                    accuracy = subLine[2].toDouble();

                DataRef *ref = getSubscribedRef(refName);
                if(!ref) {
                    ref = _refProvider->subscribeRef(refName);
                    if(ref) {
                        connect(ref, SIGNAL(changed(DataRef*)), this, SLOT(refChanged(DataRef*)));
                        _subscribedRefs.insert(ref);
                        _refAccuracy[ref] = accuracy;
                        if(ref->type() == xplmType_Float) {
                            _refValueF[ref] = qobject_cast<FloatDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_Int) {
                            _refValueI[ref] = qobject_cast<IntDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_Double) {
                            _refValueD[ref] = qobject_cast<DoubleDataRef*>(ref)->value();
                        }
                        qDebug() << Q_FUNC_INFO << "Subscribed to " << ref->name() << ", accuracy " << accuracy;
                    } else {
                        qDebug() << Q_FUNC_INFO << "Ref not found" << refName;
                    }
                } else {