gpt4 book ai didi

c# - BluetoothLEAdvertisementDataSection (ArgumentException)

转载 作者:行者123 更新时间:2023-11-30 16:04:15 24 4
gpt4 key购买 nike

我正在尝试为 Eddystone 信标做广告,但我的代码在 advertisementData.Data 处失败并出现 ArgumentException:

Value does not fall within the expected range.

对正在发生的事情有什么想法吗?

// ...
using (var memoryStream = new MemoryStream())
{
byte messageLengthByte = Convert.ToByte(message.Length);
memoryStream.WriteByte(messageLengthByte);

memoryStream.Write(message, 0, message.Length);

fullMessage = memoryStream.ToArray();
}

while (fullMessage.Length < 32)
{
byte[] newArray = new byte[fullMessage.Length + 1];
fullMessage.CopyTo(newArray, 0);
newArray[fullMessage.Length] = 0x00;
fullMessage = newArray;
}

var writer = new DataWriter();
writer.WriteBytes(fullMessage);

var advertisementData = new BluetoothLEAdvertisementDataSection();
advertisementData.Data = writer.DetachBuffer(); // Error!
publisher.Advertisement.DataSections.Add(advertisementData);
publisher.Start();

最佳答案

很可能您正试图容纳比 BLE 数据包允许的更多的字节。最大大小为 32 字节,但这包括:

  • 3 个字节用于“标志”数据部分,我认为这是强制性的并且可能由 Windows 10 BLE API 自动设置
  • 对于每个额外的节,节的长度为 1 个字节,节的类型为 1 个字节

如果您只广播一个部分,那么该部分的实际有效负载将剩下 27 个字节。

关于c# - BluetoothLEAdvertisementDataSection (ArgumentException),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35320586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com