Apply formatting to 'tests/' directory

Format per style guide.
pull/1/head
Nate Bargmann 2017-08-09 13:09:55 -05:00
rodzic 80a4097aba
commit d489b8bcb5
27 zmienionych plików z 10516 dodań i 7919 usunięć

Plik diff jest za duży Load Diff

Wyświetl plik

@ -20,7 +20,7 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -37,113 +37,141 @@
/* /*
* the rot may be in rot_init state, but not openned * the rot may be in rot_init state, but not openned
*/ */
int dumpcaps_rot (ROT* rot, FILE *fout) int dumpcaps_rot(ROT *rot, FILE *fout)
{ {
const struct rot_caps *caps; const struct rot_caps *caps;
int backend_warnings = 0; int backend_warnings = 0;
if (!rot || !rot->caps) if (!rot || !rot->caps) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rot->caps; caps = rot->caps;
fprintf(fout, "Caps dump for model:\t%d\n", caps->rot_model); fprintf(fout, "Caps dump for model:\t%d\n", caps->rot_model);
fprintf(fout, "Model name:\t\t%s\n", caps->model_name); fprintf(fout, "Model name:\t\t%s\n", caps->model_name);
fprintf(fout, "Mfg name:\t\t%s\n", caps->mfg_name); fprintf(fout, "Mfg name:\t\t%s\n", caps->mfg_name);
fprintf(fout, "Backend version:\t%s\n", caps->version); fprintf(fout, "Backend version:\t%s\n", caps->version);
fprintf(fout, "Backend copyright:\t%s\n", caps->copyright); fprintf(fout, "Backend copyright:\t%s\n", caps->copyright);
fprintf(fout, "Backend status:\t\t%s\n", rig_strstatus(caps->status)); fprintf(fout, "Backend status:\t\t%s\n", rig_strstatus(caps->status));
fprintf(fout, "Rot type:\t\t"); fprintf(fout, "Rot type:\t\t");
switch (caps->rot_type & ROT_TYPE_MASK) {
case ROT_TYPE_OTHER:
fprintf(fout, "Other\n");
break;
case ROT_TYPE_AZIMUTH:
fprintf(fout, "Azimuth\n");
break;
case ROT_TYPE_ELEVATION:
fprintf(fout, "Elevation\n");
break;
case ROT_TYPE_AZEL:
fprintf(fout, "Az-El\n");
break;
default:
fprintf(fout, "Unknown\n");
backend_warnings++;
}
fprintf(fout, "Port type:\t\t"); switch (caps->rot_type & ROT_TYPE_MASK) {
switch (caps->port_type) { case ROT_TYPE_OTHER:
case RIG_PORT_SERIAL: fprintf(fout, "Other\n");
fprintf(fout, "RS-232\n"); break;
fprintf(fout, "Serial speed:\t\t%d..%d bauds, %d%c%d%s\n", 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_stop_bits,
caps->serial_handshake == RIG_HANDSHAKE_NONE ? "" :
(caps->serial_handshake == RIG_HANDSHAKE_XONXOFF ? " XONXOFF" : " CTS/RTS")
);
break;
case RIG_PORT_PARALLEL:
fprintf(fout, "Parallel\n");
break;
case RIG_PORT_DEVICE:
fprintf(fout, "Device driver\n");
break;
case RIG_PORT_USB:
fprintf(fout, "USB\n");
break;
case RIG_PORT_NETWORK:
fprintf(fout, "Network link\n");
break;
case RIG_PORT_UDP_NETWORK:
fprintf(fout, "UDP Network link\n");
break;
case RIG_PORT_NONE:
fprintf(fout, "None\n");
break;
default:
fprintf(fout, "Unknown\n");
backend_warnings++;
}
fprintf(fout, "Write delay:\t\t%dmS, timeout %dmS, %d retr%s\n", case ROT_TYPE_AZIMUTH:
caps->write_delay, caps->timeout, caps->retry, (caps->retry == 1) ? "y" : "ies"); fprintf(fout, "Azimuth\n");
fprintf(fout, "Post Write delay:\t%dmS\n", break;
caps->post_write_delay);
fprintf(fout, "Min Azimuth:\t\t%.2f\n", caps->min_az); case ROT_TYPE_ELEVATION:
fprintf(fout, "Max Azimuth:\t\t%.2f\n", caps->max_az); fprintf(fout, "Elevation\n");
break;
fprintf(fout, "Min Elevation:\t\t%.2f\n", caps->min_el); case ROT_TYPE_AZEL:
fprintf(fout, "Max Elevation:\t\t%.2f\n", caps->max_el); fprintf(fout, "Az-El\n");
break;
fprintf(fout, "Has priv data:\t\t%c\n", caps->priv != NULL ? 'Y' : 'N'); default:
fprintf(fout, "Unknown\n");
backend_warnings++;
}
/* fprintf(fout, "Port type:\t\t");
* Status is either 'Y'es, 'E'mulated, 'N'o
*
* TODO: keep me up-to-date with API call list!
*/
fprintf(fout, "Has Init:\t\t%c\n", caps->rot_init != NULL ? 'Y' : 'N');
fprintf(fout, "Has Cleanup:\t\t%c\n", caps->rot_cleanup != NULL ? 'Y' : 'N');
fprintf(fout, "Has Open:\t\t%c\n", caps->rot_open != NULL ? 'Y' : 'N');
fprintf(fout, "Has Close:\t\t%c\n", caps->rot_close != NULL ? 'Y' : 'N');
fprintf(fout, "Can set Conf:\t\t%c\n", caps->set_conf != NULL ? 'Y' : 'N');
fprintf(fout, "Can get Conf:\t\t%c\n", caps->get_conf != NULL ? 'Y' : 'N');
fprintf(fout, "Can set Position:\t%c\n", caps->set_position != NULL ? 'Y' : 'N');
fprintf(fout, "Can get Position:\t%c\n", caps->get_position != NULL ? 'Y' : 'N');
fprintf(fout, "Can Stop:\t\t%c\n", caps->stop != NULL ? 'Y' : 'N');
fprintf(fout, "Can Park:\t\t%c\n", caps->park != NULL ? 'Y' : 'N');
fprintf(fout, "Can Reset:\t\t%c\n", caps->reset != NULL ? 'Y' : 'N');
fprintf(fout, "Can Move:\t\t%c\n", caps->move != NULL ? 'Y' : 'N');
fprintf(fout, "Can get Info:\t\t%c\n", caps->get_info != NULL ? 'Y' : 'N');
fprintf(fout, "\nOverall backend warnings: %d\n", backend_warnings); switch (caps->port_type) {
case RIG_PORT_SERIAL:
fprintf(fout, "RS-232\n");
fprintf(fout,
"Serial speed:\t\t%d..%d bauds, %d%c%d%s\n",
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_stop_bits,
caps->serial_handshake == RIG_HANDSHAKE_NONE ? "" :
(caps->serial_handshake == RIG_HANDSHAKE_XONXOFF ? " XONXOFF" : " CTS/RTS")
);
break;
return backend_warnings; case RIG_PORT_PARALLEL:
fprintf(fout, "Parallel\n");
break;
case RIG_PORT_DEVICE:
fprintf(fout, "Device driver\n");
break;
case RIG_PORT_USB:
fprintf(fout, "USB\n");
break;
case RIG_PORT_NETWORK:
fprintf(fout, "Network link\n");
break;
case RIG_PORT_UDP_NETWORK:
fprintf(fout, "UDP Network link\n");
break;
case RIG_PORT_NONE:
fprintf(fout, "None\n");
break;
default:
fprintf(fout, "Unknown\n");
backend_warnings++;
}
fprintf(fout,
"Write delay:\t\t%dmS, timeout %dmS, %d retr%s\n",
caps->write_delay,
caps->timeout, caps->retry,
(caps->retry == 1) ? "y" : "ies");
fprintf(fout,
"Post Write delay:\t%dmS\n",
caps->post_write_delay);
fprintf(fout, "Min Azimuth:\t\t%.2f\n", caps->min_az);
fprintf(fout, "Max Azimuth:\t\t%.2f\n", caps->max_az);
fprintf(fout, "Min Elevation:\t\t%.2f\n", caps->min_el);
fprintf(fout, "Max Elevation:\t\t%.2f\n", caps->max_el);
fprintf(fout, "Has priv data:\t\t%c\n", caps->priv != NULL ? 'Y' : 'N');
/*
* Status is either 'Y'es, 'E'mulated, 'N'o
*
* TODO: keep me up-to-date with API call list!
*/
fprintf(fout, "Has Init:\t\t%c\n", caps->rot_init != NULL ? 'Y' : 'N');
fprintf(fout, "Has Cleanup:\t\t%c\n", caps->rot_cleanup != NULL ? 'Y' : 'N');
fprintf(fout, "Has Open:\t\t%c\n", caps->rot_open != NULL ? 'Y' : 'N');
fprintf(fout, "Has Close:\t\t%c\n", caps->rot_close != NULL ? 'Y' : 'N');
fprintf(fout, "Can set Conf:\t\t%c\n", caps->set_conf != NULL ? 'Y' : 'N');
fprintf(fout, "Can get Conf:\t\t%c\n", caps->get_conf != NULL ? 'Y' : 'N');
fprintf(fout,
"Can set Position:\t%c\n",
caps->set_position != NULL ? 'Y' : 'N');
fprintf(fout,
"Can get Position:\t%c\n",
caps->get_position != NULL ? 'Y' : 'N');
fprintf(fout, "Can Stop:\t\t%c\n", caps->stop != NULL ? 'Y' : 'N');
fprintf(fout, "Can Park:\t\t%c\n", caps->park != NULL ? 'Y' : 'N');
fprintf(fout, "Can Reset:\t\t%c\n", caps->reset != NULL ? 'Y' : 'N');
fprintf(fout, "Can Move:\t\t%c\n", caps->move != NULL ? 'Y' : 'N');
fprintf(fout, "Can get Info:\t\t%c\n", caps->get_info != NULL ? 'Y' : 'N');
fprintf(fout, "\nOverall backend warnings: %d\n", backend_warnings);
return backend_warnings;
} }

Wyświetl plik

@ -27,211 +27,324 @@
#include <hamlib/rig.h> #include <hamlib/rig.h>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
#include "misc.h" #include "misc.h"
#define SERIAL_PORT "/dev/ttyS0" #define SERIAL_PORT "/dev/ttyS0"
static char *decode_modes(rmode_t modes);
static char * decode_modes(rmode_t modes);
static int dump_chan(RIG *rig, int chan_num); static int dump_chan(RIG *rig, int chan_num);
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{ {
RIG *my_rig; RIG *my_rig;
int status,i,j; int status, i, j;
if (argc != 2) { if (argc != 2) {
fprintf(stderr,"%s <rig_num>\n",argv[0]); fprintf(stderr, "%s <rig_num>\n", argv[0]);
exit(1); exit(1);
} }
my_rig = rig_init(atoi(argv[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, "Unknown rig num: %d\n", atoi(argv[1]));
fprintf(stderr,"Please check riglist.h\n"); fprintf(stderr, "Please check riglist.h\n");
exit(1); /* whoops! something went wrong (mem alloc?) */ exit(1); /* whoops! something went wrong (mem alloc?) */
} }
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1); strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
if (rig_open(my_rig)) if (rig_open(my_rig)) {
exit(2); exit(2);
}
status = rig_set_vfo(my_rig, RIG_VFO_B); 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)); printf("rig_set_vfo: error = %s \n", rigerror(status));
} }
/* /*
* chan_t is used to describe what memory your rig is equipped with * chan_t is used to describe what memory your rig is equipped with
* cf. chan_list field in caps * cf. chan_list field in caps
* Example for the Ic706MkIIG (99 memory channels, 2 scan edges, 2 call chans): * Example for the Ic706MkIIG (99 memory channels, 2 scan edges, 2 call chans):
* chan_t chan_list[] = { * chan_t chan_list[] = {
* { 1, 99, RIG_MTYPE_MEM, 0 }, * { 1, 99, RIG_MTYPE_MEM, 0 },
* { 100, 103, RIG_MTYPE_EDGE, 0 }, * { 100, 103, RIG_MTYPE_EDGE, 0 },
* { 104, 105, RIG_MTYPE_CALL, 0 }, * { 104, 105, RIG_MTYPE_CALL, 0 },
* RIG_CHAN_END * RIG_CHAN_END
* } * }
*/ */
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; 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); dump_chan(my_rig, j);
} }
} }
rig_close(my_rig); /* close port */ rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */ rig_cleanup(my_rig); /* if you care about memory */
printf("port %s closed ok \n",SERIAL_PORT); printf("port %s closed ok \n", SERIAL_PORT);
return 0; return 0;
} }
/* /*
* NB: this function is not reentrant, because of the static buf. * NB: this function is not reentrant, because of the static buf.
* but who cares? --SF * but who cares? --SF
*/ */
static char *decode_modes(rmode_t modes) static char * decode_modes(rmode_t modes)
{ {
static char buf[80]; static char buf[80];
buf[0] = '\0';
if (modes & RIG_MODE_AM) {
strcat(buf, "AM ");
}
if (modes & RIG_MODE_CW) {
strcat(buf, "CW ");
}
if (modes & RIG_MODE_USB) {
strcat(buf, "USB ");
}
if (modes & RIG_MODE_LSB) {
strcat(buf, "LSB ");
}
if (modes & RIG_MODE_RTTY) {
strcat(buf, "RTTY ");
}
if (modes & RIG_MODE_FM) {
strcat(buf, "FM ");
}
buf[0] = '\0';
if (modes&RIG_MODE_AM) strcat(buf,"AM ");
if (modes&RIG_MODE_CW) strcat(buf,"CW ");
if (modes&RIG_MODE_USB) strcat(buf,"USB ");
if (modes&RIG_MODE_LSB) strcat(buf,"LSB ");
if (modes&RIG_MODE_RTTY) strcat(buf,"RTTY ");
if (modes&RIG_MODE_FM) strcat(buf,"FM ");
#ifdef RIG_MODE_WFM #ifdef RIG_MODE_WFM
if (modes&RIG_MODE_WFM) strcat(buf,"WFM ");
if (modes & RIG_MODE_WFM) {
strcat(buf, "WFM ");
}
#endif #endif
return buf; return buf;
} }
int dump_chan(RIG *rig, int chan_num) int dump_chan(RIG *rig, int chan_num)
{ {
channel_t chan; channel_t chan;
int status; int status;
char freqbuf[20]; char freqbuf[20];
chan.vfo = RIG_VFO_MEM; chan.vfo = RIG_VFO_MEM;
chan.channel_num = chan_num; chan.channel_num = chan_num;
status=rig_get_channel(rig, &chan); status = rig_get_channel(rig, &chan);
if (status != RIG_OK ) { if (status != RIG_OK) {
printf("rig_get_channel: error = %s \n", rigerror(status)); printf("rig_get_channel: error = %s \n", rigerror(status));
return status; return status;
} }
printf("Channel: %d\n", chan.channel_num); printf("Channel: %d\n", chan.channel_num);
sprintf_freq(freqbuf,chan.freq); sprintf_freq(freqbuf, chan.freq);
printf("Frequency: %s\n", freqbuf); printf("Frequency: %s\n", freqbuf);
printf("Mode: %s\n", decode_modes(chan.mode)); printf("Mode: %s\n", decode_modes(chan.mode));
sprintf_freq(freqbuf,chan.width); sprintf_freq(freqbuf, chan.width);
printf("Width: %s\n", freqbuf); printf("Width: %s\n", freqbuf);
printf("VFO: %d\n", chan.vfo); printf("VFO: %d\n", chan.vfo);
printf("Split: %d\n", chan.split); printf("Split: %d\n", chan.split);
sprintf_freq(freqbuf,chan.tx_freq); sprintf_freq(freqbuf, chan.tx_freq);
printf("TXFrequency: %s\n", freqbuf); printf("TXFrequency: %s\n", freqbuf);
printf("TXMode: %s\n", decode_modes(chan.tx_mode)); printf("TXMode: %s\n", decode_modes(chan.tx_mode));
sprintf_freq(freqbuf,chan.tx_width); sprintf_freq(freqbuf, chan.tx_width);
printf("TXWidth: %s\n", freqbuf); printf("TXWidth: %s\n", freqbuf);
printf("Shift: %s\n", rig_strptrshift(chan.rptr_shift)); printf("Shift: %s\n", rig_strptrshift(chan.rptr_shift));
sprintf_freq(freqbuf,chan.rptr_offs); sprintf_freq(freqbuf, chan.rptr_offs);
printf("Offset: %s%s\n", chan.rptr_offs>0?"+":"", freqbuf); printf("Offset: %s%s\n", chan.rptr_offs > 0 ? "+" : "", freqbuf);
printf("Antenna: %d\n", chan.ant); printf("Antenna: %d\n", chan.ant);
sprintf_freq(freqbuf,chan.tuning_step); sprintf_freq(freqbuf, chan.tuning_step);
printf("Step: %s\n", freqbuf); printf("Step: %s\n", freqbuf);
sprintf_freq(freqbuf,chan.rit); sprintf_freq(freqbuf, chan.rit);
printf("RIT: %s%s\n", chan.rit>0?"+":"", freqbuf); printf("RIT: %s%s\n", chan.rit > 0 ? "+" : "", freqbuf);
sprintf_freq(freqbuf,chan.xit); sprintf_freq(freqbuf, chan.xit);
printf("XIT: %s%s\n", chan.xit>0?"+":"", freqbuf); printf("XIT: %s%s\n", chan.xit > 0 ? "+" : "", freqbuf);
printf("CTCSS: %d.%dHz\n", chan.ctcss_tone/10, chan.ctcss_tone%10); printf("CTCSS: %d.%dHz\n", chan.ctcss_tone / 10, chan.ctcss_tone % 10);
printf("CTCSSsql: %d.%dHz\n", chan.ctcss_sql/10, chan.ctcss_sql%10); printf("CTCSSsql: %d.%dHz\n", chan.ctcss_sql / 10, chan.ctcss_sql % 10);
printf("DCS: %d.%d\n", chan.dcs_code/10, chan.dcs_code%10); printf("DCS: %d.%d\n", chan.dcs_code / 10, chan.dcs_code % 10);
printf("DCSsql: %d.%d\n", chan.dcs_sql/10, chan.dcs_sql%10); printf("DCSsql: %d.%d\n", chan.dcs_sql / 10, chan.dcs_sql % 10);
printf("Name: %s\n", chan.channel_desc); printf("Name: %s\n", chan.channel_desc);
printf("Functions: "); printf("Functions: ");
if (chan.funcs!=0) {
if (chan.funcs&RIG_FUNC_FAGC) printf("FAGC ");
if (chan.funcs&RIG_FUNC_NB) printf("NB ");
if (chan.funcs&RIG_FUNC_COMP) printf("COMP ");
if (chan.funcs&RIG_FUNC_VOX) printf("VOX ");
if (chan.funcs&RIG_FUNC_TONE) printf("TONE ");
if (chan.funcs&RIG_FUNC_TSQL) printf("TSQL ");
if (chan.funcs&RIG_FUNC_SBKIN) printf("SBKIN ");
if (chan.funcs&RIG_FUNC_FBKIN) printf("FBKIN ");
if (chan.funcs&RIG_FUNC_ANF) printf("ANF ");
if (chan.funcs&RIG_FUNC_NR) printf("NR ");
if (chan.funcs&RIG_FUNC_AIP) printf("AIP ");
if (chan.funcs&RIG_FUNC_APF) printf("APF ");
if (chan.funcs&RIG_FUNC_MON) printf("MON ");
if (chan.funcs&RIG_FUNC_MN) printf("MN ");
if (chan.funcs&RIG_FUNC_RF) printf("RF ");
printf("\n");
} else
printf("none\n");
if (rig_has_set_level(rig, RIG_LEVEL_PREAMP)) if (chan.funcs != 0) {
printf("PREAMP: %ddB\n",chan.levels[rig_setting2idx(RIG_LEVEL_PREAMP)].i); if (chan.funcs & RIG_FUNC_FAGC) {
if (rig_has_set_level(rig, RIG_LEVEL_ATT)) printf("FAGC ");
printf("ATT: %ddB\n",chan.levels[rig_setting2idx(RIG_LEVEL_ATT)].i); }
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))
printf("RF: %g%%\n",100*chan.levels[rig_setting2idx(RIG_LEVEL_RF)].f);
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))
printf("IF: %dHz\n",chan.levels[rig_setting2idx(RIG_LEVEL_IF)].i);
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))
printf("NR: %g%%\n",100*chan.levels[rig_setting2idx(RIG_LEVEL_NR)].f);
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))
printf("PBT_OUT: %g%%\n",100*chan.levels[rig_setting2idx(RIG_LEVEL_PBT_OUT)].f);
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))
printf("RFPOWER: %g%%\n",100*chan.levels[rig_setting2idx(RIG_LEVEL_RFPOWER)].f);
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))
printf("COMP: %g%%\n",100*chan.levels[rig_setting2idx(RIG_LEVEL_COMP)].f);
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))
printf("KEYSPD: %d\n",chan.levels[rig_setting2idx(RIG_LEVEL_KEYSPD)].i);
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))
printf("AGC: %d\n",chan.levels[rig_setting2idx(RIG_LEVEL_AGC)].i);
if (rig_has_set_level(rig, RIG_LEVEL_BKINDL))
printf("BKINDL: %d\n",chan.levels[rig_setting2idx(RIG_LEVEL_BKINDL)].i);
return 0; if (chan.funcs & RIG_FUNC_NB) {
printf("NB ");
}
if (chan.funcs & RIG_FUNC_COMP) {
printf("COMP ");
}
if (chan.funcs & RIG_FUNC_VOX) {
printf("VOX ");
}
if (chan.funcs & RIG_FUNC_TONE) {
printf("TONE ");
}
if (chan.funcs & RIG_FUNC_TSQL) {
printf("TSQL ");
}
if (chan.funcs & RIG_FUNC_SBKIN) {
printf("SBKIN ");
}
if (chan.funcs & RIG_FUNC_FBKIN) {
printf("FBKIN ");
}
if (chan.funcs & RIG_FUNC_ANF) {
printf("ANF ");
}
if (chan.funcs & RIG_FUNC_NR) {
printf("NR ");
}
if (chan.funcs & RIG_FUNC_AIP) {
printf("AIP ");
}
if (chan.funcs & RIG_FUNC_APF) {
printf("APF ");
}
if (chan.funcs & RIG_FUNC_MON) {
printf("MON ");
}
if (chan.funcs & RIG_FUNC_MN) {
printf("MN ");
}
if (chan.funcs & RIG_FUNC_RF) {
printf("RF ");
}
printf("\n");
} else {
printf("none\n");
}
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)) {
printf("ATT: %ddB\n", chan.levels[rig_setting2idx(RIG_LEVEL_ATT)].i);
}
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)) {
printf("RF: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_RF)].f);
}
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)) {
printf("IF: %dHz\n", chan.levels[rig_setting2idx(RIG_LEVEL_IF)].i);
}
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)) {
printf("NR: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_NR)].f);
}
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)) {
printf("PBT_OUT: %g%%\n",
100 * chan.levels[rig_setting2idx(RIG_LEVEL_PBT_OUT)].f);
}
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)) {
printf("RFPOWER: %g%%\n",
100 * chan.levels[rig_setting2idx(RIG_LEVEL_RFPOWER)].f);
}
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)) {
printf("COMP: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_COMP)].f);
}
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)) {
printf("KEYSPD: %d\n", chan.levels[rig_setting2idx(RIG_LEVEL_KEYSPD)].i);
}
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)) {
printf("AGC: %d\n", chan.levels[rig_setting2idx(RIG_LEVEL_AGC)].i);
}
if (rig_has_set_level(rig, RIG_LEVEL_BKINDL)) {
printf("BKINDL: %d\n", chan.levels[rig_setting2idx(RIG_LEVEL_BKINDL)].i);
}
return 0;
} }

Wyświetl plik

