• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2018 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17import csv
18import os
19import time
20import acts_contrib.test_utils.bt.bt_test_utils as btutils
21import acts_contrib.test_utils.power.PowerBTBaseTest as PBtBT
22
23EXTRA_PLAY_TIME = 30
24GET_PROPERTY_HARDWARE_PLATFORM = 'getprop ro.boot.hardware.platform'
25
26
27class PowerBTcalibrationTest(PBtBT.PowerBTBaseTest):
28    def setup_test(self):
29
30        super().setup_test()
31        self.attenuator = self.attenuators[0]
32        btutils.enable_bqr(self.dut)
33        time.sleep(2)
34        btutils.disable_bluetooth(self.dut.droid)
35        time.sleep(2)
36        btutils.enable_bluetooth(self.dut.droid, self.dut.ed)
37        btutils.connect_phone_to_headset(self.dut, self.bt_device, 60)
38        vol = self.dut.droid.getMaxMediaVolume() * self.volume
39        self.dut.droid.setMediaVolume(int(vol))
40
41        self.cal_data_path = os.path.join(self.log_path, 'Calibration')
42        self.log_file = os.path.join(self.cal_data_path, 'Cal_data.csv')
43        os.makedirs(os.path.dirname(self.log_file), exist_ok=True)
44
45    def test_calibrate(self):
46        """Run calibration to get attenuation value at each power level
47
48        """
49
50        self.cal_matrix = []
51        self.media.play()
52        time.sleep(EXTRA_PLAY_TIME)
53
54        # Loop through attenuation in 1 dB step
55        self.log.info('Starting Calibration Process')
56        for i in range(int(self.attenuator.get_max_atten())):
57            try:
58                self.attenuator.set_atten(i)
59                bt_metrics_dict = btutils.get_bt_metric(self.dut)
60                pwl = bt_metrics_dict['pwlv'][self.dut.serial]
61                rssi = bt_metrics_dict['rssi'][self.dut.serial]
62                bftx = bt_metrics_dict['bftx'][self.dut.serial]
63                self.log.info(
64                    'Reach PW {}, RSSI {}, BFTX {} at attenuation {} dB'.format(
65                        pwl, rssi, bftx, i))
66            except Exception as e:
67                self.log.warning('Get Exception {} at attenuation {} dB'.format(
68                    str(e), i))
69                continue
70            self.cal_matrix.append([i, pwl, rssi, bftx])
71
72        # Write cal results to csv
73        with open(self.log_file, 'w', newline='') as f:
74            writer = csv.writer(f)
75            writer.writerows(self.cal_matrix)
76