LightHub  v4.0.0
Smarthome controller firmware
utils.h
Go to the documentation of this file.
1 /* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 
15 Homepage: http://lazyhome.ru
16 GIT: https://github.com/anklimov/lighthub
17 e-mail anklimov@gmail.com
18 
19 */
20 #pragma once
21 
22 #define Q(x) #x
23 #define QUOTE(x) Q(x)
24 #define VALUE_TO_STRING(x) #x
25 #define VALUE(x) VALUE_TO_STRING(x)
26 #define VAR_NAME_VALUE(var) #var "=" VALUE(var)
27 
28 #include <Arduino.h>
29 #include <IPAddress.h>
30 #include "aJSON.h"
31 #include "options.h"
32 #include "item.h"
33 #ifdef WITH_PRINTEX_LIB
34 #include "PrintEx.h"
35 using namespace ios;
36 #else
37 #include "Streaming.h"
38 #endif
39 
40 enum topicType {
41  T_DEV = 1,
42  T_BCST= 2,
43  T_OUT = 3
44  };
45 
46 #if defined(ESP32)
47 #define serialParamType uint32_t
48 #else
49 #define serialParamType uint16_t
50 #endif
51 
52 void PrintBytes(uint8_t* addr, uint8_t count, bool newline);
53 void SetBytes(uint8_t* addr, uint8_t count, char * out);
54 void SetAddr(char * out, uint8_t* addr);
55 uint8_t HEX2DEC(char i);
56 int getInt(char ** chan);
57 itemCmd getNumber(char ** chan);
58 unsigned long freeRam ();
59 void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base);
60 int log(const char *str, ...);
61 void printFloatValueToStr(float value, char *valstr);
62 void ReadUniqueID( uint32_t * pdwUniqueID );
63 int _inet_aton(const char* aIPAddrString, IPAddress& aResult);
64 char *_inet_ntoa_r(IPAddress addr, char *buf, int buflen);
65 void printIPAddress(IPAddress ipAddress);
66 char* setTopic(char* buf, int8_t buflen, topicType tt, const char* suffix = NULL);
67 void printUlongValueToStr(char *valstr, unsigned long value);
68 void scan_i2c_bus();
70 bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo = 0);
71 //bool executeCommand(aJsonObject* cmd, int8_t toggle = -1, char* defCmd = NULL);
72 bool executeCommand(aJsonObject* cmd, int8_t toggle = -1);
73 bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd, aJsonObject* defaultItem=NULL, aJsonObject* defaultEmit=NULL);
74 itemCmd mapInt(int32_t arg, aJsonObject* map);
75 unsigned long millisNZ(uint8_t shift=0);
77 String toString(const IPAddress& address);
ReadUniqueID
void ReadUniqueID(uint32_t *pdwUniqueID)
executeCommand
bool executeCommand(aJsonObject *cmd, int8_t toggle=-1)
Definition: utils.cpp:574
itemCmd
Definition: itemCmd.h:153
freeRam
unsigned long freeRam()
HEX2DEC
uint8_t HEX2DEC(char i)
Definition: utils.cpp:80
toString
String toString(const IPAddress &address)
Definition: utils.cpp:418
scan_i2c_bus
void scan_i2c_bus()
Definition: utils.cpp:493
_inet_ntoa_r
char * _inet_ntoa_r(IPAddress addr, char *buf, int buflen)
Definition: utils.cpp:402
T_BCST
@ T_BCST
Definition: utils.h:42
SetAddr
void SetAddr(char *out, uint8_t *addr)
Definition: utils.cpp:88
serialParamType
#define serialParamType
Definition: utils.h:49
options.h
millisNZ
unsigned long millisNZ(uint8_t shift=0)
Definition: utils.cpp:710
T_OUT
@ T_OUT
Definition: utils.h:43
SetBytes
void SetBytes(uint8_t *addr, uint8_t count, char *out)
Definition: utils.cpp:69
T_DEV
@ T_DEV
Definition: utils.h:41
mapInt
itemCmd mapInt(int32_t arg, aJsonObject *map)
Definition: utils.cpp:704
topicType
topicType
Definition: utils.h:40
parseBytes
void parseBytes(const char *str, char separator, byte *bytes, int maxBytes, int base)
Definition: utils.cpp:210
getInt
int getInt(char **chan)
Definition: utils.cpp:98
log
int log(const char *str,...)
Definition: utils.cpp:241
isTimeOver
bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo=0)
Definition: utils.cpp:559
_inet_aton
int _inet_aton(const char *aIPAddrString, IPAddress &aResult)
Definition: utils.cpp:332
printFloatValueToStr
void printFloatValueToStr(float value, char *valstr)
Definition: utils.cpp:222
printUlongValueToStr
void printUlongValueToStr(char *valstr, unsigned long value)
Definition: utils.cpp:477
getNumber
itemCmd getNumber(char **chan)
Definition: utils.cpp:117
str2SerialParam
serialParamType str2SerialParam(char *str)
Definition: utils.cpp:748
printIPAddress
void printIPAddress(IPAddress ipAddress)
Definition: utils.cpp:422
softRebootFunc
void softRebootFunc()
PrintBytes
void PrintBytes(uint8_t *addr, uint8_t count, bool newline)
Definition: utils.cpp:58
item.h
setTopic
char * setTopic(char *buf, int8_t buflen, topicType tt, const char *suffix=NULL)
Definition: utils.cpp:432