LightHub
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 void PrintBytes(uint8_t* addr, uint8_t count, bool newline);
47 void SetBytes(uint8_t* addr, uint8_t count, char * out);
48 void SetAddr(char * out, uint8_t* addr);
49 uint8_t HEX2DEC(char i);
50 int getInt(char ** chan);
51 unsigned long freeRam ();
52 void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base);
53 int log(const char *str, ...);
54 void printFloatValueToStr(float value, char *valstr);
55 void ReadUniqueID( uint32_t * pdwUniqueID );
56 int inet_aton(const char* aIPAddrString, IPAddress& aResult);
57 char *inet_ntoa_r(IPAddress addr, char *buf, int buflen);
58 void printIPAddress(IPAddress ipAddress);
59 char* setTopic(char* buf, int8_t buflen, topicType tt, const char* suffix = NULL);
60 void printUlongValueToStr(char *valstr, unsigned long value);
61 void scan_i2c_bus();
63 bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo = 0xFFFFFFFF);
64 //bool executeCommand(aJsonObject* cmd, int8_t toggle = -1, char* defCmd = NULL);
65 bool executeCommand(aJsonObject* cmd, int8_t toggle = -1);
66 bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd);
67 itemCmd mapInt(int32_t arg, aJsonObject* map);
ReadUniqueID
void ReadUniqueID(uint32_t *pdwUniqueID)
executeCommand
bool executeCommand(aJsonObject *cmd, int8_t toggle=-1)
Definition: utils.cpp:526
itemCmd
Definition: itemCmd.h:173
freeRam
unsigned long freeRam()
isTimeOver
bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo=0xFFFFFFFF)
Definition: utils.cpp:516
HEX2DEC
uint8_t HEX2DEC(char i)
Definition: utils.cpp:74
scan_i2c_bus
void scan_i2c_bus()
Definition: utils.cpp:450
T_BCST
@ T_BCST
Definition: utils.h:42
SetAddr
void SetAddr(char *out, uint8_t *addr)
Definition: utils.cpp:82
options.h
T_OUT
@ T_OUT
Definition: utils.h:43
SetBytes
void SetBytes(uint8_t *addr, uint8_t count, char *out)
Definition: utils.cpp:63
T_DEV
@ T_DEV
Definition: utils.h:41
mapInt
itemCmd mapInt(int32_t arg, aJsonObject *map)
Definition: utils.cpp:626
topicType
topicType
Definition: utils.h:40
parseBytes
void parseBytes(const char *str, char separator, byte *bytes, int maxBytes, int base)
Definition: utils.cpp:170
getInt
int getInt(char **chan)
Definition: utils.cpp:92
log
int log(const char *str,...)
Definition: utils.cpp:201
inet_ntoa_r
char * inet_ntoa_r(IPAddress addr, char *buf, int buflen)
Definition: utils.cpp:362
inet_aton
int inet_aton(const char *aIPAddrString, IPAddress &aResult)
Definition: utils.cpp:292
printFloatValueToStr
void printFloatValueToStr(float value, char *valstr)
Definition: utils.cpp:182
printUlongValueToStr
void printUlongValueToStr(char *valstr, unsigned long value)
Definition: utils.cpp:434
printIPAddress
void printIPAddress(IPAddress ipAddress)
Definition: utils.cpp:379
softRebootFunc
void softRebootFunc()
PrintBytes
void PrintBytes(uint8_t *addr, uint8_t count, bool newline)
Definition: utils.cpp:52
item.h
setTopic
char * setTopic(char *buf, int8_t buflen, topicType tt, const char *suffix=NULL)
Definition: utils.cpp:389