sensor: added pressure, ultraviolet, and hrm sensor devices
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Thu, 23 Oct 2014 07:57:15 +0000 (16:57 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Fri, 24 Oct 2014 04:56:56 +0000 (13:56 +0900)
- new log format is applied.

Change-Id: I5009031a8d3de8d8a51cc1c9cc2e2fe7ac47e5ae
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
tizen/src/ecs/ecs.h
tizen/src/ecs/ecs_msg.c
tizen/src/ecs/ecs_msg_device.c
tizen/src/ecs/ecs_sensor.c
tizen/src/hw/virtio/maru_virtio_sensor.c
tizen/src/hw/virtio/maru_virtio_sensor.h

index b3438456ae98800c9c374eef24b3e365b4175e6f..b11ca92d1be1c0e00bfcc4cc848c74a27d5f083c 100644 (file)
@@ -80,6 +80,9 @@ enum message_action {
     MSG_ACT_LIGHT = 113,
     MSG_ACT_PROXI = 114,
     MSG_ACT_MOTION = 115,
+    MSG_ACT_PRESSURE = 116,
+    MSG_ACT_UV = 117,
+    MSG_ACT_HRM = 118,
     MSG_ACT_LOCATION = 120
 };
 
@@ -94,7 +97,10 @@ enum injector_level {
     level_geo = 5,
     level_battery = 8,
     level_tilt = 12,
-    level_magnetic = 13
+    level_magnetic = 13,
+    level_pressure = 20,
+    level_uv = 21,
+    level_hrm = 22,
 };
 
 #define MAX_CATEGORY_LEN        10
index 3ad09b30dafcce75e371f0318bd8a51da0f26440..fd529e951eade75a794b9cf59be1159f97c38eb4 100644 (file)
 #include <stdbool.h>
 #include <glib.h>
 
-#ifdef CONFIG_LINUX
-#include <sys/epoll.h>
-#endif
-
 #include "hw/qdev.h"
 #include "net/net.h"
 #include "net/slirp.h"
 #include "qemu/queue.h"
 #include "sysemu/char.h"
 #include "qemu/main-loop.h"
+
+#ifdef CONFIG_LINUX
+#include <sys/epoll.h>
+#endif
+
+#ifndef CONFIG_WIN32
+#include <arpa/inet.h>
+#endif
+
 #include "qemu-common.h"
-#include "util/sdb.h"
 #include "ecs-json-streamer.h"
 #include "qmp-commands.h"
 
index d2a73024de905eb762a314178b39edbd0cddb17c..392285159e477377eb6031cfe3009ead31b923d8 100644 (file)
@@ -56,7 +56,7 @@ static void msgproc_device_ans(ECS_Client* ccli, const char* category, bool succ
     ECS__Master master = ECS__MASTER__INIT;
     ECS__DeviceAns ans = ECS__DEVICE_ANS__INIT;
 
-    TRACE("device ans - category : %s, succed : %d\n", category, succeed);
+    LOG_TRACE("device ans - category : %s, succed : %d\n", category, succeed);
 
     catlen = strlen(category);
     ans.category = (char*) g_malloc0(catlen + 1);
@@ -72,7 +72,7 @@ static void msgproc_device_ans(ECS_Client* ccli, const char* category, bool succ
             ans.data.data = g_malloc(ans.length);
             ans.data.len = ans.length;
             memcpy(ans.data.data, data, ans.length);
-            TRACE("data = %s, length = %hu\n", data, ans.length);
+            LOG_TRACE("data = %s, length = %hu\n", data, ans.length);
         }
     }
 
@@ -107,7 +107,7 @@ void send_target_image_information(ECS_Client* ccli) {
         ans.data.len = length;
         memcpy(ans.data.data, tizen_target_img_path, length);
 
-        TRACE("data = %s, length = %hu\n", tizen_target_img_path, length);
+        LOG_TRACE("data = %s, length = %hu\n", tizen_target_img_path, length);
     }
 
     master.type = ECS__MASTER__TYPE__DEVICE_ANS;
@@ -146,12 +146,18 @@ static void msgproc_device_req_sensor(ECS_Client* ccli, ECS__DeviceReq* msg, cha
             get_sensor_light();
         } else if (action == MSG_ACT_PROXI) {
             get_sensor_proxi();
+        } else if (action == MSG_ACT_PRESSURE) {
+            get_sensor_pressure();
+        } else if (action == MSG_ACT_UV) {
+            get_sensor_uv();
+        } else if (action == MSG_ACT_HRM) {
+            get_sensor_hrm();
         }
     } else {
         if (data != NULL) {
             set_injector_data(data);
         } else {
-            ERR("sensor set data is null\n");
+            LOG_SEVERE("sensor set data is null\n");
         }
     }
     msgproc_device_ans(ccli, cmd, true, NULL);
