|
|
@ -9,6 +9,7 @@ Cgi/template routines for configuring non-wifi settings |
|
|
|
#include "screen.h" |
|
|
|
#include "screen.h" |
|
|
|
#include "helpers.h" |
|
|
|
#include "helpers.h" |
|
|
|
#include "cgi_logging.h" |
|
|
|
#include "cgi_logging.h" |
|
|
|
|
|
|
|
#include "uart_driver.h" |
|
|
|
|
|
|
|
|
|
|
|
#define SET_REDIR_SUC "/cfg/term" |
|
|
|
#define SET_REDIR_SUC "/cfg/term" |
|
|
|
#define SET_REDIR_ERR SET_REDIR_SUC"?err=" |
|
|
|
#define SET_REDIR_ERR SET_REDIR_SUC"?err=" |
|
|
@ -30,6 +31,11 @@ cgiTermCfgSetParams(HttpdConnData *connData) |
|
|
|
redir_url += sprintf(redir_url, SET_REDIR_ERR); |
|
|
|
redir_url += sprintf(redir_url, SET_REDIR_ERR); |
|
|
|
// we'll test if anything was printed by looking for \0 in failed_keys_buf
|
|
|
|
// we'll test if anything was printed by looking for \0 in failed_keys_buf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SystemConfigBundle *sysconf_backup = malloc(sizeof(SystemConfigBundle)); |
|
|
|
|
|
|
|
TerminalConfigBundle *termconf_backup = malloc(sizeof(TerminalConfigBundle)); |
|
|
|
|
|
|
|
memcpy(sysconf_backup, sysconf, sizeof(SystemConfigBundle)); |
|
|
|
|
|
|
|
memcpy(termconf_backup, termconf, sizeof(TerminalConfigBundle)); |
|
|
|
|
|
|
|
|
|
|
|
if (connData->conn == NULL) { |
|
|
|
if (connData->conn == NULL) { |
|
|
|
//Connection aborted. Clean up.
|
|
|
|
//Connection aborted. Clean up.
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
return HTTPD_CGI_DONE; |
|
|
@ -39,34 +45,40 @@ cgiTermCfgSetParams(HttpdConnData *connData) |
|
|
|
if (GET_ARG("term_width")) { |
|
|
|
if (GET_ARG("term_width")) { |
|
|
|
cgi_dbg("Default screen width: %s", buff); |
|
|
|
cgi_dbg("Default screen width: %s", buff); |
|
|
|
w = atoi(buff); |
|
|
|
w = atoi(buff); |
|
|
|
if (w > 1) { |
|
|
|
do { |
|
|
|
if (GET_ARG("term_height")) { |
|
|
|
if (w <= 1) { |
|
|
|
cgi_dbg("Default screen height: %s", buff); |
|
|
|
cgi_warn("Bad width: \"%s\"", buff); |
|
|
|
h = atoi(buff); |
|
|
|
redir_url += sprintf(redir_url, "term_width,"); |
|
|
|
if (h > 1) { |
|
|
|
break; |
|
|
|
if (w * h <= MAX_SCREEN_SIZE) { |
|
|
|
} |
|
|
|
if (termconf->width != w || termconf->height != h) { |
|
|
|
|
|
|
|
termconf->width = w; |
|
|
|
if (!GET_ARG("term_height")) { |
|
|
|
termconf->height = h; |
|
|
|
|
|
|
|
shall_clear_screen = true; // this causes a notify
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cgi_warn("Bad dimensions: %d x %d (total %d)", w, h, w*h); |
|
|
|
|
|
|
|
redir_url += sprintf(redir_url, "term_width,term_height,"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cgi_warn("Bad height: \"%s\"", buff); |
|
|
|
|
|
|
|
redir_url += sprintf(redir_url, "term_width,"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cgi_warn("Missing height arg!"); |
|
|
|
cgi_warn("Missing height arg!"); |
|
|
|
// this wont happen normally when the form is used
|
|
|
|
// this wont happen normally when the form is used
|
|
|
|
redir_url += sprintf(redir_url, "term_width,term_height,"); |
|
|
|
redir_url += sprintf(redir_url, "term_width,term_height,"); |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
cgi_warn("Bad width: \"%s\"", buff); |
|
|
|
cgi_dbg("Default screen height: %s", buff); |
|
|
|
redir_url += sprintf(redir_url, "term_width,"); |
|
|
|
h = atoi(buff); |
|
|
|
} |
|
|
|
if (h <= 1) { |
|
|
|
|
|
|
|
cgi_warn("Bad height: \"%s\"", buff); |
|
|
|
|
|
|
|
redir_url += sprintf(redir_url, "term_height,"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (w * h > MAX_SCREEN_SIZE) { |
|
|
|
|
|
|
|
cgi_warn("Bad dimensions: %d x %d (total %d)", w, h, w * h); |
|
|
|
|
|
|
|
redir_url += sprintf(redir_url, "term_width,term_height,"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (termconf->width != w || termconf->height != h) { |
|
|
|
|
|
|
|
termconf->width = w; |
|
|
|
|
|
|
|
termconf->height = h; |
|
|
|
|
|
|
|
shall_clear_screen = true; // this causes a notify
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} while (0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (GET_ARG("default_bg")) { |
|
|
|
if (GET_ARG("default_bg")) { |
|
|
@ -265,6 +277,56 @@ cgiTermCfgSetParams(HttpdConnData *connData) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (GET_ARG("uart_baud")) { |
|
|
|
|
|
|
|
cgi_dbg("Baud rate: %s", buff); |
|
|
|
|
|
|
|
int baud = atoi(buff); |
|
|
|
|
|
|
|
if (baud == BIT_RATE_300 || |
|
|
|
|
|
|
|
baud == BIT_RATE_600 || |
|
|
|
|
|
|
|
baud == BIT_RATE_1200 || |
|
|
|
|
|
|
|
baud == BIT_RATE_2400 || |
|
|
|
|
|
|
|
baud == BIT_RATE_4800 || |
|
|
|
|
|
|
|
baud == BIT_RATE_9600 || |
|
|
|
|
|
|
|
baud == BIT_RATE_19200 || |
|
|
|
|
|
|
|
baud == BIT_RATE_38400 || |
|
|
|
|
|
|
|
baud == BIT_RATE_57600 || |
|
|
|
|
|
|
|
baud == BIT_RATE_74880 || |
|
|
|
|
|
|
|
baud == BIT_RATE_115200 || |
|
|
|
|
|
|
|
baud == BIT_RATE_230400 || |
|
|
|
|
|
|
|
baud == BIT_RATE_460800 || |
|
|
|
|
|
|
|
baud == BIT_RATE_921600 || |
|
|
|
|
|
|
|
baud == BIT_RATE_1843200 || |
|
|
|
|
|
|
|
baud == BIT_RATE_3686400) { |
|
|
|
|
|
|
|
sysconf->uart_baudrate = (u32) baud; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cgi_warn("Bad baud rate %s", buff); |
|
|
|
|
|
|
|
redir_url += sprintf(redir_url, "uart_baud,"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (GET_ARG("uart_parity")) { |
|
|
|
|
|
|
|
cgi_dbg("Parity: %s", buff); |
|
|
|
|
|
|
|
int parity = atoi(buff); |
|
|
|
|
|
|
|
if (parity >= 0 && parity <= 2) { |
|
|
|
|
|
|
|
sysconf->uart_parity = (UartParityMode) parity; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cgi_warn("Bad parity %s", buff); |
|
|
|
|
|
|
|
redir_url += sprintf(redir_url, "uart_parity,"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (GET_ARG("uart_stopbits")) { |
|
|
|
|
|
|
|
cgi_dbg("Stop bits: %s", buff); |
|
|
|
|
|
|
|
int stopbits = atoi(buff); |
|
|
|
|
|
|
|
if (stopbits >= 1 && stopbits <= 3) { |
|
|
|
|
|
|
|
sysconf->uart_stopbits = (UartStopBitsNum) stopbits; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cgi_warn("Bad stopbits %s", buff); |
|
|
|
|
|
|
|
redir_url += sprintf(redir_url, "uart_stopbits,"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(void)redir_url; |
|
|
|
|
|
|
|
|
|
|
|
if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) { |
|
|
|
if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) { |
|
|
|
// All was OK
|
|
|
|
// All was OK
|
|
|
|
info("Set term params - success, saving..."); |
|
|
|
info("Set term params - success, saving..."); |
|
|
@ -288,9 +350,16 @@ cgiTermCfgSetParams(HttpdConnData *connData) |
|
|
|
httpdRedirect(connData, SET_REDIR_SUC); |
|
|
|
httpdRedirect(connData, SET_REDIR_SUC); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
cgi_warn("Some settings did not validate, asking for correction"); |
|
|
|
cgi_warn("Some settings did not validate, asking for correction"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
memcpy(sysconf, sysconf_backup, sizeof(SystemConfigBundle)); |
|
|
|
|
|
|
|
memcpy(termconf, termconf_backup, sizeof(TerminalConfigBundle)); |
|
|
|
|
|
|
|
|
|
|
|
// Some errors, appended to the URL as ?err=
|
|
|
|
// Some errors, appended to the URL as ?err=
|
|
|
|
httpdRedirect(connData, redir_url_buf); |
|
|
|
httpdRedirect(connData, redir_url_buf); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free(sysconf_backup); |
|
|
|
|
|
|
|
free(termconf_backup); |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -357,6 +426,15 @@ tplTermCfg(HttpdConnData *connData, char *token, void **arg) |
|
|
|
else if (streq(token, "term_title")) { |
|
|
|
else if (streq(token, "term_title")) { |
|
|
|
strncpy_safe(buff, termconf->title, BUFLEN); |
|
|
|
strncpy_safe(buff, termconf->title, BUFLEN); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (streq(token, "uart_baud")) { |
|
|
|
|
|
|
|
sprintf(buff, "%d", sysconf->uart_baudrate); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (streq(token, "uart_parity")) { |
|
|
|
|
|
|
|
sprintf(buff, "%d", sysconf->uart_parity); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (streq(token, "uart_stopbits")) { |
|
|
|
|
|
|
|
sprintf(buff, "%d", sysconf->uart_stopbits); |
|
|
|
|
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
for (int btn_i = 1; btn_i <= TERM_BTN_COUNT; btn_i++) { |
|
|
|
for (int btn_i = 1; btn_i <= TERM_BTN_COUNT; btn_i++) { |
|
|
|
sprintf(buff2, "btn%d", btn_i); |
|
|
|
sprintf(buff2, "btn%d", btn_i); |
|
|
|