Skip to content

Commit f1ea4eb

Browse files
committed
Mirics is changing freq now
1 parent ce1fca4 commit f1ea4eb

13 files changed

Lines changed: 130 additions & 21 deletions

File tree

JavaGUI/jni/TSDRLibraryNDK.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ void error_translate (int exception_code, char * exceptionclass) {
4848
case TSDR_SAMPLE_RATE_WRONG:
4949
strcpy(exceptionclass, "martin/tempest/core/exceptions/TSDRSampleRateWrongException");
5050
return;
51+
case TSDR_CANNOT_OPEN_DEVICE:
52+
strcpy(exceptionclass, "martin/tempest/core/exceptions/TSDRCannotOpenDeviceException");
53+
return;
5154
default:
5255
strcpy(exceptionclass, "java/lang/Exception");
5356
return;

JavaGUI/jni/include/TSDRCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define TSDR_ALREADY_RUNNING (3)
88
#define TSDR_PLUGIN_PARAMETERS_WRONG (4)
99
#define TSDR_SAMPLE_RATE_WRONG (5)
10+
#define TSDR_CANNOT_OPEN_DEVICE (6)
1011
#define TSDR_NOT_IMPLEMENTED (404)
1112

1213
#endif

JavaGUI/jni/include/TSDRLibrary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
volatile int running;
1818
volatile int nativerunning;
1919
int frames_to_average;
20+
uint32_t centfreq;
2021
} typedef tsdr_lib_t;
2122

2223
typedef void(*tsdr_readasync_function)(float *buf, int width, int height, void *ctx);

