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()
info.UID = 10002
info.files = [file]
- info.theme = "黑暗"
+ info.theme = "黑暗001"
// activityIndicatorView.startAnimating()
IBFileSender().dial(info).progress({ total, current in
/// 长指令
case long = 0x02
/// 文件指令(用来发送文件,比如表盘、MP3、OTA等)
- case file = 0x04
+ case file = 0x06
/// Ai指令
case ai = 0x05
}
/// 发送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``
/// 发送表盘文件汇总信息
/// - 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``
/// 发送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文件信息
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()
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()
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()
// 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 {
list.append(data[i ... data.count - 1])
}
}
+
+ var fullList = [Data]();
+ for i in 0..<list.count {
+ /// 分包数
+ let packageCount = list.count
+ /// 数据包总长度
+ let dataTotalLength = data.count
+ /// 数据包长度
+ let dataLength = list[i].count
+ /// 数据包索引
+ let index = i
+
+ var bytes: [UInt8] = [0x73, 0x06, 0x02]
+ bytes = bytes + packageCount.byte4 + dataTotalLength.byte4 + index.byte4 + dataLength.byte2
+ bytes = bytes + list[i].bytes + [LRC.calculateLRC(list[i].bytes)]
+
+ fullList.append(bytes.data)
+ }
+
let lrc = LRC.calculateLRC(data.bytes).int
- return (list,data.count,lrc)
+ return (fullList,data.count,lrc)
} catch {
return (nil,0,0)
}
let result = IBGeneralParser.dataPacket(data)
let code = result.int
let desc = ["安装失败","安装成功"]
- Logger.log("表盘安装状态:",desc[code])
+ Logger.log("安装状态:",desc[code])
return true
}
//手表询问APP AI模型是否可用
return true
}
//文件已接收完成
- if data.bytes[1] == 0x05 && data.bytes[2] == 0x20 {
+ if data.bytes[1] == 0x06 && data.bytes[2] == 0x03 {
let result = IBGeneralParser.dataPacket(data)
IBBluetooth.shared.fileSender?.sendFileResult(result[0].int == 1)
return true
func receice(characteristic: CBCharacteristic){
+
+
guard let data = characteristic.value else { return }
if(data.count == 2 && data.int == 0){
// Logger.log("收到0000指令异常")
/// Write 特征值(发送字节数>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()
if $0.uuid.uuidString == writeFileCharacteristicUUID {
writeFileCharacteristic = $0
+ peripheral.setNotifyValue(true, for: $0)
+ return
+ }
+ if $0.uuid.uuidString == writeFileResponseUUID {
+ peripheral.setNotifyValue(true, for: $0)
return
}
}
if let error = error {
Logger.log(error)
}
+ if let data = characteristic.value {
+ Logger.log( "[receive] \(characteristic.uuid.uuidString)" + data.joined(" "))
+ }
receiveManager.receice(characteristic: characteristic)
}