YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ThrottleDown.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
6#include "ThrottleDown.h"
7
8#include <algorithm>
9#include <cmath>
10
12#include <yarp/os/LogStream.h>
13#include <yarp/os/Time.h>
14
15using namespace yarp::os;
16
17namespace {
19 "yarp.carrier.portmonitor.ThrottleDown",
23 nullptr)
24
25void split(const std::string& s, char delim, std::vector<std::string>& elements)
26{
27 std::istringstream iss(s);
28 std::string item;
29 while (std::getline(iss, item, delim))
30 {
31 elements.push_back(item);
32 }
33}
34
35}//anonymous namespace
36
37
39{
40 // parse the user parameters
42 std::string str = options.find("carrier").asString();
43 yCDebug(PM_THRD) << "parsed string:" << str << " "<< options.toString();
45 yCDebug(PM_THRD) << "parsed params:" << m_user_params.toString();
46
47 // get the value of the parameters
48 /* if (m_user_params.check("period")) {
49 //Float64 have issues related to the '.' character.
50 //Even replacing the separator character in getParamsFromCommandLine() from ` ` to `=`
51 //0.02 becomes 0.2, probabibly located in protocol .cpp
52 m_period = m_user_params.find("period").asFloat64();
53 yCDebug(PM_THRD) << "period set:" << m_period;
54 }*/
55 if (m_user_params.check("period_ms")) {
56 m_period = m_user_params.find("period_ms").asInt32();
57 m_period /= 1000.0;
58 yCDebug(PM_THRD) << "period set:" << m_period;
59 }
60
61 m_last_time= yarp::os::Time::now();
62
63 return true;
64}
65
67{
68}
69
71{
72 // Split command line string using '+' delimiter
73 std::vector<std::string> parameters;
74 split(carrierString, '+', parameters);
75
76 // Iterate over result strings
77 for (std::string param : parameters) {
78 // If there is no '.', then the param is bad formatted, skip it.
79 auto pointPosition = param.find('.');
80 if (pointPosition == std::string::npos) {
81 continue;
82 }
83
84 // Otherwise, separate key and value
85 std::string paramKey = param.substr(0, pointPosition);
87 std::string s = param.substr(pointPosition + 1, param.length());
88 paramValue.fromString(s.c_str());
89
90 // and append to the returned property
91 prop.put(paramKey, paramValue);
92 }
93 return;
94}
95
96
98{
99 return false;
100}
101
103{
104 return false;
105}
106
108{
109 double cur_time = yarp::os::Time::now();
110 if (cur_time - m_last_time > m_period)
111 {
112 m_last_time = cur_time;
113 return true;
114 }
115 return false;
116}
117
119{
120 return thing;
121}
bool accept(yarp::os::Things &thing) override
This will be called when the data reach the portmonitor object.
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)
void destroy() override
This will be called when the portmonitor object destroyes.
bool create(const yarp::os::Property &options) override
This will be called when the dll is properly loaded by the portmonitor carrier.
bool getparam(yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are requested via YARP admin port.
A mini-server for performing network communication in the background.
static LogCallback printCallback()
Get current print callback.
Definition Log.cpp:873
static LogType minimumPrintLevel()
Get current minimum print level.
Definition Log.cpp:833
@ LogTypeReserved
Definition Log.h:98
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.
std::string toString() const override
Return a standard text representation of the content of the object.
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:44
virtual std::string asString() const
Get string value.
Definition Value.cpp:246
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
STL namespace.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition Time.cpp:121
An interface to the operating system, including Port based communication.