Example #1
0
File: mem.c Project: airween/hamlib
/**
 * \brief lookup the memory type and capabilities
 * \param rig   The rig handle
 * \param ch    The memory channel number
 *
 *  Lookup the memory type and capabilities associated with a channel number.
 *  If \a ch equals RIG_MEM_CAPS_ALL, then a union of all the mem_caps sets
 *  is returned (pointer to static memory).
 *
 * \return a pointer to a chan_t structure if the operation has been sucessful,
 * otherwise a NULL pointer, most probably because of incorrect channel number
 * or buggy backend.
 */
const chan_t *HAMLIB_API rig_lookup_mem_caps(RIG *rig, int ch)
{
    chan_t *chan_list;
    static chan_t chan_list_all;
    int i, j;

    rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);

    if (CHECK_RIG_ARG(rig))
    {
        return NULL;
    }

    if (ch == RIG_MEM_CAPS_ALL)
    {
        memset(&chan_list_all, 0, sizeof(chan_list_all));
        chan_list = rig->state.chan_list;
        chan_list_all.start = chan_list[0].start;
        chan_list_all.type = RIG_MTYPE_NONE;    /* meaningless */

        for (i = 0; i < CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++)
        {

            unsigned char *p1, *p2;
            p1 = (unsigned char *)&chan_list_all.mem_caps;
            p2 = (unsigned char *)&chan_list[i].mem_caps;

            /* It's kind of hackish, we just want to do update set with:
             *  chan_list_all.mem_caps |= chan_list[i].mem_caps
             */
            for (j = 0; j < sizeof(channel_cap_t); j++)
            {
                p1[j] |= p2[j];
            }

            /* til the end, most probably meaningless */
            chan_list_all.end = chan_list[i].end;
        }

        return &chan_list_all;
    }

    chan_list = rig->state.chan_list;

    for (i = 0; i < CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++)
    {
        if (ch >= chan_list[i].start && ch <= chan_list[i].end)
        {
            return &chan_list[i];
        }
    }

    return NULL;
}
Example #2
0
File: mem.c Project: airween/hamlib
int set_chan_all_cb_generic(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg)
{
    int i, j, retval;
    chan_t *chan_list = rig->state.chan_list;
    channel_t *chan;

    for (i = 0; !RIG_IS_CHAN_END(chan_list[i]) && i < CHANLSTSIZ; i++)
    {

        for (j = chan_list[i].start; j <= chan_list[i].end; j++)
        {

            chan_cb(rig, &chan, j, chan_list, arg);
            chan->vfo = RIG_VFO_MEM;

            retval = rig_set_channel(rig, chan);

            if (retval != RIG_OK)
            {
                return retval;
            }
        }
    }

    return RIG_OK;
}
Example #3
0
File: mem.c Project: DF4OR/hamlib
int get_chan_all_cb_generic (RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg)
{
	int i,j,retval;
	chan_t *chan_list = rig->state.chan_list;
	channel_t *chan;

 	for (i=0; !RIG_IS_CHAN_END(chan_list[i]) && i < CHANLSTSIZ; i++) {

		/*
		 * setting chan to NULL means the application
		 * has to provide a struct where to store data
		 * future data for channel channel_num
		 */
		chan = NULL;
		retval = chan_cb(rig, &chan, chan_list[i].start, chan_list, arg);
		if (retval != RIG_OK)
			return retval;
		if (chan == NULL)
			return -RIG_ENOMEM;

		for (j = chan_list[i].start; j <= chan_list[i].end; j++) {
			int chan_next;

			chan->vfo = RIG_VFO_MEM;
			chan->channel_num = j;

			/*
			 * TODO: if doesn't have rc->get_channel, special generic
			 */
			retval = rig_get_channel(rig, chan);

			if (retval == -RIG_ENAVAIL) {
				/*
				 * empty channel
				 *
				 * Should it continue or call chan_cb with special arg?
				 */
				continue;
			}

			if (retval != RIG_OK)
				return retval;

			chan_next = j < chan_list[i].end ? j+1 : j;

			chan_cb(rig, &chan, chan_next, chan_list, arg);
		}
	}

	return RIG_OK;
}
Example #4
0
File: mem.c Project: DF4OR/hamlib
/**
 * \brief get memory channel count
 * \param rig	The rig handle
 *
 *  Get the total memory channel count, computed from the rig caps
 *
 * \return the memory count
 */
