Lely core libraries 1.9.2
time.hpp
Go to the documentation of this file.
1
23#ifndef LELY_CO_TIME_HPP_
24#define LELY_CO_TIME_HPP_
25
26#ifndef __cplusplus
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
33namespace lely {
34
36template <>
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 static void
49 free(void* ptr) noexcept {
50 __co_time_free(ptr);
51 }
52
53 static pointer
54 init(pointer p, CANNet* net, CODev* dev) noexcept {
55 return __co_time_init(p, net, dev);
56 }
57
58 static void
59 fini(pointer p) noexcept {
60 __co_time_fini(p);
61 }
62};
63
65class COTime : public incomplete_c_type<__co_time> {
67
68 public:
69 COTime(CANNet* net, CODev* dev) : c_base(net, dev) {}
70
71 CANNet*
72 getNet() const noexcept {
73 return co_time_get_net(this);
74 }
75 CODev*
76 getDev() const noexcept {
77 return co_time_get_dev(this);
78 }
79
80 void
81 getInd(co_time_ind_t** pind, void** pdata) const noexcept {
82 co_time_get_ind(this, pind, pdata);
83 }
84
85 void
86 setInd(co_time_ind_t* ind, void* data) noexcept {
87 co_time_set_ind(this, ind, data);
88 }
89
90 template <class F>
91 void
92 setInd(F* f) noexcept {
93 setInd(&c_obj_call<co_time_ind_t*, F>::function, static_cast<void*>(f));
94 }
95
96 template <class C, typename c_mem_fn<co_time_ind_t*, C>::type M>
97 void
98 setInd(C* obj) noexcept {
100 static_cast<void*>(obj));
101 }
102
103 void
104 start(const timespec* start = 0, const timespec* interval = 0) noexcept {
105 co_time_start(this, start, interval);
106 }
107
108 void
109 stop() noexcept {
110 co_time_stop(this);
111 }
112
113 protected:
114 ~COTime() {}
115};
116
117} // namespace lely
118
119#endif // !LELY_CO_TIME_HPP_
An opaque CAN network interface type.
Definition: net.hpp:83
An opaque CANopen device type.
Definition: dev.hpp:76
An opaque CANopen TIME producer/consumer service type.
Definition: time.hpp:65
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:245
This header file is part of the CANopen library; it contains the time stamp (TIME) object declaration...
void co_time_stop(co_time_t *time)
Stops a CANopen TIME producer.
Definition: time.c:306
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:287
void co_time_start(co_time_t *time, const struct timespec *start, const struct timespec *interval)
Starts a CANopen TIME producer.
Definition: time.c:296
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:276
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:260
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_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:268
Global namespace for the Lely Industries N.V. libraries.
Definition: buf.hpp:32
This header file is part of the CAN library; it contains the C++ interface of the CAN network interfa...
A CANopen TIME producer/consumer service.
Definition: time.c:41
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:344
A time type with nanosecond resolution.
Definition: time.h:83