2007-11-23 04:50:18 +00:00
|
|
|
/* This is a elementary program calling Hamlib to do some useful things.
|
2012-01-08 02:36:50 +00:00
|
|
|
*
|
2009-01-04 01:27:43 +00:00
|
|
|
* Edit to specify your rig model and serial port, and baud rate
|
|
|
|
* before compiling.
|
2007-09-04 21:53:40 +00:00
|
|
|
* To compile:
|
2019-12-19 17:51:28 +00:00
|
|
|
* gcc -I../src -I../include -g -o example example.c sprintflst.c -lhamlib
|
2017-08-09 18:09:55 +00:00
|
|
|
* if hamlib is installed in /usr/local/...
|
2007-11-23 04:50:18 +00:00
|
|
|
*
|
2007-09-04 21:53:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <hamlib/rig.h>
|
2007-11-09 03:14:39 +00:00
|
|
|
#include <hamlib/riglist.h>
|
2019-12-19 17:51:28 +00:00
|
|
|
#include "sprintflst.h"
|
2020-12-07 04:54:47 +00:00
|
|
|
#include <hamlib/rotator.h>
|
2007-09-04 21:53:40 +00:00
|
|
|
|
2020-05-03 21:10:07 +00:00
|
|
|
#if 0
|
|
|
|
#define MODEL RIG_MODEL_DUMMY
|
|
|
|
#define PATH "/dev/ttyUSB0"
|
|
|
|
#define BAUD 19200
|
|
|
|
#else
|
|
|
|
#define MODEL RIG_MODEL_NETRIGCTL
|
|
|
|
#define PATH "127.0.0.1:4532"
|
|
|
|
#define BAUD 0
|
|
|
|
#endif
|
2007-11-23 04:50:18 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
RIG *my_rig;
|
2020-05-03 21:10:07 +00:00
|
|
|
char *info_buf;
|
2017-08-09 18:09:55 +00:00
|
|
|
freq_t freq;
|
|
|
|
value_t rawstrength, power, strength;
|
|
|
|
float s_meter, rig_raw2val();
|
2019-12-09 05:30:23 +00:00
|
|
|
int status, retcode;
|
|
|
|
unsigned int mwpower;
|
2017-08-09 18:09:55 +00:00
|
|
|
rmode_t mode;
|
|
|
|
pbwidth_t width;
|
|
|
|
|
|
|
|
/* Set verbosity level */
|
2020-05-03 21:10:07 +00:00
|
|
|
rig_set_debug(RIG_DEBUG_TRACE); // errors only
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
/* Instantiate a rig */
|
2020-05-03 21:10:07 +00:00
|
|
|
my_rig = rig_init(MODEL); // your rig model.
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2020-05-03 21:10:07 +00:00
|
|
|
strncpy(my_rig->state.rigport.pathname, PATH, FILPATHLEN - 1);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2020-05-03 21:10:07 +00:00
|
|
|
my_rig->state.rigport.parm.serial.rate = BAUD; // your baud rate
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
/* Open my rig */
|
|
|
|
retcode = rig_open(my_rig);
|
|
|
|
|
2019-12-09 05:30:23 +00:00
|
|
|
if (retcode != RIG_OK)
|
|
|
|
{
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: rig_open failed %s\n", __func__,
|
|
|
|
rigerror(retcode));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
/* 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.)
|
|
|
|
*/
|
|
|
|
|
2020-05-27 17:21:41 +00:00
|
|
|
if (my_rig->caps->rig_model == RIG_MODEL_NETRIGCTL)
|
|
|
|
{
|
|
|
|
status = rig_set_vfo_opt(my_rig, 1);
|
2020-05-27 17:23:08 +00:00
|
|
|
|
2020-05-27 17:21:41 +00:00
|
|
|
if (status != RIG_OK) { printf("set_vfo_opt failed?? Err=%s\n", rigerror(status)); }
|
|
|
|
}
|
2020-05-27 17:23:08 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
/* Main VFO frequency */
|
|
|
|
status = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
2020-02-23 17:26:09 +00:00
|
|
|
|
|
|
|
if (status != RIG_OK) { printf("Get freq failed?? Err=%s\n", rigerror(status)); }
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
printf("VFO freq. = %.1f Hz\n", freq);
|
|
|
|
|
|
|
|
/* Current mode */
|
|
|
|
status = rig_get_mode(my_rig, RIG_VFO_CURR, &mode, &width);
|
2020-02-23 17:26:09 +00:00
|
|
|
|
|
|
|
if (status != RIG_OK) { printf("Get mode failed?? Err=%s\n", rigerror(status)); }
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2020-05-03 21:55:04 +00:00
|
|
|
printf("Current mode = 0x%lX = %s, width = %ld\n", mode, rig_strrmode(mode),
|
|
|
|
width);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
/* rig power output */
|
|
|
|
status = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &power);
|
|
|
|
|
2019-12-09 05:30:23 +00:00
|
|
|
if (status != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error rig_get_level: %s\n", __func__, rigerror(status)); }
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
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);
|
|
|
|
|
2019-12-09 05:30:23 +00:00
|
|
|
if (status != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error rig_get_level: %s\n", __func__, rigerror(status)); }
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
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);
|
|
|
|
|
2019-12-09 05:30:23 +00:00
|
|
|
if (status != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error rig_get_level: %s\n", __func__, rigerror(status)); }
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2019-12-09 05:30:23 +00:00
|
|
|
printf("Raw receive strength = %d\n", rawstrength.i);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-12-09 05:30:23 +00:00
|
|
|
if (status != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error rig_get_level: %s\n", __func__, rigerror(status)); }
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
printf("LEVEL_STRENGTH returns %d\n", strength.i);
|
2019-12-19 17:51:28 +00:00
|
|
|
|
2020-02-23 17:26:09 +00:00
|
|
|
const freq_range_t *range = rig_get_range(&my_rig->state.rx_range_list[0],
|
|
|
|
14074000, RIG_MODE_USB);
|
2019-12-19 17:51:28 +00:00
|
|
|
|
|
|
|
if (status != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error rig_get_ragne: %s\n", __func__, rigerror(status)); }
|
2020-02-23 17:26:09 +00:00
|
|
|
|
|
|
|
if (range)
|
|
|
|
{
|
|
|
|
char vfolist[256];
|
2020-12-07 04:54:47 +00:00
|
|
|
rig_sprintf_vfo(vfolist, my_rig->state.vfo_list);
|
2020-02-23 17:26:09 +00:00
|
|
|
printf("Range start=%"PRIfreq", end=%"PRIfreq", low_power=%d, high_power=%d, vfos=%s\n",
|
|
|
|
range->startf, range->endf, range->low_power, range->high_power, vfolist);
|
2019-12-19 17:51:28 +00:00
|
|
|
}
|
2020-02-23 17:26:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Not rx range list found\n");
|
2019-12-19 17:51:28 +00:00
|
|
|
}
|
2020-05-03 21:10:07 +00:00
|
|
|
|
|
|
|
printf("Closing and reopening rig\n");
|
|
|
|
rig_close(my_rig);
|
|
|
|
|
2020-05-27 17:21:41 +00:00
|
|
|
int loops = 1;
|
2020-05-27 17:23:08 +00:00
|
|
|
|
2020-05-27 17:21:41 +00:00
|
|
|
while (loops--)
|
2020-05-03 21:55:04 +00:00
|
|
|
{
|
|
|
|
retcode = rig_open(my_rig);
|
2020-05-03 21:10:07 +00:00
|
|
|
|
2020-05-03 21:55:04 +00:00
|
|
|
if (retcode != RIG_OK)
|
|
|
|
{
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: rig_open failed %s\n", __func__,
|
|
|
|
rigerror(retcode));
|
|
|
|
return 1;
|
|
|
|
}
|
2020-05-03 21:10:07 +00:00
|
|
|
|
|
|
|
#if 0
|
2020-05-03 21:55:04 +00:00
|
|
|
status = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
2020-05-03 21:10:07 +00:00
|
|
|
|
2020-05-03 21:55:04 +00:00
|
|
|
if (status != RIG_OK) { printf("Get freq failed?? Err=%s\n", rigerror(status)); }
|
2020-05-03 21:10:07 +00:00
|
|
|
|
2020-05-03 21:55:04 +00:00
|
|
|
printf("VFO freq. = %.1f Hz\n", freq);
|
|
|
|
printf("rig reopen is OK\n");
|
2020-05-03 21:10:07 +00:00
|
|
|
#endif
|
2020-05-03 21:55:04 +00:00
|
|
|
rig_close(my_rig);
|
2020-05-03 21:10:07 +00:00
|
|
|
}
|
2007-09-04 21:53:40 +00:00
|
|
|
};
|