From 4c2421121f9adedb5d6b902525a586e7ade7013b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Mon, 11 Sep 2017 00:08:50 +0200 Subject: [PATCH] moved funcs to flash to make it build again, reduced logging buffer, disabled some logging; add missing files --- CMakeLists.txt | 2 +- Makefile | 18 ++- esphttpdconfig.mk | 11 +- showmem.php | 58 ++++++++++ user/apars_csi.c | 36 +++--- user/apars_dcs.c | 4 +- user/apars_osc.c | 2 +- user/apars_short.c | 2 +- user/apars_utf8.c | 2 +- user/cgi_logging.h | 18 +++ user/cgi_network.c | 39 +++---- user/cgi_persist.c | 5 +- user/cgi_sockets.c | 7 +- user/cgi_system.c | 17 +-- user/cgi_term_cfg.c | 71 ++++++------ user/cgi_wifi.c | 43 +++---- user/character_sets.h | 10 +- user/persist.c | 54 ++++----- user/persist.h | 10 ++ user/screen.c | 257 ++++++++++++++++++++++++++++-------------- user/screen.h | 8 +- user/serial.c | 5 +- user/uart_buffer.c | 3 +- user/uart_handler.c | 6 +- user/user_main.c | 2 +- user/utf8.c | 58 ++++++++++ user/utf8.h | 12 ++ user/wifimgr.c | 38 +++---- user/wifimgr.h | 10 ++ 29 files changed, 541 insertions(+), 267 deletions(-) create mode 100755 showmem.php create mode 100644 user/cgi_logging.h create mode 100644 user/utf8.c create mode 100644 user/utf8.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a5a59a5..c2e420d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,7 +139,7 @@ set(SOURCE_FILES user/apars_osc.c user/apars_osc.h user/apars_dcs.c - user/apars_dcs.h user/uart_buffer.c user/uart_buffer.h user/jstring.c user/jstring.h user/character_sets.h) + user/apars_dcs.h user/uart_buffer.c user/uart_buffer.h user/jstring.c user/jstring.h user/character_sets.h user/utf8.h user/utf8.c user/cgi_logging.h) include_directories(include) include_directories(user) diff --git a/Makefile b/Makefile index 1c3c4a7..51f3721 100644 --- a/Makefile +++ b/Makefile @@ -62,8 +62,8 @@ LIBS = c gcc hal phy pp net80211 wpa main lwip crypto #Add in esphttpd lib LIBS += esphttpd -# compiler flags using during compilation of source files -CFLAGS = -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ +# compiler flags using during compilation of source files -ggdb +CFLAGS = -Os -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH \ -Wno-address -Wno-unused @@ -171,7 +171,7 @@ MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) ESP_FLASH_SIZE_IX=$(call maplookup,$(ESP_SPI_FLASH_SIZE_K),512:0 1024:2 2048:5 4096:6) ESPTOOL_FREQ=$(call maplookup,$(ESP_FLASH_FREQ_DIV),0:40m 1:26m 2:20m 0xf:80m 15:80m) ESPTOOL_MODE=$(call maplookup,$(ESP_FLASH_MODE),0:qio 1:qout 2:dio 3:dout) -ESPTOOL_SIZE=$(call maplookup,$(ESP_SPI_FLASH_SIZE_K),512:4m 256:2m 1024:8m 2048:16m 4096:32m) +ESPTOOL_SIZE=$(call maplookup,$(ESP_SPI_FLASH_SIZE_K),512:512KB 256:256KB 1024:1MB 2048:2MB 4096:4MB) ESPTOOL_OPTS=--port $(ESPPORT) --baud $(ESPBAUD) ESPTOOL_FLASHDEF=--flash_freq $(ESPTOOL_FREQ) --flash_mode $(ESPTOOL_MODE) --flash_size $(ESPTOOL_SIZE) @@ -189,7 +189,7 @@ $1/%.o: %.S $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ endef -.PHONY: all web parser checkdirs clean libesphttpd default-tgt +.PHONY: all web parser checkdirs clean libesphttpd default-tgt espsize espmac web: $(Q) ./build_web.sh @@ -197,7 +197,13 @@ web: parser: $(Q) ./build_parser.sh -all: checkdirs web parser $(TARGET_OUT) $(FW_BASE) +espsize: + $(Q) esptool --port /dev/ttyUSB0 flash_id + +espmac: + $(Q) esptool --port /dev/ttyUSB0 read_mac + +all: checkdirs parser $(TARGET_OUT) $(FW_BASE) libesphttpd/Makefile: $(Q) [[ -e "libesphttpd/Makefile" ]] || echo -e "\e[31mlibesphttpd submodule missing.\nIf build fails, run \"git submodule init\" and \"git submodule update\".\e[0m" @@ -209,7 +215,7 @@ $(APP_AR): libesphttpd $(OBJ) $(vecho) "AR $@" $(Q) $(AR) cru $@ $(OBJ) -checkdirs: $(BUILD_DIR) +checkdirs: $(BUILD_DIR) html/favicon.ico $(BUILD_DIR): $(Q) mkdir -p $@ diff --git a/esphttpdconfig.mk b/esphttpdconfig.mk index 2f53c05..56a017a 100644 --- a/esphttpdconfig.mk +++ b/esphttpdconfig.mk @@ -44,16 +44,19 @@ ADMIN_PASSWORD = "19738426" GLOBAL_CFLAGS = \ -DDEBUG_ROUTER=0 \ -DDEBUG_CAPTDNS=0 \ - -DDEBUG_HTTP=1 \ + -DDEBUG_HTTP=0 \ -DDEBUG_ESPFS=0 \ + -DDEBUG_PERSIST=0 \ + -DDEBUG_CGI=0 \ + -DDEBUG_WIFI=0 \ -DDEBUG_WS=0 \ -DDEBUG_ANSI=1 \ -DDEBUG_ANSI_NOIMPL=1 \ - -DHTTPD_MAX_BACKLOG_SIZE=8192 \ - -DHTTPD_MAX_HEAD_LEN=1024 \ - -DHTTPD_MAX_POST_LEN=512 \ -DDEBUG_INPUT=0 \ -DDEBUG_HEAP=1 \ -DDEBUG_MALLOC=0 \ + -DHTTPD_MAX_BACKLOG_SIZE=8192 \ + -DHTTPD_MAX_HEAD_LEN=1024 \ + -DHTTPD_MAX_POST_LEN=512 \ -mforce-l32 \ -DUSE_OPTIMIZE_PRINTF=1 diff --git a/showmem.php b/showmem.php new file mode 100755 index 0000000..d142615 --- /dev/null +++ b/showmem.php @@ -0,0 +1,58 @@ +#!/bin/env php + $bv); + }); +} + +$all_sections = array_diff($all_sections, [ + '.comment', + '.xtensa.info', + '.xt.lit', + '.xt.prop', + '.literal', + '.irom0.literal', + '.data', +]); + +$widths = []; +foreach($all_sections as $k) { + $widths[$k] = max(8, strlen($k)); + printf("%".($widths[$k])."s ", $k); +} +echo "\n";//.str_repeat('-',array_sum($widths))."\n"; + +foreach ($table as $file => $map) { + foreach ($all_sections as $space) { + $b = isset($map[$space]) ? $map[$space] : 0; + printf("%".$widths[$space]."d ", $b); + } + echo " $file\n"; +} diff --git a/user/apars_csi.c b/user/apars_csi.c index acccf48..fc12b02 100644 --- a/user/apars_csi.c +++ b/user/apars_csi.c @@ -49,7 +49,8 @@ static inline void do_csi_set_private_option(CSI_Data *opts); /** * Show warning and dump context for invalid CSI */ -static void warn_bad_csi(void) +static void ICACHE_FLASH_ATTR +warn_bad_csi(void) { ansi_noimpl_r("Unknown CSI"); apars_show_context(); @@ -487,27 +488,32 @@ switch_csi_LeadEquals(CSI_Data *opts) static inline void ICACHE_FLASH_ATTR switch_csi_LeadQuest(CSI_Data *opts) { + int n = 0; switch(opts->key) { case 's': // Save private attributes - ansi_noimpl("Save private attrs"); - apars_show_context(); // TODO priv attr s/r + for (int i = 0; i < opts->count; i++) { + n = opts->n[i]; + screen_save_private_opt(n); + } break; case 'r': // Restore private attributes - ansi_noimpl("Restore private attrs"); - apars_show_context(); // TODO priv attr s/r + for (int i = 0; i < opts->count; i++) { + n = opts->n[i]; + screen_restore_private_opt(n); + } break; case 'J': // Erase screen selectively // TODO selective erase - ansi_noimpl("Selective screen erase"); + switch_csi_Plain(opts); // ignore the ?, do normal erase break; case 'K': // Erase line selectively // TODO selective erase - ansi_noimpl("Selective line erase"); + switch_csi_Plain(opts); // ignore the ?, do normal erase break; case 'l': @@ -546,8 +552,8 @@ do_csi_sgr(CSI_Data *opts) else if (n >= SGR_FG_BRT_START && n <= SGR_FG_BRT_END) screen_set_fg((Color) ((n - SGR_FG_BRT_START) + 8)); // AIX bright fg else if (n >= SGR_BG_BRT_START && n <= SGR_BG_BRT_END) screen_set_bg((Color) ((n - SGR_BG_BRT_START) + 8)); // AIX bright bg // reset color - else if (n == SGR_FG_DEFAULT) screen_set_fg(termconf_scratch.default_fg); // default fg - else if (n == SGR_BG_DEFAULT) screen_set_bg(termconf_scratch.default_bg); // default bg + else if (n == SGR_FG_DEFAULT) screen_set_fg(termconf_live.default_fg); // default fg + else if (n == SGR_BG_DEFAULT) screen_set_bg(termconf_live.default_bg); // default bg // 256 colors else if (n == SGR_FG_256 || n == SGR_BG_256) { if (i < count-2) { @@ -617,7 +623,7 @@ do_csi_set_option(CSI_Data *opts) } else if (n == 12) { // SRM is inverted, according to vt510 manual - termconf_scratch.loopback = !yn; + termconf_live.loopback = !yn; } else if (n == 20) { screen_set_newline_mode(yn); @@ -754,11 +760,11 @@ do_csi_set_private_option(CSI_Data *opts) ansi_noimpl("Bracketed paste"); } else if (n == 800) { // ESPTerm: Toggle display of buttons - termconf_scratch.show_buttons = yn; + termconf_live.show_buttons = yn; screen_notifyChange(CHANGE_CONTENT); // this info is included in the screen preamble } else if (n == 801) { // ESPTerm: Toggle display of config links - termconf_scratch.show_config_links = yn; + termconf_live.show_config_links = yn; screen_notifyChange(CHANGE_CONTENT); // this info is included in the screen preamble } else { @@ -783,14 +789,14 @@ do_csi_xterm_screen_cmd(CSI_Data *opts) case 18: // Report the size of the text area in characters. case 19: // Report the size of the screen in characters. - sprintf(resp_buf, "\033[8;%d;%dt", termconf_scratch.height, termconf_scratch.width); + sprintf(resp_buf, "\033[8;%d;%dt", termconf_live.height, termconf_live.width); apars_respond(resp_buf); break; case 20: // Report icon case 21: // Report title apars_respond("\033]l"); - apars_respond(termconf_scratch.title); + apars_respond(termconf_live.title); apars_respond("\033\\"); break; @@ -802,7 +808,7 @@ do_csi_xterm_screen_cmd(CSI_Data *opts) break; case 24: // Set Height only - screen_resize(opts->n[1], termconf_scratch.width); + screen_resize(opts->n[1], termconf_live.width); break; default: diff --git a/user/apars_dcs.c b/user/apars_dcs.c index a454d5e..5238582 100644 --- a/user/apars_dcs.c +++ b/user/apars_dcs.c @@ -47,12 +47,12 @@ apars_handle_dcs(const char *buffer) } else if (buffer[2] == 'r') { // DECSTBM - Query scrolling region - sprintf(buf, "\033P1$r%d;%dr\033\\", 1, termconf_scratch.height); // 1-80 TODO real extent of scrolling region + sprintf(buf, "\033P1$r%d;%dr\033\\", 1, termconf_live.height); // 1-80 TODO real extent of scrolling region apars_respond(buf); } else if (buffer[2] == 's') { // DECSLRM - Query horizontal margins - sprintf(buf, "\033P1$r%d;%ds\033\\", 1, termconf_scratch.width); // Can erase - TODO real extent of horiz margins if implemented + sprintf(buf, "\033P1$r%d;%ds\033\\", 1, termconf_live.width); // Can erase - TODO real extent of horiz margins if implemented apars_respond(buf); } else if (buffer[2] == 'm') { diff --git a/user/apars_osc.c b/user/apars_osc.c index 2f05817..28c68b0 100644 --- a/user/apars_osc.c +++ b/user/apars_osc.c @@ -52,7 +52,7 @@ apars_handle_osc(char *buffer) } else if (n >= 91 && n <= 95) { // ESPTerm: action button message - strncpy(termconf_scratch.btn_msg[n - 91], buffer, TERM_BTN_MSG_LEN); + strncpy(termconf_live.btn_msg[n - 91], buffer, TERM_BTN_MSG_LEN); } else { ansi_noimpl("OSC %d ; %s ST", n, buffer); diff --git a/user/apars_short.c b/user/apars_short.c index b9bace9..64ae3ab 100644 --- a/user/apars_short.c +++ b/user/apars_short.c @@ -139,7 +139,7 @@ void ICACHE_FLASH_ATTR apars_handle_short_cmd(char c) break; case 'F': // bottom left - screen_cursor_set(termconf_scratch.height-1, 0); + screen_cursor_set(termconf_live.height-1, 0); break; case 'D': // move cursor down, scroll screen up if needed diff --git a/user/apars_utf8.c b/user/apars_utf8.c index a01a16b..b3f502c 100644 --- a/user/apars_utf8.c +++ b/user/apars_utf8.c @@ -37,7 +37,7 @@ apars_handle_plainchar(char c) if (utf_i == 0) { // start if (c == 192 || c == 193 || c >= 245) { - // forbidden codes + // forbidden codes (would be an overlong sequence) goto fail; } diff --git a/user/cgi_logging.h b/user/cgi_logging.h new file mode 100644 index 0000000..db1cf2b --- /dev/null +++ b/user/cgi_logging.h @@ -0,0 +1,18 @@ +// +// Created by MightyPork on 2017/09/10. +// + +#ifndef ESPTERM_CGI_LOGGING_H +#define ESPTERM_CGI_LOGGING_H + +#if DEBUG_CGI +#define cgi_warn warn +#define cgi_dbg dbg +#define cgi_info info +#else +#define cgi_warn(fmt, ...) +#define cgi_dbg(fmt, ...) +#define cgi_info(fmt, ...) +#endif + +#endif //ESPTERM_CGI_LOGGING_H diff --git a/user/cgi_network.c b/user/cgi_network.c index 66bed17..b87dd96 100644 --- a/user/cgi_network.c +++ b/user/cgi_network.c @@ -8,6 +8,7 @@ configuring the network settings #include "wifimgr.h" #include "persist.h" #include "helpers.h" +#include "cgi_logging.h" #define SET_REDIR_SUC "/cfg/network" #define SET_REDIR_ERR SET_REDIR_SUC"?err=" @@ -43,7 +44,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) // ---- AP DHCP server lease time ---- if (GET_ARG("ap_dhcp_time")) { - dbg("Setting DHCP lease time to: %s min.", buff); + cgi_dbg("Setting DHCP lease time to: %s min.", buff); int min = atoi(buff); if (min >= 1 && min <= 2880) { if (wificonf->ap_dhcp_time != min) { @@ -51,7 +52,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) wifi_change_flags.ap = true; } } else { - warn("Lease time %s out of allowed range 1-2880.", buff); + cgi_warn("Lease time %s out of allowed range 1-2880.", buff); redir_url += sprintf(redir_url, "ap_dhcp_time,"); } } @@ -59,7 +60,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) // ---- AP DHCP start and end IP ---- if (GET_ARG("ap_dhcp_start")) { - dbg("Setting DHCP range start IP to: \"%s\"", buff); + cgi_dbg("Setting DHCP range start IP to: \"%s\"", buff); u32 ip = ipaddr_addr(buff); if (ip != 0) { if (wificonf->ap_dhcp_range.start_ip.addr != ip) { @@ -67,13 +68,13 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) wifi_change_flags.ap = true; } } else { - warn("Bad IP: %s", buff); + cgi_warn("Bad IP: %s", buff); redir_url += sprintf(redir_url, "ap_dhcp_start,"); } } if (GET_ARG("ap_dhcp_end")) { - dbg("Setting DHCP range end IP to: \"%s\"", buff); + cgi_dbg("Setting DHCP range end IP to: \"%s\"", buff); u32 ip = ipaddr_addr(buff); if (ip != 0) { if (wificonf->ap_dhcp_range.end_ip.addr != ip) { @@ -81,7 +82,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) wifi_change_flags.ap = true; } } else { - warn("Bad IP: %s", buff); + cgi_warn("Bad IP: %s", buff); redir_url += sprintf(redir_url, "ap_dhcp_end,"); } } @@ -89,7 +90,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) // ---- AP local address & config ---- if (GET_ARG("ap_addr_ip")) { - dbg("Setting AP local IP to: \"%s\"", buff); + cgi_dbg("Setting AP local IP to: \"%s\"", buff); u32 ip = ipaddr_addr(buff); if (ip != 0) { if (wificonf->ap_addr.ip.addr != ip) { @@ -98,13 +99,13 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) wifi_change_flags.ap = true; } } else { - warn("Bad IP: %s", buff); + cgi_warn("Bad IP: %s", buff); redir_url += sprintf(redir_url, "ap_addr_ip,"); } } if (GET_ARG("ap_addr_mask")) { - dbg("Setting AP local IP netmask to: \"%s\"", buff); + cgi_dbg("Setting AP local IP netmask to: \"%s\"", buff); u32 ip = ipaddr_addr(buff); if (ip != 0) { if (wificonf->ap_addr.netmask.addr != ip) { @@ -114,7 +115,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) wifi_change_flags.ap = true; } } else { - warn("Bad IP mask: %s", buff); + cgi_warn("Bad IP mask: %s", buff); redir_url += sprintf(redir_url, "ap_addr_mask,"); } } @@ -123,7 +124,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) // DHCP enable / disable (disable means static IP is enabled) if (GET_ARG("sta_dhcp_enable")) { - dbg("DHCP enable = %s", buff); + cgi_dbg("DHCP enable = %s", buff); int enable = atoi(buff); if (wificonf->sta_dhcp_enable != enable) { wificonf->sta_dhcp_enable = (bool)enable; @@ -134,7 +135,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) // ---- Station IP config (Static IP) ---- if (GET_ARG("sta_addr_ip")) { - dbg("Setting Station mode static IP to: \"%s\"", buff); + cgi_dbg("Setting Station mode static IP to: \"%s\"", buff); u32 ip = ipaddr_addr(buff); if (ip != 0) { if (wificonf->sta_addr.ip.addr != ip) { @@ -142,13 +143,13 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) wifi_change_flags.sta = true; } } else { - warn("Bad IP: %s", buff); + cgi_warn("Bad IP: %s", buff); redir_url += sprintf(redir_url, "sta_addr_ip,"); } } if (GET_ARG("sta_addr_mask")) { - dbg("Setting Station mode static IP netmask to: \"%s\"", buff); + cgi_dbg("Setting Station mode static IP netmask to: \"%s\"", buff); u32 ip = ipaddr_addr(buff); if (ip != 0 && ip != 0xFFFFFFFFUL) { if (wificonf->sta_addr.netmask.addr != ip) { @@ -156,13 +157,13 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) wifi_change_flags.sta = true; } } else { - warn("Bad IP mask: %s", buff); + cgi_warn("Bad IP mask: %s", buff); redir_url += sprintf(redir_url, "sta_addr_mask,"); } } if (GET_ARG("sta_addr_gw")) { - dbg("Setting Station mode static IP default gateway to: \"%s\"", buff); + cgi_dbg("Setting Station mode static IP default gateway to: \"%s\"", buff); u32 ip = ipaddr_addr(buff); if (ip != 0) { if (wificonf->sta_addr.gw.addr != ip) { @@ -170,14 +171,14 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) wifi_change_flags.sta = true; } } else { - warn("Bad gw IP: %s", buff); + cgi_warn("Bad gw IP: %s", buff); redir_url += sprintf(redir_url, "sta_addr_gw,"); } } if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) { // All was OK - info("Set network params - success, applying in 1000 ms"); + cgi_info("Set network params - success, applying in 1000 ms"); // Settings are applied only if all was OK persist_store(); @@ -190,7 +191,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData) httpdRedirect(connData, SET_REDIR_SUC); } else { - warn("Some WiFi settings did not validate, asking for correction"); + cgi_warn("Some WiFi settings did not validate, asking for correction"); // Some errors, appended to the URL as ?err= httpdRedirect(connData, redir_url_buf); } diff --git a/user/cgi_persist.c b/user/cgi_persist.c index 92bfefd..4828b8a 100644 --- a/user/cgi_persist.c +++ b/user/cgi_persist.c @@ -6,6 +6,7 @@ Cgi/template routines for configuring non-wifi settings #include "cgi_persist.h" #include "persist.h" #include "helpers.h" +#include "cgi_logging.h" #define SET_REDIR_SUC "/cfg/admin" @@ -29,9 +30,9 @@ cgiPersistWriteDefaults(HttpdConnData *connData) // width and height must always go together so we can do max size validation if (GET_ARG("pw")) { - dbg("Entered password for admin: %s", buff); + cgi_dbg("Entered password for admin: %s", buff); if (verify_admin_pw(buff)) { - dbg("pw is OK"); + cgi_dbg("pw is OK"); persist_set_as_default(); diff --git a/user/cgi_sockets.c b/user/cgi_sockets.c index 1fc2879..6fcf87a 100644 --- a/user/cgi_sockets.c +++ b/user/cgi_sockets.c @@ -8,6 +8,7 @@ #include "ansi_parser.h" #include "jstring.h" #include "uart_driver.h" +#include "cgi_logging.h" // Heartbeat interval in ms #define HB_TIME 1000 @@ -243,7 +244,7 @@ void ICACHE_FLASH_ATTR updateSockRx(Websock *ws, char *data, int len, int flags) switch (c) { case 's': // pass string verbatim - if (termconf_scratch.loopback) { + if (termconf_live.loopback) { for (int i = 1; i < len; i++) { ansi_parser(data[i]); } @@ -264,13 +265,13 @@ void ICACHE_FLASH_ATTR updateSockRx(Websock *ws, char *data, int len, int flags) // action button press btnNum = (u8) (data[1]); if (btnNum > 0 && btnNum < 10) { - UART_SendAsync(termconf_scratch.btn_msg[btnNum-1], -1); + UART_SendAsync(termconf_live.btn_msg[btnNum-1], -1); } break; case 'i': // requests initial load - dbg("Client requests initial load"); + ws_dbg("Client requests initial load"); notifyContentTimCb(ws); break; diff --git a/user/cgi_system.c b/user/cgi_system.c index ee45b6b..1b70289 100755 --- a/user/cgi_system.c +++ b/user/cgi_system.c @@ -8,6 +8,7 @@ #include "syscfg.h" #include "uart_driver.h" #include "ansi_parser.h" +#include "cgi_logging.h" #define SET_REDIR_SUC "/cfg/system" #define SET_REDIR_ERR SET_REDIR_SUC"?err=" @@ -90,7 +91,7 @@ cgiSystemCfgSetParams(HttpdConnData *connData) } if (GET_ARG("uart_baud")) { - dbg("Baud rate: %s", buff); + cgi_dbg("Baud rate: %s", buff); int baud = atoi(buff); if (baud == BIT_RATE_300 || baud == BIT_RATE_600 || @@ -110,43 +111,43 @@ cgiSystemCfgSetParams(HttpdConnData *connData) baud == BIT_RATE_3686400) { sysconf->uart_baudrate = (u32) baud; } else { - warn("Bad baud rate %s", buff); + cgi_warn("Bad baud rate %s", buff); redir_url += sprintf(redir_url, "uart_baud,"); } } if (GET_ARG("uart_parity")) { - dbg("Parity: %s", buff); + cgi_dbg("Parity: %s", buff); int parity = atoi(buff); if (parity >= 0 && parity <= 2) { sysconf->uart_parity = (UartParityMode) parity; } else { - warn("Bad parity %s", buff); + cgi_warn("Bad parity %s", buff); redir_url += sprintf(redir_url, "uart_parity,"); } } if (GET_ARG("uart_stopbits")) { - dbg("Stop bits: %s", buff); + cgi_dbg("Stop bits: %s", buff); int stopbits = atoi(buff); if (stopbits >= 1 && stopbits <= 3) { sysconf->uart_stopbits = (UartStopBitsNum) stopbits; } else { - warn("Bad stopbits %s", buff); + cgi_warn("Bad stopbits %s", buff); redir_url += sprintf(redir_url, "uart_stopbits,"); } } if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) { // All was OK - info("Set system params - success, saving..."); + cgi_info("Set system params - success, saving..."); sysconf_apply_settings(); persist_store(); httpdRedirect(connData, SET_REDIR_SUC); } else { - warn("Some settings did not validate, asking for correction"); + cgi_warn("Some settings did not validate, asking for correction"); // Some errors, appended to the URL as ?err= httpdRedirect(connData, redir_url_buf); } diff --git a/user/cgi_term_cfg.c b/user/cgi_term_cfg.c index ba67357..2b656f2 100644 --- a/user/cgi_term_cfg.c +++ b/user/cgi_term_cfg.c @@ -8,6 +8,7 @@ Cgi/template routines for configuring non-wifi settings #include "persist.h" #include "screen.h" #include "helpers.h" +#include "cgi_logging.h" #define SET_REDIR_SUC "/cfg/term" #define SET_REDIR_ERR SET_REDIR_SUC"?err=" @@ -36,11 +37,11 @@ cgiTermCfgSetParams(HttpdConnData *connData) // width and height must always go together so we can do max size validation if (GET_ARG("term_width")) { - dbg("Default screen width: %s", buff); + cgi_dbg("Default screen width: %s", buff); w = atoi(buff); if (w > 1) { if (GET_ARG("term_height")) { - dbg("Default screen height: %s", buff); + cgi_dbg("Default screen height: %s", buff); h = atoi(buff); if (h > 1) { if (w * h <= MAX_SCREEN_SIZE) { @@ -50,26 +51,26 @@ cgiTermCfgSetParams(HttpdConnData *connData) shall_clear_screen = true; // this causes a notify } } else { - warn("Bad dimensions: %d x %d (total %d)", w, h, w*h); + cgi_warn("Bad dimensions: %d x %d (total %d)", w, h, w*h); redir_url += sprintf(redir_url, "term_width,term_height,"); } } else { - warn("Bad height: \"%s\"", buff); + cgi_warn("Bad height: \"%s\"", buff); redir_url += sprintf(redir_url, "term_width,"); } } else { - warn("Missing height arg!"); + cgi_warn("Missing height arg!"); // this wont happen normally when the form is used redir_url += sprintf(redir_url, "term_width,term_height,"); } } else { - warn("Bad width: \"%s\"", buff); + cgi_warn("Bad width: \"%s\"", buff); redir_url += sprintf(redir_url, "term_width,"); } } if (GET_ARG("default_bg")) { - dbg("Screen default BG: %s", buff); + cgi_dbg("Screen default BG: %s", buff); n = atoi(buff); if (n >= 0 && n < 16) { if (termconf->default_bg != n) { @@ -77,13 +78,13 @@ cgiTermCfgSetParams(HttpdConnData *connData) shall_clear_screen = true; } } else { - warn("Bad color %s", buff); + cgi_warn("Bad color %s", buff); redir_url += sprintf(redir_url, "default_bg,"); } } if (GET_ARG("default_fg")) { - dbg("Screen default FG: %s", buff); + cgi_dbg("Screen default FG: %s", buff); n = atoi(buff); if (n >= 0 && n < 16) { if (termconf->default_fg != n) { @@ -91,104 +92,104 @@ cgiTermCfgSetParams(HttpdConnData *connData) shall_clear_screen = true; } } else { - warn("Bad color %s", buff); + cgi_warn("Bad color %s", buff); redir_url += sprintf(redir_url, "default_fg,"); } } if (GET_ARG("parser_tout_ms")) { - dbg("Parser timeout: %s ms", buff); + cgi_dbg("Parser timeout: %s ms", buff); n = atoi(buff); if (n >= 0) { termconf->parser_tout_ms = n; } else { - warn("Bad parser timeout %s", buff); + cgi_warn("Bad parser timeout %s", buff); redir_url += sprintf(redir_url, "parser_tout_ms,"); } } if (GET_ARG("display_tout_ms")) { - dbg("Display update idle timeout: %s ms", buff); + cgi_dbg("Display update idle timeout: %s ms", buff); n = atoi(buff); if (n > 0) { termconf->display_tout_ms = n; } else { - warn("Bad update timeout %s", buff); + cgi_warn("Bad update timeout %s", buff); redir_url += sprintf(redir_url, "display_tout_ms,"); } } if (GET_ARG("display_cooldown_ms")) { - dbg("Display update cooldown: %s ms", buff); + cgi_dbg("Display update cooldown: %s ms", buff); n = atoi(buff); if (n > 0) { termconf->display_cooldown_ms = n; } else { - warn("Bad cooldown %s", buff); + cgi_warn("Bad cooldown %s", buff); redir_url += sprintf(redir_url, "display_cooldown_ms,"); } } if (GET_ARG("fn_alt_mode")) { - dbg("FN alt mode: %s", buff); + cgi_dbg("FN alt mode: %s", buff); n = atoi(buff); termconf->fn_alt_mode = (bool)n; notify_screen_content = true; } if (GET_ARG("crlf_mode")) { - dbg("CRLF mode: %s", buff); + cgi_dbg("CRLF mode: %s", buff); n = atoi(buff); termconf->crlf_mode = (bool)n; notify_screen_content = true; } if (GET_ARG("show_buttons")) { - dbg("Show buttons: %s", buff); + cgi_dbg("Show buttons: %s", buff); n = atoi(buff); termconf->show_buttons = (bool)n; notify_screen_content = true; } if (GET_ARG("show_config_links")) { - dbg("Show config links: %s", buff); + cgi_dbg("Show config links: %s", buff); n = atoi(buff); termconf->show_config_links = (bool)n; notify_screen_content = true; } if (GET_ARG("loopback")) { - dbg("Loopback: %s", buff); + cgi_dbg("Loopback: %s", buff); n = atoi(buff); termconf->loopback = (bool)n; } if (GET_ARG("theme")) { - dbg("Screen color theme: %s", buff); + cgi_dbg("Screen color theme: %s", buff); n = atoi(buff); if (n >= 0 && n <= 5) { // ALWAYS ADJUST WHEN ADDING NEW THEME! termconf->theme = (u8) n; // this can't be notified, page must reload. } else { - warn("Bad theme num: %s", buff); + cgi_warn("Bad theme num: %s", buff); redir_url += sprintf(redir_url, "theme,"); } } if (GET_ARG("cursor_shape")) { - dbg("Cursor shape: %s", buff); + cgi_dbg("Cursor shape: %s", buff); n = atoi(buff); if (n >= 0 && n <= 6 && n != 1) { termconf->cursor_shape = (enum CursorShape) n; notify_screen_content = true; } else { - warn("Bad cursor_shape num: %s", buff); + cgi_warn("Bad cursor_shape num: %s", buff); redir_url += sprintf(redir_url, "cursor_shape,"); } } if (GET_ARG("term_title")) { - dbg("Terminal title default text: \"%s\"", buff); + cgi_dbg("Terminal title default text: \"%s\"", buff); strncpy_safe(termconf->title, buff, 64); // ATTN those must match the values in notify_screen_labels = true; } @@ -196,14 +197,14 @@ cgiTermCfgSetParams(HttpdConnData *connData) for (int btn_i = 1; btn_i <= TERM_BTN_COUNT; btn_i++) { sprintf(buff, "btn%d", btn_i); if (GET_ARG(buff)) { - dbg("Button%d default text: \"%s\"", btn_i, buff); + cgi_dbg("Button%d default text: \"%s\"", btn_i, buff); strncpy_safe(termconf->btn[btn_i-1], buff, TERM_BTN_LEN); notify_screen_labels = true; } sprintf(buff, "bm%d", btn_i); if (GET_ARG(buff)) { - dbg("Button%d message (ASCII): \"%s\"", btn_i, buff); + cgi_dbg("Button%d message (ASCII): \"%s\"", btn_i, buff); // parse: comma,space or semicolon separated decimal values of ASCII codes char c; @@ -217,18 +218,18 @@ cgiTermCfgSetParams(HttpdConnData *connData) if(lastsp) continue; if (acu==0 || acu>255) { - warn("Bad value! %d", acu); + cgi_warn("Bad value! %d", acu); redir_url += sprintf(redir_url, "bm%d,", btn_i); break; } if (char_i >= TERM_BTN_MSG_LEN-1) { - warn("Too long! %d", acu); + cgi_warn("Too long! %d", acu); redir_url += sprintf(redir_url, "bm%d,", btn_i); break; } - dbg("acu %d", acu); + cgi_dbg("acu %d", acu); buff_bm[char_i++] = (char)acu; // prepare for next char @@ -239,20 +240,20 @@ cgiTermCfgSetParams(HttpdConnData *connData) acu *= 10; acu += c - '0'; } else { - warn("Bad syntax!"); + cgi_warn("Bad syntax!"); redir_url += sprintf(redir_url, "bm%d,", btn_i); break; } } if (lastsp && char_i == 0) { - warn("Required!"); + cgi_warn("Required!"); redir_url += sprintf(redir_url, "bm%d,", btn_i); } if (!lastsp) { buff_bm[char_i++] = (char)acu; } buff_bm[char_i] = 0; - dbg("%s, chari = %d", buff_bm, char_i); + cgi_dbg("%s, chari = %d", buff_bm, char_i); strncpy(termconf->btn_msg[btn_i-1], buff_bm, TERM_BTN_MSG_LEN); } @@ -280,7 +281,7 @@ cgiTermCfgSetParams(HttpdConnData *connData) httpdRedirect(connData, SET_REDIR_SUC); } else { - warn("Some settings did not validate, asking for correction"); + cgi_warn("Some settings did not validate, asking for correction"); // Some errors, appended to the URL as ?err= httpdRedirect(connData, redir_url_buf); } diff --git a/user/cgi_wifi.c b/user/cgi_wifi.c index 82f9971..df904f3 100644 --- a/user/cgi_wifi.c +++ b/user/cgi_wifi.c @@ -19,6 +19,7 @@ Cgi/template routines for the /wifi url. #include "wifimgr.h" #include "persist.h" #include "helpers.h" +#include "cgi_logging.h" #define SET_REDIR_SUC "/cfg/wifi" #define SET_REDIR_ERR SET_REDIR_SUC"?err=" @@ -116,7 +117,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) { int n; struct bss_info *bss_link = (struct bss_info *) arg; - dbg("wifiScanDoneCb %d", status); + cgi_dbg("wifiScanDoneCb %d", status); if (status != OK) { cgiWifiAps.scanInProgress = 0; return; @@ -141,7 +142,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) return; } cgiWifiAps.noAps = n; - info("Scan done: found %d APs", n); + cgi_info("Scan done: found %d APs", n); // Copy access point data to the static struct n = 0; @@ -288,7 +289,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) } STATION_STATUS st = wifi_station_get_connect_status(); - dbg("CONN STATE = %d", st); + cgi_dbg("CONN STATE = %d", st); switch(st) { case STATION_IDLE: sprintf(buff, "{\"status\": \"idle\"}"); // unclear when this is used @@ -360,18 +361,18 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) // ---- WiFi opmode ---- if (GET_ARG("opmode")) { - dbg("Setting WiFi opmode to: %s", buff); + cgi_dbg("Setting WiFi opmode to: %s", buff); int mode = atoi(buff); if (mode > NULL_MODE && mode < MAX_MODE) { wificonf->opmode = (WIFI_MODE) mode; } else { - warn("Bad opmode value \"%s\"", buff); + cgi_warn("Bad opmode value \"%s\"", buff); redir_url += sprintf(redir_url, "opmode,"); } } if (GET_ARG("ap_enable")) { - dbg("Enable AP: %s", buff); + cgi_dbg("Enable AP: %s", buff); int enable = atoi(buff); if (enable) { @@ -382,7 +383,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) } if (GET_ARG("sta_enable")) { - dbg("Enable STA: %s", buff); + cgi_dbg("Enable STA: %s", buff); int enable = atoi(buff); if (enable) { @@ -396,7 +397,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) // ---- AP transmit power ---- if (GET_ARG("tpw")) { - dbg("Setting AP power to: %s", buff); + cgi_dbg("Setting AP power to: %s", buff); int tpw = atoi(buff); if (tpw >= 0 && tpw <= 82) { // 0 actually isn't 0 but quite low. 82 is very strong if (wificonf->tpw != tpw) { @@ -404,7 +405,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) wifi_change_flags.ap = true; } } else { - warn("tpw %s out of allowed range 0-82.", buff); + cgi_warn("tpw %s out of allowed range 0-82.", buff); redir_url += sprintf(redir_url, "tpw,"); } } @@ -412,7 +413,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) // ---- AP channel (applies in AP-only mode) ---- if (GET_ARG("ap_channel")) { - info("ap_channel = %s", buff); + cgi_info("ap_channel = %s", buff); int channel = atoi(buff); if (channel > 0 && channel < 15) { if (wificonf->ap_channel != channel) { @@ -420,7 +421,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) wifi_change_flags.ap = true; } } else { - warn("Bad channel value \"%s\", allowed 1-14", buff); + cgi_warn("Bad channel value \"%s\", allowed 1-14", buff); redir_url += sprintf(redir_url, "ap_channel,"); } } @@ -439,12 +440,12 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) if (strlen(buff) > 0) { if (!streq(wificonf->ap_ssid, buff)) { - info("Setting SSID to \"%s\"", buff); + cgi_info("Setting SSID to \"%s\"", buff); strncpy_safe(wificonf->ap_ssid, buff, SSID_LEN); wifi_change_flags.ap = true; } } else { - warn("Bad SSID len."); + cgi_warn("Bad SSID len."); redir_url += sprintf(redir_url, "ap_ssid,"); } } @@ -456,12 +457,12 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) // but it may lock them out. if (strlen(buff) == 0 || (strlen(buff) >= 8 && strlen(buff) < PASSWORD_LEN-1)) { if (!streq(wificonf->ap_password, buff)) { - info("Setting AP password to \"%s\"", buff); + cgi_info("Setting AP password to \"%s\"", buff); strncpy_safe(wificonf->ap_password, buff, PASSWORD_LEN); wifi_change_flags.ap = true; } } else { - warn("Bad password len."); + cgi_warn("Bad password len."); redir_url += sprintf(redir_url, "ap_password,"); } } @@ -469,7 +470,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) // ---- Hide AP network (do not announce) ---- if (GET_ARG("ap_hidden")) { - dbg("AP hidden = %s", buff); + cgi_dbg("AP hidden = %s", buff); int hidden = atoi(buff); if (hidden != wificonf->ap_hidden) { wificonf->ap_hidden = (hidden != 0); @@ -482,7 +483,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) if (GET_ARG("sta_ssid")) { if (!streq(wificonf->sta_ssid, buff)) { // No verification needed, at worst it fails to connect - info("Setting station SSID to: \"%s\"", buff); + cgi_info("Setting station SSID to: \"%s\"", buff); strncpy_safe(wificonf->sta_ssid, buff, SSID_LEN); wifi_change_flags.sta = true; sta_ssid_pw_changed = true; @@ -494,7 +495,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) if (GET_ARG("sta_password")) { if (!streq(wificonf->sta_password, buff)) { // No verification needed, at worst it fails to connect - info("Setting station password to: \"%s\"", buff); + cgi_info("Setting station password to: \"%s\"", buff); strncpy_safe(wificonf->sta_password, buff, PASSWORD_LEN); wifi_change_flags.sta = true; sta_ssid_pw_changed = true; @@ -503,7 +504,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) { // All was OK - info("Set WiFi params - success, applying in 2000 ms"); + cgi_info("Set WiFi params - success, applying in 2000 ms"); // Settings are applied only if all was OK // @@ -523,14 +524,14 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData) && wificonf->sta_ssid[0] != 0) { // User wants to connect - info("User wants to connect to SSID, redirecting to ConnStatus page."); + cgi_info("User wants to connect to SSID, redirecting to ConnStatus page."); httpdRedirect(connData, "/cfg/wifi/connecting"); } else { httpdRedirect(connData, SET_REDIR_SUC); } } else { - warn("Some WiFi settings did not validate, asking for correction"); + cgi_warn("Some WiFi settings did not validate, asking for correction"); // Some errors, appended to the URL as ?err= httpdRedirect(connData, redir_url_buf); } diff --git a/user/character_sets.h b/user/character_sets.h index 4c1943e..ae79948 100644 --- a/user/character_sets.h +++ b/user/character_sets.h @@ -9,15 +9,7 @@ // Tables must be contiguous! -#define CODEPAGE_A_BEGIN 35 -#define CODEPAGE_A_END 35 - -static const u16 codepage_A[] ESP_CONST_DATA = - {// Unicode ASCII SYM - // %%BEGIN:A%% - 0x20a4, // 35 # £ - // %%END:A%% - }; +// Full range of UTF-8 is now supported, if needed, but the table must be changed to uint32_t #define CODEPAGE_0_BEGIN 96 #define CODEPAGE_0_END 126 diff --git a/user/persist.c b/user/persist.c index dd89036..5bb22d3 100644 --- a/user/persist.c +++ b/user/persist.c @@ -16,36 +16,36 @@ PersistBlock persist; static void ICACHE_FLASH_ATTR apply_live_settings(void) { - dbg("[Persist] Applying live settings..."); + persist_dbg("[Persist] Applying live settings..."); - dbg("[Persist] > system"); + persist_dbg("[Persist] > system"); sysconf_apply_settings(); - dbg("[Persist] > wifi"); + persist_dbg("[Persist] > wifi"); wifimgr_apply_settings(); - dbg("[Persist] > terminal"); + persist_dbg("[Persist] > terminal"); terminal_apply_settings(); - dbg("[Persist] Live settings applied."); + persist_dbg("[Persist] Live settings applied."); // ... } static void ICACHE_FLASH_ATTR restore_live_settings_to_hard_defaults(void) { - dbg("[Persist] Restore to hard defaults..."); + persist_dbg("[Persist] Restore to hard defaults..."); - dbg("[Persist] > system"); + persist_dbg("[Persist] > system"); sysconf_restore_defaults(); - dbg("[Persist] > wifi"); + persist_dbg("[Persist] > wifi"); wifimgr_restore_defaults(); - dbg("[Persist] > terminal"); + persist_dbg("[Persist] > terminal"); terminal_restore_defaults(); - dbg("[Persist] Restored to hard defaults."); + persist_dbg("[Persist] Restored to hard defaults."); // ... } @@ -103,14 +103,14 @@ compute_checksum(AppConfigBundle *bundle) void ICACHE_FLASH_ATTR persist_load(void) { - info("[Persist] Loading stored settings from FLASH..."); + persist_info("[Persist] Loading stored settings from FLASH..."); - dbg("AppConfigBundle memory map:"); - dbg("> WiFiConfigBundle at %4d (error %2d)", wconf_at, wconf_at - 0); - dbg("> SystemConfigBundle at %4d (error %2d)", sconf_at, sconf_at - WIFICONF_SIZE); - dbg("> TerminalConfigBundle at %4d (error %2d)", tconf_at, tconf_at - WIFICONF_SIZE - SYSCONF_SIZE); - dbg("> Checksum at %4d (error %2d)", cksum_at, cksum_at - (APPCONF_SIZE - 4)); - dbg("> Total size = %d bytes (error %d)", sizeof(AppConfigBundle), APPCONF_SIZE - sizeof(AppConfigBundle)); + persist_dbg("AppConfigBundle memory map:"); + persist_dbg("> WiFiConfigBundle at %4d (error %2d)", wconf_at, wconf_at - 0); + persist_dbg("> SystemConfigBundle at %4d (error %2d)", sconf_at, sconf_at - WIFICONF_SIZE); + persist_dbg("> TerminalConfigBundle at %4d (error %2d)", tconf_at, tconf_at - WIFICONF_SIZE - SYSCONF_SIZE); + persist_dbg("> Checksum at %4d (error %2d)", cksum_at, cksum_at - (APPCONF_SIZE - 4)); + persist_dbg("> Total size = %d bytes (error %d)", sizeof(AppConfigBundle), APPCONF_SIZE - sizeof(AppConfigBundle)); bool hard_reset = false; @@ -124,7 +124,7 @@ persist_load(void) error("[Persist] Checksum verification: FAILED"); hard_reset = true; } else { - info("[Persist] Checksum verification: PASSED"); + persist_info("[Persist] Checksum verification: PASSED"); } if (hard_reset) { @@ -142,13 +142,13 @@ persist_load(void) apply_live_settings(); } - info("[Persist] All settings loaded and applied."); + persist_info("[Persist] All settings loaded and applied."); } void ICACHE_FLASH_ATTR persist_store(void) { - info("[Persist] Storing all settings to FLASH..."); + persist_info("[Persist] Storing all settings to FLASH..."); // Update checksums before write persist.current.checksum = compute_checksum(&persist.current); @@ -157,7 +157,7 @@ persist_store(void) if (!system_param_save_with_protect(PERSIST_SECTOR_ID, &persist, sizeof(PersistBlock))) { error("[Persist] Store to flash failed!"); } - info("[Persist] All settings persisted."); + persist_info("[Persist] All settings persisted."); } /** @@ -166,13 +166,13 @@ persist_store(void) void ICACHE_FLASH_ATTR persist_load_hard_default(void) { - info("[Persist] Restoring live settings to hard defaults..."); + persist_info("[Persist] Restoring live settings to hard defaults..."); // Set live config to default values restore_live_settings_to_hard_defaults(); persist_store(); - info("[Persist] Settings restored to hard defaults."); + persist_info("[Persist] Settings restored to hard defaults."); apply_live_settings(); // apply } @@ -183,13 +183,13 @@ persist_load_hard_default(void) void ICACHE_FLASH_ATTR persist_restore_default(void) { - info("[Persist] Restoring live settings to stored defaults..."); + persist_info("[Persist] Restoring live settings to stored defaults..."); memcpy(&persist.current, &persist.defaults, sizeof(AppConfigBundle)); apply_live_settings(); persist_store(); - info("[Persist] Settings restored to stored defaults."); + persist_info("[Persist] Settings restored to stored defaults."); } /** @@ -198,11 +198,11 @@ persist_restore_default(void) void ICACHE_FLASH_ATTR persist_set_as_default(void) { - info("[Persist] Storing live settings as defaults.."); + persist_info("[Persist] Storing live settings as defaults.."); // current -> defaults memcpy(&persist.defaults, &persist.current, sizeof(AppConfigBundle)); persist_store(); - info("[Persist] Default settings updated."); + persist_info("[Persist] Default settings updated."); } diff --git a/user/persist.h b/user/persist.h index aba195b..1cc8a67 100644 --- a/user/persist.h +++ b/user/persist.h @@ -65,4 +65,14 @@ void persist_restore_default(void); void persist_set_as_default(void); void persist_store(void); +#if DEBUG_PERSIST +#define persist_warn warn +#define persist_dbg dbg +#define persist_info info +#else +#define persist_warn(fmt, ...) +#define persist_dbg(fmt, ...) +#define persist_info(fmt, ...) +#endif + #endif //ESP_VT100_FIRMWARE_PERSIST_H diff --git a/user/screen.c b/user/screen.c index a2ea677..53bc27e 100644 --- a/user/screen.c +++ b/user/screen.c @@ -7,17 +7,18 @@ #include "apars_logging.h" #include "jstring.h" #include "character_sets.h" +#include "utf8.h" TerminalConfigBundle * const termconf = &persist.current.termconf; -TerminalConfigBundle termconf_scratch; +TerminalConfigBundle termconf_live; MouseTrackingConfig mouse_tracking; // forward declare static void utf8_remap(char* out, char g, char charset); -#define W termconf_scratch.width -#define H termconf_scratch.height +#define W termconf_live.width +#define H termconf_live.height /** * Highest permissible value of the color attribute @@ -48,8 +49,9 @@ static Cell screen[MAX_SCREEN_SIZE]; static struct { bool numpad_alt_mode; //!< DECNKM - Numpad Application Mode bool cursors_alt_mode; //!< DECCKM - Cursors Application mode + bool bracketed_paste; - bool reverse; //!< DECSCNM - Reverse video + bool reverse_video; //!< DECSCNM - Reverse video bool insert_mode; //!< IRM - Insert mode (move rest of the line to the right) bool cursor_visible; //!< DECTCEM - Cursor visible @@ -90,7 +92,7 @@ typedef struct { /** Options saved with cursor */ bool auto_wrap; //!< DECAWM - Wrapping when EOL - bool reverse_wraparound; //!< Reverse-wraparound Mode. DECSET 45 + bool reverse_wrap; //!< Reverse-wraparound Mode. DECSET 45 bool origin_mode; //!< DECOM - absolute positioning is relative to vertical margins } CursorTypeDef; @@ -118,6 +120,23 @@ static struct { u32 tab_stops[TABSTOP_WORDS]; } state_backup; +/** options backup (save/restore) */ +static struct { + bool cursors_alt_mode; + bool reverse_video; + bool origin_mode; + bool auto_wrap; + enum MTM mouse_tracking; + enum MTE mouse_encoding; + bool focus_tracking; + bool cursor_blink; + bool cursor_visible; + bool reverse_wrap; + bool bracketed_paste; + bool show_buttons; + bool show_config_links; +} opt_backup; + /** * This is used to prevent premature change notifications * (from nested calls) @@ -188,14 +207,14 @@ terminal_apply_settings_noclear(void) // Migrate to v1 if (termconf->config_version < 1) { - dbg("termconf: Updating to version 1"); + persist_dbg("termconf: Updating to version 1"); termconf->display_cooldown_ms = SCR_DEF_DISPLAY_COOLDOWN_MS; changed = 1; } // Migrate to v2 if (termconf->config_version < 2) { - dbg("termconf: Updating to version 2"); + persist_dbg("termconf: Updating to version 2"); termconf->loopback = 0; termconf->show_config_links = 1; termconf->show_buttons = 1; @@ -204,7 +223,7 @@ terminal_apply_settings_noclear(void) // Migrate to v3 if (termconf->config_version < 3) { - dbg("termconf: Updating to version 3"); + persist_dbg("termconf: Updating to version 3"); for(int i=1; i <= TERM_BTN_COUNT; i++) { sprintf(termconf->btn_msg[i-1], "%c", i); } @@ -213,7 +232,7 @@ terminal_apply_settings_noclear(void) // Migrate to v3 if (termconf->config_version < 4) { - dbg("termconf: Updating to version 4"); + persist_dbg("termconf: Updating to version 4"); termconf->cursor_shape = CURSOR_BLOCK_BL; termconf->crlf_mode = false; changed = 1; @@ -231,13 +250,13 @@ terminal_apply_settings_noclear(void) changed = 1; } - memcpy(&termconf_scratch, termconf, sizeof(TerminalConfigBundle)); + memcpy(&termconf_live, termconf, sizeof(TerminalConfigBundle)); if (W*H > MAX_SCREEN_SIZE) { error("BAD SCREEN SIZE: %d rows x %d cols", H, W); error("reverting terminal settings to default"); terminal_restore_defaults(); changed = true; - memcpy(&termconf_scratch, termconf, sizeof(TerminalConfigBundle)); + memcpy(&termconf_live, termconf, sizeof(TerminalConfigBundle)); screen_init(); } @@ -255,7 +274,7 @@ terminal_apply_settings_noclear(void) void ICACHE_FLASH_ATTR screen_init(void) { - dbg("Screen buffer size = %d bytes", sizeof(screen)); + if(DEBUG_HEAP) dbg("Screen buffer size = %d bytes", sizeof(screen)); NOTIFY_LOCK(); screen_reset(); @@ -285,7 +304,7 @@ cursor_reset(void) static void ICACHE_FLASH_ATTR screen_reset_on_resize(void) { - dbg("Screen partial reset due to resize"); + ansi_dbg("Screen partial reset due to resize"); NOTIFY_LOCK(); cursor.x = 0; @@ -320,7 +339,7 @@ screen_reset_sgr(void) void ICACHE_FLASH_ATTR screen_reset(void) { - dbg("Screen reset."); + ansi_dbg("Screen reset."); NOTIFY_LOCK(); cursor_reset(); @@ -330,13 +349,13 @@ screen_reset(void) scr.insert_mode = false; cursor.origin_mode = false; cursor.auto_wrap = true; - cursor.reverse_wraparound = false; - termconf_scratch.cursor_shape = termconf->cursor_shape; + cursor.reverse_wrap = false; + termconf_live.cursor_shape = termconf->cursor_shape; scr.numpad_alt_mode = false; scr.cursors_alt_mode = false; - termconf_scratch.crlf_mode = termconf->crlf_mode; - scr.reverse = false; + termconf_live.crlf_mode = termconf->crlf_mode; + scr.reverse_video = false; scr.vm0 = 0; scr.vm1 = H-1; @@ -350,13 +369,26 @@ screen_reset(void) // size is left unchanged screen_clear(CLEAR_ALL); - screen_clear_all_tabs(); - // Set initial tabstops for (int i = 0; i < TABSTOP_WORDS; i++) { scr.tab_stops[i] = 0x80808080; } + // initial values in the save buffer in case of receiving restore without storing first + opt_backup.cursors_alt_mode = scr.cursors_alt_mode; + opt_backup.reverse_video = scr.reverse_video; + opt_backup.origin_mode = cursor.origin_mode; + opt_backup.auto_wrap = cursor.auto_wrap; + opt_backup.mouse_tracking = mouse_tracking.mode; + opt_backup.mouse_encoding = mouse_tracking.encoding; + opt_backup.focus_tracking = mouse_tracking.focus_tracking; + opt_backup.cursor_blink = CURSOR_BLINKS(termconf_live.cursor_shape); + opt_backup.cursor_visible = scr.cursor_visible; + opt_backup.reverse_wrap = cursor.reverse_wrap; + opt_backup.bracketed_paste = scr.bracketed_paste; + opt_backup.show_buttons = termconf_live.show_buttons; + opt_backup.show_config_links = termconf_live.show_config_links; + NOTIFY_DONE(); } @@ -369,16 +401,16 @@ void ICACHE_FLASH_ATTR screen_swap_state(bool alternate) { if (alternate == state_backup.alternate_active) { - warn("No swap, already alternate = %d", alternate); + ansi_warn("No swap, already alternate = %d", alternate); return; // nothing to do } if (alternate) { - dbg("Swap to alternate"); + ansi_dbg("Swap to alternate"); // store old state - memcpy(state_backup.title, termconf_scratch.title, TERM_TITLE_LEN); - memcpy(state_backup.btn, termconf_scratch.btn, sizeof(termconf_scratch.btn)); - memcpy(state_backup.btn_msg, termconf_scratch.btn_msg, sizeof(termconf_scratch.btn_msg)); + memcpy(state_backup.title, termconf_live.title, TERM_TITLE_LEN); + memcpy(state_backup.btn, termconf_live.btn, sizeof(termconf_live.btn)); + memcpy(state_backup.btn_msg, termconf_live.btn_msg, sizeof(termconf_live.btn_msg)); memcpy(state_backup.tab_stops, scr.tab_stops, sizeof(scr.tab_stops)); state_backup.vm0 = scr.vm0; state_backup.vm1 = scr.vm1; @@ -388,11 +420,11 @@ screen_swap_state(bool alternate) // TODO backup screen content (if this is ever possible) } else { - dbg("Unswap from alternate"); + ansi_dbg("Unswap from alternate"); NOTIFY_LOCK(); - memcpy(termconf_scratch.title, state_backup.title, TERM_TITLE_LEN); - memcpy(termconf_scratch.btn, state_backup.btn, sizeof(termconf_scratch.btn)); - memcpy(termconf_scratch.btn_msg, state_backup.btn_msg, sizeof(termconf_scratch.btn_msg)); + memcpy(termconf_live.title, state_backup.title, TERM_TITLE_LEN); + memcpy(termconf_live.btn, state_backup.btn, sizeof(termconf_live.btn)); + memcpy(termconf_live.btn_msg, state_backup.btn_msg, sizeof(termconf_live.btn_msg)); memcpy(scr.tab_stops, state_backup.tab_stops, sizeof(scr.tab_stops)); scr.vm0 = state_backup.vm0; scr.vm1 = state_backup.vm1; @@ -613,7 +645,8 @@ screen_clear_in_line(unsigned int count) } } -void screen_insert_lines(unsigned int lines) +void ICACHE_FLASH_ATTR +screen_insert_lines(unsigned int lines) { if (!cursor_inside_region()) return; // can't insert if not inside region NOTIFY_LOCK(); @@ -637,7 +670,8 @@ void screen_insert_lines(unsigned int lines) NOTIFY_DONE(); } -void screen_delete_lines(unsigned int lines) +void ICACHE_FLASH_ATTR +screen_delete_lines(unsigned int lines) { if (!cursor_inside_region()) return; // can't delete if not inside region NOTIFY_LOCK(); @@ -658,7 +692,8 @@ void screen_delete_lines(unsigned int lines) NOTIFY_DONE(); } -void screen_insert_characters(unsigned int count) +void ICACHE_FLASH_ATTR +screen_insert_characters(unsigned int count) { NOTIFY_LOCK(); int targetStart = cursor.x + count; @@ -675,7 +710,8 @@ void screen_insert_characters(unsigned int count) NOTIFY_DONE(); } -void screen_delete_characters(unsigned int count) +void ICACHE_FLASH_ATTR +screen_delete_characters(unsigned int count) { NOTIFY_LOCK(); int targetEnd = W - count; @@ -730,12 +766,12 @@ screen_resize(int rows, int cols) { // sanitize if (cols < 1 || rows < 1) { - error("Screen size must be positive, ignoring command: %d x %d", cols, rows); + error("Bad size: %d x %d", cols, rows); return; } if (cols * rows > MAX_SCREEN_SIZE) { - error("Max screen size exceeded, ignoring command: %d x %d", cols, rows); + error("Too big size: %d x %d", cols, rows); return; } @@ -751,7 +787,7 @@ screen_resize(int rows, int cols) void ICACHE_FLASH_ATTR screen_set_title(const char *title) { - strncpy(termconf_scratch.title, title, TERM_TITLE_LEN); + strncpy(termconf_live.title, title, TERM_TITLE_LEN); screen_notifyChange(CHANGE_LABELS); } @@ -763,7 +799,7 @@ screen_set_title(const char *title) void ICACHE_FLASH_ATTR screen_set_button_text(int num, const char *text) { - strncpy(termconf_scratch.btn[num-1], text, TERM_BTN_LEN); + strncpy(termconf_live.btn[num-1], text, TERM_BTN_LEN); screen_notifyChange(CHANGE_LABELS); } @@ -851,7 +887,7 @@ screen_cursor_shape(enum CursorShape shape) { NOTIFY_LOCK(); if (shape == CURSOR_DEFAULT) shape = termconf->cursor_shape; - termconf_scratch.cursor_shape = shape; + termconf_live.cursor_shape = shape; NOTIFY_DONE(); } @@ -861,13 +897,13 @@ screen_cursor_blink(bool blink) { NOTIFY_LOCK(); if (blink) { - if (termconf_scratch.cursor_shape == CURSOR_BLOCK) termconf_scratch.cursor_shape = CURSOR_BLOCK_BL; - if (termconf_scratch.cursor_shape == CURSOR_BAR) termconf_scratch.cursor_shape = CURSOR_BAR_BL; - if (termconf_scratch.cursor_shape == CURSOR_UNDERLINE) termconf_scratch.cursor_shape = CURSOR_UNDERLINE_BL; + if (termconf_live.cursor_shape == CURSOR_BLOCK) termconf_live.cursor_shape = CURSOR_BLOCK_BL; + if (termconf_live.cursor_shape == CURSOR_BAR) termconf_live.cursor_shape = CURSOR_BAR_BL; + if (termconf_live.cursor_shape == CURSOR_UNDERLINE) termconf_live.cursor_shape = CURSOR_UNDERLINE_BL; } else { - if (termconf_scratch.cursor_shape == CURSOR_BLOCK_BL) termconf_scratch.cursor_shape = CURSOR_BLOCK; - if (termconf_scratch.cursor_shape == CURSOR_BAR_BL) termconf_scratch.cursor_shape = CURSOR_BAR; - if (termconf_scratch.cursor_shape == CURSOR_UNDERLINE_BL) termconf_scratch.cursor_shape = CURSOR_UNDERLINE; + if (termconf_live.cursor_shape == CURSOR_BLOCK_BL) termconf_live.cursor_shape = CURSOR_BLOCK; + if (termconf_live.cursor_shape == CURSOR_BAR_BL) termconf_live.cursor_shape = CURSOR_BAR; + if (termconf_live.cursor_shape == CURSOR_UNDERLINE_BL) termconf_live.cursor_shape = CURSOR_UNDERLINE; } NOTIFY_DONE(); } @@ -956,7 +992,7 @@ screen_cursor_move(int dy, int dx, bool scroll) cursor.y += dy; if (cursor.x >= (int)W) cursor.x = W - 1; if (cursor.x < (int)0) { - if (cursor.auto_wrap && cursor.reverse_wraparound) { + if (cursor.auto_wrap && cursor.reverse_wrap) { // this is mimicking a behavior from xterm that allows any number of steps backwards with reverse wraparound enabled int steps = -cursor.x; if(steps > 1000) steps = 1; // avoid something stupid causing infinite loop here @@ -1097,7 +1133,7 @@ screen_wrap_enable(bool enable) void ICACHE_FLASH_ATTR screen_reverse_wrap_enable(bool enable) { - cursor.reverse_wraparound = enable; + cursor.reverse_wrap = enable; } /** @@ -1201,7 +1237,7 @@ void ICACHE_FLASH_ATTR screen_set_reverse_video(bool reverse) { NOTIFY_LOCK(); - scr.reverse = reverse; + scr.reverse_video = reverse; NOTIFY_DONE(); } @@ -1209,7 +1245,7 @@ void ICACHE_FLASH_ATTR screen_set_newline_mode(bool nlm) { NOTIFY_LOCK(); - termconf_scratch.crlf_mode = nlm; + termconf_live.crlf_mode = nlm; NOTIFY_DONE(); } @@ -1220,6 +1256,79 @@ screen_set_origin_mode(bool region_origin) screen_cursor_set(0, 0); } +static void ICACHE_FLASH_ATTR +do_save_private_opt(int n, bool save) +{ +#define SAVE_RESTORE(sf, of) do { if (save) sf=(of); else of=(sf); } while(0) + switch (n) { + case 1: + SAVE_RESTORE(opt_backup.cursors_alt_mode, scr.cursors_alt_mode); + break; + case 5: + SAVE_RESTORE(opt_backup.reverse_video, scr.reverse_video); + break; + case 6: + SAVE_RESTORE(opt_backup.origin_mode, cursor.origin_mode); + break; + case 7: + SAVE_RESTORE(opt_backup.auto_wrap, cursor.auto_wrap); + break; + case 9: + case 1000: + case 1001: // hilite, not implemented + case 1002: + case 1003: + SAVE_RESTORE(opt_backup.mouse_tracking, mouse_tracking.mode); + break; + case 1004: + SAVE_RESTORE(opt_backup.focus_tracking, mouse_tracking.focus_tracking); + break; + case 1005: + case 1006: + case 1015: + SAVE_RESTORE(opt_backup.mouse_encoding, mouse_tracking.encoding); + break; + case 12: // cursor blink + if (save) { + opt_backup.cursor_blink = CURSOR_BLINKS(termconf_live.cursor_shape); + } else { + screen_cursor_blink(opt_backup.cursor_blink); + } + break; + case 25: + SAVE_RESTORE(opt_backup.cursor_visible, scr.cursor_visible); + break; + case 45: + SAVE_RESTORE(opt_backup.reverse_wrap, cursor.reverse_wrap); + break; + case 2004: + SAVE_RESTORE(opt_backup.bracketed_paste, scr.bracketed_paste); + break; + case 800: + SAVE_RESTORE(opt_backup.show_buttons, termconf_live.show_buttons); + break; + case 801: + SAVE_RESTORE(opt_backup.show_config_links, termconf_live.show_config_links); + break; + default: + ansi_warn("Cannot store ?%d", n); + } +} + +void ICACHE_FLASH_ATTR +screen_save_private_opt(int n) +{ + do_save_private_opt(n, true); +} + +void ICACHE_FLASH_ATTR +screen_restore_private_opt(int n) +{ + NOTIFY_LOCK(); + do_save_private_opt(n, false); + NOTIFY_DONE(); +} + void ICACHE_FLASH_ATTR screen_report_sgr(char *buffer) { @@ -1357,10 +1466,7 @@ utf8_remap(char *out, char g, char charset) break; case CS_A_UKASCII: /* UK, replaces # with GBP */ - if ((g >= CODEPAGE_A_BEGIN) && (g <= CODEPAGE_A_END)) { - n = codepage_A[g - CODEPAGE_A_BEGIN]; - if (n) utf = n; - } + if (g == '#') utf = 0x20a4; // £ break; default: @@ -1369,28 +1475,7 @@ utf8_remap(char *out, char g, char charset) break; } - // Encode to UTF-8 - if (utf > 0x7F) { - // formulas taken from: https://gist.github.com/yamamushi/5823402 - if ((utf >= 0x80) && (utf <= 0x07FF)) { - // 2-byte unicode - out[0] = (char) ((utf >> 0x06) ^ 0xC0); - out[1] = (char) (((utf ^ 0xFFC0) | 0x80) & ~0x40); - out[2]=0; - } - else { - // 3-byte unicode - out[0] = (char) (((utf ^ 0xFC0FFF) >> 0x0C) | 0xE0); - out[1] = (char) ((((utf ^ 0xFFF03F) >> 0x06) | 0x80) & ~0x40); - out[2] = (char) (((utf ^ 0xFFFC0) | 0x80) & ~0x40); - out[3]=0; - } - // Missing 4-byte formulas :( - } else { - // low ASCII - out[0] = (char) utf; - out[1] = 0; - } + utf8_encode(out, utf); } //endregion @@ -1415,12 +1500,12 @@ screenSerializeLabelsToBuffer(char *buffer, size_t buf_len) { // let's just assume it's long enough - called with the huge websocket buffer sprintf(buffer, "T%s\x01%s\x01%s\x01%s\x01%s\x01%s", // use 0x01 as separator - termconf_scratch.title, - termconf_scratch.btn[0], - termconf_scratch.btn[1], - termconf_scratch.btn[2], - termconf_scratch.btn[3], - termconf_scratch.btn[4] + termconf_live.title, + termconf_live.btn[0], + termconf_live.btn[1], + termconf_live.btn[2], + termconf_live.btn[3], + termconf_live.btn[4] ); } @@ -1502,13 +1587,13 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data) (cursor.hanging << 1) | (scr.cursors_alt_mode << 2) | (scr.numpad_alt_mode << 3) | - (termconf_scratch.fn_alt_mode << 4) | + (termconf_live.fn_alt_mode << 4) | ((mouse_tracking.mode>MTM_NONE) << 5) | // disables context menu ((mouse_tracking.mode>=MTM_NORMAL) << 6) | // disables selecting - (termconf_scratch.show_buttons << 7) | - (termconf_scratch.show_config_links << 8) | - ((termconf_scratch.cursor_shape&0x07) << 9) | // 9,10,11 - cursor shape based on DECSCUSR - (termconf_scratch.crlf_mode << 12) + (termconf_live.show_buttons << 7) | + (termconf_live.show_config_links << 8) | + ((termconf_live.cursor_shape&0x07) << 9) | // 9,10,11 - cursor shape based on DECSCUSR + (termconf_live.crlf_mode << 12) ); } @@ -1535,7 +1620,7 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data) Color fg, bg; // Reverse fg and bg if we're in global reverse mode - if (! scr.reverse) { + if (! scr.reverse_video) { fg = cell0->fg; bg = cell0->bg; } diff --git a/user/screen.h b/user/screen.h index ba35209..68c64ba 100644 --- a/user/screen.h +++ b/user/screen.h @@ -68,6 +68,8 @@ enum CursorShape { CURSOR_BAR = 6, }; +#define CURSOR_BLINKS(shape) ((shape)==CURSOR_BLOCK_BL||(shape)==CURSOR_UNDERLINE_BL||(shape)==CURSOR_BAR_BL) + typedef struct { u32 width; u32 height; @@ -96,7 +98,7 @@ extern TerminalConfigBundle * const termconf; * Transient live config with no persist, can be modified via esc sequences. * terminal_apply_settings() copies termconf to this struct, erasing old scratch changes */ -extern TerminalConfigBundle termconf_scratch; +extern TerminalConfigBundle termconf_live; enum MTM { MTM_NONE = 0, @@ -259,6 +261,10 @@ void screen_set_numpad_alt_mode(bool app_mode); void screen_set_cursors_alt_mode(bool app_mode); /** Set reverse video mode */ void screen_set_reverse_video(bool reverse); +/** Save DECOPT */ +void screen_save_private_opt(int n); +/** Restore DECOPT */ +void screen_restore_private_opt(int n); // --- Charset --- diff --git a/user/serial.c b/user/serial.c index e27d8c8..74a31d1 100644 --- a/user/serial.c +++ b/user/serial.c @@ -4,7 +4,7 @@ #include "ansi_parser.h" #include "syscfg.h" -#define LOGBUF_SIZE 2048 +#define LOGBUF_SIZE 512 static char logbuf[LOGBUF_SIZE]; static u32 lb_nw = 1; static u32 lb_ls = 0; @@ -18,7 +18,8 @@ static void buf_putc(char c) } } -static void buf_pop(void *unused) +static void ICACHE_FLASH_ATTR +buf_pop(void *unused) { u32 quantity = 32; u32 old_ls; diff --git a/user/uart_buffer.c b/user/uart_buffer.c index a32f8d8..6eaf5d3 100644 --- a/user/uart_buffer.c +++ b/user/uart_buffer.c @@ -62,7 +62,8 @@ UART_AsyncBufferInit(uint32 buf_size) * @param pdata - data src * @param data_len - data len */ -static void UART_WriteToAsyncBuffer(struct UartBuffer *pCur, const char *pdata, uint16 data_len) +static void ICACHE_FLASH_ATTR +UART_WriteToAsyncBuffer(struct UartBuffer *pCur, const char *pdata, uint16 data_len) { if (data_len == 0) return; diff --git a/user/uart_handler.c b/user/uart_handler.c index 59d8f67..a3d0a00 100755 --- a/user/uart_handler.c +++ b/user/uart_handler.c @@ -118,7 +118,8 @@ void ICACHE_FLASH_ATTR UART_SetupAsyncReceiver(void) * * @param events */ -static void uart_recvTask(os_event_t *events) +static void ICACHE_FLASH_ATTR +uart_recvTask(os_event_t *events) { //#define PROCESS_CHUNK_LEN 64 // static char buf[PROCESS_CHUNK_LEN]; @@ -158,7 +159,8 @@ static void uart_recvTask(os_event_t *events) * * @param events */ -static void uart_processTask(os_event_t *events) +static void ICACHE_FLASH_ATTR +uart_processTask(os_event_t *events) { static char buf[PROCESS_CHUNK_LEN]; diff --git a/user/user_main.c b/user/user_main.c index c51b3f5..b34dd40 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -124,7 +124,7 @@ void ICACHE_FLASH_ATTR user_init(void) os_timer_arm(&userStartTimer, 10, 0); } -static void user_start(void *unused) +static void ICACHE_FLASH_ATTR user_start(void *unused) { // Load and apply stored settings, or defaults if stored settings are invalid persist_load(); diff --git a/user/utf8.c b/user/utf8.c new file mode 100644 index 0000000..57a47df --- /dev/null +++ b/user/utf8.c @@ -0,0 +1,58 @@ +// +// Created by MightyPork on 2017/09/10. +// + +#include "utf8.h" + +/** + * Encode a code point using UTF-8 + * + * @author Ondřej Hruška + * @license MIT + * + * @param out - output buffer (min 4 characters), will be 0-terminated if shorten than 4 + * @param utf - code point 0-0x10FFFF + * @return number of bytes on success, 0 on failure (also produces U+FFFD, which uses 3 bytes) + */ +int ICACHE_FLASH_ATTR +utf8_encode(char *out, uint32_t utf) +{ + if (utf <= 0x7F) { + // Plain ASCII + out[0] = (char) utf; + out[1] = 0; + return 1; + } + else if (utf <= 0x07FF) { + // 2-byte unicode + out[0] = (char) (((utf >> 6) & 0x1F) | 0xC0); + out[1] = (char) (((utf >> 0) & 0x3F) | 0x80); + out[2] = 0; + return 2; + } + else if (utf <= 0xFFFF) { + // 3-byte unicode + out[0] = (char) (((utf >> 12) & 0x0F) | 0xE0); + out[1] = (char) (((utf >> 6) & 0x3F) | 0x80); + out[2] = (char) (((utf >> 0) & 0x3F) | 0x80); + out[3] = 0; + return 3; + } + else if (utf <= 0x10FFFF) { + // 4-byte unicode + out[0] = (char) (((utf >> 18) & 0x07) | 0xF0); + out[1] = (char) (((utf >> 12) & 0x3F) | 0x80); + out[2] = (char) (((utf >> 6) & 0x3F) | 0x80); + out[3] = (char) (((utf >> 0) & 0x3F) | 0x80); +// out[4] = 0; + return 4; + } + else { + // error - use replacement character + out[0] = (char) 0xEF; + out[1] = (char) 0xBF; + out[2] = (char) 0xBD; + out[3] = 0; + return 0; + } +} diff --git a/user/utf8.h b/user/utf8.h new file mode 100644 index 0000000..a0de3a8 --- /dev/null +++ b/user/utf8.h @@ -0,0 +1,12 @@ +// +// Created by MightyPork on 2017/09/10. +// + +#ifndef ESPTERM_UTF8_H +#define ESPTERM_UTF8_H + +#include + +int utf8_encode(char *out, uint32_t utf); + +#endif //ESPTERM_UTF8_H diff --git a/user/wifimgr.c b/user/wifimgr.c index 486be36..2d20f9e 100644 --- a/user/wifimgr.c +++ b/user/wifimgr.c @@ -48,28 +48,28 @@ wifimgr_restore_defaults(void) static void ICACHE_FLASH_ATTR configure_station(void) { - info("[WiFi] Configuring Station mode..."); + wifi_info("[WiFi] Configuring Station mode..."); struct station_config conf; strcpy((char *) conf.ssid, (char *) wificonf->sta_ssid); strcpy((char *) conf.password, (char *) wificonf->sta_password); - dbg("[WiFi] Connecting to \"%s\"%s password", conf.ssid, conf.password[0]!=0?" using saved":", no"); + wifi_dbg("[WiFi] Connecting to \"%s\"%s password", conf.ssid, conf.password[0]!=0?" using saved":", no"); conf.bssid_set = 0; conf.bssid[0] = 0; wifi_station_disconnect(); wifi_station_set_config_current(&conf); if (wificonf->sta_dhcp_enable) { - dbg("[WiFi] Starting DHCP..."); + wifi_dbg("[WiFi] Starting DHCP..."); if (!wifi_station_dhcpc_start()) { error("[WiFi] DHCP failed to start!"); return; } } else { - info("[WiFi] Setting up static IP..."); - dbg("[WiFi] Client.ip = "IPSTR, GOOD_IP2STR(wificonf->sta_addr.ip.addr)); - dbg("[WiFi] Client.mask = "IPSTR, GOOD_IP2STR(wificonf->sta_addr.netmask.addr)); - dbg("[WiFi] Client.gw = "IPSTR, GOOD_IP2STR(wificonf->sta_addr.gw.addr)); + wifi_info("[WiFi] Setting up static IP..."); + wifi_dbg("[WiFi] Client.ip = "IPSTR, GOOD_IP2STR(wificonf->sta_addr.ip.addr)); + wifi_dbg("[WiFi] Client.mask = "IPSTR, GOOD_IP2STR(wificonf->sta_addr.netmask.addr)); + wifi_dbg("[WiFi] Client.gw = "IPSTR, GOOD_IP2STR(wificonf->sta_addr.gw.addr)); wifi_station_dhcpc_stop(); // Load static IP config @@ -79,7 +79,7 @@ configure_station(void) } } - info("[WiFi] Trying to connect to AP..."); + wifi_info("[WiFi] Trying to connect to AP..."); wifi_station_connect(); } @@ -88,7 +88,7 @@ configure_ap(void) { bool suc; - info("[WiFi] Configuring SoftAP mode..."); + wifi_info("[WiFi] Configuring SoftAP mode..."); // AP is enabled struct softap_config conf; conf.channel = wificonf->ap_channel; @@ -110,10 +110,10 @@ configure_ap(void) } // Set IP - info("[WiFi] Configuring SoftAP local IP..."); - dbg("[WiFi] SoftAP.ip = "IPSTR, GOOD_IP2STR(wificonf->ap_addr.ip.addr)); - dbg("[WiFi] SoftAP.mask = "IPSTR, GOOD_IP2STR(wificonf->ap_addr.netmask.addr)); - dbg("[WiFi] SoftAP.gw = "IPSTR, GOOD_IP2STR(wificonf->ap_addr.gw.addr)); + wifi_info("[WiFi] Configuring SoftAP local IP..."); + wifi_dbg("[WiFi] SoftAP.ip = "IPSTR, GOOD_IP2STR(wificonf->ap_addr.ip.addr)); + wifi_dbg("[WiFi] SoftAP.mask = "IPSTR, GOOD_IP2STR(wificonf->ap_addr.netmask.addr)); + wifi_dbg("[WiFi] SoftAP.gw = "IPSTR, GOOD_IP2STR(wificonf->ap_addr.gw.addr)); wifi_softap_dhcps_stop(); @@ -123,10 +123,10 @@ configure_ap(void) return; } - info("[WiFi] Configuring SoftAP DHCP server..."); - dbg("[WiFi] DHCP.start = "IPSTR, GOOD_IP2STR(wificonf->ap_dhcp_range.start_ip.addr)); - dbg("[WiFi] DHCP.end = "IPSTR, GOOD_IP2STR(wificonf->ap_dhcp_range.end_ip.addr)); - dbg("[WiFi] DHCP.lease = %d minutes", wificonf->ap_dhcp_time); + wifi_info("[WiFi] Configuring SoftAP DHCP server..."); + wifi_dbg("[WiFi] DHCP.start = "IPSTR, GOOD_IP2STR(wificonf->ap_dhcp_range.start_ip.addr)); + wifi_dbg("[WiFi] DHCP.end = "IPSTR, GOOD_IP2STR(wificonf->ap_dhcp_range.end_ip.addr)); + wifi_dbg("[WiFi] DHCP.lease = %d minutes", wificonf->ap_dhcp_time); if (!wifi_softap_set_dhcps_lease(&wificonf->ap_dhcp_range)) { error("[WiFi] DHCP address range set fail!"); @@ -154,7 +154,7 @@ configure_ap(void) void ICACHE_FLASH_ATTR wifimgr_apply_settings(void) { - info("[WiFi] Initializing..."); + wifi_info("[WiFi] Initializing..."); // !!! Update to current version !!! @@ -190,5 +190,5 @@ wifimgr_apply_settings(void) wifi_change_flags.ap = false; wifi_change_flags.sta = false; - info("[WiFi] WiFi settings applied."); + wifi_info("[WiFi] WiFi settings applied."); } diff --git a/user/wifimgr.h b/user/wifimgr.h index 5dc9043..33c49bb 100644 --- a/user/wifimgr.h +++ b/user/wifimgr.h @@ -60,4 +60,14 @@ void wifimgr_restore_defaults(void); void wifimgr_apply_settings(void); +#if DEBUG_WIFI +#define wifi_warn warn +#define wifi_dbg dbg +#define wifi_info info +#else +#define wifi_warn(fmt, ...) +#define wifi_dbg(fmt, ...) +#define wifi_info(fmt, ...) +#endif + #endif //ESP_VT100_FIRMWARE_WIFI_MANAGER_H