Skip to content

Commit

Permalink
Merge pull request #2434 from randaz81/yarp_repeat
Browse files Browse the repository at this point in the history
yarp repeat
  • Loading branch information
drdanz authored Jan 8, 2021
2 parents 6b64518 + 0f303f7 commit b834e56
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/release/master/yarp_repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
yarp_repeat {#master}
-------------------------

## Important Changes

### Yarp companion

#### added command `yarp repeat`
* `yarp repeat` repeats in an output port all data received in an input port. The command is useful to control stream flows on a wifi/mobile connection.
1 change: 1 addition & 0 deletions src/libYARP_companion/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ set(YARP_companion_IMPL_SRCS yarp/companion/impl/Companion.cpp
yarp/companion/impl/Companion.cmdResource.cpp
yarp/companion/impl/Companion.cmdRead.cpp
yarp/companion/impl/Companion.cmdReadWrite.cpp
yarp/companion/impl/Companion.cmdRepeat.cpp
yarp/companion/impl/Companion.cmdRpc.cpp
yarp/companion/impl/Companion.cmdRpcServer.cpp
yarp/companion/impl/Companion.cmdSample.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
* All rights reserved.
*
* This software may be modified and distributed under the terms of the
* BSD-3-Clause license. See the accompanying LICENSE file for details.
*/

#include <yarp/companion/impl/Companion.h>

#include <yarp/os/Bottle.h>
#include <yarp/os/BufferedPort.h>
#include <yarp/os/Network.h>
#include <yarp/os/Property.h>

using yarp::companion::impl::Companion;
using yarp::os::Bottle;
using yarp::os::BufferedPort;
using yarp::os::NetworkBase;
using yarp::os::Property;

int Companion::cmdRepeat(int argc, char *argv[])
{
BufferedPort<Bottle> port;

Property options;
options.fromCommand(argc, argv, false);
if (argc==0 || options.check("help"))
{
yCInfo(COMPANION, "This is yarp repeat. Syntax:");
yCInfo(COMPANION, " yarp repeat /port");
yCInfo(COMPANION, "/port is both the input port and the output port which repeats data");
return 1;
}

if (argc==1)
{
if (!port.open(argv[0]))
{
yCError(COMPANION, "Failed to open port: %s", argv[0]);
return 1;
}
}
else
{
yCError(COMPANION, "Invalid command syntax");
return 1;
}

while (true)
{
Bottle *bot = port.read();
if (!bot) continue;
if (port.getOutputCount()>0)
{
port.prepare() = *bot;
port.write();
}
}

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Companion::Companion() :
add("priority-qos", &Companion::cmdPriorityQos, "set/get the packet priority for a given connection");
add("read", &Companion::cmdRead, "read from the network and print to standard output");
add("readwrite", &Companion::cmdReadWrite, "read from the network and print to standard output, write to the network from standard input");
add("repeat", &Companion::cmdRepeat, "repeats on the output port the same data received in the input port");
add("resource", &Companion::cmdResource, "locates resource files (see ResourceFinder class)");
add("rpc", &Companion::cmdRpc, "write commands to a port, and read replies");
add("rpcserver", &Companion::cmdRpcServer, "make a test RPC server to receive and reply to Bottle-format messages");
Expand Down
3 changes: 3 additions & 0 deletions src/libYARP_companion/src/yarp/companion/impl/Companion.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class YARP_companion_API Companion
// Defined in Companion.cmdReadWrite.cpp
int cmdReadWrite(int argc, char *argv[]);

// Defined in Companion.cmdRepeat.cpp
int cmdRepeat(int argc, char* argv[]);

// Defined in Companion.cmdResource.cpp
int cmdResource(int argc, char *argv[]);

Expand Down

0 comments on commit b834e56

Please sign in to comment.