File: testmW2power.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 (77 lines) | stat: -rw-r--r-- 1,762 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
/*
 * Hamlib sample program to test transceive mode (async event)
 */

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>

#include <hamlib/rig.h>

#include <hamlib/config.h>

int nrigs = 0;

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

    switch (caps->rig_model)
    {
    case RIG_MODEL_NETRIGCTL:
        return 1;
        break;
    }

    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?) */
    }

    if (caps->mW2power)
    {
        nrigs++;
        printf("%20s:", caps->model_name);
        fflush(stdout);
        float fpow;
        unsigned int mwpower = 1 * 1000;
        freq_t freq = MHz(14);
        int retcode = rig_mW2power(rig, &fpow, mwpower, freq, RIG_MODE_CW);

        if (retcode != RIG_OK)
        {
            printf("rig_mW2power: error = %s \n", rigerror(retcode));
            return 1;
        }

        if (fpow < 0.009 || fpow > .11)
        {
//            printf("rig=%d, fpow=%g, min=%d, max=%d\n", caps->rig_model, fpow, caps->);
            printf("rig=%u, fpow=%g\n", caps->rig_model, fpow);
            // we call again to make debugging this section easier
            rig_mW2power(rig, &fpow, mwpower, freq, RIG_MODE_CW);
        }
        else { printf("\n"); }
    }

    rig_cleanup(rig); /* if you care about memory */
    return 1;
}

int main(int argc, char *argv[])
{
    RIG *rig;

    rig_set_debug(RIG_DEBUG_NONE);

    rig_load_all_backends();
    rig_list_foreach(callback, &rig);
    printf("Done testing %d rigs\n", nrigs);

    return 0;
}