mirror of
https://github.com/brmlab/kalibrate-rtl.git
synced 2025-08-01 21:53:37 +02:00
add win32 support
Signed-off-by: Steve Markgraf <steve@steve-m.de>
This commit is contained in:
parent
ed733cc952
commit
482dd05ecd
10 changed files with 140 additions and 16 deletions
|
@ -27,7 +27,9 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include "arfcn_freq.h"
|
||||
|
||||
|
|
|
@ -39,6 +39,10 @@ extern int g_verbosity;
|
|||
|
||||
static const float ERROR_DETECT_OFFSET_MAX = 40e3;
|
||||
|
||||
#ifdef _WIN32
|
||||
#define BUFSIZ 1024
|
||||
#endif
|
||||
|
||||
static double vectornorm2(const complex *v, const unsigned int len) {
|
||||
|
||||
unsigned int i;
|
||||
|
@ -53,8 +57,8 @@ static double vectornorm2(const complex *v, const unsigned int len) {
|
|||
|
||||
int c0_detect(usrp_source *u, int bi) {
|
||||
|
||||
static const double GSM_RATE = 1625000.0 / 6.0;
|
||||
static const unsigned int NOTFOUND_MAX = 10;
|
||||
#define GSM_RATE (1625000.0 / 6.0)
|
||||
#define NOTFOUND_MAX 10
|
||||
|
||||
int i, chan_count;
|
||||
unsigned int overruns, b_len, frames_len, found_count, notfound_count, r;
|
||||
|
|
|
@ -31,24 +31,29 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <sys/ipc.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <stdexcept>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifndef D_HOST_OSX
|
||||
#ifndef _WIN32
|
||||
#include <sys/shm.h>
|
||||
#endif
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#endif /* !D_HOST_OSX */
|
||||
|
||||
#include "circular_buffer.h"
|
||||
|
||||
//#include <cstdio>
|
||||
|
||||
#ifndef D_HOST_OSX
|
||||
#ifndef _WIN32
|
||||
circular_buffer::circular_buffer(const unsigned int buf_len,
|
||||
const unsigned int item_size, const unsigned int overwrite) {
|
||||
|
||||
|
@ -171,7 +176,6 @@ circular_buffer::circular_buffer(const unsigned int buf_len,
|
|||
pthread_mutex_init(&m_mutex, 0);
|
||||
}
|
||||
|
||||
|
||||
circular_buffer::~circular_buffer() {
|
||||
|
||||
shmdt((char *)m_base + m_pagesize + 2 * m_buf_size);
|
||||
|
@ -179,6 +183,92 @@ circular_buffer::~circular_buffer() {
|
|||
shmdt((char *)m_base + m_pagesize);
|
||||
shmdt((char *)m_base);
|
||||
}
|
||||
|
||||
#else
|
||||
circular_buffer::circular_buffer(const unsigned int buf_len,
|
||||
const unsigned int item_size, const unsigned int overwrite) {
|
||||
|
||||
if(!buf_len)
|
||||
throw std::runtime_error("circular_buffer: buffer len is 0");
|
||||
|
||||
if(!item_size)
|
||||
throw std::runtime_error("circular_buffer: item size is 0");
|
||||
|
||||
// calculate buffer size
|
||||
m_item_size = item_size;
|
||||
m_buf_size = item_size * buf_len;
|
||||
m_buf_len = m_buf_size / item_size;
|
||||
|
||||
|
||||
d_handle = CreateFileMapping(INVALID_HANDLE_VALUE, // use paging file
|
||||
NULL, // default security
|
||||
PAGE_READWRITE, // read/write access
|
||||
0, // max. object size
|
||||
m_buf_size, // buffer size
|
||||
NULL); // name of mapping object
|
||||
|
||||
|
||||
if (d_handle == NULL || d_handle == INVALID_HANDLE_VALUE){
|
||||
throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping");
|
||||
}
|
||||
|
||||
// Allocate virtual memory of the needed size, then free it so we can use it
|
||||
LPVOID first_tmp;
|
||||
first_tmp = VirtualAlloc( NULL, 2*m_buf_size, MEM_RESERVE, PAGE_NOACCESS );
|
||||
if (first_tmp == NULL){
|
||||
CloseHandle(d_handle); // cleanup
|
||||
throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping");
|
||||
}
|
||||
|
||||
if (VirtualFree(first_tmp, 0, MEM_RELEASE) == 0){
|
||||
CloseHandle(d_handle); // cleanup
|
||||
throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping");
|
||||
}
|
||||
|
||||
d_first_copy = MapViewOfFileEx((HANDLE)d_handle, // handle to map object
|
||||
FILE_MAP_WRITE, // read/write permission
|
||||
0,
|
||||
0,
|
||||
m_buf_size,
|
||||
first_tmp);
|
||||
if (d_first_copy != first_tmp){
|
||||
CloseHandle(d_handle); // cleanup
|
||||
throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping");
|
||||
}
|
||||
|
||||
d_second_copy = MapViewOfFileEx((HANDLE)d_handle, // handle to map object
|
||||
FILE_MAP_WRITE, // read/write permission
|
||||
0,
|
||||
0,
|
||||
m_buf_size,
|
||||
(char *)first_tmp + m_buf_size);//(LPVOID) ((char *)d_first_copy + size));
|
||||
|
||||
if (d_second_copy != (char *)first_tmp + m_buf_size){
|
||||
UnmapViewOfFile(d_first_copy);
|
||||
CloseHandle(d_handle); // cleanup
|
||||
throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping");
|
||||
}
|
||||
|
||||
// save a pointer to the data
|
||||
m_buf = d_first_copy;// (char *)base + m_pagesize;
|
||||
|
||||
m_r = m_w = 0;
|
||||
m_read = m_written = 0;
|
||||
|
||||
m_item_size = item_size;
|
||||
|
||||
m_overwrite = overwrite;
|
||||
|
||||
pthread_mutex_init(&m_mutex, 0);
|
||||
|
||||
}
|
||||
|
||||
circular_buffer::~circular_buffer() {
|
||||
UnmapViewOfFile(d_first_copy);
|
||||
UnmapViewOfFile(d_second_copy);
|
||||
CloseHandle(d_handle);
|
||||
}
|
||||
#endif
|
||||
#else /* !D_HOST_OSX */
|
||||
|
||||
|
||||
|
|
|
@ -45,6 +45,9 @@
|
|||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
class circular_buffer {
|
||||
public:
|
||||
|
@ -66,6 +69,11 @@ public:
|
|||
unsigned int buf_len();
|
||||
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
HANDLE d_handle;
|
||||
LPVOID d_first_copy;
|
||||
LPVOID d_second_copy;
|
||||
#endif
|
||||
void *m_buf;
|
||||
unsigned int m_buf_len, m_buf_size, m_r, m_w, m_item_size;
|
||||
unsigned long long m_read, m_written;
|
||||
|
|
|
@ -60,6 +60,7 @@ fcch_detector::fcch_detector(const float sample_rate, const unsigned int D,
|
|||
char plan_name[BUFSIZ];
|
||||
const char *home;
|
||||
|
||||
|
||||
m_D = D;
|
||||
m_p = p;
|
||||
m_G = G;
|
||||
|
@ -74,15 +75,15 @@ fcch_detector::fcch_detector(const float sample_rate, const unsigned int D,
|
|||
m_w = new complex[m_w_len];
|
||||
memset(m_w, 0, sizeof(complex) * m_w_len);
|
||||
|
||||
m_x_cb = new circular_buffer(1024, sizeof(complex), 0);
|
||||
m_y_cb = new circular_buffer(1024, sizeof(complex), 1);
|
||||
m_e_cb = new circular_buffer(1000000, sizeof(float), 0);
|
||||
m_x_cb = new circular_buffer(8192, sizeof(complex), 0);
|
||||
m_y_cb = new circular_buffer(8192, sizeof(complex), 1);
|
||||
m_e_cb = new circular_buffer(1015808, sizeof(float), 0);
|
||||
|
||||
m_in = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * FFT_SIZE);
|
||||
m_out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * FFT_SIZE);
|
||||
if((!m_in) || (!m_out))
|
||||
throw std::runtime_error("fcch_detector: fftw_malloc failed!");
|
||||
|
||||
#ifndef _WIN32
|
||||
home = getenv("HOME");
|
||||
if(strlen(home) + strlen(fftw_plan_name) + 2 < sizeof(plan_name)) {
|
||||
strcpy(plan_name, home);
|
||||
|
@ -99,6 +100,7 @@ fcch_detector::fcch_detector(const float sample_rate, const unsigned int D,
|
|||
fclose(plan_fp);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
m_plan = fftw_plan_dft_1d(FFT_SIZE, m_in, m_out, FFTW_FORWARD,
|
||||
FFTW_ESTIMATE);
|
||||
if(!m_plan)
|
||||
|
@ -315,8 +317,7 @@ float fcch_detector::freq_detect(const complex *s, const unsigned int s_len, flo
|
|||
fftw_execute(m_plan);
|
||||
|
||||
for(i = 0; i < FFT_SIZE; i++) {
|
||||
fft[i].real() = m_out[i][0];
|
||||
fft[i].imag() = m_out[i][1];
|
||||
fft[i] = complex(m_out[i][0], m_out[i][1]);
|
||||
}
|
||||
|
||||
max_i = peak_detect(fft, FFT_SIZE, &peak, &avg_power);
|
||||
|
|
|
@ -65,8 +65,8 @@ public:
|
|||
unsigned int x_purge(unsigned int);
|
||||
|
||||
private:
|
||||
static const double GSM_RATE = 1625000.0 / 6.0;
|
||||
static const unsigned int FFT_SIZE = 1024;
|
||||
#define GSM_RATE (1625000.0 / 6.0)
|
||||
#define FFT_SIZE 1024
|
||||
|
||||
unsigned int m_w_len,
|
||||
m_D,
|
||||
|
|
12
src/kal.cc
12
src/kal.cc
|
@ -44,12 +44,15 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#ifdef D_HOST_OSX
|
||||
#include <libgen.h>
|
||||
#endif /* D_HOST_OSX */
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "usrp_source.h"
|
||||
|
@ -58,8 +61,13 @@
|
|||
#include "offset.h"
|
||||
#include "c0_detect.h"
|
||||
#include "version.h"
|
||||
#ifdef _WIN32
|
||||
#include <getopt.h>
|
||||
#define basename(x) "meh"
|
||||
#define strtof strtod
|
||||
#endif
|
||||
|
||||
static const double GSM_RATE = 1625000.0 / 6.0;
|
||||
#define GSM_RATE (1625000.0 / 6.0)
|
||||
|
||||
|
||||
int g_verbosity = 0;
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
#include "fcch_detector.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
inline double round(double x) { return floor(x + 0.5); }
|
||||
#endif
|
||||
|
||||
static const unsigned int AVG_COUNT = 100;
|
||||
static const unsigned int AVG_THRESHOLD = (AVG_COUNT / 10);
|
||||
|
@ -39,7 +42,7 @@ extern int g_verbosity;
|
|||
|
||||
int offset_detect(usrp_source *u) {
|
||||
|
||||
static const double GSM_RATE = 1625000.0 / 6.0;
|
||||
#define GSM_RATE (1625000.0 / 6.0)
|
||||
|
||||
unsigned int new_overruns = 0, overruns = 0;
|
||||
int notfound = 0;
|
||||
|
|
|
@ -28,9 +28,12 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <complex>
|
||||
|
||||
|
@ -39,6 +42,10 @@
|
|||
extern int g_verbosity;
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
inline double round(double x) { return floor(x + 0.5); }
|
||||
#endif
|
||||
|
||||
usrp_source::usrp_source(float sample_rate, long int fpga_master_clock_freq) {
|
||||
|
||||
m_fpga_master_clock_freq = fpga_master_clock_freq;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue