Dawn Framework 1.0
Universal data acquisition framework for embedded systems
encoder.hxx
1// dawn/include/dawn/io/encoder.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include "dawn/io/common.hxx"
9#include "dawn/porting/config.hxx"
10#include "dawn/porting/encoder.hxx"
11
12namespace dawn
13{
16class CIOEncoder : public CIOCommon
17{
18public:
19 enum
20 {
21 IO_ENCODER_CFG_FIRST = 0,
22 IO_ENCODER_CFG_POSMAX = 1,
23 IO_ENCODER_CFG_LAST = 31
24 };
25
26 explicit CIOEncoder(CDescObject &desc)
27 : CIOCommon(desc)
28 , fd(-1)
29 , posmax(0)
30 , hasPosmax(false)
31 {
32 }
33
34 ~CIOEncoder() override;
35
36#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
37 const char *getClassNameStr() const override
38 {
39 return "encoder";
40 }
41#endif
42
43 int configure() override;
44 int init() override;
45 int deinit() override;
46 int getDataImpl(IODataCmn &data, size_t len) override;
47 int trigger(uint8_t cmd) override;
48
49 size_t getDataSize() const override
50 {
51 return sizeof(int32_t);
52 }
53
54 size_t getDataDim() const override
55 {
56 return 1;
57 }
58
59 bool isRead() const override
60 {
61 return true;
62 }
63
64 bool isWrite() const override
65 {
66 return false;
67 }
68
69 bool isNotify() const override
70 {
71 return false;
72 }
73
74 bool isBatch() const override
75 {
76 return false;
77 }
78
80
81 constexpr static SObjectId::ObjectId objectId(bool ts, uint16_t inst)
82 {
83 return ObjectIdHelper::create(ts, inst);
84 }
85
86 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t dtype, uint8_t size, uint8_t id)
87 {
90 }
91
92 constexpr static SObjectCfg::ObjectCfgId cfgIdPosmax()
93 {
94 return CIOEncoder::cfgId(false, SObjectId::DTYPE_UINT32, 1, IO_ENCODER_CFG_POSMAX);
95 }
96
97private:
98 char path[PATH_MAX] = {};
99 int fd;
100 uint32_t posmax;
101 bool hasPosmax;
102
103 int configureDesc(const CDescObject &desc);
104};
105
106} // Namespace dawn
Descriptor wrapper for individual object configuration.
Template helper for creating ObjectIDs for I/O types.
Definition common.hxx:236
static SObjectId::ObjectId create(bool ts, uint16_t inst)
Create ObjectID with default data type.
Definition common.hxx:246
Base class for all I/O objects.
Definition common.hxx:27
@ IO_CLASS_ENCODER
Quadrature encoder (position)
Definition common.hxx:183
Quadrature encoder I/O (position only).
Definition encoder.hxx:17
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition encoder.cxx:134
bool isRead() const
Check if IO supports read operations.
Definition encoder.hxx:59
int configure()
Configure object from descriptor data.
Definition encoder.cxx:75
size_t getDataDim() const
Get data vector dimension.
Definition encoder.hxx:54
int trigger(uint8_t cmd)
Execute a trigger command.
Definition encoder.cxx:161
int init()
One-time initialize object after bindings are resolved.
Definition encoder.cxx:116
bool isNotify() const
Check if IO supports notifications.
Definition encoder.hxx:69
bool isBatch() const
Check if IO supports batch operations.
Definition encoder.hxx:74
int deinit()
De-initialize object.
Definition encoder.cxx:127
size_t getDataSize() const
Get data size in bytes.
Definition encoder.hxx:49
bool isWrite() const
Check if IO supports write operations.
Definition encoder.hxx:64
static ObjectCfgId objectCfg(uint8_t type, uint16_t cls, uint8_t dtype, bool rw, uint16_t size, uint8_t id)
Construct 32-bit ConfigID from component fields.
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
Definition objectcfg.hxx:60
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
@ OBJTYPE_IO
Input/Output object type.
Definition objectid.hxx:184
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
Definition objectid.hxx:96
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44