Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to add support for the latest CaDA RaceCar hardware revision (Rev2) by extending CaDA device discovery and introducing an encoder abstraction for generating protocol-specific advertising payloads.
Changes:
- Extend CaDA device scanning to recognize a new Rev2 manufacturer data format.
- Introduce
IMessageEncoder/ factory + two encoder implementations (classic + Rev2) with unit tests. - Move CaDA registrations to the vendor-module pattern and broaden WinUI scan handling to include non-connectable advertisements.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| BrickController2/BrickController2/Protocols/CaDAProtocol.cs | Changes Encrypt to accept Span<byte> (call-site flexibility). |
| BrickController2/BrickController2/DeviceManagement/DI/DeviceManagementModule.cs | Removes direct CaDA registrations; relies on vendor modules for registration. |
| BrickController2/BrickController2/DeviceManagement/CaDA/RaceCarMessageEncoderRev2.cs | Adds Rev2 payload encoding logic (checksum/XOR + sequence handling). |
| BrickController2/BrickController2/DeviceManagement/CaDA/RaceCarMessageEncoder.cs | Adds classic payload encoding logic extracted into an encoder class. |
| BrickController2/BrickController2/DeviceManagement/CaDA/MessageEncoderFactory.cs | Adds a factory to choose the appropriate encoder based on device data length. |
| BrickController2/BrickController2/DeviceManagement/CaDA/IMessageEncoderFactory.cs | Introduces factory interface for encoder creation. |
| BrickController2/BrickController2/DeviceManagement/CaDA/IMessageEncoder.cs | Introduces encoder interface returning payload bytes to advertise. |
| BrickController2/BrickController2/DeviceManagement/CaDA/ICaDADeviceManager.cs | Adds CaDA-specific manager interface (exposes AppId). |
| BrickController2/BrickController2/DeviceManagement/CaDA/CaDARaceCar.cs | Minor visibility change; still contains classic telegram generation logic. |
| BrickController2/BrickController2/DeviceManagement/CaDA/CaDADeviceManager.cs | Adds Rev2 detection path and exposes AppId via ICaDADeviceManager. |
| BrickController2/BrickController2/DeviceManagement/CaDA/CaDA.cs | Registers CaDA devices/managers via the vendor module mechanism. |
| BrickController2/BrickController2.WinUI/Extensions/AdvertismentExtensions.cs | Allows processing non-connectable advertisements as data carriers. |
| BrickController2/BrickController2.Tests/DeviceManagement/CaDA/RaceCarMessageEncoderTests.cs | Adds unit tests for classic encoder behavior. |
| BrickController2/BrickController2.Tests/DeviceManagement/CaDA/RaceCarMessageEncoderRev2Tests.cs | Adds unit tests for Rev2 encoder behavior. |
| BrickController2/BrickController2.Tests/DeviceManagement/CaDA/PlatformService.cs | Adds test scaffolding for CaDA platform service behavior. |
| BrickController2/BrickController2.Tests/DeviceManagement/CaDA/MessageEncoderFactoryTests.cs | Adds unit tests for encoder selection based on device data size. |
| BrickController2/BrickController2.Tests/DeviceManagement/CaDA/CaDARaceCarTests.cs | Adds an (currently disabled) Rev2-oriented device test scaffold. |
| BrickController2/BrickController2.Tests/DeviceManagement/CaDA/CaDADeviceManagerTests.cs | Expands tests to cover Rev2 scan detection + AppId handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
BrickController2/BrickController2.Tests/DeviceManagement/CaDA/CaDARaceCarTests.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2/DeviceManagement/CaDA/CaDADeviceManager.cs
Show resolved
Hide resolved
BrickController2/BrickController2/DeviceManagement/CaDA/CaDADeviceManager.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2/DeviceManagement/CaDA/RaceCarMessageEncoder.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.Tests/DeviceManagement/CaDA/RaceCarMessageEncoderTests.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2/DeviceManagement/CaDA/CaDARaceCar.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2/DeviceManagement/CaDA/MessageEncoderFactory.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2/DeviceManagement/CaDA/RaceCarMessageEncoderRev2.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2/DeviceManagement/CaDA/RaceCarMessageEncoderRev2.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2/DeviceManagement/CaDA/RaceCarMessageEncoder.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
BrickController2/BrickController2/DeviceManagement/CaDA/MessageEncoderFactory.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.Tests/DeviceManagement/CaDA/CaDARaceCarTests.cs
Outdated
Show resolved
Hide resolved
...ntroller2/BrickController2.iOS/PlatformServices/DeviceManagement/CaDA/CaDAPlatformService.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.Tests/DeviceManagement/CaDA/PlatformService.cs
Show resolved
Hide resolved
| //TODO var intValue = (int)(value * 0x7F); // scale and cast | ||
|
|
There was a problem hiding this comment.
Leftover //TODO in production code. Either remove it or implement the intended scaling/conversion (or add a clarifying comment that this is intentionally unused) to avoid shipping dead code markers.
| //TODO var intValue = (int)(value * 0x7F); // scale and cast |
| protected internal bool TryGetTelegram(bool getConnectTelegram, out byte[] currentData) | ||
| { | ||
| ushort random = (ushort)_rnd.Next(ushort.MinValue, ushort.MaxValue); | ||
|
|
||
| byte[] channelDataArray; | ||
|
|
||
| lock (_outputLock) | ||
| { | ||
| channelDataArray = new byte[]// 8 | ||
| { | ||
| (byte)(random & 0xFF), | ||
| (byte)((random >> 8) & 0xFF), | ||
| (byte)Math.Max(0, Math.Min(0x80 - _outputValues[0], 0xFF)), // speed value - reversed | ||
| (byte)Math.Max(0, Math.Min(0x80 + _outputValues[1], 0xFF)), // | ||
| (byte)Math.Max(0, Math.Min(0x80 + _outputValues[2], 0xFF)), // light on/off | ||
| 0, | ||
| 0, | ||
| 0 | ||
| }; | ||
| } | ||
|
|
||
| CaDAProtocol.Encrypt(channelDataArray); | ||
|
|
||
| Array.Copy(channelDataArray, 0, _controlDataArray, 8, 8); | ||
|
|
||
| _controlDataArray[0] = 0x75; // 0x75 (117) | ||
| _controlDataArray[1] = 0x13; // 0x13 (19); | ||
| _outputValues.TryGetValues(out var outputValues); | ||
| currentData = _messageEncoder.Encode(outputValues, getConnectTelegram); | ||
|
|
||
| return _cadaPlatformService.TryGetRfPayload(_controlDataArray, out currentData); | ||
| return true; | ||
| } |
There was a problem hiding this comment.
TryGetTelegram ignores the boolean returned by _outputValues.TryGetValues and always returns true. That bypasses OutputValuesGroup's change/resend signaling, and can cause UpdateAdvertisedDataAsync to run even when there is nothing new to apply (e.g., reconnect/connect-mode transitions). Consider returning getConnectTelegram || _outputValues.TryGetValues(...) (and only encoding when needed) so the handler can skip unnecessary updates.
BrickController2/BrickController2/DeviceManagement/CaDA/RaceCarMessageEncoder.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
...ntroller2/BrickController2.iOS/PlatformServices/DeviceManagement/CaDA/CaDAPlatformService.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.Tests/DeviceManagement/CaDA/PlatformService.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.Tests/DeviceManagement/CaDA/CaDARaceCarTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| @@ -0,0 +1,121 @@ | |||
| using System; | |||
|
|
|||
| using static System.Half; // for convenient usage of Half constants like 0.5h | |||
There was a problem hiding this comment.
The comment suggests Half literals like 0.5h, but C# doesn’t support an h literal suffix. Consider rewording this comment (or removing it) to avoid implying a non-existent syntax; the code already uses explicit (Half) casts.
| using static System.Half; // for convenient usage of Half constants like 0.5h | |
| using static System.Half; // for convenient usage of Half members and predefined constants |
Rework of #205