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,6 +8,11 @@ | ||
8 | import SwiftDate | 8 | import SwiftDate |
9 | 9 | ||
10 | extension BleMessage { | 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 | func getTimeCmd() -> Data { | 16 | func getTimeCmd() -> Data { |
12 | let date = DateInRegion().date | 17 | let date = DateInRegion().date |
13 | let timeBytes: [UInt8] = [UInt8(date.year%100), UInt8(date.month), UInt8(date.day), UInt8(date.hour), UInt8(date.minute), UInt8(date.second)] | 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
@@ -115,7 +115,7 @@ enum SetCmd: UInt8 { | @@ -115,7 +115,7 @@ enum SetCmd: UInt8 { | ||
115 | } | 115 | } |
116 | 116 | ||
117 | enum NewCmd: UInt8 { | 117 | enum NewCmd: UInt8 { |
118 | -// case response = 0x01 | 118 | + case response = 0x01 |
119 | // case queryDevice = 0x02 | 119 | // case queryDevice = 0x02 |
120 | // case ota = 0x07 | 120 | // case ota = 0x07 |
121 | case setTime = 0x09 | 121 | case setTime = 0x09 |
HDFwear/Tools/BluetoothManager+Function.swift
@@ -9,6 +9,12 @@ import SwiftDate | @@ -9,6 +9,12 @@ import SwiftDate | ||
9 | 9 | ||
10 | 10 | ||
11 | extension BluetoothManager { | 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 | func newSetTime(completion: ((_ error: Int?) -> ())? = nil) { | 19 | func newSetTime(completion: ((_ error: Int?) -> ())? = nil) { |
14 | let data = BleMessage.shared.getTimeCmd() | 20 | let data = BleMessage.shared.getTimeCmd() |