Hamlib/tests/testrigopen.c

61 wiersze
1.3 KiB
C
Czysty Zwykły widok Historia

2021-01-20 17:16:48 +00:00
/*
* Hamlib sample program
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/time.h>
#include <hamlib/rig.h>
#include "misc.h"
#include <hamlib/config.h>
2021-01-20 17:16:48 +00:00
#define SERIAL_PORT "/dev/ttyUSB0"
int callback(const struct rig_caps *caps, rig_ptr_t rigp)
{
2021-01-22 16:41:30 +00:00
RIG *rig = (RIG *) rigp;
2021-01-20 17:16:48 +00:00
rig = rig_init(caps->rig_model);
if (!rig)
{
fprintf(stderr, "Unknown rig num: %u\n", caps->rig_model);
2021-01-20 17:16:48 +00:00
fprintf(stderr, "Please check riglist.h\n");
exit(1); /* whoops! something went wrong (mem alloc?) */
}
char *port = "/dev/pts/3";
strcpy(rig->state.rigport.pathname, port);
2021-01-20 17:16:48 +00:00
printf("%20s:", caps->model_name);
2021-01-22 16:41:30 +00:00
fflush(stdout);
struct timeval start, end;
gettimeofday(&start, NULL);
2021-01-20 17:16:48 +00:00
rig_open(rig);
2021-01-22 16:41:30 +00:00
gettimeofday(&end, NULL);
double dstart = start.tv_sec + start.tv_usec / 1e6;
double dend = end.tv_sec + end.tv_usec / (double)1e6;
2021-01-20 17:16:48 +00:00
printf(" %.1f\n", dend - dstart);
rig_close(rig); /* close port */
rig_cleanup(rig); /* if you care about memory */
return 1;
}
int main(int argc, char *argv[])
{
RIG rig;
printf("testing rig timeouts when rig powered off\n");
/* Turn off backend debugging output */
rig_set_debug_level(RIG_DEBUG_NONE);
rig_load_all_backends();
rig_list_foreach(callback, &rig);
return 0;
}