add get status routine for getting value from emualtor
authorjihye kim <jihye1128.kim@samsung.com>
Thu, 15 Nov 2012 10:46:39 +0000 (19:46 +0900)
committerjihye kim <jihye1128.kim@samsung.com>
Thu, 15 Nov 2012 10:46:39 +0000 (19:46 +0900)
CMakeLists.txt
include/emuld.h
include/emuld_common.h [new file with mode: 0644]
packaging/emuld.spec
src/emuld.c
src/get_status.c [new file with mode: 0644]

index 62a56b8f7bc1aa21a813db165373b0d2042ab20f..e958d0b3e0ab94ca5b0c1202107a0ce954fcf0f2 100644 (file)
@@ -34,9 +34,9 @@ ADD_DEFINITIONS("-DTARGET -DHWREV_CHECK")
 add_definitions(-Wall -O3 -omit-frame-pointer)
 #add_definitions(-Wall -g -D_DEBUG)
 add_definitions(-Iinclude)
-ADD_EXECUTABLE(${PROJECT_NAME} src/emuld.c)
+ADD_EXECUTABLE(${PROJECT_NAME} src/emuld.c src/get_status.c)
 
 target_link_libraries(${PROJECT_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} "-lpthread" )
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} "-lpthread -lvconf" )
 
 install(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin)
index 5c528eb93604b672ad29ba10cf16f716a407b510..702bc34502559b2cb0a51c5b6e36ab2899119735 100644 (file)
@@ -80,6 +80,7 @@ FILE* log_fd;
 
 // location
 void setting_location(char* databuf);
