-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtIO_Omnia.cpp
588 lines (514 loc) · 13.5 KB
/
ExtIO_Omnia.cpp
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
// #define WIN32_LEAN_AND_MEAN // Selten verwendete Teile der Windows-Header nicht einbinden.
#include <windows.h>
#include <commctrl.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "ExtIO_Omnia.h"
#include "Audio.h"
#include "cat.h"
#include "Config.h"
#include "ConfigDlg.h"
#include "UIHooks.h"
#pragma warning(disable : 4996)
#define snprintf _snprintf
static bool SDR_supports_settings = false; // assume not supported
static bool SDR_settings_valid = false; // assume settings are for some other ExtIO
static char SDR_progname[32+1] = "\0";
static int SDR_ver_major = -1;
static int SDR_ver_minor = -1;
volatile int64_t glLOfreq = 0L;
bool gbInitHW = false;
int giAttIdx = 0;
int giDefaultAttIdx = 4; // 0 dB
int giMgcIdx = 0;
int giDefaultMgcIdx = 0; // 0 dB
int giAgcIdx = 0;
int giDefaultAgcIdx = 1; // Auto
int giThrIdx = 0;
int giDefaultThrIdx = 2; // Threshold: 20 dB
int giWhatIdx = 0;
pfnExtIOCallback pfnCallback = nullptr;
volatile int giParameterSetNo = 0;
Audio g_Audio;
UIHooks g_UIHooks;
HINSTANCE g_hInstance = (HINSTANCE)nullptr;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
g_hInstance = (HINSTANCE)hModule;
INITCOMMONCONTROLSEX ice;
ice.dwSize = sizeof(ice);
ice.dwICC = ICC_TAB_CLASSES | ICC_UPDOWN_CLASS;
InitCommonControlsEx(&ice);
break;
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
extern "C"
bool __declspec(dllexport) __stdcall InitHW(char *name, char *model, int& type)
{
type = exthwUSBfloat32;
strcpy(name, HWNAME);
strcpy(model, HWMODEL);
if ( !gbInitHW )
{
// do initialization
glLOfreq = 6075000L; // just a default value
// .......... init here the hardware controlled by the DLL
// ......... init here the DLL graphical interface, if any
giAttIdx = giDefaultAttIdx;
giMgcIdx = giDefaultMgcIdx;
giAgcIdx = giDefaultAgcIdx;
giThrIdx = giDefaultThrIdx;
g_Audio.init();
if (! g_Audio.get_error().empty()) {
::MessageBoxA(nullptr, g_Audio.get_error().c_str(), "ExtIO_Omnia", MB_OK | MB_ICONERROR);
} else {
g_Cat.init();
if (! g_Cat.get_error().empty())
::MessageBoxA(nullptr, g_Cat.get_error().c_str(), "ExtIO_Omnia", MB_OK | MB_ICONERROR);
}
gbInitHW = true;
}
return gbInitHW;
}
//---------------------------------------------------------------------------
extern "C"
bool EXTIO_API OpenHW(void)
{
// .... display here the DLL panel ,if any....
// .....if no graphical interface, delete the following statement
//::SetWindowPos(F->handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
if (pfnCallback) {
pfnCallback(-1, extHw_Changed_ATT, 0.0F, 0);
// Let HDSDR swap the left / right IQ channels for the Omnia.
pfnCallback(-1, extHw_RX_SwapIQ_ON, 0.0F, 0);
pfnCallback(-1, extHw_TX_SwapIQ_ON, 0.0F, 0);
}
g_Cat.set_cw_keyer_mode(g_config.keyer_mode);
g_Cat.set_cw_keyer_speed(g_config.keyer_wpm);
g_Cat.setIQBalanceAndPower(g_config.tx_iq_balance_phase_correction, g_config.tx_iq_balance_amplitude_correction, g_config.tx_power);
// in the above statement, F->handle is the window handle of the panel displayed
// by the DLL, if such a panel exists
return gbInitHW;
}
//---------------------------------------------------------------------------
extern "C"
int EXTIO_API StartHW(long LOfreq)
{
int64_t ret = StartHW64( (int64_t)LOfreq );
return (int)ret;
}
//---------------------------------------------------------------------------
extern "C"
int64_t EXTIO_API StartHW64(int64_t LOfreq)
{
if (!gbInitHW)
return 0;
g_UIHooks.initialize();
g_Audio.stop();
SetHWLO64(LOfreq);
g_Audio.start();
// number of complex elements returned each
// invocation of the callback routine
return EXT_BLOCKLEN;
}
//---------------------------------------------------------------------------
extern "C"
void EXTIO_API StopHW(void)
{
g_Audio.stop();
return; // nothing to do with this specific HW
}
//---------------------------------------------------------------------------
extern "C"
void EXTIO_API CloseHW(void)
{
// ..... here you can shutdown your graphical interface, if any............
g_UIHooks.destroy();
destroy_config_dialog();
if (gbInitHW)
{
/* close port */
}
gbInitHW = false;
}
//---------------------------------------------------------------------------
extern "C"
int EXTIO_API SetHWLO(long LOfreq)
{
int64_t ret = SetHWLO64( (int64_t)LOfreq );
return (ret & 0xFFFFFFFF);
}
extern "C"
int64_t EXTIO_API SetHWLO64(int64_t LOfreq)
{
// take frequency
glLOfreq = LOfreq;
g_Cat.set_freq(LOfreq);
return 0;
}
//---------------------------------------------------------------------------
extern "C"
int EXTIO_API GetStatus(void)
{
return 0; // status not supported by this specific HW,
}
//---------------------------------------------------------------------------
extern "C"
void EXTIO_API SetCallback( pfnExtIOCallback funcptr )
{
pfnCallback = funcptr;
return;
}
//---------------------------------------------------------------------------
extern "C"
long EXTIO_API GetHWLO(void)
{
return (long)( glLOfreq & 0xFFFFFFFF );
}
extern "C"
int64_t EXTIO_API GetHWLO64(void)
{
return glLOfreq;
}
//---------------------------------------------------------------------------
extern "C"
long EXTIO_API GetHWSR(void)
{
// This DLL controls just an oscillator, not a digitizer
return SAMPLE_RATE;
}
//---------------------------------------------------------------------------
// extern "C" long EXTIO_API GetTune(void);
// extern "C" void EXTIO_API GetFilters(int& loCut, int& hiCut, int& pitch);
// extern "C" char EXTIO_API GetMode(void);
extern "C" void EXTIO_API ModeChanged(char mode)
{
char buf[2048];
sprintf(buf, "Mode changed: %c\n", mode);
OutputDebugStringA(buf);
g_UIHooks.show_my_panel(mode == 'C');
}
// extern "C" void EXTIO_API IFLimitsChanged(long low, long high);
extern "C" void EXTIO_API TuneChanged64(int64_t freq)
{
g_Cat.set_cw_tx_freq(freq + CW_IQ_TONE_OFFSET);
}
extern "C" void EXTIO_API TuneChanged(long freq)
{
char buf[2048];
sprintf(buf, "tuned to %ld\n", freq);
OutputDebugStringA(buf);
TuneChanged64((int64_t)freq);
}
// extern "C" int64_t EXTIO_API GetTune64(void);
// extern "C" void EXTIO_API IFLimitsChanged64(int64_t low, int64_t high);
//---------------------------------------------------------------------------
// extern "C" void EXTIO_API RawDataReady(long samprate, int *Ldata, int *Rdata, int numsamples)
extern "C" void EXTIO_API SwitchGUI()
{
toggle_config_dialog(g_hInstance);
}
//---------------------------------------------------------------------------
extern "C"
void EXTIO_API VersionInfo(const char * progname, int ver_major, int ver_minor)
{
SDR_progname[0] = 0;
SDR_ver_major = -1;
SDR_ver_minor = -1;
if ( progname )
{
strncpy( SDR_progname, progname, sizeof(SDR_progname) -1 );
SDR_ver_major = ver_major;
SDR_ver_minor = ver_minor;
// possibility to check program's capabilities
// depending on SDR program name and version,
// f.e. if specific extHWstatusT enums are supported
}
}
//---------------------------------------------------------------------------
// following "Attenuator"s visible on "RF" button
extern "C"
int EXTIO_API GetAttenuators( int atten_idx, float * attenuation )
{
// fill in attenuation
// use positive attenuation levels if signal is amplified (LNA)
// use negative attenuation levels if signal is attenuated
// sort by attenuation: use idx 0 for highest attenuation / most damping
// this functions is called with incrementing idx
// - until this functions return != 0 for no more attenuator setting
switch ( atten_idx )
{
case 0: *attenuation = -30.0F; return 0;
case 1: *attenuation = -20.0F; return 0;
case 2: *attenuation = -10.0F; return 0;
case 3: *attenuation = -6.0F; return 0;
case 4: *attenuation = 0.0F; return 0;
case 5: *attenuation = 9.0F; return 0;
default: return 1;
}
return 1;
}
extern "C"
int EXTIO_API GetActualAttIdx(void)
{
return giAttIdx; // returns -1 on error
}
extern "C"
int EXTIO_API SetAttenuator( int atten_idx )
{
int iPrevAttIdx = giAttIdx;
switch ( atten_idx )
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
giAttIdx = atten_idx;
if ( iPrevAttIdx != giAttIdx )
++giParameterSetNo;
return 0;
default:
return 1; // ERROR
}
return 1; // ERROR
}
//---------------------------------------------------------------------------
// optional function to get AGC Mode: AGC_OFF (always agc_index = 0), AGC_SLOW, AGC_MEDIUM, AGC_FAST, ...
// this functions is called with incrementing idx
// - until this functions returns != 0, which means that all agc modes are already delivered
extern "C"
int EXTIO_API ExtIoGetAGCs(int agc_idx, char * text) // text limited to max 16 char
{
switch (agc_idx)
{
case 0: strcpy(text, "MGC"); return 0;
case 1: strcpy(text, "AGC"); return 0;
case 2: strcpy(text, "Thr"); return 0;
//case 3: strcpy(text, "?"); return 0;
default: return 1;
}
return 1;
}
extern "C"
int EXTIO_API ExtIoGetActualAGCidx(void)
{
return giAgcIdx; // returns -1 on error
}
extern "C"
int EXTIO_API ExtIoSetAGC(int agc_idx)
{
// returns != 0 on error
int iPrevAgcIdx = giAgcIdx;
switch (agc_idx)
{
case 0:
case 1:
case 2:
//case 3:
giAgcIdx = agc_idx;
if (iPrevAgcIdx != giAgcIdx)
{
++giParameterSetNo;
if (pfnCallback )
EXTIO_STATUS_CHANGE(pfnCallback, extHw_Changed_RF_IF);
}
return 0;
default:
return 1; // ERROR
}
return 1; // ERROR
}
// optional: HDSDR >= 2.62
extern "C"
int EXTIO_API ExtIoShowMGC(int agc_idx) // return 1, to continue showing MGC slider on AGC
// return 0, is default for not showing MGC slider
{
switch (agc_idx)
{
case 0: return 1; // MGC
case 1: return 1; // AGC
case 2: return 1; // Thr
//case 3: return 1; // ?
default:
return 0; // ERROR
}
return 0; // ERROR
}
//---------------------------------------------------------------------------
// following "MGC"s visible on "IF" button
extern "C"
int EXTIO_API ExtIoGetMGCs(int mgc_idx, float * gain)
{
// fill in gain
// sort by ascending gain: use idx 0 for lowest gain
// this functions is called with incrementing idx
// - until this functions returns != 0, which means that all gains are already delivered
switch (giAgcIdx)
{
case 0: // MGC
switch (mgc_idx)
{
case 0: *gain = 0.0F; return 0;
case 1: *gain = 3.0F; return 0;
case 2: *gain = 6.0F; return 0;
default: return 1;
}
break;
case 1: // AGC
//return 1;
switch (mgc_idx) // set threshold!
{
case 0: *gain = 0.0F; return 0;
case 1: *gain = 10.0F; return 0;
case 2: *gain = 20.0F; return 0;
case 3: *gain = 30.0F; return 0;
case 4: *gain = 40.0F; return 0;
default: return 1;
}
break;
case 2: // Thr
switch (mgc_idx)
{
case 0: *gain = 10.0F; return 0;
case 1: *gain = 20.0F; return 0;
case 2: *gain = 30.0F; return 0;
case 3: *gain = 40.0F; return 0;
case 4: *gain = 50.0F; return 0;
default: return 1;
}
break;
case 3: // ?
switch (mgc_idx)
{
case 0: *gain = 50.0F; return 0;
case 1: *gain = 60.0F; return 0;
default: return 1;
}
break;
}
return 1;
}
extern "C"
int EXTIO_API ExtIoGetActualMgcIdx(void)
{
switch (giAgcIdx)
{
case 0: // MGC
return giMgcIdx; // returns -1 on error
case 1: // AGC
//return -1;
return giThrIdx;
case 2: // Thr
return giThrIdx;
case 3:
return giWhatIdx;
}
return -1;
}
extern "C"
int EXTIO_API ExtIoSetMGC(int mgc_idx)
{
int iPrevMgcIdx = giMgcIdx;
int iPrevThrIdx = giThrIdx;
switch (giAgcIdx)
{
case 0: // MGC
switch (mgc_idx)
{
case 0:
case 1:
case 2:
giMgcIdx = mgc_idx;
if (iPrevMgcIdx != giMgcIdx)
++giParameterSetNo;
return 0;
default:
return 1; // ERROR
}
break;
case 1: // AGC
//break;
case 2: // Thr
switch (mgc_idx)
{
case 0:
case 1:
case 2:
case 3:
case 4:
giThrIdx = mgc_idx;
if (iPrevMgcIdx != giThrIdx)
++giParameterSetNo;
return 0;
default:
return 1; // ERROR
}
break;
case 3: // ?
switch (mgc_idx)
{
case 0:
case 1:
giWhatIdx = mgc_idx;
return 0;
default:
return 1; // ERROR
}
break;
}
return 1; // ERROR
}
//---------------------------------------------------------------------------
// Only a single 96ksamples per second sampling rate is supported.
extern "C"
int EXTIO_API ExtIoGetSrates(int srate_idx, double *samplerate)
{
switch (srate_idx) {
case 0: *samplerate = 96000.0; return 0;
default: return 1; // ERROR
}
}
extern "C" int EXTIO_API ExtIoGetActualSrateIdx(void) { return 0; }
extern "C" int EXTIO_API ExtIoSetSrate(int srate_idx) { return (srate_idx == 0) ? 0 : 1; }
extern "C" long EXTIO_API ExtIoGetBandwidth(int srate_idx) { return (srate_idx == 0) ? 80000L : -1L; }
// HDSDR >= 2.51
// optional functions to receive and set all special receiver settings (for save/restore in application)
// allows application and profile specific settings.
// easy to handle without problems with newer Windows versions saving a .ini file below programs as non-admin-user
extern "C" int EXTIO_API ExtIoGetSetting(int idx, char *description, char *value)
{
if (idx == 0) {
strcpy(description, "Omnia Config");
std::string cfg = g_config.serialize();
// The output buffer is limited to 1024, so the configuration cannot be too long.
strncpy(value, cfg.c_str(), 1024);
// ok
return 0;
} else {
// error, this is the last index stored
return -1;
}
}
extern "C" void EXTIO_API ExtIoSetSetting(int idx, const char * value)
{
if (idx == 0) {
g_config.deserialize(value);
g_config.validate();
}
}