react-native-gizwits-sdk-v5 1.5.7-thirdbluetooth → 1.5.8-thirdbluetooth
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -22,6 +22,15 @@ struct StartMusicalRhythmParams: Decodable {
|
|
|
22
22
|
struct StopMusicalRhythmParams: Decodable {
|
|
23
23
|
var id: String
|
|
24
24
|
}
|
|
25
|
+
struct SetDeviceMtuParams: Decodable {
|
|
26
|
+
var id: String
|
|
27
|
+
var mtu: Int
|
|
28
|
+
}
|
|
29
|
+
struct SendThirdDeviceDpParams: Decodable {
|
|
30
|
+
var id: String
|
|
31
|
+
var data: String
|
|
32
|
+
var characteristicUuid: String?
|
|
33
|
+
}
|
|
25
34
|
struct CheckUpdateParams: Decodable {
|
|
26
35
|
var type: GizwitsiOSSDK.GizCapability
|
|
27
36
|
var firmwareType: GizwitsiOSSDK.GizOTAFirmwareType
|
|
@@ -551,6 +560,84 @@ class RNGizDeviceManagerModule: RCTEventEmitter {
|
|
|
551
560
|
|
|
552
561
|
}
|
|
553
562
|
}
|
|
563
|
+
|
|
564
|
+
@objc
|
|
565
|
+
public func setDeviceMtu(_ options: NSDictionary, result: @escaping RCTResponseSenderBlock) {
|
|
566
|
+
if let params = RNGizParamsChecker.check(options: options, result: result, paramsType: SetDeviceMtuParams.self) {
|
|
567
|
+
// 先找到设备
|
|
568
|
+
if let device = findDevice(id: params.id) {
|
|
569
|
+
Task {
|
|
570
|
+
var data = device.setDeviceMtu(params.mtu);
|
|
571
|
+
GizRNCallbackManager.callbackWithResult(callback: result, result:GizResult<Int?, GizAPIException?>(successMessage: "", data: nil))
|
|
572
|
+
}
|
|
573
|
+
} else {
|
|
574
|
+
// 提示设备不存在
|
|
575
|
+
GizRNCallbackManager.callbackWithResult(callback: result, result: GizResult<Int?, GizAPIException?>(error: GizAPIException.GIZ_OPENAPI_DEVICE_NOT_FOUND))
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
@objc
|
|
582
|
+
public func sendThirdDeviceDp(_ options: NSDictionary, result: @escaping RCTResponseSenderBlock) {
|
|
583
|
+
if let params = RNGizParamsChecker.check(options: options, result: result, paramsType: SendThirdDeviceDpParams.self) {
|
|
584
|
+
// 先找到设备
|
|
585
|
+
guard let device = findDevice(id: params.id), let bleDeviceCapability = device.bleCapability else {
|
|
586
|
+
GizRNCallbackManager.callbackWithResult(callback: result, result: GizResult<Int?, GizAPIException?>(error: GizAPIException.GIZ_OPENAPI_DEVICE_NOT_FOUND))
|
|
587
|
+
return
|
|
588
|
+
}
|
|
589
|
+
Task {
|
|
590
|
+
do {
|
|
591
|
+
let hexPattern = "^[0-9A-Fa-f]+$"
|
|
592
|
+
let regex = try NSRegularExpression(pattern: hexPattern, options: [])
|
|
593
|
+
let range = NSRange(location: 0, length: params.data.utf16.count)
|
|
594
|
+
|
|
595
|
+
if regex.firstMatch(in: params.data, options: [], range: range) == nil {
|
|
596
|
+
GizRNCallbackManager.callbackWithResult(
|
|
597
|
+
callback: result,
|
|
598
|
+
result: GizResult<Int?, GizCtrlException?>(error: GizCtrlException.GIZ_SDK_PARAM_INVALID)
|
|
599
|
+
)
|
|
600
|
+
return
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if params.data.count % 2 != 0 {
|
|
604
|
+
GizRNCallbackManager.callbackWithResult(
|
|
605
|
+
callback: result,
|
|
606
|
+
result: GizResult<Int?, GizCtrlException?>(error: GizCtrlException.GIZ_SDK_PARAM_INVALID)
|
|
607
|
+
)
|
|
608
|
+
return
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
var rawData = Data()
|
|
612
|
+
var index = params.data.startIndex
|
|
613
|
+
while index < params.data.endIndex {
|
|
614
|
+
let nextIndex = params.data.index(index, offsetBy: 2)
|
|
615
|
+
let byteString = params.data[index..<nextIndex]
|
|
616
|
+
if let byte = UInt8(byteString, radix: 16) {
|
|
617
|
+
rawData.append(byte)
|
|
618
|
+
} else {
|
|
619
|
+
GizRNCallbackManager.callbackWithResult(
|
|
620
|
+
callback: result,
|
|
621
|
+
result: GizResult<Int?, GizCtrlException?>(error: GizCtrlException.GIZ_SDK_PARAM_INVALID)
|
|
622
|
+
)
|
|
623
|
+
return
|
|
624
|
+
}
|
|
625
|
+
index = nextIndex
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
let res = await bleDeviceCapability.sendThirdDeviceDp(data: rawData, characteristicUuid: params.characteristicUuid)
|
|
629
|
+
GizRNCallbackManager.callbackWithResult(callback: result, result: res)
|
|
630
|
+
} catch {
|
|
631
|
+
GizRNCallbackManager.callbackWithResult(
|
|
632
|
+
callback: result,
|
|
633
|
+
result: GizResult<Int?, GizCtrlException?>(error: GizCtrlException.GIZ_SDK_PARAM_INVALID)
|
|
634
|
+
)
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
} else {
|
|
638
|
+
GizRNCallbackManager.callbackWithResult(callback: result, result: GizResult<Int?, GizAPIException?>(error: GizAPIException.GIZ_SDK_PARAM_INVALID))
|
|
639
|
+
}
|
|
640
|
+
}
|
|
554
641
|
|
|
555
642
|
@objc
|
|
556
643
|
override static func requiresMainQueueSetup() -> Bool {
|
package/package.json
CHANGED