Lely core libraries  2.3.4
time.hpp
Go to the documentation of this file.
1 
23 #ifndef LELY_CO_TIME_HPP_
24 #define LELY_CO_TIME_HPP_
25 
26 #if !defined(__cplusplus) || LELY_NO_CXX
27 #error "include <lely/co/time.h> for the C interface"
28 #endif
29 
30 #include <lely/can/net.hpp>
31 #include <lely/co/time.h>
32 
33 namespace lely {
34 
36 template <>
38  typedef __co_time value_type;
39  typedef value_type& reference;
40  typedef const value_type& const_reference;
41  typedef value_type* pointer;
42  typedef const value_type* const_pointer;
43 
44  static void*
45  alloc() noexcept {
46  return __co_time_alloc();
47  }
48 
49  static void
50  free(void* ptr) noexcept {
51  __co_time_free(ptr);
52  }
53 
54  static pointer
55  init(pointer p, CANNet* net, CODev* dev) noexcept {
56  return __co_time_init(p, net, dev);
57  }
58 
59  static void
60  fini(pointer p) noexcept {
61  __co_time_fini(p);
62  }
63 };
64 
66 class COTime : public incomplete_c_type<__co_time> {
68 
69  public:
70  COTime(CANNet* net, CODev* dev) : c_base(net, dev) {}
71 
72  int
73  start() noexcept {
74  return co_time_start(this);
75  }
76 
77  void
78  stop() noexcept {
79  co_time_stop(this);
80  }
81 
82  CANNet*
83  getNet() const noexcept {
84  return co_time_get_net(this);
85  }
86 
87  CODev*
88  getDev() const noexcept {
89  return co_time_get_dev(this);
90  }
91 
92  void
93  getInd(co_time_ind_t** pind, void** pdata) const noexcept {
94  co_time_get_ind(this, pind, pdata);
95  }
96 
97  void
98  setInd(co_time_ind_t* ind, void* data) noexcept {
99  co_time_set_ind(this, ind, data);
100  }
101 
102  template <class F>
103  void
104  setInd(F* f) noexcept {
105  setInd(&c_obj_call<co_time_ind_t*, F>::function, static_cast<void*>(f));
106  }
107 
108  template <class C, typename c_mem_fn<co_time_ind_t*, C>::type M>
109  void
110  setInd(C* obj) noexcept {
112  static_cast<void*>(obj));
113  }
114 
115  void
116  startProd(const timespec* start = 0, const timespec* interval = 0) noexcept {
117  co_time_start_prod(this, start, interval);
118  }
119 
120  void
121  stopProd() noexcept {
122  co_time_stop_prod(this);
123  }
124 
125  protected:
126  ~COTime() = default;
127 };
128 
129 } // namespace lely
130 
131 #endif // !LELY_CO_TIME_HPP_
lely::incomplete_c_type
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:249
net.hpp
__co_time
A CANopen TIME producer/consumer service.
Definition: time.c:41
co_time_set_ind
void co_time_set_ind(co_time_t *time, co_time_ind_t *ind, void *data)
Sets the indication function invoked when a CANopen time stamp is received.
Definition: time.c:355
lely::c_obj_call
Definition: c_call.hpp:62
co_time_start_prod
void co_time_start_prod(co_time_t *time, const struct timespec *start, const struct timespec *interval)
Starts a CANopen TIME producer.
Definition: time.c:364
co_time_stop
void co_time_stop(co_time_t *time)
Stops a TIME service.
Definition: time.c:300
time.h
co_time_start
int co_time_start(co_time_t *time)
Starts a TIME service.
Definition: time.c:277
lely::COTime
An opaque CANopen TIME producer/consumer service type.
Definition: time.hpp:66
co_time_stop_prod
void co_time_stop_prod(co_time_t *time)
Stops a CANopen TIME producer.
Definition: time.c:374
lely::CANNet
An opaque CAN network interface type.
Definition: net.hpp:85
co_time_get_dev
co_dev_t * co_time_get_dev(const co_time_t *time)
Returns a pointer to the CANopen device of a TIME producer/consumer service.
Definition: time.c:336
lely::c_type_traits
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:120
co_time_get_ind
void co_time_get_ind(const co_time_t *time, co_time_ind_t **pind, void **pdata)
Retrieves the indication function invoked when a CANopen time stamp is received.
Definition: time.c:344
co_time_ind_t
void co_time_ind_t(co_time_t *time, const struct timespec *tp, void *data)
The type of a CANopen TIME indication function, invoked when a time stamp is received.
Definition: time.h:52
co_time_get_net
can_net_t * co_time_get_net(const co_time_t *time)
Returns a pointer to the CAN network of a TIME producer/consumer service.
Definition: time.c:328
lely::c_mem_call
Definition: c_call.hpp:67
lely::CODev
An opaque CANopen device type.
Definition: dev.hpp:77