Пример #1
0
static void rt9396_wakeup(struct rt9396_driver_data *drvdata)
{
	if (!drvdata || drvdata->state == NORMAL_STATE)
		return;

   printk("[rt9396_wakeup] pre intensity:%d !!!!!\n", drvdata->intensity);
	if(rt9396_powerstate == SLEEP_STATE){
			rt9396_powerstate = NORMAL_STATE;
	}
//LGE_CHANGE_S, [[email protected]] , 2012-07-09
	//For backlight timing
	if(bl_chargerlogo == 1)
		msleep(50);
	else
		msleep(100);
//LGE_CHANGE_E, [[email protected]] , 2012-07-09	
	if (drvdata->state == POWEROFF_STATE) {
		//rt9396_poweron(drvdata);
	} else if (drvdata->state == SLEEP_STATE) {
		if (drvdata->mode == NORMAL_MODE) 
		{
         #if 0 /*2012-09-26 junghoon-kim([email protected]) LCD-LED brightness bug.[START]*/
			rt9396_set_table(drvdata, drvdata->cmds.normal);			
         #endif /*2012-09-26 junghoon-kim([email protected]) porting from bu61800 driver [END]*/
			drvdata->state = NORMAL_STATE;
		} else if (drvdata->mode == ALC_MODE) {
			//nothing
		}
	}

   #if 0//[V3][junghoon79.kim][2012.9.16] no file ( LG_diag_testmode.c )
	/* LGE_CHANGE_S : Test Mode(Flight Mode)
	 * 2012-07-05, [email protected]
	 * [L38C][Test Mode][Common] Modify to automatically turn off LCD while test mode flight mode on.
	 */
	// LGE_CHANGE_S [[email protected]][07-03][start]
	// minimum current at SMT
	if(LGF_TestMode_Is_SleepMode())
	{
		if(rt9396_powerstate == NORMAL_STATE )
		{
				LGF_SendKey(116);	// power key
				set_operation_mode(true);
		}
	}
	// LGE_CHANGE_E [[email protected]][07-03][end]
	/* LGE_CHANGE_E : Test Mode(Flight Mode) */
   #endif

}
Пример #2
0
static void rt9396_sleep(struct rt9396_driver_data *drvdata)
{
	if (!drvdata || drvdata->state == SLEEP_STATE)
		return;	

printk("[rt9396_sleep] pre intensity:%d !!!!!\n", drvdata->intensity);
	switch (drvdata->mode) {
		case NORMAL_MODE:
			drvdata->state = SLEEP_STATE;
			rt9396_set_table(drvdata, drvdata->cmds.sleep);			
			break;

		case ALC_MODE: //not use
			break;
		default:
			eprintk("Invalid Mode\n");
			break;
	}

//2012-11-19 junghoon.kim([email protected]) sleep current issue in cal&auto test(LCD dettach state)[START]
#ifdef CONFIG_LGE_SUPPORT_MINIOS
     if(LGE_BOOT_MODE_MINIOS == get_lge_boot_mode())
     {
         //eprintk("[rt9396_sleep] dddd LGE_BOOT_MODE_MINIOS : gpio_set_value\n");
         gpio_set_value(drvdata->gpio, 1);
         mdelay(1);
         gpio_set_value(drvdata->gpio, 0);
     }
#endif
//2012-11-19 junghoon.kim([email protected]) sleep current issue in cal&auto test(LCD dettach state)[END]

   #if 0//[V3][junghoon79.kim][2012.9.16] no file ( LG_diag_testmode.c )
	// LGE_CHANGE_S [[email protected]][07-03][start]
	// minimum current at SMT
	if(LGF_TestMode_Is_SleepMode()) {
		set_operation_mode(false);
	} 
   else 
    #endif
	{
		if(rt9396_powerstate == NORMAL_STATE){
			rt9396_powerstate = SLEEP_STATE;
		}
	}
	// LGE_CHANGE_E [[email protected]][end]
}
int main()
{
	float target_torque = -25.0; 	// mNm
	float actual_torque = 0;		// mNm
	float tolerance = 0.76; 		// mNm
	int actual_position = 0;		// ticks
	int actual_velocity = 0;		// rpm
	int ack = 0;
	int sdo_update = 1;             // 1- yes / 0 - no
	int slave_number = 0;

	/* Initialize Ethercat Master */
	init_master(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	/* Initialize all connected nodes with Mandatory Motor Configurations (specified under config/motor/)*/
	init_nodes(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	/* Initialize torque parameters */
	initialize_torque(slave_number, slv_handles);

	/* Initialize the node specified with slave_number with Profile Torque(TQ) configurations (specified under config/motor/)*/
	set_operation_mode(TQ, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	/* Enable operation of node in TQ mode */
	enable_operation(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);


	while(1)
	{
		/* Update the process data (EtherCat packets) sent/received from the node */
		pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

		if(master_setup.op_flag)		/*Check if the master is active*/
		{
			/* Send target torque for the node specified by slave_number */
			set_torque_mNm(target_torque, slave_number, slv_handles);

			/* Check if target torque is reached with specified tolerance */
			ack = target_torque_reached(slave_number, target_torque, tolerance, slv_handles);

			/* Read actual node sensor values */
			actual_torque= get_torque_actual_mNm(slave_number, slv_handles);
			actual_position = get_position_actual_ticks(slave_number, slv_handles);
			actual_velocity = get_velocity_actual_rpm(slave_number, slv_handles);
			printf("target_torque %f \n",target_torque);
			printf("actual_torque %f position %d velocity %d ack %d\n", actual_torque, actual_position, actual_velocity, ack);
		}

		if(ack == 1)
		{
			break;
		}
	}

	printf("reached \n");


	ack = 0;
	while(!ack)
	{
		pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

		if(master_setup.op_flag)	/*Check if the master is active*/
		{
			actual_torque =  get_torque_actual_mNm(slave_number, slv_handles);
			actual_position = get_position_actual_ticks(slave_number, slv_handles);
			actual_velocity = get_velocity_actual_rpm(slave_number, slv_handles);
			if(actual_torque > tolerance || actual_torque < -tolerance)
			{
				/* Quick stop Profile Torque mode (for emergency) */
				quick_stop_torque(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);
				ack = 1;
			}
			printf("actual_torque %f position %d velocity %d ack %d\n", actual_torque, actual_position, actual_velocity, ack);
		}
	}
	printf("reached \n");

	/* Regain control of node to continue after quick stop */
	renable_ctrl_quick_stop(TQ, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	set_operation_mode(TQ, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	enable_operation(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	/*target_torque = 15.0; // mNm
	while(1)
	{
		pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

		if(master_setup.op_flag)	// Check if the master is active
		{

			set_torque_mNm(target_torque, slave_number, slv_handles);
			ack = target_torque_reached(slave_number, target_torque, tolerance, slv_handles);
			actual_torque = get_torque_actual_mNm(slave_number, slv_handles);
			printf("target_torque %f \n",target_torque);
			printf("actual_torque %f ack %d\n", actual_torque, ack);
		}

		if(ack == 1)
		{
			break;
		}
	}
*/
	/*printf("reached \n");

	while(1)
	{
		pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

		if(master_setup.op_flag)//Check if we are up
		{

			actual_torque = get_torque_actual_mNm(slave_number, slv_handles);
			printf("actual_torque %f \n",actual_torque);
		}
	}*/


	/* Shutdown node operations */
	shutdown_operation(TQ, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	return 0;
}
int main() {

    int target_velocity = 2000; //rpm
    int acceleration = 1000; //rpm/s
    int deceleration = 1000; //rpm/s

    int actual_velocity = 0; // rpm
    int actual_position; // ticks
    float actual_torque; // mNm
    int steps = 0;
    int velocity_ramp = 0; // rpm

    /* Initialize Ethercat Master */
    init_master(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

    /* Initialize all connected nodes with Mandatory Motor Configurations (specified in config/motor/)*/
    init_nodes(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

    /* Initialize the node specified with ECAT_SLAVE_0 with CSV configurations (specified in config/motor/)*/
    set_operation_mode(CSV, ECAT_SLAVE_0, &master_setup, slv_handles,
            TOTAL_NUM_OF_SLAVES);

    /* Enable operation of node in CSV mode */
    enable_operation(ECAT_SLAVE_0, &master_setup, slv_handles,
            TOTAL_NUM_OF_SLAVES);

    /* Initialize velocity profile parameters */
    steps = init_velocity_profile_params(target_velocity,
            actual_velocity, acceleration, deceleration, ECAT_SLAVE_0,
            slv_handles);

    /* catch interrupt signal */
    signal(SIGINT, INThandler);

    /* Just for better printing result */
    printf("\n");
    system("setterm -cursor off");

    while(1)
    {
        if (master_setup.op_flag && actual_velocity == 0) /*Check if the master is active and we haven't started moving yet*/
        {
            for (int step = 1; step < steps + 1; step++) {
                /* Update the process data (EtherCat packets) sent/received from the node */
                pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

                /* Generate target velocity steps */
                velocity_ramp = generate_profile_velocity(step, ECAT_SLAVE_0,
                        slv_handles);

                /* Send target velocity for the node specified by ECAT_SLAVE_0 */
                set_velocity_rpm(velocity_ramp, ECAT_SLAVE_0, slv_handles);

                /* Read actual node sensor values */
                actual_velocity
                        = get_velocity_actual_rpm(ECAT_SLAVE_0, slv_handles);
                actual_position = get_position_actual_ticks(ECAT_SLAVE_0,
                        slv_handles);
                actual_torque = get_torque_actual_mNm(ECAT_SLAVE_0, slv_handles);

                printf("\r    Velocity: %d    Position: %d    Torque: %f        ",
                        actual_velocity, actual_position, actual_torque);
            }
        }
        else if (break_loop){
            break;
        }
        else {
            /* Update the process data (EtherCat packets) sent/received from the node */
            pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);
            /* Read actual node sensor values */
            actual_velocity
                    = get_velocity_actual_rpm(ECAT_SLAVE_0, slv_handles);
            actual_position = get_position_actual_ticks(ECAT_SLAVE_0,
                    slv_handles);
            actual_torque = get_torque_actual_mNm(ECAT_SLAVE_0, slv_handles);

            printf("\r    Velocity: %d    Position: %d    Torque: %f        ",
                    actual_velocity, actual_position, actual_torque);
        }
    }
    printf("\n");

    /* Quick stop velocity mode (for emergency) */
    quick_stop_velocity(ECAT_SLAVE_0, &master_setup, slv_handles,
            TOTAL_NUM_OF_SLAVES);

    /* Regain control of node to continue after quick stop */
    renable_ctrl_quick_stop(CSV, ECAT_SLAVE_0, &master_setup, slv_handles,
            TOTAL_NUM_OF_SLAVES);

    set_operation_mode(CSV, ECAT_SLAVE_0, &master_setup, slv_handles,
            TOTAL_NUM_OF_SLAVES);

    enable_operation(ECAT_SLAVE_0, &master_setup, slv_handles,
            TOTAL_NUM_OF_SLAVES);

    /* Shutdown node operations */
    shutdown_operation(CSV, ECAT_SLAVE_0, &master_setup, slv_handles,
            TOTAL_NUM_OF_SLAVES);

    /* Just for better printing result */
    system("setterm -cursor on");

    return 0;
}
int main()
{
	int flag = 0;

	int acceleration = 350;				// rpm/s
	int deceleration = 350;   			// rpm/s
	int velocity = 350;					// rpm
	int actual_position = 0;			// ticks
	int target_position = 0;			// ticks
	int actual_velocity;				// rpm
	float actual_torque;				// mNm
	int steps = 0;
	int i = 1;
	int position_ramp = 0;
	int ack;
	int home_velocity = 250;      		// rpm
	int home_acceleration = 250;		// rpm/s
	int sdo_update = 1;                 // 1- yes / 0 - no
	int slave_number = 0;

	/* Initialize Ethercat Master */
	init_master(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	/* Initialize torque parameters */
	initialize_torque(slave_number, slv_handles);

	/* Initialize all connected nodes with Mandatory Motor Configurations (specified under config/motor/)*/
	init_nodes(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	/* Initialize the node specified with slave_number with Homing configurations (specified under config/motor/)*/
	set_operation_mode(HM, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	/* Enable operation of node in Homing mode */
	enable_operation(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	start_homing(&master_setup, slv_handles, home_velocity, home_acceleration, slave_number, TOTAL_NUM_OF_SLAVES);

	/* Shutdown Homing Operation */
	shutdown_operation(HM, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	/*
	 * Acquire actual position from the node a few times after homing and
	 * set it as target position. (wait for controller to settle)
	 */
	i = 0;
	int difference = 1500;
	int previous=0;
	while(1)
	{

		pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

		if(master_setup.op_flag)	//Check if the master is active
		{
			actual_position = get_position_actual_ticks(slave_number, slv_handles);
			target_position = actual_position;
			set_profile_position_ticks(target_position, slave_number, slv_handles);
			i = i+1;

			difference = actual_position - previous;
			if(difference <1 && difference >-1)
			{
				//printf(" difference %d act %d\n",difference, actual_position);
				break;
			}

			previous = actual_position;

			//printf(" difference %d act %d\n",difference, actual_position);
		}

	}


	/* Now initialize the node specified with slave_number with CSP configurations (specified under config/motor/)*/
	set_operation_mode(CSP, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	/* Enable operation of node in CSP mode */
	enable_operation(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	/* Initialize position profile parameters */
	initialize_position_profile_limits(slave_number, slv_handles);//*/



	/* Now setting a new target position after homing */
	target_position = get_position_actual_ticks(slave_number, slv_handles) + 5000;
	if(target_position > 35000)
		target_position = 35000;
	printf(" target_position %d\n", target_position);

	/*calculate the no. of steps for the profile*/
	steps = init_position_profile_params(target_position, actual_position, velocity, acceleration, \
			deceleration, slave_number, slv_handles);

	/* Execute the position profile steps in a loop */
	i = 1;
	while(1)
	{
		/* Update the process data (EtherCat packets) sent/received from the node */
		pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

		if(master_setup.op_flag)	/*Check if the master is active*/
		{
			if(i<steps)
			{
				/* Generate target position steps */
				position_ramp = generate_profile_position(i, slave_number, slv_handles);

				/* Send target position for the node specified by slave_number */
				set_position_ticks(position_ramp, slave_number, slv_handles);
				i = i+1;
			}
			if(i >= steps)
			{
				printf("ack received");
				break;
			}
			//printf("actual position %d \n", get_position_actual_ticks(slave_number, slv_handles));

			/* Read actual node sensor values */
			actual_position = get_position_actual_ticks(slave_number, slv_handles);
			actual_velocity = get_velocity_actual_rpm(slave_number, slv_handles);
			actual_torque = get_torque_actual_mNm(slave_number, slv_handles);
			printf("actual position %d actual velocity %d actual_torque %f\n", actual_position, actual_velocity, actual_torque);
		}
	}

	/* Quick stop position mode (for emergency) */
	quick_stop_position(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	/* Regain control of node to continue after quick stop */
	renable_ctrl_quick_stop(CSP, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);

	set_operation_mode(CSP, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);			// set operation mode to CSP

	enable_operation(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);				// enable operation

	/* Shutdown node operations */
	shutdown_operation(CSP, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES);			// stop the node operation. or can continue with new position profile

	return 0;
}
Пример #6
0
int main(int argc, char *argv[])
{
	int ret, i, action = -1;
	char config_file[PATH_MAX] = {};
	int type = 0;
	struct utsname u;
	int version, major, minor;

	/* Check kernel version: it must be >= 2.6.18 */
	if (uname(&u) == -1) {
		fprintf(stderr, "Can't retrieve kernel version via uname()\n");
		exit(EXIT_FAILURE);
	}
	sscanf(u.release, "%d.%d.%d", &version, &major, &minor);
	if (version < 2 && major < 6 && minor < 18) {
		fprintf(stderr, "Linux kernel version must be >= 2.6.18\n");
		exit(EXIT_FAILURE);
	}

	for (i=1; i<argc; i++) {
		switch(argv[i][1]) {
		case 'd':
			set_operation_mode(&type, DAEMON, argv);
			break;
		case 'c':
			set_operation_mode(&type, REQUEST, argv);
			i = set_action_by_table(i, argc, argv,
						CT_COMMIT, EXP_COMMIT,
						ALL_COMMIT, &action);
			break;
		case 'i':
			set_operation_mode(&type, REQUEST, argv);
			i = set_action_by_table(i, argc, argv,
						CT_DUMP_INTERNAL,
						EXP_DUMP_INTERNAL,
						CT_DUMP_INTERNAL, &action);
			break;
		case 'e':
			set_operation_mode(&type, REQUEST, argv);
			i = set_action_by_table(i, argc, argv,
						CT_DUMP_EXTERNAL,
						EXP_DUMP_EXTERNAL,
						CT_DUMP_EXTERNAL, &action);
			break;
		case 'C':
			if (++i < argc) {
				strncpy(config_file, argv[i], PATH_MAX);
				if (strlen(argv[i]) >= PATH_MAX){
					config_file[PATH_MAX-1]='\0';
					fprintf(stderr, "Path to config file "
						        "to long. Cutting it "
							"down to %d characters",
							PATH_MAX);
				}
				break;
			}
			show_usage(argv[0]);
			fprintf(stderr, "Missing config filename\n");
			break;
		case 'F':
			set_operation_mode(&type, REQUEST, argv);
			i = set_action_by_table(i, argc, argv,
						CT_FLUSH_MASTER,
						EXP_FLUSH_MASTER,
						ALL_FLUSH_MASTER, &action);
			break;
		case 'f':
			set_operation_mode(&type, REQUEST, argv);
			if (i+1 < argc && argv[i+1][0] != '-') {
				if (strncmp(argv[i+1], "internal",
					    strlen(argv[i+1])) == 0) {
					action = CT_FLUSH_INT_CACHE;
					i++;
				} else if (strncmp(argv[i+1], "external",
						 strlen(argv[i+1])) == 0) {
					action = CT_FLUSH_EXT_CACHE;
					i++;
				} else {
					fprintf(stderr, "ERROR: unknown "
							"parameter `%s' for "
							"option `-f'\n",
							argv[i+1]);
					exit(EXIT_FAILURE);
				}
			} else {
				/* default to general flushing */
				action = ALL_FLUSH_CACHE;
			}
			break;
		case 'R':
			set_operation_mode(&type, REQUEST, argv);
			i = set_action_by_table(i, argc, argv,
						CT_RESYNC_MASTER,
						EXP_RESYNC_MASTER,
						ALL_RESYNC_MASTER, &action);
			break;
		case 'B':
			set_operation_mode(&type, REQUEST, argv);
			action = SEND_BULK;
			break;
		case 'S':
			set_operation_mode(&type, REQUEST, argv);
			action = SEND_BULKEXP;
			break;
		case 't':
			set_operation_mode(&type, REQUEST, argv);
			action = RESET_TIMERS;
			break;
		case 'k':
			set_operation_mode(&type, REQUEST, argv);
			action = KILL;
			break;
		case 's':
			set_operation_mode(&type, REQUEST, argv);
			/* we've got a parameter */
			if (i+1 < argc && argv[i+1][0] != '-') {
				if (strncmp(argv[i+1], "network",
					    strlen(argv[i+1])) == 0) {
					action = STATS_NETWORK;
					i++;
				} else if (strncmp(argv[i+1], "cache",
						 strlen(argv[i+1])) == 0) {
					action = STATS_CACHE;
					i++;
				} else if (strncmp(argv[i+1], "runtime",
						 strlen(argv[i+1])) == 0) {
					action = STATS_RUNTIME;
					i++;
				} else if (strncmp(argv[i+1], "multicast",
						 strlen(argv[i+1])) == 0) {
					fprintf(stderr, "WARNING: use `link' "
						"instead of `multicast' as "
						"parameter.\n");
					action = STATS_LINK;
					i++;
				} else if (strncmp(argv[i+1], "link",
						 strlen(argv[i+1])) == 0) {
					action = STATS_LINK;
					i++;
				} else if (strncmp(argv[i+1], "rsqueue",
						strlen(argv[i+1])) == 0) {
					action = STATS_RSQUEUE;
					i++;
				} else if (strncmp(argv[i+1], "process",
						 strlen(argv[i+1])) == 0) {
					action = STATS_PROCESS;
					i++;
				} else if (strncmp(argv[i+1], "queue",
						strlen(argv[i+1])) == 0) {
					action = STATS_QUEUE;
					i++;
				} else if (strncmp(argv[i+1], "ct",
						strlen(argv[i+1])) == 0) {
					action = STATS;
					i++;
				} else if (strncmp(argv[i+1], "expect",
						strlen(argv[i+1])) == 0) {
					action = EXP_STATS;
					i++;
				} else {
					fprintf(stderr, "ERROR: unknown "
							"parameter `%s' for "
							"option `-s'\n",
							argv[i+1]);
					exit(EXIT_FAILURE);
				}
			} else {
				/* default to general statistics */
				action = STATS;
			}
			break;
		case 'n':
			set_operation_mode(&type, REQUEST, argv);
			action = REQUEST_DUMP;
			break;
		case 'x':
			if (action == CT_DUMP_INTERNAL)
				action = CT_DUMP_INT_XML;
			else if (action == CT_DUMP_EXTERNAL)
				action = CT_DUMP_EXT_XML;
			else if (action == EXP_DUMP_INTERNAL)
				action = EXP_DUMP_INT_XML;
			else if (action == EXP_DUMP_EXTERNAL)
				action = EXP_DUMP_EXT_XML;
			else {
				show_usage(argv[0]);
				fprintf(stderr, "Error: Invalid parameters\n");
				exit(EXIT_FAILURE);

			}
			break;
		case 'v':
			show_version();
			exit(EXIT_SUCCESS);
		case 'h':
			show_usage(argv[0]);
			exit(EXIT_SUCCESS);
		default:
			show_usage(argv[0]);
			fprintf(stderr, "Unknown option: %s\n", argv[i]);
			return 0;
			break;
		}
	}

	if (!config_file[0])
		strcpy(config_file, DEFAULT_CONFIGFILE);

	umask(0177);

	if ((ret = init_config(config_file)) == -1) {
		fprintf(stderr, "can't open config file `%s'\n", config_file);
		exit(EXIT_FAILURE);
	}

	if (type == REQUEST) {
		if (do_local_request(action, &conf.local, local_step) == -1) {
			fprintf(stderr, "can't connect: is conntrackd "
					"running? appropriate permissions?\n");
			exit(EXIT_FAILURE);
		}
		exit(EXIT_SUCCESS);
	}

	/*
	 * Setting up logging
	 */
	if (init_log() == -1)
		exit(EXIT_FAILURE);

	/*
	 * lock file
	 */
	/*ret = open(CONFIG(lockfile), O_CREAT | O_EXCL | O_TRUNC, 0600);
	if (ret == -1) {
		fprintf(stderr, "lockfile `%s' exists, perhaps conntrackd "
			        "already running?\n", CONFIG(lockfile));
		exit(EXIT_FAILURE);
	}
	close(ret);*/

	/*
	 * Setting process priority and scheduler
	 */
	set_nice_value(CONFIG(nice));

	if (CONFIG(sched).type != SCHED_OTHER) {
		struct sched_param schedparam = {
			.sched_priority = CONFIG(sched).prio,
		};

		ret = sched_setscheduler(0, CONFIG(sched).type, &schedparam);
		if (ret == -1) {
			perror("sched");
			exit(EXIT_FAILURE);
		}
	}

	/*
	 * initialization process
	 */

	if (init() == -1) {
		close_log();
		fprintf(stderr, "ERROR: conntrackd cannot start, please "
				"check the logfile for more info\n");
		unlink(CONFIG(lockfile));
		exit(EXIT_FAILURE);
	}

	do_chdir("/");
	close(STDIN_FILENO);

	sd_ct_watchdog_init();

	/* Daemonize conntrackd */
	if (type == DAEMON) {
		pid_t pid;

		if ((pid = fork()) == -1) {
			perror("fork has failed: ");
			exit(EXIT_FAILURE);
		} else if (pid) {
			sd_ct_mainpid(pid);
			exit(EXIT_SUCCESS);
		}

		setsid();

		close(STDOUT_FILENO);
		close(STDERR_FILENO);

		dlog(LOG_NOTICE, "-- starting in daemon mode --");
	} else
		dlog(LOG_NOTICE, "-- starting in console mode --");

	sd_ct_init();

	/*
	 * run main process
	 */
	select_main_loop();
	return 0;
}