diff --git a/HDFwear/Tools/BleMessage+Function.swift b/HDFwear/Tools/BleMessage+Function.swift index 0d943cb..cc16016 100644 --- a/HDFwear/Tools/BleMessage+Function.swift +++ b/HDFwear/Tools/BleMessage+Function.swift @@ -13,6 +13,11 @@ extension BleMessage { return createDataPacket(key: .response, bytes: bytes) } + func getQueryDeviceInfoCmd(queryItems: [UInt8]) -> Data { + let bytes: [UInt8] = [UInt8(queryItems.count)] + queryItems + return createDataPacket(key: .setTimeFormat, bytes: bytes) + } + func getTimeCmd() -> Data { let date = DateInRegion().date let timeBytes: [UInt8] = [UInt8(date.year%100), UInt8(date.month), UInt8(date.day), UInt8(date.hour), UInt8(date.minute), UInt8(date.second)] diff --git a/HDFwear/Tools/Bluetooth+Types.swift b/HDFwear/Tools/Bluetooth+Types.swift index aeed09d..8eec953 100644 --- a/HDFwear/Tools/Bluetooth+Types.swift +++ b/HDFwear/Tools/Bluetooth+Types.swift @@ -116,7 +116,7 @@ enum SetCmd: UInt8 { enum NewCmd: UInt8 { case response = 0x01 -// case queryDevice = 0x02 + case queryDeviceInfo = 0x02 // case ota = 0x07 case setTime = 0x09 case setTimeFormat = 0x10 diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index a206ca9..63f0e70 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -15,6 +15,20 @@ extension BluetoothManager { // self.setCmdClosure = completion sendData(data) } + + // 查询设备信息 + // 0x01 设备ID + // 0x02 设备名称 + // 0x03 设备mac地址 + // 0x04 MCU版本号 + // 0x05 电量 + // 例如[0x02, 0x03]表示查询设备名称和设备mac地址 + func queryDeviceInfo(queryItems: [UInt8], completion: ((_ error: Int?) -> ())? = nil) { + let data = BleMessage.shared.getQueryDeviceInfoCmd(queryItems: queryItems) + self.setCmdClosure = completion + sendData(data) + } + // 设置时间 func newSetTime(completion: ((_ error: Int?) -> ())? = nil) { let data = BleMessage.shared.getTimeCmd()