static int thd72_get_channel(RIG *rig, channel_t *chan) { int retval, len; char cmd[8], buf[72]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); if (chan->vfo == RIG_VFO_MEM) { /* memory channel */ sprintf(cmd, "ME %03d", chan->channel_num); retval = kenwood_transaction(rig, cmd, buf, sizeof (buf)); if (retval != RIG_OK) return retval; retval = thd72_parse_channel(1, buf, chan); if (retval != RIG_OK) return retval; cmd[1] = 'N'; /* change ME to MN */ retval = kenwood_transaction(rig, cmd, buf, sizeof (buf)); if (retval != RIG_OK) return retval; len = strlen(buf); memcpy(chan->channel_desc, buf+7, len-7); } else { /* current channel */ retval = thd72_get_freq_info(rig, chan->vfo, buf); if (retval != RIG_OK) return retval; return thd72_parse_channel(0, buf, chan); } return RIG_OK; }
static int thd72_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) { int retval, tinx; char buf[64]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); retval = thd72_get_freq_info(rig, vfo, buf); if (retval != RIG_OK) { return retval; } if (buf[24] == '0') /* no tsql */ { *tone = 0; } else { sscanf(buf + 33, "%d", &tinx); if (tinx >= 0 && tinx <= 41) { *tone = kenwood42_ctcss_list[tinx]; } else { return -RIG_EINVAL; } } return RIG_OK; }
static int thd72_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) { int retval, cinx; char buf[64]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); retval = thd72_get_freq_info(rig, vfo, buf); if (retval != RIG_OK) { return retval; } if (buf[26] == '0') /* no tone */ { *code = 0; } else { sscanf(buf + 36, "%d", &cinx); *code = thd72dcs_list[cinx]; } return RIG_OK; }
/* item is an offset into reply buf that is a single char */ static int thd72_get_freq_item(RIG *rig, vfo_t vfo, int item, int hi, int *val) { int retval, lval; char c, buf[64]; retval = thd72_get_freq_info(rig, vfo, buf); if (retval != RIG_OK) { return retval; } c = buf[item]; if (c < '0' || c > '9') { return -RIG_EPROTO; } lval = c - '0'; if (lval > hi) { return -RIG_EPROTO; } *val = lval; return RIG_OK; }
static int thd72_set_freq_item(RIG *rig, vfo_t vfo, int item, int val) { int retval; char buf[64]; retval = thd72_get_freq_info(rig, vfo, buf); if (retval != RIG_OK) return retval; buf[item] = val + '0'; return kenwood_simple_transaction(rig, buf, 52); }
static int thd72_get_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t *offs) { int retval; char buf[64]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); retval = thd72_get_freq_info(rig, vfo, buf); if (retval != RIG_OK) return retval; sscanf(buf+42, "%ld", offs); return RIG_OK; }
static int thd72_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { int retval; char buf[64]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); retval = thd72_get_freq_info(rig, vfo, buf); if (retval != RIG_OK) return retval; sscanf(buf+5, "%"SCNfreq, freq); return RIG_OK; }
static int thd72_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t offs) { int retval; char boff[9], buf[64]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); retval = thd72_get_freq_info(rig, vfo, buf); if (retval != RIG_OK) return retval; sprintf(boff, "%08ld", offs); memcpy(buf+42, boff, 8); retval = kenwood_simple_transaction(rig, buf, 52); return retval; }
static int thd72_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { int retval; char buf[64], fbuf[11]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); retval = thd72_get_freq_info(rig, vfo, buf); if (retval != RIG_OK) return retval; sprintf(fbuf, "%010"PRIll, (int64_t)freq); memcpy(buf+5, fbuf, 10); retval = kenwood_simple_transaction(rig, buf, 52); return retval; }
static int thd72_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) { int retval, tinx; char buf[64], tmp[4]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); tinx = 0; /* default */ if (tone != 0) { for (tinx = 0; tinx < 42; tinx++) { if (tone == kenwood42_ctcss_list[tinx]) { break; } } if (tinx >= 42) { return -RIG_EINVAL; } } retval = thd72_get_freq_info(rig, vfo, buf); if (retval != RIG_OK) { return retval; } buf[24] = (tone == 0) ? '0' : '1'; sprintf(tmp, "%02d", tinx); memcpy(buf + 33, tmp, 2); return kenwood_simple_transaction(rig, buf, 52); }
static int thd72_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) { int retval, cinx; char buf[64], tmp[4]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); cinx = 0; /* default */ if (code != 0) { for (cinx = 0; cinx < 104; cinx++) { if (code == thd72dcs_list[cinx]) { break; } } if (cinx >= 104) { return -RIG_EINVAL; } } retval = thd72_get_freq_info(rig, vfo, buf); if (retval != RIG_OK) { return retval; } buf[26] = (code == 0) ? '0' : '1'; sprintf(tmp, "%03d", cinx); memcpy(buf + 36, tmp, 3); return kenwood_simple_transaction(rig, buf, 52); }