@ -3,8 +3,8 @@
* Edit to specify your rig model and serial port, and baud rate * Edit to specify your rig model and serial port, and baud rate
* before compiling. * before compiling.
* To compile: * To compile:
* gcc -L/usr/local/lib -lhamlib -o example example.c * gcc -L/usr/local/lib -lhamlib -o example example.c
* if hamlib is installed in /usr/local/... * if hamlib is installed in /usr/local/...
* *
*/ */
@ -13,68 +13,117 @@
#include <hamlib/rig.h> #include <hamlib/rig.h>
#include <hamlib/riglist.h> #include <hamlib/riglist.h>
int main() {
RIG *my_rig;
char *rig_file, *info_buf, *mm;
freq_t freq;
value_t rawstrength, power, strength;
float s_meter, rig_raw2val();
int status, retcode, isz, mwpower;
rmode_t mode;
pbwidth_t width;
/* Set verbosity level */ int main()
rig_set_debug(RIG_DEBUG_ERR); // errors only {
/* Instantiate a rig */ RIG *my_rig;
my_rig = rig_init(RIG_MODEL_TT565); // your rig model. char *rig_file, *info_buf, *mm;
/* Set up serial port, baud rate */ freq_t freq;
rig_file = "/dev/ttyUSB0"; // your serial device value_t rawstrength, power, strength;
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); float s_meter, rig_raw2val();
my_rig->state.rigport.parm.serial.rate = 57600; // your baud rate int status, retcode, isz, mwpower;
/* Open my rig */ rmode_t mode;
retcode = rig_open(my_rig); pbwidth_t width;
/* Give me ID info, e.g., firmware version. */
info_buf = (char *)rig_get_info(my_rig);
printf("Rig_info: '%s'\n", info_buf);
/* Note: As a general practice, we should check to see if a given /* Set verbosity level */
* function is within the rig's capabilities before calling it, but rig_set_debug(RIG_DEBUG_ERR); // errors only
* we are simplifying here. Also, we should check each call's returned
* status in case of error. (That's an inelegant way to catch an unsupported
* operation.)
*/
/* Main VFO frequency */ /* Instantiate a rig */
status = rig_get_freq(my_rig, RIG_VFO_CURR, &freq); my_rig = rig_init(RIG_MODEL_TT565); // your rig model.
printf("VFO freq. = %.1f Hz\n", freq);
/* Current mode */ /* Set up serial port, baud rate */
status = rig_get_mode(my_rig, RIG_VFO_CURR, &mode, &width); rig_file = "/dev/ttyUSB0"; // your serial device
switch(mode) {
case RIG_MODE_USB: mm = "USB"; break; strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
case RIG_MODE_LSB: mm = "LSB"; break;
case RIG_MODE_CW: mm = "CW"; break; my_rig->state.rigport.parm.serial.rate = 57600; // your baud rate
case RIG_MODE_CWR: mm = "CWR"; break;
case RIG_MODE_AM: mm = "AM"; break; /* Open my rig */
case RIG_MODE_FM: mm = "FM"; break; retcode = rig_open(my_rig);
case RIG_MODE_WFM: mm = "WFM"; break;
case RIG_MODE_RTTY:mm = "RTTY"; break; /* Give me ID info, e.g., firmware version. */
default: mm = "unrecognized"; break; /* there are more possibilities! */ info_buf = (char *)rig_get_info(my_rig);
}
printf("Current mode = 0x%X = %s, width = %d\n", mode, mm, width); printf("Rig_info: '%s'\n", info_buf);
/* rig power output */
status = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &power); /* Note: As a general practice, we should check to see if a given
printf("RF Power relative setting = %.3f (0.0 - 1.0)\n", power.f); * function is within the rig's capabilities before calling it, but
/* Convert power reading to watts */ * we are simplifying here. Also, we should check each call's returned
status = rig_power2mW(my_rig, &mwpower, power.f, freq, mode); * status in case of error. (That's an inelegant way to catch an unsupported
printf("RF Power calibrated = %.1f Watts\n", mwpower/1000.); * operation.)
/* Raw and calibrated S-meter values */ */
status = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RAWSTR,
&rawstrength); /* Main VFO frequency */
printf("Raw receive strength = %d\n", rawstrength.i); status = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
isz = my_rig->caps->str_cal.size;
s_meter = rig_raw2val(rawstrength.i, &my_rig->caps->str_cal); printf("VFO freq. = %.1f Hz\n", freq);
printf("S-meter value = %.2f dB relative to S9\n", s_meter);
/* now try using RIG_LEVEL_STRENGTH itself */ /* Current mode */
status = rig_get_strength(my_rig, RIG_VFO_CURR, &strength); status = rig_get_mode(my_rig, RIG_VFO_CURR, &mode, &width);
printf("LEVEL_STRENGTH returns %d\n", strength.i);
switch (mode) {
case RIG_MODE_USB:
mm = "USB";
break;
case RIG_MODE_LSB:
mm = "LSB";
break;
case RIG_MODE_CW:
mm = "CW";
break;
case RIG_MODE_CWR:
mm = "CWR";
break;
case RIG_MODE_AM:
mm = "AM";
break;
case RIG_MODE_FM:
mm = "FM";
break;
case RIG_MODE_WFM:
mm = "WFM";
break;
case RIG_MODE_RTTY:
mm = "RTTY";
break;
default:
mm = "unrecognized";
break; /* there are more possibilities! */
}
printf("Current mode = 0x%X = %s, width = %d\n", mode, mm, width);
/* rig power output */
status = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &power);
printf("RF Power relative setting = %.3f (0.0 - 1.0)\n", power.f);
/* Convert power reading to watts */
status = rig_power2mW(my_rig, &mwpower, power.f, freq, mode);
printf("RF Power calibrated = %.1f Watts\n", mwpower / 1000.);
/* Raw and calibrated S-meter values */
status = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RAWSTR, &rawstrength);
printf("Raw receive strength = %d\n", rawstrength.i);
isz = my_rig->caps->str_cal.size;
s_meter = rig_raw2val(rawstrength.i, &my_rig->caps->str_cal);
printf("S-meter value = %.2f dB relative to S9\n", s_meter);
/* now try using RIG_LEVEL_STRENGTH itself */
status = rig_get_strength(my_rig, RIG_VFO_CURR, &strength);
printf("LEVEL_STRENGTH returns %d\n", strength.i);
}; };

Wyświetl plik

@ -30,59 +30,73 @@
int print_caps_sum(const struct rig_caps *caps, void *data) int print_caps_sum(const struct rig_caps *caps, void *data)
{ {
printf("%d\t%-10s\t%-12s\t%s\t",caps->rig_model,caps->mfg_name, printf("%d\t%-10s\t%-12s\t%s\t",
caps->model_name, caps->version); caps->rig_model,
caps->mfg_name,
caps->model_name,
caps->version);
printf("%-10s\t", rig_strstatus(caps->status)); printf("%-10s\t", rig_strstatus(caps->status));
switch (caps->rig_type & RIG_TYPE_MASK) {
case RIG_TYPE_TRANSCEIVER: switch (caps->rig_type & RIG_TYPE_MASK) {
printf("Transceiver\n"); case RIG_TYPE_TRANSCEIVER:
break; printf("Transceiver\n");
case RIG_TYPE_HANDHELD: break;
printf("Handheld\n");
break; case RIG_TYPE_HANDHELD:
case RIG_TYPE_MOBILE: printf("Handheld\n");
printf("Mobile\n"); break;
break;
case RIG_TYPE_RECEIVER: case RIG_TYPE_MOBILE:
printf("Receiver\n"); printf("Mobile\n");
break; break;
case RIG_TYPE_PCRECEIVER:
printf("PC Receiver\n"); case RIG_TYPE_RECEIVER:
break; printf("Receiver\n");
case RIG_TYPE_SCANNER: break;
printf("Scanner\n");
break; case RIG_TYPE_PCRECEIVER:
case RIG_TYPE_TRUNKSCANNER: printf("PC Receiver\n");
printf("Trunking scanner\n"); break;
break;
case RIG_TYPE_COMPUTER: case RIG_TYPE_SCANNER:
printf("Computer\n"); printf("Scanner\n");
break; break;
case RIG_TYPE_OTHER:
printf("Other\n"); case RIG_TYPE_TRUNKSCANNER:
break; printf("Trunking scanner\n");
default: break;
printf("Unknown\n");
} case RIG_TYPE_COMPUTER:
return -1; /* !=0, we want them all ! */ printf("Computer\n");
break;
case RIG_TYPE_OTHER:
printf("Other\n");
break;
default:
printf("Unknown\n");
}
return -1; /* !=0, we want them all ! */
} }
int main (int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int status; int status;
rig_load_all_backends(); rig_load_all_backends();
printf("Rig#\tMfg \tModel \tVers.\tStatus \tType\n"); printf("Rig#\tMfg \tModel \tVers.\tStatus \tType\n");
status = rig_list_foreach(print_caps_sum,NULL);
if (status != RIG_OK ) {
printf("rig_list_foreach: error = %s \n", rigerror(status));
exit(3);
}
return 0; status = rig_list_foreach(print_caps_sum, NULL);
if (status != RIG_OK) {
printf("rig_list_foreach: error = %s \n", rigerror(status));
exit(3);
}
return 0;
} }

Plik diff jest za duży Load Diff

Wyświetl plik

@ -20,7 +20,7 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> # include <config.h>
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -32,229 +32,317 @@
#include "misc.h" #include "misc.h"
#ifdef HAVE_XML2 #ifdef HAVE_XML2
#include <libxml/parser.h> # include <libxml/parser.h>
#include <libxml/tree.h> # include <libxml/tree.h>
static int set_chan(RIG *rig, channel_t *chan ,xmlNodePtr node); static int set_chan(RIG *rig, channel_t *chan , xmlNodePtr node);
#endif #endif
int xml_load (RIG *my_rig, const char *infilename) int xml_load(RIG *my_rig, const char *infilename)
{ {
#ifdef HAVE_XML2 #ifdef HAVE_XML2
xmlDocPtr Doc; xmlDocPtr Doc;
xmlNodePtr node; xmlNodePtr node;
/* load xlm Doc */ /* load xlm Doc */
Doc=xmlParseFile(infilename); Doc = xmlParseFile(infilename);
if(Doc==NULL) {
fprintf(stderr,"xmlParse failed\n");
exit(2);
}
node=xmlDocGetRootElement(Doc); if (Doc == NULL) {
if (node == NULL) { fprintf(stderr, "xmlParse failed\n");
fprintf(stderr,"get root failed\n"); exit(2);
exit(2); }
node = xmlDocGetRootElement(Doc);
if (node == NULL) {
fprintf(stderr, "get root failed\n");
exit(2);
}
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)) {
continue;
} }
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)) continue;
if(strcmp((char *) node->name, "channels")==0)
break;
}
if(node==NULL) {
fprintf(stderr,"no channels\n");
exit(2);
}
for(node=node->xmlChildrenNode;node!=NULL;node=node->next) {
channel_t chan;
int status;
if(xmlNodeIsText(node)) continue; if (strcmp((char *) node->name, "channels") == 0) {
break;
}
}
set_chan(my_rig,&chan,node); if (node == NULL) {
fprintf(stderr, "no channels\n");
exit(2);
}
status=rig_set_channel(my_rig, &chan); for (node = node->xmlChildrenNode; node != NULL; node = node->next) {
channel_t chan;
int status;
if (status != RIG_OK ) { if (xmlNodeIsText(node)) {
printf("rig_get_channel: error = %s \n", rigerror(status)); continue;
return status; }
}
}
xmlFreeDoc(Doc); set_chan(my_rig, &chan, node);
xmlCleanupParser();
return 0; status = rig_set_channel(my_rig, &chan);
if (status != RIG_OK) {
printf("rig_get_channel: error = %s \n", rigerror(status));
return status;
}
}
xmlFreeDoc(Doc);
xmlCleanupParser();
return 0;
#else #else
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
#endif #endif
} }
int xml_parm_load (RIG *my_rig, const char *infilename)
int xml_parm_load(RIG *my_rig, const char *infilename)
{ {
return -RIG_ENIMPL; return -RIG_ENIMPL;
} }
#ifdef HAVE_XML2 #ifdef HAVE_XML2
int set_chan(RIG *rig, channel_t *chan, xmlNodePtr node) int set_chan(RIG *rig, channel_t *chan, xmlNodePtr node)
{ {
xmlChar *prop; xmlChar *prop;
int i,n; int i, n;
memset(chan,0,sizeof(channel_t)); memset(chan, 0, sizeof(channel_t));
chan->vfo = RIG_VFO_MEM; chan->vfo = RIG_VFO_MEM;
prop=xmlGetProp(node,(unsigned char *) "num"); prop = xmlGetProp(node, (unsigned char *) "num");
if(prop==NULL) {
fprintf(stderr,"no num\n");
return -1;
}
n=chan->channel_num = atoi((char *) prop);
/* find chanel caps */ if (prop == NULL) {
for(i=0;i<CHANLSTSIZ ;i++) fprintf(stderr, "no num\n");
if (rig->state.chan_list[i].start<=n && rig->state.chan_list[i].end>=n) return -1;
break; }
fprintf(stderr,"node %d %d\n",n,i); n = chan->channel_num = atoi((char *) prop);
if (rig->state.chan_list[i].mem_caps.bank_num) { /* find chanel caps */
prop=xmlGetProp(node, (unsigned char *) "bank_num"); for (i = 0; i < CHANLSTSIZ ; i++)
if(prop!=NULL) if (rig->state.chan_list[i].start <= n
chan->bank_num = atoi((char *) prop); && rig->state.chan_list[i].end >= n) {
}
if (rig->state.chan_list[i].mem_caps.channel_desc) { break;
prop=xmlGetProp(node, (unsigned char *) "channel_desc"); }
if(prop!=NULL)
strncpy(chan->channel_desc, (char *) prop, 7);
}
if (rig->state.chan_list[i].mem_caps.ant) { fprintf(stderr, "node %d %d\n", n, i);
prop=xmlGetProp(node, (unsigned char *) "ant");
if(prop!=NULL) if (rig->state.chan_list[i].mem_caps.bank_num) {
chan->ant = atoi((char *) prop); prop = xmlGetProp(node, (unsigned char *) "bank_num");
}
if (rig->state.chan_list[i].mem_caps.freq) { if (prop != NULL) {
prop=xmlGetProp(node, (unsigned char *) "freq"); chan->bank_num = atoi((char *) prop);
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.channel_desc) {
prop=xmlGetProp(node, (unsigned char *) "mode"); prop = xmlGetProp(node, (unsigned char *) "channel_desc");
if(prop!=NULL)
chan->mode = rig_parse_mode((char *) prop); if (prop != NULL) {
} strncpy(chan->channel_desc, (char *) prop, 7);
if (rig->state.chan_list[i].mem_caps.width) { }
prop=xmlGetProp(node, (unsigned char *) "width"); }
if(prop!=NULL)
chan->width = atoi((char *) prop); if (rig->state.chan_list[i].mem_caps.ant) {
} prop = xmlGetProp(node, (unsigned char *) "ant");
if (rig->state.chan_list[i].mem_caps.tx_freq) {
prop=xmlGetProp(node, (unsigned char *) "tx_freq"); if (prop != NULL) {
if(prop!=NULL) chan->ant = atoi((char *) prop);
sscanf((char *) prop,"%"SCNfreq,&chan->tx_freq); }
} }
if (rig->state.chan_list[i].mem_caps.tx_mode) {
prop=xmlGetProp(node, (unsigned char *)"tx_mode"); if (rig->state.chan_list[i].mem_caps.freq) {
if(prop!=NULL) prop = xmlGetProp(node, (unsigned char *) "freq");
chan->tx_mode = rig_parse_mode((char *) prop);
} if (prop != NULL) {
if (rig->state.chan_list[i].mem_caps.tx_width) { sscanf((char *) prop, "%"SCNfreq, &chan->freq);
prop=xmlGetProp(node, (unsigned char *)"tx_width"); }
if(prop!=NULL) }
chan->tx_width = atoi((char *) prop);
} if (rig->state.chan_list[i].mem_caps.mode) {
if (rig->state.chan_list[i].mem_caps.split) { prop = xmlGetProp(node, (unsigned char *) "mode");
chan->split=RIG_SPLIT_OFF;
prop=xmlGetProp(node, (unsigned char *)"split"); if (prop != NULL) {
if(prop!=NULL) { chan->mode = rig_parse_mode((char *) prop);
if(strcmp((char *) prop,"on")==0) { }
chan->split=RIG_SPLIT_ON; }
if (rig->state.chan_list[i].mem_caps.tx_vfo) {
prop=xmlGetProp(node, (unsigned char *)"tx_vfo"); if (rig->state.chan_list[i].mem_caps.width) {
if(prop!=NULL) prop = xmlGetProp(node, (unsigned char *) "width");
sscanf((char *) prop,"%x",&chan->tx_vfo);
} if (prop != NULL) {
} chan->width = atoi((char *) prop);
} }
} }
if (rig->state.chan_list[i].mem_caps.rptr_shift) {
prop=xmlGetProp(node, (unsigned char *)"rptr_shift"); if (rig->state.chan_list[i].mem_caps.tx_freq) {
if(prop) prop = xmlGetProp(node, (unsigned char *) "tx_freq");
switch(prop[0]) {
case '=': chan->rptr_shift=RIG_RPT_SHIFT_NONE; if (prop != NULL) {
break; sscanf((char *) prop, "%"SCNfreq, &chan->tx_freq);
case '+': chan->rptr_shift=RIG_RPT_SHIFT_PLUS; }
break; }
case '-': chan->rptr_shift=RIG_RPT_SHIFT_MINUS;
break; if (rig->state.chan_list[i].mem_caps.tx_mode) {
} prop = xmlGetProp(node, (unsigned char *)"tx_mode");
if (rig->state.chan_list[i].mem_caps.rptr_offs && chan->rptr_shift!=RIG_RPT_SHIFT_NONE) {
prop=xmlGetProp(node, (unsigned char *)"rptr_offs"); if (prop != NULL) {
if(prop!=NULL) chan->tx_mode = rig_parse_mode((char *) prop);
chan->rptr_offs = atoi((char *) prop); }
} }
}
if (rig->state.chan_list[i].mem_caps.tuning_step) { if (rig->state.chan_list[i].mem_caps.tx_width) {
prop=xmlGetProp(node, (unsigned char *)"tuning_step"); prop = xmlGetProp(node, (unsigned char *)"tx_width");
if(prop!=NULL)
chan->tuning_step = atoi((char *) prop); if (prop != NULL) {
} chan->tx_width = atoi((char *) prop);
if (rig->state.chan_list[i].mem_caps.rit) { }
prop=xmlGetProp(node, (unsigned char *)"rit"); }
if(prop!=NULL)
chan->rit = atoi((char *) prop); if (rig->state.chan_list[i].mem_caps.split) {
} chan->split = RIG_SPLIT_OFF;
if (rig->state.chan_list[i].mem_caps.xit) { prop = xmlGetProp(node, (unsigned char *)"split");
prop=xmlGetProp(node, (unsigned char *)"xit");
if(prop!=NULL) if (prop != NULL) {
chan->xit = atoi((char *) prop); if (strcmp((char *) prop, "on") == 0) {
} chan->split = RIG_SPLIT_ON;
if (rig->state.chan_list[i].mem_caps.funcs) {
prop=xmlGetProp(node, (unsigned char *)"funcs"); if (rig->state.chan_list[i].mem_caps.tx_vfo) {
if(prop!=NULL) prop = xmlGetProp(node, (unsigned char *)"tx_vfo");
sscanf((char *) prop,"%lx",&chan->funcs);
} if (prop != NULL) {
if (rig->state.chan_list[i].mem_caps.ctcss_tone) { sscanf((char *) prop, "%x", &chan->tx_vfo);
prop=xmlGetProp(node, (unsigned char *)"ctcss_tone"); }
if(prop!=NULL) }
chan->ctcss_tone = atoi((char *) prop); }
} }
if (rig->state.chan_list[i].mem_caps.ctcss_sql) { }
prop=xmlGetProp(node, (unsigned char *)"ctcss_sql");
if(prop!=NULL) if (rig->state.chan_list[i].mem_caps.rptr_shift) {
chan->ctcss_sql = atoi((char *) prop); prop = xmlGetProp(node, (unsigned char *)"rptr_shift");
}
if (rig->state.chan_list[i].mem_caps.dcs_code) { if (prop)
prop=xmlGetProp(node, (unsigned char *)"dcs_code"); switch (prop[0]) {
if(prop!=NULL) case '=':
chan->dcs_code = atoi((char *) prop); chan->rptr_shift = RIG_RPT_SHIFT_NONE;
} break;
if (rig->state.chan_list[i].mem_caps.dcs_sql) {
prop=xmlGetProp(node, (unsigned char *)"dcs_sql"); case '+':
if(prop!=NULL) chan->rptr_shift = RIG_RPT_SHIFT_PLUS;
chan->dcs_sql = atoi((char *) prop); break;
}
if (rig->state.chan_list[i].mem_caps.scan_group) { case '-':
prop=xmlGetProp(node, (unsigned char *)"scan_group"); chan->rptr_shift = RIG_RPT_SHIFT_MINUS;
if(prop!=NULL) break;
chan->scan_group = atoi((char *) prop); }
}
if (rig->state.chan_list[i].mem_caps.flags) { if (rig->state.chan_list[i].mem_caps.rptr_offs
prop=xmlGetProp(node, (unsigned char *)"flags"); && chan->rptr_shift != RIG_RPT_SHIFT_NONE) {
if(prop!=NULL) prop = xmlGetProp(node, (unsigned char *)"rptr_offs");
sscanf((char *) prop,"%x",&chan->flags);
} if (prop != NULL) {
chan->rptr_offs = atoi((char *) prop);
}
}
}
if (rig->state.chan_list[i].mem_caps.tuning_step) {
prop = xmlGetProp(node, (unsigned char *)"tuning_step");
if (prop != NULL) {
chan->tuning_step = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.rit) {
prop = xmlGetProp(node, (unsigned char *)"rit");
if (prop != NULL) {
chan->rit = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.xit) {
prop = xmlGetProp(node, (unsigned char *)"xit");
if (prop != NULL) {
chan->xit = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.funcs) {
prop = xmlGetProp(node, (unsigned char *)"funcs");
if (prop != NULL) {
sscanf((char *) prop, "%lx", &chan->funcs);
}
}
if (rig->state.chan_list[i].mem_caps.ctcss_tone) {
prop = xmlGetProp(node, (unsigned char *)"ctcss_tone");
if (prop != NULL) {
chan->ctcss_tone = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.ctcss_sql) {
prop = xmlGetProp(node, (unsigned char *)"ctcss_sql");
if (prop != NULL) {
chan->ctcss_sql = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.dcs_code) {
prop = xmlGetProp(node, (unsigned char *)"dcs_code");
if (prop != NULL) {
chan->dcs_code = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.dcs_sql) {
prop = xmlGetProp(node, (unsigned char *)"dcs_sql");
if (prop != NULL) {
chan->dcs_sql = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.scan_group) {
prop = xmlGetProp(node, (unsigned char *)"scan_group");
if (prop != NULL) {
chan->scan_group = atoi((char *) prop);
}
}
if (rig->state.chan_list[i].mem_caps.flags) {
prop = xmlGetProp(node, (unsigned char *)"flags");
if (prop != NULL) {
sscanf((char *) prop, "%x", &chan->flags);
}
}
return 0; return 0;
} }
#endif #endif

Wyświetl plik

@ -19,7 +19,7 @@
* *
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> # include <config.h>
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -32,193 +32,231 @@
#include "misc.h" #include "misc.h"
#ifdef HAVE_XML2 #ifdef HAVE_XML2
#include <libxml/parser.h> # include <libxml/parser.h>
#include <libxml/tree.h> # include <libxml/tree.h>
static int dump_xml_chan(RIG *rig, channel_t **chan, int channel_num, const chan_t *chan_list, rig_ptr_t arg); static int dump_xml_chan(RIG *rig,
channel_t **chan,
int channel_num,
const chan_t *chan_list,
rig_ptr_t arg);
#endif #endif
int xml_save (RIG *rig, const char *outfilename)
int xml_save(RIG *rig, const char *outfilename)
{ {
#ifdef HAVE_XML2 #ifdef HAVE_XML2
int retval; int retval;
xmlDocPtr Doc; xmlDocPtr Doc;
xmlNodePtr root; xmlNodePtr root;
/* create xlm Doc */ /* create xlm Doc */
Doc=xmlNewDoc((unsigned char *) "1.0"); Doc = xmlNewDoc((unsigned char *) "1.0");
root=xmlNewNode(NULL,(unsigned char *) "hamlib"); root = xmlNewNode(NULL, (unsigned char *) "hamlib");
xmlDocSetRootElement(Doc, root); xmlDocSetRootElement(Doc, root);
root=xmlNewChild(root,NULL,(unsigned char *) "channels",NULL); root = xmlNewChild(root, NULL, (unsigned char *) "channels", NULL);
if (rig->caps->clone_combo_get) if (rig->caps->clone_combo_get)
printf("About to save data, enter cloning mode: %s\n", printf("About to save data, enter cloning mode: %s\n",
rig->caps->clone_combo_get); rig->caps->clone_combo_get);
retval = rig_get_chan_all_cb (rig, dump_xml_chan, root); retval = rig_get_chan_all_cb(rig, dump_xml_chan, root);
if (retval != RIG_OK)
return retval;
/* write xml File */ if (retval != RIG_OK) {
return retval;
}
xmlSaveFormatFileEnc(outfilename, Doc, "UTF-8", 1); /* write xml File */
xmlFreeDoc(Doc); xmlSaveFormatFileEnc(outfilename, Doc, "UTF-8", 1);
xmlCleanupParser();
return 0; xmlFreeDoc(Doc);
xmlCleanupParser();
return 0;
#else #else
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
#endif #endif
} }
int xml_parm_save (RIG *rig, const char *outfilename)
{
return -RIG_ENIMPL;
}
int xml_parm_save(RIG *rig, const char *outfilename)
{
return -RIG_ENIMPL;
}
#ifdef HAVE_XML2 #ifdef HAVE_XML2
int dump_xml_chan(RIG *rig, channel_t **chan_pp, int chan_num, const chan_t *chan_list, rig_ptr_t arg) int dump_xml_chan(RIG *rig,
channel_t **chan_pp,
int chan_num,
const chan_t *chan_list,
rig_ptr_t arg)
{ {
char attrbuf[20]; char attrbuf[20];
xmlNodePtr root = arg; xmlNodePtr root = arg;
xmlNodePtr node = NULL; xmlNodePtr node = NULL;
int i; int i;
const char *mtype; const char *mtype;
static channel_t chan; static channel_t chan;
const channel_cap_t *mem_caps = &chan_list->mem_caps; const channel_cap_t *mem_caps = &chan_list->mem_caps;
if (*chan_pp == NULL) { if (*chan_pp == NULL) {
/* /*
* Hamlib frontend demand application an allocated * Hamlib frontend demand application an allocated
* channel_t pointer for next round. * channel_t pointer for next round.
*/ */
*chan_pp = &chan; *chan_pp = &chan;
return RIG_OK; return RIG_OK;
} }
if (chan_list->type == RIG_MTYPE_NONE) if (chan_list->type == RIG_MTYPE_NONE) {
return RIG_OK; return RIG_OK;
}
mtype = rig_strmtype(chan_list->type); mtype = rig_strmtype(chan_list->type);
for (i=0; i<strlen(mtype); i++)
attrbuf[i] = tolower(mtype[i]);
attrbuf[i] = '\0';
node=xmlNewChild(root,NULL,(unsigned char *)attrbuf,NULL); for (i = 0; i < strlen(mtype); i++) {
attrbuf[i] = tolower(mtype[i]);
}
if (mem_caps->bank_num) { attrbuf[i] = '\0';
sprintf(attrbuf,"%d",chan.bank_num);
xmlNewProp(node, (unsigned char *) "bank_num", (unsigned char *) attrbuf);
}
sprintf(attrbuf,"%d",chan.channel_num); node = xmlNewChild(root, NULL, (unsigned char *)attrbuf, NULL);
xmlNewProp(node, (unsigned char *) "num", (unsigned char *) attrbuf);
if (mem_caps->channel_desc && chan.channel_desc[0]!='\0') { if (mem_caps->bank_num) {
xmlNewProp(node, sprintf(attrbuf, "%d", chan.bank_num);
(unsigned char *) "channel_desc", xmlNewProp(node, (unsigned char *) "bank_num", (unsigned char *) attrbuf);
(unsigned char *) chan.channel_desc); }
}
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) {
sprintf(attrbuf,"%d",chan.ant);
xmlNewProp(node, (unsigned char *) "ant", (unsigned char *) attrbuf);
}
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) {
xmlNewProp(node, (unsigned char *) "mode", (unsigned char *) rig_strrmode(chan.mode));
}
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) {
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) {
xmlNewProp(node,
(unsigned char *) "tx_mode",
(unsigned char *) rig_strrmode(chan.tx_mode));
}
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) {
xmlNewProp(node, (unsigned char *) "split", (unsigned char *) "on");
if (mem_caps->tx_vfo) {
sprintf(attrbuf,"%x",chan.tx_vfo);
xmlNewProp(node,
(unsigned char *) "tx_vfo",
(unsigned char *) attrbuf);
}
}
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) {
sprintf(attrbuf,"%d",(int)chan.rptr_offs);
xmlNewProp(node,
(unsigned char *) "rptr_offs",
(unsigned char *) attrbuf);
}
}
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) {
sprintf(attrbuf,"%d",(int)chan.rit);
xmlNewProp(node, (unsigned char *) "rit", (unsigned char *) attrbuf);
}
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) {
sprintf(attrbuf,"%lx",chan.funcs);
xmlNewProp(node, (unsigned char *) "funcs", (unsigned char *) attrbuf);
}
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) {
sprintf(attrbuf,"%d",chan.ctcss_sql);
xmlNewProp(node, (unsigned char *) "ctcss_sql", (unsigned char *) attrbuf);
}
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) {
sprintf(attrbuf,"%d",chan.dcs_sql);
xmlNewProp(node, (unsigned char *) "dcs_sql", (unsigned char *) attrbuf);
}
if (mem_caps->scan_group) {
sprintf(attrbuf,"%d",chan.scan_group);
xmlNewProp(node, (unsigned char *) "scan_group", (unsigned char *) attrbuf);
}
if (mem_caps->flags) {
sprintf(attrbuf,"%x",chan.flags);
xmlNewProp(node, (unsigned char *) "flags", (unsigned char *) attrbuf);
}
return 0; sprintf(attrbuf, "%d", chan.channel_num);
xmlNewProp(node, (unsigned char *) "num", (unsigned char *) attrbuf);
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) {
sprintf(attrbuf, "%d", chan.vfo);
xmlNewProp(node, (unsigned char *) "vfo", (unsigned char *) attrbuf);
}
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) {
sprintf(attrbuf, "%"PRIll, (int64_t)chan.freq);
xmlNewProp(node, (unsigned char *) "freq", (unsigned char *) attrbuf);
}
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) {
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) {
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) {
xmlNewProp(node,
(unsigned char *) "tx_mode",
(unsigned char *) rig_strrmode(chan.tx_mode));
}
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) {
xmlNewProp(node, (unsigned char *) "split", (unsigned char *) "on");
if (mem_caps->tx_vfo) {
sprintf(attrbuf, "%x", chan.tx_vfo);
xmlNewProp(node,
(unsigned char *) "tx_vfo",
(unsigned char *) attrbuf);
}
}
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) {
sprintf(attrbuf, "%d", (int)chan.rptr_offs);
xmlNewProp(node,
(unsigned char *) "rptr_offs",
(unsigned char *) attrbuf);
}
}
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) {
sprintf(attrbuf, "%d", (int)chan.rit);
xmlNewProp(node, (unsigned char *) "rit", (unsigned char *) attrbuf);
}
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) {
sprintf(attrbuf, "%lx", chan.funcs);
xmlNewProp(node, (unsigned char *) "funcs", (unsigned char *) attrbuf);
}
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) {
sprintf(attrbuf, "%d", chan.ctcss_sql);
xmlNewProp(node, (unsigned char *) "ctcss_sql", (unsigned char *) attrbuf);
}
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) {
sprintf(attrbuf, "%d", chan.dcs_sql);
xmlNewProp(node, (unsigned char *) "dcs_sql", (unsigned char *) attrbuf);
}
if (mem_caps->scan_group) {
sprintf(attrbuf, "%d", chan.scan_group);
xmlNewProp(node, (unsigned char *) "scan_group", (unsigned char *) attrbuf);
}
if (mem_caps->flags) {
sprintf(attrbuf, "%x", chan.flags);
xmlNewProp(node, (unsigned char *) "flags", (unsigned char *) attrbuf);
}
return 0;
} }
#endif #endif

