Пример #1
0
static void config(int op)
{
    FILE *f = config_open(op, "servo");

    // scale factor and polarity of servo configuration,
    // servo is controlled by an avr which takes +- 1000
    config_float(op, f, "servo_scale", &servo_scale);

    config_float(op, f, "min_hardover_period", &min_hardover_period);

    fclose(f);
}
Пример #2
0
static void theme_read_module(THEME_REC *theme, const char *module)
{
	CONFIG_REC *config;

	config = config_open(theme->path, -1);
	if (config != NULL)
		config_parse(config);

	theme_init_module(theme, module, config);

	if (config != NULL) config_close(config);
}
Пример #3
0
// Parse whole file using callback
void config_parse( int( *callback )( char*, char* ) ) {
  char *value, *token;
  FILE *cf;
  if( cf = config_open() ) {
    printf( "Config [info]: Reading rc...\n" );
    while( config_read_line( &value, &token, cf ) ) {
      if( callback( value, token ) ) break;
    }
    callback( NULL, NULL );
    fclose( cf );
  }
}
Пример #4
0
static void theme_save(THEME_REC *theme, int save_all)
{
	CONFIG_REC *config;
	THEME_SAVE_REC data;
	char *path;
	int ok;

	config = config_open(theme->path, -1);
        if (config != NULL)
                config_parse(config);
        else {
                if (g_ascii_strcasecmp(theme->name, "default") == 0) {
                        config = config_open(NULL, -1);
                        config_parse_data(config, default_theme, "internal");
                        config_change_file_name(config, theme->path, 0660);
                } else {
                        config = config_open(theme->path, 0660);
                        if (config == NULL)
                                return;
                        config_parse(config);
                }
        }

	data.config = config;
        data.save_all = save_all;
	g_hash_table_foreach(theme->modules, (GHFunc) module_save, &data);

        /* always save the theme to ~/.irssi/ */
	path = g_strdup_printf("%s/%s", get_irssi_dir(),
			       g_basename(theme->path));
	ok = config_write(config, path, 0660) == 0;

	printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
		    ok ? TXT_THEME_SAVED : TXT_THEME_SAVE_FAILED,
		    path, config_last_error(config));

	g_free(path);
	config_close(config);
}
Пример #5
0
static int _merge_config_cascade(struct cmd_context *cmd, struct dm_config_tree *cft_cascaded,
                                 struct dm_config_tree **cft_merged)
{
    if (!cft_cascaded)
        return 1;

    if (!*cft_merged && !(*cft_merged = config_open(CONFIG_MERGED_FILES, NULL, 0)))
        return_0;

    if (!_merge_config_cascade(cmd, cft_cascaded->cascade, cft_merged))
        return_0;

