- [LNE_R_TWS] Redundant blank line at the start of a code block should be deleted.
- [SPC_M_SEP] Missing space after ,
- [SPC_M_SEP] Missing space before ( in while(
- [SPC_M_SEP] Extra space after (
- [SPC_M_OPR] Missing spaces around <
- ...
Change-Id: I238c4c0be773ef2b9f0067a09b35049ed322cacd
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
}
}
-static int get_power_save_state (void)
+static int get_power_save_state(void)
{
int state = 0;
int pm_state;
}
}
-
void restore_session(void)
{
AUTOLOCK(lock);
while (it_sensor != sensors.end()) {
cmd_channel = new(std::nothrow) command_channel();
- retm_if (!cmd_channel, "Failed to allocate memory");
+ retm_if(!cmd_channel, "Failed to allocate memory");
if (!cmd_channel->create_channel()) {
_E("%s failed to create command channel for %s", get_client_name(), get_sensor_name(*it_sensor));
return !(add_vec.empty() && del_vec.empty());
}
-
static bool change_sensor_rep(sensor_id_t sensor_id, sensor_rep &prev_rep, sensor_rep &cur_rep)
{
int client_id;
}
client_id = sensor_client_info::get_instance().get_client_id();
- retvm_if ((client_id < 0), false, "Invalid client id : %d, %s, %s", client_id, get_sensor_name(sensor_id), get_client_name());
+ retvm_if((client_id < 0), false, "Invalid client id : %d, %s, %s", client_id, get_sensor_name(sensor_id), get_client_name());
get_events_diff(prev_rep.event_types, cur_rep.event_types, add_event_types, del_event_types);
return false;
}
}
-
}
if (prev_rep.active && !del_event_types.empty()) {
API int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count)
{
- retvm_if (!get_sensor_list(), -EPERM, "Fail to get sensor list from server");
+ retvm_if(!get_sensor_list(), -EPERM, "Fail to get sensor list from server");
vector<sensor_info *> sensor_infos = sensor_info_manager::get_instance().get_infos(type);
API int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor)
{
- retvm_if (!get_sensor_list(), -EPERM, "Fail to get sensor list from server");
+ retvm_if(!get_sensor_list(), -EPERM, "Fail to get sensor list from server");
const sensor_info *info;
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !type,
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !type,
NULL, "Invalid param: sensor (%p), type(%p)", sensor, type);
*type = info->get_type();
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info),
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info),
NULL, "Invalid param: sensor (%p)", sensor);
return info->get_name();
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info),
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info),
NULL, "Invalid param: sensor (%p)", sensor);
return info->get_vendor();
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !privilege,
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !privilege,
false, "Invalid param: sensor (%p), privilege(%p)", sensor, privilege);
*privilege = info->get_privilege();
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !min_range,
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !min_range,
false, "Invalid param: sensor (%p), min_range(%p)", sensor, min_range);
*min_range = info->get_min_range();
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !max_range,
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !max_range,
false, "Invalid param: sensor (%p), max_range(%p)", sensor, max_range);
*max_range = info->get_max_range();
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !resolution,
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !resolution,
false, "Invalid param: sensor (%p), resolution(%p)", sensor, resolution);
*resolution = info->get_resolution();
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !min_interval,
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !min_interval,
false, "Invalid param: sensor (%p), min_interval(%p)", sensor, min_interval);
*min_interval = info->get_min_interval();
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !fifo_count,
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !fifo_count,
false, "Invalid param: sensor (%p), fifo_count(%p)", sensor, fifo_count);
*fifo_count = info->get_fifo_count();
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !max_batch_count,
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !max_batch_count,
false, "Invalid param: sensor (%p), max_batch_count(%p)", sensor, max_batch_count);
*max_batch_count = info->get_max_batch_count();
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !event_types || !count,
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !event_types || !count,
false, "Invalid param: sensor (%p), event_types(%p), count(%p)", sensor, event_types, count);
unsigned int event_type;
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !event_type || !supported,
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !event_type || !supported,
false, "Invalid param: sensor (%p), event_type(%p), supported(%p)", sensor, event_type, supported);
*supported = info->is_supported_event(event_type);
{
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info),
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info),
false, "Invalid param: sensor (%p)", sensor);
return info->is_wakeup_supported();
sensor_info* info = sensor_to_sensor_info(sensor);
- retvm_if (!sensor_info_manager::get_instance().is_valid(info),
+ retvm_if(!sensor_info_manager::get_instance().is_valid(info),
OP_ERROR, "Invalid param: sensor (%p)", sensor);
sensor_id_t sensor_id = info->get_id();
}
client_id = sensor_client_info::get_instance().get_client_id();
- retvm_if ((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
+ retvm_if((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
_I("%s disconnects with %s[%d]", get_client_name(), get_sensor_name(sensor_id), handle);
return true;
}
-
static bool register_event(int handle, unsigned int event_type, unsigned int interval, int max_batch_latency, void* cb, void *user_data)
{
sensor_id_t sensor_id;
sensor_rep prev_rep, cur_rep;
bool ret;
- retvm_if (!cb, false, "callback is NULL");
+ retvm_if(!cb, false, "callback is NULL");
AUTOLOCK(lock);
if (!sensor_client_info::get_instance().unregister_event(handle, event_type)) {
_E("%s try to unregister non registered event %s[%#x] for sensor %s[%d]",
- get_client_name(),get_event_name(event_type), event_type, get_sensor_name(sensor_id), handle);
+ get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id), handle);
return false;
}
sensor_client_info::get_instance().register_event(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data);
return ret;
-
}
-
API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data)
{
sensor_id_t sensor_id;
- retvm_if (!cb, false, "callback is NULL");
+ retvm_if(!cb, false, "callback is NULL");
AUTOLOCK(lock);
return false;
}
-
_I("%s registers accuracy_changed_cb for sensor %s[%d] with cb: %#x, user_data: %#x",
get_client_name(), get_sensor_name(sensor_id), handle, cb, user_data);
sensor_client_info::get_instance().register_accuracy_cb(handle, cb , user_data);
return true;
-
}
API bool sensord_unregister_accuracy_cb(int handle)
return false;
}
-
_I("%s unregisters accuracy_changed_cb for sensor %s[%d]",
get_client_name(), get_sensor_name(sensor_id), handle);
return true;
}
-
API bool sensord_start(int handle, int option)
{
sensor_id_t sensor_id;
return false;
}
- retvm_if ((option < 0) || (option >= SENSOR_OPTION_END), false, "Invalid option value : %d, handle: %d, %s, %s",
+ retvm_if((option < 0) || (option >= SENSOR_OPTION_END), false, "Invalid option value : %d, handle: %d, %s, %s",
option, handle, get_sensor_name(sensor_id), get_client_name());
_I("%s starts %s[%d], with option: %d, power save state: %d", get_client_name(), get_sensor_name(sensor_id),
return false;
}
- retvm_if ((sensor_state == SENSOR_STATE_STOPPED), true, "%s already stopped with %s[%d]",
+ retvm_if((sensor_state == SENSOR_STATE_STOPPED), true, "%s already stopped with %s[%d]",
get_client_name(), get_sensor_name(sensor_id), handle);
-
_I("%s stops sensor %s[%d]", get_client_name(), get_sensor_name(sensor_id), handle);
sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
return ret;
}
-
static bool change_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency)
{
sensor_id_t sensor_id;
return false;
}
- retvm_if ((option < 0) || (option >= SENSOR_OPTION_END), false, "Invalid option value : %d, handle: %d, %s, %s",
+ retvm_if((option < 0) || (option >= SENSOR_OPTION_END), false, "Invalid option value : %d, handle: %d, %s, %s",
option, handle, get_sensor_name(sensor_id), get_client_name());
-
sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_option);
sensor_client_info::get_instance().set_sensor_option(handle, prev_option);
return ret;
-
}
API int sensord_set_attribute_int(int handle, int attribute, int value)
}
client_id = sensor_client_info::get_instance().get_client_id();
- retvm_if ((client_id < 0), -EPERM,
+ retvm_if((client_id < 0), -EPERM,
"Invalid client id : %d, handle: %d, %s, %s",
client_id, handle, get_sensor_name(sensor_id), get_client_name());
value_len, value, handle, get_sensor_name(sensor_id), get_client_name());
client_id = sensor_client_info::get_instance().get_client_id();
- retvm_if ((client_id < 0), -EPERM,
+ retvm_if((client_id < 0), -EPERM,
"Invalid client id : %d, handle: %d, %s, %s",
client_id, handle, get_sensor_name(sensor_id), get_client_name());
int sensor_state;
int client_id;
- retvm_if ((!sensor_data), false, "sensor_data is NULL");
+ retvm_if((!sensor_data), false, "sensor_data is NULL");
AUTOLOCK(lock);
}
client_id = sensor_client_info::get_instance().get_client_id();
- retvm_if ((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
+ retvm_if((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
if (sensor_state != SENSOR_STATE_STARTED) {
_E("Sensor %s is not started for client %s with handle: %d, sensor_state: %d", get_sensor_name(sensor_id), get_client_name(), handle, sensor_state);
}
client_id = sensor_client_info::get_instance().get_client_id();
- retvm_if ((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
+ retvm_if((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
if (sensor_state != SENSOR_STATE_STARTED) {
_E("Sensor %s is not started for client %s with handle: %d, sensor_state: %d", get_sensor_name(sensor_id), get_client_name(), handle, sensor_state);
#ifndef _CLIENT_COMMON_H_
#define _CLIENT_COMMON_H_
-/*header for each sensor type*/
#include <sensor_internal.h>
#include <sensor_handle_info.h>
#include <reg_event_info.h>
: m_client_id(CLIENT_ID_INVALID)
, m_sensor_id(UNKNOWN_SENSOR)
{
-
}
+
command_channel::~command_channel()
{
if (m_command_socket.is_valid())
return true;
}
-
bool command_channel::cmd_hello(sensor_id_t sensor)
{
cpacket *packet;
if (m_command_socket.is_valid())
m_command_socket.close();
-
m_client_id = CLIENT_ID_INVALID;
m_sensor_id = UNKNOWN_SENSOR;
return true;
}
-
bool command_channel::cmd_register_events(event_type_vector &event_vec)
{
auto it_event = event_vec.begin();
return true;
}
-
bool command_channel::cmd_unregister_events(event_type_vector &event_vec)
{
auto it_event = event_vec.begin();
{
}
-
sensor_client_info& sensor_client_info::get_instance(void)
{
static sensor_client_info inst;
return inst;
}
-
int sensor_client_info::create_handle(sensor_id_t sensor)
{
sensor_handle_info handle_info;
handle_info.m_accuracy_cb = NULL;
handle_info.m_accuracy_user_data = NULL;
- m_sensor_handle_infos.insert(pair<int,sensor_handle_info> (handle, handle_info));
+ m_sensor_handle_infos.insert(pair<int, sensor_handle_info>(handle, handle_info));
return handle;
}
return true;
}
-
bool sensor_client_info::is_active()
{
AUTOLOCK(m_handle_info_lock);
if (!event_info)
return NULL;
-
interval = event_info->m_interval;
cb = event_info->m_cb;
user_data = event_info->m_user_data;
return true;
}
-
void sensor_client_info::get_listening_sensors(sensor_id_vector &sensors)
{
AUTOLOCK(m_handle_info_lock);
}
sort(sensors.begin(), sensors.end());
- unique(sensors.begin(),sensors.end());
+ unique(sensors.begin(), sensors.end());
}
void sensor_client_info::get_sensor_rep(sensor_id_t sensor, sensor_rep& rep) {
return false;
}
- m_command_channels.insert(pair<sensor_id_t, command_channel *> (sensor, cmd_channel));
+ m_command_channels.insert(pair<sensor_id_t, command_channel *>(sensor, cmd_channel));
return true;
-
}
+
bool sensor_client_info::get_command_channel(sensor_id_t sensor, command_channel **cmd_channel)
{
auto it_channel = m_command_channels.find(sensor);
return true;
}
-
bool sensor_client_info::close_command_channel(void)
{
auto it_channel = m_command_channels.begin();
sort(event_types.begin(), event_types.end());
unique_copy(event_types.begin(), event_types.end(), back_inserter(active_event_types));
-
}
-
void sensor_client_info::get_all_handles(handle_vector &handles)
{
AUTOLOCK(m_handle_info_lock);
}
}
-void sensor_client_info::get_sensor_handle_info(sensor_id_t sensor, sensor_handle_info_map &handles_info) {
-
+void sensor_client_info::get_sensor_handle_info(sensor_id_t sensor, sensor_handle_info_map &handles_info)
+{
AUTOLOCK(m_handle_info_lock);
auto it_handle = m_sensor_handle_infos.begin();
while (it_handle != m_sensor_handle_infos.end()) {
- if (it_handle->second.m_sensor_id == sensor) {
- handles_info.insert(pair<int,sensor_handle_info> (it_handle->first, it_handle->second));
- }
+ if (it_handle->second.m_sensor_id == sensor)
+ handles_info.insert(pair<int, sensor_handle_info>(it_handle->first, it_handle->second));
++it_handle;
}
}
-void sensor_client_info::get_all_handle_info(sensor_handle_info_map &handles_info) {
-
+void sensor_client_info::get_all_handle_info(sensor_handle_info_map &handles_info)
+{
AUTOLOCK(m_handle_info_lock);
auto it_handle = m_sensor_handle_infos.begin();
while (it_handle != m_sensor_handle_infos.end()) {
- handles_info.insert(pair<int,sensor_handle_info> (it_handle->first, it_handle->second));
+ handles_info.insert(pair<int, sensor_handle_info>(it_handle->first, it_handle->second));
++it_handle;
}
}
typedef vector<unsigned int> handle_vector;
typedef vector<sensor_id_t> sensor_id_vector;
-typedef unordered_map<int,sensor_handle_info> sensor_handle_info_map;
-typedef unordered_map<sensor_id_t, command_channel*> sensor_command_channel_map;
+typedef unordered_map<int, sensor_handle_info> sensor_handle_info_map;
+typedef unordered_map<sensor_id_t, command_channel *> sensor_command_channel_map;
typedef struct sensor_rep {
bool active;
cmutex m_handle_info_lock;
};
+
#endif /* _SENSOR_CLIENT_INFO_H_ */
if ((it_handle->second.m_sensor_state == SENSOR_STATE_STARTED) &&
power_save_state &&
!(it_handle->second.m_sensor_option & power_save_state)) {
-
m_client_info.set_sensor_state(it_handle->first, SENSOR_STATE_PAUSED);
_I("%s's %s[%d] is paused", get_client_name(), get_sensor_name(sensor), it_handle->first);
} else if ((it_handle->second.m_sensor_state == SENSOR_STATE_PAUSED) &&
(!power_save_state || (it_handle->second.m_sensor_option & power_save_state))) {
-
m_client_info.set_sensor_state(it_handle->first, SENSOR_STATE_STARTED);
_I("%s's %s[%d] is resumed", get_client_name(), get_sensor_name(sensor), it_handle->first);
}
m_client_info.get_all_handle_info(handles_info);
for (auto it_handle = handles_info.begin(); it_handle != handles_info.end(); ++it_handle) {
-
sensor_handle_info &sensor_handle_info = it_handle->second;
event_info = sensor_handle_info.get_reg_event_info(event_type);
client_callback_info* callback_info;
callback_info = new(std::nothrow)client_callback_info;
- retvm_if (!callback_info, NULL, "Failed to allocate memory");
+ retvm_if(!callback_info, NULL, "Failed to allocate memory");
callback_info->sensor = sensor_info_to_sensor(sensor_info_manager::get_instance().get_info(sensor_id));
callback_info->event_id = event_info->m_id;
if (m_hup_observer)
m_hup_observer();
}
-
}
bool sensor_event_listener::create_event_channel(void)
return true;
}
-
void sensor_event_listener::close_event_channel(void)
{
m_event_socket.close();
}
-
void sensor_event_listener::stop_event_listener(void)
{
const int THREAD_TERMINATING_TIMEOUT = 2;
m_client_info.set_client_id(CLIENT_ID_INVALID);
}
-
void sensor_event_listener::set_hup_observer(hup_observer_t observer)
{
m_hup_observer = observer;
m_event_socket.set_transfer_mode();
m_poller = new(std::nothrow) poller(m_event_socket.get_socket_fd());
- retvm_if (!m_poller, false, "Failed to allocate memory");
+ retvm_if(!m_poller, false, "Failed to allocate memory");
set_thread_state(THREAD_STATE_START);
typedef std::vector<unsigned int> handle_vector;
typedef std::vector<sensor_id_t> sensor_id_vector;
-typedef std::unordered_map<int,sensor_handle_info> sensor_handle_info_map;
+typedef std::unordered_map<int, sensor_handle_info> sensor_handle_info_map;
typedef std::unordered_map<sensor_id_t, command_channel*> sensor_command_channel_map;
typedef struct {
void set_thread_state(thread_state state);
};
+
#endif /* _SENSOR_EVENT_LISTENER_H_ */
, m_accuracy_cb(NULL)
, m_accuracy_user_data(NULL)
{
-
}
sensor_handle_info::~sensor_handle_info()
event_info.m_cb = cb;
event_info.m_user_data = user_data;
- m_reg_event_infos.insert(pair<unsigned int,reg_event_info> (event_type, event_info));
+ m_reg_event_infos.insert(pair<unsigned int, reg_event_info> (event_type, event_info));
return true;
}
m_reg_event_infos.clear();
}
-
unsigned long long sensor_handle_info::renew_event_id(void)
{
return m_event_id++;
{
return m_reg_event_infos.size();
}
-
#include <string.h>
#include <unordered_map>
-typedef std::unordered_map<unsigned int,reg_event_info> event_info_map;
+typedef std::unordered_map<unsigned int, reg_event_info> event_info_map;
class sensor_handle_info {
public:
static unsigned long long m_event_id;
};
-
#endif /* _SENSOR_HANDLE_INFO_H_ */
auto it_info = m_sensor_infos.begin();
while (it_info != m_sensor_infos.end()) {
-
delete it_info->second;
++it_info;
}
else
ret = m_sensor_infos.equal_range(type);
- for (auto it_info = ret.first; it_info != ret.second; ++it_info) {
+ for (auto it_info = ret.first; it_info != ret.second; ++it_info)
sensor_infos.push_back(it_info->second);
- }
return sensor_infos;
}
return it_info->second;
}
-
bool sensor_info_manager::is_valid(sensor_info* info)
{
auto it_info = m_info_set.find(info);
id_to_info_map m_id_to_info_map;
info_set m_info_set;
};
+
#endif /* _SENSOR_INFO_MANAGER_H_ */
*/
bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count);
-
/**
* @brief Get the supported event types of this sensor.
*
*/
bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count);
-
/**
* @brief Check a given event type is supporeted by this sensor.
*
* with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
* @return true on success, otherwise false.
*/
-
bool sensord_start(int handle, int option);
/**
}
#endif
-
#endif
float sensor_resolution;
} sensor_data_properties_t;
-DEPRECATED int sf_is_sensor_event_available(sensor_type_t sensor_type , unsigned int event_type);
+DEPRECATED int sf_is_sensor_event_available(sensor_type_t sensor_type, unsigned int event_type);
DEPRECATED int sf_get_data_properties(unsigned int data_id, sensor_data_properties_t *return_data_properties);
* @fn int sf_connect(sensor_type_t sensor)
* @brief This API connects a sensor type to respective sensor. The application calls with the type of the sensor (ex. ACCELEROMETER_SENSOR) and on basis of that server takes decision of which plug-in to be connected. Once sensor connected application can proceed for data processing. This API returns a positive handle which should be used by application to communicate on sensor type.
* @param[in] sensor_type your desired sensor type
- * @return if it succeed, it return handle value( >=0 ) , otherwise negative value return
+ * @return if it succeed, it return handle value( >=0 ), otherwise negative value return
*/
DEPRECATED int sf_connect(sensor_type_t sensor_type);
* @fn int sf_disconnect(int handle)
* @brief This API disconnects an attached sensor from an application. Application must use the handle retuned after attaching the sensor. After detaching, the corresponding handle will be released.
* @param[in] handle received handle value by sf_connect()
- * @return if it succeed, it return zero value , otherwise negative value return
+ * @return if it succeed, it return zero value, otherwise negative value return
*/
DEPRECATED int sf_disconnect(int handle);
/**
- * @fn int sf_start(int handle , int option)
+ * @fn int sf_start(int handle, int option)
* @brief This API sends a start command to sensor server. This intimates server that the client side is ready to handle data and start processing. The parameter option should be '0' for current usages.
* @param[in] handle received handle value by sf_connect()
* @param[in] option With SENSOR_OPTION_DEFAULT, it stops to sense when LCD is off, and with SENSOR_OPTION_ALWAYS_ON, it continues to sense even when LCD is off
- * @return if it succeed, it return zero value , otherwise negative value return
+ * @return if it succeed, it return zero value, otherwise negative value return
*/
-DEPRECATED int sf_start(int handle , int option);
+DEPRECATED int sf_start(int handle, int option);
/**
* @fn int sf_stop(int handle)
* @brief This API sends a stop command to the Sensor server indicating that the data processing is stopped from application side for this time.
* @param[in] handle received handle value by sf_connect()
- * @return if it succeed, it return zero value , otherwise negative value return
+ * @return if it succeed, it return zero value, otherwise negative value return
*/
DEPRECATED int sf_stop(int handle);
/**
- * @fn int sf_register_event(int handle , unsigned int event_type , event_conditon_t *event_condition , sensor_callback_func_t cb , void *user_data )
+ * @fn int sf_register_event(int handle, unsigned int event_type, event_conditon_t *event_condition, sensor_callback_func_t cb, void *user_data )
* @brief This API registers a user defined callback function with a connected sensor for a particular event. This callback function will be called when there is a change in the state of respective sensor. user_data will be the parameter used during the callback call. Callback interval can be adjusted using even_contion_t argument.
* @param[in] handle received handle value by sf_connect()
* @param[in] event_type your desired event_type to register it
* @param[in] event_condition input event_condition for special event. if you want to register without event_condition, just use a NULL value
* @param[in] cb your define callback function
* @param[in] user_data your option data that will be send when your define callback function called. if you don't have any option data, just use a NULL value
- * @return if it succeed, it return zero value , otherwise negative value return
+ * @return if it succeed, it return zero value, otherwise negative value return
*/
-DEPRECATED int sf_register_event(int handle , unsigned int event_type , event_condition_t *event_condition , sensor_callback_func_t cb , void *user_data );
+DEPRECATED int sf_register_event(int handle, unsigned int event_type, event_condition_t *event_condition, sensor_callback_func_t cb, void *user_data);
/**
* @fn int sf_unregister_event(int handle, unsigned int event_type)
* @brief This API de-registers a user defined callback function with a sensor registered with the specified handle. After unsubscribe, no event will be sent to the application.
* @param[in] handle received handle value by sf_connect()
* @param[in] event_type your desired event_type that you want to unregister event
- * @return if it succeed, it return zero value , otherwise negative value return
+ * @return if it succeed, it return zero value, otherwise negative value return
*/
DEPRECATED int sf_unregister_event(int handle, unsigned int event_type);
/**
- * @fn int sf_get_data(int handle , unsigned int data_id , sensor_data_t* values)
+ * @fn int sf_get_data(int handle, unsigned int data_id, sensor_data_t* values)
* @brief This API gets raw data from a sensor with connecting the sensor-server. The type of sensor is supplied and return data is stored in the output parameter values [].
* @param[in] handle received handle value by sf_connect()
- * @param[in] data_id predefined data_ID as every sensor in own header - sensor_xxx.h , enum xxx_data_id {}
+ * @param[in] data_id predefined data_ID as every sensor in own header - sensor_xxx.h, enum xxx_data_id {}
* @param[out] values return values
- * @return if it succeed, it return zero value , otherwise negative value return
+ * @return if it succeed, it return zero value, otherwise negative value return
*/
-DEPRECATED int sf_get_data(int handle , unsigned int data_id , sensor_data_t* values);
+DEPRECATED int sf_get_data(int handle, unsigned int data_id, sensor_data_t* values);
/**
* @fn int sf_change_event_condition(int handle, unsigned int event_type, event_condition_t *event_condition)
* @param[in] handle received handle value by sf_connect()
* @param[in] event_type your desired event_type that you want to unregister event
* @param[in] event_condition your desired event condition that you want to change event
- * @return if it succeed, it return zero value , otherwise negative value return
+ * @return if it succeed, it return zero value, otherwise negative value return
*/
DEPRECATED int sf_change_event_condition(int handle, unsigned int event_type, event_condition_t *event_condition);
* @brief This API change sensor option .
* @param[in] handle received handle value by sf_connect()
* @param[in] option your desired option that you want to turn on sensor during LCD OFF
- * @return if it succeed, it return zero value , otherwise negative value return
+ * @return if it succeed, it return zero value, otherwise negative value return
*/
DEPRECATED int sf_change_sensor_option(int handle, int option);
*/
DEPRECATED int sf_send_sensorhub_data(int handle, const char* data, int data_len);
-
#ifdef __cplusplus
}
#endif
-
#endif
SENSOR_DEVICE_STRESS_MONITOR,
SENSOR_DEVICE_AUTOSESSION_EXERCISE,
SENSOR_DEVICE_STAIR_TRACKER,
-
} sensor_device_type;
/*
enum sensor_accuracy_t {
SENSOR_ACCURACY_UNDEFINED = -1,
SENSOR_ACCURACY_BAD = 0,
- SENSOR_ACCURACY_NORMAL =1,
+ SENSOR_ACCURACY_NORMAL = 1,
SENSOR_ACCURACY_GOOD = 2,
SENSOR_ACCURACY_VERYGOOD = 3
};
accel_sensor::~accel_sensor()
{
-
}
sensor_type_t accel_sensor::get_type(void)
virtual bool stop(void);
virtual bool get_rotation(float acc[3], unsigned long long timestamp, int prev_rotation, int &rotation) = 0;
};
+
#endif /* _AUTO_ROTATION_ALG_H_ */
private:
int convert_rotation(int prev_rotation, float acc_pitch, float acc_theta);
};
+
#endif /* _AUTO_ROTATION_ALG_EMUL_H_ */
push(rotation_event);
_D("Rotation: %d, ACC[0]: %f, ACC[1]: %f, ACC[2]: %f", rotation, event.data->values[0], event.data->values[1], event.data->values[2]);
- return;
}
int auto_rotation_sensor::get_data(sensor_data_t **data, int *length)
_I("m_accel_static_bias = (%f, %f, %f)", m_accel_static_bias[0], m_accel_static_bias[1], m_accel_static_bias[2]);
- if (!config.get(SENSOR_TYPE_FUSION, ELEMENT_GYRO_STATIC_BIAS, m_gyro_static_bias,3)) {
+ if (!config.get(SENSOR_TYPE_FUSION, ELEMENT_GYRO_STATIC_BIAS, m_gyro_static_bias, 3)) {
_E("[GYRO_STATIC_BIAS] is empty\n");
throw ENXIO;
}
m_orientation_filter.get_device_orientation(m_accel_ptr, m_gyro_ptr, m_magnetic_ptr);
-
-
if (m_enable_fusion == GYROSCOPE_UNCAL_ENABLED && sensor_base::is_supported(FUSION_GYROSCOPE_UNCAL_ENABLED)) {
m_time = get_timestamp();
fusion_event.sensor_id = get_id();
}
m_enable_fusion = 0;
-
m_accel_ptr = m_gyro_ptr = m_magnetic_ptr = NULL;
}
data.values[0] = m_orientation_filter_poll.m_gyro_bias.m_vec[0];
data.values[1] = m_orientation_filter_poll.m_gyro_bias.m_vec[1];
data.values[2] = m_orientation_filter_poll.m_gyro_bias.m_vec[2];
- }
- else if (event_type == FUSION_ORIENTATION_ENABLED ||
+ } else if (event_type == FUSION_ORIENTATION_ENABLED ||
event_type == FUSION_ROTATION_VECTOR_ENABLED ||
event_type == FUSION_GAMING_ROTATION_VECTOR_ENABLED ||
event_type == FUSION_TILT_ENABLED ||
#define DEG2RAD(x) ((x) * M_PI / 180.0)
#define NORM(x, y, z) sqrt((x)*(x) + (y)*(y) + (z)*(z))
-#define ARCTAN(x, y) ((x) == 0 ? 0 : (y) != 0 ? atan2((x),(y)) : (x) > 0 ? M_PI/2.0 : -M_PI/2.0)
+#define ARCTAN(x, y) ((x) == 0 ? 0 : (y) != 0 ? atan2((x), (y)) : (x) > 0 ? M_PI/2.0 : -M_PI/2.0)
gravity_sensor::gravity_sensor()
: m_fusion(NULL)
hrm_sensor::~hrm_sensor()
{
-
}
if(m_raw_data_unit == "DEGREES") {
euler = rad2deg(euler);
azimuth_offset = AZIMUTH_OFFSET_DEGREES;
- }
- else {
+ } else {
azimuth_offset = AZIMUTH_OFFSET_RADIANS;
}
if(m_raw_data_unit == "DEGREES") {
euler = rad2deg(euler);
azimuth_offset = AZIMUTH_OFFSET_DEGREES;
- }
- else {
+ } else {
azimuth_offset = AZIMUTH_OFFSET_RADIANS;
}
if(m_raw_data_unit == "DEGREES") {
properties.min_range = -180;
properties.max_range = 360;
- }
- else {
+ } else {
properties.min_range = -PI;
properties.max_range = 2 * PI;
}
_I("m_accel_static_bias = (%f, %f, %f)", m_accel_static_bias[0], m_accel_static_bias[1], m_accel_static_bias[2]);
- if (!config.get(SENSOR_TYPE_GAMING_RV, ELEMENT_GYRO_STATIC_BIAS, m_gyro_static_bias,3)) {
+ if (!config.get(SENSOR_TYPE_GAMING_RV, ELEMENT_GYRO_STATIC_BIAS, m_gyro_static_bias, 3)) {
_E("[GYRO_STATIC_BIAS] is empty\n");
throw ENXIO;
}
template <typename TYPE>
euler_angles<TYPE>::~euler_angles()
{
-
}
template <typename TYPE>
m_pred_cov = (m_tran_mat * m_pred_cov * tran(m_tran_mat)) + m_driv_cov;
- for (int j=0; j<M6X6C; ++j) {
- for (int i=0; i<M6X6R; ++i) {
+ for (int j = 0; j < M6X6C; ++j) {
+ for (int i = 0; i < M6X6R; ++i) {
if (ABS(m_pred_cov.m_mat[i][j]) < NEGLIGIBLE_VAL)
m_pred_cov.m_mat[i][j] = NEGLIGIBLE_VAL;
}
m_quat_driv = (m_quat_driv * quat_eu_er) * (TYPE) PI;
m_quat_driv.quat_normalize();
- if (is_initialized(m_state_new))
- {
+ if (is_initialized(m_state_new)) {
m_state_error.m_vec[0] = m_euler_error.m_ang.m_vec[0];
m_state_error.m_vec[1] = m_euler_error.m_ang.m_vec[1];
m_state_error.m_vec[2] = m_euler_error.m_ang.m_vec[2];
euler_aid = quat2euler(m_quat_aid);
euler_driv = quat2euler(m_quat_output);
- if ((SQUARE(m_accel.m_data.m_vec[1]) < ACCEL_THRESHOLD) && (SQUARE(m_gyro.m_data.m_vec[0]) < GYRO_THRESHOLD))
- {
- if ((SQUARE(m_accel.m_data.m_vec[0]) < ACCEL_THRESHOLD) && (SQUARE(m_gyro.m_data.m_vec[1]) < GYRO_THRESHOLD))
- {
- if (SQUARE(m_gyro.m_data.m_vec[2]) < GYRO_THRESHOLD)
- {
+ if ((SQUARE(m_accel.m_data.m_vec[1]) < ACCEL_THRESHOLD) && (SQUARE(m_gyro.m_data.m_vec[0]) < GYRO_THRESHOLD)) {
+ if ((SQUARE(m_accel.m_data.m_vec[0]) < ACCEL_THRESHOLD) && (SQUARE(m_gyro.m_data.m_vec[1]) < GYRO_THRESHOLD)) {
+ if (SQUARE(m_gyro.m_data.m_vec[2]) < GYRO_THRESHOLD) {
euler_angles<TYPE> euler_gaming_rv(euler_aid.m_ang.m_vec[0], euler_aid.m_ang.m_vec[1],
euler_driv.m_ang.m_vec[2]);
m_quat_gaming_rv = euler2quat(euler_gaming_rv);
iden.m_mat[0][0] = iden.m_mat[1][1] = iden.m_mat[2][2] = 1;
iden.m_mat[3][3] = iden.m_mat[4][4] = iden.m_mat[5][5] = 1;
- for (int j=0; j<M6X6C; ++j) {
- for (int i=0; i<M6X6R; ++i) {
+ for (int j = 0; j < M6X6C; ++j) {
+ for (int i = 0; i < M6X6R; ++i) {
gain.m_mat[i][j] = m_pred_cov.m_mat[j][i] / (m_pred_cov.m_mat[j][j] + m_aid_cov.m_mat[j][j]);
m_state_new.m_vec[i] = m_state_new.m_vec[i] + gain.m_mat[i][j] * m_state_error.m_vec[j];
}
matrix<TYPE, M6X6R, M6X6C> temp = iden;
- for (int i=0; i<M6X6R; ++i)
+ for (int i = 0; i < M6X6R; ++i)
temp.m_mat[i][j] = iden.m_mat[i][j] - (gain.m_mat[i][j] * m_measure_mat.m_mat[j][i]);
m_pred_cov = temp * m_pred_cov;
}
- for (int j=0; j<M6X6C; ++j) {
- for (int i=0; i<M6X6R; ++i) {
+ for (int j = 0; j < M6X6C; ++j) {
+ for (int i = 0; i < M6X6R; ++i) {
if (ABS(m_pred_cov.m_mat[i][j]) < NEGLIGIBLE_VAL)
m_pred_cov.m_mat[i][j] = NEGLIGIBLE_VAL;
}
initialize_sensor_data(accel, gyro, magnetic);
if (gyro != NULL && magnetic != NULL) {
-
orientation_triad_algorithm();
-
compute_covariance();
-
time_update();
-
measurement_update();
-
m_quaternion = m_quat_9axis;
-
} else if (!gyro && !magnetic) {
-
compute_accel_orientation();
-
m_quaternion = m_quat_aid;
-
} else if (!gyro) {
-
orientation_triad_algorithm();
-
m_quaternion = m_quat_aid;
-
} else if (!magnetic) {
-
compute_accel_orientation();
-
compute_covariance();
-
time_update_gaming_rv();
-
measurement_update();
-
m_quaternion = m_quat_gaming_rv;
}
}
template <typename TYPE>
rotation_matrix<TYPE>::rotation_matrix() : m_rot_mat()
{
-
}
template <typename TYPE>
template <typename TYPE>
rotation_matrix<TYPE>::~rotation_matrix()
{
-
}
template <typename TYPE>
const vect<T, REF_VEC_SIZE> ref_vec);
template<typename T> friend void pre_process_data(sensor_data<T> &data_out,
const T *data_in, T *bias, int *sign, int scale);
-
};
#include "sensor_data.cpp"
}
orien_filter.get_device_orientation(accel_data, gyro_data, magnetic_data);
-
}
-#endif
+#endif /* _ORIENTATION_SENSOR_H_ */
float arr2[4] = {0.6, 0.6, -.18, -.44};
float arr3[4] = {-0.5, -0.36, .43, .03};
- vect<float,3> v0(arr0);
- vect<float,3> v1(arr1);
- vect<float,4> v2(arr2);
- vect<float,4> v3(arr3);
+ vect<float, 3> v0(arr0);
+ vect<float, 3> v1(arr1);
+ vect<float, 4> v2(arr2);
+ vect<float, 4> v3(arr3);
quaternion<float> q1(v2);
quaternion<float> q2(v3);
sdata[0] = strtof(line_accel.c_str(), &token);
sdata[1] = strtof(token, &token);
sdata[2] = strtof(token, &token);
- time_stamp = strtoull (token, NULL, 10);
+ time_stamp = strtoull(token, NULL, 10);
sensor_data<float> accel_data(sdata[0], sdata[1], sdata[2], time_stamp);
cout << "Accel Data\t" << accel_data.m_data << "\t Time Stamp\t" << accel_data.m_time_stamp << "\n\n";
sdata[0] = strtof(line_gyro.c_str(), &token);
sdata[1] = strtof(token, &token);
sdata[2] = strtof(token, &token);
- time_stamp = strtoull (token, NULL, 10);
+ time_stamp = strtoull(token, NULL, 10);
sensor_data<float> gyro_data(sdata[0], sdata[1], sdata[2], time_stamp);
cout << "Gyro Data\t" << gyro_data.m_data << "\t Time Stamp\t" << gyro_data.m_time_stamp << "\n\n";
sdata[0] = strtof(line_magnetic.c_str(), &token);
sdata[1] = strtof(token, &token);
sdata[2] = strtof(token, &token);
- time_stamp = strtoull (token, NULL, 10);
+ time_stamp = strtoull(token, NULL, 10);
sensor_data<float> magnetic_data(sdata[0], sdata[1], sdata[2], time_stamp);
cout << "Magnetic Data\t" << magnetic_data.m_data << "\t Time Stamp\t" << magnetic_data.m_time_stamp << "\n\n";
sdata[0] = strtof(line_accel.c_str(), &token);
sdata[1] = strtof(token, &token);
sdata[2] = strtof(token, &token);
- time_stamp = strtoull (token, NULL, 10);
+ time_stamp = strtoull(token, NULL, 10);
sensor_data<float> accel_data(sdata[0], sdata[1], sdata[2], time_stamp);
cout << "Accel Data\t" << accel_data.m_data << "\t Time Stamp\t" << accel_data.m_time_stamp << "\n\n";
sdata[0] = strtof(line_gyro.c_str(), &token);
sdata[1] = strtof(token, &token);
sdata[2] = strtof(token, &token);
- time_stamp = strtoull (token, NULL, 10);
+ time_stamp = strtoull(token, NULL, 10);
sensor_data<float> gyro_data(sdata[0], sdata[1], sdata[2], time_stamp);
cout << "Gyro Data\t" << gyro_data.m_data << "\t Time Stamp\t" << gyro_data.m_time_stamp << "\n\n";
sdata[0] = strtof(line_magnetic.c_str(), &token);
sdata[1] = strtof(token, &token);
sdata[2] = strtof(token, &token);
- time_stamp = strtoull (token, NULL, 10);
+ time_stamp = strtoull(token, NULL, 10);
sensor_data<float> magnetic_data(sdata[0], sdata[1], sdata[2], time_stamp);
cout << "Magnetic Data\t" << magnetic_data.m_data << "\t Time Stamp\t" << magnetic_data.m_time_stamp << "\n\n";
int main()
{
- float arr0[2][2] = {{-2.243, 2.57},{3.56, -3.02}};
- float arr1[2][2] = {{2.2, 2.5},{3.5, 3.0}};
+ float arr0[2][2] = {{-2.243, 2.57}, {3.56, -3.02}};
+ float arr1[2][2] = {{2.2, 2.5}, {3.5, 3.0}};
float arr5[3][2] = {{0.22, 4.56}, {3.652, 5.86}, {1.430, 0.45}};
float arr11[1][3] = {{2.0, 3.0, 4.0}};
float arr12[3][1] = {{2.0}, {1.0}, {3.0}};
matrix<float, 2, 3> m22(arr15);
matrix<float, 3, 3> m9(arr9);
- cout<< "Constructor Test\n";
- cout<< "\n" << m6;
+ cout << "Constructor Test\n";
+ cout << "\n" << m6;
- cout<<"\n\nAddition\n";
+ cout << "\n\nAddition\n";
m6 = m10 + m15;
m13 = m11 + m11;
- cout<< "\n" << m10 <<"\n"<< m15;
- cout<< "\nSum:\n" << m6 << endl;
- cout<< "\n" << m11 << "\n"<< m11;
- cout<< "\nSum:\n" << m13 << endl;
+ cout << "\n" << m10 << "\n" << m15;
+ cout << "\nSum:\n" << m6 << endl;
+ cout << "\n" << m11 << "\n" << m11;
+ cout << "\nSum:\n" << m13 << endl;
- cout<< "\n\n\nSubtraction\n";
+ cout << "\n\n\nSubtraction\n";
m6 = m10 - m12;
- cout<< "\n" << m10 << "\n" << m12;
- cout<< "\nDifference:\n" << m6 << endl;
+ cout << "\n" << m10 << "\n" << m12;
+ cout << "\nDifference:\n" << m6 << endl;
- cout<< "\n\n\nMultiplication\n";
+ cout << "\n\n\nMultiplication\n";
m6 = m10 * m12;
m3 = m1 * m2;
matrix<float, 1, 1> m7;
m7 = m20 * m21;
- cout<< "\n" << m10 << "\n" << m12;
- cout<< "\nProduct:\n" << m6 << endl;
- cout<< "\n" << m1 << "\n" << m2;
- cout<< "\nProduct:\n" << m3 << endl;
- cout<< "\n" << m20 << "\n" << m21;
- cout<< "\nProduct:\n" << m7 << endl;
- cout<< "\n" << m9 << "\n" << m21;
+ cout << "\n" << m10 << "\n" << m12;
+ cout << "\nProduct:\n" << m6 << endl;
+ cout << "\n" << m1 << "\n" << m2;
+ cout << "\nProduct:\n" << m3 << endl;
+ cout << "\n" << m20 << "\n" << m21;
+ cout << "\nProduct:\n" << m7 << endl;
+ cout << "\n" << m9 << "\n" << m21;
m21 = m9 * m21;
- cout<< "\nProduct:\n" << m21 << endl;
+ cout << "\nProduct:\n" << m21 << endl;
- cout<< "\n\n\nDivision\n";
+ cout << "\n\n\nDivision\n";
m3 = m1 / (float)2.5;
- cout<< "\n" << m1 << "\n" << "2.5";
- cout<< "\nResult:\n" << m3 << endl;
+ cout << "\n" << m1 << "\n" << "2.5";
+ cout << "\nResult:\n" << m3 << endl;
m6 = m12 / (float)0.125;
- cout<< "\n" << m12 << "\n" << ".125";
- cout<< "\nResult:\n" << m6 << endl;
+ cout << "\n" << m12 << "\n" << ".125";
+ cout << "\nResult:\n" << m6 << endl;
float num = 5.5650;
float num1 = -2.32;
- cout<< "\n\n\nScalar addition\n";
+ cout << "\n\n\nScalar addition\n";
m3 = m2 + num;
m6 = m10 + num1;
- cout<< "\nNumber added:" << num;
- cout<< "\n\n" << m2;
- cout<< "\nResult:\n\n" << m3;
- cout<< "\nNumber added:" << num1;
- cout<< "\n\n" << m10;
- cout<< "\nResult:\n\n" << m6;
+ cout << "\nNumber added:" << num;
+ cout << "\n\n" << m2;
+ cout << "\nResult:\n\n" << m3;
+ cout << "\nNumber added:" << num1;
+ cout << "\n\n" << m10;
+ cout << "\nResult:\n\n" << m6;
float x = 4.0;
float x1 = -2.5;
- cout<< "\n\n\nScalar subtraction\n";
+ cout << "\n\n\nScalar subtraction\n";
m13 = m11 - x;
m6 = m10 - x1;
- cout<< "\nNumber Subtracted:" << x;
- cout<< "\n\n" << m11;
- cout<< "\nResult:\n\n" << m13;
- cout<< "\nNumber Subtracted:" << x1;
- cout<< "\n\n" << m10;
- cout<< "\nResult:\n\n" << m6;
+ cout << "\nNumber Subtracted:" << x;
+ cout << "\n\n" << m11;
+ cout << "\nResult:\n\n" << m13;
+ cout << "\nNumber Subtracted:" << x1;
+ cout << "\n\n" << m10;
+ cout << "\nResult:\n\n" << m6;
float z = 3.50;
float z1 = -5.567;
- cout<< "\n\n\nScalar multiplication\n";
+ cout << "\n\n\nScalar multiplication\n";
m3 = m1 * z;
m6 = m12 * z1;
- cout<< "\nNumber Multiplied:"<< z;
- cout<< "\n\n" << m1;
- cout<< "\nResult:\n\n" << m3;
- cout<< "\nNumber Multiplied:" << z1;
- cout<< "\n\n" << m12;
- cout<< "\nResult:\n\n" << m6;
+ cout << "\nNumber Multiplied:" << z;
+ cout << "\n\n" << m1;
+ cout << "\nResult:\n\n" << m3;
+ cout << "\nNumber Multiplied:" << z1;
+ cout << "\n\n" << m12;
+ cout << "\nResult:\n\n" << m6;
m6 = tran(m15);
- cout<< "\n\n\nTranspose:";
+ cout << "\n\n\nTranspose:";
cout << "\n\n" << m15;
cout << "\nResult:\n\n" << m6;
cout << (m6 != m1);
- cout<< "\n\nAssignment\n";
+ cout << "\n\nAssignment\n";
matrix<float, 3, 3> m30 = m12;
- cout<< "Input \n" << m12;
- cout<< "\nOutput:\n" << m30 << endl;
-
+ cout << "Input \n" << m12;
+ cout << "\nOutput:\n" << m30 << endl;
}
sdata[0] = strtof(line_accel.c_str(), &token);
sdata[1] = strtof(token, &token);
sdata[2] = strtof(token, &token);
- time_stamp = strtoull (token, NULL, 10);
+ time_stamp = strtoull(token, NULL, 10);
sensor_data<float> accel_data(sdata[0], sdata[1], sdata[2], time_stamp);
cout << "Accel Data\t" << accel_data.m_data << "\t Time Stamp\t" << accel_data.m_time_stamp << "\n\n";
sdata[0] = strtof(line_gyro.c_str(), &token);
sdata[1] = strtof(token, &token);
sdata[2] = strtof(token, &token);
- time_stamp = strtoull (token, NULL, 10);
+ time_stamp = strtoull(token, NULL, 10);
sensor_data<float> gyro_data(sdata[0], sdata[1], sdata[2], time_stamp);
cout << "Gyro Data\t" << gyro_data.m_data << "\t Time Stamp\t" << gyro_data.m_time_stamp << "\n\n";
sdata[0] = strtof(line_magnetic.c_str(), &token);
sdata[1] = strtof(token, &token);
sdata[2] = strtof(token, &token);
- time_stamp = strtoull (token, NULL, 10);
+ time_stamp = strtoull(token, NULL, 10);
sensor_data<float> magnetic_data(sdata[0], sdata[1], sdata[2], time_stamp);
cout << "Magnetic Data\t" << magnetic_data.m_data << "\t Time Stamp\t" << magnetic_data.m_time_stamp << "\n\n";
quaternion<float> q11 = axis2quat(v2, ang1);
cout << "output\t" << q11.m_quat << "\n\n";
cout << endl;
-
}
{
float arr1[3] = {1.04, -4.678, -2.34};
float arr2[3] = {0, 0, 1};
- vect<float,3> v1(arr1);
- vect<float,3> v2(arr2);
+ vect<float, 3> v1(arr1);
+ vect<float, 3> v2(arr2);
sensor_data<float> sd1(2.0, 3.0, 4.0, 140737488355328);
sensor_data<float> sd2(1.04, -4.678, -2.34, 0);
cout << "input\t" << v1 << "\n";
cout << "output\t" << sd2.m_data << "\t" << sd2.m_time_stamp << "\n\n";
- cout<< "Addition:\n";
+ cout << "Addition:\n";
sensor_data<float> sd4 = sd1 + sd2;
- cout<< "\n" << sd1.m_data << "\n" << sd2.m_data;
- cout<< "\nSum:\n" << sd4.m_data << endl;
+ cout << "\n" << sd1.m_data << "\n" << sd2.m_data;
+ cout << "\nSum:\n" << sd4.m_data << endl;
sensor_data<float> sd9 = sd1 + sd10;
- cout<< "\n" << sd1.m_data << "\n" << sd10.m_data;
- cout<< "\nSum:\n" << sd9.m_data << endl;
+ cout << "\n" << sd1.m_data << "\n" << sd10.m_data;
+ cout << "\nSum:\n" << sd9.m_data << endl;
- cout<< "\n\n\nNormalization:\n";
- cout<< "\n" << sd3.m_data;
+ cout << "\n\n\nNormalization:\n";
+ cout << "\n" << sd3.m_data;
normalize(sd3);
- cout<< "\nResult:\n" << sd3.m_data << endl;
- cout<< "\n" << sd2.m_data;
+ cout << "\nResult:\n" << sd3.m_data << endl;
+ cout << "\n" << sd2.m_data;
normalize(sd2);
- cout<< "\nResult:\n" << sd2.m_data << endl;
+ cout << "\nResult:\n" << sd2.m_data << endl;
float xx = 2.5;
- cout<<"\n\n\nScale data:\n";
+ cout << "\n\n\nScale data:\n";
sensor_data<float> sd8 = scale_data(sd2, xx);
- cout<< "\n" << sd2.m_data << "\n" << xx;
- cout<< "\nResult:\n" << sd8.m_data << endl;
+ cout << "\n" << sd2.m_data << "\n" << xx;
+ cout << "\nResult:\n" << sd8.m_data << endl;
- cout<<"\n\n\nConvert Sensor Data to Quaternion:\n";
+ cout << "\n\n\nConvert Sensor Data to Quaternion:\n";
quaternion<float> q = sensor_data2quat(sd11, v2);
- cout<< "\n" << sd11.m_data << "\n" << v2;
- cout<< "\nResult:\n" << q.m_quat << endl;
+ cout << "\n" << sd11.m_data << "\n" << v2;
+ cout << "\nResult:\n" << q.m_quat << endl;
}
int main()
{
- float arr2[3] = {0.056,2.34,-65.76};
- float arr15[3] = {1.04,-4.678,-2.34};
- float arr3[4] = {1.03,2.345,6.78,5.55};
- float arr4[4] = {-6.78,-45.213,-7.89,-3.456};
- float arr8[5] = {0.0123,5.678,2.345,0.345,8.956};
- float arr0[5] = {2344.98,345.24,456.12,98.33,144.67};
- float arr1[6] = {1.234,4.5,6.8987,3.33,5.66,77.695};
- float arr43[6] = {2.3454,-0.0384,-8.90,3.455,6.785,21.345};
- float arr5[5] = {0.2,-0.4,0.6,-0.8,1.0};
-
- vect<float,5> v1(arr0);
- vect<float,5> v2(arr8);
- vect<float,4> v10(arr3);
- vect<float,4> v12(arr4);
- vect<float,6> v15(arr1);
- vect<float,6> v20(arr43);
- vect<float,3> v21(arr2);
- vect<float,3> v22(arr15);
- vect<float,5> v31(arr0);
- vect<float,3> v3;
- vect<float,2> vn;
- vect<float,4> v61(arr4);
- vect<float,3> v6;
- vect<float,4> vm;
- vect<float,5> v13;
- vect<float,6> v95;
- vect<float,5> v35(arr5);
- vect<float,5> vl;
- vect<float,4> vp;
- vect<float,4> vr(arr4);
- vect<float,3> vf;
+ float arr2[3] = {0.056, 2.34, -65.76};
+ float arr15[3] = {1.04, -4.678, -2.34};
+ float arr3[4] = {1.03, 2.345, 6.78, 5.55};
+ float arr4[4] = {-6.78, -45.213, -7.89, -3.456};
+ float arr8[5] = {0.0123, 5.678, 2.345, 0.345, 8.956};
+ float arr0[5] = {2344.98, 345.24, 456.12, 98.33, 144.67};
+ float arr1[6] = {1.234, 4.5, 6.8987, 3.33, 5.66, 77.695};
+ float arr43[6] = {2.3454, -0.0384, -8.90, 3.455, 6.785, 21.345};
+ float arr5[5] = {0.2, -0.4, 0.6, -0.8, 1.0};
+
+ vect<float, 5> v1(arr0);
+ vect<float, 5> v2(arr8);
+ vect<float, 4> v10(arr3);
+ vect<float, 4> v12(arr4);
+ vect<float, 6> v15(arr1);
+ vect<float, 6> v20(arr43);
+ vect<float, 3> v21(arr2);
+ vect<float, 3> v22(arr15);
+ vect<float, 5> v31(arr0);
+ vect<float, 3> v3;
+ vect<float, 2> vn;
+ vect<float, 4> v61(arr4);
+ vect<float, 3> v6;
+ vect<float, 4> vm;
+ vect<float, 5> v13;
+ vect<float, 6> v95;
+ vect<float, 5> v35(arr5);
+ vect<float, 5> vl;
+ vect<float, 4> vp;
+ vect<float, 4> vr(arr4);
+ vect<float, 3> vf;
float arr57[3][3] = {{2.24, 0.5, 0.023}, {3.675, 5.32, 0.556}, {1.023, 45.75, 621.6}};
- matrix<float,3 ,3> m12(arr57);
+ matrix<float, 3, 3> m12(arr57);
float arr67[3][1] = {{2.0}, {3.0}, {4.0}};
- matrix<float,3,1> m32(arr67);
+ matrix<float, 3, 1> m32(arr67);
- cout<< "Constructor Test\n";
- cout<< "\n" << v3;
+ cout << "Constructor Test\n";
+ cout << "\n" << v3;
- cout<< "\n\nAddition\n";
+ cout << "\n\nAddition\n";
v3 = v21 + v22;
v95 = v15 + v20;
- cout<< "\n\nNumbers added\n";
- cout<< "\n" << v21 << "\n" << v22;
- cout<< "\nSum:\n" << v3 << endl;
- cout<< "\n\nNumbers added\n";
- cout<< "\n" << v15 << "\n" << v20;
- cout<< "\nSum:\n" << v95 << endl;
+ cout << "\n\nNumbers added\n";
+ cout << "\n" << v21 << "\n" << v22;
+ cout << "\nSum:\n" << v3 << endl;
+ cout << "\n\nNumbers added\n";
+ cout << "\n" << v15 << "\n" << v20;
+ cout << "\nSum:\n" << v95 << endl;
float num = 5.5650;
float num1 = -2.32;
- cout<< "\n\n\nScalar addition\n";
+ cout << "\n\n\nScalar addition\n";
vl = v2 + num;
vm = v10 + num1;
- cout<< "\nNumber added:" << num;
- cout<< "\n\n" << v2;
- cout<< "\nResult:\n\n" << vl;
- cout<< "\nNumber added:"<< num1;
- cout<< "\n\n" << v10;
- cout<< "\nResult:\n\n"<< vm;
-
- cout<< "\n\n\nSubtraction\n";
+ cout << "\nNumber added:" << num;
+ cout << "\n\n" << v2;
+ cout << "\nResult:\n\n" << vl;
+ cout << "\nNumber added:" << num1;
+ cout << "\n\n" << v10;
+ cout << "\nResult:\n\n" << vm;
+
+ cout << "\n\n\nSubtraction\n";
vp = v10 - v12;
- cout<< "\n" << v10 << "\n" << v12;
- cout<< "\nDifference:\n" << vp << endl;
+ cout << "\n" << v10 << "\n" << v12;
+ cout << "\nDifference:\n" << vp << endl;
float x = 4.0;
float x1 = -2.5;
- cout<< "\n\n\nScalar subtraction\n";
+ cout << "\n\n\nScalar subtraction\n";
v13 = v1 - x;
vp = v10 - x1;
- cout<< "\nNumber Subtracted:" << x;
- cout<< "\n\n" << v1;
- cout<< "\nResult:\n\n" << v13;
- cout<< "\nNumber Subtracted:" << x1;
- cout<< "\n\n" << v10;
- cout<< "\nResult:\n\n" << vp;
+ cout << "\nNumber Subtracted:" << x;
+ cout << "\n\n" << v1;
+ cout << "\nResult:\n\n" << v13;
+ cout << "\nNumber Subtracted:" << x1;
+ cout << "\n\n" << v10;
+ cout << "\nResult:\n\n" << vp;
float xx = 7.2;
- cout<<"\n\n\nMultiplication\n";
+ cout << "\n\n\nMultiplication\n";
v13 = v2 * xx;
- cout<< "\n" << v2 <<"\n"<< xx;
- cout<< "\nProduct:\n" << v13 << endl;
+ cout << "\n" << v2 << "\n" << xx;
+ cout << "\nProduct:\n" << v13 << endl;
- cout<< "\n\n\nMultiplication matrix x vector:\n";
- matrix<float,3,3> m102 = m32 * v22;
- cout<< "\n" << m32 <<"\n"<< v22;
- cout<< "\nProduct:\n"<< m102 << endl;
+ cout << "\n\n\nMultiplication matrix x vector:\n";
+ matrix<float, 3, 3> m102 = m32 * v22;
+ cout << "\n" << m32 << "\n" << v22;
+ cout << "\nProduct:\n" << m102 << endl;
- cout<< "\n\n\nVector x Multiplication matrix:\n";
- vect<float,3> v102 = (v22 * m12);
- cout<< "\n" << v22 << "\n" << m12;
- cout<< "\nProduct:\n" << v102 << endl;
+ cout << "\n\n\nVector x Multiplication matrix:\n";
+ vect<float, 3> v102 = (v22 * m12);
+ cout << "\n" << v22 << "\n" << m12;
+ cout << "\nProduct:\n" << v102 << endl;
float z = 3.50;
float z1 = -5.567;
- cout<< "\n\n\nScalar multiplication\n";
+ cout << "\n\n\nScalar multiplication\n";
v13 = v1 * z;
v61 = v12 * z1;
- cout<< "\nNumber Multiplied:" << z;
- cout<< "\n\n" << v1;
- cout<< "\nResult:\n\n" << v13;
- cout<< "\nNumber Multiplied:" << z1;
- cout<< "\n\n" << v12;
- cout<< "\nResult:\n\n" << v6;
+ cout << "\nNumber Multiplied:" << z;
+ cout << "\n\n" << v1;
+ cout << "\nResult:\n\n" << v13;
+ cout << "\nNumber Multiplied:" << z1;
+ cout << "\n\n" << v12;
+ cout << "\nResult:\n\n" << v6;
float num2 = 5.5;
- cout<< "\n\n\nDivision\n";
+ cout << "\n\n\nDivision\n";
v31 = v1 / num2;
- cout<< "\n" << v1 << "\n" << num2;
- cout<< "\nResult:\n" << v3 << endl;
+ cout << "\n" << v1 << "\n" << num2;
+ cout << "\nResult:\n" << v3 << endl;
- cout<< "\n\n\nTranspose:";
+ cout << "\n\n\nTranspose:";
cout << "\n\n" << v20;
cout << "\nResult:\n\n";
- matrix<float,6,1> m101 = transpose(v20);
+ matrix<float, 6, 1> m101 = transpose(v20);
cout << m101;
cout << "\n\n" << m101;
cout << "\nResult:\n\n";
cout << "\n\n\nv15 != v15 :";
cout << (v15 != v15);
- cout<< "\n\nAssignment\n";
+ cout << "\n\nAssignment\n";
v3 = vf;
- cout<< "Input \n" << v1;
- cout<< "\nOutput:\n" << v3 << endl;
+ cout << "Input \n" << v1;
+ cout << "\nOutput:\n" << v3 << endl;
- vect<float,3> v111 = cross(v21, v22);
- cout<< "\n\n\nCross Product:";
+ vect<float, 3> v111 = cross(v21, v22);
+ cout << "\n\n\nCross Product:";
cout << "\n\n" << v21 << "\n\n" << v22;
cout << "\nResult:\n\n" << v111;
float val = dot(v21, v22);
- cout<< "\n\n\nDot Product:";
+ cout << "\n\n\nDot Product:";
cout << "\n\n" << v21 << "\n\n" << v22;
cout << "\nResult:\n\n" << val;
TYPE_SIZE vect<TYPE, SIZE>::vect(TYPE vec_data[SIZE])
{
-
for (int j = 0; j < SIZE; j++)
m_vec[j] = vec_data[j];
}
assert(R == S);
assert(C == 1);
- matrix<T,R,S> m1;
+ matrix<T, R, S> m1;
for (int i = 0; i < R; i++)
for (int j = 0; j < S; j++)
{
assert(R == S);
assert(C != 1);
- vect<T,C> v1;
+ vect<T, C> v1;
for (int j = 0; j < C; j++)
{
T_S1_S2 bool operator ==(const vect<T, S1> v1, const vect<T, S2> v2)
{
- if (S1==S2)
+ if (S1 == S2)
{
for (int i = 0; i < S1; i++)
if (v1.m_vec[i] != v2.m_vec[i])
T_S friend ostream& operator << (ostream& dout, vect<T, S>& v);
T_S friend vect<T, S> operator +(const vect<T, S> v1, const vect<T, S> v2);
T_S friend vect<T, S> operator +(const vect<T, S> v, const T val);
- T_S friend vect<T, S> operator -(const vect<T,S> v1, const vect<T,S> v2);
- T_S friend vect<T, S> operator -(const vect<T,S> v, const T val);
+ T_S friend vect<T, S> operator -(const vect<T, S> v1, const vect<T, S> v2);
+ T_S friend vect<T, S> operator -(const vect<T, S> v, const T val);
T_S_R_C friend matrix<T, R, S> operator *(const matrix<T, R, C> v1, const vect<T, S> v2);
T_S_R_C friend vect<T, S> operator *(const vect<T, S> v, const matrix<T, R, C> m);
T_S friend vect<T, S> operator *(const vect<T, S> v, const T val);
- T_S friend vect<T, S> operator /(const vect<T,S> v1, const T val);
+ T_S friend vect<T, S> operator /(const vect<T, S> v1, const T val);
T_S1_S2 friend bool operator ==(const vect<T, S1> v1, const vect<T, S2> v2);
T_S1_S2 friend bool operator !=(const vect<T, S1> v1, const vect<T, S2> v2);
#define ELEMENT_PITCH_ROTATION_COMPENSATION "PITCH_ROTATION_COMPENSATION"
#define ELEMENT_ROLL_ROTATION_COMPENSATION "ROLL_ROTATION_COMPENSATION"
-
-
tilt_sensor::tilt_sensor()
: m_accel_sensor(NULL)
, m_fusion_sensor(NULL)
_I("m_roll_rotation_compensation = %d", m_roll_rotation_compensation);
m_interval = m_default_sampling_time * MS_TO_US;
-
}
tilt_sensor::~tilt_sensor()
unsigned long long diff_time;
if (event.event_type == FUSION_EVENT) {
-
diff_time = event.data.timestamp - m_time;
if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR))
if(m_raw_data_unit == "DEGREES") {
properties.min_range = -180;
properties.max_range = 180;
- }
- else {
+ } else {
properties.min_range = -PI;
properties.max_range = PI;
}
client_info_manager::client_info_manager()
{
}
+
client_info_manager::~client_info_manager()
{
m_clients.clear();
return true;
}
-
bool client_info_manager::register_event(int client_id, sensor_id_t sensor_id, unsigned int event_type)
{
AUTOLOCK(m_mutex);
return true;
}
-
bool client_info_manager::set_start(int client_id, sensor_id_t sensor_id, bool start)
{
AUTOLOCK(m_mutex);
return false;
return true;
-
}
bool client_info_manager::is_started(int client_id, sensor_id_t sensor_id)
client_record.set_client_id(client_id);
- m_clients.insert(pair<int,client_sensor_record> (client_id, client_record));
+ m_clients.insert(pair<int, client_sensor_record> (client_id, client_record));
return client_id;
}
-
bool client_info_manager::remove_client_record(int client_id)
{
AUTOLOCK(m_mutex);
return true;
}
-
bool client_info_manager::has_client_record(int client_id)
{
AUTOLOCK(m_mutex);
return (it_record != m_clients.end());
}
-
void client_info_manager::set_client_info(int client_id, pid_t pid, const string &name)
{
AUTOLOCK(m_mutex);
return true;
}
-
bool client_info_manager::has_sensor_record(int client_id, sensor_id_t sensor_id)
{
AUTOLOCK(m_mutex);
bool client_info_manager::set_event_socket(int client_id, const csocket &socket)
{
-
AUTOLOCK(m_mutex);
auto it_record = m_clients.find(client_id);
#include <cmutex.h>
#include <vector>
-typedef std::unordered_map<int,client_sensor_record> client_id_sensor_record_map;
+typedef std::unordered_map<int, client_sensor_record> client_id_sensor_record_map;
typedef std::vector<int> client_id_vec;
class client_info_manager {
, m_pid(-1)
, m_permission(SENSOR_PERMISSION_NONE)
{
-
}
client_sensor_record::~client_sensor_record()
if (it_usage == m_sensor_usages.end()) {
sensor_usage usage;
usage.register_event(event_type);
- m_sensor_usages.insert(pair<sensor_id_t,sensor_usage>(sensor_id, usage));
+ m_sensor_usages.insert(pair<sensor_id_t, sensor_usage>(sensor_id, usage));
return true;
}
return true;
}
-
bool client_sensor_record::set_start(sensor_id_t sensor_id, bool start)
{
auto it_usage = m_sensor_usages.find(sensor_id);
}
sensor_usage usage;
- m_sensor_usages.insert(pair<sensor_id_t,sensor_usage> (sensor_id, usage));
+ m_sensor_usages.insert(pair<sensor_id_t, sensor_usage>(sensor_id, usage));
return true;
}
return true;
}
-
bool client_sensor_record::has_sensor_usage(sensor_id_t sensor_id)
{
auto it_usage = m_sensor_usages.find(sensor_id);
return true;
}
-
bool client_sensor_record::get_registered_events(sensor_id_t sensor_id, event_type_vector &event_vec)
{
auto it_usage = m_sensor_usages.find(sensor_id);
copy(it_usage->second.m_reg_events.begin(), it_usage->second.m_reg_events.end(), back_inserter(event_vec));
return true;
-
}
void client_sensor_record::set_client_id(int client_id)
return m_permission;
}
-
void client_sensor_record::set_event_socket(const csocket &socket)
{
m_event_socket = socket;
socket = m_event_socket;
}
-
bool client_sensor_record::close_event_socket(void)
{
return m_event_socket.close();
m_socket.close();
}
-
bool command_worker::start(void)
{
return m_worker.start();
}
if (header.size > 0) {
-
payload = new(std::nothrow) char[header.size];
retvm_if(!payload, false, "Failed to allocate memory");
return ret;
}
-
bool command_worker::stopped(void *ctx)
{
string info;
delete ret_packet;
return true;
-
}
-
bool command_worker::send_cmd_get_id_done(int client_id)
{
cpacket* ret_packet;
return true;
}
-
bool command_worker::send_cmd_get_sensor_list_done(void)
{
cpacket sensor_list;
return true;
}
-
bool command_worker::cmd_get_sensor_list(void *payload)
{
_D("CMD_GET_SENSOR_LIST Handler invoked\n");
return false;
}
-
client_info_manager& command_worker::get_client_info_manager(void)
{
return client_info_manager::get_instance();
virtual ~command_worker();
bool start(void);
-
};
#endif /* _COMMAND_WORKER_H_ */
device_config::device_config(void)
{
-
}
device_config::~device_config(void)
{
-
}
bool device_config::get_device_id(void)
{
}
-sensor_event_dispatcher::~sensor_event_dispatcher() { }
-
+sensor_event_dispatcher::~sensor_event_dispatcher()
+{
+}
sensor_event_dispatcher& sensor_event_dispatcher::get_instance()
{
}
}
-
void sensor_event_dispatcher::send_sensor_events(vector<void *> &events)
{
sensor_event_t *sensor_event = NULL;
return (it_v_sensor != m_active_virtual_sensors.end());
}
-
virtual_sensors sensor_event_dispatcher::get_active_virtual_sensors(void)
{
AUTOLOCK(m_active_virtual_sensors_mutex);
if (m_queue.size() >= QUEUE_FULL_SIZE) {
_E("Queue is full, drop it!");
free(event);
- } else
+ } else {
m_queue.push(event);
+ }
if (wake)
m_cond_var.notify_one();
sensor_fusion::sensor_fusion()
{
-
}
sensor_fusion::~sensor_fusion()
{
-
}
bool sensor_fusion::is_fusion(void)
FUSION_EVENT_AGM = (FUSION_SENSOR << 16) | 0x0004,
};
-typedef std::array<std::array<float,3> ,3> arr33_t;
+typedef std::array<std::array<float, 3>, 3> arr33_t;
class sensor_fusion : public sensor_base {
public:
virtual bool get_orientation(float &azimuth, float &pitch, float &roll, int &accuracy);
};
-#endif
+#endif /* _SENSOR_FUSION_H_ */
std::list<interval_info> m_interval_info_list;
std::list<batch_info> m_batch_info_list;
};
+
#endif /* _SENSOR_INFO_LIST_H_ */
std::vector<sensor_base *> get_sensors(sensor_type_t type);
std::vector<sensor_base *> get_virtual_sensors(void);
};
+
#endif /* _SENSOR_LOADER_H_ */
, m_option(SENSOR_OPTION_DEFAULT)
, m_start(false)
{
-
}
+
sensor_usage::~sensor_usage()
{
m_reg_events.clear();
auto it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type);
if (it_event == m_reg_events.end()) {
- _E("Event[%#x] is not found",event_type);
+ _E("Event[%#x] is not found", event_type);
return false;
}
bool sensor_usage::is_event_registered(unsigned int event_type)
{
- auto it_event = find (m_reg_events.begin(), m_reg_events.end(), event_type);
+ auto it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type);
if (it_event == m_reg_events.end()){
- _D("Event[%#x] is not registered",event_type);
+ _D("Event[%#x] is not registered", event_type);
return false;
}
server::server()
: m_mainloop(NULL)
{
-
}
server::~server()
#include <virtual_sensor.h>
#include <sensor_event_dispatcher.h>
-
virtual_sensor::virtual_sensor()
{
-
}
virtual_sensor::~virtual_sensor()
{
-
}
bool virtual_sensor::init(void)
xmlDocPtr doc;
xmlNodePtr cur;
- _D("virtual_sensor_config::load_config(\"%s\") is called!\n",config_path.c_str());
+ _D("virtual_sensor_config::load_config(\"%s\") is called!\n", config_path.c_str());
doc = xmlParseFile(config_path.c_str());
if (doc == NULL) {
- _E("There is no %s\n",config_path.c_str());
+ _E("There is no %s\n", config_path.c_str());
return false;
}
cur = xmlDocGetRootElement(doc);
if(cur == NULL) {
- _E("There is no root element in %s\n",config_path.c_str());
+ _E("There is no root element in %s\n", config_path.c_str());
xmlFreeDoc(doc);
return false;
}
if(xmlStrcmp(cur->name, (const xmlChar *)ROOT_ELEMENT)) {
- _E("Wrong type document: there is no [%s] root element in %s\n",ROOT_ELEMENT,config_path.c_str());
+ _E("Wrong type document: there is no [%s] root element in %s\n", ROOT_ELEMENT, config_path.c_str());
xmlFreeDoc(doc);
return false;
}
device_node_ptr = cur->xmlChildrenNode;
while (device_node_ptr != NULL){
//skip garbage element, [text]
- if (!xmlStrcmp(device_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) {
+ if (!xmlStrcmp(device_node_ptr->name, (const xmlChar *)TEXT_ELEMENT)) {
device_node_ptr = device_node_ptr->next;
continue;
}
-
string device_type;
- prop = (char*)xmlGetProp(device_node_ptr,(const xmlChar*)DEVICE_TYPE_ATTR);
+ prop = (char*)xmlGetProp(device_node_ptr, (const xmlChar*)DEVICE_TYPE_ATTR);
device_type = prop;
free(prop);
//insert device to device_list
m_virtual_sensor_configs[device_type];
- _D("<type=\"%s\">\n",device_type.c_str());
+ _D("<type=\"%s\">\n", device_type.c_str());
virtual_sensor_node_ptr = device_node_ptr->xmlChildrenNode;
while (virtual_sensor_node_ptr != NULL) {
//skip garbage element, [text]
- if (!xmlStrcmp(virtual_sensor_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) {
+ if (!xmlStrcmp(virtual_sensor_node_ptr->name, (const xmlChar *)TEXT_ELEMENT)) {
virtual_sensor_node_ptr = virtual_sensor_node_ptr->next;
continue;
}
m_virtual_sensor_configs[device_type][(const char*)virtual_sensor_node_ptr->name];
- _D("<type=\"%s\"><%s>\n",device_type.c_str(),(const char*)virtual_sensor_node_ptr->name);
+ _D("<type=\"%s\"><%s>\n", device_type.c_str(), (const char*)virtual_sensor_node_ptr->name);
element_node_ptr = virtual_sensor_node_ptr->xmlChildrenNode;
while (element_node_ptr != NULL) {
//skip garbage element, [text]
- if (!xmlStrcmp(element_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) {
+ if (!xmlStrcmp(element_node_ptr->name, (const xmlChar *)TEXT_ELEMENT)) {
element_node_ptr = element_node_ptr->next;
continue;
}
//insert Element to Model
m_virtual_sensor_configs[device_type][(const char*)virtual_sensor_node_ptr->name][(const char*)element_node_ptr->name];
- _D("<type=\"%s\"><%s><%s>\n",device_type.c_str(),(const char*)virtual_sensor_node_ptr->name,(const char*)element_node_ptr->name);
+ _D("<type=\"%s\"><%s><%s>\n", device_type.c_str(), (const char*)virtual_sensor_node_ptr->name, (const char*)element_node_ptr->name);
attr_ptr = element_node_ptr->properties;
while (attr_ptr != NULL) {
-
- string key,value;
+ string key, value;
key = (char*)attr_ptr->name;
- prop = (char*)xmlGetProp(element_node_ptr,attr_ptr->name);
+ prop = (char*)xmlGetProp(element_node_ptr, attr_ptr->name);
value = prop;
free(prop);
//insert attribute to Element
- m_virtual_sensor_configs[device_type][(const char*)virtual_sensor_node_ptr->name][(const char*)element_node_ptr->name][key]=value;
- _D("<type=\"%s\"><%s><%s \"%s\"=\"%s\">\n",device_type.c_str(),(const char*)virtual_sensor_node_ptr->name,(const char*)element_node_ptr->name,key.c_str(),value.c_str());
+ m_virtual_sensor_configs[device_type][(const char*)virtual_sensor_node_ptr->name][(const char*)element_node_ptr->name][key] = value;
+ _D("<type=\"%s\"><%s><%s \"%s\"=\"%s\">\n", device_type.c_str(), (const char*)virtual_sensor_node_ptr->name, (const char*)element_node_ptr->name, key.c_str(), value.c_str());
attr_ptr = attr_ptr->next;
}
auto it_device_list = m_virtual_sensor_configs.find(m_device_id);
if (it_device_list == m_virtual_sensor_configs.end()) {
- _E("There is no <%s> device\n",m_device_id.c_str());
+ _E("There is no <%s> device\n", m_device_id.c_str());
m_device_id = DEFAULT_DEVICE;
it_device_list = m_virtual_sensor_configs.find(m_device_id);
auto it_virtual_sensor_list = it_device_list->second.find(sensor_type);
if (it_virtual_sensor_list == it_device_list->second.end()) {
- _E("There is no <%s> sensor\n",sensor_type.c_str());
+ _E("There is no <%s> sensor\n", sensor_type.c_str());
return false;
}
auto it_element = it_virtual_sensor_list->second.find(element);
if (it_element == it_virtual_sensor_list->second.end()) {
- _E("There is no <%s><%s> element\n",sensor_type.c_str(),element.c_str());
+ _E("There is no <%s><%s> element\n", sensor_type.c_str(), element.c_str());
return false;
}
auto it_attr = it_element->second.find(attr);
if (it_attr == it_element->second.end()) {
- _D("There is no <%s><%s \"%s\">\n",sensor_type.c_str(),element.c_str(),attr.c_str());
+ _D("There is no <%s><%s \"%s\">\n", sensor_type.c_str(), element.c_str(), attr.c_str());
return false;
}
{
string str_value;
- if (get(sensor_type,element,attr,str_value) == false)
+ if (get(sensor_type, element, attr, str_value) == false)
return false;
stringstream str_stream(str_value);
{
string str_value;
- if (get(sensor_type,element,attr,str_value) == false)
+ if (get(sensor_type, element, attr, str_value) == false)
return false;
stringstream str_stream(str_value);
bool virtual_sensor_config::get(const string& sensor_type, const string& element, float *value, int count)
{
- if (count == 1)
- {
+ if (count == 1) {
if (get(sensor_type, element, DEFAULT_ATTR, value))
return true;
}
- else if (count == 3)
- {
+
+ if (count == 3) {
if (!get(sensor_type, element, DEFAULT_ATTR1, value))
return false;
return true;
}
- else
- {
- _D("Count value not supported.\n");
- }
+
+ _D("Count value not supported.\n");
return false;
}
bool virtual_sensor_config::get(const string& sensor_type, const string& element, int *value, int count)
{
- if (count == 1)
- {
+ if (count == 1) {
if (get(sensor_type, element, DEFAULT_ATTR, value))
return true;
}
- else if (count == 3)
- {
+
+ if (count == 3) {
if (!get(sensor_type, element, DEFAULT_ATTR1, value))
return false;
return true;
}
- else
- {
- _D("Count value not supported.\n");
- }
+
+ _D("Count value not supported.\n");
return false;
}
return true;
}
-
#define VIRTUAL_SENSOR_CONFIG_FILE_PATH "/usr/etc/virtual_sensors.xml"
-typedef std::unordered_map<std::string,std::string> Element;
+typedef std::unordered_map<std::string, std::string> Element;
/*
* an Element is a group of attributes
* <Element value1 = "10.0", value2 = "20.0"/>
*
*/
-typedef std::unordered_map<std::string,Element> Virtual_sensor;
+typedef std::unordered_map<std::string, Element> Virtual_sensor;
/*
* a Virtual_sensor is a group of elements to consist of one virtual sensor's configuration
* <ORIENTATION>
* ...
*/
-typedef std::unordered_map<std::string,Virtual_sensor> virtual_sensor_configs;
+typedef std::unordered_map<std::string, Virtual_sensor> virtual_sensor_configs;
/*
* a Virtual_sensor_config represents virtual_sensors.xml
* <ORIENTATION/>
*
*/
-typedef std::unordered_map<std::string,virtual_sensor_configs> virtual_sensor_device_configs;
+typedef std::unordered_map<std::string, virtual_sensor_configs> virtual_sensor_device_configs;
/*
* a virtual_sensor_device_config represents virtual_sensors.xml
* <emulator/>
class virtual_sensor_config : public device_config {
private:
virtual_sensor_config();
- virtual_sensor_config(virtual_sensor_config const&) {};
virtual_sensor_config& operator=(virtual_sensor_config const&);
bool load_config(const std::string& config_path);
bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, int *value);
bool get(const std::string& sensor_type, const std::string& element, std::string& value);
- bool get(const std::string& sensor_type, const std::string& element, float *value, int count =1);
+ bool get(const std::string& sensor_type, const std::string& element, float *value, int count = 1);
bool get(const std::string& sensor_type, const std::string& element, int *value, int count = 1);
bool is_supported(const std::string &sensor_type);
return m_state;
}
-
bool worker_thread::start(void)
{
lock l(m_mutex);
th.detach();
}
return true;
- } else if (m_state == WORKER_STATE_PAUSED) {
+ }
+
+ if (m_state == WORKER_STATE_PAUSED) {
m_state = WORKER_STATE_WORKING;
m_cond_working.notify_one();
return true;
}
if ((m_state == WORKER_STATE_WORKING) || (m_state == WORKER_STATE_PAUSED)) {
-
if (m_state == WORKER_STATE_PAUSED)
m_cond_working.notify_one();
_E("Failed to pause, because current state(%d) is not for PAUSE", m_state);
return false;
-
}
bool worker_thread::resume(void)
return false;
}
-
/*
* After state changed to STOPPED, it should not access member fields,
because some transition funciton of STOPPED delete this pointer
*
*/
-
#ifndef _WORKER_THREAD_H_
#define _WORKER_THREAD_H_
unsigned long long lock_acquired_time = 0;
unsigned long long waiting_time = 0;
-
snprintf(m_curent_info, OWNER_INFO_LEN, "%s:%s(%d)", module, func, line);
if (type == LOCK_TYPE_MUTEX)
m_curent_info, expr, this, m_owner_info);
pthread_mutex_unlock(&m_history_mutex);
-
if (type == LOCK_TYPE_MUTEX)
lock_impl();
else if (type == LOCK_TYPE_READ)
pthread_mutex_unlock(&m_history_mutex);
}
-
void cbase_lock::lock(lock_type type)
{
if (type == LOCK_TYPE_MUTEX)
unlock_impl();
}
-
int cbase_lock::lock_impl(void)
{
return 0;
};
#ifdef _LOCK_DEBUG
-#define AUTOLOCK(x) Autolock x##_autolock((x),LOCK_TYPE_MUTEX, #x, __MODULE__, __func__, __LINE__)
-#define AUTOLOCK_R(x) Autolock x##_autolock_r((x),LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__)
-#define AUTOLOCK_W(x) Autolock x##_autolock_w((x),LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
+#define AUTOLOCK(x) Autolock x##_autolock((x), LOCK_TYPE_MUTEX, #x, __MODULE__, __func__, __LINE__)
+#define AUTOLOCK_R(x) Autolock x##_autolock_r((x), LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__)
+#define AUTOLOCK_W(x) Autolock x##_autolock_w((x), LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
#define LOCK(x) (x).lock(#x, __MODULE__, __func__, __LINE__)
#define LOCK_R(x) (x).lock(LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__)
#define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
#define UNLOCK(x) (x).unlock()
#else
-#define AUTOLOCK(x) Autolock x##_autolock((x),LOCK_TYPE_MUTEX)
-#define AUTOLOCK_R(x) Autolock x##_autolock_r((x),LOCK_TYPE_READ)
-#define AUTOLOCK_W(x) Autolock x##_autolock_w((x),LOCK_TYPE_WRITE)
+#define AUTOLOCK(x) Autolock x##_autolock((x), LOCK_TYPE_MUTEX)
+#define AUTOLOCK_R(x) Autolock x##_autolock_r((x), LOCK_TYPE_READ)
+#define AUTOLOCK_W(x) Autolock x##_autolock_w((x), LOCK_TYPE_WRITE)
#define LOCK(x) (x).lock()
#define LOCK_R(x) (x).lock(LOCK_TYPE_READ)
#define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE)
#define UNLOCK(x) (x).unlock()
#endif
-
class cbase_lock {
public:
cbase_lock();
int cmutex::try_lock_impl(void)
{
return pthread_mutex_trylock(&m_mutex);
-
}
int cmutex::unlock_impl()
typedef struct {
} cmd_byebye_t;
-
typedef struct {
unsigned int type;
} cmd_get_data_t;
long value;
} cmd_done_t;
-
typedef struct {
int client_id;
} cmd_get_id_done_t;
int option;
} cmd_set_option_t;
-
typedef struct {
int attribute;
int value;
}
m_packet = (packet_header*) new(std::nothrow) char[size + sizeof(packet_header)];
- retm_if (!m_packet, "Failed to allocate memory");
+ retm_if(!m_packet, "Failed to allocate memory");
m_packet->size = size;
if (prev_cmd != CMD_NONE)
memset(&m_addr, 0, sizeof(m_addr));
}
-
csocket::csocket(int sock_fd)
: m_sock_fd(-1)
, m_sock_type(SOCK_STREAM)
memset(&m_addr, 0, sizeof(m_addr));
}
-
csocket::csocket(const csocket &sock)
: m_sock_fd(-1)
, m_sock_type(SOCK_STREAM)
return true;
}
-bool csocket::bind (const char *sock_path)
+bool csocket::bind(const char *sock_path)
{
int length;
mode_t socket_mode;
return false;
}
- socket_mode = ( S_IRWXU | S_IRWXG | S_IRWXO );
+ socket_mode = (S_IRWXU | S_IRWXG | S_IRWXO);
if (chmod(sock_path, socket_mode) < 0) {
_ERRNO(errno, _E, "Failed to chmod for socket[%d]", m_sock_fd);
close();
return err == 0 ? len : -err;
}
-
ssize_t csocket::send_for_stream(const void *buffer, size_t size) const
{
ssize_t len;
return err == 0 ? total_recv_size : -err;
}
-
ssize_t csocket::send(const void *buffer, size_t size) const
{
if (!is_valid()) {
addr_len = strlen(m_addr.sun_path) + sizeof(m_addr.sun_family);
- if (::connect(m_sock_fd,(sockaddr *) &m_addr, addr_len) < 0) {
+ if (::connect(m_sock_fd, (sockaddr *) &m_addr, addr_len) < 0) {
_ERRNO(errno, _E, "Failed to connect sock_fd: %d for %s",
m_sock_fd, get_client_name());
return false;
return true;
}
-
bool csocket::set_sock_type(void)
{
socklen_t opt_len;
return !(flags & O_NONBLOCK);
}
-
bool csocket::is_valid(void) const
{
return (m_sock_fd >= 0);
//Server
bool create(int sock_type);
- bool bind (const char *sock_path);
+ bool bind(const char *sock_path);
bool listen(const int max_connections);
bool accept(csocket& client_socket) const;
return true;
}
-
bool poller::poll(struct epoll_event &event)
{
while (true) {
_I("Wakeup_supported = %d", m_wakeup_supported);
}
-
void sensor_info::clear(void)
{
m_type = UNKNOWN_SENSOR;
m_wakeup_supported = false;
}
-
void sensor_info::put(raw_data_t &data, int value)
{
char buffer[sizeof(value)];
#endif
#define LOG_TAG "SENSOR"
-#define LOG_DUMP(fp, fmt, arg...) do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while(0)
+#define LOG_DUMP(fp, fmt, arg...) do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while (0)
#ifdef _DEBUG
#define DBG SLOGD
#else
-#define DBG(...) do{} while(0)
+#define DBG(...) do {} while (0)
#endif
#define ERR SLOGE
#include <string.h>
#include "check-sensor.h"
-
-
void printpollinglogs(sensor_type_t type,sensor_data_t data)
{
switch(type) {
handle = sensord_connect(sensor);
result = sensord_start(handle, 1);
-
if (!result) {
printf("Can't start the sensor\n");
printf("Error\n\n\n\n");
sensor_data_t data;
- while(1) {
+ while (1) {
result = sensord_get_data(handle, event, &data);
printpollinglogs(sensor_type, data);
usleep(100000);
#include <pthread.h>
#include "check-sensor.h"
-
void usage()
{
printf("Usage : ./multi-sensor <TIMEOUT> <interval>(optional)\n\n");
}
}
-
int MAX = 6, j = 0, k = 0;
struct pthread_arguments arg[MAX];
int t = 0;
arg[5].sensor_type = LIGHT_SENSOR;
arg[5].event = LIGHT_LUX_DATA_EVENT;
- for(t = 0; t < MAX; t++)
- {
+ for (t = 0; t < MAX; t++)
arg[t].interval = interval;
- }
pthread_t thread_id[MAX];
- for(j = 0; j < MAX; j++)
- {
+ for (j = 0; j < MAX; j++)
pthread_create(&thread_id[j], NULL, check_sensor, (void*)&arg[j]);
- }
sleep(TIMEOUT);
return 0;