Esempio n. 1
0
/* C entry.
 *
 * \param argc the number of arguments.
 * \param argv the arguments.
 *
 * DO NOT CHANGES THE NAME OF PARAMETERS, otherwise your program will get 
 * a compile error if you are using INIT_CMD_PIPE macro.
 */
int main(int argc, char *argv[])
{
    char buf[128];
    char device_node_path[256];
    char call_number[128];
    int single_level;
    int setup_delay;
    int call_time;
    
    /* init cmd pipe after local variable declaration */
    INIT_CMD_PIPE();

    init_script(atoi(argv[2]));
    
    db_msg("2g tester\n");

    if(script_fetch("2g","device_node",(int*)device_node_path,sizeof(device_node_path)/4)){

        db_warn("2gtester:can't fetch device_node,set to /dev/ttyUSB0\n");
        strcpy(device_node_path,"/dev/ttyUSB0");

    }
    db_msg("device_node=%s\n",device_node_path);
    if(script_fetch("2g","call_number",(int*)call_number,sizeof(call_number)/4)){

        db_warn("2gtester:can't fetch call_number,set to 10086\n");
        strcpy(call_number,"10086");

    }
    if(script_fetch("2g","setup_delay",&setup_delay,1)){

        db_warn("2gtester:can't fetch setup_delay,set to 5s\n");
        setup_delay=5;

    }
    
    if(script_fetch("2g","call_time",&call_time,1)){

        db_warn("2gtester:can't fetch call_time,set to 30s\n");
        call_time=30;

    }

    single_level=setup_2g_device(device_node_path,setup_delay);

    if(single_level==0)
    {
        SEND_CMD_PIPE_FAIL_EX("can't get single level");
        return -1;
    }
    db_msg("single level=%d\n",single_level);
    sprintf(buf,"single level=%d dB\n",single_level);
    SEND_CMD_PIPE_OK_EX(buf);

    //make a telephone call with the specified number
    //return: 0 means ok; -1 means fail;
    if(call_number_2g_device(call_number))
    {
        SEND_CMD_PIPE_FAIL_EX("can't make a call!");
        return -1;
    }
    //call time delay,you can speak th each other in this time
    sleep(call_time);
    //
    hangup_2g_device();
    /* send OK to core if test OK, otherwise send FAIL
     * by using SEND_CMD_PIPE_FAIL().
     */
    SEND_CMD_PIPE_OK_EX("test done");

    return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    char dev_path[64];
    int fd;
    int x=0;
    int y=0;
    int z=0;
    struct input_event event;
    char buf[64];
    char class_path[256];
    int ret;
    
    INIT_CMD_PIPE();

	if(sensor_get_class_path(class_path,argv[4]) < 0) {
		db_error("can't get the sensor class path\n");
        goto err;	
	}

	ret=sprintf(buf,"%d",1);
	if(0!=set_sysfs_input_attr(class_path,"enable",buf,ret)){
	  	db_warn("can't set sensor enable!!! (%s)\n", strerror(errno));
	}
	  
    fd=open_input_device(argv[4]);
    if (fd== -1) {
            db_error("can't open %s(%s)\n",argv[4], strerror(errno));
            goto err;
    }
    /*
    strncpy(dev_path, "/dev/input/event2", 64);

        fd= open(dev_path, O_RDONLY);
        if (fd== -1) {
            db_error("can't open %s(%s)\n", dev_path, strerror(errno));
            goto err;
        }
    */    
        while(1){
        	ret = read(fd, &event, sizeof(event));
        	if(ret==-1){
        		db_error("can't read %s(%s)\n", dev_path, strerror(errno));
        		goto err;
        		}
       if (event.type == EV_ABS) {

			  	switch (event.code) {
		 	   	case ABS_X:
				    x =event.value;
             	  //db_msg("senser data is: x=%d\n",x);
                         break;
				case ABS_Y:
					y =event.value;
                  // db_msg("senser date is: y=%d\n",y);
					break;				
				case ABS_Z:
					z =event.value;
                 //   db_msg("senser date is:z=%d\n",z);
					break;		
					}
				sprintf(buf,"(%d,%d,%d)",x,y,z);
			  //db_msg("senser data is:x=%d,y=%d,z=%d\n",x,y,z);
				SEND_CMD_PIPE_OK_EX(buf);
                }
        	
       sleep(1);

    }
     close(fd);
err:
    SEND_CMD_PIPE_FAIL();
    EXIT_CMD_PIPE();
    return 0;
}
Esempio n. 3
0
/* C entry.
 *
 * \param argc the number of arguments.
 * \param argv the arguments.
 *
 * DO NOT CHANGES THE NAME OF PARAMETERS, otherwise your program will get 
 * a compile error if you are using INIT_CMD_PIPE macro.
 */
