OLE Developer Guide  Latest Git
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
rdm_util.h
Go to the documentation of this file.
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * rdm_util.h
17  * Copyright (C) 2015 Simon Newton
18  */
19 
30 #ifndef FIRMWARE_SRC_RDM_UTIL_H_
31 #define FIRMWARE_SRC_RDM_UTIL_H_
32 
33 #include <stdbool.h>
34 #include <stdint.h>
35 #include <string.h>
36 
37 #include "rdm.h"
38 #include "rdm_responder.h"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
50 static inline int RDMUtil_UIDCompare(const uint8_t *uid1, const uint8_t *uid2) {
51  return memcmp(uid1, uid2, UID_LENGTH);
52 }
53 
65 bool RDMUtil_RequiresAction(const uint8_t our_uid[UID_LENGTH],
66  const uint8_t uid[UID_LENGTH]);
67 
68 /*
69  * @brief Check if a UID is unicast.
70  * @param uid The destination UID to check.
71  * @returns true if the UIDs is unicast, false otherwise.
72  *
73  * This can be used to determine if we need to respond to a request. Unicast
74  * UIDs are ones that do not end in 0xffffffff.
75  */
76 bool RDMUtil_IsUnicast(const uint8_t uid[UID_LENGTH]);
77 
87 bool RDMUtil_VerifyChecksum(const uint8_t *frame, unsigned int size);
88 
95 int RDMUtil_AppendChecksum(uint8_t *frame);
96 
109 unsigned int RDMUtil_StringCopy(char *dst, unsigned int dest_size,
110  const char *src, unsigned int max_size);
111 
121 unsigned int RDMUtil_SafeStringLength(const char *str, unsigned int max_size);
122 
131 void RDMUtil_UpdateSensor(SensorData *sensor, uint8_t recorded_value_support,
132  int16_t new_value);
133 
134 #ifdef __cplusplus
135 }
136 #endif
137 
142 #endif // FIRMWARE_SRC_RDM_UTIL_H_
unsigned int RDMUtil_SafeStringLength(const char *str, unsigned int max_size)
Calculate the size of the string, but never scan beyond max_size.
bool RDMUtil_VerifyChecksum(const uint8_t *frame, unsigned int size)
Verify the checksum of an RDM frame.
The base RDM Responder.
Remote Device Management.
void RDMUtil_UpdateSensor(SensorData *sensor, uint8_t recorded_value_support, int16_t new_value)
Update the value of a sensor, setting the lowest / highest values if appropriate. ...
Data for an RDM Sensor.
Definition: rdm_responder.h:213
static int RDMUtil_UIDCompare(const uint8_t *uid1, const uint8_t *uid2)
Compare two UIDs.
Definition: rdm_util.h:50
unsigned int RDMUtil_StringCopy(char *dst, unsigned int dest_size, const char *src, unsigned int max_size)
Copy a string from one location to another.
int RDMUtil_AppendChecksum(uint8_t *frame)
Append the RDM checksum for a frame.
bool RDMUtil_RequiresAction(const uint8_t our_uid[UID_LENGTH], const uint8_t uid[UID_LENGTH])
Check if a RDM request sent to a UID requires us to take action.