Skip to content

Commit

Permalink
Fix for bugs affecting settings handling. Issue #5 and issue #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeio committed Oct 7, 2022
1 parent 8511da5 commit e0b55d5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
31 changes: 15 additions & 16 deletions commands_v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ static bool add_setting (cJSON *settings, const setting_detail_t *setting, int32

ok = !!cJSON_AddStringToObject(settingobj, "F", opt);

strcpy(opt, uitoa(setting->id));
strcpy(opt, uitoa(setting->id + offset));
if(bit >= 0) {
strcat(opt, "#");
strcat(opt, uitoa(bit));
Expand Down Expand Up @@ -936,32 +936,31 @@ static status_code_t set_setting (const struct webui_cmd_binding *command, uint_

char *bitp;
const setting_detail_t *setting;
setting_id_t id = (setting_id_t)atoi(setting_id);

ok = !!(setting = setting_get_details(id, NULL));

// "hack" for bitfield settings
if((bitp = strchr(setting_id, '#'))) {
if(ok && (bitp = strchr(setting_id, '#'))) {

*bitp++ = '\0';
uint32_t pmask = 1 << atoi(bitp), tmask;

if((ok = !!(setting = setting_get_details(atoi(setting_id), NULL)))) {

tmask = setting_get_int_value(setting, 0);
tmask = setting_get_int_value(setting, 0);

if(*value == '0')
tmask ^= pmask;
else
tmask |= pmask;
if(*value == '0')
tmask ^= pmask;
else
tmask |= pmask;

if(setting->datatype == Format_XBitfield && (tmask & 0x01) == 0)
tmask = 0;
if(setting->datatype == Format_XBitfield && (tmask & 0x01) == 0)
tmask = 0;

value = uitoa(tmask);
}
} else
ok = !!(setting = setting_get_details((setting_id_t)atoi(setting_id), NULL));
value = uitoa(tmask);
}

if(ok)
status = sys_set_setting(setting->id, value);
status = sys_set_setting(id, value);
}

if(json) {
Expand Down
Binary file added embedded/tool.html.gz
Binary file not shown.
5 changes: 4 additions & 1 deletion lwIP patch/iMXRT1062/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
---------- Internal Memory Pool Sizes ----------
------------------------------------------------
*/


/**
* MEMP_NUM_PBUF: the number of memp struct pbufs (used for PBUF_ROM and PBUF_REF).
* If the application sends a lot of data out of ROM (or other static memory),
Expand Down Expand Up @@ -146,8 +148,9 @@
* The formula expects settings to be either '0' or '1'.
*
* To this default value, 1 was added for the snmp_increment timer.
* grblHAL: added timeouts for SSDP protocol
*/
//#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)) + 1
#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)) + 5

/**
* MEMP_NUM_NETBUF: the number of struct netbufs.
Expand Down
43 changes: 30 additions & 13 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#include "../networking/http_upload.h"
#include "../networking/fs_ram.h"
#include "../networking/fs_stream.h"
#if SSDP_ENABLE
#include "../networking/ssdp.h"
#endif

#if WIFI_ENABLE && WIFI_SOFTAP
#include "wifi.h"
Expand Down Expand Up @@ -223,7 +226,7 @@ static const char *command (http_request_t *request)

cmd += 4;

uint_fast16_t argc = 0;
uint_fast16_t argc = 0, cmdv;
char c, cp = '\0', *args = NULL, **argv = NULL, *tmp, **tmp2, *tmp3;

if((ok = (args = strchr(cmd, ']')))) {
Expand All @@ -232,6 +235,10 @@ static const char *command (http_request_t *request)

if(*args) {

// Change escaped spaces into a NBSP pair
while((tmp = strstr(args, "\\ ")))
tmp[0] = tmp[1] = '\xA0'; // NBSP

// Trim leading and trailing spaces
while(*args == ' ')
args++;
Expand All @@ -241,7 +248,7 @@ static const char *command (http_request_t *request)
*tmp = '\0';
}

// remove duplicate delimiters (spaces)
// Remove duplicate delimiters (spaces)
tmp = tmp3 = args;
while((c = *tmp++) != '\0') {
if(c != ' ' || cp != ' ')
Expand All @@ -251,7 +258,7 @@ static const char *command (http_request_t *request)
*tmp3 = '\0';
}

// tokenize arguments (if any)
// Tokenize arguments (if any)
if(*args) {

argc = 1;
Expand All @@ -264,26 +271,27 @@ static const char *command (http_request_t *request)
if(argc == 1)
argv = &args;
else if((ok = !!(argv = tmp2 = malloc(sizeof(char *) * argc)))) {

tmp = strtok(args, " ");
while(tmp) {
*tmp2++ = tmp;
tmp = strtok(NULL, " ");
}

tmp = args;
while((c = *tmp) != '\0') {
if(c == ' ')
*tmp = '\0';
tmp++;
}
} else {
http_set_response_status(request, "500 Internal Server Error");
vfs_puts("Failed to generate response", file);
}
}

uint_fast16_t cmdv = atol(cmd);
// Replace escaped spaces with a space
for(cmdv = 0; cmdv < argc; cmdv++) {
tmp = argv[cmdv];
while((tmp = strstr(tmp, "\xA0\xA0"))) {
memmove(tmp, tmp + 1, strlen(tmp));
*tmp = ' ';
}
}

cmdv = atol(cmd);

if(cmdv == 800) {

Expand Down Expand Up @@ -771,7 +779,7 @@ static void webui_options (bool newopt)
on_report_options(newopt);

if(!newopt)
hal.stream.write("[PLUGIN:WebUI v0.10]" ASCII_EOL);
hal.stream.write("[PLUGIN:WebUI v0.11]" ASCII_EOL);
}

void webui_init (void)
Expand Down Expand Up @@ -823,6 +831,9 @@ void webui_init (void)
{ .uri = "/wifi", .method = HTTP_Options, .handler = wifi_options_handler },
#endif
{ .uri = "/*", .method = HTTP_Get, .handler = get_handler }, // Must be last!
#endif
#if SSDP_ENABLE
{ .uri = "/" SSDP_LOCATION_DOC, .method = HTTP_Get, .handler = ssdp_handler_get },
#endif
};

Expand Down Expand Up @@ -853,6 +864,9 @@ void webui_init (void)
{ .uri = "/wifi", .method = HTTP_Options, .handler = wifi_options_handler },
#endif
{ .uri = "/*", .method = HTTP_Get, .handler = get_handler }, // Must be last!
#endif
#if SSDP_ENABLE
{ .uri = "/" SSDP_LOCATION_DOC, .method = HTTP_Get, .handler = ssdp_handler_get },
#endif
};

Expand Down Expand Up @@ -883,6 +897,9 @@ void webui_init (void)
{ .uri = "/wifi", .method = HTTP_Options, .handler = wifi_options_handler },
#endif
{ .uri = "/*", .method = HTTP_Get, .handler = get_handler }, // Must be last!
#endif
#if SSDP_ENABLE
{ .uri = "/" SSDP_LOCATION_DOC, .method = HTTP_Get, .handler = ssdp_handler_get },
#endif
};

Expand Down

0 comments on commit e0b55d5

Please sign in to comment.