Priprava na release 1.0.0 - moznost presmerovani na seriovy ladici port.

This commit is contained in:
Pavel Brychta 2024-01-19 11:42:39 +01:00
parent 11fcc3546c
commit be3f935575
6 changed files with 256 additions and 195 deletions

View File

@ -1,6 +1,6 @@
{ {
"name":"Trace", "name":"Trace",
"description":"Web based trace debug module", "description":"Multi-target trace debug module",
"keywords":"debug,trace", "keywords":"debug,trace",
"authors": "authors":
{ {
@ -12,7 +12,7 @@
"type": "git", "type": "git",
"url": "https://git.xpablo.cz/pablo2048/Trace.git" "url": "https://git.xpablo.cz/pablo2048/Trace.git"
}, },
"version": "0.0.6", "version": "1.0.0",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": ["espressif8266","espressif32"], "platforms": ["espressif8266","espressif32"],

View File

@ -1,9 +1,9 @@
name=Trace name=Trace
version=0.0.6 version=1.0.0
author=Pavel Brychta author=Pavel Brychta
maintainer=Pavel Brychta maintainer=Pavel Brychta
sentence=Trace application internals & messages via web server sentence=Trace application internals & messages via web server or other output device
paragraph=Trace application internals & messages via web server paragraph=Trace application internals & messages via web server or other output device
category=Other category=Other
url=http://git.xpablo.cz/pablo2048/Trace url=http://git.xpablo.cz/pablo2048/Trace
architectures=* architectures=*

View File

@ -1,5 +1,5 @@
#include "trace.h" #include "traceAsyncWebsocket.hpp"
#include <interval.h> #include <Chronos.hpp>
#define MAX_TRACE_LINES 15 #define MAX_TRACE_LINES 15
#define MAX_LINE_LEN 50 #define MAX_LINE_LEN 50
@ -25,7 +25,6 @@ static uint16_t _lines_index = 0;
static uint16_t _lines_count = 0; static uint16_t _lines_count = 0;
static volatile int _modified = 0; static volatile int _modified = 0;
static AsyncWebSocket * _wss = nullptr; // webovy soket pro trasovani static AsyncWebSocket * _wss = nullptr; // webovy soket pro trasovani
static Interval _tint(TRACE_CHECK_INTERVAL); // interval pro casovani stopare
static void (*message_cb)(const char *) = nullptr; static void (*message_cb)(const char *) = nullptr;
@ -69,9 +68,36 @@ static void print(uint8_t severity, const char *buffer, int length)
++_modified; ++_modified;
} }
static void trace_loop()
{
if (nullptr != _wss) {
// je definovany webovy soket
if (_modified) {
// mame nejakou zmenu
if (_wss->count() != 0) {
// mame klienty
String log;
_modified = 0; // rusime pozadavek na odeslani novych dat
if (log.reserve((MAX_TRACE_LINES * MAX_LINE_LEN) + (MAX_TRACE_LINES * 50))) {
log = F("{\"type\":\"trace\",\"data\":[");
trace_dumpJSON(log);
log.concat(F("]}"));
if (_wss->availableForWriteAll())
_wss->textAll(log);
} else if (_wss->availableForWriteAll())
_wss->textAll(F("{\"type\":\"trace\",\"text\":\"Memory error\"}"));
} else
_modified = 0; // zadny pripojeny klient - po pripojeni stejne musime vyzadat stav, takze ted muzeme modifikaci klidne ignorovat
}
}
}
void trace_init() void trace_init()
{ {
Chronos::attachMs(TRACEWS_CHECK_INTERVAL, trace_loop);
} }
static String _getText(const char * buffer) static String _getText(const char * buffer)
@ -252,33 +278,4 @@ void trace_forceupdate(void)
++_modified; // vynutime odeslani informaci ++_modified; // vynutime odeslani informaci
} }
void trace_poll()
{
if (nullptr != _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))) {
log = F("{\"type\":\"trace\",\"data\":[");
trace_dumpJSON(log);
log.concat(F("]}"));
if (_wss->availableForWriteAll())
_wss->textAll(log);
} else
if (_wss->availableForWriteAll())
_wss->textAll(F("{\"type\":\"trace\",\"text\":\"Memory error\"}"));
}
} else
_modified = 0; // zadny pripojeny klient - po pripojeni stejne musime vyzadat stav, takze ted muzeme modifikaci klidne ignorovat
}
}
}
// EOF // EOF

