mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 21:49:02 +08:00
Add ESP3.0 log like support for socket debug in web files
This commit is contained in:
parent
c8007cca38
commit
3291a90bf2
@ -1562,7 +1562,7 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
//go next record
|
//go next record
|
||||||
station = STAILQ_NEXT (station, next);
|
station = STAILQ_NEXT (station, next);
|
||||||
}
|
}
|
||||||
wifi_softap_free_station_info();
|
wifi_softap_free_station_info();
|
||||||
#endif
|
#endif
|
||||||
@ -1979,3 +1979,50 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
|
|||||||
ESPCOM::print (F ("\n"), output, espresponse);
|
ESPCOM::print (F ("\n"), output, espresponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_OUTPUT_SOCKET
|
||||||
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
|
#define NODEBUG_WEBSOCKETS
|
||||||
|
#include <WebSocketsServer.h>
|
||||||
|
extern WebSocketsServer * socket_server;
|
||||||
|
const char * pathToFileName(const char * path)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
size_t pos = 0;
|
||||||
|
char * p = (char *)path;
|
||||||
|
while(*p) {
|
||||||
|
i++;
|
||||||
|
if(*p == '/' || *p == '\\') {
|
||||||
|
pos = i;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
return path+pos;
|
||||||
|
}
|
||||||
|
#endif //ARDUINO_ARCH_ESP8266
|
||||||
|
|
||||||
|
void log_socket(const char *format, ...){
|
||||||
|
if(socket_server){
|
||||||
|
char loc_buf[255];
|
||||||
|
char * temp = loc_buf;
|
||||||
|
va_list arg;
|
||||||
|
va_list copy;
|
||||||
|
va_start(arg, format);
|
||||||
|
va_copy(copy, arg);
|
||||||
|
size_t len = vsnprintf(NULL, 0, format, arg);
|
||||||
|
va_end(copy);
|
||||||
|
if(len >= sizeof(loc_buf)){
|
||||||
|
temp = new char[len+1];
|
||||||
|
if(temp == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len = vsnprintf(temp, len+1, format, arg);
|
||||||
|
socket_server->sendBIN(ESPCOM::current_socket_id,(uint8_t *)temp,strlen(temp));
|
||||||
|
va_end(arg);
|
||||||
|
if(len > 255){
|
||||||
|
delete[] temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//version and sources location
|
//version and sources location
|
||||||
#define FW_VERSION "2.1.1.b3"
|
#define FW_VERSION "2.1.1.b4"
|
||||||
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
||||||
|
|
||||||
//Customize ESP3D ////////////////////////////////////////////////////////////////////////
|
//Customize ESP3D ////////////////////////////////////////////////////////////////////////
|
||||||
@ -211,6 +211,14 @@ using fs::File;
|
|||||||
//NOT YET IMPLEMENTED!!! Keep it as TODO
|
//NOT YET IMPLEMENTED!!! Keep it as TODO
|
||||||
//#define WEBHOST_SDCARD_FEATURE
|
//#define WEBHOST_SDCARD_FEATURE
|
||||||
|
|
||||||
|
#ifdef DEBUG_OUTPUT_SOCKET
|
||||||
|
extern void log_socket(const char *format, ...);
|
||||||
|
extern const char * pathToFileName(const char * path);
|
||||||
|
#define log_esp3d(format, ...) log_socket("\n[ESP3D][%s:%u] %s(): " format "\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define log_esp3d(format, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG_ESP3D
|
#ifdef DEBUG_ESP3D
|
||||||
#ifdef DEBUG_OUTPUT_SPIFFS
|
#ifdef DEBUG_OUTPUT_SPIFFS
|
||||||
#ifndef FS_NO_GLOBALS
|
#ifndef FS_NO_GLOBALS
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
#include "syncwebserver.h"
|
#include "syncwebserver.h"
|
||||||
WebSocketsServer * socket_server;
|
WebSocketsServer * socket_server;
|
||||||
|
|
||||||
|
|
||||||
#define ESP_ERROR_AUTHENTICATION 1
|
#define ESP_ERROR_AUTHENTICATION 1
|
||||||
#define ESP_ERROR_FILE_CREATION 2
|
#define ESP_ERROR_FILE_CREATION 2
|
||||||
#define ESP_ERROR_FILE_WRITE 3
|
#define ESP_ERROR_FILE_WRITE 3
|
||||||
@ -74,6 +75,7 @@ WebSocketsServer * socket_server;
|
|||||||
#define ESP_ERROR_BUFFER_OVERFLOW 11
|
#define ESP_ERROR_BUFFER_OVERFLOW 11
|
||||||
#define ESP_ERROR_START_UPLOAD 12
|
#define ESP_ERROR_START_UPLOAD 12
|
||||||
|
|
||||||
|
|
||||||
void pushError(int code, const char * st, bool web_error = 500, uint16_t timeout = 1000){
|
void pushError(int code, const char * st, bool web_error = 500, uint16_t timeout = 1000){
|
||||||
if (socket_server && st) {
|
if (socket_server && st) {
|
||||||
String s = "ERROR:" + String(code) + ":";
|
String s = "ERROR:" + String(code) + ":";
|
||||||
@ -725,7 +727,7 @@ void WebUpdateUpload()
|
|||||||
if(web_interface->is_authenticated() != LEVEL_ADMIN) {
|
if(web_interface->is_authenticated() != LEVEL_ADMIN) {
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status=UPLOAD_STATUS_FAILED;
|
||||||
ESPCOM::println (F ("Update failed"), PRINTER_PIPE);
|
ESPCOM::println (F ("Update failed"), PRINTER_PIPE);
|
||||||
LOG("Web Update failed\r\n");
|
log_esp3d("Web Update failed");
|
||||||
pushError(ESP_ERROR_AUTHENTICATION, "Upload rejected",401);
|
pushError(ESP_ERROR_AUTHENTICATION, "Upload rejected",401);
|
||||||
} else {
|
} else {
|
||||||
//get current file ID
|
//get current file ID
|
||||||
@ -853,22 +855,7 @@ void handle_not_found()
|
|||||||
String path = web_interface->web_server.urlDecode(web_interface->web_server.uri());
|
String path = web_interface->web_server.urlDecode(web_interface->web_server.uri());
|
||||||
String contentType = web_interface->getContentType(path);
|
String contentType = web_interface->getContentType(path);
|
||||||
String pathWithGz = path + ".gz";
|
String pathWithGz = path + ".gz";
|
||||||
LOG("request:")
|
log_esp3d("Not found %s, type %s", path.c_str(), contentType.c_str());
|
||||||
LOG(path)
|
|
||||||
LOG("\r\n")
|
|
||||||
#ifdef DEBUG_ESP3D
|
|
||||||
int nb = web_interface->web_server.args();
|
|
||||||
for (int i = 0 ; i < nb; i++) {
|
|
||||||
LOG(web_interface->web_server.argName(i))
|
|
||||||
LOG(":")
|
|
||||||
LOG(web_interface->web_server.arg(i))
|
|
||||||
LOG("\r\n")
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
LOG("type:")
|
|
||||||
LOG(contentType)
|
|
||||||
LOG("\r\n")
|
|
||||||
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
|
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
|
||||||
if(SPIFFS.exists(pathWithGz)) {
|
if(SPIFFS.exists(pathWithGz)) {
|
||||||
path = pathWithGz;
|
path = pathWithGz;
|
||||||
@ -901,7 +888,7 @@ void handle_not_found()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
LOG("Page not found\r\n")
|
log_esp3d("Page not found");
|
||||||
path = F("/404.htm");
|
path = F("/404.htm");
|
||||||
contentType = web_interface->getContentType(path);
|
contentType = web_interface->getContentType(path);
|
||||||
pathWithGz = path + F(".gz");
|
pathWithGz = path + F(".gz");
|
||||||
@ -946,17 +933,6 @@ void handle_web_command()
|
|||||||
}*/
|
}*/
|
||||||
String buffer2send = "";
|
String buffer2send = "";
|
||||||
ESPResponseStream espresponse;
|
ESPResponseStream espresponse;
|
||||||
LOG(String (web_interface->web_server.args()))
|
|
||||||
LOG(" Web command\r\n")
|
|
||||||
#ifdef DEBUG_ESP3D
|
|
||||||
int nb = web_interface->web_server.args();
|
|
||||||
for (int i = 0 ; i < nb; i++) {
|
|
||||||
LOG(web_interface->web_server.argName(i))
|
|
||||||
LOG(":")
|
|
||||||
LOG(web_interface->web_server.arg(i))
|
|
||||||
LOG("\r\n")
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
String cmd = "";
|
String cmd = "";
|
||||||
if (web_interface->web_server.hasArg("plain") || web_interface->web_server.hasArg("commandText")) {
|
if (web_interface->web_server.hasArg("plain") || web_interface->web_server.hasArg("commandText")) {
|
||||||
if (web_interface->web_server.hasArg("plain")) {
|
if (web_interface->web_server.hasArg("plain")) {
|
||||||
@ -964,11 +940,9 @@ void handle_web_command()
|
|||||||
} else {
|
} else {
|
||||||
cmd = web_interface->web_server.arg("commandText");
|
cmd = web_interface->web_server.arg("commandText");
|
||||||
}
|
}
|
||||||
LOG("Web Command:")
|
log_esp3d("WebCommand %s",cmd.c_str());
|
||||||
LOG(cmd)
|
|
||||||
LOG("\r\n")
|
|
||||||
} else {
|
} else {
|
||||||
LOG("invalid argument\r\n")
|
log_esp3d("Invalid arg");
|
||||||
web_interface->web_server.send(200,"text/plain","Invalid command");
|
web_interface->web_server.send(200,"text/plain","Invalid command");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1008,26 +982,25 @@ void handle_web_command()
|
|||||||
if ((web_interface->blockserial) == false) {
|
if ((web_interface->blockserial) == false) {
|
||||||
//block every query
|
//block every query
|
||||||
web_interface->blockserial = true;
|
web_interface->blockserial = true;
|
||||||
LOG("Block Serial\r\n")
|
log_esp3d("Block Serial");
|
||||||
//empty the serial buffer and incoming data
|
//empty the serial buffer and incoming data
|
||||||
LOG("Start PurgeSerial\r\n")
|
log_esp3d("Start PurgeSerial");
|
||||||
if(ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
if(ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
||||||
ESPCOM::bridge();
|
ESPCOM::bridge();
|
||||||
CONFIG::wait(1);
|
CONFIG::wait(1);
|
||||||
}
|
}
|
||||||
LOG("End PurgeSerial\r\n")
|
log_esp3d("End PurgeSerial");
|
||||||
web_interface->web_server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
web_interface->web_server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||||
web_interface->web_server.sendHeader("Content-Type","text/plain",true);
|
web_interface->web_server.sendHeader("Content-Type","text/plain",true);
|
||||||
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
||||||
web_interface->web_server.send(200);
|
web_interface->web_server.send(200);
|
||||||
//send command
|
//send command
|
||||||
LOG(String(cmd.length()))
|
log_esp3d("Start PurgeSerial");
|
||||||
LOG("Start PurgeSerial\r\n")
|
|
||||||
if(ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
if(ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
||||||
ESPCOM::bridge();
|
ESPCOM::bridge();
|
||||||
CONFIG::wait(1);
|
CONFIG::wait(1);
|
||||||
}
|
}
|
||||||
LOG("End PurgeSerial\r\n")
|
log_esp3d("End PurgeSerial");
|
||||||
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
|
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
|
||||||
bool done = false;
|
bool done = false;
|
||||||
String current_buffer;
|
String current_buffer;
|
||||||
@ -1041,7 +1014,7 @@ void handle_web_command()
|
|||||||
while ((millis() - timeout < 2000) && !done) {
|
while ((millis() - timeout < 2000) && !done) {
|
||||||
//give some time between each buffer
|
//give some time between each buffer
|
||||||
if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
||||||
LOG("Got data\r\n")
|
log_esp3d("Got data");
|
||||||
timeout = millis();
|
timeout = millis();
|
||||||
size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE);
|
size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE);
|
||||||
uint8_t sbuf[len+1];
|
uint8_t sbuf[len+1];
|
||||||
@ -1049,12 +1022,10 @@ void handle_web_command()
|
|||||||
ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len);
|
ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len);
|
||||||
//change buffer as string
|
//change buffer as string
|
||||||
sbuf[len]='\0';
|
sbuf[len]='\0';
|
||||||
LOG((const char*)sbuf)
|
|
||||||
LOG("\r\n")
|
|
||||||
//add buffer to current one if any
|
//add buffer to current one if any
|
||||||
current_buffer += (char * ) sbuf;
|
current_buffer += (char * ) sbuf;
|
||||||
while (current_buffer.indexOf("\n") !=-1) {
|
while (current_buffer.indexOf("\n") !=-1) {
|
||||||
LOG("remove newline")
|
log_esp3d("Remove new line");
|
||||||
//remove the possible "\r"
|
//remove the possible "\r"
|
||||||
current_buffer.replace("\r","");
|
current_buffer.replace("\r","");
|
||||||
//get line
|
//get line
|
||||||
@ -1063,17 +1034,11 @@ void handle_web_command()
|
|||||||
if ((current_line == "ok") || (current_line == "wait") || (current_line.startsWith("ok") && !((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)))) {
|
if ((current_line == "ok") || (current_line == "wait") || (current_line.startsWith("ok") && !((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)))) {
|
||||||
done = true;
|
done = true;
|
||||||
buffer2send +=current_line;
|
buffer2send +=current_line;
|
||||||
LOG("new buffer: ")
|
log_esp3d("Found ok/wait add New buffer %s", buffer2send.c_str());
|
||||||
LOG(buffer2send)
|
|
||||||
LOG("\r\n")
|
|
||||||
buffer2send +="\n";
|
buffer2send +="\n";
|
||||||
LOG("Found ok or wait\r\n")
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//get the line and transmit it
|
//get the line and transmit it
|
||||||
LOG("Check command: ")
|
|
||||||
LOG(current_line)
|
|
||||||
LOG("\r\n")
|
|
||||||
//check command
|
//check command
|
||||||
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) {
|
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) {
|
||||||
//save time no need to continue
|
//save time no need to continue
|
||||||
@ -1088,7 +1053,7 @@ void handle_web_command()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (temp_counter > 5) {
|
if (temp_counter > 5) {
|
||||||
LOG("Timeout X5\r\n")
|
log_esp3d("Timeout X5");
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1099,16 +1064,12 @@ void handle_web_command()
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buffer2send +=current_line;
|
buffer2send +=current_line;
|
||||||
LOG("new buffer: ")
|
log_esp3d("New buffer %s", buffer2send.c_str());
|
||||||
LOG(buffer2send)
|
|
||||||
LOG("\r\n")
|
|
||||||
buffer2send +="\n";
|
buffer2send +="\n";
|
||||||
}
|
}
|
||||||
if (buffer2send.length() > 1200) {
|
if (buffer2send.length() > 1200) {
|
||||||
web_interface->web_server.sendContent(buffer2send);
|
web_interface->web_server.sendContent(buffer2send);
|
||||||
LOG("sending: ")
|
log_esp3d("Sending %s", buffer2send.c_str());
|
||||||
LOG(buffer2send)
|
|
||||||
LOG("\r\n")
|
|
||||||
buffer2send = "";
|
buffer2send = "";
|
||||||
datasent = true;
|
datasent = true;
|
||||||
}
|
}
|
||||||
@ -1120,34 +1081,31 @@ void handle_web_command()
|
|||||||
CONFIG::wait (0);
|
CONFIG::wait (0);
|
||||||
} else {
|
} else {
|
||||||
CONFIG::wait(1);
|
CONFIG::wait(1);
|
||||||
LOG(".")
|
|
||||||
}
|
}
|
||||||
//it is sending too many temp status should be heating so let's exit the loop
|
//it is sending too many temp status should be heating so let's exit the loop
|
||||||
if (temp_counter > 5) {
|
if (temp_counter > 5) {
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG("Finished\r\n")
|
log_esp3d("Finished");
|
||||||
//to be sure connection close
|
//to be sure connection close
|
||||||
if (buffer2send.length() > 0) {
|
if (buffer2send.length() > 0) {
|
||||||
web_interface->web_server.sendContent(buffer2send);
|
web_interface->web_server.sendContent(buffer2send);
|
||||||
LOG("sending: ")
|
log_esp3d("Sending %s", buffer2send.c_str());
|
||||||
LOG(buffer2send)
|
|
||||||
LOG("\r\n")
|
|
||||||
datasent = true;
|
datasent = true;
|
||||||
}
|
}
|
||||||
if (!datasent) {
|
if (!datasent) {
|
||||||
web_interface->web_server.sendContent(" \r\n");
|
web_interface->web_server.sendContent(" \r\n");
|
||||||
}
|
}
|
||||||
web_interface->web_server.sendContent("");
|
web_interface->web_server.sendContent("");
|
||||||
LOG("Start PurgeSerial\r\n")
|
log_esp3d("Start PurgeSerial");
|
||||||
if(ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
if(ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
||||||
ESPCOM::bridge();
|
ESPCOM::bridge();
|
||||||
CONFIG::wait(1);
|
CONFIG::wait(1);
|
||||||
}
|
}
|
||||||
LOG("End PurgeSerial\r\n")
|
log_esp3d("End PurgeSerial");
|
||||||
web_interface->blockserial = false;
|
web_interface->blockserial = false;
|
||||||
LOG("Release Serial\r\n")
|
log_esp3d("Release PurgeSerial");
|
||||||
} else {
|
} else {
|
||||||
web_interface->web_server.send(200,"text/plain","Serial is busy, retry later!");
|
web_interface->web_server.send(200,"text/plain","Serial is busy, retry later!");
|
||||||
}
|
}
|
||||||
@ -1163,17 +1121,6 @@ void handle_web_command_silent()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String buffer2send = "";
|
String buffer2send = "";
|
||||||
LOG(String (web_interface->web_server.args()))
|
|
||||||
LOG(" Web silent command\r\n")
|
|
||||||
#ifdef DEBUG_ESP3D
|
|
||||||
int nb = web_interface->web_server.args();
|
|
||||||
for (int i = 0 ; i < nb; i++) {
|
|
||||||
LOG(web_interface->web_server.argName(i))
|
|
||||||
LOG(":")
|
|
||||||
LOG(web_interface->web_server.arg(i))
|
|
||||||
LOG("\r\n")
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
String cmd = "";
|
String cmd = "";
|
||||||
//int count ;
|
//int count ;
|
||||||
if (web_interface->web_server.hasArg("plain") || web_interface->web_server.hasArg("commandText")) {
|
if (web_interface->web_server.hasArg("plain") || web_interface->web_server.hasArg("commandText")) {
|
||||||
@ -1182,11 +1129,9 @@ void handle_web_command_silent()
|
|||||||
} else {
|
} else {
|
||||||
cmd = web_interface->web_server.arg("commandText");
|
cmd = web_interface->web_server.arg("commandText");
|
||||||
}
|
}
|
||||||
LOG("Web Command:")
|
log_esp3d("Web Command:%s", cmd.c_str());
|
||||||
LOG(cmd)
|
|
||||||
LOG("\r\n")
|
|
||||||
} else {
|
} else {
|
||||||
LOG("invalid argument\r\n")
|
log_esp3d("Invalid argument");
|
||||||
web_interface->web_server.send(200,"text/plain","Invalid command");
|
web_interface->web_server.send(200,"text/plain","Invalid command");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1219,7 +1164,6 @@ void handle_web_command_silent()
|
|||||||
//send command to serial as no need to transfer ESP command
|
//send command to serial as no need to transfer ESP command
|
||||||
//to avoid any pollution if Uploading file to SDCard
|
//to avoid any pollution if Uploading file to SDCard
|
||||||
if ((web_interface->blockserial) == false) {
|
if ((web_interface->blockserial) == false) {
|
||||||
LOG("Send Command\r\n")
|
|
||||||
//send command
|
//send command
|
||||||
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
|
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
|
||||||
web_interface->web_server.send(200,"text/plain","ok");
|
web_interface->web_server.send(200,"text/plain","ok");
|
||||||
@ -1241,7 +1185,8 @@ void handle_serial_SDFileList()
|
|||||||
web_interface->web_server.send(401, "application/json", "{\"status\":\"Authentication failed!\"}");
|
web_interface->web_server.send(401, "application/json", "{\"status\":\"Authentication failed!\"}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG("serial SD upload done\r\n")
|
|
||||||
|
log_esp3d("Serial SD upload done");
|
||||||
String sstatus="Ok";
|
String sstatus="Ok";
|
||||||
if ((web_interface->_upload_status == UPLOAD_STATUS_FAILED) || (web_interface->_upload_status == UPLOAD_STATUS_FAILED)) {
|
if ((web_interface->_upload_status == UPLOAD_STATUS_FAILED) || (web_interface->_upload_status == UPLOAD_STATUS_FAILED)) {
|
||||||
sstatus = "Upload failed";
|
sstatus = "Upload failed";
|
||||||
@ -1270,7 +1215,7 @@ void SDFile_serial_upload()
|
|||||||
web_interface->_upload_status=UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status=UPLOAD_STATUS_FAILED;
|
||||||
ESPCOM::println (F ("SD upload rejected"), PRINTER_PIPE);
|
ESPCOM::println (F ("SD upload rejected"), PRINTER_PIPE);
|
||||||
pushError(ESP_ERROR_AUTHENTICATION, "Upload rejected", 401);
|
pushError(ESP_ERROR_AUTHENTICATION, "Upload rejected", 401);
|
||||||
LOG("SD upload rejected\r\n");
|
log_esp3d("SD upload rejected");
|
||||||
} else {
|
} else {
|
||||||
//retrieve current file id
|
//retrieve current file id
|
||||||
HTTPUpload& upload = (web_interface->web_server).upload();
|
HTTPUpload& upload = (web_interface->web_server).upload();
|
||||||
@ -1279,7 +1224,7 @@ void SDFile_serial_upload()
|
|||||||
//**************
|
//**************
|
||||||
if(upload.status == UPLOAD_FILE_START) {
|
if(upload.status == UPLOAD_FILE_START) {
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||||
LOG("Upload Start\r\n")
|
log_esp3d("Upload start");
|
||||||
String command = "M29";
|
String command = "M29";
|
||||||
String resetcmd = "M110 N0";
|
String resetcmd = "M110 N0";
|
||||||
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)resetcmd = "N0 M110";
|
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)resetcmd = "N0 M110";
|
||||||
@ -1289,12 +1234,12 @@ void SDFile_serial_upload()
|
|||||||
//it can failed for repetier
|
//it can failed for repetier
|
||||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
||||||
if(!sendLine2Serial (command,-1, NULL)){
|
if(!sendLine2Serial (command,-1, NULL)){
|
||||||
LOG("Start Upload failed")
|
log_esp3d("Upload start failed");
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
pushError(ESP_ERROR_START_UPLOAD, "Upload rejected");
|
pushError(ESP_ERROR_START_UPLOAD, "Upload rejected");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG("Start Upload failed")
|
log_esp3d("Upload start failed");
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
pushError(ESP_ERROR_START_UPLOAD, "Upload rejected");
|
pushError(ESP_ERROR_START_UPLOAD, "Upload rejected");
|
||||||
}
|
}
|
||||||
@ -1302,14 +1247,14 @@ void SDFile_serial_upload()
|
|||||||
//Mount SD card
|
//Mount SD card
|
||||||
command = "M21";
|
command = "M21";
|
||||||
if(!sendLine2Serial (command,-1, NULL)){
|
if(!sendLine2Serial (command,-1, NULL)){
|
||||||
LOG("Mounting SD failed")
|
log_esp3d("Mounting SD failed");
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
pushError(ESP_ERROR_MOUNT_SD, "Mounting SD failed");
|
pushError(ESP_ERROR_MOUNT_SD, "Mounting SD failed");
|
||||||
}
|
}
|
||||||
if (web_interface->_upload_status != UPLOAD_STATUS_FAILED) {
|
if (web_interface->_upload_status != UPLOAD_STATUS_FAILED) {
|
||||||
//Reset line numbering
|
//Reset line numbering
|
||||||
if(!sendLine2Serial (resetcmd,-1, NULL)){
|
if(!sendLine2Serial (resetcmd,-1, NULL)){
|
||||||
LOG("Reset Numbering failed")
|
log_esp3d("Reset Numbering failed");
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
pushError(ESP_ERROR_RESET_NUMBERING, "Reset Numbering failed");
|
pushError(ESP_ERROR_RESET_NUMBERING, "Reset Numbering failed");
|
||||||
}
|
}
|
||||||
@ -1336,11 +1281,11 @@ void SDFile_serial_upload()
|
|||||||
//additional purge, in case it is slow to answer
|
//additional purge, in case it is slow to answer
|
||||||
purge_serial();
|
purge_serial();
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||||
LOG("Creation Ok\r\n")
|
log_esp3d("Creation Ok");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
LOG("Creation failed\r\n");
|
log_esp3d("Creation failed");
|
||||||
pushError(ESP_ERROR_FILE_CREATION, "File creation failed");
|
pushError(ESP_ERROR_FILE_CREATION, "File creation failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1354,7 +1299,7 @@ void SDFile_serial_upload()
|
|||||||
CONFIG::wait(0);
|
CONFIG::wait(0);
|
||||||
//it is a comment
|
//it is a comment
|
||||||
if (upload.buf[pos] == ';') {
|
if (upload.buf[pos] == ';') {
|
||||||
LOG ("Comment\r\n")
|
log_esp3d("Comment found");
|
||||||
is_comment = true;
|
is_comment = true;
|
||||||
}
|
}
|
||||||
//it is an end line
|
//it is an end line
|
||||||
@ -1367,7 +1312,7 @@ void SDFile_serial_upload()
|
|||||||
if (current_line.length() > 0 ) {
|
if (current_line.length() > 0 ) {
|
||||||
lineNb++;
|
lineNb++;
|
||||||
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
|
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
|
||||||
LOG ("Error sending line\n")
|
log_esp3d("Error sending line");
|
||||||
CloseSerialUpload (true, current_filename,lineNb);
|
CloseSerialUpload (true, current_filename,lineNb);
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
pushError(ESP_ERROR_FILE_WRITE, "File write failed");
|
pushError(ESP_ERROR_FILE_WRITE, "File write failed");
|
||||||
@ -1376,11 +1321,11 @@ void SDFile_serial_upload()
|
|||||||
current_line = "";
|
current_line = "";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOG ("Empy line\n")
|
log_esp3d ("Empy line");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//error buffer overload
|
//error buffer overload
|
||||||
LOG ("Error over buffer\n")
|
log_esp3d ("Error over buffer(1)");
|
||||||
lineNb++;
|
lineNb++;
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
pushError(ESP_ERROR_BUFFER_OVERFLOW, "Error buffer overflow");
|
pushError(ESP_ERROR_BUFFER_OVERFLOW, "Error buffer overflow");
|
||||||
@ -1389,7 +1334,7 @@ void SDFile_serial_upload()
|
|||||||
if (current_line.length() < MAX_RESEND_BUFFER) {
|
if (current_line.length() < MAX_RESEND_BUFFER) {
|
||||||
current_line += char (upload.buf[pos]); //copy current char to buffer to send/resend
|
current_line += char (upload.buf[pos]); //copy current char to buffer to send/resend
|
||||||
} else {
|
} else {
|
||||||
LOG ("Error over buffer\n")
|
log_esp3d ("Error over buffer(2)");
|
||||||
lineNb++;
|
lineNb++;
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
pushError(ESP_ERROR_BUFFER_OVERFLOW, "Error buffer overflow");
|
pushError(ESP_ERROR_BUFFER_OVERFLOW, "Error buffer overflow");
|
||||||
@ -1403,20 +1348,20 @@ void SDFile_serial_upload()
|
|||||||
if (current_line.length() > 0) {
|
if (current_line.length() > 0) {
|
||||||
lineNb++;
|
lineNb++;
|
||||||
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
|
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
|
||||||
LOG ("Error sending buffer\n")
|
log_esp3d ("Error sending buffer");
|
||||||
lineNb++;
|
lineNb++;
|
||||||
CloseSerialUpload (true, current_filename, lineNb);
|
CloseSerialUpload (true, current_filename, lineNb);
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
pushError(ESP_ERROR_FILE_WRITE, "File write failed");
|
pushError(ESP_ERROR_FILE_WRITE, "File write failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG ("Upload finished ");
|
log_esp3d ("Upload finished");
|
||||||
lineNb++;
|
lineNb++;
|
||||||
CloseSerialUpload (false, current_filename, lineNb);
|
CloseSerialUpload (false, current_filename, lineNb);
|
||||||
//Upload cancelled
|
//Upload cancelled
|
||||||
//**************
|
//**************
|
||||||
} else { //UPLOAD_FILE_ABORTED
|
} else { //UPLOAD_FILE_ABORTED
|
||||||
LOG("Error, Something happened\r\n");
|
log_esp3d("Error, Something happened");
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
//pushError(ESP_ERROR_UPLOAD_CANCELLED, "Upload cancelled");
|
//pushError(ESP_ERROR_UPLOAD_CANCELLED, "Upload cancelled");
|
||||||
}
|
}
|
||||||
|
@ -96,29 +96,26 @@ bool purge_serial()
|
|||||||
uint8_t buf [51];
|
uint8_t buf [51];
|
||||||
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
||||||
CONFIG::wait (5);
|
CONFIG::wait (5);
|
||||||
LOG("Purge Serial\r\n")
|
log_esp3d("Purge Serial");
|
||||||
while (ESPCOM::available(DEFAULT_PRINTER_PIPE) > 0 ) {
|
while (ESPCOM::available(DEFAULT_PRINTER_PIPE) > 0 ) {
|
||||||
if ((millis() - start ) > 2000) {
|
if ((millis() - start ) > 2000) {
|
||||||
LOG("Purge timeout\r\n")
|
log_esp3d("Purge timeout");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size_t len = ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, buf, 50);
|
size_t len = ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, buf, 50);
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
LOG("Purge: \r\n************\r\n")
|
|
||||||
LOG((const char *)buf)
|
|
||||||
LOG("\r\n************\r\n")
|
|
||||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
||||||
String s = (const char *)buf;
|
String s = (const char *)buf;
|
||||||
//repetier never stop sending data so no need to wait if have 'wait' or 'busy'
|
//repetier never stop sending data so no need to wait if have 'wait' or 'busy'
|
||||||
if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1)) {
|
if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
LOG("Purge interrupted\r\n")
|
log_esp3d("Purge interrupted");
|
||||||
}
|
}
|
||||||
CONFIG::wait (5);
|
CONFIG::wait (5);
|
||||||
}
|
}
|
||||||
CONFIG::wait (0);
|
CONFIG::wait (0);
|
||||||
LOG("Purge done\r\n")
|
log_esp3d("Purge done");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,9 +145,7 @@ uint32_t Get_lineNumber(String & response)
|
|||||||
//remove potential unwished char
|
//remove potential unwished char
|
||||||
snum.replace("\r", "");
|
snum.replace("\r", "");
|
||||||
l = snum.toInt();
|
l = snum.toInt();
|
||||||
LOG("Line requested is ")
|
log_esp3d("Line requested is %d", l);
|
||||||
LOG(String(l))
|
|
||||||
LOG("\r\n")
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,11 +153,7 @@ uint32_t Get_lineNumber(String & response)
|
|||||||
//if newlinenb is NULL no auto correction of line number in case of resend
|
//if newlinenb is NULL no auto correction of line number in case of resend
|
||||||
bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
||||||
{
|
{
|
||||||
LOG ("Send line ")
|
log_esp3d ("Send line %d");
|
||||||
LOG (line )
|
|
||||||
LOG (" NB:")
|
|
||||||
LOG (String(linenb))
|
|
||||||
LOG ("\r\n")
|
|
||||||
String line2send;
|
String line2send;
|
||||||
String sok = "ok";
|
String sok = "ok";
|
||||||
String sresend = "Resend:";
|
String sresend = "Resend:";
|
||||||
@ -182,9 +173,6 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
|||||||
}
|
}
|
||||||
//purge serial as nothing is supposed to interfere with upload
|
//purge serial as nothing is supposed to interfere with upload
|
||||||
purge_serial();
|
purge_serial();
|
||||||
LOG ("Send line ")
|
|
||||||
LOG (line2send )
|
|
||||||
LOG ("\r\n")
|
|
||||||
//send line
|
//send line
|
||||||
ESPCOM::println (line2send, DEFAULT_PRINTER_PIPE);
|
ESPCOM::println (line2send, DEFAULT_PRINTER_PIPE);
|
||||||
ESPCOM::flush(DEFAULT_PRINTER_PIPE);
|
ESPCOM::flush(DEFAULT_PRINTER_PIPE);
|
||||||
@ -209,19 +197,16 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
|||||||
sbuf[len] = '\0';
|
sbuf[len] = '\0';
|
||||||
//use string because easier to handle and allow to re-assemble cutted answer
|
//use string because easier to handle and allow to re-assemble cutted answer
|
||||||
response += (const char*) sbuf;
|
response += (const char*) sbuf;
|
||||||
LOG ("Response:\r\n************\r\n")
|
|
||||||
LOG (response)
|
|
||||||
LOG ("\r\n************\r\n")
|
|
||||||
//in that case there is no way to know what is the right number to use and so send should be failed
|
//in that case there is no way to know what is the right number to use and so send should be failed
|
||||||
if (( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) && (response.indexOf ("skip") != -1)) {
|
if (( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) && (response.indexOf ("skip") != -1)) {
|
||||||
LOG ("Wrong line requested\r\n")
|
log_esp3d ("Wrong line requested");
|
||||||
count = 5;
|
count = 5;
|
||||||
}
|
}
|
||||||
//it is resend ?
|
//it is resend ?
|
||||||
int pos = response.indexOf (sresend);
|
int pos = response.indexOf (sresend);
|
||||||
//be sure we get full line to be able to process properly
|
//be sure we get full line to be able to process properly
|
||||||
if (( pos > -1) && (response.lastIndexOf("\n") > pos)) {
|
if (( pos > -1) && (response.lastIndexOf("\n") > pos)) {
|
||||||
LOG ("Resend detected\r\n")
|
log_esp3d ("Resend detected");
|
||||||
uint32_t line_number = Get_lineNumber(response);
|
uint32_t line_number = Get_lineNumber(response);
|
||||||
//this part is only if have newlinenb variable
|
//this part is only if have newlinenb variable
|
||||||
if (newlinenb != nullptr) {
|
if (newlinenb != nullptr) {
|
||||||
@ -232,20 +217,18 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
|||||||
} else {
|
} else {
|
||||||
//the line requested is not the current one so we stop
|
//the line requested is not the current one so we stop
|
||||||
if (line_number !=linenb) {
|
if (line_number !=linenb) {
|
||||||
LOG ("Wrong line requested\r\n")
|
log_esp3d ("Wrong line requested");
|
||||||
count = 5;
|
count = 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
if (count > 5) {
|
if (count > 5) {
|
||||||
free(sbuf);
|
free(sbuf);
|
||||||
LOG ("Exit too many resend or wrong line\r\n")
|
log_esp3d ("Exit too many resend or wrong line");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
purge_serial();
|
purge_serial();
|
||||||
LOG ("Resend ")
|
log_esp3d ("Resend x%d", count);
|
||||||
LOG (String(count))
|
|
||||||
LOG ("\r\n")
|
|
||||||
response="";
|
response="";
|
||||||
ESPCOM::println (line2send, DEFAULT_PRINTER_PIPE);
|
ESPCOM::println (line2send, DEFAULT_PRINTER_PIPE);
|
||||||
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
||||||
@ -255,7 +238,7 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
|||||||
} else {
|
} else {
|
||||||
if ( (response.indexOf (sok) > -1) ) { //we have ok so it is done
|
if ( (response.indexOf (sok) > -1) ) { //we have ok so it is done
|
||||||
free(sbuf);
|
free(sbuf);
|
||||||
LOG ("Got ok\r\n")
|
log_esp3d ("Got ok");
|
||||||
purge_serial();
|
purge_serial();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -264,13 +247,13 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
|||||||
}
|
}
|
||||||
//no answer or over buffer exit
|
//no answer or over buffer exit
|
||||||
if ( (millis() - timeout > 2000) || (response.length() >200)) {
|
if ( (millis() - timeout > 2000) || (response.length() >200)) {
|
||||||
LOG ("Time out\r\n")
|
log_esp3d("Time out");
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
CONFIG::wait (5);
|
CONFIG::wait (5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG ("Send line error\r\n")
|
log_esp3d ("Send line error");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user