From ef30b3595b5f54802ec71d1cdcaedabc194e93c0 Mon Sep 17 00:00:00 2001 From: liangzhenying <867174124@qq.com> Date: Tue, 5 Nov 2024 18:00:40 +0800 Subject: [PATCH] =?utf8?q?=E6=96=87=E4=BB=B6=E4=BC=A0=E8=BE=93=E5=8D=8F?= =?utf8?q?=E8=AE=AE=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../Example/AbilityViewController.swift | 4 +- .../IOTBluetooth/IOTBluetooth/IBAbility.swift | 12 ++--- .../IOTBluetooth/IBFileSender+Dial.swift | 2 +- .../IOTBluetooth/IBFileSender+Mp3.swift | 2 +- .../IOTBluetooth/IBFileSender+Ota.swift | 2 +- .../IOTBluetooth/IBFileSender.swift | 44 ++++++++++++++++++- .../IOTBluetooth/IOTBluetooth/IBNotify.swift | 4 +- .../IOTBluetooth/IBReceiveManager.swift | 2 + .../IOTBluetooth/IBluetooth.swift | 11 ++++- 9 files changed, 67 insertions(+), 16 deletions(-) diff --git a/IOTBluetooth/IOTBluetooth/Example/AbilityViewController.swift b/IOTBluetooth/IOTBluetooth/Example/AbilityViewController.swift index 5265b15..aca7796 100644 --- a/IOTBluetooth/IOTBluetooth/Example/AbilityViewController.swift +++ b/IOTBluetooth/IOTBluetooth/Example/AbilityViewController.swift @@ -104,7 +104,7 @@ extension AbilityViewController{ activityIndicatorView.startAnimating() IBFileSender().mp3(info).progress({ total, current in - print("\(total) : \(current)") +// print("\(total) : \(current)") }).response {[weak self] result in print(result) self?.activityIndicatorView.stopAnimating() @@ -155,7 +155,7 @@ extension AbilityViewController{ info.UID = 10002 info.files = [file] - info.theme = "黑暗" + info.theme = "黑暗001" // activityIndicatorView.startAnimating() IBFileSender().dial(info).progress({ total, current in diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift index 9fde543..68a1dbd 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift @@ -75,7 +75,7 @@ extension IBAbility { /// 长指令 case long = 0x02 /// 文件指令(用来发送文件,比如表盘、MP3、OTA等) - case file = 0x04 + case file = 0x06 /// Ai指令 case ai = 0x05 } @@ -444,7 +444,7 @@ public extension IBAbility { /// 发送MP3文件信息 /// - Parameter mp3: see ``IBMp3File`` - static let mp3 = IBAbility.file.id(0x21).parser(IBGeneralParser.self).checker(IBMp3Checker.self) + static let mp3 = IBAbility.file.id(0x07).parser(IBGeneralParser.self).checker(IBMp3Checker.self) // /// 发送自定义表盘文件汇总信息 // /// - Parameter customDial: see ``IBCustomDial`` @@ -452,15 +452,15 @@ public extension IBAbility { /// 发送表盘文件汇总信息 /// - Parameter dial: see ``IBDial`` - static let dial = IBAbility.file.id(0x22).parser(IBGeneralParser.self).checker(IBDialChecker.self) + static let dial = IBAbility.file.id(0x05).parser(IBGeneralParser.self).checker(IBDialChecker.self) /// 发送单个表盘文件信息 /// - Parameter dialFile: see ``IBDailFile`` - internal static let dialFile = IBAbility.file.id(0x24).parser(IBGeneralParser.self).checker(IBDialFileChecker.self) + internal static let dialFile = IBAbility.file.id(0x06).parser(IBGeneralParser.self).checker(IBDialFileChecker.self) /// 发送文件校验码 /// - Parameter value:Int - internal static let fileCheckCode = IBAbility.file.id(0x23).parser(IBGeneralParser.self).checker(IBValueChecker.self) + internal static let fileCheckCode = IBAbility.file.id(0x08).parser(IBGeneralParser.self).checker(IBValueChecker.self) /// 删除指定文件 /// - Parameter deleteFile: see ``IBDeleteFile`` @@ -472,7 +472,7 @@ public extension IBAbility { /// 发送OTA文件信息 /// - Parameter ota: see ``IBOtaFile`` - static let ota = IBAbility.file.id(0x20).parser(IBGeneralParser.self).checker(IBOtaChecker.self) + static let ota = IBAbility.file.id(0x01).parser(IBGeneralParser.self).checker(IBOtaChecker.self) /// 发送EPO文件信息 diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Dial.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Dial.swift index ad202dd..ede2f01 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Dial.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Dial.swift @@ -84,7 +84,7 @@ extension IBFileSender{ guard let self = self else { return } self.lastData = nil if result.isSuccess { - self.current += data.count + self.current += data.count - 18 Logger.log("\(total) : \(current)") self.progress?(self.total,self.current) self.sendContentDial() diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Mp3.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Mp3.swift index 0090746..f8de145 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Mp3.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Mp3.swift @@ -51,7 +51,7 @@ extension IBFileSender{ guard let self = self else { return } self.lastData = nil if result.isSuccess { - self.current += data.count + self.current += data.count - 18 Logger.log("\(total) : \(current)") self.progress?(self.total,self.current) self.sendContentMp3() diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Ota.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Ota.swift index 79e4d7d..0df56a4 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Ota.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender+Ota.swift @@ -50,7 +50,7 @@ extension IBFileSender{ guard let self = self else { return } self.lastData = nil if result.isSuccess { - self.current += data.count + self.current += data.count - 18 Logger.log("\(total) : \(current)") self.progress?(self.total,self.current) self.sendContentOta() diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender.swift index f36d7bf..4a8b354 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBFileSender.swift @@ -107,11 +107,32 @@ extension IBFileSender{ // filePath = path // } } +// func readFile(from path:String) ->([Data]?,Int,Int){ +// let fileURL = URL(fileURLWithPath: path) +// do { +// let data = try Data(contentsOf:fileURL) +// let seg = 495 +// var list = [Data]() +// for i in stride(from: 0, to: data.count, by: seg) { +// if i+seg < data.count { +// list.append(data[i ... i+seg - 1]) +// } +// else{ +// list.append(data[i ... data.count - 1]) +// } +// } +// let lrc = LRC.calculateLRC(data.bytes).int +// return (list,data.count,lrc) +// } catch { +// return (nil,0,0) +// } +// } + func readFile(from path:String) ->([Data]?,Int,Int){ let fileURL = URL(fileURLWithPath: path) do { let data = try Data(contentsOf:fileURL) - let seg = 495 + let seg = 492 var list = [Data]() for i in stride(from: 0, to: data.count, by: seg) { if i+seg < data.count { @@ -121,8 +142,27 @@ extension IBFileSender{ list.append(data[i ... data.count - 1]) } } + + var fullList = [Data](); + for i in 0..20) let writeBigCharacteristicUUID: String = "2AE4" /// Write 特征值(发送文件OAT、MP3等) -let writeFileCharacteristicUUID: String = "2AE0" +let writeFileCharacteristicUUID: String = "2AE6" +let writeFileResponseUUID: String = "2AE7" class IBBluetooth: NSObject { static let shared = IBBluetooth() @@ -293,6 +294,11 @@ extension IBBluetooth: CBPeripheralDelegate { if $0.uuid.uuidString == writeFileCharacteristicUUID { writeFileCharacteristic = $0 + peripheral.setNotifyValue(true, for: $0) + return + } + if $0.uuid.uuidString == writeFileResponseUUID { + peripheral.setNotifyValue(true, for: $0) return } } @@ -304,6 +310,9 @@ extension IBBluetooth: CBPeripheralDelegate { if let error = error { Logger.log(error) } + if let data = characteristic.value { + Logger.log( "[receive] \(characteristic.uuid.uuidString)" + data.joined(" ")) + } receiveManager.receice(characteristic: characteristic) } -- 2.17.1