-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
136 lines (116 loc) · 2.31 KB
/
main.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
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
/*
* FunCube Dongle command line interface
* David Pello EA1IDZ 2011
*
* This code is licensed under a GNU GPL licensed
* See LICENSE for information
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include "fcd.h"
const char* program_name;
void print_help()
{
printf("USAGE: %s options [arguments]\n", program_name);
printf(" -s --status Gets FCD current status\n");
printf(" -f --frequency <frequency> Sets FCD frequency in Hz\n");
printf(" -c --correction <correction> Sets frequency correction in ppm\n");
printf(" -h --help Shows this help\n");
}
void print_status()
{
int stat;
char version[20];
stat = fcdGetMode();
if (stat == FCD_MODE_NONE)
{
printf("No FCD Detected.\n");
return;
}
else if (stat == FCD_MODE_BL)
{
printf("FCD present in bootloader mode.\n");
return;
}
else
{
printf("FCD present in application mode.\n");
stat = fcdGetFwVerStr(version);
printf("FCD firmware version: %s.\n", version);
return;
}
}
int main(int argc, char* argv[])
{
int stat;
int freq = 0;
int corr = 0;
/* getopt infrastructure */
int next_option;
const char* const short_options = "sf:c:h";
const struct option long_options[] =
{
{ "status", 0, NULL, 's' },
{ "frequency", 1, NULL, 'f' },
{ "correction", 1, NULL, 'c' },
{ "help", 0, NULL, 'h' }
};
/* save program name */
program_name = argv[0];
if (argc == 1)
{
print_help();
exit(EXIT_SUCCESS);
}
while(1)
{
/* call getopt */
next_option = getopt_long(argc, argv, short_options, long_options, NULL);
/* end of the options */
if (next_option == -1)
break;
switch (next_option)
{
case 'h' :
print_help();
exit(EXIT_SUCCESS);
case 's' :
print_status();
exit(EXIT_SUCCESS);
case 'f' :
freq = atoi(optarg);
break;
case 'c' :
corr = atoi(optarg);
break;
case '?' :
print_help();
exit(1);
default :
abort();
}
}
/* calculate frequency */
freq *= 1.0 + corr / 1000000.0;
/* set it */
stat = fcdAppSetFreq(freq);
if (stat == FCD_MODE_NONE)
{
printf("No FCD Detected.\n");
return 1;
}
else if (stat == FCD_MODE_BL)
{
printf("FCD in bootloader mode.\n");
return 1;
}
else
{
printf("Freq set to %d.\n", freq);
return EXIT_SUCCESS;
}
return EXIT_SUCCESS;
}