Wyświetl plik

@ -14,95 +14,106 @@
#define SERIAL_PORT "/dev/ttyS0" #define SERIAL_PORT "/dev/ttyS0"
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{ {
RIG *my_rig; /* handle to rig (nstance) */ RIG *my_rig; /* handle to rig (nstance) */
int retcode; /* generic return code from functions */ int retcode; /* generic return code from functions */
rig_model_t myrig_model; rig_model_t myrig_model;
unsigned i; unsigned i;
struct timeval tv1, tv2; struct timeval tv1, tv2;
float elapsed; float elapsed;
rig_set_debug(RIG_DEBUG_ERR); rig_set_debug(RIG_DEBUG_ERR);
/* /*
* allocate memory, setup & open port * allocate memory, setup & open port
*/ */
if (argc < 2) { if (argc < 2) {
hamlib_port_t myport; hamlib_port_t myport;
/* may be overriden by backend probe */ /* may be overriden by backend probe */
myport.type.rig = RIG_PORT_SERIAL; myport.type.rig = RIG_PORT_SERIAL;
myport.parm.serial.rate = 9600; myport.parm.serial.rate = 9600;
myport.parm.serial.data_bits = 8; myport.parm.serial.data_bits = 8;
myport.parm.serial.stop_bits = 1; myport.parm.serial.stop_bits = 1;
myport.parm.serial.parity = RIG_PARITY_NONE; myport.parm.serial.parity = RIG_PARITY_NONE;
myport.parm.serial.handshake = RIG_HANDSHAKE_NONE; myport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1); strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1);
rig_load_all_backends(); rig_load_all_backends();
myrig_model = rig_probe(&myport); myrig_model = rig_probe(&myport);
} else { } else {
myrig_model = atoi(argv[1]); myrig_model = atoi(argv[1]);
} }
my_rig = rig_init(myrig_model); my_rig = rig_init(myrig_model);
if (!my_rig) { if (!my_rig) {
fprintf(stderr,"Unknown rig num: %d\n", myrig_model); fprintf(stderr, "Unknown rig num: %d\n", myrig_model);
fprintf(stderr,"Please check riglist.h\n"); fprintf(stderr, "Please check riglist.h\n");
exit(1); /* whoops! something went wrong (mem alloc?) */ exit(1); /* whoops! something went wrong (mem alloc?) */
} }
printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model, printf("Opened rig model %d, '%s'\n",
my_rig->caps->model_name); my_rig->caps->rig_model,
printf("Backend version: %s, Status: %s\n", my_rig->caps->model_name);
my_rig->caps->version, rig_strstatus(my_rig->caps->status));
printf("Serial speed: %d bauds\n", my_rig->state.rigport.parm.serial.rate);
strncpy(my_rig->state.rigport.pathname,SERIAL_PORT,FILPATHLEN - 1); printf("Backend version: %s, Status: %s\n",
my_rig->caps->version,
rig_strstatus(my_rig->caps->status));
retcode = rig_open(my_rig); printf("Serial speed: %d bauds\n", my_rig->state.rigport.parm.serial.rate);
if (retcode != RIG_OK) {
printf("rig_open: error = %s\n", rigerror(retcode));
exit(2);
}
printf("Port %s opened ok\n", SERIAL_PORT); strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
printf("Perform %d loops...\n", LOOP_COUNT);
/* retcode = rig_open(my_rig);
* we're not using getrusage here because we want effective time
*/
gettimeofday(&tv1, NULL);
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_open: error = %s\n", rigerror(retcode));
printf("rig_get_freq: error = %s \n", rigerror(retcode)); exit(2);
exit(1); }
}
retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
if (retcode != RIG_OK ) {
printf("rig_get_mode: error = %s \n", rigerror(retcode));
exit(1);
}
}
gettimeofday(&tv2, NULL);
elapsed = tv2.tv_sec - tv1.tv_sec + (tv2.tv_usec - tv1.tv_usec)/1000000.0; printf("Port %s opened ok\n", SERIAL_PORT);
printf("Elapsed: %.3fs, Avg: %f loops/s, %f s/loop\n", printf("Perform %d loops...\n", LOOP_COUNT);
elapsed, LOOP_COUNT/elapsed, elapsed/LOOP_COUNT
);
rig_close(my_rig); /* close port */ /*
rig_cleanup(my_rig); /* if you care about memory */ * we're not using getrusage here because we want effective time
*/
gettimeofday(&tv1, NULL);
printf("port %s closed ok \n",SERIAL_PORT); for (i = 0; i < LOOP_COUNT; i++) {
freq_t freq;
rmode_t rmode;
pbwidth_t width;
return 0; retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
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) {
printf("rig_get_mode: error = %s \n", rigerror(retcode));
exit(1);
}
}
gettimeofday(&tv2, NULL);
elapsed = tv2.tv_sec - tv1.tv_sec + (tv2.tv_usec - tv1.tv_usec) / 1000000.0;
printf("Elapsed: %.3fs, Avg: %f loops/s, %f s/loop\n",
elapsed,
LOOP_COUNT / elapsed,
elapsed / LOOP_COUNT);
rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
printf("port %s closed ok \n", SERIAL_PORT);
return 0;
} }

Wyświetl plik

@ -25,7 +25,7 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -42,7 +42,7 @@
# elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */ # elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */
# include <readline.h> # include <readline.h>
# else /* !defined(HAVE_READLINE_H) */ # else /* !defined(HAVE_READLINE_H) */
extern char *readline (); extern char * readline();
# endif /* HAVE_READLINE_H */ # endif /* HAVE_READLINE_H */
#else #else
/* no readline */ /* no readline */
@ -56,9 +56,9 @@ extern char *readline ();
# elif defined(HAVE_HISTORY_H) # elif defined(HAVE_HISTORY_H)
# include <history.h> # include <history.h>
# else /* !defined(HAVE_HISTORY_H) */ # else /* !defined(HAVE_HISTORY_H) */
extern void add_history (); extern void add_history();
extern int write_history (); extern int write_history();
extern int read_history (); extern int read_history();
# endif /* defined(HAVE_READLINE_HISTORY_H) */ # endif /* defined(HAVE_READLINE_HISTORY_H) */
#else #else
/* no history */ /* no history */
@ -75,7 +75,7 @@ extern int read_history ();
#include "rigctl_parse.h" #include "rigctl_parse.h"
#define MAXNAMSIZ 32 #define MAXNAMSIZ 32
#define MAXNBOPT 100 /* max number of different options */ #define MAXNBOPT 100 /* max number of different options */
void usage(void); void usage(void);
@ -83,36 +83,35 @@ void usage(void);
/* /*
* Reminder: when adding long options, * Reminder: when adding long options,
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks. * keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
* NB: do NOT use -W since it's reserved by POSIX. * NB: do NOT use -W since it's reserved by POSIX.
* TODO: add an option to read from a file * TODO: add an option to read from a file
*/ */
#define SHORT_OPTIONS "+m:r:p:d:P:D:s:c:t:lC:LuonvhV" #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'},
{"model", 1, 0, 'm'}, {"rig-file", 1, 0, 'r'},
{"rig-file", 1, 0, 'r'}, {"ptt-file", 1, 0, 'p'},
{"ptt-file", 1, 0, 'p'}, {"dcd-file", 1, 0, 'd'},
{"dcd-file", 1, 0, 'd'}, {"ptt-type", 1, 0, 'P'},
{"ptt-type", 1, 0, 'P'}, {"dcd-type", 1, 0, 'D'},
{"dcd-type", 1, 0, 'D'}, {"serial-speed", 1, 0, 's'},
{"serial-speed", 1, 0, 's'}, {"civaddr", 1, 0, 'c'},
{"civaddr", 1, 0, 'c'}, {"send-cmd-term", 1, 0, 't'},
{"send-cmd-term", 1, 0, 't'}, {"list", 0, 0, 'l'},
{"list", 0, 0, 'l'}, {"set-conf", 1, 0, 'C'},
{"set-conf", 1, 0, 'C'}, {"show-conf", 0, 0, 'L'},
{"show-conf", 0, 0, 'L'}, {"dump-caps", 0, 0, 'u'},
{"dump-caps", 0, 0, 'u'}, {"vfo", 0, 0, 'o'},
{"vfo", 0, 0, 'o'}, {"no-restore-ai", 0, 0, 'n'},
{"no-restore-ai", 0, 0, 'n'},
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
{"read-history", 0, 0, 'i'}, {"read-history", 0, 0, 'i'},
{"save-history", 0, 0, 'I'}, {"save-history", 0, 0, 'I'},
#endif #endif
{"verbose", 0, 0, 'v'}, {"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{"version", 0, 0, 'V'}, {"version", 0, 0, 'V'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
#define MAXCONFLEN 128 #define MAXCONFLEN 128
@ -131,356 +130,441 @@ int vfo_mode = 0; /* vfo_mode = 0 means target VFO is 'currVFO' */
char send_cmd_term = '\r'; /* send_cmd termination char */ char send_cmd_term = '\r'; /* send_cmd termination char */
int main (int argc, char *argv[]) int main(int argc, char *argv[])
{ {
RIG *my_rig; /* handle to rig (nstance) */ RIG *my_rig; /* handle to rig (instance) */
rig_model_t my_model = RIG_MODEL_DUMMY; rig_model_t my_model = RIG_MODEL_DUMMY;
int retcode; /* generic return code from functions */ int retcode; /* generic return code from functions */
int exitcode; int exitcode;
int verbose = 0; int verbose = 0;
int show_conf = 0; int show_conf = 0;
int dump_caps_opt = 0; int dump_caps_opt = 0;
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
int rd_hist = 0; int rd_hist = 0;
int sv_hist = 0; int sv_hist = 0;
const char *hist_dir = NULL; const char *hist_dir = NULL;
const char hist_file[] = "/.rigctl_history"; const char hist_file[] = "/.rigctl_history";
char *hist_path = NULL; char *hist_path = NULL;
struct stat hist_dir_stat; struct stat hist_dir_stat;
#endif #endif
const char *rig_file=NULL, *ptt_file=NULL, *dcd_file=NULL; const char *rig_file = NULL, *ptt_file = NULL, *dcd_file = NULL;
ptt_type_t ptt_type = RIG_PTT_NONE; ptt_type_t ptt_type = RIG_PTT_NONE;
dcd_type_t dcd_type = RIG_DCD_NONE; dcd_type_t dcd_type = RIG_DCD_NONE;
int serial_rate = 0; int serial_rate = 0;
char *civaddr = NULL; /* NULL means no need to set conf */ char *civaddr = NULL; /* NULL means no need to set conf */
char conf_parms[MAXCONFLEN] = ""; char conf_parms[MAXCONFLEN] = "";
while(1) { while (1) {
int c; int c;
int option_index = 0; int option_index = 0;
c = getopt_long (argc, argv, SHORT_OPTIONS HST_SHRT_OPTS, c = getopt_long(argc,
long_options, &option_index); argv,
if (c == -1) SHORT_OPTIONS HST_SHRT_OPTS,
break; long_options,
&option_index);
switch(c) { if (c == -1) {
case 'h': break;
usage(); }
exit(0);
case 'V': switch (c) {
version(); case 'h':
exit(0); usage();
case 'm': exit(0);
if (!optarg) {
usage(); /* wrong arg count */ case 'V':
exit(1); version();
} exit(0);
my_model = atoi(optarg);
break; case 'm':
case 'r': if (!optarg) {
if (!optarg) { usage(); /* wrong arg count */
usage(); /* wrong arg count */ exit(1);
exit(1); }
}
rig_file = optarg; my_model = atoi(optarg);
break; break;
case 'p':
if (!optarg) { case 'r':
usage(); /* wrong arg count */ if (!optarg) {
exit(1); usage(); /* wrong arg count */
} exit(1);
ptt_file = optarg; }
break;
case 'd': rig_file = optarg;
if (!optarg) { break;
usage(); /* wrong arg count */
exit(1); case 'p':
} if (!optarg) {
dcd_file = optarg; usage(); /* wrong arg count */
break; exit(1);
case 'P': }
if (!optarg) {
usage(); /* wrong arg count */ ptt_file = optarg;
exit(1); break;
}
if (!strcmp(optarg, "RIG")) case 'd':
ptt_type = RIG_PTT_RIG; if (!optarg) {
else if (!strcmp(optarg, "DTR")) usage(); /* wrong arg count */
ptt_type = RIG_PTT_SERIAL_DTR; exit(1);
else if (!strcmp(optarg, "RTS")) }
ptt_type = RIG_PTT_SERIAL_RTS;
else if (!strcmp(optarg, "PARALLEL")) dcd_file = optarg;
ptt_type = RIG_PTT_PARALLEL; break;
else if (!strcmp(optarg, "CM108"))
ptt_type = RIG_PTT_CM108; case 'P':
else if (!strcmp(optarg, "GPIO")) if (!optarg) {
ptt_type = RIG_PTT_GPIO; usage(); /* wrong arg count */
else if (!strcmp(optarg, "GPION")) exit(1);
ptt_type = RIG_PTT_GPION; }
else if (!strcmp(optarg, "NONE"))
ptt_type = RIG_PTT_NONE; if (!strcmp(optarg, "RIG")) {
else ptt_type = RIG_PTT_RIG;
ptt_type = atoi(optarg); } else if (!strcmp(optarg, "DTR")) {
break; ptt_type = RIG_PTT_SERIAL_DTR;
case 'D': } else if (!strcmp(optarg, "RTS")) {
if (!optarg) { ptt_type = RIG_PTT_SERIAL_RTS;
usage(); /* wrong arg count */ } else if (!strcmp(optarg, "PARALLEL")) {
exit(1); ptt_type = RIG_PTT_PARALLEL;
} } else if (!strcmp(optarg, "CM108")) {
if (!strcmp(optarg, "RIG")) ptt_type = RIG_PTT_CM108;
dcd_type = RIG_DCD_RIG; } else if (!strcmp(optarg, "GPIO")) {
else if (!strcmp(optarg, "DSR")) ptt_type = RIG_PTT_GPIO;
dcd_type = RIG_DCD_SERIAL_DSR; } else if (!strcmp(optarg, "GPION")) {
else if (!strcmp(optarg, "CTS")) ptt_type = RIG_PTT_GPION;
dcd_type = RIG_DCD_SERIAL_CTS; } else if (!strcmp(optarg, "NONE")) {
else if (!strcmp(optarg, "CD")) ptt_type = RIG_PTT_NONE;
dcd_type = RIG_DCD_SERIAL_CAR; } else {
else if (!strcmp(optarg, "PARALLEL")) ptt_type = atoi(optarg);
dcd_type = RIG_DCD_PARALLEL; }
else if (!strcmp(optarg, "CM108"))
dcd_type = RIG_DCD_CM108; break;
else if (!strcmp(optarg, "NONE"))
dcd_type = RIG_DCD_NONE; case 'D':
else if (!optarg) {
dcd_type = atoi(optarg); usage(); /* wrong arg count */
break; exit(1);
case 'c': }
if (!optarg) {
usage(); /* wrong arg count */ if (!strcmp(optarg, "RIG")) {
exit(1); dcd_type = RIG_DCD_RIG;
} } else if (!strcmp(optarg, "DSR")) {
civaddr = optarg; dcd_type = RIG_DCD_SERIAL_DSR;
break; } else if (!strcmp(optarg, "CTS")) {
case 't': dcd_type = RIG_DCD_SERIAL_CTS;
if (!optarg) { } else if (!strcmp(optarg, "CD")) {
usage(); /* wrong arg count */ dcd_type = RIG_DCD_SERIAL_CAR;
exit(1); } else if (!strcmp(optarg, "PARALLEL")) {
} dcd_type = RIG_DCD_PARALLEL;
if (strlen(optarg) > 1) } else if (!strcmp(optarg, "CM108")) {
send_cmd_term = strtol(optarg, NULL, 0); dcd_type = RIG_DCD_CM108;
else } else if (!strcmp(optarg, "NONE")) {
send_cmd_term = optarg[0]; dcd_type = RIG_DCD_NONE;
break; } else {
case 's': dcd_type = atoi(optarg);
if (!optarg) { }
usage(); /* wrong arg count */
exit(1); break;
}
serial_rate = atoi(optarg); case 'c':
break; if (!optarg) {
case 'C': usage(); /* wrong arg count */
if (!optarg) { exit(1);
usage(); /* wrong arg count */ }
exit(1);
} civaddr = optarg;
if (*conf_parms != '\0') break;
strcat(conf_parms, ",");
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms)); case 't':
break; if (!optarg) {
case 'o': usage(); /* wrong arg count */
vfo_mode++; exit(1);
break; }
case 'n':
rig_no_restore_ai(); if (strlen(optarg) > 1) {
break; send_cmd_term = strtol(optarg, NULL, 0);
} else {
send_cmd_term = optarg[0];
}
break;
case 's':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
serial_rate = atoi(optarg);
break;
case 'C':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
if (*conf_parms != '\0') {
strcat(conf_parms, ",");
}
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
break;
case 'o':
vfo_mode++;
break;
case 'n':
rig_no_restore_ai();
break;
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
case 'i':
rd_hist++; case 'i':
break; rd_hist++;
case 'I': break;
sv_hist++;
break; case 'I':
sv_hist++;
break;
#endif #endif
case 'v':
verbose++;
break;
case 'L':
show_conf++;
break;
case 'l':
rig_set_debug(verbose);
list_models();
exit(0);
case 'u':
dump_caps_opt++;
break;
default:
usage(); /* unknown option? */
exit(1);
}
}
rig_set_debug(verbose); case 'v':
verbose++;
break;
rig_debug(RIG_DEBUG_VERBOSE, "rigctl, %s\n", hamlib_version); case 'L':
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to " show_conf++;
"<hamlib-developer@lists.sourceforge.net>\n\n"); break;
/* case 'l':
* at least one command on command line, rig_set_debug(verbose);
* disable interactive mode list_models();
*/ exit(0);
if (optind < argc)
interactive = 0;
my_rig = rig_init(my_model); case 'u':
dump_caps_opt++;
break;
if (!my_rig) { default:
fprintf(stderr, "Unknown rig num %d, or initialization error.\n", usage(); /* unknown option? */
my_model); exit(1);
fprintf(stderr, "Please check with --list option.\n"); }
exit(2); }
}
retcode = set_conf(my_rig, conf_parms); rig_set_debug(verbose);
if (retcode != RIG_OK) {
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (rig_file) rig_debug(RIG_DEBUG_VERBOSE, "rigctl, %s\n", hamlib_version);
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); rig_debug(RIG_DEBUG_VERBOSE,
"Report bugs to <hamlib-developer@lists.sourceforge.net>\n\n");
/* /*
* ex: RIG_PTT_PARALLEL and /dev/parport0 * at least one command on command line,
*/ * disable interactive mode
if (ptt_type != RIG_PTT_NONE) */
my_rig->state.pttport.type.ptt = ptt_type; if (optind < argc) {
if (dcd_type != RIG_DCD_NONE) interactive = 0;
my_rig->state.dcdport.type.dcd = dcd_type; }
if (ptt_file)
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
if (dcd_file)
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1);
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0)
my_rig->state.rigport.parm.serial.rate = serial_rate;
if (civaddr)
rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
/* my_rig = rig_init(my_model);
* print out conf parameters
*/
if (show_conf) {
dumpconf(my_rig, stdout);
}
/* if (!my_rig) {
* print out capabilities, and exists immediately fprintf(stderr,
* We may be interested only in only caps, and rig_open may fail. "Unknown rig num %d, or initialization error.\n",
*/ my_model);
if (dump_caps_opt) { fprintf(stderr, "Please check with --list option.\n");
dumpcaps(my_rig, stdout); exit(2);
rig_cleanup(my_rig); /* if you care about memory */ }
exit(0);
}
retcode = rig_open(my_rig); retcode = set_conf(my_rig, conf_parms);
if (retcode != RIG_OK) {
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) if (retcode != RIG_OK) {
printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model, fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
my_rig->caps->model_name); exit(2);
rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n", }
my_rig->caps->version, rig_strstatus(my_rig->caps->status));
exitcode = 0; 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) {
my_rig->state.pttport.type.ptt = ptt_type;
}
if (dcd_type != RIG_DCD_NONE) {
my_rig->state.dcdport.type.dcd = dcd_type;
}
if (ptt_file) {
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
}
if (dcd_file) {
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0) {
my_rig->state.rigport.parm.serial.rate = serial_rate;
}
if (civaddr) {
rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
}
/*
* print out conf parameters
*/
if (show_conf) {
dumpconf(my_rig, stdout);
}
/*
* print out capabilities, and exit immediately
* We may be interested only in only caps, and rig_open may fail.
*/
if (dump_caps_opt) {
dumpcaps(my_rig, stdout);
rig_cleanup(my_rig); /* if you care about memory */
exit(0);
}
retcode = rig_open(my_rig);
if (retcode != RIG_OK) {
fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) {
printf("Opened rig model %d, '%s'\n",
my_rig->caps->rig_model,
my_rig->caps->model_name);
}
rig_debug(RIG_DEBUG_VERBOSE,
"Backend version: %s, Status: %s\n",
my_rig->caps->version,
rig_strstatus(my_rig->caps->status));
exitcode = 0;
#ifdef HAVE_LIBREADLINE #ifdef HAVE_LIBREADLINE
if (interactive && prompt && have_rl) {
rl_readline_name = "rigctl"; if (interactive && prompt && have_rl) {
rl_readline_name = "rigctl";
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
using_history(); /* Initialize Readline History */ using_history(); /* Initialize Readline History */
if (rd_hist || sv_hist) { if (rd_hist || sv_hist) {
if (!(hist_dir = getenv("RIGCTL_HIST_DIR"))) if (!(hist_dir = getenv("RIGCTL_HIST_DIR"))) {
hist_dir = getenv("HOME"); hist_dir = getenv("HOME");
}
if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT)) 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); fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir);
} }
hist_path = (char *)calloc((sizeof(char) * (strlen(hist_dir) + strlen(hist_file) + 1)), sizeof(char)); hist_path = (char *)calloc((sizeof(char)
* (strlen(hist_dir)
+ strlen(hist_file) + 1)),
sizeof(char));
strncpy(hist_path, hist_dir, strlen(hist_dir)); strncpy(hist_path, hist_dir, strlen(hist_dir));
strncat(hist_path, hist_file, strlen(hist_file)); strncat(hist_path, hist_file, strlen(hist_file));
} }
if (rd_hist && hist_path) {
if (read_history(hist_path) == ENOENT) {
fprintf(stderr,
"Warning: Could not read history from %s\n",
hist_path);
}
}
if (rd_hist && hist_path)
if (read_history(hist_path) == ENOENT)
fprintf(stderr, "Warning: Could not read history from %s\n", hist_path);
#endif #endif
} }
#endif /* HAVE_LIBREADLINE */
do { #endif /* HAVE_LIBREADLINE */
retcode = rigctl_parse(my_rig, stdin, stdout, argv, argc);
if (retcode == 2) do {
exitcode = 2; retcode = rigctl_parse(my_rig, stdin, stdout, argv, argc);
}
while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL); if (retcode == 2) {
exitcode = 2;
}
} while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL);
#ifdef HAVE_LIBREADLINE #ifdef HAVE_LIBREADLINE
if (interactive && prompt && have_rl) {
if (interactive && prompt && have_rl) {
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
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 (sv_hist && hist_path) {
free(hist_path); if (write_history(hist_path) == ENOENT) {
hist_path = (char *)NULL; fprintf(stderr,
} "\nWarning: Could not write history to %s\n",
#endif hist_path);
} }
#endif }
rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
return exitcode; if ((rd_hist || sv_hist) && hist_path) {
free(hist_path);
hist_path = (char *)NULL;
}
#endif
}
#endif
rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
return exitcode;
} }
void usage(void) void usage(void)
{ {
printf("Usage: rigctl [OPTION]... [COMMAND]...\n" printf("Usage: rigctl [OPTION]... [COMMAND]...\n"
"Send COMMANDs to a connected radio transceiver or receiver.\n\n"); "Send COMMANDs to a connected radio transceiver or receiver.\n\n");
printf( printf(
" -m, --model=ID select radio model number. See model list\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" " -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" " -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" " -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" " -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" " -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" " -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, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -t, --send-cmd-term=CHAR set send_cmd command termination char\n" " -t, --send-cmd-term=CHAR set send_cmd command termination char\n"
" -C, --set-conf=PARM=VAL set config parameters\n" " -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n" " -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n" " -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n" " -u, --dump-caps dump capabilities and exit\n"
" -o, --vfo do not default to VFO_CURR, require extra vfo arg\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" " -n, --no-restore-ai do not restore auto information mode on rig\n"
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
" -i, --read-history read prior interactive session history\n" " -i, --read-history read prior interactive session history\n"
" -I, --save-history save current interactive session history\n" " -I, --save-history save current interactive session history\n"
#endif #endif
" -v, --verbose set verbose mode, cumulative\n" " -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n"
" -h, --help display this help and exit\n" " -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n" " -V, --version output version information and exit\n\n"
); );
usage_rig(stdout); usage_rig(stdout);
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n"); printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
} }