JavaGUI/src/martin/tempest/Main.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ public void stateChanged(ChangeEvent arg0) {
190190
frmTempestSdr.getContentPane().add(lblFrequency);
191191

192192
spFrequency = new JSpinner();
193+
spFrequency.addChangeListener(new ChangeListener() {
194+
public void stateChanged(ChangeEvent arg0) {
195+
onCenterFreqChange();
196+
}
197+
});
193198
spFrequency.setBounds(223, 470, 340, 22);
194199
spFrequency.setModel(new SpinnerNumberModel(new Long(200000000), new Long(0), new Long(2147483647), new Long(1)));
195200
frmTempestSdr.getContentPane().add(spFrequency);
@@ -224,6 +229,15 @@ public void run() {
224229

225230
src.setParams(textArgs.getText());
226231

232+
final Long newfreq = (Long) spFrequency.getValue();
233+
if (newfreq != null && newfreq > 0)
234+
try {
235+
mSdrlib.setBaseFreq(newfreq);
236+
} catch (TSDRException e) {
237+
displayException(frmTempestSdr, e);
238+
return;
239+
}
240+
227241
new Thread() {
228242
public void run() {
229243
try {
@@ -249,6 +263,18 @@ private void onResolutionChange() {
249263
displayException(frmTempestSdr, e);
250264
}
251265
}
266+
267+
private void onCenterFreqChange() {
268+
final Long newfreq = (Long) spFrequency.getValue();
269+
270+
if (newfreq == null || newfreq < 0) return;
271+
272+
try {
273+
mSdrlib.setBaseFreq(newfreq);
274+
} catch (TSDRException e) {
275+
displayException(frmTempestSdr, e);
276+
}
277+
}
252278

253279
@Override
254280
public void onFrameReady(TSDRLibrary lib, BufferedImage frame) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package martin.tempest.core.exceptions;
2+
3+
public class TSDRCannotOpenDeviceException extends TSDRException {
4+
5+
private static final long serialVersionUID = -7807615914689137600L;
6+
7+
public TSDRCannotOpenDeviceException(final Exception e) {
8+
super(e);
9+
}
10+
11+
public TSDRCannotOpenDeviceException(final String msg) {
12+
super(msg);
13+
}
14+
}

JavaGUI/src/martin/tempest/core/exceptions/TSDRVideoParamsException.java

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

33
public class TSDRVideoParamsException extends TSDRException {
44

5-
private static final long serialVersionUID = -7807615914689137600L;
5+
private static final long serialVersionUID = -1477143402409561990L;
66

77
public TSDRVideoParamsException(final Exception e) {
88
super(e);

TSDRPlugin_Mirics/src/TSDRCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define TSDR_ALREADY_RUNNING (3)
88
#define TSDR_PLUGIN_PARAMETERS_WRONG (4)
99
#define TSDR_SAMPLE_RATE_WRONG (5)
10+
#define TSDR_CANNOT_OPEN_DEVICE (6)
1011
#define TSDR_NOT_IMPLEMENTED (404)
1112

1213
#endif

TSDRPlugin_Mirics/src/TSDRPlugin_Mirics.c

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,34 @@
77
#include <mir_sdr.h>
88

99
#include <stdint.h>
10+
#include <stdlib.h>
11+
12+
#define SAMPLE_RATE (8000000)
13+
14+
volatile int working = 0;
15+
double freq = 200;
16+
double desiredfreq = 200;
1017

1118
void tsdrplugin_getName(char * name) {
1219
strcpy(name, "TSDR Mirics SDR Plugin");
1320
}
1421

1522
uint32_t tsdrplugin_setsamplerate(uint32_t rate) {
16-
printf("Mirics setsamplerate %d\n", rate);
17-
return TSDR_NOT_IMPLEMENTED;
23+
return SAMPLE_RATE;
1824
}
1925

2026
uint32_t tsdrplugin_getsamplerate() {
21-
printf("Mirics getsamplerate\n");
22-
return TSDR_NOT_IMPLEMENTED;
27+
return SAMPLE_RATE;
2328
}
2429

2530
int tsdrplugin_setbasefreq(uint32_t freq) {
26-
printf("Mirics setbasefreq %d\n", freq);
27-
return TSDR_NOT_IMPLEMENTED;
31+
desiredfreq = freq;
32+
return TSDR_OK;
2833
}
2934

3035
int tsdrplugin_stop(void) {
31-
printf("Mirics stop\n");
32-
return TSDR_NOT_IMPLEMENTED;
36+
working = 0;
37+
return TSDR_OK;
3338
}
3439

3540
int tsdrplugin_setgain(float gain) {
@@ -38,16 +43,62 @@ int tsdrplugin_setgain(float gain) {
3843
}
3944

4045
int tsdrplugin_setParams(const char * params) {
41-
float ver;
42-
int err;
43-
44-
err = mir_sdr_ApiVersion(&ver);
45-
printf("MIRICS VERSION %.4f with err %d\n", ver, err);
46-
printf("Mirics setParams %s\n", params);
47-
return TSDR_NOT_IMPLEMENTED;
46+
return TSDR_OK;
4847
}
4948

5049
int tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx) {
51-
printf("Mirics Readasync\n");
52-
return TSDR_NOT_IMPLEMENTED;
50+
working = 1;
51+
52+
int err, sps, grc, rfc, fsc, i;
53+
unsigned int fs;
54+
int newGr = 40;
55+
56+
freq = desiredfreq;
57+
err = mir_sdr_Init(newGr, 8, freq / 1000000.0, mir_sdr_BW_8_000, mir_sdr_IF_Zero, &sps);
58+
if (err != 0) {
59+
mir_sdr_Uninit();
60+
return TSDR_CANNOT_OPEN_DEVICE;
61+
}
62+
63+
short * xi = (short *)malloc(sps * sizeof(short));
64+
short * xq = (short *)malloc(sps * sizeof(short));
65+
66+
int outbufsize = 2 * sps;
67+
float * outbuf = (float *) malloc(sizeof(float) * outbufsize);
68+
69+
while (working) {
70+
err = mir_sdr_ReadPacket(xi, xq, &fs, &grc, &rfc, &fsc);
71+
if (err != 0) break;
72+
73+
if (freq != desiredfreq) {
74+
freq = desiredfreq;
75+
err = mir_sdr_SetRf(freq, 1, 0);
76+
77+
if (err == mir_sdr_RfUpdateError) {
78+
mir_sdr_Uninit();
79+
err = mir_sdr_Init(newGr, 8, freq / 1000000.0, mir_sdr_BW_8_000, mir_sdr_IF_Zero, &sps);
80+
}
81+
82+
if (err != 0) {
83+
printf("FS error id %d trying to set freq to %.4f\n", err, freq);
84+
break;
85+
}
86+
}
87+
88+
89+
for (i = 0; i < outbufsize; i++) {
90+
const short val = (i & 1) ? (xq[i >> 1]) : (xi[i >> 1]);
91+
outbuf[i] = (val - 32767) / 32767.0;
92+
}
93+
94+
cb(outbuf, outbufsize, ctx);
95+
}
96+
97+
free(outbuf);
98+
free(xi);
99+
free(xq);
100+
101+
if (mir_sdr_Uninit() != 0) return TSDR_ERR_PLUGIN;
102+
103+
return (err == 0) ? TSDR_OK : TSDR_ERR_PLUGIN;
53104
}

TSDRPlugin_RawFile/src/TSDRCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define TSDR_ALREADY_RUNNING (3)
88
#define TSDR_PLUGIN_PARAMETERS_WRONG (4)
99
#define TSDR_SAMPLE_RATE_WRONG (5)
10+
#define TSDR_CANNOT_OPEN_DEVICE (6)
1011
#define TSDR_NOT_IMPLEMENTED (404)
1112

1213
#endif

TSDRPlugin_RawFile/src/TSDRPlugin_RawFile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int tsdrplugin_stop(void) {
6565
}
6666

6767
int tsdrplugin_setgain(float gain) {
68-
return TSDR_NOT_IMPLEMENTED;
68+
return TSDR_OK;
6969
}
7070

7171
char * strtoken = NULL;

0 commit comments

Comments
 (0)