diff options
author | INSUN PYO <insun.pyo@samsung.com> | 2021-09-09 15:54:34 +0900 |
---|---|---|
committer | INSUN PYO <insun.pyo@samsung.com> | 2021-09-09 16:02:54 +0900 |
commit | 1b068b0f52fe40bf6395c81ccdec01f34c8e1327 (patch) | |
tree | 19674d4493a38417faa73c0982441b42d939a4d8 | |
parent | 2576ebfd6ce8bd477fff6fac459bd9bf72e3ef6e (diff) | |
download | session-utils-tizen.tar.gz session-utils-tizen.tar.bz2 session-utils-tizen.zip |
Add battery monitor on TW3tizen
Change-Id: Ic0825f69ff80487e05f5495be8f59b64537fbeed
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | packaging/session-utils.spec | 17 | ||||
-rw-r--r-- | src/battery-monitor/CMakeLists.txt | 20 | ||||
-rw-r--r-- | src/battery-monitor/battery-monitor.c | 59 |
4 files changed, 98 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e9772dd..15e7388 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,3 +13,5 @@ ADD_SUBDIRECTORY(src/kernel-module-load) ADD_SUBDIRECTORY(src/udev-monitor) ADD_SUBDIRECTORY(src/udev-enumerate) ADD_SUBDIRECTORY(src/sensor) +ADD_SUBDIRECTORY(src/battery-monitor) + diff --git a/packaging/session-utils.spec b/packaging/session-utils.spec index 4d6f536..fc1941c 100644 --- a/packaging/session-utils.spec +++ b/packaging/session-utils.spec @@ -27,6 +27,9 @@ BuildRequires: arm-rpi4-linux-kernel-devel # sensor BuildRequires: pkgconfig(capi-system-sensor) +# sensor +BuildRequires: pkgconfig(capi-system-battery-monitor) + %description This package provides some utils for session control in multi-user environment. @@ -144,6 +147,14 @@ This package provides sensor ############################################################################### +%package -n battery-monitor +Summary: battery-monitor + +%description -n battery-monitor +This package provides battery-monitor on TW3 + + +############################################################################### %prep %setup -q @@ -282,3 +293,9 @@ cd .. %license LICENSE.Apache-2.0 %manifest %{name}.manifest %{_bindir}/sensor + +############################################################################### +%files -n battery-monitor +%license LICENSE.Apache-2.0 +%manifest %{name}.manifest +%{_bindir}/battery-monitor diff --git a/src/battery-monitor/CMakeLists.txt b/src/battery-monitor/CMakeLists.txt new file mode 100644 index 0000000..2a17e61 --- /dev/null +++ b/src/battery-monitor/CMakeLists.txt @@ -0,0 +1,20 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(battery-monitor C) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + capi-system-battery-monitor +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") + +ADD_EXECUTABLE(battery-monitor battery-monitor.c) +TARGET_LINK_LIBRARIES(battery-monitor ${pkgs_LDFLAGS} -pie) + +INSTALL(TARGETS battery-monitor DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) diff --git a/src/battery-monitor/battery-monitor.c b/src/battery-monitor/battery-monitor.c new file mode 100644 index 0000000..5ee53fa --- /dev/null +++ b/src/battery-monitor/battery-monitor.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include <time.h> +#include <battery_monitor.h> + +int err_enum[9] = {BATTERY_MONITOR_ERROR_OUT_OF_MEMORY, BATTERY_MONITOR_ERROR_INVALID_PARAMETER, BATTERY_MONITOR_ERROR_NO_DATA, + BATTERY_MONITOR_ERROR_PERMISSION_DENIED, BATTERY_MONITOR_ERROR_NOT_SUPPORTED, BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND, + BATTERY_MONITOR_ERROR_DB_FAILED, BATTERY_MONITOR_ERROR_DB_NOT_OPENED, BATTERY_MONITOR_ERROR_INTERNAL}; +char *err_name[9] = {"BATTERY_MONITOR_ERROR_OUT_OF_MEMORY", "BATTERY_MONITOR_ERROR_INVALID_PARAMETER", "BATTERY_MONITOR_ERROR_NO_DATA", + "BATTERY_MONITOR_ERROR_PERMISSION_DENIED", "BATTERY_MONITOR_ERROR_NOT_SUPPORTED", "BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND", + "BATTERY_MONITOR_ERROR_DB_FAILED", "BATTERY_MONITOR_ERROR_DB_NOT_OPENED", "BATTERY_MONITOR_ERROR_INTERNAL"}; + +int resource_enum[6] = {BATTERY_MONITOR_RESOURCE_ID_BLE, BATTERY_MONITOR_RESOURCE_ID_WIFI, BATTERY_MONITOR_RESOURCE_ID_CPU, + BATTERY_MONITOR_RESOURCE_ID_DISPLAY, BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK, BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR}; +char *resource_name[6] = {"bluetooth", "WIFI", "CPU", "DISPLAY", "Device Network", "GPU Sensor"}; +char *app_id = "org.tizen.multi-assistant-service"; + +int main() +{ + battery_usage_data_h data_h; + double result; + int ret; + + time_t now = time(NULL) - 10; + time_t from = now - 60 * 60 * 24 * 7; // a week + + printf("total : %lfmah\n", result); + printf("-------------------------------------------------------------\n"); + + printf("All apps power usage : \n"); + for (int i = 0; i < 6; ++i){ + battery_monitor_get_power_usage_by_resource(resource_enum[i], from, now, &result); + printf("%s : %lfmah\n", resource_name[i], result); + } + + printf("-------------------------------------------------------------\n"); + printf("app : %s\n", app_id); + + ret = battery_monitor_get_power_usage_by_app_for_all_resources(app_id, from, now, &data_h); + if (ret < 0){ + char *str; + for(int i = 0; i < 9; ++i){ + if (ret == err_enum[i]){ + str = err_name[i]; + break; + } + } + printf("error : %s\n", str); + return ret; + } + + for (int i = 0; i < 6; ++i){ + battery_monitor_usage_data_get_power_usage_per_resource(data_h, resource_enum[i], &result); + printf("%s : %lfmah\n", resource_name[i], result); + } + + battery_monitor_get_power_usage_by_app(app_id, from, now, &result); + + return 0; +} |