@@ -172,14 +178,14 @@ static void msgproc_device_req_network(ECS_Client* ccli, ECS__DeviceReq* msg)
     }
 
     if (data != NULL) {
-        TRACE(">>> Network msg: '%s'\n", data);
+        LOG_TRACE(">>> Network msg: '%s'\n", data);
         if(net_slirp_redir(data) < 0) {
-            ERR( "redirect [%s] fail\n", data);
+            LOG_SEVERE( "redirect [%s] fail\n", data);
         } else {
-            TRACE("redirect [%s] success\n", data);
+            LOG_TRACE("redirect [%s] success\n", data);
         }
     } else {
-        ERR("Network redirection data is null.\n");
+        LOG_SEVERE("Network redirection data is null.\n");
     }
 
     if (data) {
@@ -208,11 +214,11 @@ static void msgproc_device_req_tgesture(ECS_Client* ccli, ECS__DeviceReq* msg)
 #endif
 
     if (data == NULL) {
-        ERR("touch gesture data is NULL\n");
+        LOG_SEVERE("touch gesture data is NULL\n");
         return;
     }
 
-    TRACE("%s\n", data);
+    LOG_TRACE("%s\n", data);
 
     char token[] = "#";
 
@@ -258,10 +264,10 @@ static void msgproc_device_req_input(ECS_Client* ccli, ECS__DeviceReq* msg, char
     }
 
     // cli input
-    TRACE("receive input message [%s]\n", data);
+    LOG_TRACE("receive input message [%s]\n", data);
 
     if (group == 0) {
-        TRACE("input keycode data : [%s]\n", data);
+        LOG_TRACE("input keycode data : [%s]\n", data);
 
         char token[] = " ";
         char *section = strtok(data, token);
@@ -275,13 +281,13 @@ static void msgproc_device_req_input(ECS_Client* ccli, ECS__DeviceReq* msg, char
             do_hw_key_event(KEY_RELEASED, keycode);
 
         } else {
-            ERR("unknown action : [%d]\n", (int)action);
+            LOG_SEVERE("unknown action : [%d]\n", (int)action);
         }
     } else if (group == 1) {
         //spec out
-        TRACE("input category's group 1 is spec out\n");
+        LOG_TRACE("input category's group 1 is spec out\n");
     } else {
-        ERR("unknown group [%d]\n", (int)group);
+        LOG_SEVERE("unknown group [%d]\n", (int)group);
     }
     msgproc_device_ans(ccli, cmd, true, NULL);
 
@@ -307,7 +313,7 @@ static void msgproc_device_req_nfc(ECS_Client* ccli, ECS__DeviceReq* msg)
         if (data != NULL) {
             send_to_nfc(ccli->client_id, ccli->client_type, data, msg->data.len);
         } else {
-            ERR("nfc data is null\n");
+            LOG_SEVERE("nfc data is null\n");
         }
     }
 
@@ -330,7 +336,7 @@ static void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char *
         memcpy(data, msg->data.data, msg->data.len);
     }
 
