supla-device
Toggle main menu visibility
Loading...
Searching...
No Matches
src
supla
tools.h
1
/*
2
Copyright (C) AC SOFTWARE SP. Z O.O.
3
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
*/
18
19
#ifndef SRC_SUPLA_TOOLS_H_
20
#define SRC_SUPLA_TOOLS_H_
21
22
#include <stddef.h>
23
#include <stdint.h>
24
#include "definitions.h"
25
26
void
float2DoublePacked(
float
number, uint8_t *bar,
int
byteOrder = LSBFIRST);
27
float
doublePacked2float(uint8_t *bar);
28
29
int64_t adjustRange(int64_t input,
30
int64_t inMin,
31
int64_t inMax,
32
int64_t outMin,
33
int64_t outMax);
34
35
bool
isArrayEmpty(
void
* array,
size_t
arraySize);
36
37
// Converts inputLength bytes from input to HEX and adds bytes separator
38
// if required.
39
// output buffor has to be at least (2 * inputLength + 1) bytes long without
40
// separator, or: (3 * inputLength) bytes long with separator.
41
// Trailing '\0' is added.
42
// Returns amount of non-null chars written.
43
int
generateHexString(
const
void
*input,
44
char
*output,
45
int
inputLength,
46
char
separator = 0);
47
48
// Converts hex byte string value to integer.
49
// Returns false when input contains invalid hex characters.
50
bool
hexByteToInt(
const
char
*str, uint8_t *result);
51
52
// Converts hex string to array of bytes.
53
// Returns false when input contains invalid hex characters.
54
bool
hexStringToArray(
const
char
*input,
char
*output,
int
outputLength);
55
56
// Converts decimal string value to unsigned integer
57
uint32_t stringToUInt(
const
char
*str,
int
len = -1);
58
59
// Converts decimal string value to signed integer
60
int32_t stringToInt(
const
char
*str,
int
len = -1);
61
62
// Convers float value from string to integer with given precision
63
int32_t floatStringToInt(
const
char
*str,
int
precision);
64
65
// Converts "230,12,43" string to RGB values. Returns false on error
66
bool
stringToColor(
const
char
*payload,
67
uint8_t *red,
68
uint8_t *green,
69
uint8_t *blue);
70
71
// Decode url string from buffer into buffer (inplace)
72
// Replace '+' with ' '.
73
// Replace %xy with proper byte.
74
// If not complete % parameter is found at the end, then it is omitted.
75
// Returns false when invalid hex escape is found.
76
bool
urlDecodeInplace(
char
*buffer,
int
size);
77
78
// Encode url string from input to output
79
// Returns number of non-null bytes added to output
80
int
urlEncode(
const
char
*input,
char
*output,
int
outputMaxSize);
81
82
int
stringAppend(
char
*output,
const
char
*input,
int
maxSize);
83
84
int
strncmpInsensitive(
const
char
*s1,
const
char
*s2,
int
size);
85
86
// This method should be implemented in platform specific cpp file
87
void
deviceSoftwareReset();
88
bool
isDeviceSoftwareResetSupported();
89
bool
isLastResetSoft();
90
91
const
char
*getManufacturer(int16_t
id
);
92
93
namespace
Supla {
94
int
getPlatformId();
95
int
getBitNumber(uint64_t value);
96
int
rssiToSignalStrength(
int
rssi,
int
rssiZero = -100);
97
bool
isLastResetPower();
98
99
const
char
*getRelayChannelName(
int
channelFunction);
100
const
char
*getBinarySensorChannelName(
int
channelFunction);
101
107
bool
isLittleEndian();
108
117
int
compareSemVer(
const
char
*sw1,
const
char
*sw2);
118
125
#ifndef ARDUINO_ARCH_AVR
126
void
fillRandom(uint8_t *buffer,
int
size);
127
#endif
128
129
}
// namespace Supla
130
131
132
#endif
// SRC_SUPLA_TOOLS_H_
Generated by
1.17.0