Commit 079b41b8f92caa91ce9595eaea70a361c98068f9
1 parent
3cba738e
feat:query device info
Showing
3 changed files
with
20 additions
and
1 deletions
HDFwear/Tools/BleMessage+Function.swift
... | ... | @@ -13,6 +13,11 @@ extension BleMessage { |
13 | 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 | 21 | func getTimeCmd() -> Data { |
17 | 22 | let date = DateInRegion().date |
18 | 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
HDFwear/Tools/BluetoothManager+Function.swift
... | ... | @@ -15,6 +15,20 @@ extension BluetoothManager { |
15 | 15 | // self.setCmdClosure = completion |
16 | 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 | 33 | func newSetTime(completion: ((_ error: Int?) -> ())? = nil) { |
20 | 34 | let data = BleMessage.shared.getTimeCmd() | ... | ... |