Plik diff jest za duży Load Diff

Wyświetl plik

@ -32,8 +32,8 @@
* external prototype * external prototype
*/ */
int dumpcaps (RIG *, FILE *); int dumpcaps(RIG *, FILE *);
int dumpconf (RIG *, FILE *); int dumpconf(RIG *, FILE *);
/* /*
* Prototypes * Prototypes
@ -41,10 +41,10 @@ int dumpconf (RIG *, FILE *);
void usage_rig(FILE *); void usage_rig(FILE *);
void version(); void version();
void list_models(); void list_models();
int dump_chan(FILE *, RIG*, channel_t*); int dump_chan(FILE *, RIG *, channel_t *);
int print_conf_list(const struct confparams *cfp, rig_ptr_t data); int print_conf_list(const struct confparams *cfp, rig_ptr_t data);
int set_conf(RIG *my_rig, char *conf_parms); int set_conf(RIG *my_rig, char *conf_parms);
int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc); int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc);
#endif /* RIGCTL_PARSE_H */ #endif /* RIGCTL_PARSE_H */

Plik diff jest za duży Load Diff

Plik diff jest za duży Load Diff

Wyświetl plik

@ -23,7 +23,7 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -40,22 +40,22 @@
#include "sprintflst.h" #include "sprintflst.h"
#define MAXNAMSIZ 32 #define MAXNAMSIZ 32
#define MAXNBOPT 100 /* max number of different options */ #define MAXNBOPT 100 /* max number of different options */
/* /*
* external prototype * external prototype
*/ */
extern int xml_save (RIG *rig, const char *outfilename); extern int xml_save(RIG *rig, const char *outfilename);
extern int xml_load (RIG *rig, const char *infilename); extern int xml_load(RIG *rig, const char *infilename);
extern int xml_parm_save (RIG *rig, const char *outfilename); extern int xml_parm_save(RIG *rig, const char *outfilename);
extern int xml_parm_load (RIG *rig, const char *infilename); extern int xml_parm_load(RIG *rig, const char *infilename);
extern int csv_save (RIG *rig, const char *outfilename); extern int csv_save(RIG *rig, const char *outfilename);
extern int csv_load (RIG *rig, const char *infilename); extern int csv_load(RIG *rig, const char *infilename);
extern int csv_parm_save (RIG *rig, const char *outfilename); extern int csv_parm_save(RIG *rig, const char *outfilename);
extern int csv_parm_load (RIG *rig, const char *infilename); extern int csv_parm_load(RIG *rig, const char *infilename);
/* /*
* Prototypes * Prototypes
@ -64,328 +64,378 @@ void usage();
void version(); void version();
int set_conf(RIG *rig, char *conf_parms); int set_conf(RIG *rig, char *conf_parms);
int clear_chans (RIG *rig, const char *infilename); int clear_chans(RIG *rig, const char *infilename);
/* /*
* Reminder: when adding long options, * Reminder: when adding long options,
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks. * keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
* NB: do NOT use -W since it's reserved by POSIX. * NB: do NOT use -W since it's reserved by POSIX.
*/ */
#define SHORT_OPTIONS "m:r:s:c:C:p:axvhV" #define SHORT_OPTIONS "m:r:s:c:C:p:axvhV"
static struct option long_options[] = static struct option long_options[] = {
{ {"model", 1, 0, 'm'},
{"model", 1, 0, 'm'}, {"rig-file", 1, 0, 'r'},
{"rig-file", 1, 0, 'r'}, {"serial-speed", 1, 0, 's'},
{"serial-speed", 1, 0, 's'}, {"civaddr", 1, 0, 'c'},
{"civaddr", 1, 0, 'c'}, {"set-conf", 1, 0, 'C'},
{"set-conf", 1, 0, 'C'}, {"set-separator", 1, 0, 'p'},
{"set-separator", 1, 0, 'p'}, {"all", 0, 0, 'a'},
{"all", 0, 0, 'a'},
#ifdef HAVE_XML2 #ifdef HAVE_XML2
{"xml", 0, 0, 'x'}, {"xml", 0, 0, 'x'},
#endif #endif
{"verbose", 0, 0, 'v'}, {"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{"version", 0, 0, 'V'}, {"version", 0, 0, 'V'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
#define MAXCONFLEN 128 #define MAXCONFLEN 128
int all; int all;
int main (int argc, char *argv[]) int main(int argc, char *argv[])
{ {
RIG *rig; /* handle to rig (nstance) */ RIG *rig; /* handle to rig (nstance) */
rig_model_t my_model = RIG_MODEL_DUMMY; rig_model_t my_model = RIG_MODEL_DUMMY;
int retcode; /* generic return code from functions */ int retcode; /* generic return code from functions */
int verbose = 0, xml = 0; int verbose = 0, xml = 0;
const char *rig_file=NULL; const char *rig_file = NULL;
int serial_rate = 0; int serial_rate = 0;
char *civaddr = NULL; /* NULL means no need to set conf */ char *civaddr = NULL; /* NULL means no need to set conf */
char conf_parms[MAXCONFLEN] = ""; char conf_parms[MAXCONFLEN] = "";
extern char csv_sep; extern char csv_sep;
while(1) { while (1) {
int c; int c;
int option_index = 0; int option_index = 0;
c = getopt_long (argc, argv, SHORT_OPTIONS, c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
long_options, &option_index);
if (c == -1)
break;
switch(c) { if (c == -1) {
case 'h': break;
usage(); }
exit(0);
case 'V': switch (c) {
version(); case 'h':
exit(0); usage();
case 'm': exit(0);
if (!optarg) {
usage(); /* wrong arg count */ case 'V':
exit(1); version();
} exit(0);
my_model = atoi(optarg);
break; case 'm':
case 'r': if (!optarg) {
if (!optarg) { usage(); /* wrong arg count */
usage(); /* wrong arg count */ exit(1);
exit(1); }
}
rig_file = optarg; my_model = atoi(optarg);
break; break;
case 'c':
if (!optarg) { case 'r':
usage(); /* wrong arg count */ if (!optarg) {
exit(1); usage(); /* wrong arg count */
} exit(1);
civaddr = optarg; }
break;
case 's': rig_file = optarg;
if (!optarg) { break;
usage(); /* wrong arg count */
exit(1); case 'c':
} if (!optarg) {
serial_rate = atoi(optarg); usage(); /* wrong arg count */
break; exit(1);
case 'C': }
if (!optarg) {
usage(); /* wrong arg count */ civaddr = optarg;
exit(1); break;
}
if (*conf_parms != '\0') case 's':
strcat(conf_parms, ","); if (!optarg) {
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms)); usage(); /* wrong arg count */
break; exit(1);
case 'p': }
if (!optarg) {
usage(); /* wrong arg count */ serial_rate = atoi(optarg);
exit(1); break;
}
csv_sep = optarg[0]; case 'C':
break; if (!optarg) {
case 'a': usage(); /* wrong arg count */
all++; exit(1);
break; }
if (*conf_parms != '\0') {
strcat(conf_parms, ",");
}
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
break;
case 'p':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
csv_sep = optarg[0];
break;
case 'a':
all++;
break;
#ifdef HAVE_XML2 #ifdef HAVE_XML2
case 'x':
xml++; case 'x':
break; xml++;
break;
#endif #endif
case 'v':
verbose++;
break;
default:
usage(); /* unknown option? */
exit(1);
}
}
rig_set_debug(verbose<2 ? RIG_DEBUG_WARN: verbose); case 'v':
verbose++;
break;
rig_debug(RIG_DEBUG_VERBOSE, "rigmem, %s\n", hamlib_version); default:
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to " usage(); /* unknown option? */
"<hamlib-developer@lists.sourceforge.net>\n\n"); exit(1);
}
}
if (optind+1 >= argc) { rig_set_debug(verbose < 2 ? RIG_DEBUG_WARN : verbose);
usage();
exit(1);
}
rig = rig_init(my_model); rig_debug(RIG_DEBUG_VERBOSE, "rigmem, %s\n", hamlib_version);
rig_debug(RIG_DEBUG_VERBOSE,
"Report bugs to "
"<hamlib-developer@lists.sourceforge.net>\n\n");
if (!rig) { if (optind + 1 >= argc) {
fprintf(stderr, "Unknown rig num %d, or initialization error.\n", usage();
my_model); exit(1);
fprintf(stderr, "Please check with --list option.\n"); }
exit(2);
}
retcode = set_conf(rig, conf_parms); rig = rig_init(my_model);
if (retcode != RIG_OK) {
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); if (!rig) {
exit(2); fprintf(stderr,
} "Unknown rig num %d, or initialization error.\n",
my_model);
fprintf(stderr, "Please check with --list option.\n");
exit(2);
}
retcode = set_conf(rig, conf_parms);
if (retcode != RIG_OK) {
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
/* check channel support */ /* check channel support */
if (rig->caps->set_channel == NULL && rig->caps->get_channel == NULL && if (rig->caps->set_channel == NULL
rig->caps->set_chan_all_cb == NULL && rig->caps->get_chan_all_cb == NULL && && rig->caps->get_channel == NULL
(rig->caps->set_mem == NULL || rig->caps->set_vfo == NULL)) { && rig->caps->set_chan_all_cb == NULL
fprintf(stderr, "Error: rig num %d has no memory support implemented/available.\n", && rig->caps->get_chan_all_cb == NULL
my_model); && (rig->caps->set_mem == NULL || rig->caps->set_vfo == NULL)) {
exit(3);
fprintf(stderr,
"Error: rig num %d has no memory support implemented/available.\n",
my_model);
exit(3);
} }
/* check channel description */ /* 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", fprintf(stderr, "Error: rig num %d has no channel list.\n",
my_model); my_model);
exit(3); exit(3);
} }
if (rig_file) if (rig_file) {
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */ /* FIXME: bound checking and port type == serial */
if (serial_rate != 0) if (serial_rate != 0) {
rig->state.rigport.parm.serial.rate = serial_rate; rig->state.rigport.parm.serial.rate = serial_rate;
if (civaddr) }
rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr);
retcode = rig_open(rig); if (civaddr) {
if (retcode != RIG_OK) { rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr);
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode)); }
exit(2);
}
if (verbose > 0) retcode = rig_open(rig);
printf("Opened rig model %d, '%s'\n", rig->caps->rig_model,
rig->caps->model_name);
rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n",
rig->caps->version, rig_strstatus(rig->caps->status));
/* on some rigs, this accelerates the backup/restore */ if (retcode != RIG_OK) {
rig_set_vfo(rig, RIG_VFO_MEM); fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (!strcmp(argv[optind], "save")) { if (verbose > 0) {
if (xml) printf("Opened rig model %d, '%s'\n",
retcode = xml_save(rig, argv[optind+1]); rig->caps->rig_model,
else rig->caps->model_name);
retcode = csv_save(rig, argv[optind+1]); }
} else
if (!strcmp(argv[optind], "load")) {
if (xml)
retcode = xml_load(rig, argv[optind+1]);
else
retcode = csv_load(rig, argv[optind+1]);
} else
if (!strcmp(argv[optind], "save_parm")) {
if (xml)
retcode = xml_parm_save(rig, argv[optind+1]);
else
retcode = csv_parm_save(rig, argv[optind+1]);
} else
if (!strcmp(argv[optind], "load_parm")) {
if (xml)
retcode = xml_parm_load(rig, argv[optind+1]);
else
retcode = csv_parm_load(rig, argv[optind+1]);
} else
if (!strcmp(argv[optind], "clear")) {
retcode = clear_chans(rig, argv[optind+1]);
} else {
usage();
exit(1);
}
rig_close(rig); /* close port */ rig_debug(RIG_DEBUG_VERBOSE,
rig_cleanup(rig); /* if you care about memory */ "Backend version: %s, Status: %s\n",
rig->caps->version,
rig_strstatus(rig->caps->status));
if (retcode != 0) { /* on some rigs, this accelerates the backup/restore */
fprintf(stderr, "Hamlib error: %s\n", rigerror(retcode)); rig_set_vfo(rig, RIG_VFO_MEM);
exit(2);
}
return 0; if (!strcmp(argv[optind], "save")) {
if (xml) {
retcode = xml_save(rig, argv[optind + 1]);
} else {
retcode = csv_save(rig, argv[optind + 1]);
}
} else if (!strcmp(argv[optind], "load")) {
if (xml) {
retcode = xml_load(rig, argv[optind + 1]);
} else {
retcode = csv_load(rig, argv[optind + 1]);
}
} else if (!strcmp(argv[optind], "save_parm")) {
if (xml) {
retcode = xml_parm_save(rig, argv[optind + 1]);
} else {
retcode = csv_parm_save(rig, argv[optind + 1]);
}
} else if (!strcmp(argv[optind], "load_parm")) {
if (xml) {
retcode = xml_parm_load(rig, argv[optind + 1]);
} else {
retcode = csv_parm_load(rig, argv[optind + 1]);
}
} else if (!strcmp(argv[optind], "clear")) {
retcode = clear_chans(rig, argv[optind + 1]);
} else {
usage();
exit(1);
}
rig_close(rig); /* close port */
rig_cleanup(rig); /* if you care about memory */
if (retcode != 0) {
fprintf(stderr, "Hamlib error: %s\n", rigerror(retcode));
exit(2);
}
return 0;
} }
void version() void version()
{ {
printf("rigmem, %s\n\n", hamlib_version); printf("rigmem, %s\n\n", hamlib_version);
printf("%s\n", hamlib_copyright); printf("%s\n", hamlib_copyright);
} }
void usage() void usage()
{ {
printf("Usage: rigmem [OPTION]... COMMAND...FILE\n" printf("Usage: rigmem [OPTION]... COMMAND...FILE\n"
"Backup/restore COMMANDs to a connected radio transceiver or receiver.\n\n"); "Backup/restore COMMANDs to a connected radio transceiver or receiver.\n\n");
printf( printf(
" -m, --model=ID select radio model number. See model list\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" " -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" " -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, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -C, --set-conf=PARM=VAL set config parameters\n" " -C, --set-conf=PARM=VAL set config parameters\n"
" -p, --set-separator=SEP set character separator instead of the CSV comma\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" " -a, --all bypass mem_caps, apply to all fields of channel_t\n"
#ifdef HAVE_XML2 #ifdef HAVE_XML2
" -x, --xml use XML format instead of CSV\n" " -x, --xml use XML format instead of CSV\n"
#endif #endif
" -v, --verbose set verbose mode, cumulative\n" " -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n" " -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n" " -V, --version output version information and exit\n\n"
); );
printf( printf(
"COMMANDs:\n" "COMMANDs:\n"
" load\n" " load\n"
" save\n" " save\n"
" load_parm\n" " load_parm\n"
" save_parm\n" " save_parm\n"
" clear\n\n" " clear\n\n"
); );
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n"); printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
} }
int set_conf(RIG *rig, char *conf_parms) int set_conf(RIG *rig, char *conf_parms)
{ {
char *p, *q, *n; char *p, *q, *n;
int ret; int ret;
p = conf_parms; p = conf_parms;
while (p && *p != '\0') {
/* FIXME: left hand value of = cannot be null */
q = strchr(p, '=');
if ( !q )
return RIG_EINVAL;
*q++ = '\0';
n = strchr(q, ',');
if (n) *n++ = '\0';
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q); while (p && *p != '\0') {
if (ret != RIG_OK) /* FIXME: left hand value of = cannot be null */
return ret; q = strchr(p, '=');
p = n;
} if (!q) {
return RIG_OK; return RIG_EINVAL;
}
*q++ = '\0';
n = strchr(q, ',');
if (n) {
*n++ = '\0';
}
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q);
if (ret != RIG_OK) {
return ret;
}
p = n;
}
return RIG_OK;
} }
/* /*
* Pretty nasty, clears everything you have in rig memory * Pretty nasty, clears everything you have in rig memory
*/ */
int clear_chans (RIG *rig, const char *infilename) int clear_chans(RIG *rig, const char *infilename)
{ {
int i,j,ret; int i, j, ret;
channel_t chan; channel_t chan;
memset(&chan, 0, sizeof(chan)); memset(&chan, 0, sizeof(chan));
chan.freq = RIG_FREQ_NONE; chan.freq = RIG_FREQ_NONE;
chan.tx_freq = RIG_FREQ_NONE; chan.tx_freq = RIG_FREQ_NONE;
chan.mode = RIG_MODE_NONE; chan.mode = RIG_MODE_NONE;
chan.tx_mode = RIG_MODE_NONE; chan.tx_mode = RIG_MODE_NONE;
chan.vfo = RIG_VFO_MEM; 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; 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) {
return ret;
}
}
}
return 0; chan.channel_num = j;
ret = rig_set_channel(rig, &chan);
if (ret != RIG_OK) {
return ret;
}
}
}
return 0;
} }

Wyświetl plik

