Tab to Space
This commit is contained in:
parent
1cef6284d5
commit
06b11c9a8c
@ -27,11 +27,11 @@
|
|||||||
static int control_c_received = 0;
|
static int control_c_received = 0;
|
||||||
|
|
||||||
static void control_c_handler (int sig, siginfo_t *siginfo, void *context){
|
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){
|
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" "-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" "-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"
|
"\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" "-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" "-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"
|
"\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"
|
"Example:" "\n"
|
||||||
"\t" "./limeplayer -s 1000000 -b 1 -d 1023 -g 0.1 < ../circle.1b.1M.bin" "\n", progname);
|
"\t" "./limeplayer -s 1000000 -b 1 -d 1023 -g 0.1 < ../circle.1b.1M.bin" "\n", progname);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *const argv[]){
|
int main(int argc, char *const argv[]){
|
||||||
struct sigaction control_c;
|
struct sigaction control_c;
|
||||||
|
|
||||||
memset(&control_c, 0, sizeof(control_c));
|
memset(&control_c, 0, sizeof(control_c));
|
||||||
control_c.sa_sigaction = &control_c_handler;
|
control_c.sa_sigaction = &control_c_handler;
|
||||||
|
|
||||||
/* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
|
/* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
|
||||||
control_c.sa_flags = SA_SIGINFO;
|
control_c.sa_flags = SA_SIGINFO;
|
||||||
|
|
||||||
if (sigaction(SIGTERM, &control_c, NULL) < 0) {
|
if (sigaction(SIGTERM, &control_c, NULL) < 0) {
|
||||||
perror ("sigaction");
|
perror ("sigaction");
|
||||||
return(EXIT_CODE_CONTROL_C);
|
return(EXIT_CODE_CONTROL_C);
|
||||||
}
|
}
|
||||||
if (sigaction(SIGQUIT, &control_c, NULL) < 0) {
|
if (sigaction(SIGQUIT, &control_c, NULL) < 0) {
|
||||||
perror ("sigaction");
|
perror ("sigaction");
|
||||||
return(EXIT_CODE_CONTROL_C);
|
return(EXIT_CODE_CONTROL_C);
|
||||||
}
|
}
|
||||||
if (sigaction(SIGINT, &control_c, NULL) < 0) {
|
if (sigaction(SIGINT, &control_c, NULL) < 0) {
|
||||||
perror ("sigaction");
|
perror ("sigaction");
|
||||||
return(EXIT_CODE_CONTROL_C);
|
return(EXIT_CODE_CONTROL_C);
|
||||||
}
|
}
|
||||||
|
|
||||||
int device_count = LMS_GetDeviceList(NULL);
|
int device_count = LMS_GetDeviceList(NULL);
|
||||||
if(device_count < 1){
|
if(device_count < 1){
|
||||||
return(EXIT_CODE_NO_DEVICE);
|
return(EXIT_CODE_NO_DEVICE);
|
||||||
}
|
}
|
||||||
lms_info_str_t *device_list = malloc(sizeof(lms_info_str_t) * device_count);
|
lms_info_str_t *device_list = malloc(sizeof(lms_info_str_t) * device_count);
|
||||||
device_count = LMS_GetDeviceList(device_list);
|
device_count = LMS_GetDeviceList(device_list);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(i < device_count){
|
while(i < device_count){
|
||||||
// printf("device[%d/%d]=%s" "\n", i + 1, device_count, device_list[i]);
|
// printf("device[%d/%d]=%s" "\n", i + 1, device_count, device_list[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gain = 1.0;
|
double gain = 1.0;
|
||||||
int32_t antenna = DEFAULT_ANTENNA;
|
int32_t antenna = DEFAULT_ANTENNA;
|
||||||
int32_t channel = 0;
|
int32_t channel = 0;
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
int32_t bits = 16;
|
int32_t bits = 16;
|
||||||
double sampleRate = TX_SAMPLERATE;
|
double sampleRate = TX_SAMPLERATE;
|
||||||
int32_t dynamic = 2047;
|
int32_t dynamic = 2047;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
@ -109,7 +109,7 @@ int main(int argc, char *const argv[]){
|
|||||||
#if 1
|
#if 1
|
||||||
fprintf(stderr, "option %s", long_options[option_index].name);
|
fprintf(stderr, "option %s", long_options[option_index].name);
|
||||||
if (optarg)
|
if (optarg)
|
||||||
fprintf(stderr, " with arg %s", optarg);
|
fprintf(stderr, " with arg %s", optarg);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -130,272 +130,272 @@ int main(int argc, char *const argv[]){
|
|||||||
case 'i':
|
case 'i':
|
||||||
index = strtol(optarg, NULL, 0);
|
index = strtol(optarg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
sampleRate = strtod(optarg, NULL);
|
sampleRate = strtod(optarg, NULL);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
dynamic = strtol(optarg, NULL, 0);
|
dynamic = strtol(optarg, NULL, 0);
|
||||||
if(dynamic > 2047){
|
if(dynamic > 2047){
|
||||||
dynamic = 2047;
|
dynamic = 2047;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
print_usage(argv[0]);
|
print_usage(argv[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Use correct values
|
// Use correct values
|
||||||
// Use existing device
|
// Use existing device
|
||||||
if(index < 0){
|
if(index < 0){
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
if(index >= device_count){
|
if(index >= device_count){
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
printf("Using device index %d [%s]" "\n", index, device_list[index]);
|
printf("Using device index %d [%s]" "\n", index, device_list[index]);
|
||||||
|
|
||||||
// Normalized gain shall be in [0.0 .. 1.0]
|
// Normalized gain shall be in [0.0 .. 1.0]
|
||||||
if(gain < 0.0){
|
if(gain < 0.0){
|
||||||
gain = 0.0;
|
gain = 0.0;
|
||||||
}
|
}
|
||||||
if(gain > 1.0){
|
if(gain > 1.0){
|
||||||
gain = 1.0;
|
gain = 1.0;
|
||||||
}
|
}
|
||||||
printf("Using normalized gain %lf" "\n", gain);
|
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)){
|
if(LMS_Open(&device, device_list[index], NULL)){
|
||||||
return(EXIT_CODE_LMS_OPEN);
|
return(EXIT_CODE_LMS_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lmsReset = LMS_Reset(device);
|
int lmsReset = LMS_Reset(device);
|
||||||
if(lmsReset){
|
if(lmsReset){
|
||||||
printf("lmsReset %d(%s)" "\n", lmsReset, LMS_GetLastErrorMessage());
|
printf("lmsReset %d(%s)" "\n", lmsReset, LMS_GetLastErrorMessage());
|
||||||
}
|
}
|
||||||
int lmsInit = LMS_Init(device);
|
int lmsInit = LMS_Init(device);
|
||||||
if(lmsInit){
|
if(lmsInit){
|
||||||
printf("lmsInit %d(%s)" "\n", lmsInit, LMS_GetLastErrorMessage());
|
printf("lmsInit %d(%s)" "\n", lmsInit, LMS_GetLastErrorMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
int channel_count = LMS_GetNumChannels(device, LMS_CH_TX);
|
int channel_count = LMS_GetNumChannels(device, LMS_CH_TX);
|
||||||
// printf("Tx channel count %d" "\n", channel_count);
|
// printf("Tx channel count %d" "\n", channel_count);
|
||||||
if(channel < 0){
|
if(channel < 0){
|
||||||
channel = 0;
|
channel = 0;
|
||||||
}
|
}
|
||||||
if(channel >= channel_count){
|
if(channel >= channel_count){
|
||||||
channel = 0;
|
channel = 0;
|
||||||
}
|
}
|
||||||
printf("Using channel %d" "\n", channel);
|
printf("Using channel %d" "\n", channel);
|
||||||
|
|
||||||
int antenna_count = LMS_GetAntennaList(device, LMS_CH_TX, channel, NULL);
|
int antenna_count = LMS_GetAntennaList(device, LMS_CH_TX, channel, NULL);
|
||||||
// printf("TX%d Channel has %d antenna(ae)" "\n", channel, antenna_count);
|
// printf("TX%d Channel has %d antenna(ae)" "\n", channel, antenna_count);
|
||||||
lms_name_t antenna_name[antenna_count];
|
lms_name_t antenna_name[antenna_count];
|
||||||
if(antenna_count > 0){
|
if(antenna_count > 0){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
lms_range_t antenna_bw[antenna_count];
|
lms_range_t antenna_bw[antenna_count];
|
||||||
LMS_GetAntennaList(device, LMS_CH_TX, channel, antenna_name);
|
LMS_GetAntennaList(device, LMS_CH_TX, channel, antenna_name);
|
||||||
for(i = 0 ; i < antenna_count ; i++){
|
for(i = 0 ; i < antenna_count ; i++){
|
||||||
LMS_GetAntennaBW(device, LMS_CH_TX, channel, i, antenna_bw + 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);
|
// 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){
|
if(antenna < 0){
|
||||||
antenna = DEFAULT_ANTENNA;
|
antenna = DEFAULT_ANTENNA;
|
||||||
}
|
}
|
||||||
if(antenna >= antenna_count){
|
if(antenna >= antenna_count){
|
||||||
antenna = DEFAULT_ANTENNA;
|
antenna = DEFAULT_ANTENNA;
|
||||||
}
|
}
|
||||||
// LMS_SetAntenna(device, LMS_CH_TX, channel, antenna); // SetLOFrequency should take care of selecting the proper 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);
|
LMS_SetNormalizedGain(device, LMS_CH_TX, channel, gain);
|
||||||
// Disable all other channels
|
// Disable all other channels
|
||||||
LMS_EnableChannel(device, LMS_CH_TX, 1 - channel, false);
|
LMS_EnableChannel(device, LMS_CH_TX, 1 - channel, false);
|
||||||
LMS_EnableChannel(device, LMS_CH_RX, 0, false);
|
LMS_EnableChannel(device, LMS_CH_RX, 0, false);
|
||||||
LMS_EnableChannel(device, LMS_CH_RX, 1, false);
|
LMS_EnableChannel(device, LMS_CH_RX, 1, false);
|
||||||
// Enable our Tx channel
|
// Enable our Tx channel
|
||||||
LMS_EnableChannel(device, LMS_CH_TX, channel, true);
|
LMS_EnableChannel(device, LMS_CH_TX, channel, true);
|
||||||
|
|
||||||
int setLOFrequency = LMS_SetLOFrequency(device, LMS_CH_TX, channel, TX_FREQUENCY);
|
int setLOFrequency = LMS_SetLOFrequency(device, LMS_CH_TX, channel, TX_FREQUENCY);
|
||||||
if(setLOFrequency){
|
if(setLOFrequency){
|
||||||
printf("setLOFrequency(%lf)=%d(%s)" "\n", TX_FREQUENCY, setLOFrequency, LMS_GetLastErrorMessage());
|
printf("setLOFrequency(%lf)=%d(%s)" "\n", TX_FREQUENCY, setLOFrequency, LMS_GetLastErrorMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __USE_LPF__
|
#ifdef __USE_LPF__
|
||||||
lms_range_t LPFBWRange;
|
lms_range_t LPFBWRange;
|
||||||
LMS_GetLPFBWRange(device, LMS_CH_TX, &LPFBWRange);
|
LMS_GetLPFBWRange(device, LMS_CH_TX, &LPFBWRange);
|
||||||
// printf("TX%d LPFBW [%lf .. %lf] (step %lf)" "\n", channel, LPFBWRange.min, LPFBWRange.max, LPFBWRange.step);
|
// printf("TX%d LPFBW [%lf .. %lf] (step %lf)" "\n", channel, LPFBWRange.min, LPFBWRange.max, LPFBWRange.step);
|
||||||
double LPFBW = TX_BANDWIDTH;
|
double LPFBW = TX_BANDWIDTH;
|
||||||
if(LPFBW < LPFBWRange.min){
|
if(LPFBW < LPFBWRange.min){
|
||||||
LPFBW = LPFBWRange.min;
|
LPFBW = LPFBWRange.min;
|
||||||
}
|
}
|
||||||
if(LPFBW > LPFBWRange.max){
|
if(LPFBW > LPFBWRange.max){
|
||||||
LPFBW = LPFBWRange.min;
|
LPFBW = LPFBWRange.min;
|
||||||
}
|
}
|
||||||
int setLPFBW = LMS_SetLPFBW(device, LMS_CH_TX, channel, LPFBW);
|
int setLPFBW = LMS_SetLPFBW(device, LMS_CH_TX, channel, LPFBW);
|
||||||
if(setLPFBW){
|
if(setLPFBW){
|
||||||
printf("setLPFBW(%lf)=%d(%s)" "\n", LPFBW, setLPFBW, LMS_GetLastErrorMessage());
|
printf("setLPFBW(%lf)=%d(%s)" "\n", LPFBW, setLPFBW, LMS_GetLastErrorMessage());
|
||||||
}
|
}
|
||||||
int enableLPF = LMS_SetLPF(device, LMS_CH_TX, channel, true);
|
int enableLPF = LMS_SetLPF(device, LMS_CH_TX, channel, true);
|
||||||
if(enableLPF){
|
if(enableLPF){
|
||||||
printf("enableLPF=%d(%s)" "\n", enableLPF, LMS_GetLastErrorMessage());
|
printf("enableLPF=%d(%s)" "\n", enableLPF, LMS_GetLastErrorMessage());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lms_range_t sampleRateRange;
|
lms_range_t sampleRateRange;
|
||||||
int getSampleRateRange = LMS_GetSampleRateRange(device, LMS_CH_TX, &sampleRateRange);
|
int getSampleRateRange = LMS_GetSampleRateRange(device, LMS_CH_TX, &sampleRateRange);
|
||||||
if(getSampleRateRange){
|
if(getSampleRateRange){
|
||||||
printf("getSampleRateRange=%d(%s)" "\n", getSampleRateRange, LMS_GetLastErrorMessage());
|
printf("getSampleRateRange=%d(%s)" "\n", getSampleRateRange, LMS_GetLastErrorMessage());
|
||||||
}else{
|
}else{
|
||||||
// printf("sampleRateRange [%lf MHz.. %lf MHz] (step=%lf Hz)" "\n", sampleRateRange.min / 1e6, sampleRateRange.max / 1e6, sampleRateRange.step);
|
// 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);
|
printf("Set sample rate to %lf ..." "\n", sampleRate);
|
||||||
int setSampleRate = LMS_SetSampleRate(device, sampleRate, 0);
|
int setSampleRate = LMS_SetSampleRate(device, sampleRate, 0);
|
||||||
if(setSampleRate){
|
if(setSampleRate){
|
||||||
printf("setSampleRate=%d(%s)" "\n", setSampleRate, LMS_GetLastErrorMessage());
|
printf("setSampleRate=%d(%s)" "\n", setSampleRate, LMS_GetLastErrorMessage());
|
||||||
}
|
}
|
||||||
double actualHostSampleRate = 0.0;
|
double actualHostSampleRate = 0.0;
|
||||||
double actualRFSampleRate = 0.0;
|
double actualRFSampleRate = 0.0;
|
||||||
int getSampleRate = LMS_GetSampleRate(device, LMS_CH_TX, channel, &actualHostSampleRate, &actualRFSampleRate);
|
int getSampleRate = LMS_GetSampleRate(device, LMS_CH_TX, channel, &actualHostSampleRate, &actualRFSampleRate);
|
||||||
if(getSampleRate){
|
if(getSampleRate){
|
||||||
printf("getSampleRate=%d(%s)" "\n", getSampleRate, LMS_GetLastErrorMessage());
|
printf("getSampleRate=%d(%s)" "\n", getSampleRate, LMS_GetLastErrorMessage());
|
||||||
}else{
|
}else{
|
||||||
printf("actualRate %lf (Host) / %lf (RF)" "\n", actualHostSampleRate, actualRFSampleRate);
|
printf("actualRate %lf (Host) / %lf (RF)" "\n", actualHostSampleRate, actualRFSampleRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Calibrating ..." "\n");
|
printf("Calibrating ..." "\n");
|
||||||
int calibrate = LMS_Calibrate(device, LMS_CH_TX, channel, TX_BANDWIDTH, 0);
|
int calibrate = LMS_Calibrate(device, LMS_CH_TX, channel, TX_BANDWIDTH, 0);
|
||||||
if(calibrate){
|
if(calibrate){
|
||||||
printf("calibrate=%d(%s)" "\n", calibrate, LMS_GetLastErrorMessage());
|
printf("calibrate=%d(%s)" "\n", calibrate, LMS_GetLastErrorMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Setup TX stream ..." "\n");
|
printf("Setup TX stream ..." "\n");
|
||||||
lms_stream_t tx_stream = {.channel = channel, .fifoSize = 1024*1024, .throughputVsLatency = 0.5, .isTx = true, .dataFmt = LMS_FMT_I12};
|
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);
|
int setupStream = LMS_SetupStream(device, &tx_stream);
|
||||||
if(setupStream){
|
if(setupStream){
|
||||||
printf("setupStream=%d(%s)" "\n", setupStream, LMS_GetLastErrorMessage());
|
printf("setupStream=%d(%s)" "\n", setupStream, LMS_GetLastErrorMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
struct s16iq_sample_s {
|
struct s16iq_sample_s {
|
||||||
signed short int i;
|
signed short int i;
|
||||||
signed short int q;
|
signed short int q;
|
||||||
};
|
};
|
||||||
|
|
||||||
int nSamples = (int)sampleRate / 100;
|
int nSamples = (int)sampleRate / 100;
|
||||||
struct s16iq_sample_s *sampleBuffer = (struct s16iq_sample_s*)malloc(sizeof(struct s16iq_sample_s) * nSamples);
|
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;
|
int loop = 0;
|
||||||
if((12 == bits) || (16 == bits)){
|
if((12 == bits) || (16 == bits)){
|
||||||
// File contains interleaved 16-bit IQ values, either with only 12-bit data, or with 16-bit data
|
// 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)){
|
while((0 == control_c_received) && fread(sampleBuffer, sizeof(struct s16iq_sample_s), nSamples, stdin)){
|
||||||
loop++;
|
loop++;
|
||||||
if(0 == (loop % 100)){
|
if(0 == (loop % 100)){
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
||||||
lms_stream_status_t status;
|
lms_stream_status_t status;
|
||||||
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
||||||
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
||||||
}
|
}
|
||||||
if(16 == bits){
|
if(16 == bits){
|
||||||
// Scale down to 12-bit
|
// Scale down to 12-bit
|
||||||
// Quick and dirty, so -1 (0xFFFF) to -15 (0xFFF1) scale down to -1 instead of 0
|
// Quick and dirty, so -1 (0xFFFF) to -15 (0xFFF1) scale down to -1 instead of 0
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(i < nSamples){
|
while(i < nSamples){
|
||||||
sampleBuffer[i].i >>= 4;
|
sampleBuffer[i].i >>= 4;
|
||||||
sampleBuffer[i].q >>= 4;
|
sampleBuffer[i].q >>= 4;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
||||||
if(sendStream < 0){
|
if(sendStream < 0){
|
||||||
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else if(8 == bits){
|
}else if(8 == bits){
|
||||||
// File contains interleaved signed 8-bit IQ values
|
// File contains interleaved signed 8-bit IQ values
|
||||||
struct s8iq_sample_s {
|
struct s8iq_sample_s {
|
||||||
signed char i;
|
signed char i;
|
||||||
signed char q;
|
signed char q;
|
||||||
};
|
};
|
||||||
struct s8iq_sample_s *fileSamples = (struct s8iq_sample_s*)malloc(sizeof(struct s8iq_sample_s) * nSamples);
|
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)){
|
while((0 == control_c_received) && fread(fileSamples, sizeof(struct s8iq_sample_s), nSamples, stdin)){
|
||||||
loop++;
|
loop++;
|
||||||
if(0 == (loop % 100)){
|
if(0 == (loop % 100)){
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
||||||
lms_stream_status_t status;
|
lms_stream_status_t status;
|
||||||
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
||||||
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
||||||
}
|
}
|
||||||
// Up-Scale to 12-bit
|
// Up-Scale to 12-bit
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(i < nSamples){
|
while(i < nSamples){
|
||||||
sampleBuffer[i].i = (fileSamples[i].i << 4);
|
sampleBuffer[i].i = (fileSamples[i].i << 4);
|
||||||
sampleBuffer[i].q = (fileSamples[i].q << 4);
|
sampleBuffer[i].q = (fileSamples[i].q << 4);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
||||||
if(sendStream < 0){
|
if(sendStream < 0){
|
||||||
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(fileSamples);
|
free(fileSamples);
|
||||||
}else if(1 == bits){
|
}else if(1 == bits){
|
||||||
// File contains interleaved signed 1-bit IQ values
|
// File contains interleaved signed 1-bit IQ values
|
||||||
// Each byte is IQIQIQIQ
|
// Each byte is IQIQIQIQ
|
||||||
int16_t expand_lut[256][8];
|
int16_t expand_lut[256][8];
|
||||||
int i, j;
|
int i, j;
|
||||||
for (i=0; i<256; i++){
|
for (i=0; i<256; i++){
|
||||||
for (j=0; j<8; j++){
|
for (j=0; j<8; j++){
|
||||||
expand_lut[i][j] = ((i>>(7-j))&0x1)?dynamic:-dynamic;
|
expand_lut[i][j] = ((i>>(7-j))&0x1)?dynamic:-dynamic;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("1-bit mode: using dynamic=%d" "\n", 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]));
|
// 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);
|
int8_t *fileBuffer = (int8_t*)malloc(sizeof(int8_t) * nSamples);
|
||||||
while((0 == control_c_received) && fread(fileBuffer, sizeof(int8_t), nSamples / 4, stdin)){
|
while((0 == control_c_received) && fread(fileBuffer, sizeof(int8_t), nSamples / 4, stdin)){
|
||||||
loop++;
|
loop++;
|
||||||
if(0 == (loop % 100)){
|
if(0 == (loop % 100)){
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
printf("gettimeofday()=> %ld:%06ld ; ", tv.tv_sec, tv.tv_usec);
|
||||||
lms_stream_status_t status;
|
lms_stream_status_t status;
|
||||||
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
LMS_GetStreamStatus(&tx_stream, &status); //Obtain TX stream stats
|
||||||
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
printf("TX rate:%lf MB/s" "\n", status.linkRate / 1e6);
|
||||||
}
|
}
|
||||||
// Expand
|
// Expand
|
||||||
int src = 0;
|
int src = 0;
|
||||||
int dst = 0;
|
int dst = 0;
|
||||||
while(src < (nSamples / 4)){
|
while(src < (nSamples / 4)){
|
||||||
memcpy(sampleBuffer + dst, expand_lut + fileBuffer[src], sizeof(expand_lut[0]));
|
memcpy(sampleBuffer + dst, expand_lut + fileBuffer[src], sizeof(expand_lut[0]));
|
||||||
dst += 4;
|
dst += 4;
|
||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
int sendStream = LMS_SendStream(&tx_stream, sampleBuffer, nSamples, NULL, 1000);
|
||||||
if(sendStream < 0){
|
if(sendStream < 0){
|
||||||
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
printf("sendStream %d(%s)" "\n", sendStream, LMS_GetLastErrorMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(fileBuffer);
|
free(fileBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
LMS_StopStream(&tx_stream);
|
LMS_StopStream(&tx_stream);
|
||||||
LMS_DestroyStream(device, &tx_stream);
|
LMS_DestroyStream(device, &tx_stream);
|
||||||
|
|
||||||
free(sampleBuffer);
|
free(sampleBuffer);
|
||||||
|
|
||||||
LMS_EnableChannel(device, LMS_CH_TX, channel, false);
|
LMS_EnableChannel(device, LMS_CH_TX, channel, false);
|
||||||
LMS_Close(device);
|
LMS_Close(device);
|
||||||
|
|
||||||
if(control_c_received){
|
if(control_c_received){
|
||||||
return(EXIT_CODE_CONTROL_C);
|
return(EXIT_CODE_CONTROL_C);
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ int main(int argc, char** argv) {
|
|||||||
printf("* Found %s\n", iio_context_info_get_description(info[0]));
|
printf("* Found %s\n", iio_context_info_get_description(info[0]));
|
||||||
iio_context_info_list_free(info);
|
iio_context_info_list_free(info);
|
||||||
}
|
}
|
||||||
iio_scan_context_destroy(scan_ctx);
|
iio_scan_context_destroy(scan_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("* Acquiring devices\n");
|
printf("* Acquiring devices\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user