From c96be1cf388173358e42dac073fe9ad3b784500d Mon Sep 17 00:00:00 2001 From: johan Date: Sun, 26 Jan 2014 13:00:23 +0100 Subject: [PATCH] Added option to stop receiving the proto replies Former-commit-id: b15c31b8aa500b8d7253d0c2b2368eab6a11ed50 --- src/hyperion-v4l2/ProtoConnection.cpp | 32 ++++++++++++++++----------- src/hyperion-v4l2/ProtoConnection.h | 6 +++++ src/hyperion-v4l2/hyperion-v4l2.cpp | 2 ++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/hyperion-v4l2/ProtoConnection.cpp b/src/hyperion-v4l2/ProtoConnection.cpp index 07544a8e..e78b2285 100644 --- a/src/hyperion-v4l2/ProtoConnection.cpp +++ b/src/hyperion-v4l2/ProtoConnection.cpp @@ -8,7 +8,8 @@ #include "ProtoConnection.h" ProtoConnection::ProtoConnection(const std::string & a) : - _socket() + _socket(), + _skipReply(false) { QString address(a.c_str()); QStringList parts = address.split(":"); @@ -38,6 +39,11 @@ ProtoConnection::~ProtoConnection() _socket.close(); } +void ProtoConnection::setSkipReply(bool skip) +{ + _skipReply = skip; +} + void ProtoConnection::setColor(const ColorRgb & color, int priority, int duration) { proto::HyperionRequest request; @@ -119,13 +125,11 @@ proto::HyperionReply ProtoConnection::sendMessage(const proto::HyperionRequest & throw std::runtime_error("Error while writing data to host"); } - /* // read reply data QByteArray serializedReply; length = -1; - while (serializedReply.size() != length) + while (length < 0 && serializedReply.size() < length+4) { - std::cout << length << std::endl; // receive reply if (!_socket.waitForReadyRead()) { @@ -136,20 +140,22 @@ proto::HyperionReply ProtoConnection::sendMessage(const proto::HyperionRequest & if (length < 0 && serializedReply.size() >= 4) { - std::cout << (int) serializedReply[3] << std::endl; - std::cout << (int) serializedReply[2] << std::endl; - std::cout << (int) serializedReply[1] << std::endl; - std::cout << (int) serializedReply[0] << std::endl; - - length = (uint8_t(serializedReply[0]) << 24) | (uint8_t(serializedReply[1]) << 16) | (uint8_t(serializedReply[2]) << 8) | uint8_t(serializedReply[3]) ; + // read the message size + length = + ((serializedReply[0]<<24) & 0xFF000000) | + ((serializedReply[1]<<16) & 0x00FF0000) | + ((serializedReply[2]<< 8) & 0x0000FF00) | + ((serializedReply[3] ) & 0x000000FF); } } - std::cout << length << std::endl; -*/ // parse reply data 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; } diff --git a/src/hyperion-v4l2/ProtoConnection.h b/src/hyperion-v4l2/ProtoConnection.h index b20faf34..f8a9387e 100644 --- a/src/hyperion-v4l2/ProtoConnection.h +++ b/src/hyperion-v4l2/ProtoConnection.h @@ -34,6 +34,9 @@ public: /// ~ProtoConnection(); + /// Do not read reply messages from Hyperion if set to true + void setSkipReply(bool skip); + /// /// Set all leds to the specified color /// @@ -86,4 +89,7 @@ private: private: /// The TCP-Socket with the connection to the server QTcpSocket _socket; + + /// Skip receiving reply messages from Hyperion if set + bool _skipReply; }; diff --git a/src/hyperion-v4l2/hyperion-v4l2.cpp b/src/hyperion-v4l2/hyperion-v4l2.cpp index 454832be..0df6ca95 100644 --- a/src/hyperion-v4l2/hyperion-v4l2.cpp +++ b/src/hyperion-v4l2/hyperion-v4l2.cpp @@ -81,6 +81,7 @@ int main(int argc, char** argv) SwitchParameter<> & argScreenshot = parameters.add> (0x0, "screenshot", "Take a single screenshot, save it to file and quit"); StringParameter & argAddress = parameters.add ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]"); IntParameter & argPriority = parameters.add ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]"); + SwitchParameter<> & argSkipReply = parameters.add> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion"); SwitchParameter<> & argHelp = parameters.add> ('h', "help", "Show this help message and exit"); // set defaults @@ -126,6 +127,7 @@ int main(int argc, char** argv) else { ProtoConnection connection(argAddress.getValue()); + connection.setSkipReply(argSkipReply.isSet()); grabber.setCallback(&sendImage, &connection); grabber.capture();