File: testrigopen.c

package info (click to toggle)
hamlib 4.6.5-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,984 kB
  • sloc: ansic: 262,996; sh: 6,135; cpp: 1,578; perl: 876; makefile: 855; python: 148; awk: 58; xml: 26
file content (60 lines) | stat: -rw-r--r-- 1,397 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * 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>

#define SERIAL_PORT "/dev/ttyUSB0"

int callback(const struct rig_caps *caps, rig_ptr_t rigp)
{
    RIG *rig = (RIG *) rigp;

    rig = rig_init(caps->rig_model);

    if (!rig)
    {
        fprintf(stderr, "Unknown rig num: %u\n", caps->rig_model);
        fprintf(stderr, "Please check riglist.h\n");
        exit(1); /* whoops! something went wrong (mem alloc?) */
    }

    const char *port = "/dev/pts/3";
    rig_set_conf(rig, rig_token_lookup(rig, "rig_pathname"), port);

    printf("%20s:", caps->model_name);
    fflush(stdout);
    struct timeval start, end;
    gettimeofday(&start, NULL);
    rig_open(rig);
    gettimeofday(&end, NULL);
    double dstart = start.tv_sec + start.tv_usec / 1e6;
    double dend = end.tv_sec + end.tv_usec / (double)1e6;
    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;
}