Skip to content

Commit 39fb4a5

Browse files
phanikiran1169florent-lamiraux
authored andcommitted
Methods to check whether queue received data
1 parent 6148edf commit 39fb4a5

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

src/ros_queued_subscribe-python-module-py.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@ BOOST_PYTHON_MODULE(wrap) {
2424
"Return the queue size of a given signal", bp::args("signal_name"))
2525
.def("readQueue", &dg::RosQueuedSubscribe::readQueue,
2626
"Whether signals should read values from the queues, and when.",
27-
bp::args("start_time"));
27+
bp::args("start_time"))
28+
.def("queueReceivedData", &dg::RosQueuedSubscribe::queueReceivedData,
29+
"Check whether the queue of a given signal has received atleast one data point",
30+
bp::args("signal_name"))
31+
.def("setQueueReceivedData", &dg::RosQueuedSubscribe::setQueueReceivedData,
32+
"Set the data reception status of the queue corresponding to a given signal",
33+
bp::args("signal_name","signal_data_acq_status"));
2834
}

src/ros_queued_subscribe.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,21 @@ void RosQueuedSubscribe::readQueue(int beginReadingAt) {
147147
}
148148

149149
std::string RosQueuedSubscribe::getDocString() const { return docstring_; }
150-
} // end of namespace dynamicgraph.
150+
151+
bool RosQueuedSubscribe::queueReceivedData(const std::string& signal) const{
152+
std::map<std::string, bindedSignal_t>::const_iterator _bs = bindedSignal_.find(signal);
153+
if (_bs != bindedSignal_.end()) {
154+
return _bs->second->receivedData();
155+
}
156+
157+
return false;
158+
}
159+
160+
void RosQueuedSubscribe::setQueueReceivedData(const std::string& signal, bool status) {
161+
std::map<std::string, bindedSignal_t>::const_iterator _bs = bindedSignal_.find(signal);
162+
if (_bs != bindedSignal_.end()) {
163+
_bs->second->receivedData(status);
164+
}
165+
}
166+
167+
} // end of namespace dynamicgraph.

src/ros_queued_subscribe.hh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ struct BindedSignalBase {
5757
virtual void clear() = 0;
5858
virtual std::size_t size() const = 0;
5959

60+
virtual bool receivedData() const = 0;
61+
virtual void receivedData(bool) = 0;
62+
6063
Subscriber_t subscriber;
6164
RosQueuedSubscribe* entity;
6265
};
@@ -73,7 +76,8 @@ struct BindedSignal : BindedSignalBase {
7376
frontIdx(0),
7477
backIdx(0),
7578
buffer(BufferSize),
76-
init(false) {}
79+
init(false),
80+
receivedData_(false) {}
7781
~BindedSignal() {
7882
signal.reset();
7983
clear();
@@ -107,6 +111,15 @@ struct BindedSignal : BindedSignalBase {
107111
return backIdx + BufferSize - frontIdx;
108112
}
109113

114+
/// @brief Returns the value stored in receivedData_ i.e.
115+
/// whether the signal has received atleast one data point
116+
/// or not
117+
bool receivedData() const {return receivedData_;}
118+
119+
/// @brief Set the value of data acquisition status of the signal
120+
/// @param status
121+
void receivedData(bool status) {receivedData_ = status;}
122+
110123
SignalPtr_t signal;
111124
/// Index of the next value to be read.
112125
size_type frontIdx;
@@ -120,6 +133,10 @@ struct BindedSignal : BindedSignalBase {
120133
template <typename R>
121134
void writer(const R& data);
122135
T& reader(T& val, int time);
136+
137+
private:
138+
/// Indicates whether the signal has received atleast one data point
139+
bool receivedData_;
123140
};
124141
} // namespace internal
125142

@@ -144,6 +161,8 @@ class RosQueuedSubscribe : public dynamicgraph::Entity {
144161
void clearQueue(const std::string& signal);
145162
void readQueue(int beginReadingAt);
146163
std::size_t queueSize(const std::string& signal) const;
164+
bool queueReceivedData(const std::string& signal) const;
165+
void setQueueReceivedData(const std::string& signal, bool status);
147166

148167
template <typename T>
149168
void add(const std::string& type, const std::string& signal,

src/ros_queued_subscribe.hxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ void BindedSignal<T, N>::writer(const R& data) {
8282
last = buffer[backIdx];
8383
init = true;
8484
}
85+
// Updating the status flag to indicate that the signal
86+
// has received atleast one data point.
87+
if (!receivedData_) {
88+
receivedData_ = true;
89+
}
90+
8591
backIdx = (backIdx + 1) % N;
8692
}
8793

0 commit comments

Comments
 (0)