mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-06-06 02:36:49 +08:00
Add SD files transfert
First pass - may need fine tune
This commit is contained in:
parent
22af45d69f
commit
6d73f3a9f2
@ -2430,39 +2430,91 @@ void SPIFFSFileupload()
|
|||||||
}
|
}
|
||||||
delay(0);
|
delay(0);
|
||||||
}
|
}
|
||||||
|
#define NB_RETRY 5
|
||||||
void SDFileupload()
|
void SDFileupload()
|
||||||
{
|
{
|
||||||
static bool linewrote = false;
|
static byte buffer_line[128]; //if need to resend
|
||||||
|
static int buffer_size=0;
|
||||||
|
static bool com_error = false;
|
||||||
|
String response;
|
||||||
HTTPUpload& upload = (web_interface->WebServer).upload();
|
HTTPUpload& upload = (web_interface->WebServer).upload();
|
||||||
if(upload.status == UPLOAD_FILE_START) {
|
if(upload.status == UPLOAD_FILE_START) {
|
||||||
(web_interface->blockserial) = true;
|
(web_interface->blockserial) = true;
|
||||||
linewrote = false;
|
buffer_size=0;
|
||||||
|
com_error = false;
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||||
Serial.println("M117 Start SD upload");
|
Serial.println("M117 Start SD upload");
|
||||||
String filename = "M28 " + upload.filename;
|
String filename = "M28 " + upload.filename;
|
||||||
Serial.println(filename);
|
Serial.println(filename);
|
||||||
filename = String();
|
filename = String();
|
||||||
} else if(upload.status == UPLOAD_FILE_WRITE) {
|
} else if((upload.status == UPLOAD_FILE_WRITE) && (com_error == false)){//if com error no need to send more data to serial
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||||
if (linewrote == false){
|
//upload.buf, upload.currentSize
|
||||||
Serial.write("M117 one line yes\n");
|
for (int pos = 0; pos < upload.currentSize;pos++) //parse full post data
|
||||||
Serial.flush();
|
{
|
||||||
linewrote = true;
|
Serial.write(upload.buf[pos]); //write char by char
|
||||||
}
|
buffer_line[buffer_size] = upload.buf[pos]; //copy current char to buffer if need to resend
|
||||||
|
buffer_size++;
|
||||||
//Serial.write(upload.buf, upload.currentSize);
|
if (upload.buf[pos] == '\n') //end of line
|
||||||
|
{
|
||||||
|
Serial.flush();//let's flush to wait the buffer is empty
|
||||||
|
//if resend use buffer
|
||||||
|
bool success = false;
|
||||||
|
//Question: do we need delay to get answer ?
|
||||||
|
//check NB_RETRY times if get no error when send line
|
||||||
|
for (int r = 0 ; r < NB_RETRY ; r++)
|
||||||
|
{
|
||||||
|
if(Serial.available()) { //look for answer
|
||||||
|
response = Serial.readString();
|
||||||
|
}
|
||||||
|
if (response.indexOf("resend") > -1){//we have error
|
||||||
|
//resend last line
|
||||||
|
Serial.write(buffer_line,buffer_size);
|
||||||
|
Serial.flush();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//we got it exit retry and continue send
|
||||||
|
success = true;
|
||||||
|
break; //for retry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!success){
|
||||||
|
//raise error
|
||||||
|
com_error = true;
|
||||||
|
}
|
||||||
|
//reset buffer for next command
|
||||||
|
buffer_size = 0;
|
||||||
|
}
|
||||||
|
if (buffer_size > 128) //raise error if overbuffer - command/line is not so big
|
||||||
|
{
|
||||||
|
//raise error
|
||||||
|
buffer_size = 0;
|
||||||
|
com_error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if(upload.status == UPLOAD_FILE_END) {
|
} else if(upload.status == UPLOAD_FILE_END) {
|
||||||
web_interface->blockserial = false;
|
web_interface->blockserial = false;
|
||||||
linewrote = false;
|
buffer_size=0;
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
Serial.println("M29\n");
|
||||||
Serial.println("M29\n");
|
Serial.flush();
|
||||||
delay (500);
|
if (com_error){
|
||||||
Serial.println("M117 SD upload done\n");
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
|
Serial.println("M117 SD upload failed");
|
||||||
|
Serial.flush();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
||||||
|
Serial.println("M117 SD upload done");
|
||||||
|
Serial.flush();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
com_error = true;
|
||||||
|
web_interface->blockserial = false;
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
|
buffer_size=0;
|
||||||
Serial.println("M29\n");
|
Serial.println("M29\n");
|
||||||
delay (500);
|
Serial.flush();
|
||||||
Serial.println("M117 SD upload failed");
|
Serial.println("M117 SD upload failed");
|
||||||
}
|
}
|
||||||
delay(0);
|
delay(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user