mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-02 01:30:34 -06:00
Let TimelineView handle multiple instances of Labelparser and HongkangParsers
This commit is contained in:
@@ -37,6 +37,10 @@
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace {
|
||||
QByteArray continuousData;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T readFromBuffer(char* buffer, size_t& currentReadLocation) {
|
||||
union {
|
||||
@@ -128,16 +132,25 @@ void MainWindow::onDisconnect() {
|
||||
|
||||
void MainWindow::readTcpData() {
|
||||
static const uint16_t MessageTypeStatus = 0;
|
||||
static const uint16_t MessageTypePlayBookHongKang = 2;
|
||||
static const uint16_t MessageTypeMappingIdentifier = 1;
|
||||
static const uint16_t MessageTypeInitialMessageFinished = 2;
|
||||
static const uint16_t MessageTypePlayBookLabel = 3;
|
||||
static const uint16_t MessageTypeInitialMessageFinished = 4;
|
||||
static const uint16_t MessageTypePlayBookHongKang = 4;
|
||||
|
||||
QByteArray data = _socket->readAll();
|
||||
QByteArray data = continuousData.append(_socket->readAll());
|
||||
int d = data.size();
|
||||
|
||||
if (QString(data) == "Connected to SGCT!\r\n")
|
||||
if (data.size() != 42)
|
||||
qDebug() << QString(data);
|
||||
|
||||
if (QString(data) == "Connected to SGCT!\r\n") {
|
||||
continuousData.clear();
|
||||
return;
|
||||
if (QString(data) == "OK\r\n")
|
||||
}
|
||||
if (QString(data) == "OK\r\n") {
|
||||
continuousData.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray messageTypeData = data.left(2);
|
||||
union {
|
||||
@@ -149,6 +162,14 @@ void MainWindow::readTcpData() {
|
||||
switch (messageType.value) {
|
||||
case MessageTypeStatus:
|
||||
break;
|
||||
case MessageTypeMappingIdentifier:
|
||||
qDebug() << "Mapping Identifier received";
|
||||
printMapping(data.mid(2));
|
||||
continuousData.clear();
|
||||
break;
|
||||
case MessageTypeInitialMessageFinished:
|
||||
qDebug() << "InitialMessageFinished received";
|
||||
break;
|
||||
case MessageTypePlayBookHongKang:
|
||||
qDebug() << "Hong Kang Playbook received";
|
||||
break;
|
||||
@@ -164,6 +185,7 @@ void MainWindow::readTcpData() {
|
||||
{
|
||||
if (_isConnected)
|
||||
handleStatusMessage(data.mid(2));
|
||||
continuousData.clear();
|
||||
break;
|
||||
}
|
||||
case MessageTypePlayBookHongKang:
|
||||
@@ -177,13 +199,16 @@ void MainWindow::readTcpData() {
|
||||
//qDebug() << "Begin reading data";
|
||||
while (_socket->waitForReadyRead() && data.size() < int(size)) {
|
||||
//qDebug() << ".";
|
||||
//_socket->read
|
||||
//data = data.append(_socket->re)
|
||||
data = data.append(_socket->readAll());
|
||||
//data = data.append(_socket->read(int(size) - data.size()));
|
||||
QThread::msleep(50);
|
||||
//QThread::msleep(50);
|
||||
}
|
||||
//qDebug() << "Finished reading data. Handling playbook";
|
||||
|
||||
handlePlaybook(data.mid(2));
|
||||
continuousData = handlePlaybook(data.mid(2));
|
||||
|
||||
|
||||
//qDebug() << "Finished handling playbook";
|
||||
|
||||
@@ -201,6 +226,7 @@ void MainWindow::readTcpData() {
|
||||
case MessageTypeInitialMessageFinished:
|
||||
_isConnected = true;
|
||||
fullyConnected();
|
||||
continuousData.clear();
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -248,7 +274,7 @@ std::vector<std::string> instrumentsFromId(uint16_t instrumentId, std::map<uint1
|
||||
return results;
|
||||
}
|
||||
|
||||
void MainWindow::handlePlaybook(QByteArray data) {
|
||||
QByteArray MainWindow::handlePlaybook(QByteArray data) {
|
||||
char* buffer = data.data();
|
||||
size_t currentReadLocation = 0;
|
||||
|
||||
@@ -292,9 +318,15 @@ void MainWindow::handlePlaybook(QByteArray data) {
|
||||
qDebug() << "Instruments were empty";
|
||||
images.push_back(image);
|
||||
}
|
||||
|
||||
_timelineWidget->setData(std::move(images), std::move(targetMap), std::move(instrumentMap));
|
||||
|
||||
auto dataSize = data.size();
|
||||
auto readSize = currentReadLocation;
|
||||
auto extraBytes = dataSize - readSize;
|
||||
if (extraBytes > 0)
|
||||
return data.mid(currentReadLocation);
|
||||
else
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
void MainWindow::sendScript(QString script) {
|
||||
@@ -336,3 +368,17 @@ void MainWindow::fullyConnected() {
|
||||
_informationWidget->socketConnected();
|
||||
_timelineWidget->socketConnected();
|
||||
}
|
||||
|
||||
void MainWindow::printMapping(QByteArray data) {
|
||||
char* buffer = data.data();
|
||||
size_t currentReadPosition = 0;
|
||||
|
||||
uint16_t size = readFromBuffer<uint16_t>(buffer, currentReadPosition);
|
||||
for (uint16_t i = 0; i < size; ++i) {
|
||||
uint16_t identifier = readFromBuffer<uint16_t>(buffer, currentReadPosition);
|
||||
std::string mapping = readFromBuffer<std::string>(buffer, currentReadPosition);
|
||||
|
||||
qDebug() << identifier << ": " << QString::fromStdString(mapping);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,8 @@ private slots:
|
||||
|
||||
void readTcpData();
|
||||
void handleStatusMessage(QByteArray data);
|
||||
void handlePlaybook(QByteArray data);
|
||||
QByteArray handlePlaybook(QByteArray data);
|
||||
void printMapping(QByteArray data);
|
||||
|
||||
void fullyConnected();
|
||||
|
||||
|
||||
@@ -74,6 +74,8 @@ bool NetworkEngine::handleMessage(const std::string& message) {
|
||||
}
|
||||
case MessageTypeExternalControlConnected:
|
||||
{
|
||||
publishIdentifierMappingMessage();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||
sendInitialInformation();
|
||||
return true;
|
||||
}
|
||||
@@ -118,7 +120,7 @@ void NetworkEngine::publishStatusMessage() {
|
||||
}
|
||||
|
||||
void NetworkEngine::publishIdentifierMappingMessage() {
|
||||
size_t bufferSize = 0;
|
||||
size_t bufferSize = sizeof(uint16_t);
|
||||
for (const std::pair<std::string, MessageIdentifier>& i : _identifiers) {
|
||||
bufferSize += sizeof(MessageIdentifier);
|
||||
bufferSize += i.first.size() + 1; // +1 for \0 terminating character
|
||||
@@ -126,13 +128,17 @@ void NetworkEngine::publishIdentifierMappingMessage() {
|
||||
|
||||
std::vector<char> buffer(bufferSize);
|
||||
size_t currentWritingPosition = 0;
|
||||
uint16_t size = _identifiers.size();
|
||||
std::memcpy(buffer.data(), &size, sizeof(uint16_t));
|
||||
currentWritingPosition += sizeof(uint16_t);
|
||||
for (const std::pair<std::string, MessageIdentifier>& i : _identifiers) {
|
||||
std::memcpy(buffer.data() + currentWritingPosition, &(i.second), sizeof(MessageIdentifier));
|
||||
currentWritingPosition += sizeof(MessageIdentifier);
|
||||
std::memcpy(buffer.data() + currentWritingPosition, i.first.data(), i.first.size());
|
||||
uint8_t stringSize = i.first.size();
|
||||
std::memcpy(buffer.data() + currentWritingPosition, &stringSize, sizeof(uint8_t));
|
||||
currentWritingPosition += sizeof(uint8_t);
|
||||
std::memcpy(buffer.data() + currentWritingPosition, i.first.data(), stringSize);
|
||||
currentWritingPosition += i.first.size();
|
||||
buffer[currentWritingPosition] = '\0';
|
||||
currentWritingPosition += 1;
|
||||
}
|
||||
|
||||
publishMessage(_identifierMappingIdentifier, std::move(buffer));
|
||||
@@ -178,13 +184,14 @@ void NetworkEngine::sendMessages() {
|
||||
m.body.data(),
|
||||
static_cast<int>(m.body.size())
|
||||
);
|
||||
//LINFO("Sent message: (s=" << m.body.size() << "): " << std::string(m.body.begin(), m.body.end()));
|
||||
}
|
||||
|
||||
_messagesToSend.clear();
|
||||
}
|
||||
|
||||
void NetworkEngine::sendInitialInformation() {
|
||||
static const int SleepTime = 100;
|
||||
static const int SleepTime = 250;
|
||||
_shouldPublishStatusMessage = false;
|
||||
for (const Message& m : _initialConnectionMessages) {
|
||||
union {
|
||||
@@ -199,11 +206,12 @@ void NetworkEngine::sendInitialInformation() {
|
||||
payload.data(),
|
||||
static_cast<int>(payload.size())
|
||||
);
|
||||
LINFO("Sent initial message: (s=" << m.body.size() << ") [i=" << identifier.value << "]");
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SleepTime));
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SleepTime));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(4 * SleepTime));
|
||||
|
||||
// Send finished message
|
||||
union {
|
||||
|
||||
Reference in New Issue
Block a user