-    INFO("hds group: %d, action : %d\n", group, action);
+    LOG_INFO("hds group: %d, action : %d\n", group, action);
     if (group == MSG_GROUP_STATUS) {
         char hds_data_send[PATH_MAX + 3];
         if (is_hds_attached()) {
@@ -340,27 +346,27 @@ static void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char *
         }
         make_send_device_ntf(cmd, group, 99, hds_data_send);
     } else if (group == 100 && action == 1) {
-        INFO("try attach with is_hds_attached : %d\n", is_hds_attached());
+        LOG_INFO("try attach with is_hds_attached : %d\n", is_hds_attached());
         if (data != NULL && !is_hds_attached()) {
             LOG_INFO("do attach : %s\n", hds_path);
             memset(hds_path, 0, sizeof(hds_path));
             memcpy(hds_path, data, sizeof(hds_path) - 1);
             do_hotplug(ATTACH_HDS, hds_path, strlen(hds_path) + 1);
-            INFO("send emuld to mount.\n");
+            LOG_INFO("send emuld to mount.\n");
             send_msg_to_guest(ccli, cmd, group, action, data, strlen(data));
         } else {
             make_send_device_ntf(cmd, 100, 2, NULL);
         }
     } else if (group == 100 && action == 2) {
-        INFO("try detach with is_hds_attached : %d\n", is_hds_attached());
+        LOG_INFO("try detach with is_hds_attached : %d\n", is_hds_attached());
         if (is_hds_attached()) {
-            INFO("send emuld to umount.\n");
+            LOG_INFO("send emuld to umount.\n");
             send_msg_to_guest(ccli, cmd, group, action, NULL, 0);
         } else {
-            INFO("hds is not attached. do not try detach it.\n");
+            LOG_INFO("hds is not attached. do not try detach it.\n");
         }
     } else {
-        ERR("hds unknown command: group %d action %d\n", group, action);
+        LOG_SEVERE("hds unknown command: group %d action %d\n", group, action);
     }
 
     if (data) {
@@ -374,7 +380,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
     memset(cmd, 0, 10);
     strcpy(cmd, msg->category);
 
-    TRACE(">> device_req: header = cmd = %s, length = %d, action=%d, group=%d\n",
+    LOG_TRACE(">> device_req: header = cmd = %s, length = %d, action=%d, group=%d\n",
             cmd, msg->length, msg->action, msg->group);
 
     if (!strcmp(cmd, MSG_TYPE_SENSOR)) {
@@ -385,7 +391,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
         msgproc_device_req_tgesture(ccli, msg);
     } else if (!strcmp(cmd, "info")) {
         // check to emulator target image path
-        TRACE("receive info message %s\n", tizen_target_img_path);
+        LOG_TRACE("receive info message %s\n", tizen_target_img_path);
         send_target_image_information(ccli);
     } else if (!strcmp(cmd, "hds")) {
         msgproc_device_req_hds(ccli, msg, cmd);
@@ -397,7 +403,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
     } else if (!strcmp(cmd, "nfc")) {
         msgproc_device_req_nfc(ccli, msg);
     } else {
-        ERR("unknown cmd [%s]\n", cmd);
+        LOG_SEVERE("unknown cmd [%s]\n", cmd);
     }
 
     return true;
@@ -420,7 +426,7 @@ bool send_device_ntf(const char* data, const int len)
 
     const char* ijdata = (data + catsize + 2 + 1 + 1);
 
-    TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group);
+    LOG_TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group);
 
     ECS__Master master = ECS__MASTER__INIT;
     ECS__DeviceNtf ntf = ECS__DEVICE_NTF__INIT;
@@ -441,7 +447,7 @@ bool send_device_ntf(const char* data, const int len)
         ntf.data.len = length;
         memcpy(ntf.data.data, ijdata, length);
 
-        TRACE("data = %s, length = %hu\n", ijdata, length);
+        LOG_TRACE("data = %s, length = %hu\n", ijdata, length);
     }
 
     master.type = ECS__MASTER__TYPE__DEVICE_NTF;
index 550637eaf0b17bd3eef47c90ad4b9e5b37379f54..dbe0023275a6e4a6aab036d7ad8893c5951cfb12 100644 (file)
 #include "hw/virtio/maru_virtio_power.h"
 #include "hw/virtio/maru_virtio_jack.h"
 
+#include "debug_ch.h"
+
+MULTI_DEBUG_CHANNEL(qemu, ecs);
+
 #define TEMP_BUF_SIZE   255
 #define MAX_VAL_LENGTH  40
 
@@ -69,7 +73,7 @@ static int get_parse_val (const char* buf, char* tmp)
 {
     int index = 0;
 
-    memset(tmp, 0, sizeof(TEMP_BUF_SIZE));
+    memset(tmp, 0, strlen(tmp));
 
     index = parse_val(buf, 0x0a, tmp);
     tmp[index - 1] = 0;
@@ -124,9 +128,9 @@ static void _req_set_sensor_accel(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     z = _accel_min_max(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
-    sprintf(tmp, "%d, %d, %d", x, y, z);
+    sprintf(tmp, "%d,%d,%d", x, y, z);
 
     set_sensor_accel(tmp, strlen(tmp));
 }
@@ -164,6 +168,82 @@ static void _req_set_sensor_light(int len, const char* data)
     }
 }
 
