Dawn Framework 1.0
Universal data acquisition framework for embedded systems
udp.cxx
1// dawn/src/proto/nxscope/udp.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/proto/nxscope/udp.hxx"
7
8#include "dawn/io/common.hxx"
9#include "dawn/io/sdata.hxx"
10
11using namespace dawn;
12
13int CProtoNxscopeUdp::configureDesc(const CDescObject &desc)
14{
16 size_t offset = 0;
17
18 for (size_t i = 0; i < desc.getSize(); i++)
19 {
20 item = desc.objectCfgItemNext(offset);
21
23 {
24 DAWNERR("unsupported nxscope cfg 0x08%" PRIx32 "\n", item->cfgid.v);
25 return -EINVAL;
26 }
27
28 switch (item->cfgid.s.id)
29 {
31 {
32 const size_t wpe = sizeof(SProtoNxscopeIOBind) / 4;
33 size_t j;
34
35 for (j = 0; j < item->cfgid.s.size; j++)
36 {
37 SProtoNxscopeIOBind *tmp =
38 reinterpret_cast<SProtoNxscopeIOBind *>(item->data + j * wpe);
39
40 allocObject(tmp);
41 }
42
43 break;
44 }
45
47 {
48 const size_t wpe = sizeof(SProtoNxscopeIOBind2) / 4;
49 const size_t entry_count = item->cfgid.s.size / wpe;
50 size_t j;
51
52 if (item->cfgid.s.size % wpe != 0)
53 {
54 DAWNERR("unsupported nxscope cfg 0x08%" PRIx32 "\n", item->cfgid.v);
55 return -EINVAL;
56 }
57
58 for (j = 0; j < entry_count; j++)
59 {
60 SProtoNxscopeIOBind2 *tmp =
61 reinterpret_cast<SProtoNxscopeIOBind2 *>(item->data + j * wpe);
62
63 allocObject(&tmp->bind);
64 allocNames(j, &tmp->name);
65 }
66
67 break;
68 }
69
71 {
72 port = static_cast<uint16_t>(item->data[0]);
73 break;
74 }
75
76 default:
77 {
78 DAWNERR("unsupported nxscope cfg 0x08%" PRIx32 "\n", item->cfgid.v);
79 return -EINVAL;
80 }
81 }
82 }
83
84 return OK;
85}
86
87int CProtoNxscopeUdp::confgureNxscopePriv()
88{
89 int ret;
90
91 nxsUdpCfg.port = port;
92 nxsUdpCfg.nonblock = NXSCOPE_RECV_NONBLOCK;
93
94 DAWNINFO("nxscope udp port = %u\n", nxsUdpCfg.port);
95
96 ret = nxscope_udp_init(&nxsIntf, &nxsUdpCfg);
97 if (ret != OK)
98 {
99 DAWNERR("nxscope_udp_init failed: %d\n", ret);
100 return ret;
101 }
102
103 return ret;
104}
105
106CProtoNxscopeUdp::~CProtoNxscopeUdp()
107{
108}
109
110int CProtoNxscopeUdp::initPriv()
111{
112 int ret;
113
114 ret = configureDesc(getDesc());
115 if (ret != OK)
116 {
117 return ret;
118 }
119
120 ret = confgureNxscopePriv();
121 if (ret != OK)
122 {
123 return ret;
124 }
125
126 ret = configureNxscope();
127 if (ret != OK)
128 {
129 return ret;
130 }
131
132 return OK;
133}
134
135int CProtoNxscopeUdp::deinitPriv()
136{
137 nxscope_udp_deinit(&nxsIntf);
138 return OK;
139}
140
141int CProtoNxscopeUdp::startPriv()
142{
143 return OK;
144}
145
146int CProtoNxscopeUdp::stopPriv()
147{
148 return OK;
149}
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemNext(size_t &offset) const
Get config item at current offset and advance past it.
CDescObject & getDesc()
Get descriptor object for this object.
Definition object.cxx:190
@ PROTO_CLASS_NXSCOPE_UDP
NxScope real-time visualization (UDP interface).
Definition common.hxx:51
@ PROTO_NXSCOPE_UDP_CFG_IOBIND2
I/O bindings with names.
Definition udp.hxx:22
@ PROTO_NXSCOPE_UDP_CFG_PORT
UDP local port.
Definition udp.hxx:23
@ PROTO_NXSCOPE_UDP_CFG_IOBIND
I/O bindings.
Definition udp.hxx:21
struct nxscope_intf_s nxsIntf
NXScope interface structure (from logging library).
Definition nxscope.hxx:79
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Single configuration item within object.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
Definition objectcfg.hxx:82
uint32_t cls
Object class (bits 21-29, max 511).
uint32_t id
Configuration identifier (bits 0-4, max 31).
Definition objectcfg.hxx:94
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.