Example #1
0
int config_load (rockon_config *config) {
	char *username;
	int ipc_path_lenght;

	assert(config);

	/* default values */
	config->launch_server = 0;
	config->auto_reconnect = 0;
	config->reconnect_interval = 3;

	username = getenv("USER");
	ipc_path_lenght = strlen(username) + 22;
	config->ipc_path = (char*) malloc(sizeof(char) * ipc_path_lenght);
	if (config->ipc_path == NULL) {
		EINA_LOG_CRIT("malloc ipc_path failed");
		return 0;
	}
	snprintf(config->ipc_path, ipc_path_lenght, "unix:///tmp/xmms-ipc-%s", username);

	if ((config->config_filename = get_config_filename ("rockon.conf"))) {
		config->lcfg_obj = lcfg_new(config->config_filename);
		if (lcfg_parse(config->lcfg_obj) != lcfg_status_ok) {
			return 0;
		}
		lcfg_accept(config->lcfg_obj, config_visitor_load, config);
		return 1;
	}
	return 0;
}
Example #2
0
struct lcfgx_tree_node *lcfgx_tree_new(struct lcfg *c)
{
	struct lcfgx_tree_node *root = lcfgx_tree_node_new(lcfgx_map, NULL);

	root->value.elements = NULL;

	lcfg_accept(c, lcfgx_tree_visitor, root);

	return root;
}
Example #3
0
int parse_file(char *fname, int num_samples)
{
	struct lcfg *c = lcfg_new(fname);
	enum lcfg_status stat;
	if (!c) {
		fprintf(stderr, "Config file %s: init error\n", fname);
		return -EINVAL;
	}

	stat = lcfg_parse(c);
	if (stat != lcfg_status_ok) {
		fprintf(stderr, "Config file %s: parse error(%d)\n", fname,
			stat);
		return -EINVAL;
	}

	lcfg_accept(c, compare_eventhandler, NULL);

	lcfg_delete(c);
	return 0;
}
Example #4
0
int main(int argc, char* argv[])
{
	pthread_t temperature_thread,templog_thread,setpoint_thread;
	int not_connect = 0;
	int c;
	char *channel = NULL;
	pthread_mutex_t mutex;
	pthread_cond_t condvar;
	int ret;
	int done = 0;
	gre_io_t *send_handle;
	thdata data1;
	size_t len;
	struct lcfg *cfg = lcfg_new("./brew.cfg");
	
	//open the log
	openlog("Fermtroller", LOG_PID, LOG_USER);

	if ( lcfg_parse(cfg) != lcfg_status_ok ) {
		syslog(LOG_INFO,"Error reading config file : %s\n", lcfg_error_get(cfg));
	} else {
		lcfg_accept(cfg, read_cfg,0);
	}

	lcfg_value_get(cfg, "wort_address",(void *)&temp_wort, &len);
	lcfg_value_get(cfg, "ambient_address",(void *)&temp_ambient, &len);
	if ( lcfg_value_get(cfg, "web_address", (void *)&web_address, &len) != lcfg_status_ok ) {
		syslog(LOG_ERR,"Error reading web_address : %s\n", lcfg_error_get(cfg));
	}
	lcfg_value_get(cfg, "user",(void *)&user,&len);
	lcfg_value_get(cfg,"pass",(void *)&pass,&len);

	// assign the GPIO file descriptors
	
 	cool_fd = open(cool_control,O_WRONLY);
	heat_fd = open(heat_control,O_WRONLY);

	data1.temp_data.temp1 = 0.0;
	data1.temp_data.temp2 = 0.0;
	data1.good_read = 0;	
	data1.heatcool = 1;
	data1.debug = 0;
	data1.read_freq = 30; // default read frequency is 30 seconds
	control_temp("0","0");
	while ((c = getopt( argc, argv, "vc:p:t:r:")) != -1 )
	{
		switch(c)
		{
			case 'v':
				data1.debug = 1;
				break;
			case 'c':
				channel = optarg;
				syslog(LOG_INFO,"Setting channel to : %s\n", channel);
				break;
			case 't':
				data1.temp_data.set_point= atof(optarg);
				syslog(LOG_INFO,"Setting Ferment temp to %f\n", data1.temp_data.set_point);
				break;
			case 'r':
				data1.read_freq = atoi(optarg);
				syslog(LOG_INFO,"Setting read frequency to %d\n", data1.read_freq);
				break;

		}
	}
#ifdef STORYBOARD
	if ( channel == NULL ) {
		syslog(LOG_ERR,"You must supply a greio channel temp_driver -c <storyboard channel>\n");
		exit(-1);
	}
	send_handle = gre_io_open(channel, GRE_IO_TYPE_WRONLY);
	if(send_handle == NULL && channel != NULL ) {
		syslog(LOG_ERR,"Can't open send handle\n");
		while ( not_connect == 0 ) {
			send_handle = gre_io_open(channel, GRE_IO_TYPE_WRONLY);
			if ( send_handle != NULL ) {
				not_connect = 1;
			}
			syslog(LOG_INFO,"Waiting to connect\n");
			sleep(1);
		}
	}

	// push the send handle into the thread data pointer so we can access it in our check_tmep thread.
	data1.send_handle = send_handle;
#endif
	FILE * t_fd = fopen("/tmp/set_point", "r");
	char temp_buf[32];
	long length;
	if ( t_fd ) {
		while ( fgets(temp_buf, 32, t_fd) != NULL )  {
		}
	}
	fclose(t_fd);
	if ( temp_buf ) {
		data1.temp_data.set_point = atof(temp_buf);
		syslog(LOG_DEBUG, "Setpoint converted to float is %f\n", data1.temp_data.set_point);
	}
	syslog(LOG_INFO,"Fermtroller starting");
	pthread_create(&temperature_thread, NULL, (void *)&check_temperature, &data1);
	sleep(1);
	pthread_create(&templog_thread, NULL, (void *)&log_temp, &data1);
	pthread_create(&setpoint_thread, NULL, (void *)&read_setpoint, &data1);
	ret = pthread_mutex_init(&mutex, NULL);
	if(ret != 0) {
		syslog(LOG_ERR,"Mutex error\n");
		return -1;
	}

	ret = pthread_cond_init(&condvar, NULL);
	if(ret != 0) {
		syslog(LOG_ERR,"Condvar error\n");
		return -1;
	}
	
	//get_input(&data1);
	while(!done) {
		syslog(LOG_INFO,"waiting\n");
		pthread_mutex_lock(&mutex);
		pthread_cond_wait(&condvar, &mutex);
	}


	lcfg_delete(cfg);
	free (temp_wort);
	free (temp_ambient);
	free (web_address);
	free (user);
	free (pass);
	syslog(LOG_INFO,"Fermtroller shutting down\n");

	close(cool_fd);
	close(heat_fd);
	closelog();
	return 0;
}