Skip to content

Commit

Permalink
Add output to help debug device state (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Mar 12, 2019
1 parent d55a1d4 commit be8be47
Showing 1 changed file with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
//
// Copyright (c) 2017 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

using System.Threading.Tasks;
using System.Diagnostics;

namespace nanoFramework.Tools.Debugger.Extensions
{
Expand All @@ -21,10 +21,16 @@ public static bool IsDeviceInInitializeState(this Engine debugEngine)
if (result != WireProtocol.Commands.DebuggingExecutionChangeConditions.State.Unknown)
{
// engine is in initialised state if it's not running a program or if the program execution is stopped (after having running one)
return ((result & (WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramExited | WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramRunning)) == WireProtocol.Commands.DebuggingExecutionChangeConditions.State.Initialize);
var filteredResult = result & (WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramExited | WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramRunning);

Debug.WriteLine($"Device state is: {filteredResult.OutputDeviceExecutionState()}.");

return (filteredResult == WireProtocol.Commands.DebuggingExecutionChangeConditions.State.Initialize);
}
else
{
Debug.WriteLine("Couldn't get device execution mode.");

return false;
}
}
Expand All @@ -40,7 +46,11 @@ public static bool IsDeviceInExitedState(this Engine debugEngine)

if (result != WireProtocol.Commands.DebuggingExecutionChangeConditions.State.Unknown)
{
return ((result & WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramExited) == WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramExited);
var filteredResult = result & WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramExited;

Debug.WriteLine($"Device state is: {filteredResult.OutputDeviceExecutionState()}.");

return (filteredResult == WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramExited);
}
else
{
Expand All @@ -59,13 +69,46 @@ public static bool IsDeviceInProgramRunningState(this Engine debugEngine)

if (result != WireProtocol.Commands.DebuggingExecutionChangeConditions.State.Unknown)
{
return ((result & WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramRunning) == WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramRunning);
var filteredResult = result & WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramRunning;

Debug.WriteLine($"Device state is: {filteredResult.OutputDeviceExecutionState()}.");

return (filteredResult == WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramRunning);
}
else
{
return false;
}
}

internal static string OutputDeviceExecutionState(this WireProtocol.Commands.DebuggingExecutionChangeConditions.State state)
{
if (state == WireProtocol.Commands.DebuggingExecutionChangeConditions.State.Unknown)
{
return "unknown";
}
else if (state == WireProtocol.Commands.DebuggingExecutionChangeConditions.State.Initialize)
{
return "initialized";
}
else if ((state & WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramRunning) == WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramRunning)
{
if ((state & WireProtocol.Commands.DebuggingExecutionChangeConditions.State.Stopped) == WireProtocol.Commands.DebuggingExecutionChangeConditions.State.Stopped)
{
return "running a program **BUT** execution is stopped";
}
else
{
return "running a program ";
}
}
else if ((state & WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramExited) == WireProtocol.Commands.DebuggingExecutionChangeConditions.State.ProgramExited)
{
return "idle after exiting a program execution or start-up failure";
}

// should NEVER get here
return "";
}
}
}

0 comments on commit be8be47

Please sign in to comment.