Added option to stop receiving the proto replies

Former-commit-id: b15c31b8aa500b8d7253d0c2b2368eab6a11ed50
This commit is contained in:
johan 2014-01-26 13:00:23 +01:00
parent df9b33f560
commit c96be1cf38
3 changed files with 27 additions and 13 deletions

View File

@ -8,7 +8,8 @@
#include "ProtoConnection.h" #include "ProtoConnection.h"
ProtoConnection::ProtoConnection(const std::string & a) : ProtoConnection::ProtoConnection(const std::string & a) :
_socket() _socket(),
_skipReply(false)
{ {
QString address(a.c_str()); QString address(a.c_str());
QStringList parts = address.split(":"); QStringList parts = address.split(":");
@ -38,6 +39,11 @@ ProtoConnection::~ProtoConnection()
_socket.close(); _socket.close();
} }
void ProtoConnection::setSkipReply(bool skip)
{
_skipReply = skip;
}
void ProtoConnection::setColor(const ColorRgb & color, int priority, int duration) void ProtoConnection::setColor(const ColorRgb & color, int priority, int duration)
{ {
proto::HyperionRequest request; proto::HyperionRequest request;
@ -119,13 +125,11 @@ proto::HyperionReply ProtoConnection::sendMessage(const proto::HyperionRequest &
throw std::runtime_error("Error while writing data to host"); throw std::runtime_error("Error while writing data to host");
} }
/*
// read reply data // read reply data
QByteArray serializedReply; QByteArray serializedReply;
length = -1; length = -1;
while (serializedReply.size() != length) while (length < 0 && serializedReply.size() < length+4)
{ {
std::cout << length << std::endl;
// receive reply // receive reply
if (!_socket.waitForReadyRead()) if (!_socket.waitForReadyRead())
{ {
@ -136,20 +140,22 @@ proto::HyperionReply ProtoConnection::sendMessage(const proto::HyperionRequest &
if (length < 0 && serializedReply.size() >= 4) if (length < 0 && serializedReply.size() >= 4)
{ {
std::cout << (int) serializedReply[3] << std::endl; // read the message size
std::cout << (int) serializedReply[2] << std::endl; length =
std::cout << (int) serializedReply[1] << std::endl; ((serializedReply[0]<<24) & 0xFF000000) |
std::cout << (int) serializedReply[0] << std::endl; ((serializedReply[1]<<16) & 0x00FF0000) |
((serializedReply[2]<< 8) & 0x0000FF00) |
length = (uint8_t(serializedReply[0]) << 24) | (uint8_t(serializedReply[1]) << 16) | (uint8_t(serializedReply[2]) << 8) | uint8_t(serializedReply[3]) ; ((serializedReply[3] ) & 0x000000FF);
} }
} }
std::cout << length << std::endl;
*/
// parse reply data // parse reply data
proto::HyperionReply reply; proto::HyperionReply reply;
// reply.ParseFromArray(serializedReply.constData()+4, length); reply.ParseFromArray(serializedReply.constData()+4, length);
// remove data from receive buffer
serializedReply = serializedReply.mid(length+4);
return reply; return reply;
} }

View File

@ -34,6 +34,9 @@ public:
/// ///
~ProtoConnection(); ~ProtoConnection();
/// Do not read reply messages from Hyperion if set to true
void setSkipReply(bool skip);
/// ///
/// Set all leds to the specified color /// Set all leds to the specified color
/// ///
@ -86,4 +89,7 @@ private:
private: private:
/// The TCP-Socket with the connection to the server /// The TCP-Socket with the connection to the server
QTcpSocket _socket; QTcpSocket _socket;
/// Skip receiving reply messages from Hyperion if set
bool _skipReply;
}; };

View File

@ -81,6 +81,7 @@ int main(int argc, char** argv)
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit"); SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]"); StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]");
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]"); IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]");
SwitchParameter<> & argSkipReply = parameters.add<SwitchParameter<>> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<>> ('h', "help", "Show this help message and exit"); SwitchParameter<> & argHelp = parameters.add<SwitchParameter<>> ('h', "help", "Show this help message and exit");
// set defaults // set defaults
@ -126,6 +127,7 @@ int main(int argc, char** argv)
else else
{ {
ProtoConnection connection(argAddress.getValue()); ProtoConnection connection(argAddress.getValue());
connection.setSkipReply(argSkipReply.isSet());
grabber.setCallback(&sendImage, &connection); grabber.setCallback(&sendImage, &connection);
grabber.capture(); grabber.capture();