@@ -1217,38 +1217,39 @@ bool COMMAND::execute_command(int cmd,String cmd_params, tpipe output, level_aut
1217
1217
if (currentfile) {// if file open success
1218
1218
// flush to be sure send buffer is empty
1219
1219
ESP_SERIAL_OUT.flush ();
1220
- // read content
1221
- String currentline = currentfile.readString ();
1222
1220
// until no line in file
1223
- while (currentline.length () >0 ) {
1224
- int ESPpos = currentline.indexOf (" [ESP" );
1225
- if (ESPpos>-1 ) {
1226
- // is there the second part?
1227
- int ESPpos2 = currentline.indexOf (" ]" ,ESPpos);
1228
- if (ESPpos2>-1 ) {
1229
- // Split in command and parameters
1230
- String cmd_part1=currentline.substring (ESPpos+4 ,ESPpos2);
1231
- String cmd_part2=" " ;
1232
- // is there space for parameters?
1233
- if (ESPpos2<currentline.length ()) {
1234
- cmd_part2=currentline.substring (ESPpos2+1 );
1235
- }
1236
- // if command is a valid number then execute command
1237
- if (cmd_part1.toInt ()!=0 ) {
1238
- execute_command (cmd_part1.toInt (),cmd_part2,NO_PIPE);
1221
+ while (currentfile.available ()) {
1222
+ String currentline = currentfile.readStringUntil (' \n ' );
1223
+ currentline.replace (" \n " ," " );
1224
+ currentline.replace (" \r " ," " );
1225
+ if (currentline.length () > 0 ) {
1226
+ int ESPpos = currentline.indexOf (" [ESP" );
1227
+ if (ESPpos>-1 ) {
1228
+ // is there the second part?
1229
+ int ESPpos2 = currentline.indexOf (" ]" ,ESPpos);
1230
+ if (ESPpos2>-1 ) {
1231
+ // Split in command and parameters
1232
+ String cmd_part1=currentline.substring (ESPpos+4 ,ESPpos2);
1233
+ String cmd_part2=" " ;
1234
+ // is there space for parameters?
1235
+ if (ESPpos2<currentline.length ()) {
1236
+ cmd_part2=currentline.substring (ESPpos2+1 );
1237
+ }
1238
+ // if command is a valid number then execute command
1239
+ if (cmd_part1.toInt ()!=0 ) {
1240
+ execute_command (cmd_part1.toInt (),cmd_part2,NO_PIPE);
1241
+ }
1242
+ // if not is not a valid [ESPXXX] command ignore it
1239
1243
}
1240
- // if not is not a valid [ESPXXX] command ignore it
1244
+ } else {
1245
+ // send line to serial
1246
+ ESP_SERIAL_OUT.println (currentline);
1247
+ // flush to be sure send buffer is empty
1248
+ delay (0 );
1249
+ ESP_SERIAL_OUT.flush ();
1241
1250
}
1242
- } else {
1243
- // send line to serial
1244
- ESP_SERIAL_OUT.println (currentline);
1245
- // flush to be sure send buffer is empty
1246
- delay (0 );
1247
- ESP_SERIAL_OUT.flush ();
1251
+ delay (0 );
1248
1252
}
1249
- currentline=" " ;
1250
- // read next line if any
1251
- currentline = currentfile.readString ();
1252
1253
}
1253
1254
currentfile.close ();
1254
1255
BRIDGE::println (OK_CMD_MSG, output);
0 commit comments