Merge osqzss-master into origin/master.
This commit is contained in:
commit
96faa8df9a
@ -91,7 +91,7 @@ The user motion can be specified in either dynamic or static mode:
|
||||
The TX port of a particular SDR platform is connected to the GPS receiver
|
||||
under test through a DC block and a fixed 50-60dB attenuator.
|
||||
|
||||
#### BladeRF
|
||||
#### BladeRF:
|
||||
|
||||
The simulated GPS signal file, named "gpssim.bin", can be loaded
|
||||
into the bladeRF for playback as shown below:
|
||||
@ -153,5 +153,5 @@ Default 3.0MHz. Applicable range 1.0MHz to 5.0MHz.
|
||||
|
||||
### License
|
||||
|
||||
Copyright © 2015 Takuji Ebinuma
|
||||
Copyright © 2015-2018 Takuji Ebinuma
|
||||
Distributed under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
||||
|
@ -18,8 +18,8 @@ bladeplayer: bladeplayer.o $(SDR_OBJ) $(COMPAT)
|
||||
hackplayer: hackplayer.o $(COMPAT)
|
||||
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS) $(shell pkg-config --libs libhackrf)
|
||||
|
||||
limeplayer: limeplayer.o $(COMPAT)
|
||||
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS) -lLimeSuite
|
||||
limeplayer: limeplayer.c
|
||||
gcc -O2 -Wall -o limeplayer limeplayer.c -lLimeSuite
|
||||
|
||||
plutoplayer: plutoplayer.o $(COMPAT)
|
||||
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS) $(shell pkg-config --libs libiio libad9361)
|
||||
|
@ -1,72 +1,49 @@
|
||||
## Building
|
||||
## How to build the player software on Linux
|
||||
|
||||
Modified to build on Linux.
|
||||
### bladeRF
|
||||
|
||||
```
|
||||
$ make all
|
||||
```
|
||||
Will build all players if dependencies are met.
|
||||
#### Build and install libbladeRF
|
||||
|
||||
### Dependencies - bladeRF
|
||||
#### libbladeRF
|
||||
```
|
||||
$ git clone https://github.com/Nuand/bladeRF.git
|
||||
$ cd bladeRF
|
||||
$ dpkg-buildpackage -b
|
||||
```
|
||||
Or Nuand has some build/install instructions including an Ubuntu PPA
|
||||
at https://github.com/Nuand/bladeRF/wiki/Getting-Started:-Linux
|
||||
https://github.com/Nuand/bladeRF/wiki/Getting-Started:-Linux
|
||||
|
||||
#### Build
|
||||
#### Build bladeplayer
|
||||
|
||||
```
|
||||
$ make bladeplayer
|
||||
```
|
||||
|
||||
### Dependecies - hackRF
|
||||
#### libhackrf
|
||||
### HackRF One
|
||||
|
||||
#### Build and install libhackrf
|
||||
|
||||
https://github.com/mossmann/hackrf/tree/master/host
|
||||
|
||||
#### Build hackplayer
|
||||
|
||||
```
|
||||
> git clone https://github.com/mossmann/hackrf.git
|
||||
> mkdir hackrf/host/build
|
||||
> cd hackrf/host/build
|
||||
> cmake ..
|
||||
> make
|
||||
> sudo make install
|
||||
> sudo ldconfig
|
||||
```
|
||||
Build instructions https://github.com/mossmann/hackrf/tree/master/host
|
||||
|
||||
#### Build
|
||||
|
||||
```
|
||||
> make hackplayer
|
||||
$ make hackplayer
|
||||
```
|
||||
|
||||
### Dependecies - lime
|
||||
### LimeSDR
|
||||
|
||||
LimeSuite https://github.com/myriadrf/LimeSuite
|
||||
#### Build and install libLimeSuite
|
||||
|
||||
Build instructions http://wiki.myriadrf.org/Lime_Suite
|
||||
http://wiki.myriadrf.org/Lime_Suite
|
||||
|
||||
:exclamation: Build not tested.
|
||||
#### Build limeplayer
|
||||
|
||||
### Dependecies - ADALM-Pluto
|
||||
#### libiio
|
||||
|
||||
Use the latest version from Github.
|
||||
```
|
||||
$ git clone https://github.com/analogdevicesinc/libiio.git
|
||||
$ cd libiio
|
||||
$ cmake ./
|
||||
$ make all
|
||||
$ sudo make install
|
||||
$ make limeplayer
|
||||
```
|
||||
[How to build it in detail.](https://wiki.analog.com/resources/tools-software/linux-software/libiio)
|
||||
|
||||
#### libad9361
|
||||
### ADALM-Pluto
|
||||
|
||||
#### Build and install libiio
|
||||
|
||||
https://wiki.analog.com/resources/tools-software/linux-software/libiio
|
||||
|
||||
#### Build and insatall libad9361
|
||||
|
||||
Use of the latest Github version mandatory.
|
||||
```
|
||||
$ git clone https://github.com/analogdevicesinc/libad9361-iio.git
|
||||
$ cd libad9361-iio
|
||||
@ -75,7 +52,7 @@ $ make all
|
||||
$ sudo make install
|
||||
```
|
||||
|
||||
#### Build
|
||||
#### Build plutoplayer
|
||||
|
||||
```
|
||||
$ make plutoplayer
|
||||
|
@ -4,8 +4,13 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libbladeRF.h>
|
||||
#ifdef _WIN32
|
||||
#include "getopt.h"
|
||||
#else
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#define TX_FREQUENCY 1575420000
|
||||
#define TX_SAMPLERATE 2600000
|
||||
@ -20,27 +25,25 @@
|
||||
|
||||
#define AMPLITUDE (1000) // Default amplitude for 12-bit I/Q
|
||||
|
||||
void usage(void) {
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: bladeplayer [options]\n"
|
||||
" -f <tx_file> I/Q sampling data file (required)\n"
|
||||
" -b <iq_bits> I/Q data format [1/16] (default: 16)\n"
|
||||
" -g <tx_vga1> TX VGA1 gain (default: %d)\n",
|
||||
TX_VGA1);
|
||||
" -f <tx_file> I/Q sampling data file (required)\n"
|
||||
" -b <iq_bits> I/Q data format [1/16] (default: 16)\n"
|
||||
" -g <tx_vga1> TX VGA1 gain (default: %d)\n",
|
||||
TX_VGA1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int status;
|
||||
char *devstr = NULL;
|
||||
struct bladerf *dev = NULL;
|
||||
|
||||
FILE *fp;
|
||||
int16_t *tx_buffer;
|
||||
|
||||
enum state {
|
||||
INIT, READ_FILE, PAD_TRAILING, DONE
|
||||
};
|
||||
enum state {INIT, READ_FILE, PAD_TRAILING, DONE};
|
||||
enum state state = INIT;
|
||||
|
||||
int compressed = 0;
|
||||
@ -48,7 +51,7 @@ int main(int argc, char *argv[]) {
|
||||
size_t samples_read;
|
||||
int16_t lut[256][8];
|
||||
int16_t amp = AMPLITUDE;
|
||||
uint32_t i, k;
|
||||
uint32_t i,k;
|
||||
|
||||
int gain = TX_VGA1;
|
||||
int result;
|
||||
@ -58,49 +61,55 @@ int main(int argc, char *argv[]) {
|
||||
// Empty TX file name
|
||||
txfile[0] = 0;
|
||||
|
||||
if (argc < 3) {
|
||||
if (argc<3) {
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while ((result = getopt(argc, argv, "g:b:f:")) != -1) {
|
||||
switch (result) {
|
||||
case 'g':
|
||||
gain = atoi(optarg);
|
||||
if (gain>-4 || gain<-35) {
|
||||
printf("ERROR: Invalid TX VGA1 gain.\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
data_format = atoi(optarg);
|
||||
if (data_format != 1 && data_format != 16) {
|
||||
printf("ERROR: Invalid I/Q data format.\n");
|
||||
exit(1);
|
||||
} else if (data_format == 1)
|
||||
compressed = 1;
|
||||
break;
|
||||
case 'f':
|
||||
strcpy(txfile, optarg);
|
||||
break;
|
||||
case ':':
|
||||
case '?':
|
||||
usage();
|
||||
while ((result=getopt(argc,argv,"g:b:f:"))!=-1)
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case 'g':
|
||||
gain = atoi(optarg);
|
||||
if (gain>-4 || gain<-35)
|
||||
{
|
||||
printf("ERROR: Invalid TX VGA1 gain.\n");
|
||||
exit(1);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
data_format = atoi(optarg);
|
||||
if (data_format!=1 && data_format!=16)
|
||||
{
|
||||
printf("ERROR: Invalid I/Q data format.\n");
|
||||
exit(1);
|
||||
}
|
||||
else if (data_format==1)
|
||||
compressed = 1;
|
||||
break;
|
||||
case 'f':
|
||||
strcpy(txfile, optarg);
|
||||
break;
|
||||
case ':':
|
||||
case '?':
|
||||
usage();
|
||||
exit(1);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Open TX file.
|
||||
if (txfile[0] == 0) {
|
||||
if (txfile[0]==0)
|
||||
{
|
||||
printf("ERROR: I/Q sampling data file is not specified.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fp = fopen(txfile, "rb");
|
||||
|
||||
if (fp == NULL) {
|
||||
if (fp==NULL) {
|
||||
fprintf(stderr, "ERROR: Failed to open TX file: %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
@ -127,7 +136,8 @@ int main(int argc, char *argv[]) {
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "Failed to set TX sample rate: %s\n", bladerf_strerror(status));
|
||||
goto out;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printf("TX sample rate: %u sps\n", TX_SAMPLERATE);
|
||||
}
|
||||
|
||||
@ -135,7 +145,8 @@ int main(int argc, char *argv[]) {
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "Failed to set TX bandwidth: %s\n", bladerf_strerror(status));
|
||||
goto out;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printf("TX bandwidth: %u Hz\n", TX_BANDWIDTH);
|
||||
}
|
||||
|
||||
@ -143,7 +154,8 @@ int main(int argc, char *argv[]) {
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "Failed to set TX VGA1 gain: %s\n", bladerf_strerror(status));
|
||||
goto out;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printf("TX VGA1 gain: %d dB\n", gain);
|
||||
}
|
||||
|
||||
@ -151,7 +163,8 @@ int main(int argc, char *argv[]) {
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "Failed to set TX VGA2 gain: %s\n", bladerf_strerror(status));
|
||||
goto out;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printf("TX VGA2 gain: %d dB\n", TX_VGA2);
|
||||
}
|
||||
|
||||
@ -159,7 +172,7 @@ int main(int argc, char *argv[]) {
|
||||
printf("Running...\n");
|
||||
|
||||
// Allocate a buffer to hold each block of samples to transmit.
|
||||
tx_buffer = (int16_t*) malloc(SAMPLES_PER_BUFFER * 2 * sizeof (int16_t));
|
||||
tx_buffer = (int16_t*)malloc(SAMPLES_PER_BUFFER * 2 * sizeof(int16_t));
|
||||
|
||||
if (tx_buffer == NULL) {
|
||||
fprintf(stderr, "Failed to allocate TX buffer.\n");
|
||||
@ -167,16 +180,17 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
// if compressed
|
||||
read_buffer = (uint8_t*) malloc(SAMPLES_PER_BUFFER / 4);
|
||||
read_buffer = (uint8_t*)malloc(SAMPLES_PER_BUFFER / 4);
|
||||
|
||||
if (read_buffer == NULL) {
|
||||
fprintf(stderr, "Failed to allocate read buffer.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
for (k = 0; k < 8; k++)
|
||||
lut[i][k] = ((i >> (7 - k))&0x1) ? amp : -amp;
|
||||
for (i=0; i<256; i++)
|
||||
{
|
||||
for (k=0; k<8; k++)
|
||||
lut[i][k] = ((i>>(7-k))&0x1)?amp:-amp;
|
||||
}
|
||||
|
||||
// Configure the TX module for use with the synchronous interface.
|
||||
@ -213,15 +227,16 @@ int main(int argc, char *argv[]) {
|
||||
while (buffer_samples_remaining > 0 && status == 0 && state != DONE) {
|
||||
size_t samples_populated = 0;
|
||||
|
||||
switch (state) {
|
||||
switch(state) {
|
||||
case INIT:
|
||||
case READ_FILE:
|
||||
// Read from the input file
|
||||
if (compressed) {
|
||||
if (compressed)
|
||||
{
|
||||
int16_t *write_buffer_current = tx_buffer;
|
||||
|
||||
samples_read = fread(read_buffer,
|
||||
sizeof (uint8_t),
|
||||
sizeof(uint8_t),
|
||||
read_samples_remaining,
|
||||
fp);
|
||||
|
||||
@ -229,15 +244,18 @@ int main(int argc, char *argv[]) {
|
||||
buffer_samples_remaining = read_samples_remaining * 4;
|
||||
|
||||
// Expand compressed data into TX buffer
|
||||
for (i = 0; i < samples_read; i++) {
|
||||
for (i=0; i<samples_read; i++)
|
||||
{
|
||||
memcpy(write_buffer_current, lut[read_buffer[i]], 8);
|
||||
|
||||
// Advance the write buffer pointer
|
||||
write_buffer_current += 8;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
samples_populated = fread(tx_buffer_current,
|
||||
2 * sizeof (int16_t),
|
||||
2 * sizeof(int16_t),
|
||||
buffer_samples_remaining,
|
||||
fp);
|
||||
}
|
||||
@ -245,7 +263,8 @@ int main(int argc, char *argv[]) {
|
||||
// If the end of the file was reached, pad the rest of the buffer and finish.
|
||||
if (feof(fp)) {
|
||||
state = PAD_TRAILING;
|
||||
} // Check for errors
|
||||
}
|
||||
// Check for errors
|
||||
else if (ferror(fp)) {
|
||||
status = errno;
|
||||
}
|
||||
@ -254,7 +273,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
case PAD_TRAILING:
|
||||
// Populate the remainder of the buffer with zeros.
|
||||
memset(tx_buffer_current, 0, buffer_samples_remaining * 2 * sizeof (uint16_t));
|
||||
memset(tx_buffer_current, 0, buffer_samples_remaining * 2 * sizeof(uint16_t));
|
||||
|
||||
state = DONE;
|
||||
break;
|
||||
@ -265,7 +284,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
// Advance the buffer pointer.
|
||||
buffer_samples_remaining -= (unsigned int) samples_populated;
|
||||
buffer_samples_remaining -= (unsigned int)samples_populated;
|
||||
tx_buffer_current += (2 * samples_populated);
|
||||
}
|
||||
|
||||
@ -294,5 +313,5 @@ out:
|
||||
printf("Closing device...\n");
|
||||
bladerf_close(dev);
|
||||
|
||||
return (0);
|
||||
return(0);
|
||||
}
|
||||
|
@ -1,10 +1,25 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#ifdef _WIN64
|
||||
typedef int64_t ssize_t;
|
||||
#else
|
||||
typedef int32_t ssize_t;
|
||||
#endif
|
||||
typedef int bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#include "getopt.h"
|
||||
#else
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
#include <hackrf.h>
|
||||
#endif
|
||||
#include <libhackrf/hackrf.h>
|
||||
|
||||
static hackrf_device* device = NULL;
|
||||
|
||||
@ -13,19 +28,34 @@ volatile uint32_t byte_count = 0;
|
||||
|
||||
volatile bool do_exit = false;
|
||||
|
||||
//static transceiver_mode_t transceiver_mode = TRANSCEIVER_MODE_TX;
|
||||
|
||||
#define FD_BUFFER_SIZE (8*1024)
|
||||
#define FREQ_ONE_MHZ (1000000ull)
|
||||
|
||||
#ifdef _WIN32
|
||||
BOOL WINAPI sighandler(int signum)
|
||||
{
|
||||
if(CTRL_C_EVENT == signum) {
|
||||
fprintf(stdout, "Caught signal %d\n", signum);
|
||||
do_exit = true;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
#else
|
||||
static void sighandler(int signum) {
|
||||
fprintf(stdout, "Caught signal %d\n", signum);
|
||||
do_exit = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
int tx_callback(hackrf_transfer* transfer) {
|
||||
size_t bytes_to_read;
|
||||
|
||||
if (fd != NULL) {
|
||||
size_t bytes_read;
|
||||
if( fd != NULL )
|
||||
{
|
||||
ssize_t bytes_read;
|
||||
byte_count += transfer->valid_length;
|
||||
bytes_to_read = transfer->valid_length;
|
||||
|
||||
@ -43,7 +73,7 @@ int tx_callback(hackrf_transfer* transfer) {
|
||||
|
||||
static void usage() {
|
||||
fprintf(stderr, "Usage: hackplayer [options]\n"
|
||||
" -t <filename> Transmit data from file (required)\n");
|
||||
" -t <filename> Transmit data from file (required)\n");
|
||||
|
||||
return;
|
||||
}
|
||||
@ -54,30 +84,32 @@ int main(int argc, char** argv) {
|
||||
const char* path = NULL;
|
||||
uint32_t sample_rate_hz = 2600000;
|
||||
uint32_t baseband_filter_bw_hz = 0;
|
||||
unsigned int txvga_gain = 0;
|
||||
unsigned int txvga_gain=0;
|
||||
uint64_t freq_hz = 1575420000;
|
||||
uint32_t amp_enable = 1;
|
||||
|
||||
while ((opt = getopt(argc, argv, "t:")) != EOF) {
|
||||
while( (opt = getopt(argc, argv, "t:")) != EOF )
|
||||
{
|
||||
result = HACKRF_SUCCESS;
|
||||
switch (opt) {
|
||||
case 't':
|
||||
path = optarg;
|
||||
break;
|
||||
default:
|
||||
printf("unknown argument '-%c %s'\n", opt, optarg);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
switch( opt )
|
||||
{
|
||||
case 't':
|
||||
path = optarg;
|
||||
break;
|
||||
default:
|
||||
printf("unknown argument '-%c %s'\n", opt, optarg);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("argument error: '-%c %s' %s (%d)\n", opt, optarg, hackrf_error_name(result), result);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (path == NULL) {
|
||||
if( path == NULL ) {
|
||||
printf("specify a path to a file to transmit\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
@ -87,47 +119,51 @@ int main(int argc, char** argv) {
|
||||
baseband_filter_bw_hz = hackrf_compute_baseband_filter_bw_round_down_lt(sample_rate_hz);
|
||||
|
||||
result = hackrf_init();
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = hackrf_open_by_serial(NULL, &device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fd = fopen(path, "rb");
|
||||
if (fd == NULL) {
|
||||
if( fd == NULL ) {
|
||||
printf("Failed to open file: %s\n", path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Change fd buffer to have bigger one to store or read data on/to HDD
|
||||
result = setvbuf(fd, NULL, _IOFBF, FD_BUFFER_SIZE);
|
||||
if (result != 0) {
|
||||
result = setvbuf(fd , NULL , _IOFBF , FD_BUFFER_SIZE);
|
||||
if( result != 0 ) {
|
||||
printf("setvbuf() failed: %d\n", result);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE );
|
||||
#else
|
||||
signal(SIGINT, sighandler);
|
||||
#endif
|
||||
|
||||
printf("call hackrf_sample_rate_set(%.03f MHz)\n", ((float) sample_rate_hz / (float) FREQ_ONE_MHZ));
|
||||
printf("call hackrf_sample_rate_set(%.03f MHz)\n", ((float)sample_rate_hz/(float)FREQ_ONE_MHZ));
|
||||
result = hackrf_set_sample_rate_manual(device, sample_rate_hz, 1);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("hackrf_sample_rate_set() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("call hackrf_baseband_filter_bandwidth_set(%.03f MHz)\n",
|
||||
((float) baseband_filter_bw_hz / (float) FREQ_ONE_MHZ));
|
||||
((float)baseband_filter_bw_hz/(float)FREQ_ONE_MHZ));
|
||||
result = hackrf_set_baseband_filter_bandwidth(device, baseband_filter_bw_hz);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("hackrf_baseband_filter_bandwidth_set() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
@ -136,30 +172,30 @@ int main(int argc, char** argv) {
|
||||
result = hackrf_set_txvga_gain(device, txvga_gain);
|
||||
result |= hackrf_start_tx(device, tx_callback, NULL);
|
||||
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("hackrf_start_?x() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("call hackrf_set_freq(%.03f MHz)\n", ((double) freq_hz / (double) FREQ_ONE_MHZ));
|
||||
printf("call hackrf_set_freq(%.03f MHz)\n", ((double)freq_hz/(double)FREQ_ONE_MHZ));
|
||||
result = hackrf_set_freq(device, freq_hz);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("hackrf_set_freq() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("call hackrf_set_amp_enable(%u)\n", amp_enable);
|
||||
result = hackrf_set_amp_enable(device, (uint8_t) amp_enable);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
result = hackrf_set_amp_enable(device, (uint8_t)amp_enable);
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("hackrf_set_amp_enable() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Stop with Ctrl-C\n");
|
||||
while ((hackrf_is_streaming(device) == HACKRF_TRUE) && (do_exit == false)) {
|
||||
while( (hackrf_is_streaming(device) == HACKRF_TRUE) && (do_exit == false) ) {
|
||||
// Show something?
|
||||
}
|
||||
|
||||
@ -170,16 +206,17 @@ int main(int argc, char** argv) {
|
||||
printf("\nExiting... hackrf_is_streaming() result: %s (%d)\n", hackrf_error_name(result), result);
|
||||
}
|
||||
|
||||
if (device != NULL) {
|
||||
if(device != NULL) {
|
||||
result = hackrf_stop_tx(device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("hackrf_stop_tx() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
} else {
|
||||
printf("hackrf_stop_tx() done\n");
|
||||
}
|
||||
|
||||
result = hackrf_close(device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
if( result != HACKRF_SUCCESS )
|
||||
{
|
||||
printf("hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
} else {
|
||||
printf("hackrf_close() done\n");
|
||||
@ -189,7 +226,7 @@ int main(int argc, char** argv) {
|
||||
printf("hackrf_exit() done\n");
|
||||
}
|
||||
|
||||
if (fd != NULL) {
|
||||
if(fd != NULL) {
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
printf("fclose(fd) done\n");
|
||||
|
@ -27,11 +27,11 @@
|
||||
static int control_c_received = 0;
|
||||
|
||||
static void control_c_handler (int sig, siginfo_t *siginfo, void *context){
|
||||
control_c_received = 1;
|
||||
control_c_received = 1;
|
||||
}
|
||||
|
||||
static void print_usage(const char *progname){
|
||||
printf("Usage: %s [option] < file" "\n"
|
||||
printf("Usage: %s [option] < file" "\n"
|
||||
"\t" "-g <gain> or --gain <gain> with gain in [0.0 .. 1.0] set the so-called normalized RF gain in LimeSDR (default: 1.0 max RF power)" "\n"
|
||||
"\t" "-c <channel> or --channel <channel> with channel either 0 or 1 (default: 0)" "\n"
|
||||
"\t" "-a <antenna> or --antenna <antenna> with antenna in { 0, 1, 2 } (default:" STRINGIFY(DEFAULT_ANTENNA) ")" "\n"
|
||||
@ -39,53 +39,53 @@ static void print_usage(const char *progname){
|
||||
"\t" "-b <bits> or --bits <bits> select bit count in IQ sample in { 1, 8, 12, 16 }, (default: 16)" "\n"
|
||||
"\t" "-s <samplerate> or --samplerate <samplerate> configure BB sample rate (default: " STRINGIFY(TX_SAMPLERATE) ")" "\n"
|
||||
"\t" "-d <dynamic> --dynamic <dynamic> configure dynamic for the 1-bit mode (default: 2047, max 12-bit signed value supported by LimeSDR)" "\n"
|
||||
"Example:" "\n"
|
||||
"\t" "./limeplayer -s 1000000 -b 1 -d 1023 -g 0.1 < ../circle.1b.1M.bin" "\n", progname);
|
||||
exit(0);
|
||||
"Example:" "\n"
|
||||
"\t" "./limeplayer -s 1000000 -b 1 -d 1023 -g 0.1 < ../circle.1b.1M.bin" "\n", progname);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int argc, char *const argv[]){
|
||||
struct sigaction control_c;
|
||||
struct sigaction control_c;
|
||||
|
||||
memset(&control_c, 0, sizeof(control_c));
|
||||
control_c.sa_sigaction = &control_c_handler;
|
||||
memset(&control_c, 0, sizeof(control_c));
|
||||
control_c.sa_sigaction = &control_c_handler;
|
||||
|
||||
/* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
|
||||
control_c.sa_flags = SA_SIGINFO;
|
||||
/* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
|
||||
control_c.sa_flags = SA_SIGINFO;
|
||||
|
||||
if (sigaction(SIGTERM, &control_c, NULL) < 0) {
|
||||
perror ("sigaction");
|
||||
return(EXIT_CODE_CONTROL_C);
|
||||
}
|
||||
if (sigaction(SIGQUIT, &control_c, NULL) < 0) {
|
||||
perror ("sigaction");
|
||||
return(EXIT_CODE_CONTROL_C);
|
||||
}
|
||||
if (sigaction(SIGINT, &control_c, NULL) < 0) {
|
||||
perror ("sigaction");
|
||||
return(EXIT_CODE_CONTROL_C);
|
||||
}
|
||||
if (sigaction(SIGTERM, &control_c, NULL) < 0) {
|
||||
perror ("sigaction");
|
||||
return(EXIT_CODE_CONTROL_C);
|
||||
}
|
||||
if (sigaction(SIGQUIT, &control_c, NULL) < 0) {
|
||||
perror ("sigaction");
|
||||
return(EXIT_CODE_CONTROL_C);
|
||||
}
|
||||
if (sigaction(SIGINT, &control_c, NULL) < 0) {
|
||||
perror ("sigaction");
|
||||
return(EXIT_CODE_CONTROL_C);
|
||||
}
|
||||
|
||||
int device_count = LMS_GetDeviceList(NULL);
|
||||
if(device_count < 1){
|
||||
return(EXIT_CODE_NO_DEVICE);
|
||||
}
|
||||
lms_info_str_t *device_list = malloc(sizeof(lms_info_str_t) * device_count);
|
||||
device_count = LMS_GetDeviceList(device_list);
|
||||
int device_count = LMS_GetDeviceList(NULL);
|
||||
if(device_count < 1){
|
||||
return(EXIT_CODE_NO_DEVICE);
|
||||
}
|
||||
lms_info_str_t *device_list = malloc(sizeof(lms_info_str_t) * device_count);
|
||||
device_count = LMS_GetDeviceList(device_list);
|
||||
|
||||
int i = 0;
|
||||
while(i < device_count){
|
||||
// printf("device[%d/%d]=%s" "\n", i + 1, device_count, device_list[i]);
|
||||
i++;
|
||||
}
|
||||
int i = 0;
|
||||
while(i < device_count){
|
||||
// printf("device[%d/%d]=%s" "\n", i + 1, device_count, device_list[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
double gain = 1.0;
|
||||
int32_t antenna = DEFAULT_ANTENNA;
|
||||
int32_t channel = 0;
|
||||
int32_t index = 0;
|
||||
int32_t bits = 16;
|
||||
double sampleRate = TX_SAMPLERATE;
|
||||
int32_t dynamic = 2047;
|
||||
double gain = 1.0;
|
||||
int32_t antenna = DEFAULT_ANTENNA;
|
||||
int32_t channel = 0;
|
||||
int32_t index = 0;
|
||||
int32_t bits = 16;
|
||||
double sampleRate = TX_SAMPLERATE;
|
||||
int32_t dynamic = 2047;
|
||||
|
||||
while (1) {
|
||||
int option_index = 0;
|
||||
@ -109,7 +109,7 @@ int main(int argc, char *const argv[]){
|
||||
#if 1
|
||||
fprintf(stderr, "option %s", long_options[option_index].name);
|
||||
if (optarg)
|
||||
fprintf(stderr, " with arg %s", optarg);
|
||||
fprintf(stderr, " with arg %s", optarg);
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
|
||||
@ -130,272 +130,272 @@ int main(int argc, char *const argv[]){
|
||||
case 'i':
|
||||
index = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 's':
|
||||
sampleRate = strtod(optarg, NULL);
|
||||
break;
|
||||
case 'd':
|
||||
dynamic = strtol(optarg, NULL, 0);
|
||||
if(dynamic > 2047){
|
||||
dynamic = 2047;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
print_usage(argv[0]);
|
||||
break;
|
||||
case 's':
|
||||
sampleRate = strtod(optarg, NULL);
|
||||
break;
|
||||
case 'd':
|
||||
dynamic = strtol(optarg, NULL, 0);
|
||||
if(dynamic > 2047){
|
||||
dynamic = 2047;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
print_usage(argv[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Use correct values
|
||||
// Use existing device
|
||||
if(index < 0){
|
||||
index = 0;
|
||||
}
|
||||
if(index >= device_count){
|
||||
index = 0;
|
||||
}
|
||||
printf("Using device index %d [%s]" "\n", index, device_list[index]);
|
||||
// Use correct values
|
||||
// Use existing device
|
||||
if(index < 0){
|
||||
index = 0;
|
||||
}
|
||||
if(index >= device_count){
|
||||
index = 0;
|
||||
}
|
||||
printf("Using device index %d [%s]" "\n", index, device_list[index]);
|
||||
|
||||
// Normalized gain shall be in [0.0 .. 1.0]
|
||||
if(gain < 0.0){
|
||||
gain = 0.0;
|
||||
}
|
||||
if(gain > 1.0){
|
||||
gain = 1.0;
|
||||
}
|
||||
printf("Using normalized gain %lf" "\n", gain);
|
||||
// Normalized gain shall be in [0.0 .. 1.0]
|
||||
if(gain < 0.0){
|
||||
gain = 0.0;
|
||||
}
|
||||
if(gain > 1.0){
|
||||
gain = 1.0;
|
||||
}
|
||||
printf("Using normalized gain %lf" "\n", gain);
|
||||
|
||||
|
||||
lms_device_t *device = NULL;
|
||||
lms_device_t *device = NULL;
|
||||
|
||||
if(LMS_Open(&device, device_list[index], NULL)){
|
||||
return(EXIT_CODE_LMS_OPEN);
|
||||
}
|
||||
if(LMS_Open(&device, device_list[index], NULL)){
|
||||
return(EXIT_CODE_LMS_OPEN);
|
||||
}
|
||||
|
||||
int lmsReset = LMS_Reset(device);
|
||||
if(lmsReset){
|
||||
printf("lmsReset %d(%s)" "\n", lmsReset, LMS_GetLastErrorMessage());
|
||||
}
|
||||
int lmsInit = LMS_Init(device);
|
||||
if(lmsInit){
|
||||
printf("lmsInit %d(%s)" "\n", lmsInit, LMS_GetLastErrorMessage());
|
||||
}
|
||||
int lmsReset = LMS_Reset(device);
|
||||
if(lmsReset){
|
||||
printf("lmsReset %d(%s)" "\n", lmsReset, LMS_GetLastErrorMessage());
|
||||
}
|
||||
int lmsInit = LMS_Init(device);
|
||||
if(lmsInit){
|
||||
printf("lmsInit %d(%s)" "\n", lmsInit, LMS_GetLastErrorMessage());
|
||||
}
|
||||
|
||||
int channel_count = LMS_GetNumChannels(device, LMS_CH_TX);
|
||||
// printf("Tx channel count %d" "\n", channel_count);
|
||||
if(channel < 0){
|
||||
channel = 0;
|
||||
}
|
||||
if(channel >= channel_count){
|
||||
channel = 0;
|
||||
}
|
||||
printf("Using channel %d" "\n", channel);
|
||||
int channel_count = LMS_GetNumChannels(device, LMS_CH_TX);
|
||||
// printf("Tx channel count %d" "\n", channel_count);
|
||||
if(channel < 0){
|
||||
channel = 0;
|
||||
}
|
||||
if(channel >= channel_count){
|
||||
channel = 0;
|
||||
}
|
||||
printf("Using channel %d" "\n", channel);
|
||||
|
||||
int antenna_count = LMS_GetAntennaList(device, LMS_CH_TX, channel, NULL);
|
||||
// printf("TX%d Channel has %d antenna(ae)" "\n", channel, antenna_count);
|
||||
lms_name_t antenna_name[antenna_count];
|
||||
if(antenna_count > 0){
|
||||
int i = 0;
|
||||
lms_range_t antenna_bw[antenna_count];
|
||||
LMS_GetAntennaList(device, LMS_CH_TX, channel, antenna_name);
|
||||
for(i = 0 ; i < antenna_count ; i++){
|
||||
LMS_GetAntennaBW(device, LMS_CH_TX, channel, i, antenna_bw + i);
|
||||
// printf("Channel %d, antenna [%s] has BW [%lf .. %lf] (step %lf)" "\n", channel, antenna_name[i], antenna_bw[i].min, antenna_bw[i].max, antenna_bw[i].step);
|
||||
}
|
||||
}
|
||||
if(antenna < 0){
|
||||
antenna = DEFAULT_ANTENNA;
|
||||
}
|
||||
if(antenna >= antenna_count){
|
||||
antenna = DEFAULT_ANTENNA;
|
||||
}
|
||||
// LMS_SetAntenna(device, LMS_CH_TX, channel, antenna); // SetLOFrequency should take care of selecting the proper antenna
|
||||
int antenna_count = LMS_GetAntennaList(device, LMS_CH_TX, channel, NULL);
|
||||
// printf("TX%d Channel has %d antenna(ae)" "\n", channel, antenna_count);
|
||||
lms_name_t antenna_name[antenna_count];
|
||||
if(antenna_count > 0){
|
||||
int i = 0;
|
||||
lms_range_t antenna_bw[antenna_count];
|
||||
LMS_GetAntennaList(device, LMS_CH_TX, channel, antenna_name);
|
||||
for(i = 0 ; i < antenna_count ; i++){
|
||||
LMS_GetAntennaBW(device, LMS_CH_TX, channel, i, antenna_bw + i);
|
||||
// printf("Channel %d, antenna [%s] has BW [%lf .. %lf] (step %lf)" "\n", channel, antenna_name[i], antenna_bw[i].min, antenna_bw[i].max, antenna_bw[i].step);
|
||||
}
|
||||
}
|
||||
if(antenna < 0){
|
||||
antenna = DEFAULT_ANTENNA;
|
||||
}
|
||||
if(antenna >= antenna_count){
|
||||
antenna = DEFAULT_ANTENNA;
|
||||
}
|
||||
// LMS_SetAntenna(device, LMS_CH_TX, channel, antenna); // SetLOFrequency should take care of selecting the proper antenna
|
||||
|
||||
LMS_SetNormalizedGain(device, LMS_CH_TX, channel, gain);
|
||||
// Disable all other channels
|
||||
LMS_EnableChannel(device, LMS_CH_TX, 1 - channel, false);
|
||||
LMS_EnableChannel(device, LMS_CH_RX, 0, false);
|
||||
LMS_EnableChannel(device, LMS_CH_RX, 1, false);
|
||||
// Enable our Tx channel
|
||||
LMS_EnableChannel(device, LMS_CH_TX, channel, true);
|
||||
LMS_SetNormalizedGain(device, LMS_CH_TX, channel, gain);
|
||||
// Disable all other channels
|
||||
LMS_EnableChannel(device, LMS_CH_TX, 1 - channel, false);
|
||||
LMS_EnableChannel(device, LMS_CH_RX, 0, false);
|
||||
LMS_EnableChannel(device, LMS_CH_RX, 1, false);
|
||||
// Enable our Tx channel
|
||||
LMS_EnableChannel(device, LMS_CH_TX, channel, true);
|
||||
|
||||
int setLOFrequency = LMS_SetLOFrequency(device, LMS_CH_TX, channel, TX_FREQUENCY);
|
||||
if(setLOFrequency){
|
||||
printf("setLOFrequency(%lf)=%d(%s)" "\n", TX_FREQUENCY, setLOFrequency, LMS_GetLastErrorMessage());
|
||||
}
|
||||
int setLOFrequency = LMS_SetLOFrequency(device, LMS_CH_TX, channel, TX_FREQUENCY);
|
||||
if(setLOFrequency){
|
||||
printf("setLOFrequency(%lf)=%d(%s)" "\n", TX_FREQUENCY, setLOFrequency, LMS_GetLastErrorMessage());
|
||||
}
|
||||
|
||||
#ifdef __USE_LPF__
|
||||
lms_range_t LPFBWRange;
|
||||
LMS_GetLPFBWRange(device, LMS_CH_TX, &LPFBWRange);
|
||||
// printf("TX%d LPFBW [%lf .. %lf] (step %lf)" "\n", channel, LPFBWRange.min, LPFBWRange.max, LPFBWRange.step);
|
||||
double LPFBW = TX_BANDWIDTH;
|
||||
if(LPFBW < LPFBWRange.min){
|
||||
LPFBW = LPFBWRange.min;
|
||||
}
|
||||
if(LPFBW > LPFBWRange.max){
|
||||
LPFBW = LPFBWRange.min;
|
||||
}
|
||||
int setLPFBW = LMS_SetLPFBW(device, LMS_CH_TX, channel, LPFBW);
|
||||
if(setLPFBW){
|
||||
printf("setLPFBW(%lf)=%d(%s)" "\n", LPFBW, setLPFBW, LMS_GetLastErrorMessage());
|
||||
}
|
||||
int enableLPF = LMS_SetLPF(device, LMS_CH_TX, channel, true);
|
||||
if(enableLPF){
|
||||
printf("enableLPF=%d(%s)" "\n", enableLPF, LMS_GetLastErrorMessage());
|
||||
}
|
||||
lms_range_t LPFBWRange;
|
||||
LMS_GetLPFBWRange(device, LMS_CH_TX, &LPFBWRange);
|
||||
// printf("TX%d LPFBW [%lf .. %lf] (step %lf)" "\n", channel, LPFBWRange.min, LPFBWRange.max, LPFBWRange.step);
|
||||
double LPFBW = TX_BANDWIDTH;
|
||||
if(LPFBW < LPFBWRange.min){
|
||||
LPFBW = LPFBWRange.min;
|
||||
}
|
||||
if(LPFBW > LPFBWRange.max){
|
||||
LPFBW = LPFBWRange.min;
|
||||
}
|
||||
int setLPFBW = LMS_SetLPFBW(device, LMS_CH_TX, channel, LPFBW);
|
||||
if(setLPFBW){
|
||||
printf("setLPFBW(%lf)=%d(%s)" "\n", LPFBW, setLPFBW, LMS_GetLastErrorMessage());
|
||||
}
|
||||
int enableLPF = LMS_SetLPF(device, LMS_CH_TX, channel, true);
|
||||
if(enableLPF){
|
||||
printf("enableLPF=%d(%s)" "\n", enableLPF, LMS_GetLastErrorMessage());
|
||||
}
|
||||
#endif
|
||||
|
||||
lms_range_t sampleRateRange;
|
||||
int getSampleRateRange = LMS_GetSampleRateRange(device, LMS_CH_TX, &sampleRateRange);
|
||||
if(getSampleRateRange){
|
||||
printf("getSampleRateRange=%d(%s)" "\n", getSampleRateRange, LMS_GetLastErrorMessage());
|
||||
}else{
|
||||
// printf("sampleRateRange [%lf MHz.. %lf MHz] (step=%lf Hz)" "\n", sampleRateRange.min / 1e6, sampleRateRange.max / 1e6, sampleRateRange.step);
|
||||
}
|
||||
lms_range_t sampleRateRange;
|
||||
int getSampleRateRange = LMS_GetSampleRateRange(device, LMS_CH_TX, &sampleRateRange);
|
||||
if(getSampleRateRange){
|
||||
printf("getSampleRateRange=%d(%s)" "\n", getSampleRateRange, LMS_GetLastErrorMessage());
|
||||
}else{
|
||||
// printf("sampleRateRange [%lf MHz.. %lf MHz] (step=%lf Hz)" "\n", sampleRateRange.min / 1e6, sampleRateRange.max / 1e6, sampleRateRange.step);
|
||||
}
|
||||
|
||||
printf("Set sample rate to %lf ..." "\n", sampleRate);
|
||||
int setSampleRate = LMS_SetSampleRate(device, sampleRate, 0);
|
||||
if(setSampleRate){
|
||||
printf("setSampleRate=%d(%s)" "\n", setSampleRate, LMS_GetLastErrorMessage());
|
||||
}
|
||||
double actualHostSampleRate = 0.0;
|
||||
double actualRFSampleRate = 0.0;
|
||||
int getSampleRate = LMS_GetSampleRate(device, LMS_CH_TX, channel, &actualHostSampleRate, &actualRFSampleRate);
|
||||
if(getSampleRate){
|
||||
printf("getSampleRate=%d(%s)" "\n", getSampleRate, LMS_GetLastErrorMessage());
|
||||
}else{
|
||||
printf("actualRate %lf (Host) / %lf (RF)" "\n", actualHostSampleRate, actualRFSampleRate);
|
||||
}
|
||||
printf("Set sample rate to %lf ..." "\n", sampleRate);
|
||||
int setSampleRate = LMS_SetSampleRate(device, sampleRate, 0);
|
||||
if(setSampleRate){
|
||||
printf("setSampleRate=%d(%s)" "\n", setSampleRate, LMS_GetLastErrorMessage());
|
||||
}
|
||||
double actualHostSampleRate = 0.0;
|
||||
double actualRFSampleRate = 0.0;
|
||||
int getSampleRate = LMS_GetSampleRate(device, LMS_CH_TX, channel, &actualHostSampleRate, &actualRFSampleRate);
|
||||
if(getSampleRate){
|
||||
printf("getSampleRate=%d(%s)" "\n", getSampleRate, LMS_GetLastErrorMessage());
|
||||
}else{
|
||||
printf("actualRate %lf (Host) / %lf (RF)" "\n", actualHostSampleRate, actualRFSampleRate);
|
||||
}
|
||||
|
||||
printf("Calibrating ..." "\n");
|
||||
int calibrate = LMS_Calibrate(device, LMS_CH_TX, channel, TX_BANDWIDTH, 0);
|
||||
if(calibrate){
|
||||
printf("calibrate=%d(%s)" "\n", calibrate, LMS_GetLastErrorMessage());
|
||||
}
|
||||
printf("Calibrating ..." "\n");
|
||||
int calibrate = LMS_Calibrate(device, LMS_CH_TX, channel, TX_BANDWIDTH, 0);
|
||||
if(calibrate){
|
||||
printf("calibrate=%d(%s)" "\n", calibrate, LMS_GetLastErrorMessage());
|
||||
}
|
||||
|
||||
printf("Setup TX stream ..." "\n");
|
||||
lms_stream_t tx_stream = {.channel = channel, .fifoSize = 1024*1024, .throughputVsLatency = 0.5, .isTx = true, .dataFmt = LMS_FMT_I12};
|
||||
int setupStream = LMS_SetupStream(device, &tx_stream);
|
||||
if(setupStream){
|
||||
printf("setupStream=%d(%s)" "\n", setupStream, LMS_GetLastErrorMessage());
|
||||
}
|
||||
printf("Setup TX stream ..." "\n");
|
||||
lms_stream_t tx_stream = {.channel = channel, .fifoSize = 1024*1024, .throughputVsLatency = 0.5, .isTx = true, .dataFmt = LMS_FMT_I12};
|
||||
int setupStream = LMS_SetupStream(device, &tx_stream);
|
||||
if(setupStream){
|
||||
printf("setupStream=%d(%s)" "\n", setupStream, LMS_GetLastErrorMessage());
|
||||
}
|
||||
|
||||
struct s16iq_sample_s {
|
||||
signed short int i;
|
||||
signed short int q;
|
||||
};
|
||||
struct s16iq_sample_s {
|
||||
signed short int i;
|
||||
signed short int q;
|
||||
};
|
||||
|
||||
int nSamples = (int)sampleRate / 100;
|
||||
struct s16iq_sample_s *sampleBuffer = (struct s16iq_sample_s*)malloc(sizeof(struct s16iq_sample_s) * nSamples);
|
||||
int nSamples = (int)sampleRate / 100;
|
||||
struct s16iq_sample_s *sampleBuffer = (struct s16iq_sample_s*)malloc(sizeof(struct s16iq_sample_s) * nSamples);
|
||||
|
||||
LMS_StartStream(&tx_stream);
|
||||
LMS_StartStream(&tx_stream);
|
||||
|
||||
int loop = 0;
|
||||
if((12 == bits) || (16 == bits)){
|
||||
// File contains interleaved 16-bit IQ values, either with only 12-bit data, or with 16-bit data
|
||||
while((0 == control_c_received) && fread(sampleBuffer, sizeof(struct s16iq_sample_s), nSamples, stdin)){
|
||||
loop++;
|
||||
if(0 == (loop % 100)){
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
||||
lms_stream_status_t status;
|
||||
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
||||
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
||||
}
|
||||
if(16 == bits){
|
||||
// Scale down to 12-bit
|
||||
// Quick and dirty, so -1 (0xFFFF) to -15 (0xFFF1) scale down to -1 instead of 0
|
||||
int i = 0;
|
||||
while(i < nSamples){
|
||||
sampleBuffer[i].i >>= 4;
|
||||
sampleBuffer[i].q >>= 4;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
||||
if(sendStream < 0){
|
||||
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
||||
}
|
||||
}
|
||||
}else if(8 == bits){
|
||||
// File contains interleaved signed 8-bit IQ values
|
||||
struct s8iq_sample_s {
|
||||
signed char i;
|
||||
signed char q;
|
||||
};
|
||||
struct s8iq_sample_s *fileSamples = (struct s8iq_sample_s*)malloc(sizeof(struct s8iq_sample_s) * nSamples);
|
||||
while((0 == control_c_received) && fread(fileSamples, sizeof(struct s8iq_sample_s), nSamples, stdin)){
|
||||
loop++;
|
||||
if(0 == (loop % 100)){
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
||||
lms_stream_status_t status;
|
||||
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
||||
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
||||
}
|
||||
// Up-Scale to 12-bit
|
||||
int i = 0;
|
||||
while(i < nSamples){
|
||||
sampleBuffer[i].i = (fileSamples[i].i << 4);
|
||||
sampleBuffer[i].q = (fileSamples[i].q << 4);
|
||||
i++;
|
||||
}
|
||||
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
||||
if(sendStream < 0){
|
||||
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
||||
}
|
||||
}
|
||||
free(fileSamples);
|
||||
}else if(1 == bits){
|
||||
// File contains interleaved signed 1-bit IQ values
|
||||
// Each byte is IQIQIQIQ
|
||||
int16_t expand_lut[256][8];
|
||||
int i, j;
|
||||
for (i=0; i<256; i++){
|
||||
for (j=0; j<8; j++){
|
||||
expand_lut[i][j] = ((i>>(7-j))&0x1)?dynamic:-dynamic;
|
||||
}
|
||||
}
|
||||
printf("1-bit mode: using dynamic=%d" "\n", dynamic);
|
||||
// printf("sizeof(expand_lut[][])=%d, sizeof(expand_lut[0])=%d" "\n", sizeof(expand_lut), sizeof(expand_lut[0]));
|
||||
int8_t *fileBuffer = (int8_t*)malloc(sizeof(int8_t) * nSamples);
|
||||
while((0 == control_c_received) && fread(fileBuffer, sizeof(int8_t), nSamples / 4, stdin)){
|
||||
loop++;
|
||||
if(0 == (loop % 100)){
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
||||
lms_stream_status_t status;
|
||||
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
||||
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
||||
}
|
||||
// Expand
|
||||
int src = 0;
|
||||
int dst = 0;
|
||||
while(src < (nSamples / 4)){
|
||||
memcpy(sampleBuffer + dst, expand_lut + fileBuffer[src], sizeof(expand_lut[0]));
|
||||
dst += 4;
|
||||
src++;
|
||||
}
|
||||
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
||||
if(sendStream < 0){
|
||||
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
||||
}
|
||||
}
|
||||
free(fileBuffer);
|
||||
}
|
||||
int loop = 0;
|
||||
if((12 == bits) || (16 == bits)){
|
||||
// File contains interleaved 16-bit IQ values, either with only 12-bit data, or with 16-bit data
|
||||
while((0 == control_c_received) && fread(sampleBuffer, sizeof(struct s16iq_sample_s), nSamples, stdin)){
|
||||
loop++;
|
||||
if(0 == (loop % 100)){
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
||||
lms_stream_status_t status;
|
||||
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
||||
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
||||
}
|
||||
if(16 == bits){
|
||||
// Scale down to 12-bit
|
||||
// Quick and dirty, so -1 (0xFFFF) to -15 (0xFFF1) scale down to -1 instead of 0
|
||||
int i = 0;
|
||||
while(i < nSamples){
|
||||
sampleBuffer[i].i >>= 4;
|
||||
sampleBuffer[i].q >>= 4;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
||||
if(sendStream < 0){
|
||||
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
||||
}
|
||||
}
|
||||
}else if(8 == bits){
|
||||
// File contains interleaved signed 8-bit IQ values
|
||||
struct s8iq_sample_s {
|
||||
signed char i;
|
||||
signed char q;
|
||||
};
|
||||
struct s8iq_sample_s *fileSamples = (struct s8iq_sample_s*)malloc(sizeof(struct s8iq_sample_s) * nSamples);
|
||||
while((0 == control_c_received) && fread(fileSamples, sizeof(struct s8iq_sample_s), nSamples, stdin)){
|
||||
loop++;
|
||||
if(0 == (loop % 100)){
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
||||
lms_stream_status_t status;
|
||||
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
||||
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
||||
}
|
||||
// Up-Scale to 12-bit
|
||||
int i = 0;
|
||||
while(i < nSamples){
|
||||
sampleBuffer[i].i = (fileSamples[i].i << 4);
|
||||
sampleBuffer[i].q = (fileSamples[i].q << 4);
|
||||
i++;
|
||||
}
|
||||
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
||||
if(sendStream < 0){
|
||||
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
||||
}
|
||||
}
|
||||
free(fileSamples);
|
||||
}else if(1 == bits){
|
||||
// File contains interleaved signed 1-bit IQ values
|
||||
// Each byte is IQIQIQIQ
|
||||
int16_t expand_lut[256][8];
|
||||
int i, j;
|
||||
for (i=0; i<256; i++){
|
||||
for (j=0; j<8; j++){
|
||||
expand_lut[i][j] = ((i>>(7-j))&0x1)?dynamic:-dynamic;
|
||||
}
|
||||
}
|
||||
printf("1-bit mode: using dynamic=%d" "\n", dynamic);
|
||||
// printf("sizeof(expand_lut[][])=%d, sizeof(expand_lut[0])=%d" "\n", sizeof(expand_lut), sizeof(expand_lut[0]));
|
||||
int8_t *fileBuffer = (int8_t*)malloc(sizeof(int8_t) * nSamples);
|
||||
while((0 == control_c_received) && fread(fileBuffer, sizeof(int8_t), nSamples / 4, stdin)){
|
||||
loop++;
|
||||
if(0 == (loop % 100)){
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
||||
lms_stream_status_t status;
|
||||
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
||||
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
||||
}
|
||||
// Expand
|
||||
int src = 0;
|
||||
int dst = 0;
|
||||
while(src < (nSamples / 4)){
|
||||
memcpy(sampleBuffer + dst, expand_lut + fileBuffer[src], sizeof(expand_lut[0]));
|
||||
dst += 4;
|
||||
src++;
|
||||
}
|
||||
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
||||
if(sendStream < 0){
|
||||
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
||||
}
|
||||
}
|
||||
free(fileBuffer);
|
||||
}
|
||||
|
||||
LMS_StopStream(&tx_stream);
|
||||
LMS_DestroyStream(device, &tx_stream);
|
||||
LMS_StopStream(&tx_stream);
|
||||
LMS_DestroyStream(device, &tx_stream);
|
||||
|
||||
free(sampleBuffer);
|
||||
free(sampleBuffer);
|
||||
|
||||
LMS_EnableChannel(device, LMS_CH_TX, channel, false);
|
||||
LMS_Close(device);
|
||||
LMS_EnableChannel(device, LMS_CH_TX, channel, false);
|
||||
LMS_Close(device);
|
||||
|
||||
if(control_c_received){
|
||||
return(EXIT_CODE_CONTROL_C);
|
||||
}
|
||||
return(0);
|
||||
if(control_c_received){
|
||||
return(EXIT_CODE_CONTROL_C);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ int main(int argc, char** argv) {
|
||||
printf("* Found %s\n", iio_context_info_get_description(info[0]));
|
||||
iio_context_info_list_free(info);
|
||||
}
|
||||
iio_scan_context_destroy(scan_ctx);
|
||||
iio_scan_context_destroy(scan_ctx);
|
||||
}
|
||||
|
||||
printf("* Acquiring devices\n");
|
||||
|
Loading…
Reference in New Issue
Block a user