Add GetEnergyInfo method for the power management 98/228598/1
authorDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 24 Mar 2020 05:46:40 +0000 (14:46 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 24 Mar 2020 05:52:22 +0000 (14:52 +0900)
Change-Id: I46afc2c2575f996723b175a6febbeff0ff5938f1
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
doc/adapter-api.txt
src/adapter.c
src/adapter_le_vsc_features.c
src/adapter_le_vsc_features.h

index 608d17f..f24b99f 100755 (executable)
@@ -340,6 +340,13 @@ Methods            void StartDiscovery()
                        all SDP records.
 
                        Possible errors: org.bluez.Error.InvalidArguments
+
+               void GetEnergyInfo()
+
+                       Gets the energy information such like the performing
+                       time for Tx / Rx / idle.
+
+                       Possible errors: org.bluez.Error.NotSupported
 #endif
 
 Properties     string Address [readonly]
index 52ecbd6..294121b 100644 (file)
@@ -5913,6 +5913,39 @@ static DBusMessage *adapter_set_manufacturer_data(DBusConnection *conn,
 
        return btd_error_failed(msg, "Set manufacturer data failed");
 }
+
+static DBusMessage *adapter_get_energy_info(DBusConnection *conn,
+                                               DBusMessage *msg, void *user_data)
+{
+       DBusMessage *reply;
+       uint32_t tx_time = 0;
+       uint32_t rx_time = 0;
+       uint32_t idle_time = 0;
+       uint32_t energy_used = 0;
+
+       if (adapter_le_get_energy_info(&tx_time, &rx_time,
+                                       &idle_time, &energy_used) == FALSE) {
+               error("Fail to send vcs for getting energy info");
+               reply = btd_error_not_supported(msg);
+               goto done;
+       }
+
+       reply = g_dbus_create_reply(msg,
+                               DBUS_TYPE_UINT32, &tx_time,
+                               DBUS_TYPE_UINT32, &rx_time,
+                               DBUS_TYPE_UINT32, &idle_time,
+                               DBUS_TYPE_UINT32, &energy_used,
+                               DBUS_TYPE_INVALID);
+
+       if (!reply)
+               reply = btd_error_failed(msg,
+                                       "Failed to create reply.");
+
+done:
+       return reply;
+}
+
+
 #endif /* TIZEN_FEATURE_BLUEZ_MODIFY */
 
 static DBusMessage *start_discovery(DBusConnection *conn,
@@ -7632,6 +7665,13 @@ static const GDBusMethodTable adapter_methods[] = {
        { GDBUS_ASYNC_METHOD("CreateDevice",
                        GDBUS_ARGS({ "address", "s" }), NULL,
                        create_device) },
+       { GDBUS_METHOD("GetEnergyInfo",
+                       NULL,
+                       GDBUS_ARGS({ "tx_time", "u" },
+                               { "rx_time", "u" },
+                               { "idle_time", "u" },
+                               { "energy_used", "u" }),
+                       adapter_get_energy_info) },
 #endif
        { GDBUS_ASYNC_METHOD("RemoveDevice",
                        GDBUS_ARGS({ "device", "o" }), NULL, remove_device) },
index 771a88f..5d0aee4 100755 (executable)
@@ -806,5 +806,46 @@ gboolean adapter_le_remove_irk_to_list(const bdaddr_t *bdaddr, uint8_t bdaddr_ty
        return TRUE;
 }
 
+gboolean adapter_le_get_energy_info(
+                                       uint32_t *tx_time, uint32_t *rx_time,
+                                       uint32_t *idle_time, uint32_t *energy_used)
+{
+       int ret;
+
+       adapter_le_vsc_rp_get_energy_info rp;
+       memset(&rp, 0, sizeof(rp));
+
+       DBG("");
+
+       ret = send_vsc_command(OCF_BCM_LE_GET_ENERGY_INFO, (uint8_t *) NULL, 0,
+                                               (uint8_t *) &rp, sizeof(rp));
+       if (ret < 0)
+               return FALSE;
+
+       if (HCI_SUCCESS != rp.status) {
+               error("Fail to get energy info");
+               return FALSE;
+       }
+
+       DBG("======== BLE energy info ========");
+       DBG("Result [%d]", rp.status);
+       DBG("Total time performing Tx [%d]", rp.tx_time);
+       DBG("Total time performing Rx [%d]", rp.rx_time);
+       DBG("Total time in idle [%d]", rp.idle_time);
+       DBG("Total energy used [%d]", rp.energy_used);
+       DBG("=================================");
+
+       if (rp.status != 0) {
+               error("Fail to get energy info: %d", rp.status);
+               return FALSE;
+       }
+
+       *tx_time = rp.tx_time;
+       *rx_time = rp.rx_time;
+       *idle_time = rp.idle_time;
+       *energy_used = rp.energy_used;
+
+       return TRUE;
+}
 
 #endif /* TIZEN_FEATURE_BLUEZ_MODIFY */
index 1a74f02..fdccd22 100755 (executable)
@@ -480,6 +480,30 @@ typedef struct {
        uint8_t available_space;
 } __attribute__ ((packed)) adapter_le_vsc_rp_irk_to_list;
 
+#define OCF_BCM_LE_GET_ENERGY_INFO    0x0159     /* LE Get Energy Information */
+
+/*****************************************************************************
+**                          RP for OCF_BCM_LE_GET_ENERGY_INFO
+**
+*/
+
+/**
+*
+* RP
+*
+* (1 octet) status      : Command complete status
+* (4 octet) tx_time     : Total time performing Tx
+* (4 octet) rx_time     : Total time performing Rx
+* (4 octet) idle_time   : Total time in idle
+* (4 octet) energy_used : Total energy used
+*/
+typedef struct {
+       uint8_t status;
+       uint32_t tx_time;
+       uint32_t rx_time;
+       uint32_t idle_time;
+       uint32_t energy_used;
+} __attribute__ ((packed)) adapter_le_vsc_rp_get_energy_info;
 
 /*****************************************************************************
 **                          Functions
@@ -530,4 +554,8 @@ gboolean adapter_le_add_irk_to_list(const uint8_t *le_irk, const bdaddr_t *bdadd
 
 gboolean adapter_le_remove_irk_to_list(const bdaddr_t *bdaddr, uint8_t bdaddr_type);
 
+gboolean adapter_le_get_energy_info(uint32_t *tx_time, uint32_t *rx_time,
+                                       uint32_t *idle_time, uint32_t *energy_used);
+
+
 #endif /* TIZEN_FEATURE_BLUEZ_MODIFY */