Skip to content

Commit

Permalink
Minor bug fix
Browse files Browse the repository at this point in the history
Bug fix: Sometimes the object model wasn't fully updated after a disconnect
  • Loading branch information
chrishamm committed Nov 7, 2020
1 parent 5ddefd4 commit a278937
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
1 change: 1 addition & 0 deletions WHATS_NEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Bug fixes:
- When the heaters contained null items, no config-override.g could be writen
- When the move compensation type was set to none, the heightmap file was not reset
- Starting macro files could cause out-of-order execution and stack underruns
- Sometimes the object model wasn't fully updated after a disconnect

Version 3.2.0-b2
================
Expand Down
30 changes: 12 additions & 18 deletions src/DuetControlServer/Model/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public static class Updater
/// </summary>
private static int _jsonLength = 0;

/// <summary>
/// Whether the sequence numbers may be cleared and the full OM is supposed to be queried again
/// </summary>
private static volatile bool _reloadObjectModel;

/// <summary>
/// Wait for the model to be fully updated from RepRapFirmware
/// </summary>
Expand Down Expand Up @@ -160,6 +165,12 @@ public static async Task Run()
}

// Request object model updates wherever needed
if (_reloadObjectModel)
{
_lastSeqs.Clear();
_reloadObjectModel = false;
}

bool objectModelSynchronized = true;
foreach (JsonProperty seqProperty in result.GetProperty("seqs").EnumerateObject())
{
Expand Down Expand Up @@ -195,7 +206,6 @@ public static async Task Run()
else
{
// Specific request - still updating the OM
bool outputBoards = false;
using (await Provider.AccessReadWriteAsync())
{
string keyName = key.GetString();
Expand All @@ -206,11 +216,6 @@ public static async Task Run()
{
_logger.Trace("Key JSON: {0}", Encoding.UTF8.GetString(_json, 0, _jsonLength));
}

if (keyName == "boards" && Provider.Get.Boards.Count > 0 && string.IsNullOrEmpty(Provider.Get.Boards[0].IapFileNameSBC))
{
outputBoards = true;
}
}
else
{
Expand All @@ -222,12 +227,6 @@ public static async Task Run()
Provider.Get.State.Status = MachineStatus.Updating;
}
}

if (outputBoards)
{
#warning This should never be triggered but both dc42 and I had an issue (at least once) where boards[0].*File was not set
await Provider.Output(MessageType.Warning, $"Received malformed boards key: '{Encoding.UTF8.GetString(_json, 0, _jsonLength)}'");
}
}
}
else
Expand Down Expand Up @@ -356,12 +355,7 @@ public static void ConnectionLost(string errorMessage = null)
Provider.Get.State.Status = MachineStatus.Off;
}
}

using (_lock.Lock(Program.CancellationToken))
{
// Query the full object model when a connection can be established again
_lastSeqs.Clear();
}
_reloadObjectModel = true;

if (!string.IsNullOrEmpty(errorMessage))
{
Expand Down

0 comments on commit a278937

Please sign in to comment.