Skip to content

Commit

Permalink
Added multiple target frameworks to all CLI projects
Browse files Browse the repository at this point in the history
- Fixed Examples, CLI, TestScript Projects
- Fixed the documentation

#155 breaking
  • Loading branch information
tthiery committed Apr 22, 2021
1 parent 4ea75b8 commit 3da144d
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 184 deletions.
11 changes: 6 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/examples/SharpBrick.PoweredUp.Examples/bin/Debug/netcoreapp3.1/SharpBrick.PoweredUp.Examples.dll",
"program": "${workspaceFolder}/examples/SharpBrick.PoweredUp.Examples/bin/Debug/net5.0-windows10.0.19041.0/SharpBrick.PoweredUp.Examples.dll",
"args": [
"--trace"
"--TraceDebug",
"true"
],
"cwd": "${workspaceFolder}/examples/SharpBrick.PoweredUp.Examples",
"console": "integratedTerminal",
Expand All @@ -22,7 +23,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/SharpBrick.PoweredUp.Cli/bin/Debug/netcoreapp3.1/SharpBrick.PoweredUp.Cli.dll",
"program": "${workspaceFolder}/src/SharpBrick.PoweredUp.Cli/bin/Debug/net5.0-windows10.0.19041.0/SharpBrick.PoweredUp.Cli.dll",
"args": [
"device",
"list"
Expand All @@ -36,7 +37,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/SharpBrick.PoweredUp.Cli/bin/Debug/netcoreapp3.1/SharpBrick.PoweredUp.Cli.dll",
"program": "${workspaceFolder}/src/SharpBrick.PoweredUp.Cli/bin/Debug/net5.0-windows10.0.19041.0/SharpBrick.PoweredUp.Cli.dll",
"args": [
"device",
"dump-static-port",
Expand All @@ -52,7 +53,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/SharpBrick.PoweredUp.Cli/bin/Debug/netcoreapp3.1/SharpBrick.PoweredUp.Cli.dll",
"program": "${workspaceFolder}/src/SharpBrick.PoweredUp.Cli/bin/Debug/net5.0-windows10.0.19041.0/SharpBrick.PoweredUp.Cli.dll",
"args": [
"device",
"pretty-print",
Expand Down
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ SharpBrick.PoweredUp is a .NET implementation of the Bluetooth Low Energy Protoc
- **Virtual Port Creation**: Combine multiple devices of the same type into a virtual combined port. This allows synchronous access to multiple devices using the same message (e.g. using two motors for driving).
- **Deployment Model Verification**: The SDK includes a model builder and a verification method to ensure that the wired devies are correctly reflecting the expectations in the program.
- **Tools**: The `poweredup` CLI includes a device list feature, enumerating the metadata properties of the LEGO Wireless Protocol.
- **Support for multiple Bluetooth Stacks**: Use any of Microsoft WinRT, BlueGiga Bluetooth (Silicon's Lab BlueGiga-adapter (for example BLED112) and Xamarin using BLE.Plugin to talk to your Lego hubs.
- **Support for multiple Bluetooth Stacks**: Use either Microsoft WinRT, BlueGiga Bluetooth (Silicon's Lab BlueGiga-adapter, for example BLED112) or Xamarin using BLE.Plugin to talk to your Lego hubs.

# Examples

Additional to code fragments below, look into the `examples/SharpBrick.PoweredUp.Examples` project (15+ examples).

````csharp
using SharpBrick.PoweredUp;

using Microsoft.Extensions.DependencyInjection; // SharpBrick.PoweredUp uses the DI system
using Microsoft.Extensions.Logging; // SharpBrick.PoweredUp also logs stuff
````

## Discovering Hubs
Expand All @@ -37,7 +40,7 @@ using SharpBrick.PoweredUp;
var serviceProvider = new ServiceCollection()
.AddLogging()
.AddPoweredUp()
.AddWinRTBluetooth() // using WinRT Bluetooth on Windows (separate NuGet SharpBrick.PoweredUp.WinRT)
.AddWinRTBluetooth() // using WinRT Bluetooth on Windows (separate NuGet SharpBrick.PoweredUp.WinRT; others are available)
.BuildServiceProvider();

var host = serviceProvider.GetService<PoweredUpHost>();
Expand Down Expand Up @@ -192,10 +195,9 @@ using (var scope = serviceProvider.CreateScope()) // create a scoped DI containe
await motor.GotoPositionAsync(-45, 10, 100, PortOutputCommandSpecialSpeed.Brake);
}
````
## Connecting with a BlueGiga-Bluetooth-adapter

## Connecting with other Bluetooth Adapters

For details on using BlueGiga-adapter, also on Raspberry Pi or Ubuntu, see [here.](docs/bleadapters/BlueGigaBLED112.md)
- **BlueGiga Adapter**: Find more details in the [docs](docs/bleadapters/BlueGigaBLED112.md) about the needed configuration and the setup on Windows, Ubuntu or the Raspberry Pi.

# Command Line Experience

Expand All @@ -211,16 +213,22 @@ The `poweredup` command line utility intends to allow the inspection of LEGO Wir
````
- **Pretty Print Binary Dumps**: Help to convert a binary dump in a nice representation.

- **Use of other Bluetooth LE stack** (default is WinRT on Windows)
- **Use of other Bluetooth LE stack** By default the CLI tools assumes the usage of WinRT. If used on another operating system or with another Bluetooth Adapter on Windows, the Bluetooth Adapter needs to be specified. Adapter might need additional configuration, see their details documentation.

- For BlueGiga-adapter, also on Raspberry Pi or Ubuntu, see [here.](docs/bleadapters/BlueGigaBLED112.md)
````
poweredup device list --BluetoothAdapter BlueGigaBLE
````

## Installation Instruction

1. Install the [latest .NET](https://dotnet.microsoft.com/download) on your machine (e.g. .NET 5).
2. Install the `poweredup` dotnet utility using the following instruction
````
dotnet tool install -g SharpBrick.PoweredUp.Cli
// On Windows
dotnet tool install --framework net5.0-windows10.0.19041.0 -g SharpBrick.PoweredUp.Cli
// On Linux
dotnet tool install --framework net5.0 -g SharpBrick.PoweredUp.Cli
````
3. Start using the tool
````
Expand Down Expand Up @@ -269,9 +277,8 @@ DI Container Elements
- Bluetooth Adapter
- [X] .NET Core 3.1 (on Windows 10 using WinRT Bluetooth). Please use version v3.4.0 and consider upgrading to .NET 5
- [X] .NET 5 (on Windows 10 using WinRT Bluetooth) (⚠ v4.0 or later)
- [X] .NET 5 (on Windows 10 using BlueGiga-adapter) (⚠ v4.0 or later)
- [X] .NET 5 (on Raspberry Pi 3 or 4 using BlueGiga-adapter) (⚠ v4.0 or later)
- [X] .NET 5 (on Ubuntu 20.04 using BlueGiga-adapter) (⚠ v4.0 or later)
- [X] .NET 5 (on Windows 10 using BlueGiga Adapter) (⚠ v4.0 or later)
- [X] .NET 5 (on Linux using BlueGiga Adapter) (tested on Raspberry Pi 3, 4 and Ubuntu 20.04; ⚠ v4.0 or later)
- [ ] UWP (most likely December 2021; UWP currently does not support .NET Standard 2.1 and C# 8.0+)
- [ ] .NET Framework 4.8 (will never be supported; .NET Framework does not and will never support .NET Standard 2.1 and C# 8.0+)
- [X] Xamarin 5 (on Android using BLE.Plugin) (⚠ v4.0 or later)
Expand Down Expand Up @@ -358,7 +365,6 @@ DI Container Elements
## Resources

- [Lego Wireless Protocol Specification](https://lego.github.io/lego-ble-wireless-protocol-docs) ([GitHub](https://github.com/lego/lego-ble-wireless-protocol-docs))
- [BlueGiga BLE protcol](https://www.silabs.com/documents/public/reference-manuals/Bluetooth-LE-Software-API%20Reference-Manual-for-BLE-Version-1.10.pdf)

## Contribution

Expand Down
11 changes: 6 additions & 5 deletions docs/bleadapters/BlueGigaBLED112.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ On windows-systems you can debug or run from inside Visual Studio / your IDE wit
## Command Line Experience ##

````
poweredup device list --usebluegiga COM4 --tracebluegiga
poweredup device list --BluetoothAdapter BlueGigaBLE --COMPortName COM4 --TraceDebug true
````
``--usebluegiga`` is the parameter that tells the cli-tool to use the BleuGiga-implementation. It has to be followed by the name of the serial port to use.
`--BluetoothAdapter` switches the BluetoothAdapter to use BlueGigaBLE.
`--COMPortName` is the parameter that tells the cli-tool to use the given serial port.
Use the name of the serial port as described above; so replace `COM4` with COMx whatever x is used on your Windows-system or e.g. /dev/ttyACM0 for Linux-based OS.
`--tracebluegiga` is an optional parameter; when used the cli emits **a lot** of additional trace-information of the BleuGiga-implementation. Default: no additional trace.
`--TraceDebug` is an optional parameter; when used the cli emits **a lot** of additional trace-information of the BlueGiga-implementation. Default: no additional trace.

## Using / Building for Linux-based OS ##
At the time of this writing you've got to make sure that you don't include/depend on the SharpBrick.PoweredUp.WinRT-project, because this doesn't build for Linux-platforms. So change your project-dependencies accordingly.
Expand All @@ -71,7 +72,7 @@ The following instructions assume that you've got installed at least the .NET 5
- Change the mod of the executable (the file which is named like your project) to "executable" by using ``chmod +x (filename)`` on the Raspberry Pi
- Open a terminal-windows on the Pi and enter
- ``cd ~/powered-up``
- ``./SharpBrick.PoweredUp.Examples --usebluegiga /dev/ttyACM0``
- ``./SharpBrick.PoweredUp.Examples --BluetoothAdapter BlueGigaBLE --COMPortName /dev/ttyACM0``

### Build and run for Ubuntu 20.04 ###
- open a command prompt on your dev-machine (Windows)
Expand All @@ -81,7 +82,7 @@ The following instructions assume that you've got installed at least the .NET 5
- Change the mod of the executable (the file which is named like your project) to "executable" by using ``chmod +x (filename)`` on Ubuntu
- Open a terminal-windows on Ubuntu and enter
- ``cd ~/powered-up``
- ``./SharpBrick.PoweredUp.Examples --usebluegiga /dev/ttyACM0``
- ``./SharpBrick.PoweredUp.Examples --BluetoothAdapter BlueGigaBLE --COMPortName /dev/ttyACM0``
- In case you receive a permission-denied error for /dev/ttyACM0:
- sudo chmod +rw /dev/ttyACM0
- sudo chmod o+rw /dev/ttyACM0
Expand Down
60 changes: 8 additions & 52 deletions examples/SharpBrick.PoweredUp.Examples/BaseExample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SharpBrick.PoweredUp;
Expand All @@ -22,16 +23,17 @@ public virtual void Configure(IServiceCollection serviceCollection)
{
serviceCollection
.AddPoweredUp();



}

public async Task InitHostAndDiscoverAsync(bool enableTrace , string bluetoothStackPort="WINRT", bool enableTraceBlueGiga = false)
public async Task InitExampleAndDiscoverAsync(IServiceProvider serviceProvider, IConfiguration configuration)
{
InitHost(enableTrace, bluetoothStackPort, enableTraceBlueGiga);
ServiceProvider = serviceProvider;

Host = serviceProvider.GetService<PoweredUpHost>();

Log = serviceProvider.GetService<ILoggerFactory>().CreateLogger("Example");

Log = ServiceProvider.GetService<ILoggerFactory>().CreateLogger("Example");
var enableTrace = bool.TryParse(configuration["EnableTrace"], out var x) && x;

await DiscoverAsync(enableTrace);
}
Expand Down Expand Up @@ -73,51 +75,5 @@ public virtual Task DiscoverAsync(bool enableTrace)

return Task.CompletedTask;
}

public void InitHost(bool enableTrace, string bluetoothStackPort="WINRT", bool enableTraceBlueGiga=false)
{
var serviceCollection = new ServiceCollection()
// configure your favourite level of logging.
.AddLogging(builder =>
{
builder
.AddConsole();
if (enableTrace)
{
builder.AddFilter("SharpBrick.PoweredUp.Bluetooth.BluetoothKernel", LogLevel.Debug);
}
if (enableTraceBlueGiga)
{
builder.AddFilter("SharpBrick.PoweredUp.BlueGigaBLE.BlueGigaBLEPoweredUpBluetoothAdapater", LogLevel.Debug);
}
});
if (bluetoothStackPort.Equals("WINRT" , StringComparison.OrdinalIgnoreCase))
{
serviceCollection.AddWinRTBluetooth();
}
else
{
//this adds the BlueGiga-implementation instead of the WinRT-implementation
//the value of the parameter bluetoothStackPort is taken for the COM-Port on which the BlueGiga-adapter is connected
_ = serviceCollection.AddBlueGigaBLEBluetooth(options =>
{
//enter the COMPort-Name here
//on Windows-PCs you can find it under Device Manager --> Ports (COM & LPT) --> Bleugiga Bluetooth Low Energy (COM#) (where # is a number)
options.COMPortName = bluetoothStackPort;
//setting this option to false supresses the complete LogDebug()-commands; so they will not generated at all
options.TraceDebug = enableTraceBlueGiga;
});
}
//can be easily extended here by taking another implementation (for example BlueZ for Raspberry) into the BluetoothImplementation-enum and then
//do the needed Addxxx and options here:


Configure(serviceCollection);

ServiceProvider = serviceCollection.BuildServiceProvider();

Host = ServiceProvider.GetService<PoweredUpHost>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using SharpBrick.PoweredUp;
using SharpBrick.PoweredUp.BlueGigaBLE;

namespace Example
{
Expand Down
Loading

0 comments on commit 3da144d

Please sign in to comment.