MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / FillBuffer

Method FillBuffer

src/SBC/SbcInterface.cpp:1495–1602  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1493}
1494
1495bool SbcInterface::FillBuffer(GCodeBuffer &gb) noexcept
1496{
1497 if (gb.IsInvalidated() || gb.IsMacroFileClosed() || gb.IsMessageAcknowledged() ||
1498 gb.IsAbortRequested() || (reportPause && gb.IsFileChannel()) ||
1499 (gb.LatestMachineState().waitingForAcknowledgement && gb.IsMessagePromptPending()))
1500 {
1501 // Don't process codes that are supposed to be suspended...
1502 return false;
1503 }
1504
1505 bool gotCommand = false;
1506 {
1507 //TODO can we take the lock inside the loop body instead, if we re-read readPointer and writePointer after taking it?
1508 TaskCriticalSectionLocker locker;
1509 if (rxPointer != txPointer || txEnd != 0)
1510 {
1511 bool updateRxPointer = true;
1512 uint16_t readPointer = rxPointer;
1513 do
1514 {
1515 BufferedCodeHeader *bufHeader = reinterpret_cast<BufferedCodeHeader*>(codeBuffer + readPointer);
1516 readPointer += sizeof(BufferedCodeHeader);
1517 const CodeHeader *codeHeader = reinterpret_cast<const CodeHeader*>(codeBuffer + readPointer);
1518 readPointer += bufHeader->length;
1519
1520 RRF_ASSERT(bufHeader->length > 0);
1521 RRF_ASSERT(readPointer <= SpiCodeBufferSize);
1522
1523 if (bufHeader->isPending)
1524 {
1525 if (gb.GetChannel().RawValue() == codeHeader->channel)
1526 {
1527#ifdef TRACK_FILE_CODES
1528 if (gb.IsFileChannel() && gb.GetCommandLetter() != 'Q')
1529 {
1530 fileMacrosRunning -= fileMacrosClosing;
1531 fileMacrosClosing = 0;
1532 if (fileCodesRead > fileCodesHandled + fileMacrosRunning)
1533 {
1534 // Note that we cannot use MessageF here because the task scheduler is suspended
1535 OutputBuffer *buf;
1536 if (OutputBuffer::Allocate(buf))
1537 {
1538 String<StringLength100> codeString;
1539 gb.PrintCommand(codeString.GetRef());
1540 buf->printf("Code %s did not return a code result, delta %d, running macros %d\n", codeString.c_str(), fileCodesRead - fileCodesHandled - fileMacrosRunning, fileMacrosRunning);
1541 gcodeReply.Push(buf, WarningMessage);
1542 }
1543 fileCodesRead = fileCodesHandled - fileMacrosRunning;
1544 }
1545 fileCodesRead++;
1546 }
1547#endif
1548
1549 // Process the next binary G-code
1550 gb.PutBinary(reinterpret_cast<const uint32_t *>(codeHeader), bufHeader->length / sizeof(uint32_t));
1551 bufHeader->isPending = false;
1552

Callers

nothing calls this directly

Calls 6

PushMethod · 0.80
PutBinaryMethod · 0.80
GetCommandLetterMethod · 0.45
PrintCommandMethod · 0.45
printfMethod · 0.45
DecodeCommandMethod · 0.45

Tested by

no test coverage detected