Dawn Framework 1.0
Universal data acquisition framework for embedded systems
systime.cxx
1// dawn/src/io/systime.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/io/systime.hxx"
7
8#include <errno.h>
9#include <time.h>
10
11using namespace dawn;
12
14{
15 return OK;
16}
17
18int CIOSystime::getDataImpl(IODataCmn &data, size_t len)
19{
20 struct timespec ts;
21 int ret;
22
23 if (len != 1)
24 {
25 return -ENOTSUP;
26 }
27
28 ret = clock_gettime(CLOCK_REALTIME, &ts);
29 if (ret < 0)
30 {
31 return -errno;
32 }
33
34 // Return nanoseconds since epoch
35
36 uint64_t *time_data = static_cast<uint64_t *>(data.getDataPtr());
37 *time_data = static_cast<uint64_t>(ts.tv_sec) * 1000000000ULL + static_cast<uint64_t>(ts.tv_nsec);
38
39 return OK;
40}
41
43{
44 struct timespec ts;
45 int ret;
46
47 // Set time from nanoseconds since epoch
48
49 uint64_t *time_data = static_cast<uint64_t *>(data.getDataPtr());
50 ts.tv_sec = static_cast<time_t>(*time_data / 1000000000ULL);
51 ts.tv_nsec = static_cast<long>(*time_data % 1000000000ULL);
52
53 ret = clock_settime(CLOCK_REALTIME, &ts);
54 if (ret < 0)
55 {
56 return -errno;
57 }
58
59 return OK;
60}
61
63{
64 return sizeof(uint64_t);
65}
66
68{
69 return 1;
70}
71
73{
74 return true;
75}
76
78{
79 return true;
80}
81
83{
84 return false;
85}
86
88{
89 return false;
90}
bool isWrite() const
Check if IO supports write operations.
Definition systime.cxx:77
size_t getDataDim() const
Get data vector dimension.
Definition systime.cxx:67
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
Definition systime.cxx:42
bool isNotify() const
Check if IO supports notifications.
Definition systime.cxx:82
size_t getDataSize() const
Get data size in bytes.
Definition systime.cxx:62
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition systime.cxx:18
bool isRead() const
Check if IO supports read operations.
Definition systime.cxx:72
int init()
One-time initialize object after bindings are resolved.
Definition systime.cxx:13
bool isBatch() const
Check if IO supports batch operations.
Definition systime.cxx:87
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Base interface for I/O data buffers (static and dynamic).
Definition idata.hxx:21
virtual void * getDataPtr(size_t batch=0)=0
Get pointer to data only (skips timestamp if present).