Correction> These functions work on integers.

So they go as:
int16 data = htobe16(le32toh(int32 data))
Or the associate functions,
htonl, htons

So you need to already have converted your floats to ints...
If in doubt, test them first on a single data...
Sorry about the confusion.

Nikos

On Sat, Jul 9, 2022 at 5:36 PM Nikos Balkanas <nbalka...@gmail.com> wrote:
>
> Hi,
>
> I don't know about gnuradio classes:( Maybe you should ask them...
> But in C, I would use le32toh, I assume gnuradio is in little endian.
> and then htobe16 to get for uhd:
> uint16 data = htobe16(le32toh(float 32 data))
> I assume this already does ceil or floor, so your data needs to be
> already in the right scale:)
>
> HTH
> Nikos
>
> On Sat, Jul 9, 2022 at 4:57 PM sp <stackprogra...@gmail.com> wrote:
> >
> > I know that data in USRP on FPGA is in format big-endian sint16, but in 
> > Gnuradio data is in format complex float 32...
> > I found these links
> > The conversion encompasses several elements. The most obvious is that of 
> > the data type: Most FPGAs use integer data types, the most common being 
> > complex 16-bit integers (16 bit for I and Q, respectively). If the user 
> > wants his data in float, the converter casts the data type and also scales 
> > the data, typically such that the full dynamic range of the 16-Bit integers 
> > is mapped onto the float range of -1 to 1. The converter also handles the 
> > endianness: On the network, data is usually stored as big-endian, whereas 
> > most platforms store data internally as little-endian.
> >
> > https://files.ettus.com/manual/classuhd_1_1convert_1_1converter.html#a371906249b8bd546b98bd0a867e70c88
> > https://files.ettus.com/manual/page_converters.html
> >
> > According to them, I want to use the Convert class to convert complex float 
> > 32 to sint16....
> > But my program is can not run successfully, Anyone can guide me on How 
> > should I use the Converter class...!!!
> > Thanks in advance
> >
> >> #include <uhd/convert.hpp>
> >
> >
> >
> >>
> >>  int main()
> >>
> >>    {
> >>
> >>    int16_t *in_p;
> >>
> >>    float *out_p;
> >>
> >>    *in_p=1234;
> >>
> >>    uhd::convert::converter::input_type in(in_p);
> >>
> >>    uhd::convert::converter::output_type out(out_p);
> >>
> >>    uhd::convert::converter::sptr convert;
> >>
> >>    convert->conv(in,out,1);
> >>
> >>    std::cout<<*out_p;
> >>
> >>       }
> >
> >
> > _______________________________________________
> > USRP-users mailing list -- usrp-users@lists.ettus.com
> > To unsubscribe send an email to usrp-users-le...@lists.ettus.com
_______________________________________________
USRP-users mailing list -- usrp-users@lists.ettus.com
To unsubscribe send an email to usrp-users-le...@lists.ettus.com

Reply via email to