This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
university:tools:pluto:controlling_the_transceiver_and_transferring_data [28 Apr 2017 11:29] – Michael Hennerich | university:tools:pluto:controlling_the_transceiver_and_transferring_data [28 Apr 2017 15:52] – [Receiving data] Michael Hennerich | ||
---|---|---|---|
Line 17: | Line 17: | ||
* [[https:// | * [[https:// | ||
+ | ===== Controlling the transceiver ===== | ||
+ | |||
+ | <code c> | ||
+ | int main (int argc, char **argv) | ||
+ | { | ||
+ | struct iio_context *ctx; | ||
+ | struct iio_device *phy; | ||
+ | |||
+ | ctx = iio_create_context_from_uri(" | ||
+ | |||
+ | phy = iio_context_find_device(ctx, | ||
+ | |||
+ | iio_channel_attr_write_longlong( | ||
+ | iio_device_find_channel(phy, | ||
+ | " | ||
+ | 2400000000); | ||
+ | |||
+ | iio_channel_attr_write_longlong( | ||
+ | iio_device_find_channel(phy, | ||
+ | " | ||
+ | 50000000); | ||
+ | |||
+ | receive(ctx); | ||
+ | |||
+ | iio_context_destroy(ctx); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Receiving data ===== | ||
+ | |||
+ | <code c> | ||
+ | int receive(struct iio_context *ctx) | ||
+ | { | ||
+ | struct iio_device *dev; | ||
+ | struct iio_channel *rx0_i, *rx0_q; | ||
+ | struct iio_buffer *rxbuf; | ||
+ | |||
+ | dev = iio_context_find_device(ctx, | ||
+ | |||
+ | rx0_i = iio_device_find_channel(dev, | ||
+ | rx0_q = iio_device_find_channel(dev, | ||
+ | |||
+ | iio_channel_enable(rx0_i); | ||
+ | iio_channel_enable(rx0_q); | ||
+ | |||
+ | rxbuf = iio_device_create_buffer(dev, | ||
+ | if (!rxbuf) { | ||
+ | perror(" | ||
+ | shutdown(); | ||
+ | } | ||
+ | |||
+ | while (true) { | ||
+ | void *p_dat, *p_end, *t_dat; | ||
+ | ptrdiff_t p_inc; | ||
+ | |||
+ | iio_buffer_refill(rxbuf); | ||
+ | |||
+ | p_inc = iio_buffer_step(rxbuf); | ||
+ | p_end = iio_buffer_end(rxbuf); | ||
+ | |||
+ | for (p_dat = iio_buffer_first(rxbuf, | ||
+ | const int16_t i = ((int16_t*)p_dat)[0]; | ||
+ | const int16_t q = ((int16_t*)p_dat)[1]; | ||
+ | |||
+ | /* Process here */ | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | iio_buffer_destroy(rxbuf); | ||
+ | |||
+ | } | ||
+ | </ | ||