    return merge_config_tree(cmd, *cft_merged, cft_cascaded, CONFIG_MERGE_TYPE_RAW);
}
Пример #6
0
static int theme_read(THEME_REC *theme, const char *path)
{
	CONFIG_REC *config;
	THEME_READ_REC rec;
        char *str;

	config = config_open(path, -1) ;
	if (config == NULL) {
		/* didn't exist or no access? */
		str = g_strdup_printf("Error reading theme file %s: %s",
				      path, g_strerror(errno));
		read_error(str);
		g_free(str);
		return FALSE;
	}

	if (path == NULL)
		config_parse_data(config, default_theme, "internal");
        else
		config_parse(config);

	if (config_last_error(config) != NULL) {
		str = g_strdup_printf("Ignored errors in theme %s:\n%s",
				      theme->name, config_last_error(config));
		read_error(str);
                g_free(str);
	}

	theme->default_color =
		config_get_int(config, NULL, "default_color", -1);
	theme->info_eol = config_get_bool(config, NULL, "info_eol", FALSE);

	/* FIXME: remove after 0.7.99 */
	if (theme->default_color == 0 &&
	    config_get_int(config, NULL, "default_real_color", -1) != -1)
                theme->default_color = -1;
	theme_read_replaces(config, theme);

	if (path != NULL)
		theme_copy_abstracts(theme, internal_theme);
	theme_read_abstracts(config, theme);

	rec.theme = theme;
	rec.config = config;
	g_hash_table_foreach(default_formats,
			     (GHFunc) theme_read_modules, &rec);
	config_close(config);

        return TRUE;
}
Пример #7
0
static gboolean sbar_node_isdefault(const char *name)
{
	CONFIG_REC *config;
	CONFIG_NODE *node;

	/* read the default statusbar settings from internal config */
	config = config_open(NULL, -1);
	config_parse_data(config, default_config, "internal");

	node = config_sbar_node(config, name, FALSE);

	config_close(config);

	return node != NULL ? TRUE : FALSE;
}
Пример #8
0
void config_start(char *config_path)
{
  config_load(config_path);
  FILE *f = config_open(NULL, info_paths, "r");
  log_msg("CONFIG", "%p", f);
  if (!f) {
    char *path = fs_expand_path(info_paths[0]);
    f = fopen(path, "w+");
    if (f)
      fclose(f);
    free(path);
    return;
  }
  info_read(f);
  fclose(f);
}
Пример #9
0
static THEME_REC *read_internal_theme(void)
{
	CONFIG_REC *config;
	THEME_REC *theme;

	theme = theme_create("internal", "_internal");
	theme->refcount++;
	theme_destroy(theme);

	config = config_open(NULL, -1);
	config_parse_data(config, default_theme, "internal");
	theme_read_abstracts(config, theme);
	config_close(config);

	return theme;
}
Пример #10
0
struct volume_group *text_vg_import_fd(struct format_instance *fid,
				       const char *file,
				       int single_device,
				       struct device *dev,
				       off_t offset, uint32_t size,
				       off_t offset2, uint32_t size2,
				       checksum_fn_t checksum_fn,
				       uint32_t checksum,
				       time_t *when, char **desc)
{
	struct volume_group *vg = NULL;
	struct dm_config_tree *cft;
	struct text_vg_version_ops **vsn;

	_init_text_import();

	*desc = NULL;
	*when = 0;

	if (!(cft = config_open(CONFIG_FILE, file, 0)))
		return_NULL;

	if ((!dev && !config_file_read(cft)) ||
	    (dev && !config_file_read_fd(cft, dev, offset, size,
					 offset2, size2, checksum_fn, checksum))) {
		log_error("Couldn't read volume group metadata.");
		goto out;
	}

	/*
	 * Find a set of version functions that can read this file
	 */
	for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
		if (!(*vsn)->check_version(cft))
			continue;

		if (!(vg = (*vsn)->read_vg(fid, cft, single_device)))
			goto_out;

		(*vsn)->read_desc(vg->vgmem, cft, when, desc);
		break;
	}

      out:
	config_destroy(cft);
	return vg;
}
Пример #11
0
static void statusbar_reset_defaults(void)
{
	CONFIG_REC *config;
        CONFIG_NODE *node;

	while (statusbar_groups != NULL)
		statusbar_group_destroy(statusbar_groups->data);
	active_statusbar_group = NULL;

        /* read the default statusbar settings from internal config */
	config = config_open(NULL, -1);
	config_parse_data(config, default_config, "internal");
	node = config_node_traverse(config, "statusbar", FALSE);
        if (node != NULL)
		read_statusbar_config_from_node(node);
        config_close(config);
}
Пример #12
0
bool check_mainscript_version(void)
{
	//Open the file
	FILE *config_file_in = config_open(config_path_mainscript, "rt");

	char config_line[BBI_MAX_LINE_LENGTH];
	if (config_file_in)
	{	
		if (	fgets(config_line, sizeof config_line, config_file_in)
			&&	config_line[0] == '!'
			&&	strstr(config_line, "0.9.9")
			) { fclose(config_file_in); return true; }

		fclose(config_file_in);
	}
	return false;
}
Пример #13
0
static void sig_init_finished(void)
{
	CONFIG_REC *session;

	if (session_file == NULL)
		return;

	session = config_open(session_file, -1);
	if (session == NULL)
		return;

	config_parse(session);
        signal_emit("session restore", 1, session);
	config_close(session);

	unlink(session_file);
}
int pmd_system_init() {
    create_config();
    if (config_open() != 0) {
        return 1;
    }

    if(can_net_init(10000000, 100) != 0) {
        return 2;
    }

    interrupt_init();

    if(net_device_init() != 0) {
        return 3;
    }

    //Non-smb message handler
    cb_records[0].check.port_min = 0;
    cb_records[0].check.port_max = -1;
    cb_records[0].check.id_min = 0;
    cb_records[0].check.id_max = -1;
    cb_records[0].check.smb_min = 0;
    cb_records[0].check.smb_max = 0;
    cb_records[0].callback = non_smb_net_cb;
    cb_records[0].cb_ctx = NULL;

    //smb message handler
    cb_records[1].check.port_min = 0;
    cb_records[1].check.port_max = -1;
    cb_records[1].check.id_min = 0;
    cb_records[1].check.id_max = -1;
    cb_records[1].check.smb_min = 1;
    cb_records[1].check.smb_max = 1;
    cb_records[1].callback = smb_net_cb;
    cb_records[1].cb_ctx = NULL;

    can_net_add_callback( &(cb_records[0]) );
    can_net_add_callback( &(cb_records[1]) );

    operation_mode = OPERATION_MODE_NORMAL;

    heartbeat_msg_init(&heartbeat_msg);
    ftimer_register_func(send_heartbeat, NULL, 1000);

    return 0;
}
PROCESS_THREAD(eeprom_write_contiki_test, ev, data) {
    PROCESS_BEGIN();

    static config_section_t * led_conf = 0;
    int i;
    led_conf = config_cnf_create_section(config_get());

    strcpy(led_conf->name, "led");
    config_section_set_uint(led_conf, "ddr", 39);
    config_section_set_uint(led_conf, "port", 40);
    config_section_set_uint(led_conf, "offset", 0);

    config_save();

    config_close();

    config_init();
    if (config_open() == -1) alarma(10);

    modules_init();
    devices_init();

    if (admin_get_device_by_id(2) && admin_get_device_by_id(1)) {
        static led_t * led_m = 0;
        static led_t * led = 0;

        led_m = (led_t *)admin_get_device_by_id(2)->device;
        led = (led_t *)admin_get_device_by_id(1)->device;
        led->init(led);
        led_m->init(led_m);

        if (module_get(MODULE_LED1)->config == led_conf) {
            for (i = 0; i < 10; ++i) {
                 led->on(led);
                 _delay_ms(50);
                 led->off(led);
                 _delay_ms(50);
            }
        }

        led->on(led);
        led_m->on(led_m);
    }
    PROCESS_END();
}
Пример #16
0
static CONFIG_NODE *sbar_find_item_with_defaults(const char *statusbar, const char *item,
                                                 gboolean create)
{
	CONFIG_REC *config, *close_config;
	CONFIG_NODE *node;

	close_config = NULL;
	config = mainconfig;
	node = sbar_node(statusbar, FALSE);

	if (node == NULL) {
		/* we are looking up defaults from the internal config */
		close_config = config = config_open(NULL, -1);
		config_parse_data(config, default_config, "internal");
		node = config_sbar_node(config, statusbar, FALSE);
	}

	if (node == NULL) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_STATUSBAR_NOT_FOUND, statusbar);
		if (close_config != NULL)
			config_close(close_config);
		return NULL;
	}

	node = config_sbar_items_section(config, node, create);

	if (node == NULL || (!create && config_node_section(config, node, item, -1) == NULL)) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_STATUSBAR_ITEM_NOT_FOUND, item);
		if (close_config != NULL)
			config_close(close_config);
		return NULL;
	}

	if (config != mainconfig) {
		/* we need to copy default to user config */
		node = statusbar_copy_config(config, node, sbar_node(statusbar, TRUE));
	}

	if (close_config != NULL)
		config_close(close_config);

	return node;
}
Пример #17
0
CacheConfig::CacheConfig(const GMConfig& config):
    _cache_max(100),
    _cache_min(100),
    _log_file("/var/log/arc/cache-clean.log"),
    _log_level("INFO") ,
    _lifetime("0"),
    _clean_timeout(0) {
  // Load conf file
  std::ifstream cfile;
  if(!config_open(cfile,config.ConfigFile())) throw CacheConfigException("Can't open configuration file");
  
  /* detect type of file */
  switch(config_detect(cfile)) {
    case config_file_XML: {
      Arc::XMLNode cfg;
      if(!cfg.ReadFromStream(cfile)) {
        config_close(cfile);
        throw CacheConfigException("Can't interpret configuration file as XML");
      };
      config_close(cfile);
      try {
        parseXMLConf(cfg);
      } catch (CacheConfigException& e) {
        config_close(cfile);
        throw;
      }
    }; break;
    case config_file_INI: {
      ConfigSections cf(cfile);
      try {
        parseINIConf(cf);
      } catch (CacheConfigException& e) {
        config_close(cfile);
        throw;
      }
    }; break;
    default: {
      config_close(cfile);
      throw CacheConfigException("Can't recognize type of configuration file");
    }; break;
  };
  config_close(cfile);
}
PROCESS_THREAD(config_test_contiki_app, ev, data) {
    PROCESS_BEGIN();
    printf("Hello, World!!\n\n");

    config_init();
    int st = config_open();
    if(st == 1) {
        printf("Parse success!\n");
        config_print();
        printf("\n");

        config_cnf_t * cnf = config_get();
        config_section_t * sect = list_head(cnf->sections);

        printf("Set first section:\n");
        printf("\topt = Ololo [string]\n");
        printf("\topt1 = 100500 [int]\n");

        if(config_section_set_str(sect, "opt", "Ololo") == -1) {
            printf("Set opt failed\n");
        }
        if(config_section_set_int(sect, "opt1", 100500) == -1) {
            printf("Set opt1 failed\n");
        }

        config_print();

        printf("Writing config\n");
        if(config_save() == 1) {
            printf("Successfully written\n");
        } else {
            printf("Write failed\n");
        }

    } else {
        printf("Epic Fail :(\n");
    }

    printf("\nGoodbye, World!!\n");
    PROCESS_END();
}
Пример #19
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int config_load(char *filename, module* caller, const char *section)
{
	//Open the file
	FILE *config_file_in = config_open(filename, "rt");

	char config_line[BBI_MAX_LINE_LENGTH];
	if (config_file_in)
	{
		bool wanted_section = NULL == section;
		while (config_read_line(config_line, config_file_in))
		{
			if (config_line[0] == '[')
			{
				if (wanted_section) break;
				if (0 == stricmp(config_line, section))
					wanted_section = true;
				continue;
			}

			if (false == wanted_section)
				continue;

			if (config_line[0] == '@')
			{
				//Interpret the message
				message_interpret(config_line, false, caller);
			}
		}
		//Close the file
		fclose(config_file_in);
		return 0;
	}

	//Must have been an error
	if (!plugin_suppresserrors)
	{
		sprintf(config_line, "%s:\nThere was an error loading the configuration file.", filename);
		MessageBox(NULL, config_line, szAppName, MB_OK|MB_SYSTEMMODAL);
	}
	return 1;
}
Пример #20
0
void reset_avr() {
	reset_clients();
	if (verbose) printf("Reset AVR\n");
	linuxgpio_initpin(config.reset_gpio);
	linuxgpio_highpulsepin(config.reset_gpio, 500);
	linuxgpio_close();
	//mssleep(2000);
	avrstatus=-1;
	
	if (autoconfig) {
		int ret = config_open(&config,CFG_PATH);
		if (ret<0) {
			printf("Disabling AUTOCONFIG\n");
			//printf("Failed to initiate config! [%s]\n", strerror(ret));	
			autoconfig = 0;
			return;
		}
		clock_gettime(CLOCK_REALTIME, &reset_time_prev);
		reset_timeout = initTimeout;
	}
}
Пример #21
0
static void botuser_config_read(void)
{
	CONFIG_NODE *node;
	GSList *tmp;
	char *fname;

	/* Read users from ~/.irssi/users */
	fname = g_strdup_printf("%s/users", get_irssi_dir());
	userconfig = config_open(fname, 0600);
	g_free(fname);

	if (userconfig == NULL)
		return; /* access denied?! */

	config_parse(userconfig);

	node = config_node_traverse(userconfig, "users", FALSE);
	tmp = node == NULL ? NULL : node->value;
	for (; tmp != NULL; tmp = tmp->next)
		botuser_config_read_user(tmp->data);
}
Пример #22
0
const char *text_vgname_import(const struct format_type *fmt,
			       struct device *dev,
			       off_t offset, uint32_t size,
			       off_t offset2, uint32_t size2,
			       checksum_fn_t checksum_fn, uint32_t checksum,
			       struct id *vgid, uint64_t *vgstatus,
			       char **creation_host)
{
	struct dm_config_tree *cft;
	struct text_vg_version_ops **vsn;
	const char *vgname = NULL;

	_init_text_import();

	if (!(cft = config_open(CONFIG_FILE, NULL, 0)))
		return_NULL;

	if ((!dev && !config_file_read(cft)) ||
	    (dev && !config_file_read_fd(cft, dev, offset, size,
					 offset2, size2, checksum_fn, checksum)))
		goto_out;

	/*
	 * Find a set of version functions that can read this file
	 */
	for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
		if (!(*vsn)->check_version(cft))
			continue;

		if (!(vgname = (*vsn)->read_vgname(fmt, cft, vgid, vgstatus,
						   creation_host)))
			goto_out;

		break;
	}

      out:
	config_destroy(cft);
	return vgname;
}
Пример #23
0
bool config_isolate_section(config_t *current_conf,
    config_line_t *current_line, config_t *isolated)
{
    long startpos, endpos;
    bool r = false;

    *isolated = *current_conf;

    if (current_conf->error_message)
        return false;
    if (current_line->type != CONFIG_LINE_TYPE_SECTION)
        return false;

    startpos = ftell(current_conf->file);
    if (startpos < 0)
        return false;
    if (!find_section_end(current_conf, current_line, 0))
        goto resetpos;
    endpos = ftell(current_conf->file);
    if (endpos < 0)
        goto resetpos;

    if (!config_open(isolated, current_conf->path))
        goto resetpos;
    if (fseek(isolated->file, startpos, SEEK_SET) < 0)
        goto resetpos;

    isolated->isolated.end = endpos;
    r = true;

resetpos:
    if (fseek(current_conf->file, startpos, SEEK_SET) < 0) {
        config_error(current_conf, "Could not reset file position");
        return false;
    }
    if (!r)
        config_error(current_conf, "Unknown error while isolating section");
    return r;
}
Пример #24
0
void config_init()
{
	NEW( config*, g_conf, sizeof(config) );
	if( !g_conf ) return;
	if( config_open( g_conf, "./qqconfig.txt" ) < 0 ){
		perror("can't not open qqconfig.txt file.");
		exit(-1); 
	}
	char* log_dir = config_readstr( g_conf, "QQLogDir" );
	uint log_terminal = config_readint( g_conf, "QQTerminalLog" );
	if( log_terminal ){
		debug_term_on();
	}else{
		debug_term_off();
	}
	if( log_dir == NULL ){
		debug_file_off();
	}else{
		debug_set_dir( log_dir );
		debug_file_on();
	}
}
Пример #25
0
bool cached_versions_match(void)
{
	struct win_version_info d3d8_ver  = {0};
	struct win_version_info d3d9_ver  = {0};
	struct win_version_info dxgi_ver = {0};
	bool ver_mismatch = false;
	config_t *config;
	char *ver_file;
	int ret;

	ver_mismatch |= !get_32bit_system_dll_ver(L"d3d8.dll", &d3d8_ver);
	ver_mismatch |= !get_32bit_system_dll_ver(L"d3d9.dll", &d3d9_ver);
	ver_mismatch |= !get_32bit_system_dll_ver(L"dxgi.dll", &dxgi_ver);

	ver_file = obs_module_config_path("version.ini");
	if (!ver_file)
		return false;

	ret = config_open(&config, ver_file, CONFIG_OPEN_ALWAYS);
	if (ret != CONFIG_SUCCESS)
		goto failed;

	ver_mismatch |= config_ver_mismatch(config, "d3d8", &d3d8_ver);
	ver_mismatch |= config_ver_mismatch(config, "d3d9", &d3d9_ver);
	ver_mismatch |= config_ver_mismatch(config, "dxgi", &dxgi_ver);

	if (ver_mismatch) {
		write_config_ver(config, "d3d8", &d3d8_ver);
		write_config_ver(config, "d3d9", &d3d9_ver);
		write_config_ver(config, "dxgi", &dxgi_ver);
		config_save_safe(config, "tmp", NULL);
	}

failed:
	bfree(ver_file);
	config_close(config);
	return !ver_mismatch;
}
Пример #26
0
static void botnet_config_read(void)
{
	CONFIG_REC *config;
	CONFIG_NODE *node;
	GSList *tmp;
	char *fname;

	/* Read botnets from ~/.irssi/botnets */
	fname = g_strdup_printf("%s/.irssi/botnets", g_get_home_dir());
	config = config_open(fname, -1);
	g_free(fname);

	if (config == NULL)
		return;

	config_parse(config);

	node = config_node_traverse(config, "botnets", FALSE);
	tmp = node == NULL ? NULL : node->value;
	for (; tmp != NULL; tmp = tmp->next)
                botnet_config_read_botnet(tmp->data);
	config_close(config);
}
Пример #27
0
static void load_crontab(const char *fileName)
{
	struct parser_t *parser;
	struct stat sbuf;
	int maxLines;
	char *tokens[6];
#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
	char *mailTo = NULL;
#endif
	char *shell = NULL;

	delete_cronfile(fileName);

	if (!getpwnam(fileName)) {
		log7("ignoring file '%s' (no such user)", fileName);
		return;
	}

	parser = config_open(fileName);
	if (!parser)
		return;

	maxLines = (strcmp(fileName, "root") == 0) ? 65535 : MAXLINES;

	if (fstat(fileno(parser->fp), &sbuf) == 0 && sbuf.st_uid == DAEMON_UID) {
		CronFile *file = xzalloc(sizeof(CronFile));
		CronLine **pline;
		int n;

		file->cf_username = xstrdup(fileName);
		pline = &file->cf_lines;

		while (1) {
			CronLine *line;

			if (!--maxLines) {
				bb_error_msg("user %s: too many lines", fileName);
				break;
			}

			n = config_read(parser, tokens, 6, 1, "# \t", PARSE_NORMAL | PARSE_KEEP_COPY);
			if (!n)
				break;

			log5("user:%s entry:%s", fileName, parser->data);

			/* check if line is setting MAILTO= */
			if (is_prefixed_with(tokens[0], "MAILTO=")) {
#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
				free(mailTo);
				mailTo = (tokens[0][7]) ? xstrdup(&tokens[0][7]) : NULL;
#endif /* otherwise just ignore such lines */
				continue;
			}
			if (is_prefixed_with(tokens[0], "SHELL=")) {
				free(shell);
				shell = xstrdup(&tokens[0][6]);
				continue;
			}
//TODO: handle HOME= too? "man crontab" says:
//name = value
//
//where the spaces around the equal-sign (=) are optional, and any subsequent
//non-leading spaces in value will be part of the value assigned to name.
//The value string may be placed in quotes (single or double, but matching)
//to preserve leading or trailing blanks.
//
//Several environment variables are set up automatically by the cron(8) daemon.
//SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd
//line of the crontab's owner. HOME and SHELL may be overridden by settings
//in the crontab; LOGNAME may not.

			/* check if a minimum of tokens is specified */
			if (n < 6)
				continue;
			*pline = line = xzalloc(sizeof(*line));
			/* parse date ranges */
			ParseField(file->cf_username, line->cl_Mins, 60, 0, NULL, tokens[0]);
			ParseField(file->cf_username, line->cl_Hrs, 24, 0, NULL, tokens[1]);
			ParseField(file->cf_username, line->cl_Days, 32, 0, NULL, tokens[2]);
			ParseField(file->cf_username, line->cl_Mons, 12, -1, MonAry, tokens[3]);
			ParseField(file->cf_username, line->cl_Dow, 7, 0, DowAry, tokens[4]);
			/*
			 * fix days and dow - if one is not "*" and the other
			 * is "*", the other is set to 0, and vise-versa
			 */
			FixDayDow(line);
#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
			/* copy mailto (can be NULL) */
			line->cl_mailto = xstrdup(mailTo);
#endif
			line->cl_shell = xstrdup(shell);
			/* copy command */
			line->cl_cmd = xstrdup(tokens[5]);
			pline = &line->cl_next;
//bb_error_msg("M[%s]F[%s][%s][%s][%s][%s][%s]", mailTo, tokens[0], tokens[1], tokens[2], tokens[3], tokens[4], tokens[5]);
		}
		*pline = NULL;

		file->cf_next = G.cron_files;
		G.cron_files = file;
	}
	config_close(parser);
#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
	free(mailTo);
#endif
	free(shell);
}
Пример #28
0
void stagealign(int fcnum, int lane_num, int initialize)
{

    short unsigned int *testimage;
    short unsigned int *baseimage;
    FILE *baseimgfp;
    FILE *offsetfp;
    /* used to dump score matrix to file when debugging */
    FILE *score_matrixfp;

    /* Maestro declarations */
    int m_sock; /* socket for the Maestro controller */

    char config_value[255];
    char logfilename[255];
    char offsetfilename[255];
    char stagealign_baseimgfilename[255];

    char acqcfgpath[255];

    /* Used to send commands and receive responses from Maestro */
    char command[255];
    char response[255];
    int response_length;

    /* Image acquisition settings, populated from config file */
    int stagealign_integration_inmsec;
    int stagealign_gain;
    int stagealign_well;
    int stagealign_wells_per_fc;

    /* Values used for conversion between pixels and stage units */
    int stagealign_optical_mag;
    int ccd_pixel_size;
    double pixelsize_at_stage; /* size of a pixel at the stage in microns */

    /* Hold offsets found by alignment in pixels and stageunits */
    int pixel_offset_x, pixel_offset_y;
    double stageunit_offset_x, stageunit_offset_y;
    int lane_index;

    /* Holds previous offsets from controller in case the alignment doesn't work */
    int curr_offset_x, curr_offset_y;

    /* Holds encoder resolutions from controller, used for calculating distance of move */
    double encoder_res_X, encoder_res_Y;


    /* 'score' of best alignment */
    int score;

    /* Largest pixel offset allowable _after_ the adjustment has been made */
    /* if there is still a shift larger than this, conclude something is wrong */
    /* and go back to the previous offset */
    int successful_move_threshold = 150; /*RCT was = 12*/

    int i;

  /* in debugging mode, dump internal data to files */
#ifdef DEBUG_STAGEALIGN
    FILE *imgfp;
    sprintf(command, "%s/stagealign-image%d_%d.raw", output_directory, fcnum, lane_num);
    imgfp = fopen(command, "w");
    sprintf(command, "%s/stagealign-scorematrix%d_%d", output_directory, fcnum, lane_num);
    score_matrixfp = fopen(command, "w");
#endif
    p_log_simple("awesome2\n");
    /* Open config file */
    strcpy(acqcfgpath, getenv("POLONATOR_PATH"));
    strcat(acqcfgpath, "/config_files/polonator-acq.cfg");
    config_open(acqcfgpath);
    p_log_simple("awesome1\n");
    /* Initialize variables */
    if(!config_getvalue("stagealign_logfilename", config_value)){
        fprintf(stderr, "ERROR:\tPolonator-stagealign: config_getval(key logfilename) returned no value\n");
        exit(0);
    }
    p_log_simple("awesome0\n");
    strcpy(logfilename, log_dir);
    strcat(logfilename, "/");
    strcat(logfilename, config_value);
    sprintf(command, "%d", fcnum);
    strcat(logfilename, command);
    strcat(logfilename, ".log");
    p_log_simple(logfilename);
    start_logger(logfilename, 1);

    strcpy(offsetfilename, log_dir);
    strcat(offsetfilename, "/");
    strcat(offsetfilename, config_value);
    strcat(offsetfilename, command);
    strcat(offsetfilename, ".offsetlog");
    fprintf(stdout, offsetfilename);
    fflush(stdout);
    /*
    if this is being run in 'initialize mode' -- the first scan of a run --
    overwrite the offset logfile
    */
    p_log_simple("awesome66\n");
    if(initialize){
        offsetfp = fopen(offsetfilename, "w");
    }
    else{
        offsetfp = fopen(offsetfilename, "a");
    }
    p_log_simple("awesome00\n");
    if(!config_getvalue("stagealign_baseimgfilename", config_value)){
        p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_baseimgfilename) returned no value");
        exit(0);
    }
    sprintf(stagealign_baseimgfilename, "%s/%s%s_%d.raw", output_directory, config_value, command, lane_num);
    p_log_simple("awesome01\n");
    if(!config_getvalue("stagealign_integration_inmsec", config_value)){
        p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_integration_inmsec) returned no value");
        exit(0);
    }
    stagealign_integration_inmsec = atoi(config_value);
    p_log_simple("awesome02\n");
    if(!config_getvalue("stagealign_gain", config_value)){
        p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_gain) returned no value");
        exit(0);
    }
    stagealign_gain = atoi(config_value);
    p_log_simple("awesome03\n");
    if(!config_getvalue("stagealign_optical_mag", config_value)){
        p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_optical_mag) returned no value");
        exit(0);
    }
    stagealign_optical_mag = atoi(config_value);
    p_log_simple("awesome04\n");
    if(!config_getvalue("stagealign_ccd_pixel_size", config_value)){
        p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_ccd_pixel_size) returned no value");
        exit(0);
    }
    ccd_pixel_size = atoi(config_value);
    p_log_simple("awesome05\n");
    if(!config_getvalue("stagealign_wells_per_fc", config_value)){
        p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_wells_per_fc) returned no value");
        exit(0);
    }
    stagealign_wells_per_fc = atoi(config_value);
    config_close();
    p_log_simple("awesome06\n");
    stagealign_well = lane_num;
    lane_index = (fcnum * stagealign_wells_per_fc) + stagealign_well;


    baseimage = (short unsigned int*)malloc(1000000 * sizeof(short unsigned int));

    /*--------------------------------------------------------------------------
    //
    // MAESTRO SETUP
    /*/
    p_log_simple("STATUS:\tPolonator-stagealign: Opening connection to Maestro...");
    maestro_open(&m_sock);
    /*
    //--------------------------------------------------------------------------
    */


    /*--------------------------------------------------------------------------
    //
    // CAMERA SETUP
    /*/
    p_log_simple("STATUS:\tPolonator-stagealign: Opening camera handle...");
    py_cameraInit(0); /* use non-TDI config file */
    py_set_gain(stagealign_gain);
    py_setupSnap(); /* setup capture software to wait for images from camera */
    /*
    //--------------------------------------------------------------------------
    */


    /*p_log("STATUS:\tPolonator-stagealign: Darkfield illuminator on...");  rolony*/
    /*maestro_darkfield_on(m_sock);
    p_log("STATUS:\tPolonator-stagealign: Select darkfield filter block...");  rolony*/
    maestro_setcolor(m_sock, "cy5");


    /* IF INITIALIZING, RESET OFFSETS */
    if(initialize){
        p_log_simple("INITIALIZING STAGEALIGN");
        sprintf(command, "PolonatorScan.OFFSET_X[%d]=0\n\r", lane_index);
        p_log_simple(command);
        send(m_sock, command, strlen(command), 0);
        maestro_readresponse(m_sock, response, &response_length);
        p_log_simple(response);

        sprintf(command, "PolonatorScan.OFFSET_Y[%d]=0\n\r", lane_index);
        p_log_simple(command);
        send(m_sock, command, strlen(command), 0);
        maestro_readresponse(m_sock, response, &response_length);
        p_log_simple(response);
    }
    /* GET OFFSETS IN CASE ALIGNMENT FAILS */
    else{
        p_log_simple("Storing current offsets...");
        sprintf(command, "PolonatorScan.OFFSET_X[%d]\n\r", lane_index);
        p_log_simple(command);
        send(m_sock, command, strlen(command), 0);
        maestro_readresponse(m_sock, response, &response_length);
        p_log_simple(response);
        curr_offset_x = atoi(response);

        sprintf(command, "PolonatorScan.OFFSET_Y[%d]\n\r", lane_index);
        p_log_simple(command);
        send(m_sock, command, strlen(command), 0);
        maestro_readresponse(m_sock, response, &response_length);
        p_log_simple(response);
        curr_offset_y = atoi(response);
    }

    /* MOVE STAGE TO ORIGIN */
    maestro_gotostagealign_position(m_sock, fcnum, lane_num);

    p_log_simple("awesome fool00\n");
    /* ACQUIRE IMAGE */
    p_log("STATUS:\tPolonator-stagealign: Acquire image...");
    maestro_snap(m_sock, stagealign_integration_inmsec, 1); /*rolony*/
    while(!py_snapReceived()){;}
    testimage = py_getSnapImage();


    /* IF INITIALIZING, RE-WRITE THE BASE IMAGE; THE OFFSET FOUND SHOULD BE ZERO */
    p_log_simple(stagealign_baseimgfilename);
    if(initialize){
        baseimgfp = fopen(stagealign_baseimgfilename, "w");
        fwrite(testimage, 1000000, sizeof(short unsigned int), baseimgfp);
        fclose(baseimgfp);
    }
    p_log_simple("awesome fool01\n");
