YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Simulated_network_delay.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025-2025 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7#include <yarp/os/Value.h>
8#include <yarp/os/Time.h>
9#include <vector>
10
11#include <iostream>
12
13using namespace yarp::os;
14
15namespace {
16
17void split(const std::string& s, char delim, std::vector<std::string>& elements)
18{
19 std::istringstream iss(s);
20 std::string item;
21 while (std::getline(iss, item, delim)) {
22 elements.push_back(item);
23 }
24}
25} //anonymous namespace
26
27
29{
30 // Split command line string using '+' delimiter
31 std::vector<std::string> parameters;
32 split(carrierString, '+', parameters);
33
34 // Iterate over result strings
35 for (std::string param : parameters)
36 {
37 // If there is no '.', then the param is bad formatted, skip it.
38 auto pointPosition = param.find('.');
39 if (pointPosition == std::string::npos)
40 {
41 continue;
42 }
43
44 // Otherwise, separate key and value
45 std::string paramKey = param.substr(0, pointPosition);
47 std::string s = param.substr(pointPosition + 1, param.length());
48 paramValue.fromString(s.c_str());
49
50 //and append to the returned property
51 prop.put(paramKey, paramValue);
52 }
53 return;
54}
55
57{
58 //parse the user parameters
60 std::string str = options.find("carrier").asString();
62
63 if (m_user_params.check("delay_ms"))
64 {
65 m_delay = m_user_params.find("delay_ms").asFloat32();
66 m_delay /= 1000.0;
67 }
68
69 return true;
70}
71
75
77{
78 return false;
79}
80
82{
83 return false;
84}
85
87{
88 return true;
89}
90
96
bool create(const yarp::os::Property &options) override
This will be called when the dll is properly loaded by the portmonitor carrier.
bool accept(yarp::os::Things &thing) override
This will be called when the data reach the portmonitor object.
void trig() override
This will be called when one of the peer connections to the same import port receives data.
bool getparam(yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are requested via YARP admin port.
void destroy() override
This will be called when the portmonitor object destroyes.
yarp::os::Things & update(yarp::os::Things &thing) override
After data get accpeted in the accept() callback, an instance of that is given to the update function...
bool setparam(const yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are set via YARP admin port.
void getParamsFromCommandLine(std::string carrierString, yarp::os::Property &prop)
A mini-server for performing network communication in the background.
A class for storing options and configuration information.
Definition Property.h:33
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition Property.cpp:987
Base class for generic things.
Definition Things.h:18
A single value (typically within a Bottle).
Definition Value.h:43
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
ContainerT split(const typename ContainerT::value_type &s, std::basic_regex< typename ContainerT::value_type::value_type > regex)
Utility to split a string by a separator, into a vector of strings.
Definition string.h:26
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
An interface to the operating system, including Port based communication.