@@ -101,9 +101,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length
101
101
102
102
103
103
extern bool deleteRecursive (String path);
104
- extern void CloseSerialUpload (bool iserror, String & filename);
105
- extern bool sendLine2Serial (String & line);
106
-
104
+ extern void CloseSerialUpload (bool iserror, String & filename, int32_t linenb );
105
+ extern bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb );
106
+ extern bool purge_serial ();
107
107
108
108
const uint8_t PAGE_404 [] PROGMEM = " <HTML>\n <HEAD>\n <title>Redirecting...</title> \n </HEAD>\n <BODY>\n <CENTER>Unknown page : $QUERY$- you will be redirected...\n <BR><BR>\n if not redirected, <a href='http://$WEB_ADDRESS$'>click here</a>\n <BR><BR>\n <PROGRESS name='prg' id='prg'></PROGRESS>\n\n <script>\n var i = 0; \n var x = document.getElementById(\" prg\" ); \n x.max=5; \n var interval=setInterval(function(){\n i=i+1; \n var x = document.getElementById(\" prg\" ); \n x.value=i; \n if (i>5) \n {\n clearInterval(interval);\n window.location.href='/';\n }\n },1000);\n </script>\n </CENTER>\n </BODY>\n </HTML>\n\n " ;
109
109
const uint8_t PAGE_CAPTIVE [] PROGMEM = " <HTML>\n <HEAD>\n <title>Captive Portal</title> \n </HEAD>\n <BODY>\n <CENTER>Captive Portal page : $QUERY$- you will be redirected...\n <BR><BR>\n if not redirected, <a href='http://$WEB_ADDRESS$'>click here</a>\n <BR><BR>\n <PROGRESS name='prg' id='prg'></PROGRESS>\n\n <script>\n var i = 0; \n var x = document.getElementById(\" prg\" ); \n x.max=5; \n var interval=setInterval(function(){\n i=i+1; \n var x = document.getElementById(\" prg\" ); \n x.value=i; \n if (i>5) \n {\n clearInterval(interval);\n window.location.href='/';\n }\n },1000);\n </script>\n </CENTER>\n </BODY>\n </HTML>\n\n " ;
@@ -559,7 +559,6 @@ void SPIFFSFileupload()
559
559
if (upload.status == UPLOAD_FILE_START) {
560
560
String upload_filename = upload.filename ;
561
561
String sizeargname = upload_filename + " S" ;
562
- if (web_interface->web_server .hasArg (" plain" ) ) Serial.println (" Yes" );
563
562
if (upload_filename[0 ] != ' /' ) filename = " /" + upload_filename;
564
563
else filename = upload.filename ;
565
564
// according User or Admin the root is different as user is isolate to /user when admin has full access
@@ -1152,6 +1151,7 @@ void handle_serial_SDFileList()
1152
1151
// SD file upload by serial
1153
1152
void SDFile_serial_upload ()
1154
1153
{
1154
+ static int32_t lineNb =-1 ;
1155
1155
static String current_line;
1156
1156
static bool is_comment = false ;
1157
1157
static String current_filename;
@@ -1174,93 +1174,70 @@ void SDFile_serial_upload()
1174
1174
// Upload start
1175
1175
// **************
1176
1176
if (upload.status == UPLOAD_FILE_START) {
1177
+ LOG (" Upload Start\r\n " )
1178
+ String command = " M29" ;
1179
+ String resetcmd = " M110 N0" ;
1180
+ if (CONFIG::GetFirmwareTarget () == SMOOTHIEWARE)resetcmd = " N0 M110" ;
1181
+ lineNb=1 ;
1182
+ // close any ongoing upload and get current line number
1183
+ if (!sendLine2Serial (command,1 , &lineNb)){
1184
+ // it can failed for repetier
1185
+ if ( ( CONFIG::GetFirmwareTarget () == REPETIER4DV) || (CONFIG::GetFirmwareTarget () == REPETIER) ) {
1186
+ if (!sendLine2Serial (command,-1 , NULL )){
1187
+ LOG (" Start Upload failed" )
1188
+ web_interface->_upload_status = UPLOAD_STATUS_FAILED;
1189
+ return ;
1190
+ }
1191
+ } else {
1192
+ LOG (" Start Upload failed" )
1193
+ web_interface->_upload_status = UPLOAD_STATUS_FAILED;
1194
+ return ;
1195
+ }
1196
+ }
1197
+ // Reset line numbering
1198
+ if (!sendLine2Serial (resetcmd,-1 , NULL )){
1199
+ LOG (" Reset Numbering failed" )
1200
+ web_interface->_upload_status = UPLOAD_STATUS_FAILED;
1201
+ return ;
1202
+ }
1203
+ lineNb=1 ;
1177
1204
// need to lock serial out to avoid garbage in file
1178
1205
(web_interface->blockserial ) = true ;
1179
1206
current_line =" " ;
1180
- is_comment = false ;
1181
- String response ;
1182
- web_interface-> _upload_status = UPLOAD_STATUS_ONGOING ;
1207
+ current_filename = upload. filename ;
1208
+ is_comment = false ;
1209
+ String response ;
1183
1210
ESPCOM::println (F (" Uploading..." ), PRINTER_PIPE);
1211
+ // Clear all serial
1184
1212
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
1185
- LOG (" Clear Serial\r\n " );
1186
- if (ESPCOM::available (DEFAULT_PRINTER_PIPE)) {
1187
- ESPCOM::bridge ();
1188
- CONFIG::wait (1 );
1189
- }
1190
- // command to pritnter to start print
1191
- String command = " M28 " + upload.filename ;
1192
- LOG (command);
1193
- LOG (" \r\n " );
1194
- ESPCOM::println (command, DEFAULT_PRINTER_PIPE);
1195
- ESPCOM::flush (DEFAULT_PRINTER_PIPE);
1196
- current_filename = upload.filename ;
1197
- CONFIG::wait (500 );
1198
- uint32_t timeout = millis ();
1199
- bool done = false ;
1200
- while (!done) { // time out is 2000ms
1201
- CONFIG::wait (0 );
1202
- // if there is something in serial buffer
1203
- size_t len = ESPCOM::available (DEFAULT_PRINTER_PIPE);
1204
- // get size of buffer
1205
- if (len > 0 ) {
1206
- CONFIG::wait (0 );
1207
- uint8_t * sbuf = (uint8_t *)malloc (len+1 );
1208
- if (!sbuf){
1209
- ESPCOM::println (F (" SD upload rejected" ), PRINTER_PIPE);
1210
- LOG (" SD upload rejected\r\n " );
1211
- LOG (" Need to stop" );
1212
- #if defined ( ARDUINO_ARCH_ESP8266)
1213
- web_interface->web_server .client ().stopAll ();
1214
- #else
1215
- web_interface->web_server .client ().stop ();
1216
- #endif
1217
- return ;
1218
- }
1219
- // read buffer
1220
- ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len);
1221
- // convert buffer to zero end array
1222
- sbuf[len] = ' \0 ' ;
1223
- // use string because easier to handle
1224
- response = (const char *) sbuf;
1225
- LOG (response);
1226
- // if there is a wait it means purge is done
1227
- if (response.indexOf (" wait" ) > -1 ) {
1228
- LOG (" Exit start writing\r\n " );
1229
- done = true ;
1230
- free (sbuf);
1231
- break ;
1232
- }
1233
- // it is first command if it is failed no need to continue
1234
- // and resend command won't help
1235
- if (response.indexOf (" Resend" ) > -1 || response.indexOf (" failed" ) > -1 ) {
1236
- web_interface->blockserial = false ;
1237
- LOG (" Error start writing\r\n " );
1238
- web_interface->_upload_status = UPLOAD_STATUS_FAILED;
1239
- #if defined ( ARDUINO_ARCH_ESP8266)
1240
- web_interface->web_server .client ().stopAll ();
1241
- #else
1242
- web_interface->web_server .client ().stop ();
1243
- #endif
1244
- free (sbuf);
1245
- return ;
1246
- }
1247
- free (sbuf);
1248
- }
1249
- if ( (millis () - timeout) > SERIAL_CHECK_TIMEOUT) {
1250
- done = true ;
1251
- }
1213
+ purge_serial ();
1214
+ // besure nothing left again
1215
+ purge_serial ();
1216
+ command = " M28 " + upload.filename ;
1217
+ // send start upload
1218
+ // no correction allowed because it means reset numbering was failed
1219
+ if (sendLine2Serial (command, lineNb, NULL )){
1220
+ CONFIG::wait (1200 );
1221
+ // additional purge, in case it is slow to answer
1222
+ purge_serial ();
1223
+ web_interface->_upload_status = UPLOAD_STATUS_ONGOING;
1224
+ LOG (" Creation Ok\r\n " )
1225
+
1226
+ } else {
1227
+ web_interface->_upload_status = UPLOAD_STATUS_FAILED;
1228
+ LOG (" Creation failed\r\n " );
1252
1229
}
1253
1230
// Upload write
1254
1231
// **************
1255
1232
// upload is on going with data coming by 2K blocks
1256
1233
} else if (upload.status == UPLOAD_FILE_WRITE) { // if com error no need to send more data to serial
1257
- web_interface->_upload_status = UPLOAD_STATUS_ONGOING;
1234
+ if ( web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
1258
1235
for (int pos = 0 ; pos < upload.currentSize ; pos++) { // parse full post data
1259
1236
// feed watchdog
1260
1237
CONFIG::wait (0 );
1261
1238
// it is a comment
1262
1239
if (upload.buf [pos] == ' ;' ) {
1263
- LOG (" Comment\n " )
1240
+ LOG (" Comment\r\ n " )
1264
1241
is_comment = true ;
1265
1242
}
1266
1243
// it is an end line
@@ -1271,10 +1248,11 @@ void SDFile_serial_upload()
1271
1248
if (current_line.length () < 126 ) {
1272
1249
// do we have something in buffer ?
1273
1250
if (current_line.length () > 0 ) {
1274
- current_line += " \r\n " ;
1275
- if (!sendLine2Serial (current_line) ) {
1251
+ lineNb++;
1252
+ if (!sendLine2Serial (current_line, lineNb, NULL ) ) {
1253
+ // fup.println("[Log]Write Error");
1276
1254
LOG (" Error over buffer\n " )
1277
- CloseSerialUpload (true , current_filename);
1255
+ CloseSerialUpload (true , current_filename,lineNb );
1278
1256
#if defined ( ARDUINO_ARCH_ESP8266)
1279
1257
web_interface->web_server .client ().stopAll ();
1280
1258
#else
@@ -1291,7 +1269,8 @@ void SDFile_serial_upload()
1291
1269
} else {
1292
1270
// error buffer overload
1293
1271
LOG (" Error over buffer\n " )
1294
- CloseSerialUpload (true , current_filename);
1272
+ lineNb++;
1273
+ CloseSerialUpload (true , current_filename, lineNb);
1295
1274
#if defined ( ARDUINO_ARCH_ESP8266)
1296
1275
web_interface->web_server .client ().stopAll ();
1297
1276
#else
@@ -1304,7 +1283,8 @@ void SDFile_serial_upload()
1304
1283
current_line += char (upload.buf [pos]); // copy current char to buffer to send/resend
1305
1284
} else {
1306
1285
LOG (" Error over buffer\n " )
1307
- CloseSerialUpload (true , current_filename);
1286
+ lineNb++;
1287
+ CloseSerialUpload (true , current_filename, lineNb);
1308
1288
#if defined ( ARDUINO_ARCH_ESP8266)
1309
1289
web_interface->web_server .client ().stopAll ();
1310
1290
#else
@@ -1314,15 +1294,28 @@ void SDFile_serial_upload()
1314
1294
}
1315
1295
}
1316
1296
}
1297
+ } else {
1298
+ LOG (" Error upload\n " )
1299
+ web_interface->_upload_status = UPLOAD_STATUS_FAILED;
1300
+ lineNb++;
1301
+ CloseSerialUpload (true , current_filename, lineNb);
1302
+ #if defined ( ARDUINO_ARCH_ESP8266)
1303
+ web_interface->web_server .client ().stopAll ();
1304
+ #else
1305
+ web_interface->web_server .client ().stop ();
1306
+ #endif
1307
+ return ;
1308
+ }
1317
1309
// Upload end
1318
1310
// **************
1319
- } else if (upload.status == UPLOAD_FILE_END) {
1311
+ } else if (upload.status == UPLOAD_FILE_END && web_interface-> _upload_status == UPLOAD_STATUS_ONGOING ) {
1320
1312
// if last part does not have '\n'
1321
1313
if (current_line.length () > 0 ) {
1322
- current_line += " \r\n " ;
1323
- if (!sendLine2Serial (current_line) ) {
1314
+ lineNb++ ;
1315
+ if (!sendLine2Serial (current_line, lineNb, NULL ) ) {
1324
1316
LOG (" Error sending buffer\n " )
1325
- CloseSerialUpload (true , current_filename);
1317
+ lineNb++;
1318
+ CloseSerialUpload (true , current_filename, lineNb);
1326
1319
#if defined ( ARDUINO_ARCH_ESP8266)
1327
1320
web_interface->web_server .client ().stopAll ();
1328
1321
#else
@@ -1332,12 +1325,14 @@ void SDFile_serial_upload()
1332
1325
}
1333
1326
}
1334
1327
LOG (" Upload finished " );
1335
- CloseSerialUpload (false , current_filename);
1328
+ lineNb++;
1329
+ CloseSerialUpload (false , current_filename, lineNb);
1336
1330
// Upload cancelled
1337
1331
// **************
1338
1332
} else { // UPLOAD_FILE_ABORTED
1339
1333
LOG (" Error, Something happened\r\n " );
1340
- CloseSerialUpload (true , current_filename);
1334
+ lineNb++;
1335
+ CloseSerialUpload (true , current_filename, lineNb);
1341
1336
#if defined ( ARDUINO_ARCH_ESP8266)
1342
1337
web_interface->web_server .client ().stopAll ();
1343
1338
#else
0 commit comments