-
Notifications
You must be signed in to change notification settings - Fork 18
/
dabpi_ctl.c
308 lines (297 loc) · 8.06 KB
/
dabpi_ctl.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
* dabpi_ctl - raspberry pi fm/fmhd/dab receiver board control interface
* Copyright (C) 2014 Bjoern Biesenbach <[email protected]>
* Copyright (C) 2016 Heiko Jehmlich <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <getopt.h>
#include "si46xx.h"
#include "version.h"
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
uint32_t frequency_list_nrw[] = {
CHAN_5C,
CHAN_11D
};
uint32_t frequency_list_by[] = {
CHAN_5C,
CHAN_12D,
CHAN_11D,
CHAN_9C,
CHAN_10C,
CHAN_11A,
CHAN_11C,
CHAN_12A,
CHAN_6A
};
uint32_t frequency_list_bw[] = {
CHAN_5C,
CHAN_8D,
CHAN_9D,
CHAN_11B
};
uint32_t frequency_list_bb[] = {
CHAN_5C,
CHAN_7B,
CHAN_7D
};
uint32_t frequency_list_hb[] = {
CHAN_5C,
CHAN_7B,
CHAN_12A
};
uint32_t frequency_list_hh[] = {
CHAN_5C,
CHAN_7A
};
uint32_t frequency_list_he[] = {
CHAN_5C,
CHAN_7B,
CHAN_11C
};
uint32_t frequency_list_mv[] = {
CHAN_5C,
CHAN_12B
};
uint32_t frequency_list_ni[] = {
CHAN_5C,
CHAN_6A,
CHAN_6D,
CHAN_11B,
CHAN_12A
};
uint32_t frequency_list_rp[] = {
CHAN_5C,
CHAN_11A };
uint32_t frequency_list_sl[] = {
CHAN_5C,
CHAN_9A
};
uint32_t frequency_list_sn[] = {
CHAN_5C,
CHAN_9A
};
uint32_t frequency_list_st[] = {
CHAN_5C,
CHAN_11C,
CHAN_12C
};
uint32_t frequency_list_sh[] = {
CHAN_5C,
CHAN_9C
};
uint32_t frequency_list_th[] = {
CHAN_5C,
CHAN_7B,
CHAN_9C,
CHAN_12B
};
uint32_t frequency_list_it_sue[] = {
CHAN_10B,
CHAN_10C,
CHAN_10D,
CHAN_12A,
CHAN_12B,
CHAN_12C
};
uint32_t frequency_list_ch[] = {
CHAN_12A,
CHAN_12C,
CHAN_12D,
CHAN_7D,
CHAN_7A,
CHAN_9D,
CHAN_8B
};
//static struct global_args_t{
// int dab;
// int fm;
// int dab_start_service;
// int frequency;
// int dab_service_list;
//} global_args;
//
//static struct option long_options[]=
//{
// {"dab_start_service", required_argument, &global_args.dab_start_service,0},
// {"frequency", required_argument,&global_args.frequency,0},
// {"status", no_argument,0,'s'},
// {"dab", no_argument,&global_args.dab, 'd'},
// {"fm", no_argument,&global_args.fm, 'f'},
// {"dab_service_list", no_argument, &global_args.dab_service_list,0},
// {0,0,0,0}
//};
//
void show_help(char *prog_name) {
printf("usage: %s [-a|-b]\n", prog_name);
printf(" -a init DAB mode\n");
printf(" -b init fm mode\n");
printf(" -c frequency tune frequency in FM mode\n");
printf(" -d fm status\n");
printf(" -e dab status\n");
printf(" -f service start service of dab service list\n");
printf(" -g get dab service list\n");
printf(" -i channel tune to channel in dab frequency list\n");
printf(" -j region set frequency list\n");
printf(" 0 Baden-Wuertemberg\r\n");
printf(" 1 Bayern\r\n");
printf(" 2 Berlin-Brandenburg\r\n");
printf(" 3 Bremen\r\n");
printf(" 4 Hamburg\r\n");
printf(" 5 Hessen\r\n");
printf(" 6 Mecklenburg-Vorpommern\r\n");
printf(" 7 Niedersachsen\r\n");
printf(" 8 Nordrhein-Westfalen\r\n");
printf(" 9 Rheinland-Pfalz\r\n");
printf(" 10 Saarland\r\n");
printf(" 11 Sachsen\r\n");
printf(" 12 Sachsen-Anhalt\r\n");
printf(" 13 Schleswig-Holstein\r\n");
printf(" 14 Thueringen\r\n");
printf(" 15 Suedtirol (Italien)\r\n");
printf(" 16 Schweiz\r\n");
printf(" -k region scan frequency list\r\n");
printf(" -l up|down fm seek next station\r\n");
printf(" -m fm rds status\r\n");
printf(" -n dab get audio info\r\n");
printf(" -o service dab get subchannel info\r\n");
printf(" -s get sys state (fm,dab,am...)\r\n");
printf(" -h this help\n");
}
void load_regional_channel_list(uint8_t tmp) {
if (tmp == 0) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_bw), frequency_list_bw);
} else if (tmp == 1) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_by), frequency_list_by);
} else if (tmp == 2) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_bb), frequency_list_bb);
} else if (tmp == 3) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_hb), frequency_list_hb);
} else if (tmp == 4) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_hh), frequency_list_hh);
} else if (tmp == 5) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_he), frequency_list_he);
} else if (tmp == 6) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_mv), frequency_list_mv);
} else if (tmp == 7) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_ni), frequency_list_ni);
} else if (tmp == 8) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_nrw), frequency_list_nrw);
} else if (tmp == 9) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_rp), frequency_list_rp);
} else if (tmp == 10) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_sl), frequency_list_sl);
} else if (tmp == 11) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_sn), frequency_list_sn);
} else if (tmp == 12) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_st), frequency_list_st);
} else if (tmp == 13) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_sh), frequency_list_sh);
} else if (tmp == 14) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_th), frequency_list_th);
} else if (tmp == 15) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_it_sue), frequency_list_it_sue);
} else if (tmp == 16) {
si46xx_dab_set_freq_list(ARRAY_SIZE(frequency_list_ch), frequency_list_ch);
} else {
printf("Region %d not implemented\r\n", tmp);
}
}
int main(int argc, char **argv) {
int c;
int frequency;
int tmp;
struct dab_digrad_status_t dab_digrad_status;
printf("dabpi_ctl version %s\r\n", GIT_VERSION);
spi_init();
while ((c = getopt(argc, argv, "abc:def:ghi:j:k:l:mno:s")) != -1) {
switch (c) {
case 'a':
si46xx_init_dab();
break;
case 'b':
si46xx_init_fm();
break;
case 'c':
frequency = atoi(optarg);
si46xx_fm_tune_freq(frequency, 0);
break;
case 'd':
si46xx_fm_rsq_status();
break;
case 'e':
si46xx_dab_digrad_status(&dab_digrad_status);
si46xx_dab_digrad_status_print(&dab_digrad_status);
break;
case 'f':
si46xx_dab_get_digital_service_list();
si46xx_dab_print_service_list();
si46xx_dab_start_digital_service_num(atoi(optarg));
break;
case 'g':
si46xx_dab_get_digital_service_list();
si46xx_dab_print_service_list();
break;
case 'h':
show_help(argv[0]);
break;
case 'i':
si46xx_dab_tune_freq(atoi(optarg), 0);
break;
case 'j':
tmp = atoi(optarg);
load_regional_channel_list(tmp);
break;
case 'k':
tmp = atoi(optarg);
load_regional_channel_list(tmp);
si46xx_dab_scan();
break;
case 'l':
if (strcmp(optarg, "down") == 0) {
si46xx_fm_seek_start(0, 1);
} else {
si46xx_fm_seek_start(1, 1);
}
break;
case 'm':
si46xx_fm_rds_status();
si46xx_fm_rds_blockcount();
break;
case 'n':
si46xx_dab_get_audio_info();
break;
case 'o':
tmp = atoi(optarg);
si46xx_dab_get_digital_service_list();
si46xx_dab_print_service_list();
si46xx_dab_get_subchannel_info(tmp);
break;
case 's':
si46xx_get_sys_state();
break;
default:
show_help(argv[0]);
break;
}
}
if (argc == 1) {
show_help(argv[0]);
}
return 0;
}