Ricardas,
Of course, it’s usb 3.0, it starts to show lost packets at significantly higher rates than 10 MSps that I use here. And yes, this time I did it in Release version, with the same result. Tried different sizes of buffer (40k samples/20k samples, I mean “const int bufersize” in singleRX).
I use slightly modified version of singleRX.cpp example. Unfortunately, I didn’t understand how to include source files here. Uploader takes only pictures, and when I paste it here, it autoformats the text in some weird manner which I don’t know how to cancel. Anyway, it doesn’t actually damage it, just formats. Please advise how to do it properly on this forum.
using namespace std;
//Device structure, should be initialize to NULL
lms_device_t* device = NULL;
const double Fc = 1e9; // Гц
//const double Fc = 800e6; // Гц
const double Fs = 10e6;
//const double Fs = 8e6;
const double FsOvrFact = 2;
//const double FsOvrFact = 2;
const double Flpw = 8e6;
const int Gain = 0; // дБ
const double TgtTime = 0.1; // секунд
const long TgtSampCnt = TgtTime*Fs;
int error()
{
//print last error message
cout << “ERROR:” << LMS_GetLastErrorMessage();
if (device != NULL)
LMS_Close(device);
exit(-1);
}
int main(int argc, char** argv)
{
//Find devices
//First we find number of devices, then allocate large enough list, and then populate the list
int n;
if ((n = LMS_GetDeviceList(NULL)) < 0)//Pass NULL to only obtain number of devices
error();
cout << "Devices found: " << n << endl;
if (n < 1)
return -1;
lms_info_str_t* list = new lms_info_str_t[n]; //allocate device list
if (LMS_GetDeviceList(list) < 0) //Populate device list
error();
for (int i = 0; i < n; i++) //print device list
cout << i << ": " << list[i] << endl;
cout << endl;
//Open the first device
if (LMS_Open(&device, list[0], NULL))
error();
delete [] list; //free device list
//Initialize device with default configuration
//Do not use if you want to keep existing configuration
//Use LMS_LoadConfig(device, "/path/to/file.ini") to load config from INI
if (LMS_Init(device) != 0) {
cout << "Init attempt failed (" << LMS_GetLastError() << "): " << LMS_GetLastErrorMessage() << endl;
cout << "Trying to reset..." << endl;
if (LMS_Reset(device) != 0)
error();
cout << "Init attempt 2:" << endl;
if (LMS_Init(device) != 0)
error();
} // if
//Enable RX channel
//Channels are numbered starting at 0
if (LMS_EnableChannel(device, LMS_CH_RX, 0, true) != 0)
error();
//Set center frequency to 800 MHz
if (LMS_SetLOFrequency(device, LMS_CH_RX, 0, Fc) != 0)
error();
//print currently set center frequency
float_type freq;
if (LMS_GetLOFrequency(device, LMS_CH_RX, 0, &freq) != 0)
error();
cout << "\nCenter frequency: " << freq / 1e6 << " MHz\n";
//select antenna port
lms_name_t antenna_list[10]; //large enough list for antenna names.
//Alternatively, NULL can be passed to LMS_GetAntennaList() to obtain number of antennae
if ((n = LMS_GetAntennaList(device, LMS_CH_RX, 0, antenna_list)) < 0)
error();
cout << "Available antennae:\n"; //print available antennae names
for (int i = 0; i < n; i++)
cout << i << ": " << antenna_list[i] << endl;
if ((n = LMS_GetAntenna(device, LMS_CH_RX, 0)) < 0) //get currently selected antenna index
error();
//print antenna index and name
cout << "Automatically selected antenna: " << n << ": " << antenna_list[n] << endl;
if (LMS_SetAntenna(device, LMS_CH_RX, 0, LMS_PATH_LNAW) != 0) // manually select antenna
error();
if ((n = LMS_GetAntenna(device, LMS_CH_RX, 0)) < 0) //get currently selected antenna index
error();
//print antenna index and name
cout << "Manually selected antenna: " << n << ": " << antenna_list[n] << endl;
//Set sample rate to 8 MHz, preferred oversampling in RF 8x
//This set sampling rate for all channels
if (LMS_SetSampleRate(device, Fs, FsOvrFact/*8e6, 8*/) != 0)
error();
//print resulting sampling rates (interface to host , and ADC)
float_type rate, rf_rate;
if (LMS_GetSampleRate(device, LMS_CH_RX, 0, &rate, &rf_rate) != 0) //NULL can be passed
error();
cout << "\nHost interface sample rate: " << rate / 1e6 << " MHz\nRF ADC sample rate: " << rf_rate / 1e6 << "MHz\n\n";
//Example of getting allowed parameter value range
//There are also functions to get other parameter ranges (check LimeSuite.h)
//Get allowed LPF bandwidth range
lms_range_t range;
if (LMS_GetLOFrequencyRange(device, LMS_CH_RX, &range)!=0)
error();
cout << "RX center freq range: " << range.min / 1e6 << " - " << range.max / 1e6 << " MHz\n";
if (LMS_GetSampleRateRange(device, LMS_CH_RX, &range)!=0)
error();
cout << "RX sample rate range: " << range.min / 1e6 << " - " << range.max / 1e6 << " MHz\n";
if (LMS_GetLPFBWRange(device,LMS_CH_RX,&range)!=0)
error();
cout << "RX LPF bandwitdh range: " << range.min / 1e6 << " - " << range.max / 1e6 << " MHz\n\n";
//Configure LPF, bandwidth 8 MHz
if (LMS_SetLPFBW(device, LMS_CH_RX, 0, Flpw) != 0)
error();
//Set RX gain
if (LMS_SetGaindB(device, LMS_CH_RX, 0, Gain) != 0)
error();
//Print RX gain
float_type gain; //normalized gain
if (LMS_GetNormalizedGain(device, LMS_CH_RX, 0, &gain) != 0)
error();
cout << "Normalized RX Gain: " << gain << endl;
unsigned int gaindB; //gain in dB
if (LMS_GetGaindB(device, LMS_CH_RX, 0, &gaindB) != 0)
error();
cout << "RX Gain: " << gaindB << " dB" << endl;
//Perform automatic calibration
if (LMS_Calibrate(device, LMS_CH_RX, 0, Flpw, 0) != 0)
error();
//Enable test signal generation
//To receive data from RF, remove this line or change signal to LMS_TESTSIG_NONE
/*if (LMS_SetTestSignal(device, LMS_CH_RX, 0, LMS_TESTSIG_NONE, 0, 0) != 0)
error();*/
/*if (LMS_SetTestSignal(device, LMS_CH_RX, 0, LMS_TESTSIG_NCODIV8, 0, 0) != 0)
error();
if (LMS_SetTestSignal(device, LMS_CH_RX, 1, LMS_TESTSIG_NCODIV8, 0, 0) != 0)
error();*/
if (!wrOpen("f:\\Sig\\lime_trace.dat")) {
cout << "Can't open output file!" << endl;
exit(-1);
} // if
if (!wrWriteSetCrTrHdrProps(pdu_DefLime, round(Fc), round(Fs), TgtSampCnt)) {
cout << "Can't write output file header!" << endl;
exit(-1);
} // if
//Streaming Setup
//Initialize stream
lms_stream_t streamId;
streamId.channel = 0; //channel number
streamId.fifoSize = 1024 * 1024; //fifo size in samples
streamId.throughputVsLatency = 0.5; //optimize for max throughput
streamId.isTx = false; //RX channel
streamId.dataFmt = lms_stream_t::LMS_FMT_I12; //32-bit floats
if (LMS_SetupStream(device, &streamId) != 0)
error();
//Data buffers
const int bufersize = 40000; //complex samples per buffer
int16_t buffer[bufersize * 2]; //must hold I+Q values of each sample
//Start streaming
LMS_StartStream(&streamId);
auto t1 = chrono::high_resolution_clock::now();
auto t2 = t1;
long SampsWritten = 0;
//while (chrono::high_resolution_clock::now() - t1 < chrono::seconds(3)) //run for 10 seconds
while (SampsWritten < TgtSampCnt) {
int samplesRead;
//Receive samples
samplesRead = LMS_RecvStream(&streamId, buffer, bufersize, NULL, 1000);
//I and Q samples are interleaved in buffer: IQIQIQ...
//samplesRead = LMS_RecvStream(&streamId[1], buffer[1], bufersize, NULL, 1000);
if (SampsWritten == 0) {
int16_t *p = buffer;
printf("%4d:%-4d %4d:%-4d %4d:%-4d %4d:%-4d %4d:%-4d %4d:%-4d %4d:%-4d %4d:%-4d %4d:%-4d %4d:%-4d\n",
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9],
p[10], p[11], p[12], p[13], p[14], p[15], p[16], p[17], p[18], p[19]);
byte *b = (byte*)buffer;
printf("%02X%02X:%02X%02X %02X%02X:%02X%02X %02X%02X:%02X%02X %02X%02X:%02X%02X %02X%02X:%02X%02X %02X%02X:%02X%02X %02X%02X:%02X%02X %02X%02X:%02X%02X %02X%02X:%02X%02X %02X%02X:%02X%02X\n\n",
b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9],
b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19],
b[20], b[21], b[22], b[23], b[24], b[25], b[26], b[27], b[28], b[29],
b[30], b[31], b[32], b[33], b[34], b[35], b[36], b[37], b[38], b[39]);
} // if
int Samps2Write = min(TgtSampCnt-SampsWritten, samplesRead);
if (!wrWrite(buffer, 2 * Samps2Write * sizeof(__int16))) {
cout << "Can't write samples to output file!" << endl;
exit(-1);
} // if
SampsWritten += Samps2Write;
//Print stats (once per second)
if (chrono::high_resolution_clock::now() - t2 > chrono::milliseconds(500))
{
t2 = chrono::high_resolution_clock::now();
lms_stream_status_t status;
//Get stream status
LMS_GetStreamStatus(&streamId, &status);
cout << "RX_1 data rate: " << status.linkRate / 1e6 << " MB/s\n"; //link data rate
cout << "RX_1 sample rate: " << status.sampleRate / 1e6 << " MSamples/s\n"; //link data rate
cout << "RX_1 fifo: " << 100 * status.fifoFilledCount / status.fifoSize << "%" << endl; //percentage of FIFO filled
}
} // while
wrClose();
//Stop streaming
LMS_StopStream(&streamId); //stream is stopped but can be started again with LMS_StartStream()
LMS_DestroyStream(device, &streamId); //stream is deallocated and can no longer be used
//Close device
LMS_Close(device);
return 0;
}