#include <stdlib.h>
#include <time.h>
#include <glib/gprintf.h>
-
+#include <stdio.h>
#include <bd_history_item.h>
#include <bm_dbg.h>
#include <bm_common.h>
dump_data_s history_data[HISTORY_SIZE_MAX];
-int counter = 0;
+int h_count = 0; int h_flag = false;
char state1_map[32][4] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Wm",
"", "Sd", "BP", "S", "Psc", "a", "s", "", "Pr", "Wr", "Ws", "Wl", "g", "w", "r"};
-char state2_map[32][5] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
- "Ud", "Chtp", "bles", "ca", "b", "Pcl", "ch", "", "", "fl", "W", "Ww", "v", "ps"};
+char state2_map[32][5] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "Ud", "Chtp", "bles", "ca", "b", "Pcl", "ch", "", "", "fl", "W", "Ww", "v", "ps"};
char event_map[32][4] = {"Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
"Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", "Esw", "Ewa", "Elw", "Eec"};
+//FILE *fp = NULL;
+
+static int bd_print_pool_entry(int idx, history_tag_s *pool_info)
+{
+ ENTER;
+
+ _DBG("Value from history data %d", idx);
+
+ GString *dump_p = g_string_sized_new(30);
+
+ dump_p = g_string_append(dump_p, TIZEN_DUMP_VERSION);
+ dump_p = g_string_append_c(dump_p, ',');
+ dump_p = g_string_append(dump_p, DUMP_DATA_TAG_1);
+ dump_p = g_string_append_c(dump_p, ',');
+ g_string_append_printf(dump_p, "%d,", pool_info->sp_idx);
+ g_string_append_printf(dump_p, "%d,", pool_info->uid);
+ dump_p = g_string_append(dump_p, "\"");
+
+ if (pool_info->string_info != NULL) {
+ gchar *temp = g_strdup(pool_info->string_info->str);
+ dump_p = g_string_append(dump_p, temp);
+ g_free(temp);
+ }
+
+ dump_p = g_string_append(dump_p, "\"");
+ dump_p = g_string_append(dump_p, "\n");
+ _DBG("%s", dump_p->str);
+// fputs(dump_p->str, fp);//TEMP
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
+
+static int bd_get_pool_entry_from_dump(void)
+{
+ ENTER;
+
+ GString *dump_p = g_string_sized_new(30);
+ dump_p = g_string_append(dump_p, TIZEN_DUMP_VERSION);
+ dump_p = g_string_append(dump_p, ",0");
+ dump_p = g_string_append(dump_p, ",i");
+ dump_p = g_string_append(dump_p, ",vers");
+ dump_p = g_string_append(dump_p, ",19,150,NMF26V,NMF26V");
+ dump_p = g_string_append(dump_p, "\n");
+ _DBG("%s", dump_p->str);
+// fputs(dump_p->str, fp);//TEMP
+ g_free(dump_p->str);
+ int ret = BATTERY_MONITOR_ERROR_NONE;
+ int log_count = h_count;
+ for (int i = 0; i < log_count; i++) {
+ history_tag_s *pool_info = NULL;
+ if (history_data[i].event_tag != NULL) {
+ pool_info = history_data[i].event_tag;
+ ret = bd_print_pool_entry(i, pool_info);
+ if (ret != BATTERY_MONITOR_ERROR_NONE)
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ if (history_data[i].wakelock_tag != NULL) {
+ pool_info = history_data[i].wakelock_tag;
+ ret = bd_print_pool_entry(i, pool_info);
+ if (ret != BATTERY_MONITOR_ERROR_NONE)
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ if (history_data[i].wakereason_tag != NULL) {
+ pool_info = history_data[i].wakereason_tag;
+ ret = bd_print_pool_entry(i, pool_info);
+ if (ret != BATTERY_MONITOR_ERROR_NONE)
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ }
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
// The index passed in the fn should be preferrably continuous,
// Other things should be implemented at dumping function.
{
ENTER;
- if (counter >= HISTORY_SIZE_MAX || index > counter) {
- // This assumes that counter is always greater
- // and old data should be dumped.
+ if (h_count >= HISTORY_SIZE_MAX || index > h_count) {
_ERR("Some Error occured with global index");
return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
}
_DBG("Value of index %d", index);
- _DBG("Value of counter %d", counter);
+ _DBG("Value of h_count %d", h_count);
// Print time if required
int dvar1 = 0, dvar2 = 0;
dvar1 = history_data[index].dump_1;
dump_node->event_tag = history_data[index].event_tag;
if (dump_node->event_tag == NULL)
_DBG("Event_Tag_NULL");
+ else//Remove
+ _DBG("%d %d %s", dump_node->event_tag->uid, dump_node->event_tag->sp_idx,
+ dump_node->event_tag->string_info->str);
dump_node->wakelock_tag = history_data[index].wakelock_tag;
if (dump_node->wakelock_tag == NULL)
_DBG("Wakelock_Tag_NULL");
dump_node->wakereason_tag = history_data[index].wakereason_tag;
+ //:Not supported
if (dump_node->wakereason_tag == NULL)
_DBG("Wakereason_Tag_NULL");
dump_node->time_s = history_data[index].time_s;
{
ENTER;
- if (counter >= HISTORY_SIZE_MAX) {
+ if (h_count >= HISTORY_SIZE_MAX) {
_ERR("Some Error occured with global index");
return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
}
int ret = BATTERY_MONITOR_ERROR_NONE;
+ h_flag = false; //Lock
history_item_s new_state;
history_item_s old_state;
return ret;
}
- int log_count = counter;
+// fp = fopen("/tmp/test.txt", "w+");//TEMP
+
+ ret = bd_get_pool_entry_from_dump();
+ if (ret != BATTERY_MONITOR_ERROR_NONE)
+ _ERR("S pool data dump failed");
+
+ int log_count = h_count;
for (int i = 0; i < log_count; i++) {
ret = bd_get_history_detail_from_dump(i, &new_state);
//_DBG("value %s", dump_p->str);
if (chkin)
g_string_append_printf(dump_p, "%d",
- new_state.wakelock_tag->hsp_idx);
+ new_state.wakelock_tag->sp_idx);
else{
//: NC
}
dump_p = g_string_append(dump_p, ",w=");
if (chkin) {
g_string_append_printf(dump_p, "%d",
- new_state.wakelock_tag->hsp_idx);
- //_DBG("value %s", dump_p->str);
+ new_state.wakelock_tag->sp_idx);
+ _DBG("value %s", dump_p->str);
} else {
}
}
dump_p = g_string_append(dump_p, ",wr=");
_DBG("value %s", dump_p->str);
g_string_append_printf(dump_p, "%d",
- new_state.wakereason_tag->hsp_idx);
+ new_state.wakereason_tag->sp_idx);
_DBG("value %s", dump_p->str);
}
} else {
gchar* temp = g_strdup(event_map[k]);
g_string_append(dump_p, temp);
_DBG("value %s", dump_p->str);
+ g_free(temp);
} else {
dump_p = g_string_append(dump_p, "Ev");
g_string_append_printf(dump_p, "%d", k);
_DBG("value %s", dump_p->str);
if (chkin) {
g_string_append_printf(dump_p, "%d",
- new_state.event_tag->hsp_idx);
+ new_state.event_tag->sp_idx);
+ //:Free sp memory.
} else {
//: for NC
}
old_state.state_2 = new_state.state_2;
_DBG("State assigned");
_DBG("%s", dump_p->str);
+// fputs(dump_p->str, fp);//TEMP
g_free(dump_p->str);
}
+ h_flag = true;
+// fclose(fp);//TEMP
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
}
time_t current_time;
time(¤t_time); //This time needs to be changed to MT
- history_data[counter].time_s = current_time;
+ history_data[h_count].time_s = current_time;
dvar1 = ((nrec->cmd_s) & 0xff) | ((nrec->battery_level << 8) & 0xff00) |
((nrec->battery_status << 16) & 0xf0000) |
_DBG("Value of encoded value 1 %d", dvar1);
_DBG("Value of encoded value 2 %d", dvar2);
- history_data[counter].dump_1 = dvar1;
- history_data[counter].dump_2 = dvar2;
- history_data[counter].battery_chargeUAh = nrec->battery_charge;
+ history_data[h_count].dump_1 = dvar1;
+ history_data[h_count].dump_2 = dvar2;
+ history_data[h_count].battery_chargeUAh = nrec->battery_charge;
if (nrec->wakelock_tag != NULL)
- history_data[counter].wakelock_tag = nrec->wakelock_tag;
+ history_data[h_count].wakelock_tag = nrec->wakelock_tag;
if (nrec->wakereason_tag != NULL)
- history_data[counter].wakereason_tag = nrec->wakereason_tag;
+ history_data[h_count].wakereason_tag = nrec->wakereason_tag;
if (nrec->event_code != ET_NONE) {
- history_data[counter].event_code = nrec->event_code;
- history_data[counter].event_tag = nrec->event_tag;
+ history_data[h_count].event_code = nrec->event_code;
+ history_data[h_count].event_tag = nrec->event_tag;
}
if (nrec->cmd_s == CM_CRR_TIME || nrec->cmd_s == CM_RST)
- history_data[counter].time_current = current_time;
+ history_data[h_count].time_current = current_time;
- history_data[counter].state_1 = nrec->state_1;
- history_data[counter].state_2 = nrec->state_2;
+ history_data[h_count].state_1 = nrec->state_1;
+ history_data[h_count].state_2 = nrec->state_2;
- if (counter < HISTORY_SIZE_MAX)
- counter++;
+ if (h_count < HISTORY_SIZE_MAX)
+ h_count++;
else {
//: Give some buffer
int ret = bd_print_history_item_main(0, current_time, 1);
if (ret != BATTERY_MONITOR_ERROR_NONE)
return ret;
- counter = 0;
+ h_count = 0;
}
EXIT;
return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
}
+ if (!h_flag) {
+ _ERR("Data Dump in progress");
+ return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+ }
+
int ret = BATTERY_MONITOR_ERROR_NONE;
ret = bd_set_history_from_listener(nrec);
if (ret != BATTERY_MONITOR_ERROR_NONE) {
return BATTERY_MONITOR_ERROR_NONE;
}
+/*
//: remove this
static int bd_test_fn()
{
ts.battery_temperature = 226;
ts.battery_voltage = 400;
ts.battery_charge = 0;
- ts.event_code = ET_NONE;
- ts.event_tag = NULL;
+ ts.event_code = ET_PROC; //Dummy Event
+ 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);
+ ts.event_tag->uid = 40;
+ ts.event_tag->sp_idx = 1;
+ temp = g_string_append(temp, "test-app");
+ ts.event_tag->string_info = temp;
+ _DBG("%s _1", ts.event_tag->string_info->str);
+ }
ts.wakelock_tag = NULL;
ts.wakereason_tag = NULL;
+ // Node 1
bd_set_history_from_listener(&ts);
+ ts.event_code = ET_NONE;
+ ts.event_tag = NULL;
ts.state_1 &= ~(ST1_WIFI_SCAN_FLAG);
+ // Node 2
bd_set_history_from_listener(&ts);
EXIT;
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
}
+*/
int bd_initialize_battery_dump()
{
ENTER;
- counter = 0;
- _DBG("Battery Dump Init Successful");
- bd_make_string_maps(); //add return integer check.
-
+ h_count = 0; h_flag = true;
+ _INFO("Battery Dump Init Successful");
+ //Remove
+// bd_make_string_maps();
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
}
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
}
-
-//Remove all DBG statements
+//Remove all DBG statements in final patch