* Get all commands waiting on the serial port and queue them. * Exit when the buffer is full or when no more characters are * left on the serial port. */
| 410 | * left on the serial port. |
| 411 | */ |
| 412 | void GCodeQueue::get_serial_commands() { |
| 413 | #if ENABLED(BINARY_FILE_TRANSFER) |
| 414 | if (card.flag.binary_mode) { |
| 415 | /** |
| 416 | * For binary stream file transfer, use serial_line_buffer as the working |
| 417 | * receive buffer (which limits the packet size to MAX_CMD_SIZE). |
| 418 | * The receive buffer also limits the packet size for reliable transmission. |
| 419 | */ |
| 420 | binaryStream[card.transfer_port_index.index].receive(serial_state[card.transfer_port_index.index].line_buffer); |
| 421 | return; |
| 422 | } |
| 423 | #endif |
| 424 | |
| 425 | // If the command buffer is empty for too long, |
| 426 | // send "wait" to indicate Marlin is still waiting. |
| 427 | #if NO_TIMEOUTS > 0 |
| 428 | const millis_t ms = millis(); |
| 429 | if (ring_buffer.empty() && !any_serial_data_available() && ELAPSED(ms, last_command_time, NO_TIMEOUTS)) { |
| 430 | SERIAL_ECHOLNPGM(STR_WAIT); |
| 431 | last_command_time = ms; |
| 432 | } |
| 433 | #endif |
| 434 | |
| 435 | // Loop while serial characters are incoming and the queue is not full |
| 436 | for (bool hadData = true; hadData;) { |
| 437 | // Unless a serial port has data, this will exit on next iteration |
| 438 | hadData = false; |
| 439 | |
| 440 | for (uint8_t p = 0; p < NUM_SERIAL; ++p) { |
| 441 | // Check if the queue is full and exit if it is. |
| 442 | if (ring_buffer.full()) return; |
| 443 | |
| 444 | // No data for this port ? Skip it |
| 445 | if (!serial_data_available(p)) continue; |
| 446 | |
| 447 | // Ok, we have some data to process, let's make progress here |
| 448 | hadData = true; |
| 449 | |
| 450 | const int c = read_serial(p); |
| 451 | if (c < 0) { |
| 452 | // This should never happen, let's log it |
| 453 | PORT_REDIRECT(SERIAL_PORTMASK(p)); // Reply to the serial port that sent the command |
| 454 | // Crash here to get more information why it failed |
| 455 | BUG_ON("SP available but read -1"); |
| 456 | SERIAL_ERROR_MSG(STR_ERR_SERIAL_MISMATCH); |
| 457 | SERIAL_FLUSH(); |
| 458 | continue; |
| 459 | } |
| 460 | |
| 461 | const char serial_char = (char)c; |
| 462 | SerialState &serial = serial_state[p]; |
| 463 | |
| 464 | if (ISEOL(serial_char)) { |
| 465 | |
| 466 | // Reset our state, continue if the line was empty |
| 467 | if (process_line_done(serial.input_state, serial.line_buffer, serial.count)) |
| 468 | continue; |
| 469 |
nothing calls this directly
no test coverage detected