-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: master
Are you sure you want to change the base?
Changes from all commits
eed9c37
4d9c037
86c684d
1503c7f
121a648
7564365
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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; | ||
} | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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) | ||
{ | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
} | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,8 +51,10 @@ class Player : public QThread | |
Network* m_referee; | ||
Network* m_vision; | ||
Network* m_legacyVision; | ||
Network* m_index; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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.