int HAMLIB_API rig_mem_count(RIG *rig)
{
	const chan_t *chan_list;
	int i, count;

	if (CHECK_RIG_ARG(rig))
		return -RIG_EINVAL;

	chan_list = rig->state.chan_list;
	count = 0;

	for (i=0; i<CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++) {
		count += chan_list[i].end - chan_list[i].start + 1;
	}

	return count;
}
Example #5
0
File: mem.c Project: airween/hamlib
/**
 * \brief get memory channel count
 * \param rig   The rig handle
 *
 *  Get the total memory channel count, computed from the rig caps
 *
 * \return the memory count
 */
int HAMLIB_API rig_mem_count(RIG *rig)
{
    const chan_t *chan_list;
    int i, count;

    rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);

    if (CHECK_RIG_ARG(rig))
    {
        return -RIG_EINVAL;
    }

    chan_list = rig->state.chan_list;
    count = 0;

    for (i = 0; i < CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++)
    {
        count += chan_list[i].end - chan_list[i].start + 1;
    }

    return count;
}
Example #6
0
File: aor.c Project: airween/hamlib
int aor_get_channel(RIG *rig, channel_t *chan)
{
	struct aor_priv_caps *priv = (struct aor_priv_caps*)rig->caps->priv;
	char aorcmd[BUFSZ];
	int cmd_len, chan_len;
	char chanbuf[BUFSZ];
	int retval, i;
	channel_cap_t *mem_caps = NULL;
	chan_t *chan_list;
	int mem_num, channel_num = chan->channel_num;
	char bank_base;

	chan_list = rig->caps->chan_list;

	if (chan->vfo == RIG_VFO_CURR) {
		/*
		 * curr VFO mem_caps same as memory caps
		 */
		mem_caps = &chan_list[0].mem_caps;
	} else {

		/*
		 * find mem_caps in caps, we'll need it later
		 */
		for (i=0; i<CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++) {
			if (channel_num >= chan_list[i].start &&
					channel_num <= chan_list[i].end) {
				mem_caps = &chan_list[i].mem_caps;
				break;
			}
		}
		if (!mem_caps)
			return -RIG_EINVAL;


		/*
		 * FIXME: we're assuming the banks are split 50/50.
		 * 	MW should be called the first time instead,
		 * 	and sizing memorized.
		 */
		mem_num = channel_num%100;
		if (mem_num >= 50 && priv->bank_base1 != priv->bank_base2) {
			bank_base = priv->bank_base2;
			mem_num -= 50;
		} else {
			bank_base = priv->bank_base1;
		}

		cmd_len = sprintf(aorcmd, "MR%c%02d" EOM,
				bank_base + channel_num/100, mem_num);
		retval = aor_transaction (rig, aorcmd, cmd_len, chanbuf, &chan_len);

		/* is the channel empty? */
		if (retval == -RIG_EPROTO && chanbuf[0] == '?') {
			chan->freq = RIG_FREQ_NONE;
			return -RIG_ENAVAIL;
		}

		if (retval != RIG_OK)
			return retval;
	}

	cmd_len = sprintf(aorcmd, "RX" EOM);
	retval = aor_transaction (rig, aorcmd, cmd_len, chanbuf, &chan_len);
	if (retval != RIG_OK)
		return retval;

	retval = parse_chan_line(rig, chan, chanbuf, mem_caps);

	return retval;
}