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