Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit b15c31b

Browse files
committed
Added option to stop receiving the proto replies
1 parent 1eb1806 commit b15c31b

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/hyperion-v4l2/ProtoConnection.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include "ProtoConnection.h"
99

1010
ProtoConnection::ProtoConnection(const std::string & a) :
11-
_socket()
11+
_socket(),
12+
_skipReply(false)
1213
{
1314
QString address(a.c_str());
1415
QStringList parts = address.split(":");
@@ -38,6 +39,11 @@ ProtoConnection::~ProtoConnection()
3839
_socket.close();
3940
}
4041

42+
void ProtoConnection::setSkipReply(bool skip)
43+
{
44+
_skipReply = skip;
45+
}
46+
4147
void ProtoConnection::setColor(const ColorRgb & color, int priority, int duration)
4248
{
4349
proto::HyperionRequest request;
@@ -119,13 +125,11 @@ proto::HyperionReply ProtoConnection::sendMessage(const proto::HyperionRequest &
119125
throw std::runtime_error("Error while writing data to host");
120126
}
121127

122-
/*
123128
// read reply data
124129
QByteArray serializedReply;
125130
length = -1;
126-
while (serializedReply.size() != length)
131+
while (length < 0 && serializedReply.size() < length+4)
127132
{
128-
std::cout << length << std::endl;
129133
// receive reply
130134
if (!_socket.waitForReadyRead())
131135
{
@@ -136,20 +140,22 @@ proto::HyperionReply ProtoConnection::sendMessage(const proto::HyperionRequest &
136140

137141
if (length < 0 && serializedReply.size() >= 4)
138142
{
139-
std::cout << (int) serializedReply[3] << std::endl;
140-
std::cout << (int) serializedReply[2] << std::endl;
141-
std::cout << (int) serializedReply[1] << std::endl;
142-
std::cout << (int) serializedReply[0] << std::endl;
143-
144-
length = (uint8_t(serializedReply[0]) << 24) | (uint8_t(serializedReply[1]) << 16) | (uint8_t(serializedReply[2]) << 8) | uint8_t(serializedReply[3]) ;
143+
// read the message size
144+
length =
145+
((serializedReply[0]<<24) & 0xFF000000) |
146+
((serializedReply[1]<<16) & 0x00FF0000) |
147+
((serializedReply[2]<< 8) & 0x0000FF00) |
148+
((serializedReply[3] ) & 0x000000FF);
145149
}
146150
}
147151

148-
std::cout << length << std::endl;
149-
*/
150152
// parse reply data
151153
proto::HyperionReply reply;
152-
// reply.ParseFromArray(serializedReply.constData()+4, length);
154+
reply.ParseFromArray(serializedReply.constData()+4, length);
155+
156+
// remove data from receive buffer
157+
serializedReply = serializedReply.mid(length+4);
158+
153159
return reply;
154160
}
155161

src/hyperion-v4l2/ProtoConnection.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class ProtoConnection
3434
///
3535
~ProtoConnection();
3636

37+
/// Do not read reply messages from Hyperion if set to true
38+
void setSkipReply(bool skip);
39+
3740
///
3841
/// Set all leds to the specified color
3942
///
@@ -86,4 +89,7 @@ class ProtoConnection
8689
private:
8790
/// The TCP-Socket with the connection to the server
8891
QTcpSocket _socket;
92+
93+
/// Skip receiving reply messages from Hyperion if set
94+
bool _skipReply;
8995
};

src/hyperion-v4l2/hyperion-v4l2.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ int main(int argc, char** argv)
8181
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
8282
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]");
8383
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]");
84+
SwitchParameter<> & argSkipReply = parameters.add<SwitchParameter<>> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
8485
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<>> ('h', "help", "Show this help message and exit");
8586

8687
// set defaults
@@ -126,6 +127,7 @@ int main(int argc, char** argv)
126127
else
127128
{
128129
ProtoConnection connection(argAddress.getValue());
130+
connection.setSkipReply(argSkipReply.isSet());
129131

130132
grabber.setCallback(&sendImage, &connection);
131133
grabber.capture();

0 commit comments

Comments
 (0)