lwpa  0.1.0
LightWeight Platform Abstraction (lwpa)
View other versions:
lwpa_uid.h
1 /******************************************************************************
2  * Copyright 2018 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 lwpa. For more information, go to:
17  * https://github.com/ETCLabs/lwpa
18  ******************************************************************************/
19 
20 /* lwpa_uid.h: A type and helper functions for the Unique ID (UID) used in the
21  * RDM family of protocols. */
22 #ifndef _LWPA_UID_H_
23 #define _LWPA_UID_H_
24 
25 #include "lwpa_int.h"
26 
55 typedef struct LwpaUid
56 {
57  uint16_t manu;
58  uint32_t id;
60 
61 /*************************** UID Comparison Macros ***************************/
62 
70 #define uid_cmp(uidptr1, uidptr2) \
71  (((uidptr1)->manu == (uidptr2)->manu) ? ((int)(uidptr1)->id - (int)(uidptr2)->id) \
72  : ((int)(uidptr1)->manu - (int)(uidptr2)->manu))
73 
79 #define uid_equal(uidptr1, uidptr2) ((uidptr1)->manu == (uidptr2)->manu && (uidptr1)->id == (uidptr2)->id)
80 
81 /************************* UID Initialization Macros *************************/
82 
88 #define init_static_uid(uidptr, manu_val, id_val) \
89  do \
90  { \
91  (uidptr)->manu = (manu_val); \
92  (uidptr)->id = (id_val); \
93  } while (0)
94 
100 #define init_dynamic_uid(uidptr, manu_val, id_val) \
101  do \
102  { \
103  (uidptr)->manu = (0x8000u | (manu_val)); \
104  (uidptr)->id = (id_val); \
105  } while (0)
106 
107 /**************************** UID Broadcast Macros ***************************/
108 
114 #define uid_is_broadcast(uidptr) ((uidptr)->manu == kBroadcastUid.manu && (uidptr)->id == kBroadcastUid.id)
115 
121 #define uid_is_rdmnet_controller_broadcast(uidptr) \
122  ((uidptr)->manu == kRdmnetControllerBroadcastUid.manu && (uidptr)->id == kRdmnetControllerBroadcastUid.id)
123 
129 #define uid_is_rdmnet_device_broadcast(uidptr) \
130  ((uidptr)->manu == kRdmnetDeviceBroadcastUid.manu && (uidptr)->id == kRdmnetDeviceBroadcastUid.id)
131 
146 #define uid_is_rdmnet_device_manu_broadcast(uidptr) \
147  ((uidptr)->manu == kRdmnetControllerBroadcastUid.manu && (((uidptr)->id & 0xffffu) == 0xffffu))
148 
161 #define rdmnet_device_broadcast_manu_matches(uidptr, manu_val) (rdmnet_device_broadcast_manu_id(uidptr) == manu_val)
162 
173 #define rdmnet_device_broadcast_manu_id(uidptr) ((uint16_t)((uidptr)->id >> 16))
174 
175 /******************************* UID Inspection ******************************/
176 
183 #define uid_is_dynamic(uidptr) \
184  ((((uidptr)->manu & 0x8000u) != 0) && !uid_is_rdmnet_controller_broadcast(uidptr) && \
185  !uid_is_rdmnet_device_manu_broadcast(uidptr) && !uid_is_broadcast(uidptr))
186 
193 #define get_manufacturer_id(uidptr) ((uidptr)->manu & 0x7fffu)
194 
200 #define get_device_id(uidptr) ((uidptr)->id)
201 
202 #ifdef __cplusplus
203 extern "C" {
204 #endif
205 
208 extern const LwpaUid kBroadcastUid;
209 
212 
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
222 #endif /* _LWPA_UID_H_ */
const LwpaUid kRdmnetControllerBroadcastUid
A UID that is equal to RPT_ALL_CONTROLLERS as defined in ANSI E1.33.
Definition: lwpa_uid.c:22
const LwpaUid kBroadcastUid
A UID that is equal to BROADCAST_ALL_DEVICES_ID as defined in ANSI E1.20.
Definition: lwpa_uid.c:21
struct LwpaUid LwpaUid
The UID type.
const LwpaUid kRdmnetDeviceBroadcastUid
A UID that is equal to RPT_ALL_DEVICES as defined in ANSI E1.33.
Definition: lwpa_uid.c:23
The UID type.
Definition: lwpa_uid.h:56