@ -21,7 +21,7 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -53,340 +53,411 @@ static int set_conf_rot(ROT *rot, char *conf_parms);
* NB: do NOT use -W since it's reserved by POSIX. * NB: do NOT use -W since it's reserved by POSIX.
*/ */
#define SHORT_OPTIONS "m:r:s:c:C:M:R:S:N:vhV" #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'},
{"model", 1, 0, 'm'}, {"rig-file", 1, 0, 'r'},
{"rig-file", 1, 0, 'r'}, {"serial-speed", 1, 0, 's'},
{"serial-speed", 1, 0, 's'}, {"civaddr", 1, 0, 'c'},
{"civaddr", 1, 0, 'c'}, {"set-conf", 1, 0, 'C'},
{"set-conf", 1, 0, 'C'}, {"rot-model", 1, 0, 'M'},
{"rot-model", 1, 0, 'M'}, {"rot-file", 1, 0, 'R'},
{"rot-file", 1, 0, 'R'}, {"rot-serial-speed", 1, 0, 'S'},
{"rot-serial-speed", 1, 0, 'S'}, {"rot-set-conf", 1, 0, 'N'},
{"rot-set-conf", 1, 0, 'N'}, {"verbose", 0, 0, 'v'},
{"verbose", 0, 0, 'v'}, {"help", 0, 0, 'h'},
{"help", 0, 0, 'h'}, {"version", 0, 0, 'V'},
{"version", 0, 0, 'V'}, {0, 0, 0, 0}
{0, 0, 0, 0}
}; };
#define MAXCONFLEN 128 #define MAXCONFLEN 128
int main (int argc, char *argv[]) int main(int argc, char *argv[])
{ {
RIG *rig; /* handle to rig (instance) */ RIG *rig; /* handle to rig (instance) */
ROT *rot; /* handle to rotator (instance) */ ROT *rot; /* handle to rotator (instance) */
rig_model_t rig_model = RIG_MODEL_DUMMY; rig_model_t rig_model = RIG_MODEL_DUMMY;
rot_model_t rot_model = ROT_MODEL_DUMMY; rot_model_t rot_model = ROT_MODEL_DUMMY;
int retcode; /* generic return code from functions */ int retcode; /* generic return code from functions */
int verbose = 0; int verbose = 0;
const char *rig_file=NULL, *rot_file=NULL; const char *rig_file = NULL, *rot_file = NULL;
int serial_rate = 0; int serial_rate = 0;
int rot_serial_rate = 0; int rot_serial_rate = 0;
char *civaddr = NULL; /* NULL means no need to set conf */ char *civaddr = NULL; /* NULL means no need to set conf */
char rig_conf_parms[MAXCONFLEN] = ""; char rig_conf_parms[MAXCONFLEN] = "";
char rot_conf_parms[MAXCONFLEN] = ""; char rot_conf_parms[MAXCONFLEN] = "";
/* int with_rot = 1; */ /* int with_rot = 1; */
azimuth_t azimuth; azimuth_t azimuth;
elevation_t elevation; elevation_t elevation;
unsigned step = 1000000; /* 1e6 us */ unsigned step = 1000000; /* 1e6 us */
while(1) { while (1) {
int c; int c;
int option_index = 0; int option_index = 0;
c = getopt_long (argc, argv, SHORT_OPTIONS, c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
long_options, &option_index);
if (c == -1)
break;
switch(c) { if (c == -1) {
case 'h': break;
usage(); }
exit(0);
case 'V':
version();
exit(0);
case 'm':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
rig_model = atoi(optarg);
break;
case 'r':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
rig_file = optarg;
break;
case 'c':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
civaddr = optarg;
break;
case 's':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
serial_rate = atoi(optarg);
break;
case 'C':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
if (*rig_conf_parms != '\0')
strcat(rig_conf_parms, ",");
strncat(rig_conf_parms, optarg, MAXCONFLEN-strlen(rig_conf_parms));
break;
case 'M':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
rot_model = atoi(optarg);
break;
case 'R':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
rot_file = optarg;
break;
case 'S':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
rot_serial_rate = atoi(optarg);
break;
case 'N':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
if (*rot_conf_parms != '\0')
strcat(rot_conf_parms, ",");
strncat(rot_conf_parms, optarg, MAXCONFLEN-strlen(rot_conf_parms));
break;
case 'v':
verbose++;
break;
default:
usage(); /* unknown option? */
exit(1);
}
}
rig_set_debug(verbose<2 ? RIG_DEBUG_WARN: verbose); switch (c) {
case 'h':
usage();
exit(0);
rig_debug(RIG_DEBUG_VERBOSE, "rigsmtr, %s\n", hamlib_version); case 'V':
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to " version();
"<hamlib-developer@lists.sourceforge.net>\n\n"); exit(0);
/* case 'm':
* The radio if (!optarg) {
*/ usage(); /* wrong arg count */
rig = rig_init(rig_model); exit(1);
}
if (!rig) { rig_model = atoi(optarg);
fprintf(stderr, "Unknown rig num %d, or initialization error.\n", break;
rig_model);
fprintf(stderr, "Please check with --list option.\n");
exit(2);
}
retcode = set_conf_rig(rig, rig_conf_parms); case 'r':
if (retcode != RIG_OK) { if (!optarg) {
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); usage(); /* wrong arg count */
exit(2); exit(1);
} }
if (rig_file) rig_file = optarg;
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); break;
/* FIXME: bound checking and port type == serial */ case 'c':
if (serial_rate != 0) if (!optarg) {
rig->state.rigport.parm.serial.rate = serial_rate; usage(); /* wrong arg count */
if (civaddr) exit(1);
rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr); }
civaddr = optarg;
break;
case 's':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
serial_rate = atoi(optarg);
break;
case 'C':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
if (*rig_conf_parms != '\0') {
strcat(rig_conf_parms, ",");
}
strncat(rig_conf_parms, optarg, MAXCONFLEN - strlen(rig_conf_parms));
break;
case 'M':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
rot_model = atoi(optarg);
break;
case 'R':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
rot_file = optarg;
break;
case 'S':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
rot_serial_rate = atoi(optarg);
break;
case 'N':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
if (*rot_conf_parms != '\0') {
strcat(rot_conf_parms, ",");
}
strncat(rot_conf_parms, optarg, MAXCONFLEN - strlen(rot_conf_parms));
break;
case 'v':
verbose++;
break;
default:
usage(); /* unknown option? */
exit(1);
}
}
rig_set_debug(verbose < 2 ? RIG_DEBUG_WARN : verbose);
rig_debug(RIG_DEBUG_VERBOSE, "rigsmtr, %s\n", hamlib_version);
rig_debug(RIG_DEBUG_VERBOSE,
"Report bugs to <hamlib-developer@lists.sourceforge.net>\n\n");
/*
* The radio
*/
rig = rig_init(rig_model);
if (!rig) {
fprintf(stderr,
"Unknown rig num %d, or initialization error.\n",
rig_model);
fprintf(stderr, "Please check with --list option.\n");
exit(2);
}
retcode = set_conf_rig(rig, rig_conf_parms);
if (retcode != RIG_OK) {
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (rig_file) {
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0) {
rig->state.rigport.parm.serial.rate = serial_rate;
}
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" fprintf(stderr,
"or has unsufficient capability\nSorry\n", "rig backend for %s could not get S-Meter"
rig->caps->model_name); "or has unsufficient capability\nSorry\n",
exit(3); rig->caps->model_name);
} exit(3);
}
retcode = rig_open(rig); retcode = rig_open(rig);
if (retcode != RIG_OK) {
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) if (retcode != RIG_OK) {
printf("Opened rig model %d, '%s'\n", rig->caps->rig_model, fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
rig->caps->model_name); exit(2);
}
/* if (verbose > 0) {
* The rotator printf("Opened rig model %d, '%s'\n",
*/ rig->caps->rig_model,
rot = rot_init(rot_model); rig->caps->model_name);
}
if (!rot) { /*
fprintf(stderr, "Unknown rot num %d, or initialization error.\n", * The rotator
rot_model); */
fprintf(stderr, "Please check with --list option.\n"); rot = rot_init(rot_model);
exit(2);
}
retcode = set_conf_rot(rot, rot_conf_parms); if (!rot) {
if (retcode != RIG_OK) { fprintf(stderr,
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); "Unknown rot num %d, or initialization error.\n",
exit(2); rot_model);
}
if (rot_file) fprintf(stderr, "Please check with --list option.\n");
strncpy(rot->state.rotport.pathname, rot_file, FILPATHLEN - 1); exit(2);
}
/* FIXME: bound checking and port type == serial */ retcode = set_conf_rot(rot, rot_conf_parms);
if (rot_serial_rate != 0)
rot->state.rotport.parm.serial.rate = rot_serial_rate;
retcode = rot_open(rot); if (retcode != RIG_OK) {
if (retcode != RIG_OK && rot_model != ROT_MODEL_DUMMY) { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
fprintf(stderr,"rot_open: error = %s \n", rigerror(retcode)); exit(2);
exit(2); }
}
/* Commenting out to quell "set but not used" warning. if (rot_file) {
* Enable when needed for further functionality. -N0NB strncpy(rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
*/ }
/* if (rot_model == ROT_MODEL_DUMMY) */
/* with_rot = 1; */
if (verbose > 0) /* FIXME: bound checking and port type == serial */
printf("Opened rotator model %d, '%s'\n", rot->caps->rot_model, if (rot_serial_rate != 0) {
rot->caps->model_name); rot->state.rotport.parm.serial.rate = rot_serial_rate;
}
retcode = rot_open(rot);
/*******************************/ if (retcode != RIG_OK && rot_model != ROT_MODEL_DUMMY) {
if (optind < argc) fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
step = atof(argv[optind])*1e6; exit(2);
}
fprintf(stderr,"Setting rotator to azimuth %.1f°\n",rot->state.min_az); /* Commenting out to quell "set but not used" warning.
rot_set_position (rot, rot->state.min_az, 0); * Enable when needed for further functionality. -N0NB
fprintf(stderr,"Wait for rotator to move...\n"); */
rot_get_position (rot, &azimuth, &elevation); /* if (rot_model == ROT_MODEL_DUMMY) */
while (fabs(azimuth - rot->state.min_az) > 1.) { /* with_rot = 1; */
rot_get_position (rot, &azimuth, &elevation);
usleep(step);
}
fprintf(stderr,"Now initiating full 360° rotation...\n"); if (verbose > 0) {
rot_set_position (rot, rot->state.max_az, 0); printf("Opened rotator model %d, '%s'\n",
rot->caps->rot_model,
rot->caps->model_name);
}
/* TODO: check CW or CCW */ /*******************************/
/* disable AGC? */ if (optind < argc) {
step = atof(argv[optind]) * 1e6;
}
while (fabs(rot->state.max_az - azimuth) > 1.) { fprintf(stderr, "Setting rotator to azimuth %.1f°\n", rot->state.min_az);
value_t strength; rot_set_position(rot, rot->state.min_az, 0);
fprintf(stderr, "Wait for rotator to move...\n");
rot_get_position(rot, &azimuth, &elevation);
rig_get_level(rig,RIG_VFO_CURR,RIG_LEVEL_STRENGTH,&strength); while (fabs(azimuth - rot->state.min_az) > 1.) {
rot_get_position(rot, &azimuth, &elevation);
usleep(step);
}
rot_get_position (rot, &azimuth, &elevation); fprintf(stderr, "Now initiating full 360° rotation...\n");
rot_set_position(rot, rot->state.max_az, 0);
printf("%.1f %d\n", azimuth, strength.i); /* TODO: check CW or CCW */
} /* disable AGC? */
rig_close(rig); while (fabs(rot->state.max_az - azimuth) > 1.) {
rot_close(rot); value_t strength;
return 0; rig_get_level(rig, RIG_VFO_CURR, RIG_LEVEL_STRENGTH, &strength);
rot_get_position(rot, &azimuth, &elevation);
printf("%.1f %d\n", azimuth, strength.i);
}
rig_close(rig);
rot_close(rot);
return 0;
} }
void version() void version()
{ {
printf("rigsmtr, %s\n\n", hamlib_version); printf("rigsmtr, %s\n\n", hamlib_version);
printf("%s\n", hamlib_copyright); printf("%s\n", hamlib_copyright);
} }
void usage() void usage()
{ {
printf("Usage: rigsmtr [OPTION]... [time]\n" printf("Usage: rigsmtr [OPTION]... [time]\n"
"Input S-Meter vs Azimuth.\n\n"); "Input S-Meter vs Azimuth.\n\n");
printf( printf(
" -m, --model=ID select radio model number. See model list\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" " -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" " -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, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -C, --set-conf=PARM=VAL set config parameters\n" " -C, --set-conf=PARM=VAL set config parameters\n"
" -M, --rot-model=ID select rotator model number. See model list\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" " -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" " -S, --rot-serial-speed=BAUD set serial speed of the serial port\n"
" -N, --rot-set-conf=PARM=VAL set rotator config parameters\n" " -N, --rot-set-conf=PARM=VAL set rotator config parameters\n"
" -v, --verbose set verbose mode, cumulative\n" " -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n" " -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n" " -V, --version output version information and exit\n\n"
); );
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n"); printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
} }
int set_conf_rig(RIG *rig, char *conf_parms) int set_conf_rig(RIG *rig, char *conf_parms)
{ {
char *p, *q, *n; char *p, *q, *n;
int ret; int ret;
p = conf_parms; p = conf_parms;
while (p && *p != '\0') {
/* FIXME: left hand value of = cannot be null */
q = strchr(p, '=');
if ( !q )
return RIG_EINVAL;
*q++ = '\0';
n = strchr(q, ',');
if (n) *n++ = '\0';
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q); while (p && *p != '\0') {
if (ret != RIG_OK) /* FIXME: left hand value of = cannot be null */
return ret; q = strchr(p, '=');
p = n;
} if (!q) {
return RIG_OK; return RIG_EINVAL;
}
*q++ = '\0';
n = strchr(q, ',');
if (n) {
*n++ = '\0';
}
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q);
if (ret != RIG_OK) {
return ret;
}
p = n;
}
return RIG_OK;
} }
int set_conf_rot(ROT *rot, char *conf_parms) int set_conf_rot(ROT *rot, char *conf_parms)
{ {
char *p, *q, *n; char *p, *q, *n;
int ret; int ret;
p = conf_parms; p = conf_parms;
while (p && *p != '\0') {
/* FIXME: left hand value of = cannot be null */
q = strchr(p, '=');
if (q) *q++ = '\0';
n = strchr(q, ',');
if (n) *n++ = '\0';
ret = rot_set_conf(rot, rot_token_lookup(rot, p), q); while (p && *p != '\0') {
if (ret != RIG_OK) /* FIXME: left hand value of = cannot be null */
return ret; q = strchr(p, '=');
p = n;
} if (q) {
return RIG_OK; *q++ = '\0';
}
n = strchr(q, ',');
if (n) {
*n++ = '\0';
}
ret = rot_set_conf(rot, rot_token_lookup(rot, p), q);
if (ret != RIG_OK) {
return ret;
}
p = n;
}
return RIG_OK;
} }

Wyświetl plik

@ -1,8 +1,7 @@
/* /*
* rigswr.c - (C) Stephane Fillod and Thierry Leconte 2004 * rigswr.c - (C) Stephane Fillod and Thierry Leconte 2004
* *
* This program output swr curve value * This program outputs an swr curve value using Hamlib.
* using Hamlib.
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -22,7 +21,7 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -51,266 +50,317 @@ static int set_conf(RIG *rig, char *conf_parms);
* NB: do NOT use -W since it's reserved by POSIX. * NB: do NOT use -W since it's reserved by POSIX.
*/ */
#define SHORT_OPTIONS "m:r:s:c:C:p:P:vhV" #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'},
{"model", 1, 0, 'm'}, {"rig-file", 1, 0, 'r'},
{"rig-file", 1, 0, 'r'}, {"serial-speed", 1, 0, 's'},
{"serial-speed", 1, 0, 's'}, {"civaddr", 1, 0, 'c'},
{"civaddr", 1, 0, 'c'}, {"set-conf", 1, 0, 'C'},
{"set-conf", 1, 0, 'C'}, {"ptt-file", 1, 0, 'p'},
{"ptt-file", 1, 0, 'p'}, {"ptt-type", 1, 0, 'P'},
{"ptt-type", 1, 0, 'P'}, {"verbose", 0, 0, 'v'},
{"verbose", 0, 0, 'v'}, {"help", 0, 0, 'h'},
{"help", 0, 0, 'h'}, {"version", 0, 0, 'V'},
{"version", 0, 0, 'V'}, {0, 0, 0, 0}
{0, 0, 0, 0}
}; };
#define MAXCONFLEN 128 #define MAXCONFLEN 128
int main (int argc, char *argv[]) int main(int argc, char *argv[])
{ {
RIG *rig; /* handle to rig (nstance) */ RIG *rig; /* handle to rig (nstance) */
rig_model_t my_model = RIG_MODEL_DUMMY; rig_model_t my_model = RIG_MODEL_DUMMY;
int retcode; /* generic return code from functions */ int retcode; /* generic return code from functions */
int verbose = 0; int verbose = 0;
const char *rig_file=NULL, *ptt_file=NULL; const char *rig_file = NULL, *ptt_file = NULL;
ptt_type_t ptt_type = RIG_PTT_NONE; ptt_type_t ptt_type = RIG_PTT_NONE;
int serial_rate = 0; int serial_rate = 0;
char *civaddr = NULL; /* NULL means no need to set conf */ char *civaddr = NULL; /* NULL means no need to set conf */
char conf_parms[MAXCONFLEN] = ""; char conf_parms[MAXCONFLEN] = "";
freq_t freq,freqstop; freq_t freq, freqstop;
freq_t step=kHz(100); freq_t step = kHz(100);
value_t pwr; value_t pwr;
while(1) { while (1) {
int c; int c;
int option_index = 0; int option_index = 0;
c = getopt_long (argc, argv, SHORT_OPTIONS, c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
long_options, &option_index);
if (c == -1)
break;
switch(c) { if (c == -1) {
case 'h': break;
usage(); }
exit(0);
case 'V':
version();
exit(0);
case 'm':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
my_model = atoi(optarg);
break;
case 'r':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
rig_file = optarg;
break;
case 'c':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
civaddr = optarg;
break;
case 's':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
serial_rate = atoi(optarg);
break;
case 'C':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
if (*conf_parms != '\0')
strcat(conf_parms, ",");
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
break;
case 'p':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
ptt_file = optarg;
break;
case 'P':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
if (!strcmp(optarg, "RIG"))
ptt_type = RIG_PTT_RIG;
else if (!strcmp(optarg, "DTR"))
ptt_type = RIG_PTT_SERIAL_DTR;
else if (!strcmp(optarg, "RTS"))
ptt_type = RIG_PTT_SERIAL_RTS;
else if (!strcmp(optarg, "PARALLEL"))
ptt_type = RIG_PTT_PARALLEL;
else if (!strcmp(optarg, "NONE"))
ptt_type = RIG_PTT_NONE;
else
ptt_type = atoi(optarg);
break;
case 'v':
verbose++;
break;
default:
usage(); /* unknown option? */
exit(1);
}
}
rig_set_debug(verbose<2 ? RIG_DEBUG_WARN: verbose); switch (c) {
case 'h':
usage();
exit(0);
rig_debug(RIG_DEBUG_VERBOSE, "rigswr, %s\n", hamlib_version); case 'V':
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to " version();
"<hamlib-developer@lists.sourceforge.net>\n\n"); exit(0);
if (optind+1 >= argc) { case 'm':
usage(); if (!optarg) {
exit(1); usage(); /* wrong arg count */
} exit(1);
}
rig = rig_init(my_model); my_model = atoi(optarg);
break;
if (!rig) { case 'r':
fprintf(stderr, "Unknown rig num %d, or initialization error.\n", if (!optarg) {
my_model); usage(); /* wrong arg count */
fprintf(stderr, "Please check with --list option.\n"); exit(1);
exit(2); }
}
retcode = set_conf(rig, conf_parms); rig_file = optarg;
if (retcode != RIG_OK) { break;
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (ptt_type != RIG_PTT_NONE) case 'c':
rig->state.pttport.type.ptt = ptt_type; if (!optarg) {
if (ptt_file) usage(); /* wrong arg count */
strncpy(rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1); exit(1);
}
if (rig_file) civaddr = optarg;
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); break;
/* FIXME: bound checking and port type == serial */ case 's':
if (serial_rate != 0) if (!optarg) {
rig->state.rigport.parm.serial.rate = serial_rate; usage(); /* wrong arg count */
if (civaddr) exit(1);
rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr); }
serial_rate = atoi(optarg);
break;
case 'C':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
if (*conf_parms != '\0') {
strcat(conf_parms, ",");
}
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
break;
case 'p':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
ptt_file = optarg;
break;
case 'P':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
if (!strcmp(optarg, "RIG")) {
ptt_type = RIG_PTT_RIG;
} else if (!strcmp(optarg, "DTR")) {
ptt_type = RIG_PTT_SERIAL_DTR;
} else if (!strcmp(optarg, "RTS")) {
ptt_type = RIG_PTT_SERIAL_RTS;
} else if (!strcmp(optarg, "PARALLEL")) {
ptt_type = RIG_PTT_PARALLEL;
} else if (!strcmp(optarg, "NONE")) {
ptt_type = RIG_PTT_NONE;
} else {
ptt_type = atoi(optarg);
}
break;
case 'v':
verbose++;
break;
default:
usage(); /* unknown option? */
exit(1);
}
}
rig_set_debug(verbose < 2 ? RIG_DEBUG_WARN : verbose);
rig_debug(RIG_DEBUG_VERBOSE, "rigswr, %s\n", hamlib_version);
rig_debug(RIG_DEBUG_VERBOSE,
"Report bugs to <hamlib-developer@lists.sourceforge.net>\n\n");
if (optind + 1 >= argc) {
usage();
exit(1);
}
rig = rig_init(my_model);
if (!rig) {
fprintf(stderr,
"Unknown rig num %d, or initialization error.\n",
my_model);
fprintf(stderr, "Please check with --list option.\n");
exit(2);
}
retcode = set_conf(rig, conf_parms);
if (retcode != RIG_OK) {
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (ptt_type != RIG_PTT_NONE) {
rig->state.pttport.type.ptt = ptt_type;
}
if (ptt_file) {
strncpy(rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
}
if (rig_file) {
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0) {
rig->state.rigport.parm.serial.rate = serial_rate;
}
if (civaddr) {
rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr);
}
if(!rig_has_get_level(rig,RIG_LEVEL_SWR) || 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"
"or has unsufficient capability\nSorry\n",
rig->caps->model_name);
exit(3);
}
retcode = rig_open(rig); fprintf(stderr,
if (retcode != RIG_OK) { "rig backend for %s could not get SWR"
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode)); "or has unsufficient capability\nSorry\n",
exit(2); rig->caps->model_name);
}
if (verbose > 0) exit(3);
printf("Opened rig model %d, '%s'\n", rig->caps->rig_model, }
rig->caps->model_name);
freq=atof(argv[optind++]); retcode = rig_open(rig);
freqstop=atof(argv[optind++]);
if (optind < argc)
step=atof(argv[optind]);
rig_set_freq(rig,RIG_VFO_CURR,freq); if (retcode != RIG_OK) {
rig_set_mode(rig,RIG_VFO_CURR,RIG_MODE_CW,RIG_PASSBAND_NORMAL); fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
exit(2);
}
pwr.f = 0.25; /* 25% of RF POWER */ if (verbose > 0) {
rig_set_level(rig,RIG_VFO_CURR,RIG_LEVEL_RFPOWER,pwr); printf("Opened rig model %d, '%s'\n",
rig->caps->rig_model,
rig->caps->model_name);
}
while(freq<=freqstop) { freq = atof(argv[optind++]);
value_t swr; freqstop = atof(argv[optind++]);
rig_set_ptt(rig,RIG_VFO_CURR,RIG_PTT_ON); if (optind < argc) {
usleep(500000); step = atof(argv[optind]);
rig_get_level(rig,RIG_VFO_CURR,RIG_LEVEL_SWR,&swr); }
rig_set_ptt(rig,RIG_VFO_CURR,RIG_PTT_OFF);
printf("%10.0f %4.2f\n",freq,swr.f); rig_set_freq(rig, RIG_VFO_CURR, freq);
freq+=step; rig_set_mode(rig, RIG_VFO_CURR, RIG_MODE_CW, RIG_PASSBAND_NORMAL);
rig_set_freq(rig,RIG_VFO_CURR,freq);
}
rig_close(rig); pwr.f = 0.25; /* 25% of RF POWER */
rig_set_level(rig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, pwr);
return 0; while (freq <= freqstop) {
value_t swr;
rig_set_ptt(rig, RIG_VFO_CURR, RIG_PTT_ON);
usleep(500000);
rig_get_level(rig, RIG_VFO_CURR, RIG_LEVEL_SWR, &swr);
rig_set_ptt(rig, RIG_VFO_CURR, RIG_PTT_OFF);
printf("%10.0f %4.2f\n", freq, swr.f);
freq += step;
rig_set_freq(rig, RIG_VFO_CURR, freq);
}
rig_close(rig);
return 0;
} }
void version() void version()
{ {
printf("rigswr, %s\n\n", hamlib_version); printf("rigswr, %s\n\n", hamlib_version);
printf("%s\n", hamlib_copyright); printf("%s\n", hamlib_copyright);
} }
void usage() void usage()
{ {
printf("Usage: rigswr [OPTION]... start_freq stop_freq [freq_step]\n" printf("Usage: rigswr [OPTION]... start_freq stop_freq [freq_step]\n"
"Output SWR vs Frequency.\n\n"); "Output SWR vs Frequency.\n\n");
printf( printf(
" -m, --model=ID select radio model number. See model list\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" " -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" " -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, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -C, --set-conf=PARM=VAL set config parameters\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-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" " -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
" -v, --verbose set verbose mode, cumulative\n" " -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n" " -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n" " -V, --version output version information and exit\n\n"
); );
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n"); printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
} }
int set_conf(RIG *rig, char *conf_parms) int set_conf(RIG *rig, char *conf_parms)
{ {
char *p, *q, *n; char *p, *q, *n;
int ret; int ret;
p = conf_parms; p = conf_parms;
while (p && *p != '\0') {
/* FIXME: left hand value of = cannot be null */
q = strchr(p, '=');
if ( !q )
return RIG_EINVAL;
*q++ = '\0';
n = strchr(q, ',');
if (n) *n++ = '\0';
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q); while (p && *p != '\0') {
if (ret != RIG_OK) /* FIXME: left hand value of = cannot be null */
return ret; q = strchr(p, '=');
p = n;
} if (!q) {
return RIG_OK; return RIG_EINVAL;
}
*q++ = '\0';
n = strchr(q, ',');
if (n) {
*n++ = '\0';
}
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q);
if (ret != RIG_OK) {
return ret;
}
p = n;
}
return RIG_OK;
} }

Wyświetl plik

