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 4 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,
Copy link
Member

Choose a reason for hiding this comment

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

There are spaces missing ;)

MESSAGE_SSL_INDEX_2021=6
};

#endif // MESSAGE_TYPE_H
82 changes: 57 additions & 25 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,29 +118,54 @@ 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 if (packet->type == MESSAGE_SSL_VISION_TRACKER_2020)
{
m_vision->writeData(packet->data);
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. Those packages should go to a different port. See https://ssl.robocup.org/league-software/#standard-network-parameters

Copy link
Author

Choose a reason for hiding this comment

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

thank you! It was my lack of study ...

} else {
}
else if (packet->type == MESSAGE_SSL_INDEX_2021)
{
m_index->writeData(packet->data);
Copy link
Member

Choose a reason for hiding this comment

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

This is not useful. The index should not be send to the network. It is only useful for reading the file.

}

else
{
std::cout << "Error 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.

Could you also improve this message?

  • It should print the unknown message type.
  • It would be good if this is only printed once per type.
  • I'd call it a warning, not an error.

}
}
Expand All @@ -147,12 +177,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
1 change: 1 addition & 0 deletions src/logplayer/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ 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;
};
Expand Down