mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Support for executing multiple commands via /cmd
This commit is contained in:
@@ -1639,3 +1639,37 @@ config_done:
|
|||||||
clear_command_history();
|
clear_command_history();
|
||||||
save_cmd = 1;
|
save_cmd = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute multiple commands
|
||||||
|
// If a command is too long or can't be tokenized, remaining commands are not executed
|
||||||
|
// Returns the status via `err_status`-variable.
|
||||||
|
void execute_commands(__xdata uint8_t *p) __banked {
|
||||||
|
err_status = ERR_OK;
|
||||||
|
uint8_t cmd_idx = 0;
|
||||||
|
while (1) {
|
||||||
|
if (*p == 0 || *p == '\n' || *p == '\r') {
|
||||||
|
if (cmd_idx) {
|
||||||
|
cmd_buffer[cmd_idx] = '\0';
|
||||||
|
cmd_tokenize();
|
||||||
|
if (err_status != ERR_OK)
|
||||||
|
return;
|
||||||
|
cmd_parser();
|
||||||
|
}
|
||||||
|
if (*p == 0)
|
||||||
|
return;
|
||||||
|
cmd_idx = 0;
|
||||||
|
} else {
|
||||||
|
if (cmd_idx < (CMD_BUF_SIZE - 1)) {
|
||||||
|
cmd_buffer[cmd_idx++] = *p;
|
||||||
|
} else {
|
||||||
|
cmd_buffer[CMD_BUF_SIZE - 1] = '\0';
|
||||||
|
print_string("ERROR: Command too long: ");
|
||||||
|
print_string_x(cmd_buffer);
|
||||||
|
write_char('\n');
|
||||||
|
err_status = ERR_CMD_TOO_LONG;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,10 +7,13 @@
|
|||||||
|
|
||||||
extern __xdata uint8_t cmd_buffer[CMD_BUF_SIZE];
|
extern __xdata uint8_t cmd_buffer[CMD_BUF_SIZE];
|
||||||
extern __xdata uint8_t cmd_available;
|
extern __xdata uint8_t cmd_available;
|
||||||
|
extern __xdata uint8_t err_status;
|
||||||
|
|
||||||
void cmd_tokenize(void) __banked;
|
void cmd_tokenize(void) __banked;
|
||||||
void cmd_parser(void) __banked;
|
void cmd_parser(void) __banked;
|
||||||
void execute_config(void) __banked;
|
void execute_config(void) __banked;
|
||||||
|
void execute_commands(__xdata uint8_t *p) __banked;
|
||||||
void print_sw_version(void) __banked;
|
void print_sw_version(void) __banked;
|
||||||
void clear_command_history(void) __banked;
|
void clear_command_history(void) __banked;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+3
-2
@@ -12,8 +12,10 @@ async function ipSub() {
|
|||||||
if (!checkIp(document.getElementById(ips[i]).value))
|
if (!checkIp(document.getElementById(ips[i]).value))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var cmd = '';
|
||||||
for (let i=0; i<3;i++){
|
for (let i=0; i<3;i++){
|
||||||
var cmd = ips[i]+' '+document.getElementById(ips[i]).value;
|
cmd += ips[i]+' '+document.getElementById(ips[i]).value+'\n';
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/cmd', {
|
const response = await fetch('/cmd', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -24,7 +26,6 @@ async function ipSub() {
|
|||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(`Error: ${err}`);
|
console.error(`Error: ${err}`);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cmdSub() {
|
async function cmdSub() {
|
||||||
|
|||||||
+5
-6
@@ -400,17 +400,16 @@ void handle_post(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_word(request_path, "cmd")) {
|
if (is_word(request_path, "cmd")) {
|
||||||
register uint8_t i = 0;
|
|
||||||
p += 4;
|
p += 4;
|
||||||
if (!authenticated) {
|
if (!authenticated) {
|
||||||
send_unauthorized();
|
send_unauthorized();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (*p && *p != '\n' && *p != '\r')
|
execute_commands(p);
|
||||||
cmd_buffer[i++] = *p++;
|
if (err_status != ERR_OK) {
|
||||||
cmd_buffer[i] = '\0';
|
send_bad_request();
|
||||||
if (i)
|
return;
|
||||||
cmd_available = 1;
|
}
|
||||||
} else if (is_word(request_path, "login")) {
|
} else if (is_word(request_path, "login")) {
|
||||||
dbg_string("POST login\n");
|
dbg_string("POST login\n");
|
||||||
p += 8; // Read also over "pwd="
|
p += 8; // Read also over "pwd="
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
extern __code const struct machine machine;
|
extern __code const struct machine machine;
|
||||||
extern __xdata uint32_t flash_size;
|
extern __xdata uint32_t flash_size;
|
||||||
extern __xdata uint8_t err_status;
|
|
||||||
|
|
||||||
extern __xdata uint16_t crc_value;
|
extern __xdata uint16_t crc_value;
|
||||||
__xdata struct machine_runtime machine_detected;
|
__xdata struct machine_runtime machine_detected;
|
||||||
|
|||||||
Reference in New Issue
Block a user