File: testtrn.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 (101 lines) | stat: -rw-r--r-- 2,167 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
/*
 * 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>

#define SERIAL_PORT "/dev/ttyS0"


int myfreq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg)
{
    int *count_ptr = (int *) arg;

    printf("Rig changed freq to %"PRIfreq"Hz\n", freq);
    *count_ptr += 1;

    return 0;
}


int main(int argc, const  char *argv[])
{
    RIG *my_rig;        /* handle to rig (nstance) */
    int retcode;        /* generic return code from functions */
    int i, count = 0;

    if (argc != 2)
    {
        fprintf(stderr, "%s <rig_num>\n", argv[0]);
        exit(1);
    }

    printf("testrig: Hello, I am your main() !\n");

    /*
     * allocate memory, setup & open port
     */

    my_rig = rig_init(atoi(argv[1]));

    if (!my_rig)
    {
        fprintf(stderr, "Unknown rig num: %d\n", atoi(argv[1]));
        fprintf(stderr, "Please check riglist.h\n");
        exit(1);    /* whoops! something went wrong (mem alloc?) */
    }

    rig_set_conf(my_rig, rig_token_lookup(my_rig, "rig_pathname"), SERIAL_PORT);

    if (rig_open(my_rig))
    {
        exit(2);
    }

    printf("Port %s opened ok\n", SERIAL_PORT);

    /*
     * Below are examples of set/get routines.
     * Must add checking of functionality map prior to command execution -- FS
     *
     */

    retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 439700000);

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

    rig_set_freq_callback(my_rig, myfreq_event, (rig_ptr_t)&count);

    retcode = rig_set_trn(my_rig, RIG_TRN_RIG);

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


    for (i = 0; i < 12; i++)
    {
        printf("Loop count: %d\n", i);
        sleep(10);  /* or anything smarter */
    }

    printf("Frequency changed %d times\n", 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;
}