Skip to content

Commit c1b402a

Browse files
committed
ExtIO calls functions as expected now
1 parent cffda21 commit c1b402a

11 files changed

Lines changed: 123 additions & 73 deletions

File tree

TSDRPlugin_ExtIO/src/ExtIOPluginLoader.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
void * fd;
2020

2121
// mandatory functions that the dll must implement
22-
bool (* InitHW) (char *name, char *model, int *hwtype); // for hwtype see enum extHWtypeT
23-
bool (* OpenHW) (void);
24-
void (* CloseHW) (void);
25-
int (* StartHW) (long extLOfreq);
26-
void (* StopHW) (void);
27-
void (* SetCallback) (pfnExtIOCallback funcptr);
28-
int (* SetHWLO) (long extLOfreq); // see also SetHWLO64
29-
int (* GetStatus) (void);
22+
bool (__stdcall * InitHW) (char *name, char *model, int *hwtype); // for hwtype see enum extHWtypeT
23+
bool (__stdcall * OpenHW) (void);
24+
void (__stdcall * CloseHW) (void);
25+
int (__stdcall * StartHW) (long extLOfreq);
26+
void (__stdcall * StopHW) (void);
27+
void (__stdcall * SetCallback) (pfnExtIOCallback funcptr);
28+
int (__stdcall * SetHWLO) (long extLOfreq); // see also SetHWLO64
29+
int (__stdcall * GetStatus) (void);
3030

3131
// optional functions
32-
void (* RawDataReady) (long samprate, void *Ldata, void *Rdata, int numsamples);
33-
void (* ShowGUI) (void);
34-
void (* HideGUI) (void);
32+
void (__stdcall * RawDataReady) (long samprate, void *Ldata, void *Rdata, int numsamples);
33+
void (__stdcall * ShowGUI) (void);
34+
void (__stdcall * HideGUI) (void);
3535

3636
} typedef extiosource_t;
3737

TSDRPlugin_ExtIO/src/TSDRPlugin.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
#ifndef _TSDRPluginHeader
22
#define _TSDRPluginHeader
33

4+
#ifdef __cplusplus
5+
#define EXTERNC extern "C"
6+
#else
7+
#define EXTERNC
8+
#endif
9+
410
#include <stdint.h>
511

612
typedef void(*tsdrplugin_readasync_function)(float *buf, uint32_t len, void *ctx, int dropped_samples);
713

8-
void tsdrplugin_getName(char *);
9-
int tsdrplugin_setParams(const char * params);
10-
uint32_t tsdrplugin_setsamplerate(uint32_t rate);
11-
uint32_t tsdrplugin_getsamplerate();
12-
int tsdrplugin_setbasefreq(uint32_t freq);
13-
int tsdrplugin_stop(void);
14-
int tsdrplugin_setgain(float gain);
15-
char * tsdrplugin_getlasterrortext(void);
16-
int tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx);
17-
void tsdrplugin_cleanup(void);
14+
EXTERNC void tsdrplugin_getName(char *);
15+
EXTERNC int tsdrplugin_init(const char * params);
16+
EXTERNC uint32_t tsdrplugin_setsamplerate(uint32_t rate);
17+
EXTERNC uint32_t tsdrplugin_getsamplerate();
18+
EXTERNC int tsdrplugin_setbasefreq(uint32_t freq);
19+
EXTERNC int tsdrplugin_stop(void);
20+
EXTERNC int tsdrplugin_setgain(float gain);
21+
EXTERNC char * tsdrplugin_getlasterrortext(void);
22+
EXTERNC int tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx);
23+
EXTERNC void tsdrplugin_cleanup(void);
1824

1925
#endif

TSDRPlugin_ExtIO/src/TSDRPlugin_ExtIO.c

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
extiosource_t * source = NULL;
1212
uint32_t init_freq = 100000000;
1313

14+
void closeextio(void) {
15+
if (source == NULL) return;
16+
source->CloseHW();
17+
extio_close(source);
18+
free (source);
19+
source = NULL;
20+
}
21+
1422
void tsdrplugin_getName(char * name) {
1523
strcpy(name, "TSDR ExtIO Plugin");
1624
}
@@ -41,32 +49,52 @@ int tsdrplugin_setgain(float gain) {
4149
RETURN_OK();
4250
}
4351

