diff --git a/tests/dumpcaps.c b/tests/dumpcaps.c index 40482b03f..26de7256a 100644 --- a/tests/dumpcaps.c +++ b/tests/dumpcaps.c @@ -20,7 +20,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -38,572 +38,841 @@ int range_sanity_check(const struct freq_range_list range_list[], int rx); int ts_sanity_check(const struct tuning_step_list tuning_step[]); static void dump_chan_caps(const channel_cap_t *chan, FILE *fout); + /* * the rig may be in rig_init state, but not openned */ -int dumpcaps (RIG* rig, FILE *fout) +int dumpcaps(RIG *rig, FILE *fout) { - const struct rig_caps *caps; - int status, i; - int can_esplit, can_echannel; - char freqbuf[20]; - int backend_warnings = 0; - static char prntbuf[1024]; /* a malloc would be better.. */ + const struct rig_caps *caps; + int status, i; + int can_esplit, can_echannel; + char freqbuf[20]; + int backend_warnings = 0; + static char prntbuf[1024]; /* a malloc would be better.. */ - if (!rig || !rig->caps) - return -RIG_EINVAL; + if (!rig || !rig->caps) { + return -RIG_EINVAL; + } - caps = rig->caps; + caps = rig->caps; - fprintf(fout, "Caps dump for model: %d\n", caps->rig_model); - fprintf(fout, "Model name:\t%s\n", caps->model_name); - fprintf(fout, "Mfg name:\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%s\n", rig_strstatus(caps->status)); - fprintf(fout, "Rig type:\t"); - switch (caps->rig_type & RIG_TYPE_MASK) { - case RIG_TYPE_TRANSCEIVER: - fprintf(fout, "Transceiver\n"); - break; - case RIG_TYPE_HANDHELD: - fprintf(fout, "Handheld\n"); - break; - case RIG_TYPE_MOBILE: - fprintf(fout, "Mobile\n"); - break; - case RIG_TYPE_RECEIVER: - fprintf(fout, "Receiver\n"); - break; - case RIG_TYPE_PCRECEIVER: - fprintf(fout, "PC Receiver\n"); - break; - case RIG_TYPE_SCANNER: - fprintf(fout, "Scanner\n"); - break; - case RIG_TYPE_TRUNKSCANNER: - fprintf(fout, "Trunking scanner\n"); - break; - case RIG_TYPE_COMPUTER: - fprintf(fout, "Computer\n"); - break; - case RIG_TYPE_TUNER: - fprintf(fout, "Tuner\n"); - break; - case RIG_TYPE_OTHER: - fprintf(fout, "Other\n"); - break; - default: - fprintf(fout, "Unknown\n"); - backend_warnings++; - } + fprintf(fout, "Caps dump for model: %d\n", caps->rig_model); + fprintf(fout, "Model name:\t%s\n", caps->model_name); + fprintf(fout, "Mfg name:\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%s\n", rig_strstatus(caps->status)); + fprintf(fout, "Rig type:\t"); - fprintf(fout, "PTT type:\t"); - switch (caps->ptt_type) { - case RIG_PTT_RIG: - fprintf(fout, "Rig capable\n"); - break; - case RIG_PTT_RIG_MICDATA: - fprintf(fout, "Rig capable (Mic/Data)\n"); - break; - case RIG_PTT_PARALLEL: - fprintf(fout, "Parallel port (DATA0)\n"); - break; - case RIG_PTT_SERIAL_RTS: - fprintf(fout, "Serial port (CTS/RTS)\n"); - break; - case RIG_PTT_SERIAL_DTR: - fprintf(fout, "Serial port (DTR/DSR)\n"); - break; - case RIG_PTT_NONE: - fprintf(fout, "None\n"); - break; - default: - fprintf(fout, "Unknown\n"); - backend_warnings++; - } + switch (caps->rig_type & RIG_TYPE_MASK) { + case RIG_TYPE_TRANSCEIVER: + fprintf(fout, "Transceiver\n"); + break; - fprintf(fout, "DCD type:\t"); - switch (caps->dcd_type) { - case RIG_DCD_RIG: - fprintf(fout, "Rig capable\n"); - break; - case RIG_DCD_PARALLEL: - fprintf(fout, "Parallel port (/STROBE)\n"); - break; - case RIG_DCD_SERIAL_CTS: - fprintf(fout, "Serial port (CTS/RTS)\n"); - break; - case RIG_DCD_SERIAL_DSR: - fprintf(fout, "Serial port (DTR/DSR)\n"); - break; - case RIG_DCD_SERIAL_CAR: - fprintf(fout, "Serial port (CD)\n"); - break; - case RIG_DCD_NONE: - fprintf(fout, "None\n"); - break; - default: - fprintf(fout, "Unknown\n"); - backend_warnings++; - } + case RIG_TYPE_HANDHELD: + fprintf(fout, "Handheld\n"); + break; - fprintf(fout, "Port type:\t"); - switch (caps->port_type) { - case RIG_PORT_SERIAL: - fprintf(fout, "RS-232\n"); - fprintf(fout, "Serial speed: %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++; - } + case RIG_TYPE_MOBILE: + fprintf(fout, "Mobile\n"); + break; - fprintf(fout, "Write delay: %dms, timeout %dms, %d retry\n", - caps->write_delay, caps->timeout, caps->retry); - fprintf(fout, "Post Write delay: %dms\n", - caps->post_write_delay); + case RIG_TYPE_RECEIVER: + fprintf(fout, "Receiver\n"); + break; - fprintf(fout, "Has targetable VFO: %s\n", - caps->targetable_vfo ? "Y" : "N"); + case RIG_TYPE_PCRECEIVER: + fprintf(fout, "PC Receiver\n"); + break; - fprintf(fout, "Has transceive: %s\n", - caps->transceive ? "Y" : "N"); + case RIG_TYPE_SCANNER: + fprintf(fout, "Scanner\n"); + break; - fprintf(fout, "Announce: 0x%x\n", caps->announces); - fprintf(fout, "Max RIT: -%ld.%ldkHz/+%ld.%ldkHz\n", - caps->max_rit / 1000, caps->max_rit % 1000, - caps->max_rit / 1000, caps->max_rit % 1000); + case RIG_TYPE_TRUNKSCANNER: + fprintf(fout, "Trunking scanner\n"); + break; - fprintf(fout, "Max XIT: -%ld.%ldkHz/+%ld.%ldkHz\n", - caps->max_xit / 1000, caps->max_xit % 1000, - caps->max_xit / 1000, caps->max_xit % 1000); + case RIG_TYPE_COMPUTER: + fprintf(fout, "Computer\n"); + break; - fprintf(fout, "Max IF-SHIFT: -%ld.%ldkHz/+%ld.%ldkHz\n", - caps->max_ifshift / 1000, caps->max_ifshift % 1000, - caps->max_ifshift / 1000, caps->max_ifshift % 1000); + case RIG_TYPE_TUNER: + fprintf(fout, "Tuner\n"); + break; - fprintf(fout, "Preamp:"); - for(i = 0; i < MAXDBLSTSIZ && caps->preamp[i] != 0; i++) - fprintf(fout, " %ddB", caps->preamp[i]); - if (i == 0) - fprintf(fout, " None"); - fprintf(fout, "\n"); - fprintf(fout, "Attenuator:"); - for(i = 0; i < MAXDBLSTSIZ && caps->attenuator[i] != 0; i++) - fprintf(fout, " %ddB",caps->attenuator[i]); - if (i == 0) - fprintf(fout, " None"); - fprintf(fout, "\n"); + case RIG_TYPE_OTHER: + fprintf(fout, "Other\n"); + break; - fprintf(fout, "CTCSS:"); - for(i = 0; caps->ctcss_list && i < 60 && caps->ctcss_list[i] != 0; i++) { - fprintf(fout, " %d.%1d", caps->ctcss_list[i] / 10, caps->ctcss_list[i] % 10); - } - if (i == 0) - fprintf(fout, " None"); - else - fprintf(fout, " Hz, %d tones", i); - fprintf(fout, "\n"); - - fprintf(fout, "DCS:"); - for(i = 0; caps->dcs_list && i < 128 && caps->dcs_list[i] != 0; i++) { - fprintf(fout, " %d", caps->dcs_list[i]); - } - if (i == 0) - fprintf(fout, " None"); - else - fprintf(fout, ", %d codes", i); - fprintf(fout, "\n"); - - sprintf_func(prntbuf, caps->has_get_func); - fprintf(fout, "Get functions: %s\n", prntbuf); - - sprintf_func(prntbuf, caps->has_set_func); - fprintf(fout, "Set functions: %s\n", prntbuf); - - sprintf_level_gran(prntbuf, caps->has_get_level, caps->level_gran); - fprintf(fout, "Get level: %s\n", prntbuf); - - if ((caps->has_get_level & RIG_LEVEL_SQLSTAT)) { - fprintf(fout, "Warning--backend uses deprecated SQLSTAT level!\n"); - backend_warnings++; - } - - if ((caps->has_get_level & RIG_LEVEL_RAWSTR) && - caps->str_cal.size == 0 && - !(caps->has_get_level & RIG_LEVEL_STRENGTH)) { - fprintf(fout, "Warning--backend has get RAWSTR, but not calibration data\n"); - backend_warnings++; - } - - sprintf_level_gran(prntbuf, caps->has_set_level, caps->level_gran); - fprintf(fout, "Set level: %s\n", prntbuf); - - if (caps->has_set_level & RIG_LEVEL_READONLY_LIST) { - fprintf(fout, "Warning--backend can set readonly levels!\n"); - backend_warnings++; - } - - fprintf(fout, "Extra levels:"); - rig_ext_level_foreach(rig, print_ext, fout); - fprintf(fout, "\n"); - - sprintf_parm_gran(prntbuf, caps->has_get_parm, caps->parm_gran); - fprintf(fout, "Get parameters: %s\n", prntbuf); - - sprintf_parm_gran(prntbuf, caps->has_set_parm, caps->parm_gran); - fprintf(fout, "Set parameters: %s\n", prntbuf); - if (caps->has_set_parm & RIG_PARM_READONLY_LIST) { - fprintf(fout, "Warning--backend can set readonly parms!\n"); - backend_warnings++; - } - fprintf(fout, "Extra parameters:"); - rig_ext_parm_foreach(rig, print_ext, fout); - fprintf(fout, "\n"); - - - if (rig->state.mode_list != 0) - sprintf_mode(prntbuf, rig->state.mode_list); - else { - strcpy(prntbuf,"None. This backend might be bogus!\n"); + default: + fprintf(fout, "Unknown\n"); backend_warnings++; } - fprintf(fout, "Mode list: %s\n", prntbuf); - if (rig->state.vfo_list != 0) - sprintf_vfo(prntbuf, rig->state.vfo_list); - else { - strcpy(prntbuf,"None. This backend might be bogus!\n"); + fprintf(fout, "PTT type:\t"); + + switch (caps->ptt_type) { + case RIG_PTT_RIG: + fprintf(fout, "Rig capable\n"); + break; + + case RIG_PTT_RIG_MICDATA: + fprintf(fout, "Rig capable (Mic/Data)\n"); + break; + + case RIG_PTT_PARALLEL: + fprintf(fout, "Parallel port (DATA0)\n"); + break; + + case RIG_PTT_SERIAL_RTS: + fprintf(fout, "Serial port (CTS/RTS)\n"); + break; + + case RIG_PTT_SERIAL_DTR: + fprintf(fout, "Serial port (DTR/DSR)\n"); + break; + + case RIG_PTT_NONE: + fprintf(fout, "None\n"); + break; + + default: + fprintf(fout, "Unknown\n"); backend_warnings++; } - fprintf(fout, "VFO list: %s\n", prntbuf); - sprintf_vfop(prntbuf, caps->vfo_ops); - fprintf(fout, "VFO Ops: %s\n", prntbuf); + fprintf(fout, "DCD type:\t"); - sprintf_scan(prntbuf, caps->scan_ops); - fprintf(fout, "Scan Ops: %s\n", prntbuf); + switch (caps->dcd_type) { + case RIG_DCD_RIG: + fprintf(fout, "Rig capable\n"); + break; - fprintf(fout, "Number of banks:\t%d\n", caps->bank_qty); - fprintf(fout, "Memory name desc size:\t%d\n", caps->chan_desc_sz); + case RIG_DCD_PARALLEL: + fprintf(fout, "Parallel port (/STROBE)\n"); + break; - fprintf(fout, "Memories:"); - for (i = 0; i < CHANLSTSIZ && caps->chan_list[i].type; i++) { - fprintf(fout, "\n\t%d..%d: \t%s", caps->chan_list[i].start, - caps->chan_list[i].end, - rig_strmtype(caps->chan_list[i].type)); - fprintf(fout, "\n\t Mem caps: "); - dump_chan_caps(&caps->chan_list[i].mem_caps, fout); - } - if (i == 0) - fprintf(fout, " None"); - fprintf(fout, "\n"); + case RIG_DCD_SERIAL_CTS: + fprintf(fout, "Serial port (CTS/RTS)\n"); + break; -/* TODO: print rx/tx ranges here */ - status = range_sanity_check(caps->tx_range_list1, 0); - fprintf(fout, "TX ranges status, region 1:\t%s (%d)\n", status ? "Bad" : "OK", status); - if (status) backend_warnings++; - status = range_sanity_check(caps->rx_range_list1, 1); - fprintf(fout, "RX ranges status, region 1:\t%s (%d)\n", status ? "Bad" : "OK", status); - if (status) backend_warnings++; + case RIG_DCD_SERIAL_DSR: + fprintf(fout, "Serial port (DTR/DSR)\n"); + break; - status = range_sanity_check(caps->tx_range_list2, 0); - fprintf(fout, "TX ranges status, region 2:\t%s (%d)\n", status ? "Bad" : "OK", status); - if (status) backend_warnings++; - status = range_sanity_check(caps->rx_range_list2, 1); - fprintf(fout, "RX ranges status, region 2:\t%s (%d)\n", status ? "Bad" : "OK", status); - if (status) backend_warnings++; + case RIG_DCD_SERIAL_CAR: + fprintf(fout, "Serial port (CD)\n"); + break; - fprintf(fout, "Tuning steps:"); - for (i = 0; i < TSLSTSIZ && !RIG_IS_TS_END(caps->tuning_steps[i]); i++) { - if (caps->tuning_steps[i].ts == RIG_TS_ANY) - strcpy(freqbuf, "ANY"); /* strcpy! Looks safe for now */ - else - sprintf_freq(freqbuf, caps->tuning_steps[i].ts); + case RIG_DCD_NONE: + fprintf(fout, "None\n"); + break; - sprintf_mode(prntbuf, caps->tuning_steps[i].modes); - fprintf(fout, "\n\t%s: \t%s", freqbuf, prntbuf); - } - if (i == 0) { + default: + fprintf(fout, "Unknown\n"); + backend_warnings++; + } + + fprintf(fout, "Port type:\t"); + + switch (caps->port_type) { + case RIG_PORT_SERIAL: + fprintf(fout, "RS-232\n"); + fprintf(fout, + "Serial speed: %d..%d bauds, %d%c%d %s\n", + caps->serial_rate_min, + caps->serial_rate_max, + caps->serial_data_bits, + caps->serial_parity == RIG_PARITY_NONE ? 'N' : + caps->serial_parity == RIG_PARITY_ODD ? 'O' : + caps->serial_parity == RIG_PARITY_EVEN ? 'E' : + caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S', + caps->serial_stop_bits, + caps->serial_handshake == RIG_HANDSHAKE_NONE ? "" : + (caps->serial_handshake == RIG_HANDSHAKE_XONXOFF ? "XONXOFF" : "CTS/RTS") + ); + break; + + case RIG_PORT_PARALLEL: + fprintf(fout, "Parallel\n"); + break; + + case RIG_PORT_DEVICE: + fprintf(fout, "Device driver\n"); + break; + + case RIG_PORT_USB: + fprintf(fout, "USB\n"); + break; + + case RIG_PORT_NETWORK: + fprintf(fout, "Network link\n"); + break; + + case RIG_PORT_UDP_NETWORK: + fprintf(fout, "UDP Network link\n"); + break; + + case RIG_PORT_NONE: + fprintf(fout, "None\n"); + break; + + default: + fprintf(fout, "Unknown\n"); + backend_warnings++; + } + + fprintf(fout, + "Write delay: %dmS, timeout %dmS, %d retry\n", + caps->write_delay, caps->timeout, caps->retry); + fprintf(fout, + "Post Write delay: %dmS\n", + caps->post_write_delay); + + fprintf(fout, + "Has targetable VFO: %s\n", + caps->targetable_vfo ? "Y" : "N"); + + fprintf(fout, + "Has transceive: %s\n", + caps->transceive ? "Y" : "N"); + + fprintf(fout, "Announce: 0x%x\n", caps->announces); + fprintf(fout, + "Max RIT: -%ld.%ldkHz/+%ld.%ldkHz\n", + caps->max_rit / 1000, caps->max_rit % 1000, + caps->max_rit / 1000, caps->max_rit % 1000); + + fprintf(fout, + "Max XIT: -%ld.%ldkHz/+%ld.%ldkHz\n", + caps->max_xit / 1000, caps->max_xit % 1000, + caps->max_xit / 1000, caps->max_xit % 1000); + + fprintf(fout, + "Max IF-SHIFT: -%ld.%ldkHz/+%ld.%ldkHz\n", + caps->max_ifshift / 1000, caps->max_ifshift % 1000, + caps->max_ifshift / 1000, caps->max_ifshift % 1000); + + fprintf(fout, "Preamp:"); + + for (i = 0; i < MAXDBLSTSIZ && caps->preamp[i] != 0; i++) { + fprintf(fout, " %ddB", caps->preamp[i]); + } + + if (i == 0) { + fprintf(fout, " None"); + } + + fprintf(fout, "\n"); + fprintf(fout, "Attenuator:"); + + for (i = 0; i < MAXDBLSTSIZ && caps->attenuator[i] != 0; i++) { + fprintf(fout, " %ddB", caps->attenuator[i]); + } + + if (i == 0) { + fprintf(fout, " None"); + } + + fprintf(fout, "\n"); + + fprintf(fout, "CTCSS:"); + + for (i = 0; caps->ctcss_list && i < 60 && caps->ctcss_list[i] != 0; i++) { + fprintf(fout, + " %d.%1d", + caps->ctcss_list[i] / 10, caps->ctcss_list[i] % 10); + } + + if (i == 0) { + fprintf(fout, " None"); + } else { + fprintf(fout, " Hz, %d tones", i); + } + + fprintf(fout, "\n"); + + fprintf(fout, "DCS:"); + + for (i = 0; caps->dcs_list && i < 128 && caps->dcs_list[i] != 0; i++) { + fprintf(fout, " %d", caps->dcs_list[i]); + } + + if (i == 0) { + fprintf(fout, " None"); + } else { + fprintf(fout, ", %d codes", i); + } + + fprintf(fout, "\n"); + + sprintf_func(prntbuf, caps->has_get_func); + fprintf(fout, "Get functions: %s\n", prntbuf); + + sprintf_func(prntbuf, caps->has_set_func); + fprintf(fout, "Set functions: %s\n", prntbuf); + + sprintf_level_gran(prntbuf, caps->has_get_level, caps->level_gran); + fprintf(fout, "Get level: %s\n", prntbuf); + + if ((caps->has_get_level & RIG_LEVEL_SQLSTAT)) { + fprintf(fout, "Warning--backend uses deprecated SQLSTAT level!\n"); + backend_warnings++; + } + + if ((caps->has_get_level & RIG_LEVEL_RAWSTR) + && caps->str_cal.size == 0 + && !(caps->has_get_level & RIG_LEVEL_STRENGTH)) { + + fprintf(fout, + "Warning--backend has get RAWSTR, but not calibration data\n"); + backend_warnings++; + } + + sprintf_level_gran(prntbuf, caps->has_set_level, caps->level_gran); + fprintf(fout, "Set level: %s\n", prntbuf); + + if (caps->has_set_level & RIG_LEVEL_READONLY_LIST) { + fprintf(fout, "Warning--backend can set readonly levels!\n"); + backend_warnings++; + } + + fprintf(fout, "Extra levels:"); + rig_ext_level_foreach(rig, print_ext, fout); + fprintf(fout, "\n"); + + sprintf_parm_gran(prntbuf, caps->has_get_parm, caps->parm_gran); + fprintf(fout, "Get parameters: %s\n", prntbuf); + + sprintf_parm_gran(prntbuf, caps->has_set_parm, caps->parm_gran); + fprintf(fout, "Set parameters: %s\n", prntbuf); + + if (caps->has_set_parm & RIG_PARM_READONLY_LIST) { + fprintf(fout, "Warning--backend can set readonly parms!\n"); + backend_warnings++; + } + + fprintf(fout, "Extra parameters:"); + rig_ext_parm_foreach(rig, print_ext, fout); + fprintf(fout, "\n"); + + + if (rig->state.mode_list != 0) { + sprintf_mode(prntbuf, rig->state.mode_list); + } else { + strcpy(prntbuf, "None. This backend might be bogus!\n"); + backend_warnings++; + } + + fprintf(fout, "Mode list: %s\n", prntbuf); + + if (rig->state.vfo_list != 0) { + sprintf_vfo(prntbuf, rig->state.vfo_list); + } else { + strcpy(prntbuf, "None. This backend might be bogus!\n"); + backend_warnings++; + } + + fprintf(fout, "VFO list: %s\n", prntbuf); + + sprintf_vfop(prntbuf, caps->vfo_ops); + fprintf(fout, "VFO Ops: %s\n", prntbuf); + + sprintf_scan(prntbuf, caps->scan_ops); + fprintf(fout, "Scan Ops: %s\n", prntbuf); + + fprintf(fout, "Number of banks:\t%d\n", caps->bank_qty); + fprintf(fout, "Memory name desc size:\t%d\n", caps->chan_desc_sz); + + fprintf(fout, "Memories:"); + + for (i = 0; i < CHANLSTSIZ && caps->chan_list[i].type; i++) { + fprintf(fout, + "\n\t%d..%d: \t%s", + caps->chan_list[i].start, + caps->chan_list[i].end, + rig_strmtype(caps->chan_list[i].type)); + fprintf(fout, "\n\t Mem caps: "); + dump_chan_caps(&caps->chan_list[i].mem_caps, fout); + } + + if (i == 0) { + fprintf(fout, " None"); + } + + fprintf(fout, "\n"); + + /* TODO: print rx/tx ranges here */ + status = range_sanity_check(caps->tx_range_list1, 0); + fprintf(fout, + "TX ranges status, region 1:\t%s (%d)\n", + status ? "Bad" : "OK", + status); + + if (status) { + backend_warnings++; + } + + status = range_sanity_check(caps->rx_range_list1, 1); + fprintf(fout, + "RX ranges status, region 1:\t%s (%d)\n", + status ? "Bad" : "OK", + status); + + if (status) { + backend_warnings++; + } + + status = range_sanity_check(caps->tx_range_list2, 0); + fprintf(fout, + "TX ranges status, region 2:\t%s (%d)\n", + status ? "Bad" : "OK", + status); + + if (status) { + backend_warnings++; + } + + status = range_sanity_check(caps->rx_range_list2, 1); + fprintf(fout, + "RX ranges status, region 2:\t%s (%d)\n", + status ? "Bad" : "OK", + status); + + if (status) { + backend_warnings++; + } + + fprintf(fout, "Tuning steps:"); + + for (i = 0; i < TSLSTSIZ && !RIG_IS_TS_END(caps->tuning_steps[i]); i++) { + if (caps->tuning_steps[i].ts == RIG_TS_ANY) { + strcpy(freqbuf, "ANY"); /* strcpy! Looks safe for now */ + } else { + sprintf_freq(freqbuf, caps->tuning_steps[i].ts); + } + + sprintf_mode(prntbuf, caps->tuning_steps[i].modes); + fprintf(fout, "\n\t%s: \t%s", freqbuf, prntbuf); + } + + if (i == 0) { fprintf(fout, " None! This backend might be bogus!"); - backend_warnings++; - } - fprintf(fout, "\n"); - status = ts_sanity_check(caps->tuning_steps); - fprintf(fout, "Tuning steps status:\t%s (%d)\n",status?"Bad":"OK",status); - if (status) backend_warnings++; + backend_warnings++; + } - fprintf(fout, "Filters:"); - for (i=0; ifilters[i]); i++) { - if (caps->filters[i].width == RIG_FLT_ANY) - strcpy(freqbuf, "ANY"); - else - sprintf_freq(freqbuf,caps->filters[i].width); - sprintf_mode(prntbuf,caps->filters[i].modes); - fprintf(fout, "\n\t%s: \t%s", freqbuf, prntbuf); - } - if (i == 0) { - fprintf(fout, " None. This backend might be bogus!"); - backend_warnings++; - } - fprintf(fout, "\n"); + fprintf(fout, "\n"); + status = ts_sanity_check(caps->tuning_steps); + fprintf(fout, "Tuning steps status:\t%s (%d)\n", status ? "Bad" : "OK", status); - fprintf(fout, "Bandwidths:"); - for (i = 1; i < RIG_MODE_TESTS_MAX; i <<= 1) { - pbwidth_t pbnorm = rig_passband_normal(rig, i); + if (status) { + backend_warnings++; + } - if (pbnorm == 0) - continue; + fprintf(fout, "Filters:"); - sprintf_freq(freqbuf, pbnorm); - fprintf(fout, "\n\t%s\tNormal: %s,\t", rig_strrmode(i), freqbuf); + for (i = 0; i < FLTLSTSIZ && !RIG_IS_FLT_END(caps->filters[i]); i++) { + if (caps->filters[i].width == RIG_FLT_ANY) { + strcpy(freqbuf, "ANY"); + } else { + sprintf_freq(freqbuf, caps->filters[i].width); + } - sprintf_freq(freqbuf, rig_passband_narrow(rig, i)); - fprintf(fout, "Narrow: %s,\t", freqbuf); + sprintf_mode(prntbuf, caps->filters[i].modes); + fprintf(fout, "\n\t%s: \t%s", freqbuf, prntbuf); + } - sprintf_freq(freqbuf, rig_passband_wide(rig, i)); - fprintf(fout, "Wide: %s", freqbuf); - } - fprintf(fout, "\n"); + if (i == 0) { + fprintf(fout, " None. This backend might be bogus!"); + backend_warnings++; + } - fprintf(fout, "Has priv data:\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%c\n", caps->rig_init != NULL ? 'Y' : 'N'); - fprintf(fout, "Has Cleanup:\t%c\n", caps->rig_cleanup != NULL ? 'Y' : 'N'); - fprintf(fout, "Has Open:\t%c\n", caps->rig_open != NULL ? 'Y' : 'N'); - fprintf(fout, "Has Close:\t%c\n", caps->rig_close != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Conf:\t%c\n", caps->set_conf != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Conf:\t%c\n", caps->get_conf != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Frequency:\t%c\n", caps->set_freq != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Frequency:\t%c\n", caps->get_freq != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Mode:\t%c\n", caps->set_mode != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Mode:\t%c\n", caps->get_mode != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set VFO:\t%c\n", caps->set_vfo != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get VFO:\t%c\n", caps->get_vfo != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set PTT:\t%c\n", caps->set_ptt != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get PTT:\t%c\n", caps->get_ptt != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get DCD:\t%c\n", caps->get_dcd != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Repeater Duplex:\t%c\n", caps->set_rptr_shift != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Repeater Duplex:\t%c\n", caps->get_rptr_shift != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Repeater Offset:\t%c\n", caps->set_rptr_offs != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Repeater Offset:\t%c\n", caps->get_rptr_offs != NULL ? 'Y' : 'N'); + fprintf(fout, "\n"); - can_esplit = caps->set_split_vfo && (caps->set_vfo || - (rig_has_vfo_op(rig, RIG_OP_TOGGLE) && caps->vfo_op)); - fprintf(fout, "Can set Split Freq:\t%c\n", caps->set_split_freq != NULL ? 'Y' : - (can_esplit && caps->set_freq ? 'E' : 'N')); - fprintf(fout, "Can get Split Freq:\t%c\n", caps->get_split_freq != NULL ? 'Y' : - (can_esplit && caps->get_freq ? 'E' : 'N')); - fprintf(fout, "Can set Split Mode:\t%c\n", caps->set_split_mode != NULL ? 'Y' : - (can_esplit && caps->set_mode ? 'E' : 'N')); - fprintf(fout, "Can get Split Mode:\t%c\n", caps->get_split_mode != NULL ? 'Y' : - (can_esplit && caps->get_mode ? 'E' : 'N')); + fprintf(fout, "Bandwidths:"); - fprintf(fout, "Can set Split VFO:\t%c\n", caps->set_split_vfo != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Split VFO:\t%c\n", caps->get_split_vfo != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Tuning Step:\t%c\n", caps->set_ts != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Tuning Step:\t%c\n", caps->get_ts != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set RIT:\t%c\n", caps->set_rit != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get RIT:\t%c\n", caps->get_rit != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set XIT:\t%c\n", caps->set_xit != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get XIT:\t%c\n", caps->get_xit != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set CTCSS:\t%c\n", caps->set_ctcss_tone != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get CTCSS:\t%c\n", caps->get_ctcss_tone != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set DCS:\t%c\n", caps->set_dcs_code != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get DCS:\t%c\n", caps->get_dcs_code != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set CTCSS Squelch:\t%c\n", caps->set_ctcss_sql != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get CTCSS Squelch:\t%c\n", caps->get_ctcss_sql != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set DCS Squelch:\t%c\n", caps->set_dcs_sql != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get DCS Squelch:\t%c\n", caps->get_dcs_sql != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Power Stat:\t%c\n", caps->set_powerstat != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Power Stat:\t%c\n", caps->get_powerstat != NULL ? 'Y' : 'N'); - fprintf(fout, "Can Reset:\t%c\n", caps->reset != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Ant:\t%c\n", caps->get_ant != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Ant:\t%c\n", caps->set_ant != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Transceive:\t%c\n", caps->set_trn != NULL ? 'Y' : - caps->transceive == RIG_TRN_RIG ? 'E' : 'N'); - fprintf(fout, "Can get Transceive:\t%c\n", caps->get_trn != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Func:\t%c\n", caps->set_func != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Func:\t%c\n", caps->get_func != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Level:\t%c\n", caps->set_level != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Level:\t%c\n", caps->get_level != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Param:\t%c\n", caps->set_parm != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Param:\t%c\n", caps->get_parm != NULL ? 'Y' : 'N'); - fprintf(fout, "Can send DTMF:\t%c\n", caps->send_dtmf != NULL ? 'Y': 'N'); - fprintf(fout, "Can recv DTMF:\t%c\n", caps->recv_dtmf != NULL ? 'Y' : 'N'); - fprintf(fout, "Can send Morse:\t%c\n", caps->send_morse != NULL ? 'Y' : 'N'); - fprintf(fout, "Can decode Events:\t%c\n", caps->decode_event != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Bank:\t%c\n", caps->set_bank != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Mem:\t%c\n", caps->set_mem != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Mem:\t%c\n", caps->get_mem != NULL ? 'Y' : 'N'); + for (i = 1; i < RIG_MODE_TESTS_MAX; i <<= 1) { + pbwidth_t pbnorm = rig_passband_normal(rig, i); - can_echannel = caps->set_mem && ( - (caps->set_vfo && ((rig->state.vfo_list & RIG_VFO_MEM) == RIG_VFO_MEM)) || - (caps->vfo_op && rig_has_vfo_op(rig, RIG_OP_TO_VFO|RIG_OP_FROM_VFO))); + if (pbnorm == 0) { + continue; + } - fprintf(fout, "Can set Channel:\t%c\n", caps->set_channel != NULL ? 'Y' : - (can_echannel ? 'E' : 'N')); - fprintf(fout, "Can get Channel:\t%c\n", caps->get_channel != NULL ? 'Y' : - (can_echannel ? 'E' : 'N')); + sprintf_freq(freqbuf, pbnorm); + fprintf(fout, "\n\t%s\tNormal: %s,\t", rig_strrmode(i), freqbuf); - fprintf(fout, "Can ctl Mem/VFO:\t%c\n", caps->vfo_op != NULL ? 'Y' : 'N'); - fprintf(fout, "Can Scan:\t%c\n", caps->scan != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Info:\t%c\n", caps->get_info != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get power2mW:\t%c\n", caps->power2mW != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get mW2power:\t%c\n", caps->mW2power != NULL ? 'Y' : 'N'); + sprintf_freq(freqbuf, rig_passband_narrow(rig, i)); + fprintf(fout, "Narrow: %s,\t", freqbuf); + sprintf_freq(freqbuf, rig_passband_wide(rig, i)); + fprintf(fout, "Wide: %s", freqbuf); + } - fprintf(fout, "\nOverall backend warnings: %d\n", backend_warnings); + fprintf(fout, "\n"); - return backend_warnings; + fprintf(fout, "Has priv data:\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%c\n", caps->rig_init != NULL ? 'Y' : 'N'); + fprintf(fout, "Has Cleanup:\t%c\n", caps->rig_cleanup != NULL ? 'Y' : 'N'); + fprintf(fout, "Has Open:\t%c\n", caps->rig_open != NULL ? 'Y' : 'N'); + fprintf(fout, "Has Close:\t%c\n", caps->rig_close != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set Conf:\t%c\n", caps->set_conf != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Conf:\t%c\n", caps->get_conf != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set Frequency:\t%c\n", caps->set_freq != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Frequency:\t%c\n", caps->get_freq != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set Mode:\t%c\n", caps->set_mode != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Mode:\t%c\n", caps->get_mode != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set VFO:\t%c\n", caps->set_vfo != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get VFO:\t%c\n", caps->get_vfo != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set PTT:\t%c\n", caps->set_ptt != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get PTT:\t%c\n", caps->get_ptt != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get DCD:\t%c\n", caps->get_dcd != NULL ? 'Y' : 'N'); + fprintf(fout, + "Can set Repeater Duplex:\t%c\n", + caps->set_rptr_shift != NULL ? 'Y' : 'N'); + fprintf(fout, + "Can get Repeater Duplex:\t%c\n", + caps->get_rptr_shift != NULL ? 'Y' : 'N'); + fprintf(fout, + "Can set Repeater Offset:\t%c\n", + caps->set_rptr_offs != NULL ? 'Y' : 'N'); + fprintf(fout, + "Can get Repeater Offset:\t%c\n", + caps->get_rptr_offs != NULL ? 'Y' : 'N'); + + can_esplit = caps->set_split_vfo + && (caps->set_vfo + || (rig_has_vfo_op(rig, RIG_OP_TOGGLE) && caps->vfo_op)); + + fprintf(fout, + "Can set Split Freq:\t%c\n", + caps->set_split_freq != NULL ? 'Y' : (can_esplit + && caps->set_freq ? 'E' : 'N')); + + fprintf(fout, + "Can get Split Freq:\t%c\n", + caps->get_split_freq != NULL ? 'Y' : (can_esplit + && caps->get_freq ? 'E' : 'N')); + + fprintf(fout, + "Can set Split Mode:\t%c\n", + caps->set_split_mode != NULL ? 'Y' : (can_esplit + && caps->set_mode ? 'E' : 'N')); + + fprintf(fout, + "Can get Split Mode:\t%c\n", + caps->get_split_mode != NULL ? 'Y' : (can_esplit + && caps->get_mode ? 'E' : 'N')); + + fprintf(fout, + "Can set Split VFO:\t%c\n", + caps->set_split_vfo != NULL ? 'Y' : 'N'); + + fprintf(fout, + "Can get Split VFO:\t%c\n", + caps->get_split_vfo != NULL ? 'Y' : 'N'); + + fprintf(fout, "Can set Tuning Step:\t%c\n", caps->set_ts != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Tuning Step:\t%c\n", caps->get_ts != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set RIT:\t%c\n", caps->set_rit != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get RIT:\t%c\n", caps->get_rit != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set XIT:\t%c\n", caps->set_xit != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get XIT:\t%c\n", caps->get_xit != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set CTCSS:\t%c\n", caps->set_ctcss_tone != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get CTCSS:\t%c\n", caps->get_ctcss_tone != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set DCS:\t%c\n", caps->set_dcs_code != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get DCS:\t%c\n", caps->get_dcs_code != NULL ? 'Y' : 'N'); + + fprintf(fout, + "Can set CTCSS Squelch:\t%c\n", + caps->set_ctcss_sql != NULL ? 'Y' : 'N'); + + fprintf(fout, + "Can get CTCSS Squelch:\t%c\n", + caps->get_ctcss_sql != NULL ? 'Y' : 'N'); + + fprintf(fout, + "Can set DCS Squelch:\t%c\n", + caps->set_dcs_sql != NULL ? 'Y' : 'N'); + + fprintf(fout, + "Can get DCS Squelch:\t%c\n", + caps->get_dcs_sql != NULL ? 'Y' : 'N'); + + fprintf(fout, + "Can set Power Stat:\t%c\n", + caps->set_powerstat != NULL ? 'Y' : 'N'); + + fprintf(fout, + "Can get Power Stat:\t%c\n", + caps->get_powerstat != NULL ? 'Y' : 'N'); + + fprintf(fout, "Can Reset:\t%c\n", caps->reset != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Ant:\t%c\n", caps->get_ant != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set Ant:\t%c\n", caps->set_ant != NULL ? 'Y' : 'N'); + + fprintf(fout, + "Can set Transceive:\t%c\n", + caps->set_trn != NULL ? 'Y' : caps->transceive == RIG_TRN_RIG ? 'E' : 'N'); + + fprintf(fout, "Can get Transceive:\t%c\n", caps->get_trn != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set Func:\t%c\n", caps->set_func != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Func:\t%c\n", caps->get_func != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set Level:\t%c\n", caps->set_level != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Level:\t%c\n", caps->get_level != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set Param:\t%c\n", caps->set_parm != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Param:\t%c\n", caps->get_parm != NULL ? 'Y' : 'N'); + fprintf(fout, "Can send DTMF:\t%c\n", caps->send_dtmf != NULL ? 'Y' : 'N'); + fprintf(fout, "Can recv DTMF:\t%c\n", caps->recv_dtmf != NULL ? 'Y' : 'N'); + fprintf(fout, "Can send Morse:\t%c\n", caps->send_morse != NULL ? 'Y' : 'N'); + + fprintf(fout, + "Can decode Events:\t%c\n", + caps->decode_event != NULL ? 'Y' : 'N'); + + fprintf(fout, "Can set Bank:\t%c\n", caps->set_bank != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set Mem:\t%c\n", caps->set_mem != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Mem:\t%c\n", caps->get_mem != NULL ? 'Y' : 'N'); + + can_echannel = caps->set_mem + && ((caps->set_vfo + && ((rig->state.vfo_list & RIG_VFO_MEM) == RIG_VFO_MEM)) + || (caps->vfo_op + && rig_has_vfo_op(rig, RIG_OP_TO_VFO | RIG_OP_FROM_VFO))); + + fprintf(fout, + "Can set Channel:\t%c\n", + caps->set_channel != NULL ? 'Y' : (can_echannel ? 'E' : 'N')); + + fprintf(fout, + "Can get Channel:\t%c\n", + caps->get_channel != NULL ? 'Y' : (can_echannel ? 'E' : 'N')); + + fprintf(fout, "Can ctl Mem/VFO:\t%c\n", caps->vfo_op != NULL ? 'Y' : 'N'); + fprintf(fout, "Can Scan:\t%c\n", caps->scan != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Info:\t%c\n", caps->get_info != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get power2mW:\t%c\n", caps->power2mW != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get mW2power:\t%c\n", caps->mW2power != NULL ? 'Y' : 'N'); + + fprintf(fout, "\nOverall backend warnings: %d\n", backend_warnings); + + return backend_warnings; } static int print_ext(RIG *rig, const struct confparams *cfp, rig_ptr_t ptr) { - fprintf((FILE *)ptr, " %s", cfp->name); + fprintf((FILE *)ptr, " %s", cfp->name); - return 1; /* process them all */ + return 1; /* process them all */ } /* * check for: - * - start_freq < end_freq return_code = -1 - * - modes are not 0 return_code = -2 - * - if(rx), low_power, high_power set to -1 return_code = -3 + * - start_freq < end_freq return_code = -1 + * - modes are not 0 return_code = -2 + * - if(rx), low_power, high_power set to -1 return_code = -3 * else, power is > 0 * - array is ended by a {0,0,0,0,0} element (before boundary) rc = -4 - * - ranges with same modes do not overlap rc = -5 + * - ranges with same modes do not overlap rc = -5 * ->fprintf(stderr,)! * * TODO: array is sorted in ascending freq order */ int range_sanity_check(const struct freq_range_list range_list[], int rx) { - int i; + int i; - for (i = 0; i < FRQRANGESIZ; i++) { - if (range_list[i].start == 0 && range_list[i].end == 0) - break; - if (range_list[i].start > range_list[i].end) - return -1; - if (range_list[i].modes == 0) - return -2; - if (rx) { - if (range_list[i].low_power > 0 && range_list[i].high_power > 0) - return -3; - } else { - if (!(range_list[i].low_power > 0 && range_list[i].high_power > 0)) - return -3; - if (range_list[i].low_power > range_list[i].high_power) - return -3; - } - } - if (i == FRQRANGESIZ) - return -4; + for (i = 0; i < FRQRANGESIZ; i++) { + if (range_list[i].start == 0 && range_list[i].end == 0) { + break; + } - return 0; + if (range_list[i].start > range_list[i].end) { + return -1; + } + + if (range_list[i].modes == 0) { + return -2; + } + + if (rx) { + if (range_list[i].low_power > 0 && range_list[i].high_power > 0) { + return -3; + } + } else { + if (!(range_list[i].low_power > 0 && range_list[i].high_power > 0)) { + return -3; + } + + if (range_list[i].low_power > range_list[i].high_power) { + return -3; + } + } + } + + if (i == FRQRANGESIZ) { + return -4; + } + + return 0; } /* * check for: * - steps sorted in ascending order return_code=-1 - * - modes are not 0 return_code=-2 + * - modes are not 0 return_code=-2 * - array is ended by a {0,0,0,0,0} element (before boundary) rc=-4 * * TODO: array is sorted in ascending freq order */ int ts_sanity_check(const struct tuning_step_list tuning_step[]) { - int i; - shortfreq_t last_ts; - rmode_t last_modes; + int i; + shortfreq_t last_ts; + rmode_t last_modes; - last_ts = 0; - last_modes = RIG_MODE_NONE; - for (i=0; ibank_num) fprintf(fout, "BANK "); - if (chan->ant) fprintf(fout, "ANT "); - if (chan->freq) fprintf(fout, "FREQ "); - if (chan->mode) fprintf(fout, "MODE "); - if (chan->width) fprintf(fout, "WIDTH "); - if (chan->tx_freq) fprintf(fout, "TXFREQ "); - if (chan->tx_mode) fprintf(fout, "TXMODE "); - if (chan->tx_width) fprintf(fout, "TXWIDTH "); - if (chan->split) fprintf(fout, "SPLIT "); - if (chan->rptr_shift) fprintf(fout, "RPTRSHIFT "); - if (chan->rptr_offs) fprintf(fout, "RPTROFS "); - if (chan->tuning_step) fprintf(fout, "TS "); - if (chan->rit) fprintf(fout, "RIT "); - if (chan->xit) fprintf(fout, "XIT "); - if (chan->funcs) fprintf(fout, "FUNC "); /* TODO: iterate over the list */ - if (chan->levels) fprintf(fout, "LEVEL "); /* TODO: iterate over the list */ - if (chan->ctcss_tone) fprintf(fout, "TONE "); - if (chan->ctcss_sql) fprintf(fout, "CTCSS "); - if (chan->dcs_code) fprintf(fout, "DCSCODE "); - if (chan->dcs_sql) fprintf(fout, "DCSSQL "); - if (chan->scan_group) fprintf(fout, "SCANGRP "); - if (chan->flags) fprintf(fout, "FLAG "); /* TODO: iterate over the RIG_CHFLAG's */ - if (chan->channel_desc) fprintf(fout, "NAME "); - if (chan->ext_levels) fprintf(fout, "EXTLVL "); + if (chan->bank_num) { + fprintf(fout, "BANK "); + } + + if (chan->ant) { + fprintf(fout, "ANT "); + } + + if (chan->freq) { + fprintf(fout, "FREQ "); + } + + if (chan->mode) { + fprintf(fout, "MODE "); + } + + if (chan->width) { + fprintf(fout, "WIDTH "); + } + + if (chan->tx_freq) { + fprintf(fout, "TXFREQ "); + } + + if (chan->tx_mode) { + fprintf(fout, "TXMODE "); + } + + if (chan->tx_width) { + fprintf(fout, "TXWIDTH "); + } + + if (chan->split) { + fprintf(fout, "SPLIT "); + } + + if (chan->rptr_shift) { + fprintf(fout, "RPTRSHIFT "); + } + + if (chan->rptr_offs) { + fprintf(fout, "RPTROFS "); + } + + if (chan->tuning_step) { + fprintf(fout, "TS "); + } + + if (chan->rit) { + fprintf(fout, "RIT "); + } + + if (chan->xit) { + fprintf(fout, "XIT "); + } + + if (chan->funcs) { + fprintf(fout, "FUNC "); /* TODO: iterate over the list */ + } + + if (chan->levels) { + fprintf(fout, "LEVEL "); /* TODO: iterate over the list */ + } + + if (chan->ctcss_tone) { + fprintf(fout, "TONE "); + } + + if (chan->ctcss_sql) { + fprintf(fout, "CTCSS "); + } + + if (chan->dcs_code) { + fprintf(fout, "DCSCODE "); + } + + if (chan->dcs_sql) { + fprintf(fout, "DCSSQL "); + } + + if (chan->scan_group) { + fprintf(fout, "SCANGRP "); + } + + if (chan->flags) { + fprintf(fout, "FLAG "); /* TODO: iterate over the RIG_CHFLAG's */ + } + + if (chan->channel_desc) { + fprintf(fout, "NAME "); + } + + if (chan->ext_levels) { + fprintf(fout, "EXTLVL "); + } } -int dumpconf (RIG* rig, FILE *fout) + +int dumpconf(RIG *rig, FILE *fout) { - rig_token_foreach(rig, print_conf_list, (rig_ptr_t)rig); + rig_token_foreach(rig, print_conf_list, (rig_ptr_t)rig); - return 0; + return 0; } - diff --git a/tests/dumpcaps_rot.c b/tests/dumpcaps_rot.c index 6b3129f0f..b5d18f5d4 100644 --- a/tests/dumpcaps_rot.c +++ b/tests/dumpcaps_rot.c @@ -20,7 +20,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -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; } - diff --git a/tests/dumpmem.c b/tests/dumpmem.c index c237fdb43..8b4336abd 100644 --- a/tests/dumpmem.c +++ b/tests/dumpmem.c @@ -27,211 +27,324 @@ #include #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 \n",argv[0]); - exit(1); - } + if (argc != 2) { + fprintf(stderr, "%s \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; } - - - diff --git a/tests/example.c b/tests/example.c index 2ef8a11a3..a9571d3d0 100644 --- a/tests/example.c +++ b/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 #include -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); }; diff --git a/tests/listrigs.c b/tests/listrigs.c index 05e9b3c43..21a2847c7 100644 --- a/tests/listrigs.c +++ b/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; } - - diff --git a/tests/memcsv.c b/tests/memcsv.c index 2888a6f71..01da84feb 100644 --- a/tests/memcsv.c +++ b/tests/memcsv.c @@ -22,7 +22,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -45,53 +45,73 @@ extern int all; -char csv_sep = ','; /* CSV separator */ +char csv_sep = ','; /* CSV separator */ /* * Prototypes */ -static int dump_csv_chan(RIG *rig, channel_t **chan, int channel_num, const chan_t *chan_list, rig_ptr_t arg); +static int dump_csv_chan(RIG *rig, + channel_t **chan, + int channel_num, + const chan_t *chan_list, + rig_ptr_t arg); + static void dump_csv_name(const channel_cap_t *mem_caps, FILE *f); -static int set_channel_data(RIG *rig, channel_t *chan, char **line_key, char **line_data); -static char* mystrtok( char *s, char delim ); -static int tokenize_line( char *line, char **token_list, size_t siz, char delim ); -static int find_on_list( char **list, char *what ); -int csv_save (RIG *rig, const char *outfilename); -int csv_load (RIG *rig, const char *infilename); -int csv_parm_save (RIG *rig, const char *outfilename); -int csv_parm_load (RIG *rig, const char *infilename); +static int set_channel_data(RIG *rig, + channel_t *chan, + char **line_key, + char **line_data); + +static char * mystrtok(char *s, char delim); + +static int tokenize_line(char *line, + char **token_list, + size_t siz, + char delim); + +static int find_on_list(char **list, char *what); + +int csv_save(RIG *rig, const char *outfilename); +int csv_load(RIG *rig, const char *infilename); + +int csv_parm_save(RIG *rig, const char *outfilename); +int csv_parm_load(RIG *rig, const char *infilename); - -int csv_save (RIG *rig, const char *outfilename) +int csv_save(RIG *rig, const char *outfilename) { - int status; - FILE *f; + int status; + FILE *f; - f = fopen(outfilename, "w"); - if (!f) - return -1; + f = fopen(outfilename, "w"); - if (rig->caps->clone_combo_get) - printf("About to save data, enter cloning mode: %s\n", - rig->caps->clone_combo_get); + if (!f) { + return -1; + } - status = rig_get_chan_all_cb (rig, dump_csv_chan, f); + if (rig->caps->clone_combo_get) { + printf("About to save data, enter cloning mode: %s\n", + rig->caps->clone_combo_get); + } - fclose(f); - return status; + status = rig_get_chan_all_cb(rig, dump_csv_chan, f); + + fclose(f); + + return status; } + /** csv_load assumes the first line in a csv file is a key line, - defining entries and their number. First line should not + defining entries and their number. First line should not contain 'empty column', i.e. two adjacent commas. Each next line should contain the same number of entries. However, empty columns (two adjacent commas) are allowed. \param rig - a pointer to the rig \param infilename - a string with a file name to write to */ -int csv_load (RIG *rig, const char *infilename) +int csv_load(RIG *rig, const char *infilename) { int status = RIG_OK; FILE *f; @@ -102,215 +122,265 @@ int csv_load (RIG *rig, const char *infilename) channel_t chan; f = fopen(infilename, "r"); - if (!f) return -1; - - /* First read the first line, containing the key */ - if( fgets( keys, sizeof( keys ), f ) != NULL ){ - /* fgets stores '\n' in a buffer, get rid of it */ - keys[ strlen( keys )-1 ] = '\0'; - printf("Read the key: %s\n", keys ); - - /* Tokenize the key list */ - if( !tokenize_line( keys, key_list, sizeof(key_list)/sizeof(char*), ',' ) ){ - fprintf( stderr, "Invalid (possibly too long or empty) key line, cannot continue.\n" ); - fclose(f); - return -1; - } - }else{ - /* File exists, but is empty */ - fclose(f); - return -1; - } + if (!f) { + return -1; + } - /* Next, read the file line by line */ - while ( fgets ( line, sizeof line, f ) != NULL ){ - /* Tokenize the line */ - if( !tokenize_line( line, value_list, sizeof(value_list)/sizeof(char*), ',' ) ){ - fprintf( stderr, "Invalid (possibly too long or empty) line ignored\n" ); - continue; - } - /* Parse a line, write channel data into chan */ - set_channel_data( rig, &chan, key_list, value_list ); - - /* Write a rig memory */ - status=rig_set_channel(rig, &chan); + /* First read the first line, containing the key */ + if (fgets(keys, sizeof(keys), f) != NULL) { - if (status != RIG_OK ) { - fprintf( stderr, "rig_get_channel: error = %s \n", rigerror(status)); + /* fgets stores '\n' in a buffer, get rid of it */ + keys[ strlen(keys) - 1 ] = '\0'; + printf("Read the key: %s\n", keys); + + /* Tokenize the key list */ + if (!tokenize_line(keys, + key_list, + sizeof(key_list) / sizeof(char *), + ',')) { + fprintf(stderr, + "Invalid (possibly too long or empty) key line, cannot continue.\n"); + fclose(f); + return -1; + } + } else { + /* File exists, but is empty */ + fclose(f); + return -1; + } + + /* Next, read the file line by line */ + while (fgets(line, sizeof line, f) != NULL) { + /* Tokenize the line */ + if (!tokenize_line(line, + value_list, + sizeof(value_list) / sizeof(char *), + ',')) { + + fprintf(stderr, "Invalid (possibly too long or empty) line ignored\n"); + continue; + } + + /* Parse a line, write channel data into chan */ + set_channel_data(rig, &chan, key_list, value_list); + + /* Write a rig memory */ + status = rig_set_channel(rig, &chan); + + if (status != RIG_OK) { + fprintf(stderr, "rig_get_channel: error = %s \n", rigerror(status)); fclose(f); return status; - } + } - } - fclose( f ); - return status; + } + + fclose(f); + return status; } -/** Function to break a line into a list of tokens. Delimiters are + +/** Function to break a line into a list of tokens. Delimiters are replaced by end-of-string characters ('\0'), and a list of pointers to thus created substrings is created. \param line (input) - a line to be tokenized, the line will be modified! \param token_list (output) - a resulting table containing pointers to tokens, or NULLs (the table will be initially nulled ) - all the pointers schould point to addresses within the line + all the pointers schould point to addresses within the line \param siz (input) - size of the table \param delim (input) - delimiter character \return number of tokens on success, 0 if \param token_list is too small to contain all the tokens, or if line was empty. */ -static int tokenize_line( char *line, char **token_list, size_t siz, char delim ){ - size_t i; - char *tok; - -// printf("Starting tokenizer, line pointer %x, list pointer %x, list size = %d...", line, token_list, siz); - /* Erase the table */ - for( i = 0; i < siz; i++ ){ - token_list[i] = NULL; - } -// printf(", list emptied!\n"); - /* Empty line passed? */ - if( line == NULL ) return 0; - /* Reinitialize, find the first token */ - i = 0; - tok = mystrtok( line, delim ); - /* Line contains no delim */ - if( tok == NULL ) return 0; - token_list[ i++ ] = tok; -// printf("First token is: %s\n", tok); - - /* Find the remaining tokens */ - while( i < siz ){ - tok = mystrtok( NULL, delim ); -// printf("Next token: %s\n", tok ); - /* If NULL, no more tokens left */ - if(tok == NULL) break; - /* Add token to the list */ - token_list[ i++ ] = tok; - } -// printf("Finished tokenizing, i = %d, siz = %d\n", i, siz); - /* Any tokens left? */ - if( i == siz ){ - return 0; - }else{ - return i; - } +static int tokenize_line(char *line, char **token_list, size_t siz, char delim) +{ + size_t i; + char *tok; + + /* Erase the table */ + for (i = 0; i < siz; i++) { + token_list[i] = NULL; + } + + /* Empty line passed? */ + if (line == NULL) { + return 0; + } + + /* Reinitialize, find the first token */ + i = 0; + tok = mystrtok(line, delim); + + /* Line contains no delim */ + if (tok == NULL) { + return 0; + } + + token_list[ i++ ] = tok; + + /* Find the remaining tokens */ + while (i < siz) { + tok = mystrtok(NULL, delim); + + /* If NULL, no more tokens left */ + if (tok == NULL) { + break; + } + + /* Add token to the list */ + token_list[ i++ ] = tok; + } + + /* Any tokens left? */ + if (i == siz) { + return 0; + } else { + return i; + } } + /** Tokenizer that handles two delimiters by returning an empty string. First param (input) is a string to be tokenized, second is a delimiter (input) - This tokenizer accepts only one delimiter! + This tokenizer accepts only one delimiter! \param s - string to divide on first run, NULL on each next \param delim - delimiter - \return pointer to token, or NULL if there are no more tokens - \sa "man strtok" + \return pointer to token, or NULL if there are no more tokens + \sa "man strtok" */ -static char* mystrtok( char *s, char delim ){ - static size_t pos = 0, length = 0; - static char *str = 0; - if( s != NULL ){ - str = s; - pos = 0; - length = strlen( str ); - }else{ - } - if( str[ pos+1 ] == '\0' ) return NULL; - size_t i,ent_pos = pos; - for( i = pos; i < length; ){ - if( str[i] == delim ){ - str[i] = '\0'; - pos = i+1; - return str+ent_pos; - }else{ - i++; - } - } - return str + ent_pos; -} - -static int print_parm_name(RIG *rig, const struct confparams *cfp, rig_ptr_t ptr) +static char * mystrtok(char *s, char delim) { - fprintf((FILE*)ptr, "%s%c", cfp->name, csv_sep); + static size_t pos = 0, length = 0; + static char *str = 0; - return 1; /* process them all */ + if (s != NULL) { + str = s; + pos = 0; + length = strlen(str); + } else { + } + + if (str[ pos + 1 ] == '\0') { + return NULL; + } + + size_t i, ent_pos = pos; + + for (i = pos; i < length;) { + if (str[i] == delim) { + str[i] = '\0'; + pos = i + 1; + return str + ent_pos; + } else { + i++; + } + } + + return str + ent_pos; } + +static int print_parm_name(RIG *rig, + const struct confparams *cfp, + rig_ptr_t ptr) +{ + fprintf((FILE *)ptr, "%s%c", cfp->name, csv_sep); + + return 1; /* process them all */ +} + + static int print_parm_val(RIG *rig, const struct confparams *cfp, rig_ptr_t ptr) { - value_t val; - FILE *f=(FILE*)ptr; - rig_get_ext_parm(rig, cfp->token, &val); + value_t val; + FILE *f = (FILE *)ptr; + rig_get_ext_parm(rig, cfp->token, &val); - switch (cfp->type) { - case RIG_CONF_CHECKBUTTON: - case RIG_CONF_COMBO: - fprintf(f,"%d%c", val.i, csv_sep); - break; - case RIG_CONF_NUMERIC: - fprintf(f,"%f%c", val.f, csv_sep); - break; - case RIG_CONF_STRING: - fprintf(f,"%s%c", val.s, csv_sep); - break; - default: - fprintf(f,"unknown%c", csv_sep); - } + switch (cfp->type) { + case RIG_CONF_CHECKBUTTON: + case RIG_CONF_COMBO: + fprintf(f, "%d%c", val.i, csv_sep); + break; - return 1; /* process them all */ + case RIG_CONF_NUMERIC: + fprintf(f, "%f%c", val.f, csv_sep); + break; + + case RIG_CONF_STRING: + fprintf(f, "%s%c", val.s, csv_sep); + break; + + default: + fprintf(f, "unknown%c", csv_sep); + } + + return 1; /* process them all */ } -int csv_parm_save (RIG *rig, const char *outfilename) +int csv_parm_save(RIG *rig, const char *outfilename) { - int i, ret; - FILE *f; - setting_t parm, get_parm = all ? 0x7fffffff : rig->state.has_get_parm; + int i, ret; + FILE *f; + setting_t parm, get_parm = all ? 0x7fffffff : rig->state.has_get_parm; - f = fopen(outfilename, "w"); - if (!f) - return -1; + f = fopen(outfilename, "w"); - for (i = 0; i < RIG_SETTING_MAX; i++) { - const char *ms = rig_strparm(get_parm & rig_idx2setting(i)); - if (!ms || !ms[0]) - continue; - fprintf(f, "%s%c", ms, csv_sep); - } + if (!f) { + return -1; + } - rig_ext_parm_foreach(rig, print_parm_name, f); - fprintf(f, "\n"); + for (i = 0; i < RIG_SETTING_MAX; i++) { + const char *ms = rig_strparm(get_parm & rig_idx2setting(i)); - for (i = 0; i < RIG_SETTING_MAX; i++) { - const char *ms; - value_t val; + if (!ms || !ms[0]) { + continue; + } - parm = get_parm & rig_idx2setting(i); - ms = rig_strparm(parm); + fprintf(f, "%s%c", ms, csv_sep); + } - if (!ms || !ms[0]) - continue; - ret = rig_get_parm(rig, parm, &val); - if (ret != RIG_OK) - return ret; + rig_ext_parm_foreach(rig, print_parm_name, f); + fprintf(f, "\n"); - if (RIG_PARM_IS_FLOAT(parm)) - fprintf(f, "%f%c", val.f, csv_sep); - else - fprintf(f, "%d%c", val.i, csv_sep); - } + for (i = 0; i < RIG_SETTING_MAX; i++) { + const char *ms; + value_t val; + + parm = get_parm & rig_idx2setting(i); + ms = rig_strparm(parm); + + if (!ms || !ms[0]) { + continue; + } + + ret = rig_get_parm(rig, parm, &val); + + if (ret != RIG_OK) { + return ret; + } + + if (RIG_PARM_IS_FLOAT(parm)) { + fprintf(f, "%f%c", val.f, csv_sep); + } else { + fprintf(f, "%d%c", val.i, csv_sep); + } + } - rig_ext_parm_foreach(rig, print_parm_val, f); - fprintf(f, "\n"); - fclose(f); + rig_ext_parm_foreach(rig, print_parm_val, f); + fprintf(f, "\n"); + fclose(f); - return 0; + return 0; } -int csv_parm_load (RIG *rig, const char *infilename) + +int csv_parm_load(RIG *rig, const char *infilename) { - return -RIG_ENIMPL; - /* for every parm/ext_parm, fscanf, parse, set_parm's */ + return -RIG_ENIMPL; + /* for every parm/ext_parm, fscanf, parse, set_parm's */ } @@ -319,194 +389,245 @@ int csv_parm_load (RIG *rig, const char *infilename) /* Caution! Keep the function consistent with dump_csv_chan and set_channel_data! */ void dump_csv_name(const channel_cap_t *mem_caps, FILE *f) { - fprintf(f, "num%c", csv_sep); + fprintf(f, "num%c", csv_sep); - if (mem_caps->bank_num) { - fprintf(f, "bank_num%c", csv_sep); - } + if (mem_caps->bank_num) { + fprintf(f, "bank_num%c", csv_sep); + } - if (mem_caps->channel_desc) { - fprintf(f, "channel_desc%c", csv_sep); - } - if (mem_caps->vfo) { - fprintf(f, "vfo%c", csv_sep); - } - if (mem_caps->ant) { - fprintf(f, "ant%c", csv_sep); - } - if (mem_caps->freq) { - fprintf(f, "freq%c", csv_sep); - } - if (mem_caps->mode) { - fprintf(f, "mode%c", csv_sep); - } - if (mem_caps->width) { - fprintf(f, "width%c", csv_sep); - } - if (mem_caps->tx_freq) { - fprintf(f, "tx_freq%c", csv_sep); - } - if (mem_caps->tx_mode) { - fprintf(f, "tx_mode%c", csv_sep); - } - if (mem_caps->tx_width) { - fprintf(f, "tx_width%c", csv_sep); - } - if (mem_caps->split) { - fprintf(f, "split%c", csv_sep); - } - if (mem_caps->tx_vfo) { - fprintf(f, "tx_vfo%c", csv_sep); - } - if (mem_caps->rptr_shift) { - fprintf(f, "rptr_shift%c", csv_sep); - } - if (mem_caps->rptr_offs) { - fprintf(f, "rptr_offs%c", csv_sep); - } - if (mem_caps->tuning_step) { - fprintf(f, "tuning_step%c", csv_sep); - } - if (mem_caps->rit) { - fprintf(f, "rit%c", csv_sep); - } - if (mem_caps->xit) { - fprintf(f, "xit%c", csv_sep); - } - if (mem_caps->funcs) { - fprintf(f, "funcs%c", csv_sep); - } - if (mem_caps->ctcss_tone) { - fprintf(f, "ctcss_tone%c", csv_sep); - } - if (mem_caps->ctcss_sql) { - fprintf(f, "ctcss_sql%c", csv_sep); - } - if (mem_caps->dcs_code) { - fprintf(f, "dcs_code%c", csv_sep); - } - if (mem_caps->dcs_sql) { - fprintf(f, "dcs_sql%c", csv_sep); - } - if (mem_caps->scan_group) { - fprintf(f, "scan_group%c", csv_sep); - } - if (mem_caps->flags) { - fprintf(f, "flags%c", csv_sep); - } - fprintf(f, "\n"); + if (mem_caps->channel_desc) { + fprintf(f, "channel_desc%c", csv_sep); + } + + if (mem_caps->vfo) { + fprintf(f, "vfo%c", csv_sep); + } + + if (mem_caps->ant) { + fprintf(f, "ant%c", csv_sep); + } + + if (mem_caps->freq) { + fprintf(f, "freq%c", csv_sep); + } + + if (mem_caps->mode) { + fprintf(f, "mode%c", csv_sep); + } + + if (mem_caps->width) { + fprintf(f, "width%c", csv_sep); + } + + if (mem_caps->tx_freq) { + fprintf(f, "tx_freq%c", csv_sep); + } + + if (mem_caps->tx_mode) { + fprintf(f, "tx_mode%c", csv_sep); + } + + if (mem_caps->tx_width) { + fprintf(f, "tx_width%c", csv_sep); + } + + if (mem_caps->split) { + fprintf(f, "split%c", csv_sep); + } + + if (mem_caps->tx_vfo) { + fprintf(f, "tx_vfo%c", csv_sep); + } + + if (mem_caps->rptr_shift) { + fprintf(f, "rptr_shift%c", csv_sep); + } + + if (mem_caps->rptr_offs) { + fprintf(f, "rptr_offs%c", csv_sep); + } + + if (mem_caps->tuning_step) { + fprintf(f, "tuning_step%c", csv_sep); + } + + if (mem_caps->rit) { + fprintf(f, "rit%c", csv_sep); + } + + if (mem_caps->xit) { + fprintf(f, "xit%c", csv_sep); + } + + if (mem_caps->funcs) { + fprintf(f, "funcs%c", csv_sep); + } + + if (mem_caps->ctcss_tone) { + fprintf(f, "ctcss_tone%c", csv_sep); + } + + if (mem_caps->ctcss_sql) { + fprintf(f, "ctcss_sql%c", csv_sep); + } + + if (mem_caps->dcs_code) { + fprintf(f, "dcs_code%c", csv_sep); + } + + if (mem_caps->dcs_sql) { + fprintf(f, "dcs_sql%c", csv_sep); + } + + if (mem_caps->scan_group) { + fprintf(f, "scan_group%c", csv_sep); + } + + if (mem_caps->flags) { + fprintf(f, "flags%c", csv_sep); + } + + fprintf(f, "\n"); } /* Caution! Keep the function consistent with dump_csv_name and set_channel_data! */ -int dump_csv_chan(RIG *rig, channel_t **chan_pp, int channel_num, const chan_t *chan_list, rig_ptr_t arg) +int dump_csv_chan(RIG *rig, + channel_t **chan_pp, + int channel_num, + const chan_t *chan_list, + rig_ptr_t arg) { - FILE *f = arg; - static channel_t chan; - static int first_time = 1; - const channel_cap_t *mem_caps = &chan_list->mem_caps; + FILE *f = arg; + static channel_t chan; + static int first_time = 1; + const channel_cap_t *mem_caps = &chan_list->mem_caps; - if (first_time) { - dump_csv_name(mem_caps, f); - first_time = 0; - } + if (first_time) { + dump_csv_name(mem_caps, f); + first_time = 0; + } - 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; + } - fprintf(f,"%d%c",chan.channel_num, csv_sep); + fprintf(f, "%d%c", chan.channel_num, csv_sep); - if (mem_caps->bank_num) { - fprintf(f,"%d%c",chan.bank_num, csv_sep); - } + if (mem_caps->bank_num) { + fprintf(f, "%d%c", chan.bank_num, csv_sep); + } - if (mem_caps->channel_desc) { - fprintf(f, "%s%c", chan.channel_desc, csv_sep); - } - if (mem_caps->vfo) { - fprintf(f,"%s%c",rig_strvfo(chan.vfo), csv_sep); - } - if (mem_caps->ant) { - fprintf(f,"%d%c",chan.ant, csv_sep); - } - if (mem_caps->freq) { - fprintf(f,"%.0"PRIfreq"%c",chan.freq, csv_sep); - } - if (mem_caps->mode) { - fprintf(f, "%s%c", rig_strrmode(chan.mode), csv_sep); - } - if (mem_caps->width) { - fprintf(f,"%d%c",(int)chan.width, csv_sep); - } - if (mem_caps->tx_freq) { - fprintf(f,"%.0"PRIfreq"%c",chan.tx_freq, csv_sep); - } - if (mem_caps->tx_mode) { - fprintf(f, "%s%c", rig_strrmode(chan.tx_mode), csv_sep); - } - if (mem_caps->tx_width) { - fprintf(f,"%d%c",(int)chan.tx_width, csv_sep); - } - if (mem_caps->split) { - fprintf(f, "%s%c", chan.split==RIG_SPLIT_ON?"on":"off", csv_sep); - } - if (mem_caps->tx_vfo) { - fprintf(f,"%s%c",rig_strvfo(chan.tx_vfo), csv_sep); - } - if (mem_caps->rptr_shift) { - fprintf(f, "%s%c", rig_strptrshift(chan.rptr_shift), csv_sep); - } - if (mem_caps->rptr_offs) { - fprintf(f,"%d%c",(int)chan.rptr_offs, csv_sep); - } - if (mem_caps->tuning_step) { - fprintf(f,"%d%c",(int)chan.tuning_step, csv_sep); - } - if (mem_caps->rit) { - fprintf(f,"%d%c",(int)chan.rit, csv_sep); - } - if (mem_caps->xit) { - fprintf(f,"%d%c",(int)chan.xit, csv_sep); - } - if (mem_caps->funcs) { - fprintf(f,"%lx%c",chan.funcs, csv_sep); - } - if (mem_caps->ctcss_tone) { - fprintf(f,"%d%c",chan.ctcss_tone, csv_sep); - } - if (mem_caps->ctcss_sql) { - fprintf(f,"%d%c",chan.ctcss_sql, csv_sep); - } - if (mem_caps->dcs_code) { - fprintf(f,"%d%c",chan.dcs_code, csv_sep); - } - if (mem_caps->dcs_sql) { - fprintf(f,"%d%c",chan.dcs_sql, csv_sep); - } - if (mem_caps->scan_group) { - fprintf(f,"%d%c",chan.scan_group, csv_sep); - } - if (mem_caps->flags) { - fprintf(f,"%x%c",chan.flags, csv_sep); - } - fprintf(f,"\n"); + if (mem_caps->channel_desc) { + fprintf(f, "%s%c", chan.channel_desc, csv_sep); + } - /* - * keep the same *chan_pp for next round, thanks - * to chan being static - */ + if (mem_caps->vfo) { + fprintf(f, "%s%c", rig_strvfo(chan.vfo), csv_sep); + } + + if (mem_caps->ant) { + fprintf(f, "%d%c", chan.ant, csv_sep); + } + + if (mem_caps->freq) { + fprintf(f, "%.0"PRIfreq"%c", chan.freq, csv_sep); + } + + if (mem_caps->mode) { + fprintf(f, "%s%c", rig_strrmode(chan.mode), csv_sep); + } + + if (mem_caps->width) { + fprintf(f, "%d%c", (int)chan.width, csv_sep); + } + + if (mem_caps->tx_freq) { + fprintf(f, "%.0"PRIfreq"%c", chan.tx_freq, csv_sep); + } + + if (mem_caps->tx_mode) { + fprintf(f, "%s%c", rig_strrmode(chan.tx_mode), csv_sep); + } + + if (mem_caps->tx_width) { + fprintf(f, "%d%c", (int)chan.tx_width, csv_sep); + } + + if (mem_caps->split) { + fprintf(f, "%s%c", chan.split == RIG_SPLIT_ON ? "on" : "off", csv_sep); + } + + if (mem_caps->tx_vfo) { + fprintf(f, "%s%c", rig_strvfo(chan.tx_vfo), csv_sep); + } + + if (mem_caps->rptr_shift) { + fprintf(f, "%s%c", rig_strptrshift(chan.rptr_shift), csv_sep); + } + + if (mem_caps->rptr_offs) { + fprintf(f, "%d%c", (int)chan.rptr_offs, csv_sep); + } + + if (mem_caps->tuning_step) { + fprintf(f, "%d%c", (int)chan.tuning_step, csv_sep); + } + + if (mem_caps->rit) { + fprintf(f, "%d%c", (int)chan.rit, csv_sep); + } + + if (mem_caps->xit) { + fprintf(f, "%d%c", (int)chan.xit, csv_sep); + } + + if (mem_caps->funcs) { + fprintf(f, "%lx%c", chan.funcs, csv_sep); + } + + if (mem_caps->ctcss_tone) { + fprintf(f, "%d%c", chan.ctcss_tone, csv_sep); + } + + if (mem_caps->ctcss_sql) { + fprintf(f, "%d%c", chan.ctcss_sql, csv_sep); + } + + if (mem_caps->dcs_code) { + fprintf(f, "%d%c", chan.dcs_code, csv_sep); + } + + if (mem_caps->dcs_sql) { + fprintf(f, "%d%c", chan.dcs_sql, csv_sep); + } + + if (mem_caps->scan_group) { + fprintf(f, "%d%c", chan.scan_group, csv_sep); + } + + if (mem_caps->flags) { + fprintf(f, "%x%c", chan.flags, csv_sep); + } + + fprintf(f, "\n"); + + /* + * keep the same *chan_pp for next round, thanks + * to chan being static + */ - return RIG_OK; + return RIG_OK; } + /** Function to parse a line read from csv file and store the data into appropriate fields of channel_t. The function must be consistent with dump_csv_name and dump_csv_chan. @@ -516,199 +637,265 @@ int dump_csv_chan(RIG *rig, channel_t **chan_pp, int channel_num, const chan_t * \param line_data_list - a pointer to a table of strings with values \return 0 on success, negative value on error */ -int set_channel_data(RIG *rig, channel_t *chan, char **line_key_list, char **line_data_list){ +int set_channel_data(RIG *rig, + channel_t *chan, + char **line_key_list, + char **line_data_list) +{ - int i,j,n; - - memset(chan,0,sizeof(channel_t)); - chan->vfo = RIG_VFO_CURR; - - i = find_on_list( line_key_list, "num" ); - if( i < 0 ){ - fprintf(stderr,"No channel number\n"); + int i, j, n; + + memset(chan, 0, sizeof(channel_t)); + chan->vfo = RIG_VFO_CURR; + + i = find_on_list(line_key_list, "num"); + + if (i < 0) { + fprintf(stderr, "No channel number\n"); return -1; - } - n = chan->channel_num = atoi( line_data_list[ i ] ); + } + + n = chan->channel_num = atoi(line_data_list[ i ]); /* find chanel caps of appropriate memory group? */ - for(j=0; j < CHANLSTSIZ; j++) - if( rig->state.chan_list[j].start <= n && rig->state.chan_list[j].end >= n) + for (j = 0; j < CHANLSTSIZ; j++) + if (rig->state.chan_list[j].start <= n && rig->state.chan_list[j].end >= n) { break; + } - printf("Requested channel number %d, list number %d\n",n,j); + printf("Requested channel number %d, list number %d\n", n, j); - const channel_cap_t *mem_caps = &rig->state.chan_list[j].mem_caps; + const channel_cap_t *mem_caps = &rig->state.chan_list[j].mem_caps; if (mem_caps->bank_num) { - i = find_on_list( line_key_list, "bank_num" ); - if( i >= 0 ){ - chan->bank_num = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "bank_num"); + + if (i >= 0) { + chan->bank_num = atoi(line_data_list[ i ]); } } if (mem_caps->channel_desc) { - i = find_on_list( line_key_list, "channel_desc" ); - if( i >= 0 ){ - strncpy( chan->channel_desc, line_data_list[ i ], rig->caps->chan_desc_sz-1 ); - chan->channel_desc[ rig->caps->chan_desc_sz ] = '\0'; + i = find_on_list(line_key_list, "channel_desc"); + + if (i >= 0) { + strncpy(chan->channel_desc, line_data_list[ i ], rig->caps->chan_desc_sz - 1); + chan->channel_desc[ rig->caps->chan_desc_sz ] = '\0'; } } + if (mem_caps->ant) { - i = find_on_list( line_key_list, "ant" ); - if( i >= 0 ){ - chan->ant = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "ant"); + + if (i >= 0) { + chan->ant = atoi(line_data_list[ i ]); } } + if (mem_caps->freq) { - i = find_on_list( line_key_list, "freq" ); - if( i >= 0 ){ - chan->freq = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "freq"); + + if (i >= 0) { + chan->freq = atoi(line_data_list[ i ]); } } + if (mem_caps->mode) { - i = find_on_list( line_key_list, "mode" ); - if( i >= 0 ){ - chan->mode = rig_parse_mode( line_data_list[ i ] ); + i = find_on_list(line_key_list, "mode"); + + if (i >= 0) { + chan->mode = rig_parse_mode(line_data_list[ i ]); } } + if (mem_caps->width) { - i = find_on_list( line_key_list, "width" ); - if( i >= 0 ){ - chan->width = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "width"); + + if (i >= 0) { + chan->width = atoi(line_data_list[ i ]); } } + if (mem_caps->tx_freq) { - i = find_on_list( line_key_list, "tx_freq" ); - if( i >= 0 ){ - sscanf( line_data_list[i], "%"SCNfreq, &chan->tx_freq ); + i = find_on_list(line_key_list, "tx_freq"); + + if (i >= 0) { + sscanf(line_data_list[i], "%"SCNfreq, &chan->tx_freq); } } + if (mem_caps->tx_mode) { - i = find_on_list( line_key_list, "tx_mode" ); - if( i >= 0 ){ - chan->tx_mode = rig_parse_mode( line_data_list[ i ] ); + i = find_on_list(line_key_list, "tx_mode"); + + if (i >= 0) { + chan->tx_mode = rig_parse_mode(line_data_list[ i ]); } - } + } + if (mem_caps->tx_width) { - i = find_on_list( line_key_list, "tx_width" ); - if( i >= 0 ){ - chan->tx_width = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "tx_width"); + + if (i >= 0) { + chan->tx_width = atoi(line_data_list[ i ]); } } + if (mem_caps->split) { - chan->split=RIG_SPLIT_OFF; - i = find_on_list( line_key_list, "split" ); - if( i >= 0 ){ - if( strcmp( line_data_list[i], "on" ) == 0 ) { - chan->split=RIG_SPLIT_ON; + chan->split = RIG_SPLIT_OFF; + i = find_on_list(line_key_list, "split"); + + if (i >= 0) { + if (strcmp(line_data_list[i], "on") == 0) { + chan->split = RIG_SPLIT_ON; + if (mem_caps->tx_vfo) { - i = find_on_list( line_key_list, "tx_vfo" ); - if( i >= 0 ) - sscanf( line_data_list[i],"%x",&chan->tx_vfo); + i = find_on_list(line_key_list, "tx_vfo"); + + if (i >= 0) { + sscanf(line_data_list[i], "%x", &chan->tx_vfo); + } } - } + } } } + if (mem_caps->rptr_shift) { - i = find_on_list( line_key_list, "rptr_shift" ); - if( i >= 0 ){ - switch( line_data_list[i][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; + i = find_on_list(line_key_list, "rptr_shift"); + + if (i >= 0) { + switch (line_data_list[i][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( mem_caps->rptr_offs && chan->rptr_shift != RIG_RPT_SHIFT_NONE ){ - i = find_on_list( line_key_list, "rptr_offs" ); - if( i >= 0 ) - chan->rptr_offs = atoi( line_data_list[ i ] ); + + if (mem_caps->rptr_offs && chan->rptr_shift != RIG_RPT_SHIFT_NONE) { + i = find_on_list(line_key_list, "rptr_offs"); + + if (i >= 0) { + chan->rptr_offs = atoi(line_data_list[ i ]); + } } } } + if (mem_caps->tuning_step) { - i = find_on_list( line_key_list, "tuning_step" ); - if( i >= 0 ){ - chan->tuning_step = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "tuning_step"); + + if (i >= 0) { + chan->tuning_step = atoi(line_data_list[ i ]); } } + if (mem_caps->rit) { - i = find_on_list( line_key_list, "rit" ); - if( i >= 0 ){ - chan->rit = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "rit"); + + if (i >= 0) { + chan->rit = atoi(line_data_list[ i ]); } } + if (mem_caps->xit) { - i = find_on_list( line_key_list, "xit" ); - if( i >= 0 ){ - chan->xit = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "xit"); + + if (i >= 0) { + chan->xit = atoi(line_data_list[ i ]); } } + if (mem_caps->funcs) { - i = find_on_list( line_key_list, "funcs" ); - if( i >= 0 ){ - sscanf( line_data_list[i], "%lx", &chan->funcs ); + i = find_on_list(line_key_list, "funcs"); + + if (i >= 0) { + sscanf(line_data_list[i], "%lx", &chan->funcs); } } + if (mem_caps->ctcss_tone) { - i = find_on_list( line_key_list, "ctcss_tone" ); - if( i >= 0 ){ - chan->ctcss_tone = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "ctcss_tone"); + + if (i >= 0) { + chan->ctcss_tone = atoi(line_data_list[ i ]); } } + if (mem_caps->ctcss_sql) { - i = find_on_list( line_key_list, "ctcss_sql" ); - if( i >= 0 ){ - chan->ctcss_sql = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "ctcss_sql"); + + if (i >= 0) { + chan->ctcss_sql = atoi(line_data_list[ i ]); } } + if (mem_caps->dcs_code) { - i = find_on_list( line_key_list, "dcs_code" ); - if( i >= 0 ){ - chan->dcs_code = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "dcs_code"); + + if (i >= 0) { + chan->dcs_code = atoi(line_data_list[ i ]); } } + if (mem_caps->dcs_sql) { - i = find_on_list( line_key_list, "dcs_sql" ); - if( i >= 0 ){ - chan->dcs_sql = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "dcs_sql"); + + if (i >= 0) { + chan->dcs_sql = atoi(line_data_list[ i ]); } } + if (mem_caps->scan_group) { - i = find_on_list( line_key_list, "scan_group" ); - if( i >= 0 ){ - chan->scan_group = atoi( line_data_list[ i ] ); + i = find_on_list(line_key_list, "scan_group"); + + if (i >= 0) { + chan->scan_group = atoi(line_data_list[ i ]); } } + if (mem_caps->flags) { - i = find_on_list( line_key_list, "flags" ); - if( i >= 0 ){ - sscanf( line_data_list[i], "%x", &chan->flags ); + i = find_on_list(line_key_list, "flags"); + + if (i >= 0) { + sscanf(line_data_list[i], "%x", &chan->flags); } } - return 0; + + return 0; } + /** Find a string on the list. Assumes the last element on the list is NULL \param list - a list \param what - a string to find - \return string position on the list on success, + \return string position on the list on success, -1 if string not found or if string is empty */ -int find_on_list( char **list, char *what ){ - int i = 0; - if( !what ) return -1; - while( list[i] != NULL ){ - if( strcmp( list[i], what ) == 0 ){ - return i; - }else{ - i++; - } - } - if( !list[i] ){ - return -1; - }else{ - return i; - } +int find_on_list(char **list, char *what) +{ + int i = 0; + + if (!what) { + return -1; + } + + while (list[i] != NULL) { + if (strcmp(list[i], what) == 0) { + return i; + } else { + i++; + } + } + + if (!list[i]) { + return -1; + } else { + return i; + } } diff --git a/tests/memload.c b/tests/memload.c index 3b53920eb..f448bbaf2 100644 --- a/tests/memload.c +++ b/tests/memload.c @@ -20,7 +20,7 @@ #ifdef HAVE_CONFIG_H -#include +# include #endif #include @@ -32,229 +32,317 @@ #include "misc.h" #ifdef HAVE_XML2 -#include -#include +# include +# include -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;istate.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 - diff --git a/tests/memsave.c b/tests/memsave.c index 04c73a1d0..2778d4532 100644 --- a/tests/memsave.c +++ b/tests/memsave.c @@ -19,7 +19,7 @@ * */ #ifdef HAVE_CONFIG_H -#include +# include #endif #include @@ -32,193 +32,231 @@ #include "misc.h" #ifdef HAVE_XML2 -#include -#include +# include +# include -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; itype); - 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 diff --git a/tests/rig_bench.c b/tests/rig_bench.c index 26b064cf7..b1d1659ef 100644 --- a/tests/rig_bench.c +++ b/tests/rig_bench.c @@ -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 @@ -42,7 +42,7 @@ # elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */ # include # 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 # 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 " - "\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 \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 .\n"); + printf("\nReport bugs to .\n"); } diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 14b1d4a84..dbd14fe1b 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -26,7 +26,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -42,7 +42,7 @@ # elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */ # include # else /* !defined(HAVE_READLINE_H) */ -extern char *readline (); +extern char * readline(); # endif /* HAVE_READLINE_H */ #else /* no readline */ @@ -54,11 +54,11 @@ extern char *readline (); # elif defined(HAVE_HISTORY_H) # include # 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) */ - /* no history */ +/* no history */ #endif /* HAVE_READLINE_HISTORY */ @@ -100,7 +100,7 @@ static pthread_mutex_t rig_mutex = PTHREAD_MUTEX_INITIALIZER; #define STR(S) STR1(S) #define MAXNAMSIZ 32 -#define MAXNBOPT 100 /* max number of different options */ +#define MAXNBOPT 100 /* max number of different options */ #define MAXARGSZ 127 #define ARG_IN1 0x01 @@ -121,7 +121,7 @@ static pthread_mutex_t rig_mutex = PTHREAD_MUTEX_INITIALIZER; #ifdef HAVE_LIBREADLINE static char *input_line = (char *)NULL; static char *result = (char *)NULL; -static char *parsed_input[sizeof(char*) * 5]; +static char *parsed_input[sizeof(char *) * 5]; static const int have_rl = 1; #ifdef HAVE_READLINE_HISTORY @@ -132,25 +132,39 @@ static char *rp_hist_buf = (char *)NULL; static const int have_rl = 0; #endif + struct test_table { - unsigned char cmd; - const char *name; - int (*rig_routine)(RIG*, FILE*, FILE*, int, const struct test_table*, vfo_t, - const char*, const char*, const char*); - int flags; - const char *arg1; - const char *arg2; - const char *arg3; - const char *arg4; + unsigned char cmd; + const char *name; + int (*rig_routine)(RIG *, + FILE *, + FILE *, + int, + const struct test_table *, + vfo_t, + const char *, + const char *, + const char *); + int flags; + const char *arg1; + const char *arg2; + const char *arg3; + const char *arg4; }; #define CHKSCN1ARG(a) if ((a) != 1) return -RIG_EINVAL; else do {} while(0) #define ACTION(f) rigctl_##f -#define declare_proto_rig(f) static int (ACTION(f))(RIG *rig, FILE *fout, FILE *fin, int interactive, \ - const struct test_table *cmd, vfo_t vfo, const char *arg1, \ - const char *arg2, const char *arg3) +#define declare_proto_rig(f) static int (ACTION(f))(RIG *rig, \ + FILE *fout, \ + FILE *fin, \ + int interactive, \ + const struct test_table *cmd, \ + vfo_t vfo, \ + const char *arg1, \ + const char *arg2, \ + const char *arg3) declare_proto_rig(set_freq); declare_proto_rig(get_freq); @@ -228,149 +242,163 @@ declare_proto_rig(pause); * * TODO: add missing rig_set_/rig_get_: sql, dcd, etc. * NB: 'q' 'Q' '?' are reserved by interactive mode interface - * do NOT use -W since it's reserved by POSIX. + * do NOT use -W since it's reserved by POSIX. * - * Available alphabetic letters: -.--------------*-----W-Y- + * Available alphabetic letters: -.--------------*-----W-Y- */ static struct test_table test_list[] = { - { 'F', "set_freq", ACTION(set_freq), ARG_IN, "Frequency" }, - { 'f', "get_freq", ACTION(get_freq), ARG_OUT, "Frequency" }, - { 'M', "set_mode", ACTION(set_mode), ARG_IN, "Mode", "Passband" }, - { 'm', "get_mode", ACTION(get_mode), ARG_OUT, "Mode", "Passband" }, - { 'I', "set_split_freq", ACTION(set_split_freq), ARG_IN, "TX Frequency" }, - { 'i', "get_split_freq", ACTION(get_split_freq), ARG_OUT, "TX Frequency" }, - { 'X', "set_split_mode", ACTION(set_split_mode), ARG_IN, "TX Mode", "TX Passband" }, - { 'x', "get_split_mode", ACTION(get_split_mode), ARG_OUT, "TX Mode", "TX Passband" }, - { 'K', "set_split_freq_mode", ACTION(set_split_freq_mode), ARG_IN, "TX Frequency", "TX Mode", "TX Passband" }, - { 'k', "get_split_freq_mode", ACTION(get_split_freq_mode), ARG_OUT, "TX Frequency", "TX Mode", "TX Passband" }, - { 'S', "set_split_vfo", ACTION(set_split_vfo), ARG_IN, "Split", "TX VFO" }, - { 's', "get_split_vfo", ACTION(get_split_vfo), ARG_OUT, "Split", "TX VFO" }, - { 'N', "set_ts", ACTION(set_ts), ARG_IN, "Tuning Step" }, - { 'n', "get_ts", ACTION(get_ts), ARG_OUT, "Tuning Step" }, - { 'L', "set_level", ACTION(set_level), ARG_IN, "Level", "Level Value" }, - { 'l', "get_level", ACTION(get_level), ARG_IN1|ARG_OUT2, "Level", "Level Value" }, - { 'U', "set_func", ACTION(set_func), ARG_IN, "Func", "Func Status" }, - { 'u', "get_func", ACTION(get_func), ARG_IN1|ARG_OUT2, "Func", "Func Status" }, - { 'P', "set_parm", ACTION(set_parm), ARG_IN|ARG_NOVFO, "Parm", "Parm Value" }, - { 'p', "get_parm", ACTION(get_parm), ARG_IN1|ARG_OUT2|ARG_NOVFO, "Parm", "Parm Value" }, - { 'G', "vfo_op", ACTION(vfo_op), ARG_IN, "Mem/VFO Op" }, - { 'g', "scan", ACTION(scan), ARG_IN, "Scan Fct", "Scan Channel" }, - { 'A', "set_trn", ACTION(set_trn), ARG_IN|ARG_NOVFO, "Transceive" }, - { 'a', "get_trn", ACTION(get_trn), ARG_OUT|ARG_NOVFO, "Transceive" }, - { 'R', "set_rptr_shift", ACTION(set_rptr_shift), ARG_IN, "Rptr Shift" }, - { 'r', "get_rptr_shift", ACTION(get_rptr_shift), ARG_OUT, "Rptr Shift" }, - { 'O', "set_rptr_offs", ACTION(set_rptr_offs), ARG_IN, "Rptr Offset" }, - { 'o', "get_rptr_offs", ACTION(get_rptr_offs), ARG_OUT, "Rptr Offset" }, - { 'C', "set_ctcss_tone", ACTION(set_ctcss_tone), ARG_IN, "CTCSS Tone" }, - { 'c', "get_ctcss_tone", ACTION(get_ctcss_tone), ARG_OUT, "CTCSS Tone" }, - { 'D', "set_dcs_code", ACTION(set_dcs_code), ARG_IN, "DCS Code" }, - { 'd', "get_dcs_code", ACTION(get_dcs_code), ARG_OUT, "DCS Code" }, - { 0x90, "set_ctcss_sql", ACTION(set_ctcss_sql), ARG_IN, "CTCSS Sql" }, - { 0x91, "get_ctcss_sql", ACTION(get_ctcss_sql), ARG_OUT, "CTCSS Sql" }, - { 0x92, "set_dcs_sql", ACTION(set_dcs_sql), ARG_IN, "DCS Sql" }, - { 0x93, "get_dcs_sql", ACTION(get_dcs_sql), ARG_OUT, "DCS Sql" }, - { 'V', "set_vfo", ACTION(set_vfo), ARG_IN|ARG_NOVFO, "VFO" }, - { 'v', "get_vfo", ACTION(get_vfo), ARG_OUT, "VFO" }, - { 'T', "set_ptt", ACTION(set_ptt), ARG_IN, "PTT" }, - { 't', "get_ptt", ACTION(get_ptt), ARG_OUT, "PTT" }, - { 'E', "set_mem", ACTION(set_mem), ARG_IN, "Memory#" }, - { 'e', "get_mem", ACTION(get_mem), ARG_OUT, "Memory#" }, - { 'H', "set_channel", ACTION(set_channel), ARG_IN|ARG_NOVFO, "Channel" }, - { 'h', "get_channel", ACTION(get_channel), ARG_IN|ARG_NOVFO, "Channel" }, - { 'B', "set_bank", ACTION(set_bank), ARG_IN, "Bank" }, - { '_', "get_info", ACTION(get_info), ARG_OUT|ARG_NOVFO, "Info" }, - { 'J', "set_rit", ACTION(set_rit), ARG_IN, "RIT" }, - { 'j', "get_rit", ACTION(get_rit), ARG_OUT, "RIT" }, - { 'Z', "set_xit", ACTION(set_xit), ARG_IN, "XIT" }, - { 'z', "get_xit", ACTION(get_xit), ARG_OUT, "XIT" }, - { 'Y', "set_ant", ACTION(set_ant), ARG_IN, "Antenna" }, - { 'y', "get_ant", ACTION(get_ant), ARG_OUT, "Antenna" }, - { 0x87, "set_powerstat", ACTION(set_powerstat), ARG_IN|ARG_NOVFO, "Power Status" }, - { 0x88, "get_powerstat", ACTION(get_powerstat), ARG_OUT|ARG_NOVFO, "Power Status" }, - { 0x89, "send_dtmf", ACTION(send_dtmf), ARG_IN, "Digits" }, - { 0x8a, "recv_dtmf", ACTION(recv_dtmf), ARG_OUT, "Digits" }, - { '*', "reset", ACTION(reset), ARG_IN, "Reset" }, - { 'w', "send_cmd", ACTION(send_cmd), ARG_IN1|ARG_IN_LINE|ARG_OUT2|ARG_NOVFO, "Cmd", "Reply" }, - { 'b', "send_morse", ACTION(send_morse), ARG_IN|ARG_IN_LINE, "Morse" }, - { 0x8b, "get_dcd", ACTION(get_dcd), ARG_OUT, "DCD" }, - { '2', "power2mW", ACTION(power2mW), ARG_IN1|ARG_IN2|ARG_IN3|ARG_OUT1|ARG_NOVFO, "Power [0.0..1.0]", "Frequency", "Mode", "Power mW" }, - { '4', "mW2power", ACTION(mW2power), ARG_IN1|ARG_IN2|ARG_IN3|ARG_OUT1|ARG_NOVFO, "Power mW", "Frequency", "Mode", "Power [0.0..1.0]" }, - { '1', "dump_caps", ACTION(dump_caps), ARG_NOVFO }, - { '3', "dump_conf", ACTION(dump_conf), ARG_NOVFO }, - { 0x8f,"dump_state", ACTION(dump_state), ARG_OUT|ARG_NOVFO }, - { 0xf0,"chk_vfo", ACTION(chk_vfo), ARG_NOVFO }, /* rigctld only--check for VFO mode */ - { 0xf1,"halt", ACTION(halt), ARG_NOVFO }, /* rigctld only--halt the daemon */ - { 0x8c, "pause", ACTION(pause), ARG_IN, "Seconds" }, - { 0x00, "", NULL }, + { 'F', "set_freq", ACTION(set_freq), ARG_IN, "Frequency" }, + { 'f', "get_freq", ACTION(get_freq), ARG_OUT,"Frequency" }, + { 'M', "set_mode", ACTION(set_mode), ARG_IN, "Mode", "Passband" }, + { 'm', "get_mode", ACTION(get_mode), ARG_OUT,"Mode", "Passband" }, + { 'I', "set_split_freq", ACTION(set_split_freq), ARG_IN, "TX Frequency" }, + { 'i', "get_split_freq", ACTION(get_split_freq), ARG_OUT,"TX Frequency" }, + { 'X', "set_split_mode", ACTION(set_split_mode), ARG_IN, "TX Mode", "TX Passband" }, + { 'x', "get_split_mode", ACTION(get_split_mode), ARG_OUT,"TX Mode", "TX Passband" }, + { 'K', "set_split_freq_mode", ACTION(set_split_freq_mode), ARG_IN, "TX Frequency", "TX Mode", "TX Passband" }, + { 'k', "get_split_freq_mode", ACTION(get_split_freq_mode), ARG_OUT, "TX Frequency", "TX Mode", "TX Passband" }, + { 'S', "set_split_vfo", ACTION(set_split_vfo), ARG_IN, "Split", "TX VFO" }, + { 's', "get_split_vfo", ACTION(get_split_vfo), ARG_OUT,"Split", "TX VFO" }, + { 'N', "set_ts", ACTION(set_ts), ARG_IN, "Tuning Step" }, + { 'n', "get_ts", ACTION(get_ts), ARG_OUT,"Tuning Step" }, + { 'L', "set_level", ACTION(set_level), ARG_IN, "Level", "Level Value" }, + { 'l', "get_level", ACTION(get_level), ARG_IN1 | ARG_OUT2, "Level", "Level Value" }, + { 'U', "set_func", ACTION(set_func), ARG_IN, "Func", "Func Status" }, + { 'u', "get_func", ACTION(get_func), ARG_IN1 | ARG_OUT2, "Func", "Func Status" }, + { 'P', "set_parm", ACTION(set_parm), ARG_IN | ARG_NOVFO, "Parm", "Parm Value" }, + { 'p', "get_parm", ACTION(get_parm), ARG_IN1 | ARG_OUT2 | ARG_NOVFO, "Parm", "Parm Value" }, + { 'G', "vfo_op", ACTION(vfo_op), ARG_IN, "Mem/VFO Op" }, + { 'g', "scan", ACTION(scan), ARG_IN, "Scan Fct", "Scan Channel" }, + { 'A', "set_trn", ACTION(set_trn), ARG_IN | ARG_NOVFO, "Transceive" }, + { 'a', "get_trn", ACTION(get_trn), ARG_OUT | ARG_NOVFO, "Transceive" }, + { 'R', "set_rptr_shift", ACTION(set_rptr_shift), ARG_IN, "Rptr Shift" }, + { 'r', "get_rptr_shift", ACTION(get_rptr_shift), ARG_OUT,"Rptr Shift" }, + { 'O', "set_rptr_offs", ACTION(set_rptr_offs), ARG_IN, "Rptr Offset" }, + { 'o', "get_rptr_offs", ACTION(get_rptr_offs), ARG_OUT,"Rptr Offset" }, + { 'C', "set_ctcss_tone", ACTION(set_ctcss_tone), ARG_IN, "CTCSS Tone" }, + { 'c', "get_ctcss_tone", ACTION(get_ctcss_tone), ARG_OUT,"CTCSS Tone" }, + { 'D', "set_dcs_code", ACTION(set_dcs_code), ARG_IN, "DCS Code" }, + { 'd', "get_dcs_code", ACTION(get_dcs_code), ARG_OUT,"DCS Code" }, + { 0x90, "set_ctcss_sql", ACTION(set_ctcss_sql), ARG_IN, "CTCSS Sql" }, + { 0x91, "get_ctcss_sql", ACTION(get_ctcss_sql), ARG_OUT,"CTCSS Sql" }, + { 0x92, "set_dcs_sql", ACTION(set_dcs_sql), ARG_IN, "DCS Sql" }, + { 0x93, "get_dcs_sql", ACTION(get_dcs_sql), ARG_OUT,"DCS Sql" }, + { 'V', "set_vfo", ACTION(set_vfo), ARG_IN | ARG_NOVFO, "VFO" }, + { 'v', "get_vfo", ACTION(get_vfo), ARG_OUT,"VFO" }, + { 'T', "set_ptt", ACTION(set_ptt), ARG_IN, "PTT" }, + { 't', "get_ptt", ACTION(get_ptt), ARG_OUT,"PTT" }, + { 'E', "set_mem", ACTION(set_mem), ARG_IN, "Memory#" }, + { 'e', "get_mem", ACTION(get_mem), ARG_OUT,"Memory#" }, + { 'H', "set_channel", ACTION(set_channel), ARG_IN | ARG_NOVFO, "Channel" }, + { 'h', "get_channel", ACTION(get_channel), ARG_IN | ARG_NOVFO, "Channel" }, + { 'B', "set_bank", ACTION(set_bank), ARG_IN, "Bank" }, + { '_', "get_info", ACTION(get_info), ARG_OUT | ARG_NOVFO, "Info" }, + { 'J', "set_rit", ACTION(set_rit), ARG_IN, "RIT" }, + { 'j', "get_rit", ACTION(get_rit), ARG_OUT,"RIT" }, + { 'Z', "set_xit", ACTION(set_xit), ARG_IN, "XIT" }, + { 'z', "get_xit", ACTION(get_xit), ARG_OUT,"XIT" }, + { 'Y', "set_ant", ACTION(set_ant), ARG_IN, "Antenna" }, + { 'y', "get_ant", ACTION(get_ant), ARG_OUT,"Antenna" }, + { 0x87, "set_powerstat", ACTION(set_powerstat), ARG_IN | ARG_NOVFO, "Power Status" }, + { 0x88, "get_powerstat", ACTION(get_powerstat), ARG_OUT | ARG_NOVFO, "Power Status" }, + { 0x89, "send_dtmf", ACTION(send_dtmf), ARG_IN, "Digits" }, + { 0x8a, "recv_dtmf", ACTION(recv_dtmf), ARG_OUT,"Digits" }, + { '*', "reset", ACTION(reset), ARG_IN, "Reset" }, + { 'w', "send_cmd", ACTION(send_cmd), ARG_IN1 | ARG_IN_LINE | ARG_OUT2 | ARG_NOVFO, "Cmd", "Reply" }, + { 'b', "send_morse", ACTION(send_morse), ARG_IN | ARG_IN_LINE, "Morse" }, + { 0x8b, "get_dcd", ACTION(get_dcd), ARG_OUT,"DCD" }, + { '2', "power2mW", ACTION(power2mW), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1 | ARG_NOVFO, "Power [0.0..1.0]", "Frequency", "Mode", "Power mW" }, + { '4', "mW2power", ACTION(mW2power), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1 | ARG_NOVFO, "Power mW", "Frequency", "Mode", "Power [0.0..1.0]" }, + { '1', "dump_caps", ACTION(dump_caps), ARG_NOVFO }, + { '3', "dump_conf", ACTION(dump_conf), ARG_NOVFO }, + { 0x8f, "dump_state", ACTION(dump_state), ARG_OUT | ARG_NOVFO }, + { 0xf0, "chk_vfo", ACTION(chk_vfo), ARG_NOVFO }, /* rigctld only--check for VFO mode */ + { 0xf1, "halt", ACTION(halt), ARG_NOVFO }, /* rigctld only--halt the daemon */ + { 0x8c, "pause", ACTION(pause), ARG_IN, "Seconds" }, + { 0x00, "", NULL }, }; + static struct test_table *find_cmd_entry(int cmd) { - int i; - for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0x00; i++) - if (test_list[i].cmd == cmd) - break; + int i; - if (i >= MAXNBOPT || test_list[i].cmd == 0x00) - return NULL; + for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0x00; i++) { + if (test_list[i].cmd == cmd) { + break; + } + } - return &test_list[i]; + if (i >= MAXNBOPT || test_list[i].cmd == 0x00) { + return NULL; + } + + return &test_list[i]; } + /* Structure for hash table provided by uthash.h * * Structure and hash funtions patterned after/copied from example.c * distributed with the uthash package. See: http://uthash.sourceforge.net/ */ -struct mod_lst -{ - int id; /* caps->rig_model This is the hash key */ - char mfg_name[32]; /* caps->mfg_name */ - char model_name[32]; /* caps->model_name */ - char version[32]; /* caps->version */ - char status[32]; /* caps->status */ - UT_hash_handle hh; /* makes this structure hashable */ +struct mod_lst { + int id; /* caps->rig_model This is the hash key */ + char mfg_name[32]; /* caps->mfg_name */ + char model_name[32]; /* caps->model_name */ + char version[32]; /* caps->version */ + char status[32]; /* caps->status */ + UT_hash_handle hh; /* makes this structure hashable */ }; + /* Hash declaration. Must be initialized to NULL */ struct mod_lst *models = NULL; + /* Add model information to the hash */ -void hash_add_model(int id, const char *mfg_name, const char *model_name, - const char *version, const char *status) +void hash_add_model(int id, + const char *mfg_name, + const char *model_name, + const char *version, + const char *status) { - struct mod_lst *s; + struct mod_lst *s; - s = (struct mod_lst*)malloc(sizeof(struct mod_lst)); + s = (struct mod_lst *)malloc(sizeof(struct mod_lst)); - s->id = id; - snprintf(s->mfg_name, sizeof(s->mfg_name), "%s", mfg_name); - snprintf(s->model_name, sizeof(s->model_name), "%s", model_name); - snprintf(s->version, sizeof(s->version), "%s", version); - snprintf(s->status, sizeof(s->status), "%s", status); + s->id = id; + snprintf(s->mfg_name, sizeof(s->mfg_name), "%s", mfg_name); + snprintf(s->model_name, sizeof(s->model_name), "%s", model_name); + snprintf(s->version, sizeof(s->version), "%s", version); + snprintf(s->status, sizeof(s->status), "%s", status); - HASH_ADD_INT(models, id, s); /* id: name of key field */ + HASH_ADD_INT(models, id, s); /* id: name of key field */ } + /* Hash sorting functions */ int hash_model_id_sort(struct mod_lst *a, struct mod_lst *b) { - return (a->id - b->id); + return (a->id - b->id); } + void hash_sort_by_model_id() { HASH_SORT(models, hash_model_id_sort); } -/* Delete hash */ -void hash_delete_all() { - struct mod_lst *current_model, *tmp; - HASH_ITER(hh, models, current_model, tmp) { - HASH_DEL(models, current_model); /* delete it (models advances to next) */ - free(current_model); /* free it */ - } +/* Delete hash */ +void hash_delete_all() +{ + struct mod_lst *current_model, *tmp; + + HASH_ITER(hh, models, current_model, tmp) { + HASH_DEL(models, current_model); /* delete it (models advances to next) */ + free(current_model); /* free it */ + } } @@ -380,23 +408,24 @@ void hash_delete_all() { */ static void rp_getline(const char *s) { - int i; + int i; - /* free allocated memory and set pointers to NULL */ - if (input_line) { - free(input_line); - input_line = (char *)NULL; - } + /* free allocated memory and set pointers to NULL */ + if (input_line) { + free(input_line); + input_line = (char *)NULL; + } - if (result) { - result = (char *)NULL; - } + if (result) { + result = (char *)NULL; + } - for (i = 0; i < 5; i++) - parsed_input[i] = NULL; + for (i = 0; i < 5; i++) { + parsed_input[i] = NULL; + } - /* Action! Returns typed line with newline stripped. */ - input_line = readline(s); + /* Action! Returns typed line with newline stripped. */ + input_line = readline(s); } @@ -408,11 +437,15 @@ static void rp_getline(const char *s) */ static char parse_arg(const char *arg) { - int i; - for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0; i++) - if (!strncmp(arg, test_list[i].name, MAXNAMSIZ)) - return test_list[i].cmd; - return 0; + int i; + + for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0; i++) { + if (!strncmp(arg, test_list[i].name, MAXNAMSIZ)) { + return test_list[i].cmd; + } + } + + return 0; } @@ -421,20 +454,28 @@ static char parse_arg(const char *arg) */ static int scanfc(FILE *fin, const char *format, void *p) { - int ret; + int ret; - do { - ret = fscanf(fin, format, p); - if (ret < 0) { - if (errno == EINTR) - continue; - rig_debug(RIG_DEBUG_ERR, "fscanf: %s\n", strerror(errno)); - rig_debug(RIG_DEBUG_ERR, "fscanf: parsing '%s' with '%s'\n", p, format); - } - return ret; - } while(1); + do { + ret = fscanf(fin, format, p); + + if (ret < 0) { + if (errno == EINTR) { + continue; + } + + rig_debug(RIG_DEBUG_ERR, "fscanf: %s\n", strerror(errno)); + rig_debug(RIG_DEBUG_ERR, + "fscanf: parsing '%s' with '%s'\n", + p, + format); + } + + return ret; + } while (1); } + /* * function to get the next word from the command line or from stdin * until stdin exhausted. stdin is read if the special token '-' is @@ -444,70 +485,75 @@ static int scanfc(FILE *fin, const char *format, void *p) * returns <0 is error number * returns >=0 when successful */ -static int next_word (char *buffer, int argc, char *argv[], int newline) +static int next_word(char *buffer, int argc, char *argv[], int newline) { - int ret; - char c; - static int reading_stdin; + int ret; + char c; + static int reading_stdin; - if (!reading_stdin) - { - if (optind >= argc) return EOF; - else if (newline && '-' == argv[optind][0] && 1 == strlen (argv[optind])) - { - ++optind; - reading_stdin = 1; + if (!reading_stdin) { + if (optind >= argc) { + return EOF; + } else if (newline && '-' == argv[optind][0] && 1 == strlen(argv[optind])) { + ++optind; + reading_stdin = 1; } } - if (reading_stdin) - { - do - { - do ret = scanf (" %c%" STR(MAXARGSZ) "[^ \t\n#]", &c, &buffer[1]); while (EINTR == ret); - if (ret > 0 && '#' == c) - { - do ret = scanf ("%*[^\n]"); while (EINTR == ret); /* consume comments */ - ret = 0; + if (reading_stdin) { + do { + do { + ret = scanf(" %c%" STR(MAXARGSZ) "[^ \t\n#]", &c, &buffer[1]); + } while (EINTR == ret); + + if (ret > 0 && '#' == c) { + do { + ret = scanf("%*[^\n]"); + } while (EINTR == ret); /* consume comments */ + + ret = 0; } - } - while (!ret); - if (EOF == ret) reading_stdin = 0; - else if (ret < 0) - { - rig_debug (RIG_DEBUG_ERR, "scanf: %s\n", strerror (errno)); - reading_stdin = 0; - } - else - { - buffer[0] = c; - buffer[1 == ret ? 1 : MAXARGSZ] = '\0'; - if (newline) putchar ('\n'); - fputs (buffer, stdout); - putchar (' '); + } while (!ret); + + if (EOF == ret) { + reading_stdin = 0; + } else if (ret < 0) { + rig_debug(RIG_DEBUG_ERR, "scanf: %s\n", strerror(errno)); + reading_stdin = 0; + } else { + buffer[0] = c; + buffer[1 == ret ? 1 : MAXARGSZ] = '\0'; + + if (newline) { + putchar('\n'); + } + + fputs(buffer, stdout); + putchar(' '); } } - if (!reading_stdin) - { - if (optind < argc) - { - strncpy (buffer, argv[optind++], MAXARGSZ); - buffer[MAXARGSZ] = '\0'; - ret = 1; + if (!reading_stdin) { + if (optind < argc) { + strncpy(buffer, argv[optind++], MAXARGSZ); + buffer[MAXARGSZ] = '\0'; + ret = 1; + } else { + ret = EOF; } - else ret = EOF; } - return ret; + return ret; } -#define fprintf_flush(f, a...) \ - ({ int __ret; \ - __ret = fprintf((f), a); \ - fflush((f)); \ - __ret; \ - }) + +#define fprintf_flush(f, a...) \ + ({ int __ret; \ + __ret = fprintf((f), a); \ + fflush((f)); \ + __ret; \ + }) + extern int interactive; extern int prompt; @@ -516,1417 +562,1789 @@ extern char send_cmd_term; int ext_resp = 0; unsigned char resp_sep = '\n'; /* Default response separator */ + int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) { - int retcode; /* generic return code from functions */ - unsigned char cmd; - struct test_table *cmd_entry = NULL; + int retcode; /* generic return code from functions */ + unsigned char cmd; + struct test_table *cmd_entry = NULL; - char command[MAXARGSZ+1]; - char arg1[MAXARGSZ+1], *p1 = NULL; - char arg2[MAXARGSZ+1], *p2 = NULL; - char arg3[MAXARGSZ+1], *p3 = NULL; - static int last_was_ret = 1; - vfo_t vfo = RIG_VFO_CURR; + char command[MAXARGSZ + 1]; + char arg1[MAXARGSZ + 1], *p1 = NULL; + char arg2[MAXARGSZ + 1], *p2 = NULL; + char arg3[MAXARGSZ + 1], *p3 = NULL; + static int last_was_ret = 1; + vfo_t vfo = RIG_VFO_CURR; - /* cmd, internal, rigctld */ - if (!(interactive && prompt && have_rl)) { - if (interactive) { - if (prompt) - fprintf_flush(fout, "\nRig command: "); + /* cmd, internal, rigctld */ + if (!(interactive && prompt && have_rl)) { + if (interactive) { + if (prompt) { + fprintf_flush(fout, "\nRig command: "); + } - do { - if (scanfc(fin, "%c", &cmd) < 1) - return -1; + do { + if (scanfc(fin, "%c", &cmd) < 1) { + return -1; + } - /* Extended response protocol requested with leading '+' on command - * string--rigctld only! - */ - if (cmd == '+' && !prompt) { - ext_resp = 1; - if (scanfc(fin, "%c", &cmd) < 1) - return -1; - } else if (cmd == '+' && prompt) { - return 0; - } + /* Extended response protocol requested with leading '+' on command + * string--rigctld only! + */ + if (cmd == '+' && !prompt) { + ext_resp = 1; - if (cmd != '\\' && cmd != '_' && cmd != '#' && ispunct(cmd) && !prompt) { - ext_resp = 1; - resp_sep = cmd; - if (scanfc(fin, "%c", &cmd) < 1) - return -1; - } else if (cmd != '\\' && cmd != '?' && cmd != '_' && cmd != '#' && ispunct(cmd) && prompt) { - return 0; - } + if (scanfc(fin, "%c", &cmd) < 1) { + return -1; + } + } else if (cmd == '+' && prompt) { + return 0; + } - /* command by name */ - if (cmd == '\\') { - unsigned char cmd_name[MAXNAMSIZ], *pcmd = cmd_name; - int c_len = MAXNAMSIZ; + if (cmd != '\\' + && cmd != '_' + && cmd != '#' + && ispunct(cmd) + && !prompt) { - if (scanfc(fin, "%c", pcmd) < 1) - return -1; + ext_resp = 1; + resp_sep = cmd; - while(c_len-- && (isalnum(*pcmd) || *pcmd == '_' )) - if (scanfc(fin, "%c", ++pcmd) < 1) - return -1; + if (scanfc(fin, "%c", &cmd) < 1) { + return -1; + } + } else if (cmd != '\\' + && cmd != '?' + && cmd != '_' + && cmd != '#' + && ispunct(cmd) + && prompt) { - *pcmd = '\0'; - cmd = parse_arg((char *)cmd_name); - break; - } + return 0; + } - if (cmd == 0x0a || cmd == 0x0d) { - if (last_was_ret) { - if (prompt) { - fprintf(fout, "? for help, q to quit.\n"); - fprintf_flush(fout, "\nRig command: "); - } - return 0; - } - last_was_ret = 1; - } - } while (cmd == 0x0a || cmd == 0x0d); + /* command by name */ + if (cmd == '\\') { + unsigned char cmd_name[MAXNAMSIZ], *pcmd = cmd_name; + int c_len = MAXNAMSIZ; - last_was_ret = 0; + if (scanfc(fin, "%c", pcmd) < 1) { + return -1; + } - /* comment line */ - if (cmd == '#') { - while( cmd != '\n' && cmd != '\r') - if (scanfc(fin, "%c", &cmd) < 1) - return -1; - return 0; - } - if (cmd == 'Q' || cmd == 'q') - return 1; - if (cmd == '?') { - usage_rig(fout); - fflush(fout); - return 0; - } - } else { - /* parse rest of command line */ - retcode = next_word (command, argc, argv, 1); - if (EOF == retcode) return 1; - else if (retcode < 0) return retcode; - else if ('\0' == command[1]) { - cmd = command[0]; - } else { - cmd = parse_arg (command); - } - } + while (c_len-- && (isalnum(*pcmd) || *pcmd == '_')) { + if (scanfc(fin, "%c", ++pcmd) < 1) { + return -1; + } + } - cmd_entry = find_cmd_entry(cmd); - if (!cmd_entry) { - fprintf(stderr, "Command '%c' not found!\n", cmd); - return 0; - } + *pcmd = '\0'; + cmd = parse_arg((char *)cmd_name); + break; + } - if (!(cmd_entry->flags & ARG_NOVFO) && vfo_mode) { - if (interactive) { - if (prompt) - fprintf_flush(fout, "VFO: "); - if (scanfc(fin, "%s", arg1) < 1) - return -1; - vfo = rig_parse_vfo(arg1); - } else { - retcode = next_word (arg1, argc, argv, 0); - if (EOF == retcode) { - fprintf(stderr, "Invalid arg for command '%s'\n", - cmd_entry->name); + if (cmd == 0x0a || cmd == 0x0d) { + if (last_was_ret) { + if (prompt) { + fprintf(fout, "? for help, q to quit.\n"); + fprintf_flush(fout, "\nRig command: "); + } + + return 0; + } + + last_was_ret = 1; + } + } while (cmd == 0x0a || cmd == 0x0d); + + last_was_ret = 0; + + /* comment line */ + if (cmd == '#') { + while (cmd != '\n' && cmd != '\r') { + if (scanfc(fin, "%c", &cmd) < 1) { + return -1; + } + } + + return 0; + } + + if (cmd == 'Q' || cmd == 'q') { + return 1; + } + + if (cmd == '?') { + usage_rig(fout); + fflush(fout); + return 0; + } + } else { + /* parse rest of command line */ + retcode = next_word(command, argc, argv, 1); + + if (EOF == retcode) { + return 1; + } else if (retcode < 0) { + return retcode; + } else if ('\0' == command[1]) { + cmd = command[0]; + } else { + cmd = parse_arg(command); + } } - else if (retcode < 0) return retcode; - vfo = rig_parse_vfo(arg1); - } - } - if ((cmd_entry->flags & ARG_IN_LINE) && - (cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { - if (interactive) { - char *nl; - if (prompt) - fprintf_flush(fout, "%s: ", cmd_entry->arg1); - if (fgets(arg1, MAXARGSZ, fin) == NULL) - return -1; - if (arg1[0] == 0xa) - if (fgets(arg1, MAXARGSZ, fin) == NULL) - return -1; - nl = strchr(arg1, 0xa); - if (nl) *nl = '\0'; /* chomp */ - p1 = arg1[0] == ' ' ? arg1 + 1 : arg1; - } else { - retcode = next_word (arg1, argc, argv, 0); - if (EOF == retcode) { - fprintf(stderr, "Invalid arg for command '%s'\n", - cmd_entry->name); - return 1; + cmd_entry = find_cmd_entry(cmd); + + if (!cmd_entry) { + fprintf(stderr, "Command '%c' not found!\n", cmd); + return 0; } - else if (retcode < 0) return retcode; - p1 = arg1; - } - } else - if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { - if (interactive) { - if (prompt) - fprintf_flush(fout, "%s: ", cmd_entry->arg1); - if (scanfc(fin, "%s", arg1) < 1) - return -1; - p1 = arg1; - } else { - retcode = next_word (arg1, argc, argv, 0); - if (EOF == retcode) { - fprintf(stderr, "Invalid arg for command '%s'\n", - cmd_entry->name); - return 1; + + if (!(cmd_entry->flags & ARG_NOVFO) && vfo_mode) { + if (interactive) { + if (prompt) { + fprintf_flush(fout, "VFO: "); + } + + if (scanfc(fin, "%s", arg1) < 1) { + return -1; + } + + vfo = rig_parse_vfo(arg1); + } else { + retcode = next_word(arg1, argc, argv, 0); + + if (EOF == retcode) { + fprintf(stderr, "Invalid arg for command '%s'\n", + cmd_entry->name); + } else if (retcode < 0) { + return retcode; + } + + vfo = rig_parse_vfo(arg1); + } } - else if (retcode < 0) return retcode; - p1 = arg1; - } - } - if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN2) && cmd_entry->arg2) { - if (interactive) { - if (prompt) - fprintf_flush(fout, "%s: ", cmd_entry->arg2); - if (scanfc(fin, "%s", arg2) < 1) - return -1; - p2 = arg2; - } else { - retcode = next_word (arg2, argc, argv, 0); - if (EOF == retcode) { - fprintf(stderr, "Invalid arg for command '%s'\n", - cmd_entry->name); - return 1; + + if ((cmd_entry->flags & ARG_IN_LINE) + && (cmd_entry->flags & ARG_IN1) + && cmd_entry->arg1) { + + if (interactive) { + char *nl; + + if (prompt) { + fprintf_flush(fout, "%s: ", cmd_entry->arg1); + } + + if (fgets(arg1, MAXARGSZ, fin) == NULL) { + return -1; + } + + if (arg1[0] == 0xa) { + if (fgets(arg1, MAXARGSZ, fin) == NULL) { + return -1; + } + } + + nl = strchr(arg1, 0xa); + + if (nl) { + *nl = '\0'; /* chomp */ + } + + p1 = arg1[0] == ' ' ? arg1 + 1 : arg1; + } else { + retcode = next_word(arg1, argc, argv, 0); + + if (EOF == retcode) { + fprintf(stderr, "Invalid arg for command '%s'\n", + cmd_entry->name); + return 1; + } else if (retcode < 0) { + return retcode; + } + + p1 = arg1; + } + } else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { + if (interactive) { + if (prompt) { + fprintf_flush(fout, "%s: ", cmd_entry->arg1); + } + + if (scanfc(fin, "%s", arg1) < 1) { + return -1; + } + + p1 = arg1; + } else { + retcode = next_word(arg1, argc, argv, 0); + + if (EOF == retcode) { + fprintf(stderr, "Invalid arg for command '%s'\n", + cmd_entry->name); + return 1; + } else if (retcode < 0) { + return retcode; + } + + p1 = arg1; + } } - else if (retcode < 0) return retcode; - p2 = arg2; - } - } - if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN3) && cmd_entry->arg3) { - if (interactive) { - if (prompt) - fprintf_flush(fout, "%s: ", cmd_entry->arg3); - if (scanfc(fin, "%s", arg3) < 1) - return -1; - p3 = arg3; - } else { - retcode = next_word (arg3, argc, argv, 0); - if (EOF == retcode) { - fprintf(stderr, "Invalid arg for command '%s'\n", - cmd_entry->name); - return 1; + + if (p1 + && p1[0] != '?' + && (cmd_entry->flags & ARG_IN2) + && cmd_entry->arg2) { + + if (interactive) { + if (prompt) { + fprintf_flush(fout, "%s: ", cmd_entry->arg2); + } + + if (scanfc(fin, "%s", arg2) < 1) { + return -1; + } + + p2 = arg2; + } else { + retcode = next_word(arg2, argc, argv, 0); + + if (EOF == retcode) { + fprintf(stderr, "Invalid arg for command '%s'\n", + cmd_entry->name); + return 1; + } else if (retcode < 0) { + return retcode; + } + + p2 = arg2; + } } - else if (retcode < 0) return retcode; - p3 = arg3; - } - } - } + + if (p1 + && p1[0] != '?' + && (cmd_entry->flags & ARG_IN3) + && cmd_entry->arg3) { + + if (interactive) { + if (prompt) { + fprintf_flush(fout, "%s: ", cmd_entry->arg3); + } + + if (scanfc(fin, "%s", arg3) < 1) { + return -1; + } + + p3 = arg3; + } else { + retcode = next_word(arg3, argc, argv, 0); + + if (EOF == retcode) { + fprintf(stderr, "Invalid arg for command '%s'\n", + cmd_entry->name); + return 1; + } else if (retcode < 0) { + return retcode; + } + + p3 = arg3; + } + } + } #ifdef HAVE_LIBREADLINE - if (interactive && prompt && have_rl) { - int j, x; + if (interactive && prompt && have_rl) { + int j, x; #ifdef HAVE_READLINE_HISTORY - /* Minimum space for 32+1+32+1+128+1+128+1+128+1 = 453 chars, so - * allocate 512 chars cleared to zero for safety. - */ - rp_hist_buf = (char *)calloc(512, sizeof(char)); + /* Minimum space for 32+1+32+1+128+1+128+1+128+1 = 453 chars, so + * allocate 512 chars cleared to zero for safety. + */ + rp_hist_buf = (char *)calloc(512, sizeof(char)); #endif - rl_instream = fin; - rl_outstream = fout; + rl_instream = fin; + rl_outstream = fout; - rp_getline("\nRig command: "); + rp_getline("\nRig command: "); - /* EOF (Ctl-D) received on empty input line, bail out gracefully. */ - if (!input_line) { - fprintf_flush(fout, "\n"); - return 1; - } + /* EOF (Ctl-D) received on empty input line, bail out gracefully. */ + if (!input_line) { + fprintf_flush(fout, "\n"); + return 1; + } - /* Q or q to quit */ - if (!(strncasecmp(input_line, "q", 1))) - return 1; + /* Q or q to quit */ + if (!(strncasecmp(input_line, "q", 1))) { + return 1; + } - /* '?' for help */ - if (!(strncmp(input_line, "?", 1))) { - usage_rig(fout); - fflush(fout); - return 0; - } + /* '?' for help */ + if (!(strncmp(input_line, "?", 1))) { + usage_rig(fout); + fflush(fout); + return 0; + } - /* '#' for comment */ - if (!(strncmp(input_line, "#", 1))) - return 0; + /* '#' for comment */ + if (!(strncmp(input_line, "#", 1))) { + return 0; + } - /* Blank line entered */ - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + /* Blank line entered */ + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } - rig_debug(RIG_DEBUG_BUG, "%s: input_line: %s\n", __func__, input_line); + rig_debug(RIG_DEBUG_BUG, "%s: input_line: %s\n", __func__, input_line); - /* Split input_line on any number of spaces to get the command token - * Tabs are intercepted by readline for completion and a newline - * causes readline to return the typed text. If more than one - * argument is given, it will be parsed out later. - */ - result = strtok(input_line, " "); + /* Split input_line on any number of spaces to get the command token + * Tabs are intercepted by readline for completion and a newline + * causes readline to return the typed text. If more than one + * argument is given, it will be parsed out later. + */ + result = strtok(input_line, " "); - /* parsed_input stores pointers into input_line where the token strings - * start. - */ - if (result) { - parsed_input[0] = result; - } else { - /* Oops! Invoke GDB!! */ - fprintf_flush(fout, "\n"); - return 1; - } + /* parsed_input stores pointers into input_line where the token strings + * start. + */ + if (result) { + parsed_input[0] = result; + } else { + /* Oops! Invoke GDB!! */ + fprintf_flush(fout, "\n"); + return 1; + } - /* At this point parsed_input contains the typed text of the command - * with surrounding space characters removed. If Readline History is - * available, copy the command string into a history buffer. - */ + /* At this point parsed_input contains the typed text of the command + * with surrounding space characters removed. If Readline History is + * available, copy the command string into a history buffer. + */ - /* Single character command */ - if ((strlen(parsed_input[0]) == 1) && (*parsed_input[0] != '\\')) { - cmd = *parsed_input[0]; + /* Single character command */ + if ((strlen(parsed_input[0]) == 1) && (*parsed_input[0] != '\\')) { + cmd = *parsed_input[0]; #ifdef HAVE_READLINE_HISTORY - /* Store what is typed, not validated, for history. */ - if (rp_hist_buf) - strncpy(rp_hist_buf, parsed_input[0], 1); -#endif - } - /* Test the command token, parsed_input[0] */ - else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) > 1)) { - char cmd_name[MAXNAMSIZ]; - /* if there is no terminating '\0' character in the source string, - * srncpy() doesn't add one even if the supplied length is less - * than the destination array. Truncate the source string here. - */ - if (strlen(parsed_input[0] + 1) >= MAXNAMSIZ) - *(parsed_input[0] + MAXNAMSIZ) = '\0'; + /* Store what is typed, not validated, for history. */ + if (rp_hist_buf) { + strncpy(rp_hist_buf, parsed_input[0], 1); + } + +#endif + } + /* Test the command token, parsed_input[0] */ + else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) > 1)) { + char cmd_name[MAXNAMSIZ]; + + /* if there is no terminating '\0' character in the source string, + * srncpy() doesn't add one even if the supplied length is less + * than the destination array. Truncate the source string here. + */ + if (strlen(parsed_input[0] + 1) >= MAXNAMSIZ) { + *(parsed_input[0] + MAXNAMSIZ) = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) - strncpy(rp_hist_buf, parsed_input[0], MAXNAMSIZ); + + if (rp_hist_buf) { + strncpy(rp_hist_buf, parsed_input[0], MAXNAMSIZ); + } + #endif - /* The starting position of the source string is the first - * character past the initial '\'. Using MAXNAMSIZ for the - * length leaves enough space for the '\0' string terminator in the - * cmd_name array. - */ - strncpy(cmd_name, parsed_input[0] + 1, MAXNAMSIZ); + /* The starting position of the source string is the first + * character past the initial '\'. Using MAXNAMSIZ for the + * length leaves enough space for the '\0' string terminator in the + * cmd_name array. + */ + strncpy(cmd_name, parsed_input[0] + 1, MAXNAMSIZ); - /* Sanity check as valid multiple character commands consist of - * alpha-numeric characters and the underscore ('_') character. - */ - for (j = 0; cmd_name[j] != '\0'; j++) { - if (!(isalnum((int)cmd_name[j]) || cmd_name[j] == '_')) { - fprintf(stderr, "Valid multiple character command names contain alpha-numeric characters plus '_'\n"); - return 0; - } - } + /* Sanity check as valid multiple character commands consist of + * alpha-numeric characters and the underscore ('_') character. + */ + for (j = 0; cmd_name[j] != '\0'; j++) { + if (!(isalnum((int)cmd_name[j]) || cmd_name[j] == '_')) { + fprintf(stderr, + "Valid multiple character command names contain alpha-numeric characters plus '_'\n"); + return 0; + } + } - cmd = parse_arg(cmd_name); - } - /* Single '\' entered, prompt again */ - else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) == 1)) { - return 0; - } - /* Multiple characters but no leading '\' */ - else { - fprintf(stderr, "Precede multiple character command names with '\\'\n"); - return 0; - } + cmd = parse_arg(cmd_name); + } + /* Single '\' entered, prompt again */ + else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) == 1)) { + return 0; + } + /* Multiple characters but no leading '\' */ + else { + fprintf(stderr, "Precede multiple character command names with '\\'\n"); + return 0; + } - cmd_entry = find_cmd_entry(cmd); - if (!cmd_entry) { - if (cmd == '\0') - fprintf(stderr, "Command '%s' not found!\n", parsed_input[0]); - else - fprintf(stderr, "Command '%c' not found!\n", cmd); + cmd_entry = find_cmd_entry(cmd); - return 0; - } + if (!cmd_entry) { + if (cmd == '\0') { + fprintf(stderr, "Command '%s' not found!\n", parsed_input[0]); + } else { + fprintf(stderr, "Command '%c' not found!\n", cmd); + } - /* If vfo_mode is enabled (-o|--vfo) check if already given - * or prompt for it. - */ - if (!(cmd_entry->flags & ARG_NOVFO) && vfo_mode) { - /* Check if VFO was given with command. */ - result = strtok(NULL, " "); + return 0; + } - if (result) { - x = 1; - parsed_input[x] = result; - } - /* Need to prompt if a VFO string was not given. */ - else { - x = 0; - rp_getline("VFO: "); + /* If vfo_mode is enabled (-o|--vfo) check if already given + * or prompt for it. + */ + if (!(cmd_entry->flags & ARG_NOVFO) && vfo_mode) { + /* Check if VFO was given with command. */ + result = strtok(NULL, " "); - if (!input_line) { - fprintf_flush(fout, "\n"); - return 1; - } + if (result) { + x = 1; + parsed_input[x] = result; + } + /* Need to prompt if a VFO string was not given. */ + else { + x = 0; + rp_getline("VFO: "); - /* Blank line entered */ - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + if (!input_line) { + fprintf_flush(fout, "\n"); + return 1; + } - /* Get the first token of input, the rest, if any, will be - * used later. - */ - result = strtok(input_line, " "); + /* Blank line entered */ + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } - if (result) { - parsed_input[x] = result; - } else { - fprintf_flush(fout, "\n"); - return 1; - } - } + /* Get the first token of input, the rest, if any, will be + * used later. + */ + result = strtok(input_line, " "); - /* VFO name tokens are presently quite short. Truncate excessively - * long strings. - */ - if (strlen(parsed_input[x]) >= MAXNAMSIZ) - *(parsed_input[x] + (MAXNAMSIZ - 1)) = '\0'; + if (result) { + parsed_input[x] = result; + } else { + fprintf_flush(fout, "\n"); + return 1; + } + } + + /* VFO name tokens are presently quite short. Truncate excessively + * long strings. + */ + if (strlen(parsed_input[x]) >= MAXNAMSIZ) { + *(parsed_input[x] + (MAXNAMSIZ - 1)) = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); - strncat(rp_hist_buf, parsed_input[x], MAXNAMSIZ); - } + + if (rp_hist_buf) { + strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, parsed_input[x], MAXNAMSIZ); + } + #endif - /* Sanity check, VFO names are alpha only. */ - for (j = 0; j < MAXNAMSIZ && parsed_input[x][j] != '\0'; j++) { - if (!(isalpha((int)parsed_input[x][j]))) { - parsed_input[x][j] = '\0'; - break; - } - } - vfo = rig_parse_vfo(parsed_input[x]); + /* Sanity check, VFO names are alpha only. */ + for (j = 0; j < MAXNAMSIZ && parsed_input[x][j] != '\0'; j++) { + if (!(isalpha((int)parsed_input[x][j]))) { + parsed_input[x][j] = '\0'; - if (vfo == RIG_VFO_NONE) { - fprintf(stderr, "Warning: VFO '%s' unrecognized, using 'currVFO' instead.\n", - parsed_input[x]); - vfo = RIG_VFO_CURR; - } - } + break; + } + } - /* \send_cmd, \send_morse */ - if ((cmd_entry->flags & ARG_IN_LINE) && - (cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { - /* Check for a non-existent delimiter so as to not break up - * remaining line into separate tokens (spaces OK). - */ - result = strtok(NULL, "\0"); + vfo = rig_parse_vfo(parsed_input[x]); - if (vfo_mode && result) { - x = 2; - parsed_input[x] = result; - } else if (result) { - x = 1; - parsed_input[x] = result; - } else { - x = 0; - char pmptstr[(strlen(cmd_entry->arg1) + 3)]; + if (vfo == RIG_VFO_NONE) { + fprintf(stderr, + "Warning: VFO '%s' unrecognized, using 'currVFO' instead.\n", + parsed_input[x]); + vfo = RIG_VFO_CURR; + } + } - strcpy(pmptstr, cmd_entry->arg1); - strcat(pmptstr, ": "); + /* \send_cmd, \send_morse */ + if ((cmd_entry->flags & ARG_IN_LINE) + && (cmd_entry->flags & ARG_IN1) + && cmd_entry->arg1) { + /* Check for a non-existent delimiter so as to not break up + * remaining line into separate tokens (spaces OK). + */ + result = strtok(NULL, "\0"); - rp_getline(pmptstr); + if (vfo_mode && result) { + x = 2; + parsed_input[x] = result; + } else if (result) { + x = 1; + parsed_input[x] = result; + } else { + x = 0; + char pmptstr[(strlen(cmd_entry->arg1) + 3)]; - /* Blank line entered */ - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + strcpy(pmptstr, cmd_entry->arg1); + strcat(pmptstr, ": "); - if (input_line) - parsed_input[x] = input_line; - else { - fprintf_flush(fout, "\n"); - return 1; - } - } + rp_getline(pmptstr); - /* The arg1 array size is MAXARGSZ + 1 so truncate it to fit if larger. */ - if (strlen(parsed_input[x]) > MAXARGSZ) - parsed_input[x][MAXARGSZ] = '\0'; + /* Blank line entered */ + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } + + if (input_line) { + parsed_input[x] = input_line; + } else { + fprintf_flush(fout, "\n"); + return 1; + } + } + + /* The arg1 array size is MAXARGSZ + 1 so truncate it to fit if larger. */ + if (strlen(parsed_input[x]) > MAXARGSZ) { + parsed_input[x][MAXARGSZ] = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); - strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); - } + + if (rp_hist_buf) { + strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); + } + #endif - strcpy(arg1, parsed_input[x]); - p1 = arg1; - } + strcpy(arg1, parsed_input[x]); + p1 = arg1; + } - /* Normal argument parsing. */ - else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { - result = strtok(NULL, " "); + /* Normal argument parsing. */ + else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { + result = strtok(NULL, " "); - if (vfo_mode && result) { - x = 2; - parsed_input[x] = result; - } else if (result) { - x = 1; - parsed_input[x] = result; - } else { - x = 0; - char pmptstr[(strlen(cmd_entry->arg1) + 3)]; + if (vfo_mode && result) { + x = 2; + parsed_input[x] = result; + } else if (result) { + x = 1; + parsed_input[x] = result; + } else { + x = 0; + char pmptstr[(strlen(cmd_entry->arg1) + 3)]; - strcpy(pmptstr, cmd_entry->arg1); - strcat(pmptstr, ": "); + strcpy(pmptstr, cmd_entry->arg1); + strcat(pmptstr, ": "); - rp_getline(pmptstr); + rp_getline(pmptstr); - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } - result = strtok(input_line, " "); + result = strtok(input_line, " "); - if (result) { - parsed_input[x] = result; - } else { - fprintf_flush(fout, "\n"); - return 1; - } - } + if (result) { + parsed_input[x] = result; + } else { + fprintf_flush(fout, "\n"); + return 1; + } + } - if (strlen(parsed_input[x]) > MAXARGSZ) - parsed_input[x][MAXARGSZ] = '\0'; + if (strlen(parsed_input[x]) > MAXARGSZ) { + parsed_input[x][MAXARGSZ] = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); - strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); - } + + if (rp_hist_buf) { + strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); + } + #endif - strcpy(arg1, parsed_input[x]); - p1 = arg1; - } - if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN2) && cmd_entry->arg2) { - result = strtok(NULL, " "); + strcpy(arg1, parsed_input[x]); + p1 = arg1; + } - if (vfo_mode && result) { - x = 3; - parsed_input[x] = result; - } else if (result) { - x = 2; - parsed_input[x] = result; - } else { - x = 0; - char pmptstr[(strlen(cmd_entry->arg2) + 3)]; + if (p1 + && p1[0] != '?' + && (cmd_entry->flags & ARG_IN2) + && cmd_entry->arg2) { - strcpy(pmptstr, cmd_entry->arg2); - strcat(pmptstr, ": "); + result = strtok(NULL, " "); - rp_getline(pmptstr); + if (vfo_mode && result) { + x = 3; + parsed_input[x] = result; + } else if (result) { + x = 2; + parsed_input[x] = result; + } else { + x = 0; + char pmptstr[(strlen(cmd_entry->arg2) + 3)]; - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + strcpy(pmptstr, cmd_entry->arg2); + strcat(pmptstr, ": "); - result = strtok(input_line, " "); + rp_getline(pmptstr); - if (result) { - parsed_input[x] = result; - } else { - fprintf_flush(fout, "\n"); - return 1; - } - } + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } - if (strlen(parsed_input[x]) > MAXARGSZ) - parsed_input[x][MAXARGSZ] = '\0'; + result = strtok(input_line, " "); + + if (result) { + parsed_input[x] = result; + } else { + fprintf_flush(fout, "\n"); + return 1; + } + } + + if (strlen(parsed_input[x]) > MAXARGSZ) { + parsed_input[x][MAXARGSZ] = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); - strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); - } + + if (rp_hist_buf) { + strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); + } + #endif - strcpy(arg2, parsed_input[x]); - p2 = arg2; - } - if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN3) && cmd_entry->arg3) { - result = strtok(NULL, " "); + strcpy(arg2, parsed_input[x]); + p2 = arg2; + } - if (vfo_mode && result) { - x = 4; - parsed_input[x] = result; - } else if (result) { - x = 3; - parsed_input[x] = result; - } else { - x = 0; - char pmptstr[(strlen(cmd_entry->arg3) + 3)]; + if (p1 + && p1[0] != '?' + && (cmd_entry->flags & ARG_IN3) + && cmd_entry->arg3) { - strcpy(pmptstr, cmd_entry->arg3); - strcat(pmptstr, ": "); + result = strtok(NULL, " "); - rp_getline(pmptstr); + if (vfo_mode && result) { + x = 4; + parsed_input[x] = result; + } else if (result) { + x = 3; + parsed_input[x] = result; + } else { + x = 0; + char pmptstr[(strlen(cmd_entry->arg3) + 3)]; - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + strcpy(pmptstr, cmd_entry->arg3); + strcat(pmptstr, ": "); - result = strtok(input_line, " "); + rp_getline(pmptstr); - if (result) { - parsed_input[x] = result; - } else { - fprintf_flush(fout, "\n"); - return 1; - } - } + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } - if (strlen(parsed_input[x]) > MAXARGSZ) - parsed_input[x][MAXARGSZ] = '\0'; + result = strtok(input_line, " "); + + if (result) { + parsed_input[x] = result; + } else { + fprintf_flush(fout, "\n"); + return 1; + } + } + + if (strlen(parsed_input[x]) > MAXARGSZ) { + parsed_input[x][MAXARGSZ] = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); - strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); - } + + if (rp_hist_buf) { + strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); + } + #endif - strcpy(arg3, parsed_input[x]); - p3 = arg3; - } + strcpy(arg3, parsed_input[x]); + p3 = arg3; + } + #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - add_history(rp_hist_buf); - free(rp_hist_buf); - rp_hist_buf = (char *)NULL; - } + + if (rp_hist_buf) { + add_history(rp_hist_buf); + free(rp_hist_buf); + rp_hist_buf = (char *)NULL; + } + #endif - } + } -#endif /* HAVE_LIBREADLINE */ +#endif /* HAVE_LIBREADLINE */ - /* - * mutex locking needed because rigctld is multithreaded - * and hamlib is not MT-safe - */ + /* + * mutex locking needed because rigctld is multithreaded + * and hamlib is not MT-safe + */ #ifdef HAVE_PTHREAD - pthread_mutex_lock(&rig_mutex); + pthread_mutex_lock(&rig_mutex); #endif - if (!prompt) - rig_debug(RIG_DEBUG_TRACE, "rigctl(d): %c '%s' '%s' '%s' '%s'\n", - cmd, rig_strvfo(vfo), p1?p1:"", p2?p2:"", p3?p3:""); + if (!prompt) { + rig_debug(RIG_DEBUG_TRACE, + "rigctl(d): %c '%s' '%s' '%s' '%s'\n", + cmd, + rig_strvfo(vfo), + p1 ? p1 : "", + p2 ? p2 : "", + p3 ? p3 : ""); + } - /* - * Extended Response protocol: output received command name and arguments - * response. Don't send command header on '\chk_vfo' command. - */ - if (interactive && ext_resp && !prompt && cmd != 0xf0) { - char a1[MAXARGSZ + 1]; - char a2[MAXARGSZ + 1]; - char a3[MAXARGSZ + 1]; - char vfo_str[MAXARGSZ + 1]; + /* + * Extended Response protocol: output received command name and arguments + * response. Don't send command header on '\chk_vfo' command. + */ + if (interactive && ext_resp && !prompt && cmd != 0xf0) { + char a1[MAXARGSZ + 1]; + char a2[MAXARGSZ + 1]; + char a3[MAXARGSZ + 1]; + char vfo_str[MAXARGSZ + 1]; - vfo_mode == 0 ? vfo_str[0] = '\0' : snprintf(vfo_str, sizeof(vfo_str), " %s", rig_strvfo(vfo)); - p1 == NULL ? a1[0] = '\0' : snprintf(a1, sizeof(a1), " %s", p1); - p2 == NULL ? a2[0] = '\0' : snprintf(a2, sizeof(a2), " %s", p2); - p3 == NULL ? a3[0] = '\0' : snprintf(a3, sizeof(a3), " %s", p3); + vfo_mode == 0 ? vfo_str[0] = '\0' : snprintf(vfo_str, + sizeof(vfo_str), + " %s", + rig_strvfo(vfo)); - fprintf(fout, "%s:%s%s%s%s%c", cmd_entry->name, vfo_str, a1, a2, a3, resp_sep); - } + p1 == NULL ? a1[0] = '\0' : snprintf(a1, sizeof(a1), " %s", p1); + p2 == NULL ? a2[0] = '\0' : snprintf(a2, sizeof(a2), " %s", p2); + p3 == NULL ? a3[0] = '\0' : snprintf(a3, sizeof(a3), " %s", p3); - retcode = (*cmd_entry->rig_routine)(my_rig, fout, fin, interactive, - cmd_entry, vfo, p1, p2 ? p2 : "", p3 ? p3 : ""); + fprintf(fout, + "%s:%s%s%s%s%c", + cmd_entry->name, + vfo_str, + a1, + a2, + a3, + resp_sep); + } + + retcode = (*cmd_entry->rig_routine)(my_rig, + fout, + fin, + interactive, + cmd_entry, + vfo, + p1, + p2 ? p2 : "", + p3 ? p3 : ""); #ifdef HAVE_PTHREAD - pthread_mutex_unlock(&rig_mutex); + pthread_mutex_unlock(&rig_mutex); #endif - if (retcode != RIG_OK) { - /* only for rigctld */ - if (interactive && !prompt) { - fprintf(fout, NETRIGCTL_RET "%d\n", retcode); - ext_resp = 0; - resp_sep = '\n'; - } - else - fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode)); - } else { - /* only for rigctld */ - if (interactive && !prompt) { - /* netrigctl RIG_OK */ - if (!(cmd_entry->flags & ARG_OUT) - && !ext_resp && cmd != 0xf0) - fprintf(fout, NETRIGCTL_RET "0\n"); + if (retcode != RIG_OK) { + /* only for rigctld */ + if (interactive && !prompt) { + fprintf(fout, NETRIGCTL_RET "%d\n", retcode); + ext_resp = 0; + resp_sep = '\n'; + } else { + fprintf(fout, + "%s: error = %s\n", + cmd_entry->name, + rigerror(retcode)); + } + } else { + /* only for rigctld */ + if (interactive && !prompt) { + /* netrigctl RIG_OK */ + if (!(cmd_entry->flags & ARG_OUT) + && !ext_resp && cmd != 0xf0) { + fprintf(fout, NETRIGCTL_RET "0\n"); + } - /* Extended Response protocol */ - else if (ext_resp && cmd != 0xf0) { - fprintf(fout, NETRIGCTL_RET "0\n"); - ext_resp = 0; - resp_sep = '\n'; - } - } - } + /* Extended Response protocol */ + else if (ext_resp && cmd != 0xf0) { + fprintf(fout, NETRIGCTL_RET "0\n"); + ext_resp = 0; + resp_sep = '\n'; + } + } + } - fflush(fout); - if (retcode == -RIG_ENAVAIL) return retcode; - return retcode != RIG_OK ? 2 : 0; + fflush(fout); + + if (retcode == -RIG_ENAVAIL) { + return retcode; + } + + return retcode != RIG_OK ? 2 : 0; } void version() { - printf("rigctl, %s\n\n", hamlib_version); - printf("%s\n", hamlib_copyright); + printf("rigctl(d), %s\n\n", hamlib_version); + printf("%s\n", hamlib_copyright); } + void usage_rig(FILE *fout) { - int i, nbspaces; + int i, nbspaces; - fprintf(fout, "Commands (some may not be available for this rig):\n"); - for (i = 0; test_list[i].cmd != 0; i++) { - fprintf(fout, "%c: %-16s(", isprint(test_list[i].cmd) ? - test_list[i].cmd:'?', test_list[i].name); + fprintf(fout, "Commands (some may not be available for this rig):\n"); - nbspaces = 18; - if (test_list[i].arg1 && (test_list[i].flags&ARG_IN1)) - nbspaces -= fprintf(fout, "%s", test_list[i].arg1); - if (test_list[i].arg2 && (test_list[i].flags&ARG_IN2)) - nbspaces -= fprintf(fout, ",%s", test_list[i].arg2); - if (test_list[i].arg3 && (test_list[i].flags&ARG_IN3)) - nbspaces -= fprintf(fout, ",%s", test_list[i].arg3); + for (i = 0; test_list[i].cmd != 0; i++) { + fprintf(fout, + "%c: %-16s(", + isprint(test_list[i].cmd) ? test_list[i].cmd : '?', + test_list[i].name); - if (i % 2) - fprintf(fout, ")\n"); - else - fprintf(fout, ")%*s", nbspaces, " "); - } + nbspaces = 18; - fprintf(fout, "\n\nIn interactive mode prefix long command names with '\\', e.g. '\\dump_state'\n\n" - "The special command '-' is used to read further commands from standard input\n" - "Commands and arguments read from standard input must be white space separated,\n" - "comments are allowed, comments start with the # character and continue to the\n" - "end of the line.\n"); + if (test_list[i].arg1 && (test_list[i].flags & ARG_IN1)) { + nbspaces -= fprintf(fout, "%s", test_list[i].arg1); + } + + if (test_list[i].arg2 && (test_list[i].flags & ARG_IN2)) { + nbspaces -= fprintf(fout, ",%s", test_list[i].arg2); + } + + if (test_list[i].arg3 && (test_list[i].flags & ARG_IN3)) { + nbspaces -= fprintf(fout, ",%s", test_list[i].arg3); + } + + if (i % 2) { + fprintf(fout, ")\n"); + } else { + fprintf(fout, ")%*s", nbspaces, " "); + } + } + + fprintf(fout, + "\n\nIn interactive mode prefix long command names with '\\', e.g. '\\dump_state'\n\n" + "The special command '-' is used to read further commands from standard input\n" + "Commands and arguments read from standard input must be white space separated,\n" + "comments are allowed, comments start with the # character and continue to the\n" + "end of the line.\n"); } int print_conf_list(const struct confparams *cfp, rig_ptr_t data) { - RIG *rig = (RIG*) data; - int i; - char buf[128] = ""; + RIG *rig = (RIG *) data; + int i; + char buf[128] = ""; - rig_get_conf(rig, cfp->token, buf); - printf("%s: \"%s\"\n" "\t" - "Default: %s, Value: %s\n", - cfp->name, cfp->tooltip, - cfp->dflt, buf ); + rig_get_conf(rig, cfp->token, buf); + printf("%s: \"%s\"\n" "\t" "Default: %s, Value: %s\n", + cfp->name, + cfp->tooltip, + cfp->dflt, + buf); - switch (cfp->type) { - case RIG_CONF_NUMERIC: - printf("\tRange: %.1f..%.1f, step %.1f\n", - cfp->u.n.min, cfp->u.n.max, cfp->u.n.step); - break; - case RIG_CONF_COMBO: - if (!cfp->u.c.combostr[0]) - break; - printf("\tCombo: %s", cfp->u.c.combostr[0]); - for (i=1 ; iu.c.combostr[i]; i++) - printf(", %s", cfp->u.c.combostr[i]); - printf("\n"); - break; - case RIG_CONF_STRING: - printf("\tString.\n"); - break; - case RIG_CONF_CHECKBUTTON: - printf("\tCheck button.\n"); - break; - case RIG_CONF_BUTTON: - printf("\tButton.\n"); - break; - default: - printf("\tUnknown conf\n"); - } + switch (cfp->type) { + case RIG_CONF_NUMERIC: + printf("\tRange: %.1f..%.1f, step %.1f\n", + cfp->u.n.min, + cfp->u.n.max, + cfp->u.n.step); + break; - return 1; /* !=0, we want them all ! */ + case RIG_CONF_COMBO: + if (!cfp->u.c.combostr[0]) { + break; + } + + printf("\tCombo: %s", cfp->u.c.combostr[0]); + + for (i = 1 ; i < RIG_COMBO_MAX && cfp->u.c.combostr[i]; i++) { + printf(", %s", cfp->u.c.combostr[i]); + } + + printf("\n"); + break; + + case RIG_CONF_STRING: + printf("\tString.\n"); + break; + + case RIG_CONF_CHECKBUTTON: + printf("\tCheck button.\n"); + break; + + case RIG_CONF_BUTTON: + printf("\tButton.\n"); + break; + + default: + printf("\tUnknown conf\n"); + } + + return 1; /* !=0, we want them all ! */ } + static int hash_model_list(const struct rig_caps *caps, void *data) { + hash_add_model(caps->rig_model, + caps->mfg_name, + caps->model_name, + caps->version, + rig_strstatus(caps->status)); - hash_add_model(caps->rig_model, caps->mfg_name, caps->model_name, - caps->version, rig_strstatus(caps->status)); - return 1; /* !=0, we want them all ! */ + return 1; /* !=0, we want them all ! */ } + void print_model_list() { - struct mod_lst *s; + struct mod_lst *s; - for (s = models; s != NULL; s = (struct mod_lst *)(s->hh.next)) { - printf("%6d %-23s%-24s%-16s%s\n", s->id, s->mfg_name, - s->model_name, s->version, s->status); - } + for (s = models; s != NULL; s = (struct mod_lst *)(s->hh.next)) { + printf("%6d %-23s%-24s%-16s%s\n", + s->id, + s->mfg_name, + s->model_name, + s->version, + s->status); + } } + void list_models() { - int status; + int status; - rig_load_all_backends(); + rig_load_all_backends(); - printf(" Rig # Mfg Model Version Status\n"); - status = rig_list_foreach(hash_model_list, NULL); - if (status != RIG_OK ) { - printf("rig_list_foreach: error = %s \n", rigerror(status)); - exit(2); - } + printf(" Rig # Mfg Model Version Status\n"); + status = rig_list_foreach(hash_model_list, NULL); - hash_sort_by_model_id(); - print_model_list(); - hash_delete_all(); + if (status != RIG_OK) { + printf("rig_list_foreach: error = %s \n", rigerror(status)); + exit(2); + } + + hash_sort_by_model_id(); + print_model_list(); + hash_delete_all(); } int set_conf(RIG *my_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(my_rig, rig_token_lookup(my_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(my_rig, rig_token_lookup(my_rig, p), q); + + if (ret != RIG_OK) { + return ret; + } + + p = n; + } + + return RIG_OK; } /* * static int (f)(RIG *rig, FILE *fout, int interactive, const struct test_table *cmd, - * vfo_t vfo, const void *arg1, const void *arg2, const void *arg3) + * vfo_t vfo, const void *arg1, const void *arg2, const void *arg3) */ /* 'F' */ declare_proto_rig(set_freq) { - freq_t freq; + freq_t freq; - CHKSCN1ARG(sscanf(arg1, "%"SCNfreq, &freq)); - return rig_set_freq(rig, vfo, freq); + CHKSCN1ARG(sscanf(arg1, "%"SCNfreq, &freq)); + return rig_set_freq(rig, vfo, freq); } + /* 'f' */ declare_proto_rig(get_freq) { - int status; - freq_t freq; + int status; + freq_t freq; - status = rig_get_freq(rig, vfo, &freq); - if (status != RIG_OK) - return status; + status = rig_get_freq(rig, vfo, &freq); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); /* i.e. "Frequency" */ - fprintf(fout, "%"PRIll"%c", (int64_t)freq, resp_sep); + if (status != RIG_OK) { + return status; + } - return status; + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); /* i.e. "Frequency" */ + } + + fprintf(fout, "%"PRIll"%c", (int64_t)freq, resp_sep); + + return status; } + /* 'J' */ declare_proto_rig(set_rit) { - shortfreq_t rit; + shortfreq_t rit; - CHKSCN1ARG(sscanf(arg1, "%ld", &rit)); - return rig_set_rit(rig, vfo, rit); + CHKSCN1ARG(sscanf(arg1, "%ld", &rit)); + return rig_set_rit(rig, vfo, rit); } + /* 'j' */ declare_proto_rig(get_rit) { - int status; - shortfreq_t rit; + int status; + shortfreq_t rit; - status = rig_get_rit(rig, vfo, &rit); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%ld%c", rit, resp_sep); + status = rig_get_rit(rig, vfo, &rit); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%ld%c", rit, resp_sep); + + return status; } + /* 'Z' */ declare_proto_rig(set_xit) { - shortfreq_t xit; + shortfreq_t xit; - CHKSCN1ARG(sscanf(arg1, "%ld", &xit)); - return rig_set_xit(rig, vfo, xit); + CHKSCN1ARG(sscanf(arg1, "%ld", &xit)); + return rig_set_xit(rig, vfo, xit); } + /* 'z' */ declare_proto_rig(get_xit) { - int status; - shortfreq_t xit; + int status; + shortfreq_t xit; - status = rig_get_xit(rig, vfo, &xit); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%ld%c", xit, resp_sep); + status = rig_get_xit(rig, vfo, &xit); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%ld%c", xit, resp_sep); + + return status; } + /* 'M' */ declare_proto_rig(set_mode) { - rmode_t mode; - pbwidth_t width; + rmode_t mode; + pbwidth_t width; - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_mode(s, rig->state.mode_list); - fprintf(fout, "%s\n", s); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_mode(s, rig->state.mode_list); + fprintf(fout, "%s\n", s); + return RIG_OK; + } - mode = rig_parse_mode(arg1); - CHKSCN1ARG(sscanf(arg2, "%ld", &width)); - return rig_set_mode(rig, vfo, mode, width); + mode = rig_parse_mode(arg1); + CHKSCN1ARG(sscanf(arg2, "%ld", &width)); + return rig_set_mode(rig, vfo, mode, width); } + /* 'm' */ declare_proto_rig(get_mode) { - int status; - rmode_t mode; - pbwidth_t width; + int status; + rmode_t mode; + pbwidth_t width; - status = rig_get_mode(rig, vfo, &mode, &width); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%s%c", rig_strrmode(mode), resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg2); - fprintf(fout, "%ld%c", width, resp_sep); + status = rig_get_mode(rig, vfo, &mode, &width); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%s%c", rig_strrmode(mode), resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg2); + } + + fprintf(fout, "%ld%c", width, resp_sep); + + return status; } + /* 'V' */ declare_proto_rig(set_vfo) { - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_vfo(s, rig->state.vfo_list); - fprintf(fout, "%s\n", s); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_vfo(s, rig->state.vfo_list); + fprintf(fout, "%s\n", s); + return RIG_OK; + } - return rig_set_vfo(rig, rig_parse_vfo(arg1)); + return rig_set_vfo(rig, rig_parse_vfo(arg1)); } + /* 'v' */ declare_proto_rig(get_vfo) { - int status; + int status; - status = rig_get_vfo(rig, &vfo); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%s%c", rig_strvfo(vfo), resp_sep); + status = rig_get_vfo(rig, &vfo); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%s%c", rig_strvfo(vfo), resp_sep); + + return status; } + /* 'T' */ declare_proto_rig(set_ptt) { - int scr; - ptt_t ptt; + int scr; + ptt_t ptt; - CHKSCN1ARG(sscanf(arg1, "%d", &scr)); - ptt=scr; - /* - * We allow RIG_PTT_ON_MIC and RIG_PTT_ON_DATA arriving from netrigctl. - * However, if the rig does not have two separate CAT commands, or if - * the rig is actually switched by a hardware signal (DTR etc.), then - * we map this to RIG_PTT_ON. - * Currently, this is not really necessary here because it is taken - * case of in rig_set_ptt, but you never know .... - */ - switch (ptt) { - case RIG_PTT_ON_MIC: - case RIG_PTT_ON_DATA: - // map to a legal value - if (rig->state.pttport.type.ptt != RIG_PTT_RIG_MICDATA) ptt=RIG_PTT_ON; - break; - case RIG_PTT_ON: - case RIG_PTT_OFF: - // nothing to do - break; - default: - // this case is not handled in hamlib, but we guard against - // illegal parameters here. The hamlib behaviour is to switch - // on PTT whenever ptt != RIG_PTT_OFF. - return -RIG_EINVAL; - } - return rig_set_ptt(rig, vfo, ptt); + CHKSCN1ARG(sscanf(arg1, "%d", &scr)); + ptt = scr; + + /* + * We allow RIG_PTT_ON_MIC and RIG_PTT_ON_DATA arriving from netrigctl. + * However, if the rig does not have two separate CAT commands, or if + * the rig is actually switched by a hardware signal (DTR etc.), then + * we map this to RIG_PTT_ON. + * Currently, this is not really necessary here because it is taken + * case of in rig_set_ptt, but you never know .... + */ + switch (ptt) { + case RIG_PTT_ON_MIC: + case RIG_PTT_ON_DATA: + + // map to a legal value + if (rig->state.pttport.type.ptt != RIG_PTT_RIG_MICDATA) { + ptt = RIG_PTT_ON; + } + + break; + + case RIG_PTT_ON: + case RIG_PTT_OFF: + // nothing to do + break; + + default: + // this case is not handled in hamlib, but we guard against + // illegal parameters here. The hamlib behaviour is to switch + // on PTT whenever ptt != RIG_PTT_OFF. + return -RIG_EINVAL; + } + + return rig_set_ptt(rig, vfo, ptt); } + /* 't' */ declare_proto_rig(get_ptt) { - int status; - ptt_t ptt; + int status; + ptt_t ptt; - status = rig_get_ptt(rig, vfo, &ptt); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - /* TODO MICDATA */ - fprintf(fout, "%d%c", ptt, resp_sep); + status = rig_get_ptt(rig, vfo, &ptt); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + /* TODO MICDATA */ + fprintf(fout, "%d%c", ptt, resp_sep); + + return status; } + /* '0x8b' */ declare_proto_rig(get_dcd) { - int status; - dcd_t dcd; + int status; + dcd_t dcd; - status = rig_get_dcd(rig, vfo, &dcd); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%d%c", dcd, resp_sep); + status = rig_get_dcd(rig, vfo, &dcd); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%d%c", dcd, resp_sep); + + return status; } + /* 'R' */ declare_proto_rig(set_rptr_shift) { - rptr_shift_t rptr_shift; + rptr_shift_t rptr_shift; - rptr_shift = rig_parse_rptr_shift(arg1); - return rig_set_rptr_shift(rig, vfo, rptr_shift); + rptr_shift = rig_parse_rptr_shift(arg1); + return rig_set_rptr_shift(rig, vfo, rptr_shift); } + /* 'r' */ declare_proto_rig(get_rptr_shift) { - int status; - rptr_shift_t rptr_shift; + int status; + rptr_shift_t rptr_shift; - status = rig_get_rptr_shift(rig, vfo, &rptr_shift); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%s%c", rig_strptrshift(rptr_shift), resp_sep); + status = rig_get_rptr_shift(rig, vfo, &rptr_shift); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%s%c", rig_strptrshift(rptr_shift), resp_sep); + + return status; } + /* 'O' */ declare_proto_rig(set_rptr_offs) { - unsigned long rptr_offs; + unsigned long rptr_offs; - CHKSCN1ARG(sscanf(arg1, "%ld", &rptr_offs)); - return rig_set_rptr_offs(rig, vfo, rptr_offs); + CHKSCN1ARG(sscanf(arg1, "%ld", &rptr_offs)); + return rig_set_rptr_offs(rig, vfo, rptr_offs); } + /* 'o' */ declare_proto_rig(get_rptr_offs) { - int status; - shortfreq_t rptr_offs; + int status; + shortfreq_t rptr_offs; - status = rig_get_rptr_offs(rig, vfo, &rptr_offs); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%ld%c", rptr_offs, resp_sep); + status = rig_get_rptr_offs(rig, vfo, &rptr_offs); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%ld%c", rptr_offs, resp_sep); + + return status; } + /* 'C' */ declare_proto_rig(set_ctcss_tone) { - tone_t tone; + tone_t tone; - CHKSCN1ARG(sscanf(arg1, "%d", &tone)); - return rig_set_ctcss_tone(rig, vfo, tone); + CHKSCN1ARG(sscanf(arg1, "%d", &tone)); + return rig_set_ctcss_tone(rig, vfo, tone); } + /* 'c' */ declare_proto_rig(get_ctcss_tone) { - int status; - tone_t tone; + int status; + tone_t tone; - status = rig_get_ctcss_tone(rig, vfo, &tone); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%d%c", tone, resp_sep); + status = rig_get_ctcss_tone(rig, vfo, &tone); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%d%c", tone, resp_sep); + + return status; } + /* 'D' */ declare_proto_rig(set_dcs_code) { - tone_t code; + tone_t code; - CHKSCN1ARG(sscanf(arg1, "%d", &code)); - return rig_set_dcs_code(rig, vfo, code); + CHKSCN1ARG(sscanf(arg1, "%d", &code)); + return rig_set_dcs_code(rig, vfo, code); } + /* 'd' */ declare_proto_rig(get_dcs_code) { - int status; - tone_t code; + int status; + tone_t code; - status = rig_get_dcs_code(rig, vfo, &code); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%d%c", code, resp_sep); + status = rig_get_dcs_code(rig, vfo, &code); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%d%c", code, resp_sep); + + return status; } + /* '0x90' */ declare_proto_rig(set_ctcss_sql) { - tone_t tone; + tone_t tone; - CHKSCN1ARG(sscanf(arg1, "%d", &tone)); - return rig_set_ctcss_sql(rig, vfo, tone); + CHKSCN1ARG(sscanf(arg1, "%d", &tone)); + return rig_set_ctcss_sql(rig, vfo, tone); } + /* '0x91' */ declare_proto_rig(get_ctcss_sql) { - int status; - tone_t tone; + int status; + tone_t tone; - status = rig_get_ctcss_sql(rig, vfo, &tone); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%d%c", tone, resp_sep); + status = rig_get_ctcss_sql(rig, vfo, &tone); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%d%c", tone, resp_sep); + + return status; } + /* '0x92' */ declare_proto_rig(set_dcs_sql) { - tone_t code; + tone_t code; - CHKSCN1ARG(sscanf(arg1, "%d", &code)); - return rig_set_dcs_sql(rig, vfo, code); + CHKSCN1ARG(sscanf(arg1, "%d", &code)); + return rig_set_dcs_sql(rig, vfo, code); } + /* '0x93' */ declare_proto_rig(get_dcs_sql) { - int status; - tone_t code; + int status; + tone_t code; - status = rig_get_dcs_sql(rig, vfo, &code); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%d%c", code, resp_sep); + status = rig_get_dcs_sql(rig, vfo, &code); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%d%c", code, resp_sep); + + return status; } + /* 'I' */ declare_proto_rig(set_split_freq) { - freq_t txfreq; - vfo_t txvfo = RIG_VFO_TX; + freq_t txfreq; + vfo_t txvfo = RIG_VFO_TX; - CHKSCN1ARG(sscanf(arg1, "%"SCNfreq, &txfreq)); - return rig_set_split_freq(rig, txvfo, txfreq); + CHKSCN1ARG(sscanf(arg1, "%"SCNfreq, &txfreq)); + return rig_set_split_freq(rig, txvfo, txfreq); } + /* 'i' */ declare_proto_rig(get_split_freq) { - int status; - freq_t txfreq; - vfo_t txvfo = RIG_VFO_TX; + int status; + freq_t txfreq; + vfo_t txvfo = RIG_VFO_TX; - status = rig_get_split_freq(rig, txvfo, &txfreq); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%"PRIll"%c", (int64_t)txfreq, resp_sep); + status = rig_get_split_freq(rig, txvfo, &txfreq); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%"PRIll"%c", (int64_t)txfreq, resp_sep); + + return status; } + /* 'X' */ declare_proto_rig(set_split_mode) { - rmode_t mode; - int width; - vfo_t txvfo = RIG_VFO_TX; + rmode_t mode; + int width; + vfo_t txvfo = RIG_VFO_TX; - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_mode(s, rig->state.mode_list); - fprintf(fout, "%s\n", s); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_mode(s, rig->state.mode_list); + fprintf(fout, "%s\n", s); + return RIG_OK; + } - mode = rig_parse_mode(arg1); - CHKSCN1ARG(sscanf(arg2, "%d", &width)); - return rig_set_split_mode(rig, txvfo, mode, (pbwidth_t) width); + mode = rig_parse_mode(arg1); + CHKSCN1ARG(sscanf(arg2, "%d", &width)); + return rig_set_split_mode(rig, txvfo, mode, (pbwidth_t) width); } + /* 'x' */ declare_proto_rig(get_split_mode) { - int status; - rmode_t mode; - pbwidth_t width; - vfo_t txvfo = RIG_VFO_TX; + int status; + rmode_t mode; + pbwidth_t width; + vfo_t txvfo = RIG_VFO_TX; - status = rig_get_split_mode(rig, txvfo, &mode, &width); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%s%c", rig_strrmode(mode), resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg2); - fprintf(fout, "%ld%c", width, resp_sep); + status = rig_get_split_mode(rig, txvfo, &mode, &width); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%s%c", rig_strrmode(mode), resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg2); + } + + fprintf(fout, "%ld%c", width, resp_sep); + + return status; } + /* 'K' */ declare_proto_rig(set_split_freq_mode) { - freq_t freq; - rmode_t mode; - int width; - vfo_t txvfo = RIG_VFO_TX; + freq_t freq; + rmode_t mode; + int width; + vfo_t txvfo = RIG_VFO_TX; - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_mode(s, rig->state.mode_list); - fprintf(fout, "%s\n", s); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_mode(s, rig->state.mode_list); + fprintf(fout, "%s\n", s); + return RIG_OK; + } - CHKSCN1ARG(sscanf(arg1, "%"SCNfreq, &freq)); - mode = rig_parse_mode(arg2); - CHKSCN1ARG(sscanf(arg3, "%d", &width)); - return rig_set_split_freq_mode(rig, txvfo, freq, mode, (pbwidth_t) width); + CHKSCN1ARG(sscanf(arg1, "%"SCNfreq, &freq)); + mode = rig_parse_mode(arg2); + CHKSCN1ARG(sscanf(arg3, "%d", &width)); + return rig_set_split_freq_mode(rig, txvfo, freq, mode, (pbwidth_t) width); } + /* 'k' */ declare_proto_rig(get_split_freq_mode) { - int status; - freq_t freq; - rmode_t mode; - pbwidth_t width; - vfo_t txvfo = RIG_VFO_TX; + int status; + freq_t freq; + rmode_t mode; + pbwidth_t width; + vfo_t txvfo = RIG_VFO_TX; - status = rig_get_split_freq_mode(rig, txvfo, &freq, &mode, &width); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%"PRIll"%c", (int64_t)freq, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg2); - fprintf(fout, "%s%c", rig_strrmode(mode), resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg3); - fprintf(fout, "%ld%c", width, resp_sep); + status = rig_get_split_freq_mode(rig, txvfo, &freq, &mode, &width); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%"PRIll"%c", (int64_t)freq, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg2); + } + + fprintf(fout, "%s%c", rig_strrmode(mode), resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg3); + } + + fprintf(fout, "%ld%c", width, resp_sep); + + return status; } + /* 'S' */ declare_proto_rig(set_split_vfo) { - int split; - vfo_t tx_vfo; + int split; + vfo_t tx_vfo; - CHKSCN1ARG(sscanf(arg1, "%d", &split)); + CHKSCN1ARG(sscanf(arg1, "%d", &split)); - if (!strcmp(arg2, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_vfo(s, rig->state.vfo_list); - fprintf(fout, "%s\n", s); - return RIG_OK; - } + if (!strcmp(arg2, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_vfo(s, rig->state.vfo_list); + fprintf(fout, "%s\n", s); + return RIG_OK; + } - tx_vfo = rig_parse_vfo(arg2); - if (tx_vfo == RIG_VFO_NONE) - return -RIG_EINVAL; - return rig_set_split_vfo(rig, vfo, (split_t) split, tx_vfo); + tx_vfo = rig_parse_vfo(arg2); + + if (tx_vfo == RIG_VFO_NONE) { + return -RIG_EINVAL; + } + + return rig_set_split_vfo(rig, vfo, (split_t) split, tx_vfo); } + /* 's' */ declare_proto_rig(get_split_vfo) { - int status; - split_t split; - vfo_t tx_vfo; + int status; + split_t split; + vfo_t tx_vfo; - status = rig_get_split_vfo(rig, vfo, &split, &tx_vfo); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%d%c", split, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg2); - fprintf(fout, "%s%c", rig_strvfo(tx_vfo), resp_sep); + status = rig_get_split_vfo(rig, vfo, &split, &tx_vfo); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%d%c", split, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg2); + } + + fprintf(fout, "%s%c", rig_strvfo(tx_vfo), resp_sep); + + return status; } + /* 'N' */ declare_proto_rig(set_ts) { - unsigned long ts; + unsigned long ts; - CHKSCN1ARG(sscanf(arg1, "%ld", &ts)); - return rig_set_ts(rig, vfo, ts); + CHKSCN1ARG(sscanf(arg1, "%ld", &ts)); + return rig_set_ts(rig, vfo, ts); } + /* 'n' */ declare_proto_rig(get_ts) { - int status; - shortfreq_t ts; + int status; + shortfreq_t ts; - status = rig_get_ts(rig, vfo, &ts); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%ld%c", ts, resp_sep); + status = rig_get_ts(rig, vfo, &ts); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%ld%c", ts, resp_sep); + + return status; } + /* '2' */ declare_proto_rig(power2mW) { - int status; - float power; - freq_t freq; - rmode_t mode; - unsigned int mwp; + int status; + float power; + freq_t freq; + rmode_t mode; + unsigned int mwp; - CHKSCN1ARG(sscanf(arg1, "%f", &power)); - CHKSCN1ARG(sscanf(arg2, "%"SCNfreq, &freq)); - mode = rig_parse_mode(arg3); + CHKSCN1ARG(sscanf(arg1, "%f", &power)); + CHKSCN1ARG(sscanf(arg2, "%"SCNfreq, &freq)); + mode = rig_parse_mode(arg3); - status = rig_power2mW(rig, &mwp, power, freq, mode); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg4); - fprintf(fout, "%i%c", mwp, resp_sep); + status = rig_power2mW(rig, &mwp, power, freq, mode); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg4); + } + + fprintf(fout, "%i%c", mwp, resp_sep); + + return status; } + /* '4' */ declare_proto_rig(mW2power) { - int status; - float power; - freq_t freq; - rmode_t mode; - unsigned int mwp; + int status; + float power; + freq_t freq; + rmode_t mode; + unsigned int mwp; - CHKSCN1ARG(sscanf(arg1, "%i", &mwp)); - CHKSCN1ARG(sscanf(arg2, "%"SCNfreq, &freq)); - mode = rig_parse_mode(arg3); + CHKSCN1ARG(sscanf(arg1, "%i", &mwp)); + CHKSCN1ARG(sscanf(arg2, "%"SCNfreq, &freq)); + mode = rig_parse_mode(arg3); - status = rig_mW2power(rig, &power, mwp, freq, mode); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg4); - fprintf(fout, "%f%c", power, resp_sep); + status = rig_mW2power(rig, &power, mwp, freq, mode); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg4); + } + + fprintf(fout, "%f%c", power, resp_sep); + + return status; } + /* * RIG_CONF_ extparm's type: * NUMERIC: val.f @@ -1938,1046 +2356,1339 @@ declare_proto_rig(mW2power) */ declare_proto_rig(set_level) { - setting_t level; - value_t val; + setting_t level; + value_t val; - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_level(s, rig->state.has_set_level); - fputs(s, fout); - if (rig->caps->set_ext_level) { - sprintf_level_ext(s, rig->caps->extlevels); - fputs(s, fout); - } - fputc('\n', fout); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_level(s, rig->state.has_set_level); + fputs(s, fout); - level = rig_parse_level(arg1); - if (!rig_has_set_level(rig, level)) { - const struct confparams *cfp; + if (rig->caps->set_ext_level) { + sprintf_level_ext(s, rig->caps->extlevels); + fputs(s, fout); + } - cfp = rig_ext_lookup(rig, arg1); - if (!cfp) - return -RIG_ENAVAIL; /* no such parameter */ + fputc('\n', fout); + return RIG_OK; + } - switch (cfp->type) { - case RIG_CONF_BUTTON: - /* arg is ignored */ - val.i=0; // avoid passing uninitialized data - break; - case RIG_CONF_CHECKBUTTON: - case RIG_CONF_COMBO: - CHKSCN1ARG(sscanf(arg2, "%d", &val.i)); - break; - case RIG_CONF_NUMERIC: - CHKSCN1ARG(sscanf(arg2, "%f", &val.f)); - break; - case RIG_CONF_STRING: - val.cs = arg2; - break; - default: - return -RIG_ECONF; - } - return rig_set_ext_level(rig, vfo, cfp->token, val); - } + level = rig_parse_level(arg1); - if (RIG_LEVEL_IS_FLOAT(level)) - CHKSCN1ARG(sscanf(arg2, "%f", &val.f)); - else - CHKSCN1ARG(sscanf(arg2, "%d", &val.i)); + if (!rig_has_set_level(rig, level)) { + const struct confparams *cfp; - return rig_set_level(rig, vfo, level, val); + cfp = rig_ext_lookup(rig, arg1); + + if (!cfp) { + return -RIG_ENAVAIL; /* no such parameter */ + } + + switch (cfp->type) { + case RIG_CONF_BUTTON: + /* arg is ignored */ + val.i = 0; // avoid passing uninitialized data + break; + + case RIG_CONF_CHECKBUTTON: + case RIG_CONF_COMBO: + CHKSCN1ARG(sscanf(arg2, "%d", &val.i)); + break; + + case RIG_CONF_NUMERIC: + CHKSCN1ARG(sscanf(arg2, "%f", &val.f)); + break; + + case RIG_CONF_STRING: + val.cs = arg2; + break; + + default: + return -RIG_ECONF; + } + + return rig_set_ext_level(rig, vfo, cfp->token, val); + } + + if (RIG_LEVEL_IS_FLOAT(level)) { + CHKSCN1ARG(sscanf(arg2, "%f", &val.f)); + } else { + CHKSCN1ARG(sscanf(arg2, "%d", &val.i)); + } + + return rig_set_level(rig, vfo, level, val); } + /* 'l' */ declare_proto_rig(get_level) { - int status; - setting_t level; - value_t val; + int status; + setting_t level; + value_t val; - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_level(s, rig->state.has_get_level); - fputs(s, fout); - if (rig->caps->get_ext_level) { - sprintf_level_ext(s, rig->caps->extlevels); - fputs(s, fout); - } - fputc('\n', fout); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_level(s, rig->state.has_get_level); + fputs(s, fout); - level = rig_parse_level(arg1); - if (!rig_has_get_level(rig, level)) { - const struct confparams *cfp; + if (rig->caps->get_ext_level) { + sprintf_level_ext(s, rig->caps->extlevels); + fputs(s, fout); + } - cfp = rig_ext_lookup(rig, arg1); - if (!cfp) - return -RIG_EINVAL; /* no such parameter */ + fputc('\n', fout); + return RIG_OK; + } - status = rig_get_ext_level(rig, vfo, cfp->token, &val); - if (status != RIG_OK) - return status; + level = rig_parse_level(arg1); - if (interactive && prompt) - fprintf(fout, "%s: ", cmd->arg2); + if (!rig_has_get_level(rig, level)) { + const struct confparams *cfp; - switch (cfp->type) { - case RIG_CONF_BUTTON: - /* there's no sense in retrieving value of stateless button */ - return -RIG_EINVAL; + cfp = rig_ext_lookup(rig, arg1); - case RIG_CONF_CHECKBUTTON: - case RIG_CONF_COMBO: - fprintf(fout, "%d\n", val.i); - break; - case RIG_CONF_NUMERIC: - fprintf(fout, "%f\n", val.f); - break; - case RIG_CONF_STRING: - fprintf(fout, "%s\n", val.s); - break; - default: - return -RIG_ECONF; - } - return status; - } + if (!cfp) { + return -RIG_EINVAL; /* no such parameter */ + } - status = rig_get_level(rig, vfo, level, &val); - if (status != RIG_OK) - return status; - if (interactive && prompt) - fprintf(fout, "%s: ", cmd->arg2); - if (RIG_LEVEL_IS_FLOAT(level)) - fprintf(fout, "%f\n", val.f); - else - fprintf(fout, "%d\n", val.i); + status = rig_get_ext_level(rig, vfo, cfp->token, &val); - return status; + if (status != RIG_OK) { + return status; + } + + if (interactive && prompt) { + fprintf(fout, "%s: ", cmd->arg2); + } + + switch (cfp->type) { + case RIG_CONF_BUTTON: + /* there's no sense in retrieving value of stateless button */ + return -RIG_EINVAL; + + case RIG_CONF_CHECKBUTTON: + case RIG_CONF_COMBO: + fprintf(fout, "%d\n", val.i); + break; + + case RIG_CONF_NUMERIC: + fprintf(fout, "%f\n", val.f); + break; + + case RIG_CONF_STRING: + fprintf(fout, "%s\n", val.s); + break; + + default: + return -RIG_ECONF; + } + + return status; + } + + status = rig_get_level(rig, vfo, level, &val); + + if (status != RIG_OK) { + return status; + } + + if (interactive && prompt) { + fprintf(fout, "%s: ", cmd->arg2); + } + + if (RIG_LEVEL_IS_FLOAT(level)) { + fprintf(fout, "%f\n", val.f); + } else { + fprintf(fout, "%d\n", val.i); + } + + return status; } + /* 'U' */ declare_proto_rig(set_func) { - setting_t func; - int func_stat; + setting_t func; + int func_stat; - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_func(s, rig->state.has_set_func); - fprintf(fout, "%s\n", s); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_func(s, rig->state.has_set_func); + fprintf(fout, "%s\n", s); + return RIG_OK; + } - func = rig_parse_func(arg1); - if (RIG_FUNC_NONE == func) - return -RIG_EINVAL; + func = rig_parse_func(arg1); - CHKSCN1ARG(sscanf(arg2, "%d", &func_stat)); - return rig_set_func(rig, vfo, func, func_stat); + if (RIG_FUNC_NONE == func) { + return -RIG_EINVAL; + } + + CHKSCN1ARG(sscanf(arg2, "%d", &func_stat)); + return rig_set_func(rig, vfo, func, func_stat); } + /* 'u' */ declare_proto_rig(get_func) { - int status; - setting_t func; - int func_stat; + int status; + setting_t func; + int func_stat; - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_func(s, rig->state.has_get_func); - fprintf(fout, "%s\n", s); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_func(s, rig->state.has_get_func); + fprintf(fout, "%s\n", s); + return RIG_OK; + } - func = rig_parse_func(arg1); - if (RIG_FUNC_NONE == func) - return -RIG_EINVAL; + func = rig_parse_func(arg1); - status = rig_get_func(rig, vfo, func, &func_stat); - if (status != RIG_OK) - return status; - if (interactive && prompt) - fprintf(fout, "%s: ", cmd->arg2); - fprintf(fout, "%d\n", func_stat); + if (RIG_FUNC_NONE == func) { + return -RIG_EINVAL; + } - return status; + status = rig_get_func(rig, vfo, func, &func_stat); + + if (status != RIG_OK) { + return status; + } + + if (interactive && prompt) { + fprintf(fout, "%s: ", cmd->arg2); + } + + fprintf(fout, "%d\n", func_stat); + + return status; } + /* 'P' */ declare_proto_rig(set_parm) { - setting_t parm; - value_t val; + setting_t parm; + value_t val; - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_parm(s, rig->state.has_set_parm); - fprintf(fout, "%s\n", s); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_parm(s, rig->state.has_set_parm); + fprintf(fout, "%s\n", s); + return RIG_OK; + } - parm = rig_parse_parm(arg1); - if (!rig_has_set_parm(rig, parm)) { - const struct confparams *cfp; + parm = rig_parse_parm(arg1); - cfp = rig_ext_lookup(rig, arg1); - if (!cfp) - return -RIG_EINVAL; /* no such parameter */ + if (!rig_has_set_parm(rig, parm)) { + const struct confparams *cfp; - switch (cfp->type) { - case RIG_CONF_BUTTON: - /* arg is ignored */ - val.i=0; // avoid passing uninitialized data - break; - case RIG_CONF_CHECKBUTTON: - case RIG_CONF_COMBO: - CHKSCN1ARG(sscanf(arg2, "%d", &val.i)); - break; - case RIG_CONF_NUMERIC: - CHKSCN1ARG(sscanf(arg2, "%f", &val.f)); - break; - case RIG_CONF_STRING: - val.cs = arg2; - break; - default: - return -RIG_ECONF; - } - return rig_set_ext_parm(rig, cfp->token, val); - } + cfp = rig_ext_lookup(rig, arg1); - if (RIG_PARM_IS_FLOAT(parm)) - CHKSCN1ARG(sscanf(arg2, "%f", &val.f)); - else - CHKSCN1ARG(sscanf(arg2, "%d", &val.i)); + if (!cfp) { + return -RIG_EINVAL; /* no such parameter */ + } - return rig_set_parm(rig, parm, val); + switch (cfp->type) { + case RIG_CONF_BUTTON: + /* arg is ignored */ + val.i = 0; // avoid passing uninitialized data + break; + + case RIG_CONF_CHECKBUTTON: + case RIG_CONF_COMBO: + CHKSCN1ARG(sscanf(arg2, "%d", &val.i)); + break; + + case RIG_CONF_NUMERIC: + CHKSCN1ARG(sscanf(arg2, "%f", &val.f)); + break; + + case RIG_CONF_STRING: + val.cs = arg2; + break; + + default: + return -RIG_ECONF; + } + + return rig_set_ext_parm(rig, cfp->token, val); + } + + if (RIG_PARM_IS_FLOAT(parm)) { + CHKSCN1ARG(sscanf(arg2, "%f", &val.f)); + } else { + CHKSCN1ARG(sscanf(arg2, "%d", &val.i)); + } + + return rig_set_parm(rig, parm, val); } + /* 'p' */ declare_proto_rig(get_parm) { - int status; - setting_t parm; - value_t val; + int status; + setting_t parm; + value_t val; - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_parm(s, rig->state.has_get_parm); - fprintf(fout, "%s\n", s); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_parm(s, rig->state.has_get_parm); + fprintf(fout, "%s\n", s); + return RIG_OK; + } - parm = rig_parse_parm(arg1); - if (!rig_has_get_parm(rig, parm)) { - const struct confparams *cfp; + parm = rig_parse_parm(arg1); - cfp = rig_ext_lookup(rig, arg1); - if (!cfp) - return -RIG_EINVAL; /* no such parameter */ + if (!rig_has_get_parm(rig, parm)) { + const struct confparams *cfp; - status = rig_get_ext_parm(rig, cfp->token, &val); - if (status != RIG_OK) - return status; + cfp = rig_ext_lookup(rig, arg1); - if (interactive && prompt) - fprintf(fout, "%s: ", cmd->arg2); + if (!cfp) { + return -RIG_EINVAL; /* no such parameter */ + } - switch (cfp->type) { - case RIG_CONF_BUTTON: - /* there's not sense in retrieving value of stateless button */ - return -RIG_EINVAL; - case RIG_CONF_CHECKBUTTON: - case RIG_CONF_COMBO: - fprintf(fout, "%d\n", val.i); - break; - case RIG_CONF_NUMERIC: - fprintf(fout, "%f\n", val.f); - break; - case RIG_CONF_STRING: - fprintf(fout, "%s\n", val.s); - break; - default: - return -RIG_ECONF; - } - return status; - } + status = rig_get_ext_parm(rig, cfp->token, &val); - status = rig_get_parm(rig, parm, &val); - if (status != RIG_OK) - return status; - if (interactive && prompt) - fprintf(fout, "%s: ", cmd->arg2); - if (RIG_PARM_IS_FLOAT(parm)) - fprintf(fout, "%f\n", val.f); - else - fprintf(fout, "%d\n", val.i); + if (status != RIG_OK) { + return status; + } - return status; + if (interactive && prompt) { + fprintf(fout, "%s: ", cmd->arg2); + } + + switch (cfp->type) { + case RIG_CONF_BUTTON: + /* there's not sense in retrieving value of stateless button */ + return -RIG_EINVAL; + + case RIG_CONF_CHECKBUTTON: + case RIG_CONF_COMBO: + fprintf(fout, "%d\n", val.i); + break; + + case RIG_CONF_NUMERIC: + fprintf(fout, "%f\n", val.f); + break; + + case RIG_CONF_STRING: + fprintf(fout, "%s\n", val.s); + break; + + default: + return -RIG_ECONF; + } + + return status; + } + + status = rig_get_parm(rig, parm, &val); + + if (status != RIG_OK) { + return status; + } + + if (interactive && prompt) { + fprintf(fout, "%s: ", cmd->arg2); + } + + if (RIG_PARM_IS_FLOAT(parm)) { + fprintf(fout, "%f\n", val.f); + } else { + fprintf(fout, "%d\n", val.i); + } + + return status; } + /* 'B' */ declare_proto_rig(set_bank) { - int bank; + int bank; - CHKSCN1ARG(sscanf(arg1, "%d", &bank)); - return rig_set_bank(rig, vfo, bank); + CHKSCN1ARG(sscanf(arg1, "%d", &bank)); + return rig_set_bank(rig, vfo, bank); } + /* 'E' */ declare_proto_rig(set_mem) { - int ch; + int ch; - CHKSCN1ARG(sscanf(arg1, "%d", &ch)); - return rig_set_mem(rig, vfo, ch); + CHKSCN1ARG(sscanf(arg1, "%d", &ch)); + return rig_set_mem(rig, vfo, ch); } + /* 'e' */ declare_proto_rig(get_mem) { - int status; - int ch; + int status; + int ch; - status = rig_get_mem(rig, vfo, &ch); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%d%c", ch, resp_sep); + status = rig_get_mem(rig, vfo, &ch); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%d%c", ch, resp_sep); + + return status; } + /* 'G' */ declare_proto_rig(vfo_op) { - vfo_op_t op; + vfo_op_t op; - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_vfop(s, rig->caps->vfo_ops); - fprintf(fout, "%s\n", s); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_vfop(s, rig->caps->vfo_ops); + fprintf(fout, "%s\n", s); + return RIG_OK; + } - op = rig_parse_vfo_op(arg1); - if (RIG_OP_NONE == op) - return -RIG_EINVAL; + op = rig_parse_vfo_op(arg1); - return rig_vfo_op(rig, vfo, op); + if (RIG_OP_NONE == op) { + return -RIG_EINVAL; + } + + return rig_vfo_op(rig, vfo, op); } + /* 'g' */ declare_proto_rig(scan) { - scan_t op; - int ch; + scan_t op; + int ch; - if (!strcmp(arg1, "?")) { - char s[SPRINTF_MAX_SIZE]; - sprintf_scan(s, rig->caps->scan_ops); - fprintf(fout, "%s\n", s); - return RIG_OK; - } + if (!strcmp(arg1, "?")) { + char s[SPRINTF_MAX_SIZE]; + sprintf_scan(s, rig->caps->scan_ops); + fprintf(fout, "%s\n", s); + return RIG_OK; + } - op = rig_parse_scan(arg1); - CHKSCN1ARG(sscanf(arg2, "%d", &ch)); - return rig_scan(rig, vfo, op, ch); + op = rig_parse_scan(arg1); + CHKSCN1ARG(sscanf(arg2, "%d", &ch)); + return rig_scan(rig, vfo, op, ch); } + /* 'H' */ declare_proto_rig(set_channel) { - const channel_cap_t *mem_caps = NULL; - const chan_t *chan_list; - channel_t chan; - int status; - char s[16]; + const channel_cap_t *mem_caps = NULL; + const chan_t *chan_list; + channel_t chan; + int status; + char s[16]; - memset(&chan, 0, sizeof(channel_t)); + memset(&chan, 0, sizeof(channel_t)); - if (isdigit((int)arg1[0])) { - chan.vfo = RIG_VFO_MEM; - CHKSCN1ARG(sscanf(arg1, "%d", &chan.channel_num)); - /* - * find mem_caps in caps, we'll need it later - */ - chan_list = rig_lookup_mem_caps(rig, chan.channel_num); - if (chan_list) - mem_caps = &chan_list->mem_caps; + if (isdigit((int)arg1[0])) { + chan.vfo = RIG_VFO_MEM; + CHKSCN1ARG(sscanf(arg1, "%d", &chan.channel_num)); + /* + * find mem_caps in caps, we'll need it later + */ + chan_list = rig_lookup_mem_caps(rig, chan.channel_num); - } else { - chan.vfo = rig_parse_vfo(arg1); - chan.channel_num = 0; + if (chan_list) { + mem_caps = &chan_list->mem_caps; + } - /* TODO: mem_caps for VFO! */ - /* either from mem, or reverse computed from caps */ - } + } else { + chan.vfo = rig_parse_vfo(arg1); + chan.channel_num = 0; - if (!mem_caps) - return -RIG_ECONF; + /* TODO: mem_caps for VFO! */ + /* either from mem, or reverse computed from caps */ + } + + if (!mem_caps) { + return -RIG_ECONF; + } + + if (mem_caps->bank_num) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf_flush(fout, "Bank Num: "); + } + + CHKSCN1ARG(scanfc(fin, "%d", &chan.bank_num)); + } - if (mem_caps->bank_num) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf_flush(fout, "Bank Num: "); - CHKSCN1ARG(scanfc(fin, "%d", &chan.bank_num)); - } #if 0 - if (mem_caps->vfo) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + + if (mem_caps->vfo) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "vfo (VFOA,MEM,etc...): "); - CHKSCN1ARG(scanfc(fin, "%s", s)); - chan.vfo = rig_parse_vfo(s); - } + } + + CHKSCN1ARG(scanfc(fin, "%s", s)); + chan.vfo = rig_parse_vfo(s); + } + #endif - if (mem_caps->ant) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + + if (mem_caps->ant) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "ant: "); - CHKSCN1ARG(scanfc(fin, "%d", &chan.ant)); - } - if (mem_caps->freq) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%d", &chan.ant)); + } + + if (mem_caps->freq) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "Frequency: "); - CHKSCN1ARG(scanfc(fin, "%"SCNfreq, &chan.freq)); - } - if (mem_caps->mode) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%"SCNfreq, &chan.freq)); + } + + if (mem_caps->mode) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "mode (FM,LSB,etc...): "); - CHKSCN1ARG(scanfc(fin, "%s", s)); - chan.mode = rig_parse_mode(s); - } - if (mem_caps->width) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%s", s)); + chan.mode = rig_parse_mode(s); + } + + if (mem_caps->width) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "width: "); - CHKSCN1ARG(scanfc(fin, "%ld", &chan.width)); - } - if (mem_caps->tx_freq) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%ld", &chan.width)); + } + + if (mem_caps->tx_freq) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "tx freq: "); - CHKSCN1ARG(scanfc(fin, "%"SCNfreq, &chan.tx_freq)); - } - if (mem_caps->tx_mode) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%"SCNfreq, &chan.tx_freq)); + } + + if (mem_caps->tx_mode) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "tx mode (FM,LSB,etc...): "); - CHKSCN1ARG(scanfc(fin, "%s", s)); - chan.tx_mode = rig_parse_mode(s); - } - if (mem_caps->tx_width) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%s", s)); + chan.tx_mode = rig_parse_mode(s); + } + + if (mem_caps->tx_width) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "tx width: "); - CHKSCN1ARG(scanfc(fin, "%ld", &chan.tx_width)); - } - if (mem_caps->split) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%ld", &chan.tx_width)); + } + + if (mem_caps->split) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "split (0,1): "); - CHKSCN1ARG(scanfc(fin, "%d", &status)); - chan.split = status; - } - if (mem_caps->tx_vfo) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%d", &status)); + chan.split = status; + } + + if (mem_caps->tx_vfo) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "tx vfo (VFOA,MEM,etc...): "); - CHKSCN1ARG(scanfc(fin, "%s", s)); - chan.tx_vfo = rig_parse_vfo(s); - } - if (mem_caps->rptr_shift) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%s", s)); + chan.tx_vfo = rig_parse_vfo(s); + } + + if (mem_caps->rptr_shift) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "rptr shift (+-0): "); - CHKSCN1ARG(scanfc(fin, "%s", s)); - chan.rptr_shift = rig_parse_rptr_shift(s); - } - if (mem_caps->rptr_offs) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%s", s)); + chan.rptr_shift = rig_parse_rptr_shift(s); + } + + if (mem_caps->rptr_offs) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "rptr offset: "); - CHKSCN1ARG(scanfc(fin, "%ld", &chan.rptr_offs)); - } - if (mem_caps->tuning_step) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%ld", &chan.rptr_offs)); + } + + if (mem_caps->tuning_step) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "tuning step: "); - CHKSCN1ARG(scanfc(fin, "%ld", &chan.tuning_step)); - } - if (mem_caps->rit) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%ld", &chan.tuning_step)); + } + + if (mem_caps->rit) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "rit (Hz,0=off): "); - CHKSCN1ARG(scanfc(fin, "%ld", &chan.rit)); - } - if (mem_caps->xit) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%ld", &chan.rit)); + } + + if (mem_caps->xit) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "xit (Hz,0=off): "); - CHKSCN1ARG(scanfc(fin, "%ld", &chan.xit)); - } - if (mem_caps->funcs) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%ld", &chan.xit)); + } + + if (mem_caps->funcs) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "funcs: "); - CHKSCN1ARG(scanfc(fin, "%lx", &chan.funcs)); - } + } + + CHKSCN1ARG(scanfc(fin, "%lx", &chan.funcs)); + } + #if 0 - /* for all levels (except READONLY), ask */ - if (mem_caps->levels) - sscanf(arg1, "%d", &chan.levels); + + /* for all levels (except READONLY), ask */ + if (mem_caps->levels) { + sscanf(arg1, "%d", &chan.levels); + } + #endif - if (mem_caps->ctcss_tone) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + + if (mem_caps->ctcss_tone) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "ctcss tone freq in tenth of Hz (0=off): "); - CHKSCN1ARG(scanfc(fin, "%d", &chan.ctcss_tone)); - } - if (mem_caps->ctcss_sql) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%d", &chan.ctcss_tone)); + } + + if (mem_caps->ctcss_sql) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "ctcss sql freq in tenth of Hz (0=off): "); - CHKSCN1ARG(scanfc(fin, "%d", &chan.ctcss_sql)); - } - if (mem_caps->dcs_code) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%d", &chan.ctcss_sql)); + } + + if (mem_caps->dcs_code) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "dcs code: "); - CHKSCN1ARG(scanfc(fin, "%d", &chan.dcs_code)); - } - if (mem_caps->dcs_sql) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%d", &chan.dcs_code)); + } + + if (mem_caps->dcs_sql) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "dcs sql: "); - CHKSCN1ARG(scanfc(fin, "%d", &chan.dcs_sql)); - } - if (mem_caps->scan_group) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%d", &chan.dcs_sql)); + } + + if (mem_caps->scan_group) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "scan group: "); - CHKSCN1ARG(scanfc(fin, "%d", &chan.scan_group)); - } - if (mem_caps->flags) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%d", &chan.scan_group)); + } + + if (mem_caps->flags) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "flags: "); - CHKSCN1ARG(scanfc(fin, "%d", &chan.flags)); - } - if (mem_caps->channel_desc) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + } + + CHKSCN1ARG(scanfc(fin, "%d", &chan.flags)); + } + + if (mem_caps->channel_desc) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf_flush(fout, "channel desc: "); - CHKSCN1ARG(scanfc(fin, "%s", s)); - strcpy(chan.channel_desc, s); - } + } + + CHKSCN1ARG(scanfc(fin, "%s", s)); + strcpy(chan.channel_desc, s); + } + #if 0 - /* TODO: same as levels, allocate/free the array */ - if (mem_caps->ext_levels) - sscanf(arg1, "%d", &chan.ext_levels[i].val.i); + + /* TODO: same as levels, allocate/free the array */ + if (mem_caps->ext_levels) { + sscanf(arg1, "%d", &chan.ext_levels[i].val.i); + } + #endif - status = rig_set_channel(rig, &chan); + status = rig_set_channel(rig, &chan); - return status; + return status; } + /* 'h' */ declare_proto_rig(get_channel) { - int status; - channel_t chan; + int status; + channel_t chan; - memset(&chan, 0, sizeof(channel_t)); + memset(&chan, 0, sizeof(channel_t)); - if (isdigit((int)arg1[0])) { - chan.vfo = RIG_VFO_MEM; - CHKSCN1ARG(sscanf(arg1, "%d", &chan.channel_num)); - } else { - chan.vfo = rig_parse_vfo(arg1); - chan.channel_num = 0; - } + if (isdigit((int)arg1[0])) { + chan.vfo = RIG_VFO_MEM; + CHKSCN1ARG(sscanf(arg1, "%d", &chan.channel_num)); + } else { + chan.vfo = rig_parse_vfo(arg1); + chan.channel_num = 0; + } - status = rig_get_channel(rig, &chan); - if (status != RIG_OK) - return status; + status = rig_get_channel(rig, &chan); - status = dump_chan(fout, rig, &chan); + if (status != RIG_OK) { + return status; + } - if (chan.ext_levels) - free(chan.ext_levels); + status = dump_chan(fout, rig, &chan); - return status; + if (chan.ext_levels) { + free(chan.ext_levels); + } + + return status; } + static int myfreq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg) { - printf("Event: freq changed to %"PRIll"Hz on %s\n", (int64_t)freq, rig_strvfo(vfo)); - return 0; + printf("Event: freq changed to %"PRIll"Hz on %s\n", + (int64_t)freq, + rig_strvfo(vfo)); + + return 0; } -static int mymode_event(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width, rig_ptr_t arg) + +static int mymode_event(RIG *rig, + vfo_t vfo, + rmode_t mode, + pbwidth_t width, + rig_ptr_t arg) { - printf("Event: mode changed to %s, width %liHz on %s\n", rig_strrmode(mode), - width, rig_strvfo(vfo)); - return 0; + printf("Event: mode changed to %s, width %liHz on %s\n", + rig_strrmode(mode), + width, rig_strvfo(vfo)); + + return 0; } + static int myvfo_event(RIG *rig, vfo_t vfo, rig_ptr_t arg) { - printf("Event: vfo changed to %s\n", rig_strvfo(vfo)); - return 0; + printf("Event: vfo changed to %s\n", rig_strvfo(vfo)); + return 0; } + static int myptt_event(RIG *rig, vfo_t vfo, ptt_t ptt, rig_ptr_t arg) { - printf("Event: PTT changed to %i on %s\n", ptt, rig_strvfo(vfo)); - return 0; + printf("Event: PTT changed to %i on %s\n", ptt, rig_strvfo(vfo)); + + return 0; } + static int mydcd_event(RIG *rig, vfo_t vfo, dcd_t dcd, rig_ptr_t arg) { - printf("Event: DCD changed to %i on %s\n", dcd, rig_strvfo(vfo)); - return 0; + printf("Event: DCD changed to %i on %s\n", dcd, rig_strvfo(vfo)); + + return 0; } + /* 'A' */ declare_proto_rig(set_trn) { - int trn; + int trn; - if (!strcmp(arg1, "?")) { - fprintf(fout, "OFF RIG POLL\n"); - return RIG_OK; - } - if (!strcmp(arg1, "OFF")) - trn = RIG_TRN_OFF; - else if (!strcmp(arg1, "RIG") || !strcmp(arg1, "ON")) - trn = RIG_TRN_RIG; - else if (!strcmp(arg1, "POLL")) - trn = RIG_TRN_POLL; - else - return -RIG_EINVAL; + if (!strcmp(arg1, "?")) { + fprintf(fout, "OFF RIG POLL\n"); + return RIG_OK; + } - if (trn != RIG_TRN_OFF) { - rig_set_freq_callback(rig, myfreq_event, NULL); - rig_set_mode_callback(rig, mymode_event, NULL); - rig_set_vfo_callback (rig, myvfo_event, NULL); - rig_set_ptt_callback (rig, myptt_event, NULL); - rig_set_dcd_callback (rig, mydcd_event, NULL); - } + if (!strcmp(arg1, "OFF")) { + trn = RIG_TRN_OFF; + } else if (!strcmp(arg1, "RIG") || !strcmp(arg1, "ON")) { + trn = RIG_TRN_RIG; + } else if (!strcmp(arg1, "POLL")) { + trn = RIG_TRN_POLL; + } else { + return -RIG_EINVAL; + } - return rig_set_trn(rig, trn); + if (trn != RIG_TRN_OFF) { + rig_set_freq_callback(rig, myfreq_event, NULL); + rig_set_mode_callback(rig, mymode_event, NULL); + rig_set_vfo_callback(rig, myvfo_event, NULL); + rig_set_ptt_callback(rig, myptt_event, NULL); + rig_set_dcd_callback(rig, mydcd_event, NULL); + } + + return rig_set_trn(rig, trn); } + /* 'a' */ declare_proto_rig(get_trn) { - int status; - int trn; - static const char* trn_txt[] = { - "OFF", - "RIG", - "POLL"}; + int status; + int trn; + static const char *trn_txt[] = { + "OFF", + "RIG", + "POLL" + }; - status = rig_get_trn(rig, &trn); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - if (trn>=0 && trn<=2) - fprintf(fout, "%s%c", trn_txt[trn], resp_sep); + status = rig_get_trn(rig, &trn); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + if (trn >= 0 && trn <= 2) { + fprintf(fout, "%s%c", trn_txt[trn], resp_sep); + } + + return status; } + /* '_' */ declare_proto_rig(get_info) { - const char *s; + const char *s; - s = rig_get_info(rig); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%s%c", s ? s : "None", resp_sep); + s = rig_get_info(rig); - return RIG_OK; + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%s%c", s ? s : "None", resp_sep); + + return RIG_OK; } + int dump_chan(FILE *fout, RIG *rig, channel_t *chan) { - int idx, firstloop=1; - char freqbuf[16]; - char widthbuf[16]; - char prntbuf[256]; + int idx, firstloop = 1; + char freqbuf[16]; + char widthbuf[16]; + char prntbuf[256]; - fprintf(fout, "Channel: %d, Name: '%s'\n", chan->channel_num, - chan->channel_desc); + fprintf(fout, + "Channel: %d, Name: '%s'\n", + chan->channel_num, + chan->channel_desc); - fprintf(fout, "VFO: %s, Antenna: %d, Split: %s\n", rig_strvfo(chan->vfo), - chan->ant, chan->split==RIG_SPLIT_ON?"ON":"OFF"); + fprintf(fout, + "VFO: %s, Antenna: %d, Split: %s\n", + rig_strvfo(chan->vfo), + chan->ant, + chan->split == RIG_SPLIT_ON ? "ON" : "OFF"); - sprintf_freq(freqbuf, chan->freq); - sprintf_freq(widthbuf, chan->width); - fprintf(fout, "Freq: %s\tMode: %s\tWidth: %s\n", - freqbuf, rig_strrmode(chan->mode), widthbuf); + sprintf_freq(freqbuf, chan->freq); + sprintf_freq(widthbuf, chan->width); + fprintf(fout, + "Freq: %s\tMode: %s\tWidth: %s\n", + freqbuf, + rig_strrmode(chan->mode), + widthbuf); - sprintf_freq(freqbuf, chan->tx_freq); - sprintf_freq(widthbuf, chan->tx_width); - fprintf(fout, "txFreq: %s\ttxMode: %s\ttxWidth: %s\n", - freqbuf, rig_strrmode(chan->tx_mode), widthbuf); + sprintf_freq(freqbuf, chan->tx_freq); + sprintf_freq(widthbuf, chan->tx_width); + fprintf(fout, + "txFreq: %s\ttxMode: %s\ttxWidth: %s\n", + freqbuf, + rig_strrmode(chan->tx_mode), + widthbuf); - sprintf_freq(freqbuf,chan->rptr_offs); - fprintf(fout, "Shift: %s, Offset: %s%s, ", rig_strptrshift(chan->rptr_shift), - chan->rptr_offs>0?"+":"", freqbuf); + sprintf_freq(freqbuf, chan->rptr_offs); + fprintf(fout, + "Shift: %s, Offset: %s%s, ", + rig_strptrshift(chan->rptr_shift), + chan->rptr_offs > 0 ? "+" : "", + freqbuf); - sprintf_freq(freqbuf,chan->tuning_step); - fprintf(fout, "Step: %s, ", freqbuf); - sprintf_freq(freqbuf,chan->rit); - fprintf(fout, "RIT: %s%s, ", chan->rit>0?"+":"", freqbuf); - sprintf_freq(freqbuf,chan->xit); - fprintf(fout, "XIT: %s%s\n", chan->xit>0?"+":"", freqbuf); + sprintf_freq(freqbuf, chan->tuning_step); + fprintf(fout, "Step: %s, ", freqbuf); + sprintf_freq(freqbuf, chan->rit); + fprintf(fout, "RIT: %s%s, ", chan->rit > 0 ? "+" : "", freqbuf); + sprintf_freq(freqbuf, chan->xit); + fprintf(fout, "XIT: %s%s\n", chan->xit > 0 ? "+" : "", freqbuf); - fprintf(fout, "CTCSS: %d.%dHz, ", chan->ctcss_tone/10, chan->ctcss_tone%10); - fprintf(fout, "CTCSSsql: %d.%dHz, ", chan->ctcss_sql/10, chan->ctcss_sql%10); - fprintf(fout, "DCS: %d.%d, ", chan->dcs_code/10, chan->dcs_code%10); - fprintf(fout, "DCSsql: %d.%d\n", chan->dcs_sql/10, chan->dcs_sql%10); + fprintf(fout, "CTCSS: %d.%dHz, ", chan->ctcss_tone / 10, chan->ctcss_tone % 10); + fprintf(fout, + "CTCSSsql: %d.%dHz, ", + chan->ctcss_sql / 10, + chan->ctcss_sql % 10); - sprintf_func(prntbuf, chan->funcs); - fprintf(fout, "Functions: %s\n", prntbuf); + fprintf(fout, "DCS: %d.%d, ", chan->dcs_code / 10, chan->dcs_code % 10); + fprintf(fout, "DCSsql: %d.%d\n", chan->dcs_sql / 10, chan->dcs_sql % 10); - fprintf(fout, "Levels:"); - for (idx=0; idxfuncs); + fprintf(fout, "Functions: %s\n", prntbuf); - if (!RIG_LEVEL_SET(level) || - (!rig_has_set_level(rig, level) && !rig_has_get_level(rig, level))) - continue; - level_s = rig_strlevel(level); - if (!level_s || level_s[0] == '\0') - continue; /* duh! */ - if (firstloop) - firstloop = 0; - else - fprintf(fout, ",\t"); - if (RIG_LEVEL_IS_FLOAT(level)) - fprintf(fout, " %s: %g%%", level_s, 100*chan->levels[idx].f); - else - fprintf(fout, " %s: %d", level_s, chan->levels[idx].i); - } + fprintf(fout, "Levels:"); - /* ext_levels */ - for (idx=0; chan->ext_levels && !RIG_IS_EXT_END(chan->ext_levels[idx]); idx++) { - const struct confparams *cfp; - char lstr[32]; + for (idx = 0; idx < RIG_SETTING_MAX; idx++) { + setting_t level = rig_idx2setting(idx); + const char *level_s; - cfp = rig_ext_lookup_tok(rig, chan->ext_levels[idx].token); - if (!cfp) - return -RIG_EINVAL; + if (!RIG_LEVEL_SET(level) + || (!rig_has_set_level(rig, level) + && !rig_has_get_level(rig, level))) { - switch (cfp->type) { - case RIG_CONF_STRING: - strcpy(lstr, chan->ext_levels[idx].val.s); - break; - case RIG_CONF_COMBO: - sprintf(lstr, "%d", chan->ext_levels[idx].val.i); - break; - case RIG_CONF_NUMERIC: - sprintf(lstr, "%f", chan->ext_levels[idx].val.f); - break; - case RIG_CONF_CHECKBUTTON: - sprintf(lstr, "%s", chan->ext_levels[idx].val.i ? "ON" : "OFF"); - break; - case RIG_CONF_BUTTON: - continue; - default: - return -RIG_EINTERNAL; - } - fprintf(fout, ",\t %s: %s", cfp->name, lstr); - } + continue; + } - fprintf(fout, "\n"); + level_s = rig_strlevel(level); - return RIG_OK; + if (!level_s || level_s[0] == '\0') { + continue; /* duh! */ + } + + if (firstloop) { + firstloop = 0; + } else { + fprintf(fout, ",\t"); + } + + if (RIG_LEVEL_IS_FLOAT(level)) { + fprintf(fout, " %s: %g%%", level_s, 100 * chan->levels[idx].f); + } else { + fprintf(fout, " %s: %d", level_s, chan->levels[idx].i); + } + } + + /* ext_levels */ + for (idx = 0; chan->ext_levels + && !RIG_IS_EXT_END(chan->ext_levels[idx]); idx++) { + const struct confparams *cfp; + char lstr[32]; + + cfp = rig_ext_lookup_tok(rig, chan->ext_levels[idx].token); + + if (!cfp) { + return -RIG_EINVAL; + } + + switch (cfp->type) { + case RIG_CONF_STRING: + strcpy(lstr, chan->ext_levels[idx].val.s); + break; + + case RIG_CONF_COMBO: + sprintf(lstr, "%d", chan->ext_levels[idx].val.i); + break; + + case RIG_CONF_NUMERIC: + sprintf(lstr, "%f", chan->ext_levels[idx].val.f); + break; + + case RIG_CONF_CHECKBUTTON: + sprintf(lstr, "%s", chan->ext_levels[idx].val.i ? "ON" : "OFF"); + break; + + case RIG_CONF_BUTTON: + continue; + + default: + return -RIG_EINTERNAL; + } + + fprintf(fout, ",\t %s: %s", cfp->name, lstr); + } + + fprintf(fout, "\n"); + + return RIG_OK; } + /* '1' */ declare_proto_rig(dump_caps) { - dumpcaps(rig, fout); + dumpcaps(rig, fout); - return RIG_OK; + return RIG_OK; } + /* For rigctld internal use */ declare_proto_rig(dump_state) { - int i; - struct rig_state *rs = &rig->state; + int i; + struct rig_state *rs = &rig->state; - /* - * - Protocol version - */ + /* + * - Protocol version + */ #define RIGCTLD_PROT_VER 0 - fprintf(fout, "%d\n", RIGCTLD_PROT_VER); - fprintf(fout, "%d\n", rig->caps->rig_model); - fprintf(fout, "%d\n", rs->itu_region); + fprintf(fout, "%d\n", RIGCTLD_PROT_VER); + fprintf(fout, "%d\n", rig->caps->rig_model); + fprintf(fout, "%d\n", rs->itu_region); - for (i=0; irx_range_list[i]); i++) - fprintf(fout, "%"FREQFMT" %"FREQFMT" 0x%x %d %d 0x%x 0x%x\n", - rs->rx_range_list[i].start, - rs->rx_range_list[i].end, - rs->rx_range_list[i].modes, - rs->rx_range_list[i].low_power, - rs->rx_range_list[i].high_power, - rs->rx_range_list[i].vfo, - rs->rx_range_list[i].ant - ); - fprintf(fout, "0 0 0 0 0 0 0\n"); + for (i = 0; i < FRQRANGESIZ && !RIG_IS_FRNG_END(rs->rx_range_list[i]); i++) { + fprintf(fout, + "%"FREQFMT" %"FREQFMT" 0x%x %d %d 0x%x 0x%x\n", + rs->rx_range_list[i].start, + rs->rx_range_list[i].end, + rs->rx_range_list[i].modes, + rs->rx_range_list[i].low_power, + rs->rx_range_list[i].high_power, + rs->rx_range_list[i].vfo, + rs->rx_range_list[i].ant); + } - for (i=0; itx_range_list[i]); i++) - fprintf(fout, "%"FREQFMT" %"FREQFMT" 0x%x %d %d 0x%x 0x%x\n", - rs->tx_range_list[i].start, - rs->tx_range_list[i].end, - rs->tx_range_list[i].modes, - rs->tx_range_list[i].low_power, - rs->tx_range_list[i].high_power, - rs->tx_range_list[i].vfo, - rs->tx_range_list[i].ant - ); - fprintf(fout, "0 0 0 0 0 0 0\n"); + fprintf(fout, "0 0 0 0 0 0 0\n"); - for (i=0; ituning_steps[i]); i++) - fprintf(fout, "0x%x %ld\n", - rs->tuning_steps[i].modes, - rs->tuning_steps[i].ts); - fprintf(fout, "0 0\n"); + for (i = 0; i < FRQRANGESIZ && !RIG_IS_FRNG_END(rs->tx_range_list[i]); i++) { + fprintf(fout, + "%"FREQFMT" %"FREQFMT" 0x%x %d %d 0x%x 0x%x\n", + rs->tx_range_list[i].start, + rs->tx_range_list[i].end, + rs->tx_range_list[i].modes, + rs->tx_range_list[i].low_power, + rs->tx_range_list[i].high_power, + rs->tx_range_list[i].vfo, + rs->tx_range_list[i].ant); + } - for (i=0; ifilters[i]); i++) - fprintf(fout, "0x%x %ld\n", - rs->filters[i].modes, - rs->filters[i].width); - fprintf(fout, "0 0\n"); + fprintf(fout, "0 0 0 0 0 0 0\n"); + + for (i = 0; i < TSLSTSIZ && !RIG_IS_TS_END(rs->tuning_steps[i]); i++) { + fprintf(fout, + "0x%x %ld\n", + rs->tuning_steps[i].modes, + rs->tuning_steps[i].ts); + } + + fprintf(fout, "0 0\n"); + + for (i = 0; i < FLTLSTSIZ && !RIG_IS_FLT_END(rs->filters[i]); i++) { + fprintf(fout, + "0x%x %ld\n", + rs->filters[i].modes, + rs->filters[i].width); + } + + fprintf(fout, "0 0\n"); #if 0 - chan_t chan_list[CHANLSTSIZ]; /*!< Channel list, zero ended */ + chan_t chan_list[CHANLSTSIZ]; /*!< Channel list, zero ended */ #endif - fprintf(fout, "%ld\n", rs->max_rit); - fprintf(fout, "%ld\n", rs->max_xit); - fprintf(fout, "%ld\n", rs->max_ifshift); - fprintf(fout, "%d\n", rs->announces); + fprintf(fout, "%ld\n", rs->max_rit); + fprintf(fout, "%ld\n", rs->max_xit); + fprintf(fout, "%ld\n", rs->max_ifshift); + fprintf(fout, "%d\n", rs->announces); - for (i=0; ipreamp[i]; i++) - fprintf(fout, "%d ", rs->preamp[i]); - fprintf(fout, "\n"); - for (i=0; iattenuator[i]; i++) - fprintf(fout, "%d ", rs->attenuator[i]); - fprintf(fout, "\n"); + for (i = 0; i < MAXDBLSTSIZ && rs->preamp[i]; i++) { + fprintf(fout, "%d ", rs->preamp[i]); + } - fprintf(fout, "0x%lx\n", rs->has_get_func); - fprintf(fout, "0x%lx\n", rs->has_set_func); - fprintf(fout, "0x%lx\n", rs->has_get_level); - fprintf(fout, "0x%lx\n", rs->has_set_level); - fprintf(fout, "0x%lx\n", rs->has_get_parm); - fprintf(fout, "0x%lx\n", rs->has_set_parm); + fprintf(fout, "\n"); + + for (i = 0; i < MAXDBLSTSIZ && rs->attenuator[i]; i++) { + fprintf(fout, "%d ", rs->attenuator[i]); + } + + fprintf(fout, "\n"); + + fprintf(fout, "0x%lx\n", rs->has_get_func); + fprintf(fout, "0x%lx\n", rs->has_set_func); + fprintf(fout, "0x%lx\n", rs->has_get_level); + fprintf(fout, "0x%lx\n", rs->has_set_level); + fprintf(fout, "0x%lx\n", rs->has_get_parm); + fprintf(fout, "0x%lx\n", rs->has_set_parm); #if 0 - gran_t level_gran[RIG_SETTING_MAX]; /*!< level granularity */ - gran_t parm_gran[RIG_SETTING_MAX]; /*!< parm granularity */ + gran_t level_gran[RIG_SETTING_MAX]; /*!< level granularity */ + gran_t parm_gran[RIG_SETTING_MAX]; /*!< parm granularity */ #endif - return RIG_OK; + return RIG_OK; } + /* '3' */ declare_proto_rig(dump_conf) { - dumpconf(rig, fout); + dumpconf(rig, fout); - return RIG_OK; + return RIG_OK; } + /* 'Y' */ declare_proto_rig(set_ant) { - ant_t ant; + ant_t ant; - CHKSCN1ARG(sscanf(arg1, "%d", &ant)); - return rig_set_ant(rig, vfo, rig_idx2setting(ant)); + CHKSCN1ARG(sscanf(arg1, "%d", &ant)); + return rig_set_ant(rig, vfo, rig_idx2setting(ant)); } + /* 'y' */ declare_proto_rig(get_ant) { - int status; - ant_t ant; + int status; + ant_t ant; - status = rig_get_ant(rig, vfo, &ant); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%d%c", rig_setting2idx(ant), resp_sep); + status = rig_get_ant(rig, vfo, &ant); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%d%c", rig_setting2idx(ant), resp_sep); + + return status; } + /* '*' */ declare_proto_rig(reset) { - int reset; + int reset; - CHKSCN1ARG(sscanf(arg1, "%d", &reset)); - return rig_reset(rig, (reset_t) reset); + CHKSCN1ARG(sscanf(arg1, "%d", &reset)); + return rig_reset(rig, (reset_t) reset); } + /* 'b' */ declare_proto_rig(send_morse) { - return rig_send_morse(rig, vfo, arg1); + return rig_send_morse(rig, vfo, arg1); } + declare_proto_rig(send_dtmf) { - return rig_send_dtmf(rig, vfo, arg1); + return rig_send_dtmf(rig, vfo, arg1); } + declare_proto_rig(recv_dtmf) { - int status; - int len; - char digits[MAXARGSZ]; + int status; + int len; + char digits[MAXARGSZ]; - len = MAXARGSZ-1; - status = rig_recv_dtmf(rig, vfo, digits, &len); - if (status != RIG_OK) - return status; - if (interactive && prompt) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%s\n", digits); + len = MAXARGSZ - 1; + status = rig_recv_dtmf(rig, vfo, digits, &len); - return status; + if (status != RIG_OK) { + return status; + } + + if (interactive && prompt) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%s\n", digits); + + return status; } + /* '0x87' */ declare_proto_rig(set_powerstat) { - int stat; + int stat; - CHKSCN1ARG(sscanf(arg1, "%d", &stat)); - return rig_set_powerstat(rig, (powerstat_t) stat); + CHKSCN1ARG(sscanf(arg1, "%d", &stat)); + return rig_set_powerstat(rig, (powerstat_t) stat); } + /* '0x88' */ declare_proto_rig(get_powerstat) { - int status; - powerstat_t stat; + int status; + powerstat_t stat; - status = rig_get_powerstat(rig, &stat); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%d\n", stat); + status = rig_get_powerstat(rig, &stat); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%d\n", stat); + + return status; } + /* - * special debugging purpose send command - * display reply until there's a timeout + * Special debugging purpose send command display reply until there's a + * timeout. * * 'w' */ declare_proto_rig(send_cmd) { - int retval; - struct rig_state *rs; - int backend_num, cmd_len; + int retval; + struct rig_state *rs; + int backend_num, cmd_len; #define BUFSZ 128 - char bufcmd[BUFSZ]; - char buf[BUFSZ]; - char eom_buf[4] = { 0xa, 0xd, 0, 0 }; + char bufcmd[BUFSZ]; + char buf[BUFSZ]; + char eom_buf[4] = { 0xa, 0xd, 0, 0 }; - /* - * binary protocols enter values as \0xZZ\0xYY.. - */ - backend_num = RIG_BACKEND_NUM(rig->caps->rig_model); - if (send_cmd_term == -1 || - backend_num == RIG_YAESU || - backend_num == RIG_ICOM || - backend_num == RIG_KACHINA || - backend_num == RIG_MICROTUNE) { - const char *p = arg1, *pp = NULL; - int i; - for (i=0; i < BUFSZ-1 && p != pp; i++) { - pp = p+1; - bufcmd[i] = strtol(p+1, (char **) &p, 0); - } - /* must save length to allow 0x00 to be sent as part of a command - */ - cmd_len = i-1; + /* + * binary protocols enter values as \0xZZ\0xYY.. + */ + backend_num = RIG_BACKEND_NUM(rig->caps->rig_model); - /* no End Of Message chars */ - eom_buf[0] = '\0'; - } else { - /* text protocol */ + if (send_cmd_term == -1 + || backend_num == RIG_YAESU + || backend_num == RIG_ICOM + || backend_num == RIG_KACHINA + || backend_num == RIG_MICROTUNE) { - strncpy(bufcmd,arg1,BUFSZ); - bufcmd[BUFSZ-2] = '\0'; - cmd_len = strlen(bufcmd); + const char *p = arg1, *pp = NULL; + int i; - /* Automatic termination char */ - if (send_cmd_term != 0) - bufcmd[cmd_len++] = send_cmd_term; - eom_buf[2] = send_cmd_term; - } + for (i = 0; i < BUFSZ - 1 && p != pp; i++) { + pp = p + 1; + bufcmd[i] = strtol(p + 1, (char **) &p, 0); + } - rs = &rig->state; + /* must save length to allow 0x00 to be sent as part of a command */ + cmd_len = i - 1; - serial_flush(&rs->rigport); + /* no End Of Message chars */ + eom_buf[0] = '\0'; + } else { + /* text protocol */ + strncpy(bufcmd, arg1, BUFSZ); + bufcmd[BUFSZ - 2] = '\0'; + cmd_len = strlen(bufcmd); - retval = write_block(&rs->rigport, bufcmd, cmd_len); - if (retval != RIG_OK) - return retval; + /* Automatic termination char */ + if (send_cmd_term != 0) { + bufcmd[cmd_len++] = send_cmd_term; + } - if (interactive && prompt) - fprintf(fout, "%s: ", cmd->arg2); + eom_buf[2] = send_cmd_term; + } - do { - /* - * assumes CR or LF is end of line char - * for all ascii protocols - */ - retval = read_string(&rs->rigport, buf, BUFSZ, eom_buf, strlen(eom_buf)); - if (retval < 0) - break; + rs = &rig->state; - if (retval < BUFSZ) - buf[retval] = '\0'; - else - buf[BUFSZ-1] = '\0'; + serial_flush(&rs->rigport); - fprintf(fout, "%s\n", buf); + retval = write_block(&rs->rigport, bufcmd, cmd_len); - } while (retval > 0); + if (retval != RIG_OK) { + return retval; + } - if (retval > 0 || retval == -RIG_ETIMEOUT) - retval = RIG_OK; + if (interactive && prompt) { + fprintf(fout, "%s: ", cmd->arg2); + } - return retval; + do { + /* Assumes CR or LF is end of line char for all ASCII protocols. */ + retval = read_string(&rs->rigport, buf, BUFSZ, eom_buf, strlen(eom_buf)); + + if (retval < 0) { + break; + } + + if (retval < BUFSZ) { + buf[retval] = '\0'; + } else { + buf[BUFSZ - 1] = '\0'; + } + + fprintf(fout, "%s\n", buf); + + } while (retval > 0); + + if (retval > 0 || retval == -RIG_ETIMEOUT) { + retval = RIG_OK; + } + + return retval; } + /* '0xf0'--test if rigctld called with -o|--vfo option */ declare_proto_rig(chk_vfo) { - fprintf(fout, "CHKVFO %d\n", vfo_mode); + fprintf(fout, "CHKVFO %d\n", vfo_mode); - return RIG_OK; + return RIG_OK; } + /* '0xf1'--halt rigctld daemon */ declare_proto_rig(halt) { /* a bit rough, TODO: clean daemon shutdown */ exit(0); - return RIG_OK; + return RIG_OK; } + /* '0x8c'--pause processing */ declare_proto_rig(pause) { - unsigned seconds; - CHKSCN1ARG(sscanf(arg1, "%u", &seconds)); - sleep (seconds); - return RIG_OK; + unsigned seconds; + CHKSCN1ARG(sscanf(arg1, "%u", &seconds)); + sleep(seconds); + return RIG_OK; } diff --git a/tests/rigctl_parse.h b/tests/rigctl_parse.h index ce62d3d7b..48a0d14d8 100644 --- a/tests/rigctl_parse.h +++ b/tests/rigctl_parse.h @@ -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 */ diff --git a/tests/rigctld.c b/tests/rigctld.c index c95a99fcb..c9db91659 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -24,7 +24,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "config.h" #endif #include @@ -40,26 +40,29 @@ #include /* See NOTES */ #ifdef HAVE_NETINET_IN_H -# include +# include #endif + #ifdef HAVE_ARPA_INET_H -# include +# include #endif + #ifdef HAVE_SYS_SOCKET_H -# include +# include #elif HAVE_WS2TCPIP_H -# include -# include -# if defined(HAVE_WSPIAPI_H) -# include -# endif +# include +# include +# if defined(HAVE_WSPIAPI_H) +# include +# endif #endif + #ifdef HAVE_NETDB_H -# include +# include #endif #ifdef HAVE_PTHREAD -# include +# include #endif #include @@ -70,45 +73,49 @@ #include "rigctl_parse.h" + /* * 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:t:C:lLuovhV" 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'}, - {"listen-addr", 1, 0, 'T'}, - {"port", 1, 0, 't'}, - {"set-conf", 1, 0, 'C'}, - {"list", 0, 0, 'l'}, - {"show-conf", 0, 0, 'L'}, - {"dump-caps", 0, 0, 'u'}, - {"vfo", 0, 0, 'o'}, - {"verbose", 0, 0, 'v'}, - {"help", 0, 0, 'h'}, - {"version", 0, 0, 'V'}, - {0, 0, 0, 0} + {"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'}, + {"listen-addr", 1, 0, 'T'}, + {"port", 1, 0, 't'}, + {"set-conf", 1, 0, 'C'}, + {"list", 0, 0, 'l'}, + {"show-conf", 0, 0, 'L'}, + {"dump-caps", 0, 0, 'u'}, + {"vfo", 0, 0, 'o'}, + {"verbose", 0, 0, 'v'}, + {"help", 0, 0, 'h'}, + {"version", 0, 0, 'V'}, + {0, 0, 0, 0} }; + struct handle_data { - RIG *rig; - int sock; - struct sockaddr_storage cli_addr; - socklen_t clilen; + RIG *rig; + int sock; + struct sockaddr_storage cli_addr; + socklen_t clilen; }; -void *handle_socket(void *arg); + +void * handle_socket(void *arg); void usage(void); + int interactive = 1; /* no cmd because of daemon */ int prompt = 0; /* Daemon mode for rigparse return string */ int vfo_mode = 0; /* vfo_mode=0 means target VFO is current VFO */ @@ -120,596 +127,648 @@ const char *src_addr = NULL; /* INADDR_ANY */ #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, + 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); + } #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[]) { - RIG *my_rig; /* handle to rig (instance) */ - 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 retcode; /* generic return code from functions */ - int verbose = 0; - int show_conf = 0; - int dump_caps_opt = 0; - 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] = ""; + int verbose = 0; + int show_conf = 0; + int dump_caps_opt = 0; + 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] = ""; - struct addrinfo hints, *result, *saved_result; - int sock_listen; - int sockopt; - int reuseaddr = 1; - char host[NI_MAXHOST]; - char serv[NI_MAXSERV]; + struct addrinfo hints, *result, *saved_result; + int sock_listen; + int sockopt; + int reuseaddr = 1; + 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); + } - rig_file = optarg; - break; + rig_file = optarg; + break; - case 'p': - if (!optarg) { - usage(); /* wrong arg count */ - exit(1); - } + case 'p': + if (!optarg) { + usage(); /* wrong arg count */ + exit(1); + } - ptt_file = optarg; - break; + ptt_file = optarg; + break; - case 'd': - if (!optarg) { - usage(); /* wrong arg count */ - exit(1); - } + case 'd': + if (!optarg) { + usage(); /* wrong arg count */ + exit(1); + } - dcd_file = optarg; - break; + dcd_file = optarg; + break; - case 'P': - if (!optarg) { - usage(); /* wrong arg count */ - exit(1); - } + 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, "NONE")) - ptt_type = RIG_PTT_NONE; - else - ptt_type = atoi(optarg); + 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, "NONE")) { + ptt_type = RIG_PTT_NONE; + } else { + ptt_type = atoi(optarg); + } - break; + break; - case 'D': - if (!optarg) { - usage(); /* wrong arg count */ - exit(1); - } + 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, "NONE")) - dcd_type = RIG_DCD_NONE; - else - dcd_type = atoi(optarg); + 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, "NONE")) { + dcd_type = RIG_DCD_NONE; + } else { + dcd_type = atoi(optarg); + } - break; + break; - case 'c': - if (!optarg) { - usage(); /* wrong arg count */ - exit(1); - } + case 'c': + if (!optarg) { + usage(); /* wrong arg count */ + exit(1); + } - civaddr = optarg; - break; + civaddr = 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 'o': - vfo_mode++; - break; + case 'o': + vfo_mode++; + 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, "rigctld, %s\n", hamlib_version); - rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to " - "\n\n"); + rig_debug(RIG_DEBUG_VERBOSE, "rigctld, %s\n", hamlib_version); + rig_debug(RIG_DEBUG_VERBOSE, + "Report bugs to \n\n"); - my_rig = rig_init(my_model); + my_rig = rig_init(my_model); - 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); - } + if (!my_rig) { + fprintf(stderr, + "Unknown rig num %d, or initialization error.\n", + my_model); - retcode = set_conf(my_rig, 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_rig, conf_parms); - if (rig_file) - strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); + if (retcode != RIG_OK) { + fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); + exit(2); + } - /* - * ex: RIG_PTT_PARALLEL and /dev/parport0 - */ - if (ptt_type != RIG_PTT_NONE) - my_rig->state.pttport.type.ptt = ptt_type; + if (rig_file) { + strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); + } - if (dcd_type != RIG_DCD_NONE) - my_rig->state.dcdport.type.dcd = dcd_type; + /* + * ex: RIG_PTT_PARALLEL and /dev/parport0 + */ + if (ptt_type != RIG_PTT_NONE) { + my_rig->state.pttport.type.ptt = ptt_type; + } - if (ptt_file) - strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1); + if (dcd_type != RIG_DCD_NONE) { + my_rig->state.dcdport.type.dcd = dcd_type; + } - if (dcd_file) - strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1); + if (ptt_file) { + strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1); + } - /* FIXME: bound checking and port type == serial */ - if (serial_rate != 0) - my_rig->state.rigport.parm.serial.rate = serial_rate; + if (dcd_file) { + strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1); + } - if (civaddr) - rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr); + /* FIXME: bound checking and port type == serial */ + if (serial_rate != 0) { + my_rig->state.rigport.parm.serial.rate = serial_rate; + } - /* - * print out conf parameters - */ - if (show_conf) { - rig_token_foreach(my_rig, print_conf_list, (rig_ptr_t)my_rig); - } + if (civaddr) { + rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr); + } - /* - * 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(my_rig, stdout); - rig_cleanup(my_rig); /* if you care about memory */ - exit(0); - } + /* + * print out conf parameters + */ + if (show_conf) { + rig_token_foreach(my_rig, print_conf_list, (rig_ptr_t)my_rig); + } - retcode = rig_open(my_rig); + /* + * 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(my_rig, stdout); + rig_cleanup(my_rig); /* if you care about memory */ + exit(0); + } - if (retcode != RIG_OK) { - fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode)); - exit(2); - } + retcode = rig_open(my_rig); - if (verbose > 0) - printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model, - my_rig->caps->model_name); + if (retcode != RIG_OK) { + fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode)); + exit(2); + } - rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n", - my_rig->caps->version, rig_strstatus(my_rig->caps->status)); + 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)); #ifdef __MINGW32__ -# ifndef SO_OPENTYPE -# define SO_OPENTYPE 0x7008 -# endif -# ifndef SO_SYNCHRONOUS_NONALERT -# define SO_SYNCHRONOUS_NONALERT 0x20 -# endif -# ifndef INVALID_SOCKET -# define INVALID_SOCKET -1 -# endif +# ifndef SO_OPENTYPE +# define SO_OPENTYPE 0x7008 +# endif +# ifndef SO_SYNCHRONOUS_NONALERT +# define SO_SYNCHRONOUS_NONALERT 0x20 +# endif +# ifndef INVALID_SOCKET +# define INVALID_SOCKET -1 +# endif - WSADATA wsadata; + 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(saved_result); /* No longer needed */ - exit(2); - } + if (sock_listen < 0) { + handle_error(RIG_DEBUG_ERR, "socket"); + freeaddrinfo(saved_result); /* No longer needed */ + exit(2); + } - if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR, - (char *)&reuseaddr, sizeof(reuseaddr)) < 0) { - handle_error(RIG_DEBUG_ERR, "setsockopt"); - freeaddrinfo(saved_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(saved_result); /* No longer needed */ + exit(1); + } #ifdef IPV6_V6ONLY - if (AF_INET6 == result->ai_family) { - /* allow IPv4 mapped to IPv6 clients Windows and BSD default - this to 1 (i.e. disallowed) and we prefer it off */ - sockopt = 0; + if (AF_INET6 == result->ai_family) { + /* allow IPv4 mapped to IPv6 clients Windows and BSD default + this to 1 (i.e. disallowed) and we prefer it off */ + sockopt = 0; - 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->rig = my_rig; - arg->clilen = sizeof(arg->cli_addr); - arg->sock = accept(sock_listen, (struct sockaddr *)&arg->cli_addr, &arg->clilen); + arg->rig = my_rig; + 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); - 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 */ #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); + if (!fsockout) { + rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); + fclose(fsockin); - goto handle_exit; - } + goto handle_exit; + } - do { - retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0); + do { + retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0); - if (ferror(fsockin) || ferror(fsockout)) - retcode = 1; - } while (retcode == 0 || retcode == 2 || retcode==-RIG_ENAVAIL); + if (ferror(fsockin) || ferror(fsockout)) { + retcode = 1; + } + } while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL); - 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(void) { - printf("Usage: rigctld [OPTION]...\n" - "Daemon serving COMMANDs to a connected radio transceiver or receiver.\n\n"); + printf("Usage: rigctld [OPTION]...\n" + "Daemon serving 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, --port=NUM set TCP listening port, default %s\n" - " -T, --listen-addr=IPADDR set listening IP address, default ANY\n" - " -C, --set-conf=PARM=VAL set config parameters\n" - " -L, --show-conf list all config parameters\n" - " -l, --list list all model numbers and exit\n" - " -u, --dump-caps dump capabilities and exit\n" - " -o, --vfo do not default to VFO_CURR, require extra vfo arg\n" - " -v, --verbose set verbose mode, cumulative\n" - " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n\n", - portno); + printf( + " -m, --model=ID select radio model number. See model list\n" + " -r, --rig-file=DEVICE set device of the radio to operate on\n" + " -p, --ptt-file=DEVICE set device of the PTT device to operate on\n" + " -d, --dcd-file=DEVICE set device of the DCD device to operate on\n" + " -P, --ptt-type=TYPE set type of the PTT device to operate on\n" + " -D, --dcd-type=TYPE set type of the DCD device to operate on\n" + " -s, --serial-speed=BAUD set serial speed of the serial port\n" + " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" + " -t, --port=NUM set TCP listening port, default %s\n" + " -T, --listen-addr=IPADDR set listening IP address, default ANY\n" + " -C, --set-conf=PARM=VAL set config parameters\n" + " -L, --show-conf list all config parameters\n" + " -l, --list list all model numbers and exit\n" + " -u, --dump-caps dump capabilities and exit\n" + " -o, --vfo do not default to VFO_CURR, require extra vfo arg\n" + " -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n" + " -h, --help display this help and exit\n" + " -V, --version output version information and exit\n\n", + portno); - usage_rig(stdout); + usage_rig(stdout); - printf("\nReport bugs to .\n"); + printf("\nReport bugs to .\n"); } diff --git a/tests/rigmatrix.c b/tests/rigmatrix.c index 1a817bd1c..bbc11192c 100644 --- a/tests/rigmatrix.c +++ b/tests/rigmatrix.c @@ -34,152 +34,180 @@ static setting_t bitmap_func, bitmap_level, bitmap_parm; -int create_png_range(const freq_range_t rx_range_list[], const freq_range_t tx_range_list[], int num); +int create_png_range(const freq_range_t rx_range_list[], + const freq_range_t tx_range_list[], int num); int print_caps_sum(const struct rig_caps *caps, void *data) { - printf("%s%s" - "%s%s", - caps->rig_model, - caps->model_name,caps->mfg_name,caps->version, - rig_strstatus(caps->status) - ); + printf("%s%s" + "%s%s", + caps->rig_model, + caps->model_name, + caps->mfg_name, + caps->version, + rig_strstatus(caps->status)); - switch (caps->rig_type & RIG_TYPE_MASK) { - case RIG_TYPE_TRANSCEIVER: - printf("Transceiver"); - break; - case RIG_TYPE_HANDHELD: - printf("Handheld"); - break; - case RIG_TYPE_MOBILE: - printf("Mobile"); - break; - case RIG_TYPE_RECEIVER: - printf("Receiver"); - break; - case RIG_TYPE_PCRECEIVER: - printf("PC Receiver"); - break; - case RIG_TYPE_SCANNER: - printf("Scanner"); - break; - case RIG_TYPE_TRUNKSCANNER: - printf("Trunking scanner"); - break; - case RIG_TYPE_COMPUTER: - printf("Computer"); - break; - case RIG_TYPE_OTHER: - printf("Other"); - break; - default: - printf("Unknown"); - } - printf("range" - "parms" - "caps" - "funcs" - "funcs" - "levels" - "levels" - "parms" - "parms" - "\n", - caps->rig_model, caps->rig_model, caps->rig_model, - caps->rig_model, caps->rig_model, caps->rig_model, - caps->rig_model, caps->rig_model, caps->rig_model - ); + switch (caps->rig_type & RIG_TYPE_MASK) { + case RIG_TYPE_TRANSCEIVER: + printf("Transceiver"); + break; - return 1; /* !=0, we want them all ! */ + case RIG_TYPE_HANDHELD: + printf("Handheld"); + break; + + case RIG_TYPE_MOBILE: + printf("Mobile"); + break; + + case RIG_TYPE_RECEIVER: + printf("Receiver"); + break; + + case RIG_TYPE_PCRECEIVER: + printf("PC Receiver"); + break; + + case RIG_TYPE_SCANNER: + printf("Scanner"); + break; + + case RIG_TYPE_TRUNKSCANNER: + printf("Trunking scanner"); + break; + + case RIG_TYPE_COMPUTER: + printf("Computer"); + break; + + case RIG_TYPE_OTHER: + printf("Other"); + break; + + default: + printf("Unknown"); + } + + printf("range" + "parms" + "caps" + "funcs" + "funcs" + "levels" + "levels" + "parms" + "parms" + "\n", + caps->rig_model, caps->rig_model, caps->rig_model, + caps->rig_model, caps->rig_model, caps->rig_model, + caps->rig_model, caps->rig_model, caps->rig_model); + + return 1; /* !=0, we want them all ! */ } + /* * IO params et al. */ int print_caps_parameters(const struct rig_caps *caps, void *data) { - printf("%s", - caps->rig_model, - caps->model_name); + printf("%s", + caps->rig_model, + caps->model_name); - switch (caps->ptt_type) { - case RIG_PTT_RIG: - printf("rig"); - break; - case RIG_PTT_PARALLEL: - printf("parallel"); - break; - case RIG_PTT_SERIAL_RTS: - case RIG_PTT_SERIAL_DTR: - printf("serial"); - break; - case RIG_PTT_NONE: - printf("None"); - break; - default: - printf("Unknown"); - } + switch (caps->ptt_type) { + case RIG_PTT_RIG: + printf("rig"); + break; - printf(""); + case RIG_PTT_PARALLEL: + printf("parallel"); + break; - switch (caps->dcd_type) { - case RIG_DCD_RIG: - printf("rig"); - break; - case RIG_DCD_PARALLEL: - printf("parallel"); - break; - case RIG_DCD_SERIAL_CTS: - case RIG_DCD_SERIAL_DSR: - printf("serial"); - break; - case RIG_DCD_NONE: - printf("None"); - break; - default: - printf("Unknown"); - } + case RIG_PTT_SERIAL_RTS: + case RIG_PTT_SERIAL_DTR: + printf("serial"); + break; - printf(""); + case RIG_PTT_NONE: + printf("None"); + break; - switch (caps->port_type) { - case RIG_PORT_SERIAL: - printf("serial"); - break; - case RIG_PORT_DEVICE: - printf("device"); - break; - case RIG_PORT_NETWORK: - printf("network"); - break; - case RIG_PORT_UDP_NETWORK: - printf("UDP network"); - break; - case RIG_PORT_NONE: - printf("None"); - break; - default: - printf("Unknown"); - } + default: + printf("Unknown"); + } - printf("%d%d%d%c%d%s", - 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?"none": - (caps->serial_handshake==RIG_HANDSHAKE_XONXOFF?"XONXOFF":"CTS/RTS") - ); + printf(""); - printf("%dms%dms%dms%d\n", - caps->write_delay, caps->post_write_delay, - caps->timeout, caps->retry); - return 1; + switch (caps->dcd_type) { + case RIG_DCD_RIG: + printf("rig"); + break; + + case RIG_DCD_PARALLEL: + printf("parallel"); + break; + + case RIG_DCD_SERIAL_CTS: + case RIG_DCD_SERIAL_DSR: + printf("serial"); + break; + + case RIG_DCD_NONE: + printf("None"); + break; + + default: + printf("Unknown"); + } + + printf(""); + + switch (caps->port_type) { + case RIG_PORT_SERIAL: + printf("serial"); + break; + + case RIG_PORT_DEVICE: + printf("device"); + break; + + case RIG_PORT_NETWORK: + printf("network"); + break; + + case RIG_PORT_UDP_NETWORK: + printf("UDP network"); + break; + + case RIG_PORT_NONE: + printf("None"); + break; + + default: + printf("Unknown"); + } + + printf("%d%d%d%c%d%s", + 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 ? "none" : + (caps->serial_handshake == RIG_HANDSHAKE_XONXOFF ? "XONXOFF" : "CTS/RTS")); + + printf("%dms%dms%dms%d\n", + caps->write_delay, + caps->post_write_delay, + caps->timeout, + caps->retry); + + return 1; } /* used by print_caps_caps and print_caps_level */ @@ -192,136 +220,148 @@ int print_caps_parameters(const struct rig_caps *caps, void *data) */ int print_caps_caps(const struct rig_caps *caps, void *data) { - printf("%s", - caps->rig_model, - caps->model_name); + printf("%s", + caps->rig_model, + caps->model_name); - /* targetable_vfo is not a function, but a boolean */ - print_yn(caps->targetable_vfo); + /* targetable_vfo is not a function, but a boolean */ + print_yn(caps->targetable_vfo); - print_yn(caps->set_freq); - print_yn(caps->get_freq); - print_yn(caps->set_mode); - print_yn(caps->get_mode); - print_yn(caps->set_vfo); - print_yn(caps->get_vfo); - print_yn(caps->set_ptt); - print_yn(caps->get_ptt); - print_yn(caps->get_dcd); - print_yn(caps->set_rptr_shift); - print_yn(caps->get_rptr_shift); - print_yn(caps->set_rptr_offs); - print_yn(caps->get_rptr_offs); - print_yn(caps->set_split_freq); - print_yn(caps->get_split_freq); - print_yn(caps->set_split_vfo); - print_yn(caps->get_split_vfo); - print_yn(caps->set_ts); - print_yn(caps->get_ts); - print_yn(caps->set_ctcss_tone); - print_yn(caps->get_ctcss_tone); - print_yn(caps->set_dcs_code); - print_yn(caps->get_dcs_code); - print_yn(caps->set_powerstat); - print_yn(caps->get_powerstat); - print_yn(caps->set_trn); - print_yn(caps->set_trn); - print_yn(caps->decode_event); - print_yn(caps->get_info); + print_yn(caps->set_freq); + print_yn(caps->get_freq); + print_yn(caps->set_mode); + print_yn(caps->get_mode); + print_yn(caps->set_vfo); + print_yn(caps->get_vfo); + print_yn(caps->set_ptt); + print_yn(caps->get_ptt); + print_yn(caps->get_dcd); + print_yn(caps->set_rptr_shift); + print_yn(caps->get_rptr_shift); + print_yn(caps->set_rptr_offs); + print_yn(caps->get_rptr_offs); + print_yn(caps->set_split_freq); + print_yn(caps->get_split_freq); + print_yn(caps->set_split_vfo); + print_yn(caps->get_split_vfo); + print_yn(caps->set_ts); + print_yn(caps->get_ts); + print_yn(caps->set_ctcss_tone); + print_yn(caps->get_ctcss_tone); + print_yn(caps->set_dcs_code); + print_yn(caps->get_dcs_code); + print_yn(caps->set_powerstat); + print_yn(caps->get_powerstat); + print_yn(caps->set_trn); + print_yn(caps->set_trn); + print_yn(caps->decode_event); + print_yn(caps->get_info); - printf("\n"); + printf("\n"); - return 1; + return 1; } + /* * Get/Set parm abilities */ int print_caps_parm(const struct rig_caps *caps, void *data) { - setting_t parm; - int i; + setting_t parm; + int i; - if (!data) - return 0; + if (!data) { + return 0; + } - parm = (*(int*)data)? caps->has_set_parm : caps->has_get_parm; + parm = (*(int *)data) ? caps->has_set_parm : caps->has_get_parm; - printf("%s", - (*(int*)data)? "set":"get", - caps->rig_model, - caps->model_name); + printf("%s", + (*(int *)data) ? "set" : "get", + caps->rig_model, + caps->model_name); - /* - * bitmap_parm: only those who have a label - */ - for (i = 0; i < RIG_SETTING_MAX; i++) { - if (rig_idx2setting(i) & bitmap_parm) - print_yn(parm & rig_idx2setting(i)); - } - printf("\n"); + /* + * bitmap_parm: only those who have a label + */ + for (i = 0; i < RIG_SETTING_MAX; i++) { + if (rig_idx2setting(i) & bitmap_parm) { + print_yn(parm & rig_idx2setting(i)); + } + } - return 1; + printf("\n"); + + return 1; } + /* * Get/Set level abilities */ int print_caps_level(const struct rig_caps *caps, void *data) { - setting_t level; - int i; + setting_t level; + int i; - if (!data) - return 0; + if (!data) { + return 0; + } - level = (*(int*)data)? caps->has_set_level : caps->has_get_level; + level = (*(int *)data) ? caps->has_set_level : caps->has_get_level; - printf("%s", - (*(int*)data)? "set":"get", - caps->rig_model, - caps->model_name); + printf("%s", + (*(int *)data) ? "set" : "get", + caps->rig_model, + caps->model_name); - /* - * bitmap_level: only those who have a label - */ - for (i = 0; i < 32; i++) { - if (rig_idx2setting(i) & bitmap_level) - print_yn(level & rig_idx2setting(i)); - } - printf("\n"); + /* + * bitmap_level: only those who have a label + */ + for (i = 0; i < 32; i++) { + if (rig_idx2setting(i) & bitmap_level) { + print_yn(level & rig_idx2setting(i)); + } + } - return 1; + printf("\n"); + + return 1; } + /* * Get/Set func abilities */ int print_caps_func(const struct rig_caps *caps, void *data) { - setting_t func; - int i; + setting_t func; + int i; - if (!data) - return 0; + if (!data) { + return 0; + } - func = (*(int*)data)? caps->has_set_func : caps->has_get_func; + func = (*(int *)data) ? caps->has_set_func : caps->has_get_func; - printf("%s", - (*(int*)data)? "set":"get", - caps->rig_model, - caps->model_name); + printf("%s", + (*(int *)data) ? "set" : "get", + caps->rig_model, + caps->model_name); - /* - * bitmap_func: only those who have a label - */ - for (i = 0; i < RIG_SETTING_MAX; i++) { - if (rig_idx2setting(i) & bitmap_func) - print_yn(func & rig_idx2setting(i)); - } - printf("\n"); + /* + * bitmap_func: only those who have a label + */ + for (i = 0; i < RIG_SETTING_MAX; i++) { + if (rig_idx2setting(i) & bitmap_func) { + print_yn(func & rig_idx2setting(i)); + } + } - return 1; + printf("\n"); + + return 1; } @@ -332,17 +372,18 @@ int print_caps_func(const struct rig_caps *caps, void *data) */ int print_caps_range(const struct rig_caps *caps, void *data) { - create_png_range(caps->rx_range_list2, caps->tx_range_list2, - caps->rig_model); + create_png_range(caps->rx_range_list2, caps->tx_range_list2, + caps->rig_model); - printf("%s" - "", - caps->rig_model, - caps->model_name, - caps->rig_model); - return 1; + printf("%s" + "", + caps->rig_model, + caps->model_name, + caps->rig_model); + return 1; } + #define RANGE_WIDTH 600 #define RANGE_HEIGHT 16 #define RANGE_MIDHEIGHT (RANGE_HEIGHT/2) @@ -359,294 +400,381 @@ int print_caps_range(const struct rig_caps *caps, void *data) #define UHF_H 50 #define IM_LGD 21 -static void draw_range(const freq_range_t range_list[], gdImagePtr im_rng, int h1, int h2, int rgb) + +static void draw_range(const freq_range_t range_list[], + gdImagePtr im_rng, + int h1, + int h2, + int rgb) { - int i; + int i; - for (i=0; i= RANGE_WIDTH) - end_pix = RANGE_WIDTH-1; + /* + * HF + */ + if (range_list[i].start < MHz(30)) { + start_pix = start_pix / MHz(30) * RANGE_WIDTH; + end_pix = end_pix / MHz(30) * RANGE_WIDTH; - start_pix += IM_LGD; - end_pix += IM_LGD; - gdImageFilledRectangle(im_rng, start_pix, HF_H+h1, end_pix, HF_H+h2, rgb); - } + if (end_pix >= RANGE_WIDTH) { + end_pix = RANGE_WIDTH - 1; + } - /* - * VHF - */ - start_pix = range_list[i].start; - end_pix = range_list[i].end; - if ((range_list[i].start > MHz(30) && range_list[i].start < MHz(300)) - || (range_list[i].start < MHz(30) && range_list[i].end > MHz(30))) { - start_pix = (start_pix-MHz(30)) / MHz(300) * RANGE_WIDTH; - end_pix = (end_pix-MHz(30)) / MHz(300) * RANGE_WIDTH; - if (start_pix < 0) - start_pix = 0; - if (end_pix >= RANGE_WIDTH) - end_pix = RANGE_WIDTH-1; + start_pix += IM_LGD; + end_pix += IM_LGD; + gdImageFilledRectangle(im_rng, + start_pix, + HF_H + h1, + end_pix, + HF_H + h2, + rgb); + } - start_pix += IM_LGD; - end_pix += IM_LGD; - gdImageFilledRectangle(im_rng, start_pix, VHF_H+h1, end_pix, VHF_H+h2, rgb); - } + /* + * VHF + */ + start_pix = range_list[i].start; + end_pix = range_list[i].end; - /* - * UHF - */ - start_pix = range_list[i].start; - end_pix = range_list[i].end; - if ((range_list[i].start > MHz(300) && range_list[i].start < GHz(3)) - || (range_list[i].start < MHz(300) && range_list[i].end > MHz(300))) { - start_pix = (start_pix-MHz(300)) / GHz(3) * RANGE_WIDTH; - end_pix = (end_pix-MHz(300)) / GHz(3) * RANGE_WIDTH; - if (start_pix < 0) - start_pix = 0; - if (end_pix >= RANGE_WIDTH) - end_pix = RANGE_WIDTH-1; + if ((range_list[i].start > MHz(30) && range_list[i].start < MHz(300)) + || (range_list[i].start < MHz(30) + && range_list[i].end > MHz(30))) { - start_pix += IM_LGD; - end_pix += IM_LGD; - gdImageFilledRectangle(im_rng, start_pix, UHF_H+h1, end_pix, UHF_H+h2, rgb); - } + start_pix = (start_pix - MHz(30)) / MHz(300) * RANGE_WIDTH; + end_pix = (end_pix - MHz(30)) / MHz(300) * RANGE_WIDTH; - } + if (start_pix < 0) { + start_pix = 0; + } + + if (end_pix >= RANGE_WIDTH) { + end_pix = RANGE_WIDTH - 1; + } + + start_pix += IM_LGD; + end_pix += IM_LGD; + gdImageFilledRectangle(im_rng, + start_pix, + VHF_H + h1, + end_pix, + VHF_H + h2, + rgb); + } + + /* + * UHF + */ + start_pix = range_list[i].start; + end_pix = range_list[i].end; + + if ((range_list[i].start > MHz(300) && range_list[i].start < GHz(3)) + || (range_list[i].start < MHz(300) + && range_list[i].end > MHz(300))) { + + start_pix = (start_pix - MHz(300)) / GHz(3) * RANGE_WIDTH; + end_pix = (end_pix - MHz(300)) / GHz(3) * RANGE_WIDTH; + + if (start_pix < 0) { + start_pix = 0; + } + + if (end_pix >= RANGE_WIDTH) { + end_pix = RANGE_WIDTH - 1; + } + + start_pix += IM_LGD; + end_pix += IM_LGD; + gdImageFilledRectangle(im_rng, + start_pix, + UHF_H + h1, + end_pix, + UHF_H + h2, + rgb); + } + + } } + int create_png_range(const freq_range_t rx_range_list[], - const freq_range_t tx_range_list[], int num) + const freq_range_t tx_range_list[], + int num) { - FILE *out; + FILE *out; - /* Input and output images */ - gdImagePtr im_rng; - char rng_fname[128]; + /* Input and output images */ + gdImagePtr im_rng; + char rng_fname[128]; - /* Color indexes */ - int white, black; - int rx_rgb,tx_rgb; + /* Color indexes */ +#if 0 + int white; +#endif + int black; + int rx_rgb, tx_rgb; - /* Create output image, x by y pixels. */ - im_rng = gdImageCreate(RANGE_WIDTH+IM_LGD, UHF_H+RANGE_HEIGHT); + /* Create output image, x by y pixels. */ + im_rng = gdImageCreate(RANGE_WIDTH + IM_LGD, UHF_H + RANGE_HEIGHT); - /* First color allocated is background. */ - white = gdImageColorAllocate(im_rng, 255, 255, 255); - black = gdImageColorAllocate(im_rng, 0, 0, 0); + /* First color allocated is background. */ +// white = gdImageColorAllocate(im_rng, 255, 255, 255); + gdImageColorAllocate(im_rng, 255, 255, 255); + black = gdImageColorAllocate(im_rng, 0, 0, 0); #if 0 - /* Set transparent color. */ - gdImageColorTransparent(im_rng, white); + /* Set transparent color. */ + gdImageColorTransparent(im_rng, white); #endif - /* Try to load demoin.png and paste part of it into the - output image. */ + /* Try to load demoin.png and paste part of it into the + output image. */ - tx_rgb = gdImageColorAllocate(im_rng, TX_R, TX_G, TX_B); - rx_rgb = gdImageColorAllocate(im_rng, RX_R, RX_G, RX_B); + tx_rgb = gdImageColorAllocate(im_rng, TX_R, TX_G, TX_B); + rx_rgb = gdImageColorAllocate(im_rng, RX_R, RX_G, RX_B); - draw_range(rx_range_list, im_rng, 0, RANGE_MIDHEIGHT-1, rx_rgb); - draw_range(tx_range_list, im_rng, RANGE_MIDHEIGHT, RANGE_HEIGHT-1, tx_rgb); + draw_range(rx_range_list, im_rng, 0, RANGE_MIDHEIGHT - 1, rx_rgb); + draw_range(tx_range_list, im_rng, RANGE_MIDHEIGHT, RANGE_HEIGHT - 1, tx_rgb); - gdImageRectangle(im_rng, IM_LGD, HF_H, IM_LGD+RANGE_WIDTH-1, HF_H+RANGE_HEIGHT-1, black); - gdImageRectangle(im_rng, IM_LGD, VHF_H, IM_LGD+RANGE_WIDTH-1, VHF_H+RANGE_HEIGHT-1, black); - gdImageRectangle(im_rng, IM_LGD, UHF_H, IM_LGD+RANGE_WIDTH-1, UHF_H+RANGE_HEIGHT-1, black); + gdImageRectangle(im_rng, + IM_LGD, + HF_H, + IM_LGD + RANGE_WIDTH - 1, + HF_H + RANGE_HEIGHT - 1, + black); - /* gdImageStringUp */ - gdImageString(im_rng, gdFontSmall, 1, HF_H+1, - (unsigned char *) "HF", black); - gdImageString(im_rng, gdFontSmall, 1, VHF_H+1, - (unsigned char *) "VHF", black); - gdImageString(im_rng, gdFontSmall, 1, UHF_H+1, - (unsigned char *) "UHF", black); + gdImageRectangle(im_rng, + IM_LGD, + VHF_H, + IM_LGD + RANGE_WIDTH - 1, + VHF_H + RANGE_HEIGHT - 1, + black); - /* Make output image interlaced (allows "fade in" in some viewers, - and in the latest web browsers) */ - gdImageInterlace(im_rng, 1); + gdImageRectangle(im_rng, + IM_LGD, + UHF_H, + IM_LGD + RANGE_WIDTH - 1, + UHF_H + RANGE_HEIGHT - 1, + black); - sprintf(rng_fname, "range%d.png", num); - out = fopen(rng_fname, "wb"); - /* Write PNG */ - gdImagePng(im_rng, out); - fclose(out); - gdImageDestroy(im_rng); + /* gdImageStringUp */ + gdImageString(im_rng, + gdFontSmall, + 1, + HF_H + 1, + (unsigned char *) "HF", + black); - return 0; + gdImageString(im_rng, + gdFontSmall, + 1, + VHF_H + 1, + (unsigned char *) "VHF", + black); + + gdImageString(im_rng, + gdFontSmall, + 1, + UHF_H + 1, + (unsigned char *) "UHF", + black); + + /* Make output image interlaced (allows "fade in" in some viewers, + and in the latest web browsers) */ + gdImageInterlace(im_rng, 1); + + sprintf(rng_fname, "range%d.png", num); + out = fopen(rng_fname, "wb"); + + /* Write PNG */ + gdImagePng(im_rng, out); + fclose(out); + gdImageDestroy(im_rng); + + return 0; } -int main (int argc, char *argv[]) + +int main(int argc, char *argv[]) { - int status; - time_t gentime; - int set_or_get; - int i; - char *pbuf, prntbuf[512]; + time_t gentime; + int set_or_get; + int i; + char *pbuf, prntbuf[512]; - rig_load_all_backends(); + rig_load_all_backends(); - printf(""); - printf("" - "" - "" - "" - "" - "" - "" - "" - "" - "\n"); - status = rig_list_foreach(print_caps_sum,NULL); - printf("
ModelMfgVers.StatusTypeFreq. rangeParametersCapabilitiesGet funcSet funcGet levelSet levelGet parmSet parm
\n"); + printf(""); + printf("" + "" + "" + "" + "" + "" + "" + "" + "" + "\n"); + rig_list_foreach(print_caps_sum, NULL); + printf("
ModelMfgVers.StatusTypeFreq. rangeParametersCapabilitiesGet funcSet funcGet levelSet levelGet parmSet parm
\n"); - printf("

"); + printf("

"); - printf("\n"); - printf("" - "" - "" - "\n"); - status = rig_list_foreach(print_caps_parameters,NULL); - printf("
ModelPTTDCDPortSpeed minSpeed maxParm.HandshakeWrite delayPost delayTimeoutRetry
\n"); + printf("\n"); + printf("" + "" + "" + "\n"); + rig_list_foreach(print_caps_parameters, NULL); + printf("
ModelPTTDCDPortSpeed minSpeed maxParm.HandshakeWrite delayPost delayTimeoutRetry
\n"); - printf("

"); + printf("

"); - printf("\n"); - printf("\n"); - status = rig_list_foreach(print_caps_range,NULL); - printf("
ModelFreq. range
\n"); + printf("\n"); + printf("\n"); + rig_list_foreach(print_caps_range, NULL); + printf("
ModelFreq. range
\n"); - printf("

"); + printf("

"); - printf("\n"); - printf("" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "\n"); - status = rig_list_foreach(print_caps_caps,NULL); - printf("
ModelTarget VFOSet freqGet freqSet modeGet modeSet VFOGet VFOSet PTTGet PTTGet DCDSet rptr shiftGet rptr shiftSet rptr offsGet rptr offsSet split frqGet split frqSet splitGet splitSet tsGet tsSet CTCSSGet CTCSSSet DCSGet DCSSet Power StatGet Power StatSet trnGet trnDecodeGet info
\n"); + printf("\n"); + printf("" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "\n"); + rig_list_foreach(print_caps_caps, NULL); + printf("
ModelTarget VFOSet freqGet freqSet modeGet modeSet VFOGet VFOSet PTTGet PTTGet DCDSet rptr shiftGet rptr shiftSet rptr offsGet rptr offsSet split frqGet split frqSet splitGet splitSet tsGet tsSet CTCSSGet CTCSSSet DCSGet DCSSet Power StatGet Power StatSet trnGet trnDecodeGet info
\n"); - printf("

"); + printf("

"); - bitmap_func = 0; - prntbuf[0] = '\0'; - pbuf = prntbuf; - for (i = 0; i < RIG_SETTING_MAX; i++) { - setting_t func = rig_idx2setting(i); - const char *s = rig_strfunc(func); - if (!s) - continue; - bitmap_func |= func; - pbuf += sprintf(pbuf, "%s", s); - } + bitmap_func = 0; + prntbuf[0] = '\0'; + pbuf = prntbuf; - printf("Has set func"); - printf("\n"); - printf("%s\n", prntbuf); - set_or_get = 1; - status = rig_list_foreach(print_caps_func,&set_or_get); - printf("
Model
\n"); + for (i = 0; i < RIG_SETTING_MAX; i++) { + setting_t func = rig_idx2setting(i); + const char *s = rig_strfunc(func); - printf("

"); + if (!s) { + continue; + } - printf("Has get func"); - printf("\n"); - printf("%s\n", prntbuf); - set_or_get = 0; - status = rig_list_foreach(print_caps_func,&set_or_get); - printf("
Model
\n"); + bitmap_func |= func; + pbuf += sprintf(pbuf, "%s", s); + } - printf("

"); + printf("Has set func"); + printf("\n"); + printf("%s\n", prntbuf); + set_or_get = 1; + rig_list_foreach(print_caps_func, &set_or_get); + printf("
Model
\n"); - bitmap_level = 0; - prntbuf[0] = '\0'; - pbuf = prntbuf; - for (i = 0; i < RIG_SETTING_MAX; i++) { - setting_t level = rig_idx2setting(i); - const char *s = rig_strlevel(level); - if (!s) - continue; - bitmap_level |= level; - pbuf += sprintf(pbuf, "%s", s); - } + printf("

"); - printf("Set level"); - printf("\n"); - printf("%s\n", prntbuf); - set_or_get = 1; - status = rig_list_foreach(print_caps_level,&set_or_get); - printf("
Model
\n"); + printf("Has get func"); + printf("\n"); + printf("%s\n", prntbuf); + set_or_get = 0; + rig_list_foreach(print_caps_func, &set_or_get); + printf("
Model
\n"); - printf("

"); + printf("

"); - printf("Get level"); - printf("\n"); - printf("%s\n", prntbuf); - set_or_get = 0; - status = rig_list_foreach(print_caps_level,&set_or_get); - printf("
Model
\n"); + bitmap_level = 0; + prntbuf[0] = '\0'; + pbuf = prntbuf; - printf("

"); + for (i = 0; i < RIG_SETTING_MAX; i++) { + setting_t level = rig_idx2setting(i); + const char *s = rig_strlevel(level); - bitmap_parm = 0; - prntbuf[0] = '\0'; - pbuf = prntbuf; - for (i = 0; i < RIG_SETTING_MAX; i++) { - setting_t parm = rig_idx2setting(i); - const char *s = rig_strparm(parm); - if (!s) - continue; - bitmap_parm |= parm; - pbuf += sprintf(pbuf, "%s", s); - } - printf("Set parm"); - printf("\n"); - printf("%s\n", prntbuf); - set_or_get = 1; - status = rig_list_foreach(print_caps_parm,&set_or_get); - printf("
Model
\n"); + if (!s) { + continue; + } - printf("

"); + bitmap_level |= level; + pbuf += sprintf(pbuf, "%s", s); + } - printf("Get parm"); - printf("\n"); - printf("%s\n", prntbuf); - set_or_get = 0; - status = rig_list_foreach(print_caps_parm,&set_or_get); - printf("
Model
\n"); + printf("Set level"); + printf("\n"); + printf("%s\n", prntbuf); + set_or_get = 1; + rig_list_foreach(print_caps_level, &set_or_get); + printf("
Model
\n"); - printf("

"); + printf("

"); - time(&gentime); - printf("Rigmatrix generated %s by %s\n",ctime(&gentime), getenv("USER")); + printf("Get level"); + printf("\n"); + printf("%s\n", prntbuf); + set_or_get = 0; + rig_list_foreach(print_caps_level, &set_or_get); + printf("
Model
\n"); - printf("\n"); - return 0; + printf("

"); + + bitmap_parm = 0; + prntbuf[0] = '\0'; + pbuf = prntbuf; + + for (i = 0; i < RIG_SETTING_MAX; i++) { + setting_t parm = rig_idx2setting(i); + const char *s = rig_strparm(parm); + + if (!s) { + continue; + } + + bitmap_parm |= parm; + pbuf += sprintf(pbuf, "%s", s); + } + + printf("Set parm"); + printf("\n"); + printf("%s\n", prntbuf); + set_or_get = 1; + rig_list_foreach(print_caps_parm, &set_or_get); + printf("
Model
\n"); + + printf("

"); + + printf("Get parm"); + printf("\n"); + printf("%s\n", prntbuf); + set_or_get = 0; + rig_list_foreach(print_caps_parm, &set_or_get); + printf("
Model
\n"); + + printf("

"); + + time(&gentime); + printf("Rigmatrix generated %s by %s\n", ctime(&gentime), getenv("USER")); + + printf("\n"); + + return 0; } - - diff --git a/tests/rigmem.c b/tests/rigmem.c index 7bd720c59..5d00b2ca5 100644 --- a/tests/rigmem.c +++ b/tests/rigmem.c @@ -23,7 +23,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -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 " - "\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 " + "\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 .\n"); + printf("\nReport bugs to .\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; } - diff --git a/tests/rigsmtr.c b/tests/rigsmtr.c index ab346d60a..2d17db588 100644 --- a/tests/rigsmtr.c +++ b/tests/rigsmtr.c @@ -21,7 +21,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -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 " - "\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 \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 .\n"); + printf("\nReport bugs to .\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; } diff --git a/tests/rigswr.c b/tests/rigswr.c index ef8326024..b6b31a8e3 100644 --- a/tests/rigswr.c +++ b/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 @@ -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 " - "\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 \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 .\n"); + printf("\nReport bugs to .\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; } diff --git a/tests/rotctl.c b/tests/rotctl.c index e3947f9f1..a8c1814c0 100644 --- a/tests/rotctl.c +++ b/tests/rotctl.c @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -42,7 +42,7 @@ # elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */ # include # 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 # 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 " - "\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 \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 .\n"); + printf("\nReport bugs to .\n"); } diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index 9d8e4e425..fe6cd0cba 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -41,7 +41,7 @@ # elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */ # include # else /* !defined(HAVE_READLINE_H) */ -extern char *readline (); +extern char *readline(); # endif /* HAVE_READLINE_H */ #else /* no readline */ @@ -53,18 +53,18 @@ extern char *readline (); # elif defined(HAVE_HISTORY_H) # include # 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) */ - /* no history */ +/* no history */ #endif /* HAVE_READLINE_HISTORY */ - #include #include "serial.h" #include "misc.h" + /* HAVE_SSLEEP is defined when Windows Sleep is found * HAVE_SLEEP is defined when POSIX sleep is found * _WIN32 is defined when compiling with MinGW @@ -97,7 +97,7 @@ static pthread_mutex_t rot_mutex = PTHREAD_MUTEX_INITIALIZER; #define STR(S) STR1(S) #define MAXNAMSIZ 32 -#define MAXNBOPT 100 /* max number of different options */ +#define MAXNBOPT 100 /* max number of different options */ #define MAXARGSZ 127 #define ARG_IN1 0x01 @@ -110,7 +110,7 @@ static pthread_mutex_t rot_mutex = PTHREAD_MUTEX_INITIALIZER; #define ARG_OUT4 0x80 #define ARG_IN_LINE 0x4000 -#define ARG_NONE 0 +#define ARG_NONE 0 #define ARG_IN (ARG_IN1|ARG_IN2|ARG_IN3|ARG_IN4) #define ARG_OUT (ARG_OUT1|ARG_OUT2|ARG_OUT3|ARG_OUT4) @@ -118,7 +118,7 @@ static pthread_mutex_t rot_mutex = PTHREAD_MUTEX_INITIALIZER; #ifdef HAVE_LIBREADLINE static char *input_line = (char *)NULL; static char *result = (char *)NULL; -static char *parsed_input[sizeof(char*) * 7]; +static char *parsed_input[sizeof(char *) * 7]; static const int have_rl = 1; #ifdef HAVE_READLINE_HISTORY @@ -130,25 +130,40 @@ static const int have_rl = 0; #endif struct test_table { - unsigned char cmd; - const char *name; - int (*rot_routine)(ROT*, FILE*, int, const struct test_table*, const char*, - const char*, const char*, const char*, const char*, const char*); - int flags; - const char *arg1; - const char *arg2; - const char *arg3; - const char *arg4; - const char *arg5; - const char *arg6; + unsigned char cmd; + const char *name; + int (*rot_routine)(ROT *, + FILE *, + int, + const struct test_table *, + const char *, + const char *, + const char *, + const char *, + const char *, + const char *); + int flags; + const char *arg1; + const char *arg2; + const char *arg3; + const char *arg4; + const char *arg5; + const char *arg6; }; #define CHKSCN1ARG(a) if ((a) != 1) return -RIG_EINVAL; else do {} while(0) #define ACTION(f) rigctl_##f -#define declare_proto_rot(f) static int (ACTION(f))(ROT *rot, FILE *fout, int interactive, \ - const struct test_table *cmd, const char *arg1, const char *arg2, \ - const char *arg3, const char *arg4, const char *arg5, const char *arg6) +#define declare_proto_rot(f) static int (ACTION(f))(ROT *rot, \ + FILE *fout, \ + int interactive, \ + const struct test_table *cmd, \ + const char *arg1, \ + const char *arg2, \ + const char *arg3, \ + const char *arg4, \ + const char *arg5, \ + const char *arg6) declare_proto_rot(set_position); declare_proto_rot(get_position); @@ -179,98 +194,111 @@ declare_proto_rot(pause); * NB: 'q' 'Q' '?' are reserved by interactive mode interface */ struct test_table test_list[] = { - { 'P', "set_pos", ACTION(set_position), ARG_IN, "Azimuth", "Elevation" }, - { 'p', "get_pos", ACTION(get_position), ARG_OUT, "Azimuth", "Elevation" }, - { 'K', "park", ACTION(park), ARG_NONE, }, - { 'S', "stop", ACTION(stop), ARG_NONE, }, - { 'R', "reset", ACTION(reset), ARG_IN, "Reset" }, - { 'M', "move", ACTION(move), ARG_IN, "Direction", "Speed" }, - { 'C', "set_conf", ACTION(inter_set_conf), ARG_IN, "Token", "Value" }, - { '_', "get_info", ACTION(get_info), ARG_OUT, "Info" }, - { 'w', "send_cmd", ACTION(send_cmd), ARG_IN1|ARG_IN_LINE|ARG_OUT2, "Cmd", "Reply" }, - { '1', "dump_caps", ACTION(dump_caps), }, - { 0x8f,"dump_state",ACTION(dump_state), ARG_OUT }, - { 'L', "lonlat2loc",ACTION(lonlat2loc), ARG_IN1|ARG_IN2|ARG_IN3|ARG_OUT1, "Longitude", "Latitude", "Loc Len [2-12]", "Locator" }, - { 'l', "loc2lonlat",ACTION(loc2lonlat), ARG_IN1|ARG_OUT1|ARG_OUT2, "Locator", "Longitude", "Latitude" }, - { 'D', "dms2dec", ACTION(d_m_s2dec), ARG_IN1|ARG_IN2|ARG_IN3|ARG_IN4|ARG_OUT1, "Degrees", "Minutes", "Seconds", "S/W", "Dec Degrees" }, - { 'd', "dec2dms", ACTION(dec2d_m_s), ARG_IN1|ARG_OUT1|ARG_OUT2|ARG_OUT3|ARG_OUT4, "Dec Degrees", "Degrees", "Minutes", "Seconds", "S/W" }, - { 'E', "dmmm2dec", ACTION(d_mm2dec), ARG_IN1|ARG_IN2|ARG_IN3|ARG_OUT1, "Degrees", "Dec Minutes", "S/W", "Dec Deg" }, - { 'e', "dec2dmmm", ACTION(dec2d_mm), ARG_IN1|ARG_OUT1|ARG_OUT2|ARG_OUT3, "Dec Deg", "Degrees", "Dec Minutes", "S/W" }, - { 'B', "qrb", ACTION(coord2qrb), ARG_IN1|ARG_IN2|ARG_IN3|ARG_IN4|ARG_OUT1|ARG_OUT2, "Lon 1", "Lat 1", "Lon 2", "Lat 2", "QRB Distance", "QRB Azimuth" }, - { 'A', "a_sp2a_lp", ACTION(az_sp2az_lp), ARG_IN1|ARG_OUT1, "Short Path Deg", "Long Path Deg" }, - { 'a', "d_sp2d_lp", ACTION(dist_sp2dist_lp),ARG_IN1|ARG_OUT1, "Short Path km", "Long Path km" }, - { 0x8c, "pause", ACTION(pause), ARG_IN, "Seconds" }, - { 0x00, "", NULL }, + { 'P', "set_pos", ACTION(set_position), ARG_IN, "Azimuth", "Elevation" }, + { 'p', "get_pos", ACTION(get_position), ARG_OUT, "Azimuth", "Elevation" }, + { 'K', "park", ACTION(park), ARG_NONE, }, + { 'S', "stop", ACTION(stop), ARG_NONE, }, + { 'R', "reset", ACTION(reset), ARG_IN, "Reset" }, + { 'M', "move", ACTION(move), ARG_IN, "Direction", "Speed" }, + { 'C', "set_conf", ACTION(inter_set_conf), ARG_IN, "Token", "Value" }, + { '_', "get_info", ACTION(get_info), ARG_OUT, "Info" }, + { 'w', "send_cmd", ACTION(send_cmd), ARG_IN1 | ARG_IN_LINE | ARG_OUT2, "Cmd", "Reply" }, + { '1', "dump_caps", ACTION(dump_caps), }, + { 0x8f, "dump_state", ACTION(dump_state), ARG_OUT }, + { 'L', "lonlat2loc", ACTION(lonlat2loc), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1, "Longitude", "Latitude", "Loc Len [2-12]", "Locator" }, + { 'l', "loc2lonlat", ACTION(loc2lonlat), ARG_IN1 | ARG_OUT1 | ARG_OUT2, "Locator", "Longitude", "Latitude" }, + { 'D', "dms2dec", ACTION(d_m_s2dec), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_IN4 | ARG_OUT1, "Degrees", "Minutes", "Seconds", "S/W", "Dec Degrees" }, + { 'd', "dec2dms", ACTION(dec2d_m_s), ARG_IN1 | ARG_OUT1 | ARG_OUT2 | ARG_OUT3 | ARG_OUT4, "Dec Degrees", "Degrees", "Minutes", "Seconds", "S/W" }, + { 'E', "dmmm2dec", ACTION(d_mm2dec), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1, "Degrees", "Dec Minutes", "S/W", "Dec Deg" }, + { 'e', "dec2dmmm", ACTION(dec2d_mm), ARG_IN1 | ARG_OUT1 | ARG_OUT2 | ARG_OUT3, "Dec Deg", "Degrees", "Dec Minutes", "S/W" }, + { 'B', "qrb", ACTION(coord2qrb), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_IN4 | ARG_OUT1 | ARG_OUT2, "Lon 1", "Lat 1", "Lon 2", "Lat 2", "QRB Distance", "QRB Azimuth" }, + { 'A', "a_sp2a_lp", ACTION(az_sp2az_lp), ARG_IN1 | ARG_OUT1, "Short Path Deg", "Long Path Deg" }, + { 'a', "d_sp2d_lp", ACTION(dist_sp2dist_lp), ARG_IN1 | ARG_OUT1, "Short Path km", "Long Path km" }, + { 0x8c, "pause", ACTION(pause), ARG_IN, "Seconds" }, + { 0x00, "", NULL }, }; + struct test_table *find_cmd_entry(int cmd) { - int i; - for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0x00; i++) - if (test_list[i].cmd == cmd) - break; + int i; - if (i >= MAXNBOPT || test_list[i].cmd == 0x00) - return NULL; + for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0x00; i++) + if (test_list[i].cmd == cmd) { + break; + } - return &test_list[i]; + if (i >= MAXNBOPT || test_list[i].cmd == 0x00) { + return NULL; + } + + return &test_list[i]; } + /* Structure for hash table provided by uthash.h * * Structure and hash funtions patterned after/copied from example.c * distributed with the uthash package. See: http://uthash.sourceforge.net/ */ -struct mod_lst -{ - int id; /* caps->rot_model This is the hash key */ - char mfg_name[32]; /* caps->mfg_name */ - char model_name[32]; /* caps->model_name */ - char version[32]; /* caps->version */ - char status[32]; /* caps->status */ - UT_hash_handle hh; /* makes this structure hashable */ +struct mod_lst { + int id; /* caps->rot_model This is the hash key */ + char mfg_name[32]; /* caps->mfg_name */ + char model_name[32]; /* caps->model_name */ + char version[32]; /* caps->version */ + char status[32]; /* caps->status */ + UT_hash_handle hh; /* makes this structure hashable */ }; + /* Hash declaration. Must be initialized to NULL */ struct mod_lst *models = NULL; /* Add model information to the hash */ -void hash_add_model(int id, const char *mfg_name, const char *model_name, - const char *version, const char *status) +void hash_add_model(int id, + const char *mfg_name, + const char *model_name, + const char *version, + const char *status) { - struct mod_lst *s; + struct mod_lst *s; - s = (struct mod_lst*)malloc(sizeof(struct mod_lst)); + s = (struct mod_lst *)malloc(sizeof(struct mod_lst)); - s->id = id; - snprintf(s->mfg_name, sizeof(s->mfg_name), "%s", mfg_name); - snprintf(s->model_name, sizeof(s->model_name), "%s", model_name); - snprintf(s->version, sizeof(s->version), "%s", version); - snprintf(s->status, sizeof(s->status), "%s", status); + s->id = id; + snprintf(s->mfg_name, sizeof(s->mfg_name), "%s", mfg_name); + snprintf(s->model_name, sizeof(s->model_name), "%s", model_name); + snprintf(s->version, sizeof(s->version), "%s", version); + snprintf(s->status, sizeof(s->status), "%s", status); - HASH_ADD_INT(models, id, s); /* id: name of key field */ + HASH_ADD_INT(models, id, s); /* id: name of key field */ } + /* Hash sorting functions */ int hash_model_id_sort(struct mod_lst *a, struct mod_lst *b) { - return (a->id - b->id); + return (a->id - b->id); } + void hash_sort_by_model_id() { HASH_SORT(models, hash_model_id_sort); } -/* Delete hash */ -void hash_delete_all() { - struct mod_lst *current_model, *tmp; - HASH_ITER(hh, models, current_model, tmp) { - HASH_DEL(models, current_model); /* delete it (models advances to next) */ - free(current_model); /* free it */ - } +/* Delete hash */ +void hash_delete_all() +{ + struct mod_lst *current_model, *tmp; + + HASH_ITER(hh, models, current_model, tmp) { + /* delete it (models advances to next) */ + HASH_DEL(models, current_model); + free(current_model); /* free it */ + } } @@ -280,26 +308,27 @@ void hash_delete_all() { */ static void rp_getline(const char *s) { - int i; + int i; - /* free allocated memory and set pointers to NULL */ - if (input_line) { - free(input_line); - input_line = (char *)NULL; - } + /* free allocated memory and set pointers to NULL */ + if (input_line) { + free(input_line); + input_line = (char *)NULL; + } - if (result) { - result = (char *)NULL; - } + if (result) { + result = (char *)NULL; + } - /* cmd, arg1, arg2, arg3, arg4, arg5, arg6 - * arg5 and arg 6 are currently unused. - */ - for (i = 0; i < 7; i++) - parsed_input[i] = NULL; + /* cmd, arg1, arg2, arg3, arg4, arg5, arg6 + * arg5 and arg 6 are currently unused. + */ + for (i = 0; i < 7; i++) { + parsed_input[i] = NULL; + } - /* Action! Returns typed line with newline stripped. */ - input_line = readline(s); + /* Action! Returns typed line with newline stripped. */ + input_line = readline(s); } @@ -311,32 +340,42 @@ static void rp_getline(const char *s) */ char parse_arg(const char *arg) { - int i; - for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0; i++) - if (!strncmp(arg, test_list[i].name, MAXNAMSIZ)) - return test_list[i].cmd; - return 0; + int i; + + for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0; i++) { + if (!strncmp(arg, test_list[i].name, MAXNAMSIZ)) { + return test_list[i].cmd; + } + } + + return 0; } + /* * This scanf works even in presence of signals (timer, SIGIO, ..) */ static int scanfc(FILE *fin, const char *format, void *p) { - int ret; + int ret; - do { - ret = fscanf(fin, format, p); - if (ret < 0) { - if (errno == EINTR) - continue; - rig_debug(RIG_DEBUG_ERR, "fscanf: %s\n", strerror(errno)); - rig_debug(RIG_DEBUG_ERR, "fscanf: parsing '%s' with '%s'\n", p, format); - } - return ret; - } while(1); + do { + ret = fscanf(fin, format, p); + + if (ret < 0) { + if (errno == EINTR) { + continue; + } + + rig_debug(RIG_DEBUG_ERR, "fscanf: %s\n", strerror(errno)); + rig_debug(RIG_DEBUG_ERR, "fscanf: parsing '%s' with '%s'\n", p, format); + } + + return ret; + } while (1); } + /* * function to get the next word from the command line or from stdin * until stdin exhausted. stdin is read if the special token '-' is @@ -346,70 +385,77 @@ static int scanfc(FILE *fin, const char *format, void *p) * returns <0 is error number * returns >=0 when successful */ -static int next_word (char *buffer, int argc, char *argv[], int newline) +static int next_word(char *buffer, int argc, char *argv[], int newline) { - int ret; - char c; - static int reading_stdin; + int ret; + char c; + static int reading_stdin; - if (!reading_stdin) - { - if (optind >= argc) return EOF; - else if (newline && '-' == argv[optind][0] && 1 == strlen (argv[optind])) - { - ++optind; - reading_stdin = 1; + if (!reading_stdin) { + if (optind >= argc) { + return EOF; + } else if (newline + && '-' == argv[optind][0] + && 1 == strlen(argv[optind])) { + + ++optind; + reading_stdin = 1; } } - if (reading_stdin) - { - do - { - do ret = scanf (" %c%" STR(MAXARGSZ) "[^ \t\n#]", &c, &buffer[1]); while (EINTR == ret); - if (ret > 0 && '#' == c) - { - do ret = scanf ("%*[^\n]"); while (EINTR == ret); /* consume comments */ - ret = 0; + if (reading_stdin) { + do { + do { + ret = scanf(" %c%" STR(MAXARGSZ) "[^ \t\n#]", &c, &buffer[1]); + } while (EINTR == ret); + + if (ret > 0 && '#' == c) { + do { + ret = scanf("%*[^\n]"); + } while (EINTR == ret); /* consume comments */ + + ret = 0; } - } - while (!ret); - if (EOF == ret) reading_stdin = 0; - else if (ret < 0) - { - rig_debug (RIG_DEBUG_ERR, "scanf: %s\n", strerror (errno)); - reading_stdin = 0; - } - else - { - buffer[0] = c; - buffer[1 == ret ? 1 : MAXARGSZ] = '\0'; - if (newline) putchar ('\n'); - fputs (buffer, stdout); - putchar (' '); + } while (!ret); + + if (EOF == ret) { + reading_stdin = 0; + } else if (ret < 0) { + rig_debug(RIG_DEBUG_ERR, "scanf: %s\n", strerror(errno)); + reading_stdin = 0; + } else { + buffer[0] = c; + buffer[1 == ret ? 1 : MAXARGSZ] = '\0'; + + if (newline) { + putchar('\n'); + } + + fputs(buffer, stdout); + putchar(' '); } } - if (!reading_stdin) - { - if (optind < argc) - { - strncpy (buffer, argv[optind++], MAXARGSZ); - buffer[MAXARGSZ] = '\0'; - ret = 1; + if (!reading_stdin) { + if (optind < argc) { + strncpy(buffer, argv[optind++], MAXARGSZ); + buffer[MAXARGSZ] = '\0'; + ret = 1; + } else { + ret = EOF; } - else ret = EOF; } - return ret; + return ret; } -#define fprintf_flush(f, a...) \ - ({ int __ret; \ - __ret = fprintf((f), a); \ - fflush((f)); \ - __ret; \ - }) + +#define fprintf_flush(f, a...) \ + ({ int __ret; \ + __ret = fprintf((f), a); \ + fflush((f)); \ + __ret; \ + }) extern int interactive; @@ -418,591 +464,739 @@ extern char send_cmd_term; int ext_resp = 0; unsigned char resp_sep = '\n'; /* Default response separator */ + int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) { - int retcode; /* generic return code from functions */ - unsigned char cmd; - struct test_table *cmd_entry; + int retcode; /* generic return code from functions */ + unsigned char cmd; + struct test_table *cmd_entry; - char command[MAXARGSZ+1]; - char arg1[MAXARGSZ + 1], *p1 = NULL; - char arg2[MAXARGSZ + 1], *p2 = NULL; - char arg3[MAXARGSZ + 1], *p3 = NULL; - char arg4[MAXARGSZ + 1], *p4 = NULL; - char *p5 = NULL; - char *p6 = NULL; - static int last_was_ret = 1; + char command[MAXARGSZ + 1]; + char arg1[MAXARGSZ + 1], *p1 = NULL; + char arg2[MAXARGSZ + 1], *p2 = NULL; + char arg3[MAXARGSZ + 1], *p3 = NULL; + char arg4[MAXARGSZ + 1], *p4 = NULL; + char *p5 = NULL; + char *p6 = NULL; + static int last_was_ret = 1; - /* cmd, internal, rotctld */ - if (!(interactive && prompt && have_rl)) { - if (interactive) { - if (prompt) - fprintf_flush(fout, "\nRotator command: "); + /* cmd, internal, rotctld */ + if (!(interactive && prompt && have_rl)) { + if (interactive) { + if (prompt) { + fprintf_flush(fout, "\nRotator command: "); + } - do { - if (scanfc(fin, "%c", &cmd) < 1) - return -1; + do { + if (scanfc(fin, "%c", &cmd) < 1) { + return -1; + } - /* Extended response protocol requested with leading '+' on command - * string--rotctld only! - */ - if (cmd == '+' && !prompt) { - ext_resp = 1; - if (scanfc(fin, "%c", &cmd) < 1) - return -1; - } else if (cmd == '+' && prompt) { - return 0; - } + /* Extended response protocol requested with leading '+' on command + * string--rotctld only! + */ + if (cmd == '+' && !prompt) { + ext_resp = 1; - if (cmd != '\\' && cmd != '_' && cmd != '#' && ispunct(cmd) && !prompt) { - ext_resp = 1; - resp_sep = cmd; - if (scanfc(fin, "%c", &cmd) < 1) - return -1; - } else if (cmd != '\\' && cmd != '?' && cmd != '_' && cmd != '#' && ispunct(cmd) && prompt) { - return 0; - } + if (scanfc(fin, "%c", &cmd) < 1) { + return -1; + } + } else if (cmd == '+' && prompt) { + return 0; + } - /* command by name */ - if (cmd == '\\') { - unsigned char cmd_name[MAXNAMSIZ], *pcmd = cmd_name; - int c_len = MAXNAMSIZ; + if (cmd != '\\' + && cmd != '_' + && cmd != '#' + && ispunct(cmd) + && !prompt) { - if (scanfc(fin, "%c", pcmd) < 1) - return -1; + ext_resp = 1; + resp_sep = cmd; - while(c_len-- && (isalnum(*pcmd) || *pcmd == '_' )) - if (scanfc(fin, "%c", ++pcmd) < 1) - return -1; + if (scanfc(fin, "%c", &cmd) < 1) { + return -1; + } + } else if (cmd != '\\' + && cmd != '?' + && cmd != '_' + && cmd != '#' + && ispunct(cmd) + && prompt) { + return 0; + } - *pcmd = '\0'; - cmd = parse_arg((char *) cmd_name); - break; - } + /* command by name */ + if (cmd == '\\') { + unsigned char cmd_name[MAXNAMSIZ], *pcmd = cmd_name; + int c_len = MAXNAMSIZ; - if (cmd == 0x0a || cmd == 0x0d) { - if (last_was_ret) { - if (prompt) { - fprintf_flush(fout, "? for help, q to quit.\n"); - } - return 0; - } - last_was_ret = 1; - } - } while (cmd == 0x0a || cmd == 0x0d); + if (scanfc(fin, "%c", pcmd) < 1) { + return -1; + } - last_was_ret = 0; + while (c_len-- && (isalnum(*pcmd) || *pcmd == '_')) { + if (scanfc(fin, "%c", ++pcmd) < 1) { + return -1; + } + } - /* comment line */ - if (cmd == '#') { - while( cmd != '\n' && cmd != '\r') - if (scanfc(fin, "%c", &cmd) < 1) - return -1; - return 0; - } - if (cmd == 'Q' || cmd == 'q') - return 1; - if (cmd == '?') { - usage_rot(fout); - fflush(fout); - return 0; - } - } else { - /* parse rest of command line */ - retcode = next_word (command, argc, argv, 1); - if (EOF == retcode) return 1; - else if (retcode < 0) return retcode; - else if ('\0' == command[1]) { - cmd = command[0]; - } else { - cmd = parse_arg (command); - } - } + *pcmd = '\0'; + cmd = parse_arg((char *) cmd_name); + break; + } - cmd_entry = find_cmd_entry(cmd); - if (!cmd_entry) { - fprintf_flush(stderr, "Command '%c' not found!\n", cmd); - return 0; - } + if (cmd == 0x0a || cmd == 0x0d) { + if (last_was_ret) { + if (prompt) { + fprintf_flush(fout, "? for help, q to quit.\n"); + } - if ((cmd_entry->flags & ARG_IN_LINE) && - (cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { - if (interactive) { - char *nl; - if (prompt) - fprintf_flush(fout, "%s: ", cmd_entry->arg1); - if (fgets(arg1, MAXARGSZ, fin) == NULL) - return -1; - if (arg1[0] == 0xa) - if (fgets(arg1, MAXARGSZ, fin) == NULL) - return -1; - nl = strchr(arg1, 0xa); - if (nl) *nl = '\0'; /* chomp */ - p1 = arg1[0]==' '?arg1+1:arg1; - } else { - retcode = next_word (arg1, argc, argv, 0); - if (EOF == retcode) { - fprintf(stderr, "Invalid arg for command '%s'\n", - cmd_entry->name); - return 1; + return 0; + } + + last_was_ret = 1; + } + } while (cmd == 0x0a || cmd == 0x0d); + + last_was_ret = 0; + + /* comment line */ + if (cmd == '#') { + while (cmd != '\n' && cmd != '\r') { + if (scanfc(fin, "%c", &cmd) < 1) { + return -1; + } + } + + return 0; + } + + if (cmd == 'Q' || cmd == 'q') { + return 1; + } + + if (cmd == '?') { + usage_rot(fout); + fflush(fout); + return 0; + } + } else { + /* parse rest of command line */ + retcode = next_word(command, argc, argv, 1); + + if (EOF == retcode) { + return 1; + } else if (retcode < 0) { + return retcode; + } else if ('\0' == command[1]) { + cmd = command[0]; + } else { + cmd = parse_arg(command); + } } - else if (retcode < 0) return retcode; - p1 = arg1; - } - } else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { - if (interactive) { - if (prompt) - fprintf_flush(fout, "%s: ", cmd_entry->arg1); - if (scanfc(fin, "%s", arg1) < 1) - return -1; - p1 = arg1; - } else { - retcode = next_word (arg1, argc, argv, 0); - if (EOF == retcode) { - fprintf(stderr, "Invalid arg for command '%s'\n", - cmd_entry->name); - return 1; - } - else if (retcode < 0) return retcode; - p1 = arg1; - } - } - if (p1 && p1[0]!='?' && (cmd_entry->flags & ARG_IN2) && cmd_entry->arg2) { - if (interactive) { - if (prompt) - fprintf_flush(fout, "%s: ", cmd_entry->arg2); - if (scanfc(fin, "%s", arg2) < 1) - return -1; - p2 = arg2; - } else { - retcode = next_word (arg2, argc, argv, 0); - if (EOF == retcode) { - fprintf(stderr, "Invalid arg for command '%s'\n", - cmd_entry->name); - return 1; - } - else if (retcode < 0) return retcode; - p2 = arg2; - } - } - if (p1 && p1[0]!='?' && (cmd_entry->flags & ARG_IN3) && cmd_entry->arg3) { - if (interactive) { - if (prompt) - fprintf_flush(fout, "%s: ", cmd_entry->arg3); - if (scanfc(fin, "%s", arg3) < 1) - return -1; - p3 = arg3; - } else { - retcode = next_word (arg3, argc, argv, 0); - if (EOF == retcode) { - fprintf(stderr, "Invalid arg for command '%s'\n", - cmd_entry->name); - return 1; - } - else if (retcode < 0) return retcode; - p3 = arg3; - } - } - if (p1 && p1[0]!='?' && (cmd_entry->flags & ARG_IN4) && cmd_entry->arg4) { - if (interactive) { - if (prompt) - fprintf_flush(fout, "%s: ", cmd_entry->arg4); - if (scanfc(fin, "%s", arg4) < 1) - return -1; - p4 = arg4; - } else { - retcode = next_word (arg4, argc, argv, 0); - if (EOF == retcode) { - fprintf(stderr, "Invalid arg for command '%s'\n", - cmd_entry->name); - return 1; + cmd_entry = find_cmd_entry(cmd); + + if (!cmd_entry) { + fprintf_flush(stderr, "Command '%c' not found!\n", cmd); + return 0; } - else if (retcode < 0) return retcode; - p4 = arg4; - } - } - } + + if ((cmd_entry->flags & ARG_IN_LINE) + && (cmd_entry->flags & ARG_IN1) + && cmd_entry->arg1) { + + if (interactive) { + char *nl; + + if (prompt) { + fprintf_flush(fout, "%s: ", cmd_entry->arg1); + } + + if (fgets(arg1, MAXARGSZ, fin) == NULL) { + return -1; + } + + if (arg1[0] == 0xa) { + if (fgets(arg1, MAXARGSZ, fin) == NULL) { + return -1; + } + } + + nl = strchr(arg1, 0xa); + + if (nl) { + *nl = '\0'; /* chomp */ + } + + p1 = arg1[0] == ' ' ? arg1 + 1 : arg1; + } else { + retcode = next_word(arg1, argc, argv, 0); + + if (EOF == retcode) { + fprintf(stderr, + "Invalid arg for command '%s'\n", + cmd_entry->name); + return 1; + } else if (retcode < 0) { + return retcode; + } + + p1 = arg1; + } + } else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { + if (interactive) { + if (prompt) { + fprintf_flush(fout, "%s: ", cmd_entry->arg1); + } + + if (scanfc(fin, "%s", arg1) < 1) { + return -1; + } + + p1 = arg1; + } else { + retcode = next_word(arg1, argc, argv, 0); + + if (EOF == retcode) { + fprintf(stderr, + "Invalid arg for command '%s'\n", + cmd_entry->name); + return 1; + } else if (retcode < 0) { + return retcode; + } + + p1 = arg1; + } + } + + if (p1 + && p1[0] != '?' + && (cmd_entry->flags & ARG_IN2) + && cmd_entry->arg2) { + + if (interactive) { + if (prompt) { + fprintf_flush(fout, "%s: ", cmd_entry->arg2); + } + + if (scanfc(fin, "%s", arg2) < 1) { + return -1; + } + + p2 = arg2; + } else { + retcode = next_word(arg2, argc, argv, 0); + + if (EOF == retcode) { + fprintf(stderr, + "Invalid arg for command '%s'\n", + cmd_entry->name); + return 1; + } else if (retcode < 0) { + return retcode; + } + + p2 = arg2; + } + } + + if (p1 + && p1[0] != '?' + && (cmd_entry->flags & ARG_IN3) + && cmd_entry->arg3) { + + if (interactive) { + if (prompt) { + fprintf_flush(fout, "%s: ", cmd_entry->arg3); + } + + if (scanfc(fin, "%s", arg3) < 1) { + return -1; + } + + p3 = arg3; + } else { + retcode = next_word(arg3, argc, argv, 0); + + if (EOF == retcode) { + fprintf(stderr, + "Invalid arg for command '%s'\n", + cmd_entry->name); + return 1; + } else if (retcode < 0) { + return retcode; + } + + p3 = arg3; + } + } + + if (p1 + && p1[0] != '?' + && (cmd_entry->flags & ARG_IN4) + && cmd_entry->arg4) { + + if (interactive) { + if (prompt) { + fprintf_flush(fout, "%s: ", cmd_entry->arg4); + } + + if (scanfc(fin, "%s", arg4) < 1) { + return -1; + } + + p4 = arg4; + } else { + retcode = next_word(arg4, argc, argv, 0); + + if (EOF == retcode) { + fprintf(stderr, + "Invalid arg for command '%s'\n", + cmd_entry->name); + return 1; + } else if (retcode < 0) { + return retcode; + } + + p4 = arg4; + } + } + } #ifdef HAVE_LIBREADLINE - if (interactive && prompt && have_rl) { - int j, x; + if (interactive && prompt && have_rl) { + int j, x; #ifdef HAVE_READLINE_HISTORY - /* Minimum space for 32+1+128+1+128+1+128+1+128+1+128+1+128+1 = 807 - * chars, so allocate 896 chars cleared to zero for safety. - */ - rp_hist_buf = (char *)calloc(896, sizeof(char)); + /* Minimum space for 32+1+128+1+128+1+128+1+128+1+128+1+128+1 = 807 + * chars, so allocate 896 chars cleared to zero for safety. + */ + rp_hist_buf = (char *)calloc(896, sizeof(char)); #endif - rl_instream = fin; - rl_outstream = fout; + rl_instream = fin; + rl_outstream = fout; - rp_getline("\nRotator command: "); + rp_getline("\nRotator command: "); - /* EOF (Ctl-D) received on empty input line, bail out gracefully. */ - if (!input_line) { - fprintf_flush(fout, "\n"); - return 1; - } + /* EOF (Ctl-D) received on empty input line, bail out gracefully. */ + if (!input_line) { + fprintf_flush(fout, "\n"); + return 1; + } - /* Q or q to quit */ - if (!(strncasecmp(input_line, "q", 1))) - return 1; + /* Q or q to quit */ + if (!(strncasecmp(input_line, "q", 1))) { + return 1; + } - /* '?' for help */ - if (!(strncmp(input_line, "?", 1))) { - usage_rot(fout); - fflush(fout); - return 0; - } + /* '?' for help */ + if (!(strncmp(input_line, "?", 1))) { + usage_rot(fout); + fflush(fout); + return 0; + } - /* '#' for comment */ - if (!(strncmp(input_line, "#", 1))) - return 0; + /* '#' for comment */ + if (!(strncmp(input_line, "#", 1))) { + return 0; + } - /* Blank line entered */ - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + /* Blank line entered */ + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } - rig_debug(RIG_DEBUG_BUG, "%s: input_line: %s\n", __func__, input_line); + rig_debug(RIG_DEBUG_BUG, "%s: input_line: %s\n", __func__, input_line); - /* Split input_line on any number of spaces to get the command token - * Tabs are intercepted by readline for completion and a newline - * causes readline to return the typed text. If more than one - * argument is given, it will be parsed out later. - */ - result = strtok(input_line, " "); + /* Split input_line on any number of spaces to get the command token + * Tabs are intercepted by readline for completion and a newline + * causes readline to return the typed text. If more than one + * argument is given, it will be parsed out later. + */ + result = strtok(input_line, " "); - /* parsed_input stores pointers into input_line where the token strings - * start. - */ - if (result) { - parsed_input[0] = result; - } else { - /* Oops! Invoke GDB!! */ - fprintf_flush(fout, "\n"); - return 1; - } + /* parsed_input stores pointers into input_line where the token strings + * start. + */ + if (result) { + parsed_input[0] = result; + } else { + /* Oops! Invoke GDB!! */ + fprintf_flush(fout, "\n"); + return 1; + } - /* At this point parsed_input contains the typed text of the command - * with surrounding space characters removed. If Readline History is - * available, copy the command string into a history buffer. - */ + /* At this point parsed_input contains the typed text of the command + * with surrounding space characters removed. If Readline History is + * available, copy the command string into a history buffer. + */ - /* Single character command */ - if ((strlen(parsed_input[0]) == 1) && (*parsed_input[0] != '\\')) { - cmd = *parsed_input[0]; + /* Single character command */ + if ((strlen(parsed_input[0]) == 1) && (*parsed_input[0] != '\\')) { + cmd = *parsed_input[0]; #ifdef HAVE_READLINE_HISTORY - /* Store what is typed, not validated, for history. */ - if (rp_hist_buf) - strncpy(rp_hist_buf, parsed_input[0], 1); -#endif - } - /* Test the command token, parsed_input[0] */ - else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) > 1)) { - char cmd_name[MAXNAMSIZ]; - /* if there is no terminating '\0' character in the source string, - * srncpy() doesn't add one even if the supplied length is less - * than the destination array. Truncate the source string here. - */ - if (strlen(parsed_input[0] + 1) >= MAXNAMSIZ) - *(parsed_input[0] + MAXNAMSIZ) = '\0'; + /* Store what is typed, not validated, for history. */ + if (rp_hist_buf) { + strncpy(rp_hist_buf, parsed_input[0], 1); + } + +#endif + } + /* Test the command token, parsed_input[0] */ + else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) > 1)) { + char cmd_name[MAXNAMSIZ]; + + /* if there is no terminating '\0' character in the source string, + * srncpy() doesn't add one even if the supplied length is less + * than the destination array. Truncate the source string here. + */ + if (strlen(parsed_input[0] + 1) >= MAXNAMSIZ) { + *(parsed_input[0] + MAXNAMSIZ) = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) - strncpy(rp_hist_buf, parsed_input[0], MAXNAMSIZ); + + if (rp_hist_buf) { + strncpy(rp_hist_buf, parsed_input[0], MAXNAMSIZ); + } + #endif - /* The starting position of the source string is the first - * character past the initial '\'. Using MAXNAMSIZ for the - * length leaves enough space for the '\0' string terminator in the - * cmd_name array. - */ - strncpy(cmd_name, parsed_input[0] + 1, MAXNAMSIZ); + /* The starting position of the source string is the first + * character past the initial '\'. Using MAXNAMSIZ for the + * length leaves enough space for the '\0' string terminator in the + * cmd_name array. + */ + strncpy(cmd_name, parsed_input[0] + 1, MAXNAMSIZ); - /* Sanity check as valid multiple character commands consist of - * alpha-numeric characters and the underscore ('_') character. - */ - for (j = 0; cmd_name[j] != '\0'; j++) { - if (!(isalnum((int)cmd_name[j]) || cmd_name[j] == '_')) { - fprintf(stderr, "Valid multiple character command names contain alpha-numeric characters plus '_'\n"); - return 0; - } - } + /* Sanity check as valid multiple character commands consist of + * alpha-numeric characters and the underscore ('_') character. + */ + for (j = 0; cmd_name[j] != '\0'; j++) { + if (!(isalnum((int)cmd_name[j]) || cmd_name[j] == '_')) { + fprintf(stderr, + "Valid multiple character command names contain alpha-numeric characters plus '_'\n"); + return 0; + } + } - cmd = parse_arg(cmd_name); - } - /* Single '\' entered, prompt again */ - else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) == 1)) { - return 0; - } - /* Multiple characters but no leading '\' */ - else { - fprintf(stderr, "Precede multiple character command names with '\\'\n"); - return 0; - } + cmd = parse_arg(cmd_name); + } + /* Single '\' entered, prompt again */ + else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) == 1)) { + return 0; + } + /* Multiple characters but no leading '\' */ + else { + fprintf(stderr, "Precede multiple character command names with '\\'\n"); + return 0; + } - cmd_entry = find_cmd_entry(cmd); - if (!cmd_entry) { - if (cmd == '\0') - fprintf(stderr, "Command '%s' not found!\n", parsed_input[0]); - else - fprintf(stderr, "Command '%c' not found!\n", cmd); + cmd_entry = find_cmd_entry(cmd); - return 0; - } + if (!cmd_entry) { + if (cmd == '\0') { + fprintf(stderr, "Command '%s' not found!\n", parsed_input[0]); + } else { + fprintf(stderr, "Command '%c' not found!\n", cmd); + } - /* \send_cmd */ - if ((cmd_entry->flags & ARG_IN_LINE) && - (cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { - /* Check for a non-existent delimiter so as to not break up - * remaining line into separate tokens (spaces OK). - */ - result = strtok(NULL, "\0"); + return 0; + } - if (result) { - x = 1; - parsed_input[x] = result; - } else { - x = 0; - char pmptstr[(strlen(cmd_entry->arg1) + 3)]; + /* \send_cmd */ + if ((cmd_entry->flags & ARG_IN_LINE) + && (cmd_entry->flags & ARG_IN1) + && cmd_entry->arg1) { - strcpy(pmptstr, cmd_entry->arg1); - strcat(pmptstr, ": "); + /* Check for a non-existent delimiter so as to not break up + * remaining line into separate tokens (spaces OK). + */ + result = strtok(NULL, "\0"); - rp_getline(pmptstr); + if (result) { + x = 1; + parsed_input[x] = result; + } else { + x = 0; + char pmptstr[(strlen(cmd_entry->arg1) + 3)]; - /* Blank line entered */ - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + strcpy(pmptstr, cmd_entry->arg1); + strcat(pmptstr, ": "); - if (input_line) - parsed_input[x] = input_line; - else { - fprintf_flush(fout, "\n"); - return 1; - } - } + rp_getline(pmptstr); - /* The arg1 array size is MAXARGSZ + 1 so truncate it to fit if larger. */ - if (strlen(parsed_input[x]) > MAXARGSZ) - parsed_input[x][MAXARGSZ] = '\0'; + /* Blank line entered */ + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } + + if (input_line) { + parsed_input[x] = input_line; + } else { + fprintf_flush(fout, "\n"); + return 1; + } + } + + /* The arg1 array size is MAXARGSZ + 1 so truncate it to fit if larger. */ + if (strlen(parsed_input[x]) > MAXARGSZ) { + parsed_input[x][MAXARGSZ] = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); - strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); - } + + if (rp_hist_buf) { + strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); + } + #endif - strcpy(arg1, parsed_input[x]); - p1 = arg1; - } + strcpy(arg1, parsed_input[x]); + p1 = arg1; + } - /* Normal argument parsing. */ - else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { - result = strtok(NULL, " "); + /* Normal argument parsing. */ + else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { + result = strtok(NULL, " "); - if (result) { - x = 1; - parsed_input[x] = result; - } else { - x = 0; - char pmptstr[(strlen(cmd_entry->arg1) + 3)]; + if (result) { + x = 1; + parsed_input[x] = result; + } else { + x = 0; + char pmptstr[(strlen(cmd_entry->arg1) + 3)]; - strcpy(pmptstr, cmd_entry->arg1); - strcat(pmptstr, ": "); + strcpy(pmptstr, cmd_entry->arg1); + strcat(pmptstr, ": "); - rp_getline(pmptstr); + rp_getline(pmptstr); - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } - result = strtok(input_line, " "); + result = strtok(input_line, " "); - if (result) { - parsed_input[x] = result; - } else { - fprintf_flush(fout, "\n"); - return 1; - } - } + if (result) { + parsed_input[x] = result; + } else { + fprintf_flush(fout, "\n"); + return 1; + } + } - if (strlen(parsed_input[x]) > MAXARGSZ) - parsed_input[x][MAXARGSZ] = '\0'; + if (strlen(parsed_input[x]) > MAXARGSZ) { + parsed_input[x][MAXARGSZ] = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); - strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); - } + + if (rp_hist_buf) { + strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); + } + #endif - strcpy(arg1, parsed_input[x]); - p1 = arg1; - } - if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN2) && cmd_entry->arg2) { - result = strtok(NULL, " "); + strcpy(arg1, parsed_input[x]); + p1 = arg1; + } - if (result) { - x = 2; - parsed_input[x] = result; - } else { - x = 0; - char pmptstr[(strlen(cmd_entry->arg2) + 3)]; + if (p1 + && p1[0] != '?' + && (cmd_entry->flags & ARG_IN2) + && cmd_entry->arg2) { - strcpy(pmptstr, cmd_entry->arg2); - strcat(pmptstr, ": "); + result = strtok(NULL, " "); - rp_getline(pmptstr); + if (result) { + x = 2; + parsed_input[x] = result; + } else { + x = 0; + char pmptstr[(strlen(cmd_entry->arg2) + 3)]; - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + strcpy(pmptstr, cmd_entry->arg2); + strcat(pmptstr, ": "); - result = strtok(input_line, " "); + rp_getline(pmptstr); - if (result) { - parsed_input[x] = result; - } else { - fprintf_flush(fout, "\n"); - return 1; - } - } + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } - if (strlen(parsed_input[x]) > MAXARGSZ) - parsed_input[x][MAXARGSZ] = '\0'; + result = strtok(input_line, " "); + + if (result) { + parsed_input[x] = result; + } else { + fprintf_flush(fout, "\n"); + return 1; + } + } + + if (strlen(parsed_input[x]) > MAXARGSZ) { + parsed_input[x][MAXARGSZ] = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); - strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); - } + + if (rp_hist_buf) { + strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); + } + #endif - strcpy(arg2, parsed_input[x]); - p2 = arg2; - } - if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN3) && cmd_entry->arg3) { - result = strtok(NULL, " "); + strcpy(arg2, parsed_input[x]); + p2 = arg2; + } - if (result) { - x = 3; - parsed_input[x] = result; - } else { - x = 0; - char pmptstr[(strlen(cmd_entry->arg3) + 3)]; + if (p1 + && p1[0] != '?' + && (cmd_entry->flags & ARG_IN3) + && cmd_entry->arg3) { - strcpy(pmptstr, cmd_entry->arg3); - strcat(pmptstr, ": "); + result = strtok(NULL, " "); - rp_getline(pmptstr); + if (result) { + x = 3; + parsed_input[x] = result; + } else { + x = 0; + char pmptstr[(strlen(cmd_entry->arg3) + 3)]; - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + strcpy(pmptstr, cmd_entry->arg3); + strcat(pmptstr, ": "); - result = strtok(input_line, " "); + rp_getline(pmptstr); - if (result) { - parsed_input[x] = result; - } else { - fprintf_flush(fout, "\n"); - return 1; - } - } + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } - if (strlen(parsed_input[x]) > MAXARGSZ) - parsed_input[x][MAXARGSZ] = '\0'; + result = strtok(input_line, " "); + + if (result) { + parsed_input[x] = result; + } else { + fprintf_flush(fout, "\n"); + return 1; + } + } + + if (strlen(parsed_input[x]) > MAXARGSZ) { + parsed_input[x][MAXARGSZ] = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); - strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); - } + + if (rp_hist_buf) { + strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); + } + #endif - strcpy(arg3, parsed_input[x]); - p3 = arg3; - } - if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN4) && cmd_entry->arg4) { - result = strtok(NULL, " "); + strcpy(arg3, parsed_input[x]); + p3 = arg3; + } - if (result) { - x = 4; - parsed_input[x] = result; - } else { - x = 0; - char pmptstr[(strlen(cmd_entry->arg4) + 3)]; + if (p1 + && p1[0] != '?' + && (cmd_entry->flags & ARG_IN4) + && cmd_entry->arg4) { - strcpy(pmptstr, cmd_entry->arg4); - strcat(pmptstr, ": "); + result = strtok(NULL, " "); - rp_getline(pmptstr); + if (result) { + x = 4; + parsed_input[x] = result; + } else { + x = 0; + char pmptstr[(strlen(cmd_entry->arg4) + 3)]; - if (!(strcmp(input_line, ""))) { - fprintf(fout, "? for help, q to quit.\n"); - fflush(fout); - return 0; - } + strcpy(pmptstr, cmd_entry->arg4); + strcat(pmptstr, ": "); - result = strtok(input_line, " "); + rp_getline(pmptstr); - if (result) { - parsed_input[x] = result; - } else { - fprintf_flush(fout, "\n"); - return 1; - } - } + if (!(strcmp(input_line, ""))) { + fprintf(fout, "? for help, q to quit.\n"); + fflush(fout); + return 0; + } - if (strlen(parsed_input[x]) > MAXARGSZ) - parsed_input[x][MAXARGSZ] = '\0'; + result = strtok(input_line, " "); + + if (result) { + parsed_input[x] = result; + } else { + fprintf_flush(fout, "\n"); + return 1; + } + } + + if (strlen(parsed_input[x]) > MAXARGSZ) { + parsed_input[x][MAXARGSZ] = '\0'; + } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); - strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); - } + + if (rp_hist_buf) { + strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); + } + #endif - strcpy(arg4, parsed_input[x]); - p4 = arg4; - } + strcpy(arg4, parsed_input[x]); + p4 = arg4; + } + #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { - add_history(rp_hist_buf); - free(rp_hist_buf); - rp_hist_buf = (char *)NULL; - } + + if (rp_hist_buf) { + add_history(rp_hist_buf); + free(rp_hist_buf); + rp_hist_buf = (char *)NULL; + } + #endif - } + } -#endif /* HAVE_LIBREADLINE */ +#endif /* HAVE_LIBREADLINE */ - /* - * mutex locking needed because rotctld is multithreaded - * and hamlib is not MT-safe - */ + /* + * mutex locking needed because rotctld is multithreaded + * and hamlib is not MT-safe + */ #ifdef HAVE_PTHREAD - pthread_mutex_lock(&rot_mutex); + pthread_mutex_lock(&rot_mutex); #endif - if (!prompt) - rig_debug(RIG_DEBUG_TRACE, "rotctl(d): %c '%s' '%s' '%s' '%s'\n", - cmd, p1?p1:"", p2?p2:"", p3?p3:"", p4?p4:""); + if (!prompt) + rig_debug(RIG_DEBUG_TRACE, + "rotctl(d): %c '%s' '%s' '%s' '%s'\n", + cmd, + p1 ? p1 : "", + p2 ? p2 : "", + p3 ? p3 : "", + p4 ? p4 : ""); /* * Extended Response protocol: output received command name and arguments @@ -1022,172 +1216,222 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) fprintf(fout, "%s:%s%s%s%s%c", cmd_entry->name, a1, a2, a3, a4, resp_sep); } - retcode = (*cmd_entry->rot_routine)(my_rot, fout, interactive, - cmd_entry, p1, p2 ? p2 : "", p3 ? p3 : "", - p4 ? p4 : "", p5 ? p5 : "", p6 ? p6 : ""); + retcode = (*cmd_entry->rot_routine)(my_rot, + fout, + interactive, + cmd_entry, + p1, + p2 ? p2 : "", + p3 ? p3 : "", + p4 ? p4 : "", + p5 ? p5 : "", + p6 ? p6 : ""); #ifdef HAVE_PTHREAD - pthread_mutex_unlock(&rot_mutex); + pthread_mutex_unlock(&rot_mutex); #endif - if (retcode != RIG_OK) { - /* only for rotctld */ - if (interactive && !prompt) { - fprintf(fout, NETROTCTL_RET "%d\n", retcode); - ext_resp = 0; - resp_sep = '\n'; - } - else - fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode)); - } else { - /* only for rotctld */ - if (interactive && !prompt) { - /* netrotctl RIG_OK */ - if (!(cmd_entry->flags & ARG_OUT) && !ext_resp) - fprintf(fout, NETROTCTL_RET "0\n"); + if (retcode != RIG_OK) { + /* only for rotctld */ + if (interactive && !prompt) { + fprintf(fout, NETROTCTL_RET "%d\n", retcode); + ext_resp = 0; + resp_sep = '\n'; + } else { + fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode)); + } + } else { + /* only for rotctld */ + if (interactive && !prompt) { + /* netrotctl RIG_OK */ + if (!(cmd_entry->flags & ARG_OUT) && !ext_resp) { + fprintf(fout, NETROTCTL_RET "0\n"); + } - /* Extended Response protocol */ - else if (ext_resp && cmd != 0xf0) { - fprintf(fout, NETROTCTL_RET "0\n"); - ext_resp = 0; - resp_sep = '\n'; - } - } - } + /* Extended Response protocol */ + else if (ext_resp && cmd != 0xf0) { + fprintf(fout, NETROTCTL_RET "0\n"); + ext_resp = 0; + resp_sep = '\n'; + } + } + } - fflush(fout); + fflush(fout); - return retcode != RIG_OK ? 2 : 0; + return retcode != RIG_OK ? 2 : 0; } void version() { - printf("rotctl, %s\n\n", hamlib_version); - printf("%s\n", hamlib_copyright); + printf("rotctl(d), %s\n\n", hamlib_version); + printf("%s\n", hamlib_copyright); } void usage_rot(FILE *fout) { - int i, nbspaces; + int i, nbspaces; - fprintf(fout, "Commands (some may not be available for this rotator):\n"); - for (i = 0; test_list[i].cmd != 0; i++) { - fprintf(fout, "%c: %-12s(", isprint(test_list[i].cmd) ? - test_list[i].cmd : '?', test_list[i].name); + fprintf(fout, "Commands (some may not be available for this rotator):\n"); - nbspaces = 16; - if (test_list[i].arg1 && (test_list[i].flags&ARG_IN1)) - nbspaces -= fprintf(fout, "%s", test_list[i].arg1); - if (test_list[i].arg2 && (test_list[i].flags&ARG_IN2)) - nbspaces -= fprintf(fout, ", %s", test_list[i].arg2); - if (test_list[i].arg3 && (test_list[i].flags&ARG_IN3)) - nbspaces -= fprintf(fout, ", %s", test_list[i].arg3); - if (test_list[i].arg4 && (test_list[i].flags&ARG_IN4)) - nbspaces -= fprintf(fout, ", %s", test_list[i].arg4); + for (i = 0; test_list[i].cmd != 0; i++) { + fprintf(fout, "%c: %-12s(", isprint(test_list[i].cmd) ? + test_list[i].cmd : '?', test_list[i].name); - fprintf(fout, ")\n"); - } + nbspaces = 16; - fprintf(fout, "\n\nIn interactive mode prefix long command names with '\\', e.g. '\\dump_state'\n\n" - "The special command '-' is used to read further commands from standard input\n" - "Commands and arguments read from standard input must be white space separated,\n" - "comments are allowed, comments start with the # character and continue to the\n" - "end of the line.\n"); + if (test_list[i].arg1 && (test_list[i].flags & ARG_IN1)) { + nbspaces -= fprintf(fout, "%s", test_list[i].arg1); + } + + if (test_list[i].arg2 && (test_list[i].flags & ARG_IN2)) { + nbspaces -= fprintf(fout, ", %s", test_list[i].arg2); + } + + if (test_list[i].arg3 && (test_list[i].flags & ARG_IN3)) { + nbspaces -= fprintf(fout, ", %s", test_list[i].arg3); + } + + if (test_list[i].arg4 && (test_list[i].flags & ARG_IN4)) { + nbspaces -= fprintf(fout, ", %s", test_list[i].arg4); + } + + fprintf(fout, ")\n"); + } + + fprintf(fout, + "\n\nIn interactive mode prefix long command names with '\\', e.g. '\\dump_state'\n\n" + "The special command '-' is used to read further commands from standard input\n" + "Commands and arguments read from standard input must be white space separated,\n" + "comments are allowed, comments start with the # character and continue to the\n" + "end of the line.\n"); } int print_conf_list(const struct confparams *cfp, rig_ptr_t data) { - ROT *rot = (ROT*) data; - int i; - char buf[128] = ""; + ROT *rot = (ROT *) data; + int i; + char buf[128] = ""; - rot_get_conf(rot, cfp->token, buf); - printf("%s: \"%s\"\n" "\tDefault: %s, Value: %s\n", - cfp->name, cfp->tooltip, - cfp->dflt, buf ); + rot_get_conf(rot, cfp->token, buf); + printf("%s: \"%s\"\n" "\tDefault: %s, Value: %s\n", + cfp->name, + cfp->tooltip, + cfp->dflt, + buf); + + switch (cfp->type) { + case RIG_CONF_NUMERIC: + printf("\tRange: %.1f..%.1f, step %.1f\n", + cfp->u.n.min, + cfp->u.n.max, + cfp->u.n.step); + break; + + case RIG_CONF_COMBO: + if (!cfp->u.c.combostr[0]) { + break; + } + + printf("\tCombo: %s", cfp->u.c.combostr[0]); + + for (i = 1 ; i < RIG_COMBO_MAX && cfp->u.c.combostr[i]; i++) { + printf(", %s", cfp->u.c.combostr[i]); + } + + printf("\n"); + break; - switch (cfp->type) { - case RIG_CONF_NUMERIC: - printf("\tRange: %.1f..%.1f, step %.1f\n", - cfp->u.n.min, cfp->u.n.max, cfp->u.n.step); - break; - case RIG_CONF_COMBO: - if (!cfp->u.c.combostr[0]) - break; - printf("\tCombo: %s", cfp->u.c.combostr[0]); - for (i = 1 ; i < RIG_COMBO_MAX && cfp->u.c.combostr[i]; i++) - printf(", %s", cfp->u.c.combostr[i]); - printf("\n"); - break; default: - break; - } + break; + } - return 1; /* != 0, we want them all ! */ + return 1; /* != 0, we want them all ! */ } static int hash_model_list(const struct rot_caps *caps, void *data) { - hash_add_model(caps->rot_model, caps->mfg_name, caps->model_name, - caps->version, rig_strstatus(caps->status)); - return 1; /* !=0, we want them all ! */ + hash_add_model(caps->rot_model, + caps->mfg_name, + caps->model_name, + caps->version, + rig_strstatus(caps->status)); + + return 1; /* !=0, we want them all ! */ } void print_model_list() { - struct mod_lst *s; + struct mod_lst *s; - for (s = models; s != NULL; s = (struct mod_lst *)(s->hh.next)) { - printf("%6d %-23s%-24s%-16s%s\n", s->id, s->mfg_name, - s->model_name, s->version, s->status); - } + for (s = models; s != NULL; s = (struct mod_lst *)(s->hh.next)) { + printf("%6d %-23s%-24s%-16s%s\n", + s->id, + s->mfg_name, + s->model_name, + s->version, + s->status); + } } + void list_models() { - int status; + int status; - rot_load_all_backends(); + rot_load_all_backends(); - printf(" Rig # Mfg Model Version Status\n"); - status = rot_list_foreach(hash_model_list, NULL); - if (status != RIG_OK ) { - printf("rot_list_foreach: error = %s \n", rigerror(status)); - exit(2); - } + printf(" Rig # Mfg Model Version Status\n"); + status = rot_list_foreach(hash_model_list, NULL); - hash_sort_by_model_id(); - print_model_list(); - hash_delete_all(); + if (status != RIG_OK) { + printf("rot_list_foreach: error = %s \n", rigerror(status)); + exit(2); + } + + hash_sort_by_model_id(); + print_model_list(); + hash_delete_all(); } int set_conf(ROT *my_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 ) - return RIG_EINVAL; - *q++ = '\0'; - n = strchr(q, ','); - if (n) *n++ = '\0'; + p = conf_parms; - ret = rot_set_conf(my_rot, rot_token_lookup(my_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) { + return RIG_EINVAL; + } + + *q++ = '\0'; + n = strchr(q, ','); + + if (n) { + *n++ = '\0'; + } + + ret = rot_set_conf(my_rot, rot_token_lookup(my_rot, p), q); + + if (ret != RIG_OK) { + return ret; + } + + p = n; + } + + return RIG_OK; } @@ -1195,113 +1439,133 @@ int set_conf(ROT *my_rot, char *conf_parms) * static int (f)(ROT *rot, int interactive, const void *arg1, const void *arg2, const void *arg3, const void *arg4) */ + /* 'P' */ declare_proto_rot(set_position) { - azimuth_t az; - elevation_t el; + azimuth_t az; + elevation_t el; - CHKSCN1ARG(sscanf(arg1, "%f", &az)); - CHKSCN1ARG(sscanf(arg2, "%f", &el)); - return rot_set_position(rot, az, el); + CHKSCN1ARG(sscanf(arg1, "%f", &az)); + CHKSCN1ARG(sscanf(arg2, "%f", &el)); + return rot_set_position(rot, az, el); } + /* 'p' */ declare_proto_rot(get_position) { - int status; - azimuth_t az; - elevation_t el; + int status; + azimuth_t az; + elevation_t el; - status = rot_get_position(rot, &az, &el); - if (status != RIG_OK) - return status; - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%f%c", az, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg2); - fprintf(fout, "%f%c", el, resp_sep); + status = rot_get_position(rot, &az, &el); - return status; + if (status != RIG_OK) { + return status; + } + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%f%c", az, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg2); + } + + fprintf(fout, "%f%c", el, resp_sep); + + return status; } + /* 'S' */ declare_proto_rot(stop) { - return rot_stop(rot); + return rot_stop(rot); } + /* 'K' */ declare_proto_rot(park) { - return rot_park(rot); + return rot_park(rot); } + /* 'R' */ declare_proto_rot(reset) { - rot_reset_t reset; + rot_reset_t reset; - CHKSCN1ARG(sscanf(arg1, "%d", &reset)); - return rot_reset(rot, reset); + CHKSCN1ARG(sscanf(arg1, "%d", &reset)); + return rot_reset(rot, reset); } + /* '_' */ declare_proto_rot(get_info) { - const char *s; + const char *s; - s = rot_get_info(rot); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg1); - fprintf(fout, "%s%c", s ? s : "None", resp_sep); + s = rot_get_info(rot); - return RIG_OK; + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg1); + } + + fprintf(fout, "%s%c", s ? s : "None", resp_sep); + + return RIG_OK; } + /* 'M' */ declare_proto_rot(move) { - int direction; - int speed; + int direction; + int speed; - if (!strcmp(arg1, "LEFT") || !strcmp(arg1, "CCW")) + if (!strcmp(arg1, "LEFT") || !strcmp(arg1, "CCW")) { direction = ROT_MOVE_LEFT; - else - if (!strcmp(arg1, "RIGHT") || !strcmp(arg1, "CW")) + } else if (!strcmp(arg1, "RIGHT") || !strcmp(arg1, "CW")) { direction = ROT_MOVE_RIGHT; - else - if (!strcmp(arg1, "UP")) + } else if (!strcmp(arg1, "UP")) { direction = ROT_MOVE_UP; - else - if (!strcmp(arg1, "DOWN")) + } else if (!strcmp(arg1, "DOWN")) { direction = ROT_MOVE_DOWN; - else - CHKSCN1ARG(sscanf(arg1, "%d", &direction)); + } else { + CHKSCN1ARG(sscanf(arg1, "%d", &direction)); + } - CHKSCN1ARG(sscanf(arg2, "%d", &speed)); - return rot_move(rot, direction, speed); + CHKSCN1ARG(sscanf(arg2, "%d", &speed)); + return rot_move(rot, direction, speed); } + /* 'C' */ declare_proto_rot(inter_set_conf) { - token_t token; + token_t token; - CHKSCN1ARG(sscanf(arg1, "%ld", &token)); - if (!arg2 || arg2[0] == '\0') + CHKSCN1ARG(sscanf(arg1, "%ld", &token)); + + if (!arg2 || arg2[0] == '\0') { return -RIG_EINVAL; - return rot_set_conf(rot, token, arg2); + } + + return rot_set_conf(rot, token, arg2); } /* '1' */ declare_proto_rot(dump_caps) { - dumpcaps_rot(rot, fout); + dumpcaps_rot(rot, fout); - return RIG_OK; + return RIG_OK; } @@ -1310,332 +1574,411 @@ declare_proto_rot(dump_caps) */ declare_proto_rot(dump_state) { - struct rot_state *rs = &rot->state; + struct rot_state *rs = &rot->state; - /* - * - Protocol version - */ + /* + * - Protocol version + */ #define ROTCTLD_PROT_VER 0 - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "rotctld Protocol Ver: "); - fprintf(fout, "%d%c", ROTCTLD_PROT_VER, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "Rotor Model: "); - fprintf(fout, "%d%c", rot->caps->rot_model, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "rotctld Protocol Ver: "); + } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "Minimum Azimuth: "); - fprintf(fout, "%lf%c", rs->min_az, resp_sep); + fprintf(fout, "%d%c", ROTCTLD_PROT_VER, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "Maximum Azimuth: "); - fprintf(fout, "%lf%c", rs->max_az, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "Rotor Model: "); + } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "Minimum Elevation: "); - fprintf(fout, "%lf%c", rs->min_el, resp_sep); + fprintf(fout, "%d%c", rot->caps->rot_model, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "Maximum Elevation: "); - fprintf(fout, "%lf%c", rs->max_el, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "Minimum Azimuth: "); + } - return RIG_OK; + fprintf(fout, "%lf%c", rs->min_az, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "Maximum Azimuth: "); + } + + fprintf(fout, "%lf%c", rs->max_az, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "Minimum Elevation: "); + } + + fprintf(fout, "%lf%c", rs->min_el, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "Maximum Elevation: "); + } + + fprintf(fout, "%lf%c", rs->max_el, resp_sep); + + return RIG_OK; } + /* - * special debugging purpose send command - * display reply until there's a timeout + * Special debugging purpose send command display reply until there's a + * timeout. * * 'w' */ declare_proto_rot(send_cmd) { - int retval; - struct rot_state *rs; - int backend_num, cmd_len; + int retval; + struct rot_state *rs; + int backend_num, cmd_len; #define BUFSZ 128 - char bufcmd[BUFSZ]; - char buf[BUFSZ]; - char eom_buf[4] = { 0xa, 0xd, 0, 0 }; + char bufcmd[BUFSZ]; + char buf[BUFSZ]; + char eom_buf[4] = { 0xa, 0xd, 0, 0 }; - /* - * binary protocols enter values as \0xZZ\0xYY.. - * - * Rem: no binary protocol for rotator as of now - */ - backend_num = ROT_BACKEND_NUM(rot->caps->rot_model); - if (send_cmd_term == -1 || backend_num == -1) { - const char *p = arg1, *pp = NULL; - int i; - for (i = 0; i < BUFSZ - 1 && p != pp; i++) { - pp = p + 1; - bufcmd[i] = strtol(p + 1, (char **) &p, 0); - } - /* must save length to allow 0x00 to be sent as part of a command - */ - cmd_len = i - 1; + /* + * binary protocols enter values as \0xZZ\0xYY.. + * + * Rem: no binary protocol for rotator as of now + */ + backend_num = ROT_BACKEND_NUM(rot->caps->rot_model); - /* no End Of Message chars */ - eom_buf[0] = '\0'; - } else { - /* text protocol */ + if (send_cmd_term == -1 || backend_num == -1) { + const char *p = arg1, *pp = NULL; + int i; - strncpy(bufcmd,arg1, BUFSZ); - bufcmd[BUFSZ - 2] = '\0'; + for (i = 0; i < BUFSZ - 1 && p != pp; i++) { + pp = p + 1; + bufcmd[i] = strtol(p + 1, (char **) &p, 0); + } - cmd_len = strlen(bufcmd); + /* must save length to allow 0x00 to be sent as part of a command */ + cmd_len = i - 1; - /* Automatic termination char */ - if (send_cmd_term != 0) - bufcmd[cmd_len++] = send_cmd_term; - eom_buf[2] = send_cmd_term; - } + /* no End Of Message chars */ + eom_buf[0] = '\0'; + } else { + /* text protocol */ + strncpy(bufcmd, arg1, BUFSZ); + bufcmd[BUFSZ - 2] = '\0'; - rs = &rot->state; + cmd_len = strlen(bufcmd); - serial_flush(&rs->rotport); + /* Automatic termination char */ + if (send_cmd_term != 0) { + bufcmd[cmd_len++] = send_cmd_term; + } - retval = write_block(&rs->rotport, bufcmd, cmd_len); - if (retval != RIG_OK) - return retval; + eom_buf[2] = send_cmd_term; + } - if (interactive && prompt) - fprintf(fout, "%s: ", cmd->arg2); + rs = &rot->state; - do { - /* - * assumes CR or LF is end of line char - * for all ascii protocols - */ - retval = read_string(&rs->rotport, buf, BUFSZ, eom_buf, strlen(eom_buf)); - if (retval < 0) - break; + serial_flush(&rs->rotport); - if (retval < BUFSZ) - buf[retval] = '\0'; - else - buf[BUFSZ-1] = '\0'; + retval = write_block(&rs->rotport, bufcmd, cmd_len); - fprintf(fout, "%s\n", buf); + if (retval != RIG_OK) { + return retval; + } - } while (retval > 0); + if (interactive && prompt) { + fprintf(fout, "%s: ", cmd->arg2); + } - if (retval > 0 || retval == -RIG_ETIMEOUT) - retval = RIG_OK; + do { + /* + * assumes CR or LF is end of line char + * for all ascii protocols + */ + retval = read_string(&rs->rotport, buf, BUFSZ, eom_buf, strlen(eom_buf)); - return retval; + if (retval < 0) { + break; + } + + if (retval < BUFSZ) { + buf[retval] = '\0'; + } else { + buf[BUFSZ - 1] = '\0'; + } + + fprintf(fout, "%s\n", buf); + + } while (retval > 0); + + if (retval > 0 || retval == -RIG_ETIMEOUT) { + retval = RIG_OK; + } + + return retval; } + /* 'L' */ declare_proto_rot(lonlat2loc) { - unsigned char loc[MAXARGSZ + 1]; - double lat, lon; - int err, pair; + unsigned char loc[MAXARGSZ + 1]; + double lat, lon; + int err, pair; - CHKSCN1ARG(sscanf(arg1, "%lf", &lon)); - CHKSCN1ARG(sscanf(arg2, "%lf", &lat)); - CHKSCN1ARG(sscanf(arg3, "%d", &pair)); + CHKSCN1ARG(sscanf(arg1, "%lf", &lon)); + CHKSCN1ARG(sscanf(arg2, "%lf", &lat)); + CHKSCN1ARG(sscanf(arg3, "%d", &pair)); - pair /= 2; + pair /= 2; - err = longlat2locator(lon, lat, (char *)&loc, pair); + err = longlat2locator(lon, lat, (char *)&loc, pair); - if (err != RIG_OK) - return err; + if (err != RIG_OK) { + return err; + } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg4); - fprintf(fout, "%s%c", loc, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg4); + } - return err; + fprintf(fout, "%s%c", loc, resp_sep); + + return err; } + /* 'l' */ declare_proto_rot(loc2lonlat) { - unsigned char loc[MAXARGSZ + 1]; - double lat, lon; - int status; + unsigned char loc[MAXARGSZ + 1]; + double lat, lon; + int status; - CHKSCN1ARG(sscanf(arg1, "%s", (char *)&loc)); + CHKSCN1ARG(sscanf(arg1, "%s", (char *)&loc)); - status = locator2longlat(&lon, &lat, (const char *)loc); + status = locator2longlat(&lon, &lat, (const char *)loc); - if (status != RIG_OK) - return status; + if (status != RIG_OK) { + return status; + } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg2); - fprintf(fout, "%f%c", lon, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg3); - fprintf(fout, "%f%c", lat, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg2); + } - return status; + fprintf(fout, "%f%c", lon, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg3); + } + + fprintf(fout, "%f%c", lat, resp_sep); + + return status; } + /* 'D' */ declare_proto_rot(d_m_s2dec) { - int deg, min, sw; - double sec, dec_deg; + int deg, min, sw; + double sec, dec_deg; - CHKSCN1ARG(sscanf(arg1, "%d", °)); - CHKSCN1ARG(sscanf(arg2, "%d", &min)); - CHKSCN1ARG(sscanf(arg3, "%lf", &sec)); - CHKSCN1ARG(sscanf(arg4, "%d", &sw)); + CHKSCN1ARG(sscanf(arg1, "%d", °)); + CHKSCN1ARG(sscanf(arg2, "%d", &min)); + CHKSCN1ARG(sscanf(arg3, "%lf", &sec)); + CHKSCN1ARG(sscanf(arg4, "%d", &sw)); - dec_deg = dms2dec(deg, min, sec, sw); + dec_deg = dms2dec(deg, min, sec, sw); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg5); - fprintf(fout, "%lf%c", dec_deg, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg5); + } - return RIG_OK; + fprintf(fout, "%lf%c", dec_deg, resp_sep); + + return RIG_OK; } + /* 'd' */ declare_proto_rot(dec2d_m_s) { - int deg, min, sw, err; - double sec, dec_deg; + int deg, min, sw, err; + double sec, dec_deg; - CHKSCN1ARG(sscanf(arg1, "%lf", &dec_deg)); + CHKSCN1ARG(sscanf(arg1, "%lf", &dec_deg)); - err = dec2dms(dec_deg, °, &min, &sec, &sw); + err = dec2dms(dec_deg, °, &min, &sec, &sw); - if (err != RIG_OK) - return err; + if (err != RIG_OK) { + return err; + } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg2); - fprintf(fout, "%d%c", deg, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg3); - fprintf(fout, "%d%c", min, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg4); - fprintf(fout, "%lf%c", sec, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg5); - fprintf(fout, "%d%c", sw, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg2); + } - return err; + fprintf(fout, "%d%c", deg, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg3); + } + + fprintf(fout, "%d%c", min, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg4); + } + + fprintf(fout, "%lf%c", sec, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg5); + } + + fprintf(fout, "%d%c", sw, resp_sep); + + return err; } + /* 'E' */ declare_proto_rot(d_mm2dec) { - int deg, sw; - double dec_deg, min; + int deg, sw; + double dec_deg, min; - CHKSCN1ARG(sscanf(arg1, "%d", °)); - CHKSCN1ARG(sscanf(arg2, "%lf", &min)); - CHKSCN1ARG(sscanf(arg3, "%d", &sw)); + CHKSCN1ARG(sscanf(arg1, "%d", °)); + CHKSCN1ARG(sscanf(arg2, "%lf", &min)); + CHKSCN1ARG(sscanf(arg3, "%d", &sw)); - dec_deg = dmmm2dec(deg, min, sw); + dec_deg = dmmm2dec(deg, min, sw); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg4); - fprintf(fout, "%lf%c", dec_deg, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg4); + } - return RIG_OK; + fprintf(fout, "%lf%c", dec_deg, resp_sep); + + return RIG_OK; } + /* 'e' */ declare_proto_rot(dec2d_mm) { - int deg, sw, err; - double min, dec_deg; + int deg, sw, err; + double min, dec_deg; - CHKSCN1ARG(sscanf(arg1, "%lf", &dec_deg)); + CHKSCN1ARG(sscanf(arg1, "%lf", &dec_deg)); - err = dec2dmmm(dec_deg, °, &min, &sw); + err = dec2dmmm(dec_deg, °, &min, &sw); - if (err != RIG_OK) - return err; + if (err != RIG_OK) { + return err; + } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg2); - fprintf(fout, "%d%c", deg, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg3); - fprintf(fout, "%lf%c", min, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg4); - fprintf(fout, "%d%c", sw, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg2); + } - return err; + fprintf(fout, "%d%c", deg, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg3); + } + + fprintf(fout, "%lf%c", min, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg4); + } + + fprintf(fout, "%d%c", sw, resp_sep); + + return err; } + /* 'B' */ declare_proto_rot(coord2qrb) { - double lon1, lat1, lon2, lat2, dist, az; - int err; + double lon1, lat1, lon2, lat2, dist, az; + int err; - CHKSCN1ARG(sscanf(arg1, "%lf", &lon1)); - CHKSCN1ARG(sscanf(arg2, "%lf", &lat1)); - CHKSCN1ARG(sscanf(arg3, "%lf", &lon2)); - CHKSCN1ARG(sscanf(arg4, "%lf", &lat2)); + CHKSCN1ARG(sscanf(arg1, "%lf", &lon1)); + CHKSCN1ARG(sscanf(arg2, "%lf", &lat1)); + CHKSCN1ARG(sscanf(arg3, "%lf", &lon2)); + CHKSCN1ARG(sscanf(arg4, "%lf", &lat2)); - err = qrb(lon1, lat1, lon2, lat2, &dist, &az); + err = qrb(lon1, lat1, lon2, lat2, &dist, &az); - if (err != RIG_OK) - return err; + if (err != RIG_OK) { + return err; + } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg5); - fprintf(fout, "%lf%c", dist, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg6); - fprintf(fout, "%lf%c", az, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg5); + } - return err; + fprintf(fout, "%lf%c", dist, resp_sep); + + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg6); + } + + fprintf(fout, "%lf%c", az, resp_sep); + + return err; } + /* 'A' */ declare_proto_rot(az_sp2az_lp) { - double az_sp, az_lp; + double az_sp, az_lp; - CHKSCN1ARG(sscanf(arg1, "%lf", &az_sp)); + CHKSCN1ARG(sscanf(arg1, "%lf", &az_sp)); - az_lp = azimuth_long_path(az_sp); + az_lp = azimuth_long_path(az_sp); - if (az_lp < 0) - return -RIG_EINVAL; + if (az_lp < 0) { + return -RIG_EINVAL; + } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg2); - fprintf(fout, "%lf%c", az_lp, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg2); + } - return RIG_OK; + fprintf(fout, "%lf%c", az_lp, resp_sep); + + return RIG_OK; } + /* 'a' */ declare_proto_rot(dist_sp2dist_lp) { - double dist_sp, dist_lp; + double dist_sp, dist_lp; - CHKSCN1ARG(sscanf(arg1, "%lf", &dist_sp)); + CHKSCN1ARG(sscanf(arg1, "%lf", &dist_sp)); - dist_lp = distance_long_path(dist_sp); + dist_lp = distance_long_path(dist_sp); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) - fprintf(fout, "%s: ", cmd->arg2); - fprintf(fout, "%lf%c", dist_lp, resp_sep); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + fprintf(fout, "%s: ", cmd->arg2); + } - return RIG_OK; + fprintf(fout, "%lf%c", dist_lp, resp_sep); + + return RIG_OK; } + /* '0x8c'--pause processing */ declare_proto_rot(pause) { - unsigned seconds; - CHKSCN1ARG(sscanf(arg1, "%u", &seconds)); - sleep (seconds); - return RIG_OK; + unsigned seconds; + CHKSCN1ARG(sscanf(arg1, "%u", &seconds)); + sleep(seconds); + return RIG_OK; } diff --git a/tests/rotctl_parse.h b/tests/rotctl_parse.h index d82d1935a..f30a8f340 100644 --- a/tests/rotctl_parse.h +++ b/tests/rotctl_parse.h @@ -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 */ diff --git a/tests/rotctld.c b/tests/rotctld.c index 3c94aa54d..a12c4f0a0 100644 --- a/tests/rotctld.c +++ b/tests/rotctld.c @@ -23,7 +23,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "config.h" #endif #include @@ -39,26 +39,26 @@ #include /* See NOTES */ #ifdef HAVE_NETINET_IN_H -# include +# include #endif #ifdef HAVE_ARPA_INET_H -# include +# include #endif #ifdef HAVE_SYS_SOCKET_H -# include +# include #elif HAVE_WS2TCPIP_H -# include -# include -# if defined(HAVE_WSPIAPI_H) -# include -# endif +# include +# include +# if defined(HAVE_WSPIAPI_H) +# include +# endif #endif #ifdef HAVE_NETDB_H -# include +# include #endif #ifdef HAVE_PTHREAD -# include +# include #endif #include @@ -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 " - "\n\n"); + rig_debug(RIG_DEBUG_VERBOSE, "rotctld, %s\n", hamlib_version); + rig_debug(RIG_DEBUG_VERBOSE, + "Report bugs to \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 .\n"); + printf("\nReport bugs to .\n"); } diff --git a/tests/sprintflst.c b/tests/sprintflst.c index 0f5caeb85..5b7687106 100644 --- a/tests/sprintflst.c +++ b/tests/sprintflst.c @@ -21,7 +21,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -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<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< @@ -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 [digits]\n",argv[0]); - exit(1); - } + if (argc != 2 && argc != 3) { + fprintf(stderr, "Usage: %s [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; } diff --git a/tests/testfreq.c b/tests/testfreq.c index 47553352d..2315560d8 100644 --- a/tests/testfreq.c +++ b/tests/testfreq.c @@ -5,7 +5,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -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 \n",argv[0]); - exit(1); - } - f = atoi(argv[1]); + if (argc != 2) { + fprintf(stderr, "Usage: %s \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; } diff --git a/tests/testloc.c b/tests/testloc.c index 72f215ceb..70daa2d67 100644 --- a/tests/testloc.c +++ b/tests/testloc.c @@ -17,200 +17,246 @@ #include -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 []\n", argv[0]); - exit(1); - } + if (argc < 2) { + fprintf(stderr, + "Usage: %s []\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); } diff --git a/tests/testrig.c b/tests/testrig.c index 234d32225..51ffcd9c3 100644 --- a/tests/testrig.c +++ b/tests/testrig.c @@ -10,7 +10,7 @@ #include #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; } diff --git a/tests/testtrn.c b/tests/testtrn.c index c497d6a75..097aff0c1 100644 --- a/tests/testtrn.c +++ b/tests/testtrn.c @@ -10,7 +10,7 @@ #include #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 \n", argv[0]); - exit(1); - } + if (argc != 2) { + fprintf(stderr, "%s \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; }