Skip to content

Commit 44dea2c

Browse files
committed
remove conf.h, define package and state directories from compiler command line, with defaults
1 parent 618e376 commit 44dea2c

16 files changed

Lines changed: 104 additions & 54 deletions

src/Makefile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ pkgdatadir ?= $(datadir)/ka9q-radio
1818
pkglibdir ?= $(libdir)/ka9q-radio
1919
statedir ?= $(localstatedir)/lib/ka9q-radio
2020

21+
# eg, /var/lib/ka9q-radio
22+
PATH_FLAGS += -DSTATEDIR=\"$(statedir)\"
23+
24+
# eg, /usr/local/share/ka9q-radio, /usr/share/ka9q-radio
25+
PATH_FLAGS += -DPKGDATADIR=\"$(pkgdatadir)\"
26+
27+
# eg, /usr/local/lib/ka9q-radio, /usr/lib/ka9q-radio
28+
PATH_FLAGS += -DPKGLIBDIR=\"$(pkglibdir)\"
29+
2130
UNAME_S := $(shell uname -s)
2231

2332
CPPFLAGS ?=
@@ -66,10 +75,10 @@ ARCHOPTS = -march=native
6675
# do NOT set -ffast-math or -ffinite-math-only; NANs are widely used as 'variable not set' sentinels
6776
COPTS = -std=gnu11 -pthread -Wall -funsafe-math-optimizations -fno-math-errno -fcx-limited-range -freciprocal-math -fno-trapping-math -D_GNU_SOURCE=1 -Wextra -Wno-sign-conversion -Wno-int-conversion -MMD -MP
6877
COPTS += -fPIC
69-
CFLAGS += $(DOPTS) $(ARCHOPTS) $(COPTS) $(INCLUDES) $(VERSION_FLAGS)
78+
CFLAGS += $(DOPTS) $(ARCHOPTS) $(COPTS) $(INCLUDES) $(VERSION_FLAGS) $(PATH_FLAGS)
7079
DAEMONS = aprs aprsfeed cwd packetd radiod
7180
EXECS = ctcss control fft-gen jt-decoded metadump monitor pcmrecord powers tune wd-record
72-
LIBRADIO = ax25.o morse.o bandplan.o dump.o modes.o avahi.o avahi_browse.o attr.o filter.o iir.o decode_status.o status.o misc.o multicast.o rtp.o osc.o config.o sincospi.o sincospif.o window.o gauss.o
81+
LIBRADIO = ax25.o morse.o dump.o modes.o avahi.o avahi_browse.o attr.o filter.o iir.o decode_status.o status.o misc.o multicast.o rtp.o osc.o config.o sincospi.o sincospif.o window.o gauss.o
7382
DYNAMIC_DRIVERS = sig_gen.so
7483
RADIOD_OBJECTS = main.o audio.o fm.o wfm.o linear.o spectrum.o radio.o radio_status.o rtcp.o fcd.o hid-libusb.o libradio.a
7584
CFILES = airspy.c airspyhf.c aprs.c aprsfeed.c attr.c audio.c avahi.c avahi_browse.c ax25.c bandplan.c config.c control.c cwd.c decimate.c decode_status.c dump.c ezusb.c fcd.c filter.c fm.c funcube.c hid-libusb.c iir.c jt-decoded.c linear.c main.c metadump.c misc.c modes.c monitor.c monitor-data.c monitor-display.c monitor-repeater.c morse.c multicast.c opusd.c opussend.c osc.c packetd.c pcmcat.c pcmrecord.c pcmsend.c pcmspawn.c ctcss.c powers.c radio.c radio_status.c rdsd.c rtcp.c rtlsdr.c rtp.c rx888.c setfilt.c show-pkt.c show-sig.c sig_gen.c spectrum.c status.c stereod.c tune.c wd-record.c wfm.c
@@ -169,7 +178,7 @@ aprs: aprs.o libradio.a
169178
aprsfeed: aprsfeed.o libradio.a
170179
$(CC) $(LDOPTS) -o $@ $^ $(LDLIBS)
171180

