2012-01-08 02:36:50 +00:00
|
|
|
/*
|
2003-02-24 20:55:12 +00:00
|
|
|
* Hamlib rig_bench program
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <hamlib/rig.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
#define LOOP_COUNT 100
|
|
|
|
|
|
|
|
#define SERIAL_PORT "/dev/ttyS0"
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
2012-01-08 02:36:50 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* allocate memory, setup & open port
|
|
|
|
*/
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (argc < 2)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
hamlib_port_t myport;
|
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 07:02:12 +00:00
|
|
|
/* may be overridden by backend probe */
|
2017-08-09 18:09:55 +00:00
|
|
|
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);
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
myrig_model = atoi(argv[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
my_rig = rig_init(myrig_model);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!my_rig)
|
|
|
|
{
|
2020-03-23 15:13:02 +00:00
|
|
|
fprintf(stderr, "Unknown rig num: %u\n", myrig_model);
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr, "Please check riglist.h\n");
|
|
|
|
exit(1); /* whoops! something went wrong (mem alloc?) */
|
|
|
|
}
|
|
|
|
|
2020-03-23 15:13:02 +00:00
|
|
|
printf("Opened rig model %u, '%s'\n",
|
2017-08-09 18:09:55 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
|
|
|
|
|
|
|
|
retcode = rig_open(my_rig);
|
2003-02-24 20:55:12 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (retcode != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
printf("rig_open: error = %s\n", rigerror(retcode));
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Port %s opened ok\n", SERIAL_PORT);
|
|
|
|
printf("Perform %d loops...\n", LOOP_COUNT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we're not using getrusage here because we want effective time
|
|
|
|
*/
|
|
|
|
gettimeofday(&tv1, NULL);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
for (i = 0; i < LOOP_COUNT; i++)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
freq_t freq;
|
|
|
|
rmode_t rmode;
|
|
|
|
pbwidth_t width;
|
|
|
|
|
|
|
|
retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (retcode != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
printf("rig_get_freq: error = %s \n", rigerror(retcode));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (retcode != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
printf("rig_get_mode: error = %s \n", rigerror(retcode));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gettimeofday(&tv2, NULL);
|
|
|
|
|
|
|
|
elapsed = tv2.tv_sec - tv1.tv_sec + (tv2.tv_usec - tv1.tv_usec) / 1000000.0;
|
|
|
|
printf("Elapsed: %.3fs, Avg: %f loops/s, %f s/loop\n",
|
|
|
|
elapsed,
|
|
|
|
LOOP_COUNT / elapsed,
|
|
|
|
elapsed / LOOP_COUNT);
|
|
|
|
|
|
|
|
rig_close(my_rig); /* close port */
|
|
|
|
rig_cleanup(my_rig); /* if you care about memory */
|
|
|
|
|
|
|
|
printf("port %s closed ok \n", SERIAL_PORT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|