Merge pull request #143 from Mictronics/master

Improvement and code review for plutoplayer
This commit is contained in:
OSQZSS 2018-03-30 06:52:30 +09:00 committed by GitHub
commit 1ada56c621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,7 +26,9 @@ static void usage() {
fprintf(stderr, "Usage: plutoplayer [options]\n" fprintf(stderr, "Usage: plutoplayer [options]\n"
" -t <filename> Transmit data from file (required)\n" " -t <filename> Transmit data from file (required)\n"
" -a <attenuation> Set TX attenuation [dB] (default -20.0)\n" " -a <attenuation> Set TX attenuation [dB] (default -20.0)\n"
" -b <bw> Set RF bandwidth [MHz] (default 5.0)\n"); " -b <bw> Set RF bandwidth [MHz] (default 5.0)\n"
" -u <uri> ADALM-Pluto URI\n"
" -n <network> ADALM-Pluto network IP or hostname (default pluto.local)\n");
return; return;
} }
@ -58,7 +60,8 @@ int main(int argc, char** argv) {
const char* path = NULL; const char* path = NULL;
struct stream_cfg txcfg; struct stream_cfg txcfg;
FILE *fp = NULL; FILE *fp = NULL;
enum state {INIT, READ_FILE, PAD_TRAILING, DONE}; const char *uri = NULL;
const char *ip = NULL;
// TX stream default config // TX stream default config
txcfg.bw_hz = MHZ(3.0); // 3.0 MHz RF bandwidth txcfg.bw_hz = MHZ(3.0); // 3.0 MHz RF bandwidth
@ -74,7 +77,7 @@ int main(int argc, char** argv) {
struct iio_channel *tx0_q = NULL; struct iio_channel *tx0_q = NULL;
struct iio_buffer *tx_buffer = NULL; struct iio_buffer *tx_buffer = NULL;
while ((opt = getopt(argc, argv, "t:a:b:")) != EOF) { while ((opt = getopt(argc, argv, "t:a:b:n:u:")) != EOF) {
switch (opt) { switch (opt) {
case 't': case 't':
path = optarg; path = optarg;
@ -89,6 +92,12 @@ int main(int argc, char** argv) {
if(txcfg.bw_hz > MHZ(5.0)) txcfg.bw_hz = MHZ(5.0); if(txcfg.bw_hz > MHZ(5.0)) txcfg.bw_hz = MHZ(5.0);
if(txcfg.bw_hz < MHZ(1.0)) txcfg.bw_hz = MHZ(1.0); if(txcfg.bw_hz < MHZ(1.0)) txcfg.bw_hz = MHZ(1.0);
break; break;
case 'u':
uri = optarg;
break;
case 'n':
ip = optarg;
break;
default: default:
printf("Unknown argument '-%c %s'\n", opt, optarg); printf("Unknown argument '-%c %s'\n", opt, optarg);
usage(); usage();
@ -118,7 +127,13 @@ int main(int argc, char** argv) {
printf("* Acquiring IIO context\n"); printf("* Acquiring IIO context\n");
ctx = iio_create_default_context(); ctx = iio_create_default_context();
if (ctx == NULL) { if (ctx == NULL) {
ctx = iio_create_network_context("pluto.local"); if(ip != NULL) {
ctx = iio_create_network_context(ip);
} else if (uri != NULL) {
ctx = iio_create_context_from_uri(uri);
} else {
ctx = iio_create_network_context("pluto.local");
}
} }
if (ctx == NULL) { if (ctx == NULL) {
@ -171,10 +186,6 @@ int main(int argc, char** argv) {
iio_channel_attr_write_longlong( iio_channel_attr_write_longlong(
iio_device_find_channel(phydev, "altvoltage1", true) iio_device_find_channel(phydev, "altvoltage1", true)
, "frequency", txcfg.lo_hz); // Set TX LO frequency , "frequency", txcfg.lo_hz); // Set TX LO frequency
iio_channel_attr_write_longlong(
iio_device_find_channel(phydev, "altvoltage1", true)
, "frequency", txcfg.lo_hz); // Set TX LO frequency
printf("* Initializing streaming channels\n"); printf("* Initializing streaming channels\n");
tx0_i = iio_device_find_channel(tx, "voltage0", true); tx0_i = iio_device_find_channel(tx, "voltage0", true);
@ -204,17 +215,17 @@ int main(int argc, char** argv) {
, "powerdown", false); // Turn ON TX LO , "powerdown", false); // Turn ON TX LO
int32_t ntx = 0; int32_t ntx = 0;
char *ptx_buffer = (char *)iio_buffer_start(tx_buffer); short *ptx_buffer = (short *)iio_buffer_start(tx_buffer);
printf("* Transmit starts...\n"); printf("* Transmit starts...\n");
// Keep writing samples while there is more data to send and no failures have occurred. // Keep writing samples while there is more data to send and no failures have occurred.
while (!feof(fp) && !stop) { while (!feof(fp) && !stop) {
fread(ptx_buffer, 1, BUFFER_SIZE,fp); fread(ptx_buffer, sizeof(short), BUFFER_SIZE / sizeof(short),fp);
// Schedule TX buffer // Schedule TX buffer
ntx = iio_buffer_push(tx_buffer); ntx = iio_buffer_push(tx_buffer);
if (ntx < 0) { if (ntx < 0) {
printf("Error pushing buf %d\n", (int) ntx); printf("Error pushing buf %d\n", (int) ntx);
goto error_exit; break;
} }
} }
printf("Done.\n"); printf("Done.\n");