From b0c2b5500c96b347ec7756508db0f041e7af44b7 Mon Sep 17 00:00:00 2001 From: Arnaud ZANETTI Date: Mon, 30 Oct 2017 13:55:32 +0100 Subject: [PATCH 1/8] Output file size is limited to 2GB on some 32-bit systems (Raspbian Stretch for example) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4f6933f..5b01636 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ all: gps-sdr-sim SHELL=/bin/bash CC=gcc -CFLAGS=-O3 -Wall +CFLAGS=-O3 -Wall -D_FILE_OFFSET_BITS=64 LDFLAGS=-lm gps-sdr-sim: gpssim.o From 6c88f8a1a996df7d899a39ed664600ce410fe37b Mon Sep 17 00:00:00 2001 From: Arnaud ZANETTI Date: Mon, 30 Oct 2017 14:00:26 +0100 Subject: [PATCH 2/8] Allow to use stdout as output file. --- README.md | 2 +- gpssim.c | 79 +++++++++++++++++++++++++++++-------------------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 14b0af6..b80e960 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Options: -t Scenario start time YYYY/MM/DD,hh:mm:ss -T Overwrite TOC and TOE to scenario start time -d Duration [sec] (dynamic mode max: 300 static mode max: 86400) - -o I/Q sampling data file (default: gpssim.bin) + -o I/Q sampling data file (default: gpssim.bin ; use - for stdout) -s Sampling frequency [Hz] (default: 2600000) -b I/Q data format [1/8/16] (default: 16) -i Disable ionospheric delay for spacecraft scenario diff --git a/gpssim.c b/gpssim.c index 5916511..827cd55 100644 --- a/gpssim.c +++ b/gpssim.c @@ -1512,7 +1512,7 @@ int generateNavMsg(gpstime_t g, channel_t *chan, int init) // Sanity check if (((chan->dwrd[1])&(0x1FFFFUL<<13)) != ((tow&0x1FFFFUL)<<13)) { - printf("\nWARNING: Invalid TOW in subframe 5.\n"); + fprintf(stderr, "\nWARNING: Invalid TOW in subframe 5.\n"); return(0); } */ @@ -1646,7 +1646,7 @@ int allocateChannel(channel_t *chan, ephem_t *eph, ionoutc_t ionoutc, gpstime_t void usage(void) { - printf("Usage: gps-sdr-sim [options]\n" + fprintf(stderr, "Usage: gps-sdr-sim [options]\n" "Options:\n" " -e RINEX navigation file for GPS ephemerides (required)\n" " -u User motion file (dynamic mode)\n" @@ -1779,7 +1779,7 @@ int main(int argc, char *argv[]) samp_freq = atof(optarg); if (samp_freq<1.0e6) { - printf("ERROR: Invalid sampling frequency.\n"); + fprintf(stderr, "ERROR: Invalid sampling frequency.\n"); exit(1); } break; @@ -1787,7 +1787,7 @@ int main(int argc, char *argv[]) data_format = atoi(optarg); if (data_format!=SC01 && data_format!=SC08 && data_format!=SC16) { - printf("ERROR: Invalid I/Q data format.\n"); + fprintf(stderr, "ERROR: Invalid I/Q data format.\n"); exit(1); } break; @@ -1817,7 +1817,7 @@ int main(int argc, char *argv[]) if (t0.y<=1980 || t0.m<1 || t0.m>12 || t0.d<1 || t0.d>31 || t0.hh<0 || t0.hh>23 || t0.mm<0 || t0.mm>59 || t0.sec<0.0 || t0.sec>=60.0) { - printf("ERROR: Invalid date and time.\n"); + fprintf(stderr, "ERROR: Invalid date and time.\n"); exit(1); } t0.sec = floor(t0.sec); @@ -1843,7 +1843,7 @@ int main(int argc, char *argv[]) if (navfile[0]==0) { - printf("ERROR: GPS ephemeris file is not specified.\n"); + fprintf(stderr, "ERROR: GPS ephemeris file is not specified.\n"); exit(1); } @@ -1858,7 +1858,7 @@ int main(int argc, char *argv[]) if (duration<0.0 || (duration>((double)USER_MOTION_SIZE)/10.0 && !staticLocationMode) || (duration>STATIC_MAX_DURATION && staticLocationMode)) { - printf("ERROR: Invalid duration.\n"); + fprintf(stderr, "ERROR: Invalid duration.\n"); exit(1); } iduration = (int)(duration*10.0 + 0.5); @@ -1884,12 +1884,12 @@ int main(int argc, char *argv[]) if (numd==-1) { - printf("ERROR: Failed to open user motion / NMEA GGA file.\n"); + fprintf(stderr, "ERROR: Failed to open user motion / NMEA GGA file.\n"); exit(1); } else if (numd==0) { - printf("ERROR: Failed to read user motion / NMEA GGA data.\n"); + fprintf(stderr, "ERROR: Failed to read user motion / NMEA GGA data.\n"); exit(1); } @@ -1901,14 +1901,14 @@ int main(int argc, char *argv[]) { // Static geodetic coordinates input mode: "-l" // Added by scateu@gmail.com - printf("Using static location mode.\n"); + fprintf(stderr, "Using static location mode.\n"); llh2xyz(llh,xyz[0]); // Convert llh to xyz numd = iduration; } /* - printf("xyz = %11.1f, %11.1f, %11.1f\n", xyz[0][0], xyz[0][1], xyz[0][2]); - printf("llh = %11.6f, %11.6f, %11.1f\n", llh[0]*R2D, llh[1]*R2D, llh[2]); + fprintf(stderr, "xyz = %11.1f, %11.1f, %11.1f\n", xyz[0][0], xyz[0][1], xyz[0][2]); + fprintf(stderr, "llh = %11.6f, %11.6f, %11.1f\n", llh[0]*R2D, llh[1]*R2D, llh[2]); */ //////////////////////////////////////////////////////////// // Read ephemeris @@ -1918,19 +1918,19 @@ int main(int argc, char *argv[]) if (neph==0) { - printf("ERROR: No ephemeris available.\n"); + fprintf(stderr, "ERROR: No ephemeris available.\n"); exit(1); } if ((verb==TRUE)&&(ionoutc.vflg==TRUE)) { - printf(" %12.3e %12.3e %12.3e %12.3e\n", + fprintf(stderr, " %12.3e %12.3e %12.3e %12.3e\n", ionoutc.alpha0, ionoutc.alpha1, ionoutc.alpha2, ionoutc.alpha3); - printf(" %12.3e %12.3e %12.3e %12.3e\n", + fprintf(stderr, " %12.3e %12.3e %12.3e %12.3e\n", ionoutc.beta0, ionoutc.beta1, ionoutc.beta2, ionoutc.beta3); - printf(" %19.11e %19.11e %9d %9d\n", + fprintf(stderr, " %19.11e %19.11e %9d %9d\n", ionoutc.A0, ionoutc.A1, ionoutc.tot, ionoutc.wnt); - printf("%6d\n", ionoutc.dtls); + fprintf(stderr, "%6d\n", ionoutc.dtls); } for (sv=0; sv0) - printf("%02d %6.1f %5.1f %11.1f %5.1f\n", chan[i].prn, + fprintf(stderr, "%02d %6.1f %5.1f %11.1f %5.1f\n", chan[i].prn, chan[i].azel[0]*R2D, chan[i].azel[1]*R2D, chan[i].rho0.d, chan[i].rho0.iono_delay); } @@ -2205,7 +2210,7 @@ int main(int argc, char *argv[]) chan[i].iword++; /* if (chan[i].iword>=N_DWRD) - printf("\nWARNING: Subframe word buffer overflow.\n"); + fprintf(stderr, "\nWARNING: Subframe word buffer overflow.\n"); */ } @@ -2302,11 +2307,11 @@ int main(int argc, char *argv[]) // Show ditails about simulated channels if (verb==TRUE) { - printf("\n"); + fprintf(stderr, "\n"); for (i=0; i0) - printf("%02d %6.1f %5.1f %11.1f %5.1f\n", chan[i].prn, + fprintf(stderr, "%02d %6.1f %5.1f %11.1f %5.1f\n", chan[i].prn, chan[i].azel[0]*R2D, chan[i].azel[1]*R2D, chan[i].rho0.d, chan[i].rho0.iono_delay); } } @@ -2316,13 +2321,13 @@ int main(int argc, char *argv[]) grx = incGpsTime(grx, 0.1); // Update time counter - printf("\rTime into run = %4.1f", subGpsTime(grx, g0)); + fprintf(stderr, "\rTime into run = %4.1f", subGpsTime(grx, g0)); fflush(stdout); } tend = clock(); - printf("\nDone!\n"); + fprintf(stderr, "\nDone!\n"); // Free I/Q buffer free(iq_buff); @@ -2331,7 +2336,7 @@ int main(int argc, char *argv[]) fclose(fp); // Process time - printf("Process time = %.1f [sec]\n", (double)(tend-tstart)/CLOCKS_PER_SEC); + fprintf(stderr, "Process time = %.1f [sec]\n", (double)(tend-tstart)/CLOCKS_PER_SEC); return(0); } From 0f78b6ddcd0b31a0e0b9a7cdee5dd6032a181cdf Mon Sep 17 00:00:00 2001 From: Arnaud ZANETTI Date: Mon, 30 Oct 2017 14:30:05 +0100 Subject: [PATCH 3/8] Add an SDR player for LimeSDR. --- player/Makefile | 5 + player/limeplayer.c | 340 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 345 insertions(+) create mode 100644 player/Makefile create mode 100644 player/limeplayer.c diff --git a/player/Makefile b/player/Makefile new file mode 100644 index 0000000..52220d5 --- /dev/null +++ b/player/Makefile @@ -0,0 +1,5 @@ +CC=gcc -g -Wall + +limeplayer: limeplayer.c + $(CC) -o limeplayer limeplayer.c -lLimeSuite + diff --git a/player/limeplayer.c b/player/limeplayer.c new file mode 100644 index 0000000..9ea323a --- /dev/null +++ b/player/limeplayer.c @@ -0,0 +1,340 @@ +#define _CRT_SECURE_NO_DEPRECATE + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define EXIT_CODE_NO_DEVICE (-1) +#define EXIT_CODE_LMS_OPEN (-1) + +#define TX_FREQUENCY 1575420000.0 +#define TX_SAMPLERATE 2500000.0 +#define TX_BANDWIDTH 5000000.0 +#define DEFAULT_ANTENNA 1 // antenna with BW [30MHz .. 2000MHz] + +int main(int argc, char *const argv[]){ + 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++; + } + + double gain = 1.0; + int antenna = DEFAULT_ANTENNA; + int channel = 0; + int index = 0; + int bits = 16; + double sampleRate = TX_SAMPLERATE; + + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"gain", required_argument, 0, 'g' }, + {"channel", required_argument, 0, 'c' }, + {"antenna", required_argument, 0, 'a' }, + {"index", required_argument, 0, 'i'}, + {"bits", required_argument, 0, 'b'}, + {"samplerate", required_argument, 0, 's'}, + {0, 0, 0, 0 } + }; + + int c = getopt_long(argc, argv, "g:c:a:i:s:b:", long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 0: + #if 1 + fprintf(stderr, "option %s", long_options[option_index].name); + if (optarg) + fprintf(stderr, " with arg %s", optarg); + fprintf(stderr, "\n"); + #endif + + break; + + case 'a': + antenna = strtol(optarg, NULL, 0); + break; + case 'b': + bits = strtol(optarg, NULL, 0); + break; + case 'c': + channel = strtol(optarg, NULL, 0); + break; + case 'g': + gain = strtod(optarg, NULL); + break; + case 'i': + index = strtol(optarg, NULL, 0); + break; + case 's': + sampleRate = strtod(optarg, NULL); + 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]); + + // 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; + + 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 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 + + 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()); + } + +#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()); + } +#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); + } + + 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("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; + }; + + 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); + + 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(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; + 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(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; + 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)?1024:-1024; + } + } + // 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(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); + + free(sampleBuffer); + + LMS_EnableChannel(device, LMS_CH_TX, channel, false); + LMS_Close(device); + + return(0); +} + From 8791e24e1f78297762dca57dd2d862daa972061f Mon Sep 17 00:00:00 2001 From: Arnaud ZANETTI Date: Mon, 30 Oct 2017 18:28:08 +0100 Subject: [PATCH 4/8] Add Control-C handling Add inline help --- player/limeplayer.c | 81 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 10 deletions(-) diff --git a/player/limeplayer.c b/player/limeplayer.c index 9ea323a..b5f43a4 100644 --- a/player/limeplayer.c +++ b/player/limeplayer.c @@ -8,10 +8,12 @@ #include #include #include +#include #include -#define EXIT_CODE_NO_DEVICE (-1) +#define EXIT_CODE_CONTROL_C (-3) +#define EXIT_CODE_NO_DEVICE (-2) #define EXIT_CODE_LMS_OPEN (-1) #define TX_FREQUENCY 1575420000.0 @@ -19,7 +21,51 @@ #define TX_BANDWIDTH 5000000.0 #define DEFAULT_ANTENNA 1 // antenna with BW [30MHz .. 2000MHz] +#define STRINGIFY2(X) #X +#define STRINGIFY(X) STRINGIFY2(X) + +static int control_c_received = 0; + +static void control_c_handler (int sig, siginfo_t *siginfo, void *context){ + control_c_received = 1; +} + +static void print_usage(const char *progname){ + printf("Usage: %s [option] < file" "\n" + "\t" "-g or --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 or --channel with channel either 0 or 1 (default: 0)" "\n" + "\t" "-a or --antenna with antenna in { 0, 1, 2 } (default:" STRINGIFY(DEFAULT_ANTENNA) ")" "\n" + "\t" "-i or --index select LimeSDR if multiple devices connected (default: 0)" "\n" + "\t" "-b or --bits select bit count in IQ sample in { 1, 8, 12, 16 }, (default: 16)" + "\t" "-s or --samplerate configure BB sample rate (default: " STRINGIFY(TX_SAMPLERATE) ")" "\n" + "\t" "-d --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); +} + int main(int argc, char *const argv[]){ + struct sigaction control_c; + + 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; + + 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); @@ -34,11 +80,12 @@ int main(int argc, char *const argv[]){ } double gain = 1.0; - int antenna = DEFAULT_ANTENNA; - int channel = 0; - int index = 0; - int bits = 16; + 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; @@ -49,10 +96,11 @@ int main(int argc, char *const argv[]){ {"index", required_argument, 0, 'i'}, {"bits", required_argument, 0, 'b'}, {"samplerate", required_argument, 0, 's'}, + {"dynamic", required_argument, 0, 'd'}, {0, 0, 0, 0 } }; - int c = getopt_long(argc, argv, "g:c:a:i:s:b:", long_options, &option_index); + int c = getopt_long(argc, argv, "g:c:a:i:s:b:d:", long_options, &option_index); if (c == -1) break; @@ -85,6 +133,15 @@ int main(int argc, char *const argv[]){ 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 @@ -234,7 +291,7 @@ int main(int argc, char *const argv[]){ 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(fread(sampleBuffer, sizeof(struct s16iq_sample_s), nSamples, stdin)){ + while((0 == control_c_received) && fread(sampleBuffer, sizeof(struct s16iq_sample_s), nSamples, stdin)){ loop++; if(0 == (loop % 100)){ struct timeval tv; @@ -266,7 +323,7 @@ int main(int argc, char *const argv[]){ signed char q; }; struct s8iq_sample_s *fileSamples = (struct s8iq_sample_s*)malloc(sizeof(struct s8iq_sample_s) * nSamples); - while(fread(fileSamples, sizeof(struct s8iq_sample_s), nSamples, stdin)){ + while((0 == control_c_received) && fread(fileSamples, sizeof(struct s8iq_sample_s), nSamples, stdin)){ loop++; if(0 == (loop % 100)){ struct timeval tv; @@ -296,12 +353,13 @@ int main(int argc, char *const argv[]){ int i, j; for (i=0; i<256; i++){ for (j=0; j<8; j++){ - expand_lut[i][j] = ((i>>(7-j))&0x1)?1024:-1024; + 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(fread(fileBuffer, sizeof(int8_t), nSamples / 4, stdin)){ + while((0 == control_c_received) && fread(fileBuffer, sizeof(int8_t), nSamples / 4, stdin)){ loop++; if(0 == (loop % 100)){ struct timeval tv; @@ -335,6 +393,9 @@ int main(int argc, char *const argv[]){ LMS_EnableChannel(device, LMS_CH_TX, channel, false); LMS_Close(device); + if(control_c_received){ + return(EXIT_CODE_CONTROL_C); + } return(0); } From 9c9cfcae6e5707b0fabe20772b7d317920e2a212 Mon Sep 17 00:00:00 2001 From: Arnaud ZANETTI Date: Mon, 30 Oct 2017 18:29:11 +0100 Subject: [PATCH 5/8] Typo in inline help (missing "\n" --- player/limeplayer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/player/limeplayer.c b/player/limeplayer.c index b5f43a4..e024b21 100644 --- a/player/limeplayer.c +++ b/player/limeplayer.c @@ -36,7 +36,7 @@ static void print_usage(const char *progname){ "\t" "-c or --channel with channel either 0 or 1 (default: 0)" "\n" "\t" "-a or --antenna with antenna in { 0, 1, 2 } (default:" STRINGIFY(DEFAULT_ANTENNA) ")" "\n" "\t" "-i or --index select LimeSDR if multiple devices connected (default: 0)" "\n" - "\t" "-b or --bits select bit count in IQ sample in { 1, 8, 12, 16 }, (default: 16)" + "\t" "-b or --bits select bit count in IQ sample in { 1, 8, 12, 16 }, (default: 16)" "\n" "\t" "-s or --samplerate configure BB sample rate (default: " STRINGIFY(TX_SAMPLERATE) ")" "\n" "\t" "-d --dynamic configure dynamic for the 1-bit mode (default: 2047, max 12-bit signed value supported by LimeSDR)" "\n" "Example:" "\n" From 3faf5ee027dbeded30a42ac5c1272f8e32e5d228 Mon Sep 17 00:00:00 2001 From: Arnaud ZANETTI Date: Mon, 30 Oct 2017 18:34:57 +0100 Subject: [PATCH 6/8] Add limeplayer example in README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index b80e960..c16a5d3 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,9 @@ For UHD supported devices (tested with USRP2 only): > gps-sdr-sim-uhd.py -t gpssim.bin -s 2500000 -x 0 ``` +For LimeSDR (in case of 1 Msps 1-bit file, to get full BaseBand dynamic and low RF power): + +> limeplayer -s 1000000 -b 1 -d 2047 -g 0.1 < ../circle.1b.1M.bin ### License From f0e92bcb3faee1269174fbc20845751aac03fec3 Mon Sep 17 00:00:00 2001 From: Arnaud ZANETTI Date: Tue, 31 Oct 2017 09:36:28 +0100 Subject: [PATCH 7/8] Corrected 8-bit mode (uninitialized variable not caught by -Wall !) in limeplayer --- player/limeplayer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/player/limeplayer.c b/player/limeplayer.c index e024b21..731dc37 100644 --- a/player/limeplayer.c +++ b/player/limeplayer.c @@ -334,7 +334,7 @@ int main(int argc, char *const argv[]){ printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6); } // Up-Scale to 12-bit - int i; + int i = 0; while(i < nSamples){ sampleBuffer[i].i = (fileSamples[i].i << 4); sampleBuffer[i].q = (fileSamples[i].q << 4); From 724fd8cbc76972a0ee2e6452bc8b79dc3ae9d4c0 Mon Sep 17 00:00:00 2001 From: Arnaud ZANETTI Date: Tue, 31 Oct 2017 14:01:53 +0100 Subject: [PATCH 8/8] Fix another initialized variable ; the reason why -Wall didn't catch it was the -g flag ; with -O2 flag initialized variables raise warnings. --- player/Makefile | 2 +- player/limeplayer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/player/Makefile b/player/Makefile index 52220d5..ab1ba11 100644 --- a/player/Makefile +++ b/player/Makefile @@ -1,4 +1,4 @@ -CC=gcc -g -Wall +CC=gcc -O2 -Wall limeplayer: limeplayer.c $(CC) -o limeplayer limeplayer.c -lLimeSuite diff --git a/player/limeplayer.c b/player/limeplayer.c index 731dc37..73046fe 100644 --- a/player/limeplayer.c +++ b/player/limeplayer.c @@ -304,7 +304,7 @@ int main(int argc, char *const argv[]){ 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; + int i = 0; while(i < nSamples){ sampleBuffer[i].i >>= 4; sampleBuffer[i].q >>= 4;