Exemple #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;
}
/* 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;
}