RDMnet  0.3.0
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) (&(controller_ptr)->rdm_handler.data)
98 
99 /******************************************************************************
100  * Device
101  *****************************************************************************/
102 
103 typedef enum
104 {
105  kDeviceEndpointTypeVirtual = 0,
106  kDeviceEndpointTypePhysical = 1
107 } device_endpoint_type_t;
108 
109 typedef struct EndpointResponder
110 {
111  EtcPalUuid rid;
112  RdmUid uid;
113  RdmUid binding_uid;
114  uint16_t control_field;
115 } EndpointResponder;
116 
117 typedef struct DeviceEndpoint
118 {
119  uint16_t id;
120  device_endpoint_type_t type;
121  uint32_t responder_list_change_number;
122  RC_DECLARE_BUF(EndpointResponder, responders, RDMNET_MAX_RESPONDERS_PER_DEVICE_ENDPOINT);
123 } DeviceEndpoint;
124 
125 #define DEVICE_ENDPOINT_INIT_RESPONDERS(endpoint_ptr, initial_capacity) \
126  RC_INIT_BUF(endpoint_ptr, EndpointResponder, responders, initial_capacity, RDMNET_MAX_RESPONDERS_PER_DEVICE_ENDPOINT)
127 #define DEVICE_ENDPOINT_DEINIT_RESPONDERS(endpoint_ptr) RC_DEINIT_BUF(endpoint_ptr, responders)
128 #define DEVICE_ENDPOINT_CHECK_RESPONDERS_CAPACITY(endpoint_ptr, num_additional) \
129  RC_CHECK_BUF_CAPACITY(endpoint_ptr, EndpointResponder, responders, RDMNET_MAX_RESPONDERS_PER_DEVICE_ENDPOINT, \
130  num_additional)
131 
132 typedef struct RdmnetDevice
133 {
134  RdmnetStructId id;
136  RdmnetDeviceCallbacks callbacks;
137  rdmnet_client_scope_t scope_handle;
138 
139  uint8_t* response_buf;
140 
141  uint32_t endpoint_list_change_number;
142  RC_DECLARE_BUF(DeviceEndpoint, endpoints, RDMNET_MAX_ENDPOINTS_PER_DEVICE);
143 
144  RCClient client;
145  bool connected_to_broker;
146  uint16_t manufacturer_id;
147 } RdmnetDevice;
148 
149 #define DEVICE_INIT_ENDPOINTS(device_ptr, initial_capacity) \
150  RC_INIT_BUF(device_ptr, DeviceEndpoint, endpoints, initial_capacity, RDMNET_MAX_ENDPOINTS_PER_DEVICE)
151 #define DEVICE_DEINIT_ENDPOINTS(device_ptr) RC_DEINIT_BUF(device_ptr, endpoints)
152 #define DEVICE_CHECK_ENDPOINTS_CAPACITY(device_ptr, num_additional) \
153  RC_CHECK_BUF_CAPACITY(device_ptr, DeviceEndpoint, endpoints, RDMNET_MAX_ENDPOINTS_PER_DEVICE, num_additional)
154 
155 /******************************************************************************
156  * LLRP Manager
157  *****************************************************************************/
158 
159 typedef struct LlrpManager
160 {
161  RdmnetStructId id;
163  LlrpManagerCallbacks callbacks;
164 
165  RCLlrpManager rc_manager;
166 } LlrpManager;
167 
168 /******************************************************************************
169  * LLRP Target
170  *****************************************************************************/
171 
172 typedef struct LlrpTarget
173 {
174  RdmnetStructId id;
176  LlrpTargetCallbacks callbacks;
177  uint8_t* response_buf;
178 
179  RCLlrpTarget rc_target;
180 } LlrpTarget;
181 
182 /******************************************************************************
183  * EPT client
184  *****************************************************************************/
185 
186 typedef struct RdmnetEptClient
187 {
188  RdmnetStructId id;
190  RdmnetEptClientCallbacks callbacks;
191 
192  RCClient client;
193  bool connected_to_broker;
194 } RdmnetEptClient;
195 
196 RdmnetController* rdmnet_alloc_controller_instance(void);
197 RdmnetDevice* rdmnet_alloc_device_instance(void);
198 LlrpManager* rdmnet_alloc_llrp_manager_instance(void);
199 LlrpTarget* rdmnet_alloc_llrp_target_instance(void);
200 RdmnetEptClient* rdmnet_alloc_ept_client_instance(void);
201 
202 void* rdmnet_find_struct_instance(int handle, rdmnet_struct_type_t type);
203 void rdmnet_unregister_struct_instance(void* instance);
204 void rdmnet_free_struct_instance(void* instance);
205 
206 #ifdef __cplusplus
207 }
208 #endif
209 
212 #endif /* RDMNET_COMMON_PRIV_H_ */
Definitions for the RDMnet Controller API.
Definitions for the RDMnet Device API.
Definitions for the RDMnet EPT Client API.
PLATFORM_DEFINED etcpal_mutex_t
int rdmnet_client_scope_t
A handle to a scope that an RDMnet client participates in.
Definition: client.h:41
#define RDMNET_MAX_RESPONDERS_PER_DEVICE_ENDPOINT
The maximum number of responders that can be added to each device endpoint.
Definition: opts.h:180
#define RDMNET_MAX_ENDPOINTS_PER_DEVICE
The maximum number of nonzero endpoints that can be added to each device instance.
Definition: opts.h:171
Functions for implementing LLRP Manager functionality.
Functions for implementing LLRP Target functionality.
T lock(T... args)
A set of notification callbacks received about an LLRP manager.
Definition: llrp_manager.h:84
A set of notification callbacks received about an LLRP target.
Definition: llrp_target.h:78
A set of notification callbacks received about a controller.
Definition: controller.h:151
A buffer and set of callbacks which can be optionally provided to handle RDM commands addressed to a ...
Definition: controller.h:192
A set of notification callbacks received about a device.
Definition: device.h:130
A set of notification callbacks received about an EPT client.
Definition: ept_client.h:136