#ifdef DEBUG_STAGEALIGN
    fwrite(testimage, 1000000, sizeof(short unsigned int), imgfp);
#endif

    /* LOAD BASE IMAGE */
    p_log("STATUS:\tPolonator-stagealign: Load base image and determine offset...");
    baseimgfp = fopen(stagealign_baseimgfilename, "r");
    fread(baseimage, 1000000, sizeof(short unsigned int), baseimgfp);
    fclose(baseimgfp);
    p_log("STATUS:\tPolonator-stagealign: Load base image and determine offset2...");

    /* DETERMINE OFFSETS */
    register_image(baseimage, testimage, &pixel_offset_x, &pixel_offset_y, &score, score_matrixfp);
    sprintf(log_string, "STATUS:\tPolonator-stagealign: Found pixel offsets X:%d, Y:%d, score:%d", pixel_offset_x, pixel_offset_y, score);
    p_log(log_string);


    /* LOAD ENCODER RESOLUTIONS FOR CONVERSION BELOW; THESE ARE STORED ON */
    /* THE CONTROLLER AS COUNTS PER MILLIMETER */
    p_log("Retrieving encoder resolutions...");
    sprintf(command, "PolonatorScan.cENCODER_X_RESOLUTION\n\r");
    p_log(command);
    send(m_sock, command, strlen(command), 0);
    maestro_readresponse(m_sock, response, &response_length);
    p_log(response);
    encoder_res_X = atof(response);

    sprintf(command, "PolonatorScan.cENCODER_Y_RESOLUTION\n\r");
    p_log(command);
    send(m_sock, command, strlen(command), 0);
    maestro_readresponse(m_sock, response, &response_length);
    p_log(response);
    encoder_res_Y = atof(response);


    /* CONVERT FROM PIXELS TO STAGE UNITS */
    /* CALCULATE PIXEL SIZE IN MILLIMTERS AT THE STAGE BASED */
    /* ON THE MAGNIFICATION AND THE CCD PIXEL SIZE */
    pixelsize_at_stage = ((double)ccd_pixel_size / (double)stagealign_optical_mag) / 1000;
    stageunit_offset_x = (double)pixel_offset_x * pixelsize_at_stage * encoder_res_X * -1;
    stageunit_offset_y = (double)pixel_offset_y * pixelsize_at_stage * encoder_res_Y * -1;


    /* SET NEW OFFSETS ON CONTROLLER USING VALUES */
    /* CALCULATED ABOVE */
    sprintf(command, "PolonatorScan.OFFSET_X[%d]\n\r", lane_index);
    send(m_sock, command, strlen(command), 0);
    maestro_readresponse(m_sock, response, &response_length);
    fprintf(offsetfp, "%d\t%d\t", fcnum, stagealign_well);
    fprintf(offsetfp, "%d\t", atoi(response));
    sprintf(command, "PolonatorScan.OFFSET_Y[%d]\n\r", lane_index);
    send(m_sock, command, strlen(command), 0);
    maestro_readresponse(m_sock, response, &response_length);
    fprintf(offsetfp, "%d\t", atoi(response));
    fprintf(offsetfp, "%d\t%d\t%d\t%d\t", (int)stageunit_offset_x, (int)stageunit_offset_y, pixel_offset_x, pixel_offset_y);


    /* ISSUE COMMANDS TO ADJUST STAGE COORDS */
    p_log("STATUS:\tPolonator-stagealign: Set offset variables on Maestro...");
    sprintf(command, "PolonatorScan.OFFSET_X[%d]=PolonatorScan.OFFSET_X[%d]+%d\n\r", lane_index, lane_index, (int)stageunit_offset_x);
    p_log(command);
    send(m_sock, command, strlen(command), 0);
    maestro_readresponse(m_sock, response, &response_length);
    p_log(response);

    sprintf(command, "PolonatorScan.OFFSET_Y[%d]=PolonatorScan.OFFSET_Y[%d]+%d\n\r", lane_index, lane_index, (int)stageunit_offset_y);
    p_log(command);
    send(m_sock, command, strlen(command), 0);
    maestro_readresponse(m_sock, response, &response_length);
    p_log(response);


    /* MOVE, THEN ACQUIRE ANOTHER IMAGE TO VERIFY OFFSET WORKED */
    /* maestro_gotostagealign_position(m_sock, fcnum, lane_num);
    maestro_snap(m_sock, stagealign_integration_inmsec, 0);
    while(!py_snapReceived()){;}
    testimage = py_getSnapImage();
    */

