diff options
Diffstat (limited to 'test/uat-init.c')
-rw-r--r-- | test/uat-init.c | 107 |
1 files changed, 55 insertions, 52 deletions
diff --git a/test/uat-init.c b/test/uat-init.c index 2381cfd..9a36364 100644 --- a/test/uat-init.c +++ b/test/uat-init.c @@ -38,8 +38,58 @@ static char g_uid[MENU_DATA_SIZE + 1] = {0,}; /**< User id */ static char g_ibeacon_adv_len[MENU_DATA_SIZE + 1] = {0,}; /**< iBeacon advertising data length */ static char g_ibeacon_adv_str[MENU_DATA_SIZE + 1] = {0,}; /**< iBeacon advertising data */ +static void __user_detected_foreach_sensors(gpointer data, + gpointer user_data) +{ + int ret; + char buf[MENU_DATA_SIZE] = {0, }; + char final_buf[MENU_DATA_SIZE * 4] = {0, }; + long int timestamp; + int info_count = 0; + GSList *values = NULL; + double *value; + GSList *l = 0; + ua_sensor_e bitmask; + ua_device_h sensor_handle = (ua_sensor_h)data; + + ret = ua_sensor_get_bitmask(sensor_handle, &bitmask); + if (UA_ERROR_NONE != ret) { + msg(" - ua_sensor_get_bitmask() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + } + + ret = ua_sensor_get_timestamp(sensor_handle, ×tamp); + if (UA_ERROR_NONE != ret) { + msg(" - ua_sensor_get_timestamp() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + } + + ret = ua_sensor_get_info_count(sensor_handle, &info_count); + if (UA_ERROR_NONE != ret) { + msg(" - ua_sensor_get_info_count() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + } + + values = ua_sensor_get_info_values(sensor_handle); + if (NULL == values) { + msg(" - ua_sensor_get_info_values() failed"); + } + + for (l = values; l; l = g_slist_next(l)) { + value = (double *)l->data; + snprintf(buf, MENU_DATA_SIZE, "%lF ", *value); + strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1); + memset(buf, 0, MENU_DATA_SIZE); + } + msgb("[%s] information detected at timestamp [%ld] value [%s]", + uat_get_sensor_bitmask_str(bitmask), timestamp, + final_buf); + + g_slist_free(values); +} + static void __user_absence_detected_cb(int result, ua_monitor_h monitor, - ua_user_h user_handle, void *user_data) + ua_user_h user_handle, GSList *sensor_handles, void *user_data) { int ret; char *account = NULL; @@ -55,6 +105,9 @@ static void __user_absence_detected_cb(int result, ua_monitor_h monitor, } msgp("[%s] ABSENCE detected [%s]", account, uat_get_error_str(result)); + g_slist_foreach(sensor_handles, + __user_detected_foreach_sensors, NULL); + if (account) { free(account); } @@ -101,56 +154,6 @@ static void __user_presence_detected_foreach_devices(gpointer data, g_free(mac); } -static void __user_presence_detected_foreach_sensors(gpointer data, - gpointer user_data) -{ - int ret; - char buf[MENU_DATA_SIZE] = {0, }; - char final_buf[MENU_DATA_SIZE * 4] = {0, }; - long int timestamp; - int info_count = 0; - GSList *values = NULL; - double *value; - GSList *l = 0; - ua_sensor_e bitmask; - ua_device_h sensor_handle = (ua_sensor_h)data; - - ret = ua_sensor_get_bitmask(sensor_handle, &bitmask); - if (UA_ERROR_NONE != ret) { - msg(" - ua_sensor_get_bitmask() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - } - - ret = ua_sensor_get_timestamp(sensor_handle, ×tamp); - if (UA_ERROR_NONE != ret) { - msg(" - ua_sensor_get_timestamp() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - } - - ret = ua_sensor_get_info_count(sensor_handle, &info_count); - if (UA_ERROR_NONE != ret) { - msg(" - ua_sensor_get_info_count() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - } - - values = ua_sensor_get_info_values(sensor_handle); - if (NULL == values) { - msg(" - ua_sensor_get_info_values() failed"); - } - - for (l = values; l; l = g_slist_next(l)) { - value = (double *)l->data; - snprintf(buf, MENU_DATA_SIZE, "%lF ", *value); - strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1); - memset(buf, 0, MENU_DATA_SIZE); - } - msgb("[%s] information detected at timestamp [%ld] value [%s]", - uat_get_sensor_bitmask_str(bitmask), timestamp, - final_buf); - - g_slist_free(values); -} - static void __user_presence_detected_cb(int result, ua_monitor_h monitor, ua_user_h user_handle, GSList *device_handles, GSList *sensor_handles, void *user_data) @@ -173,7 +176,7 @@ static void __user_presence_detected_cb(int result, ua_monitor_h monitor, account); g_slist_foreach(sensor_handles, - __user_presence_detected_foreach_sensors, NULL); + __user_detected_foreach_sensors, NULL); g_free(account); } |