btm_ble_cont_energy.cc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /******************************************************************************
  2. *
  3. * Copyright 2014 Broadcom Corporation
  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. *
  17. ******************************************************************************/
  18. #include <string.h>
  19. #include "bt_target.h"
  20. #include "bt_types.h"
  21. #include "bt_utils.h"
  22. #include "btm_ble_api.h"
  23. #include "btm_int.h"
  24. #include "btu.h"
  25. #include "hcidefs.h"
  26. #include "hcimsgs.h"
  27. tBTM_BLE_ENERGY_INFO_CB ble_energy_info_cb;
  28. /*******************************************************************************
  29. *
  30. * Function btm_ble_cont_energy_cmpl_cback
  31. *
  32. * Description Controller VSC complete callback
  33. *
  34. * Parameters
  35. *
  36. * Returns void
  37. *
  38. ******************************************************************************/
  39. void btm_ble_cont_energy_cmpl_cback(tBTM_VSC_CMPL* p_params) {
  40. uint8_t* p = p_params->p_param_buf;
  41. uint16_t len = p_params->param_len;
  42. uint8_t status = 0;
  43. uint32_t total_tx_time = 0, total_rx_time = 0, total_idle_time = 0,
  44. total_energy_used = 0;
  45. if (len < 17) {
  46. BTM_TRACE_ERROR("wrong length for btm_ble_cont_energy_cmpl_cback");
  47. return;
  48. }
  49. STREAM_TO_UINT8(status, p);
  50. STREAM_TO_UINT32(total_tx_time, p);
  51. STREAM_TO_UINT32(total_rx_time, p);
  52. STREAM_TO_UINT32(total_idle_time, p);
  53. STREAM_TO_UINT32(total_energy_used, p);
  54. BTM_TRACE_DEBUG(
  55. "energy_info status=%d,tx_t=%ld, rx_t=%ld, ener_used=%ld, idle_t=%ld",
  56. status, total_tx_time, total_rx_time, total_energy_used, total_idle_time);
  57. if (NULL != ble_energy_info_cb.p_ener_cback)
  58. ble_energy_info_cb.p_ener_cback(total_tx_time, total_rx_time,
  59. total_idle_time, total_energy_used, status);
  60. return;
  61. }
  62. /*******************************************************************************
  63. *
  64. * Function BTM_BleGetEnergyInfo
  65. *
  66. * Description This function obtains the energy info
  67. *
  68. * Parameters p_ener_cback - Callback pointer
  69. *
  70. * Returns status
  71. *
  72. ******************************************************************************/
  73. tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK* p_ener_cback) {
  74. tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
  75. BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
  76. BTM_TRACE_EVENT("BTM_BleGetEnergyInfo");
  77. if (0 == cmn_ble_vsc_cb.energy_support) {
  78. BTM_TRACE_ERROR("Controller does not support get energy info");
  79. return BTM_ERR_PROCESSING;
  80. }
  81. ble_energy_info_cb.p_ener_cback = p_ener_cback;
  82. BTM_VendorSpecificCommand(HCI_BLE_ENERGY_INFO_OCF, 0, NULL,
  83. btm_ble_cont_energy_cmpl_cback);
  84. return BTM_CMD_STARTED;
  85. }