From 5186410e94a48ddcdae5356c9579139a80690a84 Mon Sep 17 00:00:00 2001 From: wangweiyuan Date: Wed, 14 May 2025 20:47:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81=E6=A0=87?= =?UTF-8?q?=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangweiyuan --- .../entry/src/main/ets/pages/Index.ets | 5 +- .../main/ets/entryability/EntryAbility.ets | 6 ++- .../entry/src/main/module.json5 | 2 + .../main/ets/entry1ability/Entry1Ability.ets | 4 +- .../entry1/src/main/module.json5 | 2 + .../main/ets/entryability/EntryAbility.ets | 6 ++- .../entry/src/main/module.json5 | 2 + .../main/ets/entryability/EntryAbility.ets | 6 ++- .../entry1/src/main/module.json5 | 2 + .../main/ets/entryability/EntryAbility.ets | 2 + .../src/main/ets/entryability/p2pConnect.ets | 2 + .../src/main/ets/entryability/p2pability.ets | 4 +- .../bluetoothService/BluetoothAdvertising.ets | 4 +- .../ets/bluetoothService/BluetoothScan.ets | 17 ++++++ .../ets/bluetoothService/BluetoothSwitch.ets | 5 +- .../bluetoothService/GattClientManager.ets | 54 ++++++++++++++++++- .../bluetoothService/GattServerManager.ets | 4 +- 17 files changed, 113 insertions(+), 14 deletions(-) diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets index cea579ee8f..540edc86a4 100644 --- a/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets @@ -67,6 +67,7 @@ struct serialCommunication { }).height('40vp').width('70%') }.width('80%') + // [Start server_write_client] Button('listenSocket') .width('50%') .id('listenSocket') @@ -130,6 +131,7 @@ struct serialCommunication { } }) + // [Start socket_spp_connect] Button('connectDevice') .width('50%') .backgroundColor('#8CE072') @@ -153,9 +155,9 @@ struct serialCommunication { (err as BusinessError).message); this.toastReport.showResult('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); - } }) + // [End socket_spp_connect] Button('writeData') .width('50%') @@ -251,6 +253,7 @@ struct serialCommunication { console.info(TAG, 'sppCloseClientSocket success'); this.toastReport.showResult('sppCloseClientSocket success'); }) + // [End server_write_client] } .width('100%') .height('100%') diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets index fc8b1e1d4b..eeb5607a72 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start front_hce_swipe_ets] import { cardEmulation } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -92,4 +93,5 @@ export default class EntryAbility extends UIAbility { } } } -} \ No newline at end of file +} +// [End front_hce_swipe_ets] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 index 53fd0f2b12..2cfceef203 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 @@ -27,6 +27,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // [Start front_hce_swipe] "abilities": [ { "name": "EntryAbility", @@ -59,6 +60,7 @@ "reason": "$string:app_name", } ], + // [End front_hce_swipe] "extensionAbilities": [ { "name": "EntryBackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets index aa74877bad..362517f8a6 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start back_hce_swipe_ets] import { cardEmulation } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -82,4 +83,5 @@ export default class EntryAbility extends UIAbility { } } } -} \ No newline at end of file +} +// [End back_hce_swipe_ets] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 index c6ada203f0..38684d0ac4 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 @@ -25,6 +25,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // [Start back_hce_swipe] "abilities": [ { "name": "Entry1Ability", @@ -67,6 +68,7 @@ "reason": "$string:app_name", } ], + // [End back_hce_swipe] "extensionAbilities": [ { "name": "Entry1BackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets index 7a39747af9..d244d203a7 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start front_get_nfc_tag_ets] import { tag } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -131,4 +132,5 @@ export default class EntryAbility extends UIAbility { } } } -} \ No newline at end of file +} +// [End front_get_nfc_tag_ets] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 index 36701bff5e..87decab6f7 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 @@ -27,6 +27,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // {Start front_get_nfc_tag] "abilities": [ { "name": "EntryAbility", @@ -57,6 +58,7 @@ "reason": "$string:app_name", } ], + // [End front_get_nfc_tag] "extensionAbilities": [ { "name": "EntryBackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets index 199867b3f1..6817624c7c 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start back_get_nfc_tag_ets] import { tag } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -89,4 +90,5 @@ export default class EntryAbility extends UIAbility { return; } } -} \ No newline at end of file +} +// [End back_get_nfc_tag_ets] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 index 734f2658cb..22892b5f3d 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 @@ -25,6 +25,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // [Start back_get_nfc_tag] "abilities": [ { "name": "EntryAbility", @@ -65,6 +66,7 @@ "reason": "$string:app_name", } ], + // [End back_get_nfc_tag] "extensionAbilities": [ { "name": "Entry1BackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets index 0a6a087ff5..a680111a47 100644 --- a/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start access_security_unit] import { omapi } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -120,3 +121,4 @@ export default class EntryAbility extends UIAbility { } } +// [End access_security_unit] diff --git a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets index 708757a74a..d71da61e37 100644 --- a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets +++ b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start create_p2p_connect] import { wifiManager } from '@kit.ConnectivityKit'; export class P2PConnectMananger { @@ -79,3 +80,4 @@ export class P2PConnectMananger { let p2pConnectManager = new P2PConnectMananger(); export default p2pConnectManager as P2PConnectMananger; +// [End create_p2p_connect] diff --git a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets index 01c764fd88..d3c62deba0 100644 --- a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets +++ b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start create_delete_p2p_group] import { wifiManager } from '@kit.ConnectivityKit'; export class P2PManager { @@ -51,4 +52,5 @@ export class P2PManager { // 默认导出let let p2pManager = new P2PManager(); -export default p2pManager as P2PManager; \ No newline at end of file +export default p2pManager as P2PManager; +// [End create_delete_p2p_group] \ No newline at end of file diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets index 0c1f374b6e..bcba2b8db0 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start open_close_advertising] import { ble } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { ToastReport } from '../common/ToastReport'; @@ -179,4 +180,5 @@ export class BleAdvertisingManager { let bleAdvertisingManager = new BleAdvertisingManager(); -export default bleAdvertisingManager as BleAdvertisingManager; \ No newline at end of file +export default bleAdvertisingManager as BleAdvertisingManager; +// [End open_close_advertising] \ No newline at end of file diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets index b590b6a95f..8aa2cecd90 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start open_close_scan] import { ble } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { ScanData } from '../common/ScanData'; @@ -76,11 +77,13 @@ export class BleScanManager { if (data.length > 0) { console.info(TAG, 'BLE scan result = ' + data[0].deviceId); this.parseScanResult(data[0].data); + // [StartExclude open_close_scan] this.toastReport.showResult(data[0].deviceId); if (!this.scanDataList.some(item => item.getDeviceName() === data[0].deviceName)) { this.scanDataList.push(new ScanData(data[0].deviceId, data[0].deviceName, data[0].rssi, data[0].connectable, new Uint8Array(data[0].data))); } + // [EndExclude open_close_scan] } }); } @@ -232,6 +235,7 @@ export class BleScanManager { // manufactureData: manufactureData.buffer, manufactureDataMask: manufactureDataMask.buffer, }; + // [StartExclude open_close_scan] if (this.deviceName) { console.info('===lyk=== deviceName is not null ' + this.deviceName) scanFilter.name = this.deviceName; @@ -239,6 +243,8 @@ export class BleScanManager { if (this.deviceId) { scanFilter.deviceId = this.deviceId; } + // [EndExclude open_close_scan] + // 2.2 构造扫描参数 let scanOptions: ble.ScanOptions = { interval: this.interval, @@ -246,13 +252,19 @@ export class BleScanManager { matchMode: ble.MatchMode.MATCH_MODE_AGGRESSIVE, } try { + // [StartExclude open_close_scan] this.scanDataList = []; + // [EndExclude open_close_scan] this.onScanResult(); // 订阅扫描结果 ble.startBLEScan([scanFilter], scanOptions); + // [StartExclude open_close_scan] this.toastReport.showResult('startBleScan success'); + // [EndExclude open_close_scan] console.info(TAG, 'startBleScan success'); } catch (err) { + // [StartExclude open_close_scan] this.toastReport.showResult('startBleScan fail'); + // [EndExclude open_close_scan] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -264,10 +276,14 @@ export class BleScanManager { console.info(TAG, 'off success'); }); ble.stopBLEScan(); + // [StartExclude open_close_scan] this.toastReport.showResult('stopBleScan success'); + // [EndExclude open_close_scan] console.info(TAG, 'stopBleScan success'); } catch (err) { + // [StartExclude open_close_scan] this.toastReport.showResult('stopBleScan fail'); + // [EndExclude open_close_scan] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -276,3 +292,4 @@ export class BleScanManager { let bleScanManager = new BleScanManager(); export default bleScanManager as BleScanManager; +// [End open_close_scan] diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets index bb3829f54e..5b10dd2adb 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets @@ -12,11 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +// [Start open_close_bluetooth] import { access } from '@kit.ConnectivityKit'; export class BluetoothSwitch { public openBluetooth() { + access.off('stateChange'); access.enableBluetooth(); access.on('stateChange', (data) => { @@ -52,7 +53,6 @@ export class BluetoothSwitch { } console.info('bluetooth statues: ' + btStateMessage); }); - } public closeBluetooth() { @@ -92,3 +92,4 @@ export class BluetoothSwitch { }); } } +// [End open_close_bluetooth] \ No newline at end of file diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets index f4eef513ec..745998b1d9 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start generic_attribute] import { ble } from '@kit.ConnectivityKit'; import { constant } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -20,7 +21,9 @@ import { ToastReport } from '../common/ToastReport'; import util from '@ohos.util'; const TAG: string = 'GattClientManager'; +// [StartExclude generic_attribute] let encoder = new util.TextEncoder(); +// [EndExclude generic_attribute] export class GattData { public serviceUuid: string = '00001810-0000-1000-8000-00805F9B34FB'; @@ -83,7 +86,9 @@ export class GattClientManager { message += value[i] + ' '; } console.info(TAG, message); + // [StartExclude generic_attribute] this.toastReport.showResult(message); + // [EndExclude generic_attribute] } private logDescriptor(des: ble.BLEDescriptor) { @@ -94,7 +99,9 @@ export class GattClientManager { message += value[i] + ' '; } console.info(TAG, message); + // [StartExclude generic_attribute] this.toastReport.showResult(message); + // [EndExclude generic_attribute] } private checkService(services: Array): boolean { @@ -179,10 +186,14 @@ export class GattClientManager { try { this.onGattClientStateChange(); // 2.2 订阅连接状态 this.gattClient.connect(); // 2.3 发起连接 + // [StartExclude generic_attribute] this.toastReport.showResult('startConnect success'); console.info(TAG, 'startConnect success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('startConnect fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -197,12 +208,16 @@ export class GattClientManager { try { await this.gattClient.getServices().then((result: Array) => { console.info(TAG, 'getServices success: ' + JSON.stringify(result)); + // [StartExclude generic_attribute] this.serviceResult = JSON.stringify(result); this.toastReport.showResult('getServices success: ' + JSON.stringify(result)); + // [EndExclude generic_attribute] this.found = this.checkService(result); // 要确保server端的服务内容有业务所需要的服务 }); } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('getServices fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -211,12 +226,16 @@ export class GattClientManager { public readCharacteristicValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的characteristic console.error(TAG, 'no characteristic from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no characteristic from server'); + // [EndExclude generic_attribute] return; } @@ -226,9 +245,13 @@ export class GattClientManager { this.gattClient.readCharacteristicValue(characteristic).then((outData: ble.BLECharacteristic) => { this.logCharacteristic(outData); }) + // [StartExclude generic_attribute] this.toastReport.showResult('readCharacteristicValue success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('readCharacteristicValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -237,12 +260,16 @@ export class GattClientManager { public writeCharacteristicValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的characteristic console.error(TAG, 'no characteristic from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no characteristic from server'); + // [EndExclude generic_attribute] return; } @@ -255,12 +282,16 @@ export class GattClientManager { 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); return; } + // [StartExclude generic_attribute] this.toastReport.showResult('writeCharacteristicValue success'); + // [EndExclude generic_attribute] console.info(TAG, 'writeCharacteristicValue success'); }); } catch (err) { + // [StartExclude generic_attribute] console.info(TAG, 'writeCharacteristicValue fail'); this.toastReport.showResult('writeCharacteristicValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -269,12 +300,16 @@ export class GattClientManager { public readDescriptorValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的descriptor console.error(TAG, 'no descriptor from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no descriptor from server'); + // [EndExclude generic_attribute] return; } @@ -285,9 +320,13 @@ export class GattClientManager { this.gattClient.readDescriptorValue(descriptor).then((outData: ble.BLEDescriptor) => { this.logDescriptor(outData); }); + // [StartExclude generic_attribute] this.toastReport.showResult('readDescriptorValue success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('readDescriptorValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -296,12 +335,16 @@ export class GattClientManager { public writeDescriptorValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的descriptor console.error(TAG, 'no descriptor from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no descriptor from server'); + // [EndExclude generic_attribute] return; } @@ -319,10 +362,14 @@ export class GattClientManager { return; } console.info(TAG, 'writeDescriptorValue success'); + // [StartExclude generic_attribute] this.toastReport.showResult('writeDescriptorValue success'); + // [EndExclude generic_attribute] }); } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('writeDescriptorValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -340,9 +387,13 @@ export class GattClientManager { this.gattClient.off('BLEConnectionStateChange', (stateInfo: ble.BLEConnectionChangeState) => { }); this.gattClient.close() // 8.2 如果不再使用此gattClient,则需要close + // [StartExclude generic_attribute] this.toastReport.showResult('stopConnect success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('stopConnect fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -350,4 +401,5 @@ export class GattClientManager { let gattClientManager = new GattClientManager(); -export default gattClientManager as GattClientManager; \ No newline at end of file +export default gattClientManager as GattClientManager; +// [End generic_attribute] \ No newline at end of file diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattServerManager.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattServerManager.ets index 89570dc881..aa38c2fb43 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattServerManager.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattServerManager.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start gatt_server_manage] import { ble } from '@kit.ConnectivityKit'; import { constant } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -292,4 +293,5 @@ export class GattServerManager { let gattServerManager = new GattServerManager(); -export default gattServerManager as GattServerManager; \ No newline at end of file +export default gattServerManager as GattServerManager; +// [End gatt_server_manage] \ No newline at end of file -- Gitee