Z-Wave Protocol Controller Reference
zwave_tx_incoming_frames.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * # License
3 * <b>Copyright 2022 Silicon Laboratories Inc. www.silabs.com</b>
4 ******************************************************************************
5 * The licensor of this software is Silicon Laboratories Inc. Your use of this
6 * software is governed by the terms of Silicon Labs Master Software License
7 * Agreement (MSLA) available at
8 * www.silabs.com/about-us/legal/master-software-license-agreement. This
9 * software is distributed to you in Source Code format and is governed by the
10 * sections of the MSLA applicable to Source Code.
11 *
12 *****************************************************************************/
13
23#ifndef ZWAVE_TX_INCOMING_FRAMES_HPP
24#define ZWAVE_TX_INCOMING_FRAMES_HPP
25
26// Includes from this component
27#include "zwave_tx.h"
28#include "priority_queue.hpp"
29
30// Includes from other components
32
33// Type definition for the number of frames to expect
34using number_of_frames_t = uint8_t;
35
40using zwave_tx_incoming_frame_item_t = struct zwave_tx_incoming_frame_item {
41 // Remote NodeID that will send us some frames in the near future
43 // Number of frames that we expect to receive from NodeID
45};
46
52 const zwave_tx_incoming_frame_item_t &rhs) const
53 {
54 return lhs.node_id > rhs.node_id;
55 }
56};
57
58// Class definition that keeps track of incoming frames
60{
61 private:
62 // List of frames that we expect from NodeIDs.
67
81 {
83 item.node_id = node_id;
84 item.incoming_frames = incoming_frames;
85 return (frame_list.insert(std::move(item)) == true ? SL_STATUS_OK
87 }
88
89 public:
100 {
101 for (auto it = frame_list.begin(); it != frame_list.end(); ++it) {
102 if (it->node_id == node_id) {
103 // Decrement
104 if (incoming_frames == 0) {
105 frame_list.erase(it);
106 return SL_STATUS_OK;
107 } else {
108 it->incoming_frames = incoming_frames;
109 return SL_STATUS_OK;
110 }
111 }
112 }
113
114 // We don't know about this NodeID. Insert it.
115 if (incoming_frames > 0) {
117 }
118
119 return SL_STATUS_NOT_FOUND;
120 }
121
130 {
131 for (auto it = frame_list.begin(); it != frame_list.end(); ++it) {
132 if (it->node_id == node_id) {
133 // Decrement
134 if (it->incoming_frames <= 1) {
135 frame_list.erase(it);
136 return SL_STATUS_OK;
137 } else {
138 it->incoming_frames -= 1;
139 return SL_STATUS_OK;
140 }
141 }
142 }
143 return SL_STATUS_NOT_FOUND;
144 }
145
153 {
154 for (auto it = frame_list.begin(); it != frame_list.end(); ++it) {
155 if (it->node_id == node_id) {
156 return it->incoming_frames;
157 }
158 }
159
160 // Not found, return no frame.
161 return 0;
162 }
163
167 void clear()
168 {
170 }
171
176 bool empty() const
177 {
178 return frame_list.empty();
179 }
180};
181
182#endif //ZWAVE_TX_INCOMING_FRAMES_HPP
Priority Queue.
Definition: priority_queue.hpp:56
constexpr iterator begin() noexcept
if queue != empty() it returns a pointer to the beginning of the queue. The item with the highest pri...
Definition: priority_queue.hpp:207
constexpr iterator end() noexcept
iterator that points past the last element in the queue.
Definition: priority_queue.hpp:217
constexpr void clear() noexcept
remove all items from the queue.
Definition: priority_queue.hpp:255
constexpr bool empty() const noexcept
returns if the queue is empty. in this case both begin() and end() point to nullptr
Definition: priority_queue.hpp:196
iterator erase(const_iterator iterator)
removes an item from the queue by iterator. Performance: O(log n)
Definition: priority_queue.hpp:147
bool insert(value_type &&item) noexcept
inserts a value into the queue. inserts are ordered by their priority. this function takes O(log n) t...
Definition: priority_queue.hpp:75
Definition: zwave_tx_incoming_frames.hpp:60
bool empty() const
Checks if we have any expected frame at all.
Definition: zwave_tx_incoming_frames.hpp:176
sl_status_t decrement_frames(zwave_node_id_t node_id)
Decrements the number of expected frames from a NodeID.
Definition: zwave_tx_incoming_frames.hpp:129
sl_status_t insert(zwave_node_id_t node_id, number_of_frames_t incoming_frames)
Helper function that inserts a NodeID / Frame pair in the frame list.
Definition: zwave_tx_incoming_frames.hpp:79
void clear()
Clears the entire list of expected frames.
Definition: zwave_tx_incoming_frames.hpp:167
sl_status_t set_frames(zwave_node_id_t node_id, number_of_frames_t incoming_frames)
Sets the number of expected frames from a NodeID.
Definition: zwave_tx_incoming_frames.hpp:98
number_of_frames_t get_frames(zwave_node_id_t node_id)
Gets the number of expected frames from a NodeID.
Definition: zwave_tx_incoming_frames.hpp:152
priority_queue< zwave_tx_incoming_frame_item_t, ZWAVE_TX_INCOMING_FRAMES_BUFFER_SIZE, incoming_frame_item_compare > frame_list
Definition: zwave_tx_incoming_frames.hpp:66
#define SL_STATUS_OK
No error.
Definition: sl_status.h:49
uint32_t sl_status_t
Definition: sl_status.h:139
#define SL_STATUS_FAIL
Generic error.
Definition: sl_status.h:50
#define SL_STATUS_NOT_FOUND
Item could not be found.
Definition: sl_status.h:100
uint16_t zwave_node_id_t
Z-Wave NodeID type.
Definition: zwave_node_id_definitions.h:84
uint8_t number_of_frames_t
Definition: zwave_tx_incoming_frames.hpp:34
number_of_frames_t incoming_frames
Definition: zwave_tx_incoming_frames.hpp:44
zwave_tx_incoming_frame_item { zwave_node_id_t node_id zwave_tx_incoming_frame_item_t
Keeps track of NodeIDs and their expected spontaneous frames.
Definition: zwave_tx_incoming_frames.hpp:42
Comparion function for zwave_tx_incoming_frame_item_t objects.
Definition: zwave_tx_incoming_frames.hpp:50
bool operator()(const zwave_tx_incoming_frame_item_t &lhs, const zwave_tx_incoming_frame_item_t &rhs) const
Definition: zwave_tx_incoming_frames.hpp:51
const zwave_node_id_t node_id
#define ZWAVE_TX_INCOMING_FRAMES_BUFFER_SIZE
Definition: zwave_tx.h:31