Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #define LOG_TAG "beacon_swarm"
     18 
     19 #include "beacon_swarm.h"
     20 #include "stack/include/hcidefs.h"
     21 
     22 using std::vector;
     23 
     24 namespace test_vendor_lib {
     25 BeaconSwarm::BeaconSwarm() {
     26   advertising_interval_ms_ = std::chrono::milliseconds(1280);
     27   advertising_type_ = BTM_BLE_NON_CONNECT_EVT;
     28   adv_data_ = {0x02,  // Length
     29                BTM_BLE_AD_TYPE_FLAG,
     30                BTM_BLE_BREDR_NOT_SPT | BTM_BLE_GEN_DISC_FLAG,
     31                0x15,
     32                BTM_BLE_AD_TYPE_NAME_CMPL,
     33                'g',
     34                'D',
     35                'e',
     36                'v',
     37                'i',
     38                'c',
     39                'e',
     40                '-',
     41                'b',
     42                'e',
     43                'a',
     44                'c',
     45                'o',
     46                'n',
     47                '_',
     48                's',
     49                'w',
     50                'a',
     51                'r',
     52                'm'};
     53 
     54   scan_response_present_ = true;
     55   scan_data_ = {0x06,  // Length
     56                 BTM_BLE_AD_TYPE_NAME_SHORT,
     57                 'c',
     58                 'b',
     59                 'e',
     60                 'a',
     61                 'c'};
     62 }
     63 
     64 void BeaconSwarm::Initialize(const vector<std::string>& args) {
     65   if (args.size() < 2) return;
     66 
     67   BtAddress addr;
     68   if (addr.FromString(args[1])) SetBtAddress(addr);
     69 
     70   if (args.size() < 3) return;
     71 
     72   SetAdvertisementInterval(std::chrono::milliseconds(std::stoi(args[2])));
     73 }
     74 
     75 void BeaconSwarm::TimerTick() {
     76   std::vector<uint8_t> beacon_addr;
     77   GetBtAddress().ToVector(beacon_addr);
     78   beacon_addr[0]++;
     79   BtAddress next_addr;
     80   next_addr.FromVector(beacon_addr);
     81 
     82   SetBtAddress(next_addr);
     83 }
     84 
     85 }  // namespace test_vendor_lib
     86