void Package::fromDirectory(const std::string &dir) { LOG(INFO) << "Reading package from directory \"" << dir << "\"."; setConfigVar(Directory, dir); activateFlag(HasDirectory); QFile specsFile(QString::fromStdString(dir + "/PackageSpecs.yml")); specsFile.open(QFile::ReadOnly); if(specsFile.isReadable()) { loadSpecs(specsFile.readAll().toStdString()); } else { LOG(WARNING) << "The package in the directory \"" << dir << "\" has no \"PackageSpecs.yml\" file!"; m_isValid = false; } }
void RealTimePlot::run() { QMutexLocker guard(_dataMutex); guard.unlock(); qint64 startTime = QDateTime::currentMSecsSinceEpoch(); loadSpecs(startTime); while (!_abortFlag) { std::vector<double> sampleLine; guard.relock(); if (_stopRequested) { for (auto iter = _sources.begin(); iter != _sources.end();) { RealTimePlotInfo *rtplot = *iter; rtplot->spec->disconnect(); for (unsigned i = 0; i < rtplot->source->curveCount(); ++i) { if (PlotInstance *plot = rtplot->source->curve(i)) { _curves->completeLoading(plot); } } iter = _sources.erase(iter); delete rtplot; } _sources.clear(); _stopRequested = false; } for (auto iter = _sources.begin(); iter != _sources.end();) { RealTimePlotInfo *rtplot = *iter; if (rtplot->spec->connection()->isConnected()) { // Try get new samples. rtplot->spec->connection()->read(rtplot->readBuffer); RTMessage *msg = rtplot->spec->incomingMessage(); int bytesRead = 0; while ((bytesRead = msg->readMessage(rtplot->readBuffer)) > 0) { // Trim the buffer of the processed data rtplot->readBuffer = rtplot->readBuffer.right(rtplot->readBuffer.size() - bytesRead); unsigned sampleCount = msg->populateValues(sampleLine); // Do we need to create plots based on the first data sample? if (rtplot->source->curveCount() == 0) { // Create plots. if (!msg->headings().empty()) { createPlots(*rtplot, msg->headings()); } else { createPlots(*rtplot, sampleCount); } } double time = 1e-3 * (QDateTime::currentMSecsSinceEpoch() - startTime); unsigned limit = std::min<unsigned>(rtplot->source->curveCount(), sampleCount); for (unsigned i = 0; i < limit; ++i) { if (PlotInstance *plot = rtplot->source->curve(i)) { plot->addPoint(QPointF(time, sampleLine[i])); } } } // Clear the buffer on error, or if too large without reading any data. if (bytesRead < 0 || rtplot->readBuffer.size() >= MAX_READ_BUFFER_SIZE) { rtplot->readBuffer.clear(); } ++iter; } else { // Disconnected. Remove. rtplot->spec->disconnect(); for (unsigned i = 0; i < rtplot->source->curveCount(); ++i) { if (PlotInstance *plot = rtplot->source->curve(i)) { _curves->completeLoading(plot); } } iter = _sources.erase(iter); delete rtplot; } } guard.unlock(); } }