Commit 3cba738e8f810edcb38bd178fcc55600e1e619f3

Authored by daifengyi
1 parent 37775d8e

feat:response

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
... ... @@ -115,7 +115,7 @@ enum SetCmd: UInt8 {
115 115 }
116 116  
117 117 enum NewCmd: UInt8 {
118   -// case response = 0x01
  118 + case response = 0x01
119 119 // case queryDevice = 0x02
120 120 // case ota = 0x07
121 121 case setTime = 0x09
... ...
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()
... ...