示例#1
0
void WorkspaceSerializer::Read(const QString& fileName, SignalData& data, PlotInfo& plotInfo)
{
	DataMap newData;
	::Read(fileName, data, plotInfo, [&](Signal&& signal){
		auto signalName = signal.name;
		newData.emplace(std::move(signalName), std::move(signal));
	}, [&]{
		data.add(std::move(newData));
	});
}
示例#2
0
DataToReplay PrepareReplay(const QString& file, SignalData& signalData)
{
	SignalData data; PlotInfo info;
	WorkspaceSerializer::Read(file, data, info);

	DataMap toSet;
	vector < pair<QString, QVector<qreal>>> toSend;
	data.onSignals([&](const Signal& signal){
		toSet.emplace(signal.name, Signal{ signal.name, {}, signal.graphic });
		toSend.emplace_back(make_pair(signal.name, std::move(signal.y)));
	});

	for (auto& signal : toSet)
	{
		signalData.addIfNotExists(std::move(signal.second));
	}
	signalData.setAsDomain(data.getDomain()->name);
	return toSend;
}
示例#3
0
void RTSocketPlayer::Start()
{
	clientConnection = server.nextPendingConnection();

	// blocking - temporary
	if (clientConnection->waitForReadyRead())
	{
		auto block = clientConnection->readAll();
		auto str = block.toStdString();
		stringstream ss(str, ios::binary | ios::in);
		
		string domainName;
		DataMap data;
		names.clear();

		// number of signals
		int numberOfSignals;
		ss.read((char*) &numberOfSignals, sizeof(int));
		
		// names
		int currSignNameSize;
		for (auto i = 0; i < numberOfSignals; ++i)
		{
			ss.read((char*) &currSignNameSize, sizeof(int));
			vector<char> currName(currSignNameSize);
			ss.read((char*) currName.data(), currName.size());
			if (i == 0)
				domainName.assign(currName.begin(), currName.end());
			QString currNameAsQString(string(currName.begin(), currName.end()).c_str());
			data.emplace(currNameAsQString, Signal{currNameAsQString});
			names.push_back(currNameAsQString);
		}
		for (auto& signal : data)
		{
			m_data.addIfNotExists(std::move(signal.second));
		}
		m_data.setAsDomain(domainName.c_str());
	}
	else
	{
		QMessageBox::critical(nullptr, tr("Anvedi Server"),
			tr("Unable to receive data from client")
		);
		clientConnection->disconnectFromServer();
		return;
	}


	connect(clientConnection, &QLocalSocket::readyRead, [this]{
		auto block = clientConnection->readAll();
		auto str = block.toStdString();
		stringstream ss(str, ios::binary | ios::in);
		unsigned int samplesCount;
		ss.read((char*) &samplesCount, sizeof(unsigned int));
		
		vector<pair<QString, QVector<qreal>>> slice;

		for (auto i = 0; i < names.size(); ++i)
		{
			QVector<qreal> samples(samplesCount);
			for (auto j = 0; j < samplesCount; ++j)
			{
				ss.read((char*) &samples[j], sizeof(qreal));
			}

			slice.emplace_back(names[i], std::move(samples));
		}
		
		sender.SetDataToSend(std::move(slice));
		sender.SendData();
	});
}