TopicTimingClient.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI::ArmarXObjects::TopicTimingClient
17  * @author Fabian Paus ( fabian dot paus at kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "TopicTimingClient.h"
24 
26 
27 namespace armarx
28 {
31  {
32  defineOptionalProperty<std::string>("TimingTestTopicName", "TimingTestTopic", "-");
33  defineOptionalProperty<int>(
34  "SimulateWorkForMS", 20, "Sleeps until it returns from the topic call");
35 
36  defineOptionalProperty<std::string>(
37  "DebugObserverName", "DebugObserver", "Name of the topic the DebugObserver listens on");
38  }
39 
40  std::string
42  {
43  return "TopicTimingClient";
44  }
45 
46  void
48  {
49  usingTopicFromProperty("TimingTestTopicName");
50 
51  offeringTopicFromProperty("DebugObserverName");
52  }
53 
54  void
56  {
57  // Get topics and proxies here. Pass the *InterfacePrx type as template argument.
58  debugObserver = getTopicFromProperty<DebugObserverInterfacePrx>("DebugObserverName");
59  // debugDrawer.getTopic(*this); // Calls this->getTopic().
60 
61  // getProxyFromProperty<MyProxyInterfacePrx>("MyProxyName");
62 
63  lastSmallTime = IceUtil::Time::now();
64 
65  updateTimes = boost::circular_buffer<IceUtil::Time>(11);
66 
67  simulateWorkForMS = getProperty<int>("SimulateWorkForMS").getValue();
68  }
69 
70  void
72  {
73  }
74 
75  void
77  {
78  }
79 
82  {
85  }
86 } // namespace armarx
87 
88 void
89 armarx::TopicTimingClient::reportSmall(const topic_timing::SmallData& data, const Ice::Current&)
90 {
91  IceUtil::Time time_now = IceUtil::Time::now();
92 
93  IceUtil::Time time_sent = IceUtil::Time::microSeconds(data.sentTimestamp);
94 
95  IceUtil::Time dur_transfer = time_now - time_sent;
96 
97  IceUtil::Time dur_cycle;
98  {
99  std::unique_lock<std::mutex> lock(mutex);
100  dur_cycle = time_now - lastSmallTime;
101  lastSmallTime = time_now;
102  updateTimes.push_back(time_now);
103 
104  usleep(simulateWorkForMS * 1000);
105  }
106 
107  // Calculate updates per second
108  float updatesPerSecond = 0.0f;
109  IceUtil::Time duration = IceUtil::Time::microSeconds(0);
110  if (updateTimes.size() > 1)
111  {
112  duration = updateTimes.back() - updateTimes.front();
113  updatesPerSecond = (updateTimes.size() - 1) / duration.toSecondsDouble();
114  }
115 
116  StringVariantBaseMap channel;
117  channel["DurationTransfer"] = new Variant(dur_transfer.toMilliSecondsDouble());
118  channel["DurationCycle"] = new Variant(dur_cycle.toMilliSecondsDouble());
119  channel["Duration10"] = new Variant(duration.toMilliSecondsDouble());
120  channel["UpdatesPerSecond"] = new Variant(updatesPerSecond);
121  debugObserver->setDebugChannel("TopicTimingClientSmall-" + getName(), channel);
122 }
123 
124 void
125 armarx::TopicTimingClient::reportBig(const topic_timing::BigData& data, const Ice::Current&)
126 {
127  IceUtil::Time sentTime = IceUtil::Time::microSeconds(data.sentTimestamp);
128  (void)sentTime;
129 }
armarx::TopicTimingClient::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: TopicTimingClient.cpp:81
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:110
armarx::TopicTimingClient::reportBig
void reportBig(const topic_timing::BigData &data, const Ice::Current &) override
Definition: TopicTimingClient.cpp:125
armarx::Component::offeringTopicFromProperty
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
Definition: Component.cpp:159
armarx::TopicTimingClient::onDisconnectComponent
virtual void onDisconnectComponent() override
Definition: TopicTimingClient.cpp:71
armarx::TopicTimingClient::onConnectComponent
virtual void onConnectComponent() override
Definition: TopicTimingClient.cpp:55
armarx::TopicTimingClient::onExitComponent
virtual void onExitComponent() override
Definition: TopicTimingClient.cpp:76
armarx::TopicTimingClient::reportSmall
void reportSmall(const topic_timing::SmallData &data, const Ice::Current &) override
Definition: TopicTimingClient.cpp:89
armarx::TopicTimingClient::getDefaultName
virtual std::string getDefaultName() const override
Definition: TopicTimingClient.cpp:41
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::Component::usingTopicFromProperty
void usingTopicFromProperty(const std::string &propertyName, bool orderedPublishing=false)
Use a topic whose name is specified by the given property.
Definition: Component.cpp:165
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TopicTimingClient.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::TopicTimingClient::onInitComponent
virtual void onInitComponent() override
Definition: TopicTimingClient.cpp:47
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:108
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::TopicTimingClientPropertyDefinitions
Definition: TopicTimingClient.h:41
Variant.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::TopicTimingClientPropertyDefinitions::TopicTimingClientPropertyDefinitions
TopicTimingClientPropertyDefinitions(std::string prefix)
Definition: TopicTimingClient.cpp:29