@ -25,7 +25,7 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -42,7 +42,7 @@
# elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */ # elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */
# include <readline.h> # include <readline.h>
# else /* !defined(HAVE_READLINE_H) */ # else /* !defined(HAVE_READLINE_H) */
extern char *readline (); extern char *readline();
# endif /* HAVE_READLINE_H */ # endif /* HAVE_READLINE_H */
#else #else
/* no readline */ /* no readline */
@ -56,9 +56,9 @@ extern char *readline ();
# elif defined(HAVE_HISTORY_H) # elif defined(HAVE_HISTORY_H)
# include <history.h> # include <history.h>
# else /* !defined(HAVE_HISTORY_H) */ # else /* !defined(HAVE_HISTORY_H) */
extern void add_history (); extern void add_history();
extern int write_history (); extern int write_history();
extern int read_history (); extern int read_history();
# endif /* defined(HAVE_READLINE_HISTORY_H) */ # endif /* defined(HAVE_READLINE_HISTORY_H) */
#else #else
/* no history */ /* no history */
@ -83,24 +83,23 @@ void usage();
* TODO: add an option to read from a file * TODO: add an option to read from a file
*/ */
#define SHORT_OPTIONS "+m:r:s:C:t:LvhVlu" #define SHORT_OPTIONS "+m:r:s:C:t:LvhVlu"
static struct option long_options[] = static struct option long_options[] = {
{ {"model", 1, 0, 'm'},
{"model", 1, 0, 'm'}, {"rot-file", 1, 0, 'r'},
{"rot-file", 1, 0, 'r'}, {"serial-speed", 1, 0, 's'},
{"serial-speed", 1, 0, 's'}, {"send-cmd-term", 1, 0, 't'},
{"send-cmd-term", 1, 0, 't'}, {"list", 0, 0, 'l'},
{"list", 0, 0, 'l'}, {"set-conf", 1, 0, 'C'},
{"set-conf", 1, 0, 'C'}, {"show-conf", 0, 0, 'L'},
{"show-conf",0, 0, 'L'}, {"dump-caps", 0, 0, 'u'},
{"dump-caps",0, 0, 'u'},
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
{"read-history", 0, 0, 'i'}, {"read-history", 0, 0, 'i'},
{"save-history", 0, 0, 'I'}, {"save-history", 0, 0, 'I'},
#endif #endif
{"verbose", 0, 0, 'v'}, {"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{"version", 0, 0, 'V'}, {"version", 0, 0, 'V'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
#define MAXCONFLEN 128 #define MAXCONFLEN 128
@ -116,261 +115,322 @@ static const int have_rl = 0;
int interactive = 1; /* if no cmd on command line, switch to interactive */ int interactive = 1; /* if no cmd on command line, switch to interactive */
int prompt = 1; /* Print prompt in rotctl */ int prompt = 1; /* Print prompt in rotctl */
char send_cmd_term = '\r'; /* send_cmd termination char */ char send_cmd_term = '\r'; /* send_cmd termination char */
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{ {
ROT *my_rot; /* handle to rot (instance) */ ROT *my_rot; /* handle to rot (instance) */
rot_model_t my_model = ROT_MODEL_DUMMY; rot_model_t my_model = ROT_MODEL_DUMMY;
int retcode; /* generic return code from functions */ int retcode; /* generic return code from functions */
int exitcode; int exitcode;
int verbose = 0; int verbose = 0;
int show_conf = 0; int show_conf = 0;
int dump_caps_opt = 0; int dump_caps_opt = 0;
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
int rd_hist = 0; int rd_hist = 0;
int sv_hist = 0; int sv_hist = 0;
const char *hist_dir = NULL; const char *hist_dir = NULL;
const char hist_file[] = "/.rotctl_history"; const char hist_file[] = "/.rotctl_history";
char *hist_path = NULL; char *hist_path = NULL;
struct stat hist_dir_stat; struct stat hist_dir_stat;
#endif #endif
const char *rot_file=NULL; const char *rot_file = NULL;
int serial_rate = 0; int serial_rate = 0;
char conf_parms[MAXCONFLEN] = ""; char conf_parms[MAXCONFLEN] = "";
while(1) { while (1) {
int c; int c;
int option_index = 0; int option_index = 0;
c = getopt_long (argc, argv, SHORT_OPTIONS HST_SHRT_OPTS, c = getopt_long(argc,
long_options, &option_index); argv,
if (c == -1) SHORT_OPTIONS HST_SHRT_OPTS,
break; long_options,
&option_index);
switch(c) { if (c == -1) {
case 'h': break;
usage(); }
exit(0);
case 'V': switch (c) {
version(); case 'h':
exit(0); usage();
case 'm': exit(0);
if (!optarg) {
usage(); /* wrong arg count */ case 'V':
exit(1); version();
} exit(0);
my_model = atoi(optarg);
break; case 'm':
case 'r': if (!optarg) {
if (!optarg) { usage(); /* wrong arg count */
usage(); /* wrong arg count */ exit(1);
exit(1); }
}
rot_file = optarg; my_model = atoi(optarg);
break; break;
case 's':
if (!optarg) { case 'r':
usage(); /* wrong arg count */ if (!optarg) {
exit(1); usage(); /* wrong arg count */
} exit(1);
serial_rate = atoi(optarg); }
break;
case 'C': rot_file = optarg;
if (!optarg) { break;
usage(); /* wrong arg count */
exit(1); case 's':
} if (!optarg) {
if (*conf_parms != '\0') usage(); /* wrong arg count */
strcat(conf_parms, ","); exit(1);
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms)); }
break;
case 't': serial_rate = atoi(optarg);
if (!optarg) { break;
usage(); /* wrong arg count */
exit(1); case 'C':
} if (!optarg) {
if (strlen(optarg) > 1) usage(); /* wrong arg count */
send_cmd_term = strtol(optarg, NULL, 0); exit(1);
else }
send_cmd_term = optarg[0];
break; if (*conf_parms != '\0') {
strcat(conf_parms, ",");
}
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
break;
case 't':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
if (strlen(optarg) > 1) {
send_cmd_term = strtol(optarg, NULL, 0);
} else {
send_cmd_term = optarg[0];
}
break;
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
case 'i':
rd_hist++; case 'i':
break; rd_hist++;
case 'I': break;
sv_hist++;
break; case 'I':
sv_hist++;
break;
#endif #endif
case 'v':
verbose++;
break;
case 'L':
show_conf++;
break;
case 'l':
rig_set_debug(0);
list_models();
exit(0);
case 'u':
dump_caps_opt++;
break;
default:
usage(); /* unknown option? */
exit(1);
}
}
rig_set_debug(verbose); case 'v':
verbose++;
break;
rig_debug(RIG_DEBUG_VERBOSE, "rotctl, %s\n", hamlib_version); case 'L':
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to " show_conf++;
"<hamlib-developer@lists.sourceforge.net>\n\n"); break;
/* case 'l':
* at least one command on command line, rig_set_debug(0);
* disable interactive mode list_models();
*/ exit(0);
if (optind < argc)
interactive = 0;
my_rot = rot_init(my_model); case 'u':
dump_caps_opt++;
break;
if (!my_rot) { default:
fprintf(stderr, "Unknown rot num %d, or initialization error.\n", usage(); /* unknown option? */
my_model); exit(1);
fprintf(stderr, "Please check with --list option.\n"); }
exit(2); }
}
retcode = set_conf(my_rot, conf_parms); rig_set_debug(verbose);
if (retcode != RIG_OK) {
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (rot_file) rig_debug(RIG_DEBUG_VERBOSE, "rotctl, %s\n", hamlib_version);
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1); rig_debug(RIG_DEBUG_VERBOSE,
"Report bugs to <hamlib-developer@lists.sourceforge.net>\n\n");
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0)
my_rot->state.rotport.parm.serial.rate = serial_rate;
/*
* print out conf parameters
*/
if (show_conf) {
rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
}
/* /*
* print out capabilities, and exists immediately * at least one command on command line,
* We may be interested only in caps, and rig_open may fail. * disable interactive mode
*/
if (optind < argc) {
interactive = 0;
}
my_rot = rot_init(my_model);
if (!my_rot) {
fprintf(stderr,
"Unknown rot num %d, or initialization error.\n",
my_model);
fprintf(stderr, "Please check with --list option.\n");
exit(2);
}
retcode = set_conf(my_rot, conf_parms);
if (retcode != RIG_OK) {
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (rot_file) {
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0) {
my_rot->state.rotport.parm.serial.rate = serial_rate;
}
/*
* print out conf parameters
*/
if (show_conf) {
rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
}
/*
* 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); dumpcaps_rot(my_rot, stdout);
rot_cleanup(my_rot); /* if you care about memory */ rot_cleanup(my_rot); /* if you care about memory */
exit(0); exit(0);
} }
retcode = rot_open(my_rot); retcode = rot_open(my_rot);
if (retcode != RIG_OK) {
fprintf(stderr,"rot_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) if (retcode != RIG_OK) {
printf("Opened rot model %d, '%s'\n", my_rot->caps->rot_model, fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
my_rot->caps->model_name); exit(2);
}
rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n", if (verbose > 0) {
my_rot->caps->version, rig_strstatus(my_rot->caps->status)); printf("Opened rot model %d, '%s'\n",
my_rot->caps->rot_model,
my_rot->caps->model_name);
}
exitcode = 0; rig_debug(RIG_DEBUG_VERBOSE,
"Backend version: %s, Status: %s\n",
my_rot->caps->version,
rig_strstatus(my_rot->caps->status));
exitcode = 0;
#ifdef HAVE_LIBREADLINE #ifdef HAVE_LIBREADLINE
if (interactive && prompt && have_rl) {
rl_readline_name = "rotctl"; if (interactive && prompt && have_rl) {
rl_readline_name = "rotctl";
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
using_history(); /* Initialize Readline History */ using_history(); /* Initialize Readline History */
if (rd_hist || sv_hist) { if (rd_hist || sv_hist) {
if (!(hist_dir = getenv("ROTCTL_HIST_DIR"))) if (!(hist_dir = getenv("ROTCTL_HIST_DIR"))) {
hist_dir = getenv("HOME"); hist_dir = getenv("HOME");
}
if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT)) 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);
}
hist_path = (char *)calloc((sizeof(char) * (strlen(hist_dir) + strlen(hist_file) + 1)), sizeof(char)); fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir);
}
strncpy(hist_path, hist_dir, strlen(hist_dir)); hist_path = (char *)calloc((sizeof(char)
strncat(hist_path, hist_file, strlen(hist_file)); * (strlen(hist_dir)
} + strlen(hist_file) + 1)),
sizeof(char));
strncpy(hist_path, hist_dir, strlen(hist_dir));
strncat(hist_path, hist_file, strlen(hist_file));
}
if (rd_hist && hist_path) {
if (read_history(hist_path) == ENOENT) {
fprintf(stderr,
"Warning: Could not read history from %s\n",
hist_path);
}
}
if (rd_hist && hist_path)
if (read_history(hist_path) == ENOENT)
fprintf(stderr, "Warning: Could not read history from %s\n", hist_path);
#endif #endif
} }
#endif /* HAVE_LIBREADLINE */
do { #endif /* HAVE_LIBREADLINE */
retcode = rotctl_parse(my_rot, stdin, stdout, argv, argc);
if (retcode == 2) do {
exitcode = 2; retcode = rotctl_parse(my_rot, stdin, stdout, argv, argc);
}
while (retcode == 0 || retcode == 2); if (retcode == 2) {
exitcode = 2;
}
} while (retcode == 0 || retcode == 2);
#ifdef HAVE_LIBREADLINE #ifdef HAVE_LIBREADLINE
if (interactive && prompt && have_rl) {
if (interactive && prompt && have_rl) {
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
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 (sv_hist && hist_path) {
free(hist_path); if (write_history(hist_path) == ENOENT) {
hist_path = (char *)NULL; fprintf(stderr,
} "\nWarning: Could not write history to %s\n",
#endif hist_path);
} }
#endif }
rot_close(my_rot); /* close port */
rot_cleanup(my_rot); /* if you care about memory */
return exitcode; if ((rd_hist || sv_hist) && hist_path) {
free(hist_path);
hist_path = (char *)NULL;
}
#endif
}
#endif
rot_close(my_rot); /* close port */
rot_cleanup(my_rot); /* if you care about memory */
return exitcode;
} }
void usage() void usage()
{ {
printf("Usage: rotctl [OPTION]... [COMMAND]...\n" printf("Usage: rotctl [OPTION]... [COMMAND]...\n"
"Send COMMANDs to a connected antenna rotator.\n\n"); "Send COMMANDs to a connected antenna rotator.\n\n");
printf( printf(
" -m, --model=ID select rotator model number. See model list\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" " -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" " -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -t, --send-cmd-term=CHAR set send_cmd command termination char\n" " -t, --send-cmd-term=CHAR set send_cmd command termination char\n"
" -C, --set-conf=PARM=VAL set config parameters\n" " -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n" " -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n" " -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n" " -u, --dump-caps dump capabilities and exit\n"
#ifdef HAVE_READLINE_HISTORY #ifdef HAVE_READLINE_HISTORY
" -i, --read-history read prior interactive session history\n" " -i, --read-history read prior interactive session history\n"
" -I, --save-history save current interactive session history\n" " -I, --save-history save current interactive session history\n"
#endif #endif
" -v, --verbose set verbose mode, cumulative\n" " -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n" " -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n" " -V, --version output version information and exit\n\n"
); );
usage_rot(stdout); usage_rot(stdout);
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n"); printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
} }

Plik diff jest za duży Load Diff

Wyświetl plik

@ -32,7 +32,7 @@
* external prototype * external prototype
*/ */
int dumpcaps_rot (ROT *, FILE *); int dumpcaps_rot(ROT *, FILE *);
/* /*
@ -46,4 +46,4 @@ int set_conf(ROT *my_rot, char *conf_parms);
int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc); int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc);
#endif /* ROTCTL_PARSE_H */ #endif /* ROTCTL_PARSE_H */

Wyświetl plik

@ -23,7 +23,7 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -39,26 +39,26 @@
#include <sys/types.h> /* See NOTES */ #include <sys/types.h> /* See NOTES */
#ifdef HAVE_NETINET_IN_H #ifdef HAVE_NETINET_IN_H
# include <netinet/in.h> # include <netinet/in.h>
#endif #endif
#ifdef HAVE_ARPA_INET_H #ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h> # include <arpa/inet.h>
#endif #endif
#ifdef HAVE_SYS_SOCKET_H #ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h> # include <sys/socket.h>
#elif HAVE_WS2TCPIP_H #elif HAVE_WS2TCPIP_H
# include <ws2tcpip.h> # include <ws2tcpip.h>
# include <fcntl.h> # include <fcntl.h>
# if defined(HAVE_WSPIAPI_H) # if defined(HAVE_WSPIAPI_H)
# include <wspiapi.h> # include <wspiapi.h>
# endif # endif
#endif #endif
#ifdef HAVE_NETDB_H #ifdef HAVE_NETDB_H
# include <netdb.h> # include <netdb.h>
#endif #endif
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
# include <pthread.h> # include <pthread.h>
#endif #endif
#include <hamlib/rotator.h> #include <hamlib/rotator.h>
@ -67,13 +67,13 @@
#include "rotctl_parse.h" #include "rotctl_parse.h"
struct handle_data { struct handle_data {
ROT *rot; ROT *rot;
int sock; int sock;
struct sockaddr_storage cli_addr; struct sockaddr_storage cli_addr;
socklen_t clilen; socklen_t clilen;
}; };
void *handle_socket(void *arg); void * handle_socket(void *arg);
void usage(); void usage();
@ -85,245 +85,258 @@ void usage();
*/ */
#define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVl" #define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVl"
static struct option long_options[] = { static struct option long_options[] = {
{"model", 1, 0, 'm'}, {"model", 1, 0, 'm'},
{"rot-file", 1, 0, 'r'}, {"rot-file", 1, 0, 'r'},
{"serial-speed", 1, 0, 's'}, {"serial-speed", 1, 0, 's'},
{"port", 1, 0, 't'}, {"port", 1, 0, 't'},
{"listen-addr", 1, 0, 'T'}, {"listen-addr", 1, 0, 'T'},
{"list", 0, 0, 'l'}, {"list", 0, 0, 'l'},
{"set-conf", 1, 0, 'C'}, {"set-conf", 1, 0, 'C'},
{"show-conf", 0, 0, 'L'}, {"show-conf", 0, 0, 'L'},
{"dump-caps", 0, 0, 'u'}, {"dump-caps", 0, 0, 'u'},
{"verbose", 0, 0, 'v'}, {"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{"version", 0, 0, 'V'}, {"version", 0, 0, 'V'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
int interactive = 1; /* no cmd because of daemon */ int interactive = 1; /* no cmd because of daemon */
int prompt = 0 ; /* Daemon mode for rigparse return string */ int prompt = 0 ; /* Daemon mode for rigparse return string */
const char *portno = "4533"; const char *portno = "4533";
const char *src_addr = NULL; /* INADDR_ANY */ const char *src_addr = NULL; /* INADDR_ANY */
char send_cmd_term = '\r'; /* send_cmd termination char */ char send_cmd_term = '\r'; /* send_cmd termination char */
#define MAXCONFLEN 128 #define MAXCONFLEN 128
static void handle_error(enum rig_debug_level_e lvl, const char *msg) static void handle_error(enum rig_debug_level_e lvl, const char *msg)
{ {
int e; int e;
#ifdef __MINGW32__ #ifdef __MINGW32__
LPVOID lpMsgBuf; LPVOID lpMsgBuf;
lpMsgBuf = (LPVOID)"Unknown error"; lpMsgBuf = (LPVOID)"Unknown error";
e = WSAGetLastError(); e = WSAGetLastError();
if (FormatMessage( if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
FORMAT_MESSAGE_ALLOCATE_BUFFER | | FORMAT_MESSAGE_FROM_SYSTEM
FORMAT_MESSAGE_FROM_SYSTEM | | FORMAT_MESSAGE_IGNORE_INSERTS,
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
NULL, e, e,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
// Default language MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf, 0, NULL)) { (LPTSTR)&lpMsgBuf,
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf); 0,
LocalFree(lpMsgBuf); NULL)) {
} else {
rig_debug(lvl, "%s: Network error %d\n", msg, e); rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf);
} LocalFree(lpMsgBuf);
} else {
rig_debug(lvl, "%s: Network error %d\n", msg, e);
}
#else #else
e = errno; e = errno;
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e)); rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e));
#endif #endif
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
ROT *my_rot; /* handle to rot (instance) */ ROT *my_rot; /* handle to rot (instance) */
rot_model_t my_model = ROT_MODEL_DUMMY; rot_model_t my_model = ROT_MODEL_DUMMY;
int retcode; /* generic return code from functions */ int retcode; /* generic return code from functions */
int verbose = 0; int verbose = 0;
int show_conf = 0; int show_conf = 0;
int dump_caps_opt = 0; int dump_caps_opt = 0;
const char *rot_file = NULL; const char *rot_file = NULL;
int serial_rate = 0; int serial_rate = 0;
char conf_parms[MAXCONFLEN] = ""; char conf_parms[MAXCONFLEN] = "";
struct addrinfo hints, *result, *saved_result; struct addrinfo hints, *result, *saved_result;
int sock_listen; int sock_listen;
int reuseaddr = 1; int reuseaddr = 1;
int sockopt; int sockopt;
char host[NI_MAXHOST]; char host[NI_MAXHOST];
char serv[NI_MAXSERV]; char serv[NI_MAXSERV];
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
pthread_t thread; pthread_t thread;
pthread_attr_t attr; pthread_attr_t attr;
#endif #endif
struct handle_data *arg; struct handle_data *arg;
while (1) { while (1) {
int c; int c;
int option_index = 0; int option_index = 0;
c = getopt_long(argc, argv, SHORT_OPTIONS, c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
long_options, &option_index);
if (c == -1) if (c == -1) {
break; break;
}
switch (c) { switch (c) {
case 'h': case 'h':
usage(); usage();
exit(0); exit(0);
case 'V': case 'V':
version(); version();
exit(0); exit(0);
case 'm': case 'm':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
my_model = atoi(optarg); my_model = atoi(optarg);
break; break;
case 'r': case 'r':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
rot_file = optarg; rot_file = optarg;
break; break;
case 's': case 's':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
serial_rate = atoi(optarg); serial_rate = atoi(optarg);
break; break;
case 'C': case 'C':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
if (*conf_parms != '\0') if (*conf_parms != '\0') {
strcat(conf_parms, ","); strcat(conf_parms, ",");
}
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms)); strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
break; break;
case 't': case 't':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
portno = optarg; portno = optarg;
break; break;
case 'T': case 'T':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
src_addr = optarg; src_addr = optarg;
break; break;
case 'v': case 'v':
verbose++; verbose++;
break; break;
case 'L': case 'L':
show_conf++; show_conf++;
break; break;
case 'l': case 'l':
list_models(); list_models();
exit(0); exit(0);
case 'u': case 'u':
dump_caps_opt++; dump_caps_opt++;
break; break;
default: default:
usage(); /* unknown option? */ usage(); /* unknown option? */
exit(1); exit(1);
} }
} }
rig_set_debug(verbose); rig_set_debug(verbose);
rig_debug(RIG_DEBUG_VERBOSE, "rotctld, %s\n", hamlib_version); rig_debug(RIG_DEBUG_VERBOSE, "rotctld, %s\n", hamlib_version);
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to " rig_debug(RIG_DEBUG_VERBOSE,
"<hamlib-developer@lists.sourceforge.net>\n\n"); "Report bugs to <hamlib-developer@lists.sourceforge.net>\n\n");
my_rot = rot_init(my_model); my_rot = rot_init(my_model);
if (!my_rot) { if (!my_rot) {
fprintf(stderr, "Unknown rot num %d, or initialization error.\n", fprintf(stderr,
my_model); "Unknown rot num %d, or initialization error.\n",
fprintf(stderr, "Please check with --list option.\n"); my_model);
exit(2);
}
retcode = set_conf(my_rot, conf_parms); fprintf(stderr, "Please check with --list option.\n");
exit(2);
}
if (retcode != RIG_OK) { retcode = set_conf(my_rot, conf_parms);
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (rot_file) if (retcode != RIG_OK) {
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1); fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
/* FIXME: bound checking and port type == serial */ if (rot_file) {
if (serial_rate != 0) strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
my_rot->state.rotport.parm.serial.rate = serial_rate; }
/* /* FIXME: bound checking and port type == serial */
* print out conf parameters if (serial_rate != 0) {
*/ my_rot->state.rotport.parm.serial.rate = serial_rate;
if (show_conf) { }
rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
}
/* /*
* print out conf parameters, and exits immediately * print out conf parameters
* We may be interested only in only caps, and rig_open may fail. */
*/ if (show_conf) {
if (dump_caps_opt) { rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
dumpcaps_rot(my_rot, stdout); }
rot_cleanup(my_rot); /* if you care about memory */
exit(0);
}
retcode = rot_open(my_rot); /*
* 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) {
dumpcaps_rot(my_rot, stdout);
rot_cleanup(my_rot); /* if you care about memory */
exit(0);
}
if (retcode != RIG_OK) { retcode = rot_open(my_rot);
fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0) if (retcode != RIG_OK) {
printf("Opened rot model %d, '%s'\n", my_rot->caps->rot_model, fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
my_rot->caps->model_name); exit(2);
}
rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n", if (verbose > 0) {
my_rot->caps->version, rig_strstatus(my_rot->caps->status)); printf("Opened rot model %d, '%s'\n",
my_rot->caps->rot_model,
my_rot->caps->model_name);
}
rig_debug(RIG_DEBUG_VERBOSE,
"Backend version: %s, Status: %s\n",
my_rot->caps->version,
rig_strstatus(my_rot->caps->status));
#ifdef __MINGW32__ #ifdef __MINGW32__
# ifndef SO_OPENTYPE # ifndef SO_OPENTYPE
@ -336,267 +349,304 @@ int main(int argc, char *argv[])
# define INVALID_SOCKET -1 # define INVALID_SOCKET -1
# endif # endif
WSADATA wsadata; WSADATA wsadata;
if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) { if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) {
fprintf(stderr, "WSAStartup socket error\n"); fprintf(stderr, "WSAStartup socket error\n");
exit(1); exit(1);
} }
sockopt = SO_SYNCHRONOUS_NONALERT; sockopt = SO_SYNCHRONOUS_NONALERT;
setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&sockopt, sizeof(sockopt)); setsockopt(INVALID_SOCKET,
SOL_SOCKET,
SO_OPENTYPE,
(char *)&sockopt,
sizeof(sockopt));
#endif #endif
/* /*
* Prepare listening socket * Prepare listening socket
*/ */
memset(&hints, 0, sizeof(struct addrinfo)); memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_STREAM;/* TCP socket */ hints.ai_socktype = SOCK_STREAM; /* TCP socket */
hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */ hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
hints.ai_protocol = 0; /* Any protocol */ hints.ai_protocol = 0; /* Any protocol */
retcode = getaddrinfo(src_addr, portno, &hints, &result); retcode = getaddrinfo(src_addr, portno, &hints, &result);
if (retcode != 0) { if (retcode != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode)); fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode));
exit(2); exit(2);
} }
saved_result = result; saved_result = result;
do { do {
sock_listen = socket(result->ai_family, result->ai_socktype, sock_listen = socket(result->ai_family,
result->ai_protocol); result->ai_socktype,
result->ai_protocol);
if (sock_listen < 0) { if (sock_listen < 0) {
handle_error(RIG_DEBUG_ERR, "socket"); handle_error(RIG_DEBUG_ERR, "socket");
freeaddrinfo(result); /* No longer needed */ freeaddrinfo(result); /* No longer needed */
exit(1); exit(1);
} }
if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR, 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 */ handle_error(RIG_DEBUG_ERR, "setsockopt");
exit(1); freeaddrinfo(result); /* No longer needed */
} exit(1);
}
#ifdef IPV6_V6ONLY #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 /* allow IPv4 mapped to IPv6 clients, MS & BSD default this
to 1 i.e. disallowed */ to 1 i.e. disallowed */
sockopt = 0; sockopt = 0;
if (setsockopt(sock_listen, IPPROTO_IPV6, IPV6_V6ONLY, if (setsockopt(sock_listen,
(char *)&sockopt, sizeof(sockopt)) < 0) { IPPROTO_IPV6,
handle_error(RIG_DEBUG_ERR, "setsockopt"); IPV6_V6ONLY,
freeaddrinfo(saved_result); /* No longer needed */ (char *)&sockopt,
exit(1); sizeof(sockopt))
} < 0) {
}
handle_error(RIG_DEBUG_ERR, "setsockopt");
freeaddrinfo(saved_result); /* No longer needed */
exit(1);
}
}
#endif #endif
if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) { if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) {
break; break;
} }
handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)"); handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)");
#ifdef __MINGW32__ #ifdef __MINGW32__
closesocket(sock_listen); closesocket(sock_listen);
#else #else
close(sock_listen); close(sock_listen);
#endif #endif
} while ((result = result->ai_next) != NULL); } while ((result = result->ai_next) != NULL);
freeaddrinfo(saved_result); /* No longer needed */ freeaddrinfo(saved_result); /* No longer needed */
if (NULL == result) { if (NULL == result) {
rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n"); rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n");
exit(1); exit(1);
} }
if (listen(sock_listen, 4) < 0) { if (listen(sock_listen, 4) < 0) {
handle_error(RIG_DEBUG_ERR, "listening"); handle_error(RIG_DEBUG_ERR, "listening");
exit(1); exit(1);
} }
#ifdef SIGPIPE #ifdef SIGPIPE
/* Ignore SIGPIPE as we will handle it at the write()/send() calls /* Ignore SIGPIPE as we will handle it at the write()/send() calls
that will consequently fail with EPIPE. All child threads will that will consequently fail with EPIPE. All child threads will
inherit this disposition which is what we want. */ inherit this disposition which is what we want. */
#if HAVE_SIGACTION #if HAVE_SIGACTION
struct sigaction act; struct sigaction act;
memset (&act, 0, sizeof act); memset(&act, 0, sizeof act);
act.sa_handler = SIG_IGN; act.sa_handler = SIG_IGN;
act.sa_flags = SA_RESTART; act.sa_flags = SA_RESTART;
if (sigaction (SIGPIPE, &act, NULL)) {
handle_error (RIG_DEBUG_ERR, "sigaction"); if (sigaction(SIGPIPE, &act, NULL)) {
} handle_error(RIG_DEBUG_ERR, "sigaction");
}
#elif HAVE_SIGNAL #elif HAVE_SIGNAL
if (SIG_ERR == signal (SIGPIPE, SIG_IGN)))
handle_error (RIG_DEBUG_ERR, "signal"); if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) {
} handle_error(RIG_DEBUG_ERR, "signal");
}
#endif #endif
#endif #endif
/* /*
* main loop accepting connections * main loop accepting connections
*/ */
do { do {
arg = malloc(sizeof(struct handle_data)); arg = malloc(sizeof(struct handle_data));
if (!arg) { if (!arg) {
rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno));
exit(1); exit(1);
} }
arg->rot = my_rot; arg->rot = my_rot;
arg->clilen = sizeof(arg->cli_addr); arg->clilen = sizeof(arg->cli_addr);
arg->sock = accept(sock_listen, (struct sockaddr *) &arg->cli_addr, arg->sock = accept(sock_listen,
&arg->clilen); (struct sockaddr *) &arg->cli_addr,
&arg->clilen);
if (arg->sock < 0) { if (arg->sock < 0) {
handle_error(RIG_DEBUG_ERR, "accept"); handle_error(RIG_DEBUG_ERR, "accept");
break; break;
} }
if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr, arg->clilen, if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr,
host, sizeof(host), serv, sizeof(serv), arg->clilen,
NI_NOFQDN)) < 0) { host,
rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode)); sizeof(host),
} serv,
sizeof(serv),
NI_NOFQDN))
< 0) {
rig_debug(RIG_DEBUG_VERBOSE, "Connection opened from %s:%s\n", rig_debug(RIG_DEBUG_WARN,
host, serv); "Peer lookup error: %s",
gai_strerror(retcode));
}
rig_debug(RIG_DEBUG_VERBOSE,
"Connection opened from %s:%s\n",
host,
serv);
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
pthread_attr_init(&attr); pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
retcode = pthread_create(&thread, &attr, handle_socket, arg); 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)); rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
break; break;
} }
#else #else
handle_socket(arg); handle_socket(arg);
#endif #endif
} while (retcode == 0); } while (retcode == 0);
rot_close(my_rot); /* close port */ rot_close(my_rot); /* close port */
rot_cleanup(my_rot); /* if you care about memory */ rot_cleanup(my_rot); /* if you care about memory */
#ifdef __MINGW32__ #ifdef __MINGW32__
WSACleanup(); WSACleanup();
#endif #endif
return 0; return 0;
} }
/* /*
* This is the function run by the threads * This is the function run by the threads
*/ */
void *handle_socket(void *arg) void * handle_socket(void *arg)
{ {
struct handle_data *handle_data_arg = (struct handle_data *)arg; struct handle_data *handle_data_arg = (struct handle_data *)arg;
FILE *fsockin; FILE *fsockin;
FILE *fsockout; FILE *fsockout;
int retcode; int retcode;
char host[NI_MAXHOST]; char host[NI_MAXHOST];
char serv[NI_MAXSERV]; char serv[NI_MAXSERV];
#ifdef __MINGW32__ #ifdef __MINGW32__
int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY); 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)); rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno));
goto handle_exit; goto handle_exit;
} }
fsockin = _fdopen(sock_osfhandle, "rb"); fsockin = _fdopen(sock_osfhandle, "rb");
#else #else
fsockin = fdopen(handle_data_arg->sock, "rb"); fsockin = fdopen(handle_data_arg->sock, "rb");
#endif #endif
if (!fsockin) { if (!fsockin) {
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
goto handle_exit; goto handle_exit;
} }
#ifdef __MINGW32__ #ifdef __MINGW32__
fsockout = _fdopen(sock_osfhandle, "wb"); fsockout = _fdopen(sock_osfhandle, "wb");
#else #else
fsockout = fdopen(handle_data_arg->sock, "wb"); fsockout = fdopen(handle_data_arg->sock, "wb");
#endif #endif
if (!fsockout) { if (!fsockout) {
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
fclose(fsockin); fclose(fsockin);
goto handle_exit; goto handle_exit;
} }
do { do {
retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0); retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0);
if (ferror(fsockin) || ferror(fsockout)) if (ferror(fsockin) || ferror(fsockout)) {
retcode = 1; retcode = 1;
} while (retcode == 0 || retcode == 2); }
} while (retcode == 0 || retcode == 2);
if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr, if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr,
handle_data_arg->clilen, host, sizeof(host), handle_data_arg->clilen,
serv, sizeof(serv), NI_NOFQDN)) < 0) { host,
rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode)); sizeof(host),
} serv,
sizeof(serv),
NI_NOFQDN))
< 0) {
rig_debug(RIG_DEBUG_VERBOSE, "Connection closed from %s:%s\n", rig_debug(RIG_DEBUG_WARN,
host, serv); "Peer lookup error: %s",
gai_strerror(retcode));
}
fclose(fsockin); rig_debug(RIG_DEBUG_VERBOSE,
"Connection closed from %s:%s\n",
host,
serv);
fclose(fsockin);
#ifndef __MINGW32__ #ifndef __MINGW32__
fclose(fsockout); fclose(fsockout);
#endif #endif
handle_exit: handle_exit:
#ifdef __MINGW32__ #ifdef __MINGW32__
closesocket(handle_data_arg->sock); closesocket(handle_data_arg->sock);
#else #else
close(handle_data_arg->sock); close(handle_data_arg->sock);
#endif #endif
free(arg); free(arg);
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
pthread_exit(NULL); pthread_exit(NULL);
#endif #endif
return NULL; return NULL;
} }
void usage() void usage()
{ {
printf("Usage: rotctld [OPTION]... [COMMAND]...\n" printf("Usage: rotctld [OPTION]... [COMMAND]...\n"
"Daemon serving COMMANDs to a connected antenna rotator.\n\n"); "Daemon serving COMMANDs to a connected antenna rotator.\n\n");
printf( printf(
" -m, --model=ID select rotator model number. See model list\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" " -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" " -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -t, --port=NUM set TCP listening port, default %s\n" " -t, --port=NUM set TCP listening port, default %s\n"
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n" " -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
" -C, --set-conf=PARM=VAL set config parameters\n" " -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n" " -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n" " -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n" " -u, --dump-caps dump capabilities and exit\n"
" -v, --verbose set verbose mode, cumulative\n" " -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n" " -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n", " -V, --version output version information and exit\n\n",
portno); portno);
usage_rot(stdout); usage_rot(stdout);
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n"); printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
} }

