#include <glib/gprintf.h>
#include <stdio.h>
#include <unistd.h>
-//#include <vconf.h>
#include "bd_history_item.h"
#include "bm_util.h"
#include "bm_dbg.h"
#include "bm_server_db.h"
#include "bm_private.h"
#include "bd_private.h"
-//#include "bm_power_engine.h"
-
+/* For Test Purpose Only */
+#include "bd_history_item_dummy.h"
dump_data_s history_data[HISTORY_SIZE_MAX];
int h_count = 0; int h_flag = false;
return BATTERY_MONITOR_ERROR_NONE;
}
-static int bd_print_history_item_reset(history_item_s* old_state)
+int bd_print_history_item_reset(history_item_s* old_state)
{
ENTER;
BM_CHECK_INPUT_PARAM(old_state);
}
int change = (old_state.state_1 ^ new_state.state_1);
if (change != 0) {
- bool wake_fl = false;
- int shifts = 1;
- for (int i = 0; i < 32; i++) {
+ bool wake_fl = false; int k = 0;
+ if ((change & ST1_BRIGHTNESS_MASK) != 0) {
+ k = (new_state.state_1 & ST1_BRIGHTNESS_MASK);
+ dump_p = g_string_append(dump_p, ",Sb=");
+ k = k >> ST1_BRIGHTNESS_SHIFT;
+ _DBG("Sb = %d", k);
+ g_string_append_printf(dump_p, "%d", k);
+ k = 0;
+ }
+ if ((change & ST1_PHONE_SIGNAL_STRENGTH_MASK) != 0) {
+ k = (new_state.state_1 & ST1_PHONE_SIGNAL_STRENGTH_MASK);
+ dump_p = g_string_append(dump_p, ",Pss=");
+ k = k >> ST1_PHONE_SIGNAL_STRENGTH_SHIFT;
+ _DBG("Pss = %d", k);
+ g_string_append_printf(dump_p, "%d", k);
+ k = 0;
+ }
+ int shifts = (1 << 14);
+ for (int i = 14; i < 32; i++) {
if ((change & shifts) != 0) {
dump_p = g_string_append_c(dump_p, ',');
//Considering only -ve shift cases
if (chkin)
g_string_append_printf(dump_p,
"%d", new_state.wakelock_tag->sp_idx);
- else{
+ else {
//: NC
}
//_DBG("value %s", dump_p->str);
time_t current_time;
time(¤t_time); //This time needs to be changed to MT
- history_data[h_count].time_s = current_time;
+// history_data[h_count].time_s = current_time;// comment for testing with test fn
+ history_data[h_count].time_s = nrec->time_s;
dvar1 = ((nrec->cmd_s) & 0xff) | ((nrec->battery_level << 8) & 0xff00) |
((nrec->battery_status << 16) & 0xf0000) |
if (nrec->wakereason_tag != NULL)
history_data[h_count].wakereason_tag = nrec->wakereason_tag;
if (nrec->event_code != ET_NONE) {
+ _DBG("HI");
+ if (nrec->event_tag == NULL)
+ _ERR("IT is NULL");
history_data[h_count].event_code = nrec->event_code;
history_data[h_count].event_tag = nrec->event_tag;
}
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
-}
+}*/
+/*
static int bd_make_string_maps()
{
ENTER;
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
-}
-*/
+}*/
static int *dumpsys_handler;
}
}
+ checkin = true;
ret = bd_print_history_item_main(fd, -1, 0, checkin);
if (ret != BATTERY_MONITOR_ERROR_NONE) {
_ERR("bd_print_history_item_main failed (%x)", ret);
h_count = 0; h_flag = true;
_INFO("Battery Dump Init Successful");
//Remove
- //bd_make_string_maps();
+ // Uncomment to test
+ bd_dummy_test_fn();
+
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
}
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
}
-//Remove all DBG statements in final patch
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "bd_history_item.h"
+#include "bm_dbg.h"
+#include "bm_common.h"
+#include <stdlib.h>
+#include <time.h>
+#include <glib/gprintf.h>
+#include <stdio.h>
+#include "bd_history_item_dummy.h"
+
+int pool_idx = 0;
+int pool_idx_map_s1[32];
+int pool_idx_map_s2[32];
+int gl_time = 1;
+
+/*
+static int create_sp_idx(int mask, int state)
+{
+ ENTER;
+
+ if (state == 1) {
+ if (pool_idx_map_s1[mask] == -1) {
+ pool_idx_map_s1[mask] = pool_idx++;
+ }
+ } else if (state == 2) {
+ if (pool_idx_map_s2[mask] == -1) {
+ pool_idx_map_s2[mask] = pool_idx++;
+ }
+ }
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
+
+static int remove_sp_idx(int mask, int state)
+{
+ ENTER;
+
+ if (state == 1) {
+ if (pool_idx_map_s1[mask] != -1) {
+ pool_idx_map_s1[mask] = -1;
+ }
+ } else if (state == 2) {
+ if (pool_idx_map_s2[mask] != -1;) {
+ pool_idx_map_s2[mask] = -1;
+ }
+ }
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
+*/
+
+static int create_history_tag(history_item_s* ts, int mask, int state, int on)
+{
+ ENTER;
+
+ ts->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if (ts->event_tag != NULL) {
+ _DBG("Memory created successfully");
+ GString *temp = ts->event_tag->string_info;
+ temp = g_string_sized_new(30);
+ BM_CHECK_MEM_ALLOC(temp, {});
+ ts->event_tag->uid = 0; //All events are associated with tizen
+ if (state == 1) {
+ if (pool_idx_map_s1[mask] == -1) {
+ pool_idx_map_s1[mask] = pool_idx++;
+ ts->event_tag->sp_idx = pool_idx_map_s1[mask];
+ } else {
+ ts->event_tag->sp_idx = pool_idx_map_s1[mask];
+ pool_idx_map_s1[mask] = -1;
+ }
+ } else if (state == 2) {
+ if (pool_idx_map_s2[mask] == -1) {
+ pool_idx_map_s2[mask] = pool_idx++;
+ ts->event_tag->sp_idx = pool_idx_map_s2[mask];
+ } else {
+ ts->event_tag->sp_idx = pool_idx_map_s2[mask];
+ pool_idx_map_s1[mask] = -1;
+ }
+ } else
+ ts->event_tag->sp_idx = pool_idx++;
+
+ if (on)
+ temp = g_string_append(temp, "tizen:ON");
+ else
+ temp = g_string_append(temp, "tizen:OFF");
+ ts->event_tag->string_info = temp;
+ _DBG("%s", ts->event_tag->string_info->str);
+ }
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
+
+int bd_dummy_test_fn()
+{
+ ENTER;
+
+ for (int i = 0; i < 32; i++) {
+ pool_idx_map_s1[i] = -1;
+ pool_idx_map_s2[i] = -1;
+ }
+
+ history_item_s ts;
+ //Node 0
+ bd_print_history_item_reset(&ts);
+ ts.cmd_s = CM_CRR_TIME; ts.event_code = ET_NONE;
+ ts.event_tag = NULL; ts.wakelock_tag = NULL;
+ ts.wakereason_tag = NULL; ts.time_s = 10*(gl_time++);
+ bd_store_history_item(&ts);
+
+ // Common
+ ts.battery_status = 'd'; ts.battery_temperature = 226;
+ ts.battery_voltage = 4274; ts.battery_charge = 0;
+ ts.wakelock_tag = NULL; ts.wakelock_tag = NULL;
+
+ // Node 1
+ /*
+ state 2 wifi on
+ event connectivity change
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 = 0;
+ ts.state_2 = ST2_WIFI_ON_FLAG;
+ ts.battery_level = 99; ts.battery_health = 'g';
+ ts.battery_plugtype = 'n';
+ ts.event_code = ET_CONNECTIVITY_CHANGED;
+ ts.event_code |= ET_FLAG_START;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 28, 2, 1);
+ bd_store_history_item(&ts);
+
+ // Node 2
+ /*
+ state 2 wifi off
+ event connectivity change
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_2 &= ~(ST2_WIFI_ON_FLAG);
+ ts.battery_level = 97;
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_FINISH;
+ ts.event_code |= ET_CONNECTIVITY_CHANGED;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 28, 2, 0);
+ bd_store_history_item(&ts);
+
+ // Node 3
+ /*
+ state 1 wifi scan on
+ event connectivity change
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 |= ST1_WIFI_SCAN_FLAG;
+ ts.battery_level = 95; ts.battery_health = 'g';
+ ts.battery_plugtype = 'n';
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_START;
+ ts.event_code |= ET_CONNECTIVITY_CHANGED;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 27, 1, 1);
+ bd_store_history_item(&ts);
+
+ // Node 4
+ /*
+ state 1 wifi scan off
+ event connectivity change
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 &= ~(ST1_WIFI_SCAN_FLAG);
+ ts.battery_level = 94;
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_FINISH;
+ ts.event_code |= ET_CONNECTIVITY_CHANGED;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 27, 1, 0);
+ bd_store_history_item(&ts);
+
+ // Node 5
+ /*
+ state 2 bt on
+ event connectivity change
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_2 |= ST2_BLUETOOTH_ON_FLAG;
+ ts.battery_level = 92;
+ ts.battery_plugtype = 'n';
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_START;
+ ts.event_code |= ET_CONNECTIVITY_CHANGED;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 22, 2, 1);
+ bd_store_history_item(&ts);
+
+ // Node 6
+ /*
+ state 2 bt off
+ event connectivity change
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_2 &= ~(ST2_BLUETOOTH_ON_FLAG);
+ ts.battery_level = 90;
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_FINISH;
+ ts.event_code |= ET_CONNECTIVITY_CHANGED;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 22, 2, 0);
+ bd_store_history_item(&ts);
+
+ // Node 7
+ /*
+ state 2 bt scan on
+ event connectivity change
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_2 |= ST2_BLUETOOTH_SCAN_FLAG;
+ ts.battery_level = 88;
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_START;
+ ts.event_code |= ET_CONNECTIVITY_CHANGED;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 20, 2, 1);
+ bd_store_history_item(&ts);
+
+ // Node 8
+ /*
+ state 2 bt scan off
+ event connectivity change
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_2 &= ~(ST2_BLUETOOTH_SCAN_FLAG);
+ ts.battery_level = 87;
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_FINISH;
+ ts.event_code |= ET_CONNECTIVITY_CHANGED;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 20, 2, 0);
+ bd_store_history_item(&ts);
+
+
+ // Node 9
+ /*
+ state 1 screen on
+ event screen wakeup
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 |= ST1_SCREEN_ON_FLAG;
+ ts.battery_level = 85; ts.battery_health = 'g';
+ ts.battery_plugtype = 'n';
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_START;
+ ts.event_code |= ET_SCREEN_WAKE_UP;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 20, 1, 1);
+ bd_store_history_item(&ts);
+
+ // Node 10
+ /*
+ state 1 screen off
+ event screen wakeup (off)
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 &= ~(ST1_SCREEN_ON_FLAG);
+ ts.battery_level = 83; ts.battery_health = 'g';
+ ts.battery_plugtype = 'n';
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_FINISH;
+ ts.event_code |= ET_SCREEN_WAKE_UP;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 20, 1, 0);
+ bd_store_history_item(&ts);
+
+ // Node 11
+ /*
+ sensor on flag
+ event wakeup
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 |= ST1_SENSOR_ON_FLAG;
+ ts.battery_level = 83; ts.battery_health = 'g';
+ ts.battery_plugtype = 'n';
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_START;
+ ts.event_code |= ET_WAKEUP_AP;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 23, 1, 1);
+ bd_store_history_item(&ts);
+
+ //Node 12
+ /*
+ sensor off flag
+ event wakeup
+ */
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 &= ~(ST1_SENSOR_ON_FLAG);
+ ts.battery_level = 79; ts.battery_health = 'g';
+ ts.battery_plugtype = 'n';
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_FINISH;
+ ts.event_code |= ET_WAKEUP_AP;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 23, 1, 0);
+ bd_store_history_item(&ts);
+
+ for (int i = 1; i <= 4; i++) {
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 |= i;
+ ts.event_code = ET_NONE;
+ ts.event_tag = NULL;
+ bd_store_history_item(&ts);
+ ts.state_1 &= ~i;
+ }
+
+ for (int i = 1; i <= 4; i++) {
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 |= (i << ST1_PHONE_SIGNAL_STRENGTH_SHIFT);
+ ts.event_code = ET_NONE;
+ ts.event_tag = NULL;
+ bd_store_history_item(&ts);
+ ts.state_1 &= ~(i << ST1_PHONE_SIGNAL_STRENGTH_SHIFT);
+ }
+
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 |= ST1_BATTERY_PLUGGED_FLAG;
+ ts.battery_level = 78; ts.battery_health = 'g';
+ ts.battery_plugtype = 'a';
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_START;
+ ts.event_code |= ET_WAKEUP_AP;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 19, 1, 1);
+ bd_store_history_item(&ts);
+
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 &= ~(ST1_BATTERY_PLUGGED_FLAG);
+ ts.battery_level = 79; ts.battery_health = 'g';
+ ts.battery_plugtype = 'n';
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_FINISH;
+ ts.event_code |= ET_WAKEUP_AP;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 19, 1, 0);
+ bd_store_history_item(&ts);
+
+ for (int i = 1; i < 100; i++) {
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_2 = ST2_WIFI_ON_FLAG;
+ if (i % 5 == 0)
+ ts.battery_level--;
+ ts.battery_health = 'g';
+ ts.battery_plugtype = 'n';
+ ts.event_code = ET_CONNECTIVITY_CHANGED;
+ ts.event_code |= ET_FLAG_START;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 28, 2, 1);
+ bd_store_history_item(&ts);
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 |= ST1_SCREEN_ON_FLAG;
+ ts.battery_health = 'g';
+ ts.battery_plugtype = 'n';
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_START;
+ ts.event_code |= ET_SCREEN_WAKE_UP;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 20, 1, 1);
+ bd_store_history_item(&ts);
+
+ for (int j = 1; j <= 4; j++) {
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 |= j;
+ ts.event_code = ET_NONE;
+ ts.event_tag = NULL;
+ bd_store_history_item(&ts);
+ ts.state_1 &= ~j;
+ }
+
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_1 &= ~(ST1_SCREEN_ON_FLAG);
+ ts.battery_health = 'g';
+ ts.battery_plugtype = 'n';
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_FINISH;
+ ts.event_code |= ET_SCREEN_WAKE_UP;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 20, 1, 0);
+ bd_store_history_item(&ts);
+ ts.cmd_s = CM_UPD; ts.time_s = 10*(gl_time++);
+ ts.time_current = 0;
+ ts.state_2 &= ~(ST2_WIFI_ON_FLAG);
+ ts.event_code = ET_NONE;
+ ts.event_code |= ET_FLAG_FINISH;
+ ts.event_code |= ET_CONNECTIVITY_CHANGED;
+ ts.event_tag = NULL;
+ if (ts.event_code != ET_NONE)
+ create_history_tag(&ts, 28, 2, 0);
+ bd_store_history_item(&ts);
+ }
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}