+static void _req_set_sensor_pressure(int len, const char* data)
+{
+    char tmp[TEMP_BUF_SIZE];
+    int pressure, temperature;
+
+    // get sensor level
+    len += get_parse_val(data + len, tmp);
+
+    // pressure
+    len += get_parse_val(data + len, tmp);
+    pressure = atoi(tmp);
+
+    // temperature
+    len += get_parse_val(data + len, tmp);
+    temperature = atoi(tmp);
+
+    memset(tmp, 0, sizeof(tmp));
+
+    sprintf(tmp, "%d, %d", pressure, temperature);
+
+    set_sensor_pressure(tmp, strlen(tmp));
+}
+
+static void _req_set_sensor_uv(int len, const char* data)
+{
+    char tmp[TEMP_BUF_SIZE];
+
+    // get sensor level
+    len += get_parse_val(data + len, tmp);
+
+    // value
+    len += get_parse_val(data + len, tmp);
+
+    set_sensor_uv(tmp, strlen(tmp));
+}
+
+static void _req_set_sensor_hrm(int len, const char* data)
+{
+    char tmp[TEMP_BUF_SIZE];
+    int hrm, rri, index;
+
+    // get sensor level
+    len += get_parse_val(data + len, tmp);
+
+    // get index
+    len += get_parse_val(data + len, tmp);
+    index = atoi(tmp);
+
+    if (index == 1 || index == 0) {
+        // heart rate
+        len += get_parse_val(data + len, tmp);
+        hrm = atoi(tmp);
+    }
+
+    if (index == 2 || index == 0) {
+        // RRI
+        len += get_parse_val(data + len, tmp);
+        rri = atoi(tmp);
+    }
+
+    memset(tmp, 0, sizeof(tmp));
+
+    if (index == 0) {
+        sprintf(tmp, "%d, %d", hrm, rri);
+        set_sensor_hrm(tmp, strlen(tmp));
+    } else if (index == 1) {
+        sprintf(tmp, "%d", hrm);
+        set_sensor_hrm_heart(tmp, strlen(tmp));
+    } else if (index == 2) {
+        sprintf(tmp, "%d", rri);
+        set_sensor_hrm_rri(tmp, strlen(tmp));
+    } else {
+        LOG_SEVERE("unknown index with data '%s' & index '%d'\n", data, index);
+    }
+}
+
 static void _req_set_sensor_gyro(int len, const char* data)
 {
     char tmp[TEMP_BUF_SIZE];
@@ -184,7 +264,7 @@ static void _req_set_sensor_gyro(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     z = (int)atoi(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
     sprintf(tmp, "%d %d %d", x, y, z);
 
@@ -214,7 +294,7 @@ static void _req_set_sensor_geo(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     accuracy = atoi(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
     sprintf(tmp, "%d %d %d %d", x, y, z, accuracy);
 
@@ -232,7 +312,7 @@ static void _req_set_sensor_geo(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     t_vertical = atoi(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
     sprintf(tmp, "%d %d %d", t_north, t_east, t_vertical);
 
@@ -259,7 +339,7 @@ static void _req_set_sensor_tilt(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     z = atoi(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
     sprintf(tmp, "%d %d %d %d", x, y, z, accuracy);
 
@@ -286,7 +366,7 @@ static void _req_set_sensor_mag(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     z = atoi(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
     sprintf(tmp, "%d %d %d", x, y, z);
 
@@ -356,6 +436,15 @@ void set_injector_data(const char* data)
         case level_magnetic:
             _req_set_sensor_mag(len, data);
             break;
+        case level_pressure:
+            _req_set_sensor_pressure(len, data);
+            break;
+        case level_uv:
+            _req_set_sensor_uv(len, data);
+            break;
+        case level_hrm:
+            _req_set_sensor_hrm(len, data);
+            break;
         default:
             break;
     }
index 6efedac8488845a335df38f698ca3ff123eb8317..3d9bd472f0d8f3acc5d5bfa198cb9f44cfbed827 100644 (file)
@@ -46,6 +46,9 @@ static QemuMutex gyro_mutex;
 static QemuMutex light_mutex;
 static QemuMutex proxi_mutex;
 static QemuMutex rot_mutex;
+static QemuMutex pressure_mutex;
+static QemuMutex uv_mutex;
+static QemuMutex hrm_mutex;
 
 static char accel_xyz [__MAX_BUF_SENSOR] = {'1','0','0',',','9','8','0','6','6','5',',','1','0','0'};
 static int accel_enable = 0;
@@ -75,6 +78,19 @@ static char rot_quad [__MAX_BUF_SENSOR] = {'2','3','6','2',',','-','1','4','0','
 static int rot_enable = 0;
 static int rot_delay = 200000000;
 
+static char pressure_data [__MAX_BUF_SENSOR] = {'7','6','0',',',' ','4','2','5', 0};
+static int pressure_enable = 0;
+static int pressure_delay = 200000000;
+
+static int uv_level = 0;
+static int uv_enable = 0;
+static int uv_delay = 200000000;
+
+static int hrm_heart = 1000;
+static int hrm_rri = 600;
+static int hrm_enable = 0;
+static int hrm_delay = 200000000;
+
 VirtIOSENSOR* vsensor;
 static int sensor_capability = 0;
 
@@ -108,6 +124,15 @@ static type_action get_action(enum sensor_types type)
     case sensor_type_rotation_vector:
         action = ACTION_ROTATION;
         break;
+    case sensor_type_pressure:
+        action = ACTION_PRESSURE;
+        break;
+    case sensor_type_uv:
+        action = ACTION_UV;
+        break;
+    case sensor_type_hrm:
+        action = ACTION_HRM;
+        break;
     default:
         break;
     }
@@ -138,7 +163,7 @@ static void send_sensor_to_ecs(const char* data, enum sensor_types type)
     memcpy(ecs_message + 13, &action, sizeof(unsigned char));
     memcpy(ecs_message + 14, data, buf_len);
 
-    TRACE("ntf_to_injector- len: %d, group: %d, action: %d, data: %s\n", length, group, action, data);
+    LOG_TRACE("ntf_to_injector- len: %d, group: %d, action: %d, data: %s\n", length, group, action, data);
 
     send_device_ntf(ecs_message, message_len);
 
@@ -149,16 +174,16 @@ static void send_sensor_to_ecs(const char* data, enum sensor_types type)
 static void __set_sensor_data (enum sensor_types type, char* data, int len)
 {
     if (len < 0 || len > __MAX_BUF_SENSOR) {
-        ERR("sensor data size is wrong.\n");
+        LOG_SEVERE("sensor data size is wrong.\n");
         return;
     }
 
     if (data == NULL) {
-        ERR("sensor data is NULL.\n");
+        LOG_SEVERE("sensor data is NULL.\n");
         return;
     }
 
-    TRACE("set_sensor_data with type '%d' with data '%s'", type, data);
+    LOG_TRACE("set_sensor_data with type '%d' with data '%s'", type, data);
 
     switch (type) {
         case sensor_type_accel:
@@ -277,6 +302,61 @@ static void __set_sensor_data (enum sensor_types type, char* data, int len)
             sscanf(data, "%d", &geo_delay);
             qemu_mutex_unlock(&geo_mutex);
             break;
+        case sensor_type_pressure:
+            qemu_mutex_lock(&pressure_mutex);
+            strcpy(pressure_data, data);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_pressure_enable:
+            qemu_mutex_lock(&pressure_mutex);
+            sscanf(data, "%d", &pressure_enable);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_pressure_delay:
+            qemu_mutex_lock(&pressure_mutex);
+            sscanf(data, "%d", &pressure_delay);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_uv:
+            qemu_mutex_lock(&uv_mutex);
+            sscanf(data, "%d", &uv_level);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_uv_enable:
+            qemu_mutex_lock(&uv_mutex);
+            sscanf(data, "%d", &uv_enable);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_uv_delay:
+            qemu_mutex_lock(&uv_mutex);
+            sscanf(data, "%d", &uv_delay);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_hrm:
+            qemu_mutex_lock(&hrm_mutex);
+            sscanf(data, "%d, %d", &hrm_heart, &hrm_rri);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_heart:
+            qemu_mutex_lock(&hrm_mutex);
+            sscanf(data, "%d", &hrm_heart);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_rri:
+            qemu_mutex_lock(&hrm_mutex);
+            sscanf(data, "%d", &hrm_rri);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_enable:
+            qemu_mutex_lock(&hrm_mutex);
+            sscanf(data, "%d", &hrm_enable);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_delay:
+            qemu_mutex_lock(&hrm_mutex);
+            sscanf(data, "%d", &hrm_delay);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
         default:
             return;
     }
@@ -408,6 +488,51 @@ static void __get_sensor_data(enum sensor_types type, char* msg_info)
             sprintf(msg_info, "%d", rot_delay);
             qemu_mutex_unlock(&rot_mutex);
             break;
+        case sensor_type_pressure:
+            qemu_mutex_lock(&pressure_mutex);
+            strcpy(msg_info, pressure_data);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_pressure_enable:
+            qemu_mutex_lock(&pressure_mutex);
+            sprintf(msg_info, "%d", pressure_enable);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_pressure_delay:
+            qemu_mutex_lock(&pressure_mutex);
+            sprintf(msg_info, "%d", pressure_delay);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_uv:
+            qemu_mutex_lock(&uv_mutex);
+            sprintf(msg_info, "%d", uv_level);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_uv_enable:
+            qemu_mutex_lock(&uv_mutex);
+            sprintf(msg_info, "%d", uv_enable);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_uv_delay:
+            qemu_mutex_lock(&uv_mutex);
+            sprintf(msg_info, "%d", uv_delay);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_hrm:
+            qemu_mutex_lock(&hrm_mutex);
+            sprintf(msg_info, "%d, %d", hrm_heart, hrm_rri);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_enable:
+            qemu_mutex_lock(&hrm_mutex);
+            sprintf(msg_info, "%d", hrm_enable);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_delay:
+            qemu_mutex_lock(&hrm_mutex);
+            sprintf(msg_info, "%d", hrm_delay);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
         default:
             return;
     }
@@ -416,10 +541,10 @@ static void __get_sensor_data(enum sensor_types type, char* msg_info)
 void req_sensor_data (enum sensor_types type, enum request_cmd req, char* data, int len)
 {
     char msg_info [__MAX_BUF_SENSOR];
-    memset(msg_info, 0, __MAX_BUF_SENSOR);
+    memset(msg_info, 0, sizeof(msg_info));
 
     if (type >= sensor_type_max || (req != request_get && req != request_set)) {
-        ERR("unavailable sensor type request.\n");
+        LOG_SEVERE("unavailable sensor type request.\n");
         return;
     }
 
@@ -435,7 +560,7 @@ static void answer_sensor_data_request(int type, char* data, VirtQueueElement *e
 {
     msg_info* msginfo = (msg_info*) malloc(sizeof(msg_info));
     if (!msginfo) {
-        ERR("msginfo is NULL!\n");
+        LOG_SEVERE("msginfo is NULL!\n");
         return;
     }
 
@@ -443,7 +568,7 @@ static void answer_sensor_data_request(int type, char* data, VirtQueueElement *e
     msginfo->type = type;
     __get_sensor_data(type, msginfo->buf);
 
-    TRACE("sending message: %s, type: %d, req: %d\n", msginfo->buf, msginfo->type, msginfo->req);
+    LOG_TRACE("sending message: %s, type: %d, req: %d\n", msginfo->buf, msginfo->type, msginfo->req);
 
     memset(elem->in_sg[0].iov_base, 0, elem->in_sg[0].iov_len);
     memcpy(elem->in_sg[0].iov_base, msginfo, sizeof(struct msg_info));
@@ -457,7 +582,7 @@ static void handle_msg(struct msg_info *msg, VirtQueueElement *elem)
     unsigned int len = 0;
 
     if (msg == NULL) {
-        ERR("msg info structure is NULL.\n");
+        LOG_SEVERE("msg info structure is NULL.\n");
         return;
     }
 
@@ -480,17 +605,17 @@ static void virtio_sensor_vq(VirtIODevice *vdev, VirtQueue *vq)
     int index = 0;
 
     if (vsensor->vq == NULL) {
-        ERR("virt queue is not ready.\n");
+        LOG_SEVERE("virt queue is not ready.\n");
         return;
     }
 
     if (!virtio_queue_ready(vsensor->vq)) {
-        ERR("virtqueue is not ready.");
+        LOG_SEVERE("virtqueue is not ready.");
         return;
     }
 
     if (virtio_queue_empty(vsensor->vq)) {
-        ERR("<< virtqueue is empty.\n");
+        LOG_SEVERE("<< virtqueue is empty.\n");
         return;
     }
 
@@ -498,7 +623,7 @@ static void virtio_sensor_vq(VirtIODevice *vdev, VirtQueue *vq)
         memset(&msg, 0x00, sizeof(msg));
         memcpy(&msg, elem.out_sg[0].iov_base, elem.out_sg[0].iov_len);
 
-        TRACE("handling msg from driver: %s, len: %d, type: %d, req: %d, index: %d\n", msg.buf, strlen(msg.buf), msg.type, msg.req, index);
+        LOG_TRACE("handling msg from driver: %s, len: %d, type: %d, req: %d, index: %d\n", msg.buf, strlen(msg.buf), msg.type, msg.req, index);
 
         handle_msg(&msg, &elem);
     }
@@ -520,8 +645,14 @@ static int set_capability(char* sensor)
         return sensor_cap_rotation_vector;
     } else if (!strncmp(sensor, SENSOR_NAME_HAPTIC, 6)) {
         return sensor_cap_haptic;
+    } else if (!strncmp(sensor, SENSOR_NAME_PRESSURE, 5)) {
+        return sensor_cap_pressure;
+    } else if (!strncmp(sensor, SENSOR_NAME_UV, 2)) {
+        return sensor_cap_uv;
+    } else if (!strncmp(sensor, SENSOR_NAME_HRM, 3)) {
+        return sensor_cap_hrm;
     } else {
-        ERR("unknown sensor request: %s", sensor);
+        LOG_SEVERE("unknown sensor request: %s", sensor);
     }
 
     return 0;
@@ -543,12 +674,12 @@ static void parse_sensor_capability(char* lists)
         }
     }
 
-    INFO("sensor device capabilty enabled with %02x\n", sensor_capability);
+    LOG_INFO("sensor device capabilty enabled with %02x\n", sensor_capability);
 }
 
 static void virtio_sensor_realize(DeviceState *dev, Error **errp)
 {
-    INFO("initialize virtio-sensor device\n");
+    LOG_INFO("initialize virtio-sensor device\n");
 
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     vsensor = VIRTIO_SENSOR(vdev);
@@ -556,7 +687,7 @@ static void virtio_sensor_realize(DeviceState *dev, Error **errp)
     virtio_init(vdev, SENSOR_DEVICE_NAME, VIRTIO_ID_SENSOR, 0);
 
     if (vsensor == NULL) {
-        ERR("failed to initialize sensor device\n");
+        LOG_SEVERE("failed to initialize sensor device\n");
         error_set(errp, QERR_DEVICE_INIT_FAILED, SENSOR_DEVICE_NAME);
         return;
     }
@@ -567,10 +698,13 @@ static void virtio_sensor_realize(DeviceState *dev, Error **errp)
     qemu_mutex_init(&light_mutex);
     qemu_mutex_init(&proxi_mutex);
     qemu_mutex_init(&rot_mutex);
+    qemu_mutex_init(&pressure_mutex);
+    qemu_mutex_init(&uv_mutex);
+    qemu_mutex_init(&hrm_mutex);
 
     vsensor->vq = virtio_add_queue(&vsensor->vdev, 64, virtio_sensor_vq);
 
-    INFO("initialized sensor type: %s\n", vsensor->sensors);
+    LOG_INFO("initialized sensor type: %s\n", vsensor->sensors);
 
     if (vsensor->sensors) {
         parse_sensor_capability(vsensor->sensors);
@@ -580,7 +714,7 @@ static void virtio_sensor_realize(DeviceState *dev, Error **errp)
 static void virtio_sensor_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
-    INFO("destroy sensor device\n");
+    LOG_INFO("destroy sensor device\n");
 
     qemu_mutex_destroy(&accel_mutex);
     qemu_mutex_destroy(&gyro_mutex);
@@ -588,6 +722,9 @@ static void virtio_sensor_unrealize(DeviceState *dev, Error **errp)
     qemu_mutex_destroy(&light_mutex);
     qemu_mutex_destroy(&proxi_mutex);
     qemu_mutex_destroy(&rot_mutex);
+    qemu_mutex_destroy(&pressure_mutex);
+    qemu_mutex_destroy(&uv_mutex);
+    qemu_mutex_destroy(&hrm_mutex);
 
     virtio_cleanup(vdev);
 }
@@ -595,13 +732,13 @@ static void virtio_sensor_unrealize(DeviceState *dev, Error **errp)
 
 static void virtio_sensor_reset(VirtIODevice *vdev)
 {
-    TRACE("virtio_sensor_reset.\n");
+    LOG_TRACE("virtio_sensor_reset.\n");
 }
 
 static uint32_t virtio_sensor_get_features(VirtIODevice *vdev,
                                             uint32_t request_feature)
 {
-    TRACE("virtio_sensor_get_features.\n");
+    LOG_TRACE("virtio_sensor_get_features.\n");
     return 0;
 }
 
index 0c81d0ca1a6c6f4cfc34ce9f1bc433c4b70700bc..11a078600e667629e632031894362613c3193321 100644 (file)
@@ -69,17 +69,31 @@ enum sensor_types {
     sensor_type_rotation_vector_delay,
     sensor_type_mag,
     sensor_type_tilt,
+    sensor_type_pressure,
+    sensor_type_pressure_enable,
+    sensor_type_pressure_delay,
+    sensor_type_uv,
+    sensor_type_uv_enable,
+    sensor_type_uv_delay,
+    sensor_type_hrm,
+    sensor_type_hrm_heart,
+    sensor_type_hrm_rri,
+    sensor_type_hrm_enable,
+    sensor_type_hrm_delay,
     sensor_type_max
 };
 
 enum sensor_capabilities {
-    sensor_cap_accel            = 0x01,
-    sensor_cap_geo              = 0x02,
-    sensor_cap_gyro             = 0x04,
-    sensor_cap_light            = 0x08,
-    sensor_cap_proxi            = 0x10,
-    sensor_cap_rotation_vector  = 0x20,
-    sensor_cap_haptic           = 0x40
+    sensor_cap_accel            = 0x0001,
+    sensor_cap_geo              = 0x0002,
+    sensor_cap_gyro             = 0x0004,
+    sensor_cap_light            = 0x0008,
+    sensor_cap_proxi            = 0x0010,
+    sensor_cap_rotation_vector  = 0x0020,
+    sensor_cap_haptic           = 0x0040,
+    sensor_cap_pressure         = 0x0080,
+    sensor_cap_uv               = 0x0100,
+    sensor_cap_hrm              = 0x0200
 };
 
 #define MESSAGE_TYPE_SENSOR "sensor"
@@ -92,16 +106,22 @@ enum sensor_capabilities {
 #define ACTION_LIGHT        113
 #define ACTION_PROXI        114
 #define ACTION_ROTATION     115
+#define ACTION_PRESSURE     116
+#define ACTION_UV           117
+#define ACTION_HRM          118
 
 #define ATTRIBUTE_NAME_SENSORS "sensors"
 
-#define SENSOR_NAME_ACCEL  "accel"
-#define SENSOR_NAME_GYRO   "gyro"
-#define SENSOR_NAME_GEO    "geo"
-#define SENSOR_NAME_LIGHT  "light"
-#define SENSOR_NAME_PROXI  "proxi"
-#define SENSOR_NAME_ROT    "rot"
-#define SENSOR_NAME_HAPTIC "haptic"
+#define SENSOR_NAME_ACCEL       "accel"
+#define SENSOR_NAME_GYRO        "gyro"
+#define SENSOR_NAME_GEO         "geo"
+#define SENSOR_NAME_LIGHT       "light"
+#define SENSOR_NAME_PROXI       "proxi"
+#define SENSOR_NAME_ROT         "rot"
+#define SENSOR_NAME_HAPTIC      "haptic"
+#define SENSOR_NAME_PRESSURE    "press"
+#define SENSOR_NAME_UV          "uv"
+#define SENSOR_NAME_HRM         "hrm"
 
 #define SENSOR_CAP_TOKEN "&"
 
@@ -158,6 +178,34 @@ void req_sensor_data(enum sensor_types type, enum request_cmd req, char* data, i
 #define set_sensor_rotation_vector(data, len)  \
     req_sensor_data(sensor_type_rotation_vector, request_set, data, len);
 
+// Pressure
+#define get_sensor_pressure()  \
+    req_sensor_data(sensor_type_pressure, request_get, NULL, 0);
+
+#define set_sensor_pressure(data, len) \
+    req_sensor_data(sensor_type_pressure, request_set, data, len);
+
+// UV
+#define get_sensor_uv()  \
+    req_sensor_data(sensor_type_uv, request_get, NULL, 0);
+
+#define set_sensor_uv(data, len) \
+    req_sensor_data(sensor_type_uv, request_set, data, len);
+
+// HRM
+#define get_sensor_hrm()  \
+    req_sensor_data(sensor_type_hrm, request_get, NULL, 0);
+
+#define set_sensor_hrm(data, len) \
+    req_sensor_data(sensor_type_hrm, request_set, data, len);
+
+#define set_sensor_hrm_heart(data, len) \
+    req_sensor_data(sensor_type_hrm_heart, request_set, data, len);
+
+#define set_sensor_hrm_rri(data, len) \
+    req_sensor_data(sensor_type_hrm_rri, request_set, data, len);
+
+
 #ifdef __cplusplus
 }
 #endif