Skip to content

Commit

Permalink
Improve update device config
Browse files Browse the repository at this point in the history
Signed-off-by: josesimoes <jose.simoes@eclo.solutions>
  • Loading branch information
josesimoes committed Mar 13, 2020
1 parent 08683bc commit 139e3e3
Showing 1 changed file with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3575,11 +3575,13 @@ public bool UpdateDeviceConfiguration(DeviceConfiguration configuration)
// counters to manage the chunked update process
int count = configurationSerialized.Length;
int position = 0;
int attemptCount = 1;

// flag to signal the update operation success/failure
bool updateFailed = true;

while (count > 0)
while (count > 0 &&
attemptCount >= 0)
{
Commands.Monitor_UpdateConfiguration cmd = new Commands.Monitor_UpdateConfiguration
{
Expand Down Expand Up @@ -3623,11 +3625,12 @@ public bool UpdateDeviceConfiguration(DeviceConfiguration configuration)
// update was OK, switch flag
updateFailed = false;
}

attemptCount = 1;
}
else
{
// failure, bail out
break;
attemptCount--;
}
}

Expand Down Expand Up @@ -3737,11 +3740,13 @@ public bool UpdateDeviceConfiguration<T>(T configuration, uint blockIndex)
// counters to manage the chunked update process
int count = configurationSerialized.Length;
int position = 0;
int attemptCount = 1;

// flag to signal the update operation success/failure
bool updateFailed = true;

while (count > 0)
while ( count > 0 &&
attemptCount >= 0)
{
Commands.Monitor_UpdateConfiguration cmd = new Commands.Monitor_UpdateConfiguration
{
Expand All @@ -3751,6 +3756,19 @@ public bool UpdateDeviceConfiguration<T>(T configuration, uint blockIndex)
// get packet length, either the maximum allowed size or whatever is still available to TX
int packetLength = Math.Min(GetPacketMaxLength(cmd), count);

// check if this is the last chunk
if (count <= packetLength &&
packetLength <= GetPacketMaxLength(cmd))
{
// yes, signal that by setting the Done field
cmd.Done = 1;
}
else
{
// no, more data is coming after this one
cmd.Done = 0;
}

cmd.PrepareForSend(configurationSerialized, packetLength, position);

IncomingMessage reply = PerformSyncRequest(Commands.c_Monitor_UpdateConfiguration, 0, cmd);
Expand All @@ -3772,6 +3790,12 @@ public bool UpdateDeviceConfiguration<T>(T configuration, uint blockIndex)
// update was OK, switch flag
updateFailed = false;
}

attemptCount = 1;
}
else
{
attemptCount--;
}
}

Expand Down

0 comments on commit 139e3e3

Please sign in to comment.