+
 #define LOG(fmt, arg...) \
        do { \
                log_print_out("[%s:%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); \
diff --git a/include/emuld_common.h b/include/emuld_common.h
new file mode 100644 (file)
index 0000000..7d3abb9
--- /dev/null
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+
+// define group id
+// return value to the injector
+#define STATUS 15
+
+// define action id
+#define BATTERY_LEVEL 100
+#define BATTERY_CHARGER 101
+#define USB_STATUS 102
+#define EARJACK_STATUS 103
+#define RSSI_LEVEL 104
+
+#define ACCEL_VALUE 110
+#define GYRO_VALUE 111
+#define MAG_VALUE 112
+#define LIGHT_VALUE 113
+#define PROXI_VALUE 114
+#define MOTION_VALUE 115
+
+#define LOCATION_STATUS 120
+
+struct LXT_MESSAGE// lxt_message
+{
+       unsigned short length;
+       unsigned char group;
+       unsigned char action;
+       void *data; 
+};
+
+typedef struct LXT_MESSAGE LXT_MESSAGE;
+
+// Device
+char* get_battery_level(void* );
+char* get_battery_charger(void* );
+char* get_usb_status(void* );
+char* get_earjack_status(void* );
+char* get_rssi_level(void* );
+
+// Sensor
+char* get_proximity_status(void* );
+char* get_light_level(void* );
+char* get_acceleration_value(void* );
+char* get_gyroscope_value(void* );
+char* get_magnetic_value(void* );
+
+// Location
+char* get_location_status(void* );
index 3ea88e8b18567bd7b4cffae94574eed9d229ca0e..934a3bc2aba8d3f3ac8ab1039b779430bb826acb 100644 (file)
@@ -1,6 +1,6 @@
 #git:/slp/pkgs/e/emulator-daemon
 Name: emuld
-Version: 0.2.20
+Version: 0.2.21
 Release: 1
 Summary: emuld is used for communication emulator between and ide.
 License: Apache
@@ -9,6 +9,7 @@ Source1001: packaging/emuld.manifest
 BuildArch: i386
 ExclusiveArch: %{ix86}
 BuildRequires: cmake
+BuildRequires:  pkgconfig(vconf)
 
 %description
 
index 80eb768737a15479d521c13fd3bbaa2edf0bf766..e2711430410b38e75fb0ae1a24137fa27edca0f7 100644 (file)
@@ -33,7 +33,7 @@ compiler Gcc: 3.4.3.
 License: GNU General Public License   
 
 ------------------------------------------------------------------*/
-
+#include "emuld_common.h"
 #include "emuld.h"
 
 /* global definition */
@@ -48,6 +48,7 @@ int g_vm_sockfd;              /* vmodem fd */
 int g_sdbd_sockfd = -1;                /* sdbd fd */
 static int g_vm_connect_status;        /* connection status between emuld and vmodem  */
 int g_sdcard_sockfd = -1;
+int g_get_status_sockfd = -1;   /* return status of devive to the injector */
 
 pthread_t tid[MAX_CLIENT + 1];
 
@@ -66,15 +67,6 @@ int g_epoll_fd;                              /* epoll fd */
 
 struct epoll_event g_events[MAX_EVENTS]; 
 
-// for vmodem packets
-typedef struct // lxt_message
-{
-       unsigned short length;
-       unsigned char group;
-       unsigned char action;
-       void *data; 
-} LXT_MESSAGE;
-
 void TAPIMessageInit(LXT_MESSAGE *packet)
 {       
        packet->length = 0;
@@ -84,7 +76,10 @@ void TAPIMessageInit(LXT_MESSAGE *packet)
 }
 
 char SDpath[256];
-       
+
+unsigned char ActionID = 0;
+char GetBuffer[256];
+void setting_device(); 
 /*--------------------------------------------------------------*/
 /* FUNCTION PART 
    ---------------------------------------------------------------*/
@@ -718,8 +713,20 @@ void client_recv(int event_fd)
                        LOG("Something may be added in the data end, but it does not matter.");
                        LOG("sensor data recv buffer: %s", r_databuf);
 
-                       if(sendto(uSensordFd, r_databuf, packet->length, 0, (struct sockaddr*)&si_sensord_other, sslen) == -1)     
+                       if (packet->group == STATUS) {
+                               g_get_status_sockfd = event_fd;
+                               ActionID = packet->action;
+                               memset(GetBuffer, '\0', sizeof(GetBuffer));
+                               strcpy(GetBuffer, r_databuf);
+                               LOG("GetBuffer is %s", GetBuffer);
+
+                               if(pthread_create(&tid[2], NULL, setting_device, NULL) != 0) {
+                                       LOG("pthread create fail!");
+                               }
+                       }
+                       else if(sendto(uSensordFd, r_databuf, packet->length, 0, (struct sockaddr*)&si_sensord_other, sslen) == -1) {     
                                LOG("sendto error!");
+                       }
                }
                else if(strncmp(tmpbuf, "location", 8) == 0)
                {
@@ -735,7 +742,19 @@ void client_recv(int event_fd)
                        LOG("Something may be added in the data end, but it does not matter.");
                        LOG("location data recv buffer: %s", r_databuf);
 
-                       setting_location(r_databuf);
+                       if (packet->group == STATUS) {
+                               g_get_status_sockfd = event_fd;
+                               ActionID = packet->action;
+                               memset(GetBuffer, '\0', sizeof(GetBuffer));
+                               strcpy(GetBuffer, r_databuf);
+                               LOG("GetBuffer is %s", GetBuffer);
+
+                               if(pthread_create(&tid[2], NULL, setting_device, NULL) != 0) {
+                                       LOG("pthread create fail!");
+                               }
+                       } else {
+                               setting_location(r_databuf);
+                       }
                }
                else if(strncmp(tmpbuf, "nfc", 3) == 0)
                {
@@ -970,6 +989,113 @@ void end_server(int sig)
        exit(0);
 }
 
+void setting_device()
+{
+       pthread_detach(pthread_self());
+
+       char* msg = 0;
+       LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+
+       switch(ActionID)
+       {
+       case BATTERY_LEVEL:
+               msg = get_battery_level((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting battery level");
+               }
+       break;
+       case BATTERY_CHARGER:
+               msg = get_battery_charger((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting battery charger state");
+               }
+       break;
+       case USB_STATUS:
+               msg = get_usb_status((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting usb status");
+               }
+       break;
+       case EARJACK_STATUS:
+               msg = get_earjack_status((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting earjack status");
+               }
+       break;
+       case RSSI_LEVEL:
+               msg = get_rssi_level((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting rssi level");
+               }
+       break;
+       case ACCEL_VALUE:
+               msg = get_acceleration_value((void*)packet);
+               if (msg == 0) {
+                       LOG("falied getting acceleration value");
+               }
+       break;
+       case GYRO_VALUE:
+               msg = get_gyroscope_value((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting gyroscope value");
+               }
+       break;
+       case MAG_VALUE:
+               msg = get_magnetic_value((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting magnetic value");
+               }
+       break;
+       case LIGHT_VALUE:
+               msg = get_light_level((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting light level");
+               }
+       break;
+       case PROXI_VALUE:
+               msg = get_proximity_status((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting proximity status");
+               }
+       break;
+       case MOTION_VALUE:
+               LOG("not support getting motion value");
+       break;
+       case LOCATION_STATUS:
+               msg = get_location_status((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting location status");
+               }
+       break;
+       default:
+               //TODO
+       break;
+       }
+
+       if (g_get_status_sockfd != -1) {
+               if (msg != 0) {
+                       LOG("send data to injector");
+               } else {
+                       LOG("send error message to injector");
+                       memset(packet, 0, sizeof(LXT_MESSAGE));
+                       packet->length = 0;
+                       packet->group  = STATUS;
+                       packet->action = ActionID;
+               }
+               send(g_get_status_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+               if (packet->length != 0) {
+                       send(g_get_status_sockfd, msg, packet->length, 0);
+               }
+       }
+
+       if(msg != 0) {
+               free(msg);
+       }
+       free(packet);
+
+       pthread_exit((void *) 0); 
+}
+
 // location event
 char command[512];
 char latitude[128];
diff --git a/src/get_status.c b/src/get_status.c
new file mode 100644 (file)
index 0000000..1a02eca
--- /dev/null
@@ -0,0 +1,349 @@
+//#include <vconf.h>
+#include "emuld_common.h"
+
+
+char* message;
+char* get_usb_status(void* p)
+{
+       FILE* fd = fopen("/sys/devices/platform/jack/usb_online", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int status = 0;
+       fscanf(fd, "%d", &status);
+       fclose(fd);
+
+       // int to byte
+       message = (char*)malloc(5);
+       message[3] = (char) (status & 0xff);
+       message[2] = (char) (status >> 8 & 0xff);
+       message[1] = (char) (status >> 16 & 0xff);
+       message[0] = (char) (status >> 24 & 0xff);
+       message[4] = '\0';
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = USB_STATUS;
+
+       return message;
+}
+
+char* get_earjack_status(void* p)
+{
+       FILE* fd = fopen("/sys/devices/platform/jack/earjack_online", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int status = 0;
+       fscanf(fd, "%d", &status);
+       fclose(fd);
+
+       // int to byte
+       message = (char*)malloc(5);
+       message[3] = (char) (status & 0xff);
+       message[2] = (char) (status >> 8 & 0xff);
+       message[1] = (char) (status >> 16 & 0xff);
+       message[0] = (char) (status >> 24 & 0xff);
+       message[4] = '\0';
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = EARJACK_STATUS;
+
+       return message;
+}
+
+char* get_rssi_level(void* p)
+{
+       int level;
+       int ret = vconf_get_int("memory/telephony/rssi", &level);
+       if (ret != 0) {
+               return 0;
+       }
+
+       // int to byte
+       message = (char*)malloc(5);
+       message[3] = (char) (level & 0xff);
+       message[2] = (char) (level >> 8 & 0xff);
+       message[1] = (char) (level >> 16 & 0xff);
+       message[0] = (char) (level >> 24 & 0xff);
+       message[4] = '\0';
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = RSSI_LEVEL;
+
+       return message;
+}
+
+char* get_battery_level(void* p)
+{
+       FILE* fd = fopen("/sys/class/power_supply/battery/capacity", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int level = 0;
+       fscanf(fd, "%d", &level);
+       fclose(fd);
+
+       // int to byte
+       message = (char*)malloc(5);
+       message[3] = (char) (level & 0xff);
+       message[2] = (char) (level >> 8 & 0xff);
+       message[1] = (char) (level >> 16 & 0xff);
+       message[0] = (char) (level >> 24 & 0xff);
+       message[4] = '\0';
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = BATTERY_LEVEL;
+
+       return message;
+}
+
+char* get_battery_charger(void* p)
+{
+       FILE* fd = fopen("/sys/class/power_supply/battery/charge_now", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int charge = 0;
+       fscanf(fd, "%d", &charge);
+       fclose(fd);
+       // int to byte
+       message = (char*)malloc(5);
+
+       message[3] = (char) (charge & 0xff);
+       message[2] = (char) (charge >> 8 & 0xff);
+       message[1] = (char) (charge >> 16 & 0xff);
+       message[0] = (char) (charge >> 24 & 0xff);
+       message[4] = '\0';
+       
+       LXT_MESSAGE* packet = p;        
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = BATTERY_CHARGER;
+
+       return message;
+}
+
+char* get_proximity_status(void* p)
+{
+       FILE* fd = fopen("/opt/sensor/proxi/vo", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int status = 0;
+       fscanf(fd, "%d", &status);
+       fclose(fd);
+       // int to byte
+       message = (char*)malloc(5);
+
+       message[3] = (char) (status & 0xff);
+       message[2] = (char) (status >> 8 & 0xff);
+       message[1] = (char) (status >> 16 & 0xff);
+       message[0] = (char) (status >> 24 & 0xff);
+       message[4] = '\0';
+       
+       LXT_MESSAGE* packet = p;        
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = PROXI_VALUE;
+
+       return message;
+}
+
+char* get_light_level(void* p)
+{
+       FILE* fd = fopen("/opt/sensor/light/adc", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int level = 0;
+       fscanf(fd, "%d", &level);
+       fclose(fd);
+
+       // int to byte
+       message = (char*)malloc(5);
+       message[3] = (char) (level & 0xff);
+       message[2] = (char) (level >> 8 & 0xff);
+       message[1] = (char) (level >> 16 & 0xff);
+       message[0] = (char) (level >> 24 & 0xff);
+       message[4] = '\0';
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = LIGHT_VALUE;
+
+       return message;
+}
+
+char* get_acceleration_value(void* p)
+{
+       FILE* fd = fopen("/opt/sensor/accel/xyz", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       message = (char*)malloc(128);
+       //fscanf(fd, "%d, %d, %d", message);
+       fgets(message, 128, fd);
+       fclose(fd);
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = strlen(message);
+       packet->group  = STATUS;
+       packet->action = ACCEL_VALUE;
+
+       return message;
+}
+
+char* get_gyroscope_value(void* p)
+{
+       int x;
+       int y;
+       int z;
+       FILE* fd = fopen("/opt/sensor/gyro/gyro_x_raw", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+       fscanf(fd, "%d", &x);
+       fclose(fd);
+
+       fd = fopen("/opt/sensor/gyro/gyro_y_raw", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+       fscanf(fd, "%d", &y);
+       fclose(fd);
+
+       fd = fopen("/opt/sensor/gyro/gyro_z_raw", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+       fscanf(fd, "%d", &z);
+       fclose(fd);
+       message = (char*)malloc(128);
+       memset(message, 0, 128);
+       int ret = sprintf(message, "%d, %d, %d", x, y, z);      
+       if (ret < 0) {
+               free(message);
+               return 0;
+       }
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = strlen(message);
+       packet->group  = STATUS;
+       packet->action = GYRO_VALUE;
+
+       return message;
+}
+
+char* get_magnetic_value(void* p)
+{
+       FILE* fd = fopen("/opt/sensor/geo/tesla", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       message = (char*)malloc(128);
+       fgets(message, 128, fd);
+       fclose(fd);
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = strlen(message);
+       packet->group  = STATUS;
+       packet->action = MAG_VALUE;
+       return message;
+}
+
+char* get_location_status(void* p)
+{
+       int mode;
+       int ret = vconf_get_int("db/location/replay/ReplayMode", &mode);
+       if (ret != 0) {
+               return 0;
+       }
+
+       if (mode == 0) { // STOP
+               message = (char*)malloc(5);
+               ret = sprintf(message, "%d", mode);
+               if (ret < 0) {
+                       free(message);
+                       return 0;
+               }
+       } else if (mode == 1) { // NMEA MODE(LOG MODE)
+               //char* temp = (char*)malloc(128);
+               char* temp = 0;
+               temp = vconf_get_str("db/location/replay/FileName");
+               if (temp == 0) {
+                       //free(temp);
+                       return 0;
+               }
+
+               message = (char*)malloc(256);
+               ret = sprintf(message, "%d,%s", mode, temp);
+               if (ret < 0) {
+                       free(message);
+                       return 0;
+               }
+       } else if (mode == 2) { // MANUAL MODE
+               double latitude;
+               double logitude;
+               ret = vconf_get_dbl("db/location/replay/ManualLatitude", &latitude);
+               if (ret != 0) {
+                       return 0;
+               }
+               ret = vconf_get_dbl("db/location/replay/ManualLongitude", &logitude);
+               if (ret != 0) {
+                       return 0;
+               }
+               message = (char*)malloc(128);
+               ret = sprintf(message, "%d,%f,%f", mode, latitude, logitude);
+               if (ret < 0) {
+                       free(message);
+                       return 0;
+               }
+       }
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = strlen(message);
+       packet->group  = STATUS;
+       packet->action = LOCATION_STATUS;
+
+       return message;
+}