44-
int tsdrplugin_setParams(const char * params) {
52+
int callback(int cnt, int status, float IQoffs, void *IQdata) {
53+
return 0;
54+
}
55+
56+
int tsdrplugin_init(const char * params) {
57+
58+
extiosource_t * result = source;
4559

4660
// if an extio was already initialized before, now change
47-
if (source != NULL) {
48-
extio_close(source);
49-
free (source);
50-
source = NULL;
61+
if (result != NULL) {
62+
closeextio();
5163
}
5264

5365
// inititalize source
54-
source = (extiosource_t *) malloc(sizeof(extiosource_t));
55-
if (extio_load(source, params) == TSDR_OK) {
56-
// TODO! get samplerate?
57-
if (source->ShowGUI != NULL)
58-
source->ShowGUI();
59-
60-
RETURN_OK();
66+
result = (extiosource_t *) malloc(sizeof(extiosource_t));
67+
if (extio_load(result, params) == TSDR_OK) {
68+
char name[200];
69+
char model[200];
70+
int hwtype;
71+
72+
if (result->InitHW(name, model, &hwtype)) {
73+
result->SetCallback(&callback);
74+
75+
if (result->OpenHW()) {
76+
RETURN_OK();
77+
} else {
78+
closeextio();
79+
RETURN_EXCEPTION("The ExtIO driver failed to open a device. Make sure your device is plugged in and its drivers are installed correctly.", TSDR_CANNOT_OPEN_DEVICE);
80+
}
81+
} else {
82+
closeextio();
83+
RETURN_EXCEPTION("The ExtIO driver failed to initialize a device. Make sure your device is plugged in and its drivers are installed correctly.", TSDR_CANNOT_OPEN_DEVICE);
84+
}
6185
} else {
62-
free (source);
63-
source = NULL;
86+
free (result);
87+
result = NULL;
6488
RETURN_EXCEPTION("Cannot load the specified ExtIO dll file. Please check the filename is correct and the file is a valid ExtIO dll file and try again.", TSDR_PLUGIN_PARAMETERS_WRONG);
6589
}
6690

91+
source = result;
6792
}
6893

6994
int tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx) {
95+
if (source == NULL)
96+
RETURN_EXCEPTION("Please, first set parameters. The parameters need to contain a full path to the ExtIO dll.", TSDR_PLUGIN_PARAMETERS_WRONG);
97+
7098
RETURN_OK();
7199
}
72100

@@ -75,7 +103,5 @@ void tsdrplugin_cleanup(void) {
75103

76104
//if (source->pfnHideGUI != NULL) source->pfnHideGUI();
77105

78-
extio_close(source);
79-
free (source);
80-
source = NULL;
106+
closeextio();
81107
}

TSDRPlugin_Mirics/src/TSDRPlugin.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
#ifndef _TSDRPluginHeader
22
#define _TSDRPluginHeader
33

4+
#ifdef __cplusplus
5+
#define EXTERNC extern "C"
6+
#else
7+
#define EXTERNC
8+
#endif
9+
410
#include <stdint.h>
511

612
typedef void(*tsdrplugin_readasync_function)(float *buf, uint32_t len, void *ctx, int dropped_samples);
713

8-
void tsdrplugin_getName(char *);
9-
int tsdrplugin_setParams(const char * params);
10-
uint32_t tsdrplugin_setsamplerate(uint32_t rate);
11-
uint32_t tsdrplugin_getsamplerate();
12-
int tsdrplugin_setbasefreq(uint32_t freq);
13-
int tsdrplugin_stop(void);
14-
int tsdrplugin_setgain(float gain);
15-
char * tsdrplugin_getlasterrortext(void);
16-
int tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx);
17-
void tsdrplugin_cleanup(void);
14+
EXTERNC void tsdrplugin_getName(char *);
15+
EXTERNC int tsdrplugin_init(const char * params);
16+
EXTERNC uint32_t tsdrplugin_setsamplerate(uint32_t rate);
17+
EXTERNC uint32_t tsdrplugin_getsamplerate();
18+
EXTERNC int tsdrplugin_setbasefreq(uint32_t freq);
19+
EXTERNC int tsdrplugin_stop(void);
20+
EXTERNC int tsdrplugin_setgain(float gain);
21+
EXTERNC char * tsdrplugin_getlasterrortext(void);
22+
EXTERNC int tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx);
23+
EXTERNC void tsdrplugin_cleanup(void);
1824

1925
#endif

TSDRPlugin_Mirics/src/TSDRPlugin_Mirics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int tsdrplugin_setgain(float gain) {
7575
RETURN_OK();
7676
}
7777

