lwpa  0.1.0
LightWeight Platform Abstraction (lwpa)
View other versions:
lwpa_cid.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_cid.h: A type and helper functions for the Component IDentifier (CID)
21  * used in the ACN family of protocols. */
22 #ifndef _LWPA_CID_H_
23 #define _LWPA_CID_H_
24 
25 #include <string.h>
26 #include "lwpa_int.h"
27 #include "lwpa_bool.h"
28 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
50 #define CID_BYTES 16u
51 
54 typedef struct LwpaCid
55 {
56  uint8_t data[CID_BYTES];
58 
66 #define cidcmp(cid1ptr, cid2ptr) memcmp((cid1ptr)->data, (cid2ptr)->data, CID_BYTES)
67 
69 extern const LwpaCid NULL_CID;
70 
78 #define cid_isnull(cidptr) (memcmp((cidptr)->data, NULL_CID.data, CID_BYTES) == 0)
79 
82 #define CID_STRING_BYTES 37
83 
84 void cid_to_string(char *buf, const LwpaCid *cid);
85 bool string_to_cid(LwpaCid *cid, const char *buf, size_t buflen);
86 
87 /************************ CID Generation Functions ***************************/
88 
89 void generate_cid(LwpaCid *cid, const char *devstr, const uint8_t *macaddr, uint32_t cidnum);
90 void generate_rdm_cid(LwpaCid *cid, const uint8_t *rdmuid);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
98 #endif /* _LWPA_CID_H_ */
bool string_to_cid(LwpaCid *cid, const char *buf, size_t buflen)
Create a CID from a string representation.
Definition: lwpa_cid.c:63
const LwpaCid NULL_CID
A null (all 0's) CID, used by cid_isnull() for comparison.
Definition: lwpa_cid.c:31
void generate_cid(LwpaCid *cid, const char *devstr, const uint8_t *macaddr, uint32_t cidnum)
Generate a CID from a combination of a custom string and MAC address.
Definition: lwpa_cid.c:141
void generate_rdm_cid(LwpaCid *cid, const uint8_t *rdmuid)
Generate a CID from an RDM UID.
Definition: lwpa_cid.c:182
void cid_to_string(char *buf, const LwpaCid *cid)
Create a string representation of a CID.
Definition: lwpa_cid.c:44
#define CID_BYTES
The number of bytes that make up a CID.
Definition: lwpa_cid.h:50
struct LwpaCid LwpaCid
The CID type.
The CID type.
Definition: lwpa_cid.h:55