Loading...
Searching...
No Matches
/tests/testrig.c
/*
* Hamlib sample program
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <hamlib/rig.h>
#include <hamlib/config.h>
#define SERIAL_PORT "/dev/pts/2"
int main(int argc, const 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_model_t myrig_model;
printf("testrig: Hello, I am your main() !\n");
/* Turn off backend debugging output */
rig_set_debug_level(RIG_DEBUG_NONE);
/*
* allocate memory, setup & open port
*/
hamlib_port_t myport;
if (argc < 2)
{
/* may be overridden 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;
rig_load_all_backends();
myrig_model = rig_probe(&myport);
}
else
{
myrig_model = atoi(argv[1]);
}
my_rig = rig_init(myrig_model);
rig_set_conf(my_rig, rig_token_lookup(my_rig, "rig_pathname"), SERIAL_PORT);
if (!my_rig)
{
fprintf(stderr, "Unknown rig num: %u\n", myrig_model);
fprintf(stderr, "Please check riglist.h\n");
exit(1); /* whoops! something went wrong (mem alloc?) */
}
//strncpy(RIGPORT(my_rig)->pathname, SERIAL_PORT, HAMLIB_FILPATHLEN - 1);
retcode = rig_open(my_rig);
if (retcode != RIG_OK)
{
printf("rig_open: error = %s\n", rigerror(retcode));
exit(2);
}
uint64_t levels = rig_get_caps_int(my_rig->caps->rig_model,
RIG_CAPS_HAS_GET_LEVEL);
printf("HAS_GET_LEVEL=0x%8llx, SWR=%8llx,true=%d\n", (unsigned long long)levels,
(unsigned long long)(levels & RIG_LEVEL_SWR),
(levels & RIG_LEVEL_SWR) == RIG_LEVEL_SWR);
char val[256];
retcode = rig_get_conf2(my_rig, rig_token_lookup(my_rig, "write_delay"), val,
sizeof(val));
if (retcode != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: rig_get_conf2: %s\n", __func__,
rigerror(retcode));
}
printf("write_delay=%s\n", val);
// printf("Port %s opened ok\n", SERIAL_PORT);
/*
* Below are examples of set/get routines.
* Must add checking of functionality map prior to command execution -- FS
*
*/
/*
* Example of setting rig paameters
* 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));
}
/*
* Lets try some frequencies and modes. Return code is not checked.
* Examples of checking return code are further down.
*
*/
/* 10m FM Narrow */
printf("\nSetting 10m FM Narrow...\n");
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 29620000); /* 10m */
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM,
rig_passband_narrow(my_rig, RIG_MODE_FM));
if (retcode != RIG_OK)
{
printf("rig_set_mode: error = %s \n", rigerror(retcode));
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000000,
rig_strrmode(rmode),
width / 1000.0);
if (freq != 29620000)
{
printf("rig_set_freq: error expect %.0f got %.0f\n", 296290000.0, freq);
}
if (rmode != RIG_MODE_FM || width != rig_passband_narrow(my_rig, RIG_MODE_FM))
{
printf("rig_set_mode: error expected FM/%d, got %s/%d\n",
(int)rig_passband_narrow(my_rig, RIG_MODE_FM), rig_strrmode(rmode), (int)width);
}
sleep(1); /* so you can see it -- FS */
/* 15m USB */
printf("Setting 15m USB...\n");
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 21235175); /* 15m */
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
retcode = rig_set_mode(my_rig,
RIG_VFO_CURR,
RIG_MODE_USB,
rig_passband_normal(my_rig, RIG_MODE_USB));
if (retcode != RIG_OK)
{
printf("rig_set_mode: error = %s \n", rigerror(retcode));
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000000, rig_strrmode(rmode), width / 1000.0);
sleep(1);
/* 40m LSB */
printf("Setting 40m LSB...\n");
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 7250100); /* 40m */
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
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));
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000000,
rig_strrmode(rmode),
width / 1000.0);
sleep(1);
/* 80m AM Narrow */
printf("Setting 80m AM Narrow...\n");
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 3885000); /* 80m */
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
retcode = rig_set_mode(my_rig,
RIG_VFO_CURR,
RIG_MODE_AM,
rig_passband_narrow(my_rig, RIG_MODE_AM));
if (retcode != RIG_OK)
{
printf("rig_set_mode: error = %s \n", rigerror(retcode));
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000000,
rig_strrmode(rmode),
width / 1000.0);
sleep(1);
/* 160m CW Normal */
printf("Setting 160m CW...\n");
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 1875000); /* 160m */
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
retcode = rig_set_mode(my_rig,
RIG_VFO_CURR,
RIG_MODE_CW,
RIG_PASSBAND_NORMAL);
if (retcode != RIG_OK)
{
printf("rig_set_mode: error = %s \n", rigerror(retcode));
}
rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
freq / 1000,
rig_strrmode(rmode),
width);
sleep(1);
/* 160m CW Narrow -- The band is noisy tonight -- FS*/
printf("Setting 160m CW Narrow...\n");
retcode = rig_set_mode(my_rig,
RIG_VFO_CURR,
RIG_MODE_CW,
rig_passband_narrow(my_rig, RIG_MODE_CW));
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);
printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
freq / 1000,
rig_strrmode(rmode),
width);
sleep(1);
/* AM Broadcast band */
printf("Setting Medium Wave AM...\n");
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 770000); /* KAAM */
if (retcode != RIG_OK)
{
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
retcode = rig_set_mode(my_rig,
RIG_VFO_CURR,
RIG_MODE_AM,
RIG_PASSBAND_NORMAL);
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);
printf(" Freq: %.3f kHz, Mode: %s, Passband: %.3f kHz\n\n",
freq / 1000,
rig_strrmode(rmode),
width / 1000.0);
sleep(1);
/* 20m USB on VFO_A */
printf("Setting 20m on VFO A with two functions...\n");
retcode = rig_set_vfo(my_rig, RIG_VFO_A);
if (retcode != RIG_OK)
{
printf("rig_set_vfo: error = %s \n", rigerror(retcode));
}
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));
}
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);
/* 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);
#endif
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));
}
sleep(1);
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));
}
sleep(1);
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));
}
sleep(1);
/*
* 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 */
if (retcode == RIG_OK)
{
printf("rig_get_vfo: vfo = %u \n", vfo);
}
else
{
printf("rig_get_vfo: error = %s \n", rigerror(retcode));
}
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));
}
retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
if (retcode == RIG_OK)
{
printf("rig_get_mode: mode = %s\n", rig_strrmode(rmode));
}
else
{
printf("rig_get_mode: error = %s \n", rigerror(retcode));
}
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 (rig_has_set_func(my_rig, RIG_FUNC_RIT))
{
retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, 1);
if (retcode != RIG_OK) { printf("rig_set_func RIT error: %s\n", rigerror(retcode)); }
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);
if (retcode != RIG_OK) { printf("rig_get_func RIT error: %s\n", rigerror(retcode)); }
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);
if (retcode != RIG_OK) { printf("rig_set_func XIT error: %s\n", rigerror(retcode)); }
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);
if (retcode != RIG_OK) { printf("rig_get_func XIT error: %s\n", rigerror(retcode)); }
printf("rig_get_func: XIT: %d\n", xit);
}
rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
printf("port %s closed ok \n", SERIAL_PORT);
for (unsigned long i = 1; i < 0x80000000; i = i << 1)
{
const char *vfostr = rig_strvfo(i);
if (strlen(vfostr) > 0) { printf("0x%08lx=%s\n", i, vfostr); }
}
return 0;
}
rig_strvfo
const char * rig_strvfo(vfo_t vfo)
Convert enum RIG_VFO_... to alpha string.
Definition misc.c:670
rig_strrmode
const char * rig_strrmode(rmode_t mode)
Convert enum RIG_MODE to alpha string.
Definition misc.c:540
rig_set_vfo
int rig_set_vfo(RIG *rig, vfo_t vfo)
set the current VFO
Definition rig.c:3301
vfo_t
unsigned int vfo_t
VFO definition.
Definition rig.h:520
rig_get_mode
int rig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
get the mode of the target VFO
Definition rig.c:2970
PRIfreq
#define PRIfreq
printf(3) format to be used for freq_t type
Definition rig.h:465
rig_has_set_func
setting_t rig_has_set_func(RIG *rig, setting_t func)
check ability of radio functions
Definition settings.c:469
rig_get_vfo
int rig_get_vfo(RIG *rig, vfo_t *vfo)
get the current VFO
Definition rig.c:3448
RIG_VFO_A
#define RIG_VFO_A
VFOA – VFO A
Definition rig.h:530
rmode_t
uint64_t rmode_t
Radio mode.
Definition rig.h:1362
pbwidth_t
shortfreq_t pbwidth_t
Definition rig.h:652
rig_cleanup
int rig_cleanup(RIG *rig)
release a rig handle and free associated memory
Definition rig.c:1851
rig_get_freq
int rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
get the frequency of the target VFO
Definition rig.c:2429
rig_set_func
int rig_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
activate/de-activate functions of radio
Definition settings.c:500
rig_get_caps_int
uint64_t rig_get_caps_int(rig_model_t rig_model, enum rig_caps_int_e rig_caps)
Function to return int value from rig->caps Does not support > 32-bit rig_caps values.
Definition misc.c:2658
rig_has_get_func
setting_t rig_has_get_func(RIG *rig, setting_t func)
check ability of radio functions
Definition settings.c:439
rig_get_func
int rig_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
get the status of functions of the radio
Definition settings.c:597
RIG_FUNC_XIT
#define RIG_FUNC_XIT
Definition rig.h:1282
RIG_FUNC_RIT
#define RIG_FUNC_RIT
Definition rig.h:1275
RIG_VFO_CURR
#define RIG_VFO_CURR
currVFO – current "tunable channel"/VFO
Definition rig.h:575
rig_set_freq
int rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
set the frequency of the target VFO
Definition rig.c:2080
rig_set_ptt
int rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
set PTT on/off
Definition rig.c:3552
RIG_MODE_AM
#define RIG_MODE_AM
Definition rig.h:1365
freq_t
double freq_t
Frequency type.
Definition rig.h:460
RIG_MODE_USB
#define RIG_MODE_USB
Definition rig.h:1367
RIG_PASSBAND_NORMAL
#define RIG_PASSBAND_NORMAL
Macro for bandpass to be set to normal.
Definition rig.h:641
rig_init
RIG * rig_init(rig_model_t rig_model)
Allocate a new RIG handle.
Definition rig.c:544
rig_set_mode
int rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
set the mode of the target VFO
Definition rig.c:2769
RIG_MODE_CW
#define RIG_MODE_CW
Definition rig.h:1366
RIG_MODE_LSB
#define RIG_MODE_LSB
Definition rig.h:1368
rig_close
int rig_close(RIG *rig)
close the communication to the rig
Definition rig.c:1673
rig_passband_narrow
pbwidth_t rig_passband_narrow(RIG *rig, rmode_t mode)
get the narrow passband of a mode
Definition rig.c:3189
RIG_MODE_FM
#define RIG_MODE_FM
Definition rig.h:1370
rig_passband_normal
pbwidth_t rig_passband_normal(RIG *rig, rmode_t mode)
get the normal passband of a mode
Definition rig.c:3138
RIG
struct s_rig RIG
Rig structure definition (see rig for details).
Definition rig.h:264
RIG_LEVEL_SWR
#define RIG_LEVEL_SWR
Definition rig.h:1083
rig_open
int rig_open(RIG *rig)
open the communication to the rig
Definition rig.c:959
rig_token_lookup
hamlib_token_t rig_token_lookup(RIG *rig, const char *name)
lookup a token id
Definition conf.c:1443
RIG_VFO_B
#define RIG_VFO_B
VFOB – VFO B
Definition rig.h:533
rig_set_conf
int rig_set_conf(RIG *rig, hamlib_token_t token, const char *val)
set a radio configuration parameter
Definition conf.c:1474
rig_debug
void rig_debug(enum rig_debug_level_e debug_level, const char *fmt,...)
Print debugging messages through stderr by default.
Definition debug.c:206
rig_probe
rig_model_t rig_probe(hamlib_port_t *port)
try to guess a rig
Definition rig.c:6989
RIG_PARITY_NONE
@ RIG_PARITY_NONE
Definition rig.h:336
RIG_OK
@ RIG_OK
Definition rig.h:191
RIG_PTT_OFF
@ RIG_PTT_OFF
Definition rig.h:684
RIG_PTT_ON
@ RIG_PTT_ON
Definition rig.h:685
RIG_PORT_SERIAL
@ RIG_PORT_SERIAL
Definition rig.h:316
RIG_HANDSHAKE_NONE
@ RIG_HANDSHAKE_NONE
Definition rig.h:348
RIG_DEBUG_ERR
@ RIG_DEBUG_ERR
Definition rig.h:246
RIG_DEBUG_NONE
@ RIG_DEBUG_NONE
Definition rig.h:244
rig.h
Hamlib rig data structures.
rig_model_t
uint32_t rig_model_t
Convenience type definition for rig model.
Definition riglist.h:709
s_rig::caps
struct rig_caps * caps
Definition rig.h:3100