78-
int tsdrplugin_setParams(const char * params) {
78+
int tsdrplugin_init(const char * params) {
7979
RETURN_OK();
8080
}
8181

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
#ifndef _TSDRPluginHeader
22
#define _TSDRPluginHeader
33

4+
#ifdef __cplusplus
5+
#define EXTERNC extern "C"
6+
#else
7+
#define EXTERNC
8+
#endif
9+
410
#include <stdint.h>
511

612
typedef void(*tsdrplugin_readasync_function)(float *buf, uint32_t len, void *ctx, int dropped_samples);
713

8-
void tsdrplugin_getName(char *);
9-
int tsdrplugin_setParams(const char * params);
10-
uint32_t tsdrplugin_setsamplerate(uint32_t rate);
11-
uint32_t tsdrplugin_getsamplerate();
12-
int tsdrplugin_setbasefreq(uint32_t freq);
13-
int tsdrplugin_stop(void);
14-
int tsdrplugin_setgain(float gain);
15-
char * tsdrplugin_getlasterrortext(void);
16-
int tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx);
17-
void tsdrplugin_cleanup(void);
14+
EXTERNC void tsdrplugin_getName(char *);
15+
EXTERNC int tsdrplugin_init(const char * params);
16+
EXTERNC uint32_t tsdrplugin_setsamplerate(uint32_t rate);
17+
EXTERNC uint32_t tsdrplugin_getsamplerate();
18+
EXTERNC int tsdrplugin_setbasefreq(uint32_t freq);
19+
EXTERNC int tsdrplugin_stop(void);
20+
EXTERNC int tsdrplugin_setgain(float gain);
21+
EXTERNC char * tsdrplugin_getlasterrortext(void);
22+
EXTERNC int tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx);
23+
EXTERNC void tsdrplugin_cleanup(void);
1824

1925
#endif

TSDRPlugin_RawFile/src/TSDRPlugin_RawFile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ char * nexttoken(char * input) {
142142
}
143143
}
144144

145-
int tsdrplugin_setParams(const char * params) {
145+
int tsdrplugin_init(const char * params) {
146146
char * fname = nexttoken((char *) params);
147147
if (fname == NULL) RETURN_EXCEPTION("File name was not specified. Commands should be: filename samplerate sampleformat. Format could be float, int8, uint8, int16 or uint16.", TSDR_PLUGIN_PARAMETERS_WRONG);
148148
char * samplerate_s = nexttoken(NULL);

TempestSDR/src/TSDRLibrary.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ void process(float *buf, uint32_t len, void *ctx, int dropped) {
372372

373373
pluginsource_t * plugin = (pluginsource_t *)(tsdr->plugin);
374374

375-
if ((status = plugin->tsdrplugin_setParams(params)) != TSDR_OK) {pluginsfault =1; goto end;};
375+
if ((status = plugin->tsdrplugin_init(params)) != TSDR_OK) {pluginsfault =1; goto end;};
376376
if ((status = tsdr_getsamplerate(tsdr)) != TSDR_OK) goto end;
377377
if ((status = tsdr_setbasefreq(tsdr, tsdr->centfreq)) != TSDR_OK) goto end;
378378
if ((status = tsdr_setgain(tsdr, tsdr->gain)) != TSDR_OK) goto end;

TempestSDR/src/TSDRPluginLoader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int tsdrplug_load(pluginsource_t * plugin, const char *dlname)
2727
if (plugin->fd == NULL)
2828
return TSDR_ERR_PLUGIN;
2929

30-
if ((plugin->tsdrplugin_setParams = tsdrplug_getfunction(plugin, "tsdrplugin_setParams")) == 0) return TSDR_ERR_PLUGIN;
30+
if ((plugin->tsdrplugin_init = tsdrplug_getfunction(plugin, "tsdrplugin_init")) == 0) return TSDR_ERR_PLUGIN;
3131
if ((plugin->tsdrplugin_getsamplerate = tsdrplug_getfunction(plugin, "tsdrplugin_getsamplerate")) == 0) return TSDR_ERR_PLUGIN;
3232
if ((plugin->tsdrplugin_getName = tsdrplug_getfunction(plugin, "tsdrplugin_getName")) == 0) return TSDR_ERR_PLUGIN;
3333
if ((plugin->tsdrplugin_setsamplerate = tsdrplug_getfunction(plugin, "tsdrplugin_setsamplerate")) == 0) return TSDR_ERR_PLUGIN;

TempestSDR/src/TSDRPluginLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
struct pluginsource {
1818
void * fd;
19-
int (*tsdrplugin_setParams)(const char * params);
19+
int (*tsdrplugin_init)(const char * params);
2020
void (*tsdrplugin_getName)(char *);
2121
uint32_t (*tsdrplugin_setsamplerate)(uint32_t);
2222
uint32_t (*tsdrplugin_getsamplerate)(void);

0 commit comments

Comments
 (0)