Skip to content

CADA RaceCar - support latest hw revision#208

Draft
vicocz wants to merge 6 commits intodefaultfrom
local/cada-racecar-rev2
Draft

CADA RaceCar - support latest hw revision#208
vicocz wants to merge 6 commits intodefaultfrom
local/cada-racecar-rev2

Conversation

@vicocz
Copy link
Owner

@vicocz vicocz commented Mar 7, 2026

Rework of #205

@vicocz vicocz added the bug Something isn't working label Mar 7, 2026
@vicocz vicocz added this to the 2026.1 milestone Mar 7, 2026
@vicocz vicocz requested a review from Copilot March 7, 2026 15:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +36 to 37
//TODO var intValue = (int)(value * 0x7F); // scale and cast

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
//TODO var intValue = (int)(value * 0x7F); // scale and cast

Copilot uses AI. Check for mistakes.
Comment on lines +59 to 65
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;
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants