#ifdef CONFIG_MARU
#include "tizen/src/util/maru_err_table.h"
+#include "tizen/src/emul_state.h"
#endif
static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features)
#endif
goto out;
}
+
+#ifdef CONFIG_MARU
+ set_emul_hds_attached(true);
+ set_emul_hds_path(fse->path);
+#endif
+
v9fs_path_free(&path);
return;
#define MSG_TYPE_GUEST "guest"
#define MSG_GROUP_STATUS 15
+#define MSG_GROUP_HDS 100
+
+#define HDS_ACTION_MOUNT 1
+#define HDS_ACTION_UMOUNT 2
enum message_action {
MSG_ACT_BATTERY_LEVEL = 100,
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
};
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
bool send_msg_to_guest(ECS_Client* ccli, char* cmd, int group, int action,
char* data, int data_len);
+
void make_send_device_ntf (char* cmd, int group, int action, char* data);
bool pb_to_all_clients(ECS__Master* master);
if (clii && 0 < clii->client_fd && mon && mon->outbuf_index != 0) {
//ret = ecs_write(clii->client_fd, mon->outbuf, mon->outbuf_index);
ret = send_monitor_ntf((char*)mon->outbuf, mon->outbuf_index);
+ memset(mon->outbuf, 0, sizeof(mon->outbuf));
mon->outbuf_index = 0;
if (ret < -1) {
ecs_client_close(clii);
mon->outbuf[mon->outbuf_index++] = '\r';
#endif
mon->outbuf[mon->outbuf_index++] = c;
- if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1) || c == '\n')
+ if (mon->outbuf_index >= (sizeof(mon->outbuf) - 2) || c == '\n') {
+ mon->outbuf[mon->outbuf_index++] = 0;
ecs_monitor_flush(clii, mon);
+ }
}
}
*/
#include <stdbool.h>
-#include <pthread.h>
#include <glib.h>
#include "hw/qdev.h"
if (data != NULL) {
length = strlen(data);
}
+
msg_length += length;
+
char* send_msg = (char*) malloc(msg_length);
if(!send_msg)
return;
+
memcpy(send_msg, cmd, 10);
memcpy(send_msg + 10, &length, sizeof(unsigned short));
memcpy(send_msg + 12, &group, sizeof(unsigned char));
if (data != NULL) {
memcpy(send_msg + 14, data, strlen(data));
}
+
send_device_ntf(send_msg, msg_length);
+
free(send_msg);
}
bool send_msg_to_guest(ECS_Client* ccli, char* cmd, int group, int action, char* data, int data_len)
- {
+{
int sndlen = 15; // HEADER(CMD + LENGTH + GROUP + ACTION) + 1
char* sndbuf;
bool ret = false;
if (!sndbuf) {
return false;
}
+
memcpy(sndbuf, cmd, 10);
memcpy(sndbuf + 10, &data_len, 2);
memcpy(sndbuf + 12, &group, 1);
TRACE("telephony msg >>");
ret = send_to_vmodem(route_ij, sndbuf, sndlen);
} else {
- INFO("evdi msg >> %s", cmd);
+ TRACE("evdi msg >> %s", cmd);
ret = send_to_evdi(route_ij, sndbuf, sndlen);
}
return true;
}
-
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);
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);
}
}
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;
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);
+ msgproc_device_ans(ccli, cmd, true, NULL);
} else {
- ERR("sensor set data is null\n");
+ LOG_SEVERE("sensor set data is null\n");
}
}
- msgproc_device_ans(ccli, cmd, true, NULL);
if (data) {
g_free(data);
}
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) {
}
/* release multi-touch */
-#ifdef CONFIG_SDL
+#ifndef CONFIG_USE_SHM
if (get_multi_touch_enable() != 0) {
clear_finger_slot(false);
}
#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[] = "#";
}
// 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);
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);
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");
}
}
}
}
-static char hds_path[PATH_MAX];
-
static void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char * cmd)
{
char* data = NULL;
+ char token[] = "\n";
type_group group = (type_group) (msg->group & 0xff);
type_action action = (type_action) (msg->action & 0xff);
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()) {
- sprintf(hds_data_send, "1, %s", hds_path);
+ char* guest_path = get_emul_hds_guest_path();
+ if (strlen(guest_path) == 0) {
+ set_emul_hds_guest_path("/mnt/host");
+ guest_path = get_emul_hds_guest_path();
+ }
+ sprintf(hds_data_send, "1, %s, %s", get_emul_hds_path(), guest_path);
} else {
sprintf(hds_data_send, "0, ");
}
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());
- if (data != NULL && !is_hds_attached()) {
- do_hotplug(ATTACH_HDS, data, strlen(data) + 1);
- if (!is_hds_attached()) {
- ERR("failed to attach");
- make_send_device_ntf(cmd, 100, 2, NULL);
- } else {
- memset(hds_path, 0, sizeof(hds_path));
- memcpy(hds_path, data, sizeof(hds_path) - 1);
- INFO("send emuld to mount.\n");
- send_msg_to_guest(ccli, cmd, group, action, data, strlen(data));
- }
+ } else if (group == MSG_GROUP_HDS && action == HDS_ACTION_MOUNT) {
+ LOG_INFO("try attach with is_hds_attached : %d\n", is_hds_attached());
+ char *host = strtok(data, token);
+ if (host == NULL) {
+ make_send_device_ntf(cmd, group, 2, NULL);
+ goto hds_free;
+ }
+ char *guest = strtok(NULL, token);
+ if (guest == NULL) {
+ make_send_device_ntf(cmd, group, 2, NULL);
+ goto hds_free;
+ }
+
+ if (!is_hds_attached()) {
+ LOG_INFO("do attach host: %s\n", host);
+ do_hotplug(ATTACH_HDS, host, strlen(host) + 1);
+ LOG_INFO("send emuld to mount: %s, %d.\n", guest, strlen(guest));
+ set_emul_hds_guest_path(guest);
+ send_msg_to_guest(ccli, cmd, group, action, guest, strlen(guest) + 1);
} else {
- make_send_device_ntf(cmd, 100, 2, NULL);
+ make_send_device_ntf(cmd, group, 2, NULL);
}
- } else if (group == 100 && action == 2) {
- INFO("try detach with is_hds_attached : %d\n", is_hds_attached());
+ } else if (group == MSG_GROUP_HDS && action == HDS_ACTION_UMOUNT) {
+ LOG_INFO("try detach with is_hds_attached : %d\n", is_hds_attached());
if (is_hds_attached()) {
- INFO("send emuld to umount.\n");
- send_msg_to_guest(ccli, cmd, group, action, NULL, 0);
+ char* guest_path = get_emul_hds_guest_path();
+ if (strlen(guest_path) == 0) {
+ set_emul_hds_guest_path("/mnt/host");
+ guest_path = get_emul_hds_guest_path();
+ }
+ LOG_INFO("send emuld to umount.%s\n", guest_path);
+ send_msg_to_guest(ccli, cmd, group, action, guest_path, strlen(guest_path) + 1);
} else {
- INFO("hds is not attached. do not try detach it.\n");
+ LOG_INFO("hds is not attached. do not try detach it.\n");
+ make_send_device_ntf(cmd, group, 4, NULL);
}
} else {
- ERR("hds unknown command: group %d action %d\n", group, action);
+ LOG_SEVERE("hds unknown command: group %d action %d\n", group, action);
}
-
+hds_free:
if (data) {
g_free(data);
}
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)) {
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);
} 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;
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;
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;
{
int err_no = 0;
char ret = 0;
-
if (dataBuf != NULL){
ret = dataBuf[0];
if (ret == '0' ) {
/* umount sdcard */
+ INFO("datalen: %d\n", dataLen);
char* sdcard_img_path = get_sdcard_img_path(dataBuf + 2, dataLen);
err_no = remove_sdcard_lock_os(sdcard_img_path);
if (errno == 0 && is_sdcard_attached()) {
g_free(sdcard_img_path);
} else if (ret == '1') {
/* mount sdcard */
+ INFO("datalen: %d\n", dataLen);
char* sdcard_img_path = get_sdcard_img_path(dataBuf + 2, dataLen);
if ( !is_sdcard_attached() && make_sdcard_lock_os(sdcard_img_path)) {
do_hotplug(ATTACH_SDCARD, sdcard_img_path, strlen(sdcard_img_path) + 1);
} else if (!strcmp(cat, "suspend")) {
ecs_suspend_lock_state(ecs_get_suspend_state());
return true;
+ } else if (!strcmp(cat, "boot")) {
+ LOG_INFO("emulator booting done.\n");
+ set_emulator_condition(BOOT_COMPLETED);
+ return true;
} else if (!strcmp(cat, MSG_TYPE_GUEST)) {
INFO("emuld connection is %d\n", action);
qemu_mutex_lock(&mutex_guest_connection);
guest_connection = action;
+ if (action == 1) {
+ set_emulator_condition(BOOT_COMPLETED);
+ } else {
+ set_emulator_condition(RESET);
+ }
qemu_mutex_unlock(&mutex_guest_connection);
return false;
} else if (!strcmp(cat, "hds")) {
make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
break;
case 2:
+ do_hotplug(DETACH_HDS, NULL, 0);
make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
break;
case 3:
do_hotplug(DETACH_HDS, NULL, 0);
- if (!is_hds_attached()) {
- make_send_device_ntf(cat, MSG_GROUP_HDS, 5, NULL);
- } else {
- make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
- }
+ make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
break;
case 4:
make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
break;
}
return true;
- } else {
- ERR("unknown command: %s.\n", cat);
}
return false;
#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
{
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;
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));
}
}
}
+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 = 0, rri = 0, index = 0;
+
+ // 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];
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);
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);
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);
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);
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);
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;
}
return _emul_info.vm_name;
}
+void set_emul_hds_attached(bool attached)
+{
+ _emul_state.hds_attached = attached;
+}
+
+bool get_emul_hds_attached(void)
+{
+ return _emul_state.hds_attached;
+}
+
+void set_emul_hds_path(const char *path)
+{
+ if (path == NULL) {
+ memset(_emul_state.hds_path, 0, sizeof(_emul_state.hds_path));
+ } else {
+ strncpy(_emul_state.hds_path, path, sizeof(_emul_state.hds_path));
+ _emul_state.hds_path[sizeof(_emul_state.hds_path) -1] = 0;
+ }
+}
+
+char* get_emul_hds_path(void)
+{
+ return _emul_state.hds_path;
+}
+
+void set_emul_hds_guest_path(const char *path)
+{
+ if (path == NULL) {
+ memset(_emul_state.hds_guest_path, 0, sizeof(_emul_state.hds_guest_path));
+ } else {
+ strncpy(_emul_state.hds_guest_path, path, sizeof(_emul_state.hds_guest_path));
+ _emul_state.hds_guest_path[sizeof(_emul_state.hds_guest_path) -1] = 0;
+ }
+}
+
+char* get_emul_hds_guest_path(void)
+{
+ return _emul_state.hds_guest_path;
+}
+
#define SUPPORT_LEGACY_ARGS
+#define MAX_HDS_PATH 256
+
enum {
RESET = 0,
BOOT_COMPLETED = 1,
int qemu_caps_lock;
int qemu_num_lock;
/* add here */
+ bool hds_attached;
+ char hds_path[MAX_HDS_PATH];
+ char hds_guest_path[MAX_HDS_PATH];
} EmulatorConfigState;
/* misc */
void set_emul_caps_lock_state(int state);
void set_emul_num_lock_state(int state);
void set_emul_vm_name(char *vm_name);
+void set_emul_hds_attached(bool attached);
+void set_emul_hds_path(const char *path);
+void set_emul_hds_guest_path(const char *path);
/* getter */
bool get_emul_skin_enable(void);
int get_emul_caps_lock_state(void);
int get_emul_num_lock_state(void);
char* get_emul_vm_name(void);
+bool get_emul_hds_attached(void);
+char* get_emul_hds_path(void);
+char* get_emul_hds_guest_path(void);
#endif /* __EMUL_STATE_H__ */
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;
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;
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;
}
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);
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:
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;
}
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;
}
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;
}
{
msg_info* msginfo = (msg_info*) malloc(sizeof(msg_info));
if (!msginfo) {
- ERR("msginfo is NULL!\n");
+ LOG_SEVERE("msginfo is NULL!\n");
return;
}
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));
unsigned int len = 0;
if (msg == NULL) {
- ERR("msg info structure is NULL.\n");
+ LOG_SEVERE("msg info structure is NULL.\n");
return;
}
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;
}
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);
}
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;
}
}
- 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);
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;
}
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);
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);
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);
}
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;
}
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"
#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 "&"
#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
#include "qemu/event_notifier.h"
#include "emulator.h"
+#include "emul_state.h"
#include "maru_device_hotplug.h"
#define HOST_KEYBOARD_DRIVER "virtio-keyboard-pci"
#define FS_MOUNT_TAG "fileshare"
+#include "debug_ch.h"
+
+MULTI_DEBUG_CHANNEL(qemu, hotplug);
+
struct maru_device_hotplug {
EventNotifier notifier;
// FIXME: Should we query device every time ??
bool host_keyboard_attached;
bool sdcard_attached;
- bool hds_attached;
};
static struct maru_device_hotplug *state;
return false;
}
+ LOG_INFO("do_hds_attach - data: %s\n", file);
+
qemu_opt_set(fsdev, "fsdriver", "local");
qemu_opt_set(fsdev, "path", file);
qemu_opt_set(fsdev, "security_model", "none");
QDECREF(qdict);
- state->hds_attached = true;
-
return true;
}
QDECREF(qdict);
- state->hds_attached = false;
+ set_emul_hds_attached(false);
+ set_emul_hds_path(NULL);
+ set_emul_hds_guest_path(NULL);
return true;
}
void do_hotplug(int command, void *opaque, size_t size)
{
- if (command == ATTACH_SDCARD) {
+ if (opaque != NULL && size > 0) {
state->opaque = g_malloc(size);
memcpy(state->opaque, opaque, size);
}
break;
case ATTACH_SDCARD:
do_sdcard_attach(state->opaque);
- g_free(state->opaque);
break;
case DETACH_SDCARD:
do_sdcard_detach();
default:
break;
}
+
+ if (state->opaque != NULL) {
+ g_free(state->opaque);
+ state->opaque = NULL;
+ }
}
static void maru_device_hotplug_deinit(Notifier *notifier, void *data)
bool is_hds_attached(void)
{
- return state->hds_attached;
+ return get_emul_hds_attached();
}
qemu_opt_set_bool(fsdev, "readonly",
qemu_opt_get_bool(opts, "readonly", 0));
+#ifdef CONFIG_MARU
+ device = qemu_opts_create(qemu_find_opts("device"), "fileshare", 0,
+ &error_abort);
+#else
device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
&error_abort);
+#endif
qemu_opt_set(device, "driver", "virtio-9p-pci");
qemu_opt_set(device, "fsdev",
qemu_opt_get(opts, "mount_tag"));