Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on DeploymentExecuteIncrementalAsync #27

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/USB Test App WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private async void DeployTestButton_Click(object sender, RoutedEventArgs e)

try
{
// add mscorlib
string assemblyPath = @"..\..\..\packages\nanoFramework.CoreLibrary.1.0.0-preview020\lib\mscorlib.pe";

using (FileStream fs = File.Open(assemblyPath, FileMode.Open, FileAccess.Read))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<PackageId>nanoFramework.Tools.Debugger.Net</PackageId>
<PackageVersion>0.4.0-preview012</PackageVersion>
<PackageVersion>0.4.0-preview013</PackageVersion>
<Description>This .NET library provides a debug client for nanoFramework devices using USB or Serial connection to a board.</Description>
<Authors>nanoFramework project contributors</Authors>
<Title>nanoFramework debug library for .NET</Title>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Copyright (c) 2017 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

using nanoFramework.Tools.Debugger.WireProtocol;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace nanoFramework.Tools.Debugger.Extensions
{
public static class DeploymentSectorExtensions
{
public static List<DeploymentBlock> ToDeploymentBlockList(this List<DeploymentSector> value)
{
List<DeploymentBlock> blocks = new List<DeploymentBlock>();

foreach(DeploymentSector sector in value)
{
blocks.AddRange(sector.Blocks);
}

return blocks;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright (c) 2017 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

using nanoFramework.Tools.Debugger.WireProtocol;
using System.Collections.Generic;
using System.Threading.Tasks;
using static nanoFramework.Tools.Debugger.WireProtocol.Commands.Monitor_FlashSectorMap;

namespace nanoFramework.Tools.Debugger.Extensions
{
public static class FlashSectorDataExtensions
{
/// <summary>
/// Convert a <see cref="FlashSectorData"/> into a <see cref="DeploymentSector"/>
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static DeploymentSector ToDeploymentSector(this FlashSectorData value)
{
// build a DeploymentSector from a FlashSectorData

List<DeploymentBlock> blocks = new List<DeploymentBlock>();

for (int i = 0; i < value.m_NumBlocks; i++)
{
blocks.Add(new DeploymentBlock((int)value.m_StartAddress + (i * (int)value.m_BytesPerBlock), (int)value.m_BytesPerBlock));
}

return new DeploymentSector(blocks);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// Copyright (c) 2017 The nanoFramework project contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//

using System;

namespace nanoFramework.Tools.Debugger.WireProtocol
{
public class DeploymentBlock
{
/// <summary>
/// Start address of block
/// </summary>
public int StartAddress { get; }

/// <summary>
/// Block size
/// </summary>
public int Size { get; }

/// <summary>
/// Data to deploy to the device
/// </summary>
public byte[] DeploymentData { get { return _deploymentData; } }
private byte[] _deploymentData;

/// <summary>
/// Available space in this block
/// </summary>
public int AvailableSpace
{
get
{
return Size - DeploymentData.Length;
}
}

/// <summary>
/// Creates a new <see cref="DeploymentBlock"/> starting at <paramref name="startAddress"/> with <paramref name="size"/> size.
/// </summary>
/// <param name="startAddress">Start address of the block.</param>
/// <param name="size">Size of the block.</param>
public DeploymentBlock(int startAddress, int size)
{
// empty deploymentdata
_deploymentData = new byte[0];

StartAddress = startAddress;
Size = size;
}

internal void AddDeploymentData(byte[] buffer)
{
// resize deployment data array
int previousLenght = _deploymentData.Length;
Array.Resize(ref _deploymentData, previousLenght + buffer.Length);

Array.Copy(buffer, 0, _deploymentData, previousLenght, buffer.Length);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// Copyright (c) 2017 The nanoFramework project contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//

using System;
using System.Collections.Generic;
using System.Linq;

namespace nanoFramework.Tools.Debugger.WireProtocol
{
public class DeploymentSector
{
/// <summary>
/// Start address of sector
/// </summary>
public int StartAddress { get { return Blocks.First().StartAddress; } }

/// <summary>
/// Number of blocks in this sector
/// </summary>
public int NumBlocks { get { return Blocks.Count; } }

/// <summary>
/// Bytes per block in this sector
/// </summary>
public int BytesPerBlock { get { return Blocks.First().Size; } }

public int Size
{
get
{
return Blocks.Sum(b => b.Size);
}
}


public List<DeploymentBlock> Blocks { get; internal set; }

public byte[] DeploymentData
{

set
{
int remainingBytes = value.Length;
int currentPosition = 0;

// find first block with available space
while (remainingBytes > 0)
{
var block = Blocks.First(b => b.AvailableSpace > 0);
int currentDataSize = block.DeploymentData.Length;

int bytesToCopy = Math.Min(block.AvailableSpace, remainingBytes);

byte[] tempBuffer = new byte[bytesToCopy];

Array.Copy(value, currentPosition, tempBuffer, 0, bytesToCopy);
block.AddDeploymentData(tempBuffer);

remainingBytes -= bytesToCopy;
currentPosition += bytesToCopy;
}

}
}

/// <summary>
/// Available space in this sector
/// </summary>
public int AvailableSpace
{
get
{
int sum = 0;

Blocks.Select(b => sum += b.Size - b.DeploymentData.Length).ToList();

return sum;
}
}


public DeploymentSector(List<DeploymentBlock> blocks)
{
Blocks = blocks;
}
}
}
Loading