#ifdef DEBUG_STAGEALIGN
    fwrite(testimage, 1000000, sizeof(short unsigned int), imgfp);
    fclose(imgfp);
#endif


    /* DETERMINE OFFSET TO CONFIRM */
    /* p_log("STATUS:\tPolonator-stagealign: Re-compute alignment to verify move...");
    register_image(baseimage, testimage, &pixel_offset_x, &pixel_offset_y, &score, score_matrixfp);
    sprintf(log_string, "STATUS:\tPolonator-stagealign: Found pixel offsets X:%d, Y:%d, score:%d", pixel_offset_x, pixel_offset_y, score);
    p_log(log_string);
    fprintf(offsetfp, "%d\t%d", pixel_offset_x, pixel_offset_y);
    */

    /* DID THE MOVE WORK? */
    if(((abs(pixel_offset_x)>successful_move_threshold) || (abs(pixel_offset_y)>successful_move_threshold)) && (!initialize))
    {
        sprintf(log_string, "ERROR:\tPolonator-stagealign: one or more offsets are greater that the %d-pixel maximum; X:%d, Y:%d",
            successful_move_threshold,
            pixel_offset_x,
            pixel_offset_y);
        p_log(log_string);
        fprintf(offsetfp, "*");
        /* mark current line in offsetlog, since offsets found will not be the offsets stored on the controller */

        sprintf(log_string, "Restoring previous offsets X:%d, Y:%d", curr_offset_x, curr_offset_y);


        sprintf(command, "PolonatorScan.OFFSET_X[%d]=%d\n\r", lane_index, curr_offset_x);
        p_log(command);
        send(m_sock, command, strlen(command), 0);
        maestro_readresponse(m_sock, response, &response_length);
        p_log(response);

        sprintf(command, "PolonatorScan.OFFSET_Y[%d]=%d\n\r", lane_index, curr_offset_y);
        p_log(command);
        send(m_sock, command, strlen(command), 0);
        maestro_readresponse(m_sock, response, &response_length);
        p_log(response);
    }

    /* EXIT */
