Commit 3cba738e8f810edcb38bd178fcc55600e1e619f3
1 parent
37775d8e
feat:response
Showing
3 changed files
with
12 additions
and
1 deletions
HDFwear/Tools/BleMessage+Function.swift
... | ... | @@ -8,6 +8,11 @@ |
8 | 8 | import SwiftDate |
9 | 9 | |
10 | 10 | extension BleMessage { |
11 | + func getResponseCmd(frameNumber: [UInt8], messageId: [UInt8], success: Bool) -> Data { | |
12 | + let bytes: [UInt8] = frameNumber + messageId + (success ? [0x00] : [0x01]) | |
13 | + return createDataPacket(key: .response, bytes: bytes) | |
14 | + } | |
15 | + | |
11 | 16 | func getTimeCmd() -> Data { |
12 | 17 | let date = DateInRegion().date |
13 | 18 | 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
... | ... | @@ -9,6 +9,12 @@ import SwiftDate |
9 | 9 | |
10 | 10 | |
11 | 11 | extension BluetoothManager { |
12 | + // 通用应答 | |
13 | + func response(frameNumber: [UInt8], messageId: [UInt8], success: Bool, completion: ((_ error: Int?) -> ())? = nil) { | |
14 | + let data = BleMessage.shared.getResponseCmd(frameNumber: frameNumber, messageId: messageId, success: success) | |
15 | +// self.setCmdClosure = completion | |
16 | + sendData(data) | |
17 | + } | |
12 | 18 | // 设置时间 |
13 | 19 | func newSetTime(completion: ((_ error: Int?) -> ())? = nil) { |
14 | 20 | let data = BleMessage.shared.getTimeCmd() | ... | ... |