int main(int argc, char *argv[])
{
	char device_node_path[256];
	int setup_delay;
	int call_time;
	int loop_ctl_pipe_fd;
	int loop_mode_flag = 1;
	int ret = -1;

	/* init cmd pipe after local variable declaration */
	INIT_CMD_PIPE();

	init_script(atoi(argv[2]));
	db_msg("2glooptester\n");
	if(script_fetch("loop","device_node",(int*)device_node_path,sizeof(device_node_path)/4)){
		db_warn("2glooptester:can't fetch device_node,set to /dev/ttyUSB0\n");
		strcpy(device_node_path,"/dev/ttyUSB0");
	}
	db_msg("device_node=%s\n",device_node_path);

	if(script_fetch("loop","setup_delay",&setup_delay,1)){
		db_warn("2glooptester:can't fetch setup_delay,set to 5s\n");
		setup_delay=5;
	}

	if(script_fetch("loop","call_time",&call_time,1)){
		db_warn("2glooptester:can't fetch call_time,set to 30s\n");
		call_time=30;
	}
/*	single_level=setup_device(device_node_path,setup_delay);
	if(single_level==0)
	{
		SEND_CMD_PIPE_FAIL_EX("can't get single level");
		return -1;
	}*/
	
	loop_ctl_pipe_fd = open(LOOP_CTL_PIPE_NAME,O_RDONLY ,0); 					
	if(loop_ctl_pipe_fd==NULL){
		printf("2glooptester:fail to open loop_ctl_pipe\n");
	}
	setup_device(device_node_path,setup_delay);
LOOP_TEST:
	if(enter_loop_mode()){ 
		SEND_CMD_PIPE_FAIL_EX("failed:loop\n");
		return 0;
	}
	if(loop_test()){
		SEND_CMD_PIPE_FAIL_EX("failed:sound_loop\n");
		return 0;
	}
	SEND_CMD_PIPE_OK();

	//call time delay,you can speak th each other in this time
//	sleep(call_time);
//	exit_loop_mode();
	/* send OK to core if test OK, otherwise send FAIL
	 * by using SEND_CMD_PIPE_FAIL().
	 */
	SEND_CMD_PIPE_OK_EX("test done");
	while(1){
		db_msg("get loop_ctl_pipe\n");
		ret = read(loop_ctl_pipe_fd,&loop_mode_flag,sizeof(loop_mode_flag));
		if(ret == -1){
			db_msg("no data avlaible\n");
		}
		db_msg("loop mode ON \n");
		if(!loop_mode_flag){
				db_msg("exit_loop_mode\n");
				exit_loop_mode();
				break;
		}
		sleep(1);
	}
	while(1){
		ret = read(loop_ctl_pipe_fd,&loop_mode_flag,sizeof(loop_mode_flag));
		if(ret == -1){
			db_msg("no data avlaible\n");
		}
		db_msg("loop mode OFF \n");
		sleep(2);
		if(loop_mode_flag)
			goto LOOP_TEST;
	}
	close(loop_ctl_pipe_fd);
	return 0;
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    char dev_path[64];
    FILE *fp;
    char evt_path[32];
    int fd;
    int version;
    unsigned short id[4];
    char name[32];
    unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
    int i, j, k;
    int abs[5];
    struct input_event evt[64];
    int rd;
    char buf[64];
    char pre_key[64];

    INIT_CMD_PIPE();

    strncpy(dev_path, "/sys/class/input/event0/device/name", 64);
    for (i = 0; i < 5; i++) {
        dev_path[22] = '0' + i;
        if (access(dev_path, F_OK)) {
            db_error("can't access %s(%s)\n", dev_path, strerror(errno));
            goto err;
        }

        fp = fopen(dev_path, "r");
        if (fp == NULL) {
            db_error("can't open %s(%s)\n", dev_path, strerror(errno));
            goto err;
        }

        if (fgets(evt_path, 32, fp) == NULL) {
            db_error("can't read %s(%s)\n", dev_path, strerror(errno));
            goto err;
        }

        if (match_ir(evt_path) == 0) {
            fclose(fp);
            break;
        }
        fclose(fp);
    }

    if (i == 5) {
        db_error("NO!!! ir input found\n");
        goto err;
    }

    strncpy(evt_path, "/dev/input/event0", 32);
    evt_path[16] = '0' + i;
    if ((fd = open(evt_path, O_RDONLY)) < 0) {
        db_error("can't open %s(%s)\n", evt_path, strerror(errno));
        goto err;
    }

    if (ioctl(fd, EVIOCGVERSION, &version)) {
        db_error("can't get version\n");
        goto err;
    }
    db_debug("Input driver version is %d.%d.%d\n", 
            version >> 16, (version >> 8) & 0xff, version & 0xff);

    ioctl(fd, EVIOCGID, id);
    db_debug("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
            id[ID_BUS], id[ID_VENDOR], id[ID_PRODUCT], id[ID_VERSION]);

    ioctl(fd, EVIOCGNAME(sizeof(name)), name);
    db_debug("Input device name: \"%s\"\n", name);

    memset(bit, 0, sizeof(bit));
    ioctl(fd, EVIOCGBIT(0, sizeof(bit[0])), bit[0]);
    db_dump("Supported events:\n");

    for (i = 0; i < EV_MAX; i++) {
        if (test_bit(i, bit[0])) {
            db_dump("    Event type %d (%s)\n", i, events[i] ? events[i] : "?");
            if (!i)
                continue;

            ioctl(fd, EVIOCGBIT(i, sizeof(bit[0])), bit[i]);
            for (j = 0; j < KEY_MAX; j++) {
                if (test_bit(j, bit[i])) {
                    db_dump("        Event code %d (%s)\n", j, names[i] ? (names[i][j] ? names[i][j] : "?") : "?");
                    if (i == EV_ABS) {
                        ioctl(fd, EVIOCGABS(j), abs);
                        for (k = 0; k < 5; k++) {
                            if ((k < 3) || abs[k])
                                printf("%s %6d\n", absval[k], abs[k]);
                        }
                    }
                }
            }
        }
    }

    memset(pre_key, 0, sizeof(pre_key));
    while (1) {
        rd = read(fd, evt, sizeof(struct input_event) * 64);

        if (rd < (int)sizeof(struct input_event)) {
            db_error("error in reading\n");
            goto err;
        }

        for (i = 0; i < rd / sizeof(struct input_event); i++) {
            if (evt[i].type == EV_SYN) {
                ;
            }
            else if (evt[i].type == EV_MSC && (evt[i].code == MSC_RAW || evt[i].code == MSC_SCAN)) {
                db_debug("%s, %s(%d, %02x)\n", 
                        events[evt[i].type] ? events[evt[i].type] : "?", 
                        names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", 
                        evt[i].code, 
                        evt[i].value);
                if (evt[i].value)
                    continue;

                if (pre_key[0]) {
                    snprintf(buf, sizeof(buf), "%s, %s", 
                            names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", 
                            pre_key);
                }
                else {
                    snprintf(buf, sizeof(buf), "%s", 
                            names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?");
                }
                snprintf(pre_key, sizeof(pre_key), "%s", buf);
                SEND_CMD_PIPE_OK_EX(buf);
            }
            else {
                db_debug("%s, %s(%d, %02x)\n", 
                        events[evt[i].type] ? events[evt[i].type] : "?", 
                        names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", 
                        evt[i].code, 
                        evt[i].value);
                if (evt[i].value)
                    continue;

                if (pre_key[0]) {
                    snprintf(buf, sizeof(buf), "%s, %s", 
                            names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", 
                            pre_key);
                }
                else {
                    snprintf(buf, sizeof(buf), "%s", 
                            names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?");
                }
                snprintf(pre_key, sizeof(pre_key), "%s", buf);
                SEND_CMD_PIPE_OK_EX(buf);
            }
        }
    }

err:
    SEND_CMD_PIPE_FAIL();
    EXIT_CMD_PIPE();
    return 0;
}