From 963def301509c7620d497892e151dca575434867 Mon Sep 17 00:00:00 2001 From: Marcin Kraglak Date: Fri, 21 Nov 2014 12:16:40 +0100 Subject: [PATCH] android/hal-bluetooth: Implement read_energy_info --- android/bluetooth.c | 12 ++++++++++++ android/hal-bluetooth.c | 28 ++++++++++++++++++++++++++-- android/hal-msg.h | 12 ++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/android/bluetooth.c b/android/bluetooth.c index 947a83c23..ca3dd24b8 100644 --- a/android/bluetooth.c +++ b/android/bluetooth.c @@ -5155,6 +5155,16 @@ static void handle_get_connection_state(const void *buf, uint16_t len) -1); } +static void handle_read_energy_info(const void *buf, uint16_t len) +{ + DBG(""); + + /* TODO */ + + ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_READ_ENERGY_INFO, + HAL_STATUS_UNSUPPORTED); +} + static const struct ipc_handler cmd_handlers[] = { /* HAL_OP_ENABLE */ { handle_enable_cmd, false, 0 }, @@ -5208,6 +5218,8 @@ static const struct ipc_handler cmd_handlers[] = { /* HAL_OP_GET_CONNECTION_STATE */ { handle_get_connection_state, false, sizeof(struct hal_cmd_get_connection_state) }, + /* HAL_OP_READ_ENERGY_INFO */ + { handle_read_energy_info, false, 0 }, }; bool bt_bluetooth_register(struct ipc *ipc, uint8_t mode) diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c index defaef1ab..7be02edd9 100644 --- a/android/hal-bluetooth.c +++ b/android/hal-bluetooth.c @@ -349,6 +349,26 @@ static void handle_le_test_mode(void *buf, uint16_t len, int fd) bt_hal_cbacks->le_test_mode_cb(ev->status, ev->num_packets); } +static void handle_energy_info(void *buf, uint16_t len, int fd) +{ +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0) + struct hal_ev_energy_info *ev = buf; + bt_activity_energy_info info; + + DBG(""); + + info.ctrl_state = ev->ctrl_state; + info.energy_used = ev->energy_used; + info.idle_time = ev->idle_time; + info.rx_time = ev->rx_time; + info.status = ev->status; + info.tx_time = ev->status; + + if (bt_hal_cbacks->energy_info_cb) + bt_hal_cbacks->energy_info_cb(&info); +#endif +} + /* * handlers will be called from notification thread context, * index in table equals to 'opcode - HAL_MINIMUM_EVENT' @@ -386,6 +406,8 @@ static const struct hal_ipc_handler ev_handlers[] = { sizeof(struct hal_ev_dut_mode_receive) }, /* HAL_EV_LE_TEST_MODE */ { handle_le_test_mode, false, sizeof(struct hal_ev_le_test_mode) }, + /* HAL_EV_ENERGY_INFO */ + { handle_energy_info, false, sizeof(struct hal_ev_energy_info) }, }; static uint8_t get_mode(void) @@ -992,9 +1014,11 @@ static int read_energy_info(void) { DBG(""); - /* TODO: implement */ + if (!interface_ready()) + return BT_STATUS_NOT_READY; - return BT_STATUS_UNSUPPORTED; + return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_READ_ENERGY_INFO, 0, + NULL, NULL, NULL, NULL); } #endif diff --git a/android/hal-msg.h b/android/hal-msg.h index 6a5a81c7a..9baa2d9e2 100644 --- a/android/hal-msg.h +++ b/android/hal-msg.h @@ -261,6 +261,8 @@ struct hal_rsp_get_connection_state { int32_t connection_state; } __attribute__((packed)); +#define HAL_OP_READ_ENERGY_INFO 0x16 + /* Bluetooth Socket HAL api */ #define HAL_SOCK_RFCOMM 0x01 @@ -1348,6 +1350,16 @@ struct hal_ev_le_test_mode { uint16_t num_packets; } __attribute__((packed)); +#define HAL_EV_ENERGY_INFO 0x8c +struct hal_ev_energy_info { + uint8_t status; + uint8_t ctrl_state; + uint64_t tx_time; + uint64_t rx_time; + uint64_t idle_time; + uint64_t energy_used; +} __attribute__((packed)); + #define HAL_HIDHOST_STATE_CONNECTED 0x00 #define HAL_HIDHOST_STATE_CONNECTING 0x01 #define HAL_HIDHOST_STATE_DISCONNECTED 0x02 -- 2.47.3