├── .gitattributes ├── LICENSE ├── MatlabSimulation_EMEye ├── EMEye_Sim.m ├── data │ ├── room.dng │ └── room.jpg └── util │ ├── f_csi_time2bit.m │ ├── iqdemod.m │ └── raspidng │ ├── cygjpeg-8.dll │ ├── cygwin1.dll │ ├── cygz.dll │ └── raspi_dng.exe ├── TempestSDR_EMEye ├── .gitignore ├── JavaGUI │ ├── .classpath │ ├── crosscompile.sh │ ├── jni │ │ ├── TSDRLibraryNDK.c │ │ ├── include │ │ │ ├── TSDRCodes.h │ │ │ └── TSDRLibrary.h │ │ ├── makefile │ │ └── osdetect.h │ ├── license.txt │ ├── makefile │ └── src │ │ └── martin │ │ └── tempest │ │ ├── core │ │ ├── TSDRLibrary.java │ │ └── exceptions │ │ │ ├── TSDRAlreadyRunningException.java │ │ │ ├── TSDRCannotOpenDeviceException.java │ │ │ ├── TSDRException.java │ │ │ ├── TSDRFunctionNotImplemented.java │ │ │ ├── TSDRIncompatiblePluginException.java │ │ │ ├── TSDRInvalidParameterException.java │ │ │ ├── TSDRInvalidParameterValueException.java │ │ │ ├── TSDRLibraryNotCompatible.java │ │ │ ├── TSDRLoadPluginException.java │ │ │ ├── TSDRNotRunningException.java │ │ │ ├── TSDRPluginParametersException.java │ │ │ ├── TSDRSampleRateWrongException.java │ │ │ └── TSDRVideoParamsException.java │ │ ├── gui │ │ ├── AutoScaleVisualizer.java │ │ ├── HoldButton.java │ │ ├── ImageVisualizer.java │ │ ├── Main.java │ │ ├── OnTSDRParamChangedCallback.java │ │ ├── ParametersToggleButton.java │ │ ├── PlotVisualizer.java │ │ ├── SNRVisualizer.java │ │ ├── VideoMode.java │ │ └── scale │ │ │ ├── LogScale.java │ │ │ └── ZoomableXScale.java │ │ └── sources │ │ ├── TSDRExtIOSource.java │ │ ├── TSDRFileSource.java │ │ ├── TSDRMiricsSource.java │ │ ├── TSDRSDRPlaySource.java │ │ ├── TSDRSource.java │ │ └── TSDRUHDSource.java ├── TSDRPlugin_ExtIO │ ├── README │ ├── license.txt │ ├── makefile │ └── src │ │ ├── ExtIOPluginLoader.c │ │ ├── ExtIOPluginLoader.h │ │ ├── TSDRCodes.h │ │ ├── TSDRPlugin.h │ │ ├── TSDRPlugin_ExtIO.c │ │ └── errors.h ├── TSDRPlugin_Mirics │ ├── README │ ├── license.txt │ ├── makefile │ └── src │ │ ├── TSDRCodes.h │ │ ├── TSDRPlugin.h │ │ └── TSDRPlugin_Mirics.c ├── TSDRPlugin_RawFile │ ├── license.txt │ ├── makefile │ └── src │ │ ├── TSDRCodes.h │ │ ├── TSDRPlugin.h │ │ ├── TSDRPlugin_RawFile.c │ │ ├── osdetect.h │ │ ├── timer.c │ │ └── timer.h ├── TSDRPlugin_SdrPlay │ ├── README │ ├── license.txt │ ├── makefile │ └── src │ │ ├── TSDRCodes.h │ │ ├── TSDRPlugin.h │ │ └── TSDRPlugin_SDRPlay.c ├── TSDRPlugin_UHD │ ├── README │ ├── TSDRPlugin_UHD.vcxproj │ ├── license.txt │ ├── makefile │ └── src │ │ ├── TSDRCodes.h │ │ ├── TSDRPlugin.h │ │ ├── TSDRPlugin_UHD.cpp │ │ ├── errors.hpp │ │ └── exports.def ├── TempestSDR │ ├── license.txt │ ├── makefile │ └── src │ │ ├── TSDRLibrary.c │ │ ├── TSDRPluginLoader.c │ │ ├── TSDRPluginLoader.h │ │ ├── circbuff.c │ │ ├── circbuff.h │ │ ├── dsp.c │ │ ├── dsp.h │ │ ├── extbuffer.c │ │ ├── extbuffer.h │ │ ├── fft.c │ │ ├── fft.h │ │ ├── frameratedetector.c │ │ ├── frameratedetector.h │ │ ├── gaussian.c │ │ ├── gaussian.h │ │ ├── include │ │ ├── TSDRCodes.h │ │ ├── TSDRLibrary.h │ │ └── TSDRPlugin.h │ │ ├── internaldefinitions.h │ │ ├── osdetect.h │ │ ├── superbandwidth.c │ │ ├── superbandwidth.h │ │ ├── syncdetector.c │ │ ├── syncdetector.h │ │ ├── threading.c │ │ └── threading.h └── makefile ├── files ├── GUI.png └── SIM.png └── readme.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /MatlabSimulation_EMEye/EMEye_Sim.m: -------------------------------------------------------------------------------- 1 | %% 2 | % This demo shows a simplfied version of the EM Eye image reconstrction 3 | % process using simulated EM waveform generated from a RAW image captured 4 | % by the RPI camera v1. 5 | 6 | 7 | 8 | %% Step 1: Prepare the image data. 9 | % There is already a sample image in the ./data folder. If you want to 10 | % prepare you own image data, you need to: 11 | % First, take a jpg of rpi camera that contains RAW data using the command. Note it is full sensor resolution 12 | % Second, extract the RAW image from jpg using: raspi_dng.exe in.jpg out.dng, raspi_dng is provided in ./util 13 | 14 | 15 | %% Step 2: Simulate the transmitted bits and EM waveform from given RAW image 16 | 17 | addpath('./util') 18 | 19 | fs = 1e9; % simulation sample rate 20 | np = 33e6; % simulated sample points (1 frame) 21 | 22 | res_csi = f_csi_time2bit(np, fs); % CSI indexing 23 | 24 | dat_org = zeros(np, 1); % stores the bit waveform transmitted 25 | 26 | idx = 1:np; 27 | valid_idx = res_csi.valid(idx) == 1; 28 | dat_org(~valid_idx) = 5; % unimportant value of blanking voltage 29 | 30 | % Adjust indexing. Not important. 31 | row = res_csi.i_r(idx) + 1; 32 | col0 = res_csi.i_c0(idx) + 1; 33 | bit0 = res_csi.i_b0(idx) + 1; 34 | col1 = res_csi.i_c1(idx) + 1; 35 | bit1 = res_csi.i_b1(idx) + 1; 36 | 37 | % Get the index of transmitted bits on the two wires 38 | ind0 = sub2ind([1080,1920,10], row(valid_idx), col0(valid_idx), bit0(valid_idx)); 39 | ind1 = sub2ind([1080,1920,10], row(valid_idx), col1(valid_idx), bit1(valid_idx)); 40 | 41 | 42 | % Decoding the RAW image taken by rpi cam v1 43 | ww = 2592; 44 | hh = 1944; 45 | offset = 54102/2; 46 | name = './data/room.dng'; 47 | ii = fopen(name); 48 | data = fread(ii, '*ubit16', 0, 'b'); % Endian, can be either l or b, computer-dependent 49 | fclose(ii); 50 | data = data(1+offset:offset+ww*hh); 51 | data = permute(reshape(data, ww, hh), [2,1,3]); 52 | data_1080p = data(433:1512, 337:2256); 53 | 54 | % Covert RAW image to binary 55 | data_bi = de2bi(data_1080p(:), 16, 'left-msb'); 56 | data_bi = data_bi(:,10:-1:1); % LSB transmitted first 57 | data_bi = double(data_bi); 58 | data_bi = reshape(data_bi, 1080, 1920, []); 59 | 60 | 61 | % Plot the decoded RAW image within the 1080p area 62 | % Compare it with the binary to double check if the decoding is correct 63 | % If you get a gray noisy image, try adjusting 'l' and 'b' 64 | figure; imshow(data_1080p); 65 | 66 | disp_img = reshape(bi2de(reshape(data_bi, [], 10)), 1080, 1920); 67 | disp_img = disp_img / max(disp_img(:)); 68 | figure; imshow( disp_img ); 69 | 70 | 71 | % Finally, get the transmitted bits on the two wires 72 | line0 = data_bi(ind0); 73 | line1 = data_bi(ind1); 74 | 75 | % This is the simultaed EM waveform transmitted 76 | % The waveform can be any linear combination of the two wires' 77 | % bits, subjected to other transfer functions that are dependent on the actal 78 | % environmental conditions. For simplicity, you may just 79 | % use line0 + line1 or line0 to represent the waveform. 80 | 81 | dat_org(valid_idx) = line0 + line1; 82 | 83 | figure; plot(dat_org(1:8.5e4)) % Plots the first three rows transmitted 84 | 85 | 86 | %% Step 3: Reconstruct the image from the bit stream 87 | 88 | % Here we are demodulating the reconstructing the simulated EM data stored 89 | % in dat_org. Note that dat_org can be replaced with real EM data if you 90 | % collect it with a o-scope like a PicoScope with a 1 GHz sampe rate. The 91 | % process below simulates the IQ demodulation of USRP and image 92 | % reconstruction procedure. Note that besides IQ amplitude demod, other 93 | % demod methods such as envelope detection can also be used. 94 | 95 | fc = 255e6; % demod center frequency, tunable 96 | fb = 20e6; % demod bandwidth (two-sided), tunable 97 | z = iqdemod(dat_org, fc, fb, fs); 98 | 99 | emhead = 1; % where the transmission starts 100 | 101 | fnum = 1; % number of frames 102 | rolnum = 1080; % number of rows of each recon, fixed, equals the value of RAW image 103 | colnum = 800; % number of columns, tunable, should be smaller than the RAW image 104 | 105 | % Below are the measured transmission blanking parameters 106 | frm_sep = 33311675; 107 | row_len = 26200; 108 | row_sep = 29590; 109 | col_len = floor(row_len/colnum); 110 | col_sep = col_len; 111 | 112 | % stores the image stream recon from amplitude demod signals 113 | recimg_am = zeros(fnum, rolnum, colnum); 114 | 115 | for i_frm = 1:fnum 116 | frame_start = (i_frm-1)*frm_sep + emhead; 117 | for i_rol = 1:rolnum 118 | disp(['frame ', num2str(i_frm), ' rol ', num2str(i_rol)]) 119 | row_start = (i_rol-1)*row_sep + frame_start; 120 | for i_col = 1:colnum 121 | col_start = round((i_col-1)*col_sep + row_start); 122 | col_end = round((i_col-1)*col_sep + row_start + col_len); 123 | 124 | seg = z(col_start:col_end); 125 | recimg_am(i_frm, i_rol, i_col) = median(seg); 126 | end 127 | end 128 | end 129 | 130 | 131 | recimg_all = {recimg_am}; 132 | names = {'Amplitude Demod'}; 133 | for i = 1:length(recimg_all) 134 | recimg = recimg_all{i}; 135 | recimg = squeeze(mean(recimg, 1)); 136 | recimg = recimg(:,1:722); 137 | recimg = imresize(recimg, [480, 640]); 138 | % recimg = 1 - recimg; % if it needs polarity inversion 139 | recimg = histeq(recimg); 140 | figure; imshow(recimg); title([names{i}, ' num of col: ', num2str(colnum), ... 141 | ', fc=', num2str(fc/1e6), ', fb=', num2str(fb/1e6)]) 142 | end 143 | 144 | -------------------------------------------------------------------------------- /MatlabSimulation_EMEye/data/room.dng: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longyan97/EMEye_Tutorial/4f5cf3600e809698a2a94258391ac684427ebac4/MatlabSimulation_EMEye/data/room.dng -------------------------------------------------------------------------------- /MatlabSimulation_EMEye/data/room.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longyan97/EMEye_Tutorial/4f5cf3600e809698a2a94258391ac684427ebac4/MatlabSimulation_EMEye/data/room.jpg -------------------------------------------------------------------------------- /MatlabSimulation_EMEye/util/f_csi_time2bit.m: -------------------------------------------------------------------------------- 1 | % Generate a time table of CSI bit stream indexing. 2 | % Corresponding to the "TWO-LANE RAW10 TRANSMISSION MODEL" in Appendix A 3 | function res_csi = f_csi_time2bit(num_points, fs) 4 | 5 | 6 | point = (1:num_points)' ; 7 | 8 | t_0 = 0; 9 | t_s = point / fs; 10 | 11 | 12 | % Hard-coded parameters for rpi cam v1 13 | N_r = 1080; N_c = 1920; N_b = 10; 14 | T_fs = 33311610/1e9; 15 | T_rs = 29590/1e9; 16 | T_bs = 1/408e6; 17 | T_B = 8*T_bs; 18 | 19 | i_f = floor((t_s-t_0)/T_fs); 20 | 21 | i_r = floor((t_s-t_0-T_fs*i_f)/T_rs); 22 | i_r(i_r >= N_r) = -inf; 23 | 24 | t_til = max(0, t_s - t_0 - T_fs*i_f - T_rs*i_r); 25 | 26 | s_c = 8*floor(t_til/ 5/ T_B); 27 | g_B = mod(floor(t_til/T_B), 5); 28 | 29 | i_c0 = s_c +(g_B<2).*(2*g_B) + (g_B>2).*(2*g_B-1) + ... 30 | (g_B==2).*mod(floor(t_til/2/T_bs), 4); 31 | i_c0(i_c0 >= N_c) = -inf; 32 | 33 | i_c1 = s_c +(g_B<2).*(2*g_B+1) + ((g_B>=2)&(g_B<4)).*(2*g_B) + ... 34 | (g_B==4).*(4+mod(floor(t_til/2/T_bs), 4)); 35 | i_c1(i_c1 >= N_c) = -inf; 36 | 37 | i_b0 = (g_B~=2).*(2+mod(floor(t_til/T_bs), 8)) + ... 38 | (g_B==2).*mod(floor(t_til/T_bs), 2); 39 | i_b0(i_b0 > N_b) = -inf; 40 | 41 | i_b1 = (g_B~=4).*(2+mod(floor(t_til/T_bs), 8)) + ... 42 | (g_B==4).*mod(floor(t_til/T_bs), 2); 43 | i_b1(i_b1 > N_b) = -inf; 44 | 45 | valid = (i_r>-inf).*(i_c0>-inf); 46 | 47 | res_csi = array2table([t_s, i_f, i_r, i_c0, i_b0, i_c1, i_b1, valid], ... 48 | 'VariableNames',{'time', 'i_f', 'i_r', 'i_c0', 'i_b0', 'i_c1', 'i_b1', 'valid'}); 49 | 50 | end -------------------------------------------------------------------------------- /MatlabSimulation_EMEye/util/iqdemod.m: -------------------------------------------------------------------------------- 1 | function res = iqdemod(xx, fc, fb, fs) 2 | 3 | xx = bandpass(xx, [fc-fb/2, fc+fb/2],... 4 | fs, 'Steepness', 1); 5 | 6 | ii = xx.*sin( 2*pi*fc* (1:length(xx))/fs )'; 7 | qq = xx.*sin( 2*pi*fc* (1:length(xx))/fs + pi/2)'; 8 | 9 | 10 | res = sqrt(ii.^2 + qq.^2); 11 | 12 | end -------------------------------------------------------------------------------- /MatlabSimulation_EMEye/util/raspidng/cygjpeg-8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longyan97/EMEye_Tutorial/4f5cf3600e809698a2a94258391ac684427ebac4/MatlabSimulation_EMEye/util/raspidng/cygjpeg-8.dll -------------------------------------------------------------------------------- /MatlabSimulation_EMEye/util/raspidng/cygwin1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longyan97/EMEye_Tutorial/4f5cf3600e809698a2a94258391ac684427ebac4/MatlabSimulation_EMEye/util/raspidng/cygwin1.dll -------------------------------------------------------------------------------- /MatlabSimulation_EMEye/util/raspidng/cygz.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longyan97/EMEye_Tutorial/4f5cf3600e809698a2a94258391ac684427ebac4/MatlabSimulation_EMEye/util/raspidng/cygz.dll -------------------------------------------------------------------------------- /MatlabSimulation_EMEye/util/raspidng/raspi_dng.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longyan97/EMEye_Tutorial/4f5cf3600e809698a2a94258391ac684427ebac4/MatlabSimulation_EMEye/util/raspidng/raspi_dng.exe -------------------------------------------------------------------------------- /TempestSDR_EMEye/.gitignore: -------------------------------------------------------------------------------- 1 | *.project 2 | *.zip 3 | *.csv 4 | *.png 5 | *.project 6 | *.pydevproject 7 | .metadata 8 | .gradle 9 | bin/ 10 | tmp/ 11 | *.tmp 12 | *.bak 13 | *.swp 14 | *~.nib 15 | *~ 16 | local.properties 17 | .settings/ 18 | .loadpath 19 | 20 | # External tool builders 21 | .externalToolBuilders/ 22 | 23 | # Locally stored "Eclipse launch configurations" 24 | *.launch 25 | 26 | # CDT-specific 27 | .cproject 28 | 29 | # PDT-specific 30 | .buildpath 31 | 32 | # TeXlipse plugin 33 | .texlipse 34 | 35 | # Object files 36 | *.o 37 | *.ko 38 | *.obj 39 | *.elf 40 | 41 | # Libraries 42 | *.lib 43 | *.a 44 | 45 | # Shared objects (inc. Windows DLLs) 46 | *.dll 47 | *.so 48 | *.so.* 49 | *.dylib 50 | 51 | # Executables 52 | *.exe 53 | *.out 54 | *.app 55 | *.i*86 56 | *.x86_64 57 | *.hex 58 | 59 | *.class 60 | 61 | # Mobile Tools for Java (J2ME) 62 | .mtj.tmp/ 63 | 64 | # Package Files # 65 | *.jar 66 | *.mf 67 | *.war 68 | *.ear 69 | 70 | JavaGUI/jni/TSDRLibraryNDK.h 71 | documentation/CUni3-eps-converted-to.pdf 72 | documentation/acs-dissertation.pdf 73 | 74 | # Java crash log files 75 | *.log 76 | 77 | ## Ignore Visual Studio temporary files, build results, and 78 | ## files generated by popular Visual Studio add-ons. 79 | 80 | # User-specific files 81 | *.suo 82 | *.user 83 | *.sln.docstates 84 | 85 | # Build results 86 | [Dd]ebug/ 87 | [Dd]ebugPublic/ 88 | [Rr]elease/ 89 | x64/ 90 | build/ 91 | bld/ 92 | [Bb]in/ 93 | [Oo]bj/ 94 | 95 | # MSTest test Results 96 | [Tt]est[Rr]esult*/ 97 | [Bb]uild[Ll]og.* 98 | 99 | #NUNIT 100 | *.VisualState.xml 101 | TestResult.xml 102 | 103 | *_i.c 104 | *_p.c 105 | *_i.h 106 | *.ilk 107 | *.meta 108 | *.obj 109 | *.pch 110 | *.pdb 111 | *.pgc 112 | *.pgd 113 | *.rsp 114 | *.sbr 115 | *.tlb 116 | *.tli 117 | *.tlh 118 | *.tmp 119 | *.tmp_proj 120 | *.log 121 | *.vspscc 122 | *.vssscc 123 | .builds 124 | *.pidb 125 | *.svclog 126 | *.scc 127 | 128 | # Chutzpah Test files 129 | _Chutzpah* 130 | 131 | # Visual C++ cache files 132 | ipch/ 133 | *.aps 134 | *.ncb 135 | *.opensdf 136 | *.sdf 137 | *.cachefile 138 | 139 | # Visual Studio profiler 140 | *.psess 141 | *.vsp 142 | *.vspx 143 | 144 | # TFS 2012 Local Workspace 145 | $tf/ 146 | 147 | # Guidance Automation Toolkit 148 | *.gpState 149 | 150 | # ReSharper is a .NET coding add-in 151 | _ReSharper*/ 152 | *.[Rr]e[Ss]harper 153 | *.DotSettings.user 154 | 155 | # JustCode is a .NET coding addin-in 156 | .JustCode 157 | 158 | # TeamCity is a build add-in 159 | _TeamCity* 160 | 161 | # DotCover is a Code Coverage Tool 162 | *.dotCover 163 | 164 | # NCrunch 165 | *.ncrunch* 166 | _NCrunch_* 167 | .*crunch*.local.xml 168 | 169 | # MightyMoose 170 | *.mm.* 171 | AutoTest.Net/ 172 | 173 | # Web workbench (sass) 174 | .sass-cache/ 175 | 176 | # Installshield output folder 177 | [Ee]xpress/ 178 | 179 | # DocProject is a documentation generator add-in 180 | DocProject/buildhelp/ 181 | DocProject/Help/*.HxT 182 | DocProject/Help/*.HxC 183 | DocProject/Help/*.hhc 184 | DocProject/Help/*.hhk 185 | DocProject/Help/*.hhp 186 | DocProject/Help/Html2 187 | DocProject/Help/html 188 | 189 | # Click-Once directory 190 | publish/ 191 | 192 | # Publish Web Output 193 | *.[Pp]ublish.xml 194 | *.azurePubxml 195 | 196 | # NuGet Packages Directory 197 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 198 | #packages/* 199 | ## TODO: If the tool you use requires repositories.config, also uncomment the next line 200 | #!packages/repositories.config 201 | 202 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 203 | # This line needs to be after the ignore of the build folder (and the packages folder if the line above has been uncommented) 204 | !packages/build/ 205 | 206 | # Windows Azure Build Output 207 | csx/ 208 | *.build.csdef 209 | 210 | # Windows Store app package directory 211 | AppPackages/ 212 | 213 | # Others 214 | sql/ 215 | *.Cache 216 | ClientBin/ 217 | [Ss]tyle[Cc]op.* 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.pfx 223 | *.publishsettings 224 | node_modules/ 225 | 226 | # RIA/Silverlight projects 227 | Generated_Code/ 228 | 229 | # Backup & report files from converting an old project file to a newer 230 | # Visual Studio version. Backup files are not needed, because we have git ;-) 231 | _UpgradeReport_Files/ 232 | Backup*/ 233 | UpgradeLog*.XML 234 | UpgradeLog*.htm 235 | 236 | # SQL Server files 237 | App_Data/*.mdf 238 | App_Data/*.ldf 239 | 240 | # Business Intelligence projects 241 | *.rdl.data 242 | *.bim.layout 243 | *.bim_*.settings 244 | 245 | # Microsoft Fakes 246 | FakesAssemblies/ 247 | 248 | # ========================= 249 | # Windows detritus 250 | # ========================= 251 | 252 | # Windows image file caches 253 | Thumbs.db 254 | ehthumbs.db 255 | 256 | # Folder config file 257 | Desktop.ini 258 | 259 | # Recycle Bin used on file shares 260 | $RECYCLE.BIN/ 261 | 262 | ## Core latex/pdflatex auxiliary files: 263 | *.aux 264 | *.lof 265 | *.log 266 | *.lot 267 | *.fls 268 | *.out 269 | *.toc 270 | 271 | ## Intermediate documents: 272 | *.dvi 273 | # these rules might exclude image files for figures etc. 274 | # *.ps 275 | # *.eps 276 | # *.pdf 277 | 278 | ## Bibliography auxiliary files (bibtex/biblatex/biber): 279 | *.bbl 280 | *.bcf 281 | *.blg 282 | *-blx.aux 283 | *-blx.bib 284 | *.run.xml 285 | 286 | ## Build tool auxiliary files: 287 | *.fdb_latexmk 288 | *.synctex.gz 289 | *.synctex.gz(busy) 290 | *.pdfsync 291 | 292 | ## Auxiliary and intermediate files from other packages: 293 | 294 | # algorithms 295 | *.alg 296 | *.loa 297 | 298 | # amsthm 299 | *.thm 300 | 301 | # beamer 302 | *.nav 303 | *.snm 304 | *.vrb 305 | 306 | #(e)ledmac/(e)ledpar 307 | *.end 308 | *.[1-9] 309 | *.[1-9][0-9] 310 | *.[1-9][0-9][0-9] 311 | *.[1-9]R 312 | *.[1-9][0-9]R 313 | *.[1-9][0-9][0-9]R 314 | 315 | # glossaries 316 | *.acn 317 | *.acr 318 | *.glg 319 | *.glo 320 | *.gls 321 | 322 | # hyperref 323 | *.brf 324 | 325 | # listings 326 | *.lol 327 | 328 | # makeidx 329 | *.idx 330 | *.ilg 331 | *.ind 332 | *.ist 333 | 334 | # minitoc 335 | *.maf 336 | *.mtc 337 | *.mtc0 338 | 339 | # minted 340 | *.pyg 341 | 342 | # nomencl 343 | *.nlo 344 | 345 | # sagetex 346 | *.sagetex.sage 347 | *.sagetex.py 348 | *.sagetex.scmd 349 | 350 | # sympy 351 | *.sout 352 | *.sympy 353 | sympy-plots-for-*.tex/ 354 | 355 | # todonotes 356 | *.tdo 357 | 358 | # xindy 359 | *.xdy 360 | 361 | *.sum 362 | 363 | # General 364 | .DS_Store 365 | .AppleDouble 366 | .LSOverride 367 | 368 | # Icon must end with two \r 369 | Icon 370 | 371 | 372 | # Thumbnails 373 | ._* 374 | 375 | # Files that might appear in the root of a volume 376 | .DocumentRevisions-V100 377 | .fseventsd 378 | .Spotlight-V100 379 | .TemporaryItems 380 | .Trashes 381 | .VolumeIcon.icns 382 | .com.apple.timemachine.donotpresent 383 | 384 | # Directories potentially created on remote AFP share 385 | .AppleDB 386 | .AppleDesktop 387 | Network Trash Folder 388 | Temporary Items 389 | .apdisk 390 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/crosscompile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # The file was made for 64 bit Ubuntu 3 | # gcc-multilib is installed for cross-compilation for 32 bit Linux 4 | # mingw-w64-bin_x86_64-linux_20111101_sezero.tar.gz in opt/cross_win64 for Windows x64 target from http://kent.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win64/Personal%20Builds/sezero_4.5_20111101/ 5 | # mingw-w32-bin_x86_64-linux_20111101_sezero.tar.gz in opt/cross_win86 for Windows x86 target from http://kent.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win32/Personal%20Builds/sezero_4.5_20111101/ 6 | 7 | # Define Windows mappings 8 | C=/media/741C85CD1C858B36 9 | 10 | # Define UHD home 11 | UHD_HOME=$C/PROGRA~1/UHD 12 | 13 | # Third party libraries dir, that contains third party dlls compiled for the supported architectues (ex uhd.dll, etc) 14 | THIRD_PARTY_LIB=../home/martinmarinov/workspace/TempestSDR/thirdpartylibraries 15 | 16 | # Register the paths to your cross compilers (if they are not in the PATH already) 17 | export PATH=$PATH:/opt/cross_win64/bin:/opt/cross_win32/bin 18 | 19 | # For each cross compiler specify platform (LINUX or WINDOWS) and archtype (X86 or X64) 20 | CCs=(x86_64-w64-mingw32- i686-w64-mingw32- "" "") 21 | OSNAMEs=(WINDOWS WINDOWS LINUX LINUX) 22 | ARCHNAMEs=(X64 X86 X64 X86) 23 | JAVA_HOMEs=($C/PROGRA~2/Java/jdk1.7.0_45 $C/PROGRA~2/Java/jdk1.7.0_45 /usr/lib/jvm/java-6-openjdk-amd64 /usr/lib/jvm/java-6-openjdk-amd64) 24 | 25 | make clean 26 | make java 27 | 28 | for i in "${!CCs[@]}"; do 29 | CXX=${CCs[$i]}g++ 30 | GPP=${CCs[$i]}g++ 31 | CC=${CCs[$i]}gcc 32 | AR=${CCs[$i]}ar 33 | OSNAME=${OSNAMEs[$i]} 34 | ARCHNAME=${ARCHNAMEs[$i]} 35 | JAVA_HOME=${JAVA_HOMEs[$i]} 36 | THIRD_PARTY_FULL_PATH=$THIRD_PARTY_LIB/$OSNAME/$ARCHNAME/ 37 | 38 | echo ------ BUILDING FOR $OSNAME/$ARCHNAME >&2 39 | 40 | make jnilib CC=$CC CXX=$CXX GPP=$GPP AR=$AR OSNAME=$OSNAME ARCHNAME=$ARCHNAME JAVA_HOME=$JAVA_HOME LDFLAGS=-L$THIRD_PARTY_FULL_PATH UHD_HOME=$UHD_HOME 41 | 42 | #do release of dlls 43 | mkdir -p Release/dlls/$OSNAME/$ARCHNAME/ 44 | cp -f lib/$OSNAME/$ARCHNAME/* Release/dlls/$OSNAME/$ARCHNAME/ 45 | cp -f ../TempestSDR/bin/$OSNAME/$ARCHNAME/* Release/dlls/$OSNAME/$ARCHNAME/ 46 | 47 | make cleandependent CC=$CC OSNAME=$OSNAME ARCHNAME=$ARCHNAME JAVA_HOME=$JAVA_HOME 48 | done 49 | 50 | make jar 51 | 52 | mkdir -p Release/JavaGUI/ 53 | cp -f JTempestSDR.jar Release/JavaGUI/ 54 | 55 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/jni/include/TSDRCodes.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRCodes 14 | #define _TSDRCodes 15 | 16 | #define TSDR_OK (0) 17 | #define TSDR_ERR_PLUGIN (1) 18 | #define TSDR_WRONG_VIDEOPARAMS (2) 19 | #define TSDR_ALREADY_RUNNING (3) 20 | #define TSDR_PLUGIN_PARAMETERS_WRONG (4) 21 | #define TSDR_SAMPLE_RATE_WRONG (5) 22 | #define TSDR_CANNOT_OPEN_DEVICE (6) 23 | #define TSDR_INCOMPATIBLE_PLUGIN (7) 24 | #define TSDR_INVALID_PARAMETER (8) 25 | #define TSDR_INVALID_PARAMETER_VALUE (9) 26 | #define TSDR_NOT_RUNNING (10) 27 | #define TSDR_NOT_IMPLEMENTED (404) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/jni/include/TSDRLibrary.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRLibrary 14 | #define _TSDRLibrary 15 | 16 | #include 17 | 18 | // those PIXEL_* are only used for debugging purposes and 19 | // it is not required for the client to implement them 20 | #define PIXEL_SPECIAL_VALUE_R (256.0f) 21 | #define PIXEL_SPECIAL_VALUE_G (512.0f) 22 | #define PIXEL_SPECIAL_VALUE_B (1024.0f) 23 | #define PIXEL_SPECIAL_VALUE_TRANSPARENT (2048.0f) 24 | #define PIXEL_SPECIAL_COLOURS_ENABLED (1) 25 | 26 | #define DIRECTION_CUSTOM (0) 27 | #define DIRECTION_UP (1) 28 | #define DIRECTION_DOWN (2) 29 | #define DIRECTION_LEFT (3) 30 | #define DIRECTION_RIGHT (4) 31 | 32 | #define PARAM_INT_AUTOSHIFT (0) 33 | #define PARAM_INT_FRAMERATE_PLL (1) 34 | #define PARAM_AUTOCORR_PLOTS_RESET (2) 35 | #define PARAM_AUTOCORR_PLOTS_OFF (3) 36 | #define PARAM_AUTOCORR_SUPERRESOLUTION (4) 37 | #define PARAM_NEAREST_NEIGHBOUR_RESAMPLING (5) 38 | #define PARAM_LOW_PASS_BEFORE_SYNC (6) 39 | #define PARAM_AUTOGAIN_AFTER_PROCESSING (7) 40 | #define PARAM_AUTOCORR_DUMP (8) 41 | #define COUNT_PARAM_INT (9) 42 | 43 | #define COUNT_PARAM_DOUBLE (2) 44 | 45 | #define VALUE_ID_PLL_FRAMERATE (0) 46 | #define VALUE_ID_AUTOCORRECT_RESET (1) 47 | #define VALUE_ID_AUTOCORRECT_FRAMES_COUNT (2) 48 | #define VALUE_ID_AUTOGAIN_VALUES (3) 49 | #define VALUE_ID_SNR (4) 50 | #define VALUE_ID_AUTOCORRECT_DUMPED (5) 51 | 52 | #define PLOT_ID_FRAME (0) 53 | #define PLOT_ID_LINE (1) 54 | 55 | typedef struct tsdr_lib tsdr_lib_t; 56 | 57 | typedef void(*tsdr_readasync_function)(float *buf, int width, int height, void *ctx); 58 | typedef void(*tsdr_value_changed_callback)(int value_id, double arg0, double arg1, void * ctx); 59 | typedef void(*tsdr_on_plot_ready_callback)(int plot_id, int offset, double * values, int size, uint32_t samplerate, void * ctx); 60 | 61 | void tsdr_init(tsdr_lib_t ** tsdr, tsdr_value_changed_callback callback, tsdr_on_plot_ready_callback plotready_callback, void * ctx); 62 | void * tsdr_getctx(tsdr_lib_t * tsdr); 63 | int tsdr_setbasefreq(tsdr_lib_t * tsdr, uint32_t freq); 64 | int tsdr_stop(tsdr_lib_t * tsdr); 65 | int tsdr_setgain(tsdr_lib_t * tsdr, float gain); 66 | int tsdr_readasync(tsdr_lib_t * tsdr, tsdr_readasync_function cb, void * ctx); 67 | int tsdr_loadplugin(tsdr_lib_t * tsdr, const char * pluginfilepath, const char * params); 68 | int tsdr_unloadplugin(tsdr_lib_t * tsdr); 69 | int tsdr_setresolution(tsdr_lib_t * tsdr, int height, double refreshrate); 70 | int tsdr_isrunning(tsdr_lib_t * tsdr); 71 | int tsdr_sync(tsdr_lib_t * tsdr, int pixels, int direction); 72 | int tsdr_motionblur(tsdr_lib_t * tsdr, float coeff); 73 | void tsdr_free(tsdr_lib_t ** tsdr); 74 | char * tsdr_getlasterrortext(tsdr_lib_t * tsdr); 75 | int tsdr_setparameter_int(tsdr_lib_t * tsdr, int parameter, uint32_t value); 76 | int tsdr_setparameter_double(tsdr_lib_t * tsdr, int parameter, double value); 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/jni/makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Martin Marinov. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the GNU Public License v3.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.gnu.org/licenses/gpl.html 7 | # 8 | # Contributors: 9 | # Martin Marinov - initial API and implementation 10 | #------------------------------------------------------------------------------- 11 | # JAVA_HOME should be initialized to something like C:\PROGRA~2\Java\jdk1.7.0_45 12 | ifndef JAVA_HOME 13 | $(warning JAVA_HOME should be set so it points to your jdk installation dir) 14 | endif 15 | 16 | # Define all of the C files here 17 | OBJS = TSDRLibraryNDK.o 18 | 19 | # Define all of the dependencies here 20 | DEPS = TSDRLibraryNDK.h include/TSDRLibrary.h include/TSDRCodes.h 21 | 22 | # Flags 23 | ifeq ($(BUILD_TYPE),Debug) 24 | DEBUGFLAGS+=-g -O0 25 | else 26 | CFLAGS+=-O3 27 | endif 28 | 29 | # Headers 30 | INC += "$(JAVA_HOME)/include" "$(JAVA_HOME)/include/win32" "$(JAVA_HOME)/include/linux" "$(JAVA_HOME)/include/darwin" 31 | 32 | # Discover the library extension for each OS 33 | ifeq ($(OS),Windows_NT) 34 | 35 | OSNAME ?= WINDOWS 36 | 37 | ifndef $(ARCHNAME) 38 | 39 | ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) 40 | ARCHNAME = X64 41 | endif 42 | ifeq ($(PROCESSOR_ARCHITECTURE),x86) 43 | ARCHNAME = X86 44 | endif 45 | 46 | endif 47 | else ifeq ($(shell uname -s),Darwin) 48 | OSNAME ?= MAC 49 | INC += /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers 50 | EXT ?= .so 51 | ifeq ($(shell uname -m),x86) 52 | ARCHNAME = X86 53 | endif 54 | ifeq ($(shell uname -m),x86_64) 55 | ARCHNAME = X64 56 | endif 57 | else 58 | 59 | ifndef $(OSNAME) 60 | 61 | UNAME_S := $(shell uname -s) 62 | ifeq ($(UNAME_S),Linux) 63 | OSNAME = LINUX 64 | endif 65 | 66 | endif 67 | 68 | ifndef $(ARCHNAME) 69 | 70 | UNAME_M := $(shell uname -m) 71 | ifeq ($(UNAME_M),x86_64) 72 | ARCHNAME = X64 73 | endif 74 | ifneq ($(filter %86,$(UNAME_M)),) 75 | ARCHNAME = X86 76 | endif 77 | ifneq ($(filter arm%,$(UNAME_M)),) 78 | ARCHNAME = ARM 79 | endif 80 | 81 | endif 82 | endif 83 | 84 | ifeq ($(OSNAME),WINDOWS) 85 | EXT=.dll 86 | LIBPREFIX= 87 | endif 88 | ifeq ($(OSNAME),LINUX) 89 | EXT=.so 90 | LIBPREFIX=lib 91 | endif 92 | 93 | ifeq ($(ARCHNAME),X86) 94 | COMPILATION_TYPE=-m32 95 | else ifeq ($(ARCHNAME),X64) 96 | COMPILATION_TYPE=-m64 97 | endif 98 | 99 | 100 | # OS specific flags 101 | ifeq ($(OSNAME),LINUX) 102 | CFLAGS+=-fPIC 103 | else ifeq ($(OSNAME),WINDOWS) 104 | CFLAGS+=-D__int64="long long" -D_JNI_IMPLEMENTATION_ -Wl,--kill-at 105 | LDFLAGS+=-Wl,--add-stdcall-alias 106 | endif 107 | 108 | # The folder that will contain the libraries 109 | OUTPUTFOLDER=../lib/$(OSNAME)/$(ARCHNAME) 110 | 111 | # The folder that will contain the object files 112 | OBJFOLDER=obj 113 | 114 | # The obj files reside in the bin/obj directory 115 | _OBJS = $(patsubst %,$(OBJFOLDER)/%,$(OBJS)) 116 | 117 | # We want to build the library 118 | all : rebuildtempestsdr library 119 | 120 | # Linking 121 | library : $(_OBJS) 122 | $(CC) -Wall -shared $(LDFLAGS) $(DEBUGFLAGS) $(COMPILATION_TYPE) -o $(OUTPUTFOLDER)/$(LIBPREFIX)TSDRLibraryNDK$(EXT) $< ../../TempestSDR/bin/$(OSNAME)/$(ARCHNAME)/$(LIBPREFIX)TSDRLibrary.a 123 | 124 | # Rebuild the main library so that we have the most up-to-date version 125 | # The main library is assumed to be two levels below this jni folder 126 | rebuildtempestsdr : 127 | @$(MAKE) -C ../../TempestSDR all 128 | mkdir -p include 129 | @cp -f ../../TempestSDR/src/include/TSDRCodes.h include/ 130 | @cp -f ../../TempestSDR/src/include/TSDRLibrary.h include/ 131 | mkdir -p $(OUTPUTFOLDER) 132 | mkdir -p $(OBJFOLDER) 133 | 134 | # Compile the sources to obj files 135 | $(OBJFOLDER)/%.o : %.c $(DEPS) 136 | $(CC) -Wall $(foreach d, $(INC), -I$d) $(CFLAGS) $(DEBUGFLAGS) $(COMPILATION_TYPE) -c $< -o $@ 137 | 138 | # Generate the java header based on the class 139 | TSDRLibraryNDK.h : ../src/martin/tempest/core/TSDRLibrary.java 140 | mkdir -p include ../bin/martin/tempest/core/ 141 | javac $< -h ./ -d ../bin/ -cp ../src/ 142 | # dirty fix to match the previous name 143 | mv martin_tempest_core_TSDRLibrary.h TSDRLibraryNDK.h 144 | 145 | 146 | # Remove any compiled artifacts 147 | clean : 148 | rm -f TSDRLibraryNDK.h 149 | rm -rf $(OBJFOLDER)/ 150 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/jni/osdetect.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifdef OS_WINDOWS 14 | #define WINHEAD (1) 15 | #elif defined(_WIN64) 16 | #define WINHEAD (1) 17 | #elif defined(_WIN32) 18 | #define WINHEAD (1) 19 | #elif defined(_MSC_VER) // Microsoft compiler 20 | #define WINHEAD (1) 21 | #else 22 | #define WINHEAD (0) 23 | #endif 24 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Martin Marinov. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the GNU Public License v3.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.gnu.org/licenses/gpl.html 7 | # 8 | # Contributors: 9 | # Martin Marinov - initial API and implementation 10 | #------------------------------------------------------------------------------- 11 | # Discover the library extension for each OS 12 | ifeq ($(OS),Windows_NT) 13 | 14 | OSNAME ?= WINDOWS 15 | 16 | ifndef $(ARCHNAME) 17 | 18 | ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) 19 | ARCHNAME = X64 20 | endif 21 | ifeq ($(PROCESSOR_ARCHITECTURE),x86) 22 | ARCHNAME = X86 23 | endif 24 | 25 | endif 26 | else ifeq ($(shell uname -s),Darwin) 27 | OSNAME ?= MAC 28 | INC += /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers 29 | EXT ?= .so 30 | ifeq ($(shell uname -m),x86) 31 | ARCHNAME = X86 32 | endif 33 | ifeq ($(shell uname -m),x86_64) 34 | ARCHNAME = X64 35 | endif 36 | else 37 | 38 | ifndef $(OSNAME) 39 | 40 | UNAME_S := $(shell uname -s) 41 | ifeq ($(UNAME_S),Linux) 42 | OSNAME = LINUX 43 | endif 44 | 45 | endif 46 | 47 | ifndef $(ARCHNAME) 48 | 49 | UNAME_M := $(shell uname -m) 50 | ifeq ($(UNAME_M),x86_64) 51 | ARCHNAME = X64 52 | endif 53 | ifneq ($(filter %86,$(UNAME_M)),) 54 | ARCHNAME = X86 55 | endif 56 | ifneq ($(filter arm%,$(UNAME_M)),) 57 | ARCHNAME = ARM 58 | endif 59 | 60 | endif 61 | endif 62 | 63 | ifeq ($(OSNAME),WINDOWS) 64 | EXT=.dll 65 | LIBPREFIX= 66 | endif 67 | ifeq ($(OSNAME),LINUX) 68 | EXT=.so 69 | LIBPREFIX=lib 70 | endif 71 | 72 | ifeq ($(ARCHNAME),X86) 73 | COMPILATION_TYPE=-m32 74 | else ifeq ($(ARCHNAME),X64) 75 | COMPILATION_TYPE=-m64 76 | endif 77 | 78 | 79 | # USER CONFIGURATION STARTS HERE 80 | 81 | # Define the plugins that you like to compile with the library. They need to be in a folder 82 | # in the parent directory with the exact same name as the plugin names. The library files 83 | # produced need to have the name of the plugin folder and need to be in the bin directory. 84 | # The default plugin file will make sure this is compatible. 85 | PLUGINS=TSDRPlugin_RawFile 86 | 87 | ifeq ($(OSNAME),WINDOWS) 88 | # Windows only plugins 89 | PLUGINS += TSDRPlugin_SDRPlay TSDRPlugin_ExtIO 90 | else ifeq ($(OSNAME), LINUX) 91 | PLUGINS += TSDRPlugin_UHD 92 | else ifeq ($(OSNAME), MAC) 93 | PLUGINS += TSDRPlugin_UHD TSDRPlugin_SDRPlay 94 | endif 95 | 96 | # USER CONFIGURATION ENDS HERE 97 | 98 | # Define a recursive wildcard function 99 | rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) 100 | 101 | # Discover all the java sources 102 | JAVAFILES:=$(call rwildcard,src/,*.java) 103 | 104 | # Create the class dependencies 105 | CLASSFILES:=$(patsubst %,bin/%,$(addsuffix .class,$(basename $(foreach jfile,$(JAVAFILES), $(subst src/,,$(jfile)) )))) 106 | 107 | # The folder that will contain the libraries 108 | OUTPUTFOLDER=lib/$(OSNAME)/$(ARCHNAME) 109 | 110 | # Build the file names of the plugin files 111 | PLUGINS_FILES=$(addprefix $(LIBPREFIX),$(addsuffix $(EXT),$(PLUGINS))) 112 | 113 | # Build the directory names of the plugins 114 | PLUGINS_DIRS=$(addprefix ../,$(addsuffix /,$(PLUGINS))) 115 | 116 | debug : BUILD_TYPE = Debug 117 | 118 | debugjnilib : BUILD_TYPE = Debug 119 | 120 | debug : all 121 | 122 | debugjnilib : jnilib 123 | 124 | # When compiling from command line with all 125 | # make sure we compile both jni and java files 126 | all : jnilib jar 127 | 128 | # Package compiled files into a runnable jar 129 | jar : java 130 | jar cvfe JTempestSDR.jar martin.tempest.gui.Main lib -C bin . 131 | 132 | # The compilation of the java classes from command line 133 | # depends on the class files (we want to produce them) 134 | java : $(CLASSFILES) 135 | 136 | # For each class file, invoke javac with the source file which is constructed 137 | # from the name of the class file 138 | %.class : $(JAVAFILES) 139 | mkdir -p bin # Create the bin directory if it doesn't exist (if you downloaded it from github) 140 | javac $(patsubst %,src/%, $(subst bin/,,$(@:.class=.java))) -d bin/ -cp src/ 141 | 142 | # Invoke the makefile for the jni stuff 143 | jnilib : plugins 144 | @$(MAKE) -C jni/ all JAVA_HOME=$(JAVA_HOME) BUILD_TYPE=$(BUILD_TYPE) 145 | 146 | # Recompile each plugin and copy its shared library over to the java directory 147 | plugins : 148 | mkdir -p $(OUTPUTFOLDER) 149 | $(foreach pdir, $(PLUGINS_DIRS), $(MAKE) -C $(pdir) all BUILD_TYPE=$(BUILD_TYPE); cp -f $(pdir)/bin/$(OSNAME)/$(ARCHNAME)/*$(EXT) $(OUTPUTFOLDER)/;) 150 | 151 | # Clean the jni stuff 152 | cleanjni: cleanplugins 153 | rm -rf *.log 154 | @$(MAKE) -C jni/ clean 155 | 156 | # Clean the plugin libraries 157 | cleanplugins: 158 | $(foreach pfile, $(PLUGINS_FILES), rm -rf $(pfile);) 159 | 160 | # Clean the TempestSDR and plugins 161 | cleandependent : 162 | @$(MAKE) -C jni/ clean 163 | $(foreach pdir, $(PLUGINS_DIRS), $(MAKE) -C $(pdir) clean;) 164 | @$(MAKE) -C ../TempestSDR/ clean 165 | 166 | # Clean the java classes as well 167 | clean : cleanjni cleandependent 168 | rm -rf bin/ JTempestSDR.jar 169 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRAlreadyRunningException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRAlreadyRunningException extends TSDRException { 14 | 15 | private static final long serialVersionUID = 5365909402344178885L; 16 | 17 | public TSDRAlreadyRunningException(final Exception e) { 18 | super(e); 19 | } 20 | 21 | public TSDRAlreadyRunningException(final String msg) { 22 | super(msg); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRCannotOpenDeviceException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRCannotOpenDeviceException extends TSDRException { 14 | 15 | private static final long serialVersionUID = -7807615914689137600L; 16 | 17 | public TSDRCannotOpenDeviceException(final Exception e) { 18 | super(e); 19 | } 20 | 21 | public TSDRCannotOpenDeviceException(final String msg) { 22 | super(msg); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRException extends Exception { 14 | private static final long serialVersionUID = 6725402982063689232L; 15 | 16 | public TSDRException(final Exception e) { 17 | super(e); 18 | } 19 | 20 | public TSDRException() { 21 | super(); 22 | } 23 | 24 | public TSDRException(final String msg) { 25 | super(msg); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRFunctionNotImplemented.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRFunctionNotImplemented extends TSDRException { 14 | private static final long serialVersionUID = -3277318477469074058L; 15 | 16 | public TSDRFunctionNotImplemented(final String msg) { 17 | super(msg); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRIncompatiblePluginException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRIncompatiblePluginException extends TSDRException { 14 | private static final long serialVersionUID = -8416953642010129494L; 15 | 16 | public TSDRIncompatiblePluginException(final String msg) { 17 | super(msg); 18 | } 19 | 20 | public TSDRIncompatiblePluginException() { 21 | super(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRInvalidParameterException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRInvalidParameterException extends TSDRException { 14 | 15 | private static final long serialVersionUID = -7221178793554721474L; 16 | 17 | public TSDRInvalidParameterException(final String msg) { 18 | super(msg); 19 | } 20 | 21 | public TSDRInvalidParameterException() { 22 | super(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRInvalidParameterValueException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRInvalidParameterValueException extends TSDRException { 14 | 15 | private static final long serialVersionUID = 6721623410616506808L; 16 | 17 | public TSDRInvalidParameterValueException(final String msg) { 18 | super(msg); 19 | } 20 | 21 | public TSDRInvalidParameterValueException() { 22 | super(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRLibraryNotCompatible.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRLibraryNotCompatible extends TSDRException { 14 | private static final long serialVersionUID = -7001791780564950322L; 15 | 16 | public TSDRLibraryNotCompatible(final Exception e) { 17 | super(e); 18 | } 19 | 20 | public TSDRLibraryNotCompatible(final String msg) { 21 | super(msg); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRLoadPluginException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRLoadPluginException extends TSDRException { 14 | 15 | private static final long serialVersionUID = 5210950769308579938L; 16 | 17 | public TSDRLoadPluginException(final String msg) { 18 | super(msg); 19 | } 20 | 21 | public TSDRLoadPluginException() { 22 | super(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRNotRunningException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRNotRunningException extends TSDRException { 14 | 15 | private static final long serialVersionUID = -1951028572289070242L; 16 | 17 | public TSDRNotRunningException(final Exception e) { 18 | super(e); 19 | } 20 | 21 | public TSDRNotRunningException(final String msg) { 22 | super(msg); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRPluginParametersException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRPluginParametersException extends TSDRException { 14 | 15 | private static final long serialVersionUID = -7807615914689137600L; 16 | 17 | public TSDRPluginParametersException(final Exception e) { 18 | super(e); 19 | } 20 | 21 | public TSDRPluginParametersException(final String msg) { 22 | super(msg); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRSampleRateWrongException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRSampleRateWrongException extends TSDRException { 14 | 15 | private static final long serialVersionUID = 8116802552326966327L; 16 | 17 | public TSDRSampleRateWrongException(final Exception e) { 18 | super(e); 19 | } 20 | 21 | public TSDRSampleRateWrongException(final String msg) { 22 | super(msg); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/core/exceptions/TSDRVideoParamsException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.core.exceptions; 12 | 13 | public class TSDRVideoParamsException extends TSDRException { 14 | 15 | private static final long serialVersionUID = -1477143402409561990L; 16 | 17 | public TSDRVideoParamsException(final Exception e) { 18 | super(e); 19 | } 20 | 21 | public TSDRVideoParamsException(final String msg) { 22 | super(msg); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/gui/AutoScaleVisualizer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.gui; 12 | 13 | import java.awt.Color; 14 | import java.awt.Font; 15 | import java.awt.Graphics; 16 | import java.awt.Rectangle; 17 | 18 | import javax.swing.JPanel; 19 | 20 | import martin.tempest.gui.scale.LogScale; 21 | 22 | public class AutoScaleVisualizer extends JPanel { 23 | 24 | private static final double FONT_SPACING_COEFF = 1.5; 25 | private static final double LOWEST_DB = -50.7; 26 | private static final double HIGHEST_DB = 0.6; 27 | private static final double FONT_SIZE_COEFF = 0.8; 28 | 29 | private static final long serialVersionUID = 6629300250729955406L; 30 | 31 | private int nwidth = 1, nheight = 1; 32 | private int fontsize = 12; 33 | 34 | private volatile double min = 0, max = 0, span = 1; 35 | 36 | private boolean font_set = false; 37 | private Font font; 38 | 39 | private final static Color background = new Color(150, 170, 130); 40 | private final static Color default_txt_colour_background = Color.DARK_GRAY; 41 | 42 | private static final Color colour_map[] = new Color[256]; 43 | { 44 | for (int i = 0; i < 256; i++) colour_map[i] = new Color(i, i, i); 45 | } 46 | 47 | private final LogScale scale_y = new LogScale(default_txt_colour_background, FONT_SPACING_COEFF ,LOWEST_DB, HIGHEST_DB); 48 | 49 | private final Object locker = new Object(); 50 | 51 | @Override 52 | public void setBounds(int x, int y, int width, int height) { 53 | this.nwidth = width; 54 | this.nheight = height; 55 | scale_y.setDimentions(this.nwidth, this.nheight); 56 | 57 | super.setBounds(x, y, width, height); 58 | } 59 | 60 | @Override 61 | public void setBounds(Rectangle r) { 62 | this.nwidth = r.width; 63 | this.nheight = r.height; 64 | scale_y.setDimentions(this.nwidth, this.nheight); 65 | super.setBounds(r); 66 | } 67 | 68 | 69 | public void setValue(final double min, final double max) { 70 | 71 | synchronized (locker) { 72 | this.min = min; 73 | this.max = max; 74 | this.span = max - min; 75 | } 76 | 77 | repaint(); 78 | } 79 | 80 | private int pxtocol(final int px) { 81 | final double val = scale_y.pxtoval(px); 82 | final int col = (int) (255 * (val - min) / span); 83 | return (col < 0) ? (0) : ((col > 255) ? (255) : (col)); 84 | } 85 | 86 | @Override 87 | public void paint(Graphics g) { 88 | 89 | synchronized (locker) { 90 | 91 | final int width = this.nwidth; 92 | final int height = this.nheight; 93 | 94 | final int minpx = scale_y.valtopx(this.min); 95 | final int maxpx = scale_y.valtopx(this.max); 96 | 97 | if (!font_set) { 98 | final Font existing = g.getFont(); 99 | font = new Font(existing.getFontName(), Font.PLAIN, (int) (existing.getSize()*FONT_SIZE_COEFF)); 100 | g.setFont(font); 101 | font_set = true; 102 | fontsize = g.getFont().getSize(); 103 | } else { 104 | g.setFont(font); 105 | } 106 | 107 | // start drawing 108 | g.setColor(background); 109 | g.fillRect(0, 0, width, height); 110 | 111 | scale_y.paintScale(g); 112 | 113 | final int maxvalidpx = Math.min(minpx, nheight); 114 | for (int y = (maxpx < 0) ? 0 : maxpx ; y < maxvalidpx; y++) { 115 | g.setColor(colour_map[pxtocol(y)]); 116 | g.drawLine(0, y, nwidth, y); 117 | } 118 | 119 | if (this.min >= scale_y.getLowestValue() && this.min <= scale_y.getHighestValue()) { 120 | final double min_db = scale_y.valtodb(this.min); 121 | g.setColor(Color.lightGray); 122 | g.drawString(String.format("%.2f", min_db), 0, minpx - fontsize/2); 123 | } 124 | 125 | if (this.max >= scale_y.getLowestValue() && this.max <= scale_y.getHighestValue()) { 126 | final double max_db = scale_y.valtodb(this.max); 127 | g.setColor(Color.DARK_GRAY); 128 | g.drawString(String.format("%.1f", max_db), 0, maxpx + fontsize); 129 | } 130 | 131 | } 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/gui/HoldButton.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.gui; 12 | 13 | import java.awt.event.MouseEvent; 14 | import java.awt.event.MouseListener; 15 | import java.util.ArrayList; 16 | import java.util.Timer; 17 | import java.util.TimerTask; 18 | 19 | import javax.swing.JButton; 20 | 21 | public class HoldButton extends JButton { 22 | private static final long DEFAULT_REPEAT_INTERVAL = 50; 23 | private static final long serialVersionUID = 7176946053407595449L; 24 | 25 | private final ArrayList callbacks = new ArrayList(); 26 | private final Timer timer = new Timer(); 27 | private int clickssofar = 0; 28 | 29 | volatile boolean running = false; 30 | 31 | private TimerTask task = null; 32 | private final long repeat_interval; 33 | 34 | public HoldButton(final String caption) { 35 | this(DEFAULT_REPEAT_INTERVAL, caption); 36 | } 37 | 38 | public void doHold() { 39 | if (!isEnabled()) return; 40 | if (running) return; 41 | running = true; 42 | clickssofar = 0; 43 | timer.scheduleAtFixedRate(task = new TimerTask() { 44 | @Override 45 | public void run() { 46 | clickssofar++; 47 | notifyHoldListeners(clickssofar); 48 | } 49 | }, 0, repeat_interval); 50 | } 51 | 52 | public void doRelease() { 53 | if (!isEnabled()) return; 54 | if (!running) return; 55 | if (task != null) { 56 | task.cancel(); 57 | task = null; 58 | } 59 | running = false; 60 | } 61 | 62 | public HoldButton(final long repeat_interval, final String caption) { 63 | super(caption); 64 | this.repeat_interval = repeat_interval; 65 | addMouseListener(new MouseListener() { 66 | 67 | @Override 68 | public void mouseReleased(MouseEvent arg0) { 69 | doRelease(); 70 | } 71 | 72 | @Override 73 | public void mousePressed(MouseEvent arg0) { 74 | doHold(); 75 | } 76 | 77 | public void mouseExited(MouseEvent arg0) {} 78 | public void mouseEntered(MouseEvent arg0) {} 79 | 80 | @Override 81 | public void mouseClicked(MouseEvent arg0) { 82 | notifyHoldListeners(1); 83 | } 84 | }); 85 | } 86 | 87 | private void notifyHoldListeners(final int clickssofar) { 88 | for (final HoldListener listener : callbacks) listener.onHold(clickssofar); 89 | } 90 | 91 | public void addHoldListener(final HoldListener listener) { 92 | if (!callbacks.contains(listener)) 93 | callbacks.add(listener); 94 | } 95 | 96 | public void removeHoldListener(final HoldListener listener) { 97 | callbacks.remove(listener); 98 | } 99 | 100 | public interface HoldListener { 101 | void onHold(final int clickssofar); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/gui/ImageVisualizer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.gui; 12 | import java.awt.Color; 13 | import java.awt.Font; 14 | import java.awt.Graphics; 15 | import java.awt.Graphics2D; 16 | import java.awt.Rectangle; 17 | import java.awt.RenderingHints; 18 | import java.awt.image.BufferedImage; 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.sql.Timestamp; 22 | 23 | import javax.imageio.ImageIO; 24 | import javax.swing.JPanel; 25 | 26 | 27 | public class ImageVisualizer extends JPanel { 28 | 29 | private static final long serialVersionUID = -6754436015453195809L; 30 | private static final int COUNT_TO_AVG = 30; 31 | private static final int OSD_SIZE_FRACT_OF_HEIGHT = 20; 32 | 33 | private Font default_osd_font = null; 34 | private int current_osd_height; 35 | 36 | private BufferedImage todraw = null; 37 | private Object locker = new Object(); 38 | 39 | private long prev = System.currentTimeMillis(); 40 | private long osdtime = System.currentTimeMillis(); 41 | private int count = 0; 42 | private int fps; 43 | 44 | private String OSD; 45 | 46 | private int width = -1, height = -1, nwidth = 1, nheight = 1, im_width = -1, im_height = -1, todraw_width = 1, todraw_height = 1, todraw_x = 0, todraw_y = 0; 47 | private int disp_real_width = -1, disp_real_height = -1; 48 | private int desired_image_width = -1; 49 | 50 | private Graphics theonewith_hints = null; 51 | private volatile boolean rendering_quality_high = false; 52 | 53 | public void drawImage(final BufferedImage image, int width) { 54 | 55 | synchronized (locker) { 56 | desired_image_width = width; 57 | todraw = image; 58 | } 59 | 60 | repaint(); 61 | } 62 | 63 | @Override 64 | public void setBounds(int x, int y, int width, int height) { 65 | this.nwidth = width; 66 | this.nheight = height; 67 | current_osd_height = height / OSD_SIZE_FRACT_OF_HEIGHT; 68 | default_osd_font = new Font(null, Font.PLAIN, current_osd_height); 69 | super.setBounds(x, y, width, height); 70 | } 71 | 72 | @Override 73 | public void setBounds(Rectangle r) { 74 | this.nwidth = r.width; 75 | this.nheight = r.height; 76 | current_osd_height = height / OSD_SIZE_FRACT_OF_HEIGHT; 77 | default_osd_font = new Font(null, Font.PLAIN, current_osd_height); 78 | super.setBounds(r); 79 | } 80 | 81 | public void setRenderingQualityHigh(boolean high) { 82 | this.rendering_quality_high = high; 83 | theonewith_hints = null; 84 | } 85 | 86 | @Override 87 | public void paint(Graphics g) { 88 | 89 | if (theonewith_hints != g) { 90 | try { 91 | final Graphics2D g2D = (Graphics2D) g; 92 | 93 | if (rendering_quality_high) { 94 | g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); 95 | g2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); 96 | g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 97 | } else { 98 | g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); 99 | g2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); 100 | g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); 101 | } 102 | 103 | theonewith_hints = g; 104 | } catch( Throwable t) {}; 105 | } 106 | 107 | if (todraw != null) { 108 | if (desired_image_width != im_width || todraw.getHeight() != im_height || nwidth != width || nheight != height) { 109 | width = nwidth; 110 | height = nheight; 111 | 112 | im_width = desired_image_width; 113 | im_height = todraw.getHeight(); 114 | 115 | todraw_width = width; 116 | todraw_height = height; 117 | 118 | if (width * im_height < im_width * height) 119 | todraw_height = (width * im_height) / im_width; 120 | else 121 | todraw_width = (height * im_width) / im_height; 122 | 123 | todraw_x = (width - todraw_width) / 2; 124 | todraw_y = (height - todraw_height) / 2; 125 | } 126 | 127 | g.setColor(Color.WHITE); 128 | g.fillRect(0, 0, width, height); 129 | 130 | synchronized (locker) { 131 | g.drawImage(todraw, todraw_x, todraw_y, todraw_width, todraw_height, null); 132 | } 133 | 134 | drawFPS(g); 135 | drawOSD(g); 136 | } else { 137 | g.setColor(Color.BLUE); 138 | g.fillRect(0, 0, getWidth(), getHeight()); 139 | } 140 | } 141 | 142 | private void drawFPS(Graphics g) { 143 | count++; 144 | if (count > COUNT_TO_AVG) { 145 | final long now = System.currentTimeMillis(); 146 | fps = (int) Math.round((1000.0 * COUNT_TO_AVG) / (double) (now - prev)); 147 | count = 0; 148 | prev = now; 149 | disp_real_width = todraw.getWidth(); 150 | disp_real_height = todraw.getHeight(); 151 | } 152 | 153 | // g.setColor(Color.white); 154 | // g.fillRect(width-60, 0, 60, 20); 155 | g.setColor(Color.red); 156 | g.drawString("width:" + disp_real_width + ", height:" + disp_real_height + ", fps:" + fps, width-240, 15); 157 | } 158 | 159 | private void drawOSD(Graphics g) { 160 | if (OSD != null && !OSD.isEmpty()) { 161 | g.setColor(Color.green); 162 | final Font original = g.getFont(); 163 | g.setFont(default_osd_font); 164 | g.drawString(OSD, 5, current_osd_height); 165 | g.setFont(original); 166 | if (System.currentTimeMillis() > osdtime) 167 | OSD = null; 168 | } 169 | } 170 | 171 | public void setOSD(final String text, final long timems) { 172 | OSD = text; 173 | osdtime = System.currentTimeMillis()+timems; 174 | } 175 | 176 | public void saveImageToPNGFile(final File dir) { 177 | final File file = new File(dir, new Timestamp((new java.util.Date()).getTime()).toString().replace(" ", "").replace(":", "")+".png"); 178 | if (todraw != null) { 179 | synchronized (todraw) { 180 | try { 181 | ImageIO.write(todraw, "png", file); 182 | System.out.println("File "+file+" saved!"); 183 | } catch (IOException e) { 184 | e.printStackTrace(); 185 | } 186 | } 187 | } else 188 | System.err.println("No file on screen to write!"); 189 | 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/gui/OnTSDRParamChangedCallback.java: -------------------------------------------------------------------------------- 1 | package martin.tempest.gui; 2 | 3 | import martin.tempest.core.TSDRLibrary.PARAM; 4 | import martin.tempest.core.TSDRLibrary.PARAM_DOUBLE; 5 | 6 | 7 | public interface OnTSDRParamChangedCallback { 8 | public void onSetParam(PARAM param, long value); 9 | public void onSetParam(PARAM_DOUBLE param, double value); 10 | } 11 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/gui/ParametersToggleButton.java: -------------------------------------------------------------------------------- 1 | package martin.tempest.gui; 2 | 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | import java.util.prefs.Preferences; 6 | 7 | import javax.swing.JToggleButton; 8 | 9 | import martin.tempest.core.TSDRLibrary; 10 | 11 | public class ParametersToggleButton extends JToggleButton { 12 | 13 | private static final long serialVersionUID = -7115465123485780108L; 14 | private final TSDRLibrary.PARAM param; 15 | private OnTSDRParamChangedCallback callback; 16 | private final String prefname; 17 | private final Preferences prefs; 18 | 19 | private void notifyCallback(final boolean selected) { 20 | if (callback != null) 21 | callback.onSetParam(param, selected ? 1 : 0); 22 | if (prefs != null) prefs.putBoolean(prefname, selected); 23 | } 24 | 25 | public ParametersToggleButton(final TSDRLibrary.PARAM param, final String text, final Preferences prefs, final boolean defaultvalue) { 26 | super(text, (prefs != null) ? prefs.getBoolean("PARAM"+param, defaultvalue) : defaultvalue); 27 | this.param = param; 28 | this.prefs = prefs; 29 | prefname = "PARAM"+param; 30 | addActionListener(new ActionListener() { 31 | 32 | @Override 33 | public void actionPerformed(ActionEvent arg0) { 34 | notifyCallback(isSelected()); 35 | } 36 | }); 37 | } 38 | 39 | public void setParaChangeCallback(final OnTSDRParamChangedCallback callback) { 40 | this.callback = callback; 41 | notifyCallback(isSelected()); 42 | } 43 | 44 | @Override 45 | public void setBounds(int x, int y, int width, int height) { 46 | notifyCallback(isSelected()); 47 | super.setBounds(x, y, width, height); 48 | } 49 | 50 | @Override 51 | public void setSelected(boolean arg0) { 52 | super.setSelected(arg0); 53 | notifyCallback(arg0); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/gui/SNRVisualizer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.gui; 12 | 13 | import java.awt.Color; 14 | import java.awt.Font; 15 | import java.awt.Graphics; 16 | import java.awt.Rectangle; 17 | 18 | import javax.swing.JPanel; 19 | 20 | import martin.tempest.gui.scale.LogScale; 21 | 22 | public class SNRVisualizer extends JPanel { 23 | 24 | private static final double DB_PADDING = 2; 25 | private static final double FONT_SPACING_COEFF = 1.5; 26 | private static final double LOWEST_DB = -50.7; 27 | private static final double HIGHEST_DB = 0.6; 28 | private static final double FONT_SIZE_COEFF = 0.8; 29 | 30 | private static final long serialVersionUID = 6629300250729955406L; 31 | 32 | private int nwidth = 1, nheight = 1; 33 | 34 | private double snr_db = LOWEST_DB-10; 35 | private double max_snr_db, min_snr_db; 36 | private boolean max_min_set = false; 37 | 38 | private boolean font_set = false; 39 | private Font font; 40 | 41 | private final static Color background = new Color(150, 170, 130); 42 | private final static Color default_txt_colour_background = Color.DARK_GRAY; 43 | private final static Color snr_txt_colour_background = default_txt_colour_background; 44 | 45 | private int fontsize = 12; 46 | 47 | private final LogScale scale_y = new LogScale(default_txt_colour_background, FONT_SPACING_COEFF ,LOWEST_DB, HIGHEST_DB); 48 | 49 | private final Object locker = new Object(); 50 | 51 | @Override 52 | public void setBounds(int x, int y, int width, int height) { 53 | this.nwidth = width; 54 | this.nheight = height; 55 | scale_y.setDimentions(this.nwidth, this.nheight); 56 | 57 | super.setBounds(x, y, width, height); 58 | } 59 | 60 | @Override 61 | public void setBounds(Rectangle r) { 62 | this.nwidth = r.width; 63 | this.nheight = r.height; 64 | scale_y.setDimentions(this.nwidth, this.nheight); 65 | super.setBounds(r); 66 | } 67 | 68 | 69 | public void setSNRValue(final double snr) { 70 | synchronized (locker) { 71 | this.snr_db = scale_y.valtodb( snr ); 72 | 73 | if (!max_min_set) { 74 | max_min_set = true; 75 | min_snr_db = snr_db; 76 | max_snr_db = snr_db; 77 | } else if (snr_db > max_snr_db) 78 | max_snr_db = snr_db; 79 | else if (snr_db < min_snr_db) 80 | min_snr_db = snr_db; 81 | 82 | scale_y.setLowestHighestDb(min_snr_db - DB_PADDING, max_snr_db + DB_PADDING); 83 | 84 | } 85 | 86 | repaint(); 87 | } 88 | 89 | @Override 90 | public void paint(Graphics g) { 91 | 92 | synchronized (locker) { 93 | 94 | final int width = this.nwidth; 95 | final int height = this.nheight; 96 | 97 | if (!font_set) { 98 | final Font existing = g.getFont(); 99 | font = new Font(existing.getFontName(), Font.PLAIN, (int) (existing.getSize()*FONT_SIZE_COEFF)); 100 | g.setFont(font); 101 | font_set = true; 102 | fontsize = g.getFont().getSize(); 103 | } else { 104 | g.setFont(font); 105 | } 106 | 107 | // start drawing 108 | g.setColor(background); 109 | g.fillRect(0, 0, width, height); 110 | 111 | if (snr_db < scale_y.getHighestDb() && snr_db > scale_y.getLowestDb()) { 112 | final int snrposy = scale_y.dbtopx(snr_db); 113 | 114 | g.setColor(snr_txt_colour_background); 115 | g.drawLine(0, snrposy, nwidth, snrposy); 116 | 117 | g.drawString(String.format("%.2f", snr_db), 0, (int) (snrposy+1.5*fontsize)); 118 | g.drawString("dB", 0, (int) (snrposy-0.5*fontsize)); 119 | } 120 | 121 | scale_y.paintScale(g); 122 | 123 | } 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/gui/scale/ZoomableXScale.java: -------------------------------------------------------------------------------- 1 | package martin.tempest.gui.scale; 2 | 3 | /******************************************************************************* 4 | * Copyright (c) 2014 Martin Marinov. 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the GNU Public License v3.0 7 | * which accompanies this distribution, and is available at 8 | * http://www.gnu.org/licenses/gpl.html 9 | * 10 | * Contributors: 11 | * Martin Marinov - initial API and implementation 12 | ******************************************************************************/ 13 | 14 | 15 | /** 16 | * Implements a zoomable scale that can map values from min_val to max_val to 17 | * 0 to max_value pixels. It also has a maximum zoomable value that you can set up. 18 | * 19 | * @author martinmarinov 20 | * 21 | */ 22 | public class ZoomableXScale { 23 | 24 | private int max_pixels = 800; 25 | private double min_value, max_value, offset_val = 0.0; 26 | private int offset_px = 0; 27 | private double scale = 1.0; // one raw pixels = scale * screen pixel 28 | private double max_zoom_val = 1.0; 29 | private double one_val_in_pixels_relative = max_pixels / (max_value - min_value); 30 | private double one_px_in_values_relative = (max_value - min_value) / max_pixels; 31 | 32 | private boolean autofixzoomandoffset = true; 33 | 34 | private final Object locker = new Object(); 35 | 36 | /** 37 | * Set the values that will show up 38 | * @param min_value 39 | * @param max_value 40 | * @param max_zoom_val the maximum size of maximum zoom. If this is 0.2 then the maximum amount you can zoom is having 0.2 value accross the whole screen 41 | */ 42 | public ZoomableXScale(final double min_value, final double max_value, final double max_zoom_val) { 43 | setMinMaxValue(min_value, max_value, max_zoom_val); 44 | } 45 | 46 | public ZoomableXScale(final double min_value, final double max_value) { 47 | this(min_value, max_value, 1.0); 48 | } 49 | 50 | public ZoomableXScale(final double max_zoom_val) { 51 | this(0, 100, max_zoom_val); 52 | } 53 | 54 | public ZoomableXScale() { 55 | this(0, 100, 1.0); 56 | } 57 | 58 | public void autofixZoomAndOffsetEnabled(final boolean enforce) { 59 | synchronized (locker) { 60 | this.autofixzoomandoffset = enforce; 61 | } 62 | } 63 | 64 | public void setMaxPixels(final int max_pixels) { 65 | synchronized (locker) { 66 | this.max_pixels = max_pixels; 67 | 68 | calculateValues_unsafe(); 69 | } 70 | } 71 | 72 | public void setMinMaxValue(final double min_value, final double max_value, final double max_zoom_val) { 73 | synchronized (locker) { 74 | this.max_zoom_val = max_zoom_val; 75 | setMinMaxValue(min_value, max_value); 76 | } 77 | } 78 | 79 | public void setMinMaxValue(final double min_value, final double max_value) { 80 | synchronized (locker) { 81 | this.min_value = min_value; 82 | this.max_value = max_value; 83 | 84 | calculateValues_unsafe(); 85 | } 86 | } 87 | 88 | public void moveOffsetWithPixels(final int offset) { 89 | synchronized (locker) { 90 | setPxOffset_unsafe(offset_px - offset); 91 | 92 | if (autofixzoomandoffset) 93 | autoFixOffset_unsafe(); 94 | } 95 | } 96 | 97 | public void moveOffsetWithValue(final double value) { 98 | synchronized (locker) { 99 | setValOffset_unsafe(offset_val - value); 100 | 101 | if (autofixzoomandoffset) 102 | autoFixOffset_unsafe(); 103 | } 104 | } 105 | 106 | public void zoomAround(final int px, final double coeff) { 107 | synchronized (locker) { 108 | final double val = pixels_to_value_absolute(px); 109 | scale *= coeff; 110 | calculateValues_unsafe(); 111 | 112 | final double newval = pixels_to_value_absolute(px); 113 | 114 | setValOffset_unsafe(offset_val - newval + val); 115 | 116 | if (autofixzoomandoffset) 117 | autoFixOffset_unsafe(); 118 | } 119 | } 120 | 121 | public void fixOffset() { 122 | synchronized (locker) { 123 | autoFixOffset_unsafe(); 124 | } 125 | } 126 | 127 | public void reset() { 128 | synchronized (locker) { 129 | reset_unsafe(); 130 | } 131 | } 132 | 133 | public double pixels_to_value_absolute(final int pixels) { 134 | synchronized (locker) { 135 | return pixels * one_px_in_values_relative + offset_val + min_value; 136 | } 137 | } 138 | 139 | public double pixels_to_value_relative(final int pixels) { 140 | synchronized (locker) { 141 | return pixels * one_px_in_values_relative; 142 | } 143 | } 144 | 145 | public int value_to_pixel_absolute(final double val) { 146 | synchronized (locker) { 147 | return (int) ((val - min_value) * one_val_in_pixels_relative) - offset_px; 148 | } 149 | } 150 | 151 | public int value_to_pixel_relative(final double val) { 152 | synchronized (locker) { 153 | return (int) (val * one_val_in_pixels_relative); 154 | } 155 | } 156 | 157 | private void setPxOffset_unsafe(final int offset_px) { 158 | this.offset_px = offset_px; 159 | offset_val = pixels_to_value_relative(offset_px); 160 | } 161 | 162 | private void setValOffset_unsafe(final double offset_val) { 163 | this.offset_val = offset_val; 164 | offset_px = value_to_pixel_relative(offset_val); 165 | } 166 | 167 | private void calculateValues_unsafe() { 168 | 169 | one_val_in_pixels_relative = max_pixels / ((max_value - min_value)*scale); 170 | one_px_in_values_relative = ((max_value - min_value)*scale) / max_pixels; 171 | 172 | final double values_in_screen = pixels_to_value_relative(max_pixels); 173 | if (values_in_screen < max_zoom_val) { 174 | scale = max_zoom_val / (max_value - min_value); 175 | one_val_in_pixels_relative = max_pixels / ((max_value - min_value)*scale); 176 | one_px_in_values_relative = ((max_value - min_value)*scale) / max_pixels; 177 | } 178 | } 179 | 180 | private void reset_unsafe() { 181 | scale = 1; 182 | offset_val = 0; 183 | offset_px = 0; 184 | 185 | calculateValues_unsafe(); 186 | } 187 | 188 | private void autoFixOffset_unsafe() { 189 | 190 | if (offset_px < 0) 191 | setPxOffset_unsafe(0); 192 | 193 | final double max_val = pixels_to_value_absolute(max_pixels); 194 | if (max_val > this.max_value) 195 | setValOffset_unsafe(this.max_value - pixels_to_value_relative(max_pixels) - this.min_value); 196 | 197 | if (offset_px < 0) 198 | reset_unsafe(); 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/sources/TSDRExtIOSource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.sources; 12 | 13 | import java.awt.Container; 14 | import java.awt.event.ActionEvent; 15 | import java.awt.event.ActionListener; 16 | import java.io.File; 17 | import java.util.ArrayList; 18 | 19 | import javax.swing.DefaultComboBoxModel; 20 | import javax.swing.JButton; 21 | import javax.swing.JComboBox; 22 | import javax.swing.JFileChooser; 23 | 24 | /** 25 | * The ExtIO file source is a plugin that will load a ExtIO__.dll on Windows. The dll needs to be in the same folder 26 | * as the executabe, in the native library path (LD_LIBRARY_PATH), supplied via java.library.path or via absolute path as parameters. 27 | * 28 | * The GUI allows for user friendly selection if the system fails to automatically find a dll. 29 | * 30 | * This class will not work on Linux! 31 | * 32 | * @author Martin Marinov 33 | * 34 | */ 35 | public class TSDRExtIOSource extends TSDRSource { 36 | 37 | public TSDRExtIOSource() { 38 | super("ExtIO source", "TSDRPlugin_ExtIO", false); 39 | } 40 | 41 | /** 42 | * Finds all of the files in a folder that match the ExtIO filename convention. 43 | * @param dir the folder to be searched 44 | * @return {@link ArrayList} with all of the discovered files 45 | */ 46 | private ArrayList findExtIOpluginsInFolder(final File dir) { 47 | final ArrayList answer = new ArrayList(); 48 | if (dir.exists()) { 49 | final File[] files = dir.listFiles(); 50 | 51 | for (final File file : files) { 52 | final String fname = file.getName().toLowerCase(); 53 | if (fname.startsWith("extio_") && fname.endsWith(".dll")) 54 | answer.add(file); 55 | } 56 | } 57 | return answer; 58 | } 59 | 60 | /** 61 | * If more than one ExtIO dll is selected, build GUI for user selection. 62 | * @param cont 63 | * @param availableplugins 64 | */ 65 | @SuppressWarnings({ "unchecked", "rawtypes" }) 66 | private void makeDeviceSelectionDialog(final Container cont, final ArrayList availableplugins) { 67 | 68 | final JComboBox options = new JComboBox(); 69 | final String[] filenames = new String[availableplugins.size()]; 70 | for (int i = 0; i < filenames.length; i++) filenames[i] = availableplugins.get(i).getName(); 71 | cont.add(options); 72 | options.setBounds(12, 12, 159, 22); 73 | options.setModel(new DefaultComboBoxModel(filenames)); 74 | 75 | final JButton ok = new JButton("Choose"); 76 | cont.add(ok); 77 | ok.setBounds(12, 12+2*32, 84, 24); 78 | 79 | ok.addActionListener(new ActionListener() { 80 | @Override 81 | public void actionPerformed(ActionEvent arg0) { 82 | new Thread() { 83 | public void run() { 84 | ok.setEnabled(false); 85 | setParams(availableplugins.get(options.getSelectedIndex()).getAbsolutePath()); 86 | ok.setEnabled(true); 87 | }; 88 | }.start(); 89 | } 90 | }); 91 | } 92 | 93 | /** 94 | * If no files are pressent at all, user will have the option to pick one manually. 95 | * @param cont 96 | */ 97 | private void makeFileSelectionDialog(final Container cont) { 98 | 99 | final JFileChooser fc = new JFileChooser(); 100 | 101 | if (fc.showOpenDialog(cont) == JFileChooser.APPROVE_OPTION) 102 | setParams(fc.getSelectedFile().getAbsolutePath()); 103 | 104 | final JButton ok = new JButton("Choose ExtIO dll file"); 105 | cont.add(ok); 106 | ok.setBounds(12, 12, 200, 24); 107 | 108 | ok.addActionListener(new ActionListener() { 109 | @Override 110 | public void actionPerformed(ActionEvent arg0) { 111 | new Thread() { 112 | public void run() { 113 | ok.setEnabled(false); 114 | if (fc.showOpenDialog(cont) == JFileChooser.APPROVE_OPTION) 115 | setParams(fc.getSelectedFile().getAbsolutePath()); 116 | ok.setEnabled(true); 117 | }; 118 | }.start(); 119 | } 120 | }); 121 | } 122 | 123 | @Override 124 | public boolean populateGUI(final Container cont, final String defaultprefs, final ActionListenerRegistrator okbutton) { 125 | 126 | final String[] paths = System.getProperty("java.library.path").split(File.pathSeparator); 127 | for (final String path : paths) { 128 | final ArrayList plugins = findExtIOpluginsInFolder(new File(path)); 129 | if (plugins.size() == 1) { 130 | setParams(plugins.get(0).getAbsolutePath()); 131 | return false; 132 | } else if (plugins.size() > 1) { 133 | makeDeviceSelectionDialog(cont, plugins); 134 | return false; 135 | } 136 | } 137 | 138 | { 139 | final ArrayList plugins = findExtIOpluginsInFolder(new File(".")); 140 | if (plugins.size() == 1) { 141 | setParams(plugins.get(0).getAbsolutePath()); 142 | return false; 143 | } else if (plugins.size() > 1) { 144 | makeDeviceSelectionDialog(cont, plugins); 145 | return false; 146 | } 147 | } 148 | 149 | makeFileSelectionDialog(cont); 150 | return false; 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/sources/TSDRFileSource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.sources; 12 | 13 | import java.awt.Container; 14 | import java.awt.event.ActionEvent; 15 | import java.awt.event.ActionListener; 16 | import java.io.DataInputStream; 17 | import java.io.BufferedInputStream; 18 | import java.io.FileInputStream; 19 | import java.util.ArrayList; 20 | 21 | import javax.swing.DefaultComboBoxModel; 22 | import javax.swing.JButton; 23 | import javax.swing.JComboBox; 24 | import javax.swing.JFileChooser; 25 | import javax.swing.JLabel; 26 | import javax.swing.JTextField; 27 | 28 | /** 29 | * This plugin allows for playback of prerecorded files. 30 | * 31 | * @author Martin Marinov 32 | * 33 | */ 34 | public class TSDRFileSource extends TSDRSource { 35 | private final static String[] filetype = new String[] {"float", "int8", "int16", "uint8", "uint16"}; 36 | 37 | final JFileChooser fc = new JFileChooser(); 38 | 39 | public TSDRFileSource() { 40 | super("From file", "TSDRPlugin_RawFile", false); 41 | } 42 | 43 | private static ParsedTSDRFileSource getWavFile(String file) { 44 | DataInputStream in = null; 45 | try { 46 | 47 | in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); 48 | 49 | if (in.readInt() != 0x52494646) return null; 50 | 51 | in.skipBytes(4); 52 | 53 | if (in.readInt() != 0x57415645) return null; 54 | if (in.readInt() != 0x666d7420) return null; 55 | 56 | in.skipBytes(8); 57 | 58 | final int samplerate = in.readByte() | (in.readByte() << 8) | (in.readByte() << 16) | (in.readByte() << 24); 59 | 60 | in.skipBytes(6); 61 | 62 | final int bitspersample = in.readByte() | (in.readByte() << 8); 63 | 64 | 65 | if (bitspersample == 8 || bitspersample == 16) { 66 | final String type = (bitspersample == 8) ? "int8" : "int16"; 67 | 68 | int type_id = -1; 69 | for (int i = 0; i < filetype.length; i++) if (type.equals(filetype[i])) {type_id = i; break;}; 70 | if (type_id == -1) return null; 71 | 72 | return new ParsedTSDRFileSource(file, type_id, samplerate); 73 | 74 | } else 75 | return null; 76 | 77 | } catch (Throwable t) { 78 | return null; 79 | } finally { 80 | if (in != null) 81 | try { 82 | in.close(); 83 | } catch (Throwable t) {} 84 | } 85 | } 86 | 87 | @SuppressWarnings({ "rawtypes", "unchecked" }) 88 | @Override 89 | public boolean populateGUI(final Container cont, final String defaultprefs, final ActionListenerRegistrator okbutton) { 90 | 91 | final ParsedTSDRFileSource parsed = new ParsedTSDRFileSource(defaultprefs); 92 | 93 | final JFileChooser fc = parsed.filename.isEmpty() ? new JFileChooser() : new JFileChooser(parsed.filename); 94 | 95 | final JLabel description = new JLabel("Choose pre-recorded file, type and sample rate:"); 96 | cont.add(description); 97 | description.setBounds(12, 12, 350, 24); 98 | 99 | final JTextField filename = new JTextField(parsed.filename); 100 | cont.add(filename); 101 | filename.setBounds(12, 12+32, 150, 24); 102 | 103 | final JTextField samplerate = new JTextField(String.valueOf(parsed.samplerate)); 104 | cont.add(samplerate); 105 | samplerate.setBounds(12*2+150+100, 12+32, 150, 24); 106 | 107 | final JComboBox type = new JComboBox(); 108 | type.setModel(new DefaultComboBoxModel(filetype)); 109 | type.setSelectedIndex(parsed.type_id); 110 | type.setBounds(12*3+150+150+100, 12+32, 100, 24); 111 | cont.add(type); 112 | 113 | final JButton browse = new JButton("Browse"); 114 | cont.add(browse); 115 | browse.setBounds(150+12, 12+32, 100, 24); 116 | browse.addActionListener(new ActionListener() { 117 | @Override 118 | public void actionPerformed(ActionEvent arg0) { 119 | if (fc.showOpenDialog(cont) == JFileChooser.APPROVE_OPTION) { 120 | final String absoluteName = fc.getSelectedFile().getAbsolutePath(); 121 | final ParsedTSDRFileSource wavData = getWavFile(absoluteName); 122 | 123 | filename.setText(absoluteName); 124 | 125 | if (wavData != null) { 126 | type.setSelectedIndex(wavData.type_id); 127 | samplerate.setText(String.valueOf(wavData.samplerate)); 128 | } 129 | } 130 | } 131 | }); 132 | 133 | okbutton.addActionListener(new ActionListener() { 134 | @Override 135 | public void actionPerformed(ActionEvent arg0) { 136 | final String params = "\""+filename.getText()+"\" "+samplerate.getText()+" "+type.getSelectedItem(); 137 | setParams(params); 138 | } 139 | }); 140 | 141 | return true; 142 | } 143 | 144 | private static class ParsedTSDRFileSource { 145 | private String filename = ""; 146 | private int type_id = 0; 147 | private long samplerate = 8000000; 148 | 149 | private final ArrayList parse(final String input) { 150 | final ArrayList answer = new ArrayList(); 151 | if (input == null || input.trim().isEmpty()) return answer; 152 | 153 | StringBuilder builder = new StringBuilder(); 154 | boolean inside = false; 155 | 156 | for (int i = 0; i < input.length(); i++) { 157 | final char c = input.charAt(i); 158 | 159 | if (!inside && c == ' ') { 160 | if (builder.length() != 0) answer.add(builder.toString()); 161 | builder = new StringBuilder(); 162 | } else if (c != '"') builder.append(c); 163 | if (c == '"') inside = !inside; 164 | } 165 | if (builder.length() != 0) answer.add(builder.toString()); 166 | 167 | return answer; 168 | } 169 | 170 | public ParsedTSDRFileSource(String filename, int type_id, long samplerate) { 171 | this.filename = filename; 172 | this.type_id = type_id; 173 | this.samplerate = samplerate; 174 | } 175 | 176 | public ParsedTSDRFileSource(final String command) { 177 | final ArrayList parsed = parse(command); 178 | if (parsed.size() == 3) { 179 | final String supposed_type = parsed.get(2); 180 | 181 | int id = -1; 182 | for (int i = 0; i < filetype.length; i++) if (filetype[i].equals(supposed_type)) id = i; 183 | 184 | if (id == -1) return; 185 | 186 | long samplerate = -1; 187 | try { 188 | samplerate = Long.parseLong(parsed.get(1)); 189 | } catch (Throwable e) { 190 | return; 191 | } 192 | 193 | this.filename = parsed.get(0); 194 | this.type_id = id; 195 | this.samplerate = samplerate; 196 | 197 | } 198 | } 199 | 200 | @Override 201 | public String toString() { 202 | if (type_id < 0 || type_id >= filetype.length) 203 | return "ParsedTSDRFileSource filename: "+filename+"; type: INVALID; samplerate: "+samplerate; 204 | return "ParsedTSDRFileSource filename: "+filename+"; type: "+filetype[type_id]+"; samplerate: "+samplerate; 205 | } 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/sources/TSDRMiricsSource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.sources; 12 | 13 | import java.awt.Container; 14 | 15 | /** 16 | * This is a source that works with the Mirics dongle, for more information see mirics.com 17 | * 18 | * @author Martin Marinov 19 | * 20 | */ 21 | public class TSDRMiricsSource extends TSDRSource { 22 | 23 | public TSDRMiricsSource() { 24 | super("Mirics dongle", "TSDRPlugin_Mirics", false); 25 | } 26 | 27 | @Override 28 | public boolean populateGUI(final Container cont, final String defaultprefs, final ActionListenerRegistrator okbutton) { 29 | setParams(defaultprefs); 30 | return false; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/sources/TSDRSDRPlaySource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.sources; 12 | 13 | import java.awt.Container; 14 | 15 | /** 16 | * This is a source that works with the SDRPlay RSP, for more information see sdrplay.com 17 | * 18 | * @author Martin Marinov 19 | * 20 | */ 21 | public class TSDRSDRPlaySource extends TSDRSource { 22 | 23 | public TSDRSDRPlaySource() { 24 | super("SDRplay RSP", "TSDRPlugin_SDRPlay", false); 25 | } 26 | 27 | @Override 28 | public boolean populateGUI(final Container cont, final String defaultprefs, final ActionListenerRegistrator okbutton) { 29 | setParams(defaultprefs); 30 | return false; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/JavaGUI/src/martin/tempest/sources/TSDRUHDSource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | package martin.tempest.sources; 12 | 13 | /** 14 | * This plugin allows for playback of prerecorded files. 15 | * 16 | * @author Martin Marinov 17 | * 18 | */ 19 | public class TSDRUHDSource extends TSDRSource { 20 | 21 | public TSDRUHDSource() { 22 | super("USRP (via UHD)", "TSDRPlugin_UHD", false); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_ExtIO/README: -------------------------------------------------------------------------------- 1 | This plugin supports ExtIO dll files to be utilized as inputs for TSDR. It takes the location of the ExtIO dll as an command. 2 | 3 | In order to compile the plugin: 4 | 5 | make all 6 | 7 | This plugin is only for Windows. -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_ExtIO/makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Martin Marinov. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the GNU Public License v3.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.gnu.org/licenses/gpl.html 7 | # 8 | # Contributors: 9 | # Martin Marinov - initial API and implementation 10 | #------------------------------------------------------------------------------- 11 | # This makefile should work for all plugins that reside in the root directory of the repository. 12 | # The header file is copied over from the source 13 | PLUGNAME=TSDRPlugin_ExtIO 14 | 15 | # Dependencies 16 | OBJS=$(PLUGNAME).o ExtIOPluginLoader.o 17 | DEPS=TSDRPlugin.h TSDRCodes.h ExtIOPluginLoader.h errors.h 18 | 19 | # Flags 20 | ifeq ($(BUILD_TYPE),Debug) 21 | DEBUGFLAGS+=-g -O0 22 | else 23 | CFLAGS+=-O3 24 | endif 25 | 26 | # END OF CONFIGURATION IF STANDARD DIR STRUCTURE IS USED 27 | 28 | # Where the TSDRPlugin.h of the TempestSDR library resides (so it will be copied over) 29 | HEADLOCATION=../TempestSDR/src/include/ 30 | 31 | # Discover the library extension for each OS 32 | ifeq ($(OS),Windows_NT) 33 | 34 | OSNAME ?= WINDOWS 35 | 36 | ifndef $(ARCHNAME) 37 | 38 | ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) 39 | ARCHNAME = X64 40 | endif 41 | ifeq ($(PROCESSOR_ARCHITECTURE),x86) 42 | ARCHNAME = X86 43 | endif 44 | 45 | endif 46 | else 47 | 48 | ifndef $(OSNAME) 49 | 50 | UNAME_S := $(shell uname -s) 51 | ifeq ($(UNAME_S),Linux) 52 | OSNAME = LINUX 53 | endif 54 | 55 | endif 56 | 57 | ifndef $(ARCHNAME) 58 | 59 | UNAME_M := $(shell uname -m) 60 | ifeq ($(UNAME_M),x86_64) 61 | ARCHNAME = X64 62 | endif 63 | ifneq ($(filter %86,$(UNAME_M)),) 64 | ARCHNAME = X86 65 | endif 66 | ifneq ($(filter arm%,$(UNAME_M)),) 67 | ARCHNAME = ARM 68 | endif 69 | 70 | endif 71 | endif 72 | 73 | ifeq ($(OSNAME),WINDOWS) 74 | EXT=.dll 75 | LIBPREFIX= 76 | endif 77 | ifeq ($(OSNAME),LINUX) 78 | EXT=.so 79 | LIBPREFIX=lib 80 | endif 81 | 82 | ifeq ($(ARCHNAME),X86) 83 | COMPILATION_TYPE=-m32 84 | ARCHNAME_LOWER=x86 85 | else ifeq ($(ARCHNAME),X64) 86 | COMPILATION_TYPE=-m64 87 | ARCHNAME_LOWER=x64 88 | endif 89 | 90 | 91 | # If you need a different directory structure. Don't change that unless you really want to. 92 | SOURCEFOLDER=src 93 | OUTPUTFOLDER=bin/$(OSNAME)/$(ARCHNAME) 94 | OBJFOLDER=obj 95 | 96 | # Calculate the path to dependencies 97 | _OBJS = $(patsubst %,$(OBJFOLDER)/%,$(OBJS)) 98 | _DEPS = $(patsubst %,$(SOURCEFOLDER)/%,$(DEPS)) 99 | 100 | # OS specific flags 101 | LDFLAGS+=-Wl,--add-stdcall-alias 102 | 103 | # Generate the library 104 | all : $(OUTPUTFOLDER)/$(PLUGNAME)$(EXT) 105 | 106 | # Copy over a fresh version of the TSDRPlugin.h 107 | copyoverheaderfile: 108 | @cp -f $(HEADLOCATION)/TSDRPlugin.h $(SOURCEFOLDER)/ 109 | @cp -f $(HEADLOCATION)/TSDRCodes.h $(SOURCEFOLDER)/ 110 | 111 | # Link 112 | $(OUTPUTFOLDER)/$(PLUGNAME)$(EXT): copyoverheaderfile $(_OBJS) 113 | $(CC) -Wall $(LDFLAGS) $(DEBUGFLAGS) -shared $(COMPILATION_TYPE) -o $@ $(_OBJS) 114 | 115 | # Make dirs and compile 116 | $(OBJFOLDER)/%.o : $(SOURCEFOLDER)/%.c $(_DEPS) 117 | mkdir -p $(OUTPUTFOLDER) 118 | mkdir -p $(OBJFOLDER) 119 | $(CC) -Wall $(foreach d, $(INC), -I$d) $(CFLAGS) $(DEBUGFLAGS) $(COMPILATION_TYPE) -c $< -o $@ 120 | 121 | .PHONY: clean 122 | 123 | # Clean artifacts 124 | clean : 125 | rm -f $(OBJFOLDER)/*.o $(OUTPUTFOLDER)/*.* $(OUTPUTFOLDER)/$(PLUGNAME)$(EXT) 126 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_ExtIO/src/ExtIOPluginLoader.c: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #include "ExtIOPluginLoader.h" 14 | #include "TSDRCodes.h" 15 | 16 | #include 17 | #include 18 | 19 | // A platform independent dynamic library loader 20 | 21 | void *extio_getfunction(extiosource_t * plugin, char *functname) 22 | { 23 | return (void*)GetProcAddress(plugin->fd,functname); 24 | } 25 | 26 | void extio_close(extiosource_t * plugin) 27 | { 28 | if (plugin->fd == NULL) return; 29 | FreeLibrary(plugin->fd); 30 | } 31 | 32 | int extio_load(extiosource_t * plugin, const char *dlname) 33 | { 34 | plugin->fd = LoadLibraryA(dlname); 35 | 36 | if (plugin->fd == NULL) 37 | return TSDR_INCOMPATIBLE_PLUGIN; 38 | 39 | // mandatory 40 | if ((plugin->InitHW = (bool(__stdcall *) (char *, char *, int *)) extio_getfunction(plugin, "InitHW")) == 0) return TSDR_ERR_PLUGIN; 41 | if ((plugin->OpenHW = (bool(__stdcall *) (void)) extio_getfunction(plugin, "OpenHW")) == 0) return TSDR_ERR_PLUGIN; 42 | if ((plugin->CloseHW = (void(__stdcall *) (void)) extio_getfunction(plugin, "CloseHW")) == 0) return TSDR_ERR_PLUGIN; 43 | if ((plugin->StartHW = (int(__stdcall *) (long)) extio_getfunction(plugin, "StartHW")) == 0) return TSDR_ERR_PLUGIN; 44 | if ((plugin->StopHW = (void(__stdcall *) (void)) extio_getfunction(plugin, "StopHW")) == 0) return TSDR_ERR_PLUGIN; 45 | if ((plugin->SetCallback = (void(__stdcall *) (pfnExtIOCallback)) extio_getfunction(plugin, "SetCallback")) == 0) return TSDR_ERR_PLUGIN; 46 | if ((plugin->SetHWLO = (int(__stdcall *) (long)) extio_getfunction(plugin, "SetHWLO")) == 0) return TSDR_ERR_PLUGIN; 47 | if ((plugin->GetStatus = (int(__stdcall *) (void)) extio_getfunction(plugin, "GetStatus")) == 0) return TSDR_ERR_PLUGIN; 48 | 49 | // mandatory functions that rtlsdr expects 50 | if ((plugin->GetHWSR = (long(__stdcall *) (void)) extio_getfunction(plugin, "GetHWSR")) == 0) return TSDR_ERR_PLUGIN; 51 | 52 | // completely optional functions 53 | if ((plugin->SetAttenuator = (int(__stdcall *) (int)) extio_getfunction(plugin, "SetAttenuator")) == 0) plugin->SetAttenuator = NULL; 54 | if ((plugin->GetAttenuators = (int(__stdcall *) (int, float *)) extio_getfunction(plugin, "GetAttenuators")) == 0) plugin->GetAttenuators = NULL; 55 | if ((plugin->ShowGUI = (int(__stdcall *) (void)) extio_getfunction(plugin, "ShowGUI")) == 0) plugin->ShowGUI = NULL; 56 | if ((plugin->HideGUI = (int(__stdcall *) (void)) extio_getfunction(plugin, "HideGUI")) == 0) plugin->HideGUI = NULL; 57 | 58 | return TSDR_OK; 59 | } 60 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_ExtIO/src/ExtIOPluginLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRPluginLoader 14 | #define _TSDRPluginLoader 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | typedef void(*pfnExtIOCallback) (int cnt, int status, float IQoffs, void *IQdata); 22 | 23 | struct extiosource { 24 | HINSTANCE fd; 25 | 26 | // mandatory functions that the dll must implement 27 | bool(__stdcall * InitHW) (char *name, char *model, int *hwtype); // for hwtype see enum extHWtypeT 28 | bool(__stdcall * OpenHW) (void); 29 | void(__stdcall * CloseHW) (void); 30 | int(__stdcall * StartHW) (long extLOfreq); 31 | void(__stdcall * StopHW) (void); 32 | void(__stdcall * SetCallback) (pfnExtIOCallback funcptr); 33 | int(__stdcall * SetHWLO) (long extLOfreq); // see also SetHWLO64 34 | int(__stdcall * GetStatus) (void); 35 | 36 | // mandatory functions that tsdrrequires 37 | long(__stdcall * GetHWSR) (void); 38 | 39 | // completely optional functions 40 | int(__stdcall * SetAttenuator) (int atten_idx); 41 | int(__stdcall * GetAttenuators) (int atten_idx, float * attenuation); 42 | int(__stdcall * ShowGUI) (void); 43 | int(__stdcall * HideGUI) (void); 44 | 45 | } typedef extiosource_t; 46 | 47 | int extio_load(extiosource_t * plugin, const char *dlname); 48 | void extio_close(extiosource_t * plugin); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_ExtIO/src/TSDRCodes.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRCodes 14 | #define _TSDRCodes 15 | 16 | #define TSDR_OK (0) 17 | #define TSDR_ERR_PLUGIN (1) 18 | #define TSDR_WRONG_VIDEOPARAMS (2) 19 | #define TSDR_ALREADY_RUNNING (3) 20 | #define TSDR_PLUGIN_PARAMETERS_WRONG (4) 21 | #define TSDR_SAMPLE_RATE_WRONG (5) 22 | #define TSDR_CANNOT_OPEN_DEVICE (6) 23 | #define TSDR_INCOMPATIBLE_PLUGIN (7) 24 | #define TSDR_INVALID_PARAMETER (8) 25 | #define TSDR_INVALID_PARAMETER_VALUE (9) 26 | #define TSDR_NOT_RUNNING (10) 27 | #define TSDR_NOT_IMPLEMENTED (404) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_ExtIO/src/TSDRPlugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRPluginHeader 14 | #define _TSDRPluginHeader 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #if _MSC_VER && !__INTEL_COMPILER 21 | #define TSDRPLUGIN_API __declspec(dllexport) 22 | #elif defined _WIN32 || defined __CYGWIN__ 23 | #ifdef __GNUC__ 24 | #define TSDRPLUGIN_API __attribute__ ((dllexport)) 25 | #else 26 | #define TSDRPLUGIN_API __declspec(dllexport) 27 | #endif 28 | #else 29 | #if __GNUC__ >= 4 30 | #define TSDRPLUGIN_API __attribute__ ((visibility ("default"))) 31 | #else 32 | #define TSDRPLUGIN_API 33 | #endif 34 | #endif 35 | 36 | 37 | #ifdef __cplusplus 38 | #define EXTERNC extern "C" 39 | #else 40 | #define EXTERNC 41 | #endif 42 | 43 | #if !(defined(OS_WINDOWS) || defined(_WIN64) || defined(_WIN32) || defined(_MSC_VER) || defined(__stdcall)) 44 | #define __stdcall 45 | #endif 46 | 47 | #include 48 | 49 | typedef void(*tsdrplugin_readasync_function)(float *buf, uint64_t items_count, void *ctx, int64_t samples_dropped); 50 | 51 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_getName(char *); 52 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_init(const char * params); 53 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_setsamplerate(uint32_t rate); 54 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_getsamplerate(); 55 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setbasefreq(uint32_t freq); 56 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_stop(void); 57 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setgain(float gain); 58 | EXTERNC TSDRPLUGIN_API char* __stdcall tsdrplugin_getlasterrortext(void); 59 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx); 60 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_cleanup(void); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_ExtIO/src/errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef ERRORS_H_ 14 | #define ERRORS_H_ 15 | 16 | #include "TSDRCodes.h" 17 | #include 18 | #include 19 | 20 | 21 | int errormsg_code; 22 | char * errormsg = NULL; 23 | int errormsg_size = 0; 24 | #define RETURN_EXCEPTION(message, status) {announceexception(message, status); return status;} 25 | #define RETURN_OK() {errormsg_code = TSDR_OK; return TSDR_OK;} 26 | 27 | static inline void announceexception(const char * message, int status) { 28 | 29 | errormsg_code = status; 30 | if (status == TSDR_OK) return; 31 | 32 | const int length = strlen(message); 33 | if (errormsg_size == 0) { 34 | errormsg_size = length; 35 | errormsg = (char *)malloc(errormsg_size + 1); 36 | errormsg[errormsg_size] = 0; 37 | } 38 | else if (length > errormsg_size) { 39 | errormsg_size = length; 40 | errormsg = (char *)realloc((void*)errormsg, errormsg_size + 1); 41 | errormsg[errormsg_size] = 0; 42 | } 43 | 44 | 45 | memcpy(errormsg, message, length); 46 | } 47 | 48 | 49 | char * TSDRPLUGIN_API __stdcall tsdrplugin_getlasterrortext(void) { 50 | if (errormsg_code == TSDR_OK) 51 | return NULL; 52 | else 53 | return errormsg; 54 | } 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_Mirics/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longyan97/EMEye_Tutorial/4f5cf3600e809698a2a94258391ac684427ebac4/TempestSDR_EMEye/TSDRPlugin_Mirics/README -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_Mirics/makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Martin Marinov. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the GNU Public License v3.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.gnu.org/licenses/gpl.html 7 | # 8 | # Contributors: 9 | # Martin Marinov - initial API and implementation 10 | #------------------------------------------------------------------------------- 11 | # This makefile should work for all plugins that reside in the root directory of the repository. 12 | # The header file is copied over from the source 13 | PLUGNAME=TSDRPlugin_Mirics 14 | 15 | # Dependencies 16 | OBJS=$(PLUGNAME).o 17 | DEPS=TSDRPlugin.h TSDRCodes.h 18 | 19 | # Flags 20 | ifeq ($(BUILD_TYPE),Debug) 21 | DEBUGFLAGS+=-g -O0 22 | else 23 | CFLAGS+=-O3 24 | endif 25 | 26 | # Headers 27 | INC += "$(MIRICS_HOME)/API/inc" 28 | 29 | # END OF CONFIGURATION IF STANDARD DIR STRUCTURE IS USED 30 | 31 | # Where the TSDRPlugin.h of the TempestSDR library resides (so it will be copied over) 32 | HEADLOCATION=../TempestSDR/src/include/ 33 | 34 | # Discover the library extension for each OS 35 | ifeq ($(OS),Windows_NT) 36 | 37 | OSNAME ?= WINDOWS 38 | 39 | ifndef $(ARCHNAME) 40 | 41 | ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) 42 | ARCHNAME = X64 43 | endif 44 | ifeq ($(PROCESSOR_ARCHITECTURE),x86) 45 | ARCHNAME = X86 46 | endif 47 | 48 | endif 49 | else 50 | 51 | ifndef $(OSNAME) 52 | 53 | UNAME_S := $(shell uname -s) 54 | ifeq ($(UNAME_S),Linux) 55 | OSNAME = LINUX 56 | endif 57 | 58 | endif 59 | 60 | ifndef $(ARCHNAME) 61 | 62 | UNAME_M := $(shell uname -m) 63 | ifeq ($(UNAME_M),x86_64) 64 | ARCHNAME = X64 65 | endif 66 | ifneq ($(filter %86,$(UNAME_M)),) 67 | ARCHNAME = X86 68 | endif 69 | ifneq ($(filter arm%,$(UNAME_M)),) 70 | ARCHNAME = ARM 71 | endif 72 | 73 | endif 74 | endif 75 | 76 | ifeq ($(OSNAME),WINDOWS) 77 | EXT=.dll 78 | LIBPREFIX= 79 | endif 80 | ifeq ($(OSNAME),LINUX) 81 | EXT=.so 82 | LIBPREFIX=lib 83 | endif 84 | 85 | ifeq ($(ARCHNAME),X86) 86 | COMPILATION_TYPE=-m32 87 | ARCHNAME_LOWER=x86 88 | else ifeq ($(ARCHNAME),X64) 89 | COMPILATION_TYPE=-m64 90 | ARCHNAME_LOWER=x64 91 | endif 92 | 93 | 94 | # If you need a different directory structure. Don't change that unless you really want to. 95 | SOURCEFOLDER=src 96 | OUTPUTFOLDER=bin/$(OSNAME)/$(ARCHNAME) 97 | OBJFOLDER=obj 98 | 99 | # Calculate the path to dependencies 100 | _OBJS = $(patsubst %,$(OBJFOLDER)/%,$(OBJS)) 101 | _DEPS = $(patsubst %,$(SOURCEFOLDER)/%,$(DEPS)) 102 | 103 | # OS specific flags 104 | LDFLAGS+=-Wl,--add-stdcall-alias 105 | 106 | # Generate the library 107 | all : $(OUTPUTFOLDER)/$(PLUGNAME)$(EXT) 108 | 109 | # Copy over a fresh version of the TSDRPlugin.h 110 | copyoverheaderfile: 111 | @cp -f $(HEADLOCATION)/TSDRPlugin.h $(SOURCEFOLDER)/ 112 | @cp -f $(HEADLOCATION)/TSDRCodes.h $(SOURCEFOLDER)/ 113 | 114 | # Link 115 | $(OUTPUTFOLDER)/$(PLUGNAME)$(EXT): copyoverheaderfile $(_OBJS) 116 | $(CC) -Wall -L"$(MIRICS_HOME)/API/$(ARCHNAME_LOWER)/" -lmir_sdr_api $(LDFLAGS) $(DEBUGFLAGS) -shared $(COMPILATION_TYPE) -o $@ $(_OBJS) 117 | 118 | # Make dirs and compile 119 | $(OBJFOLDER)/%.o : $(SOURCEFOLDER)/%.c $(_DEPS) 120 | mkdir -p $(OUTPUTFOLDER) 121 | mkdir -p $(OBJFOLDER) 122 | $(CC) -Wall $(foreach d, $(INC), -I$d) $(CFLAGS) $(DEBUGFLAGS) $(COMPILATION_TYPE) -c $< -o $@ 123 | 124 | .PHONY: clean 125 | 126 | # Clean artifacts 127 | clean : 128 | rm -f $(OBJFOLDER)/*.o $(OUTPUTFOLDER)/*.* $(OUTPUTFOLDER)/$(PLUGNAME)$(EXT) 129 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_Mirics/src/TSDRCodes.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRCodes 14 | #define _TSDRCodes 15 | 16 | #define TSDR_OK (0) 17 | #define TSDR_ERR_PLUGIN (1) 18 | #define TSDR_WRONG_VIDEOPARAMS (2) 19 | #define TSDR_ALREADY_RUNNING (3) 20 | #define TSDR_PLUGIN_PARAMETERS_WRONG (4) 21 | #define TSDR_SAMPLE_RATE_WRONG (5) 22 | #define TSDR_CANNOT_OPEN_DEVICE (6) 23 | #define TSDR_INCOMPATIBLE_PLUGIN (7) 24 | #define TSDR_INVALID_PARAMETER (8) 25 | #define TSDR_INVALID_PARAMETER_VALUE (9) 26 | #define TSDR_NOT_RUNNING (10) 27 | #define TSDR_NOT_IMPLEMENTED (404) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_Mirics/src/TSDRPlugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRPluginHeader 14 | #define _TSDRPluginHeader 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #if _MSC_VER && !__INTEL_COMPILER 21 | #define TSDRPLUGIN_API __declspec(dllexport) 22 | #elif defined _WIN32 || defined __CYGWIN__ 23 | #ifdef __GNUC__ 24 | #define TSDRPLUGIN_API __attribute__ ((dllexport)) 25 | #else 26 | #define TSDRPLUGIN_API __declspec(dllexport) 27 | #endif 28 | #else 29 | #if __GNUC__ >= 4 30 | #define TSDRPLUGIN_API __attribute__ ((visibility ("default"))) 31 | #else 32 | #define TSDRPLUGIN_API 33 | #endif 34 | #endif 35 | 36 | 37 | #ifdef __cplusplus 38 | #define EXTERNC extern "C" 39 | #else 40 | #define EXTERNC 41 | #endif 42 | 43 | #if !(defined(OS_WINDOWS) || defined(_WIN64) || defined(_WIN32) || defined(_MSC_VER) || defined(__stdcall)) 44 | #define __stdcall 45 | #endif 46 | 47 | #include 48 | 49 | typedef void(*tsdrplugin_readasync_function)(float *buf, uint64_t items_count, void *ctx, int64_t samples_dropped); 50 | 51 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_getName(char *); 52 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_init(const char * params); 53 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_setsamplerate(uint32_t rate); 54 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_getsamplerate(); 55 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setbasefreq(uint32_t freq); 56 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_stop(void); 57 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setgain(float gain); 58 | EXTERNC TSDRPLUGIN_API char* __stdcall tsdrplugin_getlasterrortext(void); 59 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx); 60 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_cleanup(void); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_Mirics/src/TSDRPlugin_Mirics.c: -------------------------------------------------------------------------------- 1 | /*#------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Martin Marinov. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the GNU Public License v3.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.gnu.org/licenses/gpl.html 7 | # 8 | # Contributors: 9 | # Martin Marinov - initial API and implementation 10 | #------------------------------------------------------------------------------- */ 11 | #include 12 | #include 13 | 14 | #include "TSDRPlugin.h" 15 | #include "TSDRCodes.h" 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | #define SAMPLE_RATE (8000000) 23 | 24 | volatile int working = 0; 25 | 26 | volatile double desiredfreq = 200; 27 | volatile int desiredgainred = 40; 28 | 29 | #define SAMPLES_TO_PROCESS_AT_ONCE (200) 30 | 31 | int errormsg_code; 32 | char * errormsg; 33 | int errormsg_size = 0; 34 | #define RETURN_EXCEPTION(message, status) {announceexception(message, status); return status;} 35 | #define RETURN_OK() {errormsg_code = TSDR_OK; return TSDR_OK;} 36 | 37 | static inline void announceexception(const char * message, int status) { 38 | errormsg_code = status; 39 | if (status == TSDR_OK) return; 40 | 41 | const int length = strlen(message); 42 | if (errormsg_size == 0) { 43 | errormsg_size = length; 44 | errormsg = (char *) malloc(length+1); 45 | } else if (length > errormsg_size) { 46 | errormsg_size = length; 47 | errormsg = (char *) realloc((void*) errormsg, length+1); 48 | } 49 | strcpy(errormsg, message); 50 | } 51 | 52 | char TSDRPLUGIN_API __stdcall * tsdrplugin_getlasterrortext(void) { 53 | if (errormsg_code == TSDR_OK) 54 | return NULL; 55 | else 56 | return errormsg; 57 | } 58 | 59 | void TSDRPLUGIN_API __stdcall tsdrplugin_getName(char * name) { 60 | strcpy(name, "TSDR Mirics SDR Plugin"); 61 | } 62 | 63 | uint32_t TSDRPLUGIN_API __stdcall tsdrplugin_setsamplerate(uint32_t rate) { 64 | return SAMPLE_RATE; 65 | } 66 | 67 | uint32_t TSDRPLUGIN_API __stdcall tsdrplugin_getsamplerate() { 68 | return SAMPLE_RATE; 69 | } 70 | 71 | int TSDRPLUGIN_API __stdcall tsdrplugin_setbasefreq(uint32_t freq) { 72 | desiredfreq = freq; 73 | RETURN_OK(); 74 | } 75 | 76 | int TSDRPLUGIN_API __stdcall tsdrplugin_stop(void) { 77 | working = 0; 78 | RETURN_OK(); 79 | } 80 | 81 | int TSDRPLUGIN_API __stdcall tsdrplugin_setgain(float gain) { 82 | desiredgainred = 102 - (int) (gain * 102); 83 | if (desiredgainred < 0) desiredgainred = 0; 84 | else if (desiredgainred > 102) desiredgainred = 102; 85 | RETURN_OK(); 86 | } 87 | 88 | int TSDRPLUGIN_API __stdcall tsdrplugin_init(const char * params) { 89 | RETURN_OK(); 90 | } 91 | 92 | int TSDRPLUGIN_API __stdcall tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx) { 93 | working = 1; 94 | 95 | int err, sps, grc, rfc, fsc, i, id; 96 | unsigned int fs; 97 | unsigned int frame = 0; 98 | int inited = 0 ; 99 | 100 | double freq = desiredfreq; 101 | double gainred = desiredgainred; 102 | err = mir_sdr_Init(gainred, 8, freq / 1000000.0, mir_sdr_BW_8_000, mir_sdr_IF_Zero, &sps); 103 | if (err != 0) { 104 | mir_sdr_Uninit(); 105 | RETURN_EXCEPTION("Can't access the Mirics SDR dongle. Make sure it is properly plugged in, drivers are installed and the mir_sdr_api.dll is in the executable's folder and try again. Please, refer to the TSDRPlugin_Miricis readme file for more information.", TSDR_CANNOT_OPEN_DEVICE); 106 | } else 107 | inited = 1; 108 | 109 | short * xi = (short *)malloc(sps * SAMPLES_TO_PROCESS_AT_ONCE * sizeof(short)); 110 | short * xq = (short *)malloc(sps * SAMPLES_TO_PROCESS_AT_ONCE * sizeof(short)); 111 | 112 | int outbufsize = 2 * sps * SAMPLES_TO_PROCESS_AT_ONCE; 113 | float * outbuf = (float *) malloc(sizeof(float) * outbufsize); 114 | 115 | while (working) { 116 | unsigned int dropped = 0; 117 | 118 | for (id = 0; id < SAMPLES_TO_PROCESS_AT_ONCE; id++) { 119 | err = mir_sdr_ReadPacket(&xi[id*sps], &xq[id*sps], &fs, &grc, &rfc, &fsc); 120 | if (fs > frame) 121 | dropped += fs - frame; 122 | // else if (fs < frame) { 123 | // // wrapped around 124 | // dropped += 2147483647 - frame; 125 | // dropped += fs; 126 | // } 127 | frame = fs + sps; 128 | if (err != 0) break; 129 | } 130 | 131 | // if desired frequency is different and valid 132 | if (err == 0 && freq != desiredfreq && !(desiredfreq < 60e6 || (desiredfreq > 245e6 && desiredfreq < 420e6) || desiredfreq > 1000e6)) { 133 | 134 | err = mir_sdr_SetRf(desiredfreq, 1, 0); 135 | if (err == 0) 136 | freq = desiredfreq; // if OK, frequency has been changed 137 | else if (err == mir_sdr_RfUpdateError) { 138 | // if an error occurs, try to reset the device 139 | if (mir_sdr_Uninit() == 0) inited = 0; 140 | gainred = desiredgainred; 141 | if ((err = mir_sdr_Init(gainred, 8, desiredfreq / 1000000.0, mir_sdr_BW_8_000, mir_sdr_IF_Zero, &sps))==0) inited = 1; 142 | if (err == mir_sdr_OutOfRange) { 143 | // if the desired frequency is outside operational range, go back to the working frequency 144 | if (mir_sdr_Uninit() == 0) inited = 0; 145 | if (mir_sdr_Init(gainred, 8, freq / 1000000.0, mir_sdr_BW_8_000, mir_sdr_IF_Zero, &sps) == 0) inited = 1; 146 | desiredfreq = freq; 147 | err = 0; 148 | } else if (err == 0) 149 | freq = desiredfreq; 150 | } else if (err == mir_sdr_OutOfRange) { 151 | mir_sdr_SetRf(freq, 1, 0); 152 | desiredfreq = freq; 153 | err = 0; 154 | } 155 | } 156 | 157 | if (err == 0 && gainred != desiredgainred) { 158 | gainred = desiredgainred; 159 | mir_sdr_SetGr(gainred, 1, 0); 160 | } 161 | 162 | if (err == 0) 163 | for (i = 0; i < outbufsize; i++) { 164 | const short val = (i & 1) ? (xq[i >> 1]) : (xi[i >> 1]); 165 | outbuf[i] = val / 32767.0; 166 | } 167 | 168 | if (err != 0) 169 | { working = 0; break; } 170 | else 171 | cb(outbuf, outbufsize, ctx, dropped); 172 | } 173 | 174 | 175 | 176 | free(outbuf); 177 | free(xi); 178 | free(xq); 179 | 180 | if (inited && mir_sdr_Uninit() != 0) RETURN_EXCEPTION("Cannot properly close the Mirics USB dongle. If you experience any further issues, please disconnect it and reconnect it again.", TSDR_CANNOT_OPEN_DEVICE); 181 | 182 | RETURN_EXCEPTION("The Mirics SDR dongle stopped responding.", (err == 0) ? TSDR_OK : TSDR_ERR_PLUGIN); 183 | } 184 | 185 | void TSDRPLUGIN_API __stdcall tsdrplugin_cleanup(void) { 186 | 187 | } 188 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_RawFile/makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Martin Marinov. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the GNU Public License v3.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.gnu.org/licenses/gpl.html 7 | # 8 | # Contributors: 9 | # Martin Marinov - initial API and implementation 10 | #------------------------------------------------------------------------------- 11 | # This makefile should work for all plugins that reside in the root directory of the repository. 12 | # The header file is copied over from the source 13 | PLUGNAME=TSDRPlugin_RawFile 14 | 15 | # Dependencies 16 | OBJS=$(PLUGNAME).o timer.o 17 | DEPS=TSDRPlugin.h TSDRCodes.h timer.h osdetect.h 18 | 19 | # Flags 20 | ifeq ($(BUILD_TYPE),Debug) 21 | DEBUGFLAGS+=-g -O0 22 | else 23 | CFLAGS+=-O3 24 | endif 25 | 26 | # END OF CONFIGURATION IF STANDARD DIR STRUCTURE IS USED 27 | 28 | # Where the TSDRPlugin.h of the TempestSDR library resides (so it will be copied over) 29 | HEADLOCATION=../TempestSDR/src/include/ 30 | 31 | # Discover the library extension for each OS 32 | ifeq ($(OS),Windows_NT) 33 | 34 | OSNAME ?= WINDOWS 35 | 36 | ifndef $(ARCHNAME) 37 | 38 | ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) 39 | ARCHNAME = X64 40 | endif 41 | ifeq ($(PROCESSOR_ARCHITECTURE),x86) 42 | ARCHNAME = X86 43 | endif 44 | 45 | endif 46 | else ifeq ($(shell uname -s),Darwin) 47 | OSNAME ?= MAC 48 | INC ?= /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers 49 | EXT ?= .so 50 | ifeq ($(shell uname -m),x86) 51 | ARCHNAME = X86 52 | endif 53 | ifeq ($(shell uname -m),x86_64) 54 | ARCHNAME = X64 55 | endif 56 | else 57 | 58 | ifndef $(OSNAME) 59 | 60 | UNAME_S := $(shell uname -s) 61 | ifeq ($(UNAME_S),Linux) 62 | OSNAME = LINUX 63 | endif 64 | 65 | endif 66 | 67 | ifndef $(ARCHNAME) 68 | 69 | UNAME_M := $(shell uname -m) 70 | ifeq ($(UNAME_M),x86_64) 71 | ARCHNAME = X64 72 | endif 73 | ifneq ($(filter %86,$(UNAME_M)),) 74 | ARCHNAME = X86 75 | endif 76 | ifneq ($(filter arm%,$(UNAME_M)),) 77 | ARCHNAME = ARM 78 | endif 79 | 80 | endif 81 | endif 82 | 83 | ifeq ($(OSNAME),WINDOWS) 84 | EXT=.dll 85 | LIBPREFIX= 86 | endif 87 | ifeq ($(OSNAME),LINUX) 88 | EXT=.so 89 | LIBPREFIX=lib 90 | endif 91 | 92 | ifeq ($(ARCHNAME),X86) 93 | COMPILATION_TYPE=-m32 94 | else ifeq ($(ARCHNAME),X64) 95 | COMPILATION_TYPE=-m64 96 | endif 97 | 98 | # If you need a different directory structure. Don't change that unless you really want to. 99 | SOURCEFOLDER=src 100 | OUTPUTFOLDER=bin/$(OSNAME)/$(ARCHNAME) 101 | OBJFOLDER=obj 102 | 103 | # OS specific flags 104 | ifeq ($(OSNAME),LINUX) 105 | CFLAGS+=-fPIC 106 | else ifeq ($(OSNAME),WINDOWS) 107 | LDFLAGS+=-Wl,--add-stdcall-alias 108 | endif 109 | 110 | # Calculate the path to dependencies 111 | _OBJS = $(patsubst %,$(OBJFOLDER)/%,$(OBJS)) 112 | _DEPS = $(patsubst %,$(SOURCEFOLDER)/%,$(DEPS)) 113 | 114 | # Generate the library 115 | all : $(OUTPUTFOLDER)/$(LIBPREFIX)$(PLUGNAME)$(EXT) 116 | 117 | # Copy over a fresh version of the TSDRPlugin.h 118 | copyoverheaderfile: 119 | @cp -f $(HEADLOCATION)/TSDRPlugin.h $(SOURCEFOLDER)/ 120 | @cp -f $(HEADLOCATION)/TSDRCodes.h $(SOURCEFOLDER)/ 121 | 122 | # Link 123 | $(OUTPUTFOLDER)/$(LIBPREFIX)$(PLUGNAME)$(EXT): copyoverheaderfile $(_OBJS) 124 | $(CC) -Wall -shared $(LDFLAGS) $(DEBUGFLAGS) $(COMPILATION_TYPE) -o $@ $(_OBJS) 125 | 126 | # Make dirs and compile 127 | $(OBJFOLDER)/%.o : $(SOURCEFOLDER)/%.c $(_DEPS) 128 | mkdir -p $(OUTPUTFOLDER) 129 | mkdir -p $(OBJFOLDER) 130 | $(CC) -Wall $(foreach d, $(INC), -I$d) $(CFLAGS) $(DEBUGFLAGS) $(COMPILATION_TYPE) -c $< -o $@ 131 | 132 | .PHONY: clean 133 | 134 | # Clean artifacts 135 | clean : 136 | rm -f $(OBJFOLDER)/*.o $(OUTPUTFOLDER)/*.* $(OUTPUTFOLDER)/$(LIBPREFIX)$(PLUGNAME)$(EXT) 137 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_RawFile/src/TSDRCodes.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRCodes 14 | #define _TSDRCodes 15 | 16 | #define TSDR_OK (0) 17 | #define TSDR_ERR_PLUGIN (1) 18 | #define TSDR_WRONG_VIDEOPARAMS (2) 19 | #define TSDR_ALREADY_RUNNING (3) 20 | #define TSDR_PLUGIN_PARAMETERS_WRONG (4) 21 | #define TSDR_SAMPLE_RATE_WRONG (5) 22 | #define TSDR_CANNOT_OPEN_DEVICE (6) 23 | #define TSDR_INCOMPATIBLE_PLUGIN (7) 24 | #define TSDR_INVALID_PARAMETER (8) 25 | #define TSDR_INVALID_PARAMETER_VALUE (9) 26 | #define TSDR_NOT_RUNNING (10) 27 | #define TSDR_NOT_IMPLEMENTED (404) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_RawFile/src/TSDRPlugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRPluginHeader 14 | #define _TSDRPluginHeader 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #if _MSC_VER && !__INTEL_COMPILER 21 | #define TSDRPLUGIN_API __declspec(dllexport) 22 | #elif defined _WIN32 || defined __CYGWIN__ 23 | #ifdef __GNUC__ 24 | #define TSDRPLUGIN_API __attribute__ ((dllexport)) 25 | #else 26 | #define TSDRPLUGIN_API __declspec(dllexport) 27 | #endif 28 | #else 29 | #if __GNUC__ >= 4 30 | #define TSDRPLUGIN_API __attribute__ ((visibility ("default"))) 31 | #else 32 | #define TSDRPLUGIN_API 33 | #endif 34 | #endif 35 | 36 | 37 | #ifdef __cplusplus 38 | #define EXTERNC extern "C" 39 | #else 40 | #define EXTERNC 41 | #endif 42 | 43 | #if !(defined(OS_WINDOWS) || defined(_WIN64) || defined(_WIN32) || defined(_MSC_VER) || defined(__stdcall)) 44 | #define __stdcall 45 | #endif 46 | 47 | #include 48 | 49 | typedef void(*tsdrplugin_readasync_function)(float *buf, uint64_t items_count, void *ctx, int64_t samples_dropped); 50 | 51 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_getName(char *); 52 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_init(const char * params); 53 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_setsamplerate(uint32_t rate); 54 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_getsamplerate(); 55 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setbasefreq(uint32_t freq); 56 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_stop(void); 57 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setgain(float gain); 58 | EXTERNC TSDRPLUGIN_API char* __stdcall tsdrplugin_getlasterrortext(void); 59 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx); 60 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_cleanup(void); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_RawFile/src/osdetect.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifdef OS_WINDOWS 14 | #define WINHEAD (1) 15 | #elif defined(_WIN64) 16 | #define WINHEAD (1) 17 | #elif defined(_WIN32) 18 | #define WINHEAD (1) 19 | #elif defined(_MSC_VER) // Microsoft compiler 20 | #define WINHEAD (1) 21 | #else 22 | #define WINHEAD (0) 23 | #endif 24 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_RawFile/src/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #include "timer.h" 14 | #include 15 | 16 | #if WINHEAD 17 | int gettimeofday(struct timeval *tv, void * ignoreme) 18 | { 19 | FILETIME ft; 20 | unsigned __int64 tmpres = 0; 21 | 22 | if (NULL != tv) 23 | { 24 | GetSystemTimeAsFileTime(&ft); 25 | 26 | tmpres |= ft.dwHighDateTime; 27 | tmpres <<= 32; 28 | tmpres |= ft.dwLowDateTime; 29 | 30 | tmpres /= 10; /*convert into microseconds*/ 31 | /*converting file time to unix epoch*/ 32 | tmpres -= DELTA_EPOCH_IN_MICROSECS; 33 | tv->tv_sec = (long)(tmpres / 1000000UL); 34 | tv->tv_usec = (long)(tmpres % 1000000UL); 35 | } 36 | 37 | return 0; 38 | } 39 | 40 | void timersub(const struct timeval *val1, 41 | const struct timeval *val2, 42 | struct timeval *res) 43 | { 44 | res->tv_sec = val1->tv_sec - val2->tv_sec; 45 | if (val1->tv_usec - val2->tv_usec < 0) { 46 | res->tv_sec--; 47 | res->tv_usec = val1->tv_usec - val2->tv_usec + 1000 * 1000; 48 | } else { 49 | res->tv_usec = val1->tv_usec - val2->tv_usec; 50 | } 51 | } 52 | #endif 53 | 54 | void timer_tick(TickTockTimer_t * timer) { 55 | timer->started = 1; 56 | gettimeofday(&timer->start, NULL); 57 | } 58 | 59 | float timer_tock(TickTockTimer_t * timer) { 60 | struct timeval now; 61 | struct timeval elapsed; 62 | 63 | if (!timer->started) return -1; 64 | 65 | gettimeofday(&now, NULL); 66 | timersub(&now, &timer->start, &elapsed); 67 | 68 | return (float) elapsed.tv_sec + (float) (elapsed.tv_usec) * (float) 1e-6; 69 | } 70 | 71 | float timer_ticktock(TickTockTimer_t * timer) { 72 | struct timeval now; 73 | struct timeval elapsed; 74 | 75 | gettimeofday(&now, NULL); 76 | 77 | if (!timer->started) { 78 | timer->start = now; 79 | timer->started = 1; 80 | } else { 81 | timersub(&now, &timer->start, &elapsed); 82 | timer->start = now; 83 | 84 | return (float) elapsed.tv_sec + (float) (elapsed.tv_usec) * (float) 1e-6; 85 | } 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_RawFile/src/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef TIMR_M_H 14 | #define TIMR_M_H 15 | #include "osdetect.h" 16 | 17 | #if WINHEAD 18 | #include 19 | #include 20 | 21 | #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) 22 | #define DELTA_EPOCH_IN_MICROSECS 116444736000000000Ui64 // CORRECT 23 | #else 24 | #define DELTA_EPOCH_IN_MICROSECS 116444736000000000ULL // CORRECT 25 | #endif 26 | 27 | #else 28 | #include 29 | #endif 30 | 31 | typedef struct TickTockTimer TickTockTimer_t; 32 | 33 | struct TickTockTimer 34 | { 35 | struct timeval start; 36 | int started; 37 | }; 38 | 39 | void timer_tick(TickTockTimer_t * timer); 40 | float timer_tock(TickTockTimer_t * timer); 41 | float timer_ticktock(TickTockTimer_t * timer); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_SdrPlay/README: -------------------------------------------------------------------------------- 1 | This is a driver for SDRplay for Mac. You first need to install the SDR driver from https://www.sdrplay.com/ 2 | 3 | This driver can probably be adopted to work on Linux and Windows. I'm happy to accept pull requests. -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_SdrPlay/makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Martin Marinov. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the GNU Public License v3.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.gnu.org/licenses/gpl.html 7 | # 8 | # Contributors: 9 | # Martin Marinov - initial API and implementation 10 | #------------------------------------------------------------------------------- 11 | # This makefile should work for all plugins that reside in the root directory of the repository. 12 | # The header file is copied over from the source 13 | PLUGNAME=TSDRPlugin_SDRPlay 14 | 15 | # Dependencies 16 | OBJS=$(PLUGNAME).o 17 | DEPS=TSDRPlugin.h TSDRCodes.h 18 | 19 | # Flags 20 | ifeq ($(BUILD_TYPE),Debug) 21 | DEBUGFLAGS+=-g -O0 22 | else 23 | CFLAGS+=-O3 24 | endif 25 | 26 | # END OF CONFIGURATION IF STANDARD DIR STRUCTURE IS USED 27 | 28 | # Where the TSDRPlugin.h of the TempestSDR library resides (so it will be copied over) 29 | HEADLOCATION=../TempestSDR/src/include/ 30 | 31 | # Discover the library extension for each OS 32 | ifeq ($(OS),Windows_NT) 33 | 34 | OSNAME ?= WINDOWS 35 | 36 | ifndef $(ARCHNAME) 37 | 38 | ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) 39 | ARCHNAME = X64 40 | endif 41 | ifeq ($(PROCESSOR_ARCHITECTURE),x86) 42 | ARCHNAME = X86 43 | endif 44 | 45 | endif 46 | else ifeq ($(shell uname -s),Darwin) 47 | OSNAME ?= MAC 48 | INC += /opt/local/include 49 | ifeq ($(shell uname -m),x86) 50 | ARCHNAME = X86 51 | endif 52 | ifeq ($(shell uname -m),x86_64) 53 | ARCHNAME = X64 54 | endif 55 | else 56 | 57 | ifndef $(OSNAME) 58 | 59 | UNAME_S := $(shell uname -s) 60 | ifeq ($(UNAME_S),Linux) 61 | OSNAME = LINUX 62 | endif 63 | 64 | endif 65 | 66 | ifndef $(ARCHNAME) 67 | 68 | UNAME_M := $(shell uname -m) 69 | ifeq ($(UNAME_M),x86_64) 70 | ARCHNAME = X64 71 | endif 72 | ifneq ($(filter %86,$(UNAME_M)),) 73 | ARCHNAME = X86 74 | endif 75 | ifneq ($(filter arm%,$(UNAME_M)),) 76 | ARCHNAME = ARM 77 | endif 78 | 79 | endif 80 | endif 81 | 82 | ifeq ($(ARCHNAME),X86) 83 | COMPILATION_TYPE=-m32 84 | ARCHNAME_LOWER=x86 85 | else ifeq ($(ARCHNAME),X64) 86 | COMPILATION_TYPE=-m64 87 | ARCHNAME_LOWER=x64 88 | endif 89 | 90 | ifeq ($(OSNAME),WINDOWS) 91 | LDFLAGS+=-Wl,--add-stdcall-alias 92 | EXT=.dll 93 | LIBPREFIX= 94 | SDRPLAY_HOME?=C:/PROGRA~1/SDRplay 95 | INC += "$(SDRPLAY_HOME)/API/inc" 96 | LIBRARIES=-L"$(SDRPLAY_HOME)/API/$(ARCHNAME_LOWER)/" -lmir_sdr_api 97 | else ifeq ($(OSNAME),MAC) 98 | EXT ?= .so 99 | CXXFLAGS+=-fPIC 100 | LIBRARIES=-lmirsdrapi-rsp 101 | else ifeq ($(OSNAME),LINUX) 102 | EXT=.so 103 | LIBPREFIX=lib 104 | LIBRARIES=-lmirsdrapi-rsp 105 | endif 106 | 107 | 108 | # If you need a different directory structure. Don't change that unless you really want to. 109 | SOURCEFOLDER=src 110 | OUTPUTFOLDER=bin/$(OSNAME)/$(ARCHNAME) 111 | OBJFOLDER=obj 112 | 113 | # Calculate the path to dependencies 114 | _OBJS = $(patsubst %,$(OBJFOLDER)/%,$(OBJS)) 115 | _DEPS = $(patsubst %,$(SOURCEFOLDER)/%,$(DEPS)) 116 | 117 | # Generate the library 118 | all : $(OUTPUTFOLDER)/$(PLUGNAME)$(EXT) 119 | 120 | # Copy over a fresh version of the TSDRPlugin.h 121 | copyoverheaderfile: 122 | @cp -f $(HEADLOCATION)/TSDRPlugin.h $(SOURCEFOLDER)/ 123 | @cp -f $(HEADLOCATION)/TSDRCodes.h $(SOURCEFOLDER)/ 124 | 125 | # Link 126 | $(OUTPUTFOLDER)/$(PLUGNAME)$(EXT): copyoverheaderfile $(_OBJS) 127 | $(CC) -Wall $(LDFLAGS) $(DEBUGFLAGS) -shared $(COMPILATION_TYPE) -o $@ $(_OBJS) $(LIBRARIES) 128 | 129 | # Make dirs and compile 130 | $(OBJFOLDER)/%.o : $(SOURCEFOLDER)/%.c $(_DEPS) 131 | mkdir -p $(OUTPUTFOLDER) 132 | mkdir -p $(OBJFOLDER) 133 | $(CC) -Wall $(foreach d, $(INC), -I$d) $(CFLAGS) $(DEBUGFLAGS) $(COMPILATION_TYPE) -c $< -o $@ 134 | 135 | .PHONY: clean 136 | 137 | # Clean artifacts 138 | clean : 139 | rm -f $(OBJFOLDER)/*.o $(OUTPUTFOLDER)/*.* $(OUTPUTFOLDER)/$(PLUGNAME)$(EXT) 140 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_SdrPlay/src/TSDRCodes.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRCodes 14 | #define _TSDRCodes 15 | 16 | #define TSDR_OK (0) 17 | #define TSDR_ERR_PLUGIN (1) 18 | #define TSDR_WRONG_VIDEOPARAMS (2) 19 | #define TSDR_ALREADY_RUNNING (3) 20 | #define TSDR_PLUGIN_PARAMETERS_WRONG (4) 21 | #define TSDR_SAMPLE_RATE_WRONG (5) 22 | #define TSDR_CANNOT_OPEN_DEVICE (6) 23 | #define TSDR_INCOMPATIBLE_PLUGIN (7) 24 | #define TSDR_INVALID_PARAMETER (8) 25 | #define TSDR_INVALID_PARAMETER_VALUE (9) 26 | #define TSDR_NOT_RUNNING (10) 27 | #define TSDR_NOT_IMPLEMENTED (404) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_SdrPlay/src/TSDRPlugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRPluginHeader 14 | #define _TSDRPluginHeader 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #if _MSC_VER && !__INTEL_COMPILER 21 | #define TSDRPLUGIN_API __declspec(dllexport) 22 | #elif defined _WIN32 || defined __CYGWIN__ 23 | #ifdef __GNUC__ 24 | #define TSDRPLUGIN_API __attribute__ ((dllexport)) 25 | #else 26 | #define TSDRPLUGIN_API __declspec(dllexport) 27 | #endif 28 | #else 29 | #if __GNUC__ >= 4 30 | #define TSDRPLUGIN_API __attribute__ ((visibility ("default"))) 31 | #else 32 | #define TSDRPLUGIN_API 33 | #endif 34 | #endif 35 | 36 | 37 | #ifdef __cplusplus 38 | #define EXTERNC extern "C" 39 | #else 40 | #define EXTERNC 41 | #endif 42 | 43 | #if !(defined(OS_WINDOWS) || defined(_WIN64) || defined(_WIN32) || defined(_MSC_VER) || defined(__stdcall)) 44 | #define __stdcall 45 | #endif 46 | 47 | #include 48 | 49 | typedef void(*tsdrplugin_readasync_function)(float *buf, uint64_t items_count, void *ctx, int64_t samples_dropped); 50 | 51 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_getName(char *); 52 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_init(const char * params); 53 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_setsamplerate(uint32_t rate); 54 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_getsamplerate(); 55 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setbasefreq(uint32_t freq); 56 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_stop(void); 57 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setgain(float gain); 58 | EXTERNC TSDRPLUGIN_API char* __stdcall tsdrplugin_getlasterrortext(void); 59 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx); 60 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_cleanup(void); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_SdrPlay/src/TSDRPlugin_SDRPlay.c: -------------------------------------------------------------------------------- 1 | /*#------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Martin Marinov. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the GNU Public License v3.0 5 | # which accompanies this distribution, and is available at 6 | # http://wworg/licenses/gpl.html 7 | # 8 | # Contributors: 9 | # Martin Marinov - initial API and implementation 10 | #------------------------------------------------------------------------------- */ 11 | #include 12 | #include 13 | 14 | #include "TSDRPlugin.h" 15 | #include "TSDRCodes.h" 16 | 17 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__CYGWIN__) 18 | #include 19 | #include "mir_sdr.h" 20 | #else 21 | #include 22 | #endif 23 | 24 | #include 25 | #include 26 | 27 | #define SAMPLE_RATE (8000000) 28 | 29 | volatile int working = 0; 30 | 31 | volatile double desiredfreq = 200; 32 | volatile int desiredgainred = 40; 33 | 34 | #define SAMPLES_TO_PROCESS_AT_ONCE (200) 35 | 36 | int errormsg_code; 37 | char * errormsg; 38 | int errormsg_size = 0; 39 | #define RETURN_EXCEPTION(message, status) {announceexception(message, status); return status;} 40 | #define RETURN_OK() {errormsg_code = TSDR_OK; return TSDR_OK;} 41 | 42 | static inline void announceexception(const char * message, int status) { 43 | errormsg_code = status; 44 | if (status == TSDR_OK) return; 45 | 46 | const int length = strlen(message); 47 | if (errormsg_size == 0) { 48 | errormsg_size = length; 49 | errormsg = (char *) malloc(length+1); 50 | } else if (length > errormsg_size) { 51 | errormsg_size = length; 52 | errormsg = (char *) realloc((void*) errormsg, length+1); 53 | } 54 | strcpy(errormsg, message); 55 | } 56 | 57 | char TSDRPLUGIN_API __stdcall * tsdrplugin_getlasterrortext(void) { 58 | if (errormsg_code == TSDR_OK) 59 | return NULL; 60 | else 61 | return errormsg; 62 | } 63 | 64 | void TSDRPLUGIN_API __stdcall tsdrplugin_getName(char * name) { 65 | strcpy(name, "TSDR SDRplay SDR Plugin"); 66 | } 67 | 68 | uint32_t TSDRPLUGIN_API __stdcall tsdrplugin_setsamplerate(uint32_t rate) { 69 | return SAMPLE_RATE; 70 | } 71 | 72 | uint32_t TSDRPLUGIN_API __stdcall tsdrplugin_getsamplerate() { 73 | return SAMPLE_RATE; 74 | } 75 | 76 | int TSDRPLUGIN_API __stdcall tsdrplugin_setbasefreq(uint32_t freq) { 77 | desiredfreq = freq; 78 | RETURN_OK(); 79 | } 80 | 81 | int TSDRPLUGIN_API __stdcall tsdrplugin_stop(void) { 82 | working = 0; 83 | RETURN_OK(); 84 | } 85 | 86 | int TSDRPLUGIN_API __stdcall tsdrplugin_setgain(float gain) { 87 | desiredgainred = 20 + (int) ((1.0f - gain) * (59-20)); 88 | if (desiredgainred < 20) desiredgainred = 20; 89 | else if (desiredgainred > 59) desiredgainred = 59; 90 | RETURN_OK(); 91 | } 92 | 93 | int TSDRPLUGIN_API __stdcall tsdrplugin_init(const char * params) { 94 | RETURN_OK(); 95 | } 96 | 97 | int TSDRPLUGIN_API __stdcall tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx) { 98 | working = 1; 99 | 100 | int err, sps, grc, rfc, fsc, i, id; 101 | unsigned int fs; 102 | unsigned int frame = 0; 103 | int inited = 0 ; 104 | 105 | double freq = desiredfreq; 106 | double gainred = desiredgainred; 107 | 108 | mir_sdr_DeviceT devices[1]; 109 | unsigned int num_devices = 0; 110 | // Seems the API requires enlisting devices first, otherwise throws libusb error on Mac 111 | mir_sdr_GetDevices(devices, &num_devices, 1); 112 | if (num_devices == 0) { 113 | RETURN_EXCEPTION("No devices found", TSDR_CANNOT_OPEN_DEVICE); 114 | } 115 | 116 | mir_sdr_RSPII_AntennaControl(mir_sdr_RSPII_ANTENNA_A); 117 | mir_sdr_AgcControl(1, -30, 0, 0, 0, 0, 1); 118 | err = mir_sdr_Init(gainred, 8, freq / 1000000.0, mir_sdr_BW_8_000, mir_sdr_IF_Zero, &sps); 119 | if (err != mir_sdr_Success) { 120 | mir_sdr_Uninit(); 121 | RETURN_EXCEPTION( 122 | "Can't access the SDRplay RSP. Make sure it is properly plugged in, drivers are installed and the mir_sdr_api.dll is in the executable's folder and try again. Please, refer to the TSDRPlugin_SDRplay readme file for more information.", 123 | TSDR_CANNOT_OPEN_DEVICE); 124 | } else 125 | inited = 1; 126 | 127 | short * xi = (short *)malloc(sps * SAMPLES_TO_PROCESS_AT_ONCE * sizeof(short)); 128 | short * xq = (short *)malloc(sps * SAMPLES_TO_PROCESS_AT_ONCE * sizeof(short)); 129 | 130 | int outbufsize = 2 * sps * SAMPLES_TO_PROCESS_AT_ONCE; 131 | float * outbuf = (float *) malloc(sizeof(float) * outbufsize); 132 | 133 | while (working) { 134 | unsigned int dropped = 0; 135 | 136 | for (id = 0; id < SAMPLES_TO_PROCESS_AT_ONCE; id++) { 137 | err = mir_sdr_ReadPacket(&xi[id*sps], &xq[id*sps], &fs, &grc, &rfc, &fsc); 138 | if (fs > frame) 139 | dropped += fs - frame; 140 | // else if (fs < frame) { 141 | // // wrapped around 142 | // dropped += 2147483647 - frame; 143 | // dropped += fs; 144 | // } 145 | frame = fs + sps; 146 | if (err != 0) break; 147 | } 148 | 149 | // if desired frequency is different and valid 150 | if (err == 0 && freq != desiredfreq && !(desiredfreq < 60e6 || (desiredfreq > 245e6 && desiredfreq < 420e6) || desiredfreq > 1000e6)) { 151 | 152 | err = mir_sdr_SetRf(desiredfreq, 1, 0); 153 | if (err == 0) 154 | freq = desiredfreq; // if OK, frequency has been changed 155 | else if (err == mir_sdr_RfUpdateError) { 156 | // if an error occurs, try to reset the device 157 | if (mir_sdr_Uninit() == 0) inited = 0; 158 | gainred = desiredgainred; 159 | if ((err = mir_sdr_Init(gainred, 8, desiredfreq / 1000000.0, mir_sdr_BW_8_000, mir_sdr_IF_Zero, &sps))==0) inited = 1; 160 | if (err == mir_sdr_OutOfRange) { 161 | // if the desired frequency is outside operational range, go back to the working frequency 162 | if (mir_sdr_Uninit() == 0) inited = 0; 163 | if (mir_sdr_Init(gainred, 8, freq / 1000000.0, mir_sdr_BW_8_000, mir_sdr_IF_Zero, &sps) == 0) inited = 1; 164 | desiredfreq = freq; 165 | err = 0; 166 | } else if (err == 0) 167 | freq = desiredfreq; 168 | } else if (err == mir_sdr_OutOfRange) { 169 | mir_sdr_SetRf(freq, 1, 0); 170 | desiredfreq = freq; 171 | err = 0; 172 | } 173 | } 174 | 175 | if (err == 0 && gainred != desiredgainred) { 176 | gainred = desiredgainred; 177 | mir_sdr_RSP_SetGr(gainred, 3, 1, 0); 178 | } 179 | 180 | if (err == 0) 181 | for (i = 0; i < outbufsize; i++) { 182 | const short val = (i & 1) ? (xq[i >> 1]) : (xi[i >> 1]); 183 | outbuf[i] = val / 32767.0; 184 | } 185 | 186 | if (err != 0) 187 | { working = 0; break; } 188 | else 189 | cb(outbuf, outbufsize, ctx, dropped); 190 | } 191 | 192 | 193 | 194 | free(outbuf); 195 | free(xi); 196 | free(xq); 197 | 198 | if (inited && mir_sdr_Uninit() != 0) RETURN_EXCEPTION("Cannot properly close the SDRplay RSP. If you experience any further issues, please disconnect it and reconnect it again.", TSDR_CANNOT_OPEN_DEVICE); 199 | 200 | RETURN_EXCEPTION("SDRplay RSP dongle stopped responding.", (err == 0) ? TSDR_OK : TSDR_ERR_PLUGIN); 201 | } 202 | 203 | void TSDRPLUGIN_API __stdcall tsdrplugin_cleanup(void) { 204 | 205 | } 206 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_UHD/README: -------------------------------------------------------------------------------- 1 | This is a plugin that supports the UHD driver for the USRP devices. In order to compile it, you need to have UHD installed and the corresponding boost libraries. 2 | 3 | Compile it with 4 | 5 | make all 6 | 7 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_UHD/TSDRPlugin_UHD.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {5A538540-1924-475D-9F0A-B546D915A56C} 15 | Win32Proj 16 | TSDRPlugin_UHD 17 | 18 | 19 | 20 | DynamicLibrary 21 | false 22 | v110 23 | MultiByte 24 | 25 | 26 | DynamicLibrary 27 | false 28 | v110 29 | true 30 | MultiByte 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | bin\WINDOWS\X86\ 45 | obj\ 46 | 47 | 48 | false 49 | bin\WINDOWS\X86\ 50 | obj\ 51 | 52 | 53 | 54 | Level3 55 | NotUsing 56 | Disabled 57 | WIN32;NDEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;TSDRPLUGIN_UHD_EXPORTS;%(PreprocessorDefinitions) 58 | $(BOOST_INCLUDE);$(UHD_INCLUDE) 59 | 60 | 61 | Windows 62 | true 63 | $(ProjectDir)\dependencies\WINDOWS\X86\ 64 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;ws2_32.lib;uhd.lib 65 | src\exports.def 66 | 67 | 68 | 69 | 70 | Level3 71 | NotUsing 72 | MaxSpeed 73 | WIN32;NDEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;TSDRPLUGIN_UHD_EXPORTS;%(PreprocessorDefinitions) 74 | $(BOOST_INCLUDE);$(UHD_INCLUDE) 75 | 76 | 77 | Windows 78 | false 79 | $(ProjectDir)\dependencies\WINDOWS\X86\ 80 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;ws2_32.lib;uhd.lib 81 | src\exports.def 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_UHD/makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Martin Marinov. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the GNU Public License v3.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.gnu.org/licenses/gpl.html 7 | # 8 | # Contributors: 9 | # Martin Marinov - initial API and implementation 10 | #------------------------------------------------------------------------------- 11 | # This makefile should work for all plugins that reside in the root directory of the repository. 12 | # The header file is copied over from the source 13 | PLUGNAME=TSDRPlugin_UHD 14 | 15 | # Dependencies 16 | OBJS=$(PLUGNAME).o 17 | 18 | # Flags 19 | ifeq ($(BUILD_TYPE),Debug) 20 | DEBUGFLAGS+=-g -O0 21 | else 22 | CFLAGS+=-O3 23 | endif 24 | 25 | #for statically compiling 26 | #INC+=-I"$(BOOST_ROOT)/include" -I"$(UHD_ROOT)/include" 27 | 28 | # END OF CONFIGURATION IF STANDARD DIR STRUCTURE IS USED 29 | 30 | # Compile with g++ 31 | GPP?=g++ 32 | 33 | # Where the TSDRPlugin.h of the TempestSDR library resides (so it will be copied over) 34 | HEADLOCATION=../TempestSDR/src/include/ 35 | 36 | # Discover the library extension for each OS 37 | ifeq ($(OS),Windows_NT) 38 | 39 | OSNAME ?= WINDOWS 40 | 41 | ifndef $(ARCHNAME) 42 | 43 | ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) 44 | ARCHNAME = X64 45 | endif 46 | ifeq ($(PROCESSOR_ARCHITECTURE),x86) 47 | ARCHNAME = X86 48 | endif 49 | 50 | endif 51 | else ifeq ($(shell uname -s),Darwin) 52 | OSNAME ?= MAC 53 | EXT ?= .so 54 | INC += /opt/local/include 55 | ifeq ($(shell uname -m),x86) 56 | ARCHNAME = X86 57 | endif 58 | ifeq ($(shell uname -m),x86_64) 59 | ARCHNAME = X64 60 | endif 61 | else 62 | 63 | ifndef $(OSNAME) 64 | 65 | UNAME_S := $(shell uname -s) 66 | ifeq ($(UNAME_S),Linux) 67 | OSNAME = LINUX 68 | endif 69 | 70 | endif 71 | 72 | ifndef $(ARCHNAME) 73 | 74 | UNAME_M := $(shell uname -m) 75 | ifeq ($(UNAME_M),x86_64) 76 | ARCHNAME = X64 77 | endif 78 | ifneq ($(filter %86,$(UNAME_M)),) 79 | ARCHNAME = X86 80 | endif 81 | ifneq ($(filter arm%,$(UNAME_M)),) 82 | ARCHNAME = ARM 83 | endif 84 | 85 | endif 86 | endif 87 | 88 | ifeq ($(OSNAME),WINDOWS) 89 | EXT=.dll 90 | LIBPREFIX= 91 | endif 92 | ifeq ($(OSNAME),LINUX) 93 | EXT=.so 94 | LIBPREFIX=lib 95 | endif 96 | 97 | ifeq ($(ARCHNAME),X86) 98 | COMPILATION_TYPE=-m32 99 | else ifeq ($(ARCHNAME),X64) 100 | COMPILATION_TYPE=-m64 101 | endif 102 | 103 | # If you need a different directory structure. Don't change that unless you really want to. 104 | SOURCEFOLDER=src 105 | OUTPUTFOLDER=bin/$(OSNAME)/$(ARCHNAME) 106 | OBJFOLDER=obj 107 | 108 | # OS specific flags 109 | ifeq ($(OSNAME),LINUX) 110 | CXXFLAGS+=-fPIC 111 | # static version of the libraries if compiled LIBRARIES+=-Ldependencies/$(OSNAME)/$(ARCHNAME) -lpthread -lboost_system -lboost_thread -lboost_program_options -lboost_unit_test_framework -luhd -lboost_serialization -lboost_filesystem -lboost_date_time -lboost_regex -lrt 112 | LIBRARIES+=-lboost_thread -lboost_program_options -luhd 113 | else ifeq ($(OSNAME),MAC) 114 | CXXFLAGS+=-fPIC 115 | LIBRARIES+=-L/opt/local/lib -lboost_thread-mt -lboost_program_options-mt -lboost_system-mt -luhd 116 | else ifeq ($(OSNAME),WINDOWS) 117 | LDFLAGS+=-Wl,--add-stdcall-alias 118 | LIBRARIES+= -lboost_thread-mt -lboost_program_options-mt -lboost_system-mt -luhd 119 | endif 120 | 121 | # Calculate the path to dependencies 122 | ifneq ($(OSNAME),WINDOWS) 123 | _OBJS = $(patsubst %,$(OBJFOLDER)/%,$(OBJS)) 124 | endif 125 | _DEPS = $(patsubst %,$(SOURCEFOLDER)/%,$(DEPS)) 126 | 127 | 128 | # Generate the library 129 | all : $(OUTPUTFOLDER)/$(LIBPREFIX)$(PLUGNAME)$(EXT) 130 | 131 | # Copy over a fresh version of the TSDRPlugin.h 132 | copyoverheaderfile: 133 | @cp -f $(HEADLOCATION)/TSDRPlugin.h $(SOURCEFOLDER)/ 134 | @cp -f $(HEADLOCATION)/TSDRCodes.h $(SOURCEFOLDER)/ 135 | 136 | # Link 137 | $(OUTPUTFOLDER)/$(LIBPREFIX)$(PLUGNAME)$(EXT): copyoverheaderfile $(_OBJS) 138 | ifeq ($(OSNAME),WINDOWS) 139 | 140 | ifeq ($(ARCHNAME),X86) 141 | msbuild.exe TSDRPlugin_UHD.vcxproj //p:Configuration=Release;Platform=Win32;msbuildemitsolution=1 142 | else ifeq ($(ARCHNAME),X64) 143 | msbuild.exe TSDRPlugin_UHD.vcxproj //p:Configuration=Release;Platform=Win64;msbuildemitsolution=1 144 | endif 145 | 146 | else 147 | $(GPP) -shared $(LDFLAGS) $(DEBUGFLAGS) $(COMPILATION_TYPE) -o $@ $(_OBJS) $(LIBRARIES) 148 | endif 149 | 150 | # Make dirs and compile 151 | $(OBJFOLDER)/%.o : $(SOURCEFOLDER)/%.cpp 152 | mkdir -p $(OUTPUTFOLDER) 153 | mkdir -p $(OBJFOLDER) 154 | $(GPP) $(foreach d, $(INC), -I$d) $(CXXFLAGS) $(DEBUGFLAGS) $(COMPILATION_TYPE) -c $< -o $@ 155 | 156 | .PHONY: clean 157 | 158 | # Clean artifacts 159 | clean : 160 | rm -rf $(OBJFOLDER) 161 | rm -f $(OUTPUTFOLDER)/*.* $(OUTPUTFOLDER)/$(LIBPREFIX)$(PLUGNAME)$(EXT) 162 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_UHD/src/TSDRCodes.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRCodes 14 | #define _TSDRCodes 15 | 16 | #define TSDR_OK (0) 17 | #define TSDR_ERR_PLUGIN (1) 18 | #define TSDR_WRONG_VIDEOPARAMS (2) 19 | #define TSDR_ALREADY_RUNNING (3) 20 | #define TSDR_PLUGIN_PARAMETERS_WRONG (4) 21 | #define TSDR_SAMPLE_RATE_WRONG (5) 22 | #define TSDR_CANNOT_OPEN_DEVICE (6) 23 | #define TSDR_INCOMPATIBLE_PLUGIN (7) 24 | #define TSDR_INVALID_PARAMETER (8) 25 | #define TSDR_INVALID_PARAMETER_VALUE (9) 26 | #define TSDR_NOT_RUNNING (10) 27 | #define TSDR_NOT_IMPLEMENTED (404) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_UHD/src/TSDRPlugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRPluginHeader 14 | #define _TSDRPluginHeader 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #if _MSC_VER && !__INTEL_COMPILER 21 | #define TSDRPLUGIN_API __declspec(dllexport) 22 | #elif defined _WIN32 || defined __CYGWIN__ 23 | #ifdef __GNUC__ 24 | #define TSDRPLUGIN_API __attribute__ ((dllexport)) 25 | #else 26 | #define TSDRPLUGIN_API __declspec(dllexport) 27 | #endif 28 | #else 29 | #if __GNUC__ >= 4 30 | #define TSDRPLUGIN_API __attribute__ ((visibility ("default"))) 31 | #else 32 | #define TSDRPLUGIN_API 33 | #endif 34 | #endif 35 | 36 | 37 | #ifdef __cplusplus 38 | #define EXTERNC extern "C" 39 | #else 40 | #define EXTERNC 41 | #endif 42 | 43 | #if !(defined(OS_WINDOWS) || defined(_WIN64) || defined(_WIN32) || defined(_MSC_VER) || defined(__stdcall)) 44 | #define __stdcall 45 | #endif 46 | 47 | #include 48 | 49 | typedef void(*tsdrplugin_readasync_function)(float *buf, uint64_t items_count, void *ctx, int64_t samples_dropped); 50 | 51 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_getName(char *); 52 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_init(const char * params); 53 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_setsamplerate(uint32_t rate); 54 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_getsamplerate(); 55 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setbasefreq(uint32_t freq); 56 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_stop(void); 57 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setgain(float gain); 58 | EXTERNC TSDRPLUGIN_API char* __stdcall tsdrplugin_getlasterrortext(void); 59 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx); 60 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_cleanup(void); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_UHD/src/errors.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef ERRORS_H_ 14 | #define ERRORS_H_ 15 | 16 | #include "TSDRCodes.h" 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | 22 | int errormsg_code; 23 | char * errormsg = NULL; 24 | int errormsg_size = 0; 25 | #define RETURN_EXCEPTION(message, status) {announceexception(message, status); return status;} 26 | #define RETURN_OK() {errormsg_code = TSDR_OK; return TSDR_OK;} 27 | 28 | static inline void announceexception(const char * message, int status) { 29 | 30 | errormsg_code = status; 31 | if (status == TSDR_OK) return; 32 | 33 | const int length = strlen(message); 34 | if (errormsg_size == 0) { 35 | errormsg_size = length; 36 | errormsg = (char *)malloc(errormsg_size + 1); 37 | errormsg[errormsg_size] = 0; 38 | } 39 | else if (length > errormsg_size) { 40 | errormsg_size = length; 41 | errormsg = (char *)realloc((void*)errormsg, errormsg_size + 1); 42 | errormsg[errormsg_size] = 0; 43 | } 44 | 45 | 46 | strcpy(errormsg, message); 47 | } 48 | 49 | } 50 | 51 | EXTERNC TSDRPLUGIN_API char * __stdcall tsdrplugin_getlasterrortext(void) { 52 | if (errormsg_code == TSDR_OK) 53 | return NULL; 54 | else 55 | return errormsg; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TSDRPlugin_UHD/src/exports.def: -------------------------------------------------------------------------------- 1 | LIBRARY TSDRPlugin_UHD 2 | EXPORTS 3 | tsdrplugin_getName = _tsdrplugin_getName@4 4 | tsdrplugin_init = _tsdrplugin_init@4 5 | tsdrplugin_setsamplerate = _tsdrplugin_setsamplerate@4 6 | tsdrplugin_getsamplerate = _tsdrplugin_getsamplerate@0 7 | tsdrplugin_setbasefreq = _tsdrplugin_setbasefreq@4 8 | tsdrplugin_stop = _tsdrplugin_stop@0 9 | tsdrplugin_setgain = _tsdrplugin_setgain@4 10 | tsdrplugin_getlasterrortext = _tsdrplugin_getlasterrortext@0 11 | tsdrplugin_readasync = _tsdrplugin_readasync@8 12 | tsdrplugin_cleanup = _tsdrplugin_cleanup@0 -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Martin Marinov. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the GNU Public License v3.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.gnu.org/licenses/gpl.html 7 | # 8 | # Contributors: 9 | # Martin Marinov - initial API and implementation 10 | #------------------------------------------------------------------------------- 11 | # Define all of the C files here 12 | OBJS = TSDRLibrary.o TSDRPluginLoader.o threading.o circbuff.o syncdetector.o frameratedetector.o gaussian.o extbuffer.o superbandwidth.o fft.o dsp.o 13 | 14 | # Define all of the dependencies here 15 | DEPS = include/TSDRLibrary.h TSDRPluginLoader.h include/TSDRPlugin.h osdetect.h threading.h circbuff.h syncdetector.h internaldefinitions.h frameratedetector.h extbuffer.h gaussian.h 16 | 17 | # Flags 18 | ifeq ($(BUILD_TYPE),Debug) 19 | DEBUGFLAGS+=-g -O0 20 | else 21 | CFLAGS+=-O3 22 | endif 23 | 24 | # USER CONFIGURATION ENDS HERE 25 | 26 | 27 | # Discover the library extension for each OS 28 | ifeq ($(OS),Windows_NT) 29 | 30 | OSNAME ?= WINDOWS 31 | 32 | ifndef $(ARCHNAME) 33 | 34 | ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) 35 | ARCHNAME = X64 36 | endif 37 | ifeq ($(PROCESSOR_ARCHITECTURE),x86) 38 | ARCHNAME = X86 39 | endif 40 | 41 | endif 42 | else ifeq ($(shell uname -s),Darwin) 43 | OSNAME ?= MAC 44 | INC ?= /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers 45 | EXT ?= .so 46 | ifeq ($(shell uname -m),x86) 47 | ARCHNAME = X86 48 | endif 49 | ifeq ($(shell uname -m),x86_64) 50 | ARCHNAME = X64 51 | endif 52 | else 53 | 54 | ifndef $(OSNAME) 55 | 56 | UNAME_S := $(shell uname -s) 57 | ifeq ($(UNAME_S),Linux) 58 | OSNAME = LINUX 59 | endif 60 | 61 | endif 62 | 63 | ifndef $(ARCHNAME) 64 | 65 | UNAME_M := $(shell uname -m) 66 | ifeq ($(UNAME_M),x86_64) 67 | ARCHNAME = X64 68 | endif 69 | ifneq ($(filter %86,$(UNAME_M)),) 70 | ARCHNAME = X86 71 | endif 72 | ifneq ($(filter arm%,$(UNAME_M)),) 73 | ARCHNAME = ARM 74 | endif 75 | 76 | endif 77 | endif 78 | 79 | ifeq ($(OSNAME),WINDOWS) 80 | EXT=.dll 81 | LIBPREFIX= 82 | endif 83 | ifeq ($(OSNAME),LINUX) 84 | EXT=.so 85 | LIBPREFIX=lib 86 | endif 87 | 88 | ifeq ($(ARCHNAME),X86) 89 | COMPILATION_TYPE=-m32 90 | else ifeq ($(ARCHNAME),X64) 91 | COMPILATION_TYPE=-m64 92 | endif 93 | 94 | AR?=ar 95 | 96 | # If you need a different directory structure. Don't change that unless you really want to. 97 | SOURCEFOLDER=src 98 | OUTPUTFOLDER=bin/$(OSNAME)/$(ARCHNAME) 99 | OBJFOLDER=obj 100 | 101 | # OS specific flags 102 | ifeq ($(OSNAME),LINUX) 103 | CFLAGS+=-fPIC 104 | else ifeq ($(OSNAME),WINDOWS) 105 | LDFLAGS+=-Wl,--add-stdcall-alias 106 | CFLAGS+=-fPIC 107 | endif 108 | 109 | # The obj files reside in the bin/obj directory 110 | _OBJS = $(patsubst %,$(OBJFOLDER)/%,$(OBJS)) 111 | 112 | # The header files are relative to the source directory 113 | _DEPS = $(patsubst %,$(SOURCEFOLDER)/%,$(DEPS)) 114 | 115 | # Build library 116 | all : $(OUTPUTFOLDER)/$(LIBPREFIX)TSDRLibrary$(EXT) 117 | 118 | # Link 119 | $(OUTPUTFOLDER)/$(LIBPREFIX)TSDRLibrary$(EXT) : $(_OBJS) 120 | $(CC) -Wall -shared $(LDFLAGS) $(DEBUGFLAGS) $(COMPILATION_TYPE) -o $@ $(_OBJS) 121 | $(AR) rcs $(OUTPUTFOLDER)/$(LIBPREFIX)TSDRLibrary.a $(_OBJS) 122 | 123 | # Create folders if needed and compile 124 | $(OBJFOLDER)/%.o : src/%.c $(_DEPS) 125 | mkdir -p $(OUTPUTFOLDER) 126 | mkdir -p $(OBJFOLDER) 127 | $(CC) -Wall $(foreach d, $(INC), -I$d) $(CFLAGS) $(DEBUGFLAGS) $(COMPILATION_TYPE) -c $< -o $@ 128 | 129 | .PHONY: clean 130 | 131 | # Clean artifacts 132 | clean : 133 | rm -f $(OBJFOLDER)/*.o $(OUTPUTFOLDER)/*.* $(OUTPUTFOLDER)/$(LIBPREFIX)TSDRLibrary$(EXT) $(OUTPUTFOLDER)/$(LIBPREFIX)TSDRLibrary.a 134 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/TSDRPluginLoader.c: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | 14 | #include "TSDRPluginLoader.h" 15 | #include "include/TSDRLibrary.h" 16 | #include "include/TSDRCodes.h" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | // A platform independent dynamic library loader 23 | 24 | void *tsdrplug_getfunction(pluginsource_t * plugin, char *functname) 25 | { 26 | #if WINHEAD 27 | return (void*)GetProcAddress((HINSTANCE)plugin->fd,functname); 28 | #else 29 | return dlsym(plugin->fd,functname); 30 | #endif 31 | } 32 | 33 | int tsdrplug_load(pluginsource_t * plugin, const char *dlname) 34 | { 35 | plugin->tsdrplugin_cleanup = NULL; 36 | 37 | #if WINHEAD // Microsoft compiler 38 | plugin->fd = (void*)LoadLibrary(dlname); 39 | 40 | if (plugin->fd == NULL) { 41 | char err_str[512]; 42 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 43 | NULL, GetLastError(), 44 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 45 | err_str, 512, NULL); 46 | fprintf(stderr,"Library %s load exception: %s\n", dlname, err_str); 47 | } 48 | #else 49 | plugin->fd = dlopen(dlname,RTLD_NOW); 50 | if (plugin->fd == NULL) 51 | fprintf(stderr,"Library %s load exception: %s\n", dlname, dlerror()); 52 | #endif 53 | 54 | if (plugin->fd == NULL) 55 | return TSDR_INCOMPATIBLE_PLUGIN; 56 | 57 | if ((plugin->tsdrplugin_init = tsdrplug_getfunction(plugin, "tsdrplugin_init")) == 0) return TSDR_ERR_PLUGIN; 58 | if ((plugin->tsdrplugin_getsamplerate = tsdrplug_getfunction(plugin, "tsdrplugin_getsamplerate")) == 0) return TSDR_ERR_PLUGIN; 59 | if ((plugin->tsdrplugin_getName = tsdrplug_getfunction(plugin, "tsdrplugin_getName")) == 0) return TSDR_ERR_PLUGIN; 60 | if ((plugin->tsdrplugin_setsamplerate = tsdrplug_getfunction(plugin, "tsdrplugin_setsamplerate")) == 0) return TSDR_ERR_PLUGIN; 61 | if ((plugin->tsdrplugin_setbasefreq = tsdrplug_getfunction(plugin, "tsdrplugin_setbasefreq")) == 0) return TSDR_ERR_PLUGIN; 62 | if ((plugin->tsdrplugin_stop = tsdrplug_getfunction(plugin, "tsdrplugin_stop")) == 0) return TSDR_ERR_PLUGIN; 63 | if ((plugin->tsdrplugin_setgain = tsdrplug_getfunction(plugin, "tsdrplugin_setgain")) == 0) return TSDR_ERR_PLUGIN; 64 | if ((plugin->tsdrplugin_readasync = tsdrplug_getfunction(plugin, "tsdrplugin_readasync")) == 0) return TSDR_ERR_PLUGIN; 65 | if ((plugin->tsdrplugin_getlasterrortext = tsdrplug_getfunction(plugin, "tsdrplugin_getlasterrortext")) == 0) return TSDR_ERR_PLUGIN; 66 | 67 | // this needs to be always last! 68 | if ((plugin->tsdrplugin_cleanup = tsdrplug_getfunction(plugin, "tsdrplugin_cleanup")) == 0) return TSDR_ERR_PLUGIN; 69 | 70 | plugin->initialized = 1; 71 | return TSDR_OK; 72 | } 73 | 74 | 75 | void tsdrplug_close(pluginsource_t * plugin) 76 | { 77 | if (!plugin->initialized) return; 78 | if (plugin->fd == NULL) return; 79 | if (plugin->tsdrplugin_cleanup != NULL) plugin->tsdrplugin_cleanup(); // cleanup before closing 80 | plugin->initialized = 0; 81 | #if WINHEAD 82 | FreeLibrary((HINSTANCE)plugin->fd); 83 | #else 84 | dlclose(plugin->fd); 85 | #endif 86 | 87 | } 88 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/TSDRPluginLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRPluginLoader 14 | #define _TSDRPluginLoader 15 | 16 | // A platform independed dynamic library loader 17 | 18 | #include 19 | #include "osdetect.h" 20 | #include "include/TSDRPlugin.h" 21 | 22 | #if WINHEAD 23 | #include 24 | #else 25 | #include 26 | #endif 27 | 28 | struct pluginsource { 29 | void * fd; 30 | int (__stdcall *tsdrplugin_init)(const char * params); 31 | void (__stdcall *tsdrplugin_getName)(char *); 32 | uint32_t (__stdcall *tsdrplugin_setsamplerate)(uint32_t); 33 | uint32_t (__stdcall *tsdrplugin_getsamplerate)(void); 34 | int (__stdcall *tsdrplugin_setbasefreq)(uint32_t); 35 | int (__stdcall *tsdrplugin_stop)(void); 36 | int (__stdcall *tsdrplugin_setgain)(float); 37 | int (__stdcall *tsdrplugin_readasync)(tsdrplugin_readasync_function, void *); 38 | char * (__stdcall *tsdrplugin_getlasterrortext) (void); 39 | void * (__stdcall *tsdrplugin_cleanup) (void); 40 | volatile int initialized; 41 | 42 | } typedef pluginsource_t; 43 | 44 | int tsdrplug_load(pluginsource_t * plugin, const char * dlname); 45 | void tsdrplug_close(pluginsource_t * plugin); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/circbuff.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _Circubuffer 14 | #define _Circubuffer 15 | 16 | #include 17 | #include 18 | #include 19 | #include "threading.h" 20 | 21 | typedef struct CircBuff CircBuff_t; 22 | 23 | #define CB_OK (1) 24 | #define CB_FULL (0) 25 | #define CB_EMPTY (0) 26 | #define CB_ERROR (0) 27 | 28 | #define CB_SIZE_MAX_COEFF_LOW_LATENCY (5) 29 | #define CB_SIZE_MAX_COEFF_MED_LATENCY (10) 30 | #define CB_SIZE_MAX_COEFF_HIGH_LATENCY (20) 31 | 32 | struct CircBuff 33 | { 34 | volatile float * buffer; // the circular buffer itself 35 | volatile size_t buffer_size; // the size of the circular buffer 36 | volatile size_t desired_buf_size; // the size of the buffer that we want it to become 37 | 38 | volatile size_t remaining_capacity; // the available capacity. I.e. how many free elements are there in the buffer 39 | volatile size_t pos; // the position where the next element will be inserted 40 | volatile size_t rempos; // the position where the next element will be taken from 41 | 42 | volatile int is_waiting; 43 | volatile int invalid; 44 | 45 | mutex_t mutex; // for thread safety 46 | mutex_t locker; // for waiting 47 | 48 | int buffering; 49 | 50 | int size_coeff; 51 | int max_size_coeff; 52 | }; 53 | 54 | void cb_init(CircBuff_t * cb, int max_size_coeff); 55 | int cb_add(CircBuff_t * cb, float * buff, const size_t size); 56 | int cb_rem_blocking(CircBuff_t * cb, float * in, const size_t len); 57 | int cb_rem_nonblocking(CircBuff_t * cb, float * in, const size_t len); 58 | void cb_free(CircBuff_t * cb); 59 | void cb_purge(CircBuff_t * cb); 60 | int cb_size(CircBuff_t * cb); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/dsp.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | 14 | #include "internaldefinitions.h" 15 | 16 | #ifndef DSP_H_ 17 | #define DSP_H_ 18 | 19 | #include "extbuffer.h" 20 | #include "circbuff.h" 21 | #include "syncdetector.h" 22 | 23 | // time based lowpass 24 | 25 | /** Does a IIR simple lowpass onto output given input (past values are in output). Size is the size of the buffers. Coefficient could be 0 to 1 */ 26 | void dsp_timelowpass_run(const float coeff, int size, float * input, float * output); 27 | 28 | // autogain 29 | 30 | typedef struct { 31 | float lastmax; 32 | float lastmin; 33 | float snr; 34 | } dsp_autogain_t; 35 | 36 | /** Initialize autogain storate */ 37 | void dsp_autogain_init(dsp_autogain_t * autogain); 38 | /** Based on input, the output will be scaled to fit between 0 and 1. coeff regulates the lowpass with which the bounds change */ 39 | void dsp_autogain_run(dsp_autogain_t * autogain, int size, float * input, float * output, float coeff); 40 | 41 | // averaging on vertical and horizontal 42 | 43 | /** Averages all of the vertical and horizontal pixels of the input with height and width */ 44 | void dsp_average_v_h(int width, int height, float * input, float * widthcollapsebuffer, float * heightcollapsebuffer); 45 | 46 | // dsp collection for image enhancement before 47 | 48 | typedef struct { 49 | float * screenbuffer; 50 | float * sendbuffer; 51 | float * corrected_sendbuffer; 52 | 53 | float * widthcollapsebuffer; 54 | float * heightcollapsebuffer; 55 | 56 | int sizetopoll; 57 | int width; 58 | int height; 59 | int bufsize; 60 | 61 | int runs; 62 | 63 | dsp_autogain_t dsp_autogain; 64 | 65 | syncdetector_t sync; 66 | 67 | int lowpass_before_sync; 68 | } dsp_postprocess_t; 69 | 70 | void dsp_post_process_init(dsp_postprocess_t * pp); 71 | 72 | /** Post processing */ 73 | float * dsp_post_process(tsdr_lib_t * tsdr, dsp_postprocess_t * pp, float * buffer, int nowwidth, int nowheight, float motionblur, float lowpasscoeff, const int lowpass_before_sync, const int autogain_after_proc); 74 | 75 | void dsp_post_process_free(dsp_postprocess_t * pp); 76 | 77 | // resampling 78 | 79 | typedef struct { 80 | double contrib; 81 | double offset; 82 | } dsp_resample_t; 83 | 84 | void dsp_resample_init(dsp_resample_t * res); 85 | 86 | void dsp_resample_process(dsp_resample_t * res, extbuffer_t * in, extbuffer_t * out, const double upsample_by, const double downsample_by, int nearest_neighbour_sampling); 87 | void dsp_resample_free(dsp_resample_t * res); 88 | 89 | // compensating for dropped samples 90 | 91 | typedef struct { 92 | int64_t difference; 93 | } dsp_dropped_compensation_t; 94 | 95 | void dsp_dropped_compensation_init(dsp_dropped_compensation_t * res); 96 | void dsp_dropped_compensation_add(dsp_dropped_compensation_t * res, CircBuff_t * cb, float * buff, const uint32_t size, uint32_t block); 97 | void dsp_dropped_compensation_shift_with(dsp_dropped_compensation_t * res, uint32_t block, int64_t syncoffset); 98 | int dsp_dropped_compensation_will_drop_all(dsp_dropped_compensation_t * res, uint32_t size, uint32_t block); 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/extbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "extbuffer.h" 18 | 19 | void extbuffer_init(extbuffer_t * container) { 20 | container->buffer = NULL; 21 | container->dbuffer = NULL; 22 | container->buffer_max_size = 0; 23 | container->size_valid_elements = 0; 24 | 25 | container->valid = 0; 26 | container->cleartozero = 1; 27 | container->calls = 0; 28 | 29 | container->calls = 0; 30 | container->type = EXTBUFFER_TYPE_FLOAT; 31 | } 32 | 33 | void extbuffer_init_double(extbuffer_t * container) { 34 | container->buffer = NULL; 35 | container->dbuffer = NULL; 36 | container->buffer_max_size = 0; 37 | container->size_valid_elements = 0; 38 | 39 | container->valid = 0; 40 | container->cleartozero = 1; 41 | container->calls = 0; 42 | 43 | container->calls = 0; 44 | container->type = EXTBUFFER_TYPE_DOUBLE; 45 | } 46 | 47 | void extbuffer_preparetohandle(extbuffer_t * container, uint32_t size) { 48 | assert (size > 0); 49 | 50 | if (container->buffer_max_size < size || container->buffer_max_size > (size << 1)) { 51 | if (container->type == EXTBUFFER_TYPE_FLOAT) { 52 | if (container->buffer == NULL) { 53 | container->buffer = (float *) malloc(sizeof(float) * size); 54 | container->valid = 1; 55 | } else if (container->buffer_max_size != size) 56 | container->buffer = (float *) realloc((void *) container->buffer, sizeof(float) * size); 57 | } else if (container->type == EXTBUFFER_TYPE_DOUBLE) { 58 | if (container->dbuffer == NULL) { 59 | container->dbuffer = (double *) malloc(sizeof(double) * size); 60 | container->valid = 1; 61 | } else if (container->buffer_max_size != size) 62 | container->dbuffer = (double *) realloc((void *) container->dbuffer, sizeof(double) * size); 63 | } 64 | container->buffer_max_size = size; 65 | } 66 | 67 | container->size_valid_elements = size; 68 | if (container->cleartozero) { 69 | uint32_t i; 70 | if (container->type == EXTBUFFER_TYPE_FLOAT) { 71 | for (i = 0; i < container->size_valid_elements; i++) 72 | container->buffer[i] = 0.0f; 73 | } else if (container->type == EXTBUFFER_TYPE_DOUBLE) { 74 | for (i = 0; i < container->size_valid_elements; i++) 75 | container->dbuffer[i] = 0.0f; 76 | } 77 | container->cleartozero = 0; 78 | container->calls = 0; 79 | } 80 | 81 | container->calls++; 82 | } 83 | 84 | void extbuffer_cleartozero(extbuffer_t * container) { 85 | container->cleartozero = 1; 86 | } 87 | 88 | void extbuffer_free(extbuffer_t * container) { 89 | 90 | container->valid = 0; 91 | if (container->buffer != NULL) { 92 | float * buff = container->buffer; 93 | container->buffer = NULL; 94 | free(buff); 95 | } 96 | if (container->dbuffer != NULL) { 97 | double * dbuff = container->dbuffer; 98 | container->dbuffer = NULL; 99 | free(dbuff); 100 | } 101 | } 102 | 103 | void extbuffer_dumptofile(extbuffer_t * container, int offset, char * filename, char * xname, char * yname) { 104 | assert (container->valid); 105 | 106 | FILE *f = NULL; 107 | 108 | f = fopen(filename, "w"); 109 | 110 | fprintf(f, "%s, %s\n", xname, yname); 111 | 112 | int i; 113 | if (container->type == EXTBUFFER_TYPE_FLOAT) { 114 | for (i = 0; i < container->size_valid_elements; i++) 115 | fprintf(f, "%d, %f\n", offset + i, container->buffer[i]); 116 | } else if (container->type == EXTBUFFER_TYPE_DOUBLE) { 117 | for (i = 0; i < container->size_valid_elements; i++) 118 | fprintf(f, "%d, %f\n", offset + i, container->dbuffer[i]); 119 | } 120 | 121 | fclose(f); 122 | 123 | } 124 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/extbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | 14 | #ifndef EXTBUFFER_H_ 15 | #define EXTBUFFER_H_ 16 | 17 | #include "stdint.h" 18 | 19 | #define EXTBUFFER_TYPE_FLOAT (0) 20 | #define EXTBUFFER_TYPE_DOUBLE (1) 21 | 22 | typedef struct extbuffer { 23 | 24 | float * buffer; 25 | double * dbuffer; 26 | 27 | uint32_t size_valid_elements; 28 | 29 | uint32_t buffer_max_size; 30 | 31 | volatile int valid; 32 | volatile int cleartozero; 33 | 34 | uint64_t calls; 35 | int type; 36 | 37 | } extbuffer_t; 38 | 39 | void extbuffer_init(extbuffer_t * container); 40 | void extbuffer_init_double(extbuffer_t * container); 41 | void extbuffer_preparetohandle(extbuffer_t * container, uint32_t size); 42 | void extbuffer_cleartozero(extbuffer_t * container); 43 | void extbuffer_dumptofile(extbuffer_t * container, int offset, char * filename, char * xname, char * yname); 44 | void extbuffer_free(extbuffer_t * container); 45 | 46 | 47 | #endif /* EXTBUFFER_H_ */ 48 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/fft.c: -------------------------------------------------------------------------------- 1 | #include "fft.h" 2 | #include 3 | #include 4 | 5 | uint32_t fft_getrealsize(uint32_t size) { 6 | uint32_t m =0; 7 | while ((size /= 2) != 0) 8 | m++; 9 | 10 | return 1 << m; 11 | } 12 | 13 | // out should have a size of 2*in_size 14 | void real_to_complex(float * out, float * in, int in_size) { 15 | uint32_t i; 16 | 17 | // set the real ids in answer to the val, the imaginary ones to 0 18 | for (i = 0; i < in_size; i++) { 19 | *(out++) = *(in++); 20 | *(out++) = 0.0f; 21 | } 22 | } 23 | 24 | void complex_to_real(float * data, int samples){ 25 | float * src = data; 26 | uint32_t i; 27 | for (i = 0; i < samples; i++) { 28 | const float I = *(src++); 29 | const float Q = *(src++); 30 | *(data++) = sqrtf(I*I+Q*Q); 31 | } 32 | } 33 | 34 | void fft_complex_to_absolute_complex(float * data, int samples) { 35 | uint32_t fft_size2 = samples * 2; 36 | 37 | uint32_t i; 38 | for (i = 0; i < fft_size2; i+=2) { 39 | const int i1 = i+1; 40 | const float I = data[i]; 41 | const float Q = data[i1]; 42 | data[i] = sqrtf(I*I+Q*Q); 43 | data[i1] = 0; 44 | } 45 | } 46 | 47 | // the array temp needs to be of size at least 2*size 48 | // the answer will be written in answer at entries fro 0 to 2*size 49 | void fft_autocorrelation(float * answer, float * real, uint32_t size) { 50 | 51 | // set the real ids in answer to the val, the imaginary ones to 0 52 | real_to_complex(answer, real, size); 53 | 54 | // do the fft 55 | uint32_t fft_size = fft_getrealsize(size); 56 | 57 | fft_perform(answer, fft_size, 0); 58 | 59 | // get the abs value 60 | fft_complex_to_absolute_complex(answer, size); 61 | 62 | // get the ifft 63 | fft_perform(answer, fft_size, 1); 64 | } 65 | 66 | // a and b need to be complex with size samples * 2 67 | // the final answer can be found in answer_out and it is complex 68 | // you may need to take its absolute value to get the crosscorrelation 69 | void fft_crosscorrelation(float * answer_out, float * answer_temp, uint32_t samples) { 70 | uint32_t i; 71 | 72 | uint32_t fft_size = fft_getrealsize(samples); 73 | uint32_t fft_size2 = fft_size * 2; 74 | 75 | // perform the ffts 76 | fft_perform(answer_out, fft_size, 0); 77 | fft_perform(answer_temp, fft_size, 0); 78 | 79 | // multiply the cojugate 80 | for (i = 0; i < fft_size2; i+=2) { 81 | const int i1 = i+1; 82 | const float aI = answer_out[i]; 83 | const float aQ = answer_out[i1]; 84 | const float bI = answer_temp[i]; 85 | const float bQ = answer_temp[i1]; 86 | 87 | answer_out[i] = aI*bI + aQ*bQ; 88 | answer_out[i1] = aI*bQ - aQ*bI; 89 | } 90 | 91 | // get the ifft 92 | fft_perform(answer_out, fft_size, 1); 93 | } 94 | 95 | // iq must have a size of size*2 96 | void fft_perform(float * iq, uint32_t size, int inverse) 97 | { 98 | int64_t i,i1,j,k,i2,l,l1,l2; 99 | double c1,c2,tx,ty,t1,t2,u1,u2,z; 100 | 101 | int m =0; 102 | while ((size /= 2) != 0) 103 | m++; 104 | 105 | uint32_t nn = 1 << m; 106 | i2 = nn >> 1; 107 | j = 0; 108 | 109 | for (i=0;i>= 1; 128 | } 129 | j += k; 130 | } 131 | 132 | c1 = -1.0; 133 | c2 = 0.0; 134 | l2 = 1; 135 | for (l=0;l 6 | 7 | uint32_t fft_getrealsize(uint32_t size); 8 | void fft_perform(float * iq, uint32_t size, int inverse); 9 | void fft_autocorrelation(float * answer, float * real, uint32_t size); 10 | void fft_crosscorrelation(float * answer_out, float * answer_temp, uint32_t samples); 11 | void fft_complex_to_absolute_complex(float * data, int samples); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/frameratedetector.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | 12 | #ifndef FRAMERATEDETECTOR_H_ 13 | #define FRAMERATEDETECTOR_H_ 14 | 15 | #include "include/TSDRLibrary.h" 16 | #include "circbuff.h" 17 | 18 | #include 19 | 20 | typedef struct frameratedetector { 21 | 22 | tsdr_lib_t * tsdr; 23 | uint32_t samplerate; 24 | 25 | volatile int alive; 26 | volatile int purge_buffers; 27 | 28 | CircBuff_t circbuff; 29 | 30 | } frameratedetector_t; 31 | 32 | void frameratedetector_startthread(frameratedetector_t * frameratedetector); 33 | void frameratedetector_stopthread(frameratedetector_t * frameratedetector); 34 | void frameratedetector_flushcachedestimation(frameratedetector_t * frameratedetector); 35 | 36 | void frameratedetector_init(frameratedetector_t * frameratedetector, tsdr_lib_t * tsdr); 37 | void frameratedetector_free(frameratedetector_t * frameratedetector); 38 | void frameratedetector_run(frameratedetector_t * frameratedetector, float * data, int size, uint32_t samplerate, int drop); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/gaussian.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | 12 | #include 13 | 14 | #define GAUSSIAN_ALPHA (1.0f) 15 | 16 | // N is the number of points, i is between -(N-1)/2 and (N-1)/2 inclusive 17 | #define CALC_GAUSSCOEFF(N,i) expf(-2.0f*GAUSSIAN_ALPHA*GAUSSIAN_ALPHA*i*i/(N*N)) 18 | void gaussianblur(float * data, int size) { 19 | static float norm = 0.0f, c_2 = 0.0f, c_1 = 0.0f, c0 = 0.0f, c1 = 0.0f, c2 = 0.0f; 20 | if (norm == 0.0f) { 21 | // calculate only first time we run 22 | norm = CALC_GAUSSCOEFF(5,-2)+CALC_GAUSSCOEFF(5, -1)+CALC_GAUSSCOEFF(5, 0)+CALC_GAUSSCOEFF(5, 1)+CALC_GAUSSCOEFF(5, 2); 23 | c_2 = CALC_GAUSSCOEFF(5, -2) / norm; 24 | c_1 = CALC_GAUSSCOEFF(5, -1) / norm; 25 | c0 = CALC_GAUSSCOEFF(5, 0) / norm; 26 | c1 = CALC_GAUSSCOEFF(5, 1) / norm; 27 | c2 = CALC_GAUSSCOEFF(5, 2) / norm; 28 | } 29 | 30 | float p_2, p_1, p0, p1, p2, data_2, data_3, data_4; 31 | if (size < 5) { 32 | p_2 = data[0]; 33 | p_1 = data[1 % size]; 34 | p0 = data[2 % size]; 35 | p1 = data[3 % size]; 36 | p2 = data[4 % size]; 37 | } else { 38 | p_2 = data[0]; 39 | p_1 = data[1]; 40 | p0 = data[2]; 41 | p1 = data[3]; 42 | p2 = data[4]; 43 | } 44 | 45 | data_2 = p0; 46 | data_3 = p1; 47 | data_4 = p2; 48 | 49 | int i; 50 | const int sizem2 = size - 2; 51 | const int sizem5 = size - 5; 52 | for (i = 0; i < size; i++) { 53 | 54 | const int idtoupdate = (i < sizem2) ? (i + 2) : (i - sizem2); 55 | const int nexti = (i < sizem5) ? (i + 5) : (i - sizem5); 56 | 57 | data[idtoupdate] = p_2 * c_2 + p_1 * c_1 + p0 * c0 + p1 * c1 + p2 * c2; 58 | p_2 = p_1; 59 | p_1 = p0; 60 | p0 = p1; 61 | p1 = p2; 62 | 63 | if (nexti < 2 || nexti >= 5) 64 | p2 = data[nexti]; 65 | else { 66 | switch (nexti) { 67 | case 2: 68 | p2 = data_2; 69 | break; 70 | case 3: 71 | p2 = data_3; 72 | break; 73 | case 4: 74 | p2 = data_4; 75 | break; 76 | } 77 | } 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/gaussian.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | #ifndef GAUSSIAN_H_ 12 | #define GAUSSIAN_H_ 13 | 14 | void gaussianblur(float * data, int size); 15 | 16 | 17 | #endif /* GAUSSIAN_H_ */ 18 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/include/TSDRCodes.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRCodes 14 | #define _TSDRCodes 15 | 16 | #define TSDR_OK (0) 17 | #define TSDR_ERR_PLUGIN (1) 18 | #define TSDR_WRONG_VIDEOPARAMS (2) 19 | #define TSDR_ALREADY_RUNNING (3) 20 | #define TSDR_PLUGIN_PARAMETERS_WRONG (4) 21 | #define TSDR_SAMPLE_RATE_WRONG (5) 22 | #define TSDR_CANNOT_OPEN_DEVICE (6) 23 | #define TSDR_INCOMPATIBLE_PLUGIN (7) 24 | #define TSDR_INVALID_PARAMETER (8) 25 | #define TSDR_INVALID_PARAMETER_VALUE (9) 26 | #define TSDR_NOT_RUNNING (10) 27 | #define TSDR_NOT_IMPLEMENTED (404) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/include/TSDRLibrary.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRLibrary 14 | #define _TSDRLibrary 15 | 16 | #include 17 | 18 | // those PIXEL_* are only used for debugging purposes and 19 | // it is not required for the client to implement them 20 | #define PIXEL_SPECIAL_VALUE_R (256.0f) 21 | #define PIXEL_SPECIAL_VALUE_G (512.0f) 22 | #define PIXEL_SPECIAL_VALUE_B (1024.0f) 23 | #define PIXEL_SPECIAL_VALUE_TRANSPARENT (2048.0f) 24 | #define PIXEL_SPECIAL_COLOURS_ENABLED (1) 25 | 26 | #define DIRECTION_CUSTOM (0) 27 | #define DIRECTION_UP (1) 28 | #define DIRECTION_DOWN (2) 29 | #define DIRECTION_LEFT (3) 30 | #define DIRECTION_RIGHT (4) 31 | 32 | #define PARAM_INT_AUTOSHIFT (0) 33 | #define PARAM_INT_FRAMERATE_PLL (1) 34 | #define PARAM_AUTOCORR_PLOTS_RESET (2) 35 | #define PARAM_AUTOCORR_PLOTS_OFF (3) 36 | #define PARAM_AUTOCORR_SUPERRESOLUTION (4) 37 | #define PARAM_NEAREST_NEIGHBOUR_RESAMPLING (5) 38 | #define PARAM_LOW_PASS_BEFORE_SYNC (6) 39 | #define PARAM_AUTOGAIN_AFTER_PROCESSING (7) 40 | #define PARAM_AUTOCORR_DUMP (8) 41 | #define COUNT_PARAM_INT (9) 42 | 43 | #define COUNT_PARAM_DOUBLE (2) 44 | 45 | #define VALUE_ID_PLL_FRAMERATE (0) 46 | #define VALUE_ID_AUTOCORRECT_RESET (1) 47 | #define VALUE_ID_AUTOCORRECT_FRAMES_COUNT (2) 48 | #define VALUE_ID_AUTOGAIN_VALUES (3) 49 | #define VALUE_ID_SNR (4) 50 | #define VALUE_ID_AUTOCORRECT_DUMPED (5) 51 | 52 | #define PLOT_ID_FRAME (0) 53 | #define PLOT_ID_LINE (1) 54 | 55 | typedef struct tsdr_lib tsdr_lib_t; 56 | 57 | typedef void(*tsdr_readasync_function)(float *buf, int width, int height, void *ctx); 58 | typedef void(*tsdr_value_changed_callback)(int value_id, double arg0, double arg1, void * ctx); 59 | typedef void(*tsdr_on_plot_ready_callback)(int plot_id, int offset, double * values, int size, uint32_t samplerate, void * ctx); 60 | 61 | void tsdr_init(tsdr_lib_t ** tsdr, tsdr_value_changed_callback callback, tsdr_on_plot_ready_callback plotready_callback, void * ctx); 62 | void * tsdr_getctx(tsdr_lib_t * tsdr); 63 | int tsdr_setbasefreq(tsdr_lib_t * tsdr, uint32_t freq); 64 | int tsdr_stop(tsdr_lib_t * tsdr); 65 | int tsdr_setgain(tsdr_lib_t * tsdr, float gain); 66 | int tsdr_readasync(tsdr_lib_t * tsdr, tsdr_readasync_function cb, void * ctx); 67 | int tsdr_loadplugin(tsdr_lib_t * tsdr, const char * pluginfilepath, const char * params); 68 | int tsdr_unloadplugin(tsdr_lib_t * tsdr); 69 | int tsdr_setresolution(tsdr_lib_t * tsdr, int height, double refreshrate); 70 | int tsdr_isrunning(tsdr_lib_t * tsdr); 71 | int tsdr_sync(tsdr_lib_t * tsdr, int pixels, int direction); 72 | int tsdr_motionblur(tsdr_lib_t * tsdr, float coeff); 73 | void tsdr_free(tsdr_lib_t ** tsdr); 74 | char * tsdr_getlasterrortext(tsdr_lib_t * tsdr); 75 | int tsdr_setparameter_int(tsdr_lib_t * tsdr, int parameter, uint32_t value); 76 | int tsdr_setparameter_double(tsdr_lib_t * tsdr, int parameter, double value); 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/include/TSDRPlugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRPluginHeader 14 | #define _TSDRPluginHeader 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #if _MSC_VER && !__INTEL_COMPILER 21 | #define TSDRPLUGIN_API __declspec(dllexport) 22 | #elif defined _WIN32 || defined __CYGWIN__ 23 | #ifdef __GNUC__ 24 | #define TSDRPLUGIN_API __attribute__ ((dllexport)) 25 | #else 26 | #define TSDRPLUGIN_API __declspec(dllexport) 27 | #endif 28 | #else 29 | #if __GNUC__ >= 4 30 | #define TSDRPLUGIN_API __attribute__ ((visibility ("default"))) 31 | #else 32 | #define TSDRPLUGIN_API 33 | #endif 34 | #endif 35 | 36 | 37 | #ifdef __cplusplus 38 | #define EXTERNC extern "C" 39 | #else 40 | #define EXTERNC 41 | #endif 42 | 43 | #if !(defined(OS_WINDOWS) || defined(_WIN64) || defined(_WIN32) || defined(_MSC_VER) || defined(__stdcall)) 44 | #define __stdcall 45 | #endif 46 | 47 | #include 48 | 49 | typedef void(*tsdrplugin_readasync_function)(float *buf, uint64_t items_count, void *ctx, int64_t samples_dropped); 50 | 51 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_getName(char *); 52 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_init(const char * params); 53 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_setsamplerate(uint32_t rate); 54 | EXTERNC TSDRPLUGIN_API uint32_t __stdcall tsdrplugin_getsamplerate(); 55 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setbasefreq(uint32_t freq); 56 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_stop(void); 57 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_setgain(float gain); 58 | EXTERNC TSDRPLUGIN_API char* __stdcall tsdrplugin_getlasterrortext(void); 59 | EXTERNC TSDRPLUGIN_API int __stdcall tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx); 60 | EXTERNC TSDRPLUGIN_API void __stdcall tsdrplugin_cleanup(void); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/internaldefinitions.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | #ifndef INTERNALDEFINITIONS_H_ 12 | #define INTERNALDEFINITIONS_H_ 13 | 14 | #include "threading.h" 15 | #include "circbuff.h" 16 | #include "TSDRPluginLoader.h" 17 | #include "frameratedetector.h" 18 | #include "superbandwidth.h" 19 | 20 | #include "extbuffer.h" 21 | #include "dsp.h" 22 | 23 | #include "include/TSDRLibrary.h" 24 | 25 | #include 26 | #include 27 | 28 | #define MALLOC_OR_REALLOC(buffer, size, type) ((buffer == NULL) ? ((type *) malloc(size*sizeof(type))) : ((type *) realloc((void *) buffer, size*sizeof(type)))) 29 | 30 | struct tsdr_lib { 31 | pluginsource_t plugin; 32 | semaphore_t threadsync; 33 | mutex_t stopsync; 34 | uint32_t samplerate; 35 | uint32_t samplerate_real; 36 | int width; 37 | int height; 38 | double pixelrate; 39 | double refreshrate; 40 | double pixeltimeoversampletime; 41 | volatile int running; 42 | volatile int nativerunning; 43 | uint32_t centfreq; 44 | float gain; 45 | float motionblur; 46 | volatile int syncoffset; 47 | char * errormsg; 48 | int errormsg_size; 49 | int errormsg_code; 50 | 51 | uint32_t params_int[COUNT_PARAM_INT]; 52 | double params_double[COUNT_PARAM_DOUBLE]; 53 | 54 | frameratedetector_t frameratedetect; 55 | 56 | tsdr_value_changed_callback callback; 57 | tsdr_on_plot_ready_callback plotready_callback; 58 | void * callbackctx; 59 | 60 | superbandwidth_t super; 61 | 62 | dsp_postprocess_t dsp_postprocess; 63 | dsp_resample_t dsp_resample; 64 | 65 | }; 66 | 67 | void announce_callback_changed(tsdr_lib_t * tsdr, int value_id, double arg0, double arg1); 68 | void announce_plotready(tsdr_lib_t * tsdr, int plot_id, extbuffer_t * buffer, uint32_t data_size, uint32_t data_offset, uint32_t samplerate); 69 | 70 | void shiftfreq(tsdr_lib_t * tsdr, int32_t diff); 71 | void set_internal_samplerate(tsdr_lib_t * tsdr, uint32_t samplerate); 72 | 73 | void unloadplugin(tsdr_lib_t * tsdr); 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/osdetect.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifdef OS_WINDOWS 14 | #define WINHEAD (1) 15 | #elif defined(_WIN64) 16 | #define WINHEAD (1) 17 | #elif defined(_WIN32) 18 | #define WINHEAD (1) 19 | #elif defined(_MSC_VER) // Microsoft compiler 20 | #define WINHEAD (1) 21 | #else 22 | #define WINHEAD (0) 23 | #endif 24 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/superbandwidth.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | 14 | #include "internaldefinitions.h" 15 | 16 | #ifndef SUPERBANDWIDTH_H_ 17 | #define SUPERBANDWIDTH_H_ 18 | 19 | #include "extbuffer.h" 20 | #include "threading.h" 21 | 22 | typedef struct { 23 | int state; 24 | int samples_to_gather; 25 | int samples_gathered; 26 | int samples_in_frame; 27 | 28 | int samples_to_pause; 29 | 30 | uint32_t samplerate; 31 | 32 | float ** buffs; 33 | int buffscount; 34 | int buffsbuffcount; 35 | int buffid_current; 36 | 37 | float * outbuf; 38 | int outbufsize; 39 | tsdr_lib_t * tsdr; 40 | 41 | mutex_t thread_unlock; 42 | 43 | extbuffer_t extb; 44 | 45 | extbuffer_t extb_out; 46 | extbuffer_t extb_temp; 47 | 48 | volatile int alive; 49 | } superbandwidth_t; 50 | 51 | void superb_init(superbandwidth_t * bw); 52 | void superb_free(superbandwidth_t * bw); 53 | void superb_run(superbandwidth_t * bw, float * iq, int size, tsdr_lib_t * tsdr, int dropped, float ** outbuff, int * outbufsize); 54 | void superb_stop(superbandwidth_t * bw, tsdr_lib_t * tsdr); 55 | void super_startthread(superbandwidth_t * bw); 56 | void super_stopthread(superbandwidth_t * bw); 57 | 58 | 59 | #endif /* SUPERBANDWIDTH_H_ */ 60 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/syncdetector.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Martin Marinov. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Public License v3.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/gpl.html 7 | * 8 | * Contributors: 9 | * Martin Marinov - initial API and implementation 10 | ******************************************************************************/ 11 | #include "internaldefinitions.h" 12 | 13 | #ifndef SYNCDETECTOR_H_ 14 | #define SYNCDETECTOR_H_ 15 | 16 | typedef struct sweetspot_data { 17 | int dx; 18 | int vx; 19 | int absvx; 20 | 21 | int curr_stripsize; 22 | } sweetspot_data_t; 23 | 24 | typedef struct syncdetector { 25 | sweetspot_data_t db_x; 26 | sweetspot_data_t db_y; 27 | 28 | double last_frame_diff; 29 | int state; 30 | double avg_speed; 31 | } syncdetector_t; 32 | 33 | void syncdetector_init(syncdetector_t * sy); 34 | float * syncdetector_run(syncdetector_t * sy, tsdr_lib_t * tsdr, float * data, float * outputdata, int width, int height, float * widthbuffer, float * heightbuffer, int greenlines, int modify_data_allowed); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/TempestSDR/src/threading.h: -------------------------------------------------------------------------------- 1 | /* 2 | #------------------------------------------------------------------------------- 3 | # Copyright (c) 2014 Martin Marinov. 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the GNU Public License v3.0 6 | # which accompanies this distribution, and is available at 7 | # http://www.gnu.org/licenses/gpl.html 8 | # 9 | # Contributors: 10 | # Martin Marinov - initial API and implementation 11 | #------------------------------------------------------------------------------- 12 | */ 13 | #ifndef _TSDRThreading 14 | #define _TSDRThreading 15 | 16 | // A platform independed threading library with mutex support 17 | 18 | #include "osdetect.h" 19 | #include 20 | 21 | #define THREAD_OK (0) 22 | #define THREAD_TIMEOUT (1) 23 | #define THREAD_NOT_INITED (2) 24 | 25 | typedef void(*thread_function)(void *ctx); 26 | 27 | struct mutex { 28 | void * thing1; 29 | void * thing2; 30 | volatile int valid; 31 | } typedef mutex_t; 32 | 33 | struct semaphore { 34 | int count; 35 | mutex_t locker; 36 | mutex_t signaller; 37 | } typedef semaphore_t; 38 | 39 | struct locking_variable { 40 | volatile int value; 41 | mutex_t signaller; 42 | mutex_t locker; 43 | volatile int someonewaiting; 44 | volatile int set; 45 | } typedef locking_variable_t; 46 | 47 | #define THREAD_INIT ={NULL, NULL} 48 | 49 | void thread_start(thread_function f, void * ctx); 50 | void thread_sleep(uint32_t milliseconds); 51 | 52 | // warning, there is not mutex_free so calling too many mutex_init could be a memory leak! 53 | void mutex_init(mutex_t * mutex); 54 | int mutex_wait(mutex_t * mutex); 55 | int mutex_waitforever(mutex_t * mutex); 56 | void mutex_signal(mutex_t * mutex); 57 | void mutex_free(mutex_t * mutex); 58 | 59 | void critical_enter(mutex_t * mutex); 60 | void critical_leave(mutex_t * mutex); 61 | 62 | void semaphore_init(semaphore_t * semaphore); 63 | void semaphore_enter(semaphore_t * semaphore); 64 | void semaphore_leave(semaphore_t * semaphore); 65 | void semaphore_wait(semaphore_t * semaphore); 66 | void semaphore_free(semaphore_t * semaphore); 67 | 68 | void lockvar_init(locking_variable_t * var); 69 | int lockvar_waitandgetval(locking_variable_t * var); 70 | void lockvar_free(locking_variable_t * var); 71 | void lockvar_setval(locking_variable_t * var, int value); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /TempestSDR_EMEye/makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Martin Marinov. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the GNU Public License v3.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.gnu.org/licenses/gpl.html 7 | # 8 | # Contributors: 9 | # Martin Marinov - initial API and implementation 10 | #------------------------------------------------------------------------------- 11 | 12 | # This makefile will just do make clean and make all to all of the projects 13 | 14 | # Detect library extension depending on OS 15 | ifeq ($(OS),Windows_NT) 16 | OSNAME ?= WINDOWS 17 | else 18 | UNAME_S := $(shell uname -s) 19 | ifeq ($(UNAME_S),Linux) 20 | OSNAME ?= LINUX 21 | endif 22 | endif 23 | 24 | # Make all 25 | all : 26 | @$(MAKE) -C TSDRPlugin_RawFile/ all JAVA_HOME=$(JAVA_HOME) 27 | ifeq ($(OSNAME),WINDOWS) 28 | @$(MAKE) -C TSDRPlugin_ExtIO/ all 29 | endif 30 | @$(MAKE) -C TempestSDR/ all 31 | @$(MAKE) -C JavaGUI/ all 32 | 33 | # Clean artifacts 34 | clean : 35 | @$(MAKE) -C TSDRPlugin_RawFile/ clean 36 | @$(MAKE) -C TSDRPlugin_Mirics/ clean 37 | @$(MAKE) -C TSDRPlugin_ExtIO/ clean 38 | @$(MAKE) -C TSDRPlugin_SDRPlay/ clean 39 | @$(MAKE) -C TempestSDR/ clean 40 | @$(MAKE) -C JavaGUI/ clean 41 | -------------------------------------------------------------------------------- /files/GUI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longyan97/EMEye_Tutorial/4f5cf3600e809698a2a94258391ac684427ebac4/files/GUI.png -------------------------------------------------------------------------------- /files/SIM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longyan97/EMEye_Tutorial/4f5cf3600e809698a2a94258391ac684427ebac4/files/SIM.png -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # EM Eye 2 | 3 | This repository is the tutorial of eavesdropping on camera video from camera circuit's electromagnetic (EM) leakage, which is presented in the NDSS'24 paper "**EM Eye: Characterizing Electromagnetic Side-channel Eavesdropping on Embedded Cameras**" (contact: yanlong@umich.edu and/or qhjiang@zju.edu.cn). Please also refer to [the research project introduction website](https://emeyeattack.github.io/Website/). 4 | 5 | 6 | To enable researchers to quickly reproduce the observations in the paper on different camera devices, we modified the [TempestSDR](https://github.com/martinmarinov/TempestSDR) tool into **[TempestSDR_EMEye](#sdr_bom)**. Specifically, range of eavesdropping parameters was adjusted to fit the scope of embedded cameras. 7 | 8 | To help readers understand how this eavesdropping process works, we also provide a **[MATLAB simulation program](#matlabsimulation_emeye)**. 9 | 10 | 11 | 12 | ## TempestSDR_EMEye: Bill of Materials 13 | 14 | **Hardware**: 15 | - A decent laptop 16 | - Software-defined radio: Ettus USRP B210 USRP 17 | - Low noise amplifier: Foresight Intelligence FSTRFAMP06 18 | - Antenna: A common outdoor Log-periodic directional antenna (LPDA) for long distances or a cheap near-field magnetic field probe for short distances. 19 | 20 | Note that most hardware models can be changed. For example, the USRP can be replaced by cheaper SDR devices such as RTL-SDR. If you have expertise in software-defined radio, feel free to try different sets of hardware equipment. 21 | 22 | **Software**: 23 | - Operating System: Ubuntu/macOS/Debian (Bookworm) 24 | - UHD 4.4.0.0 driver [provided by Ettus Research](https://files.ettus.com/manual/page_install.html) 25 | - libuhd-dev 4.4.0 26 | - openjdk-8-jdk or OpenJDK 17.0.10 27 | - TempestSDR_EMEye in this repo. Compile it by running "make all JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/" (change the path to your own jdk path) in the the JavaGUI/ folder 28 | 29 | We suggest keeping the software models the same as ours. If you are compiling TempestSDR_EMEye with other software environments, you should read the instructions on the [TempestSDR](https://github.com/martinmarinov/TempestSDR) page. 30 | 31 | Make sure [your USRP is connected and you successfully ping it](https://files.ettus.com/manual/page_usrp2.html). Now the test environment is all set up. 32 | 33 | ## TempestSDR_EMEye: Usage 34 | 35 | You can go to the JavaGUI/ folder and start TempestSDR_EMEye by running "java -jar JTempestSDR.jar". You will see the GUI pop up. Go to File -> Load USRP (via UHD), and input "--rate=10000000" to set the sampling rate to 10 MHz. Then configure the eavesdropping reconstruction algorithm by setting Disp Width, Real Height, FPS, and Freq based on this table below. 36 | 37 | **Tested Devices:** 38 | 39 | | **No.** | **Vendor and Model** | **Disp Width** | **Real Height** | **FPS** | **Freq. (MHz)** | 40 | |:-------:|:----------------------------:|:--------------:|:---------------:|:-----------:|:---------------:| 41 | | **1** | Raspberry Pi Camera Module 1 | 2576 | 1126 | 30.01985577 | 204 or 255 | 42 | | **2** | Raspberry Pi Camera Module 2 | 2576 | 1790 | 29.55323582 | 457 or 570 | 43 | | **3** | Raspberry Pi Camera Module 3 | 2166 | 1244 | 30.08283973 | 335 or 1015 | 44 | | **4** | Google Pixel 1 | 2800 | 1557 | 29.89235398 | 600 or 1649 | 45 | | **5** | Google Pixel 3 | 6000 | 3055 | 30.0610185 | 515 or 680 | 46 | | **6** | Samsung S6 | 5000 | 3173 | 30.01527799 | 527 or 1054 | 47 | | **7** | ZTE Z557 | 4000 | 2453 | 23.98017526 | 522 or 1740 | 48 | | **8** | Wyze Cam Pan 2 | 2300 | 1687 | 20.0071563 | 890 or 1185 | 49 | | **9** | Xiaomi Dafang IP Camera | 2567 | 2250 | 15.0008813 | 322 or 890 | 50 | | **10** | Baidu Xiaodu X9 | 2576 | 1250 | 15.0000375 | 204 or 1470 | 51 | | **11** | TeGongMao | 2576 | 1500 | 15.15164801 | 763 or 1144 | 52 | | **12** | Goov V9 | 2000 | 750 | 30.30325987 | 546 or 656 | 53 | | **13** | QiaoDu | 2576 | 2245 | 15.04149722 | 293 or 1191 | 54 | | **14** | 360 M320 Dashcam | 2620 | 1818 | 25.00241735 | 450 or 1261 | 55 | | **15** | Blackview Dashcam | 2567 | 1196 | 30.09970806 | 155 or 1015 | 56 | 57 | The configuration parameters are for specific camera modes. You may need to adjust the parameters when testing other modes. 58 | - Raspberry Pi cameras were tested while they are in the 1080p mode (-md 1). 59 | - Smartphone cameras (rear/main cameras) were tested in the video mode. 60 | - Dash cams and home cameras were tested in their default modes. 61 | 62 | Note that individual devices of the same model may require slightly different parameters than the ones reported in the table due to hardware manufacturing and software version variations. You may need to fine-tune the frequency, FPS, and height, and even the SDR sampling rate to get the best results. The width parameter only controls the scaled aspect ratio of the displayed reconstruction and does not have any impact on the EM reconstruction process. We refer you to the [dissertation of Martin Marinov](https://github.com/martinmarinov/TempestSDR/blob/master/documentation/acs-dissertation.pdf), the author of [TempestSDR](https://github.com/martinmarinov/TempestSDR), for more information on how these parameters work. 63 | 64 | **Eavesdropping GUI:** 65 | 66 | Press the star button. You will see something similar to the figure below. The upper-left window displays the real-time reconstruction of the camera video. 67 | 68 | ![TempestSDR_EMEye Screenshot](./files/GUI.png) 69 | 70 | 71 | 72 | ## MatlabSimulation_EMEye 73 | 74 | The simulation program is in the MatlabSimulation_EMEye/ folder of this repo. 75 | 76 | The program converts a RAW image frame (room.dng) captured by a Raspberry Pi Camera V1 into the bit stream transmitted over the MIPI CSI-2 2-lane interface used by the camera sensor, and then reconstructs the image from the simulated corresponding EM signals of the bit stream. 77 | 78 | ![Simulation Results](./files/SIM.png) 79 | 80 | 81 | 82 | ## Citation Information 83 | If you find our results useful to your research, please cite it as follows: 84 | 85 | 86 | ``` 87 | @inproceedings{long2024emeye, 88 | title={EM Eye: Characterizing Electromagnetic Side-channel Eavesdropping on Embedded Cameras}, 89 | author={Long, Yan and Jiang, Qinhong and Yan, Chen and Alam, Tobias and Ji, Xiaoyu and Xu, Wenyuan and Fu, Kevin}, 90 | booktitle={Network and Distributed Systems Security (NDSS) Symposium}, 91 | year={2024} 92 | } 93 | ``` --------------------------------------------------------------------------------