1 /* 2 * Copyright (C) 2021 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 16 /** 17 * @addtogroup Bluetooth 18 * @{ 19 * 20 * @brief Defines ble advertiser, peripheral deviceand central manager functions, 21 * including scan settings and filters, advertise settings and data etc. 22 * 23 * @since 6 24 */ 25 26 /** 27 * @file ble_data.cpp 28 * 29 * @brief Ble data class. 30 * 31 * @since 6 32 */ 33 34 #ifndef BLE_SERVICE_DATA_H 35 #define BLE_SERVICE_DATA_H 36 37 #include <map> 38 #include <vector> 39 #include "bt_def.h" 40 #include "bt_uuid.h" 41 #include "raw_address.h" 42 43 namespace bluetooth { 44 /** 45 * @brief Represents scan settings. 46 * 47 * @since 6 48 */ 49 class BleScanSettingsImpl { 50 public: 51 /** 52 * @brief A constructor used to create a <b>BleScanSettingsInternal</b> instance. 53 * 54 * @since 6 55 */ BleScanSettingsImpl()56 BleScanSettingsImpl(){}; 57 58 /** 59 * @brief A destructor used to delete the <b>BleScanSettingsInternal</b> instance. 60 * 61 * @since 6 62 */ ~BleScanSettingsImpl()63 ~BleScanSettingsImpl(){}; 64 65 /** 66 * @brief Set repport delay time. 67 * 68 * @param reportDelayMillis Repport delay time. 69 * @since 6 70 */ 71 void SetReportDelay(long reportDelayMillis = 0); 72 73 /** 74 * @brief Get repport delay time. 75 * 76 * @return Returns Repport delay time. 77 * @since 6 78 */ 79 long GetReportDelayMillisValue() const; 80 81 /** 82 * @brief Set scan mode. 83 * 84 * @param scanMode Scan mode. 85 * @return If the scanMode is invalid. 86 * @since 6 87 */ 88 void SetScanMode(int scanMode); 89 90 /** 91 * @brief Get scan mode. 92 * 93 * @return Scan mode. 94 * @since 6 95 */ 96 int GetScanMode() const; 97 98 /** 99 * @brief Set legacy flag. 100 * 101 * @param legacy Legacy value. 102 * @since 6 103 */ 104 void SetLegacy(bool legacy); 105 106 /** 107 * @brief Get legacy flag. 108 * 109 * @return Legacy flag. 110 * @since 6 111 */ 112 bool GetLegacy() const; 113 114 /** 115 * @brief Set phy value. 116 * 117 * @param phy Phy value. 118 * @since 6 119 */ 120 void SetPhy(int phy); 121 122 /** 123 * @brief Get phy value. 124 * 125 * @return Phy value. 126 * @since 6 127 */ 128 int GetPhy() const; 129 130 private: 131 /// delay millistime 132 long reportDelayMillis_ = 0; 133 int scanMode_ = SCAN_MODE_LOW_POWER; 134 bool legacy_ = true; 135 int phy_ = PHY_LE_ALL_SUPPORTED; 136 }; 137 138 /** 139 * @brief Represents advertise settings. 140 * 141 * @since 6 142 */ 143 class BleAdvertiserSettingsImpl { 144 public: 145 /** 146 * @brief A constructor used to create a <b>BleAdvertiseSettingsInternal</b> instance. 147 * 148 * @since 6 149 */ BleAdvertiserSettingsImpl()150 BleAdvertiserSettingsImpl(){}; 151 152 /** 153 * @brief A destructor used to delete the <b>BleAdvertiseSettingsInternal</b> instance. 154 * 155 * @since 6 156 */ ~BleAdvertiserSettingsImpl()157 ~BleAdvertiserSettingsImpl(){}; 158 159 /** 160 * @brief Check if device service is connectable. 161 * 162 * @return Returns <b>true</b> if device service is connectable; 163 * returns <b>false</b> if device service is not connectable. 164 * @since 6 165 */ 166 bool IsConnectable() const; 167 168 /** 169 * @brief Set connectable. 170 * 171 * @param connectable Whether it is connectable. 172 * @since 6 173 */ 174 void SetConnectable(bool connectable); 175 /** 176 * @brief Check if advertiser is legacy mode. 177 * 178 * @return Returns <b>true</b> if advertiser is legacy mode; 179 * returns <b>false</b> if advertiser is not legacy mode. 180 * @since 6 181 */ 182 bool IsLegacyMode() const; 183 184 /** 185 * @brief Set legacyMode. 186 * 187 * @param connectable Whether it is legacyMode. 188 * @since 6 189 */ 190 void SetLegacyMode(bool legacyMode); 191 192 /** 193 * @brief Get advertise interval. 194 * 195 * @return Returns advertise interval. 196 * @since 6 197 */ 198 int GetInterval() const; 199 200 /** 201 * @brief Set advertise interval. 202 * 203 * @param interval Advertise interval. 204 * @since 6 205 */ 206 void SetInterval(int interval = BLE_ADV_DEFAULT_INTERVAL); 207 208 /** 209 * @brief Get advertiser Tx power. 210 * 211 * @return Returns advertiser Tx power. 212 * @since 6 213 */ 214 int GetTxPower() const; 215 216 /** 217 * @brief Set advertiser Tx power. 218 * 219 * @param txPower Advertiser Tx power. 220 * @since 6 221 */ 222 int SetTxPower(int txPower); 223 224 /** 225 * @brief Get primary phy. 226 * 227 * @return Returns primary phy. 228 * @since 6 229 */ 230 int GetPrimaryPhy() const; 231 232 /** 233 * @brief Set primary phy. 234 * 235 * @param primaryPhy Primary phy. 236 * @since 6 237 */ 238 void SetPrimaryPhy(int primaryPhy); 239 240 /** 241 * @brief Get second phy. 242 * 243 * @return Returns primary phy. 244 * @since 6 245 */ 246 int GetSecondaryPhy() const; 247 248 /** 249 * @brief Set second phy. 250 * 251 * @param secondaryPhy Second phy. 252 * @since 6 253 */ 254 void SetSecondaryPhy(int secondaryPhy); 255 256 private: 257 /// Advertising interval. 258 int interval_ = BLE_ADV_DEFAULT_INTERVAL; 259 /// Advertising connectable. 260 bool connectable_ = true; 261 /// Advertising txPower. 262 int txPower_ = BLE_ADV_TX_POWER_HIGH_VALUE; 263 /// Advertising legacyMode. 264 bool legacyMode_ = true; 265 /// Advertising primaryPhy. 266 int primaryPhy_ = BLE_ADVERTISEMENT_PHY_1M; 267 /// Advertising secondaryPhy. 268 int secondaryPhy_ = BLE_ADVERTISEMENT_PHY_1M; 269 }; 270 271 /** 272 * @brief Represents advertise data. 273 * 274 * @since 6 275 */ 276 class BleAdvertiserDataImpl { 277 public: 278 /** 279 * @brief A constructor used to create a <b>BleAdvertiseDataInternal</b> instance. 280 * 281 * @since 6 282 */ 283 BleAdvertiserDataImpl(); 284 285 /** 286 * @brief A destructor used to delete the <b>BleAdvertiseDataInternal</b> instance. 287 * 288 * @since 6 289 */ ~BleAdvertiserDataImpl()290 ~BleAdvertiserDataImpl() 291 {} 292 293 /** 294 * @brief Add manufacture data. 295 * 296 * @param manufacturerId Manufacture Id which addad data. 297 * @param data Manufacture data 298 * @since 6 299 */ 300 int AddManufacturerData(uint16_t manufacturerId, const std::string &data); 301 302 /** 303 * @brief Add service data. 304 * 305 * @param uuid Uuid of service data. 306 * @param data Service data. 307 * @since 6 308 */ 309 void AddServiceData(const Uuid &uuid, const std::string &data); 310 311 /** 312 * @brief Add characteristic value. 313 * 314 * @param adtype Type of the field. 315 * @param data Field data. 316 * @since 6 317 */ 318 void AddCharacteristicValue(uint8_t adtype, const std::string &data); 319 320 /** 321 * @brief Add service uuid. 322 * 323 * @param uuid Service uuid. 324 * @since 6 325 */ 326 void AddServiceUuid(const Uuid &uuid); 327 328 /** 329 * @brief Set device appearance. 330 * 331 * @param appearance Device appearance. 332 * @since 6 333 */ 334 void SetAppearance(uint16_t appearance); 335 336 /** 337 * @brief Set complete services. 338 * 339 * @param uuid Service uuid. 340 * @since 6 341 */ 342 void SetCompleteServices(const Uuid &uuid); 343 344 /** 345 * @brief Set advertiser flag. 346 * 347 * @param flag Advertiser flag. 348 * @since 6 349 */ 350 void SetFlags(uint8_t flag); 351 352 /** 353 * @brief Get advertiser flag. 354 * 355 * @return flag Advertiser flag. 356 * @since 6 357 */ 358 uint8_t GetFlags() const; 359 360 /** 361 * @brief Set manufacture data. 362 * 363 * @param data Manufacture data. 364 * @since 6 365 */ 366 void SetManufacturerData(const std::string &data); 367 368 /** 369 * @brief Set device name. 370 * 371 * @param name Device name. 372 * @since 6 373 */ 374 void SetDeviceName(const std::string &name); 375 376 /** 377 * @brief Set Tx power level. 378 * 379 * @param txPowerLevel Tx power level. 380 * @since 6 381 */ 382 void SetTxPowerLevel(uint8_t txPowerLevel); 383 384 /** 385 * @brief Add service data. 386 * 387 * @param data Service data. 388 * @since 6 389 */ 390 void AddData(std::string data); 391 392 /** 393 * @brief Set advertiser data packet. 394 * 395 * @return Returns advertiser data packet. 396 * @since 1.0 397 * @version 1.0 398 */ 399 void SetPayload(const std::string &payload); 400 /** 401 * @brief Get advertiser data packet. 402 * 403 * @return Returns advertiser data packet. 404 * @since 6 405 */ 406 std::string GetPayload() const; 407 408 private: 409 /// Advertiser data packet 410 std::string payload_ {}; 411 uint8_t advFlag_ {}; 412 413 /** 414 * @brief Set advertiser data long name. 415 * 416 * @param name Bluetooth device name. 417 * @since 6 418 */ 419 void SetLongName(const std::string &name); 420 421 /** 422 * @brief Set advertiser data short name 423 * 424 * @param name Bluetooth device name. 425 * @since 6 426 */ 427 void SetShortName(const std::string &name); 428 }; 429 430 /** 431 * @brief Parse advertisement parameter . 432 * 433 * @since 6 434 */ 435 struct BlePeripheralDeviceParseAdvData { 436 uint8_t *payload = nullptr; 437 size_t length = 0; 438 }; 439 /** 440 * @brief Represents peripheral device. 441 * 442 * @since 6 443 */ 444 class BlePeripheralDevice { 445 public: 446 /** 447 * @brief A constructor used to create a <b>BlePeripheralDevice</b> instance. 448 * 449 * @since 6 450 */ 451 BlePeripheralDevice(); 452 453 /** 454 * @brief A destructor used to delete the <b>BlePeripheralDevice</b> instance. 455 * 456 * @since 6 457 */ 458 ~BlePeripheralDevice(); 459 460 /** 461 * @brief Get device address. 462 * 463 * @return Returns device address. 464 * @since 6 465 */ 466 RawAddress GetRawAddress() const; 467 468 /** 469 * @brief Get device Appearance. 470 * 471 * @return Returns device Appearance. 472 * @since 6 473 */ 474 uint16_t GetAppearance() const; 475 476 /** 477 * @brief Get Manufacturer Data. 478 * 479 * @return Returns Manufacturer Data. 480 * @since 6 481 */ 482 std::map<uint16_t, std::string> GetManufacturerData() const; 483 484 /** 485 * @brief Get device Name. 486 * 487 * @return Returns device Name. 488 * @since 6 489 */ 490 std::string GetName() const; 491 492 /** 493 * @brief Get device RSSI. 494 * 495 * @return Returns device RSSI. 496 * @since 6 497 */ 498 int8_t GetRSSI() const; 499 500 /** 501 * @brief Get service Data. 502 * 503 * @return Returns service data. 504 * @since 6 505 */ 506 std::vector<std::string> GetServiceData() const; 507 508 /** 509 * @brief Get Service Data. 510 * 511 * @param index Service data index. 512 * @return Returns service data. 513 * @since 6 514 */ 515 std::string GetServiceData(int index) const; 516 517 /** 518 * @brief Get service data UUID. 519 * 520 * @return Returns service data UUID. 521 * @since 6 522 */ 523 std::vector<Uuid> GetServiceDataUUID() const; 524 525 /** 526 * @brief Get service data UUID. 527 * 528 * @param index Service data index. 529 * @return Returns service data UUID. 530 * @since 6 531 */ 532 Uuid GetServiceDataUUID(int index) const; 533 534 /** 535 * @brief Get serviceU UUID. 536 * 537 * @return Returns service UUID. 538 * @since 6 539 */ 540 std::vector<Uuid> GetServiceUUID() const; 541 542 /** 543 * @brief Get service UUID. 544 * 545 * @param index Service UUID index. 546 * @return Return service UUID. 547 * @since 6 548 */ 549 Uuid GetServiceUUID(int index) const; 550 551 /** 552 * @brief Get advertiser data packet. 553 * 554 * @return Returns advertiser data packet. 555 * @since 6 556 */ 557 uint8_t *GetPayload() const; 558 559 /** 560 * @brief Get advertising packet length. 561 * 562 * @return Returns advertising packet length. 563 * @since 6 564 */ 565 size_t GetPayloadLen() const; 566 567 /** 568 * @brief Get address type. 569 * 570 * @return Returns address type. 571 * @since 6 572 */ 573 int GetAddressType() const; 574 575 /** 576 * @brief Set address type. 577 * 578 * @param type Address type. 579 * @since 6 580 */ 581 void SetAddressType(int type); 582 /** 583 * @brief Check if include manufacture data. 584 * 585 * @return Returns <b>true</b> if include manufacture data; 586 * returns <b>false</b> if do not include manufacture data. 587 * @since 6 588 */ 589 bool IsManufacturerData() const; 590 591 /** 592 * @brief Check if include device rssi. 593 * 594 * @return Returns <b>true</b> if include device rssi; 595 * returns <b>false</b> if do not include device rssi. 596 * @since 6 597 */ 598 bool IsRSSI() const; 599 600 /** 601 * @brief Check if include service data. 602 * 603 * @return Returns <b>true</b> if include service data; 604 * returns <b>false</b> if do not include service data. 605 * @since 6 606 */ 607 bool IsServiceData() const; 608 609 /** 610 * @brief Check if include service UUID. 611 * 612 * @return Returns <b>true</b> if include service UUID; 613 * returns <b>false</b> if do not include service UUID. 614 * @since 6 615 */ 616 bool IsServiceUUID() const; 617 618 /** 619 * @brief set device address. 620 * 621 * @param address device address. 622 * @since 6 623 */ 624 void SetAddress(const RawAddress &address); 625 626 /** 627 * @brief set rssi value. 628 * 629 * @param rssi rssi value. 630 * @since 6 631 */ 632 void SetRSSI(int8_t rssi); 633 634 /** 635 * @brief set rssi value. 636 * 637 * @param [in] rssi value. 638 */ 639 bool IsConnectable() const; 640 641 /** 642 * @brief set rssi value. 643 * 644 * @param [in] rssi value. 645 */ 646 void SetConnectable(bool connectable); 647 648 /** 649 * @brief Parse advertisement data. 650 * 651 * @param payload Advertisement packet. 652 * @param totalLen Advertisement packet total len. 653 * @since 6 654 */ 655 void ParseAdvertiserment(BlePeripheralDeviceParseAdvData &parseAdvData); 656 657 /** 658 * @brief Build advertisement data. 659 * 660 * @param advType Advertisement packet type. 661 * @param payload Advertisement packet. 662 * @param length Advertisement packet len. 663 * 664 * @since 6 665 */ 666 void BuildAdvertiserData(uint8_t advType, BlePeripheralDeviceParseAdvData &parseAdvData); 667 668 /** 669 * @brief Set service uuid 16 bit data. 670 * 671 * @param payload Advertisement packet. 672 * @param total_len Advertisement packet len. 673 * @since 6 674 */ 675 void SetServiceUUID16Bits(BlePeripheralDeviceParseAdvData &parseAdvData); 676 677 /** 678 * @brief Set service uuid 32 bit data. 679 * 680 * @param payload Advertisement packet. 681 * @param total_len Advertisement packet len. 682 * @since 6 683 */ 684 void SetServiceUUID32Bits(BlePeripheralDeviceParseAdvData &parseAdvData); 685 686 /** 687 * @brief Set service uuid 128 bit data. 688 * 689 * @param payload Advertisement packet. 690 * @param total_len Advertisement packet len. 691 * @since 6 692 */ 693 void SetServiceUUID128Bits(const BlePeripheralDeviceParseAdvData &parseAdvData); 694 695 /** 696 * @brief Set service data uuid 16 bit data. 697 * 698 * @param payload Advertisement packet. 699 * @param total_len Advertisement packet len. 700 * @since 6 701 */ 702 void SetServiceDataUUID16Bits(BlePeripheralDeviceParseAdvData &parseAdvData); 703 704 /** 705 * @brief Set service data uuid 32 bit data. 706 * 707 * @param payload Advertisement packet. 708 * @param total_len Advertisement packet len. 709 * @since 6 710 */ 711 void SetServiceDataUUID32Bits(BlePeripheralDeviceParseAdvData &parseAdvData); 712 713 /** 714 * @brief Set service data uuid 128 bit data. 715 * 716 * @param payload Advertisement packet. 717 * @param total_len Advertisement packet len. 718 * @since 6 719 */ 720 void SetServiceDataUUID128Bits(BlePeripheralDeviceParseAdvData &parseAdvData); 721 722 /** 723 * @brief Set device name. 724 * 725 * @param name Device name. 726 * @since 6 727 */ 728 void SetName(const std::string &name); 729 730 /** 731 * @brief Set device roles. 732 * 733 * @param roles Device roles. 734 * @since 6 735 */ 736 void SetRoles(uint8_t roles); 737 738 /** 739 * @brief Set bonded from local. 740 * 741 * @param flag Advertiser flag. 742 * @since 6 743 */ 744 void SetBondedFromLocal(bool flag); 745 746 /** 747 * @brief Set acl connect state. 748 * 749 * @param connectState Acl connect state. 750 * @since 6 751 */ 752 void SetAclConnectState(int connectState); 753 754 /** 755 * @brief Set acl connection handle. 756 * 757 * @param handle Acl connection handle. 758 * @since 6 759 */ 760 void SetConnectionHandle(int handle); 761 762 /** 763 * @brief Check if device acl connected. 764 * 765 * @return Returns <b>true</b> if device acl connected; 766 * returns <b>false</b> if device does not acl connect. 767 * @since 6 768 */ 769 bool IsAclConnected() const; 770 771 /** 772 * @brief Check if device acl Encrypted. 773 * 774 * @return Returns <b>true</b> if device acl Encrypted; 775 * returns <b>false</b> if device does not acl Encrypt. 776 * @since 6 777 */ 778 bool IsAclEncrypted() const; 779 780 /** 781 * @brief Check if device was bonded from local. 782 * 783 * @return Returns <b>true</b> if device was bonded from local; 784 * returns <b>false</b> if device was not bonded from local. 785 * @since 6 786 */ 787 bool IsBondedFromLocal() const; 788 789 /** 790 * @brief Get acl connection handle. 791 * 792 * @return Returns acl connection handle; 793 * @since 6 794 */ 795 int GetConnectionHandle() const; 796 797 /** 798 * @brief Get device type. 799 * 800 * @return Returns device type. 801 * @since 6 802 */ 803 uint8_t GetDeviceType() const; 804 805 /** 806 * @brief Get advertising flag. 807 * 808 * @return Returns advertising flag. 809 * @since 6 810 */ 811 uint8_t GetAdFlag() const; 812 813 /** 814 * @brief Get paired status. 815 * 816 * @return Returns paired status. 817 * @since 6 818 */ 819 uint8_t GetPairedStatus() const; 820 821 /** 822 * @brief Set paired status. 823 * 824 * @param status Paired status. 825 * @return Returns <b>true</b> if the operation is successful; 826 * returns <b>false</b> if the operation fails. 827 * @since 6 828 */ 829 bool SetPairedStatus(uint8_t status); 830 831 /** 832 * @brief Set alias name. 833 * 834 * @param name Device alias name. 835 * @since 6 836 */ 837 void SetAliasName(const std::string &name); 838 839 /** 840 * @brief Get alias name. 841 * 842 * @return Returns alias name. 843 * @since 6 844 */ 845 std::string GetAliasName() const; 846 847 /** 848 * @brief Set IO capability. 849 * 850 * @param io IO capability 851 * @since 6 852 */ 853 void SetIoCapability(uint8_t io); 854 855 /** 856 * @brief Get IO capability. 857 * 858 * @return Returns IO capability. 859 * @since 6 860 */ 861 uint8_t GetIoCapability() const; 862 863 /** 864 * @brief Set device type. 865 * 866 * @param type Device type. 867 * @since 6 868 */ 869 void SetDeviceType(uint8_t type); 870 871 /** 872 * @brief Set manufacturer data. 873 * 874 * @param manufacturerData Manufacturer data. 875 * @since 6 876 */ 877 void SetManufacturerData(std::string manufacturerData); 878 879 private: 880 /** 881 * @brief Set advertising flag. 882 * 883 * @param adFlag Advertising flag. 884 * @since 6 885 */ 886 void SetAdFlag(uint8_t adFlag); 887 888 /** 889 * @brief Set appearance. 890 * 891 * @param appearance Appearance. 892 * @since 6 893 */ 894 void SetAppearance(uint16_t appearance); 895 896 /** 897 * @brief Set service data UUID. 898 * 899 * @param uuid Service data UUID. 900 * @since 6 901 */ 902 void SetServiceDataUUID(Uuid uuid, std::string data); 903 904 /** 905 * @brief Set service UUID. 906 * 907 * @param serviceUUID Service UUID. 908 * @since 6 909 */ 910 void SetServiceUUID(Uuid serviceUUID); 911 /** 912 * @brief Set TX power. 913 * 914 * @param txPower TX power. 915 * @since 6 916 */ 917 void SetTXPower(int8_t txPower); 918 919 /// include appearance? 920 bool isAppearance_ = false; 921 /// include Manufacturer Data? 922 bool isManufacturerData_ = false; 923 /// include device name? 924 bool isName_ = false; 925 /// include rssi value? 926 bool isRSSI_ = false; 927 /// include service data? 928 bool isServiceData_ = false; 929 /// include service uuid? 930 bool isServiceUUID_ = false; 931 /// include tx power? 932 bool isTXPower_ = false; 933 /// peer roles 934 uint8_t roles_ = 0; 935 /// device address 936 RawAddress address_ = RawAddress("00:00:00:00:00:00"); 937 /// device address 938 RawAddress currentAddr_ = RawAddress("00:00:00:00:00:00"); 939 /// advertising flag 940 uint8_t adFlag_ = 0; 941 /// appearance 942 uint16_t appearance_ = 0; 943 /// manufacturer Data 944 std::map<uint16_t, std::string> manufacturerData_ {}; 945 /// device name 946 std::string name_ {}; 947 /// rssi value 948 int8_t rssi_ = 0; 949 /// service uuid 950 std::vector<Uuid> serviceUUIDs_ {}; 951 /// tx power 952 int8_t txPower_ {}; 953 /// service data 954 std::vector<std::string> serviceData_ {}; 955 /// service data uuid 956 std::vector<Uuid> serviceDataUUIDs_ {}; 957 /// address type 958 uint8_t addressType_ = BLE_ADDR_TYPE_RANDOM; 959 int aclConnected_ = 0; 960 int connectionHandle_ = 0; 961 bool bondFlag_ = false; 962 uint8_t pairState_ {}; 963 uint8_t ioCapability_ {}; 964 std::string aliasName_ {}; 965 bool connectable_ = true; 966 uint8_t* payload_ {}; 967 size_t payloadLen_ = 0; 968 }; 969 970 /** 971 * @brief Represents scan result. 972 * 973 * @since 6 974 */ 975 class BleScanResultImpl { 976 public: 977 /** 978 * @brief A constructor used to create a <b>BleScanResultInternal</b> instance. 979 * 980 * @since 6 981 */ BleScanResultImpl()982 BleScanResultImpl() : peripheralDevice_() 983 {} 984 985 /** 986 * @brief A destructor used to delete the <b>BleScanResultInternal</b> instance. 987 * 988 * @since 6 989 */ ~BleScanResultImpl()990 ~BleScanResultImpl() 991 {} 992 993 /** 994 * @brief Get peripheral device. 995 * 996 * @return Returns peripheral device pointer. 997 * @since 6 998 */ 999 BlePeripheralDevice GetPeripheralDevice() const; 1000 1001 /** 1002 * @brief Set peripheral device. 1003 * 1004 * @param dev Peripheral device. 1005 * @since 6 1006 */ 1007 void SetPeripheralDevice(const BlePeripheralDevice &dev); 1008 1009 /** 1010 * @brief Get service uuids. 1011 * 1012 * @return Returns service uuids. 1013 * @since 6 1014 */ GetServiceUuids()1015 std::vector<Uuid> GetServiceUuids() const 1016 { 1017 return serviceUuids_; 1018 } 1019 1020 /** 1021 * @brief Get manufacture data. 1022 * 1023 * @return Returns manufacture data. 1024 * @since 6 1025 */ GetManufacturerData()1026 std::map<uint16_t, std::string> GetManufacturerData() const 1027 { 1028 return manufacturerSpecificData_; 1029 } 1030 1031 /** 1032 * @brief Get service data. 1033 * 1034 * @return Returns service data. 1035 * @since 6 1036 */ GetServiceData()1037 std::map<Uuid, std::string> GetServiceData() const 1038 { 1039 return serviceData_; 1040 } 1041 1042 /** 1043 * @brief Get peer device rssi. 1044 * 1045 * @return Returns peer device rssi. 1046 * @since 6 1047 */ GetRssi()1048 int8_t GetRssi() const 1049 { 1050 return rssi_; 1051 } 1052 1053 /** 1054 * @brief Check if device is connectable. 1055 * 1056 * @return Returns <b>true</b> if device is connectable; 1057 * returns <b>false</b> if device is not connectable. 1058 * @since 6 1059 */ IsConnectable()1060 bool IsConnectable() const 1061 { 1062 return connectable_; 1063 } 1064 1065 /** 1066 * @brief Get advertiser flag. 1067 * 1068 * @return Returns advertiser flag. 1069 * @since 6 1070 */ GetAdvertiseFlag()1071 uint8_t GetAdvertiseFlag() const 1072 { 1073 return advertiseFlag_; 1074 } 1075 1076 /** 1077 * @brief Add manufacture data. 1078 * 1079 * @param manufacturerId Manufacture Id which addad data. 1080 * @since 6 1081 */ AddManufacturerData(uint16_t manufacturerId,std::string data)1082 void AddManufacturerData(uint16_t manufacturerId, std::string data) 1083 { 1084 manufacturerSpecificData_.insert(std::make_pair(manufacturerId, data)); 1085 } 1086 1087 /** 1088 * @brief Add service data. 1089 * 1090 * @param uuid Uuid of service data. 1091 * @param serviceData Service data. 1092 * @since 6 1093 */ AddServiceData(Uuid uuid,std::string serviceData)1094 void AddServiceData(Uuid uuid, std::string serviceData) 1095 { 1096 serviceData_.insert(std::make_pair(uuid, serviceData)); 1097 } 1098 1099 /** 1100 * @brief Add service uuid. 1101 * 1102 * @param serviceUuid Service uuid. 1103 * @since 6 1104 */ AddServiceUuid(const Uuid & serviceUuid)1105 void AddServiceUuid(const Uuid &serviceUuid) 1106 { 1107 serviceUuids_.push_back(serviceUuid); 1108 } 1109 1110 /** 1111 * @brief Set peripheral device. 1112 * 1113 * @param device Remote device. 1114 * @since 6 1115 */ SetPeripheralDevice(const RawAddress & device)1116 void SetPeripheralDevice(const RawAddress &device) 1117 { 1118 addr_ = device; 1119 } 1120 1121 /** 1122 * @brief Set peer device rssi. 1123 * 1124 * @param rssi Peer device rssi. 1125 * @since 6 1126 */ SetRssi(int8_t rssi)1127 void SetRssi(int8_t rssi) 1128 { 1129 rssi_ = rssi; 1130 } 1131 1132 /** 1133 * @brief Set connectable. 1134 * 1135 * @param connectable Whether it is connectable. 1136 * @since 6 1137 */ SetConnectable(bool connectable)1138 void SetConnectable(bool connectable) 1139 { 1140 connectable_ = connectable; 1141 } 1142 1143 /** 1144 * @brief Set advertiser flag. 1145 * 1146 * @param flag Advertiser flag. 1147 * @since 6 1148 */ SetAdvertiseFlag(uint8_t flag)1149 void SetAdvertiseFlag(uint8_t flag) 1150 { 1151 advertiseFlag_ = flag; 1152 } 1153 1154 private: 1155 /// scan device results 1156 BlePeripheralDevice peripheralDevice_; 1157 std::vector<Uuid> serviceUuids_ {}; 1158 std::map<uint16_t, std::string> manufacturerSpecificData_ {}; 1159 std::map<Uuid, std::string> serviceData_ {}; 1160 RawAddress addr_ {}; 1161 int8_t rssi_ {}; 1162 bool connectable_ {}; 1163 uint8_t advertiseFlag_ {}; 1164 }; 1165 } // namespace bluetooth 1166 #endif /// BLE_SERVICE_DATA_H 1167