Wyświetl plik

@ -21,7 +21,7 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
#include <stdlib.h> #include <stdlib.h>
@ -42,232 +42,339 @@
int sprintf_vfo(char *str, vfo_t vfo) int sprintf_vfo(char *str, vfo_t vfo)
{ {
int i, len=0; int i, len = 0;
const char *sv; const char *sv;
*str = '\0'; *str = '\0';
if (vfo == RIG_VFO_NONE)
return 0;
sv = rig_strvfo(vfo & RIG_VFO_CURR);
if (sv && sv[0]) len += sprintf(str+len, "%s ", sv);
sv = rig_strvfo(vfo & RIG_VFO_MEM);
if (sv && sv[0]) len += sprintf(str+len, "%s ", sv);
sv = rig_strvfo(vfo & RIG_VFO_VFO);
if (sv && sv[0]) len += sprintf(str+len, "%s ", sv);
sv = rig_strvfo(vfo & RIG_VFO_MAIN);
if (sv && sv[0]) len += sprintf(str+len, "%s ", sv);
sv = rig_strvfo(vfo & RIG_VFO_SUB);
if (sv && sv[0]) len += sprintf(str+len, "%s ", sv);
for (i=0; i<16; i++) { if (vfo == RIG_VFO_NONE) {
sv = rig_strvfo(vfo & RIG_VFO_N(i)); return 0;
if (sv && sv[0]) len += sprintf(str+len, "%s ", sv); }
}
return len; sv = rig_strvfo(vfo & RIG_VFO_CURR);
if (sv && sv[0]) {
len += sprintf(str + len, "%s ", sv);
}
sv = rig_strvfo(vfo & RIG_VFO_MEM);
if (sv && sv[0]) {
len += sprintf(str + len, "%s ", sv);
}
sv = rig_strvfo(vfo & RIG_VFO_VFO);
if (sv && sv[0]) {
len += sprintf(str + len, "%s ", sv);
}
sv = rig_strvfo(vfo & RIG_VFO_MAIN);
if (sv && sv[0]) {
len += sprintf(str + len, "%s ", sv);
}
sv = rig_strvfo(vfo & RIG_VFO_SUB);
if (sv && sv[0]) {
len += sprintf(str + len, "%s ", sv);
}
for (i = 0; i < 16; i++) {
sv = rig_strvfo(vfo & RIG_VFO_N(i));
if (sv && sv[0]) {
len += sprintf(str + len, "%s ", sv);
}
}
return len;
} }
int sprintf_mode(char *str, rmode_t mode) int sprintf_mode(char *str, rmode_t mode)
{ {
int i, len=0; int i, len = 0;
*str = '\0'; *str = '\0';
if (mode == RIG_MODE_NONE)
return 0;
for (i = 0; i < 30; i++) { if (mode == RIG_MODE_NONE) {
const char *ms = rig_strrmode(mode & (1UL<<i)); return 0;
if (!ms || !ms[0]) }
continue; /* unknown, FIXME! */
strcat(str, ms); for (i = 0; i < 30; i++) {
strcat(str, " "); const char *ms = rig_strrmode(mode & (1UL << i));
len += strlen(ms) + 1;
} if (!ms || !ms[0]) {
return len; continue; /* unknown, FIXME! */
}
strcat(str, ms);
strcat(str, " ");
len += strlen(ms) + 1;
}
return len;
} }
int sprintf_func(char *str, setting_t func) int sprintf_func(char *str, setting_t func)
{ {
int i, len=0; int i, len = 0;
*str = '\0'; *str = '\0';
if (func == RIG_FUNC_NONE)
return 0;
for (i = 0; i < RIG_SETTING_MAX; i++) { if (func == RIG_FUNC_NONE) {
const char *ms = rig_strfunc(func & rig_idx2setting(i)); return 0;
if (!ms || !ms[0]) }
continue; /* unknown, FIXME! */
strcat(str, ms); for (i = 0; i < RIG_SETTING_MAX; i++) {
strcat(str, " "); const char *ms = rig_strfunc(func & rig_idx2setting(i));
len += strlen(ms) + 1;
} if (!ms || !ms[0]) {
return len; continue; /* unknown, FIXME! */
}
strcat(str, ms);
strcat(str, " ");
len += strlen(ms) + 1;
}
return len;
} }
int sprintf_level(char *str, setting_t level) int sprintf_level(char *str, setting_t level)
{ {
int i, len=0; int i, len = 0;
*str = '\0'; *str = '\0';
if (level == RIG_LEVEL_NONE)
return 0;
for (i = 0; i < RIG_SETTING_MAX; i++) { if (level == RIG_LEVEL_NONE) {
const char *ms = rig_strlevel(level & rig_idx2setting(i)); return 0;
if (!ms || !ms[0]) }
continue; /* unknown, FIXME! */
strcat(str, ms); for (i = 0; i < RIG_SETTING_MAX; i++) {
strcat(str, " "); const char *ms = rig_strlevel(level & rig_idx2setting(i));
len += strlen(ms) + 1;
} if (!ms || !ms[0]) {
return len; continue; /* unknown, FIXME! */
}
strcat(str, ms);
strcat(str, " ");
len += strlen(ms) + 1;
}
return len;
} }
int sprintf_level_ext(char *str, const struct confparams *extlevels) int sprintf_level_ext(char *str, const struct confparams *extlevels)
{ {
int len=0; int len = 0;
*str = '\0'; *str = '\0';
if (!extlevels)
return 0;
for (; extlevels->token != RIG_CONF_END; extlevels++) { if (!extlevels) {
if (!extlevels->name) return 0;
continue; /* no name */ }
switch (extlevels->type) {
case RIG_CONF_CHECKBUTTON: for (; extlevels->token != RIG_CONF_END; extlevels++) {
case RIG_CONF_COMBO: if (!extlevels->name) {
case RIG_CONF_NUMERIC: continue; /* no name */
case RIG_CONF_STRING: }
strcat(str, extlevels->name);
strcat(str, " "); switch (extlevels->type) {
len += strlen(extlevels->name) + 1; case RIG_CONF_CHECKBUTTON:
break; case RIG_CONF_COMBO:
case RIG_CONF_BUTTON: case RIG_CONF_NUMERIC:
/* ignore case RIG_CONF_BUTTON */ case RIG_CONF_STRING:
break; strcat(str, extlevels->name);
} strcat(str, " ");
} len += strlen(extlevels->name) + 1;
return len; break;
case RIG_CONF_BUTTON:
/* ignore case RIG_CONF_BUTTON */
break;
}
}
return len;
} }
int sprintf_level_gran(char *str, setting_t level, const gran_t gran[]) int sprintf_level_gran(char *str, setting_t level, const gran_t gran[])
{ {
int i, len=0; int i, len = 0;
*str = '\0'; *str = '\0';
if (level == RIG_LEVEL_NONE)
return 0;
for (i = 0; i < RIG_SETTING_MAX; i++) { if (level == RIG_LEVEL_NONE) {
const char *ms; return 0;
}
if (!(level & rig_idx2setting(i))) for (i = 0; i < RIG_SETTING_MAX; i++) {
continue; const char *ms;
ms = rig_strlevel(level & rig_idx2setting(i));
if (!ms || !ms[0]) { if (!(level & rig_idx2setting(i))) {
if (level != DUMMY_ALL && level != RIG_LEVEL_SET(DUMMY_ALL)) continue;
rig_debug(RIG_DEBUG_BUG, "unknown level idx %d\n", i); }
continue;
} ms = rig_strlevel(level & rig_idx2setting(i));
if (RIG_LEVEL_IS_FLOAT(rig_idx2setting(i)))
len += sprintf(str+len, "%s(%g..%g/%g) ", ms, if (!ms || !ms[0]) {
gran[i].min.f,gran[i].max.f,gran[i].step.f); if (level != DUMMY_ALL && level != RIG_LEVEL_SET(DUMMY_ALL)) {
else rig_debug(RIG_DEBUG_BUG, "unknown level idx %d\n", i);
len += sprintf(str+len, "%s(%d..%d/%d) ", ms, }
gran[i].min.i,gran[i].max.i,gran[i].step.i);
} continue;
return len; }
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 {
len += sprintf(str + len,
"%s(%d..%d/%d) ",
ms,
gran[i].min.i,
gran[i].max.i,
gran[i].step.i);
}
}
return len;
} }
int sprintf_parm(char *str, setting_t parm) int sprintf_parm(char *str, setting_t parm)
{ {
int i, len=0; int i, len = 0;
*str = '\0'; *str = '\0';
if (parm == RIG_PARM_NONE)
return 0;
for (i = 0; i < RIG_SETTING_MAX; i++) { if (parm == RIG_PARM_NONE) {
const char *ms = rig_strparm(parm & rig_idx2setting(i)); return 0;
if (!ms || !ms[0]) }
continue; /* unknown, FIXME! */
strcat(str, ms); for (i = 0; i < RIG_SETTING_MAX; i++) {
strcat(str, " "); const char *ms = rig_strparm(parm & rig_idx2setting(i));
len += strlen(ms) + 1;
} if (!ms || !ms[0]) {
return len; continue; /* unknown, FIXME! */
}
strcat(str, ms);
strcat(str, " ");
len += strlen(ms) + 1;
}
return len;
} }
int sprintf_parm_gran(char *str, setting_t parm, const gran_t gran[]) int sprintf_parm_gran(char *str, setting_t parm, const gran_t gran[])
{ {
int i, len=0; int i, len = 0;
*str = '\0'; *str = '\0';
if (parm == RIG_PARM_NONE)
return 0;
for (i = 0; i < RIG_SETTING_MAX; i++) { if (parm == RIG_PARM_NONE) {
const char *ms; return 0;
if (!(parm & rig_idx2setting(i))) }
continue;
ms = rig_strparm(parm & rig_idx2setting(i)); for (i = 0; i < RIG_SETTING_MAX; i++) {
if (!ms || !ms[0]) { const char *ms;
if (parm != DUMMY_ALL && parm != RIG_PARM_SET(DUMMY_ALL))
rig_debug(RIG_DEBUG_BUG, "unknown parm idx %d\n", i); if (!(parm & rig_idx2setting(i))) {
continue; continue;
} }
if (RIG_PARM_IS_FLOAT(rig_idx2setting(i)))
len += sprintf(str+len, "%s(%g..%g/%g) ", ms, ms = rig_strparm(parm & rig_idx2setting(i));
gran[i].min.f,gran[i].max.f,gran[i].step.f);
else if (!ms || !ms[0]) {
len += sprintf(str+len, "%s(%d..%d/%d) ", ms, if (parm != DUMMY_ALL && parm != RIG_PARM_SET(DUMMY_ALL)) {
gran[i].min.i,gran[i].max.i,gran[i].step.i); rig_debug(RIG_DEBUG_BUG, "unknown parm idx %d\n", i);
} }
return len;
continue;
}
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 {
len += sprintf(str + len,
"%s(%d..%d/%d) ",
ms,
gran[i].min.i,
gran[i].max.i,
gran[i].step.i);
}
}
return len;
} }
int sprintf_vfop(char *str, vfo_op_t op) int sprintf_vfop(char *str, vfo_op_t op)
{ {
int i, len=0; int i, len = 0;
*str = '\0'; *str = '\0';
if (op == RIG_OP_NONE)
return 0;
for (i = 0; i < 30; i++) { if (op == RIG_OP_NONE) {
const char *ms = rig_strvfop(op & (1UL<<i)); return 0;
if (!ms || !ms[0]) }
continue; /* unknown, FIXME! */
strcat(str, ms); for (i = 0; i < 30; i++) {
strcat(str, " "); const char *ms = rig_strvfop(op & (1UL << i));
len += strlen(ms) + 1;
} if (!ms || !ms[0]) {
return len; continue; /* unknown, FIXME! */
}
strcat(str, ms);
strcat(str, " ");
len += strlen(ms) + 1;
}
return len;
} }
int sprintf_scan(char *str, scan_t rscan) int sprintf_scan(char *str, scan_t rscan)
{ {
int i, len=0; int i, len = 0;
*str = '\0'; *str = '\0';
if (rscan == RIG_SCAN_NONE)
return 0;
for (i = 0; i < 30; i++) { if (rscan == RIG_SCAN_NONE) {
const char *ms = rig_strscan(rscan & (1UL<<i)); return 0;
if (!ms || !ms[0]) }
continue; /* unknown, FIXME! */
strcat(str, ms); for (i = 0; i < 30; i++) {
strcat(str, " "); const char *ms = rig_strscan(rscan & (1UL << i));
len += strlen(ms) + 1;
} if (!ms || !ms[0]) {
return len; continue; /* unknown, FIXME! */
}
strcat(str, ms);
strcat(str, " ");
len += strlen(ms) + 1;
}
return len;
} }

Wyświetl plik

@ -5,7 +5,7 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -15,40 +15,50 @@
#define MAXDIGITS 32 #define MAXDIGITS 32
int main (int argc, char *argv[]) int main(int argc, char *argv[])
{ {
unsigned char b[(MAXDIGITS+1)/2]; unsigned char b[(MAXDIGITS + 1) / 2];
freq_t f=0; freq_t f = 0;
int digits = 10; int digits = 10;
int i; int i;
if (argc != 2 && argc != 3) { if (argc != 2 && argc != 3) {
fprintf(stderr,"Usage: %s <freq> [digits]\n",argv[0]); fprintf(stderr, "Usage: %s <freq> [digits]\n", argv[0]);
exit(1); exit(1);
} }
f = (freq_t)atoll(argv[1]); f = (freq_t)atoll(argv[1]);
if (argc > 2) {
digits = atoi(argv[2]);
if (digits > MAXDIGITS)
exit(1);
}
printf("Little Endian mode\n"); if (argc > 2) {
printf("Frequency: %"PRIfreq"\n",f); digits = atoi(argv[2]);
to_bcd(b, f, digits);
printf("BCD: %2.2x",b[0]);
for (i = 1; i < (digits+1)/2; i++)
printf(",%2.2x",b[i]);
printf("\nResult after recoding: %"PRIll"\n", (int64_t)from_bcd(b, digits));
printf("\nBig Endian mode\n"); if (digits > MAXDIGITS) {
printf("Frequency: %"PRIfreq"\n",f); exit(1);
to_bcd_be(b, f, digits); }
printf("BCD: %2.2x",b[0]); }
for (i = 1; i < (digits+1)/2; i++)
printf(",%2.2x",b[i]);
printf("\nResult after recoding: %"PRIll"\n", (int64_t)from_bcd_be(b, digits));
return 0; printf("Little Endian mode\n");
printf("Frequency: %"PRIfreq"\n", f);
to_bcd(b, f, digits);
printf("BCD: %2.2x", b[0]);
for (i = 1; i < (digits + 1) / 2; i++) {
printf(",%2.2x", b[i]);
}
printf("\nResult after recoding: %"PRIll"\n", (int64_t)from_bcd(b, digits));
printf("\nBig Endian mode\n");
printf("Frequency: %"PRIfreq"\n", f);
to_bcd_be(b, f, digits);
printf("BCD: %2.2x", b[0]);
for (i = 1; i < (digits + 1) / 2; i++) {
printf(",%2.2x", b[i]);
}
printf("\nResult after recoding: %"PRIll"\n",
(int64_t)from_bcd_be(b, digits));
return 0;
} }

Wyświetl plik

@ -5,7 +5,7 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -14,49 +14,50 @@
#include "misc.h" #include "misc.h"
int main (int argc, char *argv[]) int main(int argc, char *argv[])
{ {
freq_t f=0; freq_t f = 0;
#if 0 #if 0
if (argc != 2) {
fprintf(stderr,"Usage: %s <freq>\n",argv[0]);
exit(1);
}
f = atoi(argv[1]); if (argc != 2) {
fprintf(stderr, "Usage: %s <freq>\n", argv[0]);
exit(1);
}
f = atoi(argv[1]);
#endif #endif
printf("%s\n", hamlib_version); printf("%s\n", hamlib_version);
printf("caps size: %lu\n", (long unsigned) sizeof(struct rig_caps)); printf("caps size: %lu\n", (long unsigned) sizeof(struct rig_caps));
printf("state size: %lu\n", (long unsigned) sizeof(struct rig_state)); printf("state size: %lu\n", (long unsigned) sizeof(struct rig_state));
printf("RIG size: %lu\n", (long unsigned) sizeof(struct rig)); printf("RIG size: %lu\n", (long unsigned) sizeof(struct rig));
printf("freq_t size: %lu\n", (long unsigned) sizeof(freq_t)); printf("freq_t size: %lu\n", (long unsigned) sizeof(freq_t));
printf("shortfreq_t size: %lu\n", (long unsigned) sizeof(shortfreq_t)); printf("shortfreq_t size: %lu\n", (long unsigned) sizeof(shortfreq_t));
/* freq on 31bits test */ /* freq on 31bits test */
f = GHz(2); f = GHz(2);
printf("GHz(2) = %"PRIll"\n", (int64_t)f); printf("GHz(2) = %"PRIll"\n", (int64_t)f);
/* freq on 32bits test */ /* freq on 32bits test */
f = GHz(4); f = GHz(4);
printf("GHz(4) = %"PRIll"\n", (int64_t)f); printf("GHz(4) = %"PRIll"\n", (int64_t)f);
/* freq on >32bits test */ /* freq on >32bits test */
f = GHz(5); f = GHz(5);
printf("GHz(5) = %"PRIll"\n", (int64_t)f); printf("GHz(5) = %"PRIll"\n", (int64_t)f);
/* floating point to freq conversion test */ /* floating point to freq conversion test */
f = GHz(1.3); f = GHz(1.3);
printf("GHz(1.3) = %"PRIll"\n", (int64_t)f); printf("GHz(1.3) = %"PRIll"\n", (int64_t)f);
/* floating point to freq conversion precision test */ /* floating point to freq conversion precision test */
f = GHz(1.234567890); f = GHz(1.234567890);
printf("GHz(1.234567890) = %"PRIll"\n", (int64_t)f); printf("GHz(1.234567890) = %"PRIll"\n", (int64_t)f);
/* floating point to freq conversion precision test, with freq >32bits */ /* floating point to freq conversion precision test, with freq >32bits */
f = GHz(123.456789012); f = GHz(123.456789012);
printf("GHz(123.456789012) = %"PRIll"\n", (int64_t)f); printf("GHz(123.456789012) = %"PRIll"\n", (int64_t)f);
return 0; return 0;
} }

Wyświetl plik