#ifdef DEBUG_STAGEALIGN
    fclose(score_matrixfp);
#endif
    fprintf(offsetfp, "\n");
    fclose(offsetfp);
    /*maestro_darkfield_off(m_sock); rolony*/
    py_cameraClose();
    free(baseimage);
    close_logger();
    p_log_simple("awesome fool02\n");
}
Пример #29
0
int main() {
	struct sched_param param;

        signal(SIGTERM, catch_signal);
        signal(SIGINT, catch_signal);

	param.sched_priority = 49;
        if(sched_setscheduler(0, SCHED_FIFO, &param) == -1) {
                perror("sched_setscheduler failed");
                exit(-1);
        }


        if(mlockall(MCL_CURRENT|MCL_FUTURE) == -1) {
                perror("mlockall failed");
                exit(-2);
        }

	stack_prefault();

	err=config_open("/var/local/rpicopter.config");
	if (err<0) {
            	printf("Failed to initiate config! [%s]\n", strerror(err));	
		return -1;
	}

	err=flog_open("/var/local/");
	if (err<0) {
            	printf("Failed to initiate log! [%s]\n", strerror(err));	
		return -1;
	}

	err = sc_open();
        if (err != 0) {
            printf("Failed to initiate speedcontroller! [%s]\n", strerror(err));	
	    return -1;
	}

	err=ms_open(GYRO_RATE);
        if (err != 0) {
            printf("Failed to initiate gyro! [%s]\n", strerror(err));	
	    return -1;
	}

	err=rec_open();
	if (err<0) {
            	printf("Failed to initiate receiver! [%s]\n", strerror(err));	
		return -1;
	}

/*
	err=bs_open();
	if (err<0) {
            	printf("Failed to initiate pressure sensor! [%s]\n", strerror(err));	
		return -1;
	}
*/
	printf("Waiting for MPU calibration... \n");
	delay_ms(1000);
	controller_stable(NULL);
	return 0;
}
Пример #30
0
/*
 * Find out vgname on a given device.
 */
