/** * @file trace.h * @author Pavel Brychta, http://www.xpablo.cz * * Copyright (c) 2016-23 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 // 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 #ifndef DONT_USE_TRACE #include #include /** * @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] 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] 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] 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(); #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) #define TRACEPLUS(when, severity, ...) if (when != 0) TRACE(severity, __VA_ARGS__) //#define TRACE(severity, ...) trace_print(severity, __VA_ARGS__) #define TRACE(severity, text, ...) trace_print(severity, PSTR(text), ##__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(a) trace_init() #define TRACE_ADDWEB(srv) trace_addweb(srv) #define TRACE_POLL(a) trace_poll() #define TRACE_FORCEUPDATE(a) trace_forceupdate() #else // DONT_USE_TRACE #define TRACEPLUS(...) ((void)0) #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(a) ((void)0) #define TRACE_ADDWEB(a) ((void)0) #define TRACE_POLL(a) ((void)0) #define TRACE_FORCEUPDATE(a) ((void)0) #endif // DONT_USE_TRACE