SDRPLAY linux commandline tools?

Add useful snippets of code or links to entire SDR projects.
Post Reply
espam
Posts: 3
Joined: Sat Jan 30, 2016 3:12 pm

SDRPLAY linux commandline tools?

Post by espam » Thu Feb 04, 2016 4:37 pm

HI,

are there any linux based tools like rtl_fm or hackrf_transfer for sdrplay?

thanks in advance,

regards
Last edited by espam on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

0815
Posts: 45
Joined: Sat Jan 30, 2016 3:07 pm

Re: SDRPLAY linux commandline tools?

Post by 0815 » Sat Feb 06, 2016 7:06 pm

Hi,

well good question - looking for something like that too...

want to pipe in a file like rtl_sdr -f XXXXXXXXX /stdout

regards
Last edited by 0815 on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

rgood123
Posts: 15
Joined: Fri Dec 18, 2015 9:55 pm

Re: SDRPLAY linux commandline tools?

Post by rgood123 » Sun Feb 07, 2016 1:39 pm

HI
Not sure, this maybe what you need "rtl_tcp server for SDRPlay"

https://github.com/TonyHoyle/sdrplay
Last edited by rgood123 on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

0815
Posts: 45
Joined: Sat Jan 30, 2016 3:07 pm

Re: SDRPLAY linux commandline tools?

Post by 0815 » Fri Feb 12, 2016 2:10 pm

thx @rgood,

i already knew that one but not that what i am looking for.

i want to stream from RSP directly into a cfile, like sdr_play can do with the RTL Dongles.....

Maybe the technical support has a solution for me...???

thanks

regards
Last edited by 0815 on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

0815
Posts: 45
Joined: Sat Jan 30, 2016 3:07 pm

Re: SDRPLAY linux commandline tools?

Post by 0815 » Sat Mar 05, 2016 9:32 pm

hi,

have now tried to pipe out the stream over gnuradio per file sink, well works at the fist moment but then comes to USB buffer overflows on maas.

is there any info if there ever will ever be an commandline tool for linux or will this never happen coz of the closed source?

thx
Last edited by 0815 on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

sdrplay
Posts: 978
Joined: Wed Jan 07, 2015 7:58 am

Re: SDRPLAY linux commandline tools?

Post by sdrplay » Sun Mar 06, 2016 8:57 am

Do you just want the raw IQ samples that come from the RSP?

That's easy enough to do with the API. Let me know if that's what you want and I'll post some example code.

Best regards,

SDRplay Support
Last edited by sdrplay on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

0815
Posts: 45
Joined: Sat Jan 30, 2016 3:07 pm

Re: SDRPLAY linux commandline tools?

Post by 0815 » Sun Mar 06, 2016 9:16 am

hi,

yep the raw I-Q data to a file and also the options to set frequency samplerate gain.... like rtl_sdr too lcan do

would be great to drop a few lines of code

thx
Last edited by 0815 on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

sdrplay
Posts: 978
Joined: Wed Jan 07, 2015 7:58 am

Re: SDRPLAY linux commandline tools?

Post by sdrplay » Sun Mar 06, 2016 10:23 am

Just a simple piece of code to take in frequency, sample rate, IF bandwidth and IF mode and then output raw IQ to stdout

./rawIQ > output_file

use ./rawIQ -h to find out the input requirements. Run without any options the code has some built in defaults which you can change to suit if that's easier.

Please note: The Mirics API header also goes to stdout so you'll need to edit the file and remove it or you can modify the code to just output the raw data to a file, but at least you have the code to do that now.

The code is provided AS-IS with no warranty.

Scroll down and a simple Makefile is also at the end of this post. As long as you have the API installed, typing make should build rawIQ. The actual code to do this is 2-3 lines, the rest is checking user input etc. so you can take the relevant bits out of this for your own purpose.

Let us know how you get on. This was built and tested on Ubutu 14.04

Best regards,

SDRplay Support

Code: Select all

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>

#include "mirsdrapi-rsp.h"

int parseArgs(int *gr, double *fs, double *rf, mir_sdr_Bw_MHzT *bwType, mir_sdr_If_kHzT *ifType, int argc, char **argv);

void INTHandler(int sig)
{
    signal(sig, SIG_IGN);
    fprintf(stderr, "Caught signal %d, exiting...\n", sig);
    exit(sig);
}

int main(int argc, char **argv)
{

   signal(SIGINT, INTHandler);

   int sampsPerPkt;
   mir_sdr_ErrT err;
   short *xi = NULL;
   short *xq = NULL;
   int i = 0;
   unsigned int firstSamp;
   int grChanged;
   int rfChanged;
   int fsChanged;
   int gr = 40;
   double fs = 2.048;
   double rf = 176.640;
   mir_sdr_Bw_MHzT bwType = mir_sdr_BW_1_536;
   mir_sdr_If_kHzT ifType = mir_sdr_IF_Zero;

   if (!parseArgs(&gr, &fs, &rf, &bwType, &ifType, argc, argv))
   {
      exit(0);
   }

   err = mir_sdr_Init(gr, fs, rf, bwType, ifType, &sampsPerPkt);
   if (err != mir_sdr_Success)
   {
      fprintf(stderr, "mir_sdr_Init: Error %d\n", err);
      exit(1);
   }

   fprintf(stderr, "sampsPerPkt = %d\n", sampsPerPkt);
   xi = (short *)malloc(sizeof(short));
   xq = (short *)malloc(sizeof(short));
   if ((xi == NULL) || (xq == NULL))
   {
      fprintf(stderr, "failed to allocate buffers - exiting\n");
      mir_sdr_Uninit();
      exit(1);
   }

   while(1)
   {
        mir_sdr_ReadPacket(&xi[0], &xq[0], &firstSamp, &grChanged, &rfChanged, &fsChanged);

        for (i = 0; i < sampsPerPkt; i++)
        {
            printf("%hi, %hi\n", xi[i], xq[i]);

        }
    }
}

int parseArgs(int *gr, double *fs, double *rf, mir_sdr_Bw_MHzT *bwType, mir_sdr_If_kHzT *ifType, int argc, char **argv)
{
   int i;
   int grdef = 1;
   int fsdef = 1;
   int rfdef = 1;
   int bwdef = 1;
   int ifdef = 1;
   int grlocal = 0;
   double fslocal = 0;
   double rflocal = 0;
   double bwlocal = (double)(*bwType) / 1000.0;
   double iflocal = (double)(*ifType) / 1000.0;
   int temp;

   for (i = 1; i < argc; i++)
   {
      if (strchr(argv[i], '-') == argv[i])
      {
         if ((i + 1) == argc)
         {
            fprintf(stderr, "Error: expected value following %s, instead found end of args\n", argv[i]);
            goto error;
         }
         if (strchr(argv[i + 1], '-') == argv[i + 1])
         {
            if (argv[i][1] != 's')
            {
               fprintf(stderr, "Error: expected value following %s, instead found %s\n", argv[i], argv[i + 1]);
               goto error;
            }
         }
         switch (argv[i][1])
         {
         case 'g':
            grlocal = atoi(argv[i + 1]);
            *gr = grlocal;
            grdef = 0;
            break;
         case 's':
            fslocal = atof(argv[i + 1]);
            if (fslocal == 0.0)
            {
               fprintf(stderr, "Error: Fs value = %.3f\n", fslocal);
               goto error;
            }
            *fs = fslocal;
            fsdef = 0;
            break;
         case 'f':
            rflocal = atof(argv[i + 1]);
            if (rflocal == 0.0)
            {
               fprintf(stderr, "Error: Rf value = %.3f\n", rflocal);
               goto error;
            }
            *rf = rflocal;
            rfdef = 0;
            break;
         case 'b':
            bwlocal = atof(argv[i + 1]);
            temp = (int)(bwlocal * 1000.0);
            switch (temp)
            {
            case 200:
               *bwType = mir_sdr_BW_0_200;
               break;
            case 300:
               *bwType = mir_sdr_BW_0_300;
               break;
            case 600:
               *bwType = mir_sdr_BW_0_600;
               break;
            case 1536:
               *bwType = mir_sdr_BW_1_536;
               break;
            case 5000:
               *bwType = mir_sdr_BW_5_000;
               break;
            case 6000:
               *bwType = mir_sdr_BW_6_000;
               break;
            case 7000:
               *bwType = mir_sdr_BW_7_000;
               break;
            case 8000:
               *bwType = mir_sdr_BW_8_000;
               break;
            default:
               fprintf(stderr, "Error: Bandwidth (in MHz) must be one of %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n",
                       0.200, 0.300, 0.600, 1.536, 5.000, 6.000, 7.000, 8.000);
               goto error;
            }
            bwdef = 0;
            break;
         case 'i':
            iflocal = atof(argv[i + 1]);
            temp = (int)(iflocal * 1000.0);
            switch(temp)
            {
            case 2048:
               *ifType = mir_sdr_IF_2_048;
               break;
            case 1620:
               *ifType = mir_sdr_IF_1_620;
               break;
            case 450:
               *ifType = mir_sdr_IF_0_450;
               break;
            case 0:
               *ifType = mir_sdr_IF_Zero;
               break;
            default:
               fprintf(stderr, "Error: If frequency (in MHz) must be one of %.3f, %.3f, %.3f, %.3f\n",
                       0.000, 0.450, 1.620, 2.048);
               goto error;
            }
            ifdef = 0;
            break;
         default:
            goto error;
        }
         i++;
      }
      else
         goto error;
   }
   fprintf(stderr, "Parameters:\n");
   fprintf(stderr, "   GainReduction   = %ddB\t%s\n", *gr, (grdef)? "[default]": "");
   fprintf(stderr, "   SampleRate      = %.3fMHz\t%s\n", *fs, (fsdef)? "[default]": "");
   fprintf(stderr, "   CentreFrequency = %.3fMHz\t%s\n", *rf, (rfdef)? "[default]": "");
   fprintf(stderr, "   Bandwidth       = %.3fMHz\t%s\n", bwlocal, (bwdef)? "[default]": "");
   fprintf(stderr, "   IfFrequency     = %.3fMHz\t%s\n", iflocal, (ifdef)? "[default]": "");
   return 1;
error:
   fprintf(stderr, "Usage: rawIQ [-g <InitialGainReduction_dB>] [-s <SampFreq_MHz>] [-f <CentreFreq_MHz>] [-b <Bandwidth_MHz>] [-i <IfFreq_MHz>]\n");
   return 0;
}
Makefile

