使用 bluetooth_low_energy插件 使用蓝牙广播 ,安卓发送数据,通过 nRF52840 可以接收到是 13个值16位列表 但是ios发送数据 只是发送了一个 128位的值 ,是13个值中的第一个 ,但我使用别的 ios app 发送蓝牙广播 可以发送13个值16位列表


class UuidManager {
// 动态生成 UUID,从广播包的十六进制字符串中截取
static List<String> getDynamicServiceUuids({
required int deviceId,
required int opCode,
required String broadcastPacketHex,
}) {
List<String> dynamicUuids = [];
String protocolString =
broadcastPacketHex.padLeft(52, '0').substring(0, 52);
// 从协议字符串中每 2 字节截取生成动态 UUID
for (int i = 0; i < protocolString.length; i += 4) {
int end = i + 4;
if (end > protocolString.length) {
end = protocolString.length;
}
// 2 字节作为一个 UUID 部分
String uuidPart = protocolString.substring(i, end);
// 如果不足2 字节,用 0 填充
if (uuidPart.length < 4) {
uuidPart = uuidPart.padRight(4, '0');
}
dynamicUuids.add(uuidPart.toUpperCase());
}
while (dynamicUuids.length < 13) {
// 当数据不足时,用0000填充剩余UUID
dynamicUuids.add('0000');
}
int seed = (deviceId ^ opCode ^ dynamicUuids.length) & 0xFFFF;
// 交换高低位
int swappedSeed = ((seed & 0xFF) << 8) | ((seed >> 8) & 0xFF);
String uuid = swappedSeed.toRadixString(16).padLeft(4, '0').toUpperCase();
if (dynamicUuids.length > 13) {
dynamicUuids = dynamicUuids.sublist(0, 13);
}
// 调试日志
debugPrint(
'UuidManager生成的动态UUID列表 (数量: ${dynamicUuids.length}): $dynamicUuids');
return dynamicUuids;
}
}
// 将2字节值转换为16位蓝牙UUID
UUID _convertToBluetoothUUID(int twoByteValue) {
int swappedValue =
((twoByteValue & 0xFF) << 8) | ((twoByteValue >> 8) & 0xFF);
return UUID.short(swappedValue);
}
// 动态城市uuid列表
List<UUID> uuidList = UuidManager.getDynamicServiceUuids(
deviceId: _currentDeviceId!,
opCode: opCode,
broadcastPacketHex: broadcastPacketHex)
.map((uuid16) {
int twoByteValue = int.parse(uuid16, radix: 16);
return _convertToBluetoothUUID(twoByteValue);
}).toList();
// 广播名称,包含操作码和广播包十六进制字符串
final Advertisement advertisement = Advertisement(
name: 'MS',
serviceUUIDs: uuidList,
);
代码是生成的uuid