kopia lustrzana https://github.com/Hamlib/Hamlib
rodzic
80a4097aba
commit
d489b8bcb5
1227
tests/dumpcaps.c
1227
tests/dumpcaps.c
Plik diff jest za duży
Load Diff
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -37,113 +37,141 @@
|
|||
/*
|
||||
* 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;
|
||||
int backend_warnings = 0;
|
||||
const struct rot_caps *caps;
|
||||
int backend_warnings = 0;
|
||||
|
||||
if (!rot || !rot->caps)
|
||||
return -RIG_EINVAL;
|
||||
if (!rot || !rot->caps) {
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rot->caps;
|
||||
caps = rot->caps;
|
||||
|
||||
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, "Mfg name:\t\t%s\n", caps->mfg_name);
|
||||
fprintf(fout, "Backend version:\t%s\n", caps->version);
|
||||
fprintf(fout, "Backend copyright:\t%s\n", caps->copyright);
|
||||
fprintf(fout, "Backend status:\t\t%s\n", rig_strstatus(caps->status));
|
||||
fprintf(fout, "Rot type:\t\t");
|
||||
switch (caps->rot_type & ROT_TYPE_MASK) {
|
||||
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, "Caps dump for model:\t%d\n", caps->rot_model);
|
||||
fprintf(fout, "Model name:\t\t%s\n", caps->model_name);
|
||||
fprintf(fout, "Mfg name:\t\t%s\n", caps->mfg_name);
|
||||
fprintf(fout, "Backend version:\t%s\n", caps->version);
|
||||
fprintf(fout, "Backend copyright:\t%s\n", caps->copyright);
|
||||
fprintf(fout, "Backend status:\t\t%s\n", rig_strstatus(caps->status));
|
||||
fprintf(fout, "Rot type:\t\t");
|
||||
|
||||
fprintf(fout, "Port type:\t\t");
|
||||
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;
|
||||
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++;
|
||||
}
|
||||
switch (caps->rot_type & ROT_TYPE_MASK) {
|
||||
case ROT_TYPE_OTHER:
|
||||
fprintf(fout, "Other\n");
|
||||
break;
|
||||
|
||||
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);
|
||||
case ROT_TYPE_AZIMUTH:
|
||||
fprintf(fout, "Azimuth\n");
|
||||
break;
|
||||
|
||||
fprintf(fout, "Min Azimuth:\t\t%.2f\n", caps->min_az);
|
||||
fprintf(fout, "Max Azimuth:\t\t%.2f\n", caps->max_az);
|
||||
case ROT_TYPE_ELEVATION:
|
||||
fprintf(fout, "Elevation\n");
|
||||
break;
|
||||
|
||||
fprintf(fout, "Min Elevation:\t\t%.2f\n", caps->min_el);
|
||||
fprintf(fout, "Max Elevation:\t\t%.2f\n", caps->max_el);
|
||||
case ROT_TYPE_AZEL:
|
||||
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++;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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, "Port type:\t\t");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
423
tests/dumpmem.c
423
tests/dumpmem.c
|
@ -27,211 +27,324 @@
|
|||
#include <hamlib/rig.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
#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);
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RIG *my_rig;
|
||||
int status,i,j;
|
||||
RIG *my_rig;
|
||||
int status, i, j;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr,"%s <rig_num>\n",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "%s <rig_num>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
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?) */
|
||||
}
|
||||
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);
|
||||
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
|
||||
|
||||
if (rig_open(my_rig))
|
||||
exit(2);
|
||||
if (rig_open(my_rig)) {
|
||||
exit(2);
|
||||
}
|
||||
|
||||
status = rig_set_vfo(my_rig, RIG_VFO_B);
|
||||
status = rig_set_vfo(my_rig, RIG_VFO_B);
|
||||
|
||||
|
||||
if (status != RIG_OK ) {
|
||||
printf("rig_set_vfo: error = %s \n", rigerror(status));
|
||||
}
|
||||
if (status != RIG_OK) {
|
||||
printf("rig_set_vfo: error = %s \n", rigerror(status));
|
||||
}
|
||||
|
||||
/*
|
||||
* chan_t is used to describe what memory your rig is equipped with
|
||||
* cf. chan_list field in caps
|
||||
* Example for the Ic706MkIIG (99 memory channels, 2 scan edges, 2 call chans):
|
||||
* chan_t chan_list[] = {
|
||||
* { 1, 99, RIG_MTYPE_MEM, 0 },
|
||||
* { 100, 103, RIG_MTYPE_EDGE, 0 },
|
||||
* { 104, 105, RIG_MTYPE_CALL, 0 },
|
||||
* RIG_CHAN_END
|
||||
* }
|
||||
*/
|
||||
/*
|
||||
* chan_t is used to describe what memory your rig is equipped with
|
||||
* cf. chan_list field in caps
|
||||
* Example for the Ic706MkIIG (99 memory channels, 2 scan edges, 2 call chans):
|
||||
* chan_t chan_list[] = {
|
||||
* { 1, 99, RIG_MTYPE_MEM, 0 },
|
||||
* { 100, 103, RIG_MTYPE_EDGE, 0 },
|
||||
* { 104, 105, RIG_MTYPE_CALL, 0 },
|
||||
* RIG_CHAN_END
|
||||
* }
|
||||
*/
|
||||
|
||||
for (i=0; my_rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) {
|
||||
for (j = my_rig->state.chan_list[i].start;
|
||||
j <= my_rig->state.chan_list[i].end; j++) {
|
||||
dump_chan(my_rig, j);
|
||||
}
|
||||
}
|
||||
for (i = 0; my_rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) {
|
||||
for (j = my_rig->state.chan_list[i].start;
|
||||
j <= my_rig->state.chan_list[i].end; j++) {
|
||||
dump_chan(my_rig, j);
|
||||
}
|
||||
}
|
||||
|
||||
rig_close(my_rig); /* close port */
|
||||
rig_cleanup(my_rig); /* if you care about memory */
|
||||
rig_close(my_rig); /* close port */
|
||||
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.
|
||||
* 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
|
||||
if (modes&RIG_MODE_WFM) strcat(buf,"WFM ");
|
||||
|
||||
if (modes & RIG_MODE_WFM) {
|
||||
strcat(buf, "WFM ");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return buf;
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
int dump_chan(RIG *rig, int chan_num)
|
||||
{
|
||||
channel_t chan;
|
||||
int status;
|
||||
char freqbuf[20];
|
||||
channel_t chan;
|
||||
int status;
|
||||
char freqbuf[20];
|
||||
|
||||
chan.vfo = RIG_VFO_MEM;
|
||||
chan.channel_num = chan_num;
|
||||
status=rig_get_channel(rig, &chan);
|
||||
chan.vfo = RIG_VFO_MEM;
|
||||
chan.channel_num = chan_num;
|
||||
status = rig_get_channel(rig, &chan);
|
||||
|
||||
if (status != RIG_OK ) {
|
||||
printf("rig_get_channel: error = %s \n", rigerror(status));
|
||||
return status;
|
||||
}
|
||||
if (status != RIG_OK) {
|
||||
printf("rig_get_channel: error = %s \n", rigerror(status));
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("Channel: %d\n", chan.channel_num);
|
||||
printf("Channel: %d\n", chan.channel_num);
|
||||
|
||||
sprintf_freq(freqbuf,chan.freq);
|
||||
printf("Frequency: %s\n", freqbuf);
|
||||
printf("Mode: %s\n", decode_modes(chan.mode));
|
||||
sprintf_freq(freqbuf, chan.freq);
|
||||
printf("Frequency: %s\n", freqbuf);
|
||||
printf("Mode: %s\n", decode_modes(chan.mode));
|
||||
|
||||
sprintf_freq(freqbuf,chan.width);
|
||||
printf("Width: %s\n", freqbuf);
|
||||
printf("VFO: %d\n", chan.vfo);
|
||||
sprintf_freq(freqbuf, chan.width);
|
||||
printf("Width: %s\n", freqbuf);
|
||||
printf("VFO: %d\n", chan.vfo);
|
||||
|
||||
printf("Split: %d\n", chan.split);
|
||||
sprintf_freq(freqbuf,chan.tx_freq);
|
||||
printf("TXFrequency: %s\n", freqbuf);
|
||||
printf("TXMode: %s\n", decode_modes(chan.tx_mode));
|
||||
printf("Split: %d\n", chan.split);
|
||||
sprintf_freq(freqbuf, chan.tx_freq);
|
||||
printf("TXFrequency: %s\n", freqbuf);
|
||||
printf("TXMode: %s\n", decode_modes(chan.tx_mode));
|
||||
|
||||
sprintf_freq(freqbuf,chan.tx_width);
|
||||
printf("TXWidth: %s\n", freqbuf);
|
||||
sprintf_freq(freqbuf, chan.tx_width);
|
||||
printf("TXWidth: %s\n", freqbuf);
|
||||
|
||||
printf("Shift: %s\n", rig_strptrshift(chan.rptr_shift));
|
||||
sprintf_freq(freqbuf,chan.rptr_offs);
|
||||
printf("Offset: %s%s\n", chan.rptr_offs>0?"+":"", freqbuf);
|
||||
printf("Shift: %s\n", rig_strptrshift(chan.rptr_shift));
|
||||
sprintf_freq(freqbuf, chan.rptr_offs);
|
||||
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);
|
||||
printf("Step: %s\n", freqbuf);
|
||||
sprintf_freq(freqbuf, chan.tuning_step);
|
||||
printf("Step: %s\n", freqbuf);
|
||||
|
||||
sprintf_freq(freqbuf,chan.rit);
|
||||
printf("RIT: %s%s\n", chan.rit>0?"+":"", freqbuf);
|
||||
sprintf_freq(freqbuf, chan.rit);
|
||||
printf("RIT: %s%s\n", chan.rit > 0 ? "+" : "", freqbuf);
|
||||
|
||||
sprintf_freq(freqbuf,chan.xit);
|
||||
printf("XIT: %s%s\n", chan.xit>0?"+":"", freqbuf);
|
||||
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("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("Name: %s\n", chan.channel_desc);
|
||||
sprintf_freq(freqbuf, chan.xit);
|
||||
printf("XIT: %s%s\n", chan.xit > 0 ? "+" : "", freqbuf);
|
||||
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("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("Name: %s\n", chan.channel_desc);
|
||||
|
||||
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");
|
||||
printf("Functions: ");
|
||||
|
||||
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);
|
||||
if (chan.funcs != 0) {
|
||||
if (chan.funcs & RIG_FUNC_FAGC) {
|
||||
printf("FAGC ");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
175
tests/example.c
175
tests/example.c
|
@ -3,8 +3,8 @@
|
|||
* Edit to specify your rig model and serial port, and baud rate
|
||||
* before compiling.
|
||||
* To compile:
|
||||
* gcc -L/usr/local/lib -lhamlib -o example example.c
|
||||
* if hamlib is installed in /usr/local/...
|
||||
* gcc -L/usr/local/lib -lhamlib -o example example.c
|
||||
* if hamlib is installed in /usr/local/...
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -13,68 +13,117 @@
|
|||
#include <hamlib/rig.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 */
|
||||
rig_set_debug(RIG_DEBUG_ERR); // errors only
|
||||
/* Instantiate a rig */
|
||||
my_rig = rig_init(RIG_MODEL_TT565); // your rig model.
|
||||
/* Set up serial port, baud rate */
|
||||
rig_file = "/dev/ttyUSB0"; // your serial device
|
||||
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
|
||||
my_rig->state.rigport.parm.serial.rate = 57600; // your baud rate
|
||||
/* Open my rig */
|
||||
retcode = rig_open(my_rig);
|
||||
/* Give me ID info, e.g., firmware version. */
|
||||
info_buf = (char *)rig_get_info(my_rig);
|
||||
printf("Rig_info: '%s'\n", info_buf);
|
||||
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;
|
||||
|
||||
/* Note: As a general practice, we should check to see if a given
|
||||
* function is within the rig's capabilities before calling it, but
|
||||
* 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.)
|
||||
*/
|
||||
/* Set verbosity level */
|
||||
rig_set_debug(RIG_DEBUG_ERR); // errors only
|
||||
|
||||
/* Main VFO frequency */
|
||||
status = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
printf("VFO freq. = %.1f Hz\n", freq);
|
||||
/* Current mode */
|
||||
status = rig_get_mode(my_rig, RIG_VFO_CURR, &mode, &width);
|
||||
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);
|
||||
/* Instantiate a rig */
|
||||
my_rig = rig_init(RIG_MODEL_TT565); // your rig model.
|
||||
|
||||
/* Set up serial port, baud rate */
|
||||
rig_file = "/dev/ttyUSB0"; // your serial device
|
||||
|
||||
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
|
||||
|
||||
my_rig->state.rigport.parm.serial.rate = 57600; // your baud rate
|
||||
|
||||
/* Open my rig */
|
||||
retcode = rig_open(my_rig);
|
||||
|
||||
/* 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
|
||||
* function is within the rig's capabilities before calling it, but
|
||||
* 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 */
|
||||
status = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
|
||||
printf("VFO freq. = %.1f Hz\n", freq);
|
||||
|
||||
/* Current mode */
|
||||
status = rig_get_mode(my_rig, RIG_VFO_CURR, &mode, &width);
|
||||
|
||||
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);
|
||||
};
|
||||
|
|
108
tests/listrigs.c
108
tests/listrigs.c
|
@ -30,59 +30,73 @@
|
|||
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,
|
||||
caps->model_name, caps->version);
|
||||
printf("%d\t%-10s\t%-12s\t%s\t",
|
||||
caps->rig_model,
|
||||
caps->mfg_name,
|
||||
caps->model_name,
|
||||
caps->version);
|
||||
|
||||
printf("%-10s\t", rig_strstatus(caps->status));
|
||||
switch (caps->rig_type & RIG_TYPE_MASK) {
|
||||
case RIG_TYPE_TRANSCEIVER:
|
||||
printf("Transceiver\n");
|
||||
break;
|
||||
case RIG_TYPE_HANDHELD:
|
||||
printf("Handheld\n");
|
||||
break;
|
||||
case RIG_TYPE_MOBILE:
|
||||
printf("Mobile\n");
|
||||
break;
|
||||
case RIG_TYPE_RECEIVER:
|
||||
printf("Receiver\n");
|
||||
break;
|
||||
case RIG_TYPE_PCRECEIVER:
|
||||
printf("PC Receiver\n");
|
||||
break;
|
||||
case RIG_TYPE_SCANNER:
|
||||
printf("Scanner\n");
|
||||
break;
|
||||
case RIG_TYPE_TRUNKSCANNER:
|
||||
printf("Trunking scanner\n");
|
||||
break;
|
||||
case RIG_TYPE_COMPUTER:
|
||||
printf("Computer\n");
|
||||
break;
|
||||
case RIG_TYPE_OTHER:
|
||||
printf("Other\n");
|
||||
break;
|
||||
default:
|
||||
printf("Unknown\n");
|
||||
}
|
||||
return -1; /* !=0, we want them all ! */
|
||||
printf("%-10s\t", rig_strstatus(caps->status));
|
||||
|
||||
switch (caps->rig_type & RIG_TYPE_MASK) {
|
||||
case RIG_TYPE_TRANSCEIVER:
|
||||
printf("Transceiver\n");
|
||||
break;
|
||||
|
||||
case RIG_TYPE_HANDHELD:
|
||||
printf("Handheld\n");
|
||||
break;
|
||||
|
||||
case RIG_TYPE_MOBILE:
|
||||
printf("Mobile\n");
|
||||
break;
|
||||
|
||||
case RIG_TYPE_RECEIVER:
|
||||
printf("Receiver\n");
|
||||
break;
|
||||
|
||||
case RIG_TYPE_PCRECEIVER:
|
||||
printf("PC Receiver\n");
|
||||
break;
|
||||
|
||||
case RIG_TYPE_SCANNER:
|
||||
printf("Scanner\n");
|
||||
break;
|
||||
|
||||
case RIG_TYPE_TRUNKSCANNER:
|
||||
printf("Trunking scanner\n");
|
||||
break;
|
||||
|
||||
case RIG_TYPE_COMPUTER:
|
||||
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");
|
||||
status = rig_list_foreach(print_caps_sum,NULL);
|
||||
if (status != RIG_OK ) {
|
||||
printf("rig_list_foreach: error = %s \n", rigerror(status));
|
||||
exit(3);
|
||||
}
|
||||
printf("Rig#\tMfg \tModel \tVers.\tStatus \tType\n");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
1123
tests/memcsv.c
1123
tests/memcsv.c
Plik diff jest za duży
Load Diff
468
tests/memload.c
468
tests/memload.c
|
@ -20,7 +20,7 @@
|
|||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -32,229 +32,317 @@
|
|||
#include "misc.h"
|
||||
|
||||
#ifdef HAVE_XML2
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
# include <libxml/parser.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
|
||||
|
||||
|
||||
int xml_load (RIG *my_rig, const char *infilename)
|
||||
int xml_load(RIG *my_rig, const char *infilename)
|
||||
{
|
||||
#ifdef HAVE_XML2
|
||||
xmlDocPtr Doc;
|
||||
xmlNodePtr node;
|
||||
xmlDocPtr Doc;
|
||||
xmlNodePtr node;
|
||||
|
||||
/* load xlm Doc */
|
||||
Doc=xmlParseFile(infilename);
|
||||
if(Doc==NULL) {
|
||||
fprintf(stderr,"xmlParse failed\n");
|
||||
exit(2);
|
||||
}
|
||||
/* load xlm Doc */
|
||||
Doc = xmlParseFile(infilename);
|
||||
|
||||
node=xmlDocGetRootElement(Doc);
|
||||
if (node == NULL) {
|
||||
fprintf(stderr,"get root failed\n");
|
||||
exit(2);
|
||||
if (Doc == NULL) {
|
||||
fprintf(stderr, "xmlParse failed\n");
|
||||
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 ) {
|
||||
printf("rig_get_channel: error = %s \n", rigerror(status));
|
||||
return status;
|
||||
}
|
||||
}
|
||||
if (xmlNodeIsText(node)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
xmlFreeDoc(Doc);
|
||||
xmlCleanupParser();
|
||||
set_chan(my_rig, &chan, node);
|
||||
|
||||
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
|
||||
return -RIG_ENAVAIL;
|
||||
return -RIG_ENAVAIL;
|
||||
#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
|
||||
int set_chan(RIG *rig, channel_t *chan, xmlNodePtr node)
|
||||
{
|
||||
xmlChar *prop;
|
||||
int i,n;
|
||||
xmlChar *prop;
|
||||
int i, n;
|
||||
|
||||
memset(chan,0,sizeof(channel_t));
|
||||
chan->vfo = RIG_VFO_MEM;
|
||||
memset(chan, 0, sizeof(channel_t));
|
||||
chan->vfo = RIG_VFO_MEM;
|
||||
|
||||
|
||||
prop=xmlGetProp(node,(unsigned char *) "num");
|
||||
if(prop==NULL) {
|
||||
fprintf(stderr,"no num\n");
|
||||
return -1;
|
||||
}
|
||||
n=chan->channel_num = atoi((char *) prop);
|
||||
prop = xmlGetProp(node, (unsigned char *) "num");
|
||||
|
||||
/* find chanel caps */
|
||||
for(i=0;i<CHANLSTSIZ ;i++)
|
||||
if (rig->state.chan_list[i].start<=n && rig->state.chan_list[i].end>=n)
|
||||
break;
|
||||
if (prop == NULL) {
|
||||
fprintf(stderr, "no num\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
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) {
|
||||
prop=xmlGetProp(node, (unsigned char *) "bank_num");
|
||||
if(prop!=NULL)
|
||||
chan->bank_num = atoi((char *) prop);
|
||||
}
|
||||
/* find chanel caps */
|
||||
for (i = 0; i < CHANLSTSIZ ; i++)
|
||||
if (rig->state.chan_list[i].start <= n
|
||||
&& rig->state.chan_list[i].end >= n) {
|
||||
|
||||
if (rig->state.chan_list[i].mem_caps.channel_desc) {
|
||||
prop=xmlGetProp(node, (unsigned char *) "channel_desc");
|
||||
if(prop!=NULL)
|
||||
strncpy(chan->channel_desc, (char *) prop, 7);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (rig->state.chan_list[i].mem_caps.ant) {
|
||||
prop=xmlGetProp(node, (unsigned char *) "ant");
|
||||
if(prop!=NULL)
|
||||
chan->ant = atoi((char *) prop);
|
||||
}
|
||||
if (rig->state.chan_list[i].mem_caps.freq) {
|
||||
prop=xmlGetProp(node, (unsigned char *) "freq");
|
||||
if(prop!=NULL)
|
||||
sscanf((char *) prop,"%"SCNfreq,&chan->freq);
|
||||
}
|
||||
if (rig->state.chan_list[i].mem_caps.mode) {
|
||||
prop=xmlGetProp(node, (unsigned char *) "mode");
|
||||
if(prop!=NULL)
|
||||
chan->mode = rig_parse_mode((char *) prop);
|
||||
}
|
||||
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.tx_freq) {
|
||||
prop=xmlGetProp(node, (unsigned char *) "tx_freq");
|
||||
if(prop!=NULL)
|
||||
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(prop!=NULL)
|
||||
chan->tx_mode = rig_parse_mode((char *) prop);
|
||||
}
|
||||
if (rig->state.chan_list[i].mem_caps.tx_width) {
|
||||
prop=xmlGetProp(node, (unsigned char *)"tx_width");
|
||||
if(prop!=NULL)
|
||||
chan->tx_width = atoi((char *) prop);
|
||||
}
|
||||
if (rig->state.chan_list[i].mem_caps.split) {
|
||||
chan->split=RIG_SPLIT_OFF;
|
||||
prop=xmlGetProp(node, (unsigned char *)"split");
|
||||
if(prop!=NULL) {
|
||||
if(strcmp((char *) prop,"on")==0) {
|
||||
chan->split=RIG_SPLIT_ON;
|
||||
if (rig->state.chan_list[i].mem_caps.tx_vfo) {
|
||||
prop=xmlGetProp(node, (unsigned char *)"tx_vfo");
|
||||
if(prop!=NULL)
|
||||
sscanf((char *) prop,"%x",&chan->tx_vfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rig->state.chan_list[i].mem_caps.rptr_shift) {
|
||||
prop=xmlGetProp(node, (unsigned char *)"rptr_shift");
|
||||
if(prop)
|
||||
switch(prop[0]) {
|
||||
case '=': chan->rptr_shift=RIG_RPT_SHIFT_NONE;
|
||||
break;
|
||||
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.rptr_offs && chan->rptr_shift!=RIG_RPT_SHIFT_NONE) {
|
||||
prop=xmlGetProp(node, (unsigned char *)"rptr_offs");
|
||||
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);
|
||||
}
|
||||
fprintf(stderr, "node %d %d\n", n, i);
|
||||
|
||||
if (rig->state.chan_list[i].mem_caps.bank_num) {
|
||||
prop = xmlGetProp(node, (unsigned char *) "bank_num");
|
||||
|
||||
if (prop != NULL) {
|
||||
chan->bank_num = atoi((char *) prop);
|
||||
}
|
||||
}
|
||||
|
||||
if (rig->state.chan_list[i].mem_caps.channel_desc) {
|
||||
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) {
|
||||
prop = xmlGetProp(node, (unsigned char *) "ant");
|
||||
|
||||
if (prop != NULL) {
|
||||
chan->ant = atoi((char *) prop);
|
||||
}
|
||||
}
|
||||
|
||||
if (rig->state.chan_list[i].mem_caps.freq) {
|
||||
prop = xmlGetProp(node, (unsigned char *) "freq");
|
||||
|
||||
if (prop != NULL) {
|
||||
sscanf((char *) prop, "%"SCNfreq, &chan->freq);
|
||||
}
|
||||
}
|
||||
|
||||
if (rig->state.chan_list[i].mem_caps.mode) {
|
||||
prop = xmlGetProp(node, (unsigned char *) "mode");
|
||||
|
||||
if (prop != NULL) {
|
||||
chan->mode = rig_parse_mode((char *) prop);
|
||||
}
|
||||
}
|
||||
|
||||
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.tx_freq) {
|
||||
prop = xmlGetProp(node, (unsigned char *) "tx_freq");
|
||||
|
||||
if (prop != NULL) {
|
||||
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 (prop != NULL) {
|
||||
chan->tx_mode = rig_parse_mode((char *) prop);
|
||||
}
|
||||
}
|
||||
|
||||
if (rig->state.chan_list[i].mem_caps.tx_width) {
|
||||
prop = xmlGetProp(node, (unsigned char *)"tx_width");
|
||||
|
||||
if (prop != NULL) {
|
||||
chan->tx_width = atoi((char *) prop);
|
||||
}
|
||||
}
|
||||
|
||||
if (rig->state.chan_list[i].mem_caps.split) {
|
||||
chan->split = RIG_SPLIT_OFF;
|
||||
prop = xmlGetProp(node, (unsigned char *)"split");
|
||||
|
||||
if (prop != NULL) {
|
||||
if (strcmp((char *) prop, "on") == 0) {
|
||||
chan->split = RIG_SPLIT_ON;
|
||||
|
||||
if (rig->state.chan_list[i].mem_caps.tx_vfo) {
|
||||
prop = xmlGetProp(node, (unsigned char *)"tx_vfo");
|
||||
|
||||
if (prop != NULL) {
|
||||
sscanf((char *) prop, "%x", &chan->tx_vfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rig->state.chan_list[i].mem_caps.rptr_shift) {
|
||||
prop = xmlGetProp(node, (unsigned char *)"rptr_shift");
|
||||
|
||||
if (prop)
|
||||
switch (prop[0]) {
|
||||
case '=':
|
||||
chan->rptr_shift = RIG_RPT_SHIFT_NONE;
|
||||
break;
|
||||
|
||||
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.rptr_offs
|
||||
&& chan->rptr_shift != RIG_RPT_SHIFT_NONE) {
|
||||
prop = xmlGetProp(node, (unsigned char *)"rptr_offs");
|
||||
|
||||
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
|
||||
|
||||
|
|
350
tests/memsave.c
350
tests/memsave.c
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -32,193 +32,231 @@
|
|||
#include "misc.h"
|
||||
|
||||
#ifdef HAVE_XML2
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
# include <libxml/parser.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
|
||||
|
||||
int xml_save (RIG *rig, const char *outfilename)
|
||||
|
||||
int xml_save(RIG *rig, const char *outfilename)
|
||||
{
|
||||
#ifdef HAVE_XML2
|
||||
int retval;
|
||||
xmlDocPtr Doc;
|
||||
xmlNodePtr root;
|
||||
int retval;
|
||||
xmlDocPtr Doc;
|
||||
xmlNodePtr root;
|
||||
|
||||
/* create xlm Doc */
|
||||
Doc=xmlNewDoc((unsigned char *) "1.0");
|
||||
root=xmlNewNode(NULL,(unsigned char *) "hamlib");
|
||||
xmlDocSetRootElement(Doc, root);
|
||||
root=xmlNewChild(root,NULL,(unsigned char *) "channels",NULL);
|
||||
/* create xlm Doc */
|
||||
Doc = xmlNewDoc((unsigned char *) "1.0");
|
||||
root = xmlNewNode(NULL, (unsigned char *) "hamlib");
|
||||
xmlDocSetRootElement(Doc, root);
|
||||
root = xmlNewChild(root, NULL, (unsigned char *) "channels", NULL);
|
||||
|
||||
|
||||
if (rig->caps->clone_combo_get)
|
||||
printf("About to save data, enter cloning mode: %s\n",
|
||||
rig->caps->clone_combo_get);
|
||||
if (rig->caps->clone_combo_get)
|
||||
printf("About to save data, enter cloning mode: %s\n",
|
||||
rig->caps->clone_combo_get);
|
||||
|
||||
retval = rig_get_chan_all_cb (rig, dump_xml_chan, root);
|
||||
if (retval != RIG_OK)
|
||||
return retval;
|
||||
retval = rig_get_chan_all_cb(rig, dump_xml_chan, root);
|
||||
|
||||
/* write xml File */
|
||||
if (retval != RIG_OK) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
xmlSaveFormatFileEnc(outfilename, Doc, "UTF-8", 1);
|
||||
/* write xml File */
|
||||
|
||||
xmlFreeDoc(Doc);
|
||||
xmlCleanupParser();
|
||||
xmlSaveFormatFileEnc(outfilename, Doc, "UTF-8", 1);
|
||||
|
||||
return 0;
|
||||
xmlFreeDoc(Doc);
|
||||
xmlCleanupParser();
|
||||
|
||||
return 0;
|
||||
#else
|
||||
return -RIG_ENAVAIL;
|
||||
return -RIG_ENAVAIL;
|
||||
#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
|
||||
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];
|
||||
xmlNodePtr root = arg;
|
||||
xmlNodePtr node = NULL;
|
||||
int i;
|
||||
const char *mtype;
|
||||
char attrbuf[20];
|
||||
xmlNodePtr root = arg;
|
||||
xmlNodePtr node = NULL;
|
||||
int i;
|
||||
const char *mtype;
|
||||
|
||||
static channel_t chan;
|
||||
const channel_cap_t *mem_caps = &chan_list->mem_caps;
|
||||
static channel_t chan;
|
||||
const channel_cap_t *mem_caps = &chan_list->mem_caps;
|
||||
|
||||
|
||||
if (*chan_pp == NULL) {
|
||||
/*
|
||||
* Hamlib frontend demand application an allocated
|
||||
* channel_t pointer for next round.
|
||||
*/
|
||||
*chan_pp = &chan;
|
||||
if (*chan_pp == NULL) {
|
||||
/*
|
||||
* Hamlib frontend demand application an allocated
|
||||
* channel_t pointer for next round.
|
||||
*/
|
||||
*chan_pp = &chan;
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
if (chan_list->type == RIG_MTYPE_NONE)
|
||||
return RIG_OK;
|
||||
if (chan_list->type == RIG_MTYPE_NONE) {
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
mtype = rig_strmtype(chan_list->type);
|
||||
for (i=0; i<strlen(mtype); i++)
|
||||
attrbuf[i] = tolower(mtype[i]);
|
||||
attrbuf[i] = '\0';
|
||||
mtype = rig_strmtype(chan_list->type);
|
||||
|
||||
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) {
|
||||
sprintf(attrbuf,"%d",chan.bank_num);
|
||||
xmlNewProp(node, (unsigned char *) "bank_num", (unsigned char *) attrbuf);
|
||||
}
|
||||
attrbuf[i] = '\0';
|
||||
|
||||
sprintf(attrbuf,"%d",chan.channel_num);
|
||||
xmlNewProp(node, (unsigned char *) "num", (unsigned char *) attrbuf);
|
||||
node = xmlNewChild(root, NULL, (unsigned char *)attrbuf, NULL);
|
||||
|
||||
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);
|
||||
}
|
||||
if (mem_caps->bank_num) {
|
||||
sprintf(attrbuf, "%d", chan.bank_num);
|
||||
xmlNewProp(node, (unsigned char *) "bank_num", (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
|
||||
|
|
|
@ -14,95 +14,106 @@
|
|||
|
||||
#define SERIAL_PORT "/dev/ttyS0"
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RIG *my_rig; /* handle to rig (nstance) */
|
||||
int retcode; /* generic return code from functions */
|
||||
rig_model_t myrig_model;
|
||||
unsigned i;
|
||||
struct timeval tv1, tv2;
|
||||
float elapsed;
|
||||
RIG *my_rig; /* handle to rig (nstance) */
|
||||
int retcode; /* generic return code from functions */
|
||||
rig_model_t myrig_model;
|
||||
unsigned i;
|
||||
struct timeval tv1, tv2;
|
||||
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) {
|
||||
hamlib_port_t myport;
|
||||
/* may be overriden by backend probe */
|
||||
myport.type.rig = RIG_PORT_SERIAL;
|
||||
myport.parm.serial.rate = 9600;
|
||||
myport.parm.serial.data_bits = 8;
|
||||
myport.parm.serial.stop_bits = 1;
|
||||
myport.parm.serial.parity = RIG_PARITY_NONE;
|
||||
myport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
|
||||
strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1);
|
||||
if (argc < 2) {
|
||||
hamlib_port_t myport;
|
||||
/* may be overriden by backend probe */
|
||||
myport.type.rig = RIG_PORT_SERIAL;
|
||||
myport.parm.serial.rate = 9600;
|
||||
myport.parm.serial.data_bits = 8;
|
||||
myport.parm.serial.stop_bits = 1;
|
||||
myport.parm.serial.parity = RIG_PARITY_NONE;
|
||||
myport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
|
||||
strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1);
|
||||
|
||||
rig_load_all_backends();
|
||||
myrig_model = rig_probe(&myport);
|
||||
} else {
|
||||
myrig_model = atoi(argv[1]);
|
||||
}
|
||||
rig_load_all_backends();
|
||||
myrig_model = rig_probe(&myport);
|
||||
} else {
|
||||
myrig_model = atoi(argv[1]);
|
||||
}
|
||||
|
||||
my_rig = rig_init(myrig_model);
|
||||
my_rig = rig_init(myrig_model);
|
||||
|
||||
if (!my_rig) {
|
||||
fprintf(stderr,"Unknown rig num: %d\n", myrig_model);
|
||||
fprintf(stderr,"Please check riglist.h\n");
|
||||
exit(1); /* whoops! something went wrong (mem alloc?) */
|
||||
}
|
||||
if (!my_rig) {
|
||||
fprintf(stderr, "Unknown rig num: %d\n", myrig_model);
|
||||
fprintf(stderr, "Please check riglist.h\n");
|
||||
exit(1); /* whoops! something went wrong (mem alloc?) */
|
||||
}
|
||||
|
||||
printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model,
|
||||
my_rig->caps->model_name);
|
||||
printf("Backend version: %s, Status: %s\n",
|
||||
my_rig->caps->version, rig_strstatus(my_rig->caps->status));
|
||||
printf("Serial speed: %d bauds\n", my_rig->state.rigport.parm.serial.rate);
|
||||
printf("Opened rig model %d, '%s'\n",
|
||||
my_rig->caps->rig_model,
|
||||
my_rig->caps->model_name);
|
||||
|
||||
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);
|
||||
if (retcode != RIG_OK) {
|
||||
printf("rig_open: error = %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
printf("Serial speed: %d bauds\n", my_rig->state.rigport.parm.serial.rate);
|
||||
|
||||
printf("Port %s opened ok\n", SERIAL_PORT);
|
||||
printf("Perform %d loops...\n", LOOP_COUNT);
|
||||
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
|
||||
|
||||
/*
|
||||
* 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_open(my_rig);
|
||||
|
||||
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);
|
||||
if (retcode != RIG_OK) {
|
||||
printf("rig_open: error = %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
printf("Port %s opened ok\n", SERIAL_PORT);
|
||||
printf("Perform %d loops...\n", 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;
|
||||
}
|
||||
|
||||
|
|
748
tests/rigctl.c
748
tests/rigctl.c
|
@ -25,7 +25,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -42,7 +42,7 @@
|
|||
# elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */
|
||||
# include <readline.h>
|
||||
# else /* !defined(HAVE_READLINE_H) */
|
||||
extern char *readline ();
|
||||
extern char * readline();
|
||||
# endif /* HAVE_READLINE_H */
|
||||
#else
|
||||
/* no readline */
|
||||
|
@ -56,9 +56,9 @@ extern char *readline ();
|
|||
# elif defined(HAVE_HISTORY_H)
|
||||
# include <history.h>
|
||||
# else /* !defined(HAVE_HISTORY_H) */
|
||||
extern void add_history ();
|
||||
extern int write_history ();
|
||||
extern int read_history ();
|
||||
extern void add_history();
|
||||
extern int write_history();
|
||||
extern int read_history();
|
||||
# endif /* defined(HAVE_READLINE_HISTORY_H) */
|
||||
#else
|
||||
/* no history */
|
||||
|
@ -75,7 +75,7 @@ extern int read_history ();
|
|||
#include "rigctl_parse.h"
|
||||
|
||||
#define MAXNAMSIZ 32
|
||||
#define MAXNBOPT 100 /* max number of different options */
|
||||
#define MAXNBOPT 100 /* max number of different options */
|
||||
|
||||
|
||||
void usage(void);
|
||||
|
@ -83,36 +83,35 @@ void usage(void);
|
|||
|
||||
/*
|
||||
* 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.
|
||||
* TODO: add an option to read from a file
|
||||
*/
|
||||
#define SHORT_OPTIONS "+m:r:p:d:P:D:s:c:t:lC:LuonvhV"
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rig-file", 1, 0, 'r'},
|
||||
{"ptt-file", 1, 0, 'p'},
|
||||
{"dcd-file", 1, 0, 'd'},
|
||||
{"ptt-type", 1, 0, 'P'},
|
||||
{"dcd-type", 1, 0, 'D'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"civaddr", 1, 0, 'c'},
|
||||
{"send-cmd-term", 1, 0, 't'},
|
||||
{"list", 0, 0, 'l'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"show-conf", 0, 0, 'L'},
|
||||
{"dump-caps", 0, 0, 'u'},
|
||||
{"vfo", 0, 0, 'o'},
|
||||
{"no-restore-ai", 0, 0, 'n'},
|
||||
static struct option long_options[] = {
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rig-file", 1, 0, 'r'},
|
||||
{"ptt-file", 1, 0, 'p'},
|
||||
{"dcd-file", 1, 0, 'd'},
|
||||
{"ptt-type", 1, 0, 'P'},
|
||||
{"dcd-type", 1, 0, 'D'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"civaddr", 1, 0, 'c'},
|
||||
{"send-cmd-term", 1, 0, 't'},
|
||||
{"list", 0, 0, 'l'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"show-conf", 0, 0, 'L'},
|
||||
{"dump-caps", 0, 0, 'u'},
|
||||
{"vfo", 0, 0, 'o'},
|
||||
{"no-restore-ai", 0, 0, 'n'},
|
||||
#ifdef HAVE_READLINE_HISTORY
|
||||
{"read-history", 0, 0, 'i'},
|
||||
{"save-history", 0, 0, 'I'},
|
||||
{"read-history", 0, 0, 'i'},
|
||||
{"save-history", 0, 0, 'I'},
|
||||
#endif
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
#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 */
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RIG *my_rig; /* handle to rig (nstance) */
|
||||
rig_model_t my_model = RIG_MODEL_DUMMY;
|
||||
RIG *my_rig; /* handle to rig (instance) */
|
||||
rig_model_t my_model = RIG_MODEL_DUMMY;
|
||||
|
||||
int retcode; /* generic return code from functions */
|
||||
int exitcode;
|
||||
int retcode; /* generic return code from functions */
|
||||
int exitcode;
|
||||
|
||||
int verbose = 0;
|
||||
int show_conf = 0;
|
||||
int dump_caps_opt = 0;
|
||||
int verbose = 0;
|
||||
int show_conf = 0;
|
||||
int dump_caps_opt = 0;
|
||||
#ifdef HAVE_READLINE_HISTORY
|
||||
int rd_hist = 0;
|
||||
int sv_hist = 0;
|
||||
const char *hist_dir = NULL;
|
||||
const char hist_file[] = "/.rigctl_history";
|
||||
char *hist_path = NULL;
|
||||
struct stat hist_dir_stat;
|
||||
int rd_hist = 0;
|
||||
int sv_hist = 0;
|
||||
const char *hist_dir = NULL;
|
||||
const char hist_file[] = "/.rigctl_history";
|
||||
char *hist_path = NULL;
|
||||
struct stat hist_dir_stat;
|
||||
#endif
|
||||
const char *rig_file=NULL, *ptt_file=NULL, *dcd_file=NULL;
|
||||
ptt_type_t ptt_type = RIG_PTT_NONE;
|
||||
dcd_type_t dcd_type = RIG_DCD_NONE;
|
||||
int serial_rate = 0;
|
||||
char *civaddr = NULL; /* NULL means no need to set conf */
|
||||
char conf_parms[MAXCONFLEN] = "";
|
||||
const char *rig_file = NULL, *ptt_file = NULL, *dcd_file = NULL;
|
||||
ptt_type_t ptt_type = RIG_PTT_NONE;
|
||||
dcd_type_t dcd_type = RIG_DCD_NONE;
|
||||
int serial_rate = 0;
|
||||
char *civaddr = NULL; /* NULL means no need to set conf */
|
||||
char conf_parms[MAXCONFLEN] = "";
|
||||
|
||||
while(1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
while (1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long (argc, argv, SHORT_OPTIONS HST_SHRT_OPTS,
|
||||
long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
c = getopt_long(argc,
|
||||
argv,
|
||||
SHORT_OPTIONS HST_SHRT_OPTS,
|
||||
long_options,
|
||||
&option_index);
|
||||
|
||||
switch(c) {
|
||||
case 'h':
|
||||
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 'p':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
ptt_file = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
dcd_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, "CM108"))
|
||||
ptt_type = RIG_PTT_CM108;
|
||||
else if (!strcmp(optarg, "GPIO"))
|
||||
ptt_type = RIG_PTT_GPIO;
|
||||
else if (!strcmp(optarg, "GPION"))
|
||||
ptt_type = RIG_PTT_GPION;
|
||||
else if (!strcmp(optarg, "NONE"))
|
||||
ptt_type = RIG_PTT_NONE;
|
||||
else
|
||||
ptt_type = atoi(optarg);
|
||||
break;
|
||||
case 'D':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
if (!strcmp(optarg, "RIG"))
|
||||
dcd_type = RIG_DCD_RIG;
|
||||
else if (!strcmp(optarg, "DSR"))
|
||||
dcd_type = RIG_DCD_SERIAL_DSR;
|
||||
else if (!strcmp(optarg, "CTS"))
|
||||
dcd_type = RIG_DCD_SERIAL_CTS;
|
||||
else if (!strcmp(optarg, "CD"))
|
||||
dcd_type = RIG_DCD_SERIAL_CAR;
|
||||
else if (!strcmp(optarg, "PARALLEL"))
|
||||
dcd_type = RIG_DCD_PARALLEL;
|
||||
else if (!strcmp(optarg, "CM108"))
|
||||
dcd_type = RIG_DCD_CM108;
|
||||
else if (!strcmp(optarg, "NONE"))
|
||||
dcd_type = RIG_DCD_NONE;
|
||||
else
|
||||
dcd_type = atoi(optarg);
|
||||
break;
|
||||
case 'c':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
civaddr = optarg;
|
||||
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;
|
||||
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;
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
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 'p':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ptt_file = optarg;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dcd_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, "CM108")) {
|
||||
ptt_type = RIG_PTT_CM108;
|
||||
} else if (!strcmp(optarg, "GPIO")) {
|
||||
ptt_type = RIG_PTT_GPIO;
|
||||
} else if (!strcmp(optarg, "GPION")) {
|
||||
ptt_type = RIG_PTT_GPION;
|
||||
} else if (!strcmp(optarg, "NONE")) {
|
||||
ptt_type = RIG_PTT_NONE;
|
||||
} else {
|
||||
ptt_type = atoi(optarg);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!strcmp(optarg, "RIG")) {
|
||||
dcd_type = RIG_DCD_RIG;
|
||||
} else if (!strcmp(optarg, "DSR")) {
|
||||
dcd_type = RIG_DCD_SERIAL_DSR;
|
||||
} else if (!strcmp(optarg, "CTS")) {
|
||||
dcd_type = RIG_DCD_SERIAL_CTS;
|
||||
} else if (!strcmp(optarg, "CD")) {
|
||||
dcd_type = RIG_DCD_SERIAL_CAR;
|
||||
} else if (!strcmp(optarg, "PARALLEL")) {
|
||||
dcd_type = RIG_DCD_PARALLEL;
|
||||
} else if (!strcmp(optarg, "CM108")) {
|
||||
dcd_type = RIG_DCD_CM108;
|
||||
} else if (!strcmp(optarg, "NONE")) {
|
||||
dcd_type = RIG_DCD_NONE;
|
||||
} else {
|
||||
dcd_type = atoi(optarg);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
civaddr = optarg;
|
||||
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;
|
||||
|
||||
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
|
||||
case 'i':
|
||||
rd_hist++;
|
||||
break;
|
||||
case 'I':
|
||||
sv_hist++;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
rd_hist++;
|
||||
break;
|
||||
|
||||
case 'I':
|
||||
sv_hist++;
|
||||
break;
|
||||
#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);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
|
||||
"<hamlib-developer@lists.sourceforge.net>\n\n");
|
||||
case 'L':
|
||||
show_conf++;
|
||||
break;
|
||||
|
||||
/*
|
||||
* at least one command on command line,
|
||||
* disable interactive mode
|
||||
*/
|
||||
if (optind < argc)
|
||||
interactive = 0;
|
||||
case 'l':
|
||||
rig_set_debug(verbose);
|
||||
list_models();
|
||||
exit(0);
|
||||
|
||||
my_rig = rig_init(my_model);
|
||||
case 'u':
|
||||
dump_caps_opt++;
|
||||
break;
|
||||
|
||||
if (!my_rig) {
|
||||
fprintf(stderr, "Unknown rig num %d, or initialization error.\n",
|
||||
my_model);
|
||||
fprintf(stderr, "Please check with --list option.\n");
|
||||
exit(2);
|
||||
}
|
||||
default:
|
||||
usage(); /* unknown option? */
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
retcode = set_conf(my_rig, conf_parms);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
rig_set_debug(verbose);
|
||||
|
||||
if (rig_file)
|
||||
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "rigctl, %s\n", hamlib_version);
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"Report bugs to <hamlib-developer@lists.sourceforge.net>\n\n");
|
||||
|
||||
/*
|
||||
* 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);
|
||||
/*
|
||||
* at least one command on command line,
|
||||
* disable interactive mode
|
||||
*/
|
||||
if (optind < argc) {
|
||||
interactive = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* print out conf parameters
|
||||
*/
|
||||
if (show_conf) {
|
||||
dumpconf(my_rig, stdout);
|
||||
}
|
||||
my_rig = rig_init(my_model);
|
||||
|
||||
/*
|
||||
* print out capabilities, and exists 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);
|
||||
}
|
||||
if (!my_rig) {
|
||||
fprintf(stderr,
|
||||
"Unknown rig num %d, or initialization error.\n",
|
||||
my_model);
|
||||
fprintf(stderr, "Please check with --list option.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
retcode = rig_open(my_rig);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
retcode = set_conf(my_rig, conf_parms);
|
||||
|
||||
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));
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
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
|
||||
if (interactive && prompt && have_rl) {
|
||||
rl_readline_name = "rigctl";
|
||||
|
||||
if (interactive && prompt && have_rl) {
|
||||
rl_readline_name = "rigctl";
|
||||
|
||||
#ifdef HAVE_READLINE_HISTORY
|
||||
using_history(); /* Initialize Readline History */
|
||||
using_history(); /* Initialize Readline History */
|
||||
|
||||
if (rd_hist || sv_hist) {
|
||||
if (!(hist_dir = getenv("RIGCTL_HIST_DIR")))
|
||||
hist_dir = getenv("HOME");
|
||||
if (rd_hist || sv_hist) {
|
||||
if (!(hist_dir = getenv("RIGCTL_HIST_DIR"))) {
|
||||
hist_dir = getenv("HOME");
|
||||
}
|
||||
|
||||
if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT))
|
||||
|| !(S_ISDIR(hist_dir_stat.st_mode))) {
|
||||
fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir);
|
||||
}
|
||||
if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT))
|
||||
|| !(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));
|
||||
hist_path = (char *)calloc((sizeof(char)
|
||||
* (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));
|
||||
}
|
||||
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 /* HAVE_LIBREADLINE */
|
||||
}
|
||||
|
||||
do {
|
||||
retcode = rigctl_parse(my_rig, stdin, stdout, argv, argc);
|
||||
if (retcode == 2)
|
||||
exitcode = 2;
|
||||
}
|
||||
while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL);
|
||||
#endif /* HAVE_LIBREADLINE */
|
||||
|
||||
do {
|
||||
retcode = rigctl_parse(my_rig, stdin, stdout, argv, argc);
|
||||
|
||||
if (retcode == 2) {
|
||||
exitcode = 2;
|
||||
}
|
||||
} while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL);
|
||||
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
if (interactive && prompt && have_rl) {
|
||||
|
||||
if (interactive && prompt && have_rl) {
|
||||
#ifdef HAVE_READLINE_HISTORY
|
||||
if (sv_hist && hist_path)
|
||||
if (write_history(hist_path) == ENOENT)
|
||||
fprintf(stderr, "\nWarning: Could not write history to %s\n", hist_path);
|
||||
|
||||
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 */
|
||||
if (sv_hist && hist_path) {
|
||||
if (write_history(hist_path) == ENOENT) {
|
||||
fprintf(stderr,
|
||||
"\nWarning: Could not write history to %s\n",
|
||||
hist_path);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
printf("Usage: rigctl [OPTION]... [COMMAND]...\n"
|
||||
"Send COMMANDs to a connected radio transceiver or receiver.\n\n");
|
||||
printf("Usage: rigctl [OPTION]... [COMMAND]...\n"
|
||||
"Send COMMANDs to a connected radio transceiver or receiver.\n\n");
|
||||
|
||||
|
||||
printf(
|
||||
" -m, --model=ID select radio model number. See model list\n"
|
||||
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
|
||||
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
|
||||
" -d, --dcd-file=DEVICE set device of the DCD device to operate on\n"
|
||||
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
|
||||
" -D, --dcd-type=TYPE set type of the DCD device to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
|
||||
" -t, --send-cmd-term=CHAR set send_cmd command termination char\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -L, --show-conf list all config parameters\n"
|
||||
" -l, --list list all model numbers and exit\n"
|
||||
" -u, --dump-caps dump capabilities and exit\n"
|
||||
" -o, --vfo do not default to VFO_CURR, require extra vfo arg\n"
|
||||
" -n, --no-restore-ai do not restore auto information mode on rig\n"
|
||||
printf(
|
||||
" -m, --model=ID select radio model number. See model list\n"
|
||||
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
|
||||
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
|
||||
" -d, --dcd-file=DEVICE set device of the DCD device to operate on\n"
|
||||
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
|
||||
" -D, --dcd-type=TYPE set type of the DCD device to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
|
||||
" -t, --send-cmd-term=CHAR set send_cmd command termination char\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -L, --show-conf list all config parameters\n"
|
||||
" -l, --list list all model numbers and exit\n"
|
||||
" -u, --dump-caps dump capabilities and exit\n"
|
||||
" -o, --vfo do not default to VFO_CURR, require extra vfo arg\n"
|
||||
" -n, --no-restore-ai do not restore auto information mode on rig\n"
|
||||
#ifdef HAVE_READLINE_HISTORY
|
||||
" -i, --read-history read prior interactive session history\n"
|
||||
" -I, --save-history save current interactive session history\n"
|
||||
" -i, --read-history read prior interactive session history\n"
|
||||
" -I, --save-history save current interactive session history\n"
|
||||
#endif
|
||||
" -v, --verbose set verbose mode, cumulative\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n\n"
|
||||
);
|
||||
" -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n"
|
||||
" -h, --help display this help and exit\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");
|
||||
|
||||
}
|
||||
|
|
4515
tests/rigctl_parse.c
4515
tests/rigctl_parse.c
Plik diff jest za duży
Load Diff
|
@ -32,8 +32,8 @@
|
|||
* external prototype
|
||||
*/
|
||||
|
||||
int dumpcaps (RIG *, FILE *);
|
||||
int dumpconf (RIG *, FILE *);
|
||||
int dumpcaps(RIG *, FILE *);
|
||||
int dumpconf(RIG *, FILE *);
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
|
@ -41,10 +41,10 @@ int dumpconf (RIG *, FILE *);
|
|||
void usage_rig(FILE *);
|
||||
void version();
|
||||
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 set_conf(RIG *my_rig, char *conf_parms);
|
||||
|
||||
int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc);
|
||||
|
||||
#endif /* RIGCTL_PARSE_H */
|
||||
#endif /* RIGCTL_PARSE_H */
|
||||
|
|
979
tests/rigctld.c
979
tests/rigctld.c
Plik diff jest za duży
Load Diff
1038
tests/rigmatrix.c
1038
tests/rigmatrix.c
Plik diff jest za duży
Load Diff
566
tests/rigmem.c
566
tests/rigmem.c
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -40,22 +40,22 @@
|
|||
#include "sprintflst.h"
|
||||
|
||||
#define MAXNAMSIZ 32
|
||||
#define MAXNBOPT 100 /* max number of different options */
|
||||
#define MAXNBOPT 100 /* max number of different options */
|
||||
|
||||
|
||||
/*
|
||||
* external prototype
|
||||
*/
|
||||
|
||||
extern int xml_save (RIG *rig, const char *outfilename);
|
||||
extern int xml_load (RIG *rig, const char *infilename);
|
||||
extern int xml_parm_save (RIG *rig, const char *outfilename);
|
||||
extern int xml_parm_load (RIG *rig, const char *infilename);
|
||||
extern int xml_save(RIG *rig, const char *outfilename);
|
||||
extern int xml_load(RIG *rig, const char *infilename);
|
||||
extern int xml_parm_save(RIG *rig, const char *outfilename);
|
||||
extern int xml_parm_load(RIG *rig, const char *infilename);
|
||||
|
||||
extern int csv_save (RIG *rig, const char *outfilename);
|
||||
extern int csv_load (RIG *rig, const char *infilename);
|
||||
extern int csv_parm_save (RIG *rig, const char *outfilename);
|
||||
extern int csv_parm_load (RIG *rig, const char *infilename);
|
||||
extern int csv_save(RIG *rig, const char *outfilename);
|
||||
extern int csv_load(RIG *rig, const char *infilename);
|
||||
extern int csv_parm_save(RIG *rig, const char *outfilename);
|
||||
extern int csv_parm_load(RIG *rig, const char *infilename);
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
|
@ -64,328 +64,378 @@ void usage();
|
|||
void version();
|
||||
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,
|
||||
* 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.
|
||||
*/
|
||||
#define SHORT_OPTIONS "m:r:s:c:C:p:axvhV"
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rig-file", 1, 0, 'r'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"civaddr", 1, 0, 'c'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"set-separator", 1, 0, 'p'},
|
||||
{"all", 0, 0, 'a'},
|
||||
static struct option long_options[] = {
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rig-file", 1, 0, 'r'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"civaddr", 1, 0, 'c'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"set-separator", 1, 0, 'p'},
|
||||
{"all", 0, 0, 'a'},
|
||||
#ifdef HAVE_XML2
|
||||
{"xml", 0, 0, 'x'},
|
||||
{"xml", 0, 0, 'x'},
|
||||
#endif
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
#define MAXCONFLEN 128
|
||||
|
||||
int all;
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RIG *rig; /* handle to rig (nstance) */
|
||||
rig_model_t my_model = RIG_MODEL_DUMMY;
|
||||
RIG *rig; /* handle to rig (nstance) */
|
||||
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;
|
||||
const char *rig_file=NULL;
|
||||
int serial_rate = 0;
|
||||
char *civaddr = NULL; /* NULL means no need to set conf */
|
||||
char conf_parms[MAXCONFLEN] = "";
|
||||
extern char csv_sep;
|
||||
int verbose = 0, xml = 0;
|
||||
const char *rig_file = NULL;
|
||||
int serial_rate = 0;
|
||||
char *civaddr = NULL; /* NULL means no need to set conf */
|
||||
char conf_parms[MAXCONFLEN] = "";
|
||||
extern char csv_sep;
|
||||
|
||||
while(1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
while (1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long (argc, argv, SHORT_OPTIONS,
|
||||
long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
|
||||
|
||||
switch(c) {
|
||||
case 'h':
|
||||
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);
|
||||
}
|
||||
csv_sep = optarg[0];
|
||||
break;
|
||||
case 'a':
|
||||
all++;
|
||||
break;
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
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);
|
||||
}
|
||||
|
||||
csv_sep = optarg[0];
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
all++;
|
||||
break;
|
||||
#ifdef HAVE_XML2
|
||||
case 'x':
|
||||
xml++;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
xml++;
|
||||
break;
|
||||
#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);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
|
||||
"<hamlib-developer@lists.sourceforge.net>\n\n");
|
||||
default:
|
||||
usage(); /* unknown option? */
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind+1 >= argc) {
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
rig_set_debug(verbose < 2 ? RIG_DEBUG_WARN : verbose);
|
||||
|
||||
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) {
|
||||
fprintf(stderr, "Unknown rig num %d, or initialization error.\n",
|
||||
my_model);
|
||||
fprintf(stderr, "Please check with --list option.\n");
|
||||
exit(2);
|
||||
}
|
||||
if (optind + 1 >= argc) {
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
retcode = set_conf(rig, conf_parms);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/* check channel support */
|
||||
if (rig->caps->set_channel == NULL && rig->caps->get_channel == NULL &&
|
||||
rig->caps->set_chan_all_cb == NULL && rig->caps->get_chan_all_cb == NULL &&
|
||||
(rig->caps->set_mem == NULL || rig->caps->set_vfo == NULL)) {
|
||||
fprintf(stderr, "Error: rig num %d has no memory support implemented/available.\n",
|
||||
my_model);
|
||||
exit(3);
|
||||
if (rig->caps->set_channel == NULL
|
||||
&& rig->caps->get_channel == NULL
|
||||
&& rig->caps->set_chan_all_cb == NULL
|
||||
&& rig->caps->get_chan_all_cb == NULL
|
||||
&& (rig->caps->set_mem == NULL || rig->caps->set_vfo == NULL)) {
|
||||
|
||||
fprintf(stderr,
|
||||
"Error: rig num %d has no memory support implemented/available.\n",
|
||||
my_model);
|
||||
exit(3);
|
||||
}
|
||||
|
||||
/* check channel description */
|
||||
if (rig->caps->chan_list[0].type == 0) {
|
||||
fprintf(stderr, "Error: rig num %d has no channel list.\n",
|
||||
my_model);
|
||||
exit(3);
|
||||
fprintf(stderr, "Error: rig num %d has no channel list.\n",
|
||||
my_model);
|
||||
exit(3);
|
||||
}
|
||||
|
||||
if (rig_file)
|
||||
strncpy(rig->state.rigport.pathname, rig_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);
|
||||
/* FIXME: bound checking and port type == serial */
|
||||
if (serial_rate != 0) {
|
||||
rig->state.rigport.parm.serial.rate = serial_rate;
|
||||
}
|
||||
|
||||
retcode = rig_open(rig);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
if (civaddr) {
|
||||
rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr);
|
||||
}
|
||||
|
||||
if (verbose > 0)
|
||||
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));
|
||||
retcode = rig_open(rig);
|
||||
|
||||
/* on some rigs, this accelerates the backup/restore */
|
||||
rig_set_vfo(rig, RIG_VFO_MEM);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
if (verbose > 0) {
|
||||
printf("Opened rig model %d, '%s'\n",
|
||||
rig->caps->rig_model,
|
||||
rig->caps->model_name);
|
||||
}
|
||||
|
||||
rig_close(rig); /* close port */
|
||||
rig_cleanup(rig); /* if you care about memory */
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"Backend version: %s, Status: %s\n",
|
||||
rig->caps->version,
|
||||
rig_strstatus(rig->caps->status));
|
||||
|
||||
if (retcode != 0) {
|
||||
fprintf(stderr, "Hamlib error: %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
/* on some rigs, this accelerates the backup/restore */
|
||||
rig_set_vfo(rig, RIG_VFO_MEM);
|
||||
|
||||
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()
|
||||
{
|
||||
printf("rigmem, %s\n\n", hamlib_version);
|
||||
printf("%s\n", hamlib_copyright);
|
||||
printf("rigmem, %s\n\n", hamlib_version);
|
||||
printf("%s\n", hamlib_copyright);
|
||||
}
|
||||
|
||||
|
||||
void usage()
|
||||
{
|
||||
printf("Usage: rigmem [OPTION]... COMMAND...FILE\n"
|
||||
"Backup/restore COMMANDs to a connected radio transceiver or receiver.\n\n");
|
||||
printf("Usage: rigmem [OPTION]... COMMAND...FILE\n"
|
||||
"Backup/restore COMMANDs to a connected radio transceiver or receiver.\n\n");
|
||||
|
||||
|
||||
printf(
|
||||
" -m, --model=ID select radio model number. See model list\n"
|
||||
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -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"
|
||||
printf(
|
||||
" -m, --model=ID select radio model number. See model list\n"
|
||||
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -p, --set-separator=SEP set character separator instead of the CSV comma\n"
|
||||
" -a, --all bypass mem_caps, apply to all fields of channel_t\n"
|
||||
#ifdef HAVE_XML2
|
||||
" -x, --xml use XML format instead of CSV\n"
|
||||
" -x, --xml use XML format instead of CSV\n"
|
||||
#endif
|
||||
" -v, --verbose set verbose mode, cumulative\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n\n"
|
||||
);
|
||||
" -v, --verbose set verbose mode, cumulative\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n\n"
|
||||
);
|
||||
|
||||
printf(
|
||||
"COMMANDs:\n"
|
||||
" load\n"
|
||||
" save\n"
|
||||
" load_parm\n"
|
||||
" save_parm\n"
|
||||
" clear\n\n"
|
||||
);
|
||||
printf(
|
||||
"COMMANDs:\n"
|
||||
" load\n"
|
||||
" save\n"
|
||||
" load_parm\n"
|
||||
" save_parm\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)
|
||||
{
|
||||
char *p, *q, *n;
|
||||
int ret;
|
||||
char *p, *q, *n;
|
||||
int ret;
|
||||
|
||||
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';
|
||||
p = conf_parms;
|
||||
|
||||
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q);
|
||||
if (ret != RIG_OK)
|
||||
return ret;
|
||||
p = n;
|
||||
}
|
||||
return RIG_OK;
|
||||
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);
|
||||
|
||||
if (ret != RIG_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
p = n;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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;
|
||||
channel_t chan;
|
||||
int i, j, ret;
|
||||
channel_t chan;
|
||||
|
||||
memset(&chan, 0, sizeof(chan));
|
||||
chan.freq = RIG_FREQ_NONE;
|
||||
chan.tx_freq = RIG_FREQ_NONE;
|
||||
chan.mode = RIG_MODE_NONE;
|
||||
chan.tx_mode = RIG_MODE_NONE;
|
||||
chan.vfo = RIG_VFO_MEM;
|
||||
memset(&chan, 0, sizeof(chan));
|
||||
chan.freq = RIG_FREQ_NONE;
|
||||
chan.tx_freq = RIG_FREQ_NONE;
|
||||
chan.mode = RIG_MODE_NONE;
|
||||
chan.tx_mode = RIG_MODE_NONE;
|
||||
chan.vfo = RIG_VFO_MEM;
|
||||
|
||||
for (i=0; rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) {
|
||||
for (j = rig->state.chan_list[i].start;
|
||||
j <= rig->state.chan_list[i].end; j++) {
|
||||
chan.channel_num = j;
|
||||
ret = rig_set_channel(rig, &chan);
|
||||
if (ret != RIG_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) {
|
||||
for (j = rig->state.chan_list[i].start;
|
||||
j <= rig->state.chan_list[i].end; j++) {
|
||||
|
||||
return 0;
|
||||
chan.channel_num = j;
|
||||
ret = rig_set_channel(rig, &chan);
|
||||
|
||||
if (ret != RIG_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
611
tests/rigsmtr.c
611
tests/rigsmtr.c
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#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.
|
||||
*/
|
||||
#define SHORT_OPTIONS "m:r:s:c:C:M:R:S:N:vhV"
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rig-file", 1, 0, 'r'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"civaddr", 1, 0, 'c'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"rot-model", 1, 0, 'M'},
|
||||
{"rot-file", 1, 0, 'R'},
|
||||
{"rot-serial-speed", 1, 0, 'S'},
|
||||
{"rot-set-conf", 1, 0, 'N'},
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
static struct option long_options[] = {
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rig-file", 1, 0, 'r'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"civaddr", 1, 0, 'c'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"rot-model", 1, 0, 'M'},
|
||||
{"rot-file", 1, 0, 'R'},
|
||||
{"rot-serial-speed", 1, 0, 'S'},
|
||||
{"rot-set-conf", 1, 0, 'N'},
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
#define MAXCONFLEN 128
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RIG *rig; /* handle to rig (instance) */
|
||||
ROT *rot; /* handle to rotator (instance) */
|
||||
rig_model_t rig_model = RIG_MODEL_DUMMY;
|
||||
rot_model_t rot_model = ROT_MODEL_DUMMY;
|
||||
RIG *rig; /* handle to rig (instance) */
|
||||
ROT *rot; /* handle to rotator (instance) */
|
||||
rig_model_t rig_model = RIG_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;
|
||||
const char *rig_file=NULL, *rot_file=NULL;
|
||||
int serial_rate = 0;
|
||||
int rot_serial_rate = 0;
|
||||
char *civaddr = NULL; /* NULL means no need to set conf */
|
||||
char rig_conf_parms[MAXCONFLEN] = "";
|
||||
char rot_conf_parms[MAXCONFLEN] = "";
|
||||
int verbose = 0;
|
||||
const char *rig_file = NULL, *rot_file = NULL;
|
||||
int serial_rate = 0;
|
||||
int rot_serial_rate = 0;
|
||||
char *civaddr = NULL; /* NULL means no need to set conf */
|
||||
char rig_conf_parms[MAXCONFLEN] = "";
|
||||
char rot_conf_parms[MAXCONFLEN] = "";
|
||||
|
||||
/* int with_rot = 1; */
|
||||
azimuth_t azimuth;
|
||||
elevation_t elevation;
|
||||
unsigned step = 1000000; /* 1e6 us */
|
||||
/* int with_rot = 1; */
|
||||
azimuth_t azimuth;
|
||||
elevation_t elevation;
|
||||
unsigned step = 1000000; /* 1e6 us */
|
||||
|
||||
while(1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
while (1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long (argc, argv, SHORT_OPTIONS,
|
||||
long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
|
||||
|
||||
switch(c) {
|
||||
case 'h':
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
|
||||
"<hamlib-developer@lists.sourceforge.net>\n\n");
|
||||
case 'V':
|
||||
version();
|
||||
exit(0);
|
||||
|
||||
/*
|
||||
* The radio
|
||||
*/
|
||||
rig = rig_init(rig_model);
|
||||
case 'm':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!rig) {
|
||||
fprintf(stderr, "Unknown rig num %d, or initialization error.\n",
|
||||
rig_model);
|
||||
fprintf(stderr, "Please check with --list option.\n");
|
||||
exit(2);
|
||||
}
|
||||
rig_model = atoi(optarg);
|
||||
break;
|
||||
|
||||
retcode = set_conf_rig(rig, rig_conf_parms);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
case 'r':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (rig_file)
|
||||
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
|
||||
rig_file = optarg;
|
||||
break;
|
||||
|
||||
/* 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);
|
||||
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);
|
||||
|
||||
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)) {
|
||||
fprintf(stderr,"rig backend for %s could not get S-Meter"
|
||||
"or has unsufficient capability\nSorry\n",
|
||||
rig->caps->model_name);
|
||||
exit(3);
|
||||
}
|
||||
if (!rig_has_get_level(rig, RIG_LEVEL_STRENGTH)) {
|
||||
fprintf(stderr,
|
||||
"rig backend for %s could not get S-Meter"
|
||||
"or has unsufficient capability\nSorry\n",
|
||||
rig->caps->model_name);
|
||||
exit(3);
|
||||
}
|
||||
|
||||
retcode = rig_open(rig);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
retcode = rig_open(rig);
|
||||
|
||||
if (verbose > 0)
|
||||
printf("Opened rig model %d, '%s'\n", rig->caps->rig_model,
|
||||
rig->caps->model_name);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/*
|
||||
* The rotator
|
||||
*/
|
||||
rot = rot_init(rot_model);
|
||||
if (verbose > 0) {
|
||||
printf("Opened rig model %d, '%s'\n",
|
||||
rig->caps->rig_model,
|
||||
rig->caps->model_name);
|
||||
}
|
||||
|
||||
if (!rot) {
|
||||
fprintf(stderr, "Unknown rot num %d, or initialization error.\n",
|
||||
rot_model);
|
||||
fprintf(stderr, "Please check with --list option.\n");
|
||||
exit(2);
|
||||
}
|
||||
/*
|
||||
* The rotator
|
||||
*/
|
||||
rot = rot_init(rot_model);
|
||||
|
||||
retcode = set_conf_rot(rot, rot_conf_parms);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
if (!rot) {
|
||||
fprintf(stderr,
|
||||
"Unknown rot num %d, or initialization error.\n",
|
||||
rot_model);
|
||||
|
||||
if (rot_file)
|
||||
strncpy(rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
|
||||
fprintf(stderr, "Please check with --list option.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* FIXME: bound checking and port type == serial */
|
||||
if (rot_serial_rate != 0)
|
||||
rot->state.rotport.parm.serial.rate = rot_serial_rate;
|
||||
retcode = set_conf_rot(rot, rot_conf_parms);
|
||||
|
||||
retcode = rot_open(rot);
|
||||
if (retcode != RIG_OK && rot_model != ROT_MODEL_DUMMY) {
|
||||
fprintf(stderr,"rot_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* Commenting out to quell "set but not used" warning.
|
||||
* Enable when needed for further functionality. -N0NB
|
||||
*/
|
||||
/* if (rot_model == ROT_MODEL_DUMMY) */
|
||||
/* with_rot = 1; */
|
||||
if (rot_file) {
|
||||
strncpy(rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
|
||||
}
|
||||
|
||||
if (verbose > 0)
|
||||
printf("Opened rotator model %d, '%s'\n", rot->caps->rot_model,
|
||||
rot->caps->model_name);
|
||||
/* FIXME: bound checking and port type == serial */
|
||||
if (rot_serial_rate != 0) {
|
||||
rot->state.rotport.parm.serial.rate = rot_serial_rate;
|
||||
}
|
||||
|
||||
retcode = rot_open(rot);
|
||||
|
||||
/*******************************/
|
||||
if (optind < argc)
|
||||
step = atof(argv[optind])*1e6;
|
||||
if (retcode != RIG_OK && rot_model != ROT_MODEL_DUMMY) {
|
||||
fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
fprintf(stderr,"Setting rotator to azimuth %.1f°\n",rot->state.min_az);
|
||||
rot_set_position (rot, rot->state.min_az, 0);
|
||||
fprintf(stderr,"Wait for rotator to move...\n");
|
||||
rot_get_position (rot, &azimuth, &elevation);
|
||||
while (fabs(azimuth - rot->state.min_az) > 1.) {
|
||||
rot_get_position (rot, &azimuth, &elevation);
|
||||
usleep(step);
|
||||
}
|
||||
/* Commenting out to quell "set but not used" warning.
|
||||
* Enable when needed for further functionality. -N0NB
|
||||
*/
|
||||
/* if (rot_model == ROT_MODEL_DUMMY) */
|
||||
/* with_rot = 1; */
|
||||
|
||||
fprintf(stderr,"Now initiating full 360° rotation...\n");
|
||||
rot_set_position (rot, rot->state.max_az, 0);
|
||||
if (verbose > 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.) {
|
||||
value_t strength;
|
||||
fprintf(stderr, "Setting rotator to azimuth %.1f°\n", rot->state.min_az);
|
||||
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);
|
||||
rot_close(rot);
|
||||
while (fabs(rot->state.max_az - azimuth) > 1.) {
|
||||
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()
|
||||
{
|
||||
printf("rigsmtr, %s\n\n", hamlib_version);
|
||||
printf("%s\n", hamlib_copyright);
|
||||
printf("rigsmtr, %s\n\n", hamlib_version);
|
||||
printf("%s\n", hamlib_copyright);
|
||||
}
|
||||
|
||||
|
||||
void usage()
|
||||
{
|
||||
printf("Usage: rigsmtr [OPTION]... [time]\n"
|
||||
"Input S-Meter vs Azimuth.\n\n");
|
||||
printf("Usage: rigsmtr [OPTION]... [time]\n"
|
||||
"Input S-Meter vs Azimuth.\n\n");
|
||||
|
||||
printf(
|
||||
" -m, --model=ID select radio model number. See model list\n"
|
||||
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -M, --rot-model=ID select rotator model number. See model list\n"
|
||||
" -R, --rot-file=DEVICE set device of the rotator to operate on\n"
|
||||
" -S, --rot-serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -N, --rot-set-conf=PARM=VAL set rotator config parameters\n"
|
||||
" -v, --verbose set verbose mode, cumulative\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n\n"
|
||||
);
|
||||
printf(
|
||||
" -m, --model=ID select radio model number. See model list\n"
|
||||
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -M, --rot-model=ID select rotator model number. See model list\n"
|
||||
" -R, --rot-file=DEVICE set device of the rotator to operate on\n"
|
||||
" -S, --rot-serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -N, --rot-set-conf=PARM=VAL set rotator config parameters\n"
|
||||
" -v, --verbose set verbose mode, cumulative\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n\n"
|
||||
);
|
||||
|
||||
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)
|
||||
{
|
||||
char *p, *q, *n;
|
||||
int ret;
|
||||
char *p, *q, *n;
|
||||
int ret;
|
||||
|
||||
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';
|
||||
p = conf_parms;
|
||||
|
||||
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q);
|
||||
if (ret != RIG_OK)
|
||||
return ret;
|
||||
p = n;
|
||||
}
|
||||
return RIG_OK;
|
||||
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);
|
||||
|
||||
if (ret != RIG_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
p = n;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
int set_conf_rot(ROT *rot, char *conf_parms)
|
||||
{
|
||||
char *p, *q, *n;
|
||||
int ret;
|
||||
char *p, *q, *n;
|
||||
int ret;
|
||||
|
||||
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';
|
||||
p = conf_parms;
|
||||
|
||||
ret = rot_set_conf(rot, rot_token_lookup(rot, p), q);
|
||||
if (ret != RIG_OK)
|
||||
return ret;
|
||||
p = n;
|
||||
}
|
||||
return RIG_OK;
|
||||
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);
|
||||
|
||||
if (ret != RIG_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
p = n;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
|
478
tests/rigswr.c
478
tests/rigswr.c
|
@ -1,8 +1,7 @@
|
|||
/*
|
||||
* rigswr.c - (C) Stephane Fillod and Thierry Leconte 2004
|
||||
*
|
||||
* This program output swr curve value
|
||||
* using Hamlib.
|
||||
* This program outputs an swr curve value using Hamlib.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -22,7 +21,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#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.
|
||||
*/
|
||||
#define SHORT_OPTIONS "m:r:s:c:C:p:P:vhV"
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rig-file", 1, 0, 'r'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"civaddr", 1, 0, 'c'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"ptt-file", 1, 0, 'p'},
|
||||
{"ptt-type", 1, 0, 'P'},
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
static struct option long_options[] = {
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rig-file", 1, 0, 'r'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"civaddr", 1, 0, 'c'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"ptt-file", 1, 0, 'p'},
|
||||
{"ptt-type", 1, 0, 'P'},
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
#define MAXCONFLEN 128
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RIG *rig; /* handle to rig (nstance) */
|
||||
rig_model_t my_model = RIG_MODEL_DUMMY;
|
||||
RIG *rig; /* handle to rig (nstance) */
|
||||
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;
|
||||
const char *rig_file=NULL, *ptt_file=NULL;
|
||||
ptt_type_t ptt_type = RIG_PTT_NONE;
|
||||
int serial_rate = 0;
|
||||
char *civaddr = NULL; /* NULL means no need to set conf */
|
||||
char conf_parms[MAXCONFLEN] = "";
|
||||
freq_t freq,freqstop;
|
||||
freq_t step=kHz(100);
|
||||
value_t pwr;
|
||||
int verbose = 0;
|
||||
const char *rig_file = NULL, *ptt_file = NULL;
|
||||
ptt_type_t ptt_type = RIG_PTT_NONE;
|
||||
int serial_rate = 0;
|
||||
char *civaddr = NULL; /* NULL means no need to set conf */
|
||||
char conf_parms[MAXCONFLEN] = "";
|
||||
freq_t freq, freqstop;
|
||||
freq_t step = kHz(100);
|
||||
value_t pwr;
|
||||
|
||||
while(1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
while (1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long (argc, argv, SHORT_OPTIONS,
|
||||
long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
|
||||
|
||||
switch(c) {
|
||||
case 'h':
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
|
||||
"<hamlib-developer@lists.sourceforge.net>\n\n");
|
||||
case 'V':
|
||||
version();
|
||||
exit(0);
|
||||
|
||||
if (optind+1 >= argc) {
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
case 'm':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rig = rig_init(my_model);
|
||||
my_model = atoi(optarg);
|
||||
break;
|
||||
|
||||
if (!rig) {
|
||||
fprintf(stderr, "Unknown rig num %d, or initialization error.\n",
|
||||
my_model);
|
||||
fprintf(stderr, "Please check with --list option.\n");
|
||||
exit(2);
|
||||
}
|
||||
case 'r':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
retcode = set_conf(rig, conf_parms);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
rig_file = optarg;
|
||||
break;
|
||||
|
||||
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);
|
||||
case 'c':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (rig_file)
|
||||
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
|
||||
civaddr = optarg;
|
||||
break;
|
||||
|
||||
/* 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);
|
||||
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);
|
||||
|
||||
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) ||
|
||||
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);
|
||||
}
|
||||
if (!rig_has_get_level(rig, RIG_LEVEL_SWR)
|
||||
|| rig->state.pttport.type.ptt == RIG_PTT_NONE) {
|
||||
|
||||
retcode = rig_open(rig);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
fprintf(stderr,
|
||||
"rig backend for %s could not get SWR"
|
||||
"or has unsufficient capability\nSorry\n",
|
||||
rig->caps->model_name);
|
||||
|
||||
if (verbose > 0)
|
||||
printf("Opened rig model %d, '%s'\n", rig->caps->rig_model,
|
||||
rig->caps->model_name);
|
||||
exit(3);
|
||||
}
|
||||
|
||||
freq=atof(argv[optind++]);
|
||||
freqstop=atof(argv[optind++]);
|
||||
if (optind < argc)
|
||||
step=atof(argv[optind]);
|
||||
retcode = rig_open(rig);
|
||||
|
||||
rig_set_freq(rig,RIG_VFO_CURR,freq);
|
||||
rig_set_mode(rig,RIG_VFO_CURR,RIG_MODE_CW,RIG_PASSBAND_NORMAL);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
pwr.f = 0.25; /* 25% of RF POWER */
|
||||
rig_set_level(rig,RIG_VFO_CURR,RIG_LEVEL_RFPOWER,pwr);
|
||||
if (verbose > 0) {
|
||||
printf("Opened rig model %d, '%s'\n",
|
||||
rig->caps->rig_model,
|
||||
rig->caps->model_name);
|
||||
}
|
||||
|
||||
while(freq<=freqstop) {
|
||||
value_t swr;
|
||||
freq = atof(argv[optind++]);
|
||||
freqstop = atof(argv[optind++]);
|
||||
|
||||
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);
|
||||
if (optind < argc) {
|
||||
step = atof(argv[optind]);
|
||||
}
|
||||
|
||||
printf("%10.0f %4.2f\n",freq,swr.f);
|
||||
freq+=step;
|
||||
rig_set_freq(rig,RIG_VFO_CURR,freq);
|
||||
}
|
||||
rig_set_freq(rig, RIG_VFO_CURR, freq);
|
||||
rig_set_mode(rig, RIG_VFO_CURR, RIG_MODE_CW, RIG_PASSBAND_NORMAL);
|
||||
|
||||
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()
|
||||
{
|
||||
printf("rigswr, %s\n\n", hamlib_version);
|
||||
printf("%s\n", hamlib_copyright);
|
||||
printf("rigswr, %s\n\n", hamlib_version);
|
||||
printf("%s\n", hamlib_copyright);
|
||||
}
|
||||
|
||||
|
||||
void usage()
|
||||
{
|
||||
printf("Usage: rigswr [OPTION]... start_freq stop_freq [freq_step]\n"
|
||||
"Output SWR vs Frequency.\n\n");
|
||||
printf("Usage: rigswr [OPTION]... start_freq stop_freq [freq_step]\n"
|
||||
"Output SWR vs Frequency.\n\n");
|
||||
|
||||
|
||||
printf(
|
||||
" -m, --model=ID select radio model number. See model list\n"
|
||||
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
|
||||
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
|
||||
" -v, --verbose set verbose mode, cumulative\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n\n"
|
||||
);
|
||||
printf(
|
||||
" -m, --model=ID select radio model number. See model list\n"
|
||||
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
|
||||
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
|
||||
" -v, --verbose set verbose mode, cumulative\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n\n"
|
||||
);
|
||||
|
||||
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
|
||||
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
int set_conf(RIG *rig, char *conf_parms)
|
||||
{
|
||||
char *p, *q, *n;
|
||||
int ret;
|
||||
char *p, *q, *n;
|
||||
int ret;
|
||||
|
||||
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';
|
||||
p = conf_parms;
|
||||
|
||||
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q);
|
||||
if (ret != RIG_OK)
|
||||
return ret;
|
||||
p = n;
|
||||
}
|
||||
return RIG_OK;
|
||||
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);
|
||||
|
||||
if (ret != RIG_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
p = n;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
|
508
tests/rotctl.c
508
tests/rotctl.c
|
@ -25,7 +25,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -42,7 +42,7 @@
|
|||
# elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */
|
||||
# include <readline.h>
|
||||
# else /* !defined(HAVE_READLINE_H) */
|
||||
extern char *readline ();
|
||||
extern char *readline();
|
||||
# endif /* HAVE_READLINE_H */
|
||||
#else
|
||||
/* no readline */
|
||||
|
@ -56,9 +56,9 @@ extern char *readline ();
|
|||
# elif defined(HAVE_HISTORY_H)
|
||||
# include <history.h>
|
||||
# else /* !defined(HAVE_HISTORY_H) */
|
||||
extern void add_history ();
|
||||
extern int write_history ();
|
||||
extern int read_history ();
|
||||
extern void add_history();
|
||||
extern int write_history();
|
||||
extern int read_history();
|
||||
# endif /* defined(HAVE_READLINE_HISTORY_H) */
|
||||
#else
|
||||
/* no history */
|
||||
|
@ -83,24 +83,23 @@ void usage();
|
|||
* TODO: add an option to read from a file
|
||||
*/
|
||||
#define SHORT_OPTIONS "+m:r:s:C:t:LvhVlu"
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rot-file", 1, 0, 'r'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"send-cmd-term", 1, 0, 't'},
|
||||
{"list", 0, 0, 'l'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"show-conf",0, 0, 'L'},
|
||||
{"dump-caps",0, 0, 'u'},
|
||||
static struct option long_options[] = {
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rot-file", 1, 0, 'r'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"send-cmd-term", 1, 0, 't'},
|
||||
{"list", 0, 0, 'l'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"show-conf", 0, 0, 'L'},
|
||||
{"dump-caps", 0, 0, 'u'},
|
||||
#ifdef HAVE_READLINE_HISTORY
|
||||
{"read-history", 0, 0, 'i'},
|
||||
{"save-history", 0, 0, 'I'},
|
||||
{"read-history", 0, 0, 'i'},
|
||||
{"save-history", 0, 0, 'I'},
|
||||
#endif
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
#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 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_model_t my_model = ROT_MODEL_DUMMY;
|
||||
ROT *my_rot; /* handle to rot (instance) */
|
||||
rot_model_t my_model = ROT_MODEL_DUMMY;
|
||||
|
||||
int retcode; /* generic return code from functions */
|
||||
int exitcode;
|
||||
int retcode; /* generic return code from functions */
|
||||
int exitcode;
|
||||
|
||||
int verbose = 0;
|
||||
int show_conf = 0;
|
||||
int dump_caps_opt = 0;
|
||||
int verbose = 0;
|
||||
int show_conf = 0;
|
||||
int dump_caps_opt = 0;
|
||||
#ifdef HAVE_READLINE_HISTORY
|
||||
int rd_hist = 0;
|
||||
int sv_hist = 0;
|
||||
const char *hist_dir = NULL;
|
||||
const char hist_file[] = "/.rotctl_history";
|
||||
char *hist_path = NULL;
|
||||
struct stat hist_dir_stat;
|
||||
int rd_hist = 0;
|
||||
int sv_hist = 0;
|
||||
const char *hist_dir = NULL;
|
||||
const char hist_file[] = "/.rotctl_history";
|
||||
char *hist_path = NULL;
|
||||
struct stat hist_dir_stat;
|
||||
#endif
|
||||
const char *rot_file=NULL;
|
||||
int serial_rate = 0;
|
||||
char conf_parms[MAXCONFLEN] = "";
|
||||
const char *rot_file = NULL;
|
||||
int serial_rate = 0;
|
||||
char conf_parms[MAXCONFLEN] = "";
|
||||
|
||||
while(1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
while (1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long (argc, argv, SHORT_OPTIONS HST_SHRT_OPTS,
|
||||
long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
c = getopt_long(argc,
|
||||
argv,
|
||||
SHORT_OPTIONS HST_SHRT_OPTS,
|
||||
long_options,
|
||||
&option_index);
|
||||
|
||||
switch(c) {
|
||||
case 'h':
|
||||
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);
|
||||
}
|
||||
rot_file = 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 '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;
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
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);
|
||||
}
|
||||
|
||||
rot_file = 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 '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
|
||||
case 'i':
|
||||
rd_hist++;
|
||||
break;
|
||||
case 'I':
|
||||
sv_hist++;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
rd_hist++;
|
||||
break;
|
||||
|
||||
case 'I':
|
||||
sv_hist++;
|
||||
break;
|
||||
#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);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
|
||||
"<hamlib-developer@lists.sourceforge.net>\n\n");
|
||||
case 'L':
|
||||
show_conf++;
|
||||
break;
|
||||
|
||||
/*
|
||||
* at least one command on command line,
|
||||
* disable interactive mode
|
||||
*/
|
||||
if (optind < argc)
|
||||
interactive = 0;
|
||||
case 'l':
|
||||
rig_set_debug(0);
|
||||
list_models();
|
||||
exit(0);
|
||||
|
||||
my_rot = rot_init(my_model);
|
||||
case 'u':
|
||||
dump_caps_opt++;
|
||||
break;
|
||||
|
||||
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);
|
||||
}
|
||||
default:
|
||||
usage(); /* unknown option? */
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
retcode = set_conf(my_rot, conf_parms);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
rig_set_debug(verbose);
|
||||
|
||||
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);
|
||||
}
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "rotctl, %s\n", hamlib_version);
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"Report bugs to <hamlib-developer@lists.sourceforge.net>\n\n");
|
||||
|
||||
/*
|
||||
* print out capabilities, and exists immediately
|
||||
* We may be interested only in caps, and rig_open may fail.
|
||||
* at least one command on command line,
|
||||
* 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) {
|
||||
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);
|
||||
}
|
||||
|
||||
retcode = rot_open(my_rot);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr,"rot_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
retcode = rot_open(my_rot);
|
||||
|
||||
if (verbose > 0)
|
||||
printf("Opened rot model %d, '%s'\n", my_rot->caps->rot_model,
|
||||
my_rot->caps->model_name);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n",
|
||||
my_rot->caps->version, rig_strstatus(my_rot->caps->status));
|
||||
if (verbose > 0) {
|
||||
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
|
||||
if (interactive && prompt && have_rl) {
|
||||
rl_readline_name = "rotctl";
|
||||
|
||||
if (interactive && prompt && have_rl) {
|
||||
rl_readline_name = "rotctl";
|
||||
#ifdef HAVE_READLINE_HISTORY
|
||||
using_history(); /* Initialize Readline History */
|
||||
using_history(); /* Initialize Readline History */
|
||||
|
||||
if (rd_hist || sv_hist) {
|
||||
if (!(hist_dir = getenv("ROTCTL_HIST_DIR")))
|
||||
hist_dir = getenv("HOME");
|
||||
if (rd_hist || sv_hist) {
|
||||
if (!(hist_dir = getenv("ROTCTL_HIST_DIR"))) {
|
||||
hist_dir = getenv("HOME");
|
||||
}
|
||||
|
||||
if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT))
|
||||
|| !(S_ISDIR(hist_dir_stat.st_mode))) {
|
||||
fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir);
|
||||
}
|
||||
if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT))
|
||||
|| !(S_ISDIR(hist_dir_stat.st_mode))) {
|
||||
|
||||
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));
|
||||
strncat(hist_path, hist_file, strlen(hist_file));
|
||||
}
|
||||
hist_path = (char *)calloc((sizeof(char)
|
||||
* (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 /* HAVE_LIBREADLINE */
|
||||
}
|
||||
|
||||
do {
|
||||
retcode = rotctl_parse(my_rot, stdin, stdout, argv, argc);
|
||||
if (retcode == 2)
|
||||
exitcode = 2;
|
||||
}
|
||||
while (retcode == 0 || retcode == 2);
|
||||
#endif /* HAVE_LIBREADLINE */
|
||||
|
||||
do {
|
||||
retcode = rotctl_parse(my_rot, stdin, stdout, argv, argc);
|
||||
|
||||
if (retcode == 2) {
|
||||
exitcode = 2;
|
||||
}
|
||||
} while (retcode == 0 || retcode == 2);
|
||||
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
if (interactive && prompt && have_rl) {
|
||||
|
||||
if (interactive && prompt && have_rl) {
|
||||
#ifdef HAVE_READLINE_HISTORY
|
||||
if (sv_hist && hist_path)
|
||||
if (write_history(hist_path) == ENOENT)
|
||||
fprintf(stderr, "\nWarning: Could not write history to %s\n", hist_path);
|
||||
|
||||
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 */
|
||||
if (sv_hist && hist_path) {
|
||||
if (write_history(hist_path) == ENOENT) {
|
||||
fprintf(stderr,
|
||||
"\nWarning: Could not write history to %s\n",
|
||||
hist_path);
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
printf("Usage: rotctl [OPTION]... [COMMAND]...\n"
|
||||
"Send COMMANDs to a connected antenna rotator.\n\n");
|
||||
printf("Usage: rotctl [OPTION]... [COMMAND]...\n"
|
||||
"Send COMMANDs to a connected antenna rotator.\n\n");
|
||||
|
||||
|
||||
printf(
|
||||
" -m, --model=ID select rotator model number. See model list\n"
|
||||
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -t, --send-cmd-term=CHAR set send_cmd command termination char\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -L, --show-conf list all config parameters\n"
|
||||
" -l, --list list all model numbers and exit\n"
|
||||
" -u, --dump-caps dump capabilities and exit\n"
|
||||
printf(
|
||||
" -m, --model=ID select rotator model number. See model list\n"
|
||||
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -t, --send-cmd-term=CHAR set send_cmd command termination char\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -L, --show-conf list all config parameters\n"
|
||||
" -l, --list list all model numbers and exit\n"
|
||||
" -u, --dump-caps dump capabilities and exit\n"
|
||||
#ifdef HAVE_READLINE_HISTORY
|
||||
" -i, --read-history read prior interactive session history\n"
|
||||
" -I, --save-history save current interactive session history\n"
|
||||
" -i, --read-history read prior interactive session history\n"
|
||||
" -I, --save-history save current interactive session history\n"
|
||||
#endif
|
||||
" -v, --verbose set verbose mode, cumulative\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n\n"
|
||||
);
|
||||
" -v, --verbose set verbose mode, cumulative\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n\n"
|
||||
);
|
||||
|
||||
usage_rot(stdout);
|
||||
usage_rot(stdout);
|
||||
|
||||
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
|
||||
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
|
||||
}
|
||||
|
|
2347
tests/rotctl_parse.c
2347
tests/rotctl_parse.c
Plik diff jest za duży
Load Diff
|
@ -32,7 +32,7 @@
|
|||
* 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);
|
||||
|
||||
#endif /* ROTCTL_PARSE_H */
|
||||
#endif /* ROTCTL_PARSE_H */
|
||||
|
|
776
tests/rotctld.c
776
tests/rotctld.c
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -39,26 +39,26 @@
|
|||
#include <sys/types.h> /* See NOTES */
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
# include <arpa/inet.h>
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
# include <sys/socket.h>
|
||||
# include <sys/socket.h>
|
||||
#elif HAVE_WS2TCPIP_H
|
||||
# include <ws2tcpip.h>
|
||||
# include <fcntl.h>
|
||||
# if defined(HAVE_WSPIAPI_H)
|
||||
# include <wspiapi.h>
|
||||
# endif
|
||||
# include <ws2tcpip.h>
|
||||
# include <fcntl.h>
|
||||
# if defined(HAVE_WSPIAPI_H)
|
||||
# include <wspiapi.h>
|
||||
# endif
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
# include <netdb.h>
|
||||
# include <netdb.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PTHREAD
|
||||
# include <pthread.h>
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <hamlib/rotator.h>
|
||||
|
@ -67,13 +67,13 @@
|
|||
#include "rotctl_parse.h"
|
||||
|
||||
struct handle_data {
|
||||
ROT *rot;
|
||||
int sock;
|
||||
struct sockaddr_storage cli_addr;
|
||||
socklen_t clilen;
|
||||
ROT *rot;
|
||||
int sock;
|
||||
struct sockaddr_storage cli_addr;
|
||||
socklen_t clilen;
|
||||
};
|
||||
|
||||
void *handle_socket(void *arg);
|
||||
void * handle_socket(void *arg);
|
||||
|
||||
void usage();
|
||||
|
||||
|
@ -85,245 +85,258 @@ void usage();
|
|||
*/
|
||||
#define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVl"
|
||||
static struct option long_options[] = {
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rot-file", 1, 0, 'r'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"port", 1, 0, 't'},
|
||||
{"listen-addr", 1, 0, 'T'},
|
||||
{"list", 0, 0, 'l'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"show-conf", 0, 0, 'L'},
|
||||
{"dump-caps", 0, 0, 'u'},
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rot-file", 1, 0, 'r'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"port", 1, 0, 't'},
|
||||
{"listen-addr", 1, 0, 'T'},
|
||||
{"list", 0, 0, 'l'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"show-conf", 0, 0, 'L'},
|
||||
{"dump-caps", 0, 0, 'u'},
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int interactive = 1; /* no cmd because of daemon */
|
||||
int prompt = 0 ; /* Daemon mode for rigparse return string */
|
||||
|
||||
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
|
||||
|
||||
|
||||
static void handle_error(enum rig_debug_level_e lvl, const char *msg)
|
||||
{
|
||||
int e;
|
||||
int e;
|
||||
#ifdef __MINGW32__
|
||||
LPVOID lpMsgBuf;
|
||||
LPVOID lpMsgBuf;
|
||||
|
||||
lpMsgBuf = (LPVOID)"Unknown error";
|
||||
e = WSAGetLastError();
|
||||
lpMsgBuf = (LPVOID)"Unknown error";
|
||||
e = WSAGetLastError();
|
||||
|
||||
if (FormatMessage(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, e,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
// Default language
|
||||
(LPTSTR)&lpMsgBuf, 0, NULL)) {
|
||||
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);
|
||||
}
|
||||
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
||||
| FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
e,
|
||||
// Default language
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR)&lpMsgBuf,
|
||||
0,
|
||||
NULL)) {
|
||||
|
||||
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
|
||||
e = errno;
|
||||
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e));
|
||||
e = errno;
|
||||
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ROT *my_rot; /* handle to rot (instance) */
|
||||
rot_model_t my_model = ROT_MODEL_DUMMY;
|
||||
ROT *my_rot; /* handle to rot (instance) */
|
||||
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 show_conf = 0;
|
||||
int dump_caps_opt = 0;
|
||||
const char *rot_file = NULL;
|
||||
int serial_rate = 0;
|
||||
char conf_parms[MAXCONFLEN] = "";
|
||||
int verbose = 0;
|
||||
int show_conf = 0;
|
||||
int dump_caps_opt = 0;
|
||||
const char *rot_file = NULL;
|
||||
int serial_rate = 0;
|
||||
char conf_parms[MAXCONFLEN] = "";
|
||||
|
||||
struct addrinfo hints, *result, *saved_result;
|
||||
int sock_listen;
|
||||
int reuseaddr = 1;
|
||||
int sockopt;
|
||||
char host[NI_MAXHOST];
|
||||
char serv[NI_MAXSERV];
|
||||
struct addrinfo hints, *result, *saved_result;
|
||||
int sock_listen;
|
||||
int reuseaddr = 1;
|
||||
int sockopt;
|
||||
char host[NI_MAXHOST];
|
||||
char serv[NI_MAXSERV];
|
||||
|
||||
#ifdef HAVE_PTHREAD
|
||||
pthread_t thread;
|
||||
pthread_attr_t attr;
|
||||
pthread_t thread;
|
||||
pthread_attr_t attr;
|
||||
#endif
|
||||
struct handle_data *arg;
|
||||
struct handle_data *arg;
|
||||
|
||||
while (1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
while (1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long(argc, argv, SHORT_OPTIONS,
|
||||
long_options, &option_index);
|
||||
c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index);
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage();
|
||||
exit(0);
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage();
|
||||
exit(0);
|
||||
|
||||
case 'V':
|
||||
version();
|
||||
exit(0);
|
||||
case 'V':
|
||||
version();
|
||||
exit(0);
|
||||
|
||||
case 'm':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
case 'm':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
my_model = atoi(optarg);
|
||||
break;
|
||||
my_model = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
case 'r':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rot_file = optarg;
|
||||
break;
|
||||
rot_file = optarg;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
case 's':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
serial_rate = atoi(optarg);
|
||||
break;
|
||||
serial_rate = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
case 'C':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (*conf_parms != '\0')
|
||||
strcat(conf_parms, ",");
|
||||
if (*conf_parms != '\0') {
|
||||
strcat(conf_parms, ",");
|
||||
}
|
||||
|
||||
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
|
||||
break;
|
||||
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
|
||||
break;
|
||||
|
||||
case 't':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
case 't':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
portno = optarg;
|
||||
break;
|
||||
portno = optarg;
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
case 'T':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
src_addr = optarg;
|
||||
break;
|
||||
src_addr = optarg;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
show_conf++;
|
||||
break;
|
||||
case 'L':
|
||||
show_conf++;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
list_models();
|
||||
exit(0);
|
||||
case 'l':
|
||||
list_models();
|
||||
exit(0);
|
||||
|
||||
case 'u':
|
||||
dump_caps_opt++;
|
||||
break;
|
||||
case 'u':
|
||||
dump_caps_opt++;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(); /* unknown option? */
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
default:
|
||||
usage(); /* unknown option? */
|
||||
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, "Report bugs to "
|
||||
"<hamlib-developer@lists.sourceforge.net>\n\n");
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "rotctld, %s\n", hamlib_version);
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"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) {
|
||||
fprintf(stderr, "Unknown rot num %d, or initialization error.\n",
|
||||
my_model);
|
||||
fprintf(stderr, "Please check with --list option.\n");
|
||||
exit(2);
|
||||
}
|
||||
if (!my_rot) {
|
||||
fprintf(stderr,
|
||||
"Unknown rot num %d, or initialization error.\n",
|
||||
my_model);
|
||||
|
||||
retcode = set_conf(my_rot, conf_parms);
|
||||
fprintf(stderr, "Please check with --list option.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
retcode = set_conf(my_rot, conf_parms);
|
||||
|
||||
if (rot_file)
|
||||
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* FIXME: bound checking and port type == serial */
|
||||
if (serial_rate != 0)
|
||||
my_rot->state.rotport.parm.serial.rate = serial_rate;
|
||||
if (rot_file) {
|
||||
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* print out conf parameters
|
||||
*/
|
||||
if (show_conf) {
|
||||
rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
|
||||
}
|
||||
/* FIXME: bound checking and port type == serial */
|
||||
if (serial_rate != 0) {
|
||||
my_rot->state.rotport.parm.serial.rate = serial_rate;
|
||||
}
|
||||
|
||||
/*
|
||||
* print out conf parameters, and exits immediately
|
||||
* 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);
|
||||
}
|
||||
/*
|
||||
* print out conf parameters
|
||||
*/
|
||||
if (show_conf) {
|
||||
rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
|
||||
}
|
||||
|
||||
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) {
|
||||
fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
retcode = rot_open(my_rot);
|
||||
|
||||
if (verbose > 0)
|
||||
printf("Opened rot model %d, '%s'\n", my_rot->caps->rot_model,
|
||||
my_rot->caps->model_name);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n",
|
||||
my_rot->caps->version, rig_strstatus(my_rot->caps->status));
|
||||
if (verbose > 0) {
|
||||
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__
|
||||
# ifndef SO_OPENTYPE
|
||||
|
@ -336,267 +349,304 @@ int main(int argc, char *argv[])
|
|||
# define INVALID_SOCKET -1
|
||||
# endif
|
||||
|
||||
WSADATA wsadata;
|
||||
WSADATA wsadata;
|
||||
|
||||
if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) {
|
||||
fprintf(stderr, "WSAStartup socket error\n");
|
||||
exit(1);
|
||||
}
|
||||
if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) {
|
||||
fprintf(stderr, "WSAStartup socket error\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sockopt = SO_SYNCHRONOUS_NONALERT;
|
||||
setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&sockopt, sizeof(sockopt));
|
||||
sockopt = SO_SYNCHRONOUS_NONALERT;
|
||||
setsockopt(INVALID_SOCKET,
|
||||
SOL_SOCKET,
|
||||
SO_OPENTYPE,
|
||||
(char *)&sockopt,
|
||||
sizeof(sockopt));
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Prepare listening socket
|
||||
*/
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
||||
hints.ai_socktype = SOCK_STREAM;/* TCP socket */
|
||||
hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
|
||||
hints.ai_protocol = 0; /* Any protocol */
|
||||
/*
|
||||
* Prepare listening socket
|
||||
*/
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
||||
hints.ai_socktype = SOCK_STREAM; /* TCP socket */
|
||||
hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
|
||||
hints.ai_protocol = 0; /* Any protocol */
|
||||
|
||||
retcode = getaddrinfo(src_addr, portno, &hints, &result);
|
||||
retcode = getaddrinfo(src_addr, portno, &hints, &result);
|
||||
|
||||
if (retcode != 0) {
|
||||
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
if (retcode != 0) {
|
||||
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
saved_result = result;
|
||||
saved_result = result;
|
||||
|
||||
do {
|
||||
sock_listen = socket(result->ai_family, result->ai_socktype,
|
||||
result->ai_protocol);
|
||||
do {
|
||||
sock_listen = socket(result->ai_family,
|
||||
result->ai_socktype,
|
||||
result->ai_protocol);
|
||||
|
||||
if (sock_listen < 0) {
|
||||
handle_error(RIG_DEBUG_ERR, "socket");
|
||||
freeaddrinfo(result); /* No longer needed */
|
||||
exit(1);
|
||||
}
|
||||
if (sock_listen < 0) {
|
||||
handle_error(RIG_DEBUG_ERR, "socket");
|
||||
freeaddrinfo(result); /* No longer needed */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *)&reuseaddr, sizeof(reuseaddr)) < 0) {
|
||||
handle_error(RIG_DEBUG_ERR, "setsockopt");
|
||||
freeaddrinfo(result); /* No longer needed */
|
||||
exit(1);
|
||||
}
|
||||
if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *)&reuseaddr, sizeof(reuseaddr)) < 0) {
|
||||
|
||||
handle_error(RIG_DEBUG_ERR, "setsockopt");
|
||||
freeaddrinfo(result); /* No longer needed */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef IPV6_V6ONLY
|
||||
|
||||
if (AF_INET6 == result->ai_family) {
|
||||
/* allow IPv4 mapped to IPv6 clients, MS & BSD default this
|
||||
to 1 i.e. disallowed */
|
||||
sockopt = 0;
|
||||
if (AF_INET6 == result->ai_family) {
|
||||
/* allow IPv4 mapped to IPv6 clients, MS & BSD default this
|
||||
to 1 i.e. disallowed */
|
||||
sockopt = 0;
|
||||
|
||||
if (setsockopt(sock_listen, IPPROTO_IPV6, IPV6_V6ONLY,
|
||||
(char *)&sockopt, sizeof(sockopt)) < 0) {
|
||||
handle_error(RIG_DEBUG_ERR, "setsockopt");
|
||||
freeaddrinfo(saved_result); /* No longer needed */
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (setsockopt(sock_listen,
|
||||
IPPROTO_IPV6,
|
||||
IPV6_V6ONLY,
|
||||
(char *)&sockopt,
|
||||
sizeof(sockopt))
|
||||
< 0) {
|
||||
|
||||
handle_error(RIG_DEBUG_ERR, "setsockopt");
|
||||
freeaddrinfo(saved_result); /* No longer needed */
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) {
|
||||
break;
|
||||
}
|
||||
if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) {
|
||||
break;
|
||||
}
|
||||
|
||||
handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)");
|
||||
handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)");
|
||||
#ifdef __MINGW32__
|
||||
closesocket(sock_listen);
|
||||
closesocket(sock_listen);
|
||||
#else
|
||||
close(sock_listen);
|
||||
close(sock_listen);
|
||||
#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) {
|
||||
rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n");
|
||||
exit(1);
|
||||
}
|
||||
if (NULL == result) {
|
||||
rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (listen(sock_listen, 4) < 0) {
|
||||
handle_error(RIG_DEBUG_ERR, "listening");
|
||||
exit(1);
|
||||
}
|
||||
if (listen(sock_listen, 4) < 0) {
|
||||
handle_error(RIG_DEBUG_ERR, "listening");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef SIGPIPE
|
||||
/* Ignore SIGPIPE as we will handle it at the write()/send() calls
|
||||
that will consequently fail with EPIPE. All child threads will
|
||||
inherit this disposition which is what we want. */
|
||||
/* Ignore SIGPIPE as we will handle it at the write()/send() calls
|
||||
that will consequently fail with EPIPE. All child threads will
|
||||
inherit this disposition which is what we want. */
|
||||
#if HAVE_SIGACTION
|
||||
struct sigaction act;
|
||||
memset (&act, 0, sizeof act);
|
||||
act.sa_handler = SIG_IGN;
|
||||
act.sa_flags = SA_RESTART;
|
||||
if (sigaction (SIGPIPE, &act, NULL)) {
|
||||
handle_error (RIG_DEBUG_ERR, "sigaction");
|
||||
}
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof act);
|
||||
act.sa_handler = SIG_IGN;
|
||||
act.sa_flags = SA_RESTART;
|
||||
|
||||
if (sigaction(SIGPIPE, &act, NULL)) {
|
||||
handle_error(RIG_DEBUG_ERR, "sigaction");
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
/*
|
||||
* main loop accepting connections
|
||||
*/
|
||||
do {
|
||||
arg = malloc(sizeof(struct handle_data));
|
||||
/*
|
||||
* main loop accepting connections
|
||||
*/
|
||||
do {
|
||||
arg = malloc(sizeof(struct handle_data));
|
||||
|
||||
if (!arg) {
|
||||
rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (!arg) {
|
||||
rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
arg->rot = my_rot;
|
||||
arg->clilen = sizeof(arg->cli_addr);
|
||||
arg->sock = accept(sock_listen, (struct sockaddr *) &arg->cli_addr,
|
||||
&arg->clilen);
|
||||
arg->rot = my_rot;
|
||||
arg->clilen = sizeof(arg->cli_addr);
|
||||
arg->sock = accept(sock_listen,
|
||||
(struct sockaddr *) &arg->cli_addr,
|
||||
&arg->clilen);
|
||||
|
||||
if (arg->sock < 0) {
|
||||
handle_error(RIG_DEBUG_ERR, "accept");
|
||||
break;
|
||||
}
|
||||
if (arg->sock < 0) {
|
||||
handle_error(RIG_DEBUG_ERR, "accept");
|
||||
break;
|
||||
}
|
||||
|
||||
if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr, arg->clilen,
|
||||
host, sizeof(host), serv, sizeof(serv),
|
||||
NI_NOFQDN)) < 0) {
|
||||
rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode));
|
||||
}
|
||||
if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr,
|
||||
arg->clilen,
|
||||
host,
|
||||
sizeof(host),
|
||||
serv,
|
||||
sizeof(serv),
|
||||
NI_NOFQDN))
|
||||
< 0) {
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Connection opened from %s:%s\n",
|
||||
host, serv);
|
||||
rig_debug(RIG_DEBUG_WARN,
|
||||
"Peer lookup error: %s",
|
||||
gai_strerror(retcode));
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"Connection opened from %s:%s\n",
|
||||
host,
|
||||
serv);
|
||||
|
||||
#ifdef HAVE_PTHREAD
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
pthread_attr_init(&attr);
|
||||
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) {
|
||||
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
|
||||
break;
|
||||
}
|
||||
if (retcode != 0) {
|
||||
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
|
||||
break;
|
||||
}
|
||||
|
||||
#else
|
||||
handle_socket(arg);
|
||||
handle_socket(arg);
|
||||
#endif
|
||||
} while (retcode == 0);
|
||||
} while (retcode == 0);
|
||||
|
||||
rot_close(my_rot); /* close port */
|
||||
rot_cleanup(my_rot); /* if you care about memory */
|
||||
rot_close(my_rot); /* close port */
|
||||
rot_cleanup(my_rot); /* if you care about memory */
|
||||
|
||||
#ifdef __MINGW32__
|
||||
WSACleanup();
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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;
|
||||
FILE *fsockin;
|
||||
FILE *fsockout;
|
||||
int retcode;
|
||||
char host[NI_MAXHOST];
|
||||
char serv[NI_MAXSERV];
|
||||
struct handle_data *handle_data_arg = (struct handle_data *)arg;
|
||||
FILE *fsockin;
|
||||
FILE *fsockout;
|
||||
int retcode;
|
||||
char host[NI_MAXHOST];
|
||||
char serv[NI_MAXSERV];
|
||||
|
||||
#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) {
|
||||
rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno));
|
||||
goto handle_exit;
|
||||
}
|
||||
if (sock_osfhandle == -1) {
|
||||
rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno));
|
||||
goto handle_exit;
|
||||
}
|
||||
|
||||
fsockin = _fdopen(sock_osfhandle, "rb");
|
||||
fsockin = _fdopen(sock_osfhandle, "rb");
|
||||
#else
|
||||
fsockin = fdopen(handle_data_arg->sock, "rb");
|
||||
fsockin = fdopen(handle_data_arg->sock, "rb");
|
||||
#endif
|
||||
|
||||
if (!fsockin) {
|
||||
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
|
||||
goto handle_exit;
|
||||
}
|
||||
if (!fsockin) {
|
||||
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
|
||||
goto handle_exit;
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
fsockout = _fdopen(sock_osfhandle, "wb");
|
||||
fsockout = _fdopen(sock_osfhandle, "wb");
|
||||
#else
|
||||
fsockout = fdopen(handle_data_arg->sock, "wb");
|
||||
fsockout = fdopen(handle_data_arg->sock, "wb");
|
||||
#endif
|
||||
|
||||
if (!fsockout) {
|
||||
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
|
||||
fclose(fsockin);
|
||||
goto handle_exit;
|
||||
}
|
||||
if (!fsockout) {
|
||||
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
|
||||
fclose(fsockin);
|
||||
goto handle_exit;
|
||||
}
|
||||
|
||||
do {
|
||||
retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0);
|
||||
do {
|
||||
retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0);
|
||||
|
||||
if (ferror(fsockin) || ferror(fsockout))
|
||||
retcode = 1;
|
||||
} while (retcode == 0 || retcode == 2);
|
||||
if (ferror(fsockin) || ferror(fsockout)) {
|
||||
retcode = 1;
|
||||
}
|
||||
} while (retcode == 0 || retcode == 2);
|
||||
|
||||
if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr,
|
||||
handle_data_arg->clilen, host, sizeof(host),
|
||||
serv, sizeof(serv), NI_NOFQDN)) < 0) {
|
||||
rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode));
|
||||
}
|
||||
if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr,
|
||||
handle_data_arg->clilen,
|
||||
host,
|
||||
sizeof(host),
|
||||
serv,
|
||||
sizeof(serv),
|
||||
NI_NOFQDN))
|
||||
< 0) {
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Connection closed from %s:%s\n",
|
||||
host, serv);
|
||||
rig_debug(RIG_DEBUG_WARN,
|
||||
"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__
|
||||
fclose(fsockout);
|
||||
fclose(fsockout);
|
||||
#endif
|
||||
|
||||
handle_exit:
|
||||
#ifdef __MINGW32__
|
||||
closesocket(handle_data_arg->sock);
|
||||
closesocket(handle_data_arg->sock);
|
||||
#else
|
||||
close(handle_data_arg->sock);
|
||||
close(handle_data_arg->sock);
|
||||
#endif
|
||||
free(arg);
|
||||
free(arg);
|
||||
|
||||
#ifdef HAVE_PTHREAD
|
||||
pthread_exit(NULL);
|
||||
pthread_exit(NULL);
|
||||
#endif
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void usage()
|
||||
{
|
||||
printf("Usage: rotctld [OPTION]... [COMMAND]...\n"
|
||||
"Daemon serving COMMANDs to a connected antenna rotator.\n\n");
|
||||
printf("Usage: rotctld [OPTION]... [COMMAND]...\n"
|
||||
"Daemon serving COMMANDs to a connected antenna rotator.\n\n");
|
||||
|
||||
printf(
|
||||
" -m, --model=ID select rotator model number. See model list\n"
|
||||
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -t, --port=NUM set TCP listening port, default %s\n"
|
||||
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -L, --show-conf list all config parameters\n"
|
||||
" -l, --list list all model numbers and exit\n"
|
||||
" -u, --dump-caps dump capabilities and exit\n"
|
||||
" -v, --verbose set verbose mode, cumulative\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n\n",
|
||||
portno);
|
||||
printf(
|
||||
" -m, --model=ID select rotator model number. See model list\n"
|
||||
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -t, --port=NUM set TCP listening port, default %s\n"
|
||||
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -L, --show-conf list all config parameters\n"
|
||||
" -l, --list list all model numbers and exit\n"
|
||||
" -u, --dump-caps dump capabilities and exit\n"
|
||||
" -v, --verbose set verbose mode, cumulative\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n\n",
|
||||
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");
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -42,232 +42,339 @@
|
|||
|
||||
int sprintf_vfo(char *str, vfo_t vfo)
|
||||
{
|
||||
int i, len=0;
|
||||
const char *sv;
|
||||
int i, len = 0;
|
||||
const char *sv;
|
||||
|
||||
*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);
|
||||
*str = '\0';
|
||||
|
||||
for (i=0; i<16; i++) {
|
||||
sv = rig_strvfo(vfo & RIG_VFO_N(i));
|
||||
if (sv && sv[0]) len += sprintf(str+len, "%s ", sv);
|
||||
}
|
||||
if (vfo == RIG_VFO_NONE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 i, len=0;
|
||||
int i, len = 0;
|
||||
|
||||
*str = '\0';
|
||||
if (mode == RIG_MODE_NONE)
|
||||
return 0;
|
||||
*str = '\0';
|
||||
|
||||
for (i = 0; i < 30; i++) {
|
||||
const char *ms = rig_strrmode(mode & (1UL<<i));
|
||||
if (!ms || !ms[0])
|
||||
continue; /* unknown, FIXME! */
|
||||
strcat(str, ms);
|
||||
strcat(str, " ");
|
||||
len += strlen(ms) + 1;
|
||||
}
|
||||
return len;
|
||||
if (mode == RIG_MODE_NONE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < 30; i++) {
|
||||
const char *ms = rig_strrmode(mode & (1UL << i));
|
||||
|
||||
if (!ms || !ms[0]) {
|
||||
continue; /* unknown, FIXME! */
|
||||
}
|
||||
|
||||
strcat(str, ms);
|
||||
strcat(str, " ");
|
||||
len += strlen(ms) + 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int sprintf_func(char *str, setting_t func)
|
||||
{
|
||||
int i, len=0;
|
||||
int i, len = 0;
|
||||
|
||||
*str = '\0';
|
||||
if (func == RIG_FUNC_NONE)
|
||||
return 0;
|
||||
*str = '\0';
|
||||
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++) {
|
||||
const char *ms = rig_strfunc(func & rig_idx2setting(i));
|
||||
if (!ms || !ms[0])
|
||||
continue; /* unknown, FIXME! */
|
||||
strcat(str, ms);
|
||||
strcat(str, " ");
|
||||
len += strlen(ms) + 1;
|
||||
}
|
||||
return len;
|
||||
if (func == RIG_FUNC_NONE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++) {
|
||||
const char *ms = rig_strfunc(func & rig_idx2setting(i));
|
||||
|
||||
if (!ms || !ms[0]) {
|
||||
continue; /* unknown, FIXME! */
|
||||
}
|
||||
|
||||
strcat(str, ms);
|
||||
strcat(str, " ");
|
||||
len += strlen(ms) + 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int sprintf_level(char *str, setting_t level)
|
||||
{
|
||||
int i, len=0;
|
||||
int i, len = 0;
|
||||
|
||||
*str = '\0';
|
||||
if (level == RIG_LEVEL_NONE)
|
||||
return 0;
|
||||
*str = '\0';
|
||||
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++) {
|
||||
const char *ms = rig_strlevel(level & rig_idx2setting(i));
|
||||
if (!ms || !ms[0])
|
||||
continue; /* unknown, FIXME! */
|
||||
strcat(str, ms);
|
||||
strcat(str, " ");
|
||||
len += strlen(ms) + 1;
|
||||
}
|
||||
return len;
|
||||
if (level == RIG_LEVEL_NONE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++) {
|
||||
const char *ms = rig_strlevel(level & rig_idx2setting(i));
|
||||
|
||||
if (!ms || !ms[0]) {
|
||||
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 len=0;
|
||||
int len = 0;
|
||||
|
||||
*str = '\0';
|
||||
if (!extlevels)
|
||||
return 0;
|
||||
*str = '\0';
|
||||
|
||||
for (; extlevels->token != RIG_CONF_END; extlevels++) {
|
||||
if (!extlevels->name)
|
||||
continue; /* no name */
|
||||
switch (extlevels->type) {
|
||||
case RIG_CONF_CHECKBUTTON:
|
||||
case RIG_CONF_COMBO:
|
||||
case RIG_CONF_NUMERIC:
|
||||
case RIG_CONF_STRING:
|
||||
strcat(str, extlevels->name);
|
||||
strcat(str, " ");
|
||||
len += strlen(extlevels->name) + 1;
|
||||
break;
|
||||
case RIG_CONF_BUTTON:
|
||||
/* ignore case RIG_CONF_BUTTON */
|
||||
break;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
if (!extlevels) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (; extlevels->token != RIG_CONF_END; extlevels++) {
|
||||
if (!extlevels->name) {
|
||||
continue; /* no name */
|
||||
}
|
||||
|
||||
switch (extlevels->type) {
|
||||
case RIG_CONF_CHECKBUTTON:
|
||||
case RIG_CONF_COMBO:
|
||||
case RIG_CONF_NUMERIC:
|
||||
case RIG_CONF_STRING:
|
||||
strcat(str, extlevels->name);
|
||||
strcat(str, " ");
|
||||
len += strlen(extlevels->name) + 1;
|
||||
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 i, len=0;
|
||||
int i, len = 0;
|
||||
|
||||
*str = '\0';
|
||||
if (level == RIG_LEVEL_NONE)
|
||||
return 0;
|
||||
*str = '\0';
|
||||
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++) {
|
||||
const char *ms;
|
||||
if (level == RIG_LEVEL_NONE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(level & rig_idx2setting(i)))
|
||||
continue;
|
||||
ms = rig_strlevel(level & rig_idx2setting(i));
|
||||
if (!ms || !ms[0]) {
|
||||
if (level != DUMMY_ALL && level != RIG_LEVEL_SET(DUMMY_ALL))
|
||||
rig_debug(RIG_DEBUG_BUG, "unknown level idx %d\n", i);
|
||||
continue;
|
||||
}
|
||||
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;
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++) {
|
||||
const char *ms;
|
||||
|
||||
if (!(level & rig_idx2setting(i))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ms = rig_strlevel(level & rig_idx2setting(i));
|
||||
|
||||
if (!ms || !ms[0]) {
|
||||
if (level != DUMMY_ALL && level != RIG_LEVEL_SET(DUMMY_ALL)) {
|
||||
rig_debug(RIG_DEBUG_BUG, "unknown level idx %d\n", i);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
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 i, len=0;
|
||||
int i, len = 0;
|
||||
|
||||
*str = '\0';
|
||||
if (parm == RIG_PARM_NONE)
|
||||
return 0;
|
||||
*str = '\0';
|
||||
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++) {
|
||||
const char *ms = rig_strparm(parm & rig_idx2setting(i));
|
||||
if (!ms || !ms[0])
|
||||
continue; /* unknown, FIXME! */
|
||||
strcat(str, ms);
|
||||
strcat(str, " ");
|
||||
len += strlen(ms) + 1;
|
||||
}
|
||||
return len;
|
||||
if (parm == RIG_PARM_NONE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++) {
|
||||
const char *ms = rig_strparm(parm & rig_idx2setting(i));
|
||||
|
||||
if (!ms || !ms[0]) {
|
||||
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 i, len=0;
|
||||
int i, len = 0;
|
||||
|
||||
*str = '\0';
|
||||
if (parm == RIG_PARM_NONE)
|
||||
return 0;
|
||||
*str = '\0';
|
||||
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++) {
|
||||
const char *ms;
|
||||
if (!(parm & rig_idx2setting(i)))
|
||||
continue;
|
||||
ms = rig_strparm(parm & rig_idx2setting(i));
|
||||
if (!ms || !ms[0]) {
|
||||
if (parm != DUMMY_ALL && parm != RIG_PARM_SET(DUMMY_ALL))
|
||||
rig_debug(RIG_DEBUG_BUG, "unknown parm idx %d\n", i);
|
||||
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;
|
||||
if (parm == RIG_PARM_NONE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++) {
|
||||
const char *ms;
|
||||
|
||||
if (!(parm & rig_idx2setting(i))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ms = rig_strparm(parm & rig_idx2setting(i));
|
||||
|
||||
if (!ms || !ms[0]) {
|
||||
if (parm != DUMMY_ALL && parm != RIG_PARM_SET(DUMMY_ALL)) {
|
||||
rig_debug(RIG_DEBUG_BUG, "unknown parm idx %d\n", i);
|
||||
}
|
||||
|
||||
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 i, len=0;
|
||||
int i, len = 0;
|
||||
|
||||
*str = '\0';
|
||||
if (op == RIG_OP_NONE)
|
||||
return 0;
|
||||
*str = '\0';
|
||||
|
||||
for (i = 0; i < 30; i++) {
|
||||
const char *ms = rig_strvfop(op & (1UL<<i));
|
||||
if (!ms || !ms[0])
|
||||
continue; /* unknown, FIXME! */
|
||||
strcat(str, ms);
|
||||
strcat(str, " ");
|
||||
len += strlen(ms) + 1;
|
||||
}
|
||||
return len;
|
||||
if (op == RIG_OP_NONE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < 30; i++) {
|
||||
const char *ms = rig_strvfop(op & (1UL << i));
|
||||
|
||||
if (!ms || !ms[0]) {
|
||||
continue; /* unknown, FIXME! */
|
||||
}
|
||||
|
||||
strcat(str, ms);
|
||||
strcat(str, " ");
|
||||
len += strlen(ms) + 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int sprintf_scan(char *str, scan_t rscan)
|
||||
{
|
||||
int i, len=0;
|
||||
int i, len = 0;
|
||||
|
||||
*str = '\0';
|
||||
if (rscan == RIG_SCAN_NONE)
|
||||
return 0;
|
||||
*str = '\0';
|
||||
|
||||
for (i = 0; i < 30; i++) {
|
||||
const char *ms = rig_strscan(rscan & (1UL<<i));
|
||||
if (!ms || !ms[0])
|
||||
continue; /* unknown, FIXME! */
|
||||
strcat(str, ms);
|
||||
strcat(str, " ");
|
||||
len += strlen(ms) + 1;
|
||||
}
|
||||
return len;
|
||||
if (rscan == RIG_SCAN_NONE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < 30; i++) {
|
||||
const char *ms = rig_strscan(rscan & (1UL << i));
|
||||
|
||||
if (!ms || !ms[0]) {
|
||||
continue; /* unknown, FIXME! */
|
||||
}
|
||||
|
||||
strcat(str, ms);
|
||||
strcat(str, " ");
|
||||
len += strlen(ms) + 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -15,40 +15,50 @@
|
|||
|
||||
#define MAXDIGITS 32
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned char b[(MAXDIGITS+1)/2];
|
||||
freq_t f=0;
|
||||
int digits = 10;
|
||||
int i;
|
||||
unsigned char b[(MAXDIGITS + 1) / 2];
|
||||
freq_t f = 0;
|
||||
int digits = 10;
|
||||
int i;
|
||||
|
||||
if (argc != 2 && argc != 3) {
|
||||
fprintf(stderr,"Usage: %s <freq> [digits]\n",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if (argc != 2 && argc != 3) {
|
||||
fprintf(stderr, "Usage: %s <freq> [digits]\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
f = (freq_t)atoll(argv[1]);
|
||||
if (argc > 2) {
|
||||
digits = atoi(argv[2]);
|
||||
if (digits > MAXDIGITS)
|
||||
exit(1);
|
||||
}
|
||||
f = (freq_t)atoll(argv[1]);
|
||||
|
||||
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));
|
||||
if (argc > 2) {
|
||||
digits = atoi(argv[2]);
|
||||
|
||||
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));
|
||||
if (digits > MAXDIGITS) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -14,49 +14,50 @@
|
|||
#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 (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
|
||||
|
||||
printf("%s\n", hamlib_version);
|
||||
printf("caps size: %lu\n", (long unsigned) sizeof(struct rig_caps));
|
||||
printf("state size: %lu\n", (long unsigned) sizeof(struct rig_state));
|
||||
printf("RIG size: %lu\n", (long unsigned) sizeof(struct rig));
|
||||
printf("freq_t size: %lu\n", (long unsigned) sizeof(freq_t));
|
||||
printf("shortfreq_t size: %lu\n", (long unsigned) sizeof(shortfreq_t));
|
||||
printf("%s\n", hamlib_version);
|
||||
printf("caps size: %lu\n", (long unsigned) sizeof(struct rig_caps));
|
||||
printf("state size: %lu\n", (long unsigned) sizeof(struct rig_state));
|
||||
printf("RIG size: %lu\n", (long unsigned) sizeof(struct rig));
|
||||
printf("freq_t size: %lu\n", (long unsigned) sizeof(freq_t));
|
||||
printf("shortfreq_t size: %lu\n", (long unsigned) sizeof(shortfreq_t));
|
||||
|
||||
/* freq on 31bits test */
|
||||
f = GHz(2);
|
||||
printf("GHz(2) = %"PRIll"\n", (int64_t)f);
|
||||
/* freq on 31bits test */
|
||||
f = GHz(2);
|
||||
printf("GHz(2) = %"PRIll"\n", (int64_t)f);
|
||||
|
||||
/* freq on 32bits test */
|
||||
f = GHz(4);
|
||||
printf("GHz(4) = %"PRIll"\n", (int64_t)f);
|
||||
/* freq on 32bits test */
|
||||
f = GHz(4);
|
||||
printf("GHz(4) = %"PRIll"\n", (int64_t)f);
|
||||
|
||||
/* freq on >32bits test */
|
||||
f = GHz(5);
|
||||
printf("GHz(5) = %"PRIll"\n", (int64_t)f);
|
||||
/* freq on >32bits test */
|
||||
f = GHz(5);
|
||||
printf("GHz(5) = %"PRIll"\n", (int64_t)f);
|
||||
|
||||
/* floating point to freq conversion test */
|
||||
f = GHz(1.3);
|
||||
printf("GHz(1.3) = %"PRIll"\n", (int64_t)f);
|
||||
/* floating point to freq conversion test */
|
||||
f = GHz(1.3);
|
||||
printf("GHz(1.3) = %"PRIll"\n", (int64_t)f);
|
||||
|
||||
/* floating point to freq conversion precision test */
|
||||
f = GHz(1.234567890);
|
||||
printf("GHz(1.234567890) = %"PRIll"\n", (int64_t)f);
|
||||
/* floating point to freq conversion precision test */
|
||||
f = GHz(1.234567890);
|
||||
printf("GHz(1.234567890) = %"PRIll"\n", (int64_t)f);
|
||||
|
||||
/* floating point to freq conversion precision test, with freq >32bits */
|
||||
f = GHz(123.456789012);
|
||||
printf("GHz(123.456789012) = %"PRIll"\n", (int64_t)f);
|
||||
/* floating point to freq conversion precision test, with freq >32bits */
|
||||
f = GHz(123.456789012);
|
||||
printf("GHz(123.456789012) = %"PRIll"\n", (int64_t)f);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
382
tests/testloc.c
382
tests/testloc.c
|
@ -17,200 +17,246 @@
|
|||
#include <hamlib/rotator.h>
|
||||
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
char recodedloc[13], *loc1, *loc2, sign;
|
||||
double lon1, lat1, lon2, lat2;
|
||||
double distance, az, mmm, sec;
|
||||
int deg, min, retcode, loc_len, nesw = 0;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char recodedloc[13], *loc1, *loc2, sign;
|
||||
double lon1, lat1, lon2, lat2;
|
||||
double distance, az, mmm, sec;
|
||||
int deg, min, retcode, loc_len, nesw = 0;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s <locator1> <precision> [<locator2>]\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if (argc < 2) {
|
||||
fprintf(stderr,
|
||||
"Usage: %s <locator1> <precision> [<locator2>]\n",
|
||||
argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
loc1 = argv[1];
|
||||
loc_len = argc > 2 ? atoi(argv[2]) : strlen(loc1)/2;
|
||||
loc2 = argc > 3 ? argv[3] : NULL;
|
||||
loc1 = argv[1];
|
||||
loc_len = argc > 2 ? atoi(argv[2]) : strlen(loc1) / 2;
|
||||
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 */
|
||||
retcode = locator2longlat(&lon1, &lat1, loc1);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "locator2longlat() failed with malformed input.\n");
|
||||
exit(2);
|
||||
}
|
||||
/* hamlib function to convert maidenhead to decimal degrees */
|
||||
retcode = locator2longlat(&lon1, &lat1, loc1);
|
||||
|
||||
/* hamlib function to convert decimal degrees to deg, min, sec */
|
||||
retcode = dec2dms(lon1, °, &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", lon1, sign, deg, min, sec);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "locator2longlat() failed with malformed input.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* hamlib function to convert deg, min, sec to decimal degrees */
|
||||
lon1 = dms2dec(deg, min, sec, nesw);
|
||||
printf(" Recoded lon:\t%f\n", lon1);
|
||||
/* hamlib function to convert decimal degrees to deg, min, sec */
|
||||
retcode = dec2dms(lon1, °, &min, &sec, &nesw);
|
||||
|
||||
/* hamlib function to convert decimal degrees to deg decimal minutes */
|
||||
retcode = dec2dmmm(lon1, °, &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", lon1, sign, deg, mmm);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* hamlib function to convert deg, decimal min to decimal degrees */
|
||||
lon1 = dmmm2dec(deg, mmm, nesw);
|
||||
printf(" Recoded GPS:\t%f\n", lon1);
|
||||
if (nesw == 1) {
|
||||
sign = '-';
|
||||
} else {
|
||||
sign = '\0';
|
||||
}
|
||||
|
||||
/* hamlib function to convert decimal degrees to deg, min, sec */
|
||||
retcode = dec2dms(lat1, °, &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);
|
||||
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 */
|
||||
lat1 = dms2dec(deg, min, sec, nesw);
|
||||
printf(" Recoded lat:\t%f\n", lat1);
|
||||
/* hamlib function to convert deg, min, sec to decimal degrees */
|
||||
lon1 = dms2dec(deg, min, sec, nesw);
|
||||
printf(" Recoded lon:\t%f\n", lon1);
|
||||
|
||||
/* hamlib function to convert decimal degrees to deg decimal minutes */
|
||||
retcode = dec2dmmm(lat1, °, &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 decimal degrees to deg decimal minutes */
|
||||
retcode = dec2dmmm(lon1, °, &mmm, &nesw);
|
||||
|
||||
/* hamlib function to convert deg, decimal min to decimal degrees */
|
||||
lat1 = dmmm2dec(deg, mmm, nesw);
|
||||
printf(" Recoded GPS:\t%f\n", lat1);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* hamlib function to convert decimal degrees to maidenhead */
|
||||
retcode = longlat2locator(lon1, lat1, recodedloc, loc_len);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
|
||||
exit(2);
|
||||
}
|
||||
printf(" Recoded:\t%s\n", recodedloc);
|
||||
if (nesw == 1) {
|
||||
sign = '-';
|
||||
} else {
|
||||
sign = '\0';
|
||||
}
|
||||
|
||||
if (loc2 == NULL)
|
||||
exit(0);
|
||||
printf(" GPS lon:\t%f\t%c%d %.3f'\n", lon1, sign, deg, mmm);
|
||||
|
||||
/* Now work on the second locator */
|
||||
printf("\nLocator2:\t%s\n", loc2);
|
||||
/* hamlib function to convert deg, decimal min to decimal degrees */
|
||||
lon1 = dmmm2dec(deg, mmm, nesw);
|
||||
printf(" Recoded GPS:\t%f\n", lon1);
|
||||
|
||||
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(lat1, °, &min, &sec, &nesw);
|
||||
|
||||
/* hamlib function to convert decimal degrees to deg, min, sec */
|
||||
retcode = dec2dms(lon2, °, &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);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* hamlib function to convert deg, min, sec to decimal degrees */
|
||||
lon2 = dms2dec(deg, min, sec, nesw);
|
||||
printf(" Recoded lon:\t%f\n", lon2);
|
||||
if (nesw == 1) {
|
||||
sign = '-';
|
||||
} else {
|
||||
sign = '\0';
|
||||
}
|
||||
|
||||
/* hamlib function to convert decimal degrees to deg decimal minutes */
|
||||
retcode = dec2dmmm(lon2, °, &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);
|
||||
printf(" Latitude:\t%f\t%c%d %d' %.2f\"\n", lat1, sign, deg, min, sec);
|
||||
|
||||
/* 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 deg, min, sec to decimal degrees */
|
||||
lat1 = dms2dec(deg, min, sec, nesw);
|
||||
printf(" Recoded lat:\t%f\n", lat1);
|
||||
|
||||
/* hamlib function to convert decimal degrees to deg, min, sec */
|
||||
retcode = dec2dms(lat2, °, &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 decimal degrees to deg decimal minutes */
|
||||
retcode = dec2dmmm(lat1, °, &mmm, &nesw);
|
||||
|
||||
/* hamlib function to convert deg, min, sec to decimal degrees */
|
||||
lat2 = dms2dec(deg, min, sec, nesw);
|
||||
printf(" Recoded lat:\t%f\n", lat2);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* hamlib function to convert decimal degrees to deg decimal minutes */
|
||||
retcode = dec2dmmm(lat2, °, &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);
|
||||
if (nesw == 1) {
|
||||
sign = '-';
|
||||
} else {
|
||||
sign = '\0';
|
||||
}
|
||||
|
||||
/* hamlib function to convert deg, decimal min to decimal degrees */
|
||||
lat2 = dmmm2dec(deg, mmm, nesw);
|
||||
printf(" Recoded GPS:\t%f\n", lat2);
|
||||
printf(" GPS lat:\t%f\t%c%d %.3f'\n", lat1, sign, deg, mmm);
|
||||
|
||||
/* 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);
|
||||
/* hamlib function to convert deg, decimal min to decimal degrees */
|
||||
lat1 = dmmm2dec(deg, mmm, nesw);
|
||||
printf(" Recoded GPS:\t%f\n", lat1);
|
||||
|
||||
retcode = qrb(lon1, lat1, lon2, lat2, &distance, &az);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "QRB error: %d\n", retcode);
|
||||
exit(2);
|
||||
}
|
||||
/* hamlib function to convert decimal degrees to maidenhead */
|
||||
retcode = longlat2locator(lon1, lat1, recodedloc, loc_len);
|
||||
|
||||
dec2dms(az, °, &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);
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
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, °, &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, °, &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, °, &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, °, &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, °, &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);
|
||||
}
|
||||
|
|
520
tests/testrig.c
520
tests/testrig.c
|
@ -10,7 +10,7 @@
|
|||
#include <hamlib/rig.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
/* HAVE_SSLEEP is defined when Windows Sleep is found
|
||||
|
@ -27,356 +27,386 @@
|
|||
*
|
||||
*/
|
||||
#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP))
|
||||
#include "hl_sleep.h"
|
||||
# include "hl_sleep.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define SERIAL_PORT "/dev/ttyS0"
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RIG *my_rig; /* handle to rig (nstance) */
|
||||
freq_t freq; /* frequency */
|
||||
rmode_t rmode; /* radio mode of operation */
|
||||
pbwidth_t width;
|
||||
vfo_t vfo; /* vfo selection */
|
||||
int strength; /* S-Meter level */
|
||||
int rit = 0; /* RIT status */
|
||||
int xit = 0; /* XIT status */
|
||||
int retcode; /* generic return code from functions */
|
||||
RIG *my_rig; /* handle to rig (nstance) */
|
||||
freq_t freq; /* frequency */
|
||||
rmode_t rmode; /* radio mode of operation */
|
||||
pbwidth_t width;
|
||||
vfo_t vfo; /* vfo selection */
|
||||
int strength; /* S-Meter level */
|
||||
int rit = 0; /* RIT status */
|
||||
int xit = 0; /* XIT status */
|
||||
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 */
|
||||
rig_set_debug_level(RIG_DEBUG_NONE);
|
||||
/* Turn off backend debugging ouput */
|
||||
rig_set_debug_level(RIG_DEBUG_NONE);
|
||||
|
||||
/*
|
||||
* allocate memory, setup & open port
|
||||
*/
|
||||
/*
|
||||
* allocate memory, setup & open port
|
||||
*/
|
||||
|
||||
if (argc < 2) {
|
||||
hamlib_port_t myport;
|
||||
/* may be overriden by backend probe */
|
||||
myport.type.rig = RIG_PORT_SERIAL;
|
||||
myport.parm.serial.rate = 9600;
|
||||
myport.parm.serial.data_bits = 8;
|
||||
myport.parm.serial.stop_bits = 1;
|
||||
myport.parm.serial.parity = RIG_PARITY_NONE;
|
||||
myport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
|
||||
strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1);
|
||||
if (argc < 2) {
|
||||
hamlib_port_t myport;
|
||||
/* may be overriden by backend probe */
|
||||
myport.type.rig = RIG_PORT_SERIAL;
|
||||
myport.parm.serial.rate = 9600;
|
||||
myport.parm.serial.data_bits = 8;
|
||||
myport.parm.serial.stop_bits = 1;
|
||||
myport.parm.serial.parity = RIG_PARITY_NONE;
|
||||
myport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
|
||||
strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1);
|
||||
|
||||
rig_load_all_backends();
|
||||
myrig_model = rig_probe(&myport);
|
||||
} else {
|
||||
myrig_model = atoi(argv[1]);
|
||||
}
|
||||
rig_load_all_backends();
|
||||
myrig_model = rig_probe(&myport);
|
||||
} else {
|
||||
myrig_model = atoi(argv[1]);
|
||||
}
|
||||
|
||||
my_rig = rig_init(myrig_model);
|
||||
my_rig = rig_init(myrig_model);
|
||||
|
||||
if (!my_rig) {
|
||||
fprintf(stderr,"Unknown rig num: %d\n", myrig_model);
|
||||
fprintf(stderr,"Please check riglist.h\n");
|
||||
exit(1); /* whoops! something went wrong (mem alloc?) */
|
||||
}
|
||||
if (!my_rig) {
|
||||
fprintf(stderr, "Unknown rig num: %d\n", myrig_model);
|
||||
fprintf(stderr, "Please check riglist.h\n");
|
||||
exit(1); /* whoops! something went wrong (mem alloc?) */
|
||||
}
|
||||
|
||||
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);
|
||||
if (retcode != RIG_OK) {
|
||||
printf("rig_open: error = %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
retcode = rig_open(my_rig);
|
||||
|
||||
printf("Port %s opened ok\n", SERIAL_PORT);
|
||||
if (retcode != RIG_OK) {
|
||||
printf("rig_open: error = %s\n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Below are examples of set/get routines.
|
||||
* Must add checking of functionality map prior to command execution -- FS
|
||||
*
|
||||
*/
|
||||
printf("Port %s opened ok\n", SERIAL_PORT);
|
||||
|
||||
/*
|
||||
* Example of setting rig paameters
|
||||
* and some error checking on the return code.
|
||||
*/
|
||||
/*
|
||||
* Below are examples of set/get routines.
|
||||
* 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 */
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM,
|
||||
rig_passband_narrow(my_rig, RIG_MODE_FM));
|
||||
printf("\nSetting 10m FM Narrow...\n");
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 29620000); /* 10m */
|
||||
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);
|
||||
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
|
||||
if (retcode != RIG_OK) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
|
||||
printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
|
||||
freq / 1000000, rig_strrmode(rmode), width / 1000.0);
|
||||
sleep(1); /* so you can see it -- FS */
|
||||
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
|
||||
|
||||
/* 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 */
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_USB,
|
||||
rig_passband_normal(my_rig, RIG_MODE_USB));
|
||||
/* 15m USB */
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
printf("Setting 15m USB...\n");
|
||||
|
||||
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 21235175); /* 15m */
|
||||
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",
|
||||
freq / 1000000, rig_strrmode(rmode), width / 1000.0);
|
||||
sleep(1);
|
||||
if (retcode != RIG_OK) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_LSB, RIG_PASSBAND_NORMAL);
|
||||
/* 40m LSB */
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
printf("Setting 40m LSB...\n");
|
||||
|
||||
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 7250100); /* 40m */
|
||||
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",
|
||||
freq / 1000000, rig_strrmode(rmode), width / 1000.0);
|
||||
sleep(1);
|
||||
if (retcode != RIG_OK) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM,
|
||||
rig_passband_narrow(my_rig, RIG_MODE_AM));
|
||||
/* 80m AM Narrow */
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
printf("Setting 80m AM Narrow...\n");
|
||||
|
||||
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 3885000); /* 80m */
|
||||
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",
|
||||
freq / 1000000, rig_strrmode(rmode), width / 1000.0);
|
||||
sleep(1);
|
||||
if (retcode != RIG_OK) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_CW, RIG_PASSBAND_NORMAL);
|
||||
sleep(1);
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
/* 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: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
|
||||
freq / 1000, rig_strrmode(rmode), width );
|
||||
sleep(1);
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 1875000); /* 160m */
|
||||
retcode = rig_set_mode(my_rig,
|
||||
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,
|
||||
rig_passband_narrow(my_rig, RIG_MODE_CW));
|
||||
printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
|
||||
freq / 1000,
|
||||
rig_strrmode(rmode), width);
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
|
||||
/* 160m CW Narrow -- The band is noisy tonight -- FS*/
|
||||
|
||||
printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
|
||||
freq / 1000, rig_strrmode(rmode), width);
|
||||
sleep(1);
|
||||
printf("Setting 160m CW Narrow...\n");
|
||||
|
||||
/* 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 */
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM, RIG_PASSBAND_NORMAL);
|
||||
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
|
||||
freq / 1000,
|
||||
rig_strrmode(rmode), width);
|
||||
|
||||
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
|
||||
sleep(1);
|
||||
|
||||
printf(" Freq: %.3f kHz, Mode: %s, Passband: %.3f kHz\n\n",
|
||||
freq / 1000, rig_strrmode(rmode), width / 1000.0);
|
||||
sleep(1);
|
||||
/* AM Broadcast band */
|
||||
|
||||
/* 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);
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 14250375); /* cq de vk3fcs */
|
||||
if (retcode != RIG_OK) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
|
||||
|
||||
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
rig_get_vfo(my_rig, &vfo);
|
||||
printf(" Freq: %.3f kHz, Mode: %s, Passband: %.3f kHz\n\n",
|
||||
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_freq(my_rig, RIG_VFO_A, 14295125); /* cq de vk3fcs */
|
||||
retcode = rig_set_vfo(my_rig, RIG_VFO_A);
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 14250375); /* cq de vk3fcs */
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
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);
|
||||
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));
|
||||
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
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 145100000); /* 2m */
|
||||
sleep(2);
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 435125000); /* 70cm */
|
||||
sleep(2);
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 145100000); /* 2m */
|
||||
sleep(2);
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 435125000); /* 70cm */
|
||||
sleep(2);
|
||||
#endif
|
||||
|
||||
printf("Setting rig Mode to LSB.\n");
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_LSB, RIG_PASSBAND_NORMAL);
|
||||
printf("Setting rig Mode to LSB.\n");
|
||||
retcode = rig_set_mode(my_rig,
|
||||
RIG_VFO_CURR,
|
||||
RIG_MODE_LSB,
|
||||
RIG_PASSBAND_NORMAL);
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_mode: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
if (retcode != RIG_OK) {
|
||||
printf("rig_set_mode: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
sleep(1);
|
||||
|
||||
printf("Setting rig PTT ON.\n");
|
||||
retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_ON ); /* stand back ! */
|
||||
printf("Setting rig PTT ON.\n");
|
||||
retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_ON); /* stand back ! */
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_ptt: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
if (retcode != RIG_OK) {
|
||||
printf("rig_set_ptt: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
sleep(1);
|
||||
|
||||
printf("Setting rig PTT OFF.\n");
|
||||
retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_OFF ); /* phew ! */
|
||||
printf("Setting rig PTT OFF.\n");
|
||||
retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_OFF); /* phew ! */
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_ptt: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
if (retcode != RIG_OK) {
|
||||
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");
|
||||
retcode = rig_get_vfo(my_rig, &vfo); /* try to get vfo info */
|
||||
printf("\nGet various raw rig values:\n");
|
||||
retcode = rig_get_vfo(my_rig, &vfo); /* try to get vfo info */
|
||||
|
||||
if (retcode == RIG_OK ) {
|
||||
printf("rig_get_vfo: vfo = %i \n", vfo);
|
||||
} else {
|
||||
printf("rig_get_vfo: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
if (retcode == RIG_OK) {
|
||||
printf("rig_get_vfo: vfo = %i \n", vfo);
|
||||
} else {
|
||||
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 ) {
|
||||
printf("rig_get_freq: freq = %"PRIfreq"\n", freq);
|
||||
} else {
|
||||
printf("rig_get_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
if (retcode == RIG_OK) {
|
||||
printf("rig_get_freq: freq = %"PRIfreq"\n", freq);
|
||||
} else {
|
||||
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 ) {
|
||||
printf("rig_get_mode: mode = %i \n", rmode);
|
||||
} else {
|
||||
printf("rig_get_mode: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
if (retcode == RIG_OK) {
|
||||
printf("rig_get_mode: mode = %i \n", rmode);
|
||||
} else {
|
||||
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 ) {
|
||||
printf("rig_get_strength: strength = %i \n", strength);
|
||||
} else {
|
||||
printf("rig_get_strength: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
if (retcode == RIG_OK) {
|
||||
printf("rig_get_strength: strength = %i \n", strength);
|
||||
} else {
|
||||
printf("rig_get_strength: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
|
||||
if (rig_has_set_func(my_rig, RIG_FUNC_RIT)) {
|
||||
retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, 1);
|
||||
printf("rig_set_func: Setting RIT ON\n");
|
||||
}
|
||||
if (rig_has_set_func(my_rig, RIG_FUNC_RIT)) {
|
||||
retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, 1);
|
||||
printf("rig_set_func: Setting RIT ON\n");
|
||||
}
|
||||
|
||||
if (rig_has_get_func(my_rig, RIG_FUNC_RIT)) {
|
||||
retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, &rit);
|
||||
printf("rig_get_func: RIT: %d\n", rit);
|
||||
}
|
||||
if (rig_has_get_func(my_rig, RIG_FUNC_RIT)) {
|
||||
retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, &rit);
|
||||
printf("rig_get_func: RIT: %d\n", rit);
|
||||
}
|
||||
|
||||
if (rig_has_set_func(my_rig, RIG_FUNC_XIT)) {
|
||||
retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, 1);
|
||||
printf("rig_set_func: Setting XIT ON\n");
|
||||
}
|
||||
if (rig_has_set_func(my_rig, RIG_FUNC_XIT)) {
|
||||
retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, 1);
|
||||
printf("rig_set_func: Setting XIT ON\n");
|
||||
}
|
||||
|
||||
if (rig_has_get_func(my_rig, RIG_FUNC_XIT)) {
|
||||
retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, &xit);
|
||||
printf("rig_get_func: XIT: %d\n", xit);
|
||||
}
|
||||
if (rig_has_get_func(my_rig, RIG_FUNC_XIT)) {
|
||||
retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, &xit);
|
||||
printf("rig_get_func: XIT: %d\n", xit);
|
||||
}
|
||||
|
||||
rig_close(my_rig); /* close port */
|
||||
rig_cleanup(my_rig); /* if you care about memory */
|
||||
rig_close(my_rig); /* close port */
|
||||
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;
|
||||
}
|
||||
|
|
118
tests/testtrn.c
118
tests/testtrn.c
|
@ -10,7 +10,7 @@
|
|||
#include <hamlib/rig.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
/* HAVE_SSLEEP is defined when Windows Sleep is found
|
||||
|
@ -27,88 +27,88 @@
|
|||
*
|
||||
*/
|
||||
#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP))
|
||||
#include "hl_sleep.h"
|
||||
# include "hl_sleep.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define SERIAL_PORT "/dev/ttyS0"
|
||||
|
||||
|
||||
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);
|
||||
*count_ptr += 1;
|
||||
printf("Rig changed freq to %"PRIfreq"Hz\n", freq);
|
||||
*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) */
|
||||
int retcode; /* generic return code from functions */
|
||||
int i, count = 0;
|
||||
RIG *my_rig; /* handle to rig (nstance) */
|
||||
int retcode; /* generic return code from functions */
|
||||
int i, count = 0;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr,"%s <rig_num>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "%s <rig_num>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("testrig:hello, I am your main() !\n");
|
||||
printf("testrig:hello, I am your main() !\n");
|
||||
|
||||
/*
|
||||
* allocate memory, setup & open port
|
||||
*/
|
||||
/*
|
||||
* allocate memory, setup & open port
|
||||
*/
|
||||
|
||||
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?) */
|
||||
}
|
||||
my_rig = rig_init(atoi(argv[1]));
|
||||
|
||||
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))
|
||||
exit(2);
|
||||
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
|
||||
|
||||
printf("Port %s opened ok\n", SERIAL_PORT);
|
||||
if (rig_open(my_rig)) {
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Below are examples of set/get routines.
|
||||
* Must add checking of functionality map prior to command execution -- FS
|
||||
*
|
||||
*/
|
||||
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
|
||||
*
|
||||
*/
|
||||
|
||||
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("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
printf("Frequency changed %d times\n", count);
|
||||
|
||||
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 ) {
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue