2018-04-22 15:48:16 +02:00
|
|
|
/**
|
|
|
|
* @file trace.h
|
|
|
|
* @author Pavel Brychta, http://www.xpablo.cz
|
|
|
|
*
|
2023-05-20 12:47:13 +02:00
|
|
|
* Copyright (c) 2016-23 Pavel Brychta. All rights reserved.
|
2018-04-22 15:48:16 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2023-05-20 12:47:13 +02:00
|
|
|
#pragma once
|
2018-04-22 15:48:16 +02:00
|
|
|
|
|
|
|
// Definice jednotlivych typu hlaseni do trasovani
|
|
|
|
#define TRACE_ERROR 0 // chybova zprava = cervena
|
|
|
|
#define TRACE_WARNING 1 // varovani - zluta
|
|
|
|
#define TRACE_INFO 2 // informacni zprava - zelena
|
|
|
|
#define TRACE_DEBUG 3 // ladici zprava - cerna
|
|
|
|
#define TRACE_DEBUGMORE 4 // mene zajimava ladici zprava - take cerna
|
|
|
|
|
|
|
|
#define TRACE_CHECK_INTERVAL 200 // interval [ms], po kterem je testovano odesilani stopare
|
|
|
|
|
2019-10-11 16:54:53 +02:00
|
|
|
#ifndef DONT_USE_TRACE
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <ESPAsyncWebServer.h>
|
|
|
|
|
2018-04-22 15:48:16 +02:00
|
|
|
/**
|
|
|
|
* @brief Inicializace modulu
|
|
|
|
*/
|
2023-05-20 12:47:13 +02:00
|
|
|
void trace_init();
|
2018-04-22 15:48:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Ziskani vypisu v JSON formatu
|
|
|
|
*
|
|
|
|
* @param str retezec udalosti v JSON
|
|
|
|
*/
|
|
|
|
void trace_dumpJSON(String &str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Vyprazdneni stopovaciho bufferu
|
|
|
|
*/
|
2023-05-20 12:47:13 +02:00
|
|
|
void trace_clear();
|
2018-04-22 15:48:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Ukonceni prace stopare - vyprazdni buffer
|
|
|
|
*/
|
2023-05-20 12:47:13 +02:00
|
|
|
void trace_end();
|
2018-04-22 15:48:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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)
|
|
|
|
*/
|
2023-05-20 12:47:13 +02:00
|
|
|
void trace_forceupdate();
|
2018-04-22 15:48:16 +02:00
|
|
|
|
2019-10-11 16:54:53 +02:00
|
|
|
#define STRINGIFY(x) #x
|
|
|
|
#define TOSTRING(x) STRINGIFY(x)
|
|
|
|
|
2022-03-24 12:46:55 +01:00
|
|
|
#define TRACEPLUS(when, severity, ...) if (when != 0) TRACE(severity, __VA_ARGS__)
|
2019-10-11 16:54:53 +02:00
|
|
|
#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)
|
2022-10-01 14:52:33 +02:00
|
|
|
#define TRACE_INIT(a) trace_init()
|
2019-10-11 16:54:53 +02:00
|
|
|
#define TRACE_ADDWEB(srv) trace_addweb(srv)
|
2022-10-01 14:52:33 +02:00
|
|
|
#define TRACE_POLL(a) trace_poll()
|
2019-10-11 16:54:53 +02:00
|
|
|
#define TRACE_FORCEUPDATE(a) trace_forceupdate()
|
|
|
|
|
|
|
|
#else // DONT_USE_TRACE
|
2022-03-24 12:46:55 +01:00
|
|
|
#define TRACEPLUS(...) ((void)0)
|
2019-10-11 16:54:53 +02:00
|
|
|
#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)
|
2022-10-01 14:52:33 +02:00
|
|
|
#define TRACE_INIT(a) ((void)0)
|
2019-10-11 16:54:53 +02:00
|
|
|
#define TRACE_ADDWEB(a) ((void)0)
|
2022-10-01 14:52:33 +02:00
|
|
|
#define TRACE_POLL(a) ((void)0)
|
2019-10-11 16:54:53 +02:00
|
|
|
#define TRACE_FORCEUPDATE(a) ((void)0)
|
|
|
|
#endif // DONT_USE_TRACE
|