#git:slp/pkgs/s/sensor-daemon-emulator
Name: sensord
-Version: 0.2.22
+Version: 0.2.33
Release: 1
Summary: sensor daemon for sensor
Group: TO_BE/FILLED_IN
License: Apache
Source0: %{name}-%{version}.tar.gz
-ExclusiveArch: %{ix86}
+Source1001: packaging/sensord.manifest
BuildRequires: cmake
-BuildRequires: pkgconfig(capi-appfw-application)
+BuildRequires: pkgconfig(capi-appfw-application)
BuildRequires: pkgconfig(appcore-common)
%description
%setup -q
%build
-export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed"
-
+export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed"
+
LDFLAGS="$LDFLAGS" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
make
%install
rm -rf %{buildroot}
+if [ ! -d %{buildroot}/usr/lib/systemd/system/emulator.target.wants ]; then
+ mkdir -p %{buildroot}/usr/lib/systemd/system/emulator.target.wants
+fi
+if [ ! -d %{buildroot}/opt/sensor ]; then
+ mkdir -p %{buildroot}/opt/sensor
+fi
+if [ ! -d %{buildroot}/opt/sensor/accel ]; then
+ mkdir -p %{buildroot}/opt/sensor/accel
+fi
+if [ ! -d %{buildroot}/opt/sensor/light ]; then
+ mkdir -p %{buildroot}/opt/sensor/light
+fi
+if [ ! -d /opt/sensor/proxi ]; then
+ mkdir -p %{buildroot}/opt/sensor/proxi
+fi
+if [ ! -d %{buildroot}/opt/sensor/geo ]; then
+ mkdir -p %{buildroot}/opt/sensor/geo
+fi
+if [ ! -d %{buildroot}/opt/sensor/gyro ]; then
+ mkdir -p %{buildroot}/opt/sensor/gyro
+fi
+if [ ! -d %{buildroot}/opt/nfc ]; then
+ mkdir -p %{buildroot}/opt/nfc
+ touch %{buildroot}/opt/nfc/sdkMsg
+fi
+if [ ! -d %{buildroot}/etc/emulator/ ]; then
+ mkdir -p %{buildroot}/etc/emulator/
+ cp sensord_setting.sh %{buildroot}/etc/emulator/sensord_setting.sh
+fi
+
+touch %{buildroot}/opt/sensor/accel/name
+echo "accel_sim" > %{buildroot}/opt/sensor/accel/name
+touch %{buildroot}/opt/sensor/accel/xyz
+echo "0, 980665, 0" > %{buildroot}/opt/sensor/accel/xyz
+
+touch %{buildroot}/opt/sensor/light/name
+echo "light_sim" > %{buildroot}/opt/sensor/light/name
+touch %{buildroot}/opt/sensor/light/adc
+echo "65535" > %{buildroot}/opt/sensor/light/adc
+touch %{buildroot}/opt/sensor/light/level
+echo "10" > %{buildroot}/opt/sensor/light/level
+
+touch %{buildroot}/opt/sensor/proxi/name
+echo "proxi_sim" > %{buildroot}/opt/sensor/proxi/name
+touch %{buildroot}/opt/sensor/proxi/enable
+echo "1" > %{buildroot}/opt/sensor/proxi/enable
+touch %{buildroot}/opt/sensor/proxi/vo
+echo "8" > %{buildroot}/opt/sensor/proxi/vo
+
+touch %{buildroot}/opt/sensor/gyro/name
+echo "gyro_sim" > %{buildroot}/opt/sensor/gyro/name
+touch %{buildroot}/opt/sensor/gyro/gyro_x_raw
+echo "0" > %{buildroot}/opt/sensor/gyro/gyro_x_raw
+touch %{buildroot}/opt/sensor/gyro/gyro_y_raw
+echo "0" > %{buildroot}/opt/sensor/gyro/gyro_y_raw
+touch %{buildroot}/opt/sensor/gyro/gyro_z_raw
+echo "0" > %{buildroot}/opt/sensor/gyro/gyro_z_raw
+
+touch %{buildroot}/opt/sensor/geo/name
+echo "geo_sim" > %{buildroot}/opt/sensor/geo/name
+touch %{buildroot}/opt/sensor/geo/raw
+echo "0 -90 0 3" > %{buildroot}/opt/sensor/geo/raw
+touch %{buildroot}/opt/sensor/geo/tesla
+echo "1 0 -10" > %{buildroot}/opt/sensor/geo/tesla
+
+cp sensord.service %{buildroot}/usr/lib/systemd/system/.
+ln -s ../sensord.service %{buildroot}/usr/lib/systemd/system/emulator.target.wants/sensord.service
%make_install
%clean
#rm -rf *.so
%post
-chmod 777 /usr/sbin/sensord
+chmod a+x /usr/sbin/sensord
+chmod a+x /etc/emulator/sensord_setting.sh
+chown -R 5100:5100 /opt/sensor
%postun
%files
%defattr(-,root,root,-)
%{_prefix}/sbin/sensord
-
+/usr/lib/systemd/system/sensord.service
+/usr/lib/systemd/system/emulator.target.wants/sensord.service
+/opt/sensor/accel/name
+/opt/sensor/accel/xyz
+/opt/sensor/geo/name
+/opt/sensor/geo/raw
+/opt/sensor/geo/tesla
+/opt/sensor/gyro/gyro_x_raw
+/opt/sensor/gyro/gyro_y_raw
+/opt/sensor/gyro/gyro_z_raw
+/opt/sensor/gyro/name
+/opt/sensor/light/adc
+/opt/sensor/light/level
+/opt/sensor/light/name
+/opt/sensor/proxi/enable
+/opt/sensor/proxi/name
+/opt/sensor/proxi/vo
+/opt/nfc/sdkMsg
+/etc/emulator/sensord_setting.sh
%changelog
-/*
+/* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: t; c-file-style: "bsd" -*-
* emulator-daemon-sensor
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Contact:
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsnung.com>
* Sungmin Ha <sungmin82.ha@samsung.com>
- * DongKyun Yun <dk77.yun@samsung.com>
* YeongKyoon Lee <yeongkyoon.lee@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
#include <stdlib.h>
#include <assert.h>
#include <pthread.h>
+#include <limits.h>
#ifdef __MINGW32__
#include <winsock2.h>
#include <signal.h>
#include <sys/socket.h>
#include <unistd.h>
+ #include <netdb.h>
#endif
#include <sys/types.h>
SENSOR_MOTION_SNAP_RIGHT = SENSOR_MOTION_SNAP_POSITIVE_X
};
+enum motion_move{
+ SENSOR_MOTION_MOVE_NONE = 0,
+ SENSOR_MOTION_MOVE_MOVETOCALL = 1
+};
+
void *init_sensor_server();
void sensor_parser(char *buffer);
int parse_val(char *buff, unsigned char data, char *parsbuf);
len1 = parse_val(buffer+len, 0x0a, tmpbuf);
len += len1;
- x = (atoi(tmpbuf) * 1000)/17.50;
+ x = (atoi(tmpbuf))/17.50;
/* second data */
memset(tmpbuf, '\0', sizeof(tmpbuf));
len1 = parse_val(buffer+len, 0x0a, tmpbuf);
len += len1;
- y = (atoi(tmpbuf) * 1000)/17.50;
+ y = (atoi(tmpbuf))/17.50;
/* third data */
memset(tmpbuf, '\0', sizeof(tmpbuf));
len1 = parse_val(buffer+len, 0x0a, tmpbuf);
len += len1;
- z = (atoi(tmpbuf) * 1000)/17.50;
+ z = (atoi(tmpbuf))/17.50;
fd = fopen("/opt/sensor/gyro/gyro_x_raw", "w");
if(!fd)
sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_X);
system(command);
break;
+ case 12: // move to call (direct call)
+ sprintf(command, "vconftool set -t int memory/private/sensor/800020 %d -i -f", SENSOR_MOTION_MOVE_MOVETOCALL);
+ system(command);
+ break;
default:
LOG("not supported activity");
break;
fprintf(fd, "%d", charge_full);
fclose(fd);
- // because time based polling
- system("/usr/bin/sys_event device_charge_chgdet");
-
if(charger_online == 1)
{
fd = fopen("/sys/class/power_supply/battery/charge_now", "w");
}
fprintf(fd, "%d", charger);
fclose(fd);
- // because time based polling
- system("/usr/bin/sys_event device_charge_chgdet");
}
+
+ // because time based polling
+ system("/usr/bin/sys_event device_charge_chgdet");
}
else if(id == 2)
{
{
int len1=0;
char tmpbuf[255];
- int x, y, z, accuracy = 4;
+ int x, y, z, accuracy = 3;
FILE* fd;
#ifdef SENSOR_DEBUG
}
fprintf(dstFD, "%d",z);
fclose(dstFD);
- }
+ }
+ fclose(srcFD);
}
}
#ifdef SENSOR_DEBUG
LOG("sensor_server port: %d", port);
#endif
- if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
+ if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1){
LOG("socket error!");
+ return;
+ }
memset((char *) &si_other, 0, sizeof(si_other));
si_other.sin_family = AF_INET;
#ifdef SENSOR_DEBUG
LOG("send 16 byte to sensor_server");
#endif
- if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
+ while(sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
{
- LOG("sendto error!");
+ LOG("sendto error! retry sendto");
+ usleep(1000);
}
close(s);
void *init_sensor_server()
{
- char* emul_ip = getenv("HOSTNAME");
- if(emul_ip == NULL)
- {
- LOG("emul_ip is null");
- assert(0);
- }
+ char emul_ip[HOST_NAME_MAX+1];
+ struct addrinfo *res = NULL;
+ struct addrinfo hints;
- int listen_s; /* listening socket */
+ int listen_s = 0; /* listening socket */
#ifdef TCP
int client_s; /* Client socket */
#endif
struct sockaddr_in servaddr;
struct sockaddr_in clientaddr;
ssize_t len;
+ int rc;
+
+ port_n = port;
#ifdef __MINGW32__
WSADATA wsadata;
return NULL;
}
#endif
-
+ /* this codes are the DEAD code because port couldn't be 0.
+ (port = default_sensor_port)
if(port !=0 )
port_n = port;
else
port_n = default_sensor_port;
+ */
+
+ memset(emul_ip, 0, sizeof(emul_ip));
+ if (gethostname(emul_ip, sizeof(emul_ip)) < 0)
+ {
+ LOG("gethostname(): %s", strerror(errno));
+ /* Abandon ship! */
+ goto clean_up;
+ }
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family=AF_INET;
#ifdef TCP
- if((listen_s = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+ hints.ai_socktype=SOCK_STREAM;
#else
- if((listen_s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ hints.ai_socktype=SOCK_DGRAM;
#endif
+
+ if ((rc = getaddrinfo(emul_ip, NULL, &hints, &res)) != 0)
{
- perror("Create the socket error: ");
- goto clean_up;
+ if (rc == EAI_SYSTEM)
+ LOG("getaddrinfo(): %s", strerror(errno));
+ else
+ LOG("getaddrinfo(): %s", gai_strerror(rc));
+ goto clean_up;
}
+ if (res->ai_addrlen > sizeof(servaddr))
+ {
+ LOG("sockaddr structure too big");
+ goto clean_up;
+ }
memset(&servaddr, '\0', sizeof(servaddr));
- memset(&clientaddr,'\0', sizeof(clientaddr));
-
- servaddr.sin_family = AF_INET;
- servaddr.sin_addr.s_addr = inet_addr(emul_ip);
+ memcpy(&servaddr, res->ai_addr, res->ai_addrlen);
servaddr.sin_port = htons(port_n);
+ if((listen_s = socket(res->ai_family, res->ai_socktype, 0)) < 0)
+ {
+ perror("Create the socket error: ");
+ goto clean_up;
+ }
+
+ freeaddrinfo(res);
+ res = NULL;
+
if(bind(listen_s, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0)
{
perror("bind error: ");
- goto clean_up;
+ goto clean_up;
}
#ifdef TCP
if(listen(listen_s, 3) == -1)
{
perror("Listen error: ");
- goto clean_up;
+ goto clean_up;
}
#endif
while(1)
{
#ifdef TCP
+ memset(&clientaddr,'\0', sizeof(clientaddr));
client_s = accept(listen_s, (struct sockaddr *)&clientaddr, &client_len);
if(len = read(client_s, buf, sizeof(buf)) <= 0)
{
}
clean_up:
+ if (res != NULL)
+ freeaddrinfo(res);
+
#ifdef __MINGW32__
- if( listen_s )
+ if( listen_s >= 0 )
closesocket(listen_s);
WSACleanup();
#else
- if( listen_s )
+ if( listen_s >= 0 )
close(listen_s);
#endif