deCONZ C++ API v2.6.1
Loading...
Searching...
No Matches
node.h
1#ifndef DECONZ_NODE_H
2#define DECONZ_NODE_H
3
4/*
5 * Copyright (c) 2012-2023 dresden elektronik ingenieurtechnik gmbh.
6 * All rights reserved.
7 *
8 * The software in this package is published under the terms of the BSD
9 * style license a copy of which has been included with this distribution in
10 * the LICENSE.txt file.
11 *
12 */
13
14#include <vector>
15#include <deconz/types.h>
16#include <deconz/aps.h>
17#include <deconz/binding_table.h>
18#include <deconz/zdp_descriptors.h>
19
20namespace deCONZ
21{
22
23class DECONZ_DLLSPEC NodeNeighbor
24{
25public:
26 NodeNeighbor() : m_lqi(0) {}
27 NodeNeighbor(const Address &addr, quint8 lqi): m_address(addr), m_lqi(lqi) { }
28 const Address &address() const { return m_address; }
29 quint8 lqi() const { return m_lqi; }
30
31private:
32 Address m_address;
33 quint8 m_lqi;
34};
35
36inline uint SR_HashUuid(const QString &uuid)
37{
38 return qHash(uuid);
39}
40
41class DECONZ_DLLSPEC SourceRoute
42{
43public:
44 enum Constants { MaxHops = 9 };
45 enum State { StateIdle, StateWorking, StateSleep };
46
47 SourceRoute(const QString &uuid, const int order, const std::vector<Address> &hops) :
48 m_uuid(uuid),
49 m_order(order),
50 m_hops(hops)
51 {
52 m_srHash = qHash(uuid);
53 }
54
55 bool operator==(const SourceRoute &other) const
56 {
57 bool eqLqi = true;
58 for (size_t i = 0; i < MaxHops && i < m_hops.size(); i++)
59 {
60 if (m_hopLqi[i] != other.m_hopLqi[i])
61 {
62 eqLqi = false;
63 break;
64 }
65 }
66 return m_srHash == other.uuidHash() &&
67 m_txOk == other.txOk() &&
68 m_errors == other.errors() &&
69 m_hops == other.hops() &&
70 eqLqi;
71 }
72
73 bool operator!=(const SourceRoute &other) const
74 {
75 return !(*this == other);
76 }
77
78 bool isValid() const { return m_srHash != 0 && !m_hops.empty(); }
79 bool isOperational() const;
80 const QString &uuid() const { return m_uuid; }
81 uint uuidHash() const { return m_srHash; }
83 const std::vector<Address> &hops() const { return m_hops; }
85 int order() const { return m_order; }
86 void addHop(const deCONZ::Address &hop, quint8 lqi);
87 bool hasHop(const deCONZ::Address &hop) const;
88 void updateHopAddress(const deCONZ::Address &hop);
89 size_t errors() const { return m_errors; }
90 void incrementErrors();
91 size_t txOk() const { return m_txOk; }
92 void incrementTxOk();
93 State state() const { return m_state; }
94 void setState(State state) { m_state = state; }
95 bool needSave() const { return m_needSave; }
96 void saved() { m_needSave = false; }
97
98 quint8 m_hopLqi[MaxHops] = { };
99
100private:
101 bool m_needSave = false;
102 State m_state = StateIdle;
103 QString m_uuid;
104 int m_order = 0;
105 size_t m_txOk = 0;
106 size_t m_errors = 0;
107 uint m_srHash = 0;
108 std::vector<Address> m_hops;
109};
110
111class NodePrivate;
112
118class DECONZ_DLLSPEC Node
119{
120public:
122 Node();
124 Node(const Node &other);
126 Node& operator=(const Node &other);
128 virtual ~Node();
130 virtual CommonState state() const = 0;
132 const deCONZ::Address &address() const;
134 bool isCoordinator() const;
136 bool isRouter() const;
138 bool isEndDevice() const;
140 bool isZombie() const;
142 void setIsZombie(bool isZombie);
144 const QString &userDescriptor() const;
148 void setUserDescriptor(const QString &userDescriptor);
150 QString deviceTypeString();
152 const std::vector<uint8_t> &endpoints() const;
154 void setActiveEndpoints(const std::vector<uint8_t> &ep);
160 SimpleDescriptor *getSimpleDescriptor(uint8_t endpoint);
165 bool setSimpleDescriptor(const SimpleDescriptor &descr);
167 std::vector<SimpleDescriptor> &simpleDescriptors();
169 const std::vector<SimpleDescriptor> &simpleDescriptors() const;
177 int copySimpleDescriptor(uint8_t endpoint, SimpleDescriptor *descr) const;
179 const NodeDescriptor & nodeDescriptor() const;
183 void setNodeDescriptor(const NodeDescriptor &descr);
185 const PowerDescriptor &powerDescriptor() const;
189 void setPowerDescriptor(const PowerDescriptor &descr);
191 const MacCapabilities &macCapabilities() const;
195 void setMacCapabilities(MacCapabilities cap);
197 void resetAll();
199 virtual const std::vector<NodeNeighbor> &neighbors() const = 0;
201 const std::vector<SourceRoute> &sourceRoutes() const;
209 int addSourceRoute(const SourceRoute &sourceRoute);
216 bool updateSourceRoute(const SourceRoute &sourceRoute);
221 int removeSourceRoute(uint srHash);
223 virtual const BindingTable &bindingTable() const = 0;
224
225 void pushEdScan(int ed);
226 int edScanValue() const;
227 bool needRedraw() const;
228 void setNeedRedraw(bool redraw);
229
230protected:
231 NodePrivate *d_ptr = nullptr;
232 Q_DECLARE_PRIVATE(Node)
233};
234
235}
236
237#endif // DECONZ_NODE_H
Convenience class to work with network, extended and group addresses.
Definition aps.h:111
Definition binding_table.h:82
Represents a ZigBee node descriptor.
Definition zdp_descriptors.h:109
Definition node.h:24
Definition node_private.h:17
Represents a ZigBee node with all its descriptors and clusters.
Definition node.h:119
virtual const std::vector< NodeNeighbor > & neighbors() const =0
Returns all neighbors of the node.
virtual CommonState state() const =0
Returns the current node state.
virtual const BindingTable & bindingTable() const =0
Returns the binding table of a node.
Represents a ZigBee power descriptor.
Definition zdp_descriptors.h:212
Represents a ZigBee simple descriptor.
Definition zdp_descriptors.h:254
Definition node.h:42
const std::vector< Address > & hops() const
The last hop in the list is the destination node.
Definition node.h:83
int order() const
A lower order means a higher priority for the source route.
Definition node.h:85
The deCONZ namespace.
Definition aps.cpp:19
State
The state of a device or node.
Definition types.h:376
CommonState
Common states for various purposes.
Definition types.h:400
Declaration of the most common deCONZ library types.