@ -17,200 +17,246 @@
#include <hamlib/rotator.h> #include <hamlib/rotator.h>
int main (int argc, char *argv[]) { int main(int argc, char *argv[])
char recodedloc[13], *loc1, *loc2, sign; {
double lon1, lat1, lon2, lat2; char recodedloc[13], *loc1, *loc2, sign;
double distance, az, mmm, sec; double lon1, lat1, lon2, lat2;
int deg, min, retcode, loc_len, nesw = 0; 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]); fprintf(stderr,
exit(1); "Usage: %s <locator1> <precision> [<locator2>]\n",
} argv[0]);
exit(1);
}
loc1 = argv[1]; loc1 = argv[1];
loc_len = argc > 2 ? atoi(argv[2]) : strlen(loc1)/2; loc_len = argc > 2 ? atoi(argv[2]) : strlen(loc1) / 2;
loc2 = argc > 3 ? argv[3] : NULL; loc2 = argc > 3 ? argv[3] : NULL;
printf("Locator1:\t%s\n", loc1); printf("Locator1:\t%s\n", loc1);
/* hamlib function to convert maidenhead to decimal degrees */ /* hamlib function to convert maidenhead to decimal degrees */
retcode = locator2longlat(&lon1, &lat1, loc1); retcode = locator2longlat(&lon1, &lat1, loc1);
if (retcode != RIG_OK) {
fprintf(stderr, "locator2longlat() failed with malformed input.\n");
exit(2);
}
/* hamlib function to convert decimal degrees to deg, min, sec */ if (retcode != RIG_OK) {
retcode = dec2dms(lon1, &deg, &min, &sec, &nesw); fprintf(stderr, "locator2longlat() failed with malformed input.\n");
if (retcode != RIG_OK) { exit(2);
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n"); }
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" Longitude:\t%f\t%c%d %d' %.2f\"\n", lon1, sign, deg, min, sec);
/* hamlib function to convert deg, min, sec to decimal degrees */ /* hamlib function to convert decimal degrees to deg, min, sec */
lon1 = dms2dec(deg, min, sec, nesw); retcode = dec2dms(lon1, &deg, &min, &sec, &nesw);
printf(" Recoded lon:\t%f\n", lon1);
/* hamlib function to convert decimal degrees to deg decimal minutes */ if (retcode != RIG_OK) {
retcode = dec2dmmm(lon1, &deg, &mmm, &nesw); fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
if (retcode != RIG_OK) { exit(2);
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n"); }
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" GPS lon:\t%f\t%c%d %.3f'\n", lon1, sign, deg, mmm);
/* hamlib function to convert deg, decimal min to decimal degrees */ if (nesw == 1) {
lon1 = dmmm2dec(deg, mmm, nesw); sign = '-';
printf(" Recoded GPS:\t%f\n", lon1); } else {
sign = '\0';
}
/* hamlib function to convert decimal degrees to deg, min, sec */ printf(" Longitude:\t%f\t%c%d %d' %.2f\"\n", lon1, sign, deg, min, sec);
retcode = dec2dms(lat1, &deg, &min, &sec, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" Latitude:\t%f\t%c%d %d' %.2f\"\n", lat1, sign, deg, min, sec);
/* hamlib function to convert deg, min, sec to decimal degrees */ /* hamlib function to convert deg, min, sec to decimal degrees */
lat1 = dms2dec(deg, min, sec, nesw); lon1 = dms2dec(deg, min, sec, nesw);
printf(" Recoded lat:\t%f\n", lat1); printf(" Recoded lon:\t%f\n", lon1);
/* hamlib function to convert decimal degrees to deg decimal minutes */ /* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dmmm(lat1, &deg, &mmm, &nesw); retcode = dec2dmmm(lon1, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" GPS lat:\t%f\t%c%d %.3f'\n", lat1, sign, deg, mmm);
/* hamlib function to convert deg, decimal min to decimal degrees */ if (retcode != RIG_OK) {
lat1 = dmmm2dec(deg, mmm, nesw); fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
printf(" Recoded GPS:\t%f\n", lat1); exit(2);
}
/* hamlib function to convert decimal degrees to maidenhead */ if (nesw == 1) {
retcode = longlat2locator(lon1, lat1, recodedloc, loc_len); sign = '-';
if (retcode != RIG_OK) { } else {
fprintf(stderr, "longlat2locator() failed, precision out of range.\n"); sign = '\0';
exit(2); }
}
printf(" Recoded:\t%s\n", recodedloc);
if (loc2 == NULL) printf(" GPS lon:\t%f\t%c%d %.3f'\n", lon1, sign, deg, mmm);
exit(0);
/* Now work on the second locator */ /* hamlib function to convert deg, decimal min to decimal degrees */
printf("\nLocator2:\t%s\n", loc2); lon1 = dmmm2dec(deg, mmm, nesw);
printf(" Recoded GPS:\t%f\n", lon1);
retcode = locator2longlat(&lon2, &lat2, loc2); /* hamlib function to convert decimal degrees to deg, min, sec */
if (retcode != RIG_OK) { retcode = dec2dms(lat1, &deg, &min, &sec, &nesw);
fprintf(stderr, "locator2longlat() failed with malformed input.\n");
exit(2);
}
/* hamlib function to convert decimal degrees to deg, min, sec */ if (retcode != RIG_OK) {
retcode = dec2dms(lon2, &deg, &min, &sec, &nesw); fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
if (retcode != RIG_OK) { exit(2);
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n"); }
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" Longitude:\t%f\t%c%d %d' %.2f\"\n", lon2, sign, deg, min, sec);
/* hamlib function to convert deg, min, sec to decimal degrees */ if (nesw == 1) {
lon2 = dms2dec(deg, min, sec, nesw); sign = '-';
printf(" Recoded lon:\t%f\n", lon2); } else {
sign = '\0';
}
/* hamlib function to convert decimal degrees to deg decimal minutes */ printf(" Latitude:\t%f\t%c%d %d' %.2f\"\n", lat1, sign, deg, min, sec);
retcode = dec2dmmm(lon2, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" GPS lon:\t%f\t%c%d %.3f'\n", lon2, sign, deg, mmm);
/* hamlib function to convert deg, decimal min to decimal degrees */ /* hamlib function to convert deg, min, sec to decimal degrees */
lon2 = dmmm2dec(deg, mmm, nesw); lat1 = dms2dec(deg, min, sec, nesw);
printf(" Recoded GPS:\t%f\n", lon2); printf(" Recoded lat:\t%f\n", lat1);
/* hamlib function to convert decimal degrees to deg, min, sec */ /* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dms(lat2, &deg, &min, &sec, &nesw); retcode = dec2dmmm(lat1, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" Latitude:\t%f\t%c%d %d' %.2f\"\n", lat2, sign, deg, min, sec);
/* hamlib function to convert deg, min, sec to decimal degrees */ if (retcode != RIG_OK) {
lat2 = dms2dec(deg, min, sec, nesw); fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
printf(" Recoded lat:\t%f\n", lat2); exit(2);
}
/* hamlib function to convert decimal degrees to deg decimal minutes */ if (nesw == 1) {
retcode = dec2dmmm(lat2, &deg, &mmm, &nesw); sign = '-';
if (retcode != RIG_OK) { } else {
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n"); sign = '\0';
exit(2); }
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" GPS lat:\t%f\t%c%d %.3f'\n", lat2, sign, deg, mmm);
/* hamlib function to convert deg, decimal min to decimal degrees */ printf(" GPS lat:\t%f\t%c%d %.3f'\n", lat1, sign, deg, mmm);
lat2 = dmmm2dec(deg, mmm, nesw);
printf(" Recoded GPS:\t%f\n", lat2);
/* hamlib function to convert decimal degrees to maidenhead */ /* hamlib function to convert deg, decimal min to decimal degrees */
retcode = longlat2locator(lon2, lat2, recodedloc, loc_len); lat1 = dmmm2dec(deg, mmm, nesw);
if (retcode != RIG_OK) { printf(" Recoded GPS:\t%f\n", lat1);
fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
exit(2);
}
printf(" Recoded:\t%s\n", recodedloc);
retcode = qrb(lon1, lat1, lon2, lat2, &distance, &az); /* hamlib function to convert decimal degrees to maidenhead */
if (retcode != RIG_OK) { retcode = longlat2locator(lon1, lat1, recodedloc, loc_len);
fprintf(stderr, "QRB error: %d\n", retcode);
exit(2);
}
dec2dms(az, &deg, &min, &sec, &nesw); if (retcode != RIG_OK) {
printf("\nDistance: %.6fkm\n", distance); fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
if (nesw == 1) exit(2);
sign = '-'; }
else
sign = '\0';
/* Beware printf() rounding error! */
printf("Bearing: %.2f, %c%d %d' %.2f\"\n", az, sign, deg, min, sec);
exit(0); printf(" Recoded:\t%s\n", recodedloc);
if (loc2 == NULL) {
exit(0);
}
/* Now work on the second locator */
printf("\nLocator2:\t%s\n", loc2);
retcode = locator2longlat(&lon2, &lat2, loc2);
if (retcode != RIG_OK) {
fprintf(stderr, "locator2longlat() failed with malformed input.\n");
exit(2);
}
/* hamlib function to convert decimal degrees to deg, min, sec */
retcode = dec2dms(lon2, &deg, &min, &sec, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
sign = '-';
} else {
sign = '\0';
}
printf(" Longitude:\t%f\t%c%d %d' %.2f\"\n", lon2, sign, deg, min, sec);
/* hamlib function to convert deg, min, sec to decimal degrees */
lon2 = dms2dec(deg, min, sec, nesw);
printf(" Recoded lon:\t%f\n", lon2);
/* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dmmm(lon2, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
sign = '-';
} else {
sign = '\0';
}
printf(" GPS lon:\t%f\t%c%d %.3f'\n", lon2, sign, deg, mmm);
/* hamlib function to convert deg, decimal min to decimal degrees */
lon2 = dmmm2dec(deg, mmm, nesw);
printf(" Recoded GPS:\t%f\n", lon2);
/* hamlib function to convert decimal degrees to deg, min, sec */
retcode = dec2dms(lat2, &deg, &min, &sec, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
sign = '-';
} else {
sign = '\0';
}
printf(" Latitude:\t%f\t%c%d %d' %.2f\"\n", lat2, sign, deg, min, sec);
/* hamlib function to convert deg, min, sec to decimal degrees */
lat2 = dms2dec(deg, min, sec, nesw);
printf(" Recoded lat:\t%f\n", lat2);
/* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dmmm(lat2, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1) {
sign = '-';
} else {
sign = '\0';
}
printf(" GPS lat:\t%f\t%c%d %.3f'\n", lat2, sign, deg, mmm);
/* hamlib function to convert deg, decimal min to decimal degrees */
lat2 = dmmm2dec(deg, mmm, nesw);
printf(" Recoded GPS:\t%f\n", lat2);
/* hamlib function to convert decimal degrees to maidenhead */
retcode = longlat2locator(lon2, lat2, recodedloc, loc_len);
if (retcode != RIG_OK) {
fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
exit(2);
}
printf(" Recoded:\t%s\n", recodedloc);
retcode = qrb(lon1, lat1, lon2, lat2, &distance, &az);
if (retcode != RIG_OK) {
fprintf(stderr, "QRB error: %d\n", retcode);
exit(2);
}
dec2dms(az, &deg, &min, &sec, &nesw);
printf("\nDistance: %.6fkm\n", distance);
if (nesw == 1) {
sign = '-';
} else {
sign = '\0';
}
/* Beware printf() rounding error! */
printf("Bearing: %.2f, %c%d %d' %.2f\"\n", az, sign, deg, min, sec);
exit(0);
} }

Wyświetl plik

@ -10,7 +10,7 @@
#include <hamlib/rig.h> #include <hamlib/rig.h>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
/* HAVE_SSLEEP is defined when Windows Sleep is found /* HAVE_SSLEEP is defined when Windows Sleep is found
@ -27,356 +27,386 @@
* *
*/ */
#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) #if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP))
#include "hl_sleep.h" # include "hl_sleep.h"
#endif #endif
#define SERIAL_PORT "/dev/ttyS0" #define SERIAL_PORT "/dev/ttyS0"
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{ {
RIG *my_rig; /* handle to rig (nstance) */ RIG *my_rig; /* handle to rig (nstance) */
freq_t freq; /* frequency */ freq_t freq; /* frequency */
rmode_t rmode; /* radio mode of operation */ rmode_t rmode; /* radio mode of operation */
pbwidth_t width; pbwidth_t width;
vfo_t vfo; /* vfo selection */ vfo_t vfo; /* vfo selection */
int strength; /* S-Meter level */ int strength; /* S-Meter level */
int rit = 0; /* RIT status */ int rit = 0; /* RIT status */
int xit = 0; /* XIT status */ int xit = 0; /* XIT status */
int retcode; /* generic return code from functions */ int retcode; /* generic return code from functions */
rig_model_t myrig_model; rig_model_t myrig_model;
printf("testrig: Hello, I am your main() !\n"); printf("testrig: Hello, I am your main() !\n");
/* Turn off backend debugging ouput */ /* Turn off backend debugging ouput */
rig_set_debug_level(RIG_DEBUG_NONE); rig_set_debug_level(RIG_DEBUG_NONE);
/* /*
* allocate memory, setup & open port * allocate memory, setup & open port
*/ */
if (argc < 2) { if (argc < 2) {
hamlib_port_t myport; hamlib_port_t myport;
/* may be overriden by backend probe */ /* may be overriden by backend probe */
myport.type.rig = RIG_PORT_SERIAL; myport.type.rig = RIG_PORT_SERIAL;
myport.parm.serial.rate = 9600; myport.parm.serial.rate = 9600;
myport.parm.serial.data_bits = 8; myport.parm.serial.data_bits = 8;
myport.parm.serial.stop_bits = 1; myport.parm.serial.stop_bits = 1;
myport.parm.serial.parity = RIG_PARITY_NONE; myport.parm.serial.parity = RIG_PARITY_NONE;
myport.parm.serial.handshake = RIG_HANDSHAKE_NONE; myport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1); strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1);
rig_load_all_backends(); rig_load_all_backends();
myrig_model = rig_probe(&myport); myrig_model = rig_probe(&myport);
} else { } else {
myrig_model = atoi(argv[1]); myrig_model = atoi(argv[1]);
} }
my_rig = rig_init(myrig_model); my_rig = rig_init(myrig_model);
if (!my_rig) { if (!my_rig) {
fprintf(stderr,"Unknown rig num: %d\n", myrig_model); fprintf(stderr, "Unknown rig num: %d\n", myrig_model);
fprintf(stderr,"Please check riglist.h\n"); fprintf(stderr, "Please check riglist.h\n");
exit(1); /* whoops! something went wrong (mem alloc?) */ exit(1); /* whoops! something went wrong (mem alloc?) */
} }
strncpy(my_rig->state.rigport.pathname,SERIAL_PORT,FILPATHLEN - 1); strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
retcode = rig_open(my_rig); retcode = rig_open(my_rig);
if (retcode != RIG_OK) {
printf("rig_open: error = %s\n", rigerror(retcode));
exit(2);
}
printf("Port %s opened ok\n", SERIAL_PORT); if (retcode != RIG_OK) {
printf("rig_open: error = %s\n", rigerror(retcode));
exit(2);
}
/* printf("Port %s opened ok\n", SERIAL_PORT);
* Below are examples of set/get routines.
* Must add checking of functionality map prior to command execution -- FS
*
*/
/* /*
* Example of setting rig paameters * Below are examples of set/get routines.
* and some error checking on the return code. * Must add checking of functionality map prior to command execution -- FS
*/ *
*/
retcode = rig_set_vfo(my_rig, RIG_VFO_B); /*
* Example of setting rig paameters
* and some error checking on the return code.
*/
retcode = rig_set_vfo(my_rig, RIG_VFO_B);
if (retcode != RIG_OK ) {
printf("rig_set_vfo: error = %s \n", rigerror(retcode));
}
if (retcode != RIG_OK) {
printf("rig_set_vfo: error = %s \n", rigerror(retcode));
}
/*
* Lets try some frequencies and modes. Return code is not checked.
* Examples of checking return code are further down.
*
*/
/* 10m FM Narrow */ /*
* Lets try some frequencies and modes. Return code is not checked.
* Examples of checking return code are further down.
*
*/
printf("\nSetting 10m FM Narrow...\n"); /* 10m FM Narrow */
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 29620000); /* 10m */ printf("\nSetting 10m FM Narrow...\n");
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM,
rig_passband_narrow(my_rig, RIG_MODE_FM));
if (retcode != RIG_OK ) { retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 29620000); /* 10m */
printf("rig_set_freq: error = %s \n", rigerror(retcode)); retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM,
} rig_passband_narrow(my_rig, RIG_MODE_FM));
rig_get_freq(my_rig, RIG_VFO_CURR, &freq); if (retcode != RIG_OK) {
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n", rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
freq / 1000000, rig_strrmode(rmode), width / 1000.0); rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
sleep(1); /* so you can see it -- FS */
/* 15m USB */ printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000000,
rig_strrmode(rmode),
width / 1000.0);
printf("Setting 15m USB...\n"); sleep(1); /* so you can see it -- FS */
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 21235175); /* 15m */ /* 15m USB */
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_USB,
rig_passband_normal(my_rig, RIG_MODE_USB));
if (retcode != RIG_OK ) { printf("Setting 15m USB...\n");
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 21235175); /* 15m */
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); retcode = rig_set_mode(my_rig,
RIG_VFO_CURR,
RIG_MODE_USB,
rig_passband_normal(my_rig, RIG_MODE_USB));
printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n", if (retcode != RIG_OK) {
freq / 1000000, rig_strrmode(rmode), width / 1000.0); printf("rig_set_freq: error = %s \n", rigerror(retcode));
sleep(1); }
/* 40m LSB */ rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf("Setting 40m LSB...\n"); printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000000, rig_strrmode(rmode), width / 1000.0);
sleep(1);
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 7250100); /* 40m */ /* 40m LSB */
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_LSB, RIG_PASSBAND_NORMAL);
if (retcode != RIG_OK ) { printf("Setting 40m LSB...\n");
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 7250100); /* 40m */
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); retcode = rig_set_mode(my_rig,
RIG_VFO_CURR,
RIG_MODE_LSB,
RIG_PASSBAND_NORMAL);
printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n", if (retcode != RIG_OK) {
freq / 1000000, rig_strrmode(rmode), width / 1000.0); printf("rig_set_freq: error = %s \n", rigerror(retcode));
sleep(1); }
/* 80m AM Narrow */ rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf("Setting 80m AM Narrow...\n"); printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000000, rig_strrmode(rmode), width / 1000.0);
sleep(1);
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 3885000); /* 80m */ /* 80m AM Narrow */
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM,
rig_passband_narrow(my_rig, RIG_MODE_AM));
if (retcode != RIG_OK ) { printf("Setting 80m AM Narrow...\n");
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 3885000); /* 80m */
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); retcode = rig_set_mode(my_rig,
RIG_VFO_CURR,
RIG_MODE_AM,
rig_passband_narrow(my_rig, RIG_MODE_AM));
printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n", if (retcode != RIG_OK) {
freq / 1000000, rig_strrmode(rmode), width / 1000.0); printf("rig_set_freq: error = %s \n", rigerror(retcode));
sleep(1); }
/* 160m CW Normal */ rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf("Setting 160m CW...\n"); printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000000,
rig_strrmode(rmode), width / 1000.0);
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 1875000); /* 160m */ sleep(1);
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_CW, RIG_PASSBAND_NORMAL);
if (retcode != RIG_OK ) { /* 160m CW Normal */
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq); printf("Setting 160m CW...\n");
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n", retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 1875000); /* 160m */
freq / 1000, rig_strrmode(rmode), width ); retcode = rig_set_mode(my_rig,
sleep(1); RIG_VFO_CURR,
RIG_MODE_CW,
RIG_PASSBAND_NORMAL);
/* 160m CW Narrow -- The band is noisy tonight -- FS*/ if (retcode != RIG_OK) {
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
printf("Setting 160m CW Narrow...\n"); rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_CW, printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
rig_passband_narrow(my_rig, RIG_MODE_CW)); freq / 1000,
rig_strrmode(rmode), width);
if (retcode != RIG_OK ) { sleep(1);
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq); /* 160m CW Narrow -- The band is noisy tonight -- FS*/
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n", printf("Setting 160m CW Narrow...\n");
freq / 1000, rig_strrmode(rmode), width);
sleep(1);
/* AM Broadcast band */ retcode = rig_set_mode(my_rig,
RIG_VFO_CURR,
RIG_MODE_CW,
rig_passband_narrow(my_rig, RIG_MODE_CW));
printf("Setting Medium Wave AM...\n"); if (retcode != RIG_OK) {
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 770000); /* KAAM */ rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM, RIG_PASSBAND_NORMAL); rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
if (retcode != RIG_OK ) { printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
printf("rig_set_freq: error = %s \n", rigerror(retcode)); freq / 1000,
} rig_strrmode(rmode), width);
rig_get_freq(my_rig, RIG_VFO_CURR, &freq); sleep(1);
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf(" Freq: %.3f kHz, Mode: %s, Passband: %.3f kHz\n\n", /* AM Broadcast band */
freq / 1000, rig_strrmode(rmode), width / 1000.0);
sleep(1);
/* 20m USB on VFO_A */ printf("Setting Medium Wave AM...\n");
printf("Setting 20m on VFO A with two functions...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 770000); /* KAAM */
retcode = rig_set_mode(my_rig,
RIG_VFO_CURR,
RIG_MODE_AM,
RIG_PASSBAND_NORMAL);
retcode = rig_set_vfo(my_rig, RIG_VFO_A); if (retcode != RIG_OK) {
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 14250375); /* cq de vk3fcs */ printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
if (retcode != RIG_OK ) { rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
printf("rig_set_freq: error = %s \n", rigerror(retcode)); rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq); printf(" Freq: %.3f kHz, Mode: %s, Passband: %.3f kHz\n\n",
rig_get_vfo(my_rig, &vfo); freq / 1000,
rig_strrmode(rmode), width / 1000.0);
printf(" Freq: %.6f MHz, VFO: %s\n\n", freq / 1000000, rig_strvfo(vfo)); sleep(1);
sleep(1); /* 20m USB on VFO_A */
/* 20m USB on VFO_A , with only 1 call */ printf("Setting 20m on VFO A with two functions...\n");
printf("Setting 20m on VFO A with one function...\n"); retcode = rig_set_vfo(my_rig, RIG_VFO_A);
retcode = rig_set_freq(my_rig, RIG_VFO_A, 14295125); /* cq de vk3fcs */ 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)); printf("rig_set_freq: error = %s \n", rigerror(retcode));
} }
rig_get_freq(my_rig, RIG_VFO_CURR, &freq); rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
rig_get_vfo(my_rig, &vfo); rig_get_vfo(my_rig, &vfo);
printf(" Freq: %.6f MHz, VFO: %s\n\n", freq / 1000000, rig_strvfo(vfo)); printf(" Freq: %.6f MHz, VFO: %s\n\n", freq / 1000000, rig_strvfo(vfo));
sleep(1); sleep(1);
/* 20m USB on VFO_A , with only 1 call */
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) {
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
rig_get_vfo(my_rig, &vfo);
printf(" Freq: %.6f MHz, VFO: %s\n\n", freq / 1000000, rig_strvfo(vfo));
sleep(1);
#if 0 #if 0
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 145100000); /* 2m */ retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 145100000); /* 2m */
sleep(2); sleep(2);
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 435125000); /* 70cm */ retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 435125000); /* 70cm */
sleep(2); sleep(2);
#endif #endif
printf("Setting rig Mode to LSB.\n"); printf("Setting rig Mode to LSB.\n");
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_LSB, RIG_PASSBAND_NORMAL); retcode = rig_set_mode(my_rig,
RIG_VFO_CURR,
RIG_MODE_LSB,
RIG_PASSBAND_NORMAL);
if (retcode != RIG_OK ) { if (retcode != RIG_OK) {
printf("rig_set_mode: error = %s \n", rigerror(retcode)); printf("rig_set_mode: error = %s \n", rigerror(retcode));
} }
sleep(1); sleep(1);
printf("Setting rig PTT ON.\n"); printf("Setting rig PTT ON.\n");
retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_ON ); /* stand back ! */ 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)); printf("rig_set_ptt: error = %s \n", rigerror(retcode));
} }
sleep(1); sleep(1);
printf("Setting rig PTT OFF.\n"); printf("Setting rig PTT OFF.\n");
retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_OFF ); /* phew ! */ 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)); printf("rig_set_ptt: error = %s \n", rigerror(retcode));
} }
sleep(1); sleep(1);
/* /*
* Simple examples of getting rig information -- FS * Simple examples of getting rig information -- FS
* *
*/ */
printf("\nGet various raw rig values:\n"); printf("\nGet various raw rig values:\n");
retcode = rig_get_vfo(my_rig, &vfo); /* try to get vfo info */ 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); printf("rig_get_vfo: vfo = %i \n", vfo);
} else { } else {
printf("rig_get_vfo: error = %s \n", rigerror(retcode)); printf("rig_get_vfo: error = %s \n", rigerror(retcode));
} }
retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq); 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); printf("rig_get_freq: freq = %"PRIfreq"\n", freq);
} else { } else {
printf("rig_get_freq: error = %s \n", rigerror(retcode)); printf("rig_get_freq: error = %s \n", rigerror(retcode));
} }
retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); 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); printf("rig_get_mode: mode = %i \n", rmode);
} else { } else {
printf("rig_get_mode: error = %s \n", rigerror(retcode)); printf("rig_get_mode: error = %s \n", rigerror(retcode));
} }
retcode = rig_get_strength(my_rig, RIG_VFO_CURR, &strength); 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); printf("rig_get_strength: strength = %i \n", strength);
} else { } else {
printf("rig_get_strength: error = %s \n", rigerror(retcode)); 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); retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, 1);
printf("rig_set_func: Setting RIT ON\n"); 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); retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, &rit);
printf("rig_get_func: RIT: %d\n", 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); retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, 1);
printf("rig_set_func: Setting XIT ON\n"); 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); retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, &xit);
printf("rig_get_func: XIT: %d\n", xit); printf("rig_get_func: XIT: %d\n", xit);
} }
rig_close(my_rig); /* close port */ rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */ rig_cleanup(my_rig); /* if you care about memory */
printf("port %s closed ok \n",SERIAL_PORT); printf("port %s closed ok \n", SERIAL_PORT);
return 0; return 0;
} }

Wyświetl plik

@ -10,7 +10,7 @@
#include <hamlib/rig.h> #include <hamlib/rig.h>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif #endif
/* HAVE_SSLEEP is defined when Windows Sleep is found /* HAVE_SSLEEP is defined when Windows Sleep is found
@ -27,88 +27,88 @@
* *
*/ */
#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) #if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP))
#include "hl_sleep.h" # include "hl_sleep.h"
#endif #endif
#define SERIAL_PORT "/dev/ttyS0" #define SERIAL_PORT "/dev/ttyS0"
int myfreq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg) int myfreq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg)
{ {
int *count_ptr = (int *) arg; int *count_ptr = (int *) arg;
printf("Rig changed freq to %"PRIfreq"Hz\n", freq); printf("Rig changed freq to %"PRIfreq"Hz\n", freq);
*count_ptr += 1; *count_ptr += 1;
return 0; return 0;
} }
int main (int argc, char *argv[]) int main(int argc, char *argv[])
{ {
RIG *my_rig; /* handle to rig (nstance) */ RIG *my_rig; /* handle to rig (nstance) */
int retcode; /* generic return code from functions */ int retcode; /* generic return code from functions */
int i, count = 0; int i, count = 0;
if (argc != 2) { if (argc != 2) {
fprintf(stderr,"%s <rig_num>\n", argv[0]); fprintf(stderr, "%s <rig_num>\n", argv[0]);
exit(1); exit(1);
} }
printf("testrig:hello, I am your main() !\n"); printf("testrig:hello, I am your main() !\n");
/* /*
* allocate memory, setup & open port * allocate memory, setup & open port
*/ */
my_rig = rig_init(atoi(argv[1])); my_rig = rig_init(atoi(argv[1]));
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?) */
}
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1); 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?) */
}
if (rig_open(my_rig)) strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
exit(2);
printf("Port %s opened ok\n", SERIAL_PORT); if (rig_open(my_rig)) {
exit(2);
}
/* printf("Port %s opened ok\n", SERIAL_PORT);
* Below are examples of set/get routines.
* Must add checking of functionality map prior to command execution -- FS /*
* * Below are examples of set/get routines.
*/ * Must add checking of functionality map prior to command execution -- FS
*
*/
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 439700000);
if (retcode != RIG_OK) {
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
rig_set_freq_callback(my_rig, myfreq_event, (rig_ptr_t)&count);
retcode = rig_set_trn(my_rig, RIG_TRN_RIG);
if (retcode != RIG_OK) {
printf("rig_set_trn: error = %s \n", rigerror(retcode));
}
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 439700000); for (i = 0; i < 12; i++) {
printf("Loop count: %d\n", i);
sleep(10); /* or anything smarter */
}
if (retcode != RIG_OK ) { printf("Frequency changed %d times\n", count);
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
rig_set_freq_callback(my_rig, myfreq_event, (rig_ptr_t)&count); rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
retcode = rig_set_trn(my_rig, RIG_TRN_RIG); printf("port %s closed ok \n", SERIAL_PORT);
if (retcode != RIG_OK ) { return 0;
printf("rig_set_trn: error = %s \n", rigerror(retcode));
}
for (i=0;i<12;i++)
{
printf("Loop count: %d\n", i);
sleep(10); /* or anything smarter */
}
printf("Frequency changed %d times\n", count);
rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
printf("port %s closed ok \n",SERIAL_PORT);
return 0;
} }