172-
control: control.o libradio.a
181+
control: control.o bandplan.o libradio.a
173182
$(CC) $(LDOPTS) -o $@ $^ -liniparser -lncursesw $(LDLIBS)
174183

175184
ctcss: ctcss.o libradio.a

src/bandplan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
#include <limits.h>
1616
#include <stdbool.h>
1717

18-
#include "conf.h"
1918
#include "misc.h"
2019
#include "bandplan.h"
2120

21+
#define BANDPLAN "bandplan.txt"
22+
2223
char Bandplan_file[] = BANDPLAN;
2324
#define MAX_BANDPLANS 1000
2425
struct bandplan Bandplans[MAX_BANDPLANS];

src/conf.h

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/fft-gen.c

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
#include <sys/stat.h>
1717
#include <errno.h>
1818
#include <sys/file.h>
19+
#include <limits.h>
1920

2021
#define System_wisdom_file "/etc/fftw/wisdomf"
21-
#define Wisdom_dir "/var/lib/ka9q-radio"
22-
#define Wisdom_file "/var/lib/ka9q-radio/wisdom"
22+
23+
#ifndef STATEDIR
24+
#define STATEDIR "/var/lib/ka9q-radio"
25+
#endif
26+
#define WISDOM_FILE "wisdom"
2327