Code: Select all

CFLAGS?=-O2 -g -Wall -W
LDLIBS+= -lpthread -lm -lmirsdrapi-rsp
CC?=gcc
PROGNAME=rawIQ

all: rawIQ

%.o: %.c
	$(CC) $(CFLAGS) -c $<

rawIQ: rawIQ.o
	$(CC) -g -o rawIQ rawIQ.o $(LDFLAGS) $(LDLIBS)

clean:
	rm -f *.o rawIQ
Last edited by sdrplay on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

sdrplay
Posts: 978
Joined: Wed Jan 07, 2015 7:58 am

Re: SDRPLAY linux commandline tools?

Post by sdrplay » Sun Mar 06, 2016 10:59 am

Please note the output is 16 bits, not 8 bits as per the RTL dongles.

You'll need to covert to 8 bits if you want a compatible format.

Best regards,

SDRplay Support
Last edited by sdrplay on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

0815
Posts: 45
Joined: Sat Jan 30, 2016 3:07 pm

Re: SDRPLAY linux commandline tools?

Post by 0815 » Sun Mar 06, 2016 11:40 am

hi,

thanks sounds good but i am only getting some random numbers but now IQ stream.....

mir_sdr_Init: starting hardware initialization
mir_sdr_Init: gR=40dB fs=2.000MHz rf=108.800MHz bw=1.536MHz if=0.000MHz

mir_sdr_usb_USB DLL: Revision 0.1.1

mir_sdr_2500_Init: revisionId = 0x0200, doing FW update
fwDownload: FW image size = 6008
Error: libusb_release_interface() -4

mir_sdr_usb_USB DLL: Revision 0.1.1

mir_sdr_2500_Init: fnaddr = 9

mir_sdr_2500_Init: adjusting squelch trim 0x1, rx gating enable 1, tx_trim 0, reg2 = 0x4801
initHw: Register7 = 0x000014
initHw: Tuner Register0 = 0x04f420
mir_sdr_SetFs: Sample Freq requested 2000000.000000
mir_sdr_SetFs: Fs->FsNomHz+dFsHz=2000000.0+0.0Hz=2000000.0Hz FsToggle->1
mir_sdr_SetRf: f->108800000.000Hz (int=24 frac=320 afc=0) fSynth:3481600000.000
mir_sdr_SetRf: Rf->RfNomHz+dRfHz+LifHz+Lif1Hz=108800000.0+0.0+0.0Hz+0.0Hz=108800000.0Hz RfToggle->1
mir_sdr_SetGr: GR->40[16,24,0,0] gRset->0x210 DCCALmode=4 DCCALspd=1 GrToggle->1
setToggleStates: initialising sampNum=0x000180d7, gainSetting=0x210, FsToggle=0, RfToggle=1, GrToggle=1
setToggleStates: initialising Fs=2000000.000, Rf=108800000.000, Gr=40
922, 7
851, -109
2169, 394
-1121, -457
-3233, -1241
534, -528
2092, 1008
1035, -553
823, -432
995, 470
1137, -621
1363, -259
3710, 991
2319, 861
Last edited by 0815 on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

Post Reply