Formatted tests/ to final coding guidelines

pull/1/head
Nate Bargmann 2017-10-06 18:58:42 -05:00
rodzic ab3e6bb5a5
commit b692fb22ef
25 zmienionych plików z 3337 dodań i 1666 usunięć

Wyświetl plik

@ -51,7 +51,8 @@ int dumpcaps(RIG *rig, FILE *fout)
int backend_warnings = 0;
static char prntbuf[1024]; /* a malloc would be better.. */
if (!rig || !rig->caps) {
if (!rig || !rig->caps)
{
return -RIG_EINVAL;
}
@ -65,7 +66,8 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "Backend status:\t%s\n", rig_strstatus(caps->status));
fprintf(fout, "Rig type:\t");
switch (caps->rig_type & RIG_TYPE_MASK) {
switch (caps->rig_type & RIG_TYPE_MASK)
{
case RIG_TYPE_TRANSCEIVER:
fprintf(fout, "Transceiver\n");
break;
@ -113,7 +115,8 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "PTT type:\t");
switch (caps->ptt_type) {
switch (caps->ptt_type)
{
case RIG_PTT_RIG:
fprintf(fout, "Rig capable\n");
break;
@ -145,7 +148,8 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "DCD type:\t");
switch (caps->dcd_type) {
switch (caps->dcd_type)
{
case RIG_DCD_RIG:
fprintf(fout, "Rig capable\n");
break;
@ -177,7 +181,8 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "Port type:\t");
switch (caps->port_type) {
switch (caps->port_type)
{
case RIG_PORT_SERIAL:
fprintf(fout, "RS-232\n");
fprintf(fout,
@ -186,9 +191,9 @@ int dumpcaps(RIG *rig, FILE *fout)
caps->serial_rate_max,
caps->serial_data_bits,
caps->serial_parity == RIG_PARITY_NONE ? 'N' :
caps->serial_parity == RIG_PARITY_ODD ? 'O' :
caps->serial_parity == RIG_PARITY_EVEN ? 'E' :
caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S',
caps->serial_parity == RIG_PARITY_ODD ? 'O' :
caps->serial_parity == RIG_PARITY_EVEN ? 'E' :
caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S',
caps->serial_stop_bits,
caps->serial_handshake == RIG_HANDSHAKE_NONE ? "" :
(caps->serial_handshake == RIG_HANDSHAKE_XONXOFF ? "XONXOFF" : "CTS/RTS")
@ -257,22 +262,26 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "Preamp:");
for (i = 0; i < MAXDBLSTSIZ && caps->preamp[i] != 0; i++) {
for (i = 0; i < MAXDBLSTSIZ && caps->preamp[i] != 0; i++)
{
fprintf(fout, " %ddB", caps->preamp[i]);
}
if (i == 0) {
if (i == 0)
{
fprintf(fout, " None");
}
fprintf(fout, "\n");
fprintf(fout, "Attenuator:");
for (i = 0; i < MAXDBLSTSIZ && caps->attenuator[i] != 0; i++) {
for (i = 0; i < MAXDBLSTSIZ && caps->attenuator[i] != 0; i++)
{
fprintf(fout, " %ddB", caps->attenuator[i]);
}
if (i == 0) {
if (i == 0)
{
fprintf(fout, " None");
}
@ -280,15 +289,19 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "CTCSS:");
for (i = 0; caps->ctcss_list && i < 60 && caps->ctcss_list[i] != 0; i++) {
for (i = 0; caps->ctcss_list && i < 60 && caps->ctcss_list[i] != 0; i++)
{
fprintf(fout,
" %d.%1d",
caps->ctcss_list[i] / 10, caps->ctcss_list[i] % 10);
}
if (i == 0) {
if (i == 0)
{
fprintf(fout, " None");
} else {
}
else
{
fprintf(fout, " Hz, %d tones", i);
}
@ -296,13 +309,17 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "DCS:");
for (i = 0; caps->dcs_list && i < 128 && caps->dcs_list[i] != 0; i++) {
for (i = 0; caps->dcs_list && i < 128 && caps->dcs_list[i] != 0; i++)
{
fprintf(fout, " %d", caps->dcs_list[i]);
}
if (i == 0) {
if (i == 0)
{
fprintf(fout, " None");
} else {
}
else
{
fprintf(fout, ", %d codes", i);
}
@ -317,24 +334,27 @@ int dumpcaps(RIG *rig, FILE *fout)
sprintf_level_gran(prntbuf, caps->has_get_level, caps->level_gran);
fprintf(fout, "Get level: %s\n", prntbuf);
if ((caps->has_get_level & RIG_LEVEL_SQLSTAT)) {
if ((caps->has_get_level & RIG_LEVEL_SQLSTAT))
{
fprintf(fout, "Warning--backend uses deprecated SQLSTAT level!\n");
backend_warnings++;
}
if ((caps->has_get_level & RIG_LEVEL_RAWSTR)
&& caps->str_cal.size == 0
&& !(caps->has_get_level & RIG_LEVEL_STRENGTH)) {
&& !(caps->has_get_level & RIG_LEVEL_STRENGTH))
{
fprintf(fout,
"Warning--backend has get RAWSTR, but not calibration data\n");
backend_warnings++;
fprintf(fout,
"Warning--backend has get RAWSTR, but not calibration data\n");
backend_warnings++;
}
sprintf_level_gran(prntbuf, caps->has_set_level, caps->level_gran);
fprintf(fout, "Set level: %s\n", prntbuf);
if (caps->has_set_level & RIG_LEVEL_READONLY_LIST) {
if (caps->has_set_level & RIG_LEVEL_READONLY_LIST)
{
fprintf(fout, "Warning--backend can set readonly levels!\n");
backend_warnings++;
}
@ -349,7 +369,8 @@ int dumpcaps(RIG *rig, FILE *fout)
sprintf_parm_gran(prntbuf, caps->has_set_parm, caps->parm_gran);
fprintf(fout, "Set parameters: %s\n", prntbuf);
if (caps->has_set_parm & RIG_PARM_READONLY_LIST) {
if (caps->has_set_parm & RIG_PARM_READONLY_LIST)
{
fprintf(fout, "Warning--backend can set readonly parms!\n");
backend_warnings++;
}
@ -359,18 +380,24 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "\n");
if (rig->state.mode_list != 0) {
if (rig->state.mode_list != 0)
{
sprintf_mode(prntbuf, rig->state.mode_list);
} else {
}
else
{
strcpy(prntbuf, "None. This backend might be bogus!\n");
backend_warnings++;
}
fprintf(fout, "Mode list: %s\n", prntbuf);
if (rig->state.vfo_list != 0) {
if (rig->state.vfo_list != 0)
{
sprintf_vfo(prntbuf, rig->state.vfo_list);
} else {
}
else
{
strcpy(prntbuf, "None. This backend might be bogus!\n");
backend_warnings++;
}
@ -388,7 +415,8 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "Memories:");
for (i = 0; i < CHANLSTSIZ && caps->chan_list[i].type; i++) {
for (i = 0; i < CHANLSTSIZ && caps->chan_list[i].type; i++)
{
fprintf(fout,
"\n\t%d..%d: \t%s",
caps->chan_list[i].start,
@ -398,7 +426,8 @@ int dumpcaps(RIG *rig, FILE *fout)
dump_chan_caps(&caps->chan_list[i].mem_caps, fout);
}
if (i == 0) {
if (i == 0)
{
fprintf(fout, " None");
}
@ -411,7 +440,8 @@ int dumpcaps(RIG *rig, FILE *fout)
status ? "Bad" : "OK",
status);
if (status) {
if (status)
{
backend_warnings++;
}
@ -421,7 +451,8 @@ int dumpcaps(RIG *rig, FILE *fout)
status ? "Bad" : "OK",
status);
if (status) {
if (status)
{
backend_warnings++;
}
@ -431,7 +462,8 @@ int dumpcaps(RIG *rig, FILE *fout)
status ? "Bad" : "OK",
status);
if (status) {
if (status)
{
backend_warnings++;
}
@ -441,16 +473,21 @@ int dumpcaps(RIG *rig, FILE *fout)
status ? "Bad" : "OK",
status);
if (status) {
if (status)
{
backend_warnings++;
}
fprintf(fout, "Tuning steps:");
for (i = 0; i < TSLSTSIZ && !RIG_IS_TS_END(caps->tuning_steps[i]); i++) {
if (caps->tuning_steps[i].ts == RIG_TS_ANY) {
for (i = 0; i < TSLSTSIZ && !RIG_IS_TS_END(caps->tuning_steps[i]); i++)
{
if (caps->tuning_steps[i].ts == RIG_TS_ANY)
{
strcpy(freqbuf, "ANY"); /* strcpy! Looks safe for now */
} else {
}
else
{
sprintf_freq(freqbuf, caps->tuning_steps[i].ts);
}
@ -458,7 +495,8 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "\n\t%s: \t%s", freqbuf, prntbuf);
}
if (i == 0) {
if (i == 0)
{
fprintf(fout, " None! This backend might be bogus!");
backend_warnings++;
}
@ -467,16 +505,21 @@ int dumpcaps(RIG *rig, FILE *fout)
status = ts_sanity_check(caps->tuning_steps);
fprintf(fout, "Tuning steps status:\t%s (%d)\n", status ? "Bad" : "OK", status);
if (status) {
if (status)
{
backend_warnings++;
}
fprintf(fout, "Filters:");
for (i = 0; i < FLTLSTSIZ && !RIG_IS_FLT_END(caps->filters[i]); i++) {
if (caps->filters[i].width == RIG_FLT_ANY) {
for (i = 0; i < FLTLSTSIZ && !RIG_IS_FLT_END(caps->filters[i]); i++)
{
if (caps->filters[i].width == RIG_FLT_ANY)
{
strcpy(freqbuf, "ANY");
} else {
}
else
{
sprintf_freq(freqbuf, caps->filters[i].width);
}
@ -484,7 +527,8 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "\n\t%s: \t%s", freqbuf, prntbuf);
}
if (i == 0) {
if (i == 0)
{
fprintf(fout, " None. This backend might be bogus!");
backend_warnings++;
}
@ -493,10 +537,12 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "Bandwidths:");
for (i = 1; i < RIG_MODE_TESTS_MAX; i <<= 1) {
for (i = 1; i < RIG_MODE_TESTS_MAX; i <<= 1)
{
pbwidth_t pbnorm = rig_passband_normal(rig, i);
if (pbnorm == 0) {
if (pbnorm == 0)
{
continue;
}
@ -690,35 +736,46 @@ int range_sanity_check(const struct freq_range_list range_list[], int rx)
{
int i;
for (i = 0; i < FRQRANGESIZ; i++) {
if (range_list[i].start == 0 && range_list[i].end == 0) {
for (i = 0; i < FRQRANGESIZ; i++)
{
if (range_list[i].start == 0 && range_list[i].end == 0)
{
break;
}
if (range_list[i].start > range_list[i].end) {
if (range_list[i].start > range_list[i].end)
{
return -1;
}
if (range_list[i].modes == 0) {
if (range_list[i].modes == 0)
{
return -2;
}
if (rx) {
if (range_list[i].low_power > 0 && range_list[i].high_power > 0) {
if (rx)
{
if (range_list[i].low_power > 0 && range_list[i].high_power > 0)
{
return -3;
}
} else {
if (!(range_list[i].low_power > 0 && range_list[i].high_power > 0)) {
}
else
{
if (!(range_list[i].low_power > 0 && range_list[i].high_power > 0))
{
return -3;
}
if (range_list[i].low_power > range_list[i].high_power) {
if (range_list[i].low_power > range_list[i].high_power)
{
return -3;
}
}
}
if (i == FRQRANGESIZ) {
if (i == FRQRANGESIZ)
{
return -4;
}
@ -742,19 +799,23 @@ int ts_sanity_check(const struct tuning_step_list tuning_step[])
last_ts = 0;
last_modes = RIG_MODE_NONE;
for (i = 0; i < TSLSTSIZ; i++) {
if (RIG_IS_TS_END(tuning_step[i])) {
for (i = 0; i < TSLSTSIZ; i++)
{
if (RIG_IS_TS_END(tuning_step[i]))
{
break;
}
if (tuning_step[i].ts != RIG_TS_ANY
&& tuning_step[i].ts < last_ts
&& last_modes == tuning_step[i].modes) {
&& last_modes == tuning_step[i].modes)
{
return -1;
return -1;
}
if (tuning_step[i].modes == 0) {
if (tuning_step[i].modes == 0)
{
return -2;
}
@ -762,7 +823,8 @@ int ts_sanity_check(const struct tuning_step_list tuning_step[])
last_modes = tuning_step[i].modes;
}
if (i == TSLSTSIZ) {
if (i == TSLSTSIZ)
{
return -4;
}
@ -772,99 +834,123 @@ int ts_sanity_check(const struct tuning_step_list tuning_step[])
static void dump_chan_caps(const channel_cap_t *chan, FILE *fout)
{
if (chan->bank_num) {
if (chan->bank_num)
{
fprintf(fout, "BANK ");
}
if (chan->ant) {
if (chan->ant)
{
fprintf(fout, "ANT ");
}
if (chan->freq) {
if (chan->freq)
{
fprintf(fout, "FREQ ");
}
if (chan->mode) {
if (chan->mode)
{
fprintf(fout, "MODE ");
}
if (chan->width) {
if (chan->width)
{
fprintf(fout, "WIDTH ");
}
if (chan->tx_freq) {
if (chan->tx_freq)
{
fprintf(fout, "TXFREQ ");
}
if (chan->tx_mode) {
if (chan->tx_mode)
{
fprintf(fout, "TXMODE ");
}
if (chan->tx_width) {
if (chan->tx_width)
{
fprintf(fout, "TXWIDTH ");
}
if (chan->split) {
if (chan->split)
{
fprintf(fout, "SPLIT ");
}
if (chan->rptr_shift) {
if (chan->rptr_shift)
{
fprintf(fout, "RPTRSHIFT ");
}
if (chan->rptr_offs) {
if (chan->rptr_offs)
{
fprintf(fout, "RPTROFS ");
}
if (chan->tuning_step) {
if (chan->tuning_step)
{
fprintf(fout, "TS ");
}
if (chan->rit) {
if (chan->rit)
{
fprintf(fout, "RIT ");
}
if (chan->xit) {
if (chan->xit)
{
fprintf(fout, "XIT ");
}
if (chan->funcs) {
if (chan->funcs)
{
fprintf(fout, "FUNC "); /* TODO: iterate over the list */
}
if (chan->levels) {
if (chan->levels)
{
fprintf(fout, "LEVEL "); /* TODO: iterate over the list */
}
if (chan->ctcss_tone) {
if (chan->ctcss_tone)
{
fprintf(fout, "TONE ");
}
if (chan->ctcss_sql) {
if (chan->ctcss_sql)
{
fprintf(fout, "CTCSS ");
}
if (chan->dcs_code) {
if (chan->dcs_code)
{
fprintf(fout, "DCSCODE ");
}
if (chan->dcs_sql) {
if (chan->dcs_sql)
{
fprintf(fout, "DCSSQL ");
}
if (chan->scan_group) {
if (chan->scan_group)
{
fprintf(fout, "SCANGRP ");
}
if (chan->flags) {
if (chan->flags)
{
fprintf(fout, "FLAG "); /* TODO: iterate over the RIG_CHFLAG's */
}
if (chan->channel_desc) {
if (chan->channel_desc)
{
fprintf(fout, "NAME ");
}
if (chan->ext_levels) {
if (chan->ext_levels)
{
fprintf(fout, "EXTLVL ");
}
}

Wyświetl plik

@ -42,7 +42,8 @@ int dumpcaps_rot(ROT *rot, FILE *fout)
const struct rot_caps *caps;
int backend_warnings = 0;
if (!rot || !rot->caps) {
if (!rot || !rot->caps)
{
return -RIG_EINVAL;
}
@ -56,7 +57,8 @@ int dumpcaps_rot(ROT *rot, FILE *fout)
fprintf(fout, "Backend status:\t\t%s\n", rig_strstatus(caps->status));
fprintf(fout, "Rot type:\t\t");
switch (caps->rot_type & ROT_TYPE_MASK) {
switch (caps->rot_type & ROT_TYPE_MASK)
{
case ROT_TYPE_OTHER:
fprintf(fout, "Other\n");
break;
@ -80,7 +82,8 @@ int dumpcaps_rot(ROT *rot, FILE *fout)
fprintf(fout, "Port type:\t\t");
switch (caps->port_type) {
switch (caps->port_type)
{
case RIG_PORT_SERIAL:
fprintf(fout, "RS-232\n");
fprintf(fout,
@ -88,10 +91,10 @@ int dumpcaps_rot(ROT *rot, FILE *fout)
caps->serial_rate_min,
caps->serial_rate_max,
caps->serial_data_bits,
caps->serial_parity == RIG_PARITY_NONE ? 'N' :
caps->serial_parity == RIG_PARITY_ODD ? 'O' :
caps->serial_parity == RIG_PARITY_EVEN ? 'E' :
caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S',
caps->serial_parity == RIG_PARITY_NONE ? 'N' :
caps->serial_parity == RIG_PARITY_ODD ? 'O' :
caps->serial_parity == RIG_PARITY_EVEN ? 'E' :
caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S',
caps->serial_stop_bits,
caps->serial_handshake == RIG_HANDSHAKE_NONE ? "" :
(caps->serial_handshake == RIG_HANDSHAKE_XONXOFF ? " XONXOFF" : " CTS/RTS")

Wyświetl plik

@ -44,14 +44,16 @@ int main(int argc, char *argv[])
RIG *my_rig;
int status, i, j;
if (argc != 2) {
if (argc != 2)
{
fprintf(stderr, "%s <rig_num>\n", argv[0]);
exit(1);
}
my_rig = rig_init(atoi(argv[1]));
if (!my_rig) {
if (!my_rig)
{
fprintf(stderr, "Unknown rig num: %d\n", atoi(argv[1]));
fprintf(stderr, "Please check riglist.h\n");
exit(1); /* whoops! something went wrong (mem alloc?) */
@ -59,14 +61,16 @@ int main(int argc, char *argv[])
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
if (rig_open(my_rig)) {
if (rig_open(my_rig))
{
exit(2);
}
status = rig_set_vfo(my_rig, RIG_VFO_B);
if (status != RIG_OK) {
if (status != RIG_OK)
{
printf("rig_set_vfo: error = %s \n", rigerror(status));
}
@ -82,9 +86,11 @@ int main(int argc, char *argv[])
* }
*/
for (i = 0; my_rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) {
for (i = 0; my_rig->state.chan_list[i].type && i < CHANLSTSIZ; i++)
{
for (j = my_rig->state.chan_list[i].start;
j <= my_rig->state.chan_list[i].end; j++) {
j <= my_rig->state.chan_list[i].end; j++)
{
dump_chan(my_rig, j);
}
}
@ -108,33 +114,40 @@ static char * decode_modes(rmode_t modes)
buf[0] = '\0';
if (modes & RIG_MODE_AM) {
if (modes & RIG_MODE_AM)
{
strcat(buf, "AM ");
}
if (modes & RIG_MODE_CW) {
if (modes & RIG_MODE_CW)
{
strcat(buf, "CW ");
}
if (modes & RIG_MODE_USB) {
if (modes & RIG_MODE_USB)
{
strcat(buf, "USB ");
}
if (modes & RIG_MODE_LSB) {
if (modes & RIG_MODE_LSB)
{
strcat(buf, "LSB ");
}
if (modes & RIG_MODE_RTTY) {
if (modes & RIG_MODE_RTTY)
{
strcat(buf, "RTTY ");
}
if (modes & RIG_MODE_FM) {
if (modes & RIG_MODE_FM)
{
strcat(buf, "FM ");
}
#ifdef RIG_MODE_WFM
if (modes & RIG_MODE_WFM) {
if (modes & RIG_MODE_WFM)
{
strcat(buf, "WFM ");
}
@ -154,7 +167,8 @@ int dump_chan(RIG *rig, int chan_num)
chan.channel_num = chan_num;
status = rig_get_channel(rig, &chan);
if (status != RIG_OK) {
if (status != RIG_OK)
{
printf("rig_get_channel: error = %s \n", rigerror(status));
return status;
}
@ -199,150 +213,187 @@ int dump_chan(RIG *rig, int chan_num)
printf("Functions: ");
if (chan.funcs != 0) {
if (chan.funcs & RIG_FUNC_FAGC) {
if (chan.funcs != 0)
{
if (chan.funcs & RIG_FUNC_FAGC)
{
printf("FAGC ");
}
if (chan.funcs & RIG_FUNC_NB) {
if (chan.funcs & RIG_FUNC_NB)
{
printf("NB ");
}
if (chan.funcs & RIG_FUNC_COMP) {
if (chan.funcs & RIG_FUNC_COMP)
{
printf("COMP ");
}
if (chan.funcs & RIG_FUNC_VOX) {
if (chan.funcs & RIG_FUNC_VOX)
{
printf("VOX ");
}
if (chan.funcs & RIG_FUNC_TONE) {
if (chan.funcs & RIG_FUNC_TONE)
{
printf("TONE ");
}
if (chan.funcs & RIG_FUNC_TSQL) {
if (chan.funcs & RIG_FUNC_TSQL)
{
printf("TSQL ");
}
if (chan.funcs & RIG_FUNC_SBKIN) {
if (chan.funcs & RIG_FUNC_SBKIN)
{
printf("SBKIN ");
}
if (chan.funcs & RIG_FUNC_FBKIN) {
if (chan.funcs & RIG_FUNC_FBKIN)
{
printf("FBKIN ");
}
if (chan.funcs & RIG_FUNC_ANF) {
if (chan.funcs & RIG_FUNC_ANF)
{
printf("ANF ");
}
if (chan.funcs & RIG_FUNC_NR) {
if (chan.funcs & RIG_FUNC_NR)
{
printf("NR ");
}
if (chan.funcs & RIG_FUNC_AIP) {
if (chan.funcs & RIG_FUNC_AIP)
{
printf("AIP ");
}
if (chan.funcs & RIG_FUNC_APF) {
if (chan.funcs & RIG_FUNC_APF)
{
printf("APF ");
}
if (chan.funcs & RIG_FUNC_MON) {
if (chan.funcs & RIG_FUNC_MON)
{
printf("MON ");
}
if (chan.funcs & RIG_FUNC_MN) {
if (chan.funcs & RIG_FUNC_MN)
{
printf("MN ");
}
if (chan.funcs & RIG_FUNC_RF) {
if (chan.funcs & RIG_FUNC_RF)
{
printf("RF ");
}
printf("\n");
} else {
}
else
{
printf("none\n");
}
if (rig_has_set_level(rig, RIG_LEVEL_PREAMP)) {
if (rig_has_set_level(rig, RIG_LEVEL_PREAMP))
{
printf("PREAMP: %ddB\n", chan.levels[rig_setting2idx(RIG_LEVEL_PREAMP)].i);
}
if (rig_has_set_level(rig, RIG_LEVEL_ATT)) {
if (rig_has_set_level(rig, RIG_LEVEL_ATT))
{
printf("ATT: %ddB\n", chan.levels[rig_setting2idx(RIG_LEVEL_ATT)].i);
}
if (rig_has_set_level(rig, RIG_LEVEL_AF)) {
if (rig_has_set_level(rig, RIG_LEVEL_AF))
{
printf("AF: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_AF)].f);
}
if (rig_has_set_level(rig, RIG_LEVEL_RF)) {
if (rig_has_set_level(rig, RIG_LEVEL_RF))
{
printf("RF: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_RF)].f);
}
if (rig_has_set_level(rig, RIG_LEVEL_SQL)) {
if (rig_has_set_level(rig, RIG_LEVEL_SQL))
{
printf("SQL: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_SQL)].f);
}
if (rig_has_set_level(rig, RIG_LEVEL_IF)) {
if (rig_has_set_level(rig, RIG_LEVEL_IF))
{
printf("IF: %dHz\n", chan.levels[rig_setting2idx(RIG_LEVEL_IF)].i);
}
if (rig_has_set_level(rig, RIG_LEVEL_APF)) {
if (rig_has_set_level(rig, RIG_LEVEL_APF))
{
printf("APF: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_APF)].f);
}
if (rig_has_set_level(rig, RIG_LEVEL_NR)) {
if (rig_has_set_level(rig, RIG_LEVEL_NR))
{
printf("NR: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_NR)].f);
}
if (rig_has_set_level(rig, RIG_LEVEL_PBT_IN)) {
if (rig_has_set_level(rig, RIG_LEVEL_PBT_IN))
{
printf("PBT_IN: %g%%\n",
100 * chan.levels[rig_setting2idx(RIG_LEVEL_PBT_IN)].f);
}
if (rig_has_set_level(rig, RIG_LEVEL_PBT_OUT)) {
if (rig_has_set_level(rig, RIG_LEVEL_PBT_OUT))
{
printf("PBT_OUT: %g%%\n",
100 * chan.levels[rig_setting2idx(RIG_LEVEL_PBT_OUT)].f);
}
if (rig_has_set_level(rig, RIG_LEVEL_CWPITCH)) {
if (rig_has_set_level(rig, RIG_LEVEL_CWPITCH))
{
printf("CWPITCH: %dHz\n", chan.levels[rig_setting2idx(RIG_LEVEL_CWPITCH)].i);
}
if (rig_has_set_level(rig, RIG_LEVEL_RFPOWER)) {
if (rig_has_set_level(rig, RIG_LEVEL_RFPOWER))
{
printf("RFPOWER: %g%%\n",
100 * chan.levels[rig_setting2idx(RIG_LEVEL_RFPOWER)].f);
}
if (rig_has_set_level(rig, RIG_LEVEL_MICGAIN)) {
if (rig_has_set_level(rig, RIG_LEVEL_MICGAIN))
{
printf("MICGAIN: %g%%\n",
100 * chan.levels[rig_setting2idx(RIG_LEVEL_MICGAIN)].f);
}
if (rig_has_set_level(rig, RIG_LEVEL_COMP)) {
if (rig_has_set_level(rig, RIG_LEVEL_COMP))
{
printf("COMP: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_COMP)].f);
}
if (rig_has_set_level(rig, RIG_LEVEL_BALANCE)) {
if (rig_has_set_level(rig, RIG_LEVEL_BALANCE))
{
printf("BALANCE: %g%%\n",
100 * chan.levels[rig_setting2idx(RIG_LEVEL_BALANCE)].f);
}
if (rig_has_set_level(rig, RIG_LEVEL_KEYSPD)) {
if (rig_has_set_level(rig, RIG_LEVEL_KEYSPD))
{
printf("KEYSPD: %d\n", chan.levels[rig_setting2idx(RIG_LEVEL_KEYSPD)].i);
}
if (rig_has_set_level(rig, RIG_LEVEL_NOTCHF)) {
if (rig_has_set_level(rig, RIG_LEVEL_NOTCHF))
{
printf("NOTCHF: %d\n", chan.levels[rig_setting2idx(RIG_LEVEL_NOTCHF)].i);
}
if (rig_has_set_level(rig, RIG_LEVEL_AGC)) {
if (rig_has_set_level(rig, RIG_LEVEL_AGC))
{
printf("AGC: %d\n", chan.levels[rig_setting2idx(RIG_LEVEL_AGC)].i);
}
if (rig_has_set_level(rig, RIG_LEVEL_BKINDL)) {
if (rig_has_set_level(rig, RIG_LEVEL_BKINDL))
{
printf("BKINDL: %d\n", chan.levels[rig_setting2idx(RIG_LEVEL_BKINDL)].i);
}

Wyświetl plik

@ -61,7 +61,8 @@ int main()
/* Current mode */
status = rig_get_mode(my_rig, RIG_VFO_CURR, &mode, &width);
switch (mode) {
switch (mode)
{
case RIG_MODE_USB:
mm = "USB";
break;

Wyświetl plik

@ -38,7 +38,8 @@ int print_caps_sum(const struct rig_caps *caps, void *data)
printf("%-10s\t", rig_strstatus(caps->status));
switch (caps->rig_type & RIG_TYPE_MASK) {
switch (caps->rig_type & RIG_TYPE_MASK)
{
case RIG_TYPE_TRANSCEIVER:
printf("Transceiver\n");
break;
@ -93,7 +94,8 @@ int main(int argc, char *argv[])
status = rig_list_foreach(print_caps_sum, NULL);
if (status != RIG_OK) {
if (status != RIG_OK)
{
printf("rig_list_foreach: error = %s \n", rigerror(status));
exit(3);
}

Wyświetl plik

@ -86,11 +86,13 @@ int csv_save(RIG *rig, const char *outfilename)
f = fopen(outfilename, "w");
if (!f) {
if (!f)
{
return -1;
}
if (rig->caps->clone_combo_get) {
if (rig->caps->clone_combo_get)
{
printf("About to save data, enter cloning mode: %s\n",
rig->caps->clone_combo_get);
}
@ -123,12 +125,14 @@ int csv_load(RIG *rig, const char *infilename)
f = fopen(infilename, "r");
if (!f) {
if (!f)
{
return -1;
}
/* First read the first line, containing the key */
if (fgets(keys, sizeof(keys), f) != NULL) {
if (fgets(keys, sizeof(keys), f) != NULL)
{
/* fgets stores '\n' in a buffer, get rid of it */
keys[ strlen(keys) - 1 ] = '\0';
@ -138,25 +142,30 @@ int csv_load(RIG *rig, const char *infilename)
if (!tokenize_line(keys,
key_list,
sizeof(key_list) / sizeof(char *),
',')) {
','))
{
fprintf(stderr,
"Invalid (possibly too long or empty) key line, cannot continue.\n");
fclose(f);
return -1;
}
} else {
}
else
{
/* File exists, but is empty */
fclose(f);
return -1;
}
/* Next, read the file line by line */
while (fgets(line, sizeof line, f) != NULL) {
while (fgets(line, sizeof line, f) != NULL)
{
/* Tokenize the line */
if (!tokenize_line(line,
value_list,
sizeof(value_list) / sizeof(char *),
',')) {
','))
{
fprintf(stderr, "Invalid (possibly too long or empty) line ignored\n");
continue;
@ -168,7 +177,8 @@ int csv_load(RIG *rig, const char *infilename)
/* Write a rig memory */
status = rig_set_channel(rig, &chan);
if (status != RIG_OK) {
if (status != RIG_OK)
{
fprintf(stderr, "rig_get_channel: error = %s \n", rigerror(status));
fclose(f);
return status;
@ -193,18 +203,20 @@ int csv_load(RIG *rig, const char *infilename)
\return number of tokens on success, 0 if \param token_list is too small to contain all the tokens,
or if line was empty.
*/
static int tokenize_line(char *line, char **token_list, size_t siz, char delim)
static int tokenize_line(char *line, char **token_list, size_t siz, char delim)
{
size_t i;
char *tok;
/* Erase the table */
for (i = 0; i < siz; i++) {
for (i = 0; i < siz; i++)
{
token_list[i] = NULL;
}
/* Empty line passed? */
if (line == NULL) {
if (line == NULL)
{
return 0;
}
@ -213,18 +225,21 @@ static int tokenize_line(char *line, char **token_list, size_t siz, char delim)
tok = mystrtok(line, delim);
/* Line contains no delim */
if (tok == NULL) {
if (tok == NULL)
{
return 0;
}
token_list[ i++ ] = tok;
/* Find the remaining tokens */
while (i < siz) {
while (i < siz)
{
tok = mystrtok(NULL, delim);
/* If NULL, no more tokens left */
if (tok == NULL) {
if (tok == NULL)
{
break;
}
@ -233,9 +248,12 @@ static int tokenize_line(char *line, char **token_list, size_t siz, char delim)
}
/* Any tokens left? */
if (i == siz) {
if (i == siz)
{
return 0;
} else {
}
else
{
return i;
}
}
@ -254,25 +272,33 @@ static char * mystrtok(char *s, char delim)
static size_t pos = 0, length = 0;
static char *str = 0;
if (s != NULL) {
if (s != NULL)
{
str = s;
pos = 0;
length = strlen(str);
} else {
}
else
{
}
if (str[ pos + 1 ] == '\0') {
if (str[ pos + 1 ] == '\0')
{
return NULL;
}
size_t i, ent_pos = pos;
for (i = pos; i < length;) {
if (str[i] == delim) {
for (i = pos; i < length;)
{
if (str[i] == delim)
{
str[i] = '\0';
pos = i + 1;
return str + ent_pos;
} else {
}
else
{
i++;
}
}
@ -297,7 +323,8 @@ static int print_parm_val(RIG *rig, const struct confparams *cfp, rig_ptr_t ptr)
FILE *f = (FILE *)ptr;
rig_get_ext_parm(rig, cfp->token, &val);
switch (cfp->type) {
switch (cfp->type)
{
case RIG_CONF_CHECKBUTTON:
case RIG_CONF_COMBO:
fprintf(f, "%d%c", val.i, csv_sep);
@ -327,14 +354,17 @@ int csv_parm_save(RIG *rig, const char *outfilename)
f = fopen(outfilename, "w");
if (!f) {
if (!f)
{
return -1;
}
for (i = 0; i < RIG_SETTING_MAX; i++) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms = rig_strparm(get_parm & rig_idx2setting(i));
if (!ms || !ms[0]) {
if (!ms || !ms[0])
{
continue;
}
@ -344,26 +374,32 @@ int csv_parm_save(RIG *rig, const char *outfilename)
rig_ext_parm_foreach(rig, print_parm_name, f);
fprintf(f, "\n");
for (i = 0; i < RIG_SETTING_MAX; i++) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms;
value_t val;
parm = get_parm & rig_idx2setting(i);
ms = rig_strparm(parm);
if (!ms || !ms[0]) {
if (!ms || !ms[0])
{
continue;
}
ret = rig_get_parm(rig, parm, &val);
if (ret != RIG_OK) {
if (ret != RIG_OK)
{
return ret;
}
if (RIG_PARM_IS_FLOAT(parm)) {
if (RIG_PARM_IS_FLOAT(parm))
{
fprintf(f, "%f%c", val.f, csv_sep);
} else {
}
else
{
fprintf(f, "%d%c", val.i, csv_sep);
}
}
@ -391,99 +427,123 @@ void dump_csv_name(const channel_cap_t *mem_caps, FILE *f)
{
fprintf(f, "num%c", csv_sep);
if (mem_caps->bank_num) {
if (mem_caps->bank_num)
{
fprintf(f, "bank_num%c", csv_sep);
}
if (mem_caps->channel_desc) {
if (mem_caps->channel_desc)
{
fprintf(f, "channel_desc%c", csv_sep);
}
if (mem_caps->vfo) {
if (mem_caps->vfo)
{
fprintf(f, "vfo%c", csv_sep);
}
if (mem_caps->ant) {
if (mem_caps->ant)
{
fprintf(f, "ant%c", csv_sep);
}
if (mem_caps->freq) {
if (mem_caps->freq)
{
fprintf(f, "freq%c", csv_sep);
}
if (mem_caps->mode) {
if (mem_caps->mode)
{
fprintf(f, "mode%c", csv_sep);
}
if (mem_caps->width) {
if (mem_caps->width)
{
fprintf(f, "width%c", csv_sep);
}
if (mem_caps->tx_freq) {
if (mem_caps->tx_freq)
{
fprintf(f, "tx_freq%c", csv_sep);
}
if (mem_caps->tx_mode) {
if (mem_caps->tx_mode)
{
fprintf(f, "tx_mode%c", csv_sep);
}
if (mem_caps->tx_width) {
if (mem_caps->tx_width)
{
fprintf(f, "tx_width%c", csv_sep);
}
if (mem_caps->split) {
if (mem_caps->split)
{
fprintf(f, "split%c", csv_sep);
}
if (mem_caps->tx_vfo) {
if (mem_caps->tx_vfo)
{
fprintf(f, "tx_vfo%c", csv_sep);
}
if (mem_caps->rptr_shift) {
if (mem_caps->rptr_shift)
{
fprintf(f, "rptr_shift%c", csv_sep);
}
if (mem_caps->rptr_offs) {
if (mem_caps->rptr_offs)
{
fprintf(f, "rptr_offs%c", csv_sep);
}
if (mem_caps->tuning_step) {
if (mem_caps->tuning_step)
{
fprintf(f, "tuning_step%c", csv_sep);
}
if (mem_caps->rit) {
if (mem_caps->rit)
{
fprintf(f, "rit%c", csv_sep);
}
if (mem_caps->xit) {
if (mem_caps->xit)
{
fprintf(f, "xit%c", csv_sep);
}
if (mem_caps->funcs) {
if (mem_caps->funcs)
{
fprintf(f, "funcs%c", csv_sep);
}
if (mem_caps->ctcss_tone) {
if (mem_caps->ctcss_tone)
{
fprintf(f, "ctcss_tone%c", csv_sep);
}
if (mem_caps->ctcss_sql) {
if (mem_caps->ctcss_sql)
{
fprintf(f, "ctcss_sql%c", csv_sep);
}
if (mem_caps->dcs_code) {
if (mem_caps->dcs_code)
{
fprintf(f, "dcs_code%c", csv_sep);
}
if (mem_caps->dcs_sql) {
if (mem_caps->dcs_sql)
{
fprintf(f, "dcs_sql%c", csv_sep);
}
if (mem_caps->scan_group) {
if (mem_caps->scan_group)
{
fprintf(f, "scan_group%c", csv_sep);
}
if (mem_caps->flags) {
if (mem_caps->flags)
{
fprintf(f, "flags%c", csv_sep);
}
@ -503,12 +563,14 @@ int dump_csv_chan(RIG *rig,
static int first_time = 1;
const channel_cap_t *mem_caps = &chan_list->mem_caps;
if (first_time) {
if (first_time)
{
dump_csv_name(mem_caps, f);
first_time = 0;
}
if (*chan_pp == NULL) {
if (*chan_pp == NULL)
{
/*
* Hamlib frontend demand application an allocated
* channel_t pointer for next round.
@ -520,99 +582,123 @@ int dump_csv_chan(RIG *rig,
fprintf(f, "%d%c", chan.channel_num, csv_sep);
if (mem_caps->bank_num) {
if (mem_caps->bank_num)
{
fprintf(f, "%d%c", chan.bank_num, csv_sep);
}
if (mem_caps->channel_desc) {
if (mem_caps->channel_desc)
{
fprintf(f, "%s%c", chan.channel_desc, csv_sep);
}
if (mem_caps->vfo) {
if (mem_caps->vfo)
{
fprintf(f, "%s%c", rig_strvfo(chan.vfo), csv_sep);
}
if (mem_caps->ant) {
if (mem_caps->ant)
{
fprintf(f, "%d%c", chan.ant, csv_sep);
}
if (mem_caps->freq) {
if (mem_caps->freq)
{
fprintf(f, "%.0"PRIfreq"%c", chan.freq, csv_sep);
}
if (mem_caps->mode) {
if (mem_caps->mode)
{
fprintf(f, "%s%c", rig_strrmode(chan.mode), csv_sep);
}
if (mem_caps->width) {
if (mem_caps->width)
{
fprintf(f, "%d%c", (int)chan.width, csv_sep);
}
if (mem_caps->tx_freq) {
if (mem_caps->tx_freq)
{
fprintf(f, "%.0"PRIfreq"%c", chan.tx_freq, csv_sep);
}
if (mem_caps->tx_mode) {
if (mem_caps->tx_mode)
{
fprintf(f, "%s%c", rig_strrmode(chan.tx_mode), csv_sep);
}
if (mem_caps->tx_width) {
if (mem_caps->tx_width)
{
fprintf(f, "%d%c", (int)chan.tx_width, csv_sep);
}
if (mem_caps->split) {
if (mem_caps->split)
{
fprintf(f, "%s%c", chan.split == RIG_SPLIT_ON ? "on" : "off", csv_sep);
}
if (mem_caps->tx_vfo) {
if (mem_caps->tx_vfo)
{
fprintf(f, "%s%c", rig_strvfo(chan.tx_vfo), csv_sep);
}
if (mem_caps->rptr_shift) {
if (mem_caps->rptr_shift)
{
fprintf(f, "%s%c", rig_strptrshift(chan.rptr_shift), csv_sep);
}
if (mem_caps->rptr_offs) {
if (mem_caps->rptr_offs)
{
fprintf(f, "%d%c", (int)chan.rptr_offs, csv_sep);
}
if (mem_caps->tuning_step) {
if (mem_caps->tuning_step)
{
fprintf(f, "%d%c", (int)chan.tuning_step, csv_sep);
}
if (mem_caps->rit) {
if (mem_caps->rit)
{
fprintf(f, "%d%c", (int)chan.rit, csv_sep);
}
if (mem_caps->xit) {
if (mem_caps->xit)
{
fprintf(f, "%d%c", (int)chan.xit, csv_sep);
}
if (mem_caps->funcs) {
if (mem_caps->funcs)
{
fprintf(f, "%lx%c", chan.funcs, csv_sep);
}
if (mem_caps->ctcss_tone) {
if (mem_caps->ctcss_tone)
{
fprintf(f, "%d%c", chan.ctcss_tone, csv_sep);
}
if (mem_caps->ctcss_sql) {
if (mem_caps->ctcss_sql)
{
fprintf(f, "%d%c", chan.ctcss_sql, csv_sep);
}
if (mem_caps->dcs_code) {
if (mem_caps->dcs_code)
{
fprintf(f, "%d%c", chan.dcs_code, csv_sep);
}
if (mem_caps->dcs_sql) {
if (mem_caps->dcs_sql)
{
fprintf(f, "%d%c", chan.dcs_sql, csv_sep);
}
if (mem_caps->scan_group) {
if (mem_caps->scan_group)
{
fprintf(f, "%d%c", chan.scan_group, csv_sep);
}
if (mem_caps->flags) {
if (mem_caps->flags)
{
fprintf(f, "%x%c", chan.flags, csv_sep);
}
@ -623,7 +709,6 @@ int dump_csv_chan(RIG *rig,
* to chan being static
*/
return RIG_OK;
}
@ -650,7 +735,8 @@ int set_channel_data(RIG *rig,
i = find_on_list(line_key_list, "num");
if (i < 0) {
if (i < 0)
{
fprintf(stderr, "No channel number\n");
return -1;
}
@ -659,99 +745,125 @@ int set_channel_data(RIG *rig,
/* find chanel caps of appropriate memory group? */
for (j = 0; j < CHANLSTSIZ; j++)
if (rig->state.chan_list[j].start <= n && rig->state.chan_list[j].end >= n) {
{
if (rig->state.chan_list[j].start <= n && rig->state.chan_list[j].end >= n)
{
break;
}
}
printf("Requested channel number %d, list number %d\n", n, j);
const channel_cap_t *mem_caps = &rig->state.chan_list[j].mem_caps;
if (mem_caps->bank_num) {
if (mem_caps->bank_num)
{
i = find_on_list(line_key_list, "bank_num");
if (i >= 0) {
if (i >= 0)
{
chan->bank_num = atoi(line_data_list[ i ]);
}
}
if (mem_caps->channel_desc) {
if (mem_caps->channel_desc)
{
i = find_on_list(line_key_list, "channel_desc");
if (i >= 0) {
if (i >= 0)
{
strncpy(chan->channel_desc, line_data_list[ i ], rig->caps->chan_desc_sz - 1);
chan->channel_desc[ rig->caps->chan_desc_sz ] = '\0';
}
}
if (mem_caps->ant) {
if (mem_caps->ant)
{
i = find_on_list(line_key_list, "ant");
if (i >= 0) {
if (i >= 0)
{
chan->ant = atoi(line_data_list[ i ]);
}
}
if (mem_caps->freq) {
if (mem_caps->freq)
{
i = find_on_list(line_key_list, "freq");
if (i >= 0) {
if (i >= 0)
{
chan->freq = atoi(line_data_list[ i ]);
}
}
if (mem_caps->mode) {
if (mem_caps->mode)
{
i = find_on_list(line_key_list, "mode");
if (i >= 0) {
if (i >= 0)
{
chan->mode = rig_parse_mode(line_data_list[ i ]);
}
}
if (mem_caps->width) {
if (mem_caps->width)
{
i = find_on_list(line_key_list, "width");
if (i >= 0) {
if (i >= 0)
{
chan->width = atoi(line_data_list[ i ]);
}
}
if (mem_caps->tx_freq) {
if (mem_caps->tx_freq)
{
i = find_on_list(line_key_list, "tx_freq");
if (i >= 0) {
if (i >= 0)
{
sscanf(line_data_list[i], "%"SCNfreq, &chan->tx_freq);
}
}
if (mem_caps->tx_mode) {
if (mem_caps->tx_mode)
{
i = find_on_list(line_key_list, "tx_mode");
if (i >= 0) {
if (i >= 0)
{
chan->tx_mode = rig_parse_mode(line_data_list[ i ]);
}
}
if (mem_caps->tx_width) {
if (mem_caps->tx_width)
{
i = find_on_list(line_key_list, "tx_width");
if (i >= 0) {
if (i >= 0)
{
chan->tx_width = atoi(line_data_list[ i ]);
}
}
if (mem_caps->split) {
if (mem_caps->split)
{
chan->split = RIG_SPLIT_OFF;
i = find_on_list(line_key_list, "split");
if (i >= 0) {
if (strcmp(line_data_list[i], "on") == 0) {
if (i >= 0)
{
if (strcmp(line_data_list[i], "on") == 0)
{
chan->split = RIG_SPLIT_ON;
if (mem_caps->tx_vfo) {
if (mem_caps->tx_vfo)
{
i = find_on_list(line_key_list, "tx_vfo");
if (i >= 0) {
if (i >= 0)
{
sscanf(line_data_list[i], "%x", &chan->tx_vfo);
}
}
@ -759,11 +871,14 @@ int set_channel_data(RIG *rig,
}
}
if (mem_caps->rptr_shift) {
if (mem_caps->rptr_shift)
{
i = find_on_list(line_key_list, "rptr_shift");
if (i >= 0) {
switch (line_data_list[i][0]) {
if (i >= 0)
{
switch (line_data_list[i][0])
{
case '=':
chan->rptr_shift = RIG_RPT_SHIFT_NONE;
break;
@ -777,92 +892,114 @@ int set_channel_data(RIG *rig,
break;
}
if (mem_caps->rptr_offs && chan->rptr_shift != RIG_RPT_SHIFT_NONE) {
if (mem_caps->rptr_offs && chan->rptr_shift != RIG_RPT_SHIFT_NONE)
{
i = find_on_list(line_key_list, "rptr_offs");
if (i >= 0) {
if (i >= 0)
{
chan->rptr_offs = atoi(line_data_list[ i ]);
}
}
}
}
if (mem_caps->tuning_step) {
if (mem_caps->tuning_step)
{
i = find_on_list(line_key_list, "tuning_step");
if (i >= 0) {
if (i >= 0)
{
chan->tuning_step = atoi(line_data_list[ i ]);
}
}
if (mem_caps->rit) {
if (mem_caps->rit)
{
i = find_on_list(line_key_list, "rit");
if (i >= 0) {
if (i >= 0)
{
chan->rit = atoi(line_data_list[ i ]);
}
}
if (mem_caps->xit) {
if (mem_caps->xit)
{
i = find_on_list(line_key_list, "xit");
if (i >= 0) {
if (i >= 0)
{
chan->xit = atoi(line_data_list[ i ]);
}
}
if (mem_caps->funcs) {
if (mem_caps->funcs)
{
i = find_on_list(line_key_list, "funcs");
if (i >= 0) {
if (i >= 0)
{
sscanf(line_data_list[i], "%lx", &chan->funcs);
}
}
if (mem_caps->ctcss_tone) {
if (mem_caps->ctcss_tone)
{
i = find_on_list(line_key_list, "ctcss_tone");
if (i >= 0) {
if (i >= 0)
{
chan->ctcss_tone = atoi(line_data_list[ i ]);
}
}
if (mem_caps->ctcss_sql) {
if (mem_caps->ctcss_sql)
{
i = find_on_list(line_key_list, "ctcss_sql");
if (i >= 0) {
if (i >= 0)
{
chan->ctcss_sql = atoi(line_data_list[ i ]);
}
}
if (mem_caps->dcs_code) {
if (mem_caps->dcs_code)
{
i = find_on_list(line_key_list, "dcs_code");
if (i >= 0) {
if (i >= 0)
{
chan->dcs_code = atoi(line_data_list[ i ]);
}
}
if (mem_caps->dcs_sql) {
if (mem_caps->dcs_sql)
{
i = find_on_list(line_key_list, "dcs_sql");
if (i >= 0) {
if (i >= 0)
{
chan->dcs_sql = atoi(line_data_list[ i ]);
}
}
if (mem_caps->scan_group) {
if (mem_caps->scan_group)
{
i = find_on_list(line_key_list, "scan_group");
if (i >= 0) {
if (i >= 0)
{
chan->scan_group = atoi(line_data_list[ i ]);
}
}
if (mem_caps->flags) {
if (mem_caps->flags)
{
i = find_on_list(line_key_list, "flags");
if (i >= 0) {
if (i >= 0)
{
sscanf(line_data_list[i], "%x", &chan->flags);
}
}
@ -881,21 +1018,29 @@ int find_on_list(char **list, char *what)
{
int i = 0;
if (!what) {
if (!what)
{
return -1;
}
while (list[i] != NULL) {
if (strcmp(list[i], what) == 0) {
while (list[i] != NULL)
{
if (strcmp(list[i], what) == 0)
{
return i;
} else {
}
else
{
i++;
}
}
if (!list[i]) {
if (!list[i])
{
return -1;
} else {
}
else
{
return i;
}
}

Wyświetl plik

@ -48,43 +48,52 @@ int xml_load(RIG *my_rig, const char *infilename)
/* load xlm Doc */
Doc = xmlParseFile(infilename);
if (Doc == NULL) {
if (Doc == NULL)
{
fprintf(stderr, "xmlParse failed\n");
exit(2);
}
node = xmlDocGetRootElement(Doc);
if (node == NULL) {
if (node == NULL)
{
fprintf(stderr, "get root failed\n");
exit(2);
}
if (strcmp((char *) node->name, "hamlib")) {
if (strcmp((char *) node->name, "hamlib"))
{
fprintf(stderr, "no hamlib tag found\n");
exit(2);
}
for (node = node->xmlChildrenNode; node != NULL; node = node->next) {
if (xmlNodeIsText(node)) {
for (node = node->xmlChildrenNode; node != NULL; node = node->next)
{
if (xmlNodeIsText(node))
{
continue;
}
if (strcmp((char *) node->name, "channels") == 0) {
if (strcmp((char *) node->name, "channels") == 0)
{
break;
}
}
if (node == NULL) {
if (node == NULL)
{
fprintf(stderr, "no channels\n");
exit(2);
}
for (node = node->xmlChildrenNode; node != NULL; node = node->next) {
for (node = node->xmlChildrenNode; node != NULL; node = node->next)
{
channel_t chan;
int status;
if (xmlNodeIsText(node)) {
if (xmlNodeIsText(node))
{
continue;
}
@ -92,7 +101,8 @@ int xml_load(RIG *my_rig, const char *infilename)
status = rig_set_channel(my_rig, &chan);
if (status != RIG_OK) {
if (status != RIG_OK)
{
printf("rig_get_channel: error = %s \n", rigerror(status));
return status;
}
@ -126,107 +136,134 @@ int set_chan(RIG *rig, channel_t *chan, xmlNodePtr node)
prop = xmlGetProp(node, (unsigned char *) "num");
if (prop == NULL) {
if (prop == NULL)
{
fprintf(stderr, "no num\n");
return -1;
}
n = chan->channel_num = atoi((char *) prop);
/* find chanel caps */
/* find channel caps */
for (i = 0; i < CHANLSTSIZ ; i++)
{
if (rig->state.chan_list[i].start <= n
&& rig->state.chan_list[i].end >= n) {
&& rig->state.chan_list[i].end >= n)
{
break;
}
}
fprintf(stderr, "node %d %d\n", n, i);
if (rig->state.chan_list[i].mem_caps.bank_num) {
if (rig->state.chan_list[i].mem_caps.bank_num)
{
prop = xmlGetProp(node, (unsigned char *) "bank_num");
if (prop != NULL) {
if (prop != NULL)
{
chan->bank_num = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.channel_desc) {
if (rig->state.chan_list[i].mem_caps.channel_desc)
{
prop = xmlGetProp(node, (unsigned char *) "channel_desc");
if (prop != NULL) {
if (prop != NULL)
{
strncpy(chan->channel_desc, (char *) prop, 7);
}
}
if (rig->state.chan_list[i].mem_caps.ant) {
if (rig->state.chan_list[i].mem_caps.ant)
{
prop = xmlGetProp(node, (unsigned char *) "ant");
if (prop != NULL) {
if (prop != NULL)
{
chan->ant = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.freq) {
if (rig->state.chan_list[i].mem_caps.freq)
{
prop = xmlGetProp(node, (unsigned char *) "freq");
if (prop != NULL) {
if (prop != NULL)
{
sscanf((char *) prop, "%"SCNfreq, &chan->freq);
}
}
if (rig->state.chan_list[i].mem_caps.mode) {
if (rig->state.chan_list[i].mem_caps.mode)
{
prop = xmlGetProp(node, (unsigned char *) "mode");
if (prop != NULL) {
if (prop != NULL)
{
chan->mode = rig_parse_mode((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.width) {
if (rig->state.chan_list[i].mem_caps.width)
{
prop = xmlGetProp(node, (unsigned char *) "width");
if (prop != NULL) {
if (prop != NULL)
{
chan->width = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.tx_freq) {
if (rig->state.chan_list[i].mem_caps.tx_freq)
{
prop = xmlGetProp(node, (unsigned char *) "tx_freq");
if (prop != NULL) {
if (prop != NULL)
{
sscanf((char *) prop, "%"SCNfreq, &chan->tx_freq);
}
}
if (rig->state.chan_list[i].mem_caps.tx_mode) {
if (rig->state.chan_list[i].mem_caps.tx_mode)
{
prop = xmlGetProp(node, (unsigned char *)"tx_mode");
if (prop != NULL) {
if (prop != NULL)
{
chan->tx_mode = rig_parse_mode((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.tx_width) {
if (rig->state.chan_list[i].mem_caps.tx_width)
{
prop = xmlGetProp(node, (unsigned char *)"tx_width");
if (prop != NULL) {
if (prop != NULL)
{
chan->tx_width = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.split) {
if (rig->state.chan_list[i].mem_caps.split)
{
chan->split = RIG_SPLIT_OFF;
prop = xmlGetProp(node, (unsigned char *)"split");
if (prop != NULL) {
if (strcmp((char *) prop, "on") == 0) {
if (prop != NULL)
{
if (strcmp((char *) prop, "on") == 0)
{
chan->split = RIG_SPLIT_ON;
if (rig->state.chan_list[i].mem_caps.tx_vfo) {
if (rig->state.chan_list[i].mem_caps.tx_vfo)
{
prop = xmlGetProp(node, (unsigned char *)"tx_vfo");
if (prop != NULL) {
if (prop != NULL)
{
sscanf((char *) prop, "%x", &chan->tx_vfo);
}
}
@ -234,11 +271,14 @@ int set_chan(RIG *rig, channel_t *chan, xmlNodePtr node)
}
}
if (rig->state.chan_list[i].mem_caps.rptr_shift) {
if (rig->state.chan_list[i].mem_caps.rptr_shift)
{
prop = xmlGetProp(node, (unsigned char *)"rptr_shift");
if (prop)
switch (prop[0]) {
{
switch (prop[0])
{
case '=':
chan->rptr_shift = RIG_RPT_SHIFT_NONE;
break;
@ -251,93 +291,116 @@ int set_chan(RIG *rig, channel_t *chan, xmlNodePtr node)
chan->rptr_shift = RIG_RPT_SHIFT_MINUS;
break;
}
}
if (rig->state.chan_list[i].mem_caps.rptr_offs
&& chan->rptr_shift != RIG_RPT_SHIFT_NONE) {
&& chan->rptr_shift != RIG_RPT_SHIFT_NONE)
{
prop = xmlGetProp(node, (unsigned char *)"rptr_offs");
if (prop != NULL) {
if (prop != NULL)
{
chan->rptr_offs = atoi((char *) prop);
}
}
}
if (rig->state.chan_list[i].mem_caps.tuning_step) {
if (rig->state.chan_list[i].mem_caps.tuning_step)
{
prop = xmlGetProp(node, (unsigned char *)"tuning_step");
if (prop != NULL) {
if (prop != NULL)
{
chan->tuning_step = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.rit) {
if (rig->state.chan_list[i].mem_caps.rit)
{
prop = xmlGetProp(node, (unsigned char *)"rit");
if (prop != NULL) {
if (prop != NULL)
{
chan->rit = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.xit) {
if (rig->state.chan_list[i].mem_caps.xit)
{
prop = xmlGetProp(node, (unsigned char *)"xit");
if (prop != NULL) {
if (prop != NULL)
{
chan->xit = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.funcs) {
if (rig->state.chan_list[i].mem_caps.funcs)
{
prop = xmlGetProp(node, (unsigned char *)"funcs");
if (prop != NULL) {
if (prop != NULL)
{
sscanf((char *) prop, "%lx", &chan->funcs);
}
}
if (rig->state.chan_list[i].mem_caps.ctcss_tone) {
if (rig->state.chan_list[i].mem_caps.ctcss_tone)
{
prop = xmlGetProp(node, (unsigned char *)"ctcss_tone");
if (prop != NULL) {
if (prop != NULL)
{
chan->ctcss_tone = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.ctcss_sql) {
if (rig->state.chan_list[i].mem_caps.ctcss_sql)
{
prop = xmlGetProp(node, (unsigned char *)"ctcss_sql");
if (prop != NULL) {
if (prop != NULL)
{
chan->ctcss_sql = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.dcs_code) {
if (rig->state.chan_list[i].mem_caps.dcs_code)
{
prop = xmlGetProp(node, (unsigned char *)"dcs_code");
if (prop != NULL) {
if (prop != NULL)
{
chan->dcs_code = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.dcs_sql) {
if (rig->state.chan_list[i].mem_caps.dcs_sql)
{
prop = xmlGetProp(node, (unsigned char *)"dcs_sql");
if (prop != NULL) {
if (prop != NULL)
{
chan->dcs_sql = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.scan_group) {
if (rig->state.chan_list[i].mem_caps.scan_group)
{
prop = xmlGetProp(node, (unsigned char *)"scan_group");
if (prop != NULL) {
if (prop != NULL)
{
chan->scan_group = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.flags) {
if (rig->state.chan_list[i].mem_caps.flags)
{
prop = xmlGetProp(node, (unsigned char *)"flags");
if (prop != NULL) {
if (prop != NULL)
{
sscanf((char *) prop, "%x", &chan->flags);
}
}

Wyświetl plik

@ -63,7 +63,8 @@ int xml_save(RIG *rig, const char *outfilename)
retval = rig_get_chan_all_cb(rig, dump_xml_chan, root);
if (retval != RIG_OK) {
if (retval != RIG_OK)
{
return retval;
}
@ -104,7 +105,8 @@ int dump_xml_chan(RIG *rig,
const channel_cap_t *mem_caps = &chan_list->mem_caps;
if (*chan_pp == NULL) {
if (*chan_pp == NULL)
{
/*
* Hamlib frontend demand application an allocated
* channel_t pointer for next round.
@ -114,13 +116,15 @@ int dump_xml_chan(RIG *rig,
return RIG_OK;
}
if (chan_list->type == RIG_MTYPE_NONE) {
if (chan_list->type == RIG_MTYPE_NONE)
{
return RIG_OK;
}
mtype = rig_strmtype(chan_list->type);
for (i = 0; i < strlen(mtype); i++) {
for (i = 0; i < strlen(mtype); i++)
{
attrbuf[i] = tolower(mtype[i]);
}
@ -128,7 +132,8 @@ int dump_xml_chan(RIG *rig,
node = xmlNewChild(root, NULL, (unsigned char *)attrbuf, NULL);
if (mem_caps->bank_num) {
if (mem_caps->bank_num)
{
sprintf(attrbuf, "%d", chan.bank_num);
xmlNewProp(node, (unsigned char *) "bank_num", (unsigned char *) attrbuf);
}
@ -136,57 +141,68 @@ int dump_xml_chan(RIG *rig,
sprintf(attrbuf, "%d", chan.channel_num);
xmlNewProp(node, (unsigned char *) "num", (unsigned char *) attrbuf);
if (mem_caps->channel_desc && chan.channel_desc[0] != '\0') {
if (mem_caps->channel_desc && chan.channel_desc[0] != '\0')
{
xmlNewProp(node,
(unsigned char *) "channel_desc",
(unsigned char *) chan.channel_desc);
}
if (mem_caps->vfo) {
if (mem_caps->vfo)
{
sprintf(attrbuf, "%d", chan.vfo);
xmlNewProp(node, (unsigned char *) "vfo", (unsigned char *) attrbuf);
}
if (mem_caps->ant && chan.ant != RIG_ANT_NONE) {
if (mem_caps->ant && chan.ant != RIG_ANT_NONE)
{
sprintf(attrbuf, "%d", chan.ant);
xmlNewProp(node, (unsigned char *) "ant", (unsigned char *) attrbuf);
}
if (mem_caps->freq && chan.freq != RIG_FREQ_NONE) {
if (mem_caps->freq && chan.freq != RIG_FREQ_NONE)
{
sprintf(attrbuf, "%"PRIll, (int64_t)chan.freq);
xmlNewProp(node, (unsigned char *) "freq", (unsigned char *) attrbuf);
}
if (mem_caps->mode && chan.mode != RIG_MODE_NONE) {
if (mem_caps->mode && chan.mode != RIG_MODE_NONE)
{
xmlNewProp(node, (unsigned char *) "mode",
(unsigned char *) rig_strrmode(chan.mode));
}
if (mem_caps->width && chan.width != 0) {
if (mem_caps->width && chan.width != 0)
{
sprintf(attrbuf, "%d", (int)chan.width);
xmlNewProp(node, (unsigned char *) "width", (unsigned char *) attrbuf);
}
if (mem_caps->tx_freq && chan.tx_freq != RIG_FREQ_NONE) {
if (mem_caps->tx_freq && chan.tx_freq != RIG_FREQ_NONE)
{
sprintf(attrbuf, "%"PRIll, (int64_t)chan.tx_freq);
xmlNewProp(node, (unsigned char *) "tx_freq", (unsigned char *) attrbuf);
}
if (mem_caps->tx_mode && chan.tx_mode != RIG_MODE_NONE) {
if (mem_caps->tx_mode && chan.tx_mode != RIG_MODE_NONE)
{
xmlNewProp(node,
(unsigned char *) "tx_mode",
(unsigned char *) rig_strrmode(chan.tx_mode));
}
if (mem_caps->tx_width && chan.tx_width != 0) {
if (mem_caps->tx_width && chan.tx_width != 0)
{
sprintf(attrbuf, "%d", (int)chan.tx_width);
xmlNewProp(node, (unsigned char *) "tx_width", (unsigned char *) attrbuf);
}
if (mem_caps->split && chan.split != RIG_SPLIT_OFF) {
if (mem_caps->split && chan.split != RIG_SPLIT_OFF)
{
xmlNewProp(node, (unsigned char *) "split", (unsigned char *) "on");
if (mem_caps->tx_vfo) {
if (mem_caps->tx_vfo)
{
sprintf(attrbuf, "%x", chan.tx_vfo);
xmlNewProp(node,
(unsigned char *) "tx_vfo",
@ -194,12 +210,14 @@ int dump_xml_chan(RIG *rig,
}
}
if (mem_caps->rptr_shift && chan.rptr_shift != RIG_RPT_SHIFT_NONE) {
if (mem_caps->rptr_shift && chan.rptr_shift != RIG_RPT_SHIFT_NONE)
{
xmlNewProp(node,
(unsigned char *) "rptr_shift",
(unsigned char *) rig_strptrshift(chan.rptr_shift));
if (mem_caps->rptr_offs && (int)chan.rptr_offs != 0) {
if (mem_caps->rptr_offs && (int)chan.rptr_offs != 0)
{
sprintf(attrbuf, "%d", (int)chan.rptr_offs);
xmlNewProp(node,
(unsigned char *) "rptr_offs",
@ -207,52 +225,62 @@ int dump_xml_chan(RIG *rig,
}
}
if (mem_caps->tuning_step && chan.tuning_step != 0) {
if (mem_caps->tuning_step && chan.tuning_step != 0)
{
sprintf(attrbuf, "%d", (int)chan.tuning_step);
xmlNewProp(node, (unsigned char *) "tuning_step", (unsigned char *) attrbuf);
}
if (mem_caps->rit && chan.rit != 0) {
if (mem_caps->rit && chan.rit != 0)
{
sprintf(attrbuf, "%d", (int)chan.rit);
xmlNewProp(node, (unsigned char *) "rit", (unsigned char *) attrbuf);
}
if (mem_caps->xit && chan.xit != 0) {
if (mem_caps->xit && chan.xit != 0)
{
sprintf(attrbuf, "%d", (int)chan.xit);
xmlNewProp(node, (unsigned char *) "xit", (unsigned char *) attrbuf);
}
if (mem_caps->funcs) {
if (mem_caps->funcs)
{
sprintf(attrbuf, "%lx", chan.funcs);
xmlNewProp(node, (unsigned char *) "funcs", (unsigned char *) attrbuf);
}
if (mem_caps->ctcss_tone && chan.ctcss_tone != 0) {
if (mem_caps->ctcss_tone && chan.ctcss_tone != 0)
{
sprintf(attrbuf, "%d", chan.ctcss_tone);
xmlNewProp(node, (unsigned char *) "ctcss_tone", (unsigned char *) attrbuf);
}
if (mem_caps->ctcss_sql && chan.ctcss_sql != 0) {
if (mem_caps->ctcss_sql && chan.ctcss_sql != 0)
{
sprintf(attrbuf, "%d", chan.ctcss_sql);
xmlNewProp(node, (unsigned char *) "ctcss_sql", (unsigned char *) attrbuf);
}
if (mem_caps->dcs_code && chan.dcs_code != 0) {
if (mem_caps->dcs_code && chan.dcs_code != 0)
{
sprintf(attrbuf, "%d", chan.dcs_code);
xmlNewProp(node, (unsigned char *) "dcs_code", (unsigned char *) attrbuf);
}
if (mem_caps->dcs_sql && chan.dcs_sql != 0) {
if (mem_caps->dcs_sql && chan.dcs_sql != 0)
{
sprintf(attrbuf, "%d", chan.dcs_sql);
xmlNewProp(node, (unsigned char *) "dcs_sql", (unsigned char *) attrbuf);
}
if (mem_caps->scan_group) {
if (mem_caps->scan_group)
{
sprintf(attrbuf, "%d", chan.scan_group);
xmlNewProp(node, (unsigned char *) "scan_group", (unsigned char *) attrbuf);
}
if (mem_caps->flags) {
if (mem_caps->flags)
{
sprintf(attrbuf, "%x", chan.flags);
xmlNewProp(node, (unsigned char *) "flags", (unsigned char *) attrbuf);
}

Wyświetl plik

@ -30,7 +30,8 @@ int main(int argc, char *argv[])
* allocate memory, setup & open port
*/
if (argc < 2) {
if (argc < 2)
{
hamlib_port_t myport;
/* may be overriden by backend probe */
myport.type.rig = RIG_PORT_SERIAL;
@ -43,13 +44,16 @@ int main(int argc, char *argv[])
rig_load_all_backends();
myrig_model = rig_probe(&myport);
} else {
}
else
{
myrig_model = atoi(argv[1]);
}
my_rig = rig_init(myrig_model);
if (!my_rig) {
if (!my_rig)
{
fprintf(stderr, "Unknown rig num: %d\n", myrig_model);
fprintf(stderr, "Please check riglist.h\n");
exit(1); /* whoops! something went wrong (mem alloc?) */
@ -69,7 +73,8 @@ int main(int argc, char *argv[])
retcode = rig_open(my_rig);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_open: error = %s\n", rigerror(retcode));
exit(2);
}
@ -82,21 +87,24 @@ int main(int argc, char *argv[])
*/
gettimeofday(&tv1, NULL);
for (i = 0; i < LOOP_COUNT; i++) {
for (i = 0; i < LOOP_COUNT; i++)
{
freq_t freq;
rmode_t rmode;
pbwidth_t width;
retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_get_freq: error = %s \n", rigerror(retcode));
exit(1);
}
retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_get_mode: error = %s \n", rigerror(retcode));
exit(1);
}

Wyświetl plik

@ -88,7 +88,8 @@ void usage(void);
* TODO: add an option to read from a file
*/
#define SHORT_OPTIONS "+m:r:p:d:P:D:s:c:t:lC:LuonvhV"
static struct option long_options[] = {
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
{"rig-file", 1, 0, 'r'},
{"ptt-file", 1, 0, 'p'},
@ -156,7 +157,8 @@ int main(int argc, char *argv[])
char *civaddr = NULL; /* NULL means no need to set conf */
char conf_parms[MAXCONFLEN] = "";
while (1) {
while (1)
{
int c;
int option_index = 0;
@ -166,11 +168,13 @@ int main(int argc, char *argv[])
long_options,
&option_index);
if (c == -1) {
if (c == -1)
{
break;
}
switch (c) {
switch (c)
{
case 'h':
usage();
exit(0);
@ -180,7 +184,8 @@ int main(int argc, char *argv[])
exit(0);
case 'm':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -189,7 +194,8 @@ int main(int argc, char *argv[])
break;
case 'r':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -198,7 +204,8 @@ int main(int argc, char *argv[])
break;
case 'p':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -207,7 +214,8 @@ int main(int argc, char *argv[])
break;
case 'd':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -216,61 +224,96 @@ int main(int argc, char *argv[])
break;
case 'P':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (!strcmp(optarg, "RIG")) {
if (!strcmp(optarg, "RIG"))
{
ptt_type = RIG_PTT_RIG;
} else if (!strcmp(optarg, "DTR")) {
}
else if (!strcmp(optarg, "DTR"))
{
ptt_type = RIG_PTT_SERIAL_DTR;
} else if (!strcmp(optarg, "RTS")) {
}
else if (!strcmp(optarg, "RTS"))
{
ptt_type = RIG_PTT_SERIAL_RTS;
} else if (!strcmp(optarg, "PARALLEL")) {
}
else if (!strcmp(optarg, "PARALLEL"))
{
ptt_type = RIG_PTT_PARALLEL;
} else if (!strcmp(optarg, "CM108")) {
}
else if (!strcmp(optarg, "CM108"))
{
ptt_type = RIG_PTT_CM108;
} else if (!strcmp(optarg, "GPIO")) {
}
else if (!strcmp(optarg, "GPIO"))
{
ptt_type = RIG_PTT_GPIO;
} else if (!strcmp(optarg, "GPION")) {
}
else if (!strcmp(optarg, "GPION"))
{
ptt_type = RIG_PTT_GPION;
} else if (!strcmp(optarg, "NONE")) {
}
else if (!strcmp(optarg, "NONE"))
{
ptt_type = RIG_PTT_NONE;
} else {
}
else
{
ptt_type = atoi(optarg);
}
break;
case 'D':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (!strcmp(optarg, "RIG")) {
if (!strcmp(optarg, "RIG"))
{
dcd_type = RIG_DCD_RIG;
} else if (!strcmp(optarg, "DSR")) {
}
else if (!strcmp(optarg, "DSR"))
{
dcd_type = RIG_DCD_SERIAL_DSR;
} else if (!strcmp(optarg, "CTS")) {
}
else if (!strcmp(optarg, "CTS"))
{
dcd_type = RIG_DCD_SERIAL_CTS;
} else if (!strcmp(optarg, "CD")) {
}
else if (!strcmp(optarg, "CD"))
{
dcd_type = RIG_DCD_SERIAL_CAR;
} else if (!strcmp(optarg, "PARALLEL")) {
}
else if (!strcmp(optarg, "PARALLEL"))
{
dcd_type = RIG_DCD_PARALLEL;
} else if (!strcmp(optarg, "CM108")) {
}
else if (!strcmp(optarg, "CM108"))
{
dcd_type = RIG_DCD_CM108;
} else if (!strcmp(optarg, "NONE")) {
}
else if (!strcmp(optarg, "NONE"))
{
dcd_type = RIG_DCD_NONE;
} else {
}
else
{
dcd_type = atoi(optarg);
}
break;
case 'c':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -279,21 +322,26 @@ int main(int argc, char *argv[])
break;
case 't':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (strlen(optarg) > 1) {
if (strlen(optarg) > 1)
{
send_cmd_term = strtol(optarg, NULL, 0);
} else {
}
else
{
send_cmd_term = optarg[0];
}
break;
case 's':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -302,12 +350,14 @@ int main(int argc, char *argv[])
break;
case 'C':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (*conf_parms != '\0') {
if (*conf_parms != '\0')
{
strcat(conf_parms, ",");
}
@ -365,13 +415,15 @@ int main(int argc, char *argv[])
* at least one command on command line,
* disable interactive mode
*/
if (optind < argc) {
if (optind < argc)
{
interactive = 0;
}
my_rig = rig_init(my_model);
if (!my_rig) {
if (!my_rig)
{
fprintf(stderr,
"Unknown rig num %d, or initialization error.\n",
my_model);
@ -381,47 +433,56 @@ int main(int argc, char *argv[])
retcode = set_conf(my_rig, conf_parms);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (rig_file) {
if (rig_file)
{
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
}
/*
* ex: RIG_PTT_PARALLEL and /dev/parport0
*/
if (ptt_type != RIG_PTT_NONE) {
if (ptt_type != RIG_PTT_NONE)
{
my_rig->state.pttport.type.ptt = ptt_type;
}
if (dcd_type != RIG_DCD_NONE) {
if (dcd_type != RIG_DCD_NONE)
{
my_rig->state.dcdport.type.dcd = dcd_type;
}
if (ptt_file) {
if (ptt_file)
{
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
}
if (dcd_file) {
if (dcd_file)
{
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0) {
if (serial_rate != 0)
{
my_rig->state.rigport.parm.serial.rate = serial_rate;
}
if (civaddr) {
if (civaddr)
{
rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
}
/*
* print out conf parameters
*/
if (show_conf) {
if (show_conf)
{
dumpconf(my_rig, stdout);
}
@ -429,7 +490,8 @@ int main(int argc, char *argv[])
* print out capabilities, and exit immediately
* We may be interested only in only caps, and rig_open may fail.
*/
if (dump_caps_opt) {
if (dump_caps_opt)
{
dumpcaps(my_rig, stdout);
rig_cleanup(my_rig); /* if you care about memory */
exit(0);
@ -437,12 +499,14 @@ int main(int argc, char *argv[])
retcode = rig_open(my_rig);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) {
if (verbose > 0)
{
printf("Opened rig model %d, '%s'\n",
my_rig->caps->rig_model,
my_rig->caps->model_name);
@ -457,19 +521,23 @@ int main(int argc, char *argv[])
#ifdef HAVE_LIBREADLINE
if (interactive && prompt && have_rl) {
if (interactive && prompt && have_rl)
{
rl_readline_name = "rigctl";
#ifdef HAVE_READLINE_HISTORY
using_history(); /* Initialize Readline History */
if (rd_hist || sv_hist) {
if (!(hist_dir = getenv("RIGCTL_HIST_DIR"))) {
if (rd_hist || sv_hist)
{
if (!(hist_dir = getenv("RIGCTL_HIST_DIR")))
{
hist_dir = getenv("HOME");
}
if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT))
|| !(S_ISDIR(hist_dir_stat.st_mode))) {
|| !(S_ISDIR(hist_dir_stat.st_mode)))
{
fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir);
}
@ -482,8 +550,10 @@ int main(int argc, char *argv[])
strncat(hist_path, hist_file, strlen(hist_file));
}
if (rd_hist && hist_path) {
if (read_history(hist_path) == ENOENT) {
if (rd_hist && hist_path)
{
if (read_history(hist_path) == ENOENT)
{
fprintf(stderr,
"Warning: Could not read history from %s\n",
hist_path);
@ -495,28 +565,35 @@ int main(int argc, char *argv[])
#endif /* HAVE_LIBREADLINE */
do {
do
{
retcode = rigctl_parse(my_rig, stdin, stdout, argv, argc);
if (retcode == 2) {
if (retcode == 2)
{
exitcode = 2;
}
} while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL);
}
while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL);
#ifdef HAVE_LIBREADLINE
if (interactive && prompt && have_rl) {
if (interactive && prompt && have_rl)
{
#ifdef HAVE_READLINE_HISTORY
if (sv_hist && hist_path) {
if (write_history(hist_path) == ENOENT) {
if (sv_hist && hist_path)
{
if (write_history(hist_path) == ENOENT)
{
fprintf(stderr,
"\nWarning: Could not write history to %s\n",
hist_path);
}
}
if ((rd_hist || sv_hist) && hist_path) {
if ((rd_hist || sv_hist) && hist_path)
{
free(hist_path);
hist_path = (char *)NULL;
}
@ -539,28 +616,28 @@ void usage(void)
printf(
" -m, --model=ID select radio model number. See model list\n"
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
" -d, --dcd-file=DEVICE set device of the DCD device to operate on\n"
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
" -D, --dcd-type=TYPE set type of the DCD device to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -t, --send-cmd-term=CHAR set send_cmd command termination char\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n"
" -o, --vfo do not default to VFO_CURR, require extra vfo arg\n"
" -n, --no-restore-ai do not restore auto information mode on rig\n"
" -m, --model=ID select radio model number. See model list\n"
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
" -d, --dcd-file=DEVICE set device of the DCD device to operate on\n"
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
" -D, --dcd-type=TYPE set type of the DCD device to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -t, --send-cmd-term=CHAR set send_cmd command termination char\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n"
" -o, --vfo do not default to VFO_CURR, require extra vfo arg\n"
" -n, --no-restore-ai do not restore auto information mode on rig\n"
#ifdef HAVE_READLINE_HISTORY
" -i, --read-history read prior interactive session history\n"
" -I, --save-history save current interactive session history\n"
" -i, --read-history read prior interactive session history\n"
" -I, --save-history save current interactive session history\n"
#endif
" -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"
" -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"
);
usage_rig(stdout);

Plik diff jest za duży Load Diff

Wyświetl plik

@ -81,7 +81,8 @@
* TODO: add an option to read from a file
*/
#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:lLuovhV"
static struct option long_options[] = {
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
{"rig-file", 1, 0, 'r'},
{"ptt-file", 1, 0, 'p'},
@ -104,7 +105,8 @@ static struct option long_options[] = {
};
struct handle_data {
struct handle_data
{
RIG *rig;
int sock;
struct sockaddr_storage cli_addr;
@ -112,7 +114,7 @@ struct handle_data {
};
void * handle_socket(void *arg);
void *handle_socket(void *arg);
void usage(void);
@ -143,11 +145,14 @@ static void handle_error(enum rig_debug_level_e lvl, const char *msg)
NULL, e,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
// Default language
(LPTSTR)&lpMsgBuf, 0, NULL)) {
(LPTSTR)&lpMsgBuf, 0, NULL))
{
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf);
LocalFree(lpMsgBuf);
} else {
}
else
{
rig_debug(lvl, "%s: Network error %d\n", msg, e);
}
@ -188,7 +193,8 @@ int main(int argc, char *argv[])
#endif
struct handle_data *arg;
while (1) {
while (1)
{
int c;
int option_index = 0;
@ -198,11 +204,13 @@ int main(int argc, char *argv[])
long_options,
&option_index);
if (c == -1) {
if (c == -1)
{
break;
}
switch (c) {
switch (c)
{
case 'h':
usage();
exit(0);
@ -212,7 +220,8 @@ int main(int argc, char *argv[])
exit(0);
case 'm':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -221,7 +230,8 @@ int main(int argc, char *argv[])
break;
case 'r':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -230,7 +240,8 @@ int main(int argc, char *argv[])
break;
case 'p':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -239,7 +250,8 @@ int main(int argc, char *argv[])
break;
case 'd':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -248,55 +260,84 @@ int main(int argc, char *argv[])
break;
case 'P':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (!strcmp(optarg, "RIG")) {
if (!strcmp(optarg, "RIG"))
{
ptt_type = RIG_PTT_RIG;
} else if (!strcmp(optarg, "DTR")) {
}
else if (!strcmp(optarg, "DTR"))
{
ptt_type = RIG_PTT_SERIAL_DTR;
} else if (!strcmp(optarg, "RTS")) {
}
else if (!strcmp(optarg, "RTS"))
{
ptt_type = RIG_PTT_SERIAL_RTS;
} else if (!strcmp(optarg, "PARALLEL")) {
}
else if (!strcmp(optarg, "PARALLEL"))
{
ptt_type = RIG_PTT_PARALLEL;
} else if (!strcmp(optarg, "CM108")) {
}
else if (!strcmp(optarg, "CM108"))
{
ptt_type = RIG_PTT_CM108;
} else if (!strcmp(optarg, "NONE")) {
}
else if (!strcmp(optarg, "NONE"))
{
ptt_type = RIG_PTT_NONE;
} else {
}
else
{
ptt_type = atoi(optarg);
}
break;
case 'D':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (!strcmp(optarg, "RIG")) {
if (!strcmp(optarg, "RIG"))
{
dcd_type = RIG_DCD_RIG;
} else if (!strcmp(optarg, "DSR")) {
}
else if (!strcmp(optarg, "DSR"))
{
dcd_type = RIG_DCD_SERIAL_DSR;
} else if (!strcmp(optarg, "CTS")) {
}
else if (!strcmp(optarg, "CTS"))
{
dcd_type = RIG_DCD_SERIAL_CTS;
} else if (!strcmp(optarg, "CD")) {
}
else if (!strcmp(optarg, "CD"))
{
dcd_type = RIG_DCD_SERIAL_CAR;
} else if (!strcmp(optarg, "PARALLEL")) {
}
else if (!strcmp(optarg, "PARALLEL"))
{
dcd_type = RIG_DCD_PARALLEL;
} else if (!strcmp(optarg, "NONE")) {
}
else if (!strcmp(optarg, "NONE"))
{
dcd_type = RIG_DCD_NONE;
} else {
}
else
{
dcd_type = atoi(optarg);
}
break;
case 'c':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -305,7 +346,8 @@ int main(int argc, char *argv[])
break;
case 's':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -314,12 +356,14 @@ int main(int argc, char *argv[])
break;
case 'C':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (*conf_parms != '\0') {
if (*conf_parms != '\0')
{
strcat(conf_parms, ",");
}
@ -327,7 +371,8 @@ int main(int argc, char *argv[])
break;
case 't':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -336,7 +381,8 @@ int main(int argc, char *argv[])
break;
case 'T':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -378,7 +424,8 @@ int main(int argc, char *argv[])
my_rig = rig_init(my_model);
if (!my_rig) {
if (!my_rig)
{
fprintf(stderr,
"Unknown rig num %d, or initialization error.\n",
my_model);
@ -389,47 +436,56 @@ int main(int argc, char *argv[])
retcode = set_conf(my_rig, conf_parms);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (rig_file) {
if (rig_file)
{
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
}
/*
* ex: RIG_PTT_PARALLEL and /dev/parport0
*/
if (ptt_type != RIG_PTT_NONE) {
if (ptt_type != RIG_PTT_NONE)
{
my_rig->state.pttport.type.ptt = ptt_type;
}
if (dcd_type != RIG_DCD_NONE) {
if (dcd_type != RIG_DCD_NONE)
{
my_rig->state.dcdport.type.dcd = dcd_type;
}
if (ptt_file) {
if (ptt_file)
{
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
}
if (dcd_file) {
if (dcd_file)
{
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0) {
if (serial_rate != 0)
{
my_rig->state.rigport.parm.serial.rate = serial_rate;
}
if (civaddr) {
if (civaddr)
{
rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
}
/*
* print out conf parameters
*/
if (show_conf) {
if (show_conf)
{
rig_token_foreach(my_rig, print_conf_list, (rig_ptr_t)my_rig);
}
@ -437,7 +493,8 @@ int main(int argc, char *argv[])
* print out conf parameters, and exits immediately
* We may be interested only in only caps, and rig_open may fail.
*/
if (dump_caps_opt) {
if (dump_caps_opt)
{
dumpcaps(my_rig, stdout);
rig_cleanup(my_rig); /* if you care about memory */
exit(0);
@ -445,12 +502,14 @@ int main(int argc, char *argv[])
retcode = rig_open(my_rig);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) {
if (verbose > 0)
{
printf("Opened rig model %d, '%s'\n",
my_rig->caps->rig_model,
my_rig->caps->model_name);
@ -472,7 +531,8 @@ int main(int argc, char *argv[])
WSADATA wsadata;
if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) {
if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR)
{
fprintf(stderr, "WSAStartup socket error\n");
exit(1);
}
@ -493,19 +553,22 @@ int main(int argc, char *argv[])
retcode = getaddrinfo(src_addr, portno, &hints, &result);
if (retcode != 0) {
if (retcode != 0)
{
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode));
exit(2);
}
saved_result = result;
do {
do
{
sock_listen = socket(result->ai_family,
result->ai_socktype,
result->ai_protocol);
if (sock_listen < 0) {
if (sock_listen < 0)
{
handle_error(RIG_DEBUG_ERR, "socket");
freeaddrinfo(saved_result); /* No longer needed */
exit(2);
@ -516,7 +579,8 @@ int main(int argc, char *argv[])
SO_REUSEADDR,
(char *)&reuseaddr,
sizeof(reuseaddr))
< 0) {
< 0)
{
handle_error(RIG_DEBUG_ERR, "setsockopt");
freeaddrinfo(saved_result); /* No longer needed */
@ -525,7 +589,8 @@ int main(int argc, char *argv[])
#ifdef IPV6_V6ONLY
if (AF_INET6 == result->ai_family) {
if (AF_INET6 == result->ai_family)
{
/* allow IPv4 mapped to IPv6 clients Windows and BSD default
this to 1 (i.e. disallowed) and we prefer it off */
sockopt = 0;
@ -535,7 +600,8 @@ int main(int argc, char *argv[])
IPV6_V6ONLY,
(char *)&sockopt,
sizeof(sockopt))
< 0) {
< 0)
{
handle_error(RIG_DEBUG_ERR, "setsockopt");
freeaddrinfo(saved_result); /* No longer needed */
@ -545,7 +611,8 @@ int main(int argc, char *argv[])
#endif
if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) {
if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen))
{
break;
}
@ -555,16 +622,19 @@ int main(int argc, char *argv[])
#else
close(sock_listen);
#endif
} while ((result = result->ai_next) != NULL);
}
while ((result = result->ai_next) != NULL);
freeaddrinfo(saved_result); /* No longer needed */
if (NULL == result) {
if (NULL == result)
{
rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n");
exit(1);
}
if (listen(sock_listen, 4) < 0) {
if (listen(sock_listen, 4) < 0)
{
handle_error(RIG_DEBUG_ERR, "listening");
exit(1);
}
@ -579,25 +649,30 @@ int main(int argc, char *argv[])
act.sa_handler = SIG_IGN;
act.sa_flags = SA_RESTART;
if (sigaction(SIGPIPE, &act, NULL)) {
if (sigaction(SIGPIPE, &act, NULL))
{
handle_error(RIG_DEBUG_ERR, "sigaction");
}
#elif HAVE_SIGNAL
if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) {
if (SIG_ERR == signal(SIGPIPE, SIG_IGN))
{
handle_error(RIG_DEBUG_ERR, "signal");
}
#endif
#endif
/*
* main loop accepting connections
*/
do {
do
{
arg = malloc(sizeof(struct handle_data));
if (!arg) {
if (!arg)
{
rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno));
exit(1);
}
@ -608,7 +683,8 @@ int main(int argc, char *argv[])
(struct sockaddr *)&arg->cli_addr,
&arg->clilen);
if (arg->sock < 0) {
if (arg->sock < 0)
{
handle_error(RIG_DEBUG_ERR, "accept");
break;
}
@ -620,12 +696,18 @@ int main(int argc, char *argv[])
serv,
sizeof(serv),
NI_NOFQDN))
< 0) {
< 0)
{
rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode));
rig_debug(RIG_DEBUG_WARN,
"Peer lookup error: %s",
gai_strerror(retcode));
}
rig_debug(RIG_DEBUG_VERBOSE, "Connection opened from %s:%s\n", host, serv);
rig_debug(RIG_DEBUG_VERBOSE,
"Connection opened from %s:%s\n",
host,
serv);
#ifdef HAVE_PTHREAD
pthread_attr_init(&attr);
@ -633,7 +715,8 @@ int main(int argc, char *argv[])
retcode = pthread_create(&thread, &attr, handle_socket, arg);
if (retcode != 0) {
if (retcode != 0)
{
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
break;
}
@ -641,7 +724,8 @@ int main(int argc, char *argv[])
#else
handle_socket(arg);
#endif
} while (retcode == 0);
}
while (retcode == 0);
rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
@ -669,7 +753,8 @@ void * handle_socket(void *arg)
#ifdef __MINGW32__
int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY);
if (sock_osfhandle == -1) {
if (sock_osfhandle == -1)
{
rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno));
goto handle_exit;
}
@ -679,7 +764,8 @@ void * handle_socket(void *arg)
fsockin = fdopen(handle_data_arg->sock, "rb");
#endif
if (!fsockin) {
if (!fsockin)
{
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
goto handle_exit;
}
@ -690,20 +776,24 @@ void * handle_socket(void *arg)
fsockout = fdopen(handle_data_arg->sock, "wb");
#endif
if (!fsockout) {
if (!fsockout)
{
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
fclose(fsockin);
goto handle_exit;
}
do {
do
{
retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0);
if (ferror(fsockin) || ferror(fsockout)) {
if (ferror(fsockin) || ferror(fsockout))
{
retcode = 1;
}
} while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL);
}
while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL);
if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr,
handle_data_arg->clilen,
@ -712,13 +802,16 @@ void * handle_socket(void *arg)
serv,
sizeof(serv),
NI_NOFQDN))
< 0) {
< 0)
{
rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode));
}
rig_debug(RIG_DEBUG_VERBOSE, "Connection closed from %s:%s\n",
host, serv);
rig_debug(RIG_DEBUG_VERBOSE,
"Connection closed from %s:%s\n",
host,
serv);
fclose(fsockin);
#ifndef __MINGW32__
@ -747,24 +840,24 @@ void usage(void)
printf(
" -m, --model=ID select radio model number. See model list\n"
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
" -d, --dcd-file=DEVICE set device of the DCD device to operate on\n"
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
" -D, --dcd-type=TYPE set type of the DCD device to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -t, --port=NUM set TCP listening port, default %s\n"
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n"
" -o, --vfo do not default to VFO_CURR, require extra vfo arg\n"
" -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n",
" -m, --model=ID select radio model number. See model list\n"
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
" -d, --dcd-file=DEVICE set device of the DCD device to operate on\n"
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
" -D, --dcd-type=TYPE set type of the DCD device to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -t, --port=NUM set TCP listening port, default %s\n"
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n"
" -o, --vfo do not default to VFO_CURR, require extra vfo arg\n"
" -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n",
portno);
usage_rig(stdout);

Wyświetl plik

@ -48,7 +48,8 @@ int print_caps_sum(const struct rig_caps *caps, void *data)
caps->version,
rig_strstatus(caps->status));
switch (caps->rig_type & RIG_TYPE_MASK) {
switch (caps->rig_type & RIG_TYPE_MASK)
{
case RIG_TYPE_TRANSCEIVER:
printf("Transceiver");
break;
@ -116,7 +117,8 @@ int print_caps_parameters(const struct rig_caps *caps, void *data)
caps->rig_model,
caps->model_name);
switch (caps->ptt_type) {
switch (caps->ptt_type)
{
case RIG_PTT_RIG:
printf("rig");
break;
@ -140,7 +142,8 @@ int print_caps_parameters(const struct rig_caps *caps, void *data)
printf("</TD><TD>");
switch (caps->dcd_type) {
switch (caps->dcd_type)
{
case RIG_DCD_RIG:
printf("rig");
break;
@ -164,7 +167,8 @@ int print_caps_parameters(const struct rig_caps *caps, void *data)
printf("</TD><TD>");
switch (caps->port_type) {
switch (caps->port_type)
{
case RIG_PORT_SERIAL:
printf("serial");
break;
@ -194,9 +198,9 @@ int print_caps_parameters(const struct rig_caps *caps, void *data)
caps->serial_rate_max,
caps->serial_data_bits,
caps->serial_parity == RIG_PARITY_NONE ? 'N' :
caps->serial_parity == RIG_PARITY_ODD ? 'O' :
caps->serial_parity == RIG_PARITY_EVEN ? 'E' :
caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S',
caps->serial_parity == RIG_PARITY_ODD ? 'O' :
caps->serial_parity == RIG_PARITY_EVEN ? 'E' :
caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S',
caps->serial_stop_bits,
caps->serial_handshake == RIG_HANDSHAKE_NONE ? "none" :
(caps->serial_handshake == RIG_HANDSHAKE_XONXOFF ? "XONXOFF" : "CTS/RTS"));
@ -271,7 +275,8 @@ int print_caps_parm(const struct rig_caps *caps, void *data)
setting_t parm;
int i;
if (!data) {
if (!data)
{
return 0;
}
@ -285,8 +290,10 @@ int print_caps_parm(const struct rig_caps *caps, void *data)
/*
* bitmap_parm: only those who have a label
*/
for (i = 0; i < RIG_SETTING_MAX; i++) {
if (rig_idx2setting(i) & bitmap_parm) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
if (rig_idx2setting(i) & bitmap_parm)
{
print_yn(parm & rig_idx2setting(i));
}
}
@ -305,7 +312,8 @@ int print_caps_level(const struct rig_caps *caps, void *data)
setting_t level;
int i;
if (!data) {
if (!data)
{
return 0;
}
@ -319,8 +327,10 @@ int print_caps_level(const struct rig_caps *caps, void *data)
/*
* bitmap_level: only those who have a label
*/
for (i = 0; i < 32; i++) {
if (rig_idx2setting(i) & bitmap_level) {
for (i = 0; i < 32; i++)
{
if (rig_idx2setting(i) & bitmap_level)
{
print_yn(level & rig_idx2setting(i));
}
}
@ -339,7 +349,8 @@ int print_caps_func(const struct rig_caps *caps, void *data)
setting_t func;
int i;
if (!data) {
if (!data)
{
return 0;
}
@ -353,8 +364,10 @@ int print_caps_func(const struct rig_caps *caps, void *data)
/*
* bitmap_func: only those who have a label
*/
for (i = 0; i < RIG_SETTING_MAX; i++) {
if (rig_idx2setting(i) & bitmap_func) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
if (rig_idx2setting(i) & bitmap_func)
{
print_yn(func & rig_idx2setting(i));
}
}
@ -409,10 +422,12 @@ static void draw_range(const freq_range_t range_list[],
{
int i;
for (i = 0; i < FRQRANGESIZ; i++) {
for (i = 0; i < FRQRANGESIZ; i++)
{
float start_pix, end_pix;
if (range_list[i].start == 0 && range_list[i].end == 0) {
if (range_list[i].start == 0 && range_list[i].end == 0)
{
break;
}
@ -422,11 +437,13 @@ static void draw_range(const freq_range_t range_list[],
/*
* HF
*/
if (range_list[i].start < MHz(30)) {
if (range_list[i].start < MHz(30))
{
start_pix = start_pix / MHz(30) * RANGE_WIDTH;
end_pix = end_pix / MHz(30) * RANGE_WIDTH;
if (end_pix >= RANGE_WIDTH) {
if (end_pix >= RANGE_WIDTH)
{
end_pix = RANGE_WIDTH - 1;
}
@ -447,17 +464,20 @@ static void draw_range(const freq_range_t range_list[],
end_pix = range_list[i].end;
if ((range_list[i].start > MHz(30) && range_list[i].start < MHz(300))
|| (range_list[i].start < MHz(30)
&& range_list[i].end > MHz(30))) {
|| (range_list[i].start < MHz(30)
&& range_list[i].end > MHz(30)))
{
start_pix = (start_pix - MHz(30)) / MHz(300) * RANGE_WIDTH;
end_pix = (end_pix - MHz(30)) / MHz(300) * RANGE_WIDTH;
if (start_pix < 0) {
if (start_pix < 0)
{
start_pix = 0;
}
if (end_pix >= RANGE_WIDTH) {
if (end_pix >= RANGE_WIDTH)
{
end_pix = RANGE_WIDTH - 1;
}
@ -478,17 +498,20 @@ static void draw_range(const freq_range_t range_list[],
end_pix = range_list[i].end;
if ((range_list[i].start > MHz(300) && range_list[i].start < GHz(3))
|| (range_list[i].start < MHz(300)
&& range_list[i].end > MHz(300))) {
|| (range_list[i].start < MHz(300)
&& range_list[i].end > MHz(300)))
{
start_pix = (start_pix - MHz(300)) / GHz(3) * RANGE_WIDTH;
end_pix = (end_pix - MHz(300)) / GHz(3) * RANGE_WIDTH;
if (start_pix < 0) {
if (start_pix < 0)
{
start_pix = 0;
}
if (end_pix >= RANGE_WIDTH) {
if (end_pix >= RANGE_WIDTH)
{
end_pix = RANGE_WIDTH - 1;
}
@ -673,11 +696,13 @@ int main(int argc, char *argv[])
prntbuf[0] = '\0';
pbuf = prntbuf;
for (i = 0; i < RIG_SETTING_MAX; i++) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
setting_t func = rig_idx2setting(i);
const char *s = rig_strfunc(func);
if (!s) {
if (!s)
{
continue;
}
@ -707,11 +732,13 @@ int main(int argc, char *argv[])
prntbuf[0] = '\0';
pbuf = prntbuf;
for (i = 0; i < RIG_SETTING_MAX; i++) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
setting_t level = rig_idx2setting(i);
const char *s = rig_strlevel(level);
if (!s) {
if (!s)
{
continue;
}
@ -741,11 +768,13 @@ int main(int argc, char *argv[])
prntbuf[0] = '\0';
pbuf = prntbuf;
for (i = 0; i < RIG_SETTING_MAX; i++) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
setting_t parm = rig_idx2setting(i);
const char *s = rig_strparm(parm);
if (!s) {
if (!s)
{
continue;
}

Wyświetl plik

@ -72,20 +72,21 @@ int clear_chans(RIG *rig, const char *infilename);
* NB: do NOT use -W since it's reserved by POSIX.
*/
#define SHORT_OPTIONS "m:r:s:c:C:p:axvhV"
static struct option long_options[] = {
{"model", 1, 0, 'm'},
{"rig-file", 1, 0, 'r'},
{"serial-speed", 1, 0, 's'},
{"civaddr", 1, 0, 'c'},
{"set-conf", 1, 0, 'C'},
{"set-separator", 1, 0, 'p'},
{"all", 0, 0, 'a'},
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
{"rig-file", 1, 0, 'r'},
{"serial-speed", 1, 0, 's'},
{"civaddr", 1, 0, 'c'},
{"set-conf", 1, 0, 'C'},
{"set-separator", 1, 0, 'p'},
{"all", 0, 0, 'a'},
#ifdef HAVE_XML2
{"xml", 0, 0, 'x'},
{"xml", 0, 0, 'x'},
#endif
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
{0, 0, 0, 0}
};
@ -107,17 +108,20 @@ int main(int argc, char *argv[])
char conf_parms[MAXCONFLEN] = "";
extern char csv_sep;
while (1) {
while (1)
{
int c;
int option_index = 0;
c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
if (c == -1) {
if (c == -1)
{
break;
}
switch (c) {
switch (c)
{
case 'h':
usage();
exit(0);
@ -127,7 +131,8 @@ int main(int argc, char *argv[])
exit(0);
case 'm':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -136,7 +141,8 @@ int main(int argc, char *argv[])
break;
case 'r':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -145,7 +151,8 @@ int main(int argc, char *argv[])
break;
case 'c':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -154,7 +161,8 @@ int main(int argc, char *argv[])
break;
case 's':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -163,12 +171,14 @@ int main(int argc, char *argv[])
break;
case 'C':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (*conf_parms != '\0') {
if (*conf_parms != '\0')
{
strcat(conf_parms, ",");
}
@ -176,7 +186,8 @@ int main(int argc, char *argv[])
break;
case 'p':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -211,14 +222,16 @@ int main(int argc, char *argv[])
"Report bugs to "
"<hamlib-developer@lists.sourceforge.net>\n\n");
if (optind + 1 >= argc) {
if (optind + 1 >= argc)
{
usage();
exit(1);
}
rig = rig_init(my_model);
if (!rig) {
if (!rig)
{
fprintf(stderr,
"Unknown rig num %d, or initialization error.\n",
my_model);
@ -229,7 +242,8 @@ int main(int argc, char *argv[])
retcode = set_conf(rig, conf_parms);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
@ -239,7 +253,8 @@ int main(int argc, char *argv[])
&& rig->caps->get_channel == NULL
&& rig->caps->set_chan_all_cb == NULL
&& rig->caps->get_chan_all_cb == NULL
&& (rig->caps->set_mem == NULL || rig->caps->set_vfo == NULL)) {
&& (rig->caps->set_mem == NULL || rig->caps->set_vfo == NULL))
{
fprintf(stderr,
"Error: rig num %d has no memory support implemented/available.\n",
@ -248,33 +263,39 @@ int main(int argc, char *argv[])
}
/* check channel description */
if (rig->caps->chan_list[0].type == 0) {
if (rig->caps->chan_list[0].type == 0)
{
fprintf(stderr, "Error: rig num %d has no channel list.\n",
my_model);
exit(3);
}
if (rig_file) {
if (rig_file)
{
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0) {
if (serial_rate != 0)
{
rig->state.rigport.parm.serial.rate = serial_rate;
}
if (civaddr) {
if (civaddr)
{
rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr);
}
retcode = rig_open(rig);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) {
if (verbose > 0)
{
printf("Opened rig model %d, '%s'\n",
rig->caps->rig_model,
rig->caps->model_name);
@ -288,33 +309,56 @@ int main(int argc, char *argv[])
/* on some rigs, this accelerates the backup/restore */
rig_set_vfo(rig, RIG_VFO_MEM);
if (!strcmp(argv[optind], "save")) {
if (xml) {
if (!strcmp(argv[optind], "save"))
{
if (xml)
{
retcode = xml_save(rig, argv[optind + 1]);
} else {
}
else
{
retcode = csv_save(rig, argv[optind + 1]);
}
} else if (!strcmp(argv[optind], "load")) {
if (xml) {
}
else if (!strcmp(argv[optind], "load"))
{
if (xml)
{
retcode = xml_load(rig, argv[optind + 1]);
} else {
}
else
{
retcode = csv_load(rig, argv[optind + 1]);
}
} else if (!strcmp(argv[optind], "save_parm")) {
if (xml) {
}
else if (!strcmp(argv[optind], "save_parm"))
{
if (xml)
{
retcode = xml_parm_save(rig, argv[optind + 1]);
} else {
}
else
{
retcode = csv_parm_save(rig, argv[optind + 1]);
}
} else if (!strcmp(argv[optind], "load_parm")) {
if (xml) {
}
else if (!strcmp(argv[optind], "load_parm"))
{
if (xml)
{
retcode = xml_parm_load(rig, argv[optind + 1]);
} else {
}
else
{
retcode = csv_parm_load(rig, argv[optind + 1]);
}
} else if (!strcmp(argv[optind], "clear")) {
}
else if (!strcmp(argv[optind], "clear"))
{
retcode = clear_chans(rig, argv[optind + 1]);
} else {
}
else
{
usage();
exit(1);
}
@ -322,7 +366,8 @@ int main(int argc, char *argv[])
rig_close(rig); /* close port */
rig_cleanup(rig); /* if you care about memory */
if (retcode != 0) {
if (retcode != 0)
{
fprintf(stderr, "Hamlib error: %s\n", rigerror(retcode));
exit(2);
}
@ -345,19 +390,19 @@ void usage()
printf(
" -m, --model=ID select radio model number. See model list\n"
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -p, --set-separator=SEP set character separator instead of the CSV comma\n"
" -a, --all bypass mem_caps, apply to all fields of channel_t\n"
" -m, --model=ID select radio model number. See model list\n"
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -p, --set-separator=SEP set character separator instead of the CSV comma\n"
" -a, --all bypass mem_caps, apply to all fields of channel_t\n"
#ifdef HAVE_XML2
" -x, --xml use XML format instead of CSV\n"
" -x, --xml use XML format instead of CSV\n"
#endif
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"
);
printf(
@ -381,24 +426,28 @@ int set_conf(RIG *rig, char *conf_parms)
p = conf_parms;
while (p && *p != '\0') {
while (p && *p != '\0')
{
/* FIXME: left hand value of = cannot be null */
q = strchr(p, '=');
if (!q) {
if (!q)
{
return RIG_EINVAL;
}
*q++ = '\0';
n = strchr(q, ',');
if (n) {
if (n)
{
*n++ = '\0';
}
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q);
if (ret != RIG_OK) {
if (ret != RIG_OK)
{
return ret;
}
@ -424,14 +473,17 @@ int clear_chans(RIG *rig, const char *infilename)
chan.tx_mode = RIG_MODE_NONE;
chan.vfo = RIG_VFO_MEM;
for (i = 0; rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) {
for (i = 0; rig->state.chan_list[i].type && i < CHANLSTSIZ; i++)
{
for (j = rig->state.chan_list[i].start;
j <= rig->state.chan_list[i].end; j++) {
j <= rig->state.chan_list[i].end; j++)
{
chan.channel_num = j;
ret = rig_set_channel(rig, &chan);
if (ret != RIG_OK) {
if (ret != RIG_OK)
{
return ret;
}
}

Wyświetl plik

@ -53,7 +53,8 @@ static int set_conf_rot(ROT *rot, char *conf_parms);
* NB: do NOT use -W since it's reserved by POSIX.
*/
#define SHORT_OPTIONS "m:r:s:c:C:M:R:S:N:vhV"
static struct option long_options[] = {
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
{"rig-file", 1, 0, 'r'},
{"serial-speed", 1, 0, 's'},
@ -94,17 +95,20 @@ int main(int argc, char *argv[])
elevation_t elevation;
unsigned step = 1000000; /* 1e6 us */
while (1) {
while (1)
{
int c;
int option_index = 0;
c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
if (c == -1) {
if (c == -1)
{
break;
}
switch (c) {
switch (c)
{
case 'h':
usage();
exit(0);
@ -114,7 +118,8 @@ int main(int argc, char *argv[])
exit(0);
case 'm':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -123,7 +128,8 @@ int main(int argc, char *argv[])
break;
case 'r':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -132,7 +138,8 @@ int main(int argc, char *argv[])
break;
case 'c':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -141,7 +148,8 @@ int main(int argc, char *argv[])
break;
case 's':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -150,12 +158,14 @@ int main(int argc, char *argv[])
break;
case 'C':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (*rig_conf_parms != '\0') {
if (*rig_conf_parms != '\0')
{
strcat(rig_conf_parms, ",");
}
@ -163,7 +173,8 @@ int main(int argc, char *argv[])
break;
case 'M':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -172,7 +183,8 @@ int main(int argc, char *argv[])
break;
case 'R':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -181,7 +193,8 @@ int main(int argc, char *argv[])
break;
case 'S':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -190,12 +203,14 @@ int main(int argc, char *argv[])
break;
case 'N':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (*rot_conf_parms != '\0') {
if (*rot_conf_parms != '\0')
{
strcat(rot_conf_parms, ",");
}
@ -223,7 +238,8 @@ int main(int argc, char *argv[])
*/
rig = rig_init(rig_model);
if (!rig) {
if (!rig)
{
fprintf(stderr,
"Unknown rig num %d, or initialization error.\n",
rig_model);
@ -234,26 +250,31 @@ int main(int argc, char *argv[])
retcode = set_conf_rig(rig, rig_conf_parms);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (rig_file) {
if (rig_file)
{
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0) {
if (serial_rate != 0)
{
rig->state.rigport.parm.serial.rate = serial_rate;
}
if (civaddr) {
if (civaddr)
{
rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr);
}
if (!rig_has_get_level(rig, RIG_LEVEL_STRENGTH)) {
if (!rig_has_get_level(rig, RIG_LEVEL_STRENGTH))
{
fprintf(stderr,
"rig backend for %s could not get S-Meter"
"or has unsufficient capability\nSorry\n",
@ -263,12 +284,14 @@ int main(int argc, char *argv[])
retcode = rig_open(rig);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) {
if (verbose > 0)
{
printf("Opened rig model %d, '%s'\n",
rig->caps->rig_model,
rig->caps->model_name);
@ -279,7 +302,8 @@ int main(int argc, char *argv[])
*/
rot = rot_init(rot_model);
if (!rot) {
if (!rot)
{
fprintf(stderr,
"Unknown rot num %d, or initialization error.\n",
rot_model);
@ -290,23 +314,27 @@ int main(int argc, char *argv[])
retcode = set_conf_rot(rot, rot_conf_parms);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (rot_file) {
if (rot_file)
{
strncpy(rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (rot_serial_rate != 0) {
if (rot_serial_rate != 0)
{
rot->state.rotport.parm.serial.rate = rot_serial_rate;
}
retcode = rot_open(rot);
if (retcode != RIG_OK && rot_model != ROT_MODEL_DUMMY) {
if (retcode != RIG_OK && rot_model != ROT_MODEL_DUMMY)
{
fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
exit(2);
}
@ -317,14 +345,16 @@ int main(int argc, char *argv[])
/* if (rot_model == ROT_MODEL_DUMMY) */
/* with_rot = 1; */
if (verbose > 0) {
if (verbose > 0)
{
printf("Opened rotator model %d, '%s'\n",
rot->caps->rot_model,
rot->caps->model_name);
}
/*******************************/
if (optind < argc) {
if (optind < argc)
{
step = atof(argv[optind]) * 1e6;
}
@ -333,7 +363,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "Wait for rotator to move...\n");
rot_get_position(rot, &azimuth, &elevation);
while (fabs(azimuth - rot->state.min_az) > 1.) {
while (fabs(azimuth - rot->state.min_az) > 1.)
{
rot_get_position(rot, &azimuth, &elevation);
usleep(step);
}
@ -344,7 +375,8 @@ int main(int argc, char *argv[])
/* TODO: check CW or CCW */
/* disable AGC? */
while (fabs(rot->state.max_az - azimuth) > 1.) {
while (fabs(rot->state.max_az - azimuth) > 1.)
{
value_t strength;
rig_get_level(rig, RIG_VFO_CURR, RIG_LEVEL_STRENGTH, &strength);
@ -375,18 +407,18 @@ void usage()
"Input S-Meter vs Azimuth.\n\n");
printf(
" -m, --model=ID select radio model number. See model list\n"
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -M, --rot-model=ID select rotator model number. See model list\n"
" -R, --rot-file=DEVICE set device of the rotator to operate on\n"
" -S, --rot-serial-speed=BAUD set serial speed of the serial port\n"
" -N, --rot-set-conf=PARM=VAL set rotator config parameters\n"
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"
" -m, --model=ID select radio model number. See model list\n"
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -M, --rot-model=ID select rotator model number. See model list\n"
" -R, --rot-file=DEVICE set device of the rotator to operate on\n"
" -S, --rot-serial-speed=BAUD set serial speed of the serial port\n"
" -N, --rot-set-conf=PARM=VAL set rotator config parameters\n"
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"
);
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
@ -401,24 +433,28 @@ int set_conf_rig(RIG *rig, char *conf_parms)
p = conf_parms;
while (p && *p != '\0') {
while (p && *p != '\0')
{
/* FIXME: left hand value of = cannot be null */
q = strchr(p, '=');
if (!q) {
if (!q)
{
return RIG_EINVAL;
}
*q++ = '\0';
n = strchr(q, ',');
if (n) {
if (n)
{
*n++ = '\0';
}
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q);
if (ret != RIG_OK) {
if (ret != RIG_OK)
{
return ret;
}
@ -436,23 +472,27 @@ int set_conf_rot(ROT *rot, char *conf_parms)
p = conf_parms;
while (p && *p != '\0') {
while (p && *p != '\0')
{
/* FIXME: left hand value of = cannot be null */
q = strchr(p, '=');
if (q) {
if (q)
{
*q++ = '\0';
}
n = strchr(q, ',');
if (n) {
if (n)
{
*n++ = '\0';
}
ret = rot_set_conf(rot, rot_token_lookup(rot, p), q);
if (ret != RIG_OK) {
if (ret != RIG_OK)
{
return ret;
}

Wyświetl plik

@ -50,7 +50,8 @@ static int set_conf(RIG *rig, char *conf_parms);
* NB: do NOT use -W since it's reserved by POSIX.
*/
#define SHORT_OPTIONS "m:r:s:c:C:p:P:vhV"
static struct option long_options[] = {
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
{"rig-file", 1, 0, 'r'},
{"serial-speed", 1, 0, 's'},
@ -84,17 +85,20 @@ int main(int argc, char *argv[])
freq_t step = kHz(100);
value_t pwr;
while (1) {
while (1)
{
int c;
int option_index = 0;
c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
if (c == -1) {
if (c == -1)
{
break;
}
switch (c) {
switch (c)
{
case 'h':
usage();
exit(0);
@ -104,7 +108,8 @@ int main(int argc, char *argv[])
exit(0);
case 'm':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -113,7 +118,8 @@ int main(int argc, char *argv[])
break;
case 'r':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -122,7 +128,8 @@ int main(int argc, char *argv[])
break;
case 'c':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -131,7 +138,8 @@ int main(int argc, char *argv[])
break;
case 's':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -140,12 +148,14 @@ int main(int argc, char *argv[])
break;
case 'C':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (*conf_parms != '\0') {
if (*conf_parms != '\0')
{
strcat(conf_parms, ",");
}
@ -153,7 +163,8 @@ int main(int argc, char *argv[])
break;
case 'p':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -162,22 +173,34 @@ int main(int argc, char *argv[])
break;
case 'P':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (!strcmp(optarg, "RIG")) {
if (!strcmp(optarg, "RIG"))
{
ptt_type = RIG_PTT_RIG;
} else if (!strcmp(optarg, "DTR")) {
}
else if (!strcmp(optarg, "DTR"))
{
ptt_type = RIG_PTT_SERIAL_DTR;
} else if (!strcmp(optarg, "RTS")) {
}
else if (!strcmp(optarg, "RTS"))
{
ptt_type = RIG_PTT_SERIAL_RTS;
} else if (!strcmp(optarg, "PARALLEL")) {
}
else if (!strcmp(optarg, "PARALLEL"))
{
ptt_type = RIG_PTT_PARALLEL;
} else if (!strcmp(optarg, "NONE")) {
}
else if (!strcmp(optarg, "NONE"))
{
ptt_type = RIG_PTT_NONE;
} else {
}
else
{
ptt_type = atoi(optarg);
}
@ -199,14 +222,16 @@ int main(int argc, char *argv[])
rig_debug(RIG_DEBUG_VERBOSE,
"Report bugs to <hamlib-developer@lists.sourceforge.net>\n\n");
if (optind + 1 >= argc) {
if (optind + 1 >= argc)
{
usage();
exit(1);
}
rig = rig_init(my_model);
if (!rig) {
if (!rig)
{
fprintf(stderr,
"Unknown rig num %d, or initialization error.\n",
my_model);
@ -217,35 +242,42 @@ int main(int argc, char *argv[])
retcode = set_conf(rig, conf_parms);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (ptt_type != RIG_PTT_NONE) {
if (ptt_type != RIG_PTT_NONE)
{
rig->state.pttport.type.ptt = ptt_type;
}
if (ptt_file) {
if (ptt_file)
{
strncpy(rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
}
if (rig_file) {
if (rig_file)
{
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0) {
if (serial_rate != 0)
{
rig->state.rigport.parm.serial.rate = serial_rate;
}
if (civaddr) {
if (civaddr)
{
rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr);
}
if (!rig_has_get_level(rig, RIG_LEVEL_SWR)
|| rig->state.pttport.type.ptt == RIG_PTT_NONE) {
|| rig->state.pttport.type.ptt == RIG_PTT_NONE)
{
fprintf(stderr,
"rig backend for %s could not get SWR"
@ -257,12 +289,14 @@ int main(int argc, char *argv[])
retcode = rig_open(rig);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) {
if (verbose > 0)
{
printf("Opened rig model %d, '%s'\n",
rig->caps->rig_model,
rig->caps->model_name);
@ -271,7 +305,8 @@ int main(int argc, char *argv[])
freq = atof(argv[optind++]);
freqstop = atof(argv[optind++]);
if (optind < argc) {
if (optind < argc)
{
step = atof(argv[optind]);
}
@ -281,7 +316,8 @@ int main(int argc, char *argv[])
pwr.f = 0.25; /* 25% of RF POWER */
rig_set_level(rig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, pwr);
while (freq <= freqstop) {
while (freq <= freqstop)
{
value_t swr;
rig_set_ptt(rig, RIG_VFO_CURR, RIG_PTT_ON);
@ -314,16 +350,16 @@ void usage()
printf(
" -m, --model=ID select radio model number. See model list\n"
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"
" -m, --model=ID select radio model number. See model list\n"
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"
);
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
@ -338,24 +374,28 @@ int set_conf(RIG *rig, char *conf_parms)
p = conf_parms;
while (p && *p != '\0') {
while (p && *p != '\0')
{
/* FIXME: left hand value of = cannot be null */
q = strchr(p, '=');
if (!q) {
if (!q)
{
return RIG_EINVAL;
}
*q++ = '\0';
n = strchr(q, ',');
if (n) {
if (n)
{
*n++ = '\0';
}
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q);
if (ret != RIG_OK) {
if (ret != RIG_OK)
{
return ret;
}

Wyświetl plik

@ -62,7 +62,7 @@ extern int read_history();
# endif /* defined(HAVE_READLINE_HISTORY_H) */
#else
/* no history */
#define HST_SHRT_OPTS ""
# define HST_SHRT_OPTS ""
#endif /* HAVE_READLINE_HISTORY */
@ -83,7 +83,8 @@ void usage();
* TODO: add an option to read from a file
*/
#define SHORT_OPTIONS "+m:r:s:C:t:LvhVlu"
static struct option long_options[] = {
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
{"rot-file", 1, 0, 'r'},
{"serial-speed", 1, 0, 's'},
@ -141,7 +142,8 @@ int main(int argc, char *argv[])
int serial_rate = 0;
char conf_parms[MAXCONFLEN] = "";
while (1) {
while (1)
{
int c;
int option_index = 0;
@ -151,11 +153,13 @@ int main(int argc, char *argv[])
long_options,
&option_index);
if (c == -1) {
if (c == -1)
{
break;
}
switch (c) {
switch (c)
{
case 'h':
usage();
exit(0);
@ -165,7 +169,8 @@ int main(int argc, char *argv[])
exit(0);
case 'm':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -174,7 +179,8 @@ int main(int argc, char *argv[])
break;
case 'r':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -183,7 +189,8 @@ int main(int argc, char *argv[])
break;
case 's':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -192,12 +199,14 @@ int main(int argc, char *argv[])
break;
case 'C':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (*conf_parms != '\0') {
if (*conf_parms != '\0')
{
strcat(conf_parms, ",");
}
@ -205,14 +214,18 @@ int main(int argc, char *argv[])
break;
case 't':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (strlen(optarg) > 1) {
if (strlen(optarg) > 1)
{
send_cmd_term = strtol(optarg, NULL, 0);
} else {
}
else
{
send_cmd_term = optarg[0];
}
@ -261,13 +274,15 @@ int main(int argc, char *argv[])
* at least one command on command line,
* disable interactive mode
*/
if (optind < argc) {
if (optind < argc)
{
interactive = 0;
}
my_rot = rot_init(my_model);
if (!my_rot) {
if (!my_rot)
{
fprintf(stderr,
"Unknown rot num %d, or initialization error.\n",
my_model);
@ -278,24 +293,28 @@ int main(int argc, char *argv[])
retcode = set_conf(my_rot, conf_parms);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (rot_file) {
if (rot_file)
{
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0) {
if (serial_rate != 0)
{
my_rot->state.rotport.parm.serial.rate = serial_rate;
}
/*
* print out conf parameters
*/
if (show_conf) {
if (show_conf)
{
rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
}
@ -303,7 +322,8 @@ int main(int argc, char *argv[])
* Print out capabilities, and exits immediately as we may be interested
* only in caps, and rig_open may fail.
*/
if (dump_caps_opt) {
if (dump_caps_opt)
{
dumpcaps_rot(my_rot, stdout);
rot_cleanup(my_rot); /* if you care about memory */
exit(0);
@ -311,12 +331,14 @@ int main(int argc, char *argv[])
retcode = rot_open(my_rot);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) {
if (verbose > 0)
{
printf("Opened rot model %d, '%s'\n",
my_rot->caps->rot_model,
my_rot->caps->model_name);
@ -331,18 +353,22 @@ int main(int argc, char *argv[])
#ifdef HAVE_LIBREADLINE
if (interactive && prompt && have_rl) {
if (interactive && prompt && have_rl)
{
rl_readline_name = "rotctl";
#ifdef HAVE_READLINE_HISTORY
using_history(); /* Initialize Readline History */
if (rd_hist || sv_hist) {
if (!(hist_dir = getenv("ROTCTL_HIST_DIR"))) {
if (rd_hist || sv_hist)
{
if (!(hist_dir = getenv("ROTCTL_HIST_DIR")))
{
hist_dir = getenv("HOME");
}
if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT))
|| !(S_ISDIR(hist_dir_stat.st_mode))) {
|| !(S_ISDIR(hist_dir_stat.st_mode)))
{
fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir);
}
@ -356,8 +382,10 @@ int main(int argc, char *argv[])
strncat(hist_path, hist_file, strlen(hist_file));
}
if (rd_hist && hist_path) {
if (read_history(hist_path) == ENOENT) {
if (rd_hist && hist_path)
{
if (read_history(hist_path) == ENOENT)
{
fprintf(stderr,
"Warning: Could not read history from %s\n",
hist_path);
@ -369,28 +397,35 @@ int main(int argc, char *argv[])
#endif /* HAVE_LIBREADLINE */
do {
do
{
retcode = rotctl_parse(my_rot, stdin, stdout, argv, argc);
if (retcode == 2) {
if (retcode == 2)
{
exitcode = 2;
}
} while (retcode == 0 || retcode == 2);
}
while (retcode == 0 || retcode == 2);
#ifdef HAVE_LIBREADLINE
if (interactive && prompt && have_rl) {
if (interactive && prompt && have_rl)
{
#ifdef HAVE_READLINE_HISTORY
if (sv_hist && hist_path) {
if (write_history(hist_path) == ENOENT) {
if (sv_hist && hist_path)
{
if (write_history(hist_path) == ENOENT)
{
fprintf(stderr,
"\nWarning: Could not write history to %s\n",
hist_path);
}
}
if ((rd_hist || sv_hist) && hist_path) {
if ((rd_hist || sv_hist) && hist_path)
{
free(hist_path);
hist_path = (char *)NULL;
}
@ -411,23 +446,22 @@ void usage()
printf("Usage: rotctl [OPTION]... [COMMAND]...\n"
"Send COMMANDs to a connected antenna rotator.\n\n");
printf(
" -m, --model=ID select rotator model number. See model list\n"
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -t, --send-cmd-term=CHAR set send_cmd command termination char\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n"
" -m, --model=ID select rotator model number. See model list\n"
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -t, --send-cmd-term=CHAR set send_cmd command termination char\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n"
#ifdef HAVE_READLINE_HISTORY
" -i, --read-history read prior interactive session history\n"
" -I, --save-history save current interactive session history\n"
" -i, --read-history read prior interactive session history\n"
" -I, --save-history save current interactive session history\n"
#endif
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"
);
usage_rot(stdout);

Plik diff jest za duży Load Diff

Wyświetl plik

@ -66,7 +66,8 @@
#include "rotctl_parse.h"
struct handle_data {
struct handle_data
{
ROT *rot;
int sock;
struct sockaddr_storage cli_addr;
@ -84,7 +85,8 @@ void usage();
* TODO: add an option to read from a file
*/
#define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVl"
static struct option long_options[] = {
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
{"rot-file", 1, 0, 'r'},
{"serial-speed", 1, 0, 's'},
@ -129,11 +131,14 @@ static void handle_error(enum rig_debug_level_e lvl, const char *msg)
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0,
NULL)) {
NULL))
{
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf);
LocalFree(lpMsgBuf);
} else {
}
else
{
rig_debug(lvl, "%s: Network error %d\n", msg, e);
}
@ -171,17 +176,20 @@ int main(int argc, char *argv[])
#endif
struct handle_data *arg;
while (1) {
while (1)
{
int c;
int option_index = 0;
c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
if (c == -1) {
if (c == -1)
{
break;
}
switch (c) {
switch (c)
{
case 'h':
usage();
exit(0);
@ -191,7 +199,8 @@ int main(int argc, char *argv[])
exit(0);
case 'm':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -200,7 +209,8 @@ int main(int argc, char *argv[])
break;
case 'r':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -209,7 +219,8 @@ int main(int argc, char *argv[])
break;
case 's':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -218,12 +229,14 @@ int main(int argc, char *argv[])
break;
case 'C':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (*conf_parms != '\0') {
if (*conf_parms != '\0')
{
strcat(conf_parms, ",");
}
@ -231,7 +244,8 @@ int main(int argc, char *argv[])
break;
case 't':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -240,7 +254,8 @@ int main(int argc, char *argv[])
break;
case 'T':
if (!optarg) {
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
@ -278,7 +293,8 @@ int main(int argc, char *argv[])
my_rot = rot_init(my_model);
if (!my_rot) {
if (!my_rot)
{
fprintf(stderr,
"Unknown rot num %d, or initialization error.\n",
my_model);
@ -289,24 +305,28 @@ int main(int argc, char *argv[])
retcode = set_conf(my_rot, conf_parms);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (rot_file) {
if (rot_file)
{
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0) {
if (serial_rate != 0)
{
my_rot->state.rotport.parm.serial.rate = serial_rate;
}
/*
* print out conf parameters
*/
if (show_conf) {
if (show_conf)
{
rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
}
@ -314,7 +334,8 @@ int main(int argc, char *argv[])
* Print out conf parameters, and exits immediately as we may be
* interested only in only caps, and rig_open may fail.
*/
if (dump_caps_opt) {
if (dump_caps_opt)
{
dumpcaps_rot(my_rot, stdout);
rot_cleanup(my_rot); /* if you care about memory */
exit(0);
@ -322,12 +343,14 @@ int main(int argc, char *argv[])
retcode = rot_open(my_rot);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) {
if (verbose > 0)
{
printf("Opened rot model %d, '%s'\n",
my_rot->caps->rot_model,
my_rot->caps->model_name);
@ -339,19 +362,20 @@ int main(int argc, char *argv[])
rig_strstatus(my_rot->caps->status));
#ifdef __MINGW32__
# ifndef SO_OPENTYPE
# define SO_OPENTYPE 0x7008
# endif
# ifndef SO_SYNCHRONOUS_NONALERT
# define SO_SYNCHRONOUS_NONALERT 0x20
# endif
# ifndef INVALID_SOCKET
# define INVALID_SOCKET -1
# endif
# ifndef SO_OPENTYPE
# define SO_OPENTYPE 0x7008
# endif
# ifndef SO_SYNCHRONOUS_NONALERT
# define SO_SYNCHRONOUS_NONALERT 0x20
# endif
# ifndef INVALID_SOCKET
# define INVALID_SOCKET -1
# endif
WSADATA wsadata;
if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) {
if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR)
{
fprintf(stderr, "WSAStartup socket error\n");
exit(1);
}
@ -375,26 +399,30 @@ int main(int argc, char *argv[])
retcode = getaddrinfo(src_addr, portno, &hints, &result);
if (retcode != 0) {
if (retcode != 0)
{
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode));
exit(2);
}
saved_result = result;
do {
do
{
sock_listen = socket(result->ai_family,
result->ai_socktype,
result->ai_protocol);
if (sock_listen < 0) {
if (sock_listen < 0)
{
handle_error(RIG_DEBUG_ERR, "socket");
freeaddrinfo(result); /* No longer needed */
exit(1);
}
if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR,
(char *)&reuseaddr, sizeof(reuseaddr)) < 0) {
(char *)&reuseaddr, sizeof(reuseaddr)) < 0)
{
handle_error(RIG_DEBUG_ERR, "setsockopt");
freeaddrinfo(result); /* No longer needed */
@ -403,7 +431,8 @@ int main(int argc, char *argv[])
#ifdef IPV6_V6ONLY
if (AF_INET6 == result->ai_family) {
if (AF_INET6 == result->ai_family)
{
/* allow IPv4 mapped to IPv6 clients, MS & BSD default this
to 1 i.e. disallowed */
sockopt = 0;
@ -413,7 +442,8 @@ int main(int argc, char *argv[])
IPV6_V6ONLY,
(char *)&sockopt,
sizeof(sockopt))
< 0) {
< 0)
{
handle_error(RIG_DEBUG_ERR, "setsockopt");
freeaddrinfo(saved_result); /* No longer needed */
@ -423,7 +453,8 @@ int main(int argc, char *argv[])
#endif
if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) {
if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen))
{
break;
}
@ -433,16 +464,19 @@ int main(int argc, char *argv[])
#else
close(sock_listen);
#endif
} while ((result = result->ai_next) != NULL);
}
while ((result = result->ai_next) != NULL);
freeaddrinfo(saved_result); /* No longer needed */
if (NULL == result) {
if (NULL == result)
{
rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n");
exit(1);
}
if (listen(sock_listen, 4) < 0) {
if (listen(sock_listen, 4) < 0)
{
handle_error(RIG_DEBUG_ERR, "listening");
exit(1);
}
@ -457,25 +491,30 @@ int main(int argc, char *argv[])
act.sa_handler = SIG_IGN;
act.sa_flags = SA_RESTART;
if (sigaction(SIGPIPE, &act, NULL)) {
if (sigaction(SIGPIPE, &act, NULL))
{
handle_error(RIG_DEBUG_ERR, "sigaction");
}
#elif HAVE_SIGNAL
if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) {
if (SIG_ERR == signal(SIGPIPE, SIG_IGN))
{
handle_error(RIG_DEBUG_ERR, "signal");
}
#endif
#endif
/*
* main loop accepting connections
*/
do {
do
{
arg = malloc(sizeof(struct handle_data));
if (!arg) {
if (!arg)
{
rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno));
exit(1);
}
@ -486,7 +525,8 @@ int main(int argc, char *argv[])
(struct sockaddr *) &arg->cli_addr,
&arg->clilen);
if (arg->sock < 0) {
if (arg->sock < 0)
{
handle_error(RIG_DEBUG_ERR, "accept");
break;
}
@ -498,7 +538,8 @@ int main(int argc, char *argv[])
serv,
sizeof(serv),
NI_NOFQDN))
< 0) {
< 0)
{
rig_debug(RIG_DEBUG_WARN,
"Peer lookup error: %s",
@ -516,7 +557,8 @@ int main(int argc, char *argv[])
retcode = pthread_create(&thread, &attr, handle_socket, arg);
if (retcode != 0) {
if (retcode != 0)
{
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
break;
}
@ -524,7 +566,8 @@ int main(int argc, char *argv[])
#else
handle_socket(arg);
#endif
} while (retcode == 0);
}
while (retcode == 0);
rot_close(my_rot); /* close port */
rot_cleanup(my_rot); /* if you care about memory */
@ -552,7 +595,8 @@ void * handle_socket(void *arg)
#ifdef __MINGW32__
int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY);
if (sock_osfhandle == -1) {
if (sock_osfhandle == -1)
{
rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno));
goto handle_exit;
}
@ -562,7 +606,8 @@ void * handle_socket(void *arg)
fsockin = fdopen(handle_data_arg->sock, "rb");
#endif
if (!fsockin) {
if (!fsockin)
{
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
goto handle_exit;
}
@ -573,19 +618,23 @@ void * handle_socket(void *arg)
fsockout = fdopen(handle_data_arg->sock, "wb");
#endif
if (!fsockout) {
if (!fsockout)
{
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
fclose(fsockin);
goto handle_exit;
}
do {
do
{
retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0);
if (ferror(fsockin) || ferror(fsockout)) {
if (ferror(fsockin) || ferror(fsockout))
{
retcode = 1;
}
} while (retcode == 0 || retcode == 2);
}
while (retcode == 0 || retcode == 2);
if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr,
handle_data_arg->clilen,
@ -594,7 +643,8 @@ void * handle_socket(void *arg)
serv,
sizeof(serv),
NI_NOFQDN))
< 0) {
< 0)
{
rig_debug(RIG_DEBUG_WARN,
"Peer lookup error: %s",
@ -632,18 +682,18 @@ void usage()
"Daemon serving COMMANDs to a connected antenna rotator.\n\n");
printf(
" -m, --model=ID select rotator model number. See model list\n"
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -t, --port=NUM set TCP listening port, default %s\n"
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n"
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n",
" -m, --model=ID select rotator model number. See model list\n"
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -t, --port=NUM set TCP listening port, default %s\n"
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n"
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n",
portno);
usage_rot(stdout);

Wyświetl plik

@ -47,44 +47,52 @@ int sprintf_vfo(char *str, vfo_t vfo)
*str = '\0';
if (vfo == RIG_VFO_NONE) {
if (vfo == RIG_VFO_NONE)
{
return 0;
}
sv = rig_strvfo(vfo & RIG_VFO_CURR);
if (sv && sv[0]) {
if (sv && sv[0])
{
len += sprintf(str + len, "%s ", sv);
}
sv = rig_strvfo(vfo & RIG_VFO_MEM);
if (sv && sv[0]) {
if (sv && sv[0])
{
len += sprintf(str + len, "%s ", sv);
}
sv = rig_strvfo(vfo & RIG_VFO_VFO);
if (sv && sv[0]) {
if (sv && sv[0])
{
len += sprintf(str + len, "%s ", sv);
}
sv = rig_strvfo(vfo & RIG_VFO_MAIN);
if (sv && sv[0]) {
if (sv && sv[0])
{
len += sprintf(str + len, "%s ", sv);
}
sv = rig_strvfo(vfo & RIG_VFO_SUB);
if (sv && sv[0]) {
if (sv && sv[0])
{
len += sprintf(str + len, "%s ", sv);
}
for (i = 0; i < 16; i++) {
for (i = 0; i < 16; i++)
{
sv = rig_strvfo(vfo & RIG_VFO_N(i));
if (sv && sv[0]) {
if (sv && sv[0])
{
len += sprintf(str + len, "%s ", sv);
}
}
@ -99,14 +107,17 @@ int sprintf_mode(char *str, rmode_t mode)
*str = '\0';
if (mode == RIG_MODE_NONE) {
if (mode == RIG_MODE_NONE)
{
return 0;
}
for (i = 0; i < 30; i++) {
for (i = 0; i < 30; i++)
{
const char *ms = rig_strrmode(mode & (1UL << i));
if (!ms || !ms[0]) {
if (!ms || !ms[0])
{
continue; /* unknown, FIXME! */
}
@ -125,14 +136,17 @@ int sprintf_func(char *str, setting_t func)
*str = '\0';
if (func == RIG_FUNC_NONE) {
if (func == RIG_FUNC_NONE)
{
return 0;
}
for (i = 0; i < RIG_SETTING_MAX; i++) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms = rig_strfunc(func & rig_idx2setting(i));
if (!ms || !ms[0]) {
if (!ms || !ms[0])
{
continue; /* unknown, FIXME! */
}
@ -151,14 +165,17 @@ int sprintf_level(char *str, setting_t level)
*str = '\0';
if (level == RIG_LEVEL_NONE) {
if (level == RIG_LEVEL_NONE)
{
return 0;
}
for (i = 0; i < RIG_SETTING_MAX; i++) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms = rig_strlevel(level & rig_idx2setting(i));
if (!ms || !ms[0]) {
if (!ms || !ms[0])
{
continue; /* unknown, FIXME! */
}
@ -177,16 +194,20 @@ int sprintf_level_ext(char *str, const struct confparams *extlevels)
*str = '\0';
if (!extlevels) {
if (!extlevels)
{
return 0;
}
for (; extlevels->token != RIG_CONF_END; extlevels++) {
if (!extlevels->name) {
for (; extlevels->token != RIG_CONF_END; extlevels++)
{
if (!extlevels->name)
{
continue; /* no name */
}
switch (extlevels->type) {
switch (extlevels->type)
{
case RIG_CONF_CHECKBUTTON:
case RIG_CONF_COMBO:
case RIG_CONF_NUMERIC:
@ -212,35 +233,43 @@ int sprintf_level_gran(char *str, setting_t level, const gran_t gran[])
*str = '\0';
if (level == RIG_LEVEL_NONE) {
if (level == RIG_LEVEL_NONE)
{
return 0;
}
for (i = 0; i < RIG_SETTING_MAX; i++) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms;
if (!(level & rig_idx2setting(i))) {
if (!(level & rig_idx2setting(i)))
{
continue;
}
ms = rig_strlevel(level & rig_idx2setting(i));
if (!ms || !ms[0]) {
if (level != DUMMY_ALL && level != RIG_LEVEL_SET(DUMMY_ALL)) {
if (!ms || !ms[0])
{
if (level != DUMMY_ALL && level != RIG_LEVEL_SET(DUMMY_ALL))
{
rig_debug(RIG_DEBUG_BUG, "unknown level idx %d\n", i);
}
continue;
}
if (RIG_LEVEL_IS_FLOAT(rig_idx2setting(i))) {
if (RIG_LEVEL_IS_FLOAT(rig_idx2setting(i)))
{
len += sprintf(str + len,
"%s(%g..%g/%g) ",
ms,
gran[i].min.f,
gran[i].max.f,
gran[i].step.f);
} else {
}
else
{
len += sprintf(str + len,
"%s(%d..%d/%d) ",
ms,
@ -260,14 +289,17 @@ int sprintf_parm(char *str, setting_t parm)
*str = '\0';
if (parm == RIG_PARM_NONE) {
if (parm == RIG_PARM_NONE)
{
return 0;
}
for (i = 0; i < RIG_SETTING_MAX; i++) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms = rig_strparm(parm & rig_idx2setting(i));
if (!ms || !ms[0]) {
if (!ms || !ms[0])
{
continue; /* unknown, FIXME! */
}
@ -286,35 +318,43 @@ int sprintf_parm_gran(char *str, setting_t parm, const gran_t gran[])
*str = '\0';
if (parm == RIG_PARM_NONE) {
if (parm == RIG_PARM_NONE)
{
return 0;
}
for (i = 0; i < RIG_SETTING_MAX; i++) {
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms;
if (!(parm & rig_idx2setting(i))) {
if (!(parm & rig_idx2setting(i)))
{
continue;
}
ms = rig_strparm(parm & rig_idx2setting(i));
if (!ms || !ms[0]) {
if (parm != DUMMY_ALL && parm != RIG_PARM_SET(DUMMY_ALL)) {
if (!ms || !ms[0])
{
if (parm != DUMMY_ALL && parm != RIG_PARM_SET(DUMMY_ALL))
{
rig_debug(RIG_DEBUG_BUG, "unknown parm idx %d\n", i);
}
continue;
}
if (RIG_PARM_IS_FLOAT(rig_idx2setting(i))) {
if (RIG_PARM_IS_FLOAT(rig_idx2setting(i)))
{
len += sprintf(str + len,
"%s(%g..%g/%g) ",
ms,
gran[i].min.f,
gran[i].max.f,
gran[i].step.f);
} else {
}
else
{
len += sprintf(str + len,
"%s(%d..%d/%d) ",
ms,
@ -334,14 +374,17 @@ int sprintf_vfop(char *str, vfo_op_t op)
*str = '\0';
if (op == RIG_OP_NONE) {
if (op == RIG_OP_NONE)
{
return 0;
}
for (i = 0; i < 30; i++) {
for (i = 0; i < 30; i++)
{
const char *ms = rig_strvfop(op & (1UL << i));
if (!ms || !ms[0]) {
if (!ms || !ms[0])
{
continue; /* unknown, FIXME! */
}
@ -360,14 +403,17 @@ int sprintf_scan(char *str, scan_t rscan)
*str = '\0';
if (rscan == RIG_SCAN_NONE) {
if (rscan == RIG_SCAN_NONE)
{
return 0;
}
for (i = 0; i < 30; i++) {
for (i = 0; i < 30; i++)
{
const char *ms = rig_strscan(rscan & (1UL << i));
if (!ms || !ms[0]) {
if (!ms || !ms[0])
{
continue; /* unknown, FIXME! */
}

Wyświetl plik

@ -22,17 +22,20 @@ int main(int argc, char *argv[])
int digits = 10;
int i;
if (argc != 2 && argc != 3) {
if (argc != 2 && argc != 3)
{
fprintf(stderr, "Usage: %s <freq> [digits]\n", argv[0]);
exit(1);
}
f = (freq_t)atoll(argv[1]);
if (argc > 2) {
if (argc > 2)
{
digits = atoi(argv[2]);
if (digits > MAXDIGITS) {
if (digits > MAXDIGITS)
{
exit(1);
}
}
@ -42,7 +45,8 @@ int main(int argc, char *argv[])
to_bcd(b, f, digits);
printf("BCD: %2.2x", b[0]);
for (i = 1; i < (digits + 1) / 2; i++) {
for (i = 1; i < (digits + 1) / 2; i++)
{
printf(",%2.2x", b[i]);
}
@ -53,7 +57,8 @@ int main(int argc, char *argv[])
to_bcd_be(b, f, digits);
printf("BCD: %2.2x", b[0]);
for (i = 1; i < (digits + 1) / 2; i++) {
for (i = 1; i < (digits + 1) / 2; i++)
{
printf(",%2.2x", b[i]);
}

Wyświetl plik

@ -20,7 +20,8 @@ int main(int argc, char *argv[])
#if 0
if (argc != 2) {
if (argc != 2)
{
fprintf(stderr, "Usage: %s <freq>\n", argv[0]);
exit(1);
}

Wyświetl plik

@ -24,7 +24,8 @@ int main(int argc, char *argv[])
double distance, az, mmm, sec;
int deg, min, retcode, loc_len, nesw = 0;
if (argc < 2) {
if (argc < 2)
{
fprintf(stderr,
"Usage: %s <locator1> <precision> [<locator2>]\n",
argv[0]);
@ -40,7 +41,8 @@ int main(int argc, char *argv[])
/* hamlib function to convert maidenhead to decimal degrees */
retcode = locator2longlat(&lon1, &lat1, loc1);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "locator2longlat() failed with malformed input.\n");
exit(2);
}
@ -48,14 +50,18 @@ int main(int argc, char *argv[])
/* hamlib function to convert decimal degrees to deg, min, sec */
retcode = dec2dms(lon1, &deg, &min, &sec, &nesw);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
if (nesw == 1)
{
sign = '-';
} else {
}
else
{
sign = '\0';
}
@ -68,14 +74,18 @@ int main(int argc, char *argv[])
/* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dmmm(lon1, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
if (nesw == 1)
{
sign = '-';
} else {
}
else
{
sign = '\0';
}
@ -88,14 +98,18 @@ int main(int argc, char *argv[])
/* hamlib function to convert decimal degrees to deg, min, sec */
retcode = dec2dms(lat1, &deg, &min, &sec, &nesw);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
if (nesw == 1)
{
sign = '-';
} else {
}
else
{
sign = '\0';
}
@ -108,14 +122,18 @@ int main(int argc, char *argv[])
/* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dmmm(lat1, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
if (nesw == 1)
{
sign = '-';
} else {
}
else
{
sign = '\0';
}
@ -128,14 +146,16 @@ int main(int argc, char *argv[])
/* hamlib function to convert decimal degrees to maidenhead */
retcode = longlat2locator(lon1, lat1, recodedloc, loc_len);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
exit(2);
}
printf(" Recoded:\t%s\n", recodedloc);
if (loc2 == NULL) {
if (loc2 == NULL)
{
exit(0);
}
@ -144,7 +164,8 @@ int main(int argc, char *argv[])
retcode = locator2longlat(&lon2, &lat2, loc2);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "locator2longlat() failed with malformed input.\n");
exit(2);
}
@ -152,14 +173,18 @@ int main(int argc, char *argv[])
/* hamlib function to convert decimal degrees to deg, min, sec */
retcode = dec2dms(lon2, &deg, &min, &sec, &nesw);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
if (nesw == 1)
{
sign = '-';
} else {
}
else
{
sign = '\0';
}
@ -172,14 +197,18 @@ int main(int argc, char *argv[])
/* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dmmm(lon2, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
if (nesw == 1)
{
sign = '-';
} else {
}
else
{
sign = '\0';
}
@ -192,14 +221,18 @@ int main(int argc, char *argv[])
/* hamlib function to convert decimal degrees to deg, min, sec */
retcode = dec2dms(lat2, &deg, &min, &sec, &nesw);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
if (nesw == 1)
{
sign = '-';
} else {
}
else
{
sign = '\0';
}
@ -212,14 +245,18 @@ int main(int argc, char *argv[])
/* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dmmm(lat2, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
if (nesw == 1)
{
sign = '-';
} else {
}
else
{
sign = '\0';
}
@ -232,7 +269,8 @@ int main(int argc, char *argv[])
/* hamlib function to convert decimal degrees to maidenhead */
retcode = longlat2locator(lon2, lat2, recodedloc, loc_len);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
exit(2);
}
@ -241,7 +279,8 @@ int main(int argc, char *argv[])
retcode = qrb(lon1, lat1, lon2, lat2, &distance, &az);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
fprintf(stderr, "QRB error: %d\n", retcode);
exit(2);
}
@ -249,9 +288,12 @@ int main(int argc, char *argv[])
dec2dms(az, &deg, &min, &sec, &nesw);
printf("\nDistance: %.6fkm\n", distance);
if (nesw == 1) {
if (nesw == 1)
{
sign = '-';
} else {
}
else
{
sign = '\0';
}

Wyświetl plik

@ -57,7 +57,8 @@ int main(int argc, char *argv[])
* allocate memory, setup & open port
*/
if (argc < 2) {
if (argc < 2)
{
hamlib_port_t myport;
/* may be overriden by backend probe */
myport.type.rig = RIG_PORT_SERIAL;
@ -70,13 +71,16 @@ int main(int argc, char *argv[])
rig_load_all_backends();
myrig_model = rig_probe(&myport);
} else {
}
else
{
myrig_model = atoi(argv[1]);
}
my_rig = rig_init(myrig_model);
if (!my_rig) {
if (!my_rig)
{
fprintf(stderr, "Unknown rig num: %d\n", myrig_model);
fprintf(stderr, "Please check riglist.h\n");
exit(1); /* whoops! something went wrong (mem alloc?) */
@ -86,7 +90,8 @@ int main(int argc, char *argv[])
retcode = rig_open(my_rig);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_open: error = %s\n", rigerror(retcode));
exit(2);
}
@ -107,7 +112,8 @@ int main(int argc, char *argv[])
retcode = rig_set_vfo(my_rig, RIG_VFO_B);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_vfo: error = %s \n", rigerror(retcode));
}
@ -126,7 +132,8 @@ int main(int argc, char *argv[])
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM,
rig_passband_narrow(my_rig, RIG_MODE_FM));
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
@ -150,7 +157,8 @@ int main(int argc, char *argv[])
RIG_MODE_USB,
rig_passband_normal(my_rig, RIG_MODE_USB));
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
@ -171,7 +179,8 @@ int main(int argc, char *argv[])
RIG_MODE_LSB,
RIG_PASSBAND_NORMAL);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
@ -179,7 +188,9 @@ int main(int argc, char *argv[])
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000000, rig_strrmode(rmode), width / 1000.0);
freq / 1000000,
rig_strrmode(rmode),
width / 1000.0);
sleep(1);
/* 80m AM Narrow */
@ -192,7 +203,8 @@ int main(int argc, char *argv[])
RIG_MODE_AM,
rig_passband_narrow(my_rig, RIG_MODE_AM));
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
@ -201,7 +213,8 @@ int main(int argc, char *argv[])
printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000000,
rig_strrmode(rmode), width / 1000.0);
rig_strrmode(rmode),
width / 1000.0);
sleep(1);
@ -215,7 +228,8 @@ int main(int argc, char *argv[])
RIG_MODE_CW,
RIG_PASSBAND_NORMAL);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
@ -224,7 +238,8 @@ int main(int argc, char *argv[])
printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
freq / 1000,
rig_strrmode(rmode), width);
rig_strrmode(rmode),
width);
sleep(1);
@ -237,7 +252,8 @@ int main(int argc, char *argv[])
RIG_MODE_CW,
rig_passband_narrow(my_rig, RIG_MODE_CW));
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
@ -246,7 +262,8 @@ int main(int argc, char *argv[])
printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
freq / 1000,
rig_strrmode(rmode), width);
rig_strrmode(rmode),
width);
sleep(1);
@ -260,7 +277,8 @@ int main(int argc, char *argv[])
RIG_MODE_AM,
RIG_PASSBAND_NORMAL);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
@ -269,7 +287,8 @@ int main(int argc, char *argv[])
printf(" Freq: %.3f kHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000,
rig_strrmode(rmode), width / 1000.0);
rig_strrmode(rmode),
width / 1000.0);
sleep(1);
@ -280,7 +299,8 @@ int main(int argc, char *argv[])
retcode = rig_set_vfo(my_rig, RIG_VFO_A);
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 14250375); /* cq de vk3fcs */
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
@ -296,7 +316,8 @@ int main(int argc, char *argv[])
printf("Setting 20m on VFO A with one function...\n");
retcode = rig_set_freq(my_rig, RIG_VFO_A, 14295125); /* cq de vk3fcs */
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
@ -321,7 +342,8 @@ int main(int argc, char *argv[])
RIG_MODE_LSB,
RIG_PASSBAND_NORMAL);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_mode: error = %s \n", rigerror(retcode));
}
@ -330,7 +352,8 @@ int main(int argc, char *argv[])
printf("Setting rig PTT ON.\n");
retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_ON); /* stand back ! */
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_ptt: error = %s \n", rigerror(retcode));
}
@ -339,7 +362,8 @@ int main(int argc, char *argv[])
printf("Setting rig PTT OFF.\n");
retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_OFF); /* phew ! */
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_ptt: error = %s \n", rigerror(retcode));
}
@ -353,52 +377,68 @@ int main(int argc, char *argv[])
printf("\nGet various raw rig values:\n");
retcode = rig_get_vfo(my_rig, &vfo); /* try to get vfo info */
if (retcode == RIG_OK) {
if (retcode == RIG_OK)
{
printf("rig_get_vfo: vfo = %i \n", vfo);
} else {
}
else
{
printf("rig_get_vfo: error = %s \n", rigerror(retcode));
}
retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
if (retcode == RIG_OK) {
if (retcode == RIG_OK)
{
printf("rig_get_freq: freq = %"PRIfreq"\n", freq);
} else {
}
else
{
printf("rig_get_freq: error = %s \n", rigerror(retcode));
}
retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
if (retcode == RIG_OK) {
if (retcode == RIG_OK)
{
printf("rig_get_mode: mode = %i \n", rmode);
} else {
}
else
{
printf("rig_get_mode: error = %s \n", rigerror(retcode));
}
retcode = rig_get_strength(my_rig, RIG_VFO_CURR, &strength);
if (retcode == RIG_OK) {
if (retcode == RIG_OK)
{
printf("rig_get_strength: strength = %i \n", strength);
} else {
}
else
{
printf("rig_get_strength: error = %s \n", rigerror(retcode));
}
if (rig_has_set_func(my_rig, RIG_FUNC_RIT)) {
if (rig_has_set_func(my_rig, RIG_FUNC_RIT))
{
retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, 1);
printf("rig_set_func: Setting RIT ON\n");
}
if (rig_has_get_func(my_rig, RIG_FUNC_RIT)) {
if (rig_has_get_func(my_rig, RIG_FUNC_RIT))
{
retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, &rit);
printf("rig_get_func: RIT: %d\n", rit);
}
if (rig_has_set_func(my_rig, RIG_FUNC_XIT)) {
if (rig_has_set_func(my_rig, RIG_FUNC_XIT))
{
retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, 1);
printf("rig_set_func: Setting XIT ON\n");
}
if (rig_has_get_func(my_rig, RIG_FUNC_XIT)) {
if (rig_has_get_func(my_rig, RIG_FUNC_XIT))
{
retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, &xit);
printf("rig_get_func: XIT: %d\n", xit);
}

Wyświetl plik

@ -50,12 +50,13 @@ int main(int argc, char *argv[])
int retcode; /* generic return code from functions */
int i, count = 0;
if (argc != 2) {
if (argc != 2)
{
fprintf(stderr, "%s <rig_num>\n", argv[0]);
exit(1);
}
printf("testrig:hello, I am your main() !\n");
printf("testrig: Hello, I am your main() !\n");
/*
* allocate memory, setup & open port
@ -63,7 +64,8 @@ int main(int argc, char *argv[])
my_rig = rig_init(atoi(argv[1]));
if (!my_rig) {
if (!my_rig)
{
fprintf(stderr, "Unknown rig num: %d\n", atoi(argv[1]));
fprintf(stderr, "Please check riglist.h\n");
exit(1); /* whoops! something went wrong (mem alloc?) */
@ -71,7 +73,8 @@ int main(int argc, char *argv[])
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
if (rig_open(my_rig)) {
if (rig_open(my_rig))
{
exit(2);
}
@ -85,7 +88,8 @@ int main(int argc, char *argv[])
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 439700000);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
@ -93,12 +97,14 @@ int main(int argc, char *argv[])
retcode = rig_set_trn(my_rig, RIG_TRN_RIG);
if (retcode != RIG_OK) {
if (retcode != RIG_OK)
{
printf("rig_set_trn: error = %s \n", rigerror(retcode));
}
for (i = 0; i < 12; i++) {
for (i = 0; i < 12; i++)
{
printf("Loop count: %d\n", i);
sleep(10); /* or anything smarter */
}