コード例 #1
0
ファイル: aserver.c プロジェクト: Shield-Firewall/c-icap
int main(int argc, char **argv)
{
#if ! defined(_WIN32)
     __log_error = (void (*)(void *, const char *,...)) log_server;     /*set c-icap library log  function */
#else
     __vlog_error = vlog_server;        /*set c-icap library  log function */
#endif

     mem_init();
     init_internal_lookup_tables();
     ci_acl_init();
     init_http_auth();
     if (init_body_system() != CI_OK) {
         ci_debug_printf(1, "Can not initialize body system\n");
         exit(-1);
     }
     ci_txt_template_init();
     ci_txt_template_set_dir(DATADIR"templates");
     commands_init();

     if (!(CI_CONF.MAGIC_DB = ci_magic_db_load(CI_CONF.magics_file))) {
          ci_debug_printf(1, "Can not load magic file %s!!!\n",
                          CI_CONF.magics_file);
     }
     init_conf_tables();
     request_stats_init();
     init_modules();
     init_services();
     config(argc, argv);
     compute_my_hostname();
     ci_debug_printf(2, "My hostname is:%s\n", MY_HOSTNAME);

     if (!log_open()) {
          ci_debug_printf(1, "Can not init loggers. Exiting.....\n");
          exit(-1);
     }

#if ! defined(_WIN32)
     if (is_icap_running(CI_CONF.PIDFILE)) {
          ci_debug_printf(1, "c-icap server already running!\n");
          exit(-1);
     }
     if (DAEMON_MODE)
          run_as_daemon();
     if (!set_running_permissions(CI_CONF.RUN_USER, CI_CONF.RUN_GROUP))
          exit(-1);
     store_pid(CI_CONF.PIDFILE);
#endif

     if (!init_server(CI_CONF.ADDRESS, CI_CONF.PORT, &(CI_CONF.PROTOCOL_FAMILY)))
          return -1;
     post_init_modules();
     post_init_services();
     start_server();
     clear_pid(CI_CONF.PIDFILE);
     return 0;
}
コード例 #2
0
ファイル: Styrmodul.c プロジェクト: grupphenning/allt
int main(void)
{
	//Sväng inte
	turn = 0;
	
	//Initiera spi, pwm och display
	spi_init();
	pwm_init();
	init_display();
	update();
	
	claw_out();
	_delay_ms(500);
	claw_in();	
	
	//Aktivera global interrupts
	sei();
	
	//Initiera regulator
	clear_pid();	
	init_pid(80, -80);
	//update_k_values(40, 12, 22);
	update_k_values(40, 170, 20);
	
	// Pekare till aktuell position i bufferten
	tmp_sensor_buffer_p = 0x00;
	
	// Flagga som avgör huruvida vi är i början av meddelande	
	sensor_start = 1;
	
	// Anger aktuell längd av meddelandet				
	tmp_sensor_buffer_len = 0x00;
	
	//Initiera standardsträng på display		
	init_default_printf_string();
	clear_screen();
	update();
	
	
	while(1)
	{
		uint8_t has_comm_data, has_sensor_data, comm_data, sensor_data;
	
		do_spi(&has_comm_data, &has_sensor_data, &comm_data, &sensor_data);
		
		//Undersök och hantera meddelanden från slavarna
		if(has_comm_data) decode_comm(comm_data);
		if(has_sensor_data) decode_sensor(sensor_data);
		
		//Vid manuell sväng eller 180 grader måste make_turn anropas 		
		if(!autonomous || turning_180)
		{
			if(turn_dir) 
			{
				make_turn_flag = 1;
				make_turn(turn_dir);
				
				if(!make_turn_flag) 
				{
					turn_dir = 0;
					stop_motors();
				}				
			}
		}			
		
		//Kör regulatorn
		if (regulator_enable)
		{
			regulator(sensor_buffer[IR_RIGHT_FRONT] - sensor_buffer[IR_RIGHT_BACK], 
					  sensor_buffer[IR_LEFT_FRONT] - sensor_buffer[IR_LEFT_BACK], 
					  sensor_buffer[IR_RIGHT_FRONT] - sensor_buffer[IR_LEFT_FRONT], 
					  sensor_buffer[IR_RIGHT_BACK] - sensor_buffer[IR_LEFT_BACK]);
			regulator_enable = 0;
		}	
	}
}