Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support new message types #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/common/format/message_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ enum MessageType
MESSAGE_UNKNOWN = 1,
MESSAGE_SSL_VISION_2010 = 2,
MESSAGE_SSL_REFBOX_2013 = 3,
MESSAGE_SSL_VISION_2014 = 4
MESSAGE_SSL_VISION_2014 = 4,
MESSAGE_SSL_VISION_TRACKER_2020 = 5,
MESSAGE_SSL_INDEX_2021 = 6
};

#endif // MESSAGE_TYPE_H
89 changes: 63 additions & 26 deletions src/logplayer/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
#include <iostream>
#include <QFileInfo>

Player::Player() :
m_referee(NULL),
m_vision(NULL),
m_legacyVision(NULL)
Player::Player() : m_referee(NULL),
m_vision(NULL),
m_legacyVision(NULL)
{
// create referee socket
Q_ASSERT(m_referee == NULL);
Expand Down Expand Up @@ -54,28 +53,33 @@ Player::~Player()
packets.clear();
}

bool Player::load(const QString& filename, int& maxFrame, double& duration) {
bool Player::load(const QString &filename, int &maxFrame, double &duration)
{
QFileInfo fileInfo(filename);

bool compressed = false;

if (fileInfo.suffix() == "gz") {
if (fileInfo.suffix() == "gz")
{
compressed = true;
}

LogFile file(filename, compressed);

if (!file.openRead()) {
if (!file.openRead())
{
return false;
}

qDeleteAll(packets);
packets.clear();

for (;;) {
Frame* packet = new Frame;
for (;;)
{
Frame *packet = new Frame;

if (!file.readMessage(packet->data, packet->time, packet->type)) {
if (!file.readMessage(packet->data, packet->time, packet->type))
{
delete packet;
break;
}
Expand All @@ -89,8 +93,9 @@ bool Player::load(const QString& filename, int& maxFrame, double& duration) {
}

bool Player::start(int position)
{
if (position > packets.size() - 1) {
{
if (position > packets.size() - 1)
{
return false;
}

Expand All @@ -113,30 +118,60 @@ bool Player::good()
return packets.size() > 0;
}

void Player::sendMessage(const Frame* packet)
void Player::sendMessage(const Frame *packet)
{
RoboCup2014Legacy::Wrapper::SSL_WrapperPacket legacyVisionPacket;
SSL_Referee refereePacket;

if (packet->type == MESSAGE_BLANK) {
if (packet->type == MESSAGE_BLANK)
{
// ignore
} else if (packet->type == MESSAGE_UNKNOWN) {
}
else if (packet->type == MESSAGE_UNKNOWN)
{
// OK, let's try to figure this out by parsing the message
if (refereePacket.ParseFromArray(packet->data.data(), packet->data.size())) {
if (refereePacket.ParseFromArray(packet->data.data(), packet->data.size()))
{
m_referee->writeData(packet->data);
} else if (legacyVisionPacket.ParseFromArray(packet->data.data(), packet->data.size())) {
}
else if (legacyVisionPacket.ParseFromArray(packet->data.data(), packet->data.size()))
{
m_legacyVision->writeData(packet->data);
} else {
}
else
{
std::cout << "Error unsupported or corrupt packet found in log file!" << std::endl;
}
} else if (packet->type == MESSAGE_SSL_VISION_2010) {
}
else if (packet->type == MESSAGE_SSL_VISION_2010)
{
m_legacyVision->writeData(packet->data);
} else if (packet->type == MESSAGE_SSL_REFBOX_2013) {
}
else if (packet->type == MESSAGE_SSL_REFBOX_2013)
{
m_referee->writeData(packet->data);
} else if (packet->type == MESSAGE_SSL_VISION_2014) {
}
else if (packet->type == MESSAGE_SSL_VISION_2014)
{
m_vision->writeData(packet->data);
} else {
std::cout << "Error unsupported message type found in log file!" << std::endl;
}
else if (packet->type == MESSAGE_SSL_VISION_TRACKER_2020)
{
if (receive_VT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be replaced with sth like m_visionTracker->writeData(packet->data), I'd say.

{
std::cout << "MESSAGE_SSL_VISION_TRACKER_2020 Received" << std::endl;
receive_VT=false;
}
}
else if (packet->type == MESSAGE_SSL_INDEX_2021)
{
std::cout << "MESSAGE_SSL_INDEX_2021 Received" << std::endl;
}

else
{
std::cout << packet->type <<std::endl;
std::cout << "Warning unsupported message type found in log file!" << std::endl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better move those two lines into one. Like "... in the log file: " << packet->type <<stdl::endl.

And it would nicer to print it on stderr (std::cerr).

}
}

Expand All @@ -147,12 +182,14 @@ void Player::run()
const qint64 startTime = Timer::systemTime();
const qint64 referenceTime = packets.at(m_currentFrame)->time;

while (m_mayRun && ++m_currentFrame < packets.size() && this->isRunning()) {
Frame* packet = packets.at(m_currentFrame);
while (m_mayRun && ++m_currentFrame < packets.size() && this->isRunning())
{
Frame *packet = packets.at(m_currentFrame);

qint64 sleepTime = ((packet->time - referenceTime) - (Timer::systemTime() - startTime)) / 1000;

if (sleepTime > 0) {
if (sleepTime > 0)
{
QThread::currentThread()->usleep(sleepTime);
}

Expand Down
2 changes: 2 additions & 0 deletions src/logplayer/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ class Player : public QThread
Network* m_referee;
Network* m_vision;
Network* m_legacyVision;
Network* m_index;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index is not sent via network. Have you mixed things up? Shouldn't there be a Network instance for visionTracker? 🤔

bool m_mayRun;
int m_currentFrame;
bool receive_VT=true;
};

#endif // PLAYER_H