supla-device
Loading...
Searching...
No Matches
tools.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_TOOLS_H_
5#define SRC_SUPLA_TOOLS_H_
6
7#include <stddef.h>
8#include <stdint.h>
9#include "definitions.h"
10
11void float2DoublePacked(float number, uint8_t *bar, int byteOrder = LSBFIRST);
12float doublePacked2float(uint8_t *bar);
13
14int64_t adjustRange(int64_t input,
15 int64_t inMin,
16 int64_t inMax,
17 int64_t outMin,
18 int64_t outMax);
19
20bool isArrayEmpty(void* array, size_t arraySize);
21
22// Converts inputLength bytes from input to HEX and adds bytes separator
23// if required.
24// output buffor has to be at least (2 * inputLength + 1) bytes long without
25// separator, or: (3 * inputLength) bytes long with separator.
26// Trailing '\0' is added.
27// Returns amount of non-null chars written.
28int generateHexString(const void *input,
29 char *output,
30 int inputLength,
31 char separator = 0);
32
33// Converts hex byte string value to integer.
34// Returns false when input contains invalid hex characters.
35bool hexByteToInt(const char *str, uint8_t *result);
36
37// Converts hex string to array of bytes.
38// Returns false when input contains invalid hex characters.
39bool hexStringToArray(const char *input, char *output, int outputLength);
40
41// Converts decimal string value to unsigned integer
42uint32_t stringToUInt(const char *str, int len = -1);
43
44// Converts decimal string value to signed integer
45int32_t stringToInt(const char *str, int len = -1);
46
47// Convers float value from string to integer with given precision
48int32_t floatStringToInt(const char *str, int precision);
49
50// Converts "230,12,43" string to RGB values. Returns false on error
51bool stringToColor(const char *payload,
52 uint8_t *red,
53 uint8_t *green,
54 uint8_t *blue);
55
56// Decode url string from buffer into buffer (inplace)
57// Replace '+' with ' '.
58// Replace %xy with proper byte.
59// If not complete % parameter is found at the end, then it is omitted.
60// Returns false when invalid hex escape is found.
61bool urlDecodeInplace(char *buffer, int size);
62
63// Encode url string from input to output
64// Returns number of non-null bytes added to output
65int urlEncode(const char *input, char *output, int outputMaxSize);
66
67int stringAppend(char *output, const char *input, int maxSize);
68
69int strncmpInsensitive(const char *s1, const char *s2, int size);
70
71// This method should be implemented in platform specific cpp file
72void deviceSoftwareReset();
73bool isDeviceSoftwareResetSupported();
74bool isLastResetSoft();
75
76const char *getManufacturer(int16_t id);
77
78namespace Supla {
79int getPlatformId();
80int getBitNumber(uint64_t value);
81int rssiToSignalStrength(int rssi, int rssiZero = -100);
82bool isLastResetPower();
83
84const char *getRelayChannelName(int channelFunction);
85const char *getBinarySensorChannelName(int channelFunction);
86
92bool isLittleEndian();
93
102int compareSemVer(const char *sw1, const char *sw2);
103
110#ifndef ARDUINO_ARCH_AVR
111void fillRandom(uint8_t *buffer, int size);
112#endif
113
114} // namespace Supla
115
116
117#endif // SRC_SUPLA_TOOLS_H_