Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds uid to PresentTag #18

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions LegoDimensions/LegoPortal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
private const int ReceiveTimeout = 2000;

// This needs to be static to keep the context otherwise, the app will close it
private static UsbContext context = null;

Check warning on line 26 in LegoDimensions/LegoPortal.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

// Class variables
private IUsbDevice _portal;
Expand Down Expand Up @@ -118,7 +118,7 @@
/// </summary>
/// <param name="device">A valid Lego Dimensions instance.</param>
/// <param name="id">An ID for this device, can be handy if you manage multiple ones.</param>
public LegoPortal(IUsbDevice device, int id = 0)

Check warning on line 121 in LegoDimensions/LegoPortal.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'SerialNumber' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
_portal = device;
Id = id;
Expand Down Expand Up @@ -400,7 +400,7 @@
/// <param name="password">The desired state, Automatic is the default value.</param>
/// <param name="index">The tag index.</param>
/// <param name="newPassword">The new 4 bytes password if any.</param>
public void SetTagPassword(PortalPassword password, byte index, byte[] newPassword = null)

Check warning on line 403 in LegoDimensions/LegoPortal.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
if (password == PortalPassword.Custom)
{
Expand Down Expand Up @@ -471,7 +471,7 @@

if (legoTag == null)
{
_presentTags.Add(new PresentTag((Pad)pad, tadType, padIndex));
_presentTags.Add(new PresentTag((Pad)pad, tadType, padIndex, uuid));
legoTag = new PadTag() { Pad = (Pad)pad, TagIndex = padIndex, Present = present, CardUid = uuid, TagType = tadType };
_padTag.Add(legoTag);

Expand All @@ -481,7 +481,7 @@
var msgToSend = new Message(MessageCommand.Read);
msgToSend.AddPayload(padIndex, (byte)0x24);
legoTag.LastMessageId = SendMessage(msgToSend);
_commandId.Add(new CommandId(legoTag.LastMessageId, MessageCommand.Read, null));

Check warning on line 484 in LegoDimensions/LegoPortal.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
}
else
{
Expand Down Expand Up @@ -589,7 +589,9 @@
_presentTags.Clear();
for (int i = 0; i < message.Payload.Length / 2; i++)
{
PresentTag presentTag = new PresentTag((Pad)(message.Payload[i * 2] >> 4), (TagType)message.Payload[i * 2 + 1], (byte)(message.Payload[i * 2] & 0xF));
var index = (byte)(message.Payload[i * 2] & 0xF);
var uid = _padTag.FirstOrDefault(x => x.TagIndex == index)?.CardUid ?? Array.Empty<byte>();
PresentTag presentTag = new PresentTag((Pad)(message.Payload[i * 2] >> 4), (TagType)message.Payload[i * 2 + 1], index, uid);
_presentTags.Add(presentTag);
}

Expand Down
9 changes: 8 additions & 1 deletion LegoDimensions/Tag/PresentTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public class PresentTag
/// <param name="pad">The pad the tag is on.</param>
/// <param name="tagType">The type or tag, normal or uninitialized.</param>
/// <param name="index">The index of the tag on the portal.</param>
public PresentTag(Pad pad, TagType tagType, byte index)
/// <param name="cardUid">The 7 bytes card UID.</param>
public PresentTag(Pad pad, TagType tagType, byte index, byte[] cardUid)
{
Pad = pad;
TagType = tagType;
Index = index;
CardUid = cardUid;
}

/// <summary>
Expand All @@ -37,6 +39,11 @@ public PresentTag(Pad pad, TagType tagType, byte index)
/// Gets or sets the index of the tag on the portal.
/// </summary>
public byte Index { get; set; }

/// <summary>
/// Gets or sets the 7 bytes card UID.
/// </summary>
public byte[] CardUid { get; set; }
}
}

2 changes: 1 addition & 1 deletion TestLegoDimensions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void TestListTags()
var tagList = portal.ListTags();
foreach (var tag in tagList)
{
Console.WriteLine($"Pad: {tag.Pad}, Index: {tag.Index}, Type: {tag.TagType}");
Console.WriteLine($"Pad: {tag.Pad}, Index: {tag.Index}, UID: {BitConverter.ToString(tag.CardUid)}, Type: {tag.TagType}");
}
}

Expand Down
Loading