View File

@ -0,0 +1,108 @@
/**
* @file traceWebsocket.h
* @author Pavel Brychta, http://www.xpablo.cz
*
* Copyright (c) 2016-24 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
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#pragma once
#include <Arduino.h>
#include <ESPAsyncWebServer.h>
#define TRACEWS_CHECK_INTERVAL 200 // interval [ms], po kterem je testovano odesilani stopare
/**
* @brief Inicializace modulu
*/
void trace_init();
/**
* @brief Ziskani vypisu v JSON formatu
*
* @param str retezec udalosti v JSON
*/
void trace_dumpJSON(String & str);
/**
* @brief Vyprazdneni stopovaciho bufferu
*/
void trace_clear();
/**
* @brief Ukonceni prace stopare - vyprazdni buffer
*/
void trace_end();
/**
* @brief Ulozeni zpravy s obsahem z programove pameti (PROGMEM, F, ...)
*
* @param[in] severity Uroven - viz. TRACE_ERROR, TRACE_WARNING, ...
* @param[in] fmt Formatovaci retezec vysledne zpravy. Je ulozeny v PROGMEM
* @param[in] <unnamed> Parametry, ktere jsou dosazeny do formatovaciho retezce
*/
void trace_print(uint8_t severity, const __FlashStringHelper * fmt, ...);
/**
* @brief Ulozeni zpravy
*
* @param[in] severity Uroven - viz. TRACE_ERROR, TRACE_WARNING, ...
* @param[in] fmt Formatovaci retezec vysledne zpravy.
* @param[in] <unnamed> Parametry, ktere jsou dosazeny do formatovaciho retezce
*/
void trace_print(uint8_t severity, const char * fmt, ...);
/**
* @brief Registrace callback metody - je volana pri kazde zmene (zapisu) do stopare
*
* @param[in] <unnamed> Ukazatel na volanou metodu
*/
void trace_registermessagecb(void (*)(const char * msg));
/**
* @brief Pridani obsluhy stranky /trace do weboveho serveru
*
* @param socket webovy soket pro komunikaci
*/
void trace_addweb(AsyncWebSocket * socket);
void trace_printfunc(uint8_t severity, const char * func, const char * file, int line, const char * fmt, ...);
/**
* @brief Vypis oblasti pameti (dump)
*
* @param[in] severity Uroven - viz. TRACE_ERROR, TRACE_WARNING, ...
* @param[in] prefix Prefix (text), ktery je uvedeny pred vlastnim vypisem pameti
* @param address Adresa pocatku vypisu
* @param[in] size Pocet vypisovanych bytu (POZOR!!! musi se vejit do jednoho radku stopare!!!)
*/
void trace_dump(uint8_t severity, const char * prefix, uint8_t * address, size_t size);
/**
* @brief Vypis oblasti pameti (dump)
*
* @param[in] severity Uroven - viz. TRACE_ERROR, TRACE_WARNING, ...
* @param[in] prefix Prefix (text), ktery je uvedeny pred vlastnim vypisem pameti
* @param address Adresa pocatku vypisu
* @param[in] size Pocet vypisovanych bytu (POZOR!!! musi se vejit do jednoho radku stopare!!!)
*/
void trace_dump(uint8_t severity, const __FlashStringHelper * prefix, uint8_t * address, size_t size);
/**
* @brief Vynuceni odeslani obsahu bufferu (napr. pri obnovovani spojeni)
*/
void trace_forceupdate();

View File

@ -2,7 +2,7 @@
* @file trace.h * @file trace.h
* @author Pavel Brychta, http://www.xpablo.cz * @author Pavel Brychta, http://www.xpablo.cz
* *
* Copyright (c) 2016-23 Pavel Brychta. All rights reserved. * Copyright (c) 2016-24 Pavel Brychta. All rights reserved.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -22,125 +22,81 @@
#pragma once #pragma once
// Definice jednotlivych typu hlaseni do trasovani // Definice jednotlivych typu hlaseni do trasovani
#define TRACE_NONE -1 // nic
#define TRACE_ERROR 0 // chybova zprava = cervena #define TRACE_ERROR 0 // chybova zprava = cervena
#define TRACE_WARNING 1 // varovani - zluta #define TRACE_WARNING 1 // varovani - zluta
#define TRACE_INFO 2 // informacni zprava - zelena #define TRACE_INFO 2 // informacni zprava - zelena
#define TRACE_DEBUG 3 // ladici zprava - cerna #define TRACE_DEBUG 3 // ladici zprava - cerna
#define TRACE_DEBUGMORE 4 // mene zajimava ladici zprava - take cerna #define TRACE_VERBOSE 4 // mene zajimava ladici zprava - take cerna
#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
*/
void trace_init();
/**
* @brief Ziskani vypisu v JSON formatu
*
* @param str retezec udalosti v JSON
*/
void trace_dumpJSON(String &str);
/**
* @brief Vyprazdneni stopovaciho bufferu
*/
void trace_clear();
/**
* @brief Ukonceni prace stopare - vyprazdni buffer
*/
void trace_end();
/**
* @brief Ulozeni zpravy s obsahem z programove pameti (PROGMEM, F, ...)
*
* @param[in] severity Uroven - viz. TRACE_ERROR, TRACE_WARNING, ...
* @param[in] fmt Formatovaci retezec vysledne zpravy. Je ulozeny v PROGMEM
* @param[in] <unnamed> Parametry, ktere jsou dosazeny do formatovaciho retezce
*/
void trace_print(uint8_t severity, const __FlashStringHelper *fmt, ...);
/**
* @brief Ulozeni zpravy
*
* @param[in] severity Uroven - viz. TRACE_ERROR, TRACE_WARNING, ...
* @param[in] fmt Formatovaci retezec vysledne zpravy.
* @param[in] <unnamed> Parametry, ktere jsou dosazeny do formatovaciho retezce
*/
void trace_print(uint8_t severity, const char *fmt, ...);
/**
* @brief Registrace callback metody - je volana pri kazde zmene (zapisu) do stopare
*
* @param[in] <unnamed> Ukazatel na volanou metodu
*/
void trace_registermessagecb(void (*)(const char *msg));
/**
* @brief Pridani obsluhy stranky /trace do weboveho serveru
*
* @param socket webovy soket pro komunikaci
*/
void trace_addweb(AsyncWebSocket *socket);
/**
* @brief Periodicky tik modulem - osetruje odeslani novych dat v pripade modifikace
*/
void trace_poll();
void trace_printfunc(uint8_t severity, const char *func, const char *file, int line, const char *fmt, ...);
/**
* @brief Vypis oblasti pameti (dump)
*
* @param[in] severity Uroven - viz. TRACE_ERROR, TRACE_WARNING, ...
* @param[in] prefix Prefix (text), ktery je uvedeny pred vlastnim vypisem pameti
* @param address Adresa pocatku vypisu
* @param[in] size Pocet vypisovanych bytu (POZOR!!! musi se vejit do jednoho radku stopare!!!)
*/
void trace_dump(uint8_t severity, const char *prefix, uint8_t *address, size_t size);
/**
* @brief Vypis oblasti pameti (dump)
*
* @param[in] severity Uroven - viz. TRACE_ERROR, TRACE_WARNING, ...
* @param[in] prefix Prefix (text), ktery je uvedeny pred vlastnim vypisem pameti
* @param address Adresa pocatku vypisu
* @param[in] size Pocet vypisovanych bytu (POZOR!!! musi se vejit do jednoho radku stopare!!!)
*/
void trace_dump(uint8_t severity, const __FlashStringHelper *prefix, uint8_t *address, size_t size);
/**
* @brief Vynuceni odeslani obsahu bufferu (napr. pri obnovovani spojeni)
*/
void trace_forceupdate();
#ifndef TRACE_LIMIT
#define TRACE_LIMIT TRACE_DEBUG
#endif
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x) #define TOSTRING(x) STRINGIFY(x)
#define TRACEPLUS(when, severity, ...) if (when != 0) TRACE(severity, __VA_ARGS__) #if defined(TRACE_USE_ASYNC_WEBSOCKET)
//#define TRACE(severity, ...) trace_print(severity, __VA_ARGS__) #include "asyncWebsocket/traceAsyncWebsocket.hpp"
#define TRACE(severity, text, ...) trace_print(severity, PSTR(text), ##__VA_ARGS__) #define TRACEPLUS(when, severity, ...) \
{ \
if (when > 0) \
TRACE(severity, __VA_ARGS__) \
}
#define TRACE(severity, text, ...) \
{ \
constexpr bool trace_limit = (severity <= TRACE_LIMIT); \
if (trace_limit) \
trace_print(severity, PSTR(text), ##__VA_ARGS__); \
}
#define TRACEFUNC(severity, ...) trace_printfunc(severity, __func__, __FILE__, TOSTRING(__LINE__), __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 TRACEDUMP(severity, prefix, address, size) trace_dump(severity, prefix, address, size)
#define TRACE_INIT(a) trace_init() #define TRACE_INIT(a) trace_init()
#define TRACE_ADDWEB(srv) trace_addweb(srv) #define TRACE_ADDWEB(srv) trace_addweb(srv)
#define TRACE_POLL(a) trace_poll()
#define TRACE_FORCEUPDATE(a) trace_forceupdate() #define TRACE_FORCEUPDATE(a) trace_forceupdate()
#else // DONT_USE_TRACE #else
#define TRACEPLUS(...) ((void) 0) #define TRACEPLUS(...) ((void) 0)
#if defined(ESP32)
#include <Arduino.h>
#define TRACE(severity, format, ...) \
{ \
constexpr int s = severity; \
if (s == TRACE_ERROR) \
log_e(format, ##__VA_ARGS__); \
else if (s == TRACE_DEBUG) \
log_d(format, ##__VA_ARGS__); \
else if (s == TRACE_WARNING) \
log_w(format, ##__VA_ARGS__); \
else if (s == TRACE_INFO) \
log_i(format, ##__VA_ARGS__); \
else if (s == TRACE_VERBOSE) \
log_v(format, ##__VA_ARGS__); \
}
#else
#ifdef DEBUG_ESP_PORT
#include <Arduino.h>
#define TRACE(severity, text, ...) \
{ \
constexpr int s = severity; \
if (s == TRACE_ERROR) \
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [E] " text "\n"), millis(), ##__VA_ARGS__); \
else if (s == TRACE_DEBUG) \
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [D] " text "\n"), millis(), ##__VA_ARGS__); \
else if (s == TRACE_WARNING) \
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [W] " text "\n"), millis(), ##__VA_ARGS__); \
else if (s == TRACE_INFO) \
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [I] " text "\n"), millis(), ##__VA_ARGS__); \
else if (s == TRACE_VERBOSE) \
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [V] " text "\n"), millis(), ##__VA_ARGS__); \
}
#else
#warning TRACE output is disabled!
#define TRACE(...) ((void) 0) // from assert.h "NOP" - http://stackoverflow.com/questions/9187628/c-empty-function-macros #define TRACE(...) ((void) 0) // from assert.h "NOP" - http://stackoverflow.com/questions/9187628/c-empty-function-macros
#endif
#endif
#define TRACEFUNC(...) ((void) 0) #define TRACEFUNC(...) ((void) 0)
#define TRACEDUMP(...) ((void) 0) #define TRACEDUMP(...) ((void) 0)
#define TRACE_INIT(a) ((void) 0) #define TRACE_INIT(a) ((void) 0)
#define TRACE_ADDWEB(a) ((void) 0) #define TRACE_ADDWEB(a) ((void) 0)
#define TRACE_POLL(a) ((void)0)
#define TRACE_FORCEUPDATE(a) ((void) 0) #define TRACE_FORCEUPDATE(a) ((void) 0)
#endif // DONT_USE_TRACE #endif