diff --git a/README.md b/README.md index d8b93dc..ea76f9a 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ using (var scope = serviceProvider.CreateScope()) // create a scoped DI containe // init BT layer with right bluetooth address scope.ServiceProvider.GetService().BluetoothAddress = bluetoothAddress; - var protocol = scope.GetService(); + var protocol = scope.GetService(); await protocol.ConnectAsync(); // also connects underlying BT connection @@ -209,11 +209,11 @@ Basic Architecture within the SDK +---------+ | | | Devices | <-+ -| | | +-------------------+ +-------------+ +-----+ -+---------+ +-> | | | | | | - | PoweredUpProtocol | <-> | BLE Adapter | <-> | BLE | -+---------+ +-> | (w/ Knowlege) | | | | | -| | | +-------------------+ +-------------+ +-----+ +| | | +-----------------------+ +-------------+ +-----+ ++---------+ +-> | | | | | | + | ILegoWirelessProtocol | <-> | BLE Adapter | <-> | BLE | ++---------+ +-> | (w/ Knowlege) | | | | | +| | | +-----------------------+ +-------------+ +-----+ | Hub | <-+ | | +---------+ @@ -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 diff --git a/docs/arch/breaking.md b/docs/arch/breaking.md index 79fa1f2..9f99d1c 100644 --- a/docs/arch/breaking.md +++ b/docs/arch/breaking.md @@ -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 diff --git a/docs/development/adding-new-device.md b/docs/development/adding-new-device.md index da14813..2fc775f 100644 --- a/docs/development/adding-new-device.md +++ b/docs/development/adding-new-device.md @@ -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 ` 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) diff --git a/examples/SharpBrick.PoweredUp.Examples/ExampleDynamicDevice.cs b/examples/SharpBrick.PoweredUp.Examples/ExampleDynamicDevice.cs index 5f1c3fb..7042137 100644 --- a/examples/SharpBrick.PoweredUp.Examples/ExampleDynamicDevice.cs +++ b/examples/SharpBrick.PoweredUp.Examples/ExampleDynamicDevice.cs @@ -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 diff --git a/src/SharpBrick.PoweredUp.Cli/Commands/DevicesList.cs b/src/SharpBrick.PoweredUp.Cli/Commands/DevicesList.cs index 7af4b58..4bf7dea 100644 --- a/src/SharpBrick.PoweredUp.Cli/Commands/DevicesList.cs +++ b/src/SharpBrick.PoweredUp.Cli/Commands/DevicesList.cs @@ -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)); diff --git a/src/SharpBrick.PoweredUp.Cli/Commands/DumpStaticPortInfo.cs b/src/SharpBrick.PoweredUp.Cli/Commands/DumpStaticPortInfo.cs index c0b8242..c81859a 100644 --- a/src/SharpBrick.PoweredUp.Cli/Commands/DumpStaticPortInfo.cs +++ b/src/SharpBrick.PoweredUp.Cli/Commands/DumpStaticPortInfo.cs @@ -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)); diff --git a/src/SharpBrick.PoweredUp/Deployment/DeploymentModel.cs b/src/SharpBrick.PoweredUp/Deployment/DeploymentModel.cs index 7199e16..03702e3 100644 --- a/src/SharpBrick.PoweredUp/Deployment/DeploymentModel.cs +++ b/src/SharpBrick.PoweredUp/Deployment/DeploymentModel.cs @@ -28,7 +28,7 @@ public DeploymentModel(DeploymentHubModel[] hubs) /// /// /// - public DeploymentModelError[] Verify(params IPoweredUpProtocol[] protocols) + public DeploymentModelError[] Verify(params ILegoWirelessProtocol[] protocols) { //TODO: match best hub with best protocol @@ -42,7 +42,7 @@ public DeploymentModelError[] Verify(params IPoweredUpProtocol[] protocols) /// /// /// - public DeploymentModelError[] Verify(IPoweredUpProtocol protocol, byte hubId, DeploymentHubModel hubModel) + public DeploymentModelError[] Verify(ILegoWirelessProtocol protocol, byte hubId, DeploymentHubModel hubModel) { if (protocol is null) { diff --git a/src/SharpBrick.PoweredUp/Devices/AbsoluteMotor.cs b/src/SharpBrick.PoweredUp/Devices/AbsoluteMotor.cs index 1e45dfd..712a3b2 100644 --- a/src/SharpBrick.PoweredUp/Devices/AbsoluteMotor.cs +++ b/src/SharpBrick.PoweredUp/Devices/AbsoluteMotor.cs @@ -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(ModeIndexAbsolutePosition); diff --git a/src/SharpBrick.PoweredUp/Devices/BasicMotor.cs b/src/SharpBrick.PoweredUp/Devices/BasicMotor.cs index 95a6960..37fd20e 100644 --- a/src/SharpBrick.PoweredUp/Devices/BasicMotor.cs +++ b/src/SharpBrick.PoweredUp/Devices/BasicMotor.cs @@ -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(ModeIndexPower); diff --git a/src/SharpBrick.PoweredUp/Devices/Current.cs b/src/SharpBrick.PoweredUp/Devices/Current.cs index 7036131..41ee919 100644 --- a/src/SharpBrick.PoweredUp/Devices/Current.cs +++ b/src/SharpBrick.PoweredUp/Devices/Current.cs @@ -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(ModeIndexCurrentL); diff --git a/src/SharpBrick.PoweredUp/Devices/Device.cs b/src/SharpBrick.PoweredUp/Devices/Device.cs index 15877f5..ddb22ca 100644 --- a/src/SharpBrick.PoweredUp/Devices/Device.cs +++ b/src/SharpBrick.PoweredUp/Devices/Device.cs @@ -16,7 +16,7 @@ public abstract class Device : IDisposable, INotifyPropertyChanged private CompositeDisposable _compositeDisposable = new CompositeDisposable(); private ConcurrentDictionary _modes = new ConcurrentDictionary(); - protected readonly IPoweredUpProtocol _protocol; + protected readonly ILegoWirelessProtocol _protocol; protected readonly byte _hubId; protected readonly byte _portId; protected readonly IObservable _portValueObservable; @@ -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; diff --git a/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs b/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs index c039074..fac8606 100644 --- a/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs +++ b/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs @@ -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); diff --git a/src/SharpBrick.PoweredUp/Devices/DynamicDevice.cs b/src/SharpBrick.PoweredUp/Devices/DynamicDevice.cs index e7da938..6bfb33d 100644 --- a/src/SharpBrick.PoweredUp/Devices/DynamicDevice.cs +++ b/src/SharpBrick.PoweredUp/Devices/DynamicDevice.cs @@ -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) { } diff --git a/src/SharpBrick.PoweredUp/Devices/IDeviceFactory.cs b/src/SharpBrick.PoweredUp/Devices/IDeviceFactory.cs index c54691e..004b99e 100644 --- a/src/SharpBrick.PoweredUp/Devices/IDeviceFactory.cs +++ b/src/SharpBrick.PoweredUp/Devices/IDeviceFactory.cs @@ -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); } } \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Devices/Mode.cs b/src/SharpBrick.PoweredUp/Devices/Mode.cs index cc8e8d5..c2123bc 100644 --- a/src/SharpBrick.PoweredUp/Devices/Mode.cs +++ b/src/SharpBrick.PoweredUp/Devices/Mode.cs @@ -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 _modeValueObservable; @@ -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 modeValueObservable) + public static Mode Create(ILegoWirelessProtocol protocol, byte hubId, byte portId, byte modeIndex, IObservable modeValueObservable) { var modeInfo = protocol.Knowledge.PortMode(hubId, portId, modeIndex); @@ -49,7 +49,7 @@ public static Mode Create(IPoweredUpProtocol protocol, byte hubId, byte portId, return result; } - protected Mode(IPoweredUpProtocol protocol, PortModeInfo modeInfo, IObservable modeValueObservable) + protected Mode(ILegoWirelessProtocol protocol, PortModeInfo modeInfo, IObservable modeValueObservable) { this._protocol = protocol; this._modeInfo = modeInfo; diff --git a/src/SharpBrick.PoweredUp/Devices/MultiValueMode.cs b/src/SharpBrick.PoweredUp/Devices/MultiValueMode.cs index 55c1837..bb9f8c3 100644 --- a/src/SharpBrick.PoweredUp/Devices/MultiValueMode.cs +++ b/src/SharpBrick.PoweredUp/Devices/MultiValueMode.cs @@ -14,7 +14,7 @@ public class MultiValueMode : Mode public IObservable> Observable { get; } - public MultiValueMode(IPoweredUpProtocol protocol, PortModeInfo modeInfo, IObservable modeValueObservable) + public MultiValueMode(ILegoWirelessProtocol protocol, PortModeInfo modeInfo, IObservable modeValueObservable) : base(protocol, modeInfo, modeValueObservable) { Observable = CreateObservable(); diff --git a/src/SharpBrick.PoweredUp/Devices/RgbLight.cs b/src/SharpBrick.PoweredUp/Devices/RgbLight.cs index 6c9a98f..770012c 100644 --- a/src/SharpBrick.PoweredUp/Devices/RgbLight.cs +++ b/src/SharpBrick.PoweredUp/Devices/RgbLight.cs @@ -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) { } diff --git a/src/SharpBrick.PoweredUp/Devices/SingleValueMode.cs b/src/SharpBrick.PoweredUp/Devices/SingleValueMode.cs index d4ef8cb..f970b9e 100644 --- a/src/SharpBrick.PoweredUp/Devices/SingleValueMode.cs +++ b/src/SharpBrick.PoweredUp/Devices/SingleValueMode.cs @@ -14,7 +14,7 @@ public class SingleValueMode : Mode public IObservable> Observable { get; } - public SingleValueMode(IPoweredUpProtocol protocol, PortModeInfo modeInfo, IObservable modeValueObservable) + public SingleValueMode(ILegoWirelessProtocol protocol, PortModeInfo modeInfo, IObservable modeValueObservable) : base(protocol, modeInfo, modeValueObservable) { Observable = CreateObservable(); diff --git a/src/SharpBrick.PoweredUp/Devices/TachoMotor.cs b/src/SharpBrick.PoweredUp/Devices/TachoMotor.cs index ef18a98..82c1cc2 100644 --- a/src/SharpBrick.PoweredUp/Devices/TachoMotor.cs +++ b/src/SharpBrick.PoweredUp/Devices/TachoMotor.cs @@ -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(ModeIndexSpeed); diff --git a/src/SharpBrick.PoweredUp/Devices/TechnicLargeLinearMotor.cs b/src/SharpBrick.PoweredUp/Devices/TechnicLargeLinearMotor.cs index 28a134f..7316e24 100644 --- a/src/SharpBrick.PoweredUp/Devices/TechnicLargeLinearMotor.cs +++ b/src/SharpBrick.PoweredUp/Devices/TechnicLargeLinearMotor.cs @@ -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) { } diff --git a/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubAccelerometer.cs b/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubAccelerometer.cs index 5b87073..c336c43 100644 --- a/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubAccelerometer.cs +++ b/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubAccelerometer.cs @@ -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(ModeIndexGravity); diff --git a/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubGestSensor.cs b/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubGestSensor.cs index b3f9fca..9e036cf 100644 --- a/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubGestSensor.cs +++ b/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubGestSensor.cs @@ -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) { } diff --git a/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubGyroSensor.cs b/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubGyroSensor.cs index ec856e3..4e8614e 100644 --- a/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubGyroSensor.cs +++ b/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubGyroSensor.cs @@ -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(ModeIndexRotation); diff --git a/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubTemperatureSensor.cs b/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubTemperatureSensor.cs index 3082e05..ca94a0f 100644 --- a/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubTemperatureSensor.cs +++ b/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubTemperatureSensor.cs @@ -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(ModeIndexTemperature); diff --git a/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubTiltSensor.cs b/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubTiltSensor.cs index cf21f65..3a5a021 100644 --- a/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubTiltSensor.cs +++ b/src/SharpBrick.PoweredUp/Devices/TechnicMediumHubTiltSensor.cs @@ -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(ModeIndexPosition); diff --git a/src/SharpBrick.PoweredUp/Devices/TechnicXLargeLinearMotor.cs b/src/SharpBrick.PoweredUp/Devices/TechnicXLargeLinearMotor.cs index 50fdd0a..960dca4 100644 --- a/src/SharpBrick.PoweredUp/Devices/TechnicXLargeLinearMotor.cs +++ b/src/SharpBrick.PoweredUp/Devices/TechnicXLargeLinearMotor.cs @@ -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) { } diff --git a/src/SharpBrick.PoweredUp/Devices/Voltage.cs b/src/SharpBrick.PoweredUp/Devices/Voltage.cs index 6f722f4..b546bdb 100644 --- a/src/SharpBrick.PoweredUp/Devices/Voltage.cs +++ b/src/SharpBrick.PoweredUp/Devices/Voltage.cs @@ -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(ModeIndexVoltageL); diff --git a/src/SharpBrick.PoweredUp/Functions/DiscoverPorts.cs b/src/SharpBrick.PoweredUp/Functions/DiscoverPorts.cs index fe748e5..daa43de 100644 --- a/src/SharpBrick.PoweredUp/Functions/DiscoverPorts.cs +++ b/src/SharpBrick.PoweredUp/Functions/DiscoverPorts.cs @@ -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 _logger; private TaskCompletionSource _taskCompletionSource; @@ -25,7 +25,7 @@ public class DiscoverPorts public ConcurrentBag ReceivedMessagesData { get; private set; } - public DiscoverPorts(IPoweredUpProtocol protocol, byte hubId = 0, ILogger logger = default) + public DiscoverPorts(ILegoWirelessProtocol protocol, byte hubId = 0, ILogger logger = default) { _protocol = protocol ?? throw new System.ArgumentNullException(nameof(protocol)); _hubId = hubId; @@ -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; diff --git a/src/SharpBrick.PoweredUp/Functions/TraceMessages.cs b/src/SharpBrick.PoweredUp/Functions/TraceMessages.cs index 8bd7a19..29698f5 100644 --- a/src/SharpBrick.PoweredUp/Functions/TraceMessages.cs +++ b/src/SharpBrick.PoweredUp/Functions/TraceMessages.cs @@ -10,10 +10,10 @@ namespace SharpBrick.PoweredUp.Functions { public class TraceMessages { - private IPoweredUpProtocol _protocol; + private ILegoWirelessProtocol _protocol; private readonly ILogger _logger; - public TraceMessages(IPoweredUpProtocol protocol, ILogger logger = default) + public TraceMessages(ILegoWirelessProtocol protocol, ILogger logger = default) { _protocol = protocol ?? throw new ArgumentNullException(nameof(protocol)); _logger = logger; @@ -21,7 +21,7 @@ public TraceMessages(IPoweredUpProtocol protocol, ILogger logger public Task ExecuteAsync() { - void TraceMessage(PoweredUpMessage message) + void TraceMessage(LegoWirelessMessage message) { try { @@ -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(); diff --git a/src/SharpBrick.PoweredUp/Hubs/Hub.cs b/src/SharpBrick.PoweredUp/Hubs/Hub.cs index 48d6ef7..ed7622b 100644 --- a/src/SharpBrick.PoweredUp/Hubs/Hub.cs +++ b/src/SharpBrick.PoweredUp/Hubs/Hub.cs @@ -15,12 +15,12 @@ public abstract partial class Hub : IDisposable private readonly ILogger _logger; private readonly IDeviceFactory _deviceFactory; - public IPoweredUpProtocol Protocol { get; private set; } + public ILegoWirelessProtocol Protocol { get; private set; } public byte HubId { get; private set; } public IServiceProvider ServiceProvider { get; } public bool IsConnected => Protocol != null; - public Hub(IPoweredUpProtocol protocol, IDeviceFactory deviceFactory, ILogger logger, IServiceProvider serviceProvider, Port[] knownPorts) + public Hub(ILegoWirelessProtocol protocol, IDeviceFactory deviceFactory, ILogger logger, IServiceProvider serviceProvider, Port[] knownPorts) { Protocol = protocol ?? throw new ArgumentNullException(nameof(protocol)); _deviceFactory = deviceFactory ?? throw new ArgumentNullException(nameof(deviceFactory)); @@ -89,7 +89,7 @@ private void SetupOnHubChange() _compositeDisposable.Add(disposable); } - private void OnHubChange(PoweredUpMessage message) + private void OnHubChange(LegoWirelessMessage message) { if (message is HubPropertyMessage hubProperty && hubProperty.Operation == HubPropertyOperation.Update) { diff --git a/src/SharpBrick.PoweredUp/Hubs/Hub_Alerts.cs b/src/SharpBrick.PoweredUp/Hubs/Hub_Alerts.cs index 828ace2..b637e4e 100644 --- a/src/SharpBrick.PoweredUp/Hubs/Hub_Alerts.cs +++ b/src/SharpBrick.PoweredUp/Hubs/Hub_Alerts.cs @@ -9,7 +9,7 @@ public abstract partial class Hub { public IObservable AlertObservable { get; private set; } - private void SetupHubAlertObservable(IObservable upstreamMessages) + private void SetupHubAlertObservable(IObservable upstreamMessages) { AlertObservable = upstreamMessages .OfType() diff --git a/src/SharpBrick.PoweredUp/Hubs/Hub_Ports.cs b/src/SharpBrick.PoweredUp/Hubs/Hub_Ports.cs index 215a747..d4843ad 100644 --- a/src/SharpBrick.PoweredUp/Hubs/Hub_Ports.cs +++ b/src/SharpBrick.PoweredUp/Hubs/Hub_Ports.cs @@ -23,7 +23,7 @@ public Port Port(byte id) public Port Port(string friendlyName) => _ports.Values.FirstOrDefault(p => p.FriendlyName == friendlyName) ?? default; - private void SetupOnPortChangeObservable(IObservable upstreamMessages) + private void SetupOnPortChangeObservable(IObservable upstreamMessages) { PortChangeObservable = upstreamMessages .OfType() diff --git a/src/SharpBrick.PoweredUp/Hubs/Hub_Properties.cs b/src/SharpBrick.PoweredUp/Hubs/Hub_Properties.cs index 55b121c..8da168e 100644 --- a/src/SharpBrick.PoweredUp/Hubs/Hub_Properties.cs +++ b/src/SharpBrick.PoweredUp/Hubs/Hub_Properties.cs @@ -42,7 +42,7 @@ public Task ResetHardwareNetworkIdAsync() public IObservable RssiObservable { get; private set; } public IObservable BatteryVoltageInPercentObservable { get; private set; } - private void SetupHubPropertyObservable(IObservable upstreamMessages) + private void SetupHubPropertyObservable(IObservable upstreamMessages) { PropertyChangedObservable = upstreamMessages .OfType() @@ -55,7 +55,7 @@ private void SetupHubPropertyObservable(IObservable upstreamMe BatteryVoltageInPercentObservable = BuildObservableForProperty(upstreamMessages, HubProperty.BatteryVoltage); } - private IObservable BuildObservableForProperty(IObservable upstreamMessages, HubProperty property) + private IObservable BuildObservableForProperty(IObservable upstreamMessages, HubProperty property) => upstreamMessages .OfType() .Where(msg => msg.Operation == HubPropertyOperation.Update && msg.Property == property) diff --git a/src/SharpBrick.PoweredUp/Hubs/TechnicMediumHub.cs b/src/SharpBrick.PoweredUp/Hubs/TechnicMediumHub.cs index 9bfa549..471145f 100644 --- a/src/SharpBrick.PoweredUp/Hubs/TechnicMediumHub.cs +++ b/src/SharpBrick.PoweredUp/Hubs/TechnicMediumHub.cs @@ -7,7 +7,7 @@ namespace SharpBrick.PoweredUp { public class TechnicMediumHub : Hub { - public TechnicMediumHub(IPoweredUpProtocol protocol, IDeviceFactory deviceFactory, ILogger logger, IServiceProvider serviceProvider = default) + public TechnicMediumHub(ILegoWirelessProtocol protocol, IDeviceFactory deviceFactory, ILogger logger, IServiceProvider serviceProvider = default) : base(protocol, deviceFactory, logger, serviceProvider, new Port[] { new Port(0, nameof(A), true), new Port(1, nameof(B), true), diff --git a/src/SharpBrick.PoweredUp/IServiceCollectionExtensions.cs b/src/SharpBrick.PoweredUp/IServiceCollectionExtensions.cs index 43c6564..a95094f 100644 --- a/src/SharpBrick.PoweredUp/IServiceCollectionExtensions.cs +++ b/src/SharpBrick.PoweredUp/IServiceCollectionExtensions.cs @@ -18,7 +18,7 @@ public static IServiceCollection AddPoweredUp(this IServiceCollection self) .AddScoped() .AddScoped() .AddScoped() - .AddScoped() + .AddScoped() // hubs .AddTransient() diff --git a/src/SharpBrick.PoweredUp/PoweredUpHost.cs b/src/SharpBrick.PoweredUp/PoweredUpHost.cs index b6c70ef..c9cbbc7 100644 --- a/src/SharpBrick.PoweredUp/PoweredUpHost.cs +++ b/src/SharpBrick.PoweredUp/PoweredUpHost.cs @@ -102,11 +102,11 @@ public THub Create(ulong bluetoothAddress) where THub : Hub return hub; } - public IPoweredUpProtocol CreateProtocol(ulong bluetoothAddress) + public ILegoWirelessProtocol CreateProtocol(ulong bluetoothAddress) { var protocolScope = CreateProtocolScope(bluetoothAddress); - var protocol = protocolScope.ServiceProvider.GetService(); + var protocol = protocolScope.ServiceProvider.GetService(); return protocol; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/CommonMessageHeaderEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/CommonMessageHeaderEncoder.cs index 278c873..f092f4c 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/CommonMessageHeaderEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/CommonMessageHeaderEncoder.cs @@ -5,7 +5,7 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public static class CommonMessageHeaderEncoder { - public static void DecodeAndApply(in Span data, PoweredUpMessage message) + public static void DecodeAndApply(in Span data, LegoWirelessMessage message) { var (length, hubId, messageType, headerLength) = ParseCommonHeader(data); diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/GenericErrorMessageEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/GenericErrorMessageEncoder.cs index f330b09..93da55b 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/GenericErrorMessageEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/GenericErrorMessageEncoder.cs @@ -5,17 +5,17 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class GenericErrorMessageEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => throw new NotImplementedException(); - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) => new GenericErrorMessage() { CommandType = data[0], ErrorCode = (ErrorCode)data[1], }; - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/HubActionEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/HubActionEncoder.cs index 3519e54..b86fcfa 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/HubActionEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/HubActionEncoder.cs @@ -5,13 +5,13 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class HubActionEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => 1; - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) => new HubActionMessage() { Action = (HubAction)data[0] }; - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) { var hubActionMessage = message as HubActionMessage ?? throw new ArgumentException(nameof(message)); diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/HubAlertEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/HubAlertEncoder.cs index 9b3a78d..f0c21f2 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/HubAlertEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/HubAlertEncoder.cs @@ -5,16 +5,16 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class HubAlertEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) { var hubAlertMessage = message as HubAlertMessage ?? throw new ArgumentException(nameof(message)); return (ushort)(hubAlertMessage.Operation == HubAlertOperation.Update ? 3 : 2); } - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) => new HubAlertMessage() { Alert = (HubAlert)data[0], Operation = (HubAlertOperation)data[1], DownstreamPayload = (byte)((data[1] == (byte)HubAlertOperation.Update) ? data[2] : 0) }; - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) { var hubAlertMessage = message as HubAlertMessage ?? throw new ArgumentException(nameof(message)); diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/HubAttachedIOEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/HubAttachedIOEncoder.cs index 88ba0dd..44d5908 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/HubAttachedIOEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/HubAttachedIOEncoder.cs @@ -5,7 +5,7 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class HubAttachedIOEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => message switch { HubAttachedIOForAttachedDeviceMessage _ => 12, @@ -15,7 +15,7 @@ public ushort CalculateContentLength(PoweredUpMessage message) }; - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) { switch (message) { @@ -46,7 +46,7 @@ public void Encode(HubAttachedIOForDetachedDeviceMessage message, in Span public void Encode(HubAttachedIOForAttachedVirtualDeviceMessage message, in Span data) => throw new NotImplementedException(); - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) { byte portId = data[0]; HubAttachedIOEvent ev = (HubAttachedIOEvent)data[1]; diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/HubPropertiesEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/HubPropertiesEncoder.cs index 17f7ff4..5b481a9 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/HubPropertiesEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/HubPropertiesEncoder.cs @@ -5,7 +5,7 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class HubPropertiesEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => CalculateMessageLength(message as HubPropertyMessage ?? throw new ArgumentException(nameof(message))); public ushort CalculateMessageLength(HubPropertyMessage message) @@ -35,7 +35,7 @@ public ushort CalculateMessageLength(HubPropertyMessage message) return (ushort)length; } - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => Encode(message as HubPropertyMessage ?? throw new ArgumentException(nameof(message)), data); public void Encode(HubPropertyMessage message, Span data) @@ -64,7 +64,7 @@ public void Encode(HubPropertyMessage message, Span data) } } - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) { HubPropertyMessage message = (HubProperty)data[0] switch { diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/IMessageContentEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/IMessageContentEncoder.cs index 893bf4d..dd19007 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/IMessageContentEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/IMessageContentEncoder.cs @@ -5,8 +5,8 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public interface IMessageContentEncoder { - ushort CalculateContentLength(PoweredUpMessage message); - void Encode(PoweredUpMessage message, in Span data); - PoweredUpMessage Decode(byte hubId, in Span data); + ushort CalculateContentLength(LegoWirelessMessage message); + void Encode(LegoWirelessMessage message, in Span data); + LegoWirelessMessage Decode(byte hubId, in Span data); } } \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/MessageEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/MessageEncoder.cs index b7e55d9..04cf500 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/MessageEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/MessageEncoder.cs @@ -6,7 +6,7 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class MessageEncoder { - public static byte[] Encode(PoweredUpMessage message, ProtocolKnowledge knowledge) + public static byte[] Encode(LegoWirelessMessage message, ProtocolKnowledge knowledge) { var messageType = message switch { @@ -71,7 +71,7 @@ private static IMessageContentEncoder CreateEncoder(MessageType messageType, Pro _ => null, }; - public static PoweredUpMessage Decode(in Span data, ProtocolKnowledge knowledge) + public static LegoWirelessMessage Decode(in Span data, ProtocolKnowledge knowledge) { var (length, hubId, messageType, headerLength) = CommonMessageHeaderEncoder.ParseCommonHeader(data); @@ -79,7 +79,7 @@ public static PoweredUpMessage Decode(in Span data, ProtocolKnowledge know var content = data.Slice(headerLength); - PoweredUpMessage result; + LegoWirelessMessage result; if (encoder != null) { diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInformationEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInformationEncoder.cs index dcf47d0..75699ed 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInformationEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInformationEncoder.cs @@ -6,10 +6,10 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class PortInformationEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => throw new NotImplementedException(); - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) { byte portId = data[0]; var informationType = (PortInformationType)data[1]; @@ -58,7 +58,7 @@ public PoweredUpMessage Decode(byte hubId, in Span data) return result; } - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInformationRequestEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInformationRequestEncoder.cs index 163c284..4447c30 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInformationRequestEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInformationRequestEncoder.cs @@ -5,13 +5,13 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class PortInformationRequestEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => 2; - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) => throw new NotImplementedException(); - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => Encode(message as PortInformationRequestMessage ?? throw new ArgumentException(nameof(message)), data); public void Encode(PortInformationRequestMessage message, in Span data) diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatCombinedModeEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatCombinedModeEncoder.cs index 6ff37d9..a8e65fc 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatCombinedModeEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatCombinedModeEncoder.cs @@ -6,10 +6,10 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class PortInputFormatCombinedModeEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => throw new NotImplementedException(); - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) { ushort bitMask = BitConverter.ToUInt16(data.Slice(2, 2)); @@ -24,7 +24,7 @@ public PoweredUpMessage Decode(byte hubId, in Span data) }; } - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => throw new NotImplementedException(); } diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSetupCombinedModeEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSetupCombinedModeEncoder.cs index 7777998..32768d7 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSetupCombinedModeEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSetupCombinedModeEncoder.cs @@ -5,13 +5,13 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class PortInputFormatSetupCombinedModeEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => (ushort)(message is PortInputFormatSetupCombinedModeForSetModeDataSetMessage setMessage ? 3 + setMessage.ModeDataSets.Length : 2); - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) => throw new NotImplementedException(); - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => Encode(message as PortInputFormatSetupCombinedModeMessage ?? throw new ArgumentException(nameof(message)), data); public void Encode(PortInputFormatSetupCombinedModeMessage message, in Span data) { diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSetupSingleEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSetupSingleEncoder.cs index 7d3de6e..4d65a05 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSetupSingleEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSetupSingleEncoder.cs @@ -6,13 +6,13 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter // spec chapter: 3.17 public class PortInputFormatSetupSingleEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => 7; - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) => throw new NotImplementedException(); - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => Encode(message as PortInputFormatSetupSingleMessage ?? throw new ArgumentException(nameof(message)), data); public void Encode(PortInputFormatSetupSingleMessage message, in Span data) { diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSingleEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSingleEncoder.cs index ae613d6..d028410 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSingleEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortInputFormatSingleEncoder.cs @@ -6,10 +6,10 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter // spec chapter: 3.23 public class PortInputFormatSingleEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => 7; - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => Encode(message as PortInputFormatSingleMessage, data); public void Encode(PortInputFormatSingleMessage message, in Span data) { @@ -19,7 +19,7 @@ public void Encode(PortInputFormatSingleMessage message, in Span data) data[6] = (byte)(message.NotificationEnabled ? 0x01 : 0x00); } - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) => new PortInputFormatSingleMessage() { PortId = data[0], diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortModeInformationEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortModeInformationEncoder.cs index f9101d6..46e19b9 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortModeInformationEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortModeInformationEncoder.cs @@ -6,10 +6,10 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class PortModeInformationEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => throw new NotImplementedException(); - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) { var portId = data[0]; var mode = data[1]; @@ -96,7 +96,7 @@ private PortModeInformationMessage DecodeValueFormat(in Span data) Decimals = data[3], }; - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortModeInformationRequestEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortModeInformationRequestEncoder.cs index 0fad5e2..515c40a 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortModeInformationRequestEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortModeInformationRequestEncoder.cs @@ -5,13 +5,13 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class PortModeInformationRequestEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => 3; - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) => throw new NotImplementedException(); - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => Encode(message as PortModeInformationRequestMessage ?? throw new ArgumentException(nameof(message)), data); public void Encode(PortModeInformationRequestMessage message, in Span data) diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortOutputCommandEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortOutputCommandEncoder.cs index 780c83a..0f20da3 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortOutputCommandEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortOutputCommandEncoder.cs @@ -5,7 +5,7 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class PortOutputCommandEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => (ushort)(message switch { PortOutputCommandMessage portOutputMessage => 3 + portOutputMessage switch @@ -41,10 +41,10 @@ public ushort CalculateContentLength(PoweredUpMessage message) _ => throw new NotSupportedException(), }); - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) => throw new NotImplementedException(); - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => Encode(message as PortOutputCommandMessage ?? throw new InvalidOperationException(), data); public void Encode(PortOutputCommandMessage message, in Span data) diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortOutputCommandFeedbackEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortOutputCommandFeedbackEncoder.cs index cfa0ba0..01ff835 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortOutputCommandFeedbackEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortOutputCommandFeedbackEncoder.cs @@ -6,10 +6,10 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class PortOutputCommandFeedbackEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => throw new NotImplementedException(); - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) { var remainingSlice = data; @@ -33,7 +33,7 @@ public PoweredUpMessage Decode(byte hubId, in Span data) }; } - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortValueCombinedModeEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortValueCombinedModeEncoder.cs index f1fb179..be2b4e5 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortValueCombinedModeEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortValueCombinedModeEncoder.cs @@ -15,10 +15,10 @@ public PortValueCombinedModeEncoder(ProtocolKnowledge knowledge) _knowledge = knowledge; } - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => throw new NotImplementedException(); - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) { var result = new List(); @@ -63,7 +63,7 @@ public PoweredUpMessage Decode(byte hubId, in Span data) }; } - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortValueSingleEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortValueSingleEncoder.cs index e58c352..601701b 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/PortValueSingleEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/PortValueSingleEncoder.cs @@ -16,10 +16,10 @@ public PortValueSingleEncoder(ProtocolKnowledge knowledge) _knowledge = knowledge; } - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => throw new NotImplementedException(); - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) { var remainingSlice = data; @@ -141,7 +141,7 @@ internal static float Scale(float value, float rawMin, float rawMax, float min, return (positionInRawRange * (max - min)) + min; } - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Protocol/Formatter/VirtualPortSetupEncoder.cs b/src/SharpBrick.PoweredUp/Protocol/Formatter/VirtualPortSetupEncoder.cs index 2e71f43..9113c45 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Formatter/VirtualPortSetupEncoder.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Formatter/VirtualPortSetupEncoder.cs @@ -5,7 +5,7 @@ namespace SharpBrick.PoweredUp.Protocol.Formatter { public class VirtualPortSetupEncoder : IMessageContentEncoder { - public ushort CalculateContentLength(PoweredUpMessage message) + public ushort CalculateContentLength(LegoWirelessMessage message) => message switch { VirtualPortSetupForConnectedMessage msg => 3, @@ -13,10 +13,10 @@ public ushort CalculateContentLength(PoweredUpMessage message) _ => throw new NotSupportedException(), }; - public PoweredUpMessage Decode(byte hubId, in Span data) + public LegoWirelessMessage Decode(byte hubId, in Span data) => throw new NotImplementedException(); - public void Encode(PoweredUpMessage message, in Span data) + public void Encode(LegoWirelessMessage message, in Span data) { switch (message) { diff --git a/src/SharpBrick.PoweredUp/Protocol/IPoweredUpProtocol.cs b/src/SharpBrick.PoweredUp/Protocol/ILegoWirelessProtocol.cs similarity index 53% rename from src/SharpBrick.PoweredUp/Protocol/IPoweredUpProtocol.cs rename to src/SharpBrick.PoweredUp/Protocol/ILegoWirelessProtocol.cs index 7741c91..57ad43d 100644 --- a/src/SharpBrick.PoweredUp/Protocol/IPoweredUpProtocol.cs +++ b/src/SharpBrick.PoweredUp/Protocol/ILegoWirelessProtocol.cs @@ -1,18 +1,18 @@ -using System; +using System; using System.Threading.Tasks; using SharpBrick.PoweredUp.Protocol.Knowledge; using SharpBrick.PoweredUp.Protocol.Messages; namespace SharpBrick.PoweredUp.Protocol { - public interface IPoweredUpProtocol : IDisposable + public interface ILegoWirelessProtocol : IDisposable { Task ConnectAsync(); Task DisconnectAsync(); - Task SendMessageAsync(PoweredUpMessage message); - IObservable UpstreamMessages { get; } - IObservable<(byte[] data, PoweredUpMessage message)> UpstreamRawMessages { get; } + Task SendMessageAsync(LegoWirelessMessage message); + IObservable UpstreamMessages { get; } + IObservable<(byte[] data, LegoWirelessMessage message)> UpstreamRawMessages { get; } ProtocolKnowledge Knowledge { get; } diff --git a/src/SharpBrick.PoweredUp/Protocol/IPoweredUpProtocolExtensions.cs b/src/SharpBrick.PoweredUp/Protocol/ILegoWirelessProtocolExtensions.cs similarity index 78% rename from src/SharpBrick.PoweredUp/Protocol/IPoweredUpProtocolExtensions.cs rename to src/SharpBrick.PoweredUp/Protocol/ILegoWirelessProtocolExtensions.cs index 86fd4e9..8b24241 100644 --- a/src/SharpBrick.PoweredUp/Protocol/IPoweredUpProtocolExtensions.cs +++ b/src/SharpBrick.PoweredUp/Protocol/ILegoWirelessProtocolExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Reactive.Linq; using System.Threading.Tasks; @@ -6,9 +6,9 @@ namespace SharpBrick.PoweredUp.Protocol { - public static class IPoweredUpProtocolExtensions + public static class ILegoWirelessProtocolExtensions { - public static async Task SendMessageReceiveResultAsync(this IPoweredUpProtocol self, PoweredUpMessage message, Func filter = default) + public static async Task SendMessageReceiveResultAsync(this ILegoWirelessProtocol self, LegoWirelessMessage message, Func filter = default) { var awaitable = self.UpstreamMessages .OfType() @@ -23,7 +23,7 @@ public static async Task SendMessageReceiveResultAsync SendPortOutputCommandAsync(this IPoweredUpProtocol self, PortOutputCommandMessage message) + public static async Task SendPortOutputCommandAsync(this ILegoWirelessProtocol self, PortOutputCommandMessage message) { var portId = message.PortId; diff --git a/src/SharpBrick.PoweredUp/Protocol/Knowledge/KnowledgeManager.cs b/src/SharpBrick.PoweredUp/Protocol/Knowledge/KnowledgeManager.cs index c4d118a..8f82369 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Knowledge/KnowledgeManager.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Knowledge/KnowledgeManager.cs @@ -10,7 +10,7 @@ namespace SharpBrick.PoweredUp.Protocol.Knowledge { public static class KnowledgeManager { - public static bool ApplyStaticProtocolKnowledge(PoweredUpMessage message, ProtocolKnowledge knowledge) + public static bool ApplyStaticProtocolKnowledge(LegoWirelessMessage message, ProtocolKnowledge knowledge) { var applicableMessage = true; @@ -104,7 +104,7 @@ public static bool ApplyStaticProtocolKnowledge(PoweredUpMessage message, Protoc return applicableMessage; } - public static Task ApplyDynamicProtocolKnowledge(PoweredUpMessage message, ProtocolKnowledge knowledge, IDeviceFactory deviceFactory) + public static Task ApplyDynamicProtocolKnowledge(LegoWirelessMessage message, ProtocolKnowledge knowledge, IDeviceFactory deviceFactory) { HubInfo hub; PortInfo port; diff --git a/src/SharpBrick.PoweredUp/Protocol/PoweredUpProtocol.cs b/src/SharpBrick.PoweredUp/Protocol/LegoWirelessProtocol.cs similarity index 72% rename from src/SharpBrick.PoweredUp/Protocol/PoweredUpProtocol.cs rename to src/SharpBrick.PoweredUp/Protocol/LegoWirelessProtocol.cs index 1f3280f..44fb6df 100644 --- a/src/SharpBrick.PoweredUp/Protocol/PoweredUpProtocol.cs +++ b/src/SharpBrick.PoweredUp/Protocol/LegoWirelessProtocol.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reactive.Linq; using System.Reactive.Subjects; using System.Threading.Tasks; @@ -11,26 +11,26 @@ namespace SharpBrick.PoweredUp.Protocol { - public class PoweredUpProtocol : IPoweredUpProtocol + public class LegoWirelessProtocol : ILegoWirelessProtocol { private readonly BluetoothKernel _kernel; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IDeviceFactory _deviceFactory; - private Subject<(byte[] data, PoweredUpMessage message)> _upstreamSubject = null; + private Subject<(byte[] data, LegoWirelessMessage message)> _upstreamSubject = null; public ProtocolKnowledge Knowledge { get; } = new ProtocolKnowledge(); - public IObservable<(byte[] data, PoweredUpMessage message)> UpstreamRawMessages => _upstreamSubject; - public IObservable UpstreamMessages => _upstreamSubject.Select(x => x.message); + public IObservable<(byte[] data, LegoWirelessMessage message)> UpstreamRawMessages => _upstreamSubject; + public IObservable UpstreamMessages => _upstreamSubject.Select(x => x.message); public IServiceProvider ServiceProvider { get; } - public PoweredUpProtocol(BluetoothKernel kernel, ILogger logger, IDeviceFactory deviceFactory, IServiceProvider serviceProvider) + public LegoWirelessProtocol(BluetoothKernel kernel, ILogger logger, IDeviceFactory deviceFactory, IServiceProvider serviceProvider) { ServiceProvider = serviceProvider; _kernel = kernel ?? throw new ArgumentNullException(nameof(kernel)); _logger = logger; _deviceFactory = deviceFactory ?? throw new ArgumentNullException(nameof(_deviceFactory)); - _upstreamSubject = new Subject<(byte[] data, PoweredUpMessage message)>(); + _upstreamSubject = new Subject<(byte[] data, LegoWirelessMessage message)>(); } public async Task ConnectAsync() @@ -49,7 +49,7 @@ await _kernel.ReceiveBytesAsync(async data => } catch (Exception e) { - _logger.LogError(e, "Exception in PoweredUpProtocol Decode/Knowledge"); + _logger.LogError(e, "Exception in LegoWirelessProtocol Decode/Knowledge"); throw; } @@ -61,7 +61,7 @@ public async Task DisconnectAsync() await _kernel.DisconnectAsync(); } - public async Task SendMessageAsync(PoweredUpMessage message) + public async Task SendMessageAsync(LegoWirelessMessage message) { try { @@ -73,7 +73,7 @@ public async Task SendMessageAsync(PoweredUpMessage message) } catch (Exception e) { - _logger.LogError(e, "Exception in PoweredUpProtocol Encode/Knowledge"); + _logger.LogError(e, "Exception in LegoWirelessProtocol Encode/Knowledge"); throw; } @@ -94,7 +94,7 @@ protected virtual void Dispose(bool disposing) } } - // ~PoweredUpProtocol() + // ~LegoWirelessProtocol() // { // Dispose(disposing: false); // } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/GenericErrorMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/GenericErrorMessage.cs index 0d3c05e..9d58a0c 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/GenericErrorMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/GenericErrorMessage.cs @@ -1,7 +1,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.9.1 - public class GenericErrorMessage : PoweredUpMessage + public class GenericErrorMessage : LegoWirelessMessage { public byte CommandType { get; set; } public ErrorCode ErrorCode { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/HubActionMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/HubActionMessage.cs index 52cf596..a46060c 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/HubActionMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/HubActionMessage.cs @@ -1,7 +1,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.6.1 - public class HubActionMessage : PoweredUpMessage + public class HubActionMessage : LegoWirelessMessage { public HubAction Action { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/HubAlertMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/HubAlertMessage.cs index b245a75..4188462 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/HubAlertMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/HubAlertMessage.cs @@ -1,7 +1,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.7.1 - public class HubAlertMessage : PoweredUpMessage + public class HubAlertMessage : LegoWirelessMessage { public HubAlert Alert { get; set; } public HubAlertOperation Operation { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/HubAttachedIOMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/HubAttachedIOMessage.cs index 4c12aa0..376c461 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/HubAttachedIOMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/HubAttachedIOMessage.cs @@ -3,7 +3,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.8.1 - public abstract class HubAttachedIOMessage : PoweredUpMessage + public abstract class HubAttachedIOMessage : LegoWirelessMessage { public byte PortId { get; set; } public HubAttachedIOEvent Event { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/HubPropertyMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/HubPropertyMessage.cs index 635361e..2badcb5 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/HubPropertyMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/HubPropertyMessage.cs @@ -5,7 +5,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.5.2 - public class HubPropertyMessage : PoweredUpMessage + public class HubPropertyMessage : LegoWirelessMessage { public HubProperty Property { get; set; } public HubPropertyOperation Operation { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PoweredUpMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/LegoWirelessMessage.cs similarity index 87% rename from src/SharpBrick.PoweredUp/Protocol/Messages/PoweredUpMessage.cs rename to src/SharpBrick.PoweredUp/Protocol/Messages/LegoWirelessMessage.cs index 1628211..e03de92 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PoweredUpMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/LegoWirelessMessage.cs @@ -3,7 +3,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.1 - public abstract class PoweredUpMessage + public abstract class LegoWirelessMessage { // spec chapter: 3.2 // encoded as byte or ushort diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInformationMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInformationMessage.cs index 4d8b350..08422c0 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInformationMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInformationMessage.cs @@ -3,7 +3,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.19.1 - public abstract class PortInformationMessage : PoweredUpMessage + public abstract class PortInformationMessage : LegoWirelessMessage { public byte PortId { get; set; } public PortInformationType InformationType { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInformationRequestMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInformationRequestMessage.cs index 5920875..b3acbb8 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInformationRequestMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInformationRequestMessage.cs @@ -1,7 +1,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.15.1 - public class PortInformationRequestMessage : PoweredUpMessage + public class PortInformationRequestMessage : LegoWirelessMessage { public byte PortId { get; set; } public PortInformationType InformationType { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatCombinedModeMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatCombinedModeMessage.cs index 49dadb7..b2d145c 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatCombinedModeMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatCombinedModeMessage.cs @@ -1,6 +1,6 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { - public class PortInputFormatCombinedModeMessage : PoweredUpMessage + public class PortInputFormatCombinedModeMessage : LegoWirelessMessage { public byte PortId { get; set; } public byte UsedCombinationIndex { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSetupCombinedModeMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSetupCombinedModeMessage.cs index 00ccd18..5034abe 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSetupCombinedModeMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSetupCombinedModeMessage.cs @@ -1,6 +1,6 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { - public class PortInputFormatSetupCombinedModeMessage : PoweredUpMessage + public class PortInputFormatSetupCombinedModeMessage : LegoWirelessMessage { public byte PortId { get; set; } public PortInputFormatSetupCombinedSubCommand SubCommand { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSetupSingleMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSetupSingleMessage.cs index 6f72d58..1d50111 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSetupSingleMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSetupSingleMessage.cs @@ -1,7 +1,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.17 - public class PortInputFormatSetupSingleMessage : PoweredUpMessage + public class PortInputFormatSetupSingleMessage : LegoWirelessMessage { public byte PortId { get; set; } public byte Mode { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSingleMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSingleMessage.cs index 644a811..de3a49f 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSingleMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortInputFormatSingleMessage.cs @@ -1,7 +1,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.23 - public class PortInputFormatSingleMessage : PoweredUpMessage + public class PortInputFormatSingleMessage : LegoWirelessMessage { public byte PortId { get; set; } public byte ModeIndex { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortModeInformationMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortModeInformationMessage.cs index 295b9d9..741df44 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortModeInformationMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortModeInformationMessage.cs @@ -1,7 +1,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.20.1 - public abstract class PortModeInformationMessage : PoweredUpMessage + public abstract class PortModeInformationMessage : LegoWirelessMessage { public byte PortId { get; set; } public byte Mode { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortModeInformationRequestMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortModeInformationRequestMessage.cs index 014c512..8e30967 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortModeInformationRequestMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortModeInformationRequestMessage.cs @@ -1,7 +1,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { // spec chapter: 3.16.1 - public class PortModeInformationRequestMessage : PoweredUpMessage + public class PortModeInformationRequestMessage : LegoWirelessMessage { public byte PortId { get; set; } public byte Mode { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortOutputCommandFeedbackMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortOutputCommandFeedbackMessage.cs index 78942de..84d6e5d 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortOutputCommandFeedbackMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortOutputCommandFeedbackMessage.cs @@ -2,7 +2,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { - public class PortOutputCommandFeedbackMessage : PoweredUpMessage + public class PortOutputCommandFeedbackMessage : LegoWirelessMessage { public PortOutputCommandFeedback[] Feedbacks { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortOutputCommandMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortOutputCommandMessage.cs index 24d3570..2eec7ea 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortOutputCommandMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortOutputCommandMessage.cs @@ -1,6 +1,6 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { - public abstract class PortOutputCommandMessage : PoweredUpMessage + public abstract class PortOutputCommandMessage : LegoWirelessMessage { public PortOutputCommandMessage(PortOutputSubCommand subCommand) { diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortValueCombinedModeMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortValueCombinedModeMessage.cs index dc07b6c..b971bdd 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortValueCombinedModeMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortValueCombinedModeMessage.cs @@ -1,6 +1,6 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { - public class PortValueCombinedModeMessage : PoweredUpMessage + public class PortValueCombinedModeMessage : LegoWirelessMessage { public byte PortId { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/PortValueSingleMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/PortValueSingleMessage.cs index 556d9d0..5fbdd43 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/PortValueSingleMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/PortValueSingleMessage.cs @@ -2,7 +2,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { - public class PortValueSingleMessage : PoweredUpMessage + public class PortValueSingleMessage : LegoWirelessMessage { public PortValueData[] Data { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/UnknownMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/UnknownMessage.cs index ba22b51..5389ce8 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/UnknownMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/UnknownMessage.cs @@ -2,7 +2,7 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { - public class UnknownMessage : PoweredUpMessage + public class UnknownMessage : LegoWirelessMessage { public byte[] Data { get; set; } diff --git a/src/SharpBrick.PoweredUp/Protocol/Messages/VirtualPortSetupMessage.cs b/src/SharpBrick.PoweredUp/Protocol/Messages/VirtualPortSetupMessage.cs index b17671f..8a08c1f 100644 --- a/src/SharpBrick.PoweredUp/Protocol/Messages/VirtualPortSetupMessage.cs +++ b/src/SharpBrick.PoweredUp/Protocol/Messages/VirtualPortSetupMessage.cs @@ -1,6 +1,6 @@ namespace SharpBrick.PoweredUp.Protocol.Messages { - public class VirtualPortSetupMessage : PoweredUpMessage + public class VirtualPortSetupMessage : LegoWirelessMessage { public VirtualPortSubCommand SubCommand { get; set; } } diff --git a/test/SharpBrick.PoweredUp.Test/Bluetooth/PoweredUpBluetoothAdapterMock.cs b/test/SharpBrick.PoweredUp.Test/Bluetooth/PoweredUpBluetoothAdapterMock.cs index f2bb8a9..c5ab69b 100644 --- a/test/SharpBrick.PoweredUp.Test/Bluetooth/PoweredUpBluetoothAdapterMock.cs +++ b/test/SharpBrick.PoweredUp.Test/Bluetooth/PoweredUpBluetoothAdapterMock.cs @@ -91,7 +91,7 @@ public Task WriteValueAsync(byte[] data) return Task.FromResult(true); } - public Task WriteUpstreamAsync(PoweredUpMessage message) + public Task WriteUpstreamAsync(LegoWirelessMessage message) => WriteUpstreamAsync(MessageEncoder.Encode(message, null)); public Task WriteUpstreamAsync(string message) diff --git a/test/SharpBrick.PoweredUp.Test/Devices/VoltageTest.cs b/test/SharpBrick.PoweredUp.Test/Devices/VoltageTest.cs index 3b05fd3..a529dfd 100644 --- a/test/SharpBrick.PoweredUp.Test/Devices/VoltageTest.cs +++ b/test/SharpBrick.PoweredUp.Test/Devices/VoltageTest.cs @@ -69,20 +69,20 @@ await mock.WriteUpstreamAsync(new PortInputFormatSingleMessage() } - internal (IPoweredUpProtocol protocol, PoweredUpBluetoothCharacteristicMock mock) CreateProtocolAndMock() + internal (ILegoWirelessProtocol protocol, PoweredUpBluetoothCharacteristicMock mock) CreateProtocolAndMock() { var serviceProvider = new ServiceCollection() .AddLogging() .AddSingleton() .AddSingleton() - .AddSingleton() + .AddSingleton() .AddSingleton() // for protocol knowledge init .BuildServiceProvider(); var poweredUpBluetoothAdapterMock = serviceProvider.GetService() as PoweredUpBluetoothAdapterMock; - var protocol = serviceProvider.GetService(); + var protocol = serviceProvider.GetService(); protocol.ConnectAsync().Wait(); diff --git a/test/SharpBrick.PoweredUp.Test/Protocol/Formatter/PortOutputCommandEncoderTest.cs b/test/SharpBrick.PoweredUp.Test/Protocol/Formatter/PortOutputCommandEncoderTest.cs index e2d28d8..0180949 100644 --- a/test/SharpBrick.PoweredUp.Test/Protocol/Formatter/PortOutputCommandEncoderTest.cs +++ b/test/SharpBrick.PoweredUp.Test/Protocol/Formatter/PortOutputCommandEncoderTest.cs @@ -281,7 +281,7 @@ public void PortOutputCommandEncoder_Encode_GenericWriteDirectModeDataMessage(st Data = data, }); - private void PortOutputCommandEncoder_Encode(string expectedDataAsString, PoweredUpMessage message) + private void PortOutputCommandEncoder_Encode(string expectedDataAsString, LegoWirelessMessage message) { // act var data = MessageEncoder.Encode(message, null);