int text_read_metadata_summary(const struct format_type *fmt,
		       struct device *dev, dev_io_reason_t reason,
		       off_t offset, uint32_t size,
		       off_t offset2, uint32_t size2,
		       checksum_fn_t checksum_fn,
		       int checksum_only,
		       struct lvmcache_vgsummary *vgsummary)
{
	struct dm_config_tree *cft;
	struct text_vg_version_ops **vsn;
	int r = 0;

	_init_text_import();

	if (!(cft = config_open(CONFIG_FILE_SPECIAL, NULL, 0)))
		return_0;

	if (dev) {
		log_debug_metadata("Reading metadata summary from %s at %llu size %d (+%d)",
				   dev_name(dev), (unsigned long long)offset,
				   size, size2);

		if (!config_file_read_fd(cft, dev, reason, offset, size,
					 offset2, size2, checksum_fn,
					 vgsummary->mda_checksum,
					 checksum_only, 1)) {
			/* FIXME: handle errors */
			log_error("Couldn't read volume group metadata from %s.", dev_name(dev));
			goto out;
		}
	} else {
		if (!config_file_read(cft)) {
			log_error("Couldn't read volume group metadata from file.");
			goto out;
		}
	}

	if (checksum_only) {
		/* Checksum matches already-cached content - no need to reparse. */
		log_debug_metadata("Skipped parsing metadata on %s", dev_name(dev));
		r = 1;
		goto out;
	}

	/*
	 * Find a set of version functions that can read this file
	 */
	for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
		if (!(*vsn)->check_version(cft))
			continue;

		if (!(*vsn)->read_vgsummary(fmt, cft, vgsummary))
			goto_out;

		r = 1;
		break;
	}

      out:
	config_destroy(cft);
	return r;
}