nicer logging

master
Ondřej Hruška 9 years ago
parent a55c25ddca
commit 2a4b72fbb5
  1. 2
      Makefile
  2. 3
      libesphttpd/Makefile
  3. 50
      libesphttpd/include/logging.h
  4. 2
      libesphttpd/include/platform.h
  5. 4
      libesphttpd/util/cgiflash.c
  6. 7
      user/sampling.c
  7. 22
      user/sbmp_config.h
  8. 21
      user/uptime.c
  9. 2
      user/uptime.h
  10. 4
      user/user_main.c

@ -56,7 +56,7 @@ TARGET = httpd
# which modules (subdirectories) of the project to include in compiling
MODULES = user sbmp/library
EXTRA_INCDIR = include libesphttpd/include sbmp/library
EXTRA_INCDIR = include libesphttpd/include sbmp/library user/
# libraries used in this project, mainly provided by the SDK
LIBS = c gcc hal phy pp net80211 wpa main lwip crypto

@ -48,7 +48,8 @@ LIB = libesphttpd.a
MODULES = espfs core util
EXTRA_INCDIR = ./include \
. \
lib/heatshrink/
lib/heatshrink/ \
../user
# compiler flags using during compilation of source files

@ -1,19 +1,51 @@
#ifndef HTTPD_LOGGING_H
#define HTTPD_LOGGING_H
#ifndef httpd_printf
#define httpd_printf(fmt, ...) os_printf(fmt, ##__VA_ARGS__)
#endif
#include <esp8266.h>
#include "uptime.h"
// logging functions
#define LOG_EOL "\n"
#define dbg(fmt, ...) httpd_printf(fmt LOG_EOL, ##__VA_ARGS__);
#define banner(fmt, ...) httpd_printf("\x1b[32;1m"fmt"\x1b[0m"LOG_EOL, ##__VA_ARGS__);
#define info(fmt, ...) httpd_printf("\x1b[32m"fmt"\x1b[0m"LOG_EOL, ##__VA_ARGS__);
#define error(fmt, ...) httpd_printf("\x1b[31;1m"fmt"\x1b[0m"LOG_EOL, ##__VA_ARGS__);
#define warn(fmt, ...) httpd_printf("\x1b[33;1m"fmt"\x1b[0m"LOG_EOL, ##__VA_ARGS__);
#define dbg(fmt, ...) \
do { \
uptime_print(); \
printf(" [ ] "fmt LOG_EOL, ##__VA_ARGS__); \
} while(0)
#define banner(fmt, ...) \
do { \
printf("\x1b[32;1m"); \
uptime_print(); \
printf(" [i] "fmt"\x1b[0m"LOG_EOL, ##__VA_ARGS__); \
} while(0)
#define info(fmt, ...) \
do { \
printf("\x1b[32m"); \
uptime_print(); \
printf(" [i] "fmt"\x1b[0m"LOG_EOL, ##__VA_ARGS__); \
} while(0)
#define error(fmt, ...) \
do { \
printf("\x1b[31;1m"); \
uptime_print(); \
printf(" [E] "fmt"\x1b[0m"LOG_EOL, ##__VA_ARGS__); \
} while(0)
#define warn(fmt, ...) \
do { \
printf("\x1b[33;1m"); \
uptime_print(); \
printf(" [W] "fmt"\x1b[0m"LOG_EOL, ##__VA_ARGS__); \
} while(0)
#endif // HTTPD_LOGGING_H

@ -25,7 +25,7 @@ typedef RtosConnType* ConnTypePtr;
#define strlen(a) os_strlen(a)
#define memcmp(a, b, c) os_memcmp(a, b, c)
typedef struct espconn* ConnTypePtr;
#define httpd_printf(format, ...) os_printf(format, ##__VA_ARGS__)
//#define httpd_printf(format, ...) os_printf(format, ##__VA_ARGS__)
#endif

@ -55,7 +55,7 @@ int ICACHE_FLASH_ATTR cgiGetFirmwareNext(HttpdConnData *connData) {
httpdEndHeaders(connData);
char *next = id == 1 ? "user1.bin" : "user2.bin";
httpdSend(connData, next, -1);
httpd_printf("Next firmware: %s (got %d)\n", next, id);
dbg("Next firmware: %s (got %d)", next, id);
return HTTPD_CGI_DONE;
}
@ -70,7 +70,7 @@ int ICACHE_FLASH_ATTR cgiReadFlash(HttpdConnData *connData) {
}
if (*pos==0) {
httpd_printf("Start flash download.\n");
info("Start flash download.");
httpdStartResponse(connData, 200);
httpdHeader(connData, "Content-Type", "application/bin");
httpdEndHeaders(connData);

@ -70,6 +70,7 @@ static void FLASH_FN request_data_sesn_listener(SBMP_Endpoint *ep, SBMP_Datagram
switch (dg->type) {
case DG_BULK_OFFER:// Data ready notification
info("--- Data offered for bulk transfer ---");
setReadoutTmeoTimer(1000);
// data is ready to be read
pp = pp_start(dg->payload, dg->length);
@ -79,13 +80,14 @@ static void FLASH_FN request_data_sesn_listener(SBMP_Endpoint *ep, SBMP_Datagram
dbg("Total bytes: %d", readState->total);
retry_TO(100, sbmp_bulk_request(ep, readState->pos, CHUNK_LEN, dg->session));
// we choose to request the data immediately
setReadoutTmeoTimer(500);
retry_TO(100, sbmp_bulk_request(ep, readState->pos, CHUNK_LEN, dg->session));
break;
case DG_BULK_DATA: // data received
info("--- Received a chunk, length %d ---", dg->length);
setReadoutTmeoTimer(1000);
// Process the received data
pp = pp_start(dg->payload, dg->length);
@ -110,7 +112,6 @@ static void FLASH_FN request_data_sesn_listener(SBMP_Endpoint *ep, SBMP_Datagram
} else {
// read next part
retry_TO(100, sbmp_bulk_request(ep, readState->pos, CHUNK_LEN, dg->session));
setReadoutTmeoTimer(500);
}
break;

@ -55,13 +55,25 @@
/**
* @brief Enable detailed logging (only for debugging, disable for better performance).
*/
#define SBMP_DEBUG 0
#define SBMP_DEBUG 1
// here are the actual logging functions
#define sbmp_error(fmt, ...) (SBMP_DEBUG||SBMP_LOGGING ? os_printf("\x1b[31;1m[SBMP][E] "fmt"\x1b[0m\n", ##__VA_ARGS__) : 0)
#define sbmp_warn(fmt, ...) (SBMP_DEBUG||SBMP_LOGGING ? os_printf("\x1b[33;1m[SBMP][E] "fmt"\x1b[0m\n", ##__VA_ARGS__) : 0)
#define sbmp_info(fmt, ...) (SBMP_DEBUG||SBMP_LOGGING ? os_printf("\x1b[32m[SBMP][i] "fmt"\x1b[0m\n", ##__VA_ARGS__) : 0)
#define sbmp_dbg(fmt, ...) (SBMP_DEBUG ? os_printf("[SBMP][ ] "fmt"\n", ##__VA_ARGS__) : 0)
#if SBMP_DEBUG||SBMP_LOGGING
# define sbmp_error(fmt, ...) error("[SBMP] "fmt, ##__VA_ARGS__)
# define sbmp_warn(fmt, ...) warn("[SBMP] "fmt, ##__VA_ARGS__)
# define sbmp_info(fmt, ...) info("[SBMP] "fmt, ##__VA_ARGS__)
#else
# define sbmp_error(fmt, ...)
# define sbmp_warn(fmt, ...)
# define sbmp_info(fmt, ...)
#endif
#if SBMP_DEBUG
# define sbmp_dbg(fmt, ...) dbg("[SBMP] "fmt, ##__VA_ARGS__)
#else
# define sbmp_dbg(fmt, ...)
#endif
/* ---------- Fix formatting -------------- */

@ -36,3 +36,24 @@ void uptime_str(char *buf)
sprintf(buf, "%02u:%02u:%02u", hours, mins, secs);
}
}
void uptime_print(void)
{
u32 a = uptime;
u32 days = a / 86400;
a -= days * 86400;
u32 hours = a / 3600;
a -= hours * 3600;
u32 mins = a / 60;
a -= mins * 60;
u32 secs = a;
if (days > 0) {
printf("%ud %02u:%02u:%02u", days, hours, mins, secs);
} else {
printf("%02u:%02u:%02u", hours, mins, secs);
}
}

@ -10,4 +10,6 @@ void uptime_timer_init(void);
/** Print uptime to a buffer. Should be at least 20 long. */
void uptime_str(char *buf);
void uptime_print(void);
#endif // UPTIME_H

@ -43,9 +43,7 @@ static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg)
if (++cnt == 3) {
cnt = 0;
u32 heap = system_get_free_heap_size();
char upt[20];
uptime_str(upt);
os_printf("%s, heap: %u (~ %d)\n", upt, heap, (heap-last));
dbg("Heap: %u (~ %d)\n", heap, (heap-last));
last = heap;
}

Loading…
Cancel
Save