Skip to content

Commit

Permalink
Rename PoweredUpProtocol (#85)
Browse files Browse the repository at this point in the history
#61 (breaking)
  • Loading branch information
tthiery committed Aug 31, 2020
1 parent 83b0b4c commit 1f6198a
Show file tree
Hide file tree
Showing 84 changed files with 179 additions and 179 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ using (var scope = serviceProvider.CreateScope()) // create a scoped DI containe
// init BT layer with right bluetooth address
scope.ServiceProvider.GetService<BluetoothKernel>().BluetoothAddress = bluetoothAddress;

var protocol = scope.GetService<IPoweredUpProtocol>();
var protocol = scope.GetService<ILegoWirelessProtocol>();

await protocol.ConnectAsync(); // also connects underlying BT connection
Expand Down Expand Up @@ -209,11 +209,11 @@ Basic Architecture within the SDK
+---------+
| |
| Devices | <-+
| | | +-------------------+ +-------------+ +-----+
+---------+ +-> | | | | | |
| PoweredUpProtocol | <-> | BLE Adapter | <-> | BLE |
+---------+ +-> | (w/ Knowlege) | | | | |
| | | +-------------------+ +-------------+ +-----+
| | | +-----------------------+ +-------------+ +-----+
+---------+ +-> | | | | | |
| ILegoWirelessProtocol | <-> | BLE Adapter | <-> | BLE |
+---------+ +-> | (w/ Knowlege) | | | | |
| | | +-----------------------+ +-------------+ +-----+
| Hub | <-+
| |
+---------+
Expand All @@ -223,20 +223,20 @@ Basic Architecture within the SDK
DI Container Elements

````
PoweredUpHost +----+
+ |
| |
+-------------------- Scoped Service Provider ---------------------+
| | | |
| v +--->IPoweredUp
| LinearMidCalibration + HubFactory | | BluetoothAdapter
| | | |
| TechnicMediumHub +---+-> PoweredUpProtocol +-> BluetoothKernel + |
| + + |
| | | |
| +-----------------------+--------> DeviceFactory |
| |
+------------------------------------------------------------------+
PoweredUpHost +-------+
+ |
| |
+-------------------- Scoped Service Provider ------------------------+
| | | |
| v +--->IPoweredUp
| LinearMidCalibration + HubFactory | | BluetoothAdapter
| | | |
| TechnicMediumHub +---+-> LegoWirelessProtocol +-> BluetoothKernel + |
| + + |
| | | |
| +-----------------------+--------> DeviceFactory |
| |
+---------------------------------------------------------------------+
````

## Implementation Status
Expand Down
2 changes: 1 addition & 1 deletion docs/arch/breaking.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Supported Namespaces

- `SharpBrick.PoweredUp` (all devices, all hubs, PoweredUpHost, IPoweredUpProtocol)
- `SharpBrick.PoweredUp` (all devices, all hubs, PoweredUpHost, ILegoWirelessProtocol)
- `SharpBrick.PoweredUp.Deployment` (builder and model verifer)

# Internal Namespaces
Expand Down
2 changes: 1 addition & 1 deletion docs/development/adding-new-device.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

1. Create new device in namespace `SharpBrick.PoweredUp` and folder `src/SharpBrick.PoweredUp/Devices`
2. Derive from `Device`
3. Create empty constructor (for non-interactive purposes) and `ctr(IPoweredUpProtocol protocol, byte hubId, byte portId)` (for interactive connected purposes)
3. Create empty constructor (for non-interactive purposes) and `ctr(ILegoWirelessProtocol protocol, byte hubId, byte portId)` (for interactive connected purposes)
4. Dervice from interface `IPoweredUpDevice`
5. Execute `poweredup device dump-static-port -p <port number>` to retrieve static port information.
6. Add dump to method `IPoweredUpDevice.GetStaticPortInfoMessages` (this method improves startup performance since protocol knowledge can be initialized without lenthly querying the actual devices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class EmptyDeviceFactory : IDeviceFactory
public IPoweredUpDevice Create(DeviceType deviceType)
=> null;

public IPoweredUpDevice CreateConnected(DeviceType deviceType, IPoweredUpProtocol protocol, byte hubId, byte portId)
public IPoweredUpDevice CreateConnected(DeviceType deviceType, ILegoWirelessProtocol protocol, byte hubId, byte portId)
=> new DynamicDevice(protocol, hubId, portId);
}
public class ExampleDynamicDevice : BaseExample
Expand Down
4 changes: 2 additions & 2 deletions src/SharpBrick.PoweredUp.Cli/Commands/DevicesList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace SharpBrick.PoweredUp.Cli
{
public class DevicesList
{
private readonly IPoweredUpProtocol protocol;
private readonly ILegoWirelessProtocol protocol;
private readonly DiscoverPorts discoverPorts;

public DevicesList(IPoweredUpProtocol protocol, DiscoverPorts discoverPorts)
public DevicesList(ILegoWirelessProtocol protocol, DiscoverPorts discoverPorts)
{
this.protocol = protocol ?? throw new ArgumentNullException(nameof(protocol));
this.discoverPorts = discoverPorts ?? throw new ArgumentNullException(nameof(discoverPorts));
Expand Down
4 changes: 2 additions & 2 deletions src/SharpBrick.PoweredUp.Cli/Commands/DumpStaticPortInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace SharpBrick.PoweredUp.Cli
{
public class DumpStaticPortInfo
{
private readonly IPoweredUpProtocol protocol;
private readonly ILegoWirelessProtocol protocol;
private readonly DiscoverPorts discoverPorts;

public DumpStaticPortInfo(IPoweredUpProtocol protocol, DiscoverPorts discoverPorts)
public DumpStaticPortInfo(ILegoWirelessProtocol protocol, DiscoverPorts discoverPorts)
{
this.protocol = protocol ?? throw new ArgumentNullException(nameof(protocol));
this.discoverPorts = discoverPorts ?? throw new ArgumentNullException(nameof(discoverPorts));
Expand Down
4 changes: 2 additions & 2 deletions src/SharpBrick.PoweredUp/Deployment/DeploymentModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DeploymentModel(DeploymentHubModel[] hubs)
/// </summary>
/// <param name="protocols"></param>
/// <returns></returns>
public DeploymentModelError[] Verify(params IPoweredUpProtocol[] protocols)
public DeploymentModelError[] Verify(params ILegoWirelessProtocol[] protocols)
{
//TODO: match best hub with best protocol

Expand All @@ -42,7 +42,7 @@ public DeploymentModelError[] Verify(params IPoweredUpProtocol[] protocols)
/// <param name="hubId"></param>
/// <param name="hubModel"></param>
/// <returns></returns>
public DeploymentModelError[] Verify(IPoweredUpProtocol protocol, byte hubId, DeploymentHubModel hubModel)
public DeploymentModelError[] Verify(ILegoWirelessProtocol protocol, byte hubId, DeploymentHubModel hubModel)
{
if (protocol is null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/AbsoluteMotor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class AbsoluteMotor : TachoMotor
public AbsoluteMotor()
{ }

protected AbsoluteMotor(IPoweredUpProtocol protocol, byte hubId, byte portId)
protected AbsoluteMotor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_absoluteMode = SingleValueMode<short>(ModeIndexAbsolutePosition);
Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/BasicMotor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class BasicMotor : Device
public BasicMotor()
{ }

public BasicMotor(IPoweredUpProtocol protocol, byte hubId, byte portId)
public BasicMotor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_powerMode = SingleValueMode<sbyte>(ModeIndexPower);
Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/Current.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Current : Device, IPoweredUpDevice
public Current()
{ }

public Current(IPoweredUpProtocol protocol, byte hubId, byte portId)
public Current(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_currentLMode = SingleValueMode<short>(ModeIndexCurrentL);
Expand Down
4 changes: 2 additions & 2 deletions src/SharpBrick.PoweredUp/Devices/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class Device : IDisposable, INotifyPropertyChanged
private CompositeDisposable _compositeDisposable = new CompositeDisposable();
private ConcurrentDictionary<byte, Mode> _modes = new ConcurrentDictionary<byte, Mode>();

protected readonly IPoweredUpProtocol _protocol;
protected readonly ILegoWirelessProtocol _protocol;
protected readonly byte _hubId;
protected readonly byte _portId;
protected readonly IObservable<PortValueData> _portValueObservable;
Expand All @@ -27,7 +27,7 @@ public abstract class Device : IDisposable, INotifyPropertyChanged
public Device()
{ }

public Device(IPoweredUpProtocol protocol, byte hubId, byte portId)
public Device(ILegoWirelessProtocol protocol, byte hubId, byte portId)
{
_protocol = protocol ?? throw new ArgumentNullException(nameof(protocol));
_hubId = hubId;
Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public IPoweredUpDevice Create(DeviceType deviceType)
return (type == null) ? null : (IPoweredUpDevice)ActivatorUtilities.CreateInstance(_serviceProvider, type);
}

public IPoweredUpDevice CreateConnected(DeviceType deviceType, IPoweredUpProtocol protocol, byte hubId, byte portId)
public IPoweredUpDevice CreateConnected(DeviceType deviceType, ILegoWirelessProtocol protocol, byte hubId, byte portId)
{
var type = GetTypeFromDeviceType(deviceType);

Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/DynamicDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DynamicDevice : Device, IPoweredUpDevice
public DynamicDevice()
{ }

public DynamicDevice(IPoweredUpProtocol protocol, byte hubId, byte portId)
public DynamicDevice(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{ }

Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/IDeviceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace SharpBrick.PoweredUp.Devices
public interface IDeviceFactory
{
IPoweredUpDevice Create(DeviceType deviceType);
IPoweredUpDevice CreateConnected(DeviceType deviceType, IPoweredUpProtocol protocol, byte hubId, byte portId);
IPoweredUpDevice CreateConnected(DeviceType deviceType, ILegoWirelessProtocol protocol, byte hubId, byte portId);
}
}
6 changes: 3 additions & 3 deletions src/SharpBrick.PoweredUp/Devices/Mode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace SharpBrick.PoweredUp
public class Mode : IDisposable, INotifyPropertyChanged
{
private CompositeDisposable _compositeDisposable = new CompositeDisposable();
private IPoweredUpProtocol _protocol;
private ILegoWirelessProtocol _protocol;
private PortModeInfo _modeInfo;
protected IObservable<PortValueData> _modeValueObservable;

Expand All @@ -23,7 +23,7 @@ public class Mode : IDisposable, INotifyPropertyChanged
public string Name => _modeInfo.Name;
public string Symbol => _modeInfo.Symbol;

public static Mode Create(IPoweredUpProtocol protocol, byte hubId, byte portId, byte modeIndex, IObservable<PortValueData> modeValueObservable)
public static Mode Create(ILegoWirelessProtocol protocol, byte hubId, byte portId, byte modeIndex, IObservable<PortValueData> modeValueObservable)
{
var modeInfo = protocol.Knowledge.PortMode(hubId, portId, modeIndex);

Expand All @@ -49,7 +49,7 @@ public static Mode Create(IPoweredUpProtocol protocol, byte hubId, byte portId,
return result;
}

protected Mode(IPoweredUpProtocol protocol, PortModeInfo modeInfo, IObservable<PortValueData> modeValueObservable)
protected Mode(ILegoWirelessProtocol protocol, PortModeInfo modeInfo, IObservable<PortValueData> modeValueObservable)
{
this._protocol = protocol;
this._modeInfo = modeInfo;
Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/MultiValueMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class MultiValueMode<TPayload> : Mode

public IObservable<Value<TPayload[]>> Observable { get; }

public MultiValueMode(IPoweredUpProtocol protocol, PortModeInfo modeInfo, IObservable<PortValueData> modeValueObservable)
public MultiValueMode(ILegoWirelessProtocol protocol, PortModeInfo modeInfo, IObservable<PortValueData> modeValueObservable)
: base(protocol, modeInfo, modeValueObservable)
{
Observable = CreateObservable();
Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/RgbLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class RgbLight : Device, IPoweredUpDevice
public RgbLight()
{ }

public RgbLight(IPoweredUpProtocol protocol, byte hubId, byte portId)
public RgbLight(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{ }

Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/SingleValueMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SingleValueMode<TPayload> : Mode

public IObservable<Value<TPayload>> Observable { get; }

public SingleValueMode(IPoweredUpProtocol protocol, PortModeInfo modeInfo, IObservable<PortValueData> modeValueObservable)
public SingleValueMode(ILegoWirelessProtocol protocol, PortModeInfo modeInfo, IObservable<PortValueData> modeValueObservable)
: base(protocol, modeInfo, modeValueObservable)
{
Observable = CreateObservable();
Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/TachoMotor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class TachoMotor : BasicMotor
public TachoMotor()
{ }

protected TachoMotor(IPoweredUpProtocol protocol, byte hubId, byte portId)
protected TachoMotor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_speedMode = SingleValueMode<sbyte>(ModeIndexSpeed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TechnicLargeLinearMotor : AbsoluteMotor, IPoweredUpDevice
public TechnicLargeLinearMotor()
: base()
{ }
public TechnicLargeLinearMotor(IPoweredUpProtocol protocol, byte hubId, byte portId)
public TechnicLargeLinearMotor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{ }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class TechnicMediumHubAccelerometer : Device, IPoweredUpDevice
public TechnicMediumHubAccelerometer()
{ }

public TechnicMediumHubAccelerometer(IPoweredUpProtocol protocol, byte hubId, byte portId)
public TechnicMediumHubAccelerometer(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_gravityMode = MultiValueMode<short>(ModeIndexGravity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TechnicMediumHubGestSensor : Device, IPoweredUpDevice
public TechnicMediumHubGestSensor()
{ }

public TechnicMediumHubGestSensor(IPoweredUpProtocol protocol, byte hubId, byte portId)
public TechnicMediumHubGestSensor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{ }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TechnicMediumHubGyroSensor : Device, IPoweredUpDevice
public TechnicMediumHubGyroSensor()
{ }

public TechnicMediumHubGyroSensor(IPoweredUpProtocol protocol, byte hubId, byte portId)
public TechnicMediumHubGyroSensor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_rotationMode = MultiValueMode<short>(ModeIndexRotation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TechnicMediumHubTemperatureSensor : Device, IPoweredUpDevice
public TechnicMediumHubTemperatureSensor()
{ }

public TechnicMediumHubTemperatureSensor(IPoweredUpProtocol protocol, byte hubId, byte portId)
public TechnicMediumHubTemperatureSensor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_temperatureMode = SingleValueMode<short>(ModeIndexTemperature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class TechnicMediumHubTiltSensor : Device, IPoweredUpDevice
public TechnicMediumHubTiltSensor()
{ }

public TechnicMediumHubTiltSensor(IPoweredUpProtocol protocol, byte hubId, byte portId)
public TechnicMediumHubTiltSensor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_positionMode = MultiValueMode<short>(ModeIndexPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TechnicXLargeLinearMotor : AbsoluteMotor, IPoweredUpDevice
public TechnicXLargeLinearMotor()
: base()
{ }
public TechnicXLargeLinearMotor(IPoweredUpProtocol protocol, byte hubId, byte portId)
public TechnicXLargeLinearMotor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{ }

Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/Voltage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Voltage : Device, IPoweredUpDevice
public Voltage()
{ }

public Voltage(IPoweredUpProtocol protocol, byte hubId, byte portId)
public Voltage(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_voltageLMode = SingleValueMode<short>(ModeIndexVoltageL);
Expand Down
6 changes: 3 additions & 3 deletions src/SharpBrick.PoweredUp/Functions/DiscoverPorts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DiscoverPorts
{
private object lockObject = new object();

private readonly IPoweredUpProtocol _protocol;
private readonly ILegoWirelessProtocol _protocol;
private readonly byte _hubId;
private readonly ILogger<DiscoverPorts> _logger;
private TaskCompletionSource<int> _taskCompletionSource;
Expand All @@ -25,7 +25,7 @@ public class DiscoverPorts

public ConcurrentBag<byte[]> ReceivedMessagesData { get; private set; }

public DiscoverPorts(IPoweredUpProtocol protocol, byte hubId = 0, ILogger<DiscoverPorts> logger = default)
public DiscoverPorts(ILegoWirelessProtocol protocol, byte hubId = 0, ILogger<DiscoverPorts> logger = default)
{
_protocol = protocol ?? throw new System.ArgumentNullException(nameof(protocol));
_hubId = hubId;
Expand Down Expand Up @@ -99,7 +99,7 @@ private async Task RequestPortModePropertiesAsync(PortInfo port)
CheckEndOfDiscovery();
}

private void UpdateKnowledge(byte[] data, PoweredUpMessage message)
private void UpdateKnowledge(byte[] data, LegoWirelessMessage message)
{
var knowledge = _protocol.Knowledge;

Expand Down
8 changes: 4 additions & 4 deletions src/SharpBrick.PoweredUp/Functions/TraceMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace SharpBrick.PoweredUp.Functions
{
public class TraceMessages
{
private IPoweredUpProtocol _protocol;
private ILegoWirelessProtocol _protocol;
private readonly ILogger<TraceMessages> _logger;

public TraceMessages(IPoweredUpProtocol protocol, ILogger<TraceMessages> logger = default)
public TraceMessages(ILegoWirelessProtocol protocol, ILogger<TraceMessages> logger = default)
{
_protocol = protocol ?? throw new ArgumentNullException(nameof(protocol));
_logger = logger;
}

public Task ExecuteAsync()
{
void TraceMessage(PoweredUpMessage message)
void TraceMessage(LegoWirelessMessage message)
{
try
{
Expand All @@ -47,7 +47,7 @@ void TraceMessage(PoweredUpMessage message)
return Task.CompletedTask;
}

private static string MessageToString(PoweredUpMessage message)
private static string MessageToString(LegoWirelessMessage message)
{
var result = message.ToString();

Expand Down
Loading

0 comments on commit 1f6198a

Please sign in to comment.