File: cachetest.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 (166 lines) | stat: -rw-r--r-- 4,888 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*  This program does a number of iterations of v f m t s
 *  By Michael Black W9MDB
 *  This simulates what WSJT-X and JTDX do
 *  Used in testing caching effects that have been added
 *  Original performance against dummy device with 20ms delays showed
 *  about 50 calls/sec to get frequency.  After caching was added can
 *  do about 37,000 calls/sec or about 740 times faster.
 *  To compile:
 *      gcc -I../src -I../include -g -o cachetest cachetest.c -lhamlib
 *  To test dummy device cache effect:
 *      dummy without any cache -- 12 iterations per second
 *      ./cachetest 1 "" 0 12 0
 *      Elapsed:Elapsed 1.004sec
 *
 *      dummy with 500ms cache (default value) -- 12 iterations in 0.071sec
 *      ./cachetest 1 "" 0 12 500
 *      Elapsed 0.071sec
 *
 *      dummy with 5700 iterations in less than 1 second with 500ms cache
 *      ./cachetest 1 "" 0 5700 500
 *      Elapsed 0.872sec
 *
 *      ic-706mkiig  -- no cache
 *      ./cachetest 3011 /dev/ttyUSB0 19200 12 0
 *      Elapsed 1.182sec
 *
 *      ic-706mkiig  -- 500ms cache
 *      ./cachetest 3011 /dev/ttyUSB0 19200 12 500
 *      Elapsed 0.13sec
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hamlib/rig.h>
#include <hamlib/riglist.h>
#include "sprintflst.h"
#include "misc.h"


int main(int argc, char *argv[])
{
    RIG *my_rig;
    char *rig_file, *info_buf;
    freq_t freq;
    int retcode;
    int model;
    int baud;
    int loops;
    int cache_timeout = 500;
    int i;
    struct timespec start, startall;

    if (argc < 5)
    {
        fprintf(stderr, "Usage: %s model port baud loops [cachetimems]\n", argv[0]);
        fprintf(stderr,
                "cachetimems defaults to 500ms, 0 to disable or pick your own cache time\n");
        fprintf(stderr, "To test rigctld: %s 2 127.0.0.1:4532 0 1000 500\n", argv[0]);
        exit(1);
    }

    model = atoi(argv[1]);
    baud = atoi(argv[3]);
    loops = atoi(argv[4]);

    if (argc == 6)
    {
        cache_timeout = atoi(argv[5]);
    }

    rig_set_debug(RIG_DEBUG_NONE);

    /* Instantiate a rig */
    my_rig = rig_init(model); // your rig model.

    /* Set up serial port, baud rate */
    rig_file = argv[2];        // your serial device

    strncpy(RIGPORT(my_rig)->pathname, rig_file, HAMLIB_FILPATHLEN - 1);

    RIGPORT(my_rig)->parm.serial.rate = baud; // your baud rate

    /* Open my rig */
    retcode = rig_open(my_rig);

    if (retcode != RIG_OK)
    {
        fprintf(stderr, "%s: rig_open failed %s\n", __func__,
                rigerror(retcode));
        return 1;
    }

    rig_set_cache_timeout_ms(my_rig, HAMLIB_CACHE_ALL, cache_timeout);
    /* Give me ID info, e.g., firmware version. */
    info_buf = (char *)rig_get_info(my_rig);

    if (info_buf)
    {
        strtok(info_buf, "\r\n");
        printf("Rig_info: '%s'\n", info_buf);
    }

    elapsed_ms(&startall, HAMLIB_ELAPSED_SET);

    for (i = 0; i < loops; ++i)
    {
        rmode_t mode;
        pbwidth_t width;
        vfo_t vfo;
        ptt_t ptt;
        split_t split;

        elapsed_ms(&start, HAMLIB_ELAPSED_SET);

        retcode = rig_get_vfo(my_rig, &vfo);

        if (retcode != RIG_OK) { printf("Get vfo failed?? Err=%s\n", rigerror(retcode)); }

        printf("%4dms: VFO = %s\n", (int)elapsed_ms(&start, HAMLIB_ELAPSED_GET),
               rig_strvfo(vfo));

        elapsed_ms(&start, HAMLIB_ELAPSED_SET);
        retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);

        if (retcode != RIG_OK) { printf("Get freq failed?? Err=%s\n", rigerror(retcode)); }

        printf("%4dms: VFO freq. = %.1f Hz\n", (int)elapsed_ms(&start,
                HAMLIB_ELAPSED_GET),
               freq);
        elapsed_ms(&start, HAMLIB_ELAPSED_SET);
        retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &mode, &width);

        if (retcode != RIG_OK) { printf("Get mode failed?? Err=%s\n", rigerror(retcode)); }

        printf("%4dms: Current mode = %s, width = %ld\n", (int)elapsed_ms(&start,
                HAMLIB_ELAPSED_GET),
               rig_strrmode(mode), width);

        elapsed_ms(&start, HAMLIB_ELAPSED_SET);
        retcode = rig_get_ptt(my_rig, RIG_VFO_A, &ptt);

        if (retcode != RIG_OK) { printf("Get ptt failed?? Err=%s\n", rigerror(retcode)); }

        printf("%4dms: ptt=%d\n", (int)elapsed_ms(&start, HAMLIB_ELAPSED_GET), ptt);

#if 1
        elapsed_ms(&start, HAMLIB_ELAPSED_SET);
        retcode = rig_get_split_vfo(my_rig, RIG_VFO_A, &split, &vfo);

        if (retcode != RIG_OK) { printf("Get split_vfo failed?? Err=%s\n", rigerror(retcode)); }

        printf("%4dms: split=%d, tx_vfo=%s\n", (int)elapsed_ms(&start,
                HAMLIB_ELAPSED_GET),
               split,
               rig_strvfo(vfo));
#endif
    }

    printf("Elapsed %gsec\n", (int)elapsed_ms(&startall,
            HAMLIB_ELAPSED_GET) / 1000.0);

    rig_close(my_rig);
    return 0;

};