AqualinkD/utils.h

134 lines
3.5 KiB
C
Raw Permalink Normal View History

2017-12-30 20:12:01 +00:00
#include <syslog.h>
#include <stdbool.h>
2020-07-18 16:37:19 +00:00
#include <stdint.h>
2017-12-30 20:12:01 +00:00
#ifndef UTILS_H_
#define UTILS_H_
2023-06-23 20:16:30 +00:00
#define LOG_DEBUG_SERIAL LOG_DEBUG+1
2018-03-05 23:52:42 +00:00
2017-12-30 20:12:01 +00:00
#ifndef EXIT_SUCCESS
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
#endif
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
2023-06-20 00:15:45 +00:00
#define LOGBUFFER 256
2023-06-04 21:17:48 +00:00
2023-06-20 00:15:45 +00:00
//#define MAXLEN 256
2017-12-30 20:12:01 +00:00
2020-08-28 19:12:38 +00:00
//#define round(a) (int) (a+0.5) // 0 decimal places (doesn't work for negative numbers)
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define roundf(a) (float) ((a*100)/100) // 2 decimal places
2017-12-30 20:12:01 +00:00
2020-07-18 16:37:19 +00:00
// Defined as int16_t so 16 bits to mask
#define AQUA_LOG (1 << 0) // Aqualink Generic / catchall
#define NET_LOG (1 << 1) // Network
// Control protocols
#define AQRS_LOG (1 << 2) // Allbutton RS Keypad
#define ONET_LOG (1 << 3) // OneTouch
#define IAQT_LOG (1 << 4) // iAqualinkTouch
#define PDA_LOG (1 << 5) // PDA
2020-08-28 19:12:38 +00:00
#define RSSA_LOG (1 << 6) // Serial Adapter
2020-07-18 16:37:19 +00:00
// Message PRotocols
2020-08-28 19:12:38 +00:00
#define DJAN_LOG (1 << 7) // Jange Device
#define DPEN_LOG (1 << 8) // Pentair Device
2020-07-18 16:37:19 +00:00
// misc
2020-08-28 19:12:38 +00:00
#define RSSD_LOG (1 << 9) // RS485 Connection /dev/ttyUSB?
#define PROG_LOG (1 << 10) // Programmer
#define DBGT_LOG (1 << 11) // Debug Timer
2023-05-14 21:35:13 +00:00
#define TIMR_LOG (1 << 12) // Timers
2024-04-19 19:06:00 +00:00
#define SIM_LOG (1 << 13) // Simulator
2023-05-14 21:35:13 +00:00
2023-05-17 17:51:00 +00:00
// Set scheduler log to timer log
#define SCHD_LOG TIMR_LOG
2023-05-14 21:35:13 +00:00
2017-12-30 20:12:01 +00:00
/*
typedef enum
{
false = FALSE, true = TRUE
} bool;
*/
2019-08-18 20:54:10 +00:00
//void setLoggingPrms(int level , bool deamonized, char* log_file);
2023-07-08 16:14:44 +00:00
#ifdef AQ_MANAGER
void setLoggingPrms(int level , bool deamonized, char *error_messages);
#else
2019-08-18 20:54:10 +00:00
void setLoggingPrms(int level , bool deamonized, char* log_file, char *error_messages);
2023-07-08 16:14:44 +00:00
#endif
2020-07-18 16:37:19 +00:00
int getLogLevel(int16_t from);
2023-06-20 00:15:45 +00:00
int getSystemLogLevel();
void setSystemLogLevel( int level);
2017-12-30 20:12:01 +00:00
void daemonise ( char *pidFile, void (*main_function)(void) );
//void debugPrint (char *format, ...);
2023-07-08 16:14:44 +00:00
2020-07-18 16:37:19 +00:00
void addDebugLogMask(int16_t flag);
2020-08-28 19:12:38 +00:00
void removeDebugLogMask(int16_t flag);
2023-06-20 00:15:45 +00:00
void clearDebugLogMask();
bool isDebugLogMaskSet(int16_t flag);
const char* logmask2name(int16_t mask);
const char* loglevel2name(int level);
2020-07-18 16:37:19 +00:00
//#define logMessage(msg_level, format, ...) LOG (1, msg_level, format, ##__VA_ARGS__)
2020-07-26 19:28:58 +00:00
//void logMessage(int level, const char *format, ...);
2020-07-18 16:37:19 +00:00
//void LOG(int from, int level, char *format, ...);
void LOG(int16_t from, int msg_level, const char *format, ...);
2023-07-08 16:14:44 +00:00
void LOGSystemError (int errnum, int16_t from, const char *on_what);
void displayLastSystemError (const char *on_what);
2020-07-18 16:37:19 +00:00
2017-12-30 20:12:01 +00:00
int count_characters(const char *str, char character);
//void readCfg (char *cfgFile);
int text2elevel(char* level);
char *elevel2text(int level);
char *cleanwhitespace(char *str);
//char *cleanquotes(char *str);
2019-06-05 16:41:38 +00:00
char *chopwhitespace(char *str);
char *trimwhitespace(char *str);
2018-03-16 17:18:15 +00:00
char *stripwhitespace(char *str);
2017-12-30 20:12:01 +00:00
int cleanint(char*str);
bool text2bool(char *str);
2019-10-13 15:07:14 +00:00
bool request2bool(char *str);
2017-12-30 20:12:01 +00:00
char *bool2text(bool val);
void delay (unsigned int howLong);
2020-08-28 19:12:38 +00:00
//void ndelay (float howLong)
2017-12-30 20:12:01 +00:00
float degFtoC(float degF);
float degCtoF(float degC);
2018-02-18 14:07:53 +00:00
char* stristr(const char* haystack, const char* needle);
2020-07-18 16:37:19 +00:00
//int ascii(char *destination, char *source);
2019-05-25 16:52:36 +00:00
char *prittyString(char *str);
2019-08-18 20:54:10 +00:00
//void writePacketLog(char *buff);
//void closePacketLog();
2023-06-20 00:15:45 +00:00
2023-06-23 20:16:30 +00:00
#ifdef AQ_MANAGER
2023-06-24 00:38:59 +00:00
//void startInlineLog2File();
//void stopInlineLog2File();
//void cleanInlineLog2File();
2023-06-23 20:16:30 +00:00
#else
2019-08-25 20:57:51 +00:00
void startInlineDebug();
void stopInlineDebug();
2023-06-20 00:15:45 +00:00
void startInlineSerialDebug();
2019-08-25 20:57:51 +00:00
void cleanInlineDebug();
char *getInlineLogFName();
bool islogFileReady();
2023-06-24 00:38:59 +00:00
#endif
2023-06-20 00:15:45 +00:00
//const char *logmask2name(int16_t from);
2017-12-30 20:12:01 +00:00
//#ifndef _UTILS_C_
extern bool _daemon_;
extern bool _debuglog_;
extern bool _debug2file_;
//#endif
#endif /* UTILS_H_ */