31 return ((val >> 8) & 0xFF) | ((val & 0xFF) << 8);
42 return ((val >> 24) & 0xFF) | ((val >> 8) & 0xFF00) | ((val & 0xFF00) << 8) | ((val & 0xFF) << 24);
50#define CS_ROUND_UP_TO_MULTIPLE_OF(num, multiple) (((num + multiple - 1) / multiple) * multiple)
56#define CS_ROUND_UP_TO_MULTIPLE_OF_POWER_OF_2(num, multiple) ((num + multiple - 1) & -multiple)
63template <
class T,
size_t N>
70 _logArray(verbosity, addNewLine, arr, len,
"",
"",
"%02X",
":",
true);
73inline void print_heap([[maybe_unused]]
const std::string& msg) {
74 uint8_t* p = (uint8_t*)malloc(128);
75 LOGd(
"%s %p", msg.c_str(), p);
79inline void print_stack([[maybe_unused]]
const std::string& msg) {
81 asm(
"mov %0, sp" :
"=r"(sp) : :);
82 LOGd(
"%s %p", msg.c_str(), (uint8_t*)sp);
86inline bool isBitSet(
const T value, uint8_t bit) {
87 return value & (1 << bit);
91inline bool setBit(T& value, uint8_t bit) {
92 return value |= (1 << bit);
97 return value &= ~(1 << bit);
114 T numBits =
sizeof(T) * 8;
115 for (T i = 0; i < numBits; i++) {
127inline bool isNewer(uint8_t previousValue, uint8_t newValue) {
128 int8_t diff = newValue - previousValue;
147 foundData->
data =
nullptr;
149 while (index < advLen - 1) {
150 uint8_t fieldLen = advData[index];
151 uint8_t fieldType = advData[index + 1];
153 if (fieldLen == 0 || index + 1 + fieldLen > advLen) {
157 if (fieldType == type) {
158 foundData->
data = &advData[index + 2];
159 foundData->
len = fieldLen - 1;
162 index += fieldLen + 1;
175constexpr uint16_t
stringLen(
const char* str, uint16_t maxSize) {
177 while ((str[size] !=
'\0') && (size < maxSize)) {
@ ERR_NOT_FOUND
Definition: cs_ErrorCodes.h:24
@ ERR_SUCCESS
Definition: cs_ErrorCodes.h:10
#define _logArray(level, addNewLine, pointer,...)
Definition: cs_LogBinaryProtocol.h:128
#define LOGd(fmt,...)
Definition: cs_Logger.h:90
#define SERIAL_DEBUG
Definition: cs_SerialTypes.h:24
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 29,...
uint16_t convertEndian16(uint16_t val)
Convert a short (uint16_t) from LSB (little-endian) to MSB (big-endian) and vice versa.
Definition: cs_Utils.h:30
bool isBitSet(const T value, uint8_t bit)
Definition: cs_Utils.h:86
bool isNewer(uint8_t previousValue, uint8_t newValue)
Returns true when newValue is newer than previousValue, for a value that is increased all the time an...
Definition: cs_Utils.h:127
void print_stack(const std::string &msg)
Definition: cs_Utils.h:79
constexpr uint16_t stringLen(const char *str, uint16_t maxSize)
Gets the string length of a null terminated constant string.
Definition: cs_Utils.h:175
void printAddress(T *arr, uint16_t len, uint8_t verbosity=SERIAL_DEBUG, bool addNewLine=true)
Definition: cs_Utils.h:69
uint32_t getInterruptLevel()
Definition: cs_Utils.h:183
constexpr T lowestBitSet(T value)
Returns the index of the lowest bit set in given value.
Definition: cs_Utils.h:112
bool setBit(T &value, uint8_t bit)
Definition: cs_Utils.h:91
void print_heap(const std::string &msg)
Definition: cs_Utils.h:73
bool clearBit(T &value, uint8_t bit)
Definition: cs_Utils.h:96
uint32_t convertEndian32(uint32_t val)
Convert an integer (uint32_t) from LSB (little-endian) to MSB (big-endian) and vice versa.
Definition: cs_Utils.h:41
static cs_ret_code_t findAdvType(uint8_t type, uint8_t *advData, uint8_t advLen, cs_data_t *foundData)
Parses advertisement data, providing length and location of the field in case matching data is found.
Definition: cs_Utils.h:145
constexpr auto ArraySize(T(&)[N])
Get number of items in an array.
Definition: cs_Utils.h:64
Packets (structs) that are used internally in the firmware, and can be changed freely.
Definition: cs_PacketsInternal.h:27
cs_buffer_size_t len
< Pointer to data.
Definition: cs_PacketsInternal.h:29
buffer_ptr_t data
Definition: cs_PacketsInternal.h:28