UAM_EVENT_USER_PRESENCE_DETECTED, /**< User presence detected */
UAM_EVENT_ABSENCE_DETECTED, /**< Absence detected */
UAM_EVENT_USER_ABSENCE_DETECTED, /**< User absence detected */
+ UAM_EVENT_USER_LOCATION_DETECTED, /**< User location detected */
UAM_EVENT_AMBIANT_MODE_ENABLED, /**< Ambient mode enabled */
UAM_EVENT_AMBIANT_MODE_DISABLED, /**< Ambient mode disabled */
UAM_EVENT_SENSOR_STATE_READY, /**< Sensor state ready */
gboolean discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
unsigned long long last_seen; /**< Latest seen time when device was discoverd */
int app_num; /**<*App Number*/
+ int distance_mm; /** Device distance */
+ int x; /** Device x coordinate */
+ int y; /** Device y coordinate */
+ int z; /** Device z coordinate */
} uam_device_info_s;
/**
char service[UAM_SERVICE_MAX_STRING_LEN]; /**< Service name */
unsigned long long last_seen; /**< The last time of detection */
char device_id[UAM_DEVICE_ID_MAX_STRING_LEN]; /**< Device's unique ID */
+ int distance_mm; /* Device distance */
+ int x; /* x coordinate */
+ int y; /* y coordinate */
+ int z; /* z coordinate */
} uam_detection_event_data_s;
/**
#define UAM_SIGNAL_USER_PRESENCE_DETECTED "UserPresenceDetected"
#define UAM_SIGNAL_ABSENCE_DETECTED "AbsenceDetected"
#define UAM_SIGNAL_USER_ABSENCE_DETECTED "UserAbsenceDetected"
+#define UAM_SIGNAL_USER_LOCATION_DETECTED "UserLocationDetected"
#define UAM_SIGNAL_SENSOR_STATE_READY "SensorReady"
#define UAM_SIGNAL_SENSOR_STATE_NOT_READY "SensorNotReady"
#define UAM_SIGNAL_DETECTION_STARTED "DetectionStarted"
CASE_TO_STR(UAM_EVENT_USER_PRESENCE_DETECTED)
CASE_TO_STR(UAM_EVENT_ABSENCE_DETECTED)
CASE_TO_STR(UAM_EVENT_USER_ABSENCE_DETECTED)
+ CASE_TO_STR(UAM_EVENT_USER_LOCATION_DETECTED)
CASE_TO_STR(UAM_EVENT_AMBIANT_MODE_ENABLED)
CASE_TO_STR(UAM_EVENT_AMBIANT_MODE_DISABLED)
CASE_TO_STR(UAM_EVENT_SENSOR_STATE_READY)
__uam_send_event(event, result, &event_data,
event_info->cb, event_info->user_data);
+
+ } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_USER_LOCATION_DETECTED)) {
+ uam_detection_event_data_s event_data;
+ unsigned int sensor_bitmask;
+ const char *account = NULL;
+ const char *service = NULL;
+ const char *device_id = NULL;
+ unsigned long long last_seen = 0;
+ unsigned int distance = 0;
+ unsigned int x = 0;
+ unsigned int y = 0;
+ unsigned int z = 0;
+
+ g_variant_get(parameters, "(ut&s&s&siiii)", &sensor_bitmask, &last_seen, &account,
+ &service, &device_id, &distance, &x, &y, &z);
+
+ UAM_DBG("Sensor: 0x%8.8X, User: %s, Device: %s timestamp [%llu] distance %d"
+ " coordinates x:%d, y:%d, z:%d", sensor_bitmask, account, device_id,
+ last_seen, distance, x, y, z);
+ event = UAM_EVENT_USER_LOCATION_DETECTED;
+ event_data.sensor_bitmask = sensor_bitmask;
+ g_strlcpy(event_data.account, account,
+ UAM_USER_ACCOUNT_MAX_STRING_LEN);
+ g_strlcpy(event_data.service, service, UAM_SERVICE_MAX_STRING_LEN);
+ event_data.last_seen = last_seen;
+ event_data.distance_mm = distance;
+ event_data.x = x;
+ event_data.y = y;
+ event_data.z = z;
+ g_strlcpy(event_data.device_id, device_id, UAM_DEVICE_ID_MAX_STRING_LEN);
+
+ __uam_send_event(event, result, &event_data,
+ event_info->cb, event_info->user_data);
} else if (0 == strcasecmp(signal_name, UAM_SIGNAL_PRESENCE_DETECTED)) {
uam_sensor_info_s sensor_info;
unsigned int sensor_bitmask;
void _uam_core_handle_absence_detected(unsigned int sensor,
int user_id, void *sensor_info);
+int _uam_core_handle_location_detected(unsigned int sensor,
+ int user_id, void *sensor_info);
+
void _uam_core_cleanup_monitor(char *name);
void _uam_core_reset_database(void);
_pm_util_uas_payload_to_uam_payload(payload, device->payload);
}
+ if (device->location) {
+ dev_info->distance_mm = device->location->distance_mm;
+ dev_info->x = device->location->x;
+ dev_info->y = device->location->y;
+ dev_info->z = device->location->z;
+ }
+
if (UAS_PRESENCE == type) {
UAM_DBG("Presence detected for device %s on sensor 0x%2.2X",
dev_info->device_id, sensor);
if (UAM_ERROR_NONE != ret)
UAM_WARN("_uam_core_handle_presence_detected failed");
+ } else if (UAS_LOCATION == type) {
+ UAM_DBG("Location detected for device %s on sensor 0x%2.2X",
+ dev_info->device_id, sensor);
+
+ ret = _uam_core_handle_location_detected(sensor,
+ device->user_id, dev_info);
+ if (UAM_ERROR_NONE != ret)
+ UAM_WARN("_uam_core_handle_location_detected failed");
+
} else {
UAM_DBG("Absence detected for device %s on sensor 0x%2.2X",
dev_info->device_id, sensor);
CASE_TO_STR(UAM_EVENT_USER_PRESENCE_DETECTED)
CASE_TO_STR(UAM_EVENT_ABSENCE_DETECTED)
CASE_TO_STR(UAM_EVENT_USER_ABSENCE_DETECTED)
+ CASE_TO_STR(UAM_EVENT_USER_LOCATION_DETECTED)
CASE_TO_STR(UAM_EVENT_AMBIANT_MODE_ENABLED)
CASE_TO_STR(UAM_EVENT_AMBIANT_MODE_DISABLED)
CASE_TO_STR(UAM_EVENT_SENSOR_STATE_READY)
case UAM_ADDR_TYPE_BT:
case UAM_ADDR_TYPE_P2P:
case UAM_ADDR_TYPE_WIFI:
+ case UAM_ADDR_TYPE_UWB:
g_strlcpy(device->mac, addr->address,
UAM_MAC_ADDRESS_STRING_LEN);
break;
GSList *l;
retv_if((UAM_DETECT_PRESENCE != detection_mode) &&
- (UAM_DETECT_ABSENCE != detection_mode), 0);
+ (UAM_DETECT_ABSENCE != detection_mode) &&
+ (UAM_DETECT_LOCATION != detection_mode), 0);
for (l = monitors; NULL != l; l = g_slist_next(l)) {
uam_monitor_info_t *monitor = l->data;
if (!service || !service->monitors)
continue;
- UAM_DBG("service: %p, monitors: %p", service, service->monitors);
+ UAM_DBG("service: %s, monitors: %p", service->name, service->monitors);
UAM_DBG("service->remaining_time: %d", service->remaining_time);
service->remaining_time -= UAM_DETECTION_CYCLE_MIN;
if (0 >= service->remaining_time) {
return ret;
}
+void __send_user_location_event(uam_db_tech_info_t *tech,
+ unsigned int sensor, uam_device_info_s *dev_info)
+{
+ FUNC_ENTRY;
+
+ GSList *l;
+ uam_db_user_info_t *user;
+ uam_svc_dev_info_t *svc_dev = NULL;
+ unsigned long long timestamp;
+
+ ret_if(NULL == tech);
+ ret_if(NULL == tech->svc_list);
+ ret_if(NULL == dev_info);
+
+ user = tech->device->user;
+
+ for (l = tech->svc_list; NULL != l; l = g_slist_next(l)) {
+ uam_db_service_info_t *svc = l->data;
+ GSList *l1;
+
+ if (!svc || !svc->monitors)
+ continue;
+
+ UAM_DBG("Check service device discriminant");
+ svc_dev = _uam_core_find_svc_dev_info(dev_info->device_id,
+ dev_info->type, svc->name, dev_info->app_num);
+ if (!svc_dev || !svc_dev->discriminant)
+ continue;
+
+ UAM_DBG("Send event");
+ for (l1 = svc->monitors; NULL != l1; l1 = g_slist_next(l1)) {
+ uam_monitor_info_t *mon = l1->data;
+
+ if (!mon)
+ continue;
+
+ if (!(mon->sensors & sensor))
+ continue;
+
+ if (UAM_DETECT_LOCATION != mon->mode)
+ continue;
+
+ /*
+ * For current service, if any of its running monitor has same sensor
+ * and detection_mode
+ */
+
+ timestamp = _uam_get_timestamp();
+ UAM_INFO("sensor [%d]", sensor);
+ _uam_manager_send_event(mon->name,
+ UAM_EVENT_USER_LOCATION_DETECTED,
+ g_variant_new("(utsssiiii)", sensor, timestamp,
+ user->account, svc->name, dev_info->device_id,
+ dev_info->distance_mm, dev_info->x, dev_info->y,
+ dev_info->z));
+ UAM_DBG("Sent UAM_EVENT_USER_LOCATION_DETECTED to %s"
+ " on device %s for 0x%8.8X, User: %s"
+ " Service: %s Timestamp: %llu distance: %d"
+ " coordinates x:%d y:%d z:%d",
+ mon->name, dev_info->device_id,
+ sensor, user->account, svc->name,
+ timestamp, dev_info->distance_mm,
+ dev_info->x, dev_info->y, dev_info->z);
+ }
+ }
+
+ FUNC_EXIT;
+}
+
+int _uam_core_handle_location_detected(unsigned int sensor,
+ int user_id, void *info)
+{
+ FUNC_ENTRY;
+ int ret = UAM_ERROR_NONE;
+
+ GSList *l;
+ uam_db_user_info_t *user;
+ uam_db_device_info_t *device;
+ uam_db_tech_info_t *tech;
+ uam_device_info_s *dev_info = NULL;
+
+ UAM_INFO("sensor: 0x%8.8X, user_id: %d", sensor, user_id);
+
+ if (info && (sensor & _uam_core_get_user_sensors())) {
+ /* Received info is device information */
+ dev_info = info;
+ }
+
+ if (NULL == dev_info) {
+ /* To-Do: Handle location detection if no dev info available */
+ return ret;
+ }
+
+ retv_if(0 > user_id, UAM_ERROR_INVALID_PARAMETER);
+
+ /* fetch the app_num info for the corresponding user_id */
+ _uam_core_get_app_num_from_userid(user_id, &dev_info->app_num);
+
+ /* Search user */
+ l = g_slist_find_custom(users, &user_id, __compare_user_id);
+ if (NULL == l) {
+ UAM_ERR("Invalid user_id [%d]", user_id);
+ return UAM_ERROR_INVALID_PARAMETER;
+ }
+ user = l->data;
+
+ /* Search device */
+ l = g_slist_find_custom(user->devices,
+ dev_info->device_id, __compare_device_id);
+ if (NULL == l) {
+ UAM_ERR("Valid user_id [%d] but Invalid device_id [%s]",
+ user_id, dev_info->device_id);
+ return UAM_ERROR_INVALID_PARAMETER;
+ }
+ device = l->data;
+
+ if (!(device->supported_techs & dev_info->type)) {
+ UAM_ERR("Valid device_id [%s] but Invalid tech type [%d]",
+ dev_info->device_id, dev_info->type);
+ return UAM_ERROR_INVALID_PARAMETER;
+ }
+
+ l = g_slist_find_custom(device->tech_list,
+ &(dev_info->type), __compare_tech_type);
+ if (NULL == l) {
+ UAM_ERR("Strange, tech type [%d] not found", dev_info->type);
+ return UAM_ERROR_INVALID_PARAMETER;
+ }
+ tech = l->data;
+
+ /* Send user location event */
+ __send_user_location_event(tech, sensor, dev_info);
+
+ FUNC_EXIT;
+ return ret;
+}
+
static void __send_user_absence_event(uam_tech_type_e type, unsigned int sensor)
{
FUNC_ENTRY;
CASE_TO_STR(UAM_EVENT_USER_PRESENCE_DETECTED)
CASE_TO_STR(UAM_EVENT_ABSENCE_DETECTED)
CASE_TO_STR(UAM_EVENT_USER_ABSENCE_DETECTED)
+ CASE_TO_STR(UAM_EVENT_USER_LOCATION_DETECTED)
CASE_TO_STR(UAM_EVENT_DETECTION_STARTED)
CASE_TO_STR(UAM_EVENT_DETECTION_STOPPED)
CASE_TO_STR(UAM_EVENT_DEVICE_FOUND)
case UAM_EVENT_USER_ABSENCE_DETECTED:
signal = UAM_SIGNAL_USER_ABSENCE_DETECTED;
break;
+ case UAM_EVENT_USER_LOCATION_DETECTED:
+ signal = UAM_SIGNAL_USER_LOCATION_DETECTED;
+ break;
case UAM_EVENT_DETECTION_STARTED:
signal = UAM_SIGNAL_DETECTION_STARTED;
break;
char *address; /**< Address data */
} uas_address_info_t;
+/* Device location information structure */
+typedef struct {
+ int distance_mm; /** Device distance (mm) */
+ int x; /** x coordinate */
+ int y; /** x coordinate */
+ int z; /** x coordinate */
+} uas_location_info_t;
+
/* Device payload information structure */
typedef struct {
char primary_key; /** Primary Key */
unsigned long long last_seen; /**< Last seen time */
int num_payload; /**< The number of payloads */
uas_payload_info_t *payload; /**< Payload for device filtering */
+ uas_location_info_t *location; /**< Device Location */
} uas_device_info_t;
/* Sensor information structure */