Odstraneni nutnosti dalsiho hlavickoveho souboru, nyni staci define DONT_USE_TRACE
This commit is contained in:
parent
d9c4fb7cd8
commit
92dd05d0ac
@ -4,8 +4,7 @@
|
||||
#define MAX_TRACE_LINES 15
|
||||
#define MAX_LINE_LEN 50
|
||||
|
||||
struct TraceLine
|
||||
{
|
||||
struct TraceLine {
|
||||
char _text[MAX_LINE_LEN + 1];
|
||||
uint32_t _time;
|
||||
uint8_t _severity;
|
||||
@ -26,7 +25,7 @@ static uint16_t _lines_index = 0;
|
||||
static uint16_t _lines_count = 0;
|
||||
static volatile int _modified = 0;
|
||||
static AsyncWebSocket *_wss = NULL; // webovy soket pro trasovani
|
||||
static Interval _tint; // interval pro casovani stopare
|
||||
static Interval _tint(TRACE_CHECK_INTERVAL); // interval pro casovani stopare
|
||||
|
||||
static void (*message_cb)(const char *) = NULL;
|
||||
|
||||
@ -50,8 +49,7 @@ static void print(uint8_t severity, const char *buffer, int length)
|
||||
char lin[MAX_LINE_LEN + 1];
|
||||
unsigned int lineptr = 0;
|
||||
|
||||
while ((0 != *buffer) && (lineptr < (sizeof(lin) - 1)))
|
||||
{
|
||||
while ((0 != *buffer) && (lineptr < (sizeof(lin) - 1))) {
|
||||
if (*buffer > 0x1f)
|
||||
lin[lineptr] = *buffer;
|
||||
else
|
||||
@ -65,8 +63,7 @@ static void print(uint8_t severity, const char *buffer, int length)
|
||||
|
||||
_lines[_lines_index++] = line;
|
||||
_lines_index %= MAX_TRACE_LINES;
|
||||
if (_lines_count < MAX_TRACE_LINES)
|
||||
{
|
||||
if (_lines_count < MAX_TRACE_LINES) {
|
||||
++_lines_count;
|
||||
}
|
||||
++_modified;
|
||||
@ -83,10 +80,8 @@ static String _getText(const char *buffer)
|
||||
|
||||
res.reserve(MAX_LINE_LEN * 4);
|
||||
|
||||
while (0 != *buffer)
|
||||
{
|
||||
switch (*buffer)// uprava escape sekvenci pro JSON/HTML
|
||||
{
|
||||
while (0 != *buffer) {
|
||||
switch (*buffer) { // uprava escape sekvenci pro JSON/HTML
|
||||
case '"':
|
||||
res.concat(F("\\\""));
|
||||
break;
|
||||
@ -110,8 +105,7 @@ static String _getText(const char *buffer)
|
||||
default:
|
||||
if (*buffer < 128)
|
||||
res.concat(*buffer);
|
||||
else
|
||||
{
|
||||
else {
|
||||
char chr[3];
|
||||
res.concat(F("\\u00"));
|
||||
sprintf_P(chr, PSTR("%02X"), *buffer);
|
||||
@ -127,8 +121,7 @@ static String _getText(const char *buffer)
|
||||
void trace_dumpJSON(String &str)
|
||||
{
|
||||
|
||||
for (int i=0; i<_lines_count; i++)
|
||||
{
|
||||
for (int i = 0; i < _lines_count; i++) {
|
||||
TraceLine line = trace_line(i);
|
||||
|
||||
if (0 != i)
|
||||
@ -213,8 +206,7 @@ void trace_dump(uint8_t severity, const char *prefix, uint8_t *address, size_t s
|
||||
if (prefix)
|
||||
idx = snprintf_P(buffer, MAX_LINE_LEN, PSTR("%s"), prefix);
|
||||
|
||||
while ((idx < MAX_LINE_LEN) && size)
|
||||
{
|
||||
while ((idx < MAX_LINE_LEN) && size) {
|
||||
buffer[idx] = hexascii(*address >> 4);
|
||||
++idx;
|
||||
buffer[idx] = hexascii(*address);
|
||||
@ -233,16 +225,14 @@ void trace_dump(uint8_t severity, const __FlashStringHelper *prefix, uint8_t *ad
|
||||
char buffer[MAX_LINE_LEN + 1 + 3];
|
||||
int idx = 0;
|
||||
|
||||
if (prefix)
|
||||
{
|
||||
if (prefix) {
|
||||
char dummy[64];
|
||||
|
||||
strcpy_P(dummy, (const char *)prefix);
|
||||
idx = snprintf_P(buffer, MAX_LINE_LEN, PSTR("%s"), dummy);
|
||||
}
|
||||
|
||||
while ((idx < MAX_LINE_LEN) && size)
|
||||
{
|
||||
while ((idx < MAX_LINE_LEN) && size) {
|
||||
buffer[idx] = hexascii(*address >> 4);
|
||||
++idx;
|
||||
buffer[idx] = hexascii(*address);
|
||||
@ -265,30 +255,26 @@ void trace_forceupdate(void)
|
||||
void trace_poll()
|
||||
{
|
||||
|
||||
if (NULL != _wss)
|
||||
{ // je definovany webovy soket
|
||||
if (_modified)
|
||||
{ // mame nejakou zmenu
|
||||
if (_wss->count() != 0)
|
||||
{ // mame klienty
|
||||
if (_tint.expired())
|
||||
{ // .. a vyprsel timeout pro obcerstvovani
|
||||
if (NULL != _wss) {
|
||||
// je definovany webovy soket
|
||||
if (_modified) {
|
||||
// mame nejakou zmenu
|
||||
if (_wss->count() != 0) {
|
||||
// mame klienty
|
||||
if (_tint.expired()) {
|
||||
// .. a vyprsel timeout pro obcerstvovani
|
||||
String log;
|
||||
|
||||
_modified = 0; // rusime pozadavek na odeslani novych dat
|
||||
if (log.reserve((MAX_TRACE_LINES * MAX_LINE_LEN) + (MAX_TRACE_LINES * 50)))
|
||||
{
|
||||
if (log.reserve((MAX_TRACE_LINES * MAX_LINE_LEN) + (MAX_TRACE_LINES * 50))) {
|
||||
log = F("{\"type\":\"trace\",\"data\":[");
|
||||
trace_dumpJSON(log);
|
||||
log.concat(F("]}"));
|
||||
_wss->textAll(log);
|
||||
}
|
||||
else
|
||||
} else
|
||||
_wss->textAll(F("{\"type\":\"trace\",\"text\":\"Memory error\"}"));
|
||||
_tint.set(TRACE_CHECK_INTERVAL);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
_modified = 0; // zadny pripojeny klient - po pripojeni stejne musime vyzadat stav, takze ted muzeme modifikaci klidne ignorovat
|
||||
}
|
||||
}
|
||||
|
31
src/trace.h
31
src/trace.h
@ -2,7 +2,7 @@
|
||||
* @file trace.h
|
||||
* @author Pavel Brychta, http://www.xpablo.cz
|
||||
*
|
||||
* Copyright (c) 2016-18 Pavel Brychta. All rights reserved.
|
||||
* Copyright (c) 2016-19 Pavel Brychta. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@ -22,9 +22,6 @@
|
||||
#ifndef _TRACE_H_
|
||||
#define _TRACE_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
// Definice jednotlivych typu hlaseni do trasovani
|
||||
#define TRACE_ERROR 0 // chybova zprava = cervena
|
||||
#define TRACE_WARNING 1 // varovani - zluta
|
||||
@ -34,6 +31,11 @@
|
||||
|
||||
#define TRACE_CHECK_INTERVAL 200 // interval [ms], po kterem je testovano odesilani stopare
|
||||
|
||||
#ifndef DONT_USE_TRACE
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
/**
|
||||
* @brief Inicializace modulu
|
||||
*/
|
||||
@ -120,4 +122,25 @@ void trace_dump(uint8_t severity, const __FlashStringHelper *prefix, uint8_t *ad
|
||||
*/
|
||||
void trace_forceupdate(void);
|
||||
|
||||
#define STRINGIFY(x) #x
|
||||
#define TOSTRING(x) STRINGIFY(x)
|
||||
|
||||
#define TRACE(severity, ...) trace_print(severity, __VA_ARGS__)
|
||||
#define TRACEFUNC(severity, ...) trace_printfunc(severity, __func__, __FILE__, TOSTRING(__LINE__), __VA_ARGS__)
|
||||
#define TRACEDUMP(severity, prefix, address, size) trace_dump(severity, prefix, address, size)
|
||||
#define TRACE_INIT trace_init()
|
||||
#define TRACE_ADDWEB(srv) trace_addweb(srv)
|
||||
#define TRACE_POLL trace_poll()
|
||||
#define TRACE_FORCEUPDATE(a) trace_forceupdate()
|
||||
|
||||
#else // DONT_USE_TRACE
|
||||
#define TRACE(...) ((void)0) // from assert.h "NOP" - http://stackoverflow.com/questions/9187628/c-empty-function-macros
|
||||
#define TRACEFUNC(...) ((void)0)
|
||||
#define TRACEDUMP(...) ((void)0)
|
||||
#define TRACE_INIT ((void)0)
|
||||
#define TRACE_ADDWEB(a) ((void)0)
|
||||
#define TRACE_POLL ((void)0)
|
||||
#define TRACE_FORCEUPDATE(a) ((void)0)
|
||||
#endif // DONT_USE_TRACE
|
||||
|
||||
#endif // _TRACE_H_
|
||||
|
Loading…
Reference in New Issue
Block a user