Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/wil-extend-m111' into 3.3-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dc42 committed Mar 10, 2021
2 parents e4802d8 + b762535 commit a49bbb4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/GCodes/GCodeBuffer/BinaryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void BinaryParser::DecodeCommand() noexcept
{
if (gb.bufferState == GCodeBufferState::parsingGCode)
{
if (reprap.Debug(moduleGcodes))
if (reprap.GetDebugFlags(moduleGcodes).IsBitSet(gb.GetChannel().ToBaseType()))
{
String<MaxCodeBufferSize> buf;
AppendFullCommand(buf.GetRef());
Expand Down
2 changes: 1 addition & 1 deletion src/GCodes/GCodeBuffer/StringParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ bool StringParser::LineFinished()
{
const bool badChecksum = (hadChecksum && computedChecksum != declaredChecksum);
const bool missingChecksum = (checksumRequired && !hadChecksum && gb.LatestMachineState().GetPrevious() == nullptr);
if (reprap.Debug(moduleGcodes) && fileBeingWritten == nullptr)
if (reprap.GetDebugFlags(moduleGcodes).IsBitSet(gb.GetChannel().ToBaseType()) && fileBeingWritten == nullptr)
{
debugPrintf("%s%s: %s\n", gb.GetChannel().ToString(), ((badChecksum) ? "(bad-csum)" : (missingChecksum) ? "(no-csum)" : ""), gb.buffer);
}
Expand Down
55 changes: 39 additions & 16 deletions src/GCodes/GCodes2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1583,32 +1583,55 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
break;

case 111: // Debug level
if (gb.Seen('S'))
{
const bool dbv = (gb.GetIValue() != 0);
bool seen = false;
uint32_t flags = 0;
Module module = Module::noModule;
if (gb.Seen('S'))
{
flags = gb.GetUIValue();
if (flags != 0)
{
flags = 0xFFFFFFFF;
}
seen = true;
}
else if (gb.Seen('D'))
{
flags = gb.GetUIValue();
seen = true;
}
if (gb.Seen('P'))
{
reprap.SetDebug(static_cast<Module>(gb.GetIValue()), dbv);
reprap.PrintDebug(gb.GetResponseMessageType());
return true;
module = static_cast<Module>(gb.GetLimitedUIValue('P', Module::numModules));
seen = true;
}
if (dbv)
if (seen)
{
// Repetier Host sends M111 with various S parameters to enable echo and similar features, which used to turn on all out debugging.
// But it's not useful to enable all debugging anyway. So we no longer allow debugging to be enabled without a P parameter.
reply.copy("Use P parameter to specify which module to debug");
if (module != Module::noModule)
{
reprap.SetDebug(module, flags);
reprap.PrintDebug(gb.GetResponseMessageType());
return true;
}
else if (flags != 0)
{
// Repetier Host sends M111 with various S parameters to enable echo and similar features, which used to turn on all out debugging.
// But it's not useful to enable all debugging anyway. So we no longer allow debugging to be enabled without a P parameter.
reply.copy("Use P parameter to specify which module to debug");
}
else
{
// M111 S0 still clears all debugging
reprap.ClearDebug();
}
}
else
{
// M111 S0 still clears all debugging
reprap.ClearDebug();
reprap.PrintDebug(gb.GetResponseMessageType());
return true;
}
}
else
{
reprap.PrintDebug(gb.GetResponseMessageType());
return true;
}
break;

case 112: // Emergency stop - acted upon in Webserver, but also here in case it comes from USB etc.
Expand Down
25 changes: 11 additions & 14 deletions src/Platform/RepRap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ RepRap::RepRap() noexcept
networkSeq(0), scannerSeq(0), sensorsSeq(0), spindlesSeq(0), stateSeq(0), toolsSeq(0), volumesSeq(0),
toolList(nullptr), currentTool(nullptr), lastWarningMillis(0),
activeExtruders(0), activeToolHeaters(0), numToolsToReport(0),
ticksInSpinState(0), heatTaskIdleTicks(0), debug(0),
ticksInSpinState(0), heatTaskIdleTicks(0),
beepFrequency(0), beepDuration(0), beepTimer(0),
previousToolNumber(-1),
diagnosticsDestination(MessageType::NoDestinationMessage), justSentDiagnostics(false),
Expand All @@ -420,6 +420,7 @@ RepRap::RepRap() noexcept
// because a disconnected SBC interface can generate noise which may trigger interrupts and DMA
#endif
{
ClearDebug();
// Don't call constructors for other objects here
}

Expand Down Expand Up @@ -927,41 +928,37 @@ void RepRap::EmergencyStop() noexcept
platform->StopLogging();
}

void RepRap::SetDebug(Module m, bool enable) noexcept
void RepRap::SetDebug(Module m, uint32_t flags) noexcept
{
if (m < numModules)
{
if (enable)
{
debug |= (1u << m);
}
else
{
debug &= ~(1u << m);
}
debugMaps[m].SetFromRaw(flags);
}
}

void RepRap::ClearDebug() noexcept
{
debug = 0;
for (DebugFlags& dm : debugMaps)
{
dm.Clear();
}
}

void RepRap::PrintDebug(MessageType mt) noexcept
{
platform->Message((MessageType)(mt | PushFlag), "Debugging enabled for modules:");
for (size_t i = 0; i < numModules; i++)
{
if ((debug & (1u << i)) != 0)
if (debugMaps[i].IsNonEmpty())
{
platform->MessageF((MessageType)(mt | PushFlag), " %s(%u)", GetModuleName(i), i);
platform->MessageF((MessageType)(mt | PushFlag), " %s(%u - %#" PRIx32 ")", GetModuleName(i), i, debugMaps[i].GetRaw());
}
}

platform->Message((MessageType)(mt | PushFlag), "\nDebugging disabled for modules:");
for (size_t i = 0; i < numModules; i++)
{
if ((debug & (1u << i)) == 0)
if (debugMaps[i].IsEmpty())
{
platform->MessageF((MessageType)(mt | PushFlag), " %s(%u)", GetModuleName(i), i);
}
Expand Down
10 changes: 6 additions & 4 deletions src/Platform/RepRap.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct MessageBox
MessageBox() noexcept : active(false), seq(0) { }
};

typedef Bitmap<uint32_t> DebugFlags;

class RepRap INHERIT_OBJECT_MODEL
{
public:
Expand All @@ -68,8 +70,9 @@ class RepRap INHERIT_OBJECT_MODEL
void DeferredDiagnostics(MessageType mtype) noexcept { diagnosticsDestination = mtype; }
void Timing(MessageType mtype) noexcept;

bool Debug(Module module) const noexcept;
void SetDebug(Module m, bool enable) noexcept;
bool Debug(Module module) const noexcept { return debugMaps[module].IsNonEmpty(); }
DebugFlags GetDebugFlags(Module m) const noexcept { return debugMaps[m]; }
void SetDebug(Module m, uint32_t flags) noexcept;
void ClearDebug() noexcept;
void PrintDebug(MessageType mt) noexcept;
Module GetSpinningModule() const noexcept;
Expand Down Expand Up @@ -273,7 +276,7 @@ class RepRap INHERIT_OBJECT_MODEL
uint16_t heatTaskIdleTicks;
uint32_t fastLoop, slowLoop;

uint32_t debug;
DebugFlags debugMaps[Module::numModules];

String<RepRapPasswordLength> password;
String<MachineNameLength> myName;
Expand Down Expand Up @@ -306,7 +309,6 @@ class RepRap INHERIT_OBJECT_MODEL
// A single instance of the RepRap class contains all the others
extern RepRap reprap;

inline bool RepRap::Debug(Module m) const noexcept { return debug & (1u << m); }
inline Module RepRap::GetSpinningModule() const noexcept { return spinningModule; }

inline Tool* RepRap::GetCurrentTool() const noexcept { return currentTool; }
Expand Down

0 comments on commit a49bbb4

Please sign in to comment.