Commit 079b41b8f92caa91ce9595eaea70a361c98068f9

Authored by daifengyi
1 parent 3cba738e

feat:query device info

HDFwear/Tools/BleMessage+Function.swift
@@ -13,6 +13,11 @@ extension BleMessage { @@ -13,6 +13,11 @@ extension BleMessage {
13 return createDataPacket(key: .response, bytes: bytes) 13 return createDataPacket(key: .response, bytes: bytes)
14 } 14 }
15 15
  16 + func getQueryDeviceInfoCmd(queryItems: [UInt8]) -> Data {
  17 + let bytes: [UInt8] = [UInt8(queryItems.count)] + queryItems
  18 + return createDataPacket(key: .setTimeFormat, bytes: bytes)
  19 + }
  20 +
16 func getTimeCmd() -> Data { 21 func getTimeCmd() -> Data {
17 let date = DateInRegion().date 22 let date = DateInRegion().date
18 let timeBytes: [UInt8] = [UInt8(date.year%100), UInt8(date.month), UInt8(date.day), UInt8(date.hour), UInt8(date.minute), UInt8(date.second)] 23 let timeBytes: [UInt8] = [UInt8(date.year%100), UInt8(date.month), UInt8(date.day), UInt8(date.hour), UInt8(date.minute), UInt8(date.second)]
HDFwear/Tools/Bluetooth+Types.swift
@@ -116,7 +116,7 @@ enum SetCmd: UInt8 { @@ -116,7 +116,7 @@ enum SetCmd: UInt8 {
116 116
117 enum NewCmd: UInt8 { 117 enum NewCmd: UInt8 {
118 case response = 0x01 118 case response = 0x01
119 -// case queryDevice = 0x02 119 + case queryDeviceInfo = 0x02
120 // case ota = 0x07 120 // case ota = 0x07
121 case setTime = 0x09 121 case setTime = 0x09
122 case setTimeFormat = 0x10 122 case setTimeFormat = 0x10
HDFwear/Tools/BluetoothManager+Function.swift
@@ -15,6 +15,20 @@ extension BluetoothManager { @@ -15,6 +15,20 @@ extension BluetoothManager {
15 // self.setCmdClosure = completion 15 // self.setCmdClosure = completion
16 sendData(data) 16 sendData(data)
17 } 17 }
  18 +
  19 + // 查询设备信息
  20 + // 0x01 设备ID
  21 + // 0x02 设备名称
  22 + // 0x03 设备mac地址
  23 + // 0x04 MCU版本号
  24 + // 0x05 电量
  25 + // 例如[0x02, 0x03]表示查询设备名称和设备mac地址
  26 + func queryDeviceInfo(queryItems: [UInt8], completion: ((_ error: Int?) -> ())? = nil) {
  27 + let data = BleMessage.shared.getQueryDeviceInfoCmd(queryItems: queryItems)
  28 + self.setCmdClosure = completion
  29 + sendData(data)
  30 + }
  31 +
18 // 设置时间 32 // 设置时间
19 func newSetTime(completion: ((_ error: Int?) -> ())? = nil) { 33 func newSetTime(completion: ((_ error: Int?) -> ())? = nil) {
20 let data = BleMessage.shared.getTimeCmd() 34 let data = BleMessage.shared.getTimeCmd()