void sJarvisNodeComponent::parseEvent(QString component, jarvisEvents event, QStringList args) { if(component != m_id) return; if (event == E_DISABLED) { emit disabled(); }else if(event == E_ENABLED) { emit enabled(); }else if(event == E_ACTIVATED) { emit activated(); }else if(event == E_DEACTIVATED) { emit deactivated(); }else if(event == E_RAW_READ) { emit rawRead(); emit rawRead(args); }else if(event == E_DATA_READ) { emit dataRead(); emit dataRead(args); }else if(event == E_COFFEE_MAKING) { emit coffeeMaking(); }else if(event == E_COFFEE_MADE) { emit coffeeMade(); } }
FenPrincipale::FenPrincipale(Serial* _com) : ui(new Ui::FenPrincipale), historique(new Donnees()){ connect(historique, SIGNAL(msg(QString)), this, SLOT(message(QString))); //------------------------------------------------------------------------------------------------------ com = _com; ui->setupUi(this); ui->tableWindow->setWindowTitle("Historique"); ui->infosWindow->setWindowTitle("Tableau de bord"); ui->consoleWindow->setWindowTitle("Console"); ui->table->setModel(historique->toFen()); historique->connect(); tableauBord = new BoardingTable((QGridLayout*)ui->container); if(QFile::exists(QApplication::applicationDirPath() + "/save.log")){ historique->open(); } timerAct = new QTimer(); connect(timerAct,SIGNAL(timeout()),this,SLOT(requestAct())); timerAct->start(5000); connect(com,SIGNAL(dataRead(QStringList)),this,SLOT(informationsReceived(QStringList))); requestAct(); }
void MediaDownload::startRequest(unsigned position, unsigned size) { Q_ASSERT(m_url.isValid()); if (m_task) { m_task->abortLater(); m_task->deleteLater(); } m_task = new MediaDownloadTask; m_task->moveToThread(m_thread); connect(m_task, SIGNAL(requestReady(uint)), SLOT(requestReady(uint)), Qt::DirectConnection); connect(m_task, SIGNAL(dataRead(QByteArray,uint)), SLOT(incomingData(QByteArray,uint)), Qt::DirectConnection); connect(m_task, SIGNAL(finished()), SLOT(taskFinished()), Qt::DirectConnection); connect(m_task, SIGNAL(error(QString)), SLOT(taskError(QString)), Qt::DirectConnection); /* If size will reach the end of what we believe the file size to be, make it infinite instead, * to ease behavior with still active files */ if (position + size >= m_fileSize) size = 0; bool ok = m_task->metaObject()->invokeMethod(m_task, "start", Q_ARG(QUrl, m_url), Q_ARG(QList<QNetworkCookie>, m_cookies), Q_ARG(unsigned, position), Q_ARG(unsigned, size)); Q_ASSERT(ok); Q_UNUSED(ok); }
int ComediChan::dioRead(bool *ok) const { double v = dataRead(ok); // see if the voltage is close enough to rangemax... if (v >= m_rangeMax-epsilon) return 1; return 0; }
void ProxyTunnel::doOpen() { if(m_server) { connect(m_server, SIGNAL(newData(QByteArray)), SIGNAL(dataRead(QByteArray))); this->SetState(st_connected); } }
void JSSupporter::readData(QNetworkReply * reply) { QByteArray result = reply->readAll(); qDebug() << "JSSupporter::readData " << reply->url().toString() << "error: " << reply->error() << " (" << reply->errorString() << "): " << result.length() << "bytes"; reply->deleteLater(); emit dataRead(QString(result)); }
VersionChecker::VersionChecker(QObject *parent) : QTcpSocket(parent), version(VERSION_STRING), internversion(VERSION_INTEGER), htmldata(false) { connect(this, SIGNAL(connected()), this, SLOT(socketOpened())); connect(this, SIGNAL(readyRead()), this, SLOT(dataRead())); }
void MediaDownloadTask::read() { QByteArray data = m_reply->readAll(); if (data.isEmpty()) return; emit dataRead(data, m_writePos); m_writePos += data.size(); /* Very carefully threadsafe: bcApp and the globalRate pointer are * const, and 'addSampleValue' is threadsafe and lockfree for the common case. */ bcApp->globalRate->addSampleValue(data.size()); }
bool Client::auth(const QString& login){ QTextStream ss(_socket); ss<<"[auth]"<<login; ss.flush(); bool b = _socket->waitForReadyRead(); if(b){ QString answer = ss.readAll(); qDebug()<<"server say: " << answer; _login = login; connect(_socket, SIGNAL(readyRead()), SLOT(dataRead())); } else { qDebug()<<"auth problem"; } return b; }
static void fillDataFromReadBuffer(SoupBuffer* readBuffer, size_t size, Data& data) { GRefPtr<SoupBuffer> buffer; if (size != readBuffer->length) { // The subbuffer does not copy the data. buffer = adoptGRef(soup_buffer_new_subbuffer(readBuffer, 0, size)); } else buffer = readBuffer; if (data.isNull()) { // First chunk, we need to force the data to be copied. data = { reinterpret_cast<const uint8_t*>(buffer->data), size }; } else { Data dataRead(WTF::move(buffer)); // Concatenate will copy the data. data = concatenate(data, dataRead); } }
void BulkReaderThread::run() { int readSize; m_handle = pthread_self(); m_threadRunning = true; char* inbuf = new char[MAX_DATA_IN_SIZE]; // // Use m_lock to control message flow btw bulkreader and main thread // 1. reader has lock // 2. read data // 3. inform main thread // 4. reader waits in lock until main has processed data and unlocked // 5. goto 2 // m_lock.lock(); // First we have the lock do { readSize = read(m_fd, inbuf, MAX_DATA_IN_SIZE); // Read Header while(readSize != -1) { emit dataRead(inbuf, readSize); if(!m_threadRunning) break; m_lock.lock(); if(!m_threadRunning) break; inbuf = new char[MAX_DATA_IN_SIZE]; readSize = read(m_fd, inbuf, MAX_DATA_IN_SIZE); // Read Header } } while(errno == ESHUTDOWN && m_threadRunning); //} while(errno == EINTR || errno == ESHUTDOWN); // TODO: Handle the exceptions above properly. m_handle = 0; // Known errors to exit here: // EAGAIN 11 Try Again ** Seems to be triggered from DISABLE/ENABLE // EINTR 4 Interrupt ** Triggered from SIGUSR1 if(errno != EINTR) { MTP_LOG_CRITICAL("BulkReaderThread exited: " << errno); } }
void AmpPlot::dataRead(double value, double time) { emit dataRead(value); double size; _data.append(value); _dataTime.append(time+_pauseTime); size = _data.size(); // lastMean = _mean; _mean = (1 - (1/size))*_mean + (1/size)*value; // _sd = ((size-1) * _sd + (value -_mean)*(value - lastMean))* (1 / size); if (_max < value) { _max = value; } _meanData.first() = _mean; _meanData.last() = _mean; _meanTime.last() = _dataTime.last(); _maxData.first() = _max; _maxData.last() = _max; _maxTime.last() = _dataTime.last(); _currentMeanData.append(_mean); _dataCurve->setRawSamples(_dataTime.data(), _data.data(), _data.size()); _meanCurve->setRawSamples(_meanTime.data(), _meanData.data(), _meanTime.size()); _maxCurve->setRawSamples(_maxTime.data(), _maxData.data(), _maxTime.size()); _currentMeanCurve->setRawSamples(_dataTime.data(), _currentMeanData.data(), _dataTime.size()); emit meanChanged(_mean); _plot->setAxisScale(QwtPlot::xBottom,_dataTime.last() - _xMax, _dataTime.last()); _plot->replot(); }
void SerialRXThread::run() { //qint64 currms = QDateTime::currentMSecsSinceEpoch(); QString byteoutofpacket; QByteArray qbuffer; unsigned char buffer[10240]; bool m_inpacket = false; bool m_inescape = false; int m_packetErrorCount=0; int readlen=0; while (!m_terminate) { readlen = m_serialPort->readBytes(buffer,1024); if (readlen < 0) { //Nothing on the port qDebug() << "Timeout"; //msleep(10); } else { //emit dataRead(QByteArray((const char*)buffer,readlen)); /*if (m_logsEnabled) { m_logInFile->write((const char*)buffer,readlen); m_logInFile->flush(); }*/ emit dataRead(QByteArray((const char*)buffer,readlen)); } if (readlen == 0) { //This should be an error //qDebug() << "Nothing to read"; //perror("Error:"); //printf("\n"); //return; //Disable this, now that we are using timeouts. //msleep(10); continue; } for (int i=0;i<readlen;i++) { if (buffer[i] == 0xAA) { if (m_inpacket) { //Start byte in the middle of a packet //Clear out the buffer and start fresh m_inescape = false; QByteArray bufToEmit; bufToEmit.append(0xAA); QByteArray nbuffer(qbuffer); nbuffer.replace(0xBB,QByteArray().append(0xBB).append(0x44)); nbuffer.replace(0xAA,QByteArray().append(0xBB).append(0x55)); nbuffer.replace(0xCC,QByteArray().append(0xBB).append(0x33)); bufToEmit.append(nbuffer); bufToEmit.append(0xCC); emit dataRead(bufToEmit); qbuffer.clear(); qDebug() << "Buffer error"; m_packetErrorCount++; } //qbuffer.append(buffer[i]); //qDebug() << "Start of packet"; //Start of packet m_inpacket = true; } else if (buffer[i] == 0xCC && m_inpacket) { //qDebug() << "End of packet. Size:" << qbuffer.size(); //End of packet m_inpacket = false; //qbuffer.append(buffer[i]); //m_logFile->flush(); //emit parseBuffer(qbuffer); //New Location of checksum unsigned char sum = 0; for (int i=0;i<qbuffer.size()-1;i++) { sum += qbuffer[i]; } QByteArray bufToEmit; bufToEmit.append(0xAA); QByteArray nbuffer(qbuffer); nbuffer.replace(0xBB,QByteArray().append(0xBB).append(0x44)); nbuffer.replace(0xAA,QByteArray().append(0xBB).append(0x55)); nbuffer.replace(0xCC,QByteArray().append(0xBB).append(0x33)); bufToEmit.append(nbuffer); bufToEmit.append(0xCC); emit dataRead(bufToEmit); /*if (m_logsEnabled) { m_logWriteMutex->lock(); m_logInOutFile->write(QByteArray().append(0xAA)); QByteArray nbuffer(qbuffer); nbuffer.replace(0xBB,QByteArray().append(0xBB).append(0x44)); nbuffer.replace(0xAA,QByteArray().append(0xBB).append(0x55)); nbuffer.replace(0xCC,QByteArray().append(0xBB).append(0x33)); m_logInOutFile->write((const char*)nbuffer.data(),nbuffer.size()); m_logInOutFile->write(QByteArray().append(0xCC)); m_logInOutFile->flush(); m_logWriteMutex->unlock(); }*/ //qDebug() << "Payload sum:" << QString::number(sum); //qDebug() << "Checksum sum:" << QString::number((unsigned char)currPacket[currPacket.length()-1]); if (sum != (unsigned char)qbuffer[qbuffer.size()-1]) { qDebug() << "BAD CHECKSUM!"; m_packetErrorCount++; //return QPair<QByteArray,QByteArray>(); } else { m_packetErrorCount=0; //m_queuedMessages.append(qbuffer.mid(0,qbuffer.length()-1)); emit incomingPacket(qbuffer.mid(0,qbuffer.length()-1)); } //return qbuffer; QString output; for (int i=0;i<qbuffer.size();i++) { int num = (unsigned char)qbuffer[i]; output.append(" ").append((num < 0xF) ? "0" : "").append(QString::number(num,16)); } //qDebug() << "Full packet:"; //qDebug() << output; qbuffer.clear(); } else { if (m_inpacket && !m_inescape) { if (buffer[i] == 0xBB) { //Need to escape the next byte //retval = logfile.read(1); m_inescape = true; } else { qbuffer.append(buffer[i]); } } else if (m_inpacket && m_inescape) { if (buffer[i] == 0x55) { qbuffer.append((char)0xAA); } else if (buffer[i] == 0x44) { qbuffer.append((char)0xBB); } else if (buffer[i] == 0x33) { qbuffer.append((char)0xCC); } else { qDebug() << "Error, escaped character is not valid!:" << QString::number(buffer[i],16); m_packetErrorCount++; } m_inescape = false; } else { //qDebug() << "Byte out of a packet:" << QString::number(buffer[i],16); byteoutofpacket += QString::number(buffer[i],16) + " "; } } } //qDebug() << "Bytes out of a packet:" << byteoutofpacket; } //m_buffer.append(qbuffer); if (readlen > 0) { //m_buffer.write(buffer,readlen); // m_buffer.append((const char*)buffer,readlen); } //return m_packetErrorCount; return; }
String FTPServer::run() { if (client.connected()) { String clientIP = String(remoteIp = client.remoteIP()); dbg("-------------------------------------------------------------", ""); dbg("FTPino", "Client connected: " + clientIP); #if - 1 != BUZZER_PIN Buzzer::beepTwice(); #endif digitalWrite(D7, HIGH); String clientResponse, parseInfo; isFTPinoClient = false; if (timeoutSec > 0) aliveTimer = millis() + timeoutSec * 1000; else aliveTimer = -1; while (client.connected()) { switch (state) { case TEftpState_Init: server->println("220 Welcome to FTPino FTP Server."); break; case TEftpState_User: server->println("331 Password required for user " + parseInfo + "."); break; case TEftpState_AuthOk: server->println("230 User successfuly logged in."); break; case TEftpState_AuthFail: client.stop(); break; case TEftpState_CurrentDir: server->println("257 \"/\" is current directory."); break; case TEftpState_System: server->println("215 UNIX emulated by FTPino."); break; case TEftpState_Features: server->println("211 Extensions supported SIZE MDTM XCRC."); break; case TEftpState_Type: server->println("200 Type set to BINARY."); break; case TEftpState_RestartAt: server->println("350 Restarting at " + parseInfo + ". !!! Not implemented"); break; case TEftpState_Store: writeFile(parseInfo, fh); break; case TEftpState_DeleteDir: if (fh->deleteTarget(parseInfo, true) < 0) server->println("550 Can't delete Directory."); else server->println("250 Directory " + parseInfo + " was deleted."); break; case TEftpState_DeleteFile: if (fh->deleteTarget(parseInfo, false) < 0) server->println("550 Can't delete File."); else server->println("250 File " + parseInfo + " was deleted."); break; case TEftpState_MakeDir: if (fh->makeDir(parseInfo) < 0) server->println("550 Can't create directory."); else server->println("257 Directory created : " + parseInfo + "."); break; case TEftpState_Append: writeFile(parseInfo, fh, true); break; case TEftpState_Client: if (parseInfo.startsWith("FTPino")) isFTPinoClient = true; break; case TEftpState_RenameFrom: fh->renameFrom(parseInfo); server->println("350 Directory exists, ready for destination name"); break; case TEftpState_RenameTo: fh->renameTo(parseInfo); server->println("250 Directory renamed successfully"); break; case TEftpState_List: dataWrite(fh->getDirList()); break; // implementing LIST verb as described at : // https://files.stairways.com/other/ftp-list-specs-info.txt case TEftpState_RetrieveFile: readFile(parseInfo); break; case TEftpState_Quit: server->println("221 Bye."); client.stop(); dclient.stop(); break; case TEftpState_ParentDir: fh->changeToParentDir(); server->println("250 Going one level up."); break; case TEftpState_Port: { transferMode = TEftpTransferMode_Active; dclient.connect(remoteIp, activeDataPortHi << 8 | activeDataPortLo); server->println("200 Port command successful."); break; } case TEftpState_Passive: { auto ip = WiFi.localIP(); char buffer[1024]; sprintf(buffer, "(%d,%d,%d,%d," + String(passiveDataPortHi) + "," + String(passiveDataPortLo) + ")", ip[0], ip[1], ip[2], ip[3]); server->println("227 Entering Passive Mode " + String(buffer)); waitForClientDataConnection(); transferMode = TEftpTransferMode_Passive; break; } case TEftpState_ChangeDir: { if (fh->changeDir(parseInfo) < 0) server->println("550 Can't change directory to " + parseInfo + "."); else server->println("250 \"/" + parseInfo + "\" is current directory."); break; } } if (client.connected()) { // if client not disconnected by the logic above do { delay(100); // allow the client to read response clientResponse = dataRead(); auto newState = parseCommand(clientResponse, parseInfo); if (newState != state) state = newState; if ((clientResponse.length() > 0) && (TEftpState_Unknown == state)) server->println("502 Command not implemented: " + parseInfo + "."); if ((-1 != aliveTimer) && (static_cast<int64_t>(millis()) - static_cast<int64_t>(aliveTimer)) > 0) server->println("530 Timeout, disconnecting control socket."), state = TEftpState_Quit; // timeout } while (TEftpState_Unknown == state); } } state = TEftpState_Init; dbg("FTPino", "Client disconnected: " + clientIP); fh->flush(); #if - 1 != BUZZER_PIN Buzzer::beepOnce(); #endif totalConnections++; } else { client = server->available(); digitalWrite(D7, LOW); state = TEftpState_Init; } return ""; }
bool Reader::readProperty(PropertyInfo& prop) { size_t num = prop.size * elementSize(prop.dims); size_t bytes = dataSizeInBytes(prop.type) * num; char* buffer = 0; // // Cache the offset pointer // prop.offset = tell(); bool readok = false; if (prop.requested) { if ((buffer = (char*)data(prop, bytes))) { read(buffer, bytes); if (!m_error) readok = true; } else { seekForward(bytes); } } else { seekForward(bytes); } if (m_error) return false; if (readok) { if (m_swapped) { switch (prop.type) { case Gto::Int: case Gto::String: case Gto::Float: swapWords(buffer, num); break; case Gto::Short: case Gto::Half: swapShorts(buffer, num); break; case Gto::Double: swapWords(buffer, num * 2); break; case Gto::Byte: case Gto::Boolean: break; } } dataRead(prop); } return true; }
void ProxyTunnel::doClose() { disconnect(m_server, SIGNAL(newData(QByteArray)), this, SIGNAL(dataRead(QByteArray))); this->SetState(st_disconnected); }
bool Reader::readProperty(PropertyInfo& prop) { size_t num = prop.size * prop.width; size_t bytes = num * dataSize(prop.type); char* buffer = 0; // // Cache the offset pointer // if( m_currentReadOffset == 0 ) { // Offset can never be zero here, so it must be // uninitialized. Set it to the real file position. m_currentReadOffset = tell(); } prop.offset = m_currentReadOffset; bool readok = false; if (prop.requested) { if ((buffer = (char*)data(prop, bytes))) { if(prop.index < m_dataOffsets.size()) { seekTo(prop); } else { // Do we need to be somewhere else? if(m_currentReadOffset != tell()) { // If so, move the actual file pointer there. seekForward(m_currentReadOffset - tell()); } } read(buffer, bytes); readok = true; } } // Move the 'virtual' file offset forward by the data // size of this property, whether we read it or not. m_currentReadOffset += bytes; if (m_error) return false; if (readok) { if (m_swapped) { switch (prop.type) { case Gto::Int: case Gto::String: case Gto::Float: swapWords(buffer, num); break; case Gto::Short: case Gto::Half: swapShorts(buffer, num); break; case Gto::Double: swapWords(buffer, num * 2); break; case Gto::Byte: case Gto::Boolean: break; } } dataRead(prop); } return true; }
gNodeComponentWidget::gNodeComponentWidget(sJarvisNodeComponent* comp,QWidget *parent) : QGroupBox(parent), m_component(comp), ui(new Ui::gNodeComponentWidget) { ui->setupUi(this); this->setTitle(m_component->getId()); QList<jarvisActions> actions = m_component->getActions(); for(int i = 0 ; i < actions.count() ; i++) { jarvisActions action = actions[i]; //qDebug() << QString::number(int(action)); QToolButton* b = new QToolButton(ui->actionsBox); QGridLayout* l = (QGridLayout*)ui->actionsBox->layout(); if (action == A_DIMM){ b->deleteLater(); QSlider* w = new QSlider(this); w->setMaximum(100); w->setValue(50); l->addWidget(w,l->count()/2,l->count()%2); connect(w,SIGNAL(valueChanged(int)),m_component,SLOT(dimm(int))); }else if(action == A_SET_COLOR){ connect(b,SIGNAL(clicked()),this,SLOT(selectComponentColor())); b->setText(m_component->actionName((m_component->getActions()[i]))); l->addWidget(b,l->count()/2,l->count()%2); }else if(action == A_SET_LEDS){ connect(b,SIGNAL(clicked()),this,SLOT(sendImage())); b->setText(m_component->actionName((m_component->getActions()[i]))); l->addWidget(b,l->count()/2,l->count()%2); }else if(action == A_DISPLAY){ connect(b,SIGNAL(clicked()),this,SLOT(sendImage())); b->setText(m_component->actionName((m_component->getActions()[i]))); l->addWidget(b,l->count()/2,l->count()%2); }else if(action == A_PLAYRTTTL){ connect(b,SIGNAL(clicked()),this,SLOT(openRtttlPlayer())); b->setText(m_component->actionName((m_component->getActions()[i]))); l->addWidget(b,l->count()/2,l->count()%2); }else{ QString slotName = m_component->slotName(m_component->getActions()[i]); b->setText(m_component->actionName((m_component->getActions()[i]))); l->addWidget(b,l->count()/2,l->count()%2); connect(b,SIGNAL(clicked()),m_component,slotName.toStdString().c_str()); } } QList<jarvisEvents> events = m_component->getCapableEvents(); for(int i = 0 ; i < events.count() ; i++) { gBlinkWidget* w = new gBlinkWidget(ui->eventsBox); QLabel* label = new QLabel(ui->eventsBox); QGridLayout* l = (QGridLayout*)ui->eventsBox->layout(); l->addWidget(label,i,0); l->addWidget(w,i,1); w->setMaximumHeight(50); if(events[i] == E_RAW_READ) { connect(m_component,SIGNAL(rawRead()),w,SLOT(blink())); connect(m_component,SIGNAL(rawRead(QStringList)),w,SLOT(displayRead(QStringList))); label->setText(m_component->eventName((m_component->getCapableEvents()[i]))); }else if(events[i] == E_DATA_READ) { connect(m_component,SIGNAL(dataRead()),w,SLOT(blink())); connect(m_component,SIGNAL(dataRead(QStringList)),w,SLOT(displayRead(QStringList))); label->setText(m_component->eventName((m_component->getCapableEvents()[i]))); }else { QString signalName = m_component->signalName(m_component->getCapableEvents()[i]); label->setText(m_component->eventName((m_component->getCapableEvents()[i]))); connect(m_component,signalName.toStdString().c_str(),w,SLOT(blink())); } //w->setMinimumSize(32,32); //w->setMaximumSize(32,32); } }