Skip to content

Commit

Permalink
Merge pull request #591 from WildernessLabs/AddCompanyIDToBluetooth
Browse files Browse the repository at this point in the history
Allow the user to set the company assigned number.
  • Loading branch information
ctacke authored Dec 4, 2024
2 parents 21696a3 + f6b4530 commit 83f09d8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Source/Meadow.Core/Gateways/Bluetooth/Definitions/Definition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public class Definition : IDefinition
/// </summary>
public string DeviceName { get; }

/// <summary>
/// Gets the company ID.
/// </summary>
public ushort? CompanyId { get; }

/// <summary>
/// Gets the collection of services associated with this device definition.
/// </summary>
Expand All @@ -23,6 +28,21 @@ public class Definition : IDefinition
public Definition(string deviceName, params IService[] services)
{
DeviceName = deviceName;
CompanyId = null;
Services = new ServiceCollection();
Services.AddRange(services);
}

/// <summary>
/// Initializes a new instance of the <see cref="Definition"/> class with the specified device name and services.
/// </summary>
/// <param name="companyId">The company ID (assigned number).</param>
/// <param name="deviceName">The name of the device.</param>
/// <param name="services">The services associated with the device.</param>
public Definition(ushort companyId, string deviceName, params IService[] services)
{
DeviceName = deviceName;
CompanyId = companyId;
Services = new ServiceCollection();
Services.AddRange(services);
}
Expand All @@ -38,6 +58,11 @@ public string ToJson()
""deviceName"":""{DeviceName}""
";

if (CompanyId != null)
{
json += $@", ""companyIdentifier"":{CompanyId}";
}

if (Services != null && Services.Count > 0)
{
json += ", \"services\": [";
Expand All @@ -58,4 +83,4 @@ public string ToJson()
json += "}";
return json;
}
}
}

0 comments on commit 83f09d8

Please sign in to comment.