Browse Source

加入ios通过uuid做过滤的代码

newdev_shunjiawei
fdp 1 year ago
parent
commit
95c4e863bd
  1. 2
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift
  2. 8
      local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleConst.swift
  3. 82
      local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift

2
local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift

@ -560,7 +560,7 @@ private func detectLanguage(from result: SPXSpeechRecognitionResult) -> String {
guard let self = self else { return }
while self.isRunning {
print("是否写入: \(self.isWriting)")
// print("是否写入: \(self.isWriting)")
if !self.isWriting {
usleep(10_000)
continue

8
local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleConst.swift

@ -24,6 +24,12 @@ class BleConst {
/** 客户端特征配置描述符UUID */
static let CLIENT_CHAR_CONFIG_UUID = CBUUID(string: "00002902-0000-1000-8000-00805f9b34fb")
/** 扫描服务UUID - 用于后台扫描过滤 */
static let SERVICE_UUID = CBUUID(string: "FD7B")
/** 扫描服务UUID1 - 用于后台扫描过滤 */
static let SERVICE_UUID1 = CBUUID(string: "FF11")
/** BLE扫描Action */
static let ACTION_SCAN_RESULT = "com.yunqiinnovation.ble_service.ACTION_BLE_SCAN"
@ -90,4 +96,4 @@ class BleConst {
static let AUDIO_CHANNEL_RIGHT: UInt8 = 0x02
/** 立体声 */
static let AUDIO_CHANNEL_STEREO: UInt8 = 0x03
}
}

82
local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift

@ -229,11 +229,14 @@ private var cmdReplyType: UInt8 = 0
isScanning = true
// 移除服务UUID过滤,扫描所有设备
// // 移除服务UUID过滤,扫描所有设备
// manager.scanForPeripherals(withServices: nil, options: [
// CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据
// ])
//let serviceUUIDs = [BleConst.SERVICE_UUID, BleConst.SERVICE_UUID1]
manager.scanForPeripherals(withServices: nil, options: [
CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据
CBCentralManagerScanOptionAllowDuplicatesKey: true
])
os_log("🔍 开始扫描所有BLE设备(无过滤),超时时间: %.1f秒", log: logger, type: .info, timeout)
// 设置扫描超时
@ -383,6 +386,7 @@ private var cmdReplyType: UInt8 = 0
// 遍历所有已发现的设备,查找匹配的设备名
for (deviceId, deviceInfo) in discoveredDevices {
print("deviceInfo: \(deviceInfo)")
if let name = deviceInfo["name"] as? String, name == deviceName {
// 获取对应的广播数据
var deviceData = deviceInfo
@ -1216,14 +1220,76 @@ extension BleService: CBCentralManagerDelegate {
os_log("📱 设备RSSI变化较大 - 名称: %{public}@, UUID: %{public}@, RSSI: %d → %d", log: logger, type: .debug, deviceName, deviceId, oldRssi, newRssi)
}
} else {
// 新设备,需要上报
// 新设备,需要上报并打印详细信息
shouldNotify = true
os_log("📱 发现新设备 - 名称: %{public}@, UUID: %{public}@", log: logger, type: .info, deviceName, deviceId)
// 打印 hex 数据 - 直接从 deviceInfo 获取
if let hex = deviceInfo["hex"] as? String {
os_log("📡 设备 hex 数据: %{public}@", log: logger, type: .info, hex)
// 打印详细的设备信息
os_log("📱 ===== 发现新BLE设备 =====", log: logger, type: .info)
os_log("📱 设备名称: %{public}@", log: logger, type: .info, deviceName)
os_log("📱 设备UUID(MAC地址): %{public}@", log: logger, type: .info, deviceId)
os_log("📱 RSSI信号强度: %d dBm", log: logger, type: .info, RSSI.intValue)
os_log("📱 发现时间: %{public}@", log: logger, type: .info, Date().description)
// 打印服务UUID信息
if let serviceUUIDs = advertisementData[CBAdvertisementDataServiceUUIDsKey] as? [CBUUID] {
var uuidDetails: [String] = []
for uuid in serviceUUIDs {
let uuidString = uuid.uuidString
// 检查是否为16位UUID(通常显示为4个字符)
if uuidString.count == 4 {
let fullUUID = "0000\(uuidString)-0000-1000-8000-00805F9B34FB"
uuidDetails.append("\(uuidString) (完整: \(fullUUID))")
} else {
uuidDetails.append(uuidString)
}
}
os_log("📱 服务UUIDs: %{public}@", log: logger, type: .info, uuidDetails.joined(separator: ", "))
os_log("📱 服务UUID数量: %d", log: logger, type: .info, serviceUUIDs.count)
} else {
os_log("📱 服务UUIDs: 无", log: logger, type: .info)
}
// 打印制造商数据
if let manufacturerData = advertisementData[CBAdvertisementDataManufacturerDataKey] as? Data {
let hexString = manufacturerData.map { String(format: "%02X", $0) }.joined(separator: " ")
os_log("📱 制造商数据: %{public}@", log: logger, type: .info, hexString)
} else {
os_log("📱 制造商数据: 无", log: logger, type: .info)
}
// 打印服务数据
if let serviceData = advertisementData[CBAdvertisementDataServiceDataKey] as? [CBUUID: Data] {
for (serviceUUID, data) in serviceData {
let hexString = data.map { String(format: "%02X", $0) }.joined(separator: " ")
os_log("📱 服务数据[%{public}@]: %{public}@", log: logger, type: .info, serviceUUID.uuidString, hexString)
}
} else {
os_log("📱 服务数据: 无", log: logger, type: .info)
}
// 打印本地名称
if let localName = advertisementData[CBAdvertisementDataLocalNameKey] as? String {
os_log("📱 本地名称: %{public}@", log: logger, type: .info, localName)
}
// 打印TX功率等级
if let txPowerLevel = advertisementData[CBAdvertisementDataTxPowerLevelKey] as? NSNumber {
os_log("📱 TX功率等级: %d dBm", log: logger, type: .info, txPowerLevel.intValue)
}
// 打印是否可连接
if let isConnectable = advertisementData[CBAdvertisementDataIsConnectable] as? NSNumber {
os_log("📱 可连接状态: %{public}@", log: logger, type: .info, isConnectable.boolValue ? "是" : "否")
}
// 打印完整的原始广播数据(十六进制)
if let hex = deviceInfo["hex"] as? String, !hex.isEmpty {
os_log("📱 原始广播数据(HEX): %{public}@", log: logger, type: .info, hex)
} else {
os_log("📱 原始广播数据(HEX): 无", log: logger, type: .info)
}
os_log("📱 =========================", log: logger, type: .info)
}
// 更新缓存(无论是否上报都要更新)

Loading…
Cancel
Save