forked from Hamlib/Hamlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesttrn.c
103 lines (73 loc) · 2.13 KB
/
testtrn.c
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
/*
* 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>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#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, 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?) */
}
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, HAMLIB_FILPATHLEN - 1);
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;
}