From 3cba738e8f810edcb38bd178fcc55600e1e619f3 Mon Sep 17 00:00:00 2001 From: daifengyi Date: Fri, 30 Jun 2023 15:59:45 +0800 Subject: [PATCH] feat:response --- HDFwear/Tools/BleMessage+Function.swift | 5 +++++ HDFwear/Tools/Bluetooth+Types.swift | 2 +- HDFwear/Tools/BluetoothManager+Function.swift | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/HDFwear/Tools/BleMessage+Function.swift b/HDFwear/Tools/BleMessage+Function.swift index 1323242..0d943cb 100644 --- a/HDFwear/Tools/BleMessage+Function.swift +++ b/HDFwear/Tools/BleMessage+Function.swift @@ -8,6 +8,11 @@ import SwiftDate extension BleMessage { + func getResponseCmd(frameNumber: [UInt8], messageId: [UInt8], success: Bool) -> Data { + let bytes: [UInt8] = frameNumber + messageId + (success ? [0x00] : [0x01]) + return createDataPacket(key: .response, 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 2bc375f..aeed09d 100644 --- a/HDFwear/Tools/Bluetooth+Types.swift +++ b/HDFwear/Tools/Bluetooth+Types.swift @@ -115,7 +115,7 @@ enum SetCmd: UInt8 { } enum NewCmd: UInt8 { -// case response = 0x01 + case response = 0x01 // case queryDevice = 0x02 // case ota = 0x07 case setTime = 0x09 diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index eb46e21..a206ca9 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -9,6 +9,12 @@ import SwiftDate extension BluetoothManager { + // 通用应答 + func response(frameNumber: [UInt8], messageId: [UInt8], success: Bool, completion: ((_ error: Int?) -> ())? = nil) { + let data = BleMessage.shared.getResponseCmd(frameNumber: frameNumber, messageId: messageId, success: success) +// self.setCmdClosure = completion + sendData(data) + } // 设置时间 func newSetTime(completion: ((_ error: Int?) -> ())? = nil) { let data = BleMessage.shared.getTimeCmd() -- libgit2 0.21.4