|
|
|
@ -834,7 +834,7 @@ private var cmdReplyType: UInt8 = 0 |
|
|
|
private func sendCommand(_ cmd: UInt8, data: Data = Data()) -> Bool { |
|
|
|
guard let characteristic = writeCharacteristic, |
|
|
|
connectionState == BleConst.STATE_CONNECTED else { |
|
|
|
os_log("发送命令失败: 设备未连接", log: logger, type: .error) |
|
|
|
os_log("liwei---- 发送命令失败: 设备未连接", log: logger, type: .error) |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
@ -862,7 +862,7 @@ private var cmdReplyType: UInt8 = 0 |
|
|
|
if !data.isEmpty { |
|
|
|
dataHexString = data.map { String(format: "0x%02X", $0) }.joined(separator: ", ") |
|
|
|
} |
|
|
|
os_log("发送命令: CMD=0x%02X, 长度=%d, 数据=[%@], CRC=0x%02X", |
|
|
|
os_log("liwei---- 发送命令: CMD=0x%02X, 长度=%d, 数据=[%@], CRC=0x%02X", |
|
|
|
log: logger, type: .debug, cmd, cmdLength, dataHexString, crc) |
|
|
|
|
|
|
|
|
|
|
|
@ -881,7 +881,7 @@ private var cmdReplyType: UInt8 = 0 |
|
|
|
|
|
|
|
return true |
|
|
|
} catch { |
|
|
|
os_log("发送命令异常: %@", log: logger, type: .error, error.localizedDescription) |
|
|
|
os_log("liwei---- 发送命令异常: %@", log: logger, type: .error, error.localizedDescription) |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
@ -929,19 +929,17 @@ private var cmdReplyType: UInt8 = 0 |
|
|
|
/// - Returns: 可用于追加写入的 RecordingFile 实例 |
|
|
|
/// - Throws: 不抛出;若创建文件失败将导致后续写入无效 |
|
|
|
private func ensureOpusRecordingStarted(fileName: String) -> RecordingFile { |
|
|
|
if recordingFile == nil { |
|
|
|
let recorder = RecordingFile() |
|
|
|
let recorder = recordingFile ?? RecordingFile() |
|
|
|
if recorder.fileName.isEmpty { |
|
|
|
recorder.fileName = fileName |
|
|
|
recordingFile = recorder |
|
|
|
} else if (recordingFile?.fileName.isEmpty ?? true) { |
|
|
|
recordingFile?.fileName = fileName |
|
|
|
} |
|
|
|
|
|
|
|
if recordingFile?.isRecording() != true { |
|
|
|
recordingFile?.createFile() |
|
|
|
if !recorder.isRecording() { |
|
|
|
recorder.createFile() |
|
|
|
} |
|
|
|
|
|
|
|
return recordingFile! |
|
|
|
recordingFile = recorder |
|
|
|
return recorder |
|
|
|
} |
|
|
|
|
|
|
|
/// 停止并释放 Opus 落盘资源 |
|
|
|
@ -1010,7 +1008,7 @@ private var cmdReplyType: UInt8 = 0 |
|
|
|
|
|
|
|
// 记录响应详情 |
|
|
|
var hexString = data.map { String(format: "0x%02X", $0) }.joined(separator: ", ") |
|
|
|
os_log("收到设备响应: %@", log: logger, type: .debug, hexString) |
|
|
|
os_log("liwei---- 收到设备响应: %@", log: logger, type: .debug, hexString) |
|
|
|
|
|
|
|
// 检查数据长度(与 Android 统一失败判定保持一致) |
|
|
|
if data.count != Int(length) + 4 { // 帧头 + 命令 + 长度 + 数据 + CRC |
|
|
|
|