EEROS  0.4.1.0
API for the EEROS Real-Time Robotics Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Signal.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CONTROL_SIGNAL_HPP_
2 #define ORG_EEROS_CONTROL_SIGNAL_HPP_
3 
4 #include <string>
5 #include <list>
6 #include <type_traits>
7 #include <eeros/types.hpp>
9 
10 namespace eeros {
11  namespace control {
12 
13  template < typename T = double >
14  class Signal : public SignalInterface {
15  public:
16  Signal() {
17  id = signalCounter++;
18 // signalList.push_back(this);
19  }
20 
21  virtual sigid_t getId() const {
22  return static_cast<sigid_t>(id) << 16;
23  }
24 
25  virtual std::string getName() const {
26  return name;
27  }
28 
29  virtual void setName(std::string n) {
30  name = name;
31  }
32 
33  virtual std::string getLabel() const {
34 // std::stringstream label;
35 // label << '#' << id << '.' << index << ": " << getName(index);
36 // if(getAffiliation(index) != "") {
37 // label << " (" << getAffiliation(index) << ')';
38 // }
39 // if(getUnit(index) != "") {
40 // label << " [" << getUnit(index) << ']';
41 // }
42 // return label.str();
43  return name; // TODO
44  }
45 
46  virtual T getValue() const {
47  return value;
48  }
49 
50  virtual void setValue(T newValue) {
51  value = newValue;
52  }
53 
54  template < typename VT >
55  void setValue(VT newValue) {
56  value = newValue;
57  }
58 
59  virtual timestamp_t getTimestamp() const {
60  return timestamp;
61  }
62 
63  virtual void setTimestamp(timestamp_t newTimestamp) {
64  timestamp = newTimestamp;
65  }
66 
67  virtual void clear() {
68  _clear<T>();
69  }
70 
72  value = right.value;
73  timestamp = right.timestamp;
74  return *this;
75  }
76 
77  Signal<T>& operator= (T right) {
78  value = right;
79  return *this;
80  }
81 
83  return illegalSignal;
84  }
85 
86  static std::list<SignalInterface*> getSignalList() {
87  return signalList;
88  }
89 
91  std::list<SignalInterface*>::iterator i = signalList.begin();
92  while(i != signalList.end()) {
93  if((*i)->getId() == id) {
94  return (*i);
95  }
96  i++;
97  }
98  return NULL;
99  }
100 
101  protected:
102  T value;
105  std::string name;
106 
107  private:
108  template <typename S> typename std::enable_if<std::is_arithmetic<S>::value>::type _clear() {
109  value = 0;
110  }
111 
112  template <typename S> typename std::enable_if<!std::is_arithmetic<S>::value>::type _clear() {
113  value.fill(0);
114  }
115 
116  static std::list<SignalInterface*> signalList;
117  static uint16_t signalCounter;
118  static Signal<T> illegalSignal;
119  };
120 
121  template < typename T>
122  std::list<SignalInterface*> Signal<T>::signalList;
123 
124  template < typename T>
125  uint16_t Signal<T>::signalCounter = startSignalId;
126 
127  template < typename T>
128  Signal<T> Signal<T>::illegalSignal;
129 
130  };
131 };
132 
133 #endif /* ORG_EEROS_CONTROL_SIGNAL_HPP_ */
virtual void clear()
Definition: Signal.hpp:67
sigid_t id
Definition: Signal.hpp:104
void setValue(VT newValue)
Definition: Signal.hpp:55
virtual T getValue() const
Definition: Signal.hpp:46
virtual sigid_t getId() const
Definition: Signal.hpp:21
virtual std::string getName() const
Definition: Signal.hpp:25
virtual void setValue(T newValue)
Definition: Signal.hpp:50
T value
Definition: Signal.hpp:102
Signal< T > & operator=(Signal< T > right)
Definition: Signal.hpp:71
virtual void setTimestamp(timestamp_t newTimestamp)
Definition: Signal.hpp:63
type
Definition: Sequencer.hpp:15
std::string name
Definition: Signal.hpp:105
static Signal< T > & getIllegalSignal()
Definition: Signal.hpp:82
timestamp_t timestamp
Definition: Signal.hpp:103
virtual timestamp_t getTimestamp() const
Definition: Signal.hpp:59
static SignalInterface * getSignalById(sigid_t id)
Definition: Signal.hpp:90
Definition: Signal.hpp:14
virtual std::string getLabel() const
Definition: Signal.hpp:33
Definition: SignalInterface.hpp:12
Signal()
Definition: Signal.hpp:16
int i
Definition: RingBufferTest.cpp:12
virtual void setName(std::string n)
Definition: Signal.hpp:29
uint32_t sigid_t
Definition: types.hpp:9
static std::list< SignalInterface * > getSignalList()
Definition: Signal.hpp:86
uint64_t timestamp_t
Definition: types.hpp:12
Definition: SignalInterface.hpp:14