Dawn Framework 1.0
Universal data acquisition framework for embedded systems
nxscope.hxx
1// dawn/include/dawn/proto/nxscope/nxscope.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include "dawn/common/thread.hxx"
9#include "dawn/porting/config.hxx"
10#include "dawn/proto/common.hxx"
11#include "logging/nxscope/nxscope.h"
12#include <cstddef>
13
14// Recv is non blocking and uses usleep.
15// TODO: blocking recv doesn't work for some reason - investigate per
16// transport (UDP/serial). Until resolved, NXSCOPE_RECV_NONBLOCK is
17// required to keep threadRecv() responsive to stop requests.
18
19#define NXSCOPE_RECV_NONBLOCK (1)
20
21namespace dawn
22{
23// Forward declaration
24
25class IIOCommon;
26class CIOCommon;
27struct io_ddata_t;
28
37{
38public:
39 struct
40 {
42 } typedef SProtoNxscopeIOBind;
43
44 struct
45 {
46 const char name[12];
47 } typedef SProtoNxscopeNames;
48
49 struct
50 {
51 SProtoNxscopeIOBind bind;
52 SProtoNxscopeNames name;
53 } typedef SProtoNxscopeIOBind2;
54
55 explicit CProtoNxscope(CDescObject &desc)
56 : CProtoCommon(desc)
57 , nxsIntf()
58 , threadRecvMember()
59#ifdef CONFIG_DAWN_PROTO_NXSCOPE_SAMPLE_THREAD
60 , threadSampleMember()
61#endif
62 , nxs()
63 , nxsCfg()
64 , nxsProto()
65 , nxsCbs()
66 {
67 }
68
69 ~CProtoNxscope() override;
70
71 int configure() override;
72 int init() override;
73 int deinit() override;
74 int doStart() override;
75 int doStop() override;
76 bool hasThread() const override;
77
78protected:
79 struct nxscope_intf_s nxsIntf;
80
81 int allocObject(SProtoNxscopeIOBind *alloc);
82 int allocNames(size_t j, SProtoNxscopeNames *names);
83 int configureNxscope();
84
85 virtual int initPriv() = 0;
86 virtual int deinitPriv() = 0;
87 virtual int startPriv() = 0;
88 virtual int stopPriv() = 0;
89
90private:
91#ifdef CONFIG_DAWN_IO_NOTIFY
92 typedef int (*nxscope_put_cb_t)(struct nxscope_s *nxs, uint8_t chan, void *data, uint8_t dim);
93#endif
94
95#ifdef CONFIG_DAWN_PROTO_NXSCOPE_SAMPLE_THREAD
96 struct proto_nxscope_iochan_s;
97
98 typedef int (*nxscope_sample_cb_t)(CProtoNxscope *obj, struct proto_nxscope_iochan_s *iochan);
99#endif
100
101 struct proto_nxscope_iochan_s
102 {
103 uint8_t chan;
104 uint8_t dim;
105 bool stream;
106 CIOCommon *io;
107 CProtoNxscope *obj;
108 io_ddata_t *setData;
109
110#ifdef CONFIG_DAWN_IO_NOTIFY
111 nxscope_put_cb_t put;
112#endif
113
114#ifdef CONFIG_DAWN_PROTO_NXSCOPE_SAMPLE_THREAD
115 nxscope_sample_cb_t sample;
116 io_ddata_t *data;
117#endif
118 } typedef SProtoNxscopeIochan;
119
120 enum
121 {
122 NXSCOPE_USER_SET_IO = NXSCOPE_HDRID_USER,
123 NXSCOPE_USER_SET_IO_SEEK = NXSCOPE_HDRID_USER + 1
124 };
125
126 CThreadedObject threadRecvMember;
127
128#ifdef CONFIG_DAWN_PROTO_NXSCOPE_SAMPLE_THREAD
129 CThreadedObject threadSampleMember;
130#endif
131
132 struct nxscope_s nxs;
133 struct nxscope_cfg_s nxsCfg;
134 struct nxscope_proto_s nxsProto;
135 struct nxscope_callbacks_s nxsCbs;
136
137 std::vector<const SProtoNxscopeIOBind *> vchannels;
138 std::vector<const SProtoNxscopeNames *> vnames;
139 std::vector<SProtoNxscopeIochan> vio;
140 bool hasStreamChannels = false;
141
142 SProtoNxscopeIochan *findIochan(SObjectId::ObjectId objid);
143
144 int handleUserCommand(uint8_t id, uint8_t *buff);
145 int userSetIO(uint8_t *buff);
146 int userSetIOSeek(uint8_t *buff);
147 int sendAck(int ret);
148
149 static int userIdCb(void *priv, uint8_t id, uint8_t *buff);
150
151#ifdef CONFIG_DAWN_IO_NOTIFY
152 static int ioNotifierCb(void *priv, io_ddata_t *data);
153#endif
154
155 uint8_t getChannelDim(const CIOCommon &io);
156 uint8_t getChannelDtype(const CIOCommon &io);
157 int nxscopeChannelsCreate();
158 int bindChannelCallbacks(SProtoNxscopeIochan &iochan, uint8_t dtype);
159
160#ifdef CONFIG_DAWN_IO_NOTIFY
161 static int putInt32(struct nxscope_s *nxs, uint8_t chan, void *data, uint8_t dim);
162 static int putUint32(struct nxscope_s *nxs, uint8_t chan, void *data, uint8_t dim);
163 static int putUint64(struct nxscope_s *nxs, uint8_t chan, void *data, uint8_t dim);
164 static int putFloat(struct nxscope_s *nxs, uint8_t chan, void *data, uint8_t dim);
165#endif
166
167#ifdef CONFIG_DAWN_PROTO_NXSCOPE_SAMPLE_THREAD
168 void getAndPut(SProtoNxscopeIochan *iochan);
169
170 static int sampleInt32(CProtoNxscope *obj, SProtoNxscopeIochan *iochan);
171 static int sampleUint32(CProtoNxscope *obj, SProtoNxscopeIochan *iochan);
172 static int sampleUint64(CProtoNxscope *obj, SProtoNxscopeIochan *iochan);
173 static int sampleFloat(CProtoNxscope *obj, SProtoNxscopeIochan *iochan);
174#endif
175
176 void threadRecv();
177
178#ifdef CONFIG_DAWN_PROTO_NXSCOPE_SAMPLE_THREAD
179 void threadSample();
180#endif
181};
182} // Namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
Definition common.hxx:27
Base class for all protocol implementations.
Definition common.hxx:23
Real-time data visualization protocol (base class).
Definition nxscope.hxx:37
int doStop()
Stop implementation hook.
Definition nxscope.cxx:970
bool hasThread() const
Check if a background thread is active.
Definition nxscope.cxx:991
struct nxscope_intf_s nxsIntf
NXScope interface structure (from logging library).
Definition nxscope.hxx:79
int configure()
Configure object from descriptor data.
Definition nxscope.cxx:878
int doStart()
Start implementation hook.
Definition nxscope.cxx:910
int init()
One-time initialize object after bindings are resolved.
Definition nxscope.cxx:891
int deinit()
De-initialize object.
Definition nxscope.cxx:897
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44
Heap-allocated dynamic I/O data buffer.
Definition ddata.hxx:21
32-bit encoded object identifier (union with bit field).
Definition objectid.hxx:218