예제 #1
0
int lirc_code2char(const struct lirc_state *state, struct lirc_config *config,char *code,char **string)
{
	if(config->sockfd!=-1)
	{
		char command[10+strlen(code)+1+1];
		static char buf[LIRC_PACKET_SIZE];
		size_t buf_len = LIRC_PACKET_SIZE;
		int success;
		int ret;
		
		sprintf(command, "CODE %s\n", code);
		
		ret = lirc_send_command(state, config->sockfd, command,
					buf, &buf_len, &success);
		if(success == LIRC_RET_SUCCESS)
		{
			if(ret > 0)
			{
				*string = buf;
			}
			else
			{
				*string = NULL;
			}
			return LIRC_RET_SUCCESS;
		}
		return LIRC_RET_ERROR;
	}
	return lirc_code2char_internal(state, config, code, string, NULL);
}
예제 #2
0
const char *lirc_getmode(const struct lirc_state *state, struct lirc_config *config)
{
	if(config->sockfd!=-1)
	{
		static char buf[LIRC_PACKET_SIZE];
		size_t buf_len = LIRC_PACKET_SIZE;
		int success;
		int ret;
		
		ret = lirc_send_command(state, config->sockfd, "GETMODE\n",
					buf, &buf_len, &success);
		if(success == LIRC_RET_SUCCESS)
		{
			if(ret > 0)
			{
				return buf;
			}
			else
			{
				return NULL;
			}
		}
		return NULL;
	}
	return config->current_mode;
}
예제 #3
0
int lirc_identify(const struct lirc_state *state, int sockfd)
{
	char command[10+strlen(state->lirc_prog)+1+1];
	int success;
	
	sprintf(command, "IDENT %s\n", state->lirc_prog);
	
	(void) lirc_send_command(state, sockfd, command, NULL, NULL, &success);
	return success;
}
예제 #4
0
int lirc_identify(const struct lirc_state *state, int sockfd)
{
	char* command = malloc((10+strlen(state->lirc_prog)+1+1) * sizeof(char));
	if (command == NULL)
		return LIRC_RET_ERROR;
	int success;

	sprintf(command, "IDENT %s\n", state->lirc_prog);

	(void) lirc_send_command(state, sockfd, command, NULL, NULL, &success);
	free(command);
	return success;
}
예제 #5
0
const char *lirc_setmode(const struct lirc_state *state, struct lirc_config *config, const char *mode)
{
	if(config->sockfd!=-1)
	{
		static char buf[LIRC_PACKET_SIZE];
		size_t buf_len = LIRC_PACKET_SIZE;
		int success;
		int ret;
		char cmd[LIRC_PACKET_SIZE];
		if(snprintf(cmd, LIRC_PACKET_SIZE, "SETMODE%s%s\n",
			    mode ? " ":"",
			    mode ? mode:"")
		   >= LIRC_PACKET_SIZE)
		{
			return NULL;
		}
		
		ret = lirc_send_command(state, config->sockfd, cmd,
					buf, &buf_len, &success);
		if(success == LIRC_RET_SUCCESS)
		{
			if(ret > 0)
			{
				return buf;
			}
			else
			{
				return NULL;
			}
		}
		return NULL;
	}
	
	free(config->current_mode);
	config->current_mode = mode ? strdup(mode) : NULL;
	return config->current_mode;
}