Ejemplo n.º 1
0
static int mnl_set_suspend(unsigned char suspend)
{
    if (suspend < GPS_PWR_MAX) {
        return mnl_write_attr(MNL_ATTR_SUSPEND, suspend);
    } else {
        MND_ERR("invalid suspend = %d\n", suspend);
        errno = -EINVAL;
        return -1;
    }
}
Ejemplo n.º 2
0
static int mnl_set_pwrsave(unsigned char pwrsave)
{
    if (pwrsave < GPS_PWRSAVE_MAX) {
        return mnl_write_attr(MNL_ATTR_PWRSAVE, pwrsave);
    } else {
        MND_ERR("invalid pwrsave = %d\n", pwrsave);
        errno = -EINVAL;
        return -1;
    }
}
Ejemplo n.º 3
0
static int mnl_set_pwrctl(unsigned char pwrctl)
{
    if (pwrctl < GPS_PWRCTL_MAX) {
        return mnl_write_attr(MNL_ATTR_PWRCTL, pwrctl);
    } else {
        MND_ERR("invalid pwrctl = %d\n", pwrctl);
        errno = -EINVAL;
        return -1;
    }
}
void power_off_3332()
{
	int err;
	err = mnl_write_attr(MNL_ATTR_PWRCTL, GPS_PWRCTL_OFF);    
	if(err != 0)    
	{        
		MND_ERR("GPS_Open: GPS power-on error: %d\n", err);       
		return ;    
	}
	usleep(1000*100);
	return;
}
Ejemplo n.º 5
0
static int mnl_set_state(unsigned char state)
{
    int err;
    if (state < GPS_STATE_MAX) {
        if ((err = mnl_write_attr(MNL_ATTR_STATE, state)))
            return err;
        mnld_data.state = state;
        return 0;
    } else {
        MND_ERR("invalid state = %d\n", state);
        errno = -EINVAL;
        return -1;
    }
}
void META_GPS_Close()
{    
    int err;
    
    META_LOG("META_GPS_Close() 1\n");
    // close GPS_MetaThread
#if 0
    if ((err = pthread_kill(gps_meta_thread_handle, SIGUSR1))) 
    {
        META_LOG("META_GPS_Close: pthread_kill 1 error(%d) \n", err);
    }
    META_LOG("META_GPS_Close() 2\n");
    if ((err = pthread_join(gps_meta_thread_handle, NULL)))
    {
        META_LOG("META_GPS_Close: pthread_kill 2 error(%d) \n", err);
    }
    META_LOG("META_GPS_Close() 3\n");
#endif

    // disconnect to gps driver
    if(sockfd != C_INVALID_SOCKET)
    {
        close(sockfd);
        sockfd = C_INVALID_SOCKET;
    }
    META_LOG("META_GPS_Close() 4\n");

    // kill gps driver (libmnlp)
    if(mnl_pid != C_INVALID_PID)
    {
        kill(mnl_pid, SIGKILL);
    }
    META_LOG("META_GPS_Close() 5\n");
    
    // power off GPS chip
    err = mnl_write_attr("/sys/class/gpsdrv/gps/pwrctl", 0);
    if(err != 0)
    {
        META_LOG("GPS power-off error: %d\n", err);
    }
    META_LOG("META_GPS_Close() 6\n");

	unlink(GPS_PROPERTY);
    META_LOG("META_GPS_Close() 7\n");
    return;
}
Ejemplo n.º 7
0
static void GPS_Close()
{    
    int err;
    
    LOGD(TAG"GPS_Close() 1\n");

    // disconnect to gps driver
    if(sockfd != C_INVALID_SOCKET)
    {
        LOGD(TAG"GPS_Close() 2\n");
        close(sockfd);
        LOGD(TAG"GPS_Close() 3\n");
        sockfd = C_INVALID_SOCKET;
    }
    LOGD(TAG"GPS_Close() 4\n");

    // kill gps driver (libmnlp)
    if(mnl_pid != C_INVALID_PID)
    {
        LOGD(TAG"GPS_Close() 5\n");
        kill(mnl_pid, SIGKILL);
        usleep(500000); //500ms
    }
    LOGD(TAG"GPS_Close() 6\n");
    
    // power off GPS chip
#if !(defined(MTK_GPS_MT6620)||defined(MTK_GPS_MT6628)||defined(MTK_GPS_MT6630)||defined(MTK_GPS_MT6572))
    err = mnl_write_attr("/sys/class/gpsdrv/gps/pwrctl", 0);
    if(err != 0)
    {
        LOGD(TAG"GPS power-off error: %d\n", err);
    }
    LOGD(TAG"GPS_Close() 6\n");
#endif

    return;
}
int META_GPS_Open()
{
    int err;
    pid_t pid;
    int portno;
    struct sockaddr_in serv_addr;
    struct hostent *server;
    char *argv[] = {"/system/xbin/libmnla", "libmnlp"};
	chip_detector();
    META_LOG("META_GPS_Open() 1\n");
    // power on GPS chip
    err = mnl_write_attr("/sys/class/gpsdrv/gps/pwrctl", 4);
    if(err != 0)
    {
        META_LOG("META_GPS_Open: GPS power-on error: %d\n", err);
        return (-1);
    }

    // run gps driver (libmnlp)
    if ((pid = fork()) < 0) 
    {
        META_LOG("META_GPS_Open: fork fails: %d (%s)\n", errno, strerror(errno));
        return (-2);
    } 
    else if (pid == 0)  /*child process*/
    {
		char chip_id[100]={0};
		int fd;
		if((fd = open(GPS_PROPERTY, O_RDONLY)) == -1)
			MND_ERR("open % error, %s\n", GPS_PROPERTY, strerror(errno));	
		if(read(fd, chip_id, sizeof(chip_id)) == -1)
			MND_ERR("open % error, %s\n", GPS_PROPERTY, strerror(errno));
		close(fd);
		unlink(GPS_PROPERTY);
		MND_MSG("chip_id is %s\n", chip_id);
		if (strcmp(chip_id, "0x6620") ==0 )
		{
			MND_MSG("we get MT6620\n");
			char *mnl6620 = "/system/xbin/libmnlp_mt6620";
			argv[0] = mnl6620;	
		}
		else if(strcmp(chip_id, "0x6628") == 0)
		{
			MND_MSG("we get MT6628\n");
			char *mnl6628 = "/system/xbin/libmnlp_mt6628";
			argv[0] = mnl6628;			
		}	
		else if(strcmp(chip_id, "0x6630") == 0)
		{
			MND_MSG("we get MT6630\n");
			char *mnl6630 = "/system/xbin/libmnlp_mt6630";
			argv[0] = mnl6630;				
		}
		else if(strcmp(chip_id, "0x6572") == 0)
		{
			MND_MSG("we get MT6572\n");
			char *mnl6572 = "/system/xbin/libmnlp_mt6572";
			argv[0] = mnl6572;				
		}
		else if(strcmp(chip_id, "0x6582") == 0)
		{
			MND_MSG("we get MT6582\n");
			char *mnl6582 = "/system/xbin/libmnlp_mt6582";
			argv[0] = mnl6582;				
		}
                else if(strcmp(chip_id, "0x6592") == 0)
		{
			MND_MSG("we get MT6592\n");
			char *mnl6592 = "/system/xbin/libmnlp_mt6592";
			argv[0] = mnl6592;				
		}
		else if(strcmp(chip_id, "0x3332") == 0)
		{
			MND_MSG("we get MT3332\n");
			char *mnl3332 = "/system/xbin/libmnlp_mt3332";
			argv[0] = mnl3332;				
		}
		else
		{
			MND_ERR("chip is unknown, chip id is %s\n", chip_id);
			return -1; 
		}        

        MND_MSG("execute: %s \n", argv[0]);
        err = execl(argv[0], "libmnlp", "1Hz=y", NULL);
        if (err == -1){
            MND_MSG("execl error: %s\n", strerror(errno));
            return -1;
        }
        return 0;
    } 
    else  /*parent process*/
    {
        mnl_pid = pid;
        META_LOG("META_GPS_Open: mnl_pid = %d\n", pid);
    }

    // create socket connection to gps driver
    portno = 7000;
    /* Create a socket point */
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) 
    {
        META_LOG("META_GPS_Open: ERROR opening socket");
        return (-4);
    }
  /*  server = gethostbyname("127.0.0.1");
    if (server == NULL) {
        META_LOG("META_GPS_Open: ERROR, no such host\n");
        return (-5);
    }
*/
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
   // bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_addr.s_addr = htons(INADDR_ANY);
    serv_addr.sin_port = htons(portno);

    sleep(3);  // sleep 5sec for libmnlp to finish initialization

    /* Now connect to the server */
    if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) 
    {
         META_LOG("META_GPS_Open: ERROR connecting");
         return (-6);
    }	

    // run GPS_MetaThread
    if (pthread_create(&gps_meta_thread_handle, NULL, GPS_MetaThread, NULL)) 
    {
        META_LOG("META_GPS_Open: error creating dsp thread \n");
        return (-7);
    }
    META_LOG("META_GPS_Open() 2\n");

    return 0;
}
Ejemplo n.º 9
0
int META_GPS_Open()
{
    int err;
    pid_t pid;
    int portno;
    struct sockaddr_in serv_addr;
    struct hostent *server;

    META_LOG("META_GPS_Open() 1\n");
    // power on GPS chip
    err = mnl_write_attr("/sys/class/gpsdrv/gps/pwrctl", 4);
    if(err != 0)
    {
        META_LOG("META_GPS_Open: GPS power-on error: %d\n", err);
        return (-1);
    }

    // run gps driver (libmnlp)
    if ((pid = fork()) < 0) 
    {
        META_LOG("META_GPS_Open: fork fails: %d (%s)\n", errno, strerror(errno));
        return (-2);
    } 
    else if (pid == 0)  /*child process*/
    {
        int err;

        META_LOG("META_GPS_Open: execute: %s\n", "/system/xbin/libmnlp");
        err = execl("/system/xbin/libmnlp", "libmnlp", NULL);
        if (err == -1)
        {
            META_LOG("META_GPS_Open: execl error: %s\n", strerror(errno));
            return (-3);
        }
        return 0;
    } 
    else  /*parent process*/
    {
        mnl_pid = pid;
        META_LOG("META_GPS_Open: mnl_pid = %d\n", pid);
    }

    // create socket connection to gps driver
    portno = 7000;
    /* Create a socket point */
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) 
    {
        META_LOG("META_GPS_Open: ERROR opening socket");
        return (-4);
    }
    server = gethostbyname("127.0.0.1");
    if (server == NULL) {
        META_LOG("META_GPS_Open: ERROR, no such host\n");
        return (-5);
    }

    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_port = htons(portno);

    sleep(3);  // sleep 5sec for libmnlp to finish initialization

    /* Now connect to the server */
    if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) 
    {
         META_LOG("META_GPS_Open: ERROR connecting");
         return (-6);
    }	

    // run GPS_MetaThread
    if (pthread_create(&gps_meta_thread_handle, NULL, GPS_MetaThread, NULL)) 
    {
        META_LOG("META_GPS_Open: error creating dsp thread \n");
        return (-7);
    }
    META_LOG("META_GPS_Open() 2\n");

    return 0;
}
Ejemplo n.º 10
0
static int GPS_Open()
{
    short err;
    pid_t pid;
    int portno;
    struct sockaddr_in serv_addr;
    struct hostent *server;
    int mt3326_fd;
    struct termios termOptions;
    unsigned char query[11]     = {0x04, 0x24, 0x0b, 0x00, 0x08, 0xff, 0x19, 0x00, 0xe5, 0x0d, 0x0a};
    unsigned char response[11]  = {0x04, 0x24, 0x0b, 0x00, 0x1d, 0xff, 0x01, 0xaa, 0x42, 0x0d, 0x0a};
    unsigned char buf[20] = {0};
    int nRead = 0, nWrite = 0;
#if (defined(MTK_GPS_MT6620)||defined(MTK_GPS_MT6628)||defined(MTK_GPS_MT6630)||defined(MTK_GPS_MT6572))
#define DSP_DEV     "/dev/stpgps"
#else
#define DSP_DEV     "/dev/ttyMT1"
#endif

    LOGD(TAG"GPS_Open() 1\n");
    // power on GPS chip
#if !(defined(MTK_GPS_MT6620)||defined(MTK_GPS_MT6628)||defined(MTK_GPS_MT6630)||defined(MTK_GPS_MT6572))
    err = mnl_write_attr("/sys/class/gpsdrv/gps/pwrctl", 4);
    if(err != 0)
    {
        LOGD(TAG"GPS_Open: GPS power-on error: %d\n", err);
        return (-1);
    }
#endif
#if !(defined(MTK_GPS_MT6620)||defined(MTK_GPS_MT6628)||defined(MTK_GPS_MT6630)||defined(MTK_GPS_MT6572))
    // check whether GPS chip is alive or not
	mt3326_fd = open(DSP_DEV, O_RDWR | O_NOCTTY);
	if (mt3326_fd == -1) 
    {
		LOGD(TAG"GPS_Open: Unable to open - %s\n", DSP_DEV);
        /*the process should exit if fail to open UART device*/
        return (-7); 
	}
    else 
    {
		LOGD("GPS_Open: open - %s\n", DSP_DEV);
		fcntl(mt3326_fd, F_SETFL, 0);

		// Get the current options:
		tcgetattr(mt3326_fd, &termOptions);

		// Set 8bit data, No parity, stop 1 bit (8N1):
		termOptions.c_cflag &= ~PARENB;
		termOptions.c_cflag &= ~CSTOPB;
		termOptions.c_cflag &= ~CSIZE;
		termOptions.c_cflag |= CS8 | CLOCAL | CREAD;

		LOGD("GPS_Open: c_lflag=%x,c_iflag=%x,c_oflag=%x\n",termOptions.c_lflag,termOptions.c_iflag,
								termOptions.c_oflag);
		//termOptions.c_lflag

		// Raw mode
		termOptions.c_iflag &= ~(INLCR | ICRNL | IXON | IXOFF | IXANY);
		termOptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);  /*raw input*/
		termOptions.c_oflag &= ~OPOST;  /*raw output*/

		tcflush(mt3326_fd,TCIFLUSH);//clear input buffer
		termOptions.c_cc[VTIME] = 0; /* inter-character timer unused */
		termOptions.c_cc[VMIN] = 0; /* blocking read until 0 character arrives */

        // Set baudrate to 38400 bps
        cfsetispeed(&termOptions, B38400);
		cfsetospeed(&termOptions, B38400);

		/*
		* Set the new options for the port...
		*/
		tcsetattr(mt3326_fd, TCSANOW, &termOptions);
	}
#if !defined(MTK_GPS_MT3332)
    usleep(500000);
    nWrite = write(mt3326_fd, query, sizeof(query));
    LOGD(TAG"nWrite = %d\n", nWrite);
    usleep(500000);
    nRead = read(mt3326_fd, buf, sizeof(buf));
    LOGD(TAG"nRead = %d\n", nRead);
    if(nRead > 0)
    {
        int i;

        for(i = 0; i < nRead; i++)
        {
            LOGD("%02x ", buf[i]);
        }
        LOGD("\n");
    }
    close(mt3326_fd);
    if(nRead < 11) // response should be 11 bytes long
    {
        return (-8);
    }
    usleep(500000);
#endif
#endif
    // run gps driver (libmnlp)
    if ((pid = fork()) < 0) 
    {
        LOGD(TAG"GPS_Open: fork fails: %d (%s)\n", errno, strerror(errno));
        return (-2);
    } 
    else if (pid == 0)  /*child process*/
    {
        int err;

        LOGD(TAG"GPS_Open: execute: %s\n", "/system/xbin/libmnlp");
#if (defined(MTK_GPS_MT6620)||defined(MTK_GPS_MT6628)||defined(MTK_GPS_MT6630)||defined(MTK_GPS_MT6572))
        LOGD("check MTK_GPS_MT6620/MTK_GPS_MT6628/MTK6630/MTK6572)\n");
		int get_time = 5;
		char chip_id[PROPERTY_VALUE_MAX];
		while(get_time-- != 0 && (property_get("persist.mtk.wcn.combo.chipid", chip_id, NULL) !=0))
		{
			usleep(100000);
		}
		LOGD(TAG"chip_id is %s\n", chip_id);
		if (strcmp(chip_id, "0x6620") ==0 )
		{
			LOGD(TAG"we get MT6620\n");
       		err = execl("/system/xbin/libmnlp_mt6620", "libmnlp", "1Hz=y", NULL);
		}
		else if(strcmp(chip_id, "0x6628") == 0)
		{
			LOGD(TAG"we get MT6628\n");
       		err = execl("/system/xbin/libmnlp_mt6628", "libmnlp", "1Hz=y", NULL);		
		}	
		else if(strcmp(chip_id, "0x6630") == 0)
		{
			LOGD(TAG"we get MT6630\n");
       		err = execl("/system/xbin/libmnlp_mt6630", "libmnlp", "1Hz=y", NULL);			
		}   
		else if(strcmp(chip_id, "0x6572") == 0)
		{
			LOGD(TAG"we get MT6572\n");
       		err = execl("/system/xbin/libmnlp_mt6572", "libmnlp", "1Hz=y", NULL);			
		}      
#else
        err = execl("/system/xbin/libmnlp", "libmnlp", NULL);
#endif
        if (err == -1)
        {
            LOGD(TAG"GPS_Open: execl error: %s\n", strerror(errno));
            return (-3);
        }
        return 0;
    } 
    else  /*parent process*/
    {
        mnl_pid = pid;
        LOGD(TAG"GPS_Open: mnl_pid = %d\n", pid);
    }

    // create socket connection to gps driver
    portno = 7000;
    /* Create a socket point */
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) 
    {
        LOGD(TAG"GPS_Open: ERROR opening socket");
        return (-4);
    }
    server = gethostbyname("127.0.0.1");
    if (server == NULL) {
        LOGD(TAG"GPS_Open: ERROR, no such host\n");
        return (-5);
    }

    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_port = htons(portno);

	int try_time = 5;
   	do
   	{
   		LOGD(TAG"GPS_Open: try connecting");
   		sleep(1);// sleep 5sec for libmnlp to finish initialization
    }while(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0 && --try_time);
    if (try_time == 0) 
    {
         LOGD(TAG"GPS_Open: ERROR connecting");
         return (-6);
    }	
	init_flag = 1;
    LOGD(TAG"GPS_Open() 2, set init_flag = 1\n");

    return 0;
}
Ejemplo n.º 11
0
int META_GPS_Open()
{
    int err;
    pid_t pid;
    int portno;
    struct sockaddr_in serv_addr;
    struct hostent *server;

    META_LOG("META_GPS_Open() 1\n");
    // power on GPS chip
    err = mnl_write_attr("/sys/class/gpsdrv/gps/pwrctl", 4);
    if(err != 0)
    {
        META_LOG("META_GPS_Open: GPS power-on error: %d\n", err);
        return (-1);
    }

    // run gps driver (libmnlp)
    if ((pid = fork()) < 0) 
    {
        META_LOG("META_GPS_Open: fork fails: %d (%s)\n", errno, strerror(errno));
        return (-2);
    } 
    else if (pid == 0)  /*child process*/
    {
        int err;

        META_LOG("META_GPS_Open: execute: %s\n", "/system/xbin/libmnlp");
        int get_time = 5;
		char chip_id[PROPERTY_VALUE_MAX];
		while(get_time-- != 0 && (property_get("persist.mtk.wcn.combo.chipid", chip_id, NULL) !=0))
		{
			usleep(100000);
		}
		META_LOG("chip_id is %s\n", chip_id);
		if (strcmp(chip_id, "0x6620") ==0 )
		{
			META_LOG("we get MT6620\n");
			err = execl("/system/xbin/libmnlp_mt6620", "libmnlp", NULL);
		}
		else if(strcmp(chip_id, "0x6628") == 0)
		{
			META_LOG("we get MT6628\n");
			err = execl("/system/xbin/libmnlp_mt6628", "libmnlp", NULL);		
		}	
		else if(strcmp(chip_id, "0x6630") == 0)
		{
			META_LOG("we get MT6630\n");
			err = execl("/system/xbin/libmnlp_mt6630", "libmnlp", NULL);				
		}
		else if(strcmp(chip_id, "0x6572") == 0)
		{
			META_LOG("we get MT6572\n");
			err = execl("/system/xbin/libmnlp_mt6572", "libmnlp", NULL);				
		}
        if (err == -1)
        {
            META_LOG("META_GPS_Open: execl error: %s\n", strerror(errno));
            return (-3);
        }
        return 0;
    } 
    else  /*parent process*/
    {
        mnl_pid = pid;
        META_LOG("META_GPS_Open: mnl_pid = %d\n", pid);
    }

    // create socket connection to gps driver
    portno = 7000;
    /* Create a socket point */
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) 
    {
        META_LOG("META_GPS_Open: ERROR opening socket");
        return (-4);
    }
 /*
    server = gethostbyname("127.0.0.1");
    if (server == NULL) {
        META_LOG("META_GPS_Open: ERROR, no such host\n");
        return (-5);
    }
*/
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
//    bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_addr.s_addr = htons(INADDR_ANY);
    serv_addr.sin_port = htons(portno);

    sleep(3);  // sleep 5sec for libmnlp to finish initialization

    /* Now connect to the server */
    if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) 
    {
         META_LOG("META_GPS_Open: ERROR connecting");
         return (-6);
    }	

    // run GPS_MetaThread
    if (pthread_create(&gps_meta_thread_handle, NULL, GPS_MetaThread, NULL)) 
    {
        META_LOG("META_GPS_Open: error creating dsp thread \n");
        return (-7);
    }
    META_LOG("META_GPS_Open() 2\n");

    return 0;
}