2428
static int Verbose;
2529
static bool Force;
@@ -173,16 +177,18 @@ int main(int argc,char *argv[]){
173177
}
174178
}
175179
track_wisdom_length();
176-
lr = fftwf_import_wisdom_from_filename(Wisdom_file);
180+
char wisdom_file[PATH_MAX];
181+
snprintf(wisdom_file,sizeof wisdom_file,"%s/%s",STATEDIR,WISDOM_FILE);
182+
lr = fftwf_import_wisdom_from_filename(wisdom_file);
177183
if(Verbose > 1){
178-
printf("fftwf_import_wisdom_from_filename(%s) %s\n",Wisdom_file,lr ? "succeeded" : "failed");
184+
printf("fftwf_import_wisdom_from_filename(%s) %s\n",wisdom_file,lr ? "succeeded" : "failed");
179185
if(!lr){
180-
if(access(Wisdom_file,R_OK) == -1){
181-
printf("%s not readable: %s\n",Wisdom_file,strerror(errno));
186+
if(access(wisdom_file,R_OK) == -1){
187+
printf("%s not readable: %s\n",wisdom_file,strerror(errno));
182188
}
183189
}
184-
if(access(Wisdom_file,W_OK) == -1)
185-
printf("Warning: %s not writeable, exports will fail: %s\n",Wisdom_file,strerror(errno));
190+
if(access(wisdom_file,W_OK) == -1)
191+
printf("Warning: %s not writeable, exports will fail: %s\n",wisdom_file,strerror(errno));
186192
}
187193
track_wisdom_length();
188194
}
@@ -310,7 +316,10 @@ static int save_plans(){
310316
int fd = -1;
311317

312318
// Import or re-import wisdom and merge
313-
if(asprintf(&lockfile,"%s.lock",Wisdom_file) <= 0){
319+
char wisdom_file[PATH_MAX];
320+
snprintf(wisdom_file,sizeof wisdom_file,"%s/%s",STATEDIR,WISDOM_FILE);
321+
322+
if(asprintf(&lockfile,"%s.lock",wisdom_file) <= 0){
314323
free(lockfile);
315324
return 0;
316325
}
@@ -320,12 +329,12 @@ static int save_plans(){
320329
printf("Can't acquire lock on %s\n",lockfile);
321330
else
322331
flock(lockfd,LOCK_EX);
323-
bool reimport = fftwf_import_wisdom_from_filename(Wisdom_file);
332+
bool reimport = fftwf_import_wisdom_from_filename(wisdom_file);
324333
if(Verbose > 1)
325-
printf("fftwf_import_wisdom_from_filename(%s) %s\n",Wisdom_file,reimport ? "succeeded" : "failed");
334+
printf("fftwf_import_wisdom_from_filename(%s) %s\n",wisdom_file,reimport ? "succeeded" : "failed");
326335
track_wisdom_length();
327336

328-
if(asprintf(&newtemp,"%s-XXXXXX",Wisdom_file) < 0)
337+
if(asprintf(&newtemp,"%s-XXXXXX",wisdom_file) < 0)
329338
goto quit;
330339

331340
wisdom = fftwf_export_wisdom_to_string();
@@ -350,7 +359,7 @@ static int save_plans(){
350359

351360
// Copy user/group/mode from old version
352361
struct stat st;
353-
if(stat(Wisdom_file,&st) == 0){
362+
if(stat(wisdom_file,&st) == 0){
354363
int r = fchown(fd, st.st_uid, st.st_gid); // Best effort
355364
(void)r;
356365
fchmod(fd, st.st_mode);
@@ -363,13 +372,13 @@ static int save_plans(){
363372
fsync(fd);
364373
close(fd);
365374
fd = -1;
366-
int dir = open(Wisdom_dir,O_DIRECTORY);
375+
int dir = open(STATEDIR,O_DIRECTORY);
367376
fsync(dir);
368377
close(dir);
369-
if(rename(newtemp,Wisdom_file) != 0)
370-
printf("rename %s to %s failed: %s\n",newtemp,Wisdom_file,strerror(errno));
378+
if(rename(newtemp,wisdom_file) != 0)
379+
printf("rename %s to %s failed: %s\n",newtemp,wisdom_file,strerror(errno));
371380
else if(Verbose > 1)
372-
printf("rename %s to %s succeeded\n",newtemp,Wisdom_file);
381+
printf("rename %s to %s succeeded\n",newtemp,wisdom_file);
373382

374383
if(Force)
375384
fftwf_forget_wisdom(); // start fresh for the next on the list

src/filter.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@
3333
#pragma GCC diagnostic pop
3434
#endif
3535

36-
#include "conf.h"
3736
#include "misc.h"
3837
#include "filter.h"
3938
#include "window.h"
4039

41-
#define FFT_LOG_FILE "/var/lib/ka9q-radio/fft.log"
40+
#ifndef STATEDIR
41+
#define STATEDIR "/var/lib/ka9q-radio"
42+
#endif
43+
#define FFT_LOG_FILE "fft.log"
44+
45+
const char *Wisdom_file; // Set in radio.c when reading config file
46+
4247

4348
//#define FILTER_DEBUG 1 // turn on lots of printfs in the window creation code
4449

4550
// Settable from main
46-
char const *Wisdom_file = "/var/lib/ka9q-radio/wisdom";
4751
char const *System_wisdom_file = "/etc/fftw/wisdomf"; // only valid for float version
4852
int N_worker_threads = 1;
4953
int N_internal_threads = 1; // Usually most efficient
@@ -211,9 +215,11 @@ int create_filter_input(struct filter_in *master,int const L,int const M, enum f
211215
// of independent FFTs to execute at the same time
212216
if(!atomic_flag_test_and_set_explicit(&FFTW_init,memory_order_relaxed)){
213217
fprintf(stderr,"FFTW version: %s\n", fftwf_version);
214-
FFT_log = fopen(FFT_LOG_FILE,"a");
218+
char fft_file[PATH_MAX];
219+
snprintf(fft_file,sizeof fft_file,"%s/%s",STATEDIR,FFT_LOG_FILE);
220+
FFT_log = fopen(fft_file,"a");
215221
if(FFT_log == NULL)
216-
fprintf(stderr,"Can't append to %s: %s\n",FFT_LOG_FILE,strerror(errno));
222+
fprintf(stderr,"Can't append to %s: %s\n",fft_file,strerror(errno));
217223

218224
fftwf_init_threads();
219225
bool sr = fftwf_import_system_wisdom();
@@ -223,7 +229,6 @@ int create_filter_input(struct filter_in *master,int const L,int const M, enum f
223229
fprintf(stderr,"%s not readable: %s\n",System_wisdom_file,strerror(errno));
224230
}
225231
}
226-
227232
bool lr = fftwf_import_wisdom_from_filename(Wisdom_file);
228233
fprintf(stderr,"fftwf_import_wisdom_from_filename(%s) %s\n",Wisdom_file,lr ? "succeeded" : "failed");
229234
if(!lr){

src/filter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern double FFTW_plan_timelimit;
2222
extern pthread_mutex_t FFTW_planning_mutex;
2323
extern int N_internal_threads;
2424
extern int N_worker_threads; // owned by filter.c
25+
extern char const *Wisdom_file;
2526

2627
// Input can be REAL or COMPLEX
2728
// Output can be REAL, COMPLEX, BEAM or SPECTRUM

src/hydrasdr.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,24 @@ static void *hydrasdr_monitor(void *p){
325325
(void)ret;
326326
assert(ret == HYDRASDR_SUCCESS);
327327
fprintf(stderr,"hydrasdr running\n");
328+
#if 1
329+
{
330+
hydrasdr_device_info_t info = {0};
331+
hydrasdr_get_device_info(sdr->device, &info);
332+
333+
// Current streaming configuration
334+
fprintf(stderr,"Effective rate: %u Hz\n", info.current_samplerate);
335+
fprintf(stderr,"Hardware rate: %u Hz\n", info.current_hw_samplerate);
336+
fprintf(stderr,"Decimation: %ux (%s mode)\n",
337+
info.current_decimation_factor,
338+
info.current_decimation_mode ? "High Definition" : "Low Bandwidth");
339+
fprintf(stderr,"Bandwidth: %u Hz (%s)\n",
340+
info.current_bandwidth,
341+
info.bandwidth_auto_selected ? "auto" : "manual");
342+
fprintf(stderr,"Sample type: %u\n", info.current_sample_type);
343+
fprintf(stderr,"Packing: %s\n", info.current_packing ? "12-bit" : "16-bit");
344+
}
345+
#endif
328346
// Periodically poll status to ensure device hasn't reset
329347
while(true){
330348
sleep(1);

src/misc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
#define NULL ((void *)0)
3434
#endif
3535

36-
#include "conf.h"
3736
#include "misc.h"
3837

39-
char const *Libdir = LIBDIR;
38+
#ifndef PKGDATADIR
39+
#define PKGDATADIR "/usr/local/share/ka9q-radio"
40+
#endif
41+
42+
char const *Pkgdatadir = PKGDATADIR;
4043

4144
// Return path to file which is part of the application distribution.
4245
// This allows to run the program either from build directory or from
@@ -57,7 +60,7 @@ int dist_path(char *path,int path_len,const char *fname){
5760
if(stat(path, &st) == 0 && (st.st_mode & S_IFMT) == S_IFREG)
5861
return 0;
5962

60-
snprintf(path,path_len,"%s/%s",Libdir,fname);
63+
snprintf(path,path_len,"%s/%s",Pkgdatadir,fname);
6164
if(stat(path, &st) == 0 && (st.st_mode & S_IFMT) == S_IFREG)
6265
return 0;
6366

src/monitor-data.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <poll.h>
2626
#include <stdatomic.h>
2727

28-
#include "conf.h"
2928
#include "config.h"
3029
#include "misc.h"
3130
#include "multicast.h"

src/monitor-display.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <regex.h>
2626
#include <ctype.h>
2727

28-
#include "conf.h"
2928
#include "config.h"
3029
#include "misc.h"
3130
#include "multicast.h"
@@ -35,6 +34,8 @@
3534
#include "status.h"
3635
#include "monitor.h"
3736

37+
#define ID "id.txt"
38+
3839
bool Auto_sort = false;
3940
int Update_interval = 100; // Default time in ms between display updates
4041

0 commit comments

Comments
 (0)