1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import bluetooth from '@ohos.bluetooth'; 17import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' 18import { UiComponent, UiDriver, BY, Component, Driver, UiWindow, ON, MatchPattern, DisplayRotation, ResizeDirection, UiDirection, MouseButton, WindowMode, PointerMatrix, UIElementInfo, UIEventObserver } from '@ohos.UiTest' 19 20export default function btBleScanTest() { 21describe('btBleScanTest', function() { 22 function sleep(delay) { 23 return new Promise(resovle => setTimeout(resovle, delay)) 24 } 25 26 async function openPhone() { 27 try{ 28 let drivers = Driver.create(); 29 console.info('[bluetooth_js] bt driver create:'+ drivers); 30 await drivers.delayMs(1000); 31 await drivers.wakeUpDisplay(); 32 await drivers.delayMs(5000); 33 await drivers.swipe(1500, 1000, 1500, 100); 34 await drivers.delayMs(10000); 35 } catch (error) { 36 console.info('[bluetooth_js] driver error info:'+ error); 37 } 38 } 39 40 async function clickTheWindow() { 41 console.info('[bluetooth_js] clickRequestPermission start'); 42 let driver = Driver.create(); 43 await driver.delayMs(3000); 44 try { 45 let button = await driver.findComponent(ON.text("开启")); 46 await button.click(); 47 await driver.delayMs(3000); 48 console.info('[bluetooth_js] click 开启 end'); 49 } catch (err) { 50 console.info('[bluetooth_js] clickRequestPermission failed. ' + err); 51 } 52 try { 53 let button1 = await driver.findComponent(ON.text("允许")); 54 await button1.click(); 55 await driver.delayMs(3000); 56 console.info('[bluetooth_js] click 允许 end'); 57 } catch (err) { 58 console.info('[bluetooth_js] click 允许 failed. ' + err); 59 } 60 } 61 62 async function tryToEnableBt() { 63 let sta = bluetooth.getState(); 64 switch(sta){ 65 case 0: 66 bluetooth.enableBluetooth(); 67 await clickTheWindow(); 68 await sleep(10000); 69 let sta1 = bluetooth.getState(); 70 console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); 71 break; 72 case 1: 73 console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); 74 await sleep(3000); 75 break; 76 case 2: 77 console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta)); 78 break; 79 case 3: 80 bluetooth.enableBluetooth(); 81 await clickTheWindow(); 82 await sleep(10000); 83 let sta2 = bluetooth.getState(); 84 console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); 85 break; 86 default: 87 console.info('[bluetooth_js] enable success'); 88 } 89 } 90 beforeAll(async function (done) { 91 console.info('beforeAll called') 92 await openPhone(); 93 done(); 94 }) 95 beforeEach(async function(done) { 96 console.info('beforeEach called') 97 await tryToEnableBt() 98 done() 99 }) 100 afterEach(function () { 101 console.info('afterEach called') 102 }) 103 afterAll(function () { 104 console.info('afterAll called') 105 }) 106 107 /** 108 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0100 109 * @tc.name testClassicStartBLEScan 110 * @tc.desc Test ClassicStartBLEScan api. 111 * @tc.type Function 112 * @tc.size MediumTest 113 * @tc.level Level 0 114 */ 115 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0100', 0, async function (done) { 116 function onReceiveEvent(data) 117 { 118 console.info('[bluetooth_js] BLEscan device result1 '+JSON.stringify(data)); 119 expect(data.length > 0).assertTrue(); 120 } 121 bluetooth.BLE.on("BLEDeviceFind",onReceiveEvent) 122 bluetooth.BLE.startBLEScan(null); 123 await sleep(1000); 124 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 125 bluetooth.BLE.stopBLEScan(); 126 done(); 127 }) 128 129 /** 130 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0200 131 * @tc.name testClassicStartBLEScan 132 * @tc.desc Test ClassicStartBLEScan api. 133 * @tc.type Function 134 * @tc.size MediumTest 135 * @tc.level Level 2 136 */ 137 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0200', 0, async function (done) { 138 function onReceiveEvent(data) 139 { 140 console.info('[bluetooth_js] BLEscan device result2'+JSON.stringify(data)); 141 expect(data.length > 0).assertTrue(); 142 } 143 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 144 bluetooth.BLE.startBLEScan([{deviceId:"00:11:22:33:44:55"}]); 145 await sleep(1000); 146 console.info('[bluetooth_js] BLE scan off2'); 147 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 148 bluetooth.BLE.stopBLEScan(); 149 done(); 150 }) 151 152 /** 153 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0300 154 * @tc.name testClassicStartBLEScan 155 * @tc.desc Test ClassicStartBLEScan api. 156 * @tc.type Function 157 * @tc.size MediumTest 158 * @tc.level Level 2 159 */ 160 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0300', 0, async function (done) { 161 function onReceiveEvent(data) 162 { 163 console.info('[bluetooth_js] BLEscan device result3'+JSON.stringify(data)); 164 expect(data.length > 0).assertTrue(); 165 } 166 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 167 bluetooth.BLE.startBLEScan([{name:"blue_test"}]); 168 await sleep(1000); 169 console.info('[bluetooth_js] BLE scan off3'); 170 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 171 bluetooth.BLE.stopBLEScan(); 172 done(); 173 }) 174 175 /** 176 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0400 177 * @tc.name testClassicStartBLEScan 178 * @tc.desc Test ClassicStartBLEScan api. 179 * @tc.type Function 180 * @tc.size MediumTest 181 * @tc.level Level 3 182 */ 183 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0400', 0, async function (done) { 184 function onReceiveEvent(data) 185 { 186 console.info('[bluetooth_js] BLEscan device result4'+JSON.stringify(data)); 187 expect(data.length > 0).assertTrue(); 188 } 189 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 190 bluetooth.BLE.startBLEScan([{serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"}]); 191 await sleep(1000); 192 console.info('[bluetooth_js] BLE scan off4'); 193 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 194 bluetooth.BLE.stopBLEScan(); 195 done(); 196 }) 197 198 /** 199 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0500 200 * @tc.name testClassicStartBLEScan 201 * @tc.desc Test ClassicStartBLEScan api. 202 * @tc.type Function 203 * @tc.size MediumTest 204 * @tc.level Level 3 205 */ 206 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0500', 0, async function (done) { 207 function onReceiveEvent(data) 208 { 209 console.info('[bluetooth_js] BLEscan device result5'+JSON.stringify(data)); 210 expect(data.length > 0).assertTrue(); 211 } 212 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 213 bluetooth.BLE.startBLEScan( 214 [{}], 215 { 216 interval: 100, 217 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, 218 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 219 } 220 ); 221 await sleep(1000); 222 console.info('[bluetooth_js] BLE scan off5'); 223 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 224 bluetooth.BLE.stopBLEScan(); 225 done(); 226 }) 227 228 /** 229 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0600 230 * @tc.name testClassicStartBLEScan 231 * @tc.desc Test ClassicStartBLEScan api. 232 * @tc.type Function 233 * @tc.size MediumTest 234 * @tc.level Level 3 235 */ 236 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0600', 0, async function (done) { 237 function onReceiveEvent(data) 238 { 239 console.info('[bluetooth_js] BLEscan device result6'+JSON.stringify(data)); 240 expect(data.length > 0).assertTrue(); 241 } 242 let ScanOptions= { 243 interval: 100, 244 dutyMode: bluetooth.ScanDuty.SCAN_MODE_BALANCED, 245 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 246 } 247 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 248 bluetooth.BLE.startBLEScan([{}],ScanOptions); 249 await sleep(1000); 250 console.info('[bluetooth_js] BLE scan off6'); 251 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 252 bluetooth.BLE.stopBLEScan(); 253 done(); 254 }) 255 256 /** 257 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0700 258 * @tc.name testClassicStartBLEScan 259 * @tc.desc Test ClassicStartBLEScan api. 260 * @tc.type Function 261 * @tc.size MediumTest 262 * @tc.level Level 3 263 */ 264 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0700', 0, async function (done) { 265 function onReceiveEvent(data) 266 { 267 console.info('[bluetooth_js] BLEscan device result7'+JSON.stringify(data)); 268 expect(data.length > 0).assertTrue(); 269 } 270 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 271 bluetooth.BLE.startBLEScan( 272 [{}], 273 { 274 interval: 100, 275 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, 276 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 277 } 278 ); 279 await sleep(1000); 280 console.info('[bluetooth_js] BLE scan off7'); 281 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 282 done(); 283 }) 284 285 /** 286 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0900 287 * @tc.name testClassicStartBLEScan 288 * @tc.desc Test ClassicStartBLEScan api. 289 * @tc.type Function 290 * @tc.size MediumTest 291 * @tc.level Level 3 292 */ 293 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_0900', 0, async function (done) { 294 function onReceiveEvent(data) 295 { 296 console.info('[bluetooth_js] BLEscan device result9'+JSON.stringify(data)); 297 expect(data.length > 0).assertTrue(); 298 } 299 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 300 bluetooth.BLE.startBLEScan( 301 [{}], 302 { 303 interval: 0, 304 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, 305 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 306 } 307 ); 308 await sleep(1000); 309 console.info('[bluetooth_js] BLE scan off7'); 310 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 311 bluetooth.BLE.stopBLEScan(); 312 done(); 313 }) 314 315 /** 316 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1000 317 * @tc.name testClassicStartBLEScan 318 * @tc.desc Test ClassicStartBLEScan api. 319 * @tc.type Function 320 * @tc.size MediumTest 321 * @tc.level Level 3 322 */ 323 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1000', 0, async function (done) { 324 function onReceiveEvent(data) 325 { 326 console.info('[bluetooth_js] BLEscan device result10'+JSON.stringify(data)); 327 expect(data.length > 0).assertTrue(); 328 } 329 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 330 bluetooth.BLE.startBLEScan( 331 [{}], 332 { 333 interval: 500, 334 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, 335 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 336 } 337 ); 338 await sleep(1000); 339 console.info('[bluetooth_js] BLE scan off10'); 340 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 341 bluetooth.BLE.stopBLEScan(); 342 done(); 343 }) 344 345 /** 346 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1100 347 * @tc.name testClassicStartBLEScan 348 * @tc.desc Test ClassicStartBLEScan api. 349 * @tc.type Function 350 * @tc.size MediumTest 351 * @tc.level Level 3 352 */ 353 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1100', 0, async function (done) { 354 function onReceiveEvent(data) 355 { 356 console.info('[bluetooth_js] BLEscan device result11'+JSON.stringify(data)); 357 expect(data.length > 0).assertTrue(); 358 } 359 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 360 bluetooth.BLE.startBLEScan( 361 [{}], 362 { 363 interval: 500, 364 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, 365 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 366 } 367 ); 368 await sleep(1000); 369 console.info('[bluetooth_js] BLE scan off11'); 370 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 371 bluetooth.BLE.stopBLEScan(); 372 done(); 373 }) 374 375 /** 376 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1200 377 * @tc.name testClassicStartBLEScan 378 * @tc.desc Test ClassicStartBLEScan api. 379 * @tc.type Function 380 * @tc.size MediumTest 381 * @tc.level Level 3 382 */ 383 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1200', 0, async function (done) { 384 function onReceiveEvent(data) 385 { 386 console.info('[bluetooth_js] BLEscan device result12'+JSON.stringify(data)); 387 expect(data.length > 0).assertTrue(); 388 } 389 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 390 bluetooth.BLE.startBLEScan( 391 [{}], 392 { 393 interval: 500, 394 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, 395 matchMode: bluetooth.MatchMode.MATCH_MODE_STICKY, 396 } 397 ); 398 await sleep(1000); 399 console.info('[bluetooth_js] BLE scan off12'); 400 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 401 bluetooth.BLE.stopBLEScan(); 402 done(); 403 }) 404 405 /** 406 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1300 407 * @tc.name testClassicStartBLEScan 408 * @tc.desc Test ClassicStartBLEScan api. 409 * @tc.type Function 410 * @tc.size MediumTest 411 * @tc.level Level 3 412 */ 413 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1300', 0, async function (done) { 414 function onReceiveEvent(data) 415 { 416 console.info('[bluetooth_js] BLEscan device result13'+JSON.stringify(data)); 417 expect(data.length > 0).assertTrue(); 418 } 419 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 420 bluetooth.BLE.startBLEScan( 421 [{ 422 deviceId:"11:22:33:44:55:66", 423 name:"test", 424 serviceUuid:"00001888-0000-1000-8000-00805f9b34fb" 425 }], 426 { 427 interval: 500, 428 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, 429 matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, 430 } 431 ); 432 await sleep(1000); 433 console.info('[bluetooth_js] BLE scan off13'); 434 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 435 bluetooth.BLE.stopBLEScan(); 436 done(); 437 }) 438 439 /* @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1400 440 * @tc.name testClassicStartBLEScan 441 * @tc.desc Test ClassicStartBLEScan api. 442 * @tc.type Function 443 * @tc.size MediumTest 444 * @tc.level Level 3 445 */ 446 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1400', 0, async function (done) { 447 function onReceiveEvent(data) 448 { 449 console.info('[bluetooth_js] BLE scan device find result14'+ JSON.stringify(data)); 450 expect(data.length > 0).assertTrue(); 451 } 452 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 453 bluetooth.BLE.startBLEScan([{ 454 serviceUuid:"00001812-0000-1000-8000-00805F9B34FB", 455 serviceUuidMask:"0000FFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", 456 }]); 457 await sleep(1000); 458 console.info('[bluetooth_js] BLE scan off14 '); 459 bluetooth.BLE.stopBLEScan(); 460 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 461 done(); 462 463 }) 464 465 /** 466 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1500 467 * @tc.name testClassicStartBLEScan 468 * @tc.desc Test ClassicStartBLEScan api. 469 * @tc.type Function 470 * @tc.size MediumTest 471 * @tc.level Level 2 472 */ 473 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1500', 0, async function (done) { 474 function onReceiveEvent(data) 475 { 476 console.info('[bluetooth_js] BLE scan device find result15'+ JSON.stringify(data)); 477 expect(data.length > 0).assertTrue(); 478 } 479 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 480 bluetooth.BLE.startBLEScan([{ 481 serviceSolicitationUuid:"00000101-0000-1000-8000-00805F9B34FB", 482 serviceSolicitationUuidMask:"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", 483 484 }]); 485 await sleep(1000); 486 console.info('[bluetooth_js] BLE scan off15 '); 487 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 488 bluetooth.BLE.stopBLEScan(); 489 done(); 490 }) 491 492 /** 493 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1600 494 * @tc.name testClassicStartBLEScan 495 * @tc.desc Test ClassicStartBLEScan api. 496 * @tc.type Function 497 * @tc.size MediumTest 498 * @tc.level Level 2 499 */ 500 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1600', 0, async function (done) { 501 function onReceiveEvent(data) 502 { 503 console.info('[bluetooth_js] BLE scan device find result16'+ JSON.stringify(data)); 504 expect(data.length > 0).assertTrue(); 505 } 506 let ScanFilters= []; 507 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 508 const serviceDataArrayBuffer = new ArrayBuffer(1); 509 const serviceDataMaskArrayBuffer = new ArrayBuffer(1); 510 const serviceDataValue = new Uint8Array(serviceDataArrayBuffer); 511 const serviceDataMaskValue = new Uint8Array(serviceDataMaskArrayBuffer); 512 serviceDataValue[0] = '0xFF'; 513 serviceDataMaskValue[0] = '0xFF'; 514 let ScanFilter = { 515 serviceData:serviceDataValue, 516 serviceDataMask:serviceDataMaskValue, 517 } 518 ScanFilters[0]=ScanFilter; 519 bluetooth.BLE.startBLEScan(ScanFilters); 520 await sleep(1000); 521 console.info('[bluetooth_js] BLE scan off16'); 522 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 523 bluetooth.BLE.stopBLEScan(); 524 done(); 525 }) 526 527 /** 528 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1700 529 * @tc.name testClassicStartBLEScan 530 * @tc.desc Test ClassicStartBLEScan api. 531 * @tc.type Function 532 * @tc.size MediumTest 533 * @tc.level Level 2 534 */ 535 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1700', 0, async function (done) { 536 function onReceiveEvent(data) 537 { 538 console.info('[bluetooth_js] BLE scan device find result17'+ JSON.stringify(data)); 539 expect(data.length > 0).assertTrue(); 540 } 541 bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) 542 const manufactureDataArrayBuffer = new ArrayBuffer(29); 543 const manufactureDataMaskArrayBuffer = new ArrayBuffer(29); 544 const manufactureDataValue = new Uint8Array(manufactureDataArrayBuffer); 545 const manufactureDataMaskValue = new Uint8Array(manufactureDataMaskArrayBuffer); 546 for (let i = 0; i < 29; i++) { 547 manufactureDataValue[i] = '0xFF'; 548 } 549 for (let i = 0; i < 29; i++) { 550 manufactureDataMaskValue[i] = '0xFF'; 551 } 552 bluetooth.BLE.startBLEScan([{ 553 manufactureId:0x0006, 554 manufactureData:manufactureDataValue, 555 manufactureDataMask:manufactureDataMaskValue, 556 }]); 557 await sleep(1000); 558 console.info('[bluetooth_js] BLE scan off17 '); 559 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 560 bluetooth.BLE.stopBLEScan(); 561 done(); 562 }) 563 564 /** 565 * @tc.number SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1800 566 * @tc.name testStartBLEScan 567 * @tc.desc Test connect and disconnect api . 568 * @tc.type Function 569 * @tc.size MediumTest 570 * @tc.level Level 2 571 */ 572 it('SUB_COMMUNICATION_BLUETOOTH_BLESCAN_1800', 0, async function (done) { 573 async function onReceiveEvent(ScanResult) 574 { 575 console.info('[bluetooth_js] BLEscan device result12'+JSON.stringify(ScanResult) 576 +ScanResult.deviceId+ScanResult.rssi+ ScanResult.data); 577 expect(ScanResult.length > 0).assertTrue(); 578 await sleep(1000); 579 let gattClient = bluetooth.BLE.createGattClientDevice(ScanResult[0].deviceId); 580 let ret = gattClient.connect(); 581 await sleep(2000); 582 console.info('[bluetooth_js] gattClient connect' + ret) 583 expect(ret).assertTrue(); 584 let disconnect = gattClient.disconnect(); 585 console.info('[bluetooth_js] gatt disconnect:' + disconnect); 586 expect(disconnect).assertEqual(false); 587 } 588 await bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent); 589 bluetooth.BLE.startBLEScan( 590 [{}], 591 { 592 interval: 500, 593 dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, 594 matchMode: bluetooth.MatchMode.MATCH_MODE_STICKY, 595 } 596 ); 597 console.info('[bluetooth_js] BLE scan offC'); 598 bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); 599 bluetooth.BLE.stopBLEScan(); 600 done() 601 }) 602}) 603}