4 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #define SIGNAL_CHARGE_NOW "ChargeNow"
25 #define SIGNAL_CHARGER_STATUS "ChargerStatus"
26 #define SIGNAL_TEMP_GOOD "TempGood"
28 static E_DBus_Signal_Handler *edbus_charge_now_handler;
29 static E_DBus_Signal_Handler *edbus_charger_status_handler;
30 static E_DBus_Signal_Handler *edbus_temp_good_handler;
31 static E_DBus_Connection *edbus_conn;
33 static struct power_supply_type {
42 } power_supply_types [] = {
43 {"norm", S_ENTER, "100","Charging", "Good", "2", "1", "CHARGE"},
44 {"norm", S_ENTER, "100","Discharging", "Good", "1", "1", "DISCHARGE"},
45 {"norm", S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
47 {"heat1",S_ENTER, "100","Discharging", "Overheat", "1", "1", NULL},
48 {"heat1",S_ENTER, "100","Not charging","Overheat", "2", "1", "HEALTH(H) BEFORE CHARGE"},
49 {"heat1",S_LEAVE, "100","Discharging", "Overheat", "1", "1", "DISCHARGE"},
50 {"heat1",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
52 {"heat2",S_ENTER, "100","Charging", "Good", "2", "1", NULL},
53 {"heat2",S_ENTER, "100","Not charging","Overheat", "2", "1", "HEALTH(H) AFTER CHARGE"},
54 {"heat2",S_LEAVE, "100","Discharging", "Overheat", "1", "1", "DISCHARGE"},
55 {"heat2",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
57 {"cold1",S_ENTER, "100","Discharging", "Cold", "1", "1", NULL},
58 {"cold1",S_ENTER, "100","Not charging","Cold", "2", "1", "HEALTH(L) BEFORE CHARGE"},
59 {"cold1",S_LEAVE, "100","Discharging", "Cold", "1", "1", "DISCHARGE"},
60 {"cold1",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
62 {"cold2",S_ENTER, "100","Charging", "Good", "2", "1", NULL},
63 {"cold2",S_ENTER, "100","Not charging","Cold", "2", "1", "HEALTH(L) AFTER CHARGE"},
64 {"cold2",S_LEAVE, "100","Discharging", "Cold", "1", "1", "DISCHARGE"},
65 {"cold2",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
67 {"ovp", S_ENTER, "100","Discharging", "Over voltage", "1", "1", "OVP"},
68 {"ovp", S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
70 {"pres1",S_ENTER, "100","Discharging", "Good", "1", "0", NULL},
71 {"pres1",S_ENTER, "100","Not charging","Good", "2", "0", "PRESENT BEFORE CHARGE"},
72 {"pres1",S_LEAVE, "100","Discharging", "Good", "1", "0", "DISCHARGE"},
73 {"pres1",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
75 {"pres2",S_ENTER, "100","Charging", "Good", "2", "1", NULL},
76 {"pres2",S_ENTER, "100","Not charging","Good", "2", "0", "PRESENT AFTER CHARGE"},
77 {"pres2",S_LEAVE, "100","Discharging", "Good", "1", "0", "DISCHARGE"},
78 {"pres2",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
80 {"bat15",S_ENTER, "15", "Discharging", "Good", "1", "1", "LOWBAT 15%"}, //lowbat 15%
81 {"bat15",S_LEAVE, "15", "Charging", "Good", "2", "1", "LOWBAT 15%"},
82 {"bat5", S_ENTER, "5", "Discharging", "Good", "1", "1", "LOWBAT 5%"}, //lowbat 5%
83 {"bat5", S_LEAVE, "5", "Charging", "Good", "2", "1", "LOWBAT 5%"},
84 {"bat3", S_ENTER, "3", "Discharging", "Good", "1", "1", "LOWBAT 3%"}, //lowbat 3%
85 {"bat3", S_LEAVE, "3", "Charging", "Good", "2", "1", "LOWBAT 3%"},
86 {"bat1", S_ENTER, "1", "Discharging", "Good", "1", "1", "LOWBAT 1%"}, //lowbat 1%
87 {"bat1", S_LEAVE, "1", "Charging", "Good", "2", "1", "LOWBAT 1%"},
89 {"ta", S_ENTER, "100","Charging", "Good", "2", "1", "CHARGE"}, //charging
90 {"ta", S_LEAVE, "100","Discharging", "Good", "1", "1", "DISCHARGE"},//discharging
91 {"capacity", S_ENTER, "100","Discharging", "Good", "1", "1", "CAPACITY"},//charging
92 {"capacity", S_LEAVE, "100","Charging", "Good", "2", "1", "CAPACITY"},//discharging
95 static void unregister_edbus_signal_handler(void)
97 e_dbus_signal_handler_del(edbus_conn, edbus_charge_now_handler);
98 e_dbus_signal_handler_del(edbus_conn, edbus_charger_status_handler);
99 e_dbus_signal_handler_del(edbus_conn, edbus_temp_good_handler);
100 e_dbus_connection_close(edbus_conn);
104 static void power_supply_changed(void *data, DBusMessage *msg)
110 _I("edbus signal Received");
112 r = dbus_message_is_signal(msg, DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGE_NOW);
114 _E("dbus_message_is_signal error");
118 _I("%s - %s", DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGE_NOW);
120 dbus_error_init(&err);
121 r = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
123 _E("dbus_message_get_args error");
126 _I("receive data : %d", val);
129 static int register_charge_now_handler(void)
135 edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
138 goto edbus_handler_out;
141 edbus_charge_now_handler = e_dbus_signal_handler_add(edbus_conn, NULL, DEVICED_PATH_BATTERY,
142 DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGE_NOW, power_supply_changed, NULL);
143 if (!(edbus_charge_now_handler)) {
145 goto edbus_handler_connection_out;
149 edbus_handler_connection_out:
150 e_dbus_connection_close(edbus_conn);
156 static void charger_status_changed(void *data, DBusMessage *msg)
162 _I("edbus signal Received");
164 r = dbus_message_is_signal(msg, DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGER_STATUS);
166 _E("dbus_message_is_signal error");
170 _I("%s - %s", DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGER_STATUS);
172 dbus_error_init(&err);
173 r = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
175 _E("dbus_message_get_args error");
178 _I("receive data : %d", val);
181 static int register_charger_status_handler(void)
187 edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
190 goto edbus_handler_out;
193 edbus_charger_status_handler = e_dbus_signal_handler_add(edbus_conn, NULL, DEVICED_PATH_BATTERY,
194 DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGER_STATUS, charger_status_changed, NULL);
195 if (!(edbus_charger_status_handler)) {
197 goto edbus_handler_connection_out;
201 edbus_handler_connection_out:
202 e_dbus_connection_close(edbus_conn);
208 static void temp_status_changed(void *data, DBusMessage *msg)
214 _I("edbus signal Received");
216 r = dbus_message_is_signal(msg, DEVICED_INTERFACE_BATTERY, SIGNAL_TEMP_GOOD);
218 _E("dbus_message_is_signal error");
222 _I("%s - %s", DEVICED_INTERFACE_BATTERY, SIGNAL_TEMP_GOOD);
225 static int register_temp_good_handler(void)
231 edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
234 goto edbus_handler_out;
237 edbus_temp_good_handler = e_dbus_signal_handler_add(edbus_conn, NULL, DEVICED_PATH_BATTERY,
238 DEVICED_INTERFACE_BATTERY, SIGNAL_TEMP_GOOD, temp_status_changed, NULL);
239 if (!(edbus_temp_good_handler)) {
241 goto edbus_handler_connection_out;
245 edbus_handler_connection_out:
246 e_dbus_connection_close(edbus_conn);
251 static void test_signal(void)
254 register_charge_now_handler();
255 register_charger_status_handler();
256 register_temp_good_handler();
257 ecore_main_loop_begin();
260 static int test(int index)
267 param[0] = POWER_SUBSYSTEM;
269 param[2] = power_supply_types[index].capacity;
270 param[3] = power_supply_types[index].charge_status;
271 param[4] = power_supply_types[index].health;
272 param[5] = power_supply_types[index].online;
273 param[6] = power_supply_types[index].present;
275 msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
276 DEVICED_PATH_SYSNOTI,
277 DEVICED_INTERFACE_SYSNOTI,
278 POWER_SUBSYSTEM, "sisssss", param);
280 _E("fail : %s %s %s %s",
281 DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
286 dbus_error_init(&err);
288 ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
290 _E("no message : [%s:%s]", err.name, err.message);
291 dbus_error_free(&err);
295 if (power_supply_types[index].name != NULL)
296 _I("++++++++++[START] %s ++++++++++", power_supply_types[index].name);
297 _I("CAPACITY(%s , %s) P(%s) STATUS(%s) HEALTH(%s)",
298 power_supply_types[index].capacity,
299 power_supply_types[index].online,
300 power_supply_types[index].present,
301 power_supply_types[index].charge_status,
302 power_supply_types[index].health);
303 if (power_supply_types[index].name != NULL)
304 _I("++++++++++[END] %s ++++++++++", power_supply_types[index].name);
306 dbus_message_unref(msg);
307 dbus_error_free(&err);
308 sleep(TEST_WAIT_TIME_INTERVAL);
312 static void scenario(char *scenario)
316 for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) {
317 if (strcmp(scenario, power_supply_types[index].scenario) != 0)
323 static void unit(char *unit, int status)
327 char *scenario = NULL;
329 for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) {
330 scenario = power_supply_types[index].scenario;
331 if (strcmp(unit, scenario) != 0 ||
332 power_supply_types[index].status != status)
341 index = strlen(unit);
342 if (index < 0 || index > 3)
345 index = strtol(unit, NULL, 10);
346 if (index < 0 || index > 100)
349 for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) {
350 if (strcmp("capacity", power_supply_types[index].scenario) != 0 ||
351 power_supply_types[index].status != status)
353 power_supply_types[index].capacity = unit;
354 _D("%s", power_supply_types[index].capacity);
359 static void power_supply_init(void *data)
364 for (index = 0; index < ARRAY_SIZE(power_supply_types); index++)
368 static void power_supply_exit(void *data)
373 static int power_supply_unit(int argc, char **argv)
379 if (strcmp("wait", argv[2]) == 0)
381 else if (strcmp("scenario", argv[2]) == 0)
383 else if (strcmp("enter", argv[3]) == 0)
384 unit(argv[2], S_ENTER);
385 else if (strcmp("leave", argv[3]) == 0)
386 unit(argv[2], S_LEAVE);
390 static const struct test_ops power_test_ops = {
391 .priority = TEST_PRIORITY_NORMAL,
393 .init = power_supply_init,
394 .exit = power_supply_exit,
395 .unit = power_supply_unit,
398 TEST_OPS_REGISTER(&power_test_ops)