supla-device
Loading...
Searching...
No Matches
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
26void float2DoublePacked(float number, uint8_t *bar, int byteOrder = LSBFIRST);
27float doublePacked2float(uint8_t *bar);
28
29int64_t adjustRange(int64_t input,
30 int64_t inMin,
31 int64_t inMax,
32 int64_t outMin,
33 int64_t outMax);
34
35bool 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.
43int generateHexString(const void *input,
44 char *output,
45 int inputLength,
46 char separator = 0);
47
48void hexStringToArray(const char *input, char *output, int outputLength);
49
50// Converts hex string value to integer
51uint32_t hexStringToInt(const char *str, int len = -1);
52
53// Converts decimal string value to unsigned integer
54uint32_t stringToUInt(const char *str, int len = -1);
55
56// Converts decimal string value to signed integer
57int32_t stringToInt(const char *str, int len = -1);
58
59// Convers float value from string to integer with given precision
60int32_t floatStringToInt(const char *str, int precision);
61
62// Converts "230,12,43" string to RGB values. Returns false on error
63bool stringToColor(const char *payload,
64 uint8_t *red,
65 uint8_t *green,
66 uint8_t *blue);
67
68// Decode url string from buffer into buffer (inplace)
69// Replace '+' with ' '.
70// Replace %xy with proper byte.
71// If not complete % parameter is found at the end, then it is omitted.
72void urlDecodeInplace(char *buffer, int size);
73
74// Encode url string from input to output
75// Returns number of non-null bytes added to output
76int urlEncode(const char *input, char *output, int outputMaxSize);
77
78int stringAppend(char *output, const char *input, int maxSize);
79
80int strncmpInsensitive(const char *s1, const char *s2, int size);
81
82// This method should be implemented in platform specific cpp file
83void deviceSoftwareReset();
84bool isDeviceSoftwareResetSupported();
85bool isLastResetSoft();
86
87const char *getManufacturer(int16_t id);
88
89namespace Supla {
90int getPlatformId();
91int getBitNumber(uint64_t value);
92int rssiToSignalStrength(int rssi, int rssiZero = -100);
93bool isLastResetPower();
94
95const char *getRelayChannelName(int channelFunction);
96const char *getBinarySensorChannelName(int channelFunction);
97
103bool isLittleEndian();
104
113int compareSemVer(const char *sw1, const char *sw2);
114
115} // namespace Supla
116
117
118#endif // SRC_SUPLA_TOOLS_H_