unsigned char ActionID = 0;
char GetBuffer[256];
-void setting_device();
+void* setting_device();
/*--------------------------------------------------------------*/
/* FUNCTION PART
---------------------------------------------------------------*/
}
/*------------------------------- end of function init_server0 */
+static void send_msg(int fd, const void* data, size_t len, int flag)
+{
+ size_t ret = 0;
+ ret = send(fd, data, len, flag);
+ if (ret < 0)
+ {
+ LOG("Sending data to fd %d failed.", fd);
+ }
+}
+
void* init_vm_connect(void* data)
{
struct sockaddr_in vm_addr;
pthread_exit((void *) 0);
}
+void system_msg(const char* command)
+{
+ int ret = 0;
+
+ ret = system(command);
+ if (ret == -1)
+ {
+ LOG("system command (%s)failed.", command);
+ }
+}
+
int is_mounted()
{
int ret = -1, i = 0;
if(!S_ISBLK(buf.st_mode))
{
sprintf(command, "rm -rf %s", file_name);
- system(command);
+ system_msg(command);
}
else
break;
else
packet->action = 5; // failed
- send(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+ send_msg(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
LOG("SDpath is %s", SDpath);
- send(g_sdcard_sockfd, SDpath, packet->length, 0);
+ send_msg(g_sdcard_sockfd, SDpath, packet->length, 0);
if(ret == 0)
{
- system("/usr/bin/sys_event mmcblk_add");
+ system_msg("/usr/bin/sys_event mmcblk_add");
}
}
break;
packet->group = 11; // sdcard
packet->action = 0; // unmounted
- send(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+ send_msg(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
LOG("SDpath is %s", SDpath);
- send(g_sdcard_sockfd, SDpath, packet->length, 0);
+ send_msg(g_sdcard_sockfd, SDpath, packet->length, 0);
{
memset(SDpath, '\0', sizeof(SDpath));
sprintf(SDpath, "umounted");
- system("/usr/bin/sys_event mmcblk_remove");
+ system_msg("/usr/bin/sys_event mmcblk_remove");
}
}
break;
return 1;
}
+//sdcard event
+static void send_guest_server(char* databuf)
+{
+ if (!databuf)
+ {
+ LOG("invalid data buf");
+ return;
+ }
+
+ char buf[32];
+ struct sockaddr_in si_other;
+ int s, slen=sizeof(si_other);
+ FILE* fd;
+ char* ret = NULL;
+ char fbuf[16];
+ int port;
+ fd = fopen("/opt/home/sdb_port.txt", "r");
+ LOG("sdb_port.txt fopen fd is %d", fd);
+ if(!fd)
+ {
+ LOG("fopen /opt/home/sdb_port.txt fail");
+ port = 3581;
+ }
+ else
+ {
+ ret = fgets(fbuf, 16, fd);
+ if (ret == NULL)
+ LOG("Failed to read sdb port");
+ fclose(fd);
+ port = atoi(fbuf) + 3;
+ }
+
+ 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;
+ si_other.sin_port = htons(port);
+ if (inet_aton(SRV_IP, &si_other.sin_addr)==0) {
+ fprintf(stderr, "inet_aton() failed\n");
+ }
+
+ memset(buf, '\0', sizeof(buf));
+ snprintf(buf, sizeof(buf), "4\n%s", databuf);
+
+ LOG("sendGuestServer msg: %s", buf);
+ if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
+ {
+ LOG("sendto error!");
+ }
+
+ close(s);
+}
+
void client_recv(int event_fd)
{
char* r_databuf = NULL;
char tmpbuf[48];
- int len = 0, recvd_size = 0, parse_len = 0;
+ int recvd_size = 0, parse_len = 0;
if (event_fd == -1) {
LOG("invalid event fd");
if(g_sdbd_sockfd != -1)
{
- len = send(g_sdbd_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
- LOG("send_len: %d, next packet length: %d", len, packet->length);
+ send_msg(g_sdbd_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+ LOG("next packet length: %d", packet->length);
}
if (packet->length > 0)
LOG("recv_len: %d, vmodem data recv buffer: %s", recvd_size, r_databuf);
if (recvd_size > 0)
{
- len = send(g_sdbd_sockfd, r_databuf, packet->length, 0);
- LOG("send_len: %d", len);
+ send_msg(g_sdbd_sockfd, r_databuf, packet->length, 0);
}
}
else
}
recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);
- len = send(g_vm_sockfd, r_databuf, HEADER_SIZE, 0);
+ send_msg(g_vm_sockfd, r_databuf, HEADER_SIZE, 0);
memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);
LOG("Something may be added in the data end, but it does not matter.");
LOG("telephony data recv buffer: %s", r_databuf);
- len = send(g_vm_sockfd, r_databuf, packet->length, 0);
+ send_msg(g_vm_sockfd, r_databuf, packet->length, 0);
}
}
else if(strncmp(tmpbuf, "sensor", 6) == 0)
LOG("sync");
sync();
- system("/etc/rc.d/rc.shutdown &");
+ system_msg("/etc/rc.d/rc.shutdown &");
gettimeofday(&tv_start_poweroff, NULL);
powerdown_by_force();
{
case 0:
mntData->action = 2; // umounted status
- send(g_sdcard_sockfd, (void*)mntData, sizeof(char) * HEADER_SIZE, 0);
+ send_msg(g_sdcard_sockfd, (void*)mntData, sizeof(char) * HEADER_SIZE, 0);
LOG("SDpath is %s", SDpath);
- send(g_sdcard_sockfd, SDpath, mntData->length, 0);
+ send_msg(g_sdcard_sockfd, SDpath, mntData->length, 0);
memset(SDpath, '\0', sizeof(SDpath));
sprintf(SDpath, "umounted");
break;
case 1:
mntData->action = 3; // mounted status
- send(g_sdcard_sockfd, (void*)mntData, sizeof(char) * HEADER_SIZE, 0);
+ send_msg(g_sdcard_sockfd, (void*)mntData, sizeof(char) * HEADER_SIZE, 0);
LOG("SDpath is %s", SDpath);
- send(g_sdcard_sockfd, SDpath, mntData->length, 0);
+ send_msg(g_sdcard_sockfd, SDpath, mntData->length, 0);
break;
default:
break;
exit(0);
}
-void setting_device()
+void* setting_device()
{
pthread_detach(pthread_self());
packet->group = STATUS;
packet->action = ActionID;
}
- send(g_get_status_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+ send_msg(g_get_status_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
if (packet->length != 0) {
- send(g_get_status_sockfd, msg, packet->length, 0);
+ send_msg(g_get_status_sockfd, msg, packet->length, 0);
}
}
break;
}
LOG("Location Command : %s", command);
- system(command);
+ system_msg(command);
} else {
*s = '\0';
int mode = atoi(databuf);
if(mode == 1) { // NMEA MODE (LOG MODE)
sprintf(command, "vconftool set -t string db/location/replay/FileName \"%s\"", s+1);
LOG("%s", command);
- system(command);
+ system_msg(command);
memset(command, 0, 256);
sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 1 -f");
LOG("%s", command);
- system(command);
+ system_msg(command);
} else if(mode == 2) {
memset(latitude, 0, 128);
memset(longitude, 0, 128);
// Latitude
sprintf(command, "vconftool set -t double db/location/replay/ManualLatitude %s -f", latitude);
LOG("%s", command);
- system(command);
+ system_msg(command);
// Longitude
sprintf(command, "vconftool set -t double db/location/replay/ManualLongitude %s -f", longitude);
LOG("%s", command);
- system(command);
+ system_msg(command);
}
}
}
-//sdcard event
-void send_guest_server(char* databuf)
-{
- if (!databuf)
- {
- LOG("invalid data buf");
- return;
- }
-
- char buf[32];
- struct sockaddr_in si_other;
- int s, slen=sizeof(si_other);
- FILE* fd;
- char fbuf[16];
- int port;
- fd = fopen("/opt/home/sdb_port.txt", "r");
- LOG("sdb_port.txt fopen fd is %d", fd);
- if(!fd)
- {
- LOG("fopen /opt/home/sdb_port.txt fail");
- port = 3581;
- }
- else
- {
- fgets(fbuf, 16, fd);
- fclose(fd);
- port = atoi(fbuf) + 3;
- }
-
- 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;
- si_other.sin_port = htons(port);
- if (inet_aton(SRV_IP, &si_other.sin_addr)==0) {
- fprintf(stderr, "inet_aton() failed\n");
- }
-
- memset(buf, '\0', sizeof(buf));
- snprintf(buf, sizeof(buf), "4\n%s", databuf);
-
- LOG("sendGuestServer msg: %s", buf);
- if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
- {
- LOG("sendto error!");
- }
-
- close(s);
-}
-
int main( int argc , char *argv[])
{
int state;
if(log_print == 1)
{
// for emuld log file
- system("rm /opt/sensor/emuld.log");
- system("touch /opt/sensor/emuld.log");
+ system_msg("rm /opt/sensor/emuld.log");
+ system_msg("touch /opt/sensor/emuld.log");
}
LOG("start");
state = pthread_mutex_destroy(&mutex_vmconnect);
fprintf(stderr, "emuld exit\n");
+
+ return 0;
}
*/
//#include <vconf.h>
+#include "emuld.h"
#include "emuld_common.h"
+static int file_read(FILE* fd)
+{
+ int ret = 0;
+ int status = 0;
+ ret = fscanf(fd, "%d", &status);
+ if (ret < 0)
+ LOG("fscanf failed with fd: %d", fd);
+
+ return status;
+}
char* message;
char* get_usb_status(void* p)
return 0;
}
- int status = 0;
- fscanf(fd, "%d", &status);
+ int status = file_read(fd);
fclose(fd);
// int to byte
return 0;
}
- int status = 0;
- fscanf(fd, "%d", &status);
+ int status = file_read(fd);
fclose(fd);
// int to byte
return 0;
}
- int level = 0;
- fscanf(fd, "%d", &level);
+ int level = file_read(fd);
fclose(fd);
// int to byte
return 0;
}
- int charge = 0;
- fscanf(fd, "%d", &charge);
+ int charge = file_read(fd);
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);
return 0;
}
- int status = 0;
- fscanf(fd, "%d", &status);
+ int status = file_read(fd);
fclose(fd);
+
// int to byte
message = (char*)malloc(5);
return 0;
}
- int level = 0;
- fscanf(fd, "%d", &level);
+ int level = file_read(fd);
fclose(fd);
// int to byte
char* get_acceleration_value(void* p)
{
+ char* ret = NULL;
FILE* fd = fopen("/opt/sensor/accel/xyz", "r");
if(!fd)
{
message = (char*)malloc(128);
//fscanf(fd, "%d, %d, %d", message);
- fgets(message, 128, fd);
+ ret = fgets(message, 128, fd);
+ if (ret == NULL)
+ LOG("getting accel xyz value failed.");
+
fclose(fd);
LXT_MESSAGE* packet = p;
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);
+ int x = file_read(fd);
fclose(fd);
fd = fopen("/opt/sensor/gyro/gyro_y_raw", "r");
{
return 0;
}
- fscanf(fd, "%d", &y);
+ int y = file_read(fd);
fclose(fd);
fd = fopen("/opt/sensor/gyro/gyro_z_raw", "r");
{
return 0;
}
- fscanf(fd, "%d", &z);
+ int z = file_read(fd);
fclose(fd);
message = (char*)malloc(128);
char* get_magnetic_value(void* p)
{
+ char* ret = NULL;
FILE* fd = fopen("/opt/sensor/geo/tesla", "r");
if(!fd)
{
}
message = (char*)malloc(128);
- fgets(message, 128, fd);
+ ret = fgets(message, 128, fd);
+ if (ret == NULL)
+ LOG("getting tesla value failed.");
fclose(fd);
LXT_MESSAGE* packet = p;
char* get_nfc_status(void* p)
{
+ int ret = 0;
FILE* fd = fopen("/opt/nfc/sdkMsg", "r");
if(!fd)
{
}
message = (char*)malloc(5000);
- fscanf(fd, "%s\n", message);
+ ret = fscanf(fd, "%s\n", message);
+ if (ret < 0)
+ LOG("fscanf failed with fd: %d", fd);
fclose(fd);
LXT_MESSAGE* packet = p;