ret_if(NULL == user_state);
g_free(user_state->account);
+ g_slist_free(user_state->found_devices);
g_free(user_state);
FUNC_EXIT;
}
continue;
}
- UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->absence_detected_bitmask: 0x%8.8X",
- monitor->sensor_bitmask, monitor->absence_detected_bitmask);
+ UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->presence_detected_bitmask: 0x%8.8X",
+ monitor->sensor_bitmask, monitor->presence_detected_bitmask);
if (monitor->sensor_bitmask == monitor->presence_detected_bitmask) {
if (monitor->presence_cb)
monitor->presence_cb(UA_ERROR_NONE, monitor,
}
static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
- ua_user_h user_handle,
- unsigned int user_sensor_bitmask,
- char *device_id)
+ ua_user_state_info_s *user_state)
{
FUNC_ENTRY;
+ unsigned int env_presence_bm = 0;
+ unsigned int user_sensor_bitmask = user_state->sensor_bitmask;
+
+ ua_user_h user_handle = _ua_get_user_handle_by_account(
+ user_state->account);
+ env_presence_bm = monitor->presence_detected_bitmask & UA_SENSOR_MOTION
+ & UA_SENSOR_LIGHT;
/**
* Check whether user_handle present or not and also check
* whether presence has been started or not.
*/
- if (!user_handle || !monitor->presence_user_cb.callback ||
- !monitor->presence_detection_started) {
+ if (!user_handle || user_state->cb_sent
+ || !monitor->presence_user_cb.callback
+ || !monitor->presence_detection_started) {
FUNC_EXIT;
return;
}
UA_DBG("User's sensor bitmask [0x%u], monior presence bitmask AND [0x%u], OR [0x%u]",
- user_sensor_bitmask,
- monitor->presence_bitmask_and, monitor->presence_bitmask_or);
+ user_sensor_bitmask, monitor->presence_bitmask_and,
+ monitor->presence_bitmask_or);
/**
* Check AND conditions for sensors.
*/
if (monitor->presence_bitmask_and !=
- (user_sensor_bitmask & monitor->presence_bitmask_and)) {
+ (monitor->presence_bitmask_and
+ & (user_sensor_bitmask | env_presence_bm))) {
FUNC_EXIT;
return;
}
* Check OR conditions for sensors.
*/
if (monitor->presence_bitmask_or &&
- !(user_sensor_bitmask & monitor->presence_bitmask_or)) {
+ !(monitor->presence_bitmask_or
+ & (user_sensor_bitmask | env_presence_bm))) {
FUNC_EXIT;
return;
}
UA_DBG("OR condition matched");
- GSList *device_handles = NULL;
- ua_device_h device_handle;
-
- if (user_sensor_bitmask & UA_SENSOR_BT) {
- ua_device_get_by_device_id(device_id,
- user_sensor_bitmask & UA_SENSOR_BT,
- &device_handle);
- device_handles = g_slist_prepend(device_handles, device_handle);
- }
-
- if (user_sensor_bitmask & UA_SENSOR_BLE) {
- ua_device_get_by_device_id(device_id,
- user_sensor_bitmask & UA_SENSOR_BLE,
- &device_handle);
- device_handles = g_slist_prepend(device_handles, device_handle);
- }
-
- if (user_sensor_bitmask & UA_SENSOR_WIFI) {
- ua_device_get_by_device_id(device_id,
- user_sensor_bitmask & UA_SENSOR_WIFI,
- &device_handle);
- device_handles = g_slist_prepend(device_handles, device_handle);
- }
((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
- UA_ERROR_NONE, monitor, user_handle,
- device_handles,
- monitor->presence_user_cb.user_data);
+ UA_ERROR_NONE, monitor, user_handle,
+ user_state->found_devices,
+ monitor->presence_user_cb.user_data);
- g_slist_free(device_handles);
+ user_state->cb_sent = TRUE;
}
static void __ua_sensor_presence_detected(ua_monitor_s *monitor,
FUNC_ENTRY;
GSList *l;
+ GSList *us;
int found = 0;
+ int ret = UA_ERROR_NONE;
ua_user_state_info_s *user_state;
+ ua_device_h device_handle = NULL;
+
ret_if(NULL == monitor);
if (account) {
monitor->user_state = g_slist_append(monitor->user_state, user_state);
}
- ua_user_h user_handle = _ua_get_user_handle_by_account(user_state->account);
-
- _ua_set_user_last_presence_timestamp(user_handle, timestamp);
user_state->sensor_bitmask |= bitmask;
- __ua_monitor_send_user_presence_cb(monitor, user_handle,
- user_state->sensor_bitmask,
- device_id);
+ ret = ua_device_get_by_device_id(device_id, bitmask, &device_handle);
+ UA_INFO("ua_device_get_by_device_id returned %s",
+ _ua_get_error_string(ret));
+ if (device_handle)
+ user_state->found_devices = g_slist_prepend(user_state->found_devices,
+ device_handle);
+
+ __ua_monitor_send_user_presence_cb(monitor, user_state);
+
+ ua_user_h user_handle = _ua_get_user_handle_by_account(user_state->account);
+ _ua_set_user_last_presence_timestamp(user_handle, timestamp);
}
switch (monitor->presence_mode) {
* send presence detection callback to application. This will make sure that each sensor is
* detected at least one device from registered devices list.
*/
+//TODO remove this (BLE | WIFI) condition and the ALL/ANY thing.
if (((bitmask == UA_SENSOR_BLE) && (monitor->sensor_bitmask & UA_SENSOR_WIFI))
|| ((bitmask == UA_SENSOR_WIFI) && (monitor->sensor_bitmask & UA_SENSOR_BLE)))
monitor->presence_detected_bitmask |= (UA_SENSOR_BLE | UA_SENSOR_WIFI);
UA_WARN("Unexpected detection mode: %d", monitor->presence_mode);
}
+ /* if environmental sensor comes after connectivity sensor */
+ if (!account) {
+ for (us = monitor->user_state; us; us = g_slist_next(us)) {
+ user_state = (ua_user_state_info_s *)us->data;
+ UA_DBG("user_state->account [%s]", user_state->account);
+
+ __ua_monitor_send_user_presence_cb(monitor, user_state);
+ }
+ }
+
FUNC_EXIT;
}
for (l = ua_monitor_list; l; l = g_slist_next(l)) {
ua_monitor_s *monitor = l->data;
- if (!monitor || (!monitor->presence_detection_started && !monitor->internal_presence_started))
+ if (!monitor || (!monitor->presence_detection_started
+ && !monitor->internal_presence_started))
continue;
if (0 == (bitmask & monitor->sensor_bitmask))
ua_monitor_s *monitor = data;
ret_if(NULL == monitor);
+//TODO lk, where are these timers used?
if (monitor->presence_detection_timer) {
/* LCOV_EXCL_START */
g_source_remove(monitor->presence_detection_timer);
return UA_ERROR_INVALID_PARAMETER;
}
+ if (!(bitmask_and | bitmask_or)) {
+ UA_ERR("Both of AND/OR bitmask are zero");
+ FUNC_EXIT;
+ return UA_ERROR_INVALID_PARAMETER;
+ }
+
_uam_get_available_sensors(&available_sensors);
if (bitmask_and != (available_sensors & bitmask_and)) {
static char cycle_time[MENU_DATA_SIZE + 1] = {"900", }; /**< cycle time */
static char window[MENU_DATA_SIZE + 1] = {"60", }; /**< Detection window */
-static char g_presence_and_cond[MENU_DATA_SIZE + 1] = {"00", }; /**< PRESENCE AND condition */
-static char g_presence_or_cond[MENU_DATA_SIZE + 1] = {"00", }; /**< PRESENCE OR condition */
-static char g_absence_and_cond[MENU_DATA_SIZE + 1] = {"00", }; /**< ABSENCE AND condition */
-static char g_absence_or_cond[MENU_DATA_SIZE + 1] = {"00", }; /**< ABSENCE OR condition */
+static char g_presence_and_cond[MENU_DATA_SIZE + 1] = {0,}; /**< PRESENCE AND condition */
+static char g_presence_or_cond[MENU_DATA_SIZE + 1] = {0,}; /**< PRESENCE OR condition */
+static char g_absence_and_cond[MENU_DATA_SIZE + 1] = {0,}; /**< ABSENCE AND condition */
+static char g_absence_or_cond[MENU_DATA_SIZE + 1] = {0,}; /**< ABSENCE OR condition */
static char g_presence_type[MENU_DATA_SIZE + 1] = "2"; /**< Selected PRESENCE type */
static char g_absence_type[MENU_DATA_SIZE + 1] = "2"; /**< Selected ABSENCE type */
MManager *mm, struct menu_data *menu)
{
int ret = UA_ERROR_NONE;
- unsigned int bitmask_and = 0x00;
- unsigned int bitmask_or = 0x00;
+ unsigned int bitmask_and = 0;
+ unsigned int bitmask_or = 0;
msg("ua_monitor_set_user_presence_condition");
if (strlen(g_presence_and_cond))
- bitmask_and = (unsigned char)strtol(g_presence_and_cond, NULL, 10);
+ bitmask_and = (unsigned int)strtol(g_presence_and_cond, NULL, 10);
if (strlen(g_presence_or_cond))
- bitmask_or = (unsigned char)strtol(g_absence_or_cond, NULL, 10);
+ bitmask_or = (unsigned int)strtol(g_presence_or_cond, NULL, 10);
- msgb("AND [0x%u] OR [0x%u]", bitmask_and, bitmask_or);
+ msgb("AND [%u] - OR [%u]", bitmask_and, bitmask_or);
ret = ua_monitor_set_user_presence_condition(g_ua_mon_h, bitmask_and, bitmask_or);
MManager *mm, struct menu_data *menu)
{
int ret = UA_ERROR_NONE;
- unsigned int bitmask_and = 0x00;
- unsigned int bitmask_or = 0x00;
+ unsigned int bitmask_and = 0;
+ unsigned int bitmask_or = 0;
msg("ua_monitor_set_user_absence_condition");
if (strlen(g_absence_and_cond))
- bitmask_and = (unsigned char)strtol(g_absence_and_cond, NULL, 10);
+ bitmask_and = (unsigned int)strtol(g_absence_and_cond, NULL, 10);
if (strlen(g_absence_or_cond))
- bitmask_or = (unsigned char)strtol(g_absence_or_cond, NULL, 10);
+ bitmask_or = (unsigned int)strtol(g_absence_or_cond, NULL, 10);
- msgb("AND [0x%u] OR [0x%u]", bitmask_and, bitmask_or);
+ msgb("AND [%u] - OR [%u]", bitmask_and, bitmask_or);
ret = ua_monitor_set_user_absence_condition(g_ua_mon_h, bitmask_and, bitmask_or);
};
static struct menu_data menu_ua_set_presence_condition[] = {
- { "1", "AND Bitmask (01:BT 02:BLE 04:Wi-Fi 08:Motion 10:Light 20:Audio",
+ { "1", "AND Bitmask (1:BT 2:BLE 4:Wi-Fi 8:Motion 16:Light 32:Audio",
NULL, NULL, g_presence_and_cond },
- { "2", "OR Bitmask (01:BT 02:BLE 04:Wi-Fi 08:Motion 10:Light 20:Audio",
+ { "2", "OR Bitmask (01:BT 02:BLE 04:Wi-Fi 08:Motion 16:Light 32:Audio",
NULL, NULL, g_presence_or_cond },
{ "3", "run", NULL,
run_ua_monitor_set_user_presence_condition, NULL },
};
static struct menu_data menu_ua_set_absence_condition[] = {
- { "1", "AND Bitmask (0x01:BT 0x02:BLE 0x04:Wi-Fi 0x08:Motion 0x10:Light 0x20:Audio",
+ { "1", "AND Bitmask (1:BT 2:BLE 4:Wi-Fi 8:Motion 16:Light 32:Audio",
NULL, NULL, g_absence_and_cond },
- { "2", "OR Bitmask (0x01:BT 0x02:BLE 0x04:Wi-Fi 0x08:Motion 0x10:Light 0x20:Audio",
+ { "2", "OR Bitmask (01:BT 02:BLE 04:Wi-Fi 08:Motion 16:Light 32:Audio",
NULL, NULL, g_absence_or_cond },
{ "3", "run", NULL,
run_ua_monitor_set_user_absence_condition, NULL },