RDMnet  HEAD (unstable)
Implementation of ANSI E1.33 (RDMnet)
View other versions:
common_priv.h
1 /******************************************************************************
2  * Copyright 2020 ETC Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************
16  * This file is a part of RDMnet. For more information, go to:
17  * https://github.com/ETCLabs/RDMnet
18  *****************************************************************************/
19 
20 #ifndef RDMNET_COMMON_PRIV_H_
21 #define RDMNET_COMMON_PRIV_H_
22 
23 #include "rdmnet/controller.h"
24 #include "rdmnet/core/client.h"
25 #include "rdmnet/core/llrp_manager.h"
26 #include "rdmnet/core/llrp_target.h"
27 #include "rdmnet/core/util.h"
28 #include "rdmnet/device.h"
29 #include "rdmnet/ept_client.h"
30 #include "rdmnet/llrp_manager.h"
31 #include "rdmnet/llrp_target.h"
32 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 typedef void (*RdmnetStructCleanupFunction)(void* instance);
40 
41 typedef enum
42 {
43  kRdmnetStructTypeController,
44  kRdmnetStructTypeDevice,
45  kRdmnetStructTypeLlrpManager,
46  kRdmnetStructTypeLlrpTarget,
47  kRdmnetStructTypeEptClient,
48 } rdmnet_struct_type_t;
49 
50 typedef struct RdmnetStructId
51 {
52  int handle;
53  rdmnet_struct_type_t type;
54  RdmnetStructCleanupFunction cleanup_fn;
55 } RdmnetStructId;
56 
57 /******************************************************************************
58  * Controller
59  *****************************************************************************/
60 
61 typedef enum
62 {
63  kRdmHandleMethodUseCallbacks,
64  kRdmHandleMethodUseData
65 } rdm_handle_method_t;
66 
67 #define CONTROLLER_RDM_LABEL_BUF_LENGTH 33
68 
69 typedef struct ControllerRdmDataInternal
70 {
71  uint16_t model_id;
72  uint16_t product_category;
73  uint32_t software_version_id;
74  char manufacturer_label[CONTROLLER_RDM_LABEL_BUF_LENGTH];
75  char device_model_description[CONTROLLER_RDM_LABEL_BUF_LENGTH];
76  char software_version_label[CONTROLLER_RDM_LABEL_BUF_LENGTH];
77  char device_label[CONTROLLER_RDM_LABEL_BUF_LENGTH];
78  bool device_label_settable;
79 } ControllerRdmDataInternal;
80 
81 typedef struct RdmnetController
82 {
83  RdmnetStructId id;
85  RdmnetControllerCallbacks callbacks;
86 
87  rdm_handle_method_t rdm_handle_method;
88  union
89  {
91  ControllerRdmDataInternal data;
92  } rdm_handler;
93 
94  RCClient client;
95 } RdmnetController;
96 
97 #define CONTROLLER_RDM_DATA(controller_ptr) \
98  (RDMNET_ASSERT_VERIFY(controller_ptr) ? &(controller_ptr)->rdm_handler.data : NULL)
99 
100 /******************************************************************************
101  * Device
102  *****************************************************************************/
103 
104 typedef enum
105 {
106  kDeviceEndpointTypeVirtual = 0,
107  kDeviceEndpointTypePhysical = 1
108 } device_endpoint_type_t;
109 
110 typedef struct EndpointResponder
111 {
112  EtcPalUuid rid;
113  RdmUid uid;
114  RdmUid binding_uid;
115  uint16_t control_field;
116 } EndpointResponder;
117 
118 typedef struct DeviceEndpoint
119 {
120  uint16_t id;
121  device_endpoint_type_t type;
122  uint32_t responder_list_change_number;
123  EtcPalRbTree responders;
124 } DeviceEndpoint;
125 
126 #define DEVICE_ENDPOINT_INIT_RESPONDER_REFS(endpoint_ptr, initial_capacity) TODO_REMOVE
127 #define DEVICE_ENDPOINT_DEINIT_RESPONDER_REFS(endpoint_ptr) TODO_REMOVE
128 
129 typedef struct RdmnetDevice
130 {
131  RdmnetStructId id;
133  RdmnetDeviceCallbacks callbacks;
134  rdmnet_client_scope_t scope_handle;
135 
136  uint8_t* response_buf;
137 
138  uint32_t endpoint_list_change_number;
139  RC_DECLARE_BUF(DeviceEndpoint, endpoints, RDMNET_MAX_ENDPOINTS_PER_DEVICE);
140 
141  RCClient client;
142  bool connected_to_broker;
143  uint16_t manufacturer_id;
144 } RdmnetDevice;
145 
146 #define DEVICE_INIT_ENDPOINTS(device_ptr, initial_capacity) \
147  (RDMNET_ASSERT_VERIFY(device_ptr) && \
148  RC_INIT_BUF(device_ptr, DeviceEndpoint, endpoints, initial_capacity, RDMNET_MAX_ENDPOINTS_PER_DEVICE))
149 #define DEVICE_DEINIT_ENDPOINTS(device_ptr) \
150  if (RDMNET_ASSERT_VERIFY(device_ptr)) \
151  { \
152  RC_DEINIT_BUF(device_ptr, endpoints); \
153  }
154 #define DEVICE_CHECK_ENDPOINTS_CAPACITY(device_ptr, num_additional) \
155  (RDMNET_ASSERT_VERIFY(device_ptr) && \
156  RC_CHECK_BUF_CAPACITY(device_ptr, DeviceEndpoint, endpoints, RDMNET_MAX_ENDPOINTS_PER_DEVICE, num_additional))
157 
158 #define DEVICE_INIT_RESPONDERS(device_ptr, initial_capacity) TODO_REMOVE
159 #define DEVICE_DEINIT_RESPONDERS(device_ptr) TODO_REMOVE
160 #define DEVICE_CHECK_RESPONDERS_CAPACITY(device_ptr, endpoint_ptr, num_additional) TODO_REMOVE
161 
162 /******************************************************************************
163  * LLRP Manager
164  *****************************************************************************/
165 
166 typedef struct LlrpManager
167 {
168  RdmnetStructId id;
170  LlrpManagerCallbacks callbacks;
171 
172  RCLlrpManager rc_manager;
173 } LlrpManager;
174 
175 /******************************************************************************
176  * LLRP Target
177  *****************************************************************************/
178 
179 typedef struct LlrpTarget
180 {
181  RdmnetStructId id;
183  LlrpTargetCallbacks callbacks;
184  uint8_t* response_buf;
185 
186  RCLlrpTarget rc_target;
187 } LlrpTarget;
188 
189 /******************************************************************************
190  * EPT client
191  *****************************************************************************/
192 
193 typedef struct RdmnetEptClient
194 {
195  RdmnetStructId id;
197  RdmnetEptClientCallbacks callbacks;
198 
199  RCClient client;
200  bool connected_to_broker;
201 } RdmnetEptClient;
202 
203 RdmnetController* rdmnet_alloc_controller_instance(void);
204 RdmnetDevice* rdmnet_alloc_device_instance(void);
205 LlrpManager* rdmnet_alloc_llrp_manager_instance(void);
206 LlrpTarget* rdmnet_alloc_llrp_target_instance(void);
207 RdmnetEptClient* rdmnet_alloc_ept_client_instance(void);
208 
209 void* rdmnet_find_struct_instance(int handle, rdmnet_struct_type_t type);
210 void rdmnet_unregister_struct_instance(void* instance);
211 void rdmnet_free_struct_instance(void* instance);
212 
213 void rdmnet_init_endpoints(DeviceEndpoint* endpoints, size_t num_endpoints);
214 void rdmnet_deinit_endpoints(DeviceEndpoint* endpoints, size_t num_endpoints);
215 
216 etcpal_error_t rdmnet_add_static_responders(RdmnetDevice* device,
217  DeviceEndpoint* endpoint,
218  const RdmUid* uids,
219  size_t num_uids);
220 etcpal_error_t rdmnet_add_dynamic_responders(RdmnetDevice* device,
221  DeviceEndpoint* endpoint,
222  uint16_t manufacturer_id,
223  const EtcPalUuid* rids,
224  size_t num_rids);
225 etcpal_error_t rdmnet_add_physical_responders(RdmnetDevice* device,
226  DeviceEndpoint* endpoint,
227  const RdmnetPhysicalEndpointResponder* responders,
228  size_t num_responders);
229 
230 EndpointResponder* rdmnet_find_responder_by_rid(DeviceEndpoint* endpoint, const EtcPalUuid* rid);
231 EndpointResponder* rdmnet_find_responder_by_uid(DeviceEndpoint* endpoint, const RdmUid* uid);
232 
233 void rdmnet_remove_responders_by_rid(DeviceEndpoint* endpoint, const EtcPalUuid* rids, size_t num_rids);
234 void rdmnet_remove_responders_by_uid(DeviceEndpoint* endpoint, const RdmUid* uids, size_t num_uids);
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 
242 #endif /* RDMNET_COMMON_PRIV_H_ */
Definitions for the RDMnet Controller API.
Definitions for the RDMnet Device API.
Definitions for the RDMnet EPT Client API.
etcpal_error_t
PLATFORM_DEFINED etcpal_mutex_t
int rdmnet_client_scope_t
Definition: client.h:41
#define RDMNET_MAX_ENDPOINTS_PER_DEVICE
The maximum number of nonzero endpoints that can be added to each device instance.
Definition: opts.h:193
Functions for implementing LLRP Manager functionality.
Functions for implementing LLRP Target functionality.
T lock(T... args)
Definition: llrp_manager.h:84
Definition: llrp_target.h:78
Definition: controller.h:153
Definition: controller.h:194
Definition: device.h:131
